diff --git "a/data.txt" "b/data.txt" new file mode 100644--- /dev/null +++ "b/data.txt" @@ -0,0 +1,293854 @@ +int gcd(int a, int b) { + return !b ? a : gcd(b, a % b); +} +int main() { + int n, nn, ans = 0; + cin >> n; + for (int i = 2; i <= n - 1; ++i) { + nn = n; + while (nn) ans += nn % i, nn /= i; + } + int o = gcd(ans, n - 2); + cout << ans / o << "/" << (n - 2) / o << "\n"; + return 0; +} +int gcd(int a, int b) { + return !b ? a : gcd(b, a % b); +} +int main() { + int n, nn, ans = 0; + cin >> n; + for (int i = 2; i <= n - 1; ++i) { + nn = n; + while (nn) ans += nn % i, nn /= i; + } + int o = gcd(ans, n - 2); + cout << ans / o << "/" << (n - 2) / o << "\n"; + return 0; +} +int main() { + string a, b; + int n; + set st; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + st.insert(a + " " + b); + } + cout << st.size() << endl; + return 0; +} +int main() { + int n, m, su = 0, su2 = 0, a, b, c; + cin >> n; + m = n; + for (int i = 2; i < n; i++) { + while (n > 0) { + su += n % i; + n = n / i; + } + n = m; + } + c = su; + a = su; + m = m - 2; + b = m; + su2 = su % b; + while (su2 > 0) { + su = b; + b = su2; + su2 = su % b; + } + cout << c / b << "/" << m / b << endl; + return 0; +} +int gcd1(int a, int b) { + if (a == 0) return b; + return gcd1(b % a, a); +} +long long modx(long long base, long long ex) { + long long ans = 1LL, val = base; + while (ex > 0LL) { + if (ex & 1LL) ans = (ans * val) % 1000000009LL; + val = (val * val) % 1000000009LL; + ex = ex >> 1LL; + } + return ans; +} +int ans1 = 0, ans2 = 0; +int n, a, b, c; +const int maxn = 105; +bool visit[maxn]; +vector adj[maxn]; +int dist[maxn][maxn]; +vector v; +void dfs(int start) { + visit[start] = true; + v.push_back(start); + for (int i = 0; i < adj[start].size(); i++) { + int pt = adj[start][i]; + if (!visit[pt]) dfs(pt); + } +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b >> c; + adj[a].push_back(b); + adj[b].push_back(a); + dist[b][a] = c; + } + dfs(1); + for (int i = 0; i < v.size(); i++) { ans1 += dist[v[i]][v[(i + 1) % n]]; } + for (int i = v.size() - 1; i >= 0; i--) { + if (i == 0) + ans2 += dist[v[i]][v[v.size() - 1]]; + else + ans2 += dist[v[i]][v[i - 1]]; + } + cout << min(ans1, ans2) << endl; + return 0; +} +map m; +map::iterator it; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + m[str] = 1; + } + int ans = 0; + for (it = m.begin(); it != m.end(); it++) { ans++; } + cout << ans << endl; +} +int main() { + int i, n, k, rem, sum = 0, l; + cin >> n; + for (i = 2; i < n; i++) { + k = n; + while (k > 0) { + rem = k % i; + sum += rem; + k /= i; + } + } + l = __gcd(sum, n - 2); + cout << sum / l << "/" << (n - 2) / l << endl; +} +int main() { + int i, n, k, rem, sum = 0, l; + cin >> n; + for (i = 2; i < n; i++) { + k = n; + while (k > 0) { + rem = k % i; + sum += rem; + k /= i; + } + } + l = __gcd(sum, n - 2); + cout << sum / l << "/" << (n - 2) / l << endl; +} +string s, s1; +set se; +int main() { + int i, j, k; + int n, m; + cin >> n; + for (i = 0; i < n; i++) cin >> s >> s1, s += ' ', s += s1, se.insert(s); + cout << se.size() << endl; +} +string s, s1; +set se; +int main() { + int i, j, k; + int n, m; + cin >> n; + for (i = 0; i < n; i++) cin >> s >> s1, s += ' ', s += s1, se.insert(s); + cout << se.size() << endl; +} +int main() { + int n, m, su = 0, su2 = 0, a, b, c; + cin >> n; + m = n; + for (int i = 2; i < n; i++) { + while (n > 0) { + su += n % i; + n = n / i; + } + n = m; + } + c = su; + a = su; + m = m - 2; + b = m; + su2 = su % b; + while (su2 > 0) { + su = b; + b = su2; + su2 = su % b; + } + cout << c / b << "/" << m / b << endl; + return 0; +} +int main() { + int n, m, su = 0, su2 = 0, a, b, c; + cin >> n; + m = n; + for (int i = 2; i < n; i++) { + while (n > 0) { + su += n % i; + n = n / i; + } + n = m; + } + c = su; + a = su; + m = m - 2; + b = m; + su2 = su % b; + while (su2 > 0) { + su = b; + b = su2; + su2 = su % b; + } + cout << c / b << "/" << m / b << endl; + return 0; +} +string s1[110], s2[110]; +int n, ans, book[110]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) cin >> s1[i] >> s2[i]; + for (int i = 0; i < n; ++i) { + int ok = 1; + for (int j = 0; j < n; ++j) { + if (i == j) continue; + if (s1[i] == s1[j] && s2[i] == s2[j]) { + if (book[j]) { + ok = 0; + break; + } + } + } + book[i] = 1; + ans += ok; + } + cout << ans << endl; + return 0; +} +string s1[110], s2[110]; +int n, ans, book[110]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) cin >> s1[i] >> s2[i]; + for (int i = 0; i < n; ++i) { + int ok = 1; + for (int j = 0; j < n; ++j) { + if (i == j) continue; + if (s1[i] == s1[j] && s2[i] == s2[j]) { + if (book[j]) { + ok = 0; + break; + } + } + } + book[i] = 1; + ans += ok; + } + cout << ans << endl; + return 0; +} +int num[105][105]; +int vis[105]; +int n; +int counts; +int en; +void dfs(int k) { + en = k; + if (k == 1 && vis[1] == 1) return; + vis[k] = 1; + for (int i = 1; i <= n; i++) { + if (vis[i] == 0) { + if (num[k][i] == -1) { + if (num[i][k] != -1) { + counts += num[i][k]; + dfs(i); + } + } else { + dfs(i); + } + } + } +} +int main() { + int x, y, l; + int sum; + while (cin >> n) { + sum = 0; + memset(num, -1, sizeof(num)); + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < n; i++) { + cin >> x >> y >> l; + num[x][y] = l; + sum += l; + } + counts = 0; + dfs(1); + if (num[en][1] == -1) counts += num[1][en]; + cout << min(counts, sum - counts) << endl; + } +} +int num[105][105]; +int vis[105]; +int n; +int counts; +int en; +void dfs(int k) { + en = k; + if (k == 1 && vis[1] == 1) return; + vis[k] = 1; + for (int i = 1; i <= n; i++) { + if (vis[i] == 0) { + if (num[k][i] == -1) { + if (num[i][k] != -1) { + counts += num[i][k]; + dfs(i); + } + } else { + dfs(i); + } + } + } +} +int main() { + int x, y, l; + int sum; + while (cin >> n) { + sum = 0; + memset(num, -1, sizeof(num)); + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < n; i++) { + cin >> x >> y >> l; + num[x][y] = l; + sum += l; + } + counts = 0; + dfs(1); + if (num[en][1] == -1) counts += num[1][en]; + cout << min(counts, sum - counts) << endl; + } +} +int main() { + int x, y; + cin >> x >> y; + cout << x * y / 2 << endl; +} +int main() { + int x, y; + cin >> x >> y; + cout << x * y / 2 << endl; +} +long long gcd(long long a, long long b) { + while (b != 0) { + long long t = b; + b = a % b; + a = t; + } + return a; +} +int main() { + long long a, s, i, j, k, ct, aa, g; + cin >> a; + s = 0; + for (i = 2; i <= a - 1; i++) { + aa = a; + ct = 0; + while (aa > 0) { + ct += aa % i; + aa /= i; + } + s += ct; + } + ct = a - 2; + g = gcd(s, ct); + s /= g; + ct /= g; + cout << s << "/" << ct << "\n"; + return 0; +} +long long gcd(long long a, long long b) { + while (b != 0) { + long long t = b; + b = a % b; + a = t; + } + return a; +} +int main() { + long long a, s, i, j, k, ct, aa, g; + cin >> a; + s = 0; + for (i = 2; i <= a - 1; i++) { + aa = a; + ct = 0; + while (aa > 0) { + ct += aa % i; + aa /= i; + } + s += ct; + } + ct = a - 2; + g = gcd(s, ct); + s /= g; + ct /= g; + cout << s << "/" << ct << "\n"; + return 0; +} +void fastIo() {} +int main() { + fastIo(); + int n, m; + cin >> n >> m; + char MAT[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cin >> MAT[i][j]; + } + int LC = m, RC = -1, TR = n, BR = -1; + for (int i = 0; i < n; i++) { + bool first = false; + for (int j = 0; j < m; j++) { + if (MAT[i][j] == '*') { + if (!first) { + LC = min(LC, j); + first = true; + } + RC = max(RC, j); + } + } + } + for (int j = 0; j < m; j++) { + bool first = false; + for (int i = 0; i < n; i++) { + if (MAT[i][j] == '*') { + if (!first) { TR = min(TR, i); } + BR = max(BR, i); + } + } + } + for (int i = TR; i <= BR; i++) { + for (int j = LC; j <= RC; j++) { cout << MAT[i][j]; } + cout << '\n'; + } +} +int i, n, a, b, c, fa[102][102], p1, p2; +vector v[102]; +bool viy[102][2]; +void f1(int dg, int msh) { + if (viy[dg][0]) return; + viy[dg][0] = 1; + if (msh != v[dg][0]) { + p1 += fa[v[dg][0]][dg]; + f1(v[dg][0], dg); + } else { + p1 += fa[v[dg][1]][dg]; + f1(v[dg][1], dg); + } +} +void f2(int dg, int msh) { + if (viy[dg][1]) return; + viy[dg][1] = 1; + if (msh != v[dg][1]) { + p2 += fa[v[dg][1]][dg]; + f2(v[dg][1], dg); + } else { + p2 += fa[v[dg][0]][dg]; + f2(v[dg][0], dg); + } +} +int main() { + cin >> n; + for (i = 0; i < n; ++i) { + cin >> a >> b >> c; + v[a].push_back(b); + v[b].push_back(a); + fa[b][a] = c; + } + f1(1, 0); + f2(1, 0); + cout << min(p1, p2) << "\n"; +} +set set1; +set set2; +map map1; +map map2; +int cp[101][101]; +int mc1; +int mc2; +int malloc_1(string a) { + if (set1.count(a) != 0) { + return map1[a]; + } else { + set1.insert(a); + map1[a] = mc1++; + return map1[a]; + } +} +int malloc_2(string a) { + if (set2.count(a) != 0) { + return map2[a]; + } else { + set2.insert(a); + map2[a] = mc2++; + return map2[a]; + } +} +int main() { + int n; + int cnt = 0; + while (cin >> n) { + cnt = 0; + set1.clear(); + set2.clear(); + mc1 = mc2 = 0; + map1.clear(); + memset(cp, 0, sizeof(cp)); + map2.clear(); + string a, b; + int c, d; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + c = malloc_1(a); + d = malloc_2(b); + if (cp[c][d] == 0) { + cnt++; + cp[c][d] = 1; + } + } + cout << cnt << endl; + } + return 0; +} +set set1; +set set2; +map map1; +map map2; +int cp[101][101]; +int mc1; +int mc2; +int malloc_1(string a) { + if (set1.count(a) != 0) { + return map1[a]; + } else { + set1.insert(a); + map1[a] = mc1++; + return map1[a]; + } +} +int malloc_2(string a) { + if (set2.count(a) != 0) { + return map2[a]; + } else { + set2.insert(a); + map2[a] = mc2++; + return map2[a]; + } +} +int main() { + int n; + int cnt = 0; + while (cin >> n) { + cnt = 0; + set1.clear(); + set2.clear(); + mc1 = mc2 = 0; + map1.clear(); + memset(cp, 0, sizeof(cp)); + map2.clear(); + string a, b; + int c, d; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + c = malloc_1(a); + d = malloc_2(b); + if (cp[c][d] == 0) { + cnt++; + cp[c][d] = 1; + } + } + cout << cnt << endl; + } + return 0; +} +int lcm(int a, int b) { + if (a < b) { + int tem = a; + a = b; + b = tem; + } + if (a % b == 0) { + return b; + } else + return lcm(b, a % b); +} +int main() { + int sum, n, su, i; + while (cin >> n) { + sum = 0; + for (i = 2; i < n; i++) { + su = 0; + int tem = n; + while (tem != 0) { + su += tem % i; + tem = tem / i; + } + sum += su; + } + int re = lcm(sum, n - 2); + cout << sum / re << "/" << (n - 2) / re << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + getchar(); + string s; + map p; + while (n--) { + getline(cin, s); + p[s]++; + } + cout << p.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + getchar(); + string s; + map p; + while (n--) { + getline(cin, s); + p[s]++; + } + cout << p.size() << endl; + return 0; +} +int GCD(int x, int y) { + int r = x % y; + while (r != 0) { + x = y; + y = r; + r = x % y; + } + return y; +} +int main() { + int m, u; + cin >> m; + int x(0), y(m - 2); + for (int i = 2; i < m; i++) { + int n(m), z(0); + while (n != 0) { + z += n % i; + n /= i; + } + x += z; + } + u = GCD(x, y); + x /= u; + y /= u; + cout << x << "/" << y << endl; + return 0; +} +int n, m, min_i = 51, min_j = 51, max_i, max_j; +char a[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + min_i = min(min_i, i); + min_j = min(min_j, j); + max_i = max(max_i, i); + max_j = max(max_j, j); + } + } + for (int i = min_i; i <= max_i; i++) { + for (int j = min_j; j <= max_j; j++) { cout << a[i][j]; } + cout << "\n"; + } +} +int n, m, min_i = 51, min_j = 51, max_i, max_j; +char a[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + min_i = min(min_i, i); + min_j = min(min_j, j); + max_i = max(max_i, i); + max_j = max(max_j, j); + } + } + for (int i = min_i; i <= max_i; i++) { + for (int j = min_j; j <= max_j; j++) { cout << a[i][j]; } + cout << "\n"; + } +} +const int maxn = 100; +int G[maxn][maxn]; +int G1[maxn][maxn]; +int vis[maxn]; +int num; +int N; +int lsum, ssum; +void dfs(int cur, int n) { + for (int i = 1; i <= num; i++) { + if (!vis[i] && G1[cur][i] != 0) { + vis[i] = 1; + if (G[cur][i] != 0) { lsum += G[cur][i]; } + dfs(i, n + 1); + } + } + if (n == N) { + if (G[cur][1]) { lsum += G[cur][1]; } + } +} +int main() { + while (cin >> N) { + memset(vis, 0, sizeof(vis)); + memset(G, 0, sizeof(G)); + memset(G1, 0, sizeof(G1)); + int x, y, v; + num = 0; + lsum = 0; + ssum = 0; + for (int i = 0; i < N; i++) { + cin >> x >> y >> v; + G[x][y] = v; + G1[x][y] = v; + G1[y][x] = v; + ssum += v; + num = max(num, max(x, y)); + } + vis[1] = 1; + dfs(1, 1); + cout << min(lsum, ssum - lsum) << endl; + } +} +const int maxn = 100; +int G[maxn][maxn]; +int G1[maxn][maxn]; +int vis[maxn]; +int num; +int N; +int lsum, ssum; +void dfs(int cur, int n) { + for (int i = 1; i <= num; i++) { + if (!vis[i] && G1[cur][i] != 0) { + vis[i] = 1; + if (G[cur][i] != 0) { lsum += G[cur][i]; } + dfs(i, n + 1); + } + } + if (n == N) { + if (G[cur][1]) { lsum += G[cur][1]; } + } +} +int main() { + while (cin >> N) { + memset(vis, 0, sizeof(vis)); + memset(G, 0, sizeof(G)); + memset(G1, 0, sizeof(G1)); + int x, y, v; + num = 0; + lsum = 0; + ssum = 0; + for (int i = 0; i < N; i++) { + cin >> x >> y >> v; + G[x][y] = v; + G1[x][y] = v; + G1[y][x] = v; + ssum += v; + num = max(num, max(x, y)); + } + vis[1] = 1; + dfs(1, 1); + cout << min(lsum, ssum - lsum) << endl; + } +} +int main() { + int m, n, s = 0; + cin >> m >> n; + if (m % 2 != 0 && n % 2 != 0) { + if (n == 1) { + s = (((m - 1) / 2) * n); + cout << s << "\n"; + } else if (m == 1) { + s = (((n - 1) / 2) * m); + cout << s << "\n"; + } else { + s = (((m - 1) / 2) * n) + n / 2; + cout << s << "\n"; + } + } else if (m % 2 == 0) + cout << (m / 2) * n << "\n"; + else if (n % 2 == 0) + cout << (n / 2) * m << "\n"; + return 0; +} +int main() { + int m, n, s = 0; + cin >> m >> n; + if (m % 2 != 0 && n % 2 != 0) { + if (n == 1) { + s = (((m - 1) / 2) * n); + cout << s << "\n"; + } else if (m == 1) { + s = (((n - 1) / 2) * m); + cout << s << "\n"; + } else { + s = (((m - 1) / 2) * n) + n / 2; + cout << s << "\n"; + } + } else if (m % 2 == 0) + cout << (m / 2) * n << "\n"; + else if (n % 2 == 0) + cout << (n / 2) * m << "\n"; + return 0; +} +map m; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + m[str] = 3; + } + int cnt = 0; + for (map::iterator it = m.begin(); it != m.end(); ++it) { cnt++; } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + for (int i = 2; i < n; i++) { + int temp = 0; + int num = n; + while (num != 0) { + temp += (num % i); + num /= i; + } + ans += temp; + } + cout << ans / __gcd(ans, n - 2) << "/" << (n - 2) / __gcd(ans, n - 2) << "\n"; + return 0; +} +int edges[105][105]; +void dfs(int *visited, int index, long *ans, int n) { + visited[index] = 1; + for (int i = 0; i < n; i++) { + if (edges[index][i] >= 0) { + if (visited[i] == 0) { + *ans = *ans + edges[index][i]; + dfs(visited, i, ans, n); + } + } + } +} +void dfs2(int *visited, int index, long *ans, int n) { + visited[index] = 1; + for (int i = n - 1; i >= 0; i--) { + if (edges[index][i] >= 0) { + if (visited[i] == 0) { + *ans = *ans + edges[index][i]; + dfs(visited, i, ans, n); + } + } + } +} +int main() { + int n; + cin >> n; + int a, b, c; + int visited[n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { edges[i][j] = -1; } + } + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + a--; + b--; + edges[a][b] = 0; + edges[b][a] = c; + visited[i] = 0; + } + long ans = 0; + dfs(visited, 0, &ans, n); + for (int i = n - 1; i >= 0; i--) { + if (edges[0][i] >= 0) { + ans += edges[i][0]; + break; + } + } + long ans2 = 0; + for (int i = 0; i < n; i++) { visited[i] = 0; } + dfs2(visited, 0, &ans2, n); + for (int i = 0; i < n; i++) { + if (edges[0][i] >= 0) { + ans2 += edges[i][0]; + break; + } + } + ans = min(ans, ans2); + cout << ans << endl; + return 0; +} +int edges[105][105]; +void dfs(int *visited, int index, long *ans, int n) { + visited[index] = 1; + for (int i = 0; i < n; i++) { + if (edges[index][i] >= 0) { + if (visited[i] == 0) { + *ans = *ans + edges[index][i]; + dfs(visited, i, ans, n); + } + } + } +} +void dfs2(int *visited, int index, long *ans, int n) { + visited[index] = 1; + for (int i = n - 1; i >= 0; i--) { + if (edges[index][i] >= 0) { + if (visited[i] == 0) { + *ans = *ans + edges[index][i]; + dfs(visited, i, ans, n); + } + } + } +} +int main() { + int n; + cin >> n; + int a, b, c; + int visited[n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { edges[i][j] = -1; } + } + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + a--; + b--; + edges[a][b] = 0; + edges[b][a] = c; + visited[i] = 0; + } + long ans = 0; + dfs(visited, 0, &ans, n); + for (int i = n - 1; i >= 0; i--) { + if (edges[0][i] >= 0) { + ans += edges[i][0]; + break; + } + } + long ans2 = 0; + for (int i = 0; i < n; i++) { visited[i] = 0; } + dfs2(visited, 0, &ans2, n); + for (int i = 0; i < n; i++) { + if (edges[0][i] >= 0) { + ans2 += edges[i][0]; + break; + } + } + ans = min(ans, ans2); + cout << ans << endl; + return 0; +} +int main() { + int l, b; + cin >> l >> b; + cout << ((l * b) / 2) << endl; + return 0; +} +int main() { + int l, b; + cin >> l >> b; + cout << ((l * b) / 2) << endl; + return 0; +} +int GCD(int x, int y) { + int r = x % y; + while (r != 0) { + x = y; + y = r; + r = x % y; + } + return y; +} +int main() { + int m, u; + cin >> m; + int x(0), y(m - 2); + for (int i = 2; i < m; i++) { + int n(m), z(0); + while (n != 0) { + z += n % i; + n /= i; + } + x += z; + } + u = GCD(x, y); + x /= u; + y /= u; + cout << x << "/" << y << endl; + return 0; +} +int GCD(int x, int y) { + int r = x % y; + while (r != 0) { + x = y; + y = r; + r = x % y; + } + return y; +} +int main() { + int m, u; + cin >> m; + int x(0), y(m - 2); + for (int i = 2; i < m; i++) { + int n(m), z(0); + while (n != 0) { + z += n % i; + n /= i; + } + x += z; + } + u = GCD(x, y); + x /= u; + y /= u; + cout << x << "/" << y << endl; + return 0; +} +int main() { + int n; + string a[105], b[105]; + cin >> n; + int i, j, ans = n; + for (i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + for (j = 0; j < i; j++) { + if (a[i] == a[j] && b[i] == b[j]) { + ans--; + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + string a[105], b[105]; + cin >> n; + int i, j, ans = n; + for (i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + for (j = 0; j < i; j++) { + if (a[i] == a[j] && b[i] == b[j]) { + ans--; + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int prev; + int count = 0; + for (int i = 0; i < n; ++i) { + int b; + cin >> b; + if (i > 0) { + if (b < prev) { + int mult = (prev - b) / d + (((prev - b) % d) ? 1 : 0); + if (b + d * mult == prev) mult++; + count += mult; + prev = b + mult * d; + } else if (b == prev) { + count++; + prev += d; + } else { + prev = b; + } + } else { + prev = b; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int prev; + int count = 0; + for (int i = 0; i < n; ++i) { + int b; + cin >> b; + if (i > 0) { + if (b < prev) { + int mult = (prev - b) / d + (((prev - b) % d) ? 1 : 0); + if (b + d * mult == prev) mult++; + count += mult; + prev = b + mult * d; + } else if (b == prev) { + count++; + prev += d; + } else { + prev = b; + } + } else { + prev = b; + } + } + cout << count << endl; + return 0; +} +bool vis[200]; +int a[101][101], c[101][101]; +int main() { + int n, x1, x2, i, j, x, y, w, ans1, ans2, cur; + cin >> n; + bool bo; + memset(a, 0, sizeof(a)); + memset(c, 0, sizeof(c)); + for (i = 0; i < n; i++) { + cin >> x >> y >> w; + a[x][y] = 1; + a[y][x] = -1; + c[x][y] = c[y][x] = w; + } + ans1 = 0; + ans2 = 0; + cur = 1; + vis[1] = true; + while (true) { + bo = true; + for (i = 1; i <= n; i++) + if (vis[i] == false) bo = false; + if (bo) break; + for (i = 1; i <= n; i++) + if (a[cur][i] != 0 && vis[i] == false) { + if (a[cur][i] < 0) ans1 += c[cur][i]; + cur = i; + vis[cur] = true; + break; + } + } + if (a[cur][1] < 0) ans1 += c[cur][1]; + cur = 1; + memset(vis, false, sizeof(vis)); + while (true) { + bo = true; + for (i = 1; i <= n; i++) + if (vis[i] == false) bo = false; + if (bo) break; + for (i = n; i >= 1; i--) { + if ((a[cur][i] != 0) && (vis[i] == false)) { + if (a[cur][i] < 0) ans2 += c[cur][i]; + cur = i; + vis[cur] = true; + break; + } + } + } + if (a[cur][2] < 0) ans2 += c[cur][1]; + cout << min(ans1, ans2) << endl; +} +int main() { + int n, m; + cin >> n >> m; + if (n % 2 && m % 2) + cout << (n / 2) * m + m / 2 << "\n"; + else if (n % 2) + cout << (m / 2) * n << "\n"; + else if (m % 2) + cout << (n / 2) * m << "\n"; + else + cout << (n / 2) * m << "\n"; +} +int main() { + int n, m; + cin >> n >> m; + if (n % 2 && m % 2) + cout << (n / 2) * m + m / 2 << "\n"; + else if (n % 2) + cout << (m / 2) * n << "\n"; + else if (m % 2) + cout << (n / 2) * m << "\n"; + else + cout << (n / 2) * m << "\n"; +} +int sum; +int gcd(int a, int b) { + if (a % b == 0) return b; + return gcd(b, a % b); +} +void add(int n, int x) { + while (n != 0) { + sum += n % x; + n /= x; + } +} +int main() { + int n; + cin >> n; + for (int i = 2; i < n; i++) add(n, i); + int div = gcd(sum, n - 2); + cout << sum / div << '/' << (n - 2) / div << endl; + return 0; +} +int sum; +int gcd(int a, int b) { + if (a % b == 0) return b; + return gcd(b, a % b); +} +void add(int n, int x) { + while (n != 0) { + sum += n % x; + n /= x; + } +} +int main() { + int n; + cin >> n; + for (int i = 2; i < n; i++) add(n, i); + int div = gcd(sum, n - 2); + cout << sum / div << '/' << (n - 2) / div << endl; + return 0; +} +int n; +string s[105]; +int ans; +int main() { + cin >> n; + ans = n; + for (int i = 0; i <= n; i++) { + getline(cin, s[i]); + for (int j = 0; j < i; j++) + if (s[j] == s[i]) { + ans--; + break; + } + } + cout << ans << endl; + return 0; +} +map m; +map::iterator it; +int main() { + char s[20]; + int n; + m[0] = "January"; + m[1] = "February"; + m[2] = "March"; + m[3] = "April"; + m[4] = "May"; + m[5] = "June"; + m[6] = "July"; + m[7] = "August"; + m[8] = "September"; + m[9] = "October"; + m[10] = "November"; + m[11] = "December"; + while (cin >> s >> n) { + int j = 0; + for (it = m.begin(); it != m.end(); it++) { + ++j; + if (it->second == s) break; + } + cout << m[(j + n - 1) % 12] << endl; + } + return 0; +} +map m; +map::iterator it; +int main() { + char s[20]; + int n; + m[0] = "January"; + m[1] = "February"; + m[2] = "March"; + m[3] = "April"; + m[4] = "May"; + m[5] = "June"; + m[6] = "July"; + m[7] = "August"; + m[8] = "September"; + m[9] = "October"; + m[10] = "November"; + m[11] = "December"; + while (cin >> s >> n) { + int j = 0; + for (it = m.begin(); it != m.end(); it++) { + ++j; + if (it->second == s) break; + } + cout << m[(j + n - 1) % 12] << endl; + } + return 0; +} +const int maxn = 100; +int G[maxn][maxn]; +int G1[maxn][maxn]; +int vis[maxn]; +int num; +int N; +int lsum, ssum; +void dfs(int cur, int n) { + for (int i = 1; i <= num; i++) { + if (!vis[i] && G1[cur][i] != 0) { + vis[i] = 1; + if (G[cur][i] != 0) { lsum += G[cur][i]; } + dfs(i, n + 1); + } + } + if (n == N) { + if (G[cur][1]) { lsum += G[cur][1]; } + } +} +int main() { + while (cin >> N) { + memset(vis, 0, sizeof(vis)); + memset(G, 0, sizeof(G)); + memset(G1, 0, sizeof(G1)); + int x, y, v; + num = 0; + lsum = 0; + ssum = 0; + for (int i = 0; i < N; i++) { + cin >> x >> y >> v; + G[x][y] = v; + G1[x][y] = v; + G1[y][x] = v; + ssum += v; + num = max(num, max(x, y)); + } + vis[1] = 1; + dfs(1, 1); + cout << min(lsum, ssum - lsum) << endl; + } +} +long long fp(long long n, long long p) { + if (p == 0) return 1; + if (p == 1) return n; + long long res = fp(n, p / 2) % int(1e9 + 7); + res = ((res % int(1e9 + 7)) * (res % int(1e9 + 7))) % int(1e9 + 7); + if (p % 2) res = (res * n) % int(1e9 + 7); + return res % int(1e9 + 7); +} +long long n, m, arr[100005], a, ans = 0; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (i) { + if (arr[i] <= arr[i - 1]) { + a = (arr[i - 1] - arr[i]) / m; + ans += a; + arr[i] += a * m; + if (arr[i] <= arr[i - 1]) arr[i] += m, ans++; + } + } + } + cout << ans << '\n'; + return 0; +} +long long fp(long long n, long long p) { + if (p == 0) return 1; + if (p == 1) return n; + long long res = fp(n, p / 2) % int(1e9 + 7); + res = ((res % int(1e9 + 7)) * (res % int(1e9 + 7))) % int(1e9 + 7); + if (p % 2) res = (res * n) % int(1e9 + 7); + return res % int(1e9 + 7); +} +long long n, m, arr[100005], a, ans = 0; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (i) { + if (arr[i] <= arr[i - 1]) { + a = (arr[i - 1] - arr[i]) / m; + ans += a; + arr[i] += a * m; + if (arr[i] <= arr[i - 1]) arr[i] += m, ans++; + } + } + } + cout << ans << '\n'; + return 0; +} +int main() { + int i, j, k, l, m, n, o, p, a, b; + cin >> a; + cin >> b; + cout << (a * b) / 2 << endl; +} +int main() { + int i, j, k, l, m, n, o, p, a, b; + cin >> a; + cin >> b; + cout << (a * b) / 2 << endl; +} +int base(int n, int b) { + int res = 0; + while (n != 0) { + res += (n % b); + n /= b; + } + return res; +} +int main() { + int n, a = 0, b, c; + cin >> n; + for (int i = 2; i <= n - 1; i++) { a += base(n, i); } + b = n - 2; + c = __gcd(a, b); + cout << a / c << '/' << b / c << "\n"; + return 0; +} +map m; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + m[str] = 1; + } + int cnt = 0; + for (map::iterator it = m.begin(); it != m.end(); ++it) { cnt++; } + cout << cnt << endl; + return 0; +} +map m; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + m[str] = 1; + } + int cnt = 0; + for (map::iterator it = m.begin(); it != m.end(); ++it) { cnt++; } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n], c[n], total = 0, ans = 0; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i] >> c[i]; + total += c[i]; + } + bool v[n + 1] = {0}; + int i = 0, m = 0, second; + while (!v[i]) { + int k = 0; + v[i] = 1; + if (m == 0) + second = b[i]; + else + second = a[i]; + for (int j = 0; j < n; j++) { + if (a[j] == second && !v[j]) { + i = j; + k = 1; + m = 0; + break; + } + } + if (k == 1) continue; + for (int j = 0; j < n; j++) { + if (b[j] == second && !v[j]) { + i = j; + ans += c[j]; + k = m = 1; + break; + } + } + if (k == 1) continue; + cout << min(ans, total - ans) << endl; + } + return 0; +} +int main() { + string a; + int s; + cin >> a >> s; + int d; + if (a == "January") + d = 1; + else if (a == "February") + d = 2; + else if (a == "March") + d = 3; + else if (a == "April") + d = 4; + else if (a == "May") + d = 5; + else if (a == "June") + d = 6; + else if (a == "July") + d = 7; + else if (a == "August") + d = 8; + else if (a == "September") + d = 9; + else if (a == "October") + d = 10; + else if (a == "November") + d = 11; + else + d = 12; + d--; + d = d + s; + d = d % 12; + if (d == 0) + a = "January"; + else if (d == 1) + a = "February"; + else if (d == 2) + a = "March"; + else if (d == 3) + a = "April"; + else if (d == 4) + a = "May"; + else if (d == 5) + a = "June"; + else if (d == 6) + a = "July"; + else if (d == 7) + a = "August"; + else if (d == 8) + a = "September"; + else if (d == 9) + a = "October"; + else if (d == 10) + a = "November"; + else + a = "December"; + cout << a << endl; +} +int main() { + int n, d, a; + cin >> n >> d; + vector v; + for (int i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + } + int c = 0; + for (int i = 0; i <= n - 2; i++) { + if (v[i] < v[i + 1]) + continue; + else if (v[i] == v[i + 1]) { + v[i + 1] += d; + c++; + } else if (v[i] > v[i + 1]) { + int x = (v[i] - v[i + 1]) / d + 1; + c += x; + v[i + 1] += d * x; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, d, a; + cin >> n >> d; + vector v; + for (int i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + } + int c = 0; + for (int i = 0; i <= n - 2; i++) { + if (v[i] < v[i + 1]) + continue; + else if (v[i] == v[i + 1]) { + v[i + 1] += d; + c++; + } else if (v[i] > v[i + 1]) { + int x = (v[i] - v[i + 1]) / d + 1; + c += x; + v[i + 1] += d * x; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << ((n * m) / 2) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << ((n * m) / 2) << endl; + return 0; +} +long long n, zs, m; +string c[105], s[105]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s[i] >> c[i]; + for (int j = 1; j < i; j++) + if (s[i] == s[j] && c[i] == c[j]) + break; + else + m++; + if (m == i - 1) zs++; + m = 0; + } + cout << zs << endl; + return 0; +} +int a[105], b[105], c[105]; +long long result = 0; +int n; +void dfs(int start, int self) { + for (int i = 1; i <= n; i++) { + if (self == i) continue; + if (start == a[i]) { + if (b[i] == a[1]) return; + dfs(b[i], i); + } else if (start == b[i]) { + result += c[i]; + if (a[i] == a[1]) return; + dfs(a[i], i); + } + } +} +int main() { + cin >> n; + long long sum = 0; + for (int i = 1; i <= n; i++) { + cin >> a[i] >> b[i] >> c[i]; + sum += c[i]; + } + dfs(b[1], 1); + result = min(result, sum - result); + cout << result << endl; + return 0; +} +int a[105], b[105], c[105]; +long long result = 0; +int n; +void dfs(int start, int self) { + for (int i = 1; i <= n; i++) { + if (self == i) continue; + if (start == a[i]) { + if (b[i] == a[1]) return; + dfs(b[i], i); + } else if (start == b[i]) { + result += c[i]; + if (a[i] == a[1]) return; + dfs(a[i], i); + } + } +} +int main() { + cin >> n; + long long sum = 0; + for (int i = 1; i <= n; i++) { + cin >> a[i] >> b[i] >> c[i]; + sum += c[i]; + } + dfs(b[1], 1); + result = min(result, sum - result); + cout << result << endl; + return 0; +} +int main() { + vector v(120); + for (int i = 0; i < 120; i += 12) { + v[i] = "January"; + v[i + 1] = "February"; + v[i + 2] = "March"; + v[i + 3] = "April"; + v[i + 4] = "May"; + v[i + 5] = "June"; + v[i + 6] = "July"; + v[i + 7] = "August"; + v[i + 8] = "September"; + v[i + 9] = "October"; + v[i + 10] = "November"; + v[i + 11] = "December"; + } + string x; + cin >> x; + int n, z; + cin >> n; + for (int i = 0; i < 120; i++) { + if (v[i] == x) { + z = i; + break; + } + } + cout << v[z + n] << endl; +} +int main() { + int n, d; + cin >> n >> d; + int prev; + int count = 0; + for (int i = 0; i < n; ++i) { + int b; + cin >> b; + if (i > 0) { + if (b <= prev) { + int mult = (prev - b) / d + (((prev - b) % d) ? 1 : 0); + if (b + d * mult == prev) mult++; + count += mult; + prev = b + mult * d; + } else { + prev = b; + } + } else { + prev = b; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int prev; + int count = 0; + for (int i = 0; i < n; ++i) { + int b; + cin >> b; + if (i > 0) { + if (b <= prev) { + int mult = (prev - b) / d + (((prev - b) % d) ? 1 : 0); + if (b + d * mult == prev) mult++; + count += mult; + prev = b + mult * d; + } else { + prev = b; + } + } else { + prev = b; + } + } + cout << count << endl; + return 0; +} +int main() { + int i, n, k, rem, sum = 0, l; + cin >> n; + for (i = 2; i < n; i++) { + k = n; + while (k > 0) { + rem = k % i; + sum += rem; + k /= i; + } + } + l = __gcd(sum, n - 2); + cout << sum / l << "/" << (n - 2) / l << endl; +} +int main() { + int i, n, k, rem, sum = 0, l; + cin >> n; + for (i = 2; i < n; i++) { + k = n; + while (k > 0) { + rem = k % i; + sum += rem; + k /= i; + } + } + l = __gcd(sum, n - 2); + cout << sum / l << "/" << (n - 2) / l << endl; +} +int main() { + set s; + int n; + string m; + cin >> n; + getchar(); + for (int i = 1; i <= n; i++) { + getline(cin, m); + s.insert(m); + } + cout << s.size() << endl; + return 0; +} +int main() { + set s; + int n; + string m; + cin >> n; + getchar(); + for (int i = 1; i <= n; i++) { + getline(cin, m); + s.insert(m); + } + cout << s.size() << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << (a * b) / 2 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << (a * b) / 2 << endl; + return 0; +} +int n, a, b, c, sum = 0, gtw = 0; +int edge[100][100]; +bool ada_edge() { + bool ro = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { ro = ro or (edge[i][j] != 0); } + } + return ro; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + sum = sum + c; + a--; + b--; + edge[a][b] = c; + } + a = 0; + while (ada_edge()) { + int ada_out_edge = 0; + for (int i = 0; i < n; i++) { ada_out_edge = ada_out_edge or (edge[a][i] != 0); } + if (ada_out_edge) { + for (int i = 0; i < n; i++) { + if (edge[a][i] != 0) { + edge[a][i] = 0; + a = i; + break; + } + } + } else { + for (int i = 0; i < n; i++) { + if (edge[i][a] != 0) { + gtw = gtw + edge[i][a]; + edge[i][a] = 0; + a = i; + break; + } + } + } + } + cout << min(gtw, sum - gtw) << '\n'; + return 0; +} +int main() { + long long n, d, b, o; + long long ans = 0; + long long pre = 0; + cin >> n >> d; + for (long long i = 0; i < n; i++) { + cin >> b; + if (b <= pre) { + o = (b % d <= pre % d) + (pre / d) - (b / d); + ans += o; + b += o * d; + } + pre = b; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, d, b, o; + long long ans = 0; + long long pre = 0; + cin >> n >> d; + for (long long i = 0; i < n; i++) { + cin >> b; + if (b <= pre) { + o = (b % d <= pre % d) + (pre / d) - (b / d); + ans += o; + b += o * d; + } + pre = b; + } + cout << ans << endl; + return 0; +} +int gcd(int a, int b) { + if (b == 0) { return a; } + return gcd(b, a % b); +} +int A; +int main() { + cin >> A; + long long s = 0; + for (int i = 2; i < A; i++) { + int x = A; + while (x != 0) { + s += x % i; + x /= i; + } + } + int g = gcd(A - 2, s); + cout << s / g << '/' << (A - 2) / g << endl; + return 0; +} +int gcd(int a, int b) { + if (b == 0) { return a; } + return gcd(b, a % b); +} +int A; +int main() { + cin >> A; + long long s = 0; + for (int i = 2; i < A; i++) { + int x = A; + while (x != 0) { + s += x % i; + x /= i; + } + } + int g = gcd(A - 2, s); + cout << s / g << '/' << (A - 2) / g << endl; + return 0; +} +map asd; +map dsa; +map dataa[105]; +int main() { + int z; + cin >> z; + string a, s; + int d = 1, f = 1; + int itung = 0; + while (z--) { + cin >> a >> s; + if (asd[a] == 0) { + asd[a] = d; + d++; + } + if (dsa[s] == 0) { + dsa[s] = f; + f++; + } + if (dataa[asd[a]][dsa[s]] == 0) { + dataa[asd[a]][dsa[s]]++; + itung++; + } + } + cout << itung << endl; +} +map asd; +map dsa; +map dataa[105]; +int main() { + int z; + cin >> z; + string a, s; + int d = 1, f = 1; + int itung = 0; + while (z--) { + cin >> a >> s; + if (asd[a] == 0) { + asd[a] = d; + d++; + } + if (dsa[s] == 0) { + dsa[s] = f; + f++; + } + if (dataa[asd[a]][dsa[s]] == 0) { + dataa[asd[a]][dsa[s]]++; + itung++; + } + } + cout << itung << endl; +} +char catur[8][8]; +bool vis[8][8]; +bool sb = 1; +int cnt = 0; +int main() { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + cin >> catur[i][j]; + sb = sb & (catur[i][j] == 'B'); + } + } + for (int j = 0; j < 8; j++) { + int lol = 0; + for (int i = 0; i < 8 && catur[i][j] == 'B'; i++) { lol++; } + if (lol == 8) { + for (int i = 0; i < 8 && catur[i][j] == 'B'; i++) { vis[i][j] = 1; } + cnt++; + } + } + for (int i = 0; i < 8; i++) { + int lol = 0; + for (int j = 0; j < 8 && catur[i][j] == 'B'; j++) { lol++; } + if (lol == 8) { + for (int j = 0; j < 8 && catur[i][j] == 'B'; j++) { vis[i][j] = 1; } + cnt++; + } + } + if (sb) { cnt = cnt / 2; } + cout << cnt << '\n'; + return 0; +} +int graph[105][105]; +int vis[105]; +int m[105][105]; +int t; +int k; +int n; +void dfs(int u) { + k++; + vis[u] = 1; + if (k == n) { t += m[1][u]; } + for (int i = 0; i < 105; i++) { + if (graph[u][i] == 1 && vis[i] == 0) { + t += m[i][u]; + if (k == n) { return; } + dfs(i); + } + } +} +int main() { + while (cin >> n) { + t = 0; + k = 0; + int sum = 0; + memset(graph, 0, sizeof(graph)); + memset(vis, 0, sizeof(vis)); + memset(m, 0, sizeof(m)); + for (int i = 0; i < n; i++) { + int x, y, z; + cin >> x >> y >> z; + graph[x][y] = graph[y][x] = 1; + m[y][x] = z; + sum += z; + } + dfs(1); + if (sum - t < t) { t = sum - t; } + cout << t << endl; + } +} +int graph[105][105]; +int vis[105]; +int m[105][105]; +int t; +int k; +int n; +void dfs(int u) { + k++; + vis[u] = 1; + if (k == n) { t += m[1][u]; } + for (int i = 0; i < 105; i++) { + if (graph[u][i] == 1 && vis[i] == 0) { + t += m[i][u]; + if (k == n) { return; } + dfs(i); + } + } +} +int main() { + while (cin >> n) { + t = 0; + k = 0; + int sum = 0; + memset(graph, 0, sizeof(graph)); + memset(vis, 0, sizeof(vis)); + memset(m, 0, sizeof(m)); + for (int i = 0; i < n; i++) { + int x, y, z; + cin >> x >> y >> z; + graph[x][y] = graph[y][x] = 1; + m[y][x] = z; + sum += z; + } + dfs(1); + if (sum - t < t) { t = sum - t; } + cout << t << endl; + } +} +int main() { + int a, b; + cin >> a >> b; + cout << (a * b / 2) << endl; +} +int main() { + int a, b; + cin >> a >> b; + cout << (a * b / 2) << endl; +} +int num[3005]; +map ma; +int ans = 0; +bool is_prime(int u); +int main() { + string s; + s = "January"; + ma[s] = 1; + s = "February"; + ma[s] = 2; + s = "March"; + ma[s] = 3; + s = "April"; + ma[s] = 4; + s = "May"; + ma[s] = 5; + ma["June"] = 6; + ma["July"] = 7; + ma["August"] = 8; + ma["September"] = 9; + ma["October"] = 10; + ma["November"] = 11; + ma["December"] = 12; + int n; + cin >> s; + cin >> n; + if (n % 12 == 0) + cout << s << endl; + else { + int a = ma[s]; + n += a; + if (n % 12 == 1) cout << "January" << endl; + if (n % 12 == 2) cout << "February" << endl; + if (n % 12 == 3) cout << "March" << endl; + if (n % 12 == 4) cout << "April" << endl; + if (n % 12 == 5) cout << "May" << endl; + if (n % 12 == 6) cout << "June" << endl; + if (n % 12 == 7) cout << "July" << endl; + if (n % 12 == 8) cout << "August" << endl; + if (n % 12 == 9) cout << "September" << endl; + if (n % 12 == 10) cout << "October" << endl; + if (n % 12 == 11) cout << "November" << endl; + if (n % 12 == 0) cout << "December" << endl; + } +} +int main() { + long long i, j, k; + string s[10]; + for (i = 0; i < 8; i++) { cin >> s[i]; } + int cnt = 0; + for (i = 0; i < 8; i++) { + int f = 0, flag = 0; + if (s[i][0] == 'B') { + for (j = 0; j < 8; j++) { + if (s[i][j] != 'B') { + f = 1; + break; + } + } + if (f == 0) cnt++; + } + if (s[0][i] == 'B') { + for (j = 0; j < 8; j++) { + if (s[j][i] != 'B') { + flag = 1; + break; + } + } + if (flag == 0) cnt++; + } + } + if (cnt == 16) + cout << "8" << endl; + else + cout << cnt << endl; + return 0; +} +int main() { + long long i, j, k; + string s[10]; + for (i = 0; i < 8; i++) { cin >> s[i]; } + int cnt = 0; + for (i = 0; i < 8; i++) { + int f = 0, flag = 0; + if (s[i][0] == 'B') { + for (j = 0; j < 8; j++) { + if (s[i][j] != 'B') { + f = 1; + break; + } + } + if (f == 0) cnt++; + } + if (s[0][i] == 'B') { + for (j = 0; j < 8; j++) { + if (s[j][i] != 'B') { + flag = 1; + break; + } + } + if (flag == 0) cnt++; + } + } + if (cnt == 16) + cout << "8" << endl; + else + cout << cnt << endl; + return 0; +} +map m; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + m.insert(make_pair(str, 1)); + } + int cnt = m.size(); + cout << cnt << endl; + return 0; +} +int main() { + int m, n, o, i, j; + cin >> m >> n; + if (m <= n) { + o = m * n; + i = 2 * 1; + j = o / i; + } + cout << j << endl; + return 0; +} +int main() { + int m, n, o, i, j; + cin >> m >> n; + if (m <= n) { + o = m * n; + i = 2 * 1; + j = o / i; + } + cout << j << endl; + return 0; +} +vector v[101]; +bool vis[101]; +int cost = 0; +int GRAPH[101][101]; +void DFS(int x) { + vis[x] = true; + for (int i = 0; i < v[x].size(); i++) { + if (!vis[v[x][i]]) { + if (GRAPH[v[x][i]][x] != -1) cost += GRAPH[v[x][i]][x]; + DFS(v[x][i]); + } + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) GRAPH[i][j] = -1; + } + for (int i = 1; i <= n; i++) vis[i] = false; + for (int i = 0; i < n; i++) { + long long x, y, z; + cin >> x >> y >> z; + GRAPH[x][y] = z; + v[x].push_back(y); + v[y].push_back(x); + } + vis[1] = true; + DFS(v[1][0]); + int cost1 = cost; + if (GRAPH[1][v[1][0]] == -1) { cost1 += GRAPH[v[1][0]][1]; } + if (GRAPH[v[1][1]][1] == -1) cost1 += GRAPH[1][v[1][1]]; + cost = 0; + for (int i = 1; i <= n; i++) vis[i] = false; + vis[1] = true; + DFS(v[1][1]); + int cost2 = cost; + if (GRAPH[1][v[1][1]] == -1) { cost2 += GRAPH[v[1][1]][1]; } + if (GRAPH[v[1][0]][1] == -1) cost2 += GRAPH[1][v[1][0]]; + cout << min(cost1, cost2) << endl; + return 0; +} +vector v[101]; +bool vis[101]; +int cost = 0; +int GRAPH[101][101]; +void DFS(int x) { + vis[x] = true; + for (int i = 0; i < v[x].size(); i++) { + if (!vis[v[x][i]]) { + if (GRAPH[v[x][i]][x] != -1) cost += GRAPH[v[x][i]][x]; + DFS(v[x][i]); + } + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) GRAPH[i][j] = -1; + } + for (int i = 1; i <= n; i++) vis[i] = false; + for (int i = 0; i < n; i++) { + long long x, y, z; + cin >> x >> y >> z; + GRAPH[x][y] = z; + v[x].push_back(y); + v[y].push_back(x); + } + vis[1] = true; + DFS(v[1][0]); + int cost1 = cost; + if (GRAPH[1][v[1][0]] == -1) { cost1 += GRAPH[v[1][0]][1]; } + if (GRAPH[v[1][1]][1] == -1) cost1 += GRAPH[1][v[1][1]]; + cost = 0; + for (int i = 1; i <= n; i++) vis[i] = false; + vis[1] = true; + DFS(v[1][1]); + int cost2 = cost; + if (GRAPH[1][v[1][1]] == -1) { cost2 += GRAPH[v[1][1]][1]; } + if (GRAPH[v[1][0]][1] == -1) cost2 += GRAPH[1][v[1][0]]; + cout << min(cost1, cost2) << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (!b) return a; + return gcd(b, a % b); +} +int main() { + int i, j, k, l; + int n, m, s = 0; + cin >> n; + for (i = 2; i < n; i++) { + k = i; + m = n; + while (m / k != 0) { + s += m % k; + m /= k; + } + s += m % k; + } + k = gcd(s, n - 2); + cout << s / k << "/" << (n - 2) / k << endl; +} +const int INF = 0x3f3f3f3f; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (!b) return a; + return gcd(b, a % b); +} +int main() { + int i, j, k, l; + int n, m, s = 0; + cin >> n; + for (i = 2; i < n; i++) { + k = i; + m = n; + while (m / k != 0) { + s += m % k; + m /= k; + } + s += m % k; + } + k = gcd(s, n - 2); + cout << s / k << "/" << (n - 2) / k << endl; +} +inline long long nxt() { + long long _x = 0, _tmp = 1; + char _tc = getchar(); + while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); + if (_tc == '-') _tc = getchar(), _tmp = -1; + while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar(); + return _x * _tmp; +} +int main() { + string s[170]; + for (int i = 1; i <= 160; ++i) { + if (i % 12 == 1) s[i] = "January"; + if (i % 12 == 2) s[i] = "February"; + if (i % 12 == 3) s[i] = "March"; + if (i % 12 == 4) s[i] = "April"; + if (i % 12 == 5) s[i] = "May"; + if (i % 12 == 6) s[i] = "June"; + if (i % 12 == 7) s[i] = "July"; + if (i % 12 == 8) s[i] = "August"; + if (i % 12 == 9) s[i] = "September"; + if (i % 12 == 10) s[i] = "October"; + if (i % 12 == 11) s[i] = "November"; + if (i % 12 == 0) s[i] = "December"; + } + string str; + int n; + cin >> str >> n; + for (int i = 1; i <= 12; ++i) { + if (s[i] == str) { cout << s[i + n] << endl; } + } +} +const int MAX = 105; +int g[MAX], v[MAX]; +int main() { + int n, res = 0, ans = 0; + cin >> n; + int f, t, c; + for (int i = 0; i < n; ++i) { + cin >> f >> t >> c; + if (v[f] || g[t]) { + res += c; + g[f] = v[t] = 1; + } else + v[f] = g[t] = 1; + ans += c; + } + cout << min(res, ans - res) << endl; +} +const int MAX = 105; +int g[MAX], v[MAX]; +int main() { + int n, res = 0, ans = 0; + cin >> n; + int f, t, c; + for (int i = 0; i < n; ++i) { + cin >> f >> t >> c; + if (v[f] || g[t]) { + res += c; + g[f] = v[t] = 1; + } else + v[f] = g[t] = 1; + ans += c; + } + cout << min(res, ans - res) << endl; +} +int main() { + char arr[8][8]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) { cin >> arr[i][j]; } + int a = 0; + int b = 0; + for (int i = 0; i < 8; i++) { + int count = 0; + for (int j = 0; j < 8; j++) { + if (arr[i][j] == 'B') count++; + } + if (count == 8) + a++; + else + b = count; + } + a = a + b; + cout << a << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int A; + cin >> A; + int res = 0; + for (int b = 2; b < A; b++) { + int t = A; + while (t) { + res += t % b; + t /= b; + } + } + int d = gcd(res, A - 2); + cout << res / d << "/" << (A - 2) / d << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int A; + cin >> A; + int res = 0; + for (int b = 2; b < A; b++) { + int t = A; + while (t) { + res += t % b; + t /= b; + } + } + int d = gcd(res, A - 2); + cout << res / d << "/" << (A - 2) / d << endl; + return 0; +} +int main() { + int n; + set leaves; + cin >> n; + while (n--) { + string l1, l2; + cin >> l1 >> l2; + leaves.insert(l1 + " " + l2); + } + cout << leaves.size() << endl; +} +int main() { + int n; + set leaves; + cin >> n; + while (n--) { + string l1, l2; + cin >> l1 >> l2; + leaves.insert(l1 + " " + l2); + } + cout << leaves.size() << endl; +} +int main() { + string s[8]; + for (int i = 0; i < 8; i++) cin >> s[i]; + int cnt = 0; + for (int o = 0; o < 8; o++) { + bool good = 1; + for (int i = 0; i < 8; i++) { + if (s[o][i] == 'W') { + good = 0; + break; + } + } + cnt += good; + } + for (int o = 0; o < 8; o++) { + bool good = 1; + for (int i = 0; i < 8; i++) { + if (s[i][o] == 'W') { + good = 0; + break; + } + } + cnt += good; + } + if (cnt == 16) cnt = 8; + cout << cnt << endl; + return 0; +} +int main() { + int x; + string name; + set leafName; + cin >> x; + for (int i = 0; i <= x; i++) { + getline(cin, name); + leafName.insert(name); + } + cout << leafName.size() - 1 << endl; +} +int main() { + string s; + getline(cin, s); + char x; + int len = s.size() - 1; + int flag = 1; + while (flag) { + char temp = s[len]; + if (temp >= 'A' && temp <= 'Z') { + x = temp; + flag = 0; + } else if (temp >= 'a' && temp <= 'z') { + x = temp; + flag = 0; + } + len--; + } + x = tolower(x); + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y') + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + char x; + int len = s.size() - 1; + int flag = 1; + while (flag) { + char temp = s[len]; + if (temp >= 'A' && temp <= 'Z') { + x = temp; + flag = 0; + } else if (temp >= 'a' && temp <= 'z') { + x = temp; + flag = 0; + } + len--; + } + x = tolower(x); + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y') + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + vector board(9); + for (int i = 0; i < 8; ++i) { cin >> board[i]; } + int row = 0; + for (int i = 0; i < 8; ++i) { + if (board[i] == "BBBBBBBB") ++row; + } + int col = 0; + for (int j = 0; j < 8; ++j) { + bool paint = true; + for (int i = 0; i < 8; ++i) { + if (board[i][j] == 'W') { + paint = false; + break; + } + } + if (paint) ++col; + } + if (row == 8 && col == 8) { + cout << 8; + } else { + cout << row + col; + } + cout << '\n'; + return 0; +} +int main() { + vector board(9); + for (int i = 0; i < 8; ++i) { cin >> board[i]; } + int row = 0; + for (int i = 0; i < 8; ++i) { + if (board[i] == "BBBBBBBB") ++row; + } + int col = 0; + for (int j = 0; j < 8; ++j) { + bool paint = true; + for (int i = 0; i < 8; ++i) { + if (board[i][j] == 'W') { + paint = false; + break; + } + } + if (paint) ++col; + } + if (row == 8 && col == 8) { + cout << 8; + } else { + cout << row + col; + } + cout << '\n'; + return 0; +} +const int maxn = 105; +int n; +int u[maxn], v[maxn], c[maxn]; +int ans = 0; +void dfs(int s, int index) { + for (int i = 1; i <= n; i++) { + if (index == i) continue; + if (s == u[i]) { + if (v[i] == u[1]) return; + dfs(v[i], i); + } else if (s == v[i]) { + ans += c[i]; + if (u[i] == u[1]) return; + dfs(u[i], i); + } + } +} +int main() { + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { + cin >> u[i] >> v[i] >> c[i]; + sum += c[i]; + } + dfs(v[1], 1); + cout << min(ans, sum - ans) << endl; +} +const int maxn = 105; +int n; +int u[maxn], v[maxn], c[maxn]; +int ans = 0; +void dfs(int s, int index) { + for (int i = 1; i <= n; i++) { + if (index == i) continue; + if (s == u[i]) { + if (v[i] == u[1]) return; + dfs(v[i], i); + } else if (s == v[i]) { + ans += c[i]; + if (u[i] == u[1]) return; + dfs(u[i], i); + } + } +} +int main() { + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { + cin >> u[i] >> v[i] >> c[i]; + sum += c[i]; + } + dfs(v[1], 1); + cout << min(ans, sum - ans) << endl; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + map mp; + cin.ignore(); + while (n--) { + string s; + getline(cin, s); + mp[s]++; + } + cout << mp.size() << '\n'; + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + map mp; + cin.ignore(); + while (n--) { + string s; + getline(cin, s); + mp[s]++; + } + cout << mp.size() << '\n'; + return 0; +} +int mat[9][9]; +int main() { + int n = 8; + string s; + for (int i = 1; i <= 8; i++) { + cin >> s; + for (int j = 0; j < 8; j++) { + if (s[j] == 'B') mat[i][j + 1] = 1; + } + } + int a1 = 0, a2 = 0; + for (int i = 1; i <= 8; i++) { + int f1 = 1, f2 = 1; + for (int j = 1; j <= 8; j++) { + f1 = f1 & mat[j][i]; + f2 = f2 & mat[i][j]; + } + a1 += f1; + a2 += f2; + } + if (a1 == 8 || a2 == 8) + cout << 8 << endl; + else + cout << a1 + a2 << endl; +} +int gcd1(int a, int b) { + if (a == 0) return b; + return gcd1(b % a, a); +} +long long modx(long long base, long long ex) { + long long ans = 1LL, val = base; + while (ex > 0LL) { + if (ex & 1LL) ans = (ans * val) % 1000000007LL; + val = (val * val) % 1000000007LL; + ex = ex >> 1LL; + } + return ans; +} +vector adj[500005]; +bool visit[500005]; +map, int> mp1; +vector cycle; +void dfs(int start) { + visit[start] = true; + cycle.push_back(start); + for (int i = 0; i < adj[start].size(); i++) { + if (!visit[adj[start][i]]) dfs(adj[start][i]); + } +} +int main() { + int n; + cin >> n; + int a, b, c; + for (int i = 1; i <= n; i++) { + cin >> a >> b >> c; + adj[a].push_back(b); + adj[b].push_back(a); + mp1[make_pair(b, a)] = c; + } + dfs(1); + long long ans1 = 0, ans2 = 0; + int sz = cycle.size(); + for (int i = 0; i < sz - 1; i++) { + ans1 += mp1[make_pair(cycle[i], cycle[i + 1])]; + ans2 += mp1[make_pair(cycle[i + 1], cycle[i])]; + } + ans1 += mp1[make_pair(cycle[sz - 1], cycle[0])]; + ans2 += mp1[make_pair(cycle[0], cycle[sz - 1])]; + cout << min(ans1, ans2) << endl; + return 0; +} +char vol[] = {'y', 'Y', 'o', 'O', 'i', 'I', 'a', 'A', 'e', 'E', 'u', 'U'}; +int main() { + string s; + getline(cin, s); + for (int i = s.size() - 1; i > -1; i--) + if (s[i] != '?' && s[i] != ' ') { + for (int j = 0; j < 12; j++) + if (s[i] == vol[j]) return cout << "YES" << '\n', 0; + return cout << "NO" << '\n', 0; + } + return 0; +} +int main() { + int n; + cin >> n; + int p[5], t[3], l[200], r[200]; + cin >> p[0] >> p[1] >> p[2] >> t[0] >> t[1]; + int ans = 0, mid; + cin >> l[0] >> r[0]; + ans += (r[0] - l[0]) * p[0]; + for (int i = 1; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p[0]; + mid = l[i] - r[i - 1]; + if (mid <= t[0]) + ans += mid * p[0]; + else { + ans += t[0] * p[0]; + mid -= t[0]; + if (mid <= t[1]) + ans += mid * p[1]; + else { + ans += t[1] * p[1]; + mid -= t[1]; + ans += mid * p[2]; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int p[5], t[3], l[200], r[200]; + cin >> p[0] >> p[1] >> p[2] >> t[0] >> t[1]; + int ans = 0, mid; + cin >> l[0] >> r[0]; + ans += (r[0] - l[0]) * p[0]; + for (int i = 1; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p[0]; + mid = l[i] - r[i - 1]; + if (mid <= t[0]) + ans += mid * p[0]; + else { + ans += t[0] * p[0]; + mid -= t[0]; + if (mid <= t[1]) + ans += mid * p[1]; + else { + ans += t[1] * p[1]; + mid -= t[1]; + ans += mid * p[2]; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + string ss[10]; + for (int i = 0; i < 8; i++) cin >> ss[i]; + int sum = 0; + int a = 654; + for (int i = 0; i < 8; i++) { + int temp = 0; + for (int j = 0; j < 8; j++) + if (ss[i][j] == 'B') temp++; + a = min(temp, a); + } + sum += a; + a = 654; + for (int i = 0; i < 8; i++) { + int temp = 0; + for (int j = 0; j < 8; j++) + if (ss[j][i] == 'B') temp++; + a = min(temp, a); + } + sum += a; + if (sum == 16) sum /= 2; + cout << sum << endl; + return 0; +} +int main() { + string ss[10]; + for (int i = 0; i < 8; i++) cin >> ss[i]; + int sum = 0; + int a = 654; + for (int i = 0; i < 8; i++) { + int temp = 0; + for (int j = 0; j < 8; j++) + if (ss[i][j] == 'B') temp++; + a = min(temp, a); + } + sum += a; + a = 654; + for (int i = 0; i < 8; i++) { + int temp = 0; + for (int j = 0; j < 8; j++) + if (ss[j][i] == 'B') temp++; + a = min(temp, a); + } + sum += a; + if (sum == 16) sum /= 2; + cout << sum << endl; + return 0; +} +int n; +string a; +set values; +int main() { + cin >> n; + cin.ignore(); + for (int i = 0; i < n; i++) { + getline(cin, a); + values.insert(a); + } + cout << values.size() << endl; + return 0; +} +int n, p1, p2, p3, t1, t2, l, r, ans = 0; +int main() { + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int e1 = p1 * t1, e2 = p2 * t2 + e1; + cin >> l >> r; + n -= 1; + int last = l; + while (n >= 0) { + if (l - last < t1) ans += (l - last) * p1; + if (l - last >= t1 && l - last < t2 + t1) ans += e1 + (l - last - t1) * p2; + ; + if (l - last >= t2 + t1) ans += e2 + ((l - last) - (t1 + t2)) * p3; + ; + ans += (r - l) * p1; + last = r; + n--; + if (n < 0) break; + cin >> l >> r; + } + cout << ans << endl; + return 0; +} +int main() { + char s[500]; + gets(s); + char c; + int len = strlen(s); + for (int i = 0; i < len; i++) { + char cc = tolower(s[i]); + if (cc >= 'a' && cc <= 'z') c = cc; + } + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char s[500]; + gets(s); + char c; + int len = strlen(s); + for (int i = 0; i < len; i++) { + char cc = tolower(s[i]); + if (cc >= 'a' && cc <= 'z') c = cc; + } + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + int vis[105]; + int k[105], t, v; + int a[105], b[105], c[105]; + int x[105], y[105], z[105]; + int s[105][105]; + int s1, s2, s3, sum; + cin >> n; + memset(vis, 0, sizeof(vis)); + memset(k, 0, sizeof(k)); + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); + memset(z, 0, sizeof(z)); + memset(s, 0, sizeof(s)); + sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i] >> c[i]; + vis[a[i]]++; + vis[b[i]]--; + sum += c[i]; + } + t = 0; + for (int i = 1; i <= n; i++) { + if (vis[i] == 0) { + k[t] = i; + t++; + } + } + if (t == n) { + cout << 0 << endl; + } else { + for (int i = 0; i < t; i++) { + for (int j = 0; j < n; j++) { + if (k[i] == a[j]) { + s1 = b[j]; + s3 = c[j]; + } + if (k[i] == b[j]) { s2 = a[j]; } + } + for (int j = 0; j < n; j++) { + if (k[i] == a[j]) { + b[j] = k[i]; + c[j] = 0; + } else if (k[i] == b[j]) { + b[j] = s1; + c[j] = c[j] + s3; + } + } + } + v = 0; + for (int i = 0; i < n; i++) { + if (c[i] != 0) { + x[v] = a[i]; + y[v] = b[i]; + z[v] = c[i]; + v++; + } + } + int gb1 = 0, gb2 = 0; + int f = 0; + int ss = x[0]; + t = 0; + memset(vis, 0, sizeof(vis)); + while (f < v) { + for (int j = 0; j < v; j++) { + if (vis[j] == 0) { + if ((x[j] == ss) || (y[j] == ss)) { + vis[j] = 1; + if (f % 2 == 0) { + ss = y[j]; + gb1 += z[j]; + } else { + ss = x[j]; + gb2 += z[j]; + } + break; + } + } + } + f++; + } + cout << min(gb1, gb2) << endl; + } + return 0; +} +int main() { + char s[20][20]; + for (int i = 0; i < 8; i++) cin >> s[i]; + int ans1 = 10, ans2 = 10; + for (int i = 0; i < 8; i++) { + int l = 0, r = 0; + for (int j = 0; j < 8; j++) { + if (s[i][j] == 'B') l++; + if (s[j][i] == 'B') r++; + } + ans1 = min(l, ans1); + ans2 = min(r, ans2); + } + if (ans1 != 8 && ans2 != 8) + cout << ans1 + ans2 << endl; + else + cout << "8" << endl; + return 0; +} +int n, ans; +string s; +map cek; +int main() { + cin >> n; + getline(cin, s); + while (n--) { + getline(cin, s); + if (!cek[s]) ans++; + cek[s] = true; + } + cout << ans << "\n"; +} +int l[105], r[105]; +int main() { + int n; + cin >> n; + int p1, p2, p3, t1, t2; + cin >> p1 >> p2 >> p3 >> t1 >> t2; + int p = 0; + for (int i = 0; i < n; ++i) { + cin >> l[i] >> r[i]; + p += p1 * (r[i] - l[i]); + if (i != 0) { + int gap = l[i] - r[i - 1]; + if (gap <= t1) { + p += p1 * gap; + } else if (0 < gap - t1 && gap - t1 <= t2) { + p += p1 * t1 + p2 * (gap - t1); + } else if (gap > t1 + t2) { + p += p1 * t1 + p2 * t2 + p3 * (gap - t1 - t2); + } + } + } + cout << p << endl; + return 0; +} +int l[105], r[105]; +int main() { + int n; + cin >> n; + int p1, p2, p3, t1, t2; + cin >> p1 >> p2 >> p3 >> t1 >> t2; + int p = 0; + for (int i = 0; i < n; ++i) { + cin >> l[i] >> r[i]; + p += p1 * (r[i] - l[i]); + if (i != 0) { + int gap = l[i] - r[i - 1]; + if (gap <= t1) { + p += p1 * gap; + } else if (0 < gap - t1 && gap - t1 <= t2) { + p += p1 * t1 + p2 * (gap - t1); + } else if (gap > t1 + t2) { + p += p1 * t1 + p2 * t2 + p3 * (gap - t1 - t2); + } + } + } + cout << p << endl; + return 0; +} +int main() { + int sum = 0, cost = 0; + int n; + cin >> n; + int out[n + 1] = {0}; + int in[n + 1] = {0}; + for (int i = 0; i < n; i++) { + int a, b, c; + cin >> a >> b >> c; + if (out[a] || in[b]) { + sum += c; + out[b] = 1; + in[a] = 1; + } else { + out[a] = 1; + in[b] = 1; + } + cost += c; + } + cout << min(cost - sum, sum) << endl; + return 0; +} +int main() { + int sum = 0, cost = 0; + int n; + cin >> n; + int out[n + 1] = {0}; + int in[n + 1] = {0}; + for (int i = 0; i < n; i++) { + int a, b, c; + cin >> a >> b >> c; + if (out[a] || in[b]) { + sum += c; + out[b] = 1; + in[a] = 1; + } else { + out[a] = 1; + in[b] = 1; + } + cost += c; + } + cout << min(cost - sum, sum) << endl; + return 0; +} +string vow = "aeiouy"; +int main() { + string x; + getline(cin, x); + bool ok = false; + for (int i = 0; i < x.length(); ++i) { + if (isalpha(x[i])) { + if (vow.find(tolower(x[i])) != -1) + ok = true; + else + ok = false; + } + } + cout << ((ok) ? "YES" : "NO") << endl; +} +string vow = "aeiouy"; +int main() { + string x; + getline(cin, x); + bool ok = false; + for (int i = 0; i < x.length(); ++i) { + if (isalpha(x[i])) { + if (vow.find(tolower(x[i])) != -1) + ok = true; + else + ok = false; + } + } + cout << ((ok) ? "YES" : "NO") << endl; +} +int main() { + string board[8]; + for (int i = 0; i < 8; ++i) { cin >> board[i]; } + int B = 0; + for (int i = 0; i < 8; ++i) { + bool flag = true; + for (int j = 0; j < 8; ++j) { flag &= (board[i][j] == 'B'); } + if (flag) { ++B; } + flag = true; + for (int j = 0; j < 8; ++j) { flag &= (board[j][i] == 'B'); } + if (flag) { ++B; } + } + if (B == 16) { B = 8; } + cout << B << endl; + return 0; +} +int main() { + string board[8]; + for (int i = 0; i < 8; ++i) { cin >> board[i]; } + int B = 0; + for (int i = 0; i < 8; ++i) { + bool flag = true; + for (int j = 0; j < 8; ++j) { flag &= (board[i][j] == 'B'); } + if (flag) { ++B; } + flag = true; + for (int j = 0; j < 8; ++j) { flag &= (board[j][i] == 'B'); } + if (flag) { ++B; } + } + if (B == 16) { B = 8; } + cout << B << endl; + return 0; +} +int main() { + int n, P1, P2, P3, T1, T2; + cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; + int l, r, rprev = 0, tdiff = 0; + int tp1 = 0, tp2 = 0, tp3 = 0; + for (int i = 0; i < n; i++) { + cin >> l >> r; + tp1 += r - l; + if (rprev == 0) { + rprev = r; + continue; + } + tdiff = l - rprev; + if (tdiff > (T1 + T2)) { + tp1 += T1; + tp2 += T2; + tp3 += (tdiff - T1 - T2); + } else if (tdiff > T1) { + tp1 += T1; + tp2 += tdiff - T1; + } else { + tp1 += tdiff; + } + rprev = r; + } + cout << tp1 * P1 + tp2 * P2 + tp3 * P3 << endl; + return 0; +} +int main() { + int ans = 0; + int num = 100; + char ch[100]; + for (int i = 0; i < 8; i++) { + int sum = 0; + cin >> ch; + for (int j = 0; j < 8; j++) + if (ch[j] == 'B') sum++; + if (sum == 8) ans++; + num = min(num, sum); + } + if (ans == 8) + cout << 8 << endl; + else + cout << ans + num << endl; + return 0; +} +int main() { + int ans = 0; + int num = 100; + char ch[100]; + for (int i = 0; i < 8; i++) { + int sum = 0; + cin >> ch; + for (int j = 0; j < 8; j++) + if (ch[j] == 'B') sum++; + if (sum == 8) ans++; + num = min(num, sum); + } + if (ans == 8) + cout << 8 << endl; + else + cout << ans + num << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int a[n + 1], b[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= n; i++) { + ans += (b[i] - a[i]) * p1; + if (i != n) { + if (a[i + 1] - b[i] <= t1) + ans += p1 * (a[i + 1] - b[i]); + else if (a[i + 1] - b[i] <= t1 + t2) + ans += p1 * t1 + p2 * (a[i + 1] - b[i] - t1); + else + ans += p1 * t1 + p2 * t2 + p3 * (a[i + 1] - b[i] - t1 - t2); + } + } + cout << ans << endl; +} +int main() { + int n, p1, p2, p3, t1, t2, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int a[n + 1], b[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= n; i++) { + ans += (b[i] - a[i]) * p1; + if (i != n) { + if (a[i + 1] - b[i] <= t1) + ans += p1 * (a[i + 1] - b[i]); + else if (a[i + 1] - b[i] <= t1 + t2) + ans += p1 * t1 + p2 * (a[i + 1] - b[i] - t1); + else + ans += p1 * t1 + p2 * t2 + p3 * (a[i + 1] - b[i] - t1 - t2); + } + } + cout << ans << endl; +} +int main() { + string s[10]; + for (int i = 0; i < 8; i++) cin >> s[i]; + int r = 0, c = 0; + for (int i = 0; i < 8; i++) { + int flag = 1; + for (int j = 0; j < 8; j++) { + if (s[i][j] == 'W') { + flag = 0; + break; + } + } + if (flag) r++; + } + for (int i = 0; i < 8; i++) { + int flag = 1; + for (int j = 0; j < 8; j++) { + if (s[j][i] == 'W') { + flag = 0; + break; + } + } + if (flag) c++; + } + if (c == 8 && r == 8) + cout << 8 << endl; + else + cout << r + c << endl; + return 0; +} +int main() { + string s[10]; + for (int i = 0; i < 8; i++) cin >> s[i]; + int r = 0, c = 0; + for (int i = 0; i < 8; i++) { + int flag = 1; + for (int j = 0; j < 8; j++) { + if (s[i][j] == 'W') { + flag = 0; + break; + } + } + if (flag) r++; + } + for (int i = 0; i < 8; i++) { + int flag = 1; + for (int j = 0; j < 8; j++) { + if (s[j][i] == 'W') { + flag = 0; + break; + } + } + if (flag) c++; + } + if (c == 8 && r == 8) + cout << 8 << endl; + else + cout << r + c << endl; + return 0; +} +int main() { + int n, P1, P2, P3, T1, T2; + cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; + int ans = 0, last = 0; + for (int i = 0; i < n; ++i) { + int l, r; + cin >> l >> r; + if (i != 0) { + int d = l - last; + if (d > T1 + T2) + ans += (d - (T1 + T2)) * P3 + T2 * P2 + T1 * P1; + else if (d > T1) + ans += (d - T1) * P2 + T1 * P1; + else + ans += d * P1; + } + ans += (r - l) * P1; + last = r; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, P1, P2, P3, T1, T2; + cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; + int ans = 0, last = 0; + for (int i = 0; i < n; ++i) { + int l, r; + cin >> l >> r; + if (i != 0) { + int d = l - last; + if (d > T1 + T2) + ans += (d - (T1 + T2)) * P3 + T2 * P2 + T1 * P1; + else if (d > T1) + ans += (d - T1) * P2 + T1 * P1; + else + ans += d * P1; + } + ans += (r - l) * P1; + last = r; + } + cout << ans << "\n"; + return 0; +} +const int MAXN = 1e6; +int n, a[MAXN], b[MAXN], c[MAXN]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; + int res1 = 0; + int cur = b[0]; + vector used(n, 0); + used[0] = 1; + for (int t = 0; t + 1 < n; t++) { + for (int i = 0; i < n; i++) + if (used[i] == 0 && (a[i] == cur || b[i] == cur)) { + if (b[i] == cur) res1 += c[i]; + cur = a[i] + b[i] - cur; + used[i] = 1; + break; + } + } + int res2 = c[0]; + cur = a[0]; + used.assign(n, 0); + used[0] = 1; + for (int t = 0; t <= n; t++) { + for (int i = 0; i < n; i++) + if (used[i] == 0 && (a[i] == cur || b[i] == cur)) { + if (b[i] == cur) res2 += c[i]; + cur = a[i] + b[i] - cur; + used[i] = 1; + break; + } + } + cout << min(res1, res2) << "\n"; + return 0; +} +int main() { + int a = 0, b = 100; + for (int i = 0; i <= 7; ++i) { + string s; + cin >> s; + int num = 0; + for (int j = 0; j <= 7; ++j) + if (s[j] == 'B') num++; + if (num == 8) a++; + b = min(b, num); + } + int ans = a + b; + if (a == 8) ans = 8; + cout << ans << endl; + return 0; +} +int main() { + int a = 0, b = 100; + for (int i = 0; i <= 7; ++i) { + string s; + cin >> s; + int num = 0; + for (int j = 0; j <= 7; ++j) + if (s[j] == 'B') num++; + if (num == 8) a++; + b = min(b, num); + } + int ans = a + b; + if (a == 8) ans = 8; + cout << ans << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int r0, l, r, d, sum = 0; + cin >> l >> r; + r0 = r; + sum += (r - l) * p1; + for (int i = 1; i < n; ++i) { + cin >> l >> r; + sum += (r - l) * p1; + d = l - r0; + if (d <= t1) + sum += d * p1; + else if (d <= t1 + t2) + sum += t1 * p1 + (d - t1) * p2; + else + sum += t1 * p1 + t2 * p2 + (d - t1 - t2) * p3; + r0 = r; + } + cout << sum << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int r0, l, r, d, sum = 0; + cin >> l >> r; + r0 = r; + sum += (r - l) * p1; + for (int i = 1; i < n; ++i) { + cin >> l >> r; + sum += (r - l) * p1; + d = l - r0; + if (d <= t1) + sum += d * p1; + else if (d <= t1 + t2) + sum += t1 * p1 + (d - t1) * p2; + else + sum += t1 * p1 + t2 * p2 + (d - t1 - t2) * p3; + r0 = r; + } + cout << sum << endl; + return 0; +} +int N, a, b, c; +int path[105][105]; +bool isVisited[105]; +int totAll, totCc; +int main() { + memset(path, -1, sizeof(path)); + totAll = 0; + totCc = 0; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> a >> b >> c; + path[a][b] = c; + totAll += c; + } + int now = 1; + isVisited[1] = 1; + int cnt = 1; + while (cnt != N + 1) { + if (cnt > 2) isVisited[1] = 0; + for (int i = 1; i <= N; i++) { + if (not(isVisited[i]) and (path[now][i] != -1 or path[i][now] != -1)) { + if (path[i][now] != -1) { totCc += path[i][now]; } + cnt++; + now = i; + isVisited[i] = 1; + break; + } + } + } + cout << min(totCc, totAll - totCc) << endl; +} +int main() { + string s[10]; + int h = 0; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + if (s[i] == "BBBBBBBB") ++h; + } + int l = 0; + for (int i = 0; i < s[0].size(); i++) { + bool flag = true; + for (int j = 0; j < 8; j++) { + if (s[j][i] != 'B') { + flag = false; + break; + } + } + if (flag) ++l; + } + if (h == 8 and l == 8) + cout << 8 << endl; + else + cout << l + h << endl; + return 0; +} +int main() { + string s[10]; + int h = 0; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + if (s[i] == "BBBBBBBB") ++h; + } + int l = 0; + for (int i = 0; i < s[0].size(); i++) { + bool flag = true; + for (int j = 0; j < 8; j++) { + if (s[j][i] != 'B') { + flag = false; + break; + } + } + if (flag) ++l; + } + if (h == 8 and l == 8) + cout << 8 << endl; + else + cout << l + h << endl; + return 0; +} +int main() { + int i, j, s, s1, s2; + char ch[8][8]; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { cin >> ch[i][j]; } + } + s1 = 0, s2 = 0; + for (i = 0; i < 8; i++) { + s = 0; + for (j = 0; j < 8; j++) { + if (ch[i][j] == 'B') s++; + } + if (s == 8) + s1++; + else + s2 = s; + } + cout << s1 + s2 << endl; + return 0; +} +int n, p1, p2, p3, t1, t2, ans = 0, l[105], r[105]; +int main() { + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p1; + if (i > 0) { + if (l[i] - r[i - 1] > t1) { + ans += t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) { + ans += t2 * p2; + ans += (t - t2) * p3; + } else + ans += t * p2; + } else + ans += (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; + return 0; +} +int n, p1, p2, p3, t1, t2, ans = 0, l[105], r[105]; +int main() { + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p1; + if (i > 0) { + if (l[i] - r[i - 1] > t1) { + ans += t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) { + ans += t2 * p2; + ans += (t - t2) * p3; + } else + ans += t * p2; + } else + ans += (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; + return 0; +} +int main() { + int x, y, z = 7, q = 6; + cin >> x >> y; + if (x > y) + z = z - x; + else + z = z - y; + if (z == 6 || z > 0 && z < 4) { + q = q / z; + z = 1; + cout << z << "/" << q << endl; + } else { + if (z == 4) { + q = q / 2; + z = z / 2; + cout << z << "/" << q << endl; + } else + cout << z << "/" << q << endl; + } + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int consume = 0; + int l, r, prer = -1; + for (int i = 0; i < n; i++) { + cin >> l >> r; + consume += (r - l) * p1; + if (-1 != prer) { + int diff = l - prer; + if (diff > t1 + t2) { + consume += (diff - t1 - t2) * p3 + t2 * p2 + t1 * p1; + } else if (diff > t1) { + consume += (diff - t1) * p2 + t1 * p1; + } else { + consume += diff * p1; + } + } + prer = r; + } + cout << consume << endl; + return 0; +} +string a[8]; +int main() { + for (int i = (0), _b(8); i < _b; ++i) cin >> a[i]; + int res = 8; + for (int i = (0), _b(8); i < _b; ++i) + for (int j = (0), _b(8); j < _b; ++j) + if (a[i][j] == 'W') { + res = 0; + for (int q = (0), _b(8); q < _b; ++q) { + if (a[q][j] == 'B') ++res; + if (a[i][q] == 'B') ++res; + } + cout << res << endl; + return 0; + } + cout << res << endl; + return 0; +} +string a[8]; +int main() { + for (int i = (0), _b(8); i < _b; ++i) cin >> a[i]; + int res = 8; + for (int i = (0), _b(8); i < _b; ++i) + for (int j = (0), _b(8); j < _b; ++j) + if (a[i][j] == 'W') { + res = 0; + for (int q = (0), _b(8); q < _b; ++q) { + if (a[q][j] == 'B') ++res; + if (a[i][q] == 'B') ++res; + } + cout << res << endl; + return 0; + } + cout << res << endl; + return 0; +} +int a, b; +bool read() { + if (!(cin >> a >> b)) return false; + return true; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +void solve() { + int e = 6 - max(a, b) + 1; + int d = 6; + int g = gcd(e, d); + cout << e / g << "/" << d / g << endl; +} +int main() { + while (read()) solve(); + return 0; +} +int a, b; +bool read() { + if (!(cin >> a >> b)) return false; + return true; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +void solve() { + int e = 6 - max(a, b) + 1; + int d = 6; + int g = gcd(e, d); + cout << e / g << "/" << d / g << endl; +} +int main() { + while (read()) solve(); + return 0; +} +char Chess[100][100]; +int main() { + int sum, X, Y; + while (cin >> Chess[0]) { + for (int i = 1; i < 8; i++) cin >> Chess[i]; + sum = 0; + for (int i = 0; i < 8; i++) { + X = Y = 0; + for (int j = 0; j < 8; j++) { + if (Chess[i][j] != 'B') X = 1; + if (Chess[j][i] != 'B') Y = 1; + } + if (!X) sum++; + if (!Y) sum++; + } + if (sum == 16) { + cout << "8" << endl; + continue; + } + cout << sum << endl; + } + return 0; +} +char Chess[100][100]; +int main() { + int sum, X, Y; + while (cin >> Chess[0]) { + for (int i = 1; i < 8; i++) cin >> Chess[i]; + sum = 0; + for (int i = 0; i < 8; i++) { + X = Y = 0; + for (int j = 0; j < 8; j++) { + if (Chess[i][j] != 'B') X = 1; + if (Chess[j][i] != 'B') Y = 1; + } + if (!X) sum++; + if (!Y) sum++; + } + if (sum == 16) { + cout << "8" << endl; + continue; + } + cout << sum << endl; + } + return 0; +} +int y, w; +int gcd(int a, int b) { + return (a == 0 ? b : gcd(b % a, a)); +} +int main() { + cin >> y >> w; + int x = max(y, w); + x = 7 - x; + int y = gcd(x, 6); + x /= y; + cout << x << "/" << 6 / y << "\n"; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int l, r, s, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (register int i = 1; i <= n; i++) { + cin >> l >> r; + if (i > 1) { + ans = ans + min(t1, l - s) * p1; + if (l - s > t1) { + ans = ans + min(l - s - t1, t2) * p2; + if (l - s > t1 + t2) ans = ans + (l - s - t1 - t2) * p3; + } + } + ans = ans + (r - l) * p1; + s = r; + } + cout << ans << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int l, r, s, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (register int i = 1; i <= n; i++) { + cin >> l >> r; + if (i > 1) { + ans = ans + min(t1, l - s) * p1; + if (l - s > t1) { + ans = ans + min(l - s - t1, t2) * p2; + if (l - s > t1 + t2) ans = ans + (l - s - t1 - t2) * p3; + } + } + ans = ans + (r - l) * p1; + s = r; + } + cout << ans << endl; + return 0; +} +int main() { + int y, w, m; + cin >> y >> w; + m = max(y, w); + int c = 6 - m + 1; + if (c == 5) + cout << "5/6" << endl; + else if (c == 4) + cout << "2/3" << endl; + else if (c == 3) + cout << "1/2" << endl; + else if (c == 2) + cout << "1/3" << endl; + else if (c == 1) + cout << "1/6" << endl; + else { + cout << "1/1" << endl; + } + return 0; +} +int main() { + int y, w, m; + cin >> y >> w; + m = max(y, w); + int c = 6 - m + 1; + if (c == 5) + cout << "5/6" << endl; + else if (c == 4) + cout << "2/3" << endl; + else if (c == 3) + cout << "1/2" << endl; + else if (c == 2) + cout << "1/3" << endl; + else if (c == 1) + cout << "1/6" << endl; + else { + cout << "1/1" << endl; + } + return 0; +} +int main() { + int l[1000], r[1000]; + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p1; + if (i > 0) { + if (l[i] - r[i - 1] > t1) { + ans += t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) { + ans += t2 * p2; + ans += (t - t2) * p3; + } else + ans += t * p2; + } else + ans += (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; +} +int main() { + int l[1000], r[1000]; + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p1; + if (i > 0) { + if (l[i] - r[i - 1] > t1) { + ans += t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) { + ans += t2 * p2; + ans += (t - t2) * p3; + } else + ans += t * p2; + } else + ans += (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; +} +set st[55]; +int x, y, c; +string s[9], s1[9]; +int main() { + int l = 0, r = 0, k; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + k = 0; + for (int j = 0; j < 8; j++) + if (s[i][j] == 'B') k++; + if (k == 8) + l++; + else + r = k; + } + cout << l + r << endl; + return 0; +} +set st[55]; +int x, y, c; +string s[9], s1[9]; +int main() { + int l = 0, r = 0, k; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + k = 0; + for (int j = 0; j < 8; j++) + if (s[i][j] == 'B') k++; + if (k == 8) + l++; + else + r = k; + } + cout << l + r << endl; + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + long long x = i * (i + 1); + x /= 2; + if (x == n) { + cout << "YES" << '\n'; + break; + } + if (x > n) { + cout << "NO" << '\n'; + break; + } + } + return 0; +} +int main() { + int a, b, f; + cin >> a >> b; + int y = max(a, b); + y = 6 - y + 1; + int g = __gcd(y, 6); + y = y / g; + f = 6 / g; + cout << y << "/" << f << endl; +} +int main() { + int a, b, f; + cin >> a >> b; + int y = max(a, b); + y = 6 - y + 1; + int g = __gcd(y, 6); + y = y / g; + f = 6 / g; + cout << y << "/" << f << endl; +} +int k[1440], min1 = 0, max1 = 0; +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 1; i <= n; i++) { + int a, b; + cin >> a >> b; + for (int j = a; j < b; j++) { k[j] = 1; } + if (i == 1) min1 = a; + if (i == n) max1 = b; + } + int f = 0, ans = 0; + for (int i = min1; i < max1; i++, f++) { + if (k[i]) f = 0; + if (f <= t1) { + ans += p1; + } else if (f <= t1 + t2) { + ans += p2; + } else { + ans += p3; + } + } + cout << ans << endl; + return 0; +} +int k[1440], min1 = 0, max1 = 0; +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 1; i <= n; i++) { + int a, b; + cin >> a >> b; + for (int j = a; j < b; j++) { k[j] = 1; } + if (i == 1) min1 = a; + if (i == n) max1 = b; + } + int f = 0, ans = 0; + for (int i = min1; i < max1; i++, f++) { + if (k[i]) f = 0; + if (f <= t1) { + ans += p1; + } else if (f <= t1 + t2) { + ans += p2; + } else { + ans += p3; + } + } + cout << ans << endl; + return 0; +} +int main() { + int i, j, count = 0, count2; + char c[10][10]; + int a[10] = {0}, b[10] = {0}; + for (i = 0; i < 8; i++) + for (j = 0; j < 8; j++) cin >> c[i][j]; + for (i = 0; i < 8; i++) { + count2 = 0; + for (j = 0; j < 8; j++) { + if (c[i][j] == 'B') { + a[i]++; + if (b[j] == 0) count2++; + } + } + if (a[i] == 8) + count++; + else { + count += count2; + for (j = 0; j < 8; j++) + if (c[i][j] == 'B' && b[j] == 0) b[j] = 1; + } + } + cout << count << endl; + return 0; +} +int main() { + int i, j, count = 0, count2; + char c[10][10]; + int a[10] = {0}, b[10] = {0}; + for (i = 0; i < 8; i++) + for (j = 0; j < 8; j++) cin >> c[i][j]; + for (i = 0; i < 8; i++) { + count2 = 0; + for (j = 0; j < 8; j++) { + if (c[i][j] == 'B') { + a[i]++; + if (b[j] == 0) count2++; + } + } + if (a[i] == 8) + count++; + else { + count += count2; + for (j = 0; j < 8; j++) + if (c[i][j] == 'B' && b[j] == 0) b[j] = 1; + } + } + cout << count << endl; + return 0; +} +char vocals[] = {'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}; +bool contains(char vocal) { + for (int i = 0; i < 12; i++) { + if (vocals[i] == vocal) return true; + } + return false; +} +int main() { + string question; + getline(cin, question); + for (int i = question.size() - 2; i >= 0; i--) { + if (question[i] != ' ') { + if (contains(question[i])) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + } + } + return 0; +} +int main() { + int y, w, big = 0, six = 6; + cin >> y >> w; + if (y >= w) { + big = y - 1; + } else { + big = w - 1; + } + int r = (6 - big); + if (6 % r == 0) { + six = six / r; + r = r / r; + } else { + if (r % 2 == 0) { + do { r = r / 2; } while (r % 2 != 0); + six = six / 2; + } else if (r % 3 == 0) { + do { r = r / 3; } while (r % 3 != 0); + six = six / 3; + } + } + cout << r << "/" << six << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2, i; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + long l[n], r[n]; + long p = 0; + for (i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + p += p1 * (r[i] - l[i]); + } + for (i = 1; i < n; i++) { + if (l[i] - r[i - 1] > t2 + t1) { + p += t1 * p1 + t2 * p2 + (l[i] - r[i - 1] - t2 - t1) * p3; + } else if (l[i] - r[i - 1] > t1) { + p += t1 * p1 + (l[i] - r[i - 1] - t1) * p2; + } else + p += p1 * (l[i] - r[i - 1]); + } + cout << p << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2, i; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + long l[n], r[n]; + long p = 0; + for (i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + p += p1 * (r[i] - l[i]); + } + for (i = 1; i < n; i++) { + if (l[i] - r[i - 1] > t2 + t1) { + p += t1 * p1 + t2 * p2 + (l[i] - r[i - 1] - t2 - t1) * p3; + } else if (l[i] - r[i - 1] > t1) { + p += t1 * p1 + (l[i] - r[i - 1] - t1) * p2; + } else + p += p1 * (l[i] - r[i - 1]); + } + cout << p << endl; + return 0; +} +string s[15]; +int a[15][15], b[15][15], res; +int fun(int x, int y) { + long long cnt = 0, r = 0; + for (int i = x; i < 8; i++) { + if (a[i][y] != 1 && s[i][y] == 'B') { r++; } + } + for (int i = x - 1; i >= 0; i--) + if (a[i][y] != 1 && s[i][y] == 'B') { r++; } + if (r == 8) { + for (int i = x; i < 8; i++) { a[i][y] = 1; } + for (int i = x - 1; i >= 0; i--) a[i][y] = 1; + cnt++; + } + r = 0; + for (int i = y; i < 8; i++) { + if (b[x][i] != 1 && s[x][i] == 'B') { r++; } + } + for (int i = y - 1; i >= 0; i--) + if (b[x][i] != 1 && s[x][i] == 'B') { r++; } + if (r == 8) { + for (int i = y; i < 8; i++) b[x][i] = 1; + for (int i = y - 1; i >= 0; i--) b[x][i] = 1; + cnt++; + } + return cnt; +} +int main() { + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (s[i][j] == 'B') { res += fun(i, j); } + } + } + long long cnt = 0; + for (int i = 0; i < 8; i++) { + if (a[i][0] == 1 && b[i][0] == 1) { cnt++; } + } + if (cnt == 8) res -= 8; + cout << res << endl; + return 0; +} +bool a(char c) { + c = tolower(c); + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return 1; + return 0; +} +string s; +int main() { + getline(cin, s); + for (int i = s.size() - 2; i >= 0; --i) { + if (s[i] != ' ') { + if (a(s[i])) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; + } + } +} +bool a(char c) { + c = tolower(c); + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return 1; + return 0; +} +string s; +int main() { + getline(cin, s); + for (int i = s.size() - 2; i >= 0; --i) { + if (s[i] != ' ') { + if (a(s[i])) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; + } + } +} +int y, w; +int gcd(int a, int b) { + return (a == 0 ? b : gcd(b % a, a)); +} +int main() { + cin >> y >> w; + int x = max(y, w); + x = 7 - x; + if (x == 6) { + cout << "1/1\n"; + } else { + int y = gcd(x, 6); + x /= y; + cout << x << "/" << 6 / y << "\n"; + } + return 0; +} +int y, w; +int gcd(int a, int b) { + return (a == 0 ? b : gcd(b % a, a)); +} +int main() { + cin >> y >> w; + int x = max(y, w); + x = 7 - x; + if (x == 6) { + cout << "1/1\n"; + } else { + int y = gcd(x, 6); + x /= y; + cout << x << "/" << 6 / y << "\n"; + } + return 0; +} +int main() { + int n, P1, P2, P3, T1, T2; + cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; + int l, r, rprev = 0, tdiff = 0; + int tp1 = 0, tp2 = 0, tp3 = 0; + for (int i = 0; i < n; i++) { + cin >> l >> r; + tp1 += r - l; + if (rprev == 0) { + rprev = r; + continue; + } + tdiff = l - rprev; + if (tdiff <= T1) { + tp1 += tdiff; + } else if (tdiff <= (T1 + T2)) { + tp1 += T1; + tp2 += tdiff - T1; + } else { + tp1 += T1; + tp2 += T2; + tp3 += tdiff - T1 - T2; + } + rprev = r; + } + cout << tp1 * P1 + tp2 * P2 + tp3 * P3 << endl; + return 0; +} +int main() { + char a[9][9]; + int s = 0, count = 0, h[8] = {0}, countr = 0; + for (int i = 0; i < 8; ++i) { + cin.get(a[i], 9, '\n'); + cin.ignore(1000, '\n'); + for (int j = 0; j < 8; ++j) { + if (a[i][j] == 'B') ++count; + } + if (count == 8) ++countr; + count = 0; + } + for (int i = 0; i < 8; ++i) { + if (countr == 8 && i == 0) break; + for (int j = 0; j < 8; ++j) { + if (a[j][i] == 'B') ++count; + } + if (count == 8) ++countr; + count = 0; + } + cout << countr << endl; + return 0; +} +map point, num_diff, num; +string s; +string name[56]; +bool cmp(string s1, string s2) { + if (point[s1] != point[s2]) return point[s1] > point[s2]; + if (num_diff[s1] != num_diff[s2]) return num_diff[s1] > num_diff[s2]; + return num[s1] > num[s2]; +} +string s1, s2; +int n; +int num1, num2; +char c; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> name[i]; } + for (int i = 1; i <= (n * (n - 1)) >> 1; i++) { + cin >> s >> num1 >> c >> num2; + s1 = s.substr(0, s.find("-")); + s2 = s.substr(s.find("-") + 1); + if (num1 > num2) { point[s1] += 3; } + if (num1 < num2) { point[s2] += 3; } + if (num1 == num2) { + point[s1]++; + point[s2]++; + } + num[s1] += num1; + num[s2] += num2; + num_diff[s1] += num1 - num2; + num_diff[s2] += num2 - num1; + } + sort(name + 1, name + n + 1, cmp); + sort(name + 1, name + (n / 2 + 1)); + for (int i = 1; i <= (n >> 1); i++) { cout << name[i] << endl; } + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + for (int i = 1; i <= 100; i++) { + if (i * (i + 1) / 2 == N) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + for (int i = 1; i <= 100; i++) { + if (i * (i + 1) / 2 == N) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + string a[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + int h = max(x, y); + cout << a[6 - h] << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + string a[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + int h = max(x, y); + cout << a[6 - h] << endl; + return 0; +} +map scored, conceed, points; +vector vec, a; +bool cmp(string a, string b) { + if (points[b] > points[a]) + return 1; + else if (points[b] < points[a]) + return 0; + else { + int dif1 = scored[a] - conceed[a]; + int dif2 = scored[b] - conceed[b]; + if (dif1 < dif2) + return 1; + else if (dif1 > dif2) + return 0; + else { + if (scored[a] > scored[b]) + return 0; + else if (scored[a] < scored[b]) + return 1; + } + } +} +int main() { + int n = 0; + string st; + cin >> n; + int m = n, k = n / 2; + while (m--) { + cin >> st; + vec.push_back(st); + } + n = (n * n - 1) / 2; + st = ""; + getchar(); + while (n--) { + int i; + string team1 = "", team2 = ""; + getline(cin, st); + for (i = 0; i < st.size(); i++) { + if (st[i] == '-') { + i++; + break; + } + team1 += st[i]; + } + for (; i < st.size(); i++) { + if (st[i] == ' ') { + i++; + break; + } + team2 += st[i]; + } + int j = 1, sum1 = 0; + for (; i < st.size(); i++) { + if (st[i] == ':') { + i++; + break; + } + int c = st[i] - 48; + sum1 = (sum1 * j) + c; + j *= 10; + } + scored[team1] += sum1; + conceed[team2] += sum1; + int sum2 = 0; + j = 1; + for (; i < st.size(); i++) { + int c = st[i] - 48; + sum2 = (sum2 * j) + c; + j *= 10; + } + scored[team2] += sum2; + conceed[team1] += sum2; + if (sum1 > sum2) + points[team1] += 3; + else if (sum1 < sum2) + points[team2] += 3; + else { + points[team1]++; + points[team2]++; + } + } + sort(vec.begin(), vec.end(), cmp); + for (int i = vec.size() - 1; i >= k; i--) a.push_back(vec[i]); + sort(a.begin(), a.end()); + for (int i = 0; i < a.size(); i++) cout << a[i] << endl; +} +int main() { + int a, b; + int n, p1, p2, p3, t1, t2; + vector v; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + while (n--) { + cin >> a >> b; + v.push_back(a); + v.push_back(b); + } + int ans = 0; + for (int i = 1; i < v.size(); i++) { + if (i % 2 != 0) { + ans = ans + p1 * (v[i] - v[i - 1]); + } else { + int k = v[i] - v[i - 1]; + if (k > t2 + t1) { + ans += p1 * (t1) + p2 * (t2) + p3 * (k - t2 - t1); + } else if (k > t1) { + ans += p1 * t1 + p2 * (k - t1); + } else { + ans += p1 * k; + } + } + } + cout << ans << endl; +} +int main() { + int a, b; + int n, p1, p2, p3, t1, t2; + vector v; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + while (n--) { + cin >> a >> b; + v.push_back(a); + v.push_back(b); + } + int ans = 0; + for (int i = 1; i < v.size(); i++) { + if (i % 2 != 0) { + ans = ans + p1 * (v[i] - v[i - 1]); + } else { + int k = v[i] - v[i - 1]; + if (k > t2 + t1) { + ans += p1 * (t1) + p2 * (t2) + p3 * (k - t2 - t1); + } else if (k > t1) { + ans += p1 * t1 + p2 * (k - t1); + } else { + ans += p1 * k; + } + } + } + cout << ans << endl; +} +int main() { + int i, n, c, counter = 0, j; + char k; + int arr[9]; + for (i = 0; i < 9; i++) { + cin >> k; + if (k == 'X') { + arr[i] = 1; + } else { + arr[i] = 0; + } + } + for (i = 0, j = 8; i < 9, j >= 0; i++, j--) { + if (arr[i] != arr[j]) { + counter++; + break; + } + } + if (counter == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int i, n, c, counter = 0, j; + char k; + int arr[9]; + for (i = 0; i < 9; i++) { + cin >> k; + if (k == 'X') { + arr[i] = 1; + } else { + arr[i] = 0; + } + } + for (i = 0, j = 8; i < 9, j >= 0; i++, j--) { + if (arr[i] != arr[j]) { + counter++; + break; + } + } + if (counter == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int triangleNumber[501] = {}; +void precomp() { + for (int i = 1; i < 32; i++) { triangleNumber[(i * i + i) / 2] = 1; } +} +int main() { + int N; + precomp(); + cin >> N; + if (triangleNumber[N]) { + cout << "YES"; + } else { + cout << "NO"; + } + cout << "\n"; + return 0; +} +int main() { + int n = 0, P1 = 0, P2 = 0, P3 = 0, T1 = 0, T2 = 0; + cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; + int l[1440] = {0}, r[1440] = {0}; + int res = 0; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + res += (r[i] - l[i]) * P1; + if (i != 0) { + if (l[i] - r[i - 1] > T1) { + res += T1 * P1; + if (l[i] - r[i - 1] - T1 > T2) { + res += T2 * P2; + res += (l[i] - r[i - 1] - T1 - T2) * P3; + } else + res += (l[i] - r[i - 1] - T1) * P2; + } else + res += (l[i] - r[i - 1]) * P1; + } + } + cout << res << endl; + return 0; +} +int main() { + int num1, num2; + cin >> num1 >> num2; + string Die_Roll[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + int x = 0; + x = max(num1, num2); + cout << Die_Roll[6 - x] << endl; + return 0; +} +long long int choose(long long int n, long long int m) { + long long int ans = 0; + long long int num = 1; + long long int den = 1; + for (long long int i = 0; i < m; i++) { + num *= (n - i); + num = num / (i + 1); + } + return num; +} +bool isPrime(int n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (int i = 5; i * i <= n; i = i + 6) { + if (n % i == 0 || n % (i + 2) == 0) return false; + } + return true; +} +long long int numzero(long long int p) { + long long int i = 0, sum = 0, temp; + while (p > 0) { + temp = p % 10; + if (temp == 0) { sum++; } + p = p / 10; + } + return p; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) { + return b; + } else { + return gcd(b % a, a); + } +} +int main() { + long long int i, j, k, n, m; + char a[3][3]; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { cin >> a[i][j]; } + } + if (a[0][0] != a[2][2]) { + cout << "NO\n"; + } else if (a[0][1] != a[2][1]) { + cout << "NO\n"; + } else if (a[0][2] != a[2][0]) { + cout << "NO\n"; + } else if (a[1][0] != a[1][2]) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int i; + int clock = 0; + int con = 0; + for (i = 0; i < n; i++) { + int st, en; + cin >> st >> en; + int k; + if (i == 0) { clock = st; } + int ct = 0; + for (clock; clock < st; clock++) { + ct++; + if (ct > 0 && ct <= t1) { con += p1; } + if (ct > t1 && ct <= t1 + t2) { con += p2; } + if (ct > t2 + t1) { con += p3; } + } + con += ((en - st) * p1); + clock = en; + } + cout << con << endl; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int i; + int clock = 0; + int con = 0; + for (i = 0; i < n; i++) { + int st, en; + cin >> st >> en; + int k; + if (i == 0) { clock = st; } + int ct = 0; + for (clock; clock < st; clock++) { + ct++; + if (ct > 0 && ct <= t1) { con += p1; } + if (ct > t1 && ct <= t1 + t2) { con += p2; } + if (ct > t2 + t1) { con += p3; } + } + con += ((en - st) * p1); + clock = en; + } + cout << con << endl; +} +int main() { + int y, w; + cin >> y >> w; + int chance = 7 - max(y, w); + int gcd = __gcd(chance, 6); + chance /= gcd; + int pembagi = 6 / gcd; + cout << chance << '/' << pembagi << '\n'; + return 0; +} +int main() { + int y, w; + cin >> y >> w; + int chance = 7 - max(y, w); + int gcd = __gcd(chance, 6); + chance /= gcd; + int pembagi = 6 / gcd; + cout << chance << '/' << pembagi << '\n'; + return 0; +} +int n; +int main() { + cin >> n; + n *= 2; + for (register int i = 1; i <= sqrt(n); ++i) + if (i * (i + 1) == n) puts("YES"), exit(0); + puts("NO"); +} +const int INF = 1 << 28; +const double EPS = 1e-7; +int main() { + int N, P1, P2, P3, T1, T2; + cin >> N >> P1 >> P2 >> P3 >> T1 >> T2; + int last = -1; + int answer = 0; + for (int i = 0; i < (N); ++i) { + int a, b; + cin >> a >> b; + if (last != -1) { + int t = a - last; + int k = min(t, T1); + answer += k * P1; + t -= k; + k = min(t, T2); + answer += k * P2; + t -= k; + answer += t * P3; + t = 0; + } + answer += P1 * (b - a); + last = b; + } + cout << answer << endl; + return 0; +} +const int INF = 1 << 28; +const double EPS = 1e-7; +int main() { + int N, P1, P2, P3, T1, T2; + cin >> N >> P1 >> P2 >> P3 >> T1 >> T2; + int last = -1; + int answer = 0; + for (int i = 0; i < (N); ++i) { + int a, b; + cin >> a >> b; + if (last != -1) { + int t = a - last; + int k = min(t, T1); + answer += k * P1; + t -= k; + k = min(t, T2); + answer += k * P2; + t -= k; + answer += t * P3; + t = 0; + } + answer += P1 * (b - a); + last = b; + } + cout << answer << endl; + return 0; +} +int main() { + char a[10]; + cin >> a[1] >> a[2] >> a[3]; + cin >> a[4] >> a[5] >> a[6]; + cin >> a[7] >> a[8] >> a[9]; + if ((a[1] == a[9]) && (a[2] == a[8]) && (a[3] == a[7]) && (a[4] == a[6])) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + char a[10]; + cin >> a[1] >> a[2] >> a[3]; + cin >> a[4] >> a[5] >> a[6]; + cin >> a[7] >> a[8] >> a[9]; + if ((a[1] == a[9]) && (a[2] == a[8]) && (a[3] == a[7]) && (a[4] == a[6])) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + bool arr[505]; + int tambah = 1; + for (int i = 0; i <= 500; i++) { arr[i] = 0; } + for (int i = 1; i <= 500; i += tambah) { + arr[i] = 1; + tambah++; + } + int n; + cin >> n; + if (arr[n]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + bool arr[505]; + int tambah = 1; + for (int i = 0; i <= 500; i++) { arr[i] = 0; } + for (int i = 1; i <= 500; i += tambah) { + arr[i] = 1; + tambah++; + } + int n; + cin >> n; + if (arr[n]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int c = max(a, b); + if (c == 1) cout << "1/1" << endl; + if (c == 2) cout << "5/6" << endl; + if (c == 3) cout << "2/3" << endl; + if (c == 4) cout << "1/2" << endl; + if (c == 5) cout << "1/3" << endl; + if (c == 6) cout << "1/6" << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int l, r, s, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (register int i = 1; i <= n; i++) { + cin >> l >> r; + if (i > 1) { + ans = ans + min(t1, l - s) * p1; + if (l - s > t1) { + ans = ans + min(l - s - t1, t2) * p2; + if (l - s > t1 + t2) ans = ans + (l - s - t1 - t2) * p3; + } + } + ans = ans + (r - l) * p1; + s = r; + } + cout << ans << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int l, r, s, ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (register int i = 1; i <= n; i++) { + cin >> l >> r; + if (i > 1) { + ans = ans + min(t1, l - s) * p1; + if (l - s > t1) { + ans = ans + min(l - s - t1, t2) * p2; + if (l - s > t1 + t2) ans = ans + (l - s - t1 - t2) * p3; + } + } + ans = ans + (r - l) * p1; + s = r; + } + cout << ans << endl; + return 0; +} +map pt, sc, mi; +string name[50]; +bool cmp(string s1, string s2) { + if (pt[s1] != pt[s2]) return pt[s1] > pt[s2]; + if (mi[s1] != mi[s2]) + return mi[s1] > mi[s2]; + else + return sc[s1] > sc[s2]; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> name[i]; + cin.ignore(); + for (int i = 0; i < n * (n - 1) / 2; i++) { + string A, B; + getline(cin, A, '-'); + getline(cin, B, ' '); + char ch; + int pA, pB; + cin >> pA >> ch >> pB; + cin.ignore(); + if (pA < pB) pt[B] += 3; + if (pA > pB) pt[A] += 3; + if (pA == pB) pt[A]++, pt[B]++; + sc[A] += pA; + mi[A] += pA - pB; + sc[B] += pB; + mi[B] += pB - pA; + } + sort(name, name + n, cmp); + sort(name, name + n / 2); + for (int i = 0; i < n / 2; i++) cout << name[i] << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool ok = false; + for (int i = 1; i < 50; ++i) { + if ((i * (i + 1)) / 2 == n) ok = true; + } + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + bool ok = false; + for (int i = 1; i < 50; ++i) { + if ((i * (i + 1)) / 2 == n) ok = true; + } + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, p1, p2, p3, t1, t2; + int a[105]; + int b[105]; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int workTime = 0; + int midTime = 0; + int sleepTime = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < n; i++) workTime += (b[i] - a[i]); + for (int i = 0; i < n - 1; i++) { + if (a[i + 1] - b[i] < t1) + workTime += (a[i + 1] - b[i]); + else if (a[i + 1] - b[i] < t1 + t2) { + workTime += t1; + midTime += (a[i + 1] - b[i] - t1); + } else { + workTime += t1; + midTime += t2; + sleepTime += (a[i + 1] - b[i] - t1 - t2); + } + } + cout << p1 * workTime + p2 * midTime + p3 * sleepTime << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int a[105]; + int b[105]; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int workTime = 0; + int midTime = 0; + int sleepTime = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < n; i++) workTime += (b[i] - a[i]); + for (int i = 0; i < n - 1; i++) { + if (a[i + 1] - b[i] < t1) + workTime += (a[i + 1] - b[i]); + else if (a[i + 1] - b[i] < t1 + t2) { + workTime += t1; + midTime += (a[i + 1] - b[i] - t1); + } else { + workTime += t1; + midTime += t2; + sleepTime += (a[i + 1] - b[i] - t1 - t2); + } + } + cout << p1 * workTime + p2 * midTime + p3 * sleepTime << endl; + return 0; +} +int main() { + int n, m = 2; + cin >> n; + cout << m; + for (int i = 1; i < n - 1; i++) { + m += (i + 1); + if (m % n == 0) + cout << " " << n; + else + cout << " " << m % n; + } + cout << endl; + return 0; +} +int main() { + int n, m = 2; + cin >> n; + cout << m; + for (int i = 1; i < n - 1; i++) { + m += (i + 1); + if (m % n == 0) + cout << " " << n; + else + cout << " " << m % n; + } + cout << endl; + return 0; +} +int v[1000]; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v[i] = 0; + for (int i = 1; i < 501; i++) { + v[i] = 1; + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int v[1000]; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v[i] = 0; + for (int i = 1; i < 501; i++) { + v[i] = 1; + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +char s[5][5]; +int main() { + int i, j, k, l; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) cin >> s[i][j]; + for (i = 0, j = 2; i < 3; i++, j--) + if (s[0][i] != s[2][j]) { + cout << "NO" << endl; + return 0; + } + if (s[1][0] != s[1][2]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; +} +const int INF = 0x3f3f3f3f; +char s[5][5]; +int main() { + int i, j, k, l; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) cin >> s[i][j]; + for (i = 0, j = 2; i < 3; i++, j--) + if (s[0][i] != s[2][j]) { + cout << "NO" << endl; + return 0; + } + if (s[1][0] != s[1][2]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; +} +int main() { + long long t, n, i, l, m, x, y, a, b, c, p1, p2, p3, t1, t2, r, sum = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + cin >> l >> r; + sum += (r - l) * p1; + n--; + while (n--) { + cin >> a >> b; + if ((a - r) <= t1) { + sum += (a - r) * p1; + } else if ((a - r) > t1 && (a - r) <= t1 + t2) { + sum += t1 * p1 + (a - r - t1) * p2; + } else if ((a - r) > t1 + t2) { + sum += t1 * p1 + t2 * p2 + (a - r - t1 - t2) * p3; + } + sum += (b - a) * p1; + l = a; + r = b; + } + cout << sum << endl; +} +int main() { + int n; + cin >> n; + int cur = 0; + for (int i = 1; i < n; ++i) { + if (i > 1) cout << " "; + cur += i; + cur %= n; + cout << cur + 1; + } + cout << endl; +} +int main() { + int x, y, z = 7, q = 6; + cin >> x >> y; + if (x > y) + z = z - x; + else + z = z - y; + if (z == 6 || z > 0 && z < 4) { + q = q / z; + z = 1; + cout << z << "/" << q << endl; + } else if (z == 0) + cout << "0/1\n"; + else { + if (z == 4) { + q = q / 2; + z = z / 2; + cout << z << "/" << q << endl; + } else + cout << z << "/" << q << endl; + } + return 0; +} +int main() { + int x, y, z = 7, q = 6; + cin >> x >> y; + if (x > y) + z = z - x; + else + z = z - y; + if (z == 6 || z > 0 && z < 4) { + q = q / z; + z = 1; + cout << z << "/" << q << endl; + } else if (z == 0) + cout << "0/1\n"; + else { + if (z == 4) { + q = q / 2; + z = z / 2; + cout << z << "/" << q << endl; + } else + cout << z << "/" << q << endl; + } + return 0; +} +int main() { + string s[3]; + bool flag = true; + for (int i = 0; i < 3; i++) cin >> s[i]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (s[i][j] != s[2 - i][2 - j]) flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s[3]; + bool flag = true; + for (int i = 0; i < 3; i++) cin >> s[i]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (s[i][j] != s[2 - i][2 - j]) flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int y; + double n, x; + cin >> n; + x = 8 * n + 1; + x = sqrt(x); + x--; + x /= 2; + y = (int)x; + if (x == y) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int y; + double n, x; + cin >> n; + x = 8 * n + 1; + x = sqrt(x); + x--; + x /= 2; + y = (int)x; + if (x == y) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int n; + int p1, p2, p3; + int t1, t2; + int l[110], r[110]; + while (cin >> n >> p1 >> p2 >> p3 >> t1 >> t2) { + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans += (r[i] - l[i]) * p1; + if (i) { + if (l[i] - r[i - 1] > t1) { + ans += t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) { + ans += t2 * p2; + ans += (t - t2) * p3; + } else + ans += t * p2; + } else + ans += (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, a[200], i; + cin >> n; + a[0] = 1; + for (i = 1; i <= n - 1; i++) { + a[i] = (a[i - 1] + i) % n; + if (a[i] == 0) a[i] = n; + } + for (i = 1; i < n - 1; i++) { cout << a[i] << " "; } + cout << a[n - 1] << endl; + return 0; +} +int main() { + int n, a[200], i; + cin >> n; + a[0] = 1; + for (i = 1; i <= n - 1; i++) { + a[i] = (a[i - 1] + i) % n; + if (a[i] == 0) a[i] = n; + } + for (i = 1; i < n - 1; i++) { cout << a[i] << " "; } + cout << a[n - 1] << endl; + return 0; +} +int main() { + int y, w; + const string p[7] = {"", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"}; + cin >> y >> w; + cout << p[max(y, w)] << endl; + return 0; +} +int main() { + int y, w; + const string p[7] = {"", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"}; + cin >> y >> w; + cout << p[max(y, w)] << endl; + return 0; +} +int main() { + string str1, str2, str3, str4; + cin >> str1 >> str2 >> str3; + str4 = str2; + int flag = 0, flag1 = 0; + if ((str1[0] == str3[2]) && (str1[1] == str3[1]) && (str1[2] == str3[0])) { flag = 1; } + if ((str2[0] == str2[2]) && (str2[1] == str2[1]) && (str2[2] == str2[0])) { flag1 = 1; } + if (flag && flag1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +map mp; +vector s; +vector v; +int main() { + int m; + cin >> m; + int k = m, i = 1, j = 1; + m--; + while (m--) { + j += i; + int ans = j % k; + if (ans == 0) ans = j; + cout << ans; + if (m == 0) + cout << endl; + else + cout << " "; + i++; + j %= k; + if (j == 0) j = ans; + } + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int s[n], e[n]; + for (int i = 0; i < n; i++) { cin >> s[i] >> e[i]; } + int sum = 0; + for (int i = 0; i < n; i++) { sum = sum + (p1 * (e[i] - s[i])); } + int ans = 0; + ans = ans + sum; + for (int i = 1; i < n; i++) { + int diff = 0, k; + diff = s[i] - e[i - 1]; + if (diff >= (t1 + t2)) { + k = (t1 * p1) + (t2 * p2) + ((diff - (t1 + t2)) * p3); + } else if (diff >= t1 && diff < (t1 + t2)) { + k = (t1 * p1) + ((diff - t1) * p2); + } else if (diff < t1) { + k = diff * p1; + } + ans = ans + k; + } + cout << ans << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int s[n], e[n]; + for (int i = 0; i < n; i++) { cin >> s[i] >> e[i]; } + int sum = 0; + for (int i = 0; i < n; i++) { sum = sum + (p1 * (e[i] - s[i])); } + int ans = 0; + ans = ans + sum; + for (int i = 1; i < n; i++) { + int diff = 0, k; + diff = s[i] - e[i - 1]; + if (diff >= (t1 + t2)) { + k = (t1 * p1) + (t2 * p2) + ((diff - (t1 + t2)) * p3); + } else if (diff >= t1 && diff < (t1 + t2)) { + k = (t1 * p1) + ((diff - t1) * p2); + } else if (diff < t1) { + k = diff * p1; + } + ans = ans + k; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, s, ans; + cin >> m >> n; + s = max(m, n); + ans = 7 - s; + if (ans == 1) + cout << "1/6" << endl; + else if (ans == 2) + cout << "1/3" << endl; + else if (ans == 3) + cout << "1/2" << endl; + else if (ans == 4) + cout << "2/3" << endl; + else if (ans == 5) + cout << "5/6" << endl; + else + cout << "1/1" << endl; + return 0; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + reverse(c.begin(), c.end()); + if (a == c && b[0] == b[2]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + int s[105], e[105]; + int ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 0; i < n; i++) { + cin >> s[i] >> e[i]; + int x = e[i] - s[i]; + ans += x * p1; + if (i != 0) { + int t = s[i] - e[i - 1]; + if (t <= t1) + ans += t * p1; + else { + if (t - t1 <= t2) + ans += p1 * t1 + (t - t1) * p2; + else + ans += p1 * t1 + p2 * t2 + (t - t1 - t2) * p3; + } + } + } + cout << ans << endl; + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int w, y; + cin >> w >> y; + int d = 7 - max(w, y); + if (d % 2 != 0 && d != 3) + cout << d << "/6" << endl; + else if (d % 2 == 0 && d != 6) + cout << d / 2 << "/" << 6 / 2 << endl; + else if (d == 3) + cout << "1/2" << endl; + else + cout << "1/1" << endl; +} +int main() { + int n; + cin >> n; + int minIncl = 1, maxExcl = 500; + while (minIncl < maxExcl - 1) { + int mid = (minIncl + maxExcl) / 2; + if (mid * (mid + 1) / 2 > n) + maxExcl = mid; + else + minIncl = mid; + } + cout << (n == minIncl * (minIncl + 1) / 2 ? "YES\n" : "NO\n"); + return 0; +} +int main() { + int n; + cin >> n; + int minIncl = 1, maxExcl = 500; + while (minIncl < maxExcl - 1) { + int mid = (minIncl + maxExcl) / 2; + if (mid * (mid + 1) / 2 > n) + maxExcl = mid; + else + minIncl = mid; + } + cout << (n == minIncl * (minIncl + 1) / 2 ? "YES\n" : "NO\n"); + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2, l[110], r[110], ans = 0; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + ans = ans + (r[i] - l[i]) * p1; + if (i > 0) { + if (l[i] - r[i - 1] > t1) { + ans = ans + t1 * p1; + int t = l[i] - r[i - 1] - t1; + if (t > t2) + ans = ans + t2 * p2 + (t - t2) * p3; + else + ans = ans + t * p2; + } else + ans = ans + (l[i] - r[i - 1]) * p1; + } + } + cout << ans << endl; + return 0; +} +int main() { + char a[3][3]; + int i, j, l, m; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) cin >> a[i][j]; + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + l = 1; + m = 1; + if (i == 0) { + l = 2; + } else if (i == 2) { + l = 0; + } + if (j == 0) { + m = 2; + } else if (j == 2) { + m = 0; + } + if (a[l][m] != a[i][j]) { + cout << "NO\n"; + goto label; + } + } + } + cout << "YES\n"; +label:; +} +int main() { + long long n, x; + cin >> n; + if (n == 2) + cout << "NO" << endl; + else if (n % 2 == 0) { + x = n / 2; + if (x % 2 == 0) + cout << "YES" << endl; + else if (x % 2 == 1) { + if (n % 2 == 0) cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else { + cout << "NO" << endl; + } + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int sum = 0; + int last_time = 0; + for (int i = 0; i < n; ++i) { + int begin, end; + cin >> begin >> end; + if (i > 0) { + int interval = begin - last_time; + if (interval >= t1) { + sum += t1 * p1; + interval -= t1; + if (interval >= t2) { + sum += t2 * p2; + interval -= t2; + if (interval > 0) { sum += p3 * interval; } + } else { + sum += p2 * interval; + } + } else { + sum += p1 * interval; + } + } + last_time = end; + sum += (end - begin) * p1; + } + cout << sum << endl; + return 0; +} +int main() { + int n, p1, p2, p3, t1, t2; + cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; + int sum = 0; + int last_time = 0; + for (int i = 0; i < n; ++i) { + int begin, end; + cin >> begin >> end; + if (i > 0) { + int interval = begin - last_time; + if (interval >= t1) { + sum += t1 * p1; + interval -= t1; + if (interval >= t2) { + sum += t2 * p2; + interval -= t2; + if (interval > 0) { sum += p3 * interval; } + } else { + sum += p2 * interval; + } + } else { + sum += p1 * interval; + } + } + last_time = end; + sum += (end - begin) * p1; + } + cout << sum << endl; + return 0; +} +int main() { + int i, k, n; + cin >> n; + for (i = 1; i <= n; i++) { + if (i * (i + 1) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int i, k, n; + cin >> n; + for (i = 1; i <= n; i++) { + if (i * (i + 1) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + char a[3][3]; + bool cond = false; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> a[i][j]; } + } + if (a[0][0] == a[2][2]) { + if (a[0][1] == a[2][1]) { + if (a[0][2] == a[2][0]) { + if (a[1][0] == a[1][2]) cond = true; + } + } + } + if (cond) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, x; + cin >> n; + if (n == 2) + cout << "NO" << endl; + else if (n % 2 == 0) { + x = n / 2; + if (x % 2 == 0) + cout << "YES" << endl; + else if (x % 2 == 1) { + if (n % 2 == 0) cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, i, c, max, d; + cin >> a >> b; + if (a > b) + max = a; + else if (a < b) + max = b; + else + max = a; + c = 6 - max + 1; + d = 6; + for (i = 2; i <= 3; i++) { + if (d % i == 0 && c % i == 0) { + d = d / i; + c = c / i; + } + } + cout << c << "/" << d << endl; + return 0; +} +int main() { + int a, b, i, c, max, d; + cin >> a >> b; + if (a > b) + max = a; + else if (a < b) + max = b; + else + max = a; + c = 6 - max + 1; + d = 6; + for (i = 2; i <= 3; i++) { + if (d % i == 0 && c % i == 0) { + d = d / i; + c = c / i; + } + } + cout << c << "/" << d << endl; + return 0; +} +bool tri[50000]; +int num, tot; +int main() { + for (register int i = 0; tot <= 500; i++) { + tot += i; + tri[tot] = 1; + } + cin >> num; + tri[num] ? cout << "YES" << endl : cout << "NO" << endl; +} +bool tri[50000]; +int num, tot; +int main() { + for (register int i = 0; tot <= 500; i++) { + tot += i; + tri[tot] = 1; + } + cin >> num; + tri[num] ? cout << "YES" << endl : cout << "NO" << endl; +} +string x[3]; +string m[3] = {"rock", "scissors", "paper"}; +string ans = "FMS"; +int main() { + map cnt; + for (int i = 0; i < 3; ++i) cin >> x[i], cnt[x[i]]++; + string win = ""; + for (int i = 0; i < 3; ++i) { + if (cnt[m[i]] == 1 && cnt[m[(i + 1) % 3]] == 2) win = m[i]; + } + if (win == "") + cout << "?" << endl; + else { + for (int i = 0; i < 3; ++i) { + if (x[i] == win) cout << ans[i] << endl; + } + } +} +int main() { + string s[3]; + cin >> s[0]; + cin >> s[1]; + cin >> s[2]; + int f = 0; + if (s[0][0] != s[2][2]) f = 1; + if (s[0][1] != s[2][1]) f = 1; + if (s[0][2] != s[2][0]) f = 1; + if (s[1][0] != s[1][2]) f = 1; + if (f) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + string s[3]; + cin >> s[0]; + cin >> s[1]; + cin >> s[2]; + int f = 0; + if (s[0][0] != s[2][2]) f = 1; + if (s[0][1] != s[2][1]) f = 1; + if (s[0][2] != s[2][0]) f = 1; + if (s[1][0] != s[1][2]) f = 1; + if (f) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int gcd_1(int a, int b) { + if (b == 0) { + return a; + } else { + return gcd_1(b, a % b); + } +} +int main() { + int n, m; + cin >> n >> m; + float k = max(n, m); + float answer = gcd_1(7 - k, 6); + cout << (7 - k) / answer << "/" << 6 / answer << endl; +} +long long n; +int main() { + int flag = 0; + cin >> n; + for (double i = 0;; ++i) { + if (i * (i + 1) / 2 == n) { + flag = 1; + break; + } else if (i * (i + 1) / 2 > n) { + break; + } + } + if (flag == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long n; +int main() { + int flag = 0; + cin >> n; + for (double i = 0;; ++i) { + if (i * (i + 1) / 2 == n) { + flag = 1; + break; + } else if (i * (i + 1) / 2 > n) { + break; + } + } + if (flag == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a; + cin >> a; + if (a & 1 || a == 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int a; + cin >> a; + if (a & 1 || a == 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) + cout << "YES\n"; + else + cout << "NO\n"; +} +inline int judge(string x) { + if (x == "rock") return 3; + if (x == "scissors") return 2; + if (x == "paper") return 1; +} +int main() { + string s, s1, s2; + cin >> s >> s1 >> s2; + int x, x1, x2; + x = judge(s); + x1 = judge(s1); + x2 = judge(s2); + if (x == x1) + if (x2 - x == 1 || x2 - x == -2) { + cout << "S\n"; + return 0; + } + if (x == x2) + if (x1 - x == 1 || x1 - x == -2) { + cout << "M\n"; + return 0; + } + if (x1 == x2) + if (x - x1 == 1 || x - x1 == -2) { + cout << "F\n"; + return 0; + } + cout << "?\n"; + return 0; +} +int main() { + int n; + cin >> n; + int i = 1; + while (i <= n) { + if ((i * i + i) == 2 * n) { + cout << "YES" << endl; + return 0; + } + i++; + } + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int i = 1; + while (i <= n) { + if ((i * i + i) == 2 * n) { + cout << "YES" << endl; + return 0; + } + i++; + } + cout << "NO" << endl; +} +char a, b, c, d, e, f, g, h, i; +int main() { + cin >> a >> b >> c >> d >> e >> f >> g >> h >> i; + if (a == i && b == h && c == g && d == f) + puts("YES"); + else + puts("NO"); +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n) { + if (n % 2 == 0 && n > 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + int n, m; + while (cin >> n) { + if (n % 2 == 0 && n > 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + char one[4]; + char two[4]; + char three[4]; + int res = 2; + int finall = 0; + cin >> one >> two >> three; + for (int i = 0; i < 3; i++) { + if (one[i] == 'X') { + if (three[res] == 'X') { + finall++; + res--; + } else { + finall = 0; + cout << "NO" << endl; + break; + } + } else if (one[i] == '.') { + if (three[res] == '.') { + finall++; + res--; + } else { + finall = 0; + cout << "NO" << endl; + break; + } + } + if (two[0] != two[2]) { + finall = 0; + cout << "NO" << endl; + break; + } + } + if (finall != 0) { cout << "YES" << endl; } + return 0; +} +int main() { + char one[4]; + char two[4]; + char three[4]; + int res = 2; + int finall = 0; + cin >> one >> two >> three; + for (int i = 0; i < 3; i++) { + if (one[i] == 'X') { + if (three[res] == 'X') { + finall++; + res--; + } else { + finall = 0; + cout << "NO" << endl; + break; + } + } else if (one[i] == '.') { + if (three[res] == '.') { + finall++; + res--; + } else { + finall = 0; + cout << "NO" << endl; + break; + } + } + if (two[0] != two[2]) { + finall = 0; + cout << "NO" << endl; + break; + } + } + if (finall != 0) { cout << "YES" << endl; } + return 0; +} +int check(int i, int j) { + if (i == 1) { + if (j == 2) return 1; + return 0; + } else if (i == 2) { + if (j == 3) return 1; + return 0; + } else { + if (j == 1) return 1; + return 0; + } +} +int main() { + string s; + int a[3]; + for (int i = 0; i < 3; i++) { + cin >> s; + if (s == "rock") a[i] = 1; + if (s == "scissors") a[i] = 2; + if (s == "paper") a[i] = 3; + } + if (check(a[0], a[1]) && check(a[0], a[2])) { + cout << "F" << endl; + } else if (check(a[1], a[0]) && check(a[1], a[2])) + cout << "M" << endl; + else if (check(a[2], a[0]) && check(a[2], a[1])) + cout << "S" << endl; + else + cout << "?" << endl; +} +int check(int i, int j) { + if (i == 1) { + if (j == 2) return 1; + return 0; + } else if (i == 2) { + if (j == 3) return 1; + return 0; + } else { + if (j == 1) return 1; + return 0; + } +} +int main() { + string s; + int a[3]; + for (int i = 0; i < 3; i++) { + cin >> s; + if (s == "rock") a[i] = 1; + if (s == "scissors") a[i] = 2; + if (s == "paper") a[i] = 3; + } + if (check(a[0], a[1]) && check(a[0], a[2])) { + cout << "F" << endl; + } else if (check(a[1], a[0]) && check(a[1], a[2])) + cout << "M" << endl; + else if (check(a[2], a[0]) && check(a[2], a[1])) + cout << "S" << endl; + else + cout << "?" << endl; +} +int n; +bool flag = false; +void f(int n) { + for (int i = 1; i <= n; i++) { + int k = n * 2, p = i * i + i; + if (k == p) { + flag = true; + break; + } + } +} +int main() { + cin >> n; + f(n); + if (flag == false) + cout << "NO"; + else + cout << "YES"; + cout << endl; + return 0; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + string str = a + b + c; + string rts = str; + reverse(str.begin(), str.end()); + if (str == rts) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + string str = a + b + c; + string rts = str; + reverse(str.begin(), str.end()); + if (str == rts) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long ModPow(long long a, long long n, long long m) { + if (!n) return 1; + if (n % 2) return (1ll * a * ModPow(a, n - 1, m)) % m; + return ModPow((1ll * a * a) % m, n / 2, m); +} +long long const MAX = INT_MAX; +int main() { + long long a, b, c; + cin >> a; + if (!(a % 2) && a != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int y, w, nom, dom = 6; + cin >> y >> w; + if (y >= w) { + nom = (6 - y) + 1; + } else if (w >= y) { + nom = (6 - w) + 1; + } + if (!(nom % 2) && !(dom % 2)) { + while (!(nom % 2) && !(dom % 2)) { + nom /= 2; + dom /= 2; + } + } + if (!(nom % 3) && !(dom % 3)) { + while (!(nom % 3) && !(dom % 3)) { + nom /= 3; + dom /= 3; + } + } + cout << nom << "/" << dom << endl; + return 0; +} +int main() { + int count; + char a[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> a[i][j]; + count = 0; + if (a[0][0] == a[2][2]) count++; + if (a[0][1] == a[2][1]) count++; + if (a[0][2] == a[2][0]) count++; + if (a[1][0] == a[1][2]) count++; + if (count == 4) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + int count; + char a[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> a[i][j]; + count = 0; + if (a[0][0] == a[2][2]) count++; + if (a[0][1] == a[2][1]) count++; + if (a[0][2] == a[2][0]) count++; + if (a[1][0] == a[1][2]) count++; + if (count == 4) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i * (i - 1) / 2 <= n; i++) + if (i * (i - 1) / 2 == n) return !(cout << "YES\n"); + return !(cout << "NO\n"); +} +int main() { + int n; + cin >> n; + for (int i = 0; i * (i - 1) / 2 <= n; i++) + if (i * (i - 1) / 2 == n) return !(cout << "YES\n"); + return !(cout << "NO\n"); +} +int main() { + int w, y; + cin >> w >> y; + int mx = max(w, y); + if (mx == 1) + cout << "1/1\n"; + else if (mx == 2) + cout << "5/6\n"; + else if (mx == 3) + cout << "2/3\n"; + else if (mx == 4) + cout << "1/2\n"; + else if (mx == 5) + cout << "1/3\n"; + else if (mx == 6) + cout << "1/6\n"; + else + cout << "0/6\n"; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int res = i * (i + 1) / 2; + if (res == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int res = i * (i + 1) / 2; + if (res == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int c = 0; + string n, m, s; + cin >> n >> m >> s; + for (int i = 1; i <= 3; i++) { + if ((n[0] == s[2]) && (n[1] == s[1]) && (n[2] == s[0]) && (m[0] == m[2])) { c++; } + } + if (c > 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w == 2) { + cout << "NO" << endl; + } else if (w % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w == 2) { + cout << "NO" << endl; + } else if (w % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k = 0; + cin >> n; + int a[500]; + for (int i = 0; i < 500; i++) { a[i] = ((i + 1) * (i + 2)) / 2; } + for (int i = 0; i < n; i++) { + if (a[i] == n) { + cout << "YES" << endl; + k = 1; + break; + } + } + if (k == 0) { cout << "NO" << endl; } + return 0; +} +int main() { + int n, k = 0; + cin >> n; + int a[500]; + for (int i = 0; i < 500; i++) { a[i] = ((i + 1) * (i + 2)) / 2; } + for (int i = 0; i < n; i++) { + if (a[i] == n) { + cout << "YES" << endl; + k = 1; + break; + } + } + if (k == 0) { cout << "NO" << endl; } + return 0; +} +string F, M, S; +long long N, K, A, B, C[2005], D, sum; +bool win(string x, string y) { + if (x[0] == 's' && y[0] == 'p') return true; + if (x[0] == 'p' && y[0] == 'r') return true; + if (x[0] == 'r' && y[0] == 's') + return true; + else + return false; +} +int main() { + cin >> F >> M >> S; + if (win(F, M) && win(F, S)) + cout << "F\n"; + else if (win(M, F) && win(M, S)) + cout << "M\n"; + else if (win(S, F) && win(S, M)) + cout << "S\n"; + else + cout << "?\n"; +} +const long long N = 1e8 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, m, cnt, mx = MX; +string a, b; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> n >> m; + cnt = (6 - (max(n, m) - 1)); + if (cnt == 1) + cout << "1/6"; + else if (cnt == 2) + cout << "1/3"; + else if (cnt == 3) + cout << "1/2"; + else if (cnt == 4) + cout << "2/3"; + else if (cnt == 5) + cout << "5/6"; + else + cout << "1/1"; + cout << "\n"; + return 0; +} +const long long N = 1e8 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, m, cnt, mx = MX; +string a, b; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> n >> m; + cnt = (6 - (max(n, m) - 1)); + if (cnt == 1) + cout << "1/6"; + else if (cnt == 2) + cout << "1/3"; + else if (cnt == 3) + cout << "1/2"; + else if (cnt == 4) + cout << "2/3"; + else if (cnt == 5) + cout << "5/6"; + else + cout << "1/1"; + cout << "\n"; + return 0; +} +int main() { + int c = 0; + string n, m, s; + cin >> n >> m >> s; + for (int i = 1; i <= 3; i++) { + if ((n[0] == s[2]) && (n[1] == s[1]) && (n[2] == s[0]) && (m[0] == m[2])) { c++; } + } + if (c > 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long spf[100001]; +long long gcd(long long a, long long b); +long long palindrome(string s); +long long modexp(long long a, long long b, long long m); +void sieve(); +long long ceil(long long a, long long b); +vector getFactorization(long long x); +void getZarr(string str, long long Z[]); +vector prefix_function(string s); +vector pi; +string s1, s2, virus; +long long dp[105][105][105]; +long long prefix(long long j, string s, char ch) { + while (j > 0 && ch != s[j]) { j = pi[j - 1]; } + if (ch == s[j]) { j++; } + return j; +} +long long f(long long i, long long j, long long k) { + if (dp[i][j][k] != -1) { return dp[i][j][k]; } + if (k == virus.length()) { return dp[i][j][k] = -1; } + if (i == s1.length() || j == s2.length()) { + return dp[i][j][k] = 0; + } else if (s1[i] != s2[j]) { + return dp[i][j][k] = max(f(i + 1, j, k), f(i, j + 1, k)); + } else { + long long a = prefix(k, virus, s1[i]); + if (a < k) { + return dp[i][j][k] = 1 + f(i + 1, j + 1, a); + } else + return dp[i][j][k] = max(1 + f(i + 1, j + 1, a), f(i + 1, j + 1, k)); + } +} +int main() { + long long y, w; + cin >> y >> w; + long long x = max(y, w); + long long num = 6 - x + 1; + long long den = 6; + long long g = gcd(num, den); + cout << num / g << "/" << den / g << '\n'; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + if (a == b) return a; + if (a > b) return gcd(a % b, b); + return gcd(a, b % a); +} +long long palindrome(string s) { + long long l = 0; + long long h = s.length() - 1; + while (h > l) { + if (s[l++] != s[h--]) { return 0; } + } + return 1; +} +long long modexp(long long a, long long b, long long m) { + if (b == 0) return 1; + long long temp = modexp(a, b / 2, m); + temp = (temp * temp) % m; + if (b & 1) return (temp * (a % m)) % m; + return temp; +} +void sieve() { + spf[1] = 1; + for (long long i = 2; i < 100001; i++) spf[i] = i; + for (long long i = 4; i < 100001; i += 2) spf[i] = 2; + for (long long i = 3; i * i < 100001; i++) { + if (spf[i] == i) { + for (long long j = i * i; j < 100001; j += i) + if (spf[j] == j) spf[j] = i; + } + } +} +vector getFactorization(long long x) { + vector ret; + while (x != 1) { + ret.push_back(spf[x]); + x = x / spf[x]; + } + return ret; +} +long long ceil(long long a, long long b) { + return a / b + (a % b != 0); +} +void getZarr(string str, long long Z[]) { + long long n = str.length(); + long long L, R, k; + L = R = 0; + for (long long i = 1; i < n; ++i) { + if (i > R) { + L = R = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } else { + k = i - L; + if (Z[k] < R - i + 1) + Z[i] = Z[k]; + else { + L = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } + } + } +} +vector prefix_function(string s) { + long long n = (long long)s.length(); + vector pi(n); + for (long long i = 1; i < n; i++) { + long long j = pi[i - 1]; + while (j > 0 && s[i] != s[j]) j = pi[j - 1]; + if (s[i] == s[j]) j++; + pi[i] = j; + } + return pi; +} +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + if (i * (i + 1) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + if (i * (i + 1) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + string a[3], b[3]; + for (int i = 0; i < 3; i++) { + cin >> a[i]; + b[i] = a[i]; + } + reverse(a[2].begin(), a[2].end()); + reverse(a[1].begin(), a[1].end()); + if (a[0] == a[2] && a[1] == b[1]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + string a[3], b[3]; + for (int i = 0; i < 3; i++) { + cin >> a[i]; + b[i] = a[i]; + } + reverse(a[2].begin(), a[2].end()); + reverse(a[1].begin(), a[1].end()); + if (a[0] == a[2] && a[1] == b[1]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int n, l, mt; + string s; + cin >> n; + if (n == 2) + cout << "NO" << endl; + else if (n % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int gcd(int a, int b) { + if (b == 0) { + return a; + } else + return gcd(b, a % b); +} +int main() { + int w, y; + cin >> w >> y; + int b = 6 - max(w, y) + 1; + int gc = gcd(b, 6); + b /= gc; + cout << b << "/" << 6 / gc << endl; +} +vector v; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v.push_back(0); + for (int i = 1; i < 501; i++) { + v.insert(v.begin() + i, 1); + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +vector v; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v.push_back(0); + for (int i = 1; i < 501; i++) { + v.insert(v.begin() + i, 1); + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int a = 0; + while (cin >> a) { + if (a > 3) + cout << (a & 1 ? "NO" : "YES") << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int a = 0; + while (cin >> a) { + if (a > 3) + cout << (a & 1 ? "NO" : "YES") << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int y, w, A = 0, gcd = 0; + cin >> y >> w; + if (y > w) { + for (int i = y; i <= 6; i++) { A += 1; } + for (int i = 1; i <= 6; i++) { + if (A % i == 0 && 6 % i == 0) { gcd = i; } + } + cout << A / gcd << "/" << 6 / gcd << endl; + } else { + for (int i = w; i <= 6; i++) { A += 1; } + for (int i = 1; i <= 6; i++) { + if (A % i == 0 && 6 % i == 0) { gcd = i; } + } + cout << A / gcd << "/" << 6 / gcd << endl; + } +} +int main() { + int number; + long sum = 0; + bool ok = false; + cin >> number; + if (number == 1) ok = true; + for (int counter = 1; counter < number; ++counter) { + sum += counter; + if (sum == number) ok = true; + } + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const double pi = acos(-1); +const int N = 1000000005; +const int MAXN = 5; +const int dy[] = {0, -1, 0, 1}; +const int dx[] = {-1, 0, 1, 0}; +int main() { + int y, w; + cin >> y >> w; + int x = 6 - max(y, w) + 1; + if (x == 6) + cout << "1/1\n"; + else if (x == 5) + cout << "5/6\n"; + else if (x == 4) + cout << "2/3\n"; + else if (x == 3) + cout << "1/2\n"; + else if (x == 2) + cout << "1/3\n"; + else + cout << "1/6\n"; +} +const double pi = acos(-1); +const int N = 1000000005; +const int MAXN = 5; +const int dy[] = {0, -1, 0, 1}; +const int dx[] = {-1, 0, 1, 0}; +int main() { + int y, w; + cin >> y >> w; + int x = 6 - max(y, w) + 1; + if (x == 6) + cout << "1/1\n"; + else if (x == 5) + cout << "5/6\n"; + else if (x == 4) + cout << "2/3\n"; + else if (x == 3) + cout << "1/2\n"; + else if (x == 2) + cout << "1/3\n"; + else + cout << "1/6\n"; +} +int main() { + char A[9], B[9]; + int x = 8; + for (int i = 0; i < 9; i++) { + cin >> A[i]; + B[x] = A[i]; + x--; + } + for (int i = 0; i < 9; i++) { + if (A[i] == B[i]) + continue; + else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + char A[9], B[9]; + int x = 8; + for (int i = 0; i < 9; i++) { + cin >> A[i]; + B[x] = A[i]; + x--; + } + for (int i = 0; i < 9; i++) { + if (A[i] == B[i]) + continue; + else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int n; +int main() { + cin >> n; + if (n % 2 == 0 && n != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int n, set = 0; + cin >> n; + long long int val = 8 * n + 1; + long long int fix = sqrt(val) - 1; + fix /= 2; + fix *= (fix + 1); + fix /= 2; + if (fix == n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + long long int n, set = 0; + cin >> n; + long long int val = 8 * n + 1; + long long int fix = sqrt(val) - 1; + fix /= 2; + fix *= (fix + 1); + fix /= 2; + if (fix == n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + a = max(a, b); + if (a == 1) cout << "1/1" << endl; + if (a == 2) cout << "5/6" << endl; + if (a == 3) cout << "2/3" << endl; + if (a == 4) cout << "1/2" << endl; + if (a == 5) cout << "1/3" << endl; + if (a == 6) cout << "1/6" << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + a = max(a, b); + if (a == 1) cout << "1/1" << endl; + if (a == 2) cout << "5/6" << endl; + if (a == 3) cout << "2/3" << endl; + if (a == 4) cout << "1/2" << endl; + if (a == 5) cout << "1/3" << endl; + if (a == 6) cout << "1/6" << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0 && a > 2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0 && a > 2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +string winner[] = {"F", "M", "S", "?"}; +bool getwin(string &a, string &b) { + if (a == "rock" && b == "scissors") + return true; + else if (a == "scissors" && b == "paper") + return true; + else if (a == "paper" && b == "rock") + return true; + return false; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + if (getwin(a, b) && getwin(a, c)) + cout << winner[0] << "\n"; + else if (getwin(b, a) && getwin(b, c)) + cout << winner[1] << "\n"; + else if (getwin(c, a) && getwin(c, b)) + cout << winner[2] << "\n"; + else + cout << winner[3] << "\n"; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + reverse(a.begin(), a.end()); + if (a == c && b[0] == b[2]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + reverse(a.begin(), a.end()); + if (a == c && b[0] == b[2]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int r = 6 - max(a, b) + 1; + int r2 = 6; + while (!(r % 2) && !(r2 % 2)) { + r /= 2; + r2 /= 2; + } + while (!(r % 3) && !(r2 % 3)) { + r /= 3; + r2 /= 3; + } + cout << r << "/" << r2 << endl; +} +int main() { + int a, b; + cin >> a >> b; + int r = 6 - max(a, b) + 1; + int r2 = 6; + while (!(r % 2) && !(r2 % 2)) { + r /= 2; + r2 /= 2; + } + while (!(r % 3) && !(r2 % 3)) { + r /= 3; + r2 /= 3; + } + cout << r << "/" << r2 << endl; +} +int main() { + int number; + long sum = 0; + bool ok = false; + cin >> number; + if (number == 1) ok = true; + for (int counter = 1; counter < number; ++counter) { + sum += counter; + if (sum == number) ok = true; + } + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int number; + long sum = 0; + bool ok = false; + cin >> number; + if (number == 1) ok = true; + for (int counter = 1; counter < number; ++counter) { + sum += counter; + if (sum == number) ok = true; + } + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int x = 10; + cin >> x; + if (x % 2 == 0 && x > 3) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int x = 10; + cin >> x; + if (x % 2 == 0 && x > 3) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + char a[10]; + for (int i = 0; i < 9; i++) { cin >> a[i]; } + for (int i = 0; i < 5; i++) { + if (a[i] != a[8 - i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + string ans[] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + int x, y; + cin >> x >> y; + x = max(x, y); + cout << ans[6 - x] << endl; +} +int main() { + string ans[] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + int x, y; + cin >> x >> y; + x = max(x, y); + cout << ans[6 - x] << endl; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + long long x = i * (i + 1); + x /= 2; + if (x == n) { + cout << "YES" << '\n'; + break; + } + if (x > n) { + cout << "NO" << '\n'; + break; + } + } + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + long long x = i * (i + 1); + x /= 2; + if (x == n) { + cout << "YES" << '\n'; + break; + } + if (x > n) { + cout << "NO" << '\n'; + break; + } + } + return 0; +} +int main() { + int a; + cin >> a; + if (a == 2) { + cout << "NO" << endl; + return 0; + } + if (a % 2 == 0) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } +} +int main() { + int a; + cin >> a; + if (a == 2) { + cout << "NO" << endl; + return 0; + } + if (a % 2 == 0) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } +} +int main() { + int A, B, pro = 0; + cin >> A >> B; + if (A > B) { + for (int i = A; i <= 6; i++) { pro++; } + } else { + for (int i = B; i <= 6; i++) { pro++; } + } + int result = __gcd(pro, 6); + if (pro == 0) + cout << "0/1" << endl; + else + cout << pro / result << "/" << 6 / result << endl; + return 0; +} +int main() { + char a, b, c, d, e, f, g, h, i, j, k, l; + while (cin >> a >> b >> c >> d >> e >> f >> g >> h >> i) { + if (a == i && b == h && c == g && d == f) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +int main() { + char a, b, c, d, e, f, g, h, i, j, k, l; + while (cin >> a >> b >> c >> d >> e >> f >> g >> h >> i) { + if (a == i && b == h && c == g && d == f) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +const int M = 100 + 5; +int main() { + int n; + cin >> n; + bool ok = false; + for (int i = 1; i < 1000 + 10; i++) { + if (i * (i + 1) == 2 * n) { + ok = true; + break; + } + } + if (ok == true) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +char graph[4][5]; +int main() { + for (int i = 1; i <= 3; i++) cin >> graph[i] + 1; + for (int i = 1; i <= 3; i++) + for (int j = 1; j <= 3; j++) + if (graph[i][j] != graph[4 - i][4 - j]) { + puts("NO"); + return 0; + } + puts("YES"); + return 0; +} +char graph[4][5]; +int main() { + for (int i = 1; i <= 3; i++) cin >> graph[i] + 1; + for (int i = 1; i <= 3; i++) + for (int j = 1; j <= 3; j++) + if (graph[i][j] != graph[4 - i][4 - j]) { + puts("NO"); + return 0; + } + puts("YES"); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int max = n; + if (m > max) max = m; + if (max == 1) + cout << "1/1" << endl; + else if (max == 2) + cout << "5/6" << endl; + else if (max == 3) + cout << "2/3" << endl; + else if (max == 4) + cout << "1/2" << endl; + else if (max == 5) + cout << "1/3" << endl; + else + cout << "1/6" << endl; +} +int main() { + int n, m; + cin >> n >> m; + int max = n; + if (m > max) max = m; + if (max == 1) + cout << "1/1" << endl; + else if (max == 2) + cout << "5/6" << endl; + else if (max == 3) + cout << "2/3" << endl; + else if (max == 4) + cout << "1/2" << endl; + else if (max == 5) + cout << "1/3" << endl; + else + cout << "1/6" << endl; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0 && a != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0 && a != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char person[4]{'F', 'M', 'S', '?'}; +int battle(const string a, const string b) { + if (a == "scissors" && b == "paper") { return 1; } + if (a == "rock" && b == "scissors") { return 1; } + if (a == "paper" && b == "rock") { return 1; } + return 0; +} +int wins(const string a, const string b, const string c) { + int ret = 0; + ret += battle(a, b); + ret += battle(a, c); + return ret; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + int winA, winB, winC, winner = 0, maxWin = 0, winCounter = 0; + winA = wins(a, b, c); + winB = wins(b, a, c); + winC = wins(c, a, b); + maxWin = winA; + if (winB > winA) { + winner = 1; + maxWin = winB; + } + if (winC > winB) { + winner = 2; + maxWin = winC; + } + if (winC > winA) { + winner = 2; + maxWin = winC; + } + winCounter = (maxWin == winA) + (maxWin == winB) + (maxWin == winC); + if (winCounter > 1) winner = 3; + cout << person[winner] << "\n"; + return 0; +} +int main() { + int n, previous = 0, next = 1; + cin >> n; + if (n == 1) { + cout << "YES" << endl; + return 0; + } + for (int i = 2;; i++) { + previous = next; + next = (i * (i + 1)) / 2; + if ((i * (i + 1)) / 2 == n) { + cout << "YES" << endl; + return 0; + } else if (n > previous && n < next) { + cout << "NO" << endl; + return 0; + ; + } + } +} +int main() { + int a, b, x; + cin >> a >> b; + string die_roll[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + x = max(a, b); + cout << die_roll[6 - x] << endl; + return 0; +} +int main() { + int a, b, x; + cin >> a >> b; + string die_roll[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + x = max(a, b); + cout << die_roll[6 - x] << endl; + return 0; +} +int main() { + string a, b, c; + getline(cin, a); + getline(cin, b); + getline(cin, c); + if (a[0] == 'r' && b[0] == 's' && b[0] == c[0]) + cout << "F" << endl; + else if (b[0] == 'r' && a[0] == 's' && a[0] == c[0]) + cout << "M" << endl; + else if (c[0] == 'r' && a[0] == 's' && b[0] == a[0]) + cout << "S" << endl; + else if (a[0] == 's' && b[0] == 'p' && b[0] == c[0]) + cout << "F" << endl; + else if (b[0] == 's' && a[0] == 'p' && a[0] == c[0]) + cout << "M" << endl; + else if (c[0] == 's' && b[0] == 'p' && b[0] == a[0]) + cout << "S" << endl; + else if (a[0] == 'p' && b[0] == 'r' && b[0] == c[0]) + cout << "F" << endl; + else if (b[0] == 'p' && a[0] == 'r' && a[0] == c[0]) + cout << "M" << endl; + else if (c[0] == 'p' && b[0] == 'r' && b[0] == a[0]) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + char x[9]; + for (int i = 0; i < 9; i++) cin >> x[i]; + for (int i = 0; i < 9; i++) + if (x[i] == x[8 - i]) + continue; + else { + cout << "NO\n"; + exit(0); + } + cout << "YES\n"; +} +int main() { + char x[9]; + for (int i = 0; i < 9; i++) cin >> x[i]; + for (int i = 0; i < 9; i++) + if (x[i] == x[8 - i]) + continue; + else { + cout << "NO\n"; + exit(0); + } + cout << "YES\n"; +} +void fast() {} +void file() {} +int main() { + fast(); + file(); + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if ((i * (i + 1)) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +void fast() {} +void file() {} +int main() { + fast(); + file(); + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if ((i * (i + 1)) / 2 == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0 && n != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0 && n != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int i, j, k, l, m, n, mark = 0; + char a[17]; + for (i = 1; i <= 9; i++) cin >> a[i]; + for (i = 1; i <= 9; i++) { + if (a[i] == 'X') + if (a[2 * 5 - i] != 'X') { + mark = 1; + cout << "NO" << endl; + break; + } + } + if (mark == 0) cout << "YES" << endl; +} +int main() { + int i, j, k, l, m, n, mark = 0; + char a[17]; + for (i = 1; i <= 9; i++) cin >> a[i]; + for (i = 1; i <= 9; i++) { + if (a[i] == 'X') + if (a[2 * 5 - i] != 'X') { + mark = 1; + cout << "NO" << endl; + break; + } + } + if (mark == 0) cout << "YES" << endl; +} +bool used[111111]; +long long n, a[211111], sum; +int main() { + string f, m, s; + cin >> f >> m >> s; + if ((f != m && f != s && s != m) || (f == m && m == s)) { + puts("?"); + return 0; + } + if (f == "rock" && m == "paper" && s == "rock") { + puts("M"); + return 0; + } + if (f == "rock" && m == "rock" && s == "paper") { + puts("S"); + return 0; + } + if (f == "paper" && m == "rock" && s == "rock") { + puts("F"); + return 0; + } + if (f == "scissors" && m == "scissors" && s == "rock") { + puts("S"); + return 0; + } + if (f == "rock" && m == "scissors" && s == "scissors") { + puts("F"); + return 0; + } + if (f == "scissors" && m == "rock" && s == "scissors") { + puts("M"); + return 0; + } + if (f == "scissors" && m == "paper" && s == "paper") { + puts("F"); + return 0; + } + if (f == "paper" && m == "paper" && s == "scissors") { + puts("S"); + return 0; + } + if (f == "paper" && m == "scissors" && s == "paper") { + puts("M"); + return 0; + } + puts("?"); +} +int main() { + int i, j, m, n, cnt = 0; + cin >> m; + i = (8 * m) + 1; + if (int(sqrt(i)) * int(sqrt(i)) == i) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int i, j, m, n, cnt = 0; + cin >> m; + i = (8 * m) + 1; + if (int(sqrt(i)) * int(sqrt(i)) == i) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char v[3][3] = {'\0'}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> v[i][j]; } + } + bool ans = true; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (v[i][j] != v[2 - i][2 - j]) { + ans = false; + break; + } + } + } + cout << (ans ? "YES" : "NO") << endl; + return 0; +} +long long w; +int main() { + cin >> w; + if (w > 2 && w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long w; +int main() { + cin >> w; + if (w > 2 && w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i < 500; ++i) { + if (i * (i + 1) / 2 == n) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i < 500; ++i) { + if (i * (i + 1) / 2 == n) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int n, m; +bool let(const int x, const int y) { + return 0 <= x && x < n && 0 <= y && y < m; +} +const int maxn = 123; +int main() { + cout.precision(10); + cout << fixed; + cin >> n >> m; + vector vs(n); + for (int i = 0; i < (int)(n); ++i) cin >> vs[i]; + for (int i = 0; i < (int)(n); ++i) { + for (int j = 0; j < (int)(m); ++j) { + if (vs[i][j] != vs[i][0]) { + cout << "NO" << endl; + return 0; + } + } + if (i > 0 && vs[i][0] == vs[i - 1][0]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; + return 0; +} +int n, m; +bool let(const int x, const int y) { + return 0 <= x && x < n && 0 <= y && y < m; +} +const int maxn = 123; +int main() { + cout.precision(10); + cout << fixed; + cin >> n >> m; + vector vs(n); + for (int i = 0; i < (int)(n); ++i) cin >> vs[i]; + for (int i = 0; i < (int)(n); ++i) { + for (int j = 0; j < (int)(m); ++j) { + if (vs[i][j] != vs[i][0]) { + cout << "NO" << endl; + return 0; + } + } + if (i > 0 && vs[i][0] == vs[i - 1][0]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; + return 0; +} +int main() { + map asd; + int temp; + for (int q = 1; q <= 500; q++) { + temp = q * (q + 1); + temp = temp / 2; + asd[temp]++; + } + int z; + cin >> z; + if (asd[z] > 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + map asd; + int temp; + for (int q = 1; q <= 500; q++) { + temp = q * (q + 1); + temp = temp / 2; + asd[temp]++; + } + int z; + cin >> z; + if (asd[z] > 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + char x[3][3]; + int i, k; + for (i = 0; i < 3; i++) { + for (k = 0; k < 3; k++) { cin >> x[i][k]; } + } + for (i = 0; i < 3; i++) { + for (k = 0; k < 3; k++) { + if (x[i][k] != x[2 - i][2 - k]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +int main() { + char x[3][3]; + int i, k; + for (i = 0; i < 3; i++) { + for (k = 0; k < 3; k++) { cin >> x[i][k]; } + } + for (i = 0; i < 3; i++) { + for (k = 0; k < 3; k++) { + if (x[i][k] != x[2 - i][2 - k]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +int main() { + int i, j, m, n, cnt = 0, tmp = 0; + int sum = 0, temp = 0, h1 = 0, h2 = 0; + char a[101][101]; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (i = 0; i < n - 1; i++) { + for (j = 0; j < m; j++) { + if (a[i][j] == a[i + 1][j]) cnt = 1; + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < m - 1; j++) { + if (a[i][j] != a[i][j + 1]) tmp = 1; + } + } + if (cnt == 1 or tmp == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + char data[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> data[i][j]; + bool flag = true; + if (data[0][0] != data[2][2]) + flag = false; + else if (data[0][1] != data[2][1]) + flag = false; + else if (data[0][2] != data[2][0]) + flag = false; + else if (data[1][0] != data[1][2]) + flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char data[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> data[i][j]; + bool flag = true; + if (data[0][0] != data[2][2]) + flag = false; + else if (data[0][1] != data[2][1]) + flag = false; + else if (data[0][2] != data[2][0]) + flag = false; + else if (data[1][0] != data[1][2]) + flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m = 0, a = 0; + cin >> n; + while (1) { + a++; + m += a; + if (n < m) { + cout << "NO" << endl; + exit(0); + } else if (n == m) { + cout << "YES" << endl; + exit(0); + } + } +} +int main() { + int n, m = 0, a = 0; + cin >> n; + while (1) { + a++; + m += a; + if (n < m) { + cout << "NO" << endl; + exit(0); + } else if (n == m) { + cout << "YES" << endl; + exit(0); + } + } +} +int main() { + int n; + cin >> n; + n *= 2; + for (int i = 1; i < n; i++) { + if (i * (i + 1) == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + n *= 2; + for (int i = 1; i < n; i++) { + if (i * (i + 1) == n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + char a[101][101]; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + bool flag = true; + for (int i = 1; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == a[i - 1][j]) { + flag = false; + break; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 1; j < m; j++) { + if (a[i][j] != a[i][j - 1]) { + flag = false; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int n, m; + char a[101][101]; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + bool flag = true; + for (int i = 1; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == a[i - 1][j]) { + flag = false; + break; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 1; j < m; j++) { + if (a[i][j] != a[i][j - 1]) { + flag = false; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +char m[10]; +int main() { + for (int i = 1; i <= 9; ++i) cin >> m[i]; + for (int i = 1; i < 5; ++i) { + if (m[i] != m[10 - i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +char m[10]; +int main() { + for (int i = 1; i <= 9; ++i) cin >> m[i]; + for (int i = 1; i < 5; ++i) { + if (m[i] != m[10 - i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, m; + char a, b; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (j == 0) { + cin >> a; + if (i != 0 && a == b) { + cout << "NO\n"; + return 0; + } + b = a; + } else + cin >> a; + if (a != b) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n, m; + char a, b; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (j == 0) { + cin >> a; + if (i != 0 && a == b) { + cout << "NO\n"; + return 0; + } + b = a; + } else + cin >> a; + if (a != b) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int main() { + char e[3][3]; + int flag = 0; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { cin >> e[i][j]; } + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { + if (e[i][j] != e[2 - i][2 - j]) flag = 1; + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + char e[3][3]; + int flag = 0; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { cin >> e[i][j]; } + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { + if (e[i][j] != e[2 - i][2 - j]) flag = 1; + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + map ms; + ms["scissors"] = "paper"; + ms["paper"] = "rock"; + ms["rock"] = "scissors"; + string f, m, s; + cin >> f >> m >> s; + if (ms[f] == m && ms[f] == s) + cout << "F" << endl; + else if (ms[m] == f && ms[m] == s) + cout << "M" << endl; + else if (ms[s] == f && ms[s] == m) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + int w; + cin >> w; + cout << (w > 3 && w % 2 == 0 ? "YES" : "NO") << endl; + return 0; +} +int main() { + int w; + cin >> w; + cout << (w > 3 && w % 2 == 0 ? "YES" : "NO") << endl; + return 0; +} +int main() { + string s1, s2, s3; + cin >> s1 >> s2 >> s3; + bool disC = false; + if (s2[0] == s2[2]) { + for (int c = 0; c < 3; c++) { + if (s1[c] != s3[2 - c]) { + disC = true; + cout << "NO" << endl; + break; + } + } + if (!disC) { cout << "YES" << endl; } + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i <= 32; i++) { + int ans = i * (i + 1); + if (ans == 2 * n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i <= 32; i++) { + int ans = i * (i + 1); + if (ans == 2 * n) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + bool valid = true; + for (int j = 1; j < m; ++j) { + if (s[j] != s[j - 1]) { + valid = false; + break; + } + } + for (int i = 1; i < n; i++) { + char c = s[0]; + cin >> s; + if (s[0] == c) { valid = false; } + for (int j = 1; j < m && valid; ++j) { + if (s[j] != s[j - 1]) { + valid = false; + break; + } + } + } + cout << (valid ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + bool valid = true; + for (int j = 1; j < m; ++j) { + if (s[j] != s[j - 1]) { + valid = false; + break; + } + } + for (int i = 1; i < n; i++) { + char c = s[0]; + cin >> s; + if (s[0] == c) { valid = false; } + for (int j = 1; j < m && valid; ++j) { + if (s[j] != s[j - 1]) { + valid = false; + break; + } + } + } + cout << (valid ? "YES" : "NO") << endl; + return 0; +} +const long long oo = 2 * 1000 * 1000 * 1000; +const int _cnt = 1000 * 1000; +const int _p = 1000 * 1000 * 1000 + 7; +long long o(long long x) { + return x % _p; +} +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} +int lcm(int a, int b) { + return a * b / gcd(a, b); +} +void file_put() { + freopen("filename.in", "r", stdin); + freopen("filename.out", "w", stdout); +} +string st[3]; +int main() { + for (int i = 0; i < 3; i++) getline(cin, st[i]); + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (st[i][j] != st[2 - i][2 - j]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int r, c; + cin >> r >> c; + char temp; + int t; + int prevc = -1; + int prevr = -1; + for (int i = 0; i < r; i++) { + prevc = -1; + for (int j = 0; j < c; j++) { + cin >> temp; + t = temp - '0'; + if (prevr != -1 && t == prevr) { + cout << "NO\n"; + return 0; + } + if (t != prevc && prevc != -1) { + cout << "NO\n"; + return 0; + } + prevc = t; + } + prevr = prevc; + } + cout << "YES\n"; + return 0; +} +int main() { + int r, c; + cin >> r >> c; + char temp; + int t; + int prevc = -1; + int prevr = -1; + for (int i = 0; i < r; i++) { + prevc = -1; + for (int j = 0; j < c; j++) { + cin >> temp; + t = temp - '0'; + if (prevr != -1 && t == prevr) { + cout << "NO\n"; + return 0; + } + if (t != prevc && prevc != -1) { + cout << "NO\n"; + return 0; + } + prevc = t; + } + prevr = prevc; + } + cout << "YES\n"; + return 0; +} +vector v; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v.push_back(0); + for (int i = 1; i < 501; i++) { + v.at(i) = 1; + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +vector v; +void prealoc() { + int count = 1; + for (int i = 0; i < 501; i++) v.push_back(0); + for (int i = 1; i < 501; i++) { + v.at(i) = 1; + i += count; + ++count; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + char a[10]; + for (int i = 1; i <= 9; i++) cin >> a[i]; + if (a[1] == a[9] && a[2] == a[8] && a[3] == a[7] && a[4] == a[6]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string as, bs, cs; + char W = ' '; + cin >> as >> bs >> cs; + int a, b, c, d, e; + if (as == "rock") a = 0; + if (as == "paper") a = 1; + if (as == "scissors") a = 2; + if (bs == "rock") b = 0; + if (bs == "paper") b = 1; + if (bs == "scissors") b = 2; + if (cs == "rock") c = 0; + if (cs == "paper") c = 1; + if (cs == "scissors") c = 2; + if ((a != b) & (b == c)) { + d = a; + e = b; + W = 'F'; + } else if ((c != b) & (a == b)) { + d = c; + e = a; + W = 'S'; + } else if ((b != c) & (a == c)) { + d = b; + e = c; + W = 'M'; + } else { + cout << "?" << '\n'; + return 0; + } + if ((d == 1) & (e == 0) | (d == 2) & (e == 1) | (d == 0) & (e == 2)) { + cout << W << '\n'; + return 0; + } else + (cout << '?' << '\n'); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v(n); + for (int i = 0; i < n; i++) { + cin >> v[i]; + if (i != 0) { + if (v[i][0] == v[i - 1][0]) { + cout << "NO" << endl; + return 0; + } + } + for (int j = 0; j < v[i].size(); j++) + if (v[i][j] != v[i][0]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +void rotate90(int N, string start[10][10], string end[10][10]) { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { end[j][N - i - 1] = start[i][j]; } + } +} +bool areSame(int N, string start[10][10], string end[10][10]) { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (end[i][j] != start[i][j]) { return false; } + } + } + return true; +} +int main() { + string resultsquare[10][10], newsquare[10][10], originalsquare[10][10]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + char n1; + cin >> n1; + originalsquare[i][j] = n1; + } + } + string hi[10][10]; + rotate90(3, originalsquare, newsquare); + rotate90(3, newsquare, hi); + if (areSame(3, originalsquare, hi)) { + cout << "YES"; + cout << endl; + } else { + cout << "NO"; + cout << endl; + } +} +int main() { + int x; + cin >> x; + if (x > 3 && x % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int x; + cin >> x; + if (x > 3 && x % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool win(string a, string b) { + if (a[0] == b[0]) return false; + if (a[0] == 'r' && b[0] == 's') return true; + if (a[0] == 's' && b[0] == 'p') return true; + if (a[0] == 'p' && b[0] == 'r') return true; + return false; +} +int main() { + string f, m, s; + cin >> f >> m >> s; + if (win(f, m) && win(f, s)) + cout << "F" << endl; + else if (win(m, f) && win(m, s)) + cout << "M" << endl; + else if (win(s, m) && win(s, f)) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + long long i, j, n, m; + char s[101][101]; + while (cin >> n >> m) { + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cin >> s[i][j]; } + } + bool f = 1; + for (i = 1; i < n; i++) { + for (j = 0; j < m; j++) { + if (s[i][j] == s[i - 1][j]) { + f = 0; + break; + } + } + } + for (i = 0; i < n; i++) { + for (j = 1; j < m; j++) { + if (s[i][j] != s[i][j - 1]) { + f = 0; + break; + } + } + } + if (f == 1) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +const int mxn = 1.e3; +int a[mxn]; +bool tri(int n) { + int sum = 0; + for (int i = 0; sum < n; i++) { + sum = (i * (i + 1)) / 2; + if (sum == n) return true; + } + return false; +} +int main() { + int n; + cin >> n; + { + cout << ((tri(n) ? "YES" : "NO")) << "\n"; + exit(0); + }; +} +bool winner(string x, string y, string z) { + if (x == "rock") { + if (y == z && y == "scissors") { return true; } + } else if (x == "scissors") { + if (y == z && y == "paper") { return true; } + } else { + if (y == z && y == "rock") { return true; } + } + return false; +} +int main() { + string x, y, z; + cin >> x >> y >> z; + if (winner(x, y, z)) { + cout << "F" + << "\n"; + } else if (winner(y, x, z)) { + cout << "M" + << "\n"; + } else if (winner(z, x, y)) { + cout << "S" + << "\n"; + } else { + cout << "?" + << "\n"; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char **c; + bool flag = true, flag2 = false; + c = new char *[3]; + for (int i = 0; i < 3; i++) c[i] = new char[3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> c[i][j]; + for (int i = 0, j = 2; i < 3; i++) { + if (c[0][i] != c[2][j]) flag = false; + j--; + } + if (c[1][0] == c[1][2]) flag2 = true; + if (flag && flag2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int x; + cin >> x; + if (x == 2) { + cout << "NO" << endl; + } else { + if (x % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int x; + cin >> x; + if (x == 2) { + cout << "NO" << endl; + } else { + if (x % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + string a, b, c; + cin >> a >> b >> c; + bool nan = 0; + if (a != b && a != c && b == c) { + if (a[0] == 'p' && b[0] == 'r') { nan = 1; } + if (a[0] == 'r' && b[0] == 's') { nan = 1; } + if (a[0] == 's' && b[0] == 'p') { nan = 1; } + if (nan) { + cout << "F" << endl; + return 0; + } + } + if (a != b && c != b && a == c) { + if (b[0] == 'p' && a[0] == 'r') { nan = 1; } + if (b[0] == 'r' && a[0] == 's') { nan = 1; } + if (b[0] == 's' && a[0] == 'p') { nan = 1; } + if (nan) { + cout << "M" << endl; + return 0; + } + } + if (c != b && a != c && b == a) { + if (c[0] == 'p' && b[0] == 'r') { nan = 1; } + if (c[0] == 'r' && b[0] == 's') { nan = 1; } + if (c[0] == 's' && b[0] == 'p') { nan = 1; } + if (nan) { + cout << "S" << endl; + return 0; + } + } + cout << "?" << endl; +} +int main() { + int n; + cin >> n; + n = n * 2; + int flag = 0; + for (int i = 1; i <= n; i++) { + if (i * (i + 1) == n) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + n = n * 2; + int flag = 0; + for (int i = 1; i <= n; i++) { + if (i * (i + 1) == n) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int w; + cin >> w; + if (w == 2) + cout << "NO" << endl; + else if (w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w == 2) + cout << "NO" << endl; + else if (w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int i, j, k, l, p = 0, q = 0, r; + string a, b, c; + cin >> a >> b >> c; + if (b[0] != b[2]) { + cout << "NO" << endl; + return 0; + } + for (i = 0; i < 3; i++) { + if (a[i] == 'X') p++; + } + for (j = 0; j < 3; j++) { + if (c[j] == 'X') q++; + } + if (p != q) { + cout << "NO" << endl; + return 0; + } + for (i = 0, j = 2; i < 3; i++, j--) { + if (a[i] != c[j]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int i, j, k, l, p = 0, q = 0, r; + string a, b, c; + cin >> a >> b >> c; + if (b[0] != b[2]) { + cout << "NO" << endl; + return 0; + } + for (i = 0; i < 3; i++) { + if (a[i] == 'X') p++; + } + for (j = 0; j < 3; j++) { + if (c[j] == 'X') q++; + } + if (p != q) { + cout << "NO" << endl; + return 0; + } + for (i = 0, j = 2; i < 3; i++, j--) { + if (a[i] != c[j]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char pr, ls = 'a', nx; + int c = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> nx; + if (j == m - 1) { + ls = nx; + } else if (j == 0) { + if (nx == ls) { + c++; + cout << "NO\n"; + break; + } + pr = nx; + } + if (j != 0) { + if (pr != nx) { + c++; + cout << "NO\n"; + break; + } + } + } + if (c != 0) break; + } + if (c == 0) { cout << "YES\n"; } +} +int main() { + int n; + cin >> n; + if (n % 2 == 0 && n >= 4) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0 && n >= 4) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +string a, b, c; +int main() { + cin >> a >> b >> c; + if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +string a, b, c; +int main() { + cin >> a >> b >> c; + if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + double y = sqrt(8 * n + 1); + if (y - (int)y == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +char x[101][101]; +int m, n; +set s; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> x[i][j]; + if (x[i][j] != x[i][j - 1] && j != 1) { + cout << "NO\n"; + return 0; + } + s.insert(x[i][j]); + } + if (i != 1) { + if (x[i][1] == x[i - 1][1]) { + cout << "NO\n"; + return 0; + } + } + } + if (s.size() > 10) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + return 0; +} +char x[101][101]; +int m, n; +set s; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> x[i][j]; + if (x[i][j] != x[i][j - 1] && j != 1) { + cout << "NO\n"; + return 0; + } + s.insert(x[i][j]); + } + if (i != 1) { + if (x[i][1] == x[i - 1][1]) { + cout << "NO\n"; + return 0; + } + } + } + if (s.size() > 10) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + return 0; +} +int main() { + int a; + cin >> a; + if (a == 2 || a % 2 == 1) { + cout << "NO" + << "\n"; + return 0; + } else + cout << "YES" + << "\n"; + return 0; +} +int main() { + int a; + cin >> a; + if (a == 2 || a % 2 == 1) { + cout << "NO" + << "\n"; + return 0; + } else + cout << "YES" + << "\n"; + return 0; +} +int main() { + char mp[5][5]; + for (int i = 0; i < 3; i++) { gets(mp[i]); } + int flag = 1; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 3; j++) { + if (mp[i][j] != mp[2 - i][2 - j]) { + flag = 0; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char mp[5][5]; + for (int i = 0; i < 3; i++) { gets(mp[i]); } + int flag = 1; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 3; j++) { + if (mp[i][j] != mp[2 - i][2 - j]) { + flag = 0; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) + cout << "YES\n"; + else { + cout << "NO\n"; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w % 2 == 0 && w != 2) + cout << "YES\n"; + else { + cout << "NO\n"; + } + return 0; +} +int main() { + vector table; + for (size_t i = 0; i < 3; ++i) { + string row; + cin >> row; + table.push_back(row); + } + for (size_t i = 0; i < 3; ++i) { + for (size_t j = 0; j < 3; ++j) { + if (table[i][j] != table[3 - i - 1][3 - j - 1]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int n, m; +char ch1, ch2; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> ch1; + if (ch2 == ch1 && i != 1) { + cout << "NO\n"; + return 0; + } + for (int j = 2; j <= m; j++) { + cin >> ch2; + if (ch1 != ch2) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int main() { + string cmd; + int ans = 0, people_cnt = 0; + while (getline(cin, cmd)) { + if (cmd[0] == '+') + people_cnt++; + else if (cmd[0] == '-') + people_cnt--; + else { + int idx = 0; + while (cmd[idx] != ':') idx++; + ans += (int)cmd.substr(idx + 1).size() * people_cnt; + } + cerr << cmd << " " << ans << endl; + } + cout << ans << endl; + return 0; +} +const int maxs = 100 + 10; +char s[maxs]; +int k, ans; +int main() { + while (gets(s)) { + if (s[0] == '+') { + k++; + } else if (s[0] == '-') { + k--; + } else { + int t = 0; + while (s[t] != ':') { t++; } + ans += k * (strlen(s) - t - 1); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long w; + cin >> w; + if (w == 2) { + cout << "NO" << endl; + } else if (w % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long w; + cin >> w; + if (w == 2) { + cout << "NO" << endl; + } else if (w % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int n, m, l = 0, k = 0; + cin >> n >> m; + string s[n]; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + for (int j = 0; j < m - 1; j++) { + if (a[j] != a[j + 1]) { l = 1; } + } + s[i] = a; + } + if (l == 1) { + cout << "NO" << endl; + } else { + for (int j = 0; j < n - 1; j++) { + if (s[j] == s[j + 1]) { k = 1; } + } + if (k == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } +} +int main() { + string s; + set Q; + int ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + string ss = s.substr(1, s.size()); + Q.insert(ss); + } + if (s[0] == '-') { + string ss = s.substr(1, s.size()); + Q.erase(ss); + } else { + bool flag = false; + int t = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == ':') flag = true; + if (flag) t++; + } + if (t) t--; + ans += (t * Q.size()); + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + set Q; + int ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + string ss = s.substr(1, s.size()); + Q.insert(ss); + } + if (s[0] == '-') { + string ss = s.substr(1, s.size()); + Q.erase(ss); + } else { + bool flag = false; + int t = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == ':') flag = true; + if (flag) t++; + } + if (t) t--; + ans += (t * Q.size()); + } + } + cout << ans << endl; + return 0; +} +int checker(string a, string b) { + if (a == "rock" && b == "scissors") { + return 0; + } else if (a == "scissors" && b == "paper") { + return 0; + } else if (a == "paper" && b == "rock") { + return 0; + } else if (b == "rock" && a == "scissors") { + return 1; + } else if (b == "scissors" && a == "paper") { + return 1; + } else if (b == "paper" && a == "rock") { + return 1; + } + return 2; +} +int main() { + string F, M, S; + cin >> F >> M >> S; + int f = -1; + if (checker(F, M) == 0) { + if (checker(F, S) == 0) { + cout << "F" << endl; + return 0; + } + if (checker(F, S) == 1) { + if (checker(S, M) == 1) { + cout << "?" << endl; + return 0; + } + cout << "S" << endl; + return 0; + } + if (checker(F, S) == 2) { + cout << "?" << endl; + return 0; + } + } + if (checker(F, M) == 1) { + if (checker(M, S) == 0) { + cout << "M" << endl; + return 0; + } + if (checker(M, S) == 1) { + if (checker(S, F) == 1) { + cout << "?" << endl; + return 0; + } + cout << "S" << endl; + return 0; + } + if (checker(M, S) == 2) { + cout << "?" << endl; + return 0; + } + } + if (checker(F, M) == 2) { + if (checker(F, S) == 0) { + cout << "?" << endl; + return 0; + } + if (checker(F, S) == 1) { + cout << "S" << endl; + return 0; + } + if (checker(F, S) == 2) { + cout << "?" << endl; + return 0; + } + } + return 0; +} +int main() { + int w; + cin >> w; + if (w > 2 && w % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string s1, s2, s3; + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +long long n, m, a, b, x, ff, l, r, cnt, ans; +vector v, f, res; +string s1, s2; +long long used[1001]; +int main() { + cin >> n >> m; + char ch, arr[n + 1][n + 1]; + set st; + for (int i = 1; i <= n; i++) { + int j; + for (j = 1; j <= m; j++) { + cin >> ch; + st.insert(ch); + } + x = *st.begin(); + v.push_back(x); + if (st.size() == 1) + a = 1; + else + b = 1; + st.clear(); + } + if (b == 1) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < v.size() - 1; i++) + if (v[i] == v[i + 1]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; +} +int main() { + string s; + set l; + int ans = 0; + while (getline(cin, s)) { + if (s == "") break; + if (s[0] == '+') { + l.insert(s.substr(1)); + } else if (s[0] == '-') { + l.erase(s.substr(1)); + } else { + int i = 0; + while (s[i] != ':') i++; + ans += ((int)s.size() - i - 1) * l.size(); + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + set l; + int ans = 0; + while (getline(cin, s)) { + if (s == "") break; + if (s[0] == '+') { + l.insert(s.substr(1)); + } else if (s[0] == '-') { + l.erase(s.substr(1)); + } else { + int i = 0; + while (s[i] != ':') i++; + ans += ((int)s.size() - i - 1) * l.size(); + } + } + cout << ans << endl; + return 0; +} +int main() { + int w; + cin >> w; + int x = w % 2; + if (x == 0 && w != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int w; + cin >> w; + int x = w % 2; + if (x == 0 && w != 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string s; +int n, ans; +int main() { + char c = getchar(); + while (c != EOF) { + s = ""; + while (c != '\n') s += c, c = getchar(); + if (s[0] == '+') + ++n; + else if (s[0] == '-') + --n; + else { + int i = 0; + while (s[i] != ':') ++i; + ans += n * (s.size() - i - 1); + } + c = getchar(); + } + cout << ans << endl; + return 0; +} +string s; +int n, ans; +int main() { + char c = getchar(); + while (c != EOF) { + s = ""; + while (c != '\n') s += c, c = getchar(); + if (s[0] == '+') + ++n; + else if (s[0] == '-') + --n; + else { + int i = 0; + while (s[i] != ':') ++i; + ans += n * (s.size() - i - 1); + } + c = getchar(); + } + cout << ans << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w != 2 && w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w != 2 && w % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, c = 0, c1 = 0; + cin >> n; + string s, d, d1; + for (int i = 1; i <= n; i++) { + cin >> s; + if (i == 1) { d = s; } + if (s == d) + c++; + else + d1 = s; + if (s == d1) c1++; + } + if (c > c1) + cout << d << endl; + else + cout << d1 << endl; + return 0; +} +string st[110]; +int main() { + int n, m; + cin >> n >> m; + bool flg = false; + for (int i = 1; i <= n; i++) { + cin >> st[i]; + for (int j = 1; j < st[i].size(); j++) { + if (st[i][j] != st[i][j - 1] || i > 1 && st[i][j] == st[i - 1][j]) { + flg = true; + break; + } + } + } + if (flg) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int w; + cin >> w; + if (w <= 2) + cout << "NO" << endl; + else { + if (w % 2 != 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } +} +int main() { + int w; + cin >> w; + if (w <= 2) + cout << "NO" << endl; + else { + if (w % 2 != 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } +} +int n, maxn = 0; +string s, temp; +map m; +int main() { + cin >> n; + m.clear(); + while (n--) { + cin >> s; + m[s]++; + } + map::iterator it; + for (it = m.begin(); it != m.end(); it++) { + if (it->second > maxn) { + maxn = it->second; + temp = it->first; + } + } + cout << temp << endl; + return 0; +} +char c[1000000]; +int main() { + int s = 0, total = 0, i, j, k, n, m; + while (gets(c + 1)) { + if (c[1] == '+') s++; + if (c[1] == '-') s--; + if (c[1] - '+' && c[1] - '-') { + int t = 1; + while (c[t] - ':') t++; + total += ((strlen(c + 1) - t) * s); + } + } + cout << total << endl; + return 0; +} +char c[1000000]; +int main() { + int s = 0, total = 0, i, j, k, n, m; + while (gets(c + 1)) { + if (c[1] == '+') s++; + if (c[1] == '-') s--; + if (c[1] - '+' && c[1] - '-') { + int t = 1; + while (c[t] - ':') t++; + total += ((strlen(c + 1) - t) * s); + } + } + cout << total << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n & 1 || n == 0 || n == 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n; + cin >> n; + if (n & 1 || n == 0 || n == 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + string s; + int p = 0; + int d = 0; + while (getline(cin, s)) { + if (s[0] == '+') + p++; + else if (s[0] == '-') + p--; + else + d += p * (s.size() - 1 - s.find(":")); + } + cout << d << endl; + return 0; +} +int main() { + string s; + int p = 0; + int d = 0; + while (getline(cin, s)) { + if (s[0] == '+') + p++; + else if (s[0] == '-') + p--; + else + d += p * (s.size() - 1 - s.find(":")); + } + cout << d << endl; + return 0; +} +int main() { + string Team, Win; + int n, Goals = 0; + cin >> n; + while (n--) { + if (Goals != 0) { + cin >> Team; + if (Team == Win) { + Goals++; + } else { + Goals--; + } + } else + { + cin >> Win; + Goals = 1; + } + } + cout << Win << endl; + return 0; +} +int main() { + string a[5]; + int i, r = 0, s = 0, p = 0; + for (i = 0; i < 3; i++) { + cin >> a[i]; + if (a[i] == "rock") r++; + if (a[i] == "paper") p++; + if (a[i] == "scissors") s++; + } + if (r == 1 && s == 2) { + if (a[0] == "rock") cout << "F" << endl; + if (a[1] == "rock") cout << "M" << endl; + if (a[2] == "rock") cout << "S" << endl; + } else if (s == 1 && p == 2) { + if (a[0] == "scissors") cout << "F" << endl; + if (a[1] == "scissors") cout << "M" << endl; + if (a[2] == "scissors") cout << "S" << endl; + } else if (p == 1 && r == 2) { + if (a[0] == "paper") cout << "F" << endl; + if (a[1] == "paper") cout << "M" << endl; + if (a[2] == "paper") cout << "S" << endl; + } else + cout << "?" << endl; + return 0; +} +char ch[105]; +int main() { + int ans = 0; + int sum = 0; + while (gets(ch)) { + int byte = 0, flag = 0; + if (ch[0] == '+') + sum++; + else if (ch[0] == '-') + sum--; + else { + int len = strlen(ch); + for (int i = 0; i < len; i++) { + if (flag) byte++; + if (ch[i] == ':') flag = 1; + } + } + ans += byte * sum; + } + cout << ans << endl; + return 0; +} +int main() { + bool iso = true; + char chrColor; + int n, m, color, perColor, perRowColor; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> chrColor; + color = chrColor - '0'; + if (color > 9 || color < 0) { + iso = false; + break; + } + if (j != 0 && perColor != color) { + iso = false; + break; + } + perColor = color; + } + if (i != 0 && perColor == perRowColor) { iso = false; } + perRowColor = perColor; + } + cout << (iso ? "YES" : "NO") << endl; + return 0; +} +int main() { + bool iso = true; + char chrColor; + int n, m, color, perColor, perRowColor; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> chrColor; + color = chrColor - '0'; + if (color > 9 || color < 0) { + iso = false; + break; + } + if (j != 0 && perColor != color) { + iso = false; + break; + } + perColor = color; + } + if (i != 0 && perColor == perRowColor) { iso = false; } + perRowColor = perColor; + } + cout << (iso ? "YES" : "NO") << endl; + return 0; +} +const long long N = 2e5 + 5; +int n; +int a[1001][1001], x; +string s; +map mm; +void solve() { + cin >> n; + int mx = 0; + string ans; + for (int i = 0; i < n; i++) { + cin >> s; + mm[s]++; + if (mx < mm[s]) { + mx = mm[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + int T = 1; + for (int i = 0; i < T; i++) { solve(); } + return 0; +} +const long long N = 2e5 + 5; +int n; +int a[1001][1001], x; +string s; +map mm; +void solve() { + cin >> n; + int mx = 0; + string ans; + for (int i = 0; i < n; i++) { + cin >> s; + mm[s]++; + if (mx < mm[s]) { + mx = mm[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + int T = 1; + for (int i = 0; i < T; i++) { solve(); } + return 0; +} +map gesture; +int main() { + gesture["rock"] = "scissors"; + gesture["scissors"] = "paper"; + gesture["paper"] = "rock"; + string f, m, s; + cin >> f >> m >> s; + if (gesture[f] == m && gesture[f] == s) + cout << "F" << endl; + else if (gesture[m] == f && gesture[m] == s) + cout << "M" << endl; + else if (gesture[s] == f && gesture[s] == m) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +map gesture; +int main() { + gesture["rock"] = "scissors"; + gesture["scissors"] = "paper"; + gesture["paper"] = "rock"; + string f, m, s; + cin >> f >> m >> s; + if (gesture[f] == m && gesture[f] == s) + cout << "F" << endl; + else if (gesture[m] == f && gesture[m] == s) + cout << "M" << endl; + else if (gesture[s] == f && gesture[s] == m) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +string s; +int active = 0; +long long ans = 0; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') { + ++active; + } else if (s[0] == '-') { + --active; + } else { + for (int i = 0; i <= s.length() - 1; ++i) { + if (s[i] == ':') { + ans += active * (s.length() - i - 1); + break; + } + } + } + } + cout << ans << "\n"; + return 0; +} +string s; +int active = 0; +long long ans = 0; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') { + ++active; + } else if (s[0] == '-') { + --active; + } else { + for (int i = 0; i <= s.length() - 1; ++i) { + if (s[i] == ':') { + ans += active * (s.length() - i - 1); + break; + } + } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + char tmp; + cin >> n >> m; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 1; s[j]; j++) { + if (s[0] != s[j]) { + cout << "NO" << endl; + return 0; + } + } + if (i != 0 && tmp == s[0]) { + cout << "NO" << endl; + return 0; + } + tmp = s[0]; + } + cout << "YES" << endl; +} +int n, maxn; +map s; +string answer, S686; +void M249(int n) { + while (n--) { + cin >> S686; + s[S686]++; + if (maxn < s[S686]) { + maxn = s[S686]; + answer = S686; + } + } + cout << answer << endl; +} +int main() { + cin >> n; + M249(n); + return 0; +} +set q; +int main() { + int total = 0; + string s; + while (1) { + getline(cin, s); + if (s.size() == 0) break; + if (s[0] == '-') { + s = s.substr(1); + q.erase(s); + } else if (s[0] == '+') { + s = s.substr(1); + q.insert(s); + } else { + string name = ""; + for (int i(0); i < (s.size()); i++) + if (s[i] == ':') { + name = s.substr(0, i); + s = s.substr(i + 1); + break; + } + total += s.size() * q.size(); + } + } + cout << total << endl; + return 0; +} +set q; +int main() { + int total = 0; + string s; + while (1) { + getline(cin, s); + if (s.size() == 0) break; + if (s[0] == '-') { + s = s.substr(1); + q.erase(s); + } else if (s[0] == '+') { + s = s.substr(1); + q.insert(s); + } else { + string name = ""; + for (int i(0); i < (s.size()); i++) + if (s[i] == ':') { + name = s.substr(0, i); + s = s.substr(i + 1); + break; + } + total += s.size() * q.size(); + } + } + cout << total << endl; + return 0; +} +int main() { + int w; + cin >> w; + cout << (w & 1 || w == 2 ? "NO" : "YES") << endl; + return 0; +} +int main() { + int w; + cin >> w; + cout << (w & 1 || w == 2 ? "NO" : "YES") << endl; + return 0; +} +const int SIZE = 110; +string M[SIZE]; +int main() { + int t, i, j, k, n, m; + cin >> m >> n; + for (i = 0; i < m; i++) cin >> M[i]; + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (j + 1 < n && M[i][j] != M[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + if (i + 1 < m && M[i][j] == M[i + 1][j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +const int SIZE = 110; +string M[SIZE]; +int main() { + int t, i, j, k, n, m; + cin >> m >> n; + for (i = 0; i < m; i++) cin >> M[i]; + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (j + 1 < n && M[i][j] != M[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + if (i + 1 < m && M[i][j] == M[i + 1][j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int n, maxn; +map s; +string ans, k; +int main() { + cin >> n; + while (n--) { + cin >> k; + s[k]++; + if (s[k] > maxn) { + maxn = s[k]; + ans = k; + } + } + cout << ans << endl; + ; +} +int main() { + string commands; + int person = 0, mark_idx, send_size = 0; + while (getline(cin, commands)) { + if (commands[0] == '+') + person++; + else if (commands[0] == '-') + person--; + else { + mark_idx = commands.find(':'); + send_size += (commands.size() - mark_idx - 1) * person; + } + } + cout << send_size << endl; +} +int main() { + string commands; + int person = 0, mark_idx, send_size = 0; + while (getline(cin, commands)) { + if (commands[0] == '+') + person++; + else if (commands[0] == '-') + person--; + else { + mark_idx = commands.find(':'); + send_size += (commands.size() - mark_idx - 1) * person; + } + } + cout << send_size << endl; +} +int main() { + int n, m; + string a[110]; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + for (int j = 1; j < m; j++) { + if (a[i][j] != a[i][j - 1]) { + cout << "NO\n"; + return 0; + } + } + } + for (int j = 0; j < m; j++) { + for (int i = 1; i < n; i++) { + if (a[i][j] == a[i - 1][j]) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + string s, t, u; + cin >> s >> t >> u; + if (s == t && s == u) { + cout << "?\n"; + return 0; + } + if (s != t && s != u && t != u) { + cout << "?\n"; + return 0; + } + string r; + r.push_back(s[0]); + r.push_back(t[0]); + r.push_back(u[0]); + sort(r.begin(), r.end()); + if (r == "rrs" || r == "ppr" || r == "pss") { + cout << "?\n"; + return 0; + } + char box = r[0] ^ r[1] ^ r[2]; + if (s[0] == box) cout << "F\n"; + if (t[0] == box) cout << "M\n"; + if (u[0] == box) cout << "S\n"; + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +int main() { + int w; + cin >> w; + (w > 2 && w % 2 == 0) ? cout << "YES\n" : cout << "NO\n"; + return 0; +} +int main() { + int w; + cin >> w; + (w > 2 && w % 2 == 0) ? cout << "YES\n" : cout << "NO\n"; + return 0; +} +string s; +int main() { + int n, m, c, i, flag; + char k; + cin >> n >> m; + flag = 0; + for (i = 0; i < n; i++) { + cin >> s; + c = count(s.begin(), s.end(), s[0]); + if (c != s.size()) { flag = 1; } + if (k == s[0] && i > 0) flag = 1; + k = s[0]; + } + if (flag == 0) + cout << "YES"; + else + cout << "NO"; + cout << endl; + return 0; +} +int main() { + int q; + vector v; + string s, a, b; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> s; + if (i == 0) + a = s; + else if (i > 0 && s != a) + b = s; + v.push_back(s); + } + int k = count(v.begin(), v.end(), a); + int j = count(v.begin(), v.end(), b); + if (k > j) + cout << a << endl; + else + cout << b << endl; + return 0; +} +int main() { + string s; + int k = 0, now = 0; + ; + while (getline(cin, s)) { + if (s[0] == '-' || s[0] == '+') { + if (s[0] == '-') { + now--; + } else { + now++; + } + continue; + } else { + bool p = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + if (s[i] == ':') { + k += (len - i - 1) * now; + break; + } + } + } + } + cout << k << endl; + return 0; +} +int main() { + string s; + int k = 0, now = 0; + ; + while (getline(cin, s)) { + if (s[0] == '-' || s[0] == '+') { + if (s[0] == '-') { + now--; + } else { + now++; + } + continue; + } else { + bool p = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + if (s[i] == ':') { + k += (len - i - 1) * now; + break; + } + } + } + } + cout << k << endl; + return 0; +} +short n, m; +char flag[100][100]; +int main() { + cin >> n >> m >> flag[0][0]; + for (int i = 1; i < m; ++i) { + cin >> flag[0][i]; + if (flag[0][i] != flag[0][i - 1]) { + cout << "NO" << endl; + return 0; + } + } + for (int i = 1; i < n; ++i) { + cin >> flag[i][0]; + for (int j = 1; j < m; ++j) { + cin >> flag[i][j]; + if (flag[i][j] != flag[i][j - 1] || flag[i][j] == flag[i - 1][j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int a[100]; + while (cin >> a[0] >> a[1] >> a[2] >> a[3]) { + sort(a, a + 4); + if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) { + cout << "TRIANGLE" << endl; + } else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + map mmm; + string b; + int maxx = -1; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + mmm[a]++; + if (mmm[a] > maxx) { + b = a; + maxx = mmm[a]; + } + } + cout << b << endl; + } + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +char c[(int)1e2 + 5]; +int n, ans; +int mygets(char *s) { + memset(s, 0, sizeof(s)); + char c; + int i = 0; + while ((c = getchar()) != '\n') { s[i] = c, i++; } + return i; +} +int main() { + n = 0; + int me = 0, cnt = 0, ok = 0; + while (gets(c)) { + if (c[0] == '+') + n++; + else if (c[0] == '-') + n--; + else { + ok = 0, cnt = 0; + for (int i = 0; i < strlen(c); i++) { + if (c[i] == ':') + ok = 1; + else if (ok == 1) + cnt++; + } + ans += n * cnt; + } + } + cout << ans << endl; + return 0; +} +char c[(int)1e2 + 5]; +int n, ans; +int mygets(char *s) { + memset(s, 0, sizeof(s)); + char c; + int i = 0; + while ((c = getchar()) != '\n') { s[i] = c, i++; } + return i; +} +int main() { + n = 0; + int me = 0, cnt = 0, ok = 0; + while (gets(c)) { + if (c[0] == '+') + n++; + else if (c[0] == '-') + n--; + else { + ok = 0, cnt = 0; + for (int i = 0; i < strlen(c); i++) { + if (c[i] == ':') + ok = 1; + else if (ok == 1) + cnt++; + } + ans += n * cnt; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, l = 0, k = 0; + cin >> n >> m; + string s[n]; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + for (int j = 0; j < m - 1; j++) { + if (a[j] != a[j + 1]) { l = 1; } + } + s[i] = a; + } + if (l == 1) { + cout << "NO" << endl; + } else { + for (int j = 0; j < n - 1; j++) { + if (s[j] == s[j + 1]) { k = 1; } + } + if (k == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } +} +int main() { + int n, m, l = 0, k = 0; + cin >> n >> m; + string s[n]; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + for (int j = 0; j < m - 1; j++) { + if (a[j] != a[j + 1]) { l = 1; } + } + s[i] = a; + } + if (l == 1) { + cout << "NO" << endl; + } else { + for (int j = 0; j < n - 1; j++) { + if (s[j] == s[j + 1]) { k = 1; } + } + if (k == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } +} +const int mod = 100000000 + 7; +vector v; +int n, ctr = 0, temp = 0, wt; +string s; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + v.push_back(s); + } + for (int i = 0; i < v.size(); i++) { + for (int j = 0; j < v.size(); j++) { + if (v[i] == v[j]) ctr++; + if (j == n - 1) { + if (temp <= ctr) { + temp = ctr; + wt = i; + } + ctr = 0; + } + } + } + cout << v[wt] << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || a + b > d || a + c > d || b + c > d) + cout << "TRIANGLE" << endl; + else if (a + b == c || a + b == d || a + c == d || b + c == d) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || a + b > d || a + c > d || b + c > d) + cout << "TRIANGLE" << endl; + else if (a + b == c || a + b == d || a + c == d || b + c == d) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +long long n, m, a, b, x, cnt, ans; +string s1 = "rock", s2 = "paper", s3 = "scissors", s4; +map mp; +vector V; +int main() { + for (int i = 1; i <= 3; i++) { + cin >> s4; + mp[s4]++; + V.push_back(s4); + } + if (mp[s1] == 2 && mp[s2] == 1) { + for (int i = 0; i < V.size(); i++) { + if (V[i] == s2) { + if (i == 0) + cout << "F" << endl; + else if (i == 1) + cout << "M" << endl; + else + cout << "S" << endl; + return 0; + } + } + } else if (mp[s3] == 2 && mp[s1] == 1) { + for (int i = 0; i < V.size(); i++) { + if (V[i] == s1) { + if (i == 0) + cout << "F" << endl; + else if (i == 1) + cout << "M" << endl; + else + cout << "S" << endl; + return 0; + } + } + } else if (mp[s2] == 2 && mp[s3] == 1) { + for (int i = 0; i < V.size(); i++) { + if (V[i] == s3) { + if (i == 0) + cout << "F" << endl; + else if (i == 1) + cout << "M" << endl; + else + cout << "S" << endl; + return 0; + } + } + } else + cout << "?" << endl; +} +int main() { + string s; + set Q; + int ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + string ss = s.substr(1, s.size()); + Q.insert(ss); + } + if (s[0] == '-') { + string ss = s.substr(1, s.size()); + Q.erase(ss); + } else { + bool flag = false; + int t = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == ':') flag = true; + if (flag) t++; + } + if (t) t--; + ans += (t * Q.size()); + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + set Q; + int ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + string ss = s.substr(1, s.size()); + Q.insert(ss); + } + if (s[0] == '-') { + string ss = s.substr(1, s.size()); + Q.erase(ss); + } else { + bool flag = false; + int t = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == ':') flag = true; + if (flag) t++; + } + if (t) t--; + ans += (t * Q.size()); + } + } + cout << ans << endl; + return 0; +} +string s[110]; +string a, b; +int n, score1, score2; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> s[i]; + a = s[1]; + for (int i = 1; i <= n; i++) { + if (s[i] == a) + score1++; + else { + b = s[i]; + score2++; + } + } + if (score1 > score2) + cout << a << endl; + else if (score2 > score1) + cout << b << endl; + return 0; +} +string s[110]; +string a, b; +int n, score1, score2; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> s[i]; + a = s[1]; + for (int i = 1; i <= n; i++) { + if (s[i] == a) + score1++; + else { + b = s[i]; + score2++; + } + } + if (score1 > score2) + cout << a << endl; + else if (score2 > score1) + cout << b << endl; + return 0; +} +int main() { + int n, m, i, j, a[105]; + char x; + cin >> n >> m; + for (i = 0; i < n; i++) { + set s; + s.clear(); + for (j = 0; j < m; j++) { + cin >> x; + s.insert(x - '0'); + } + if (s.size() > 1) break; + a[i] = x - '0'; + } + if (i < n) + cout << "NO" << endl; + else { + int flag = 1; + for (i = 1; i < n - 1; i++) { + if (a[i] == a[i - 1] || a[i] == a[i + 1]) { + flag = 0; + break; + } + } + cout << (flag ? "YES" : "NO") << endl; + } + return 0; +} +int main() { + int xx[6]; + int yy[4]; + cin >> xx[0] >> xx[1] >> xx[2] >> xx[3]; + sort(xx, xx + 4); + int b = 0, c = 0, d = 0; + for (int i = 0; i < 4; i++) { + b = 0; + for (int j = 0; j < 4; j++) { + if (j != i) { yy[b++] = xx[j]; } + } + if (yy[0] + yy[1] > yy[2]) c = 1; + if (yy[0] + yy[1] == yy[2]) d = 1; + } + if (c == 1) cout << "TRIANGLE" << endl; + if (c == 0 && d == 1) cout << "SEGMENT" << endl; + if (c == 0 && d == 0) cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int xx[6]; + int yy[4]; + cin >> xx[0] >> xx[1] >> xx[2] >> xx[3]; + sort(xx, xx + 4); + int b = 0, c = 0, d = 0; + for (int i = 0; i < 4; i++) { + b = 0; + for (int j = 0; j < 4; j++) { + if (j != i) { yy[b++] = xx[j]; } + } + if (yy[0] + yy[1] > yy[2]) c = 1; + if (yy[0] + yy[1] == yy[2]) d = 1; + } + if (c == 1) cout << "TRIANGLE" << endl; + if (c == 0 && d == 1) cout << "SEGMENT" << endl; + if (c == 0 && d == 0) cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int n, x = 0; + cin >> n; + map m; + string s; + for (int i = 0; i < n; ++i) { + cin >> s; + m[s]++; + } + for (map::iterator it = m.begin(); it != m.end(); ++it) { + if (it->second > x) { + s = it->first; + x = it->second; + } + } + cout << s << endl; + return 0; +} +int main() { + int n, x = 0; + cin >> n; + map m; + string s; + for (int i = 0; i < n; ++i) { + cin >> s; + m[s]++; + } + for (map::iterator it = m.begin(); it != m.end(); ++it) { + if (it->second > x) { + s = it->first; + x = it->second; + } + } + cout << s << endl; + return 0; +} +int main() { + char s1[101 * 101 * 101] = {}; + int i = 1, j, k, s = 0, t = 0; + while (gets(s1)) { + if (s1[0] == '+') + t++; + else if (s1[0] == '-') + t--; + else { + j = 0; + while (s1[j] - ':') j++; + s = s + (strlen(s1 + 1) - j) * t; + } + } + cout << s << endl; + return 0; +} +int main() { + char s1[101 * 101 * 101] = {}; + int i = 1, j, k, s = 0, t = 0; + while (gets(s1)) { + if (s1[0] == '+') + t++; + else if (s1[0] == '-') + t--; + else { + j = 0; + while (s1[j] - ':') j++; + s = s + (strlen(s1 + 1) - j) * t; + } + } + cout << s << endl; + return 0; +} +int main() { + int n, m; + char mat[105][105]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> mat[i][j]; } + } + int anomalyFound = 0; + for (int i = 1; i < n - 1; i++) { + if ((mat[i][0] == mat[i - 1][0]) || (mat[i][0] == mat[i + 1][0])) { + anomalyFound = 1; + break; + } + } + if (anomalyFound == 0) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (mat[i][0] != mat[i][j]) { + anomalyFound = 1; + break; + } + } + if (anomalyFound == 1) break; + } + } + if (anomalyFound == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int a[100]; + int i, j, k; + for (i = 0; i < 4; i++) cin >> a[i]; + int mark = 0; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (j != i) { + for (k = 0; k < 4; k++) { + if (k != i && k != j) { + if ((a[i] < a[j] + a[k]) && (a[i] > (int)fabs((a[j] - a[k])))) { + mark = 2; + break; + } else if (a[i] == a[j] + a[k]) { + mark = 1; + } + } + } + if (mark == 2) break; + } + } + if (mark == 2) break; + } + if (mark == 0) + cout << "IMPOSSIBLE\n"; + else if (mark == 1) + cout << "SEGMENT\n"; + else if (mark == 2) + cout << "TRIANGLE\n"; + return 0; +} +int main() { + int a[100]; + int i, j, k; + for (i = 0; i < 4; i++) cin >> a[i]; + int mark = 0; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (j != i) { + for (k = 0; k < 4; k++) { + if (k != i && k != j) { + if ((a[i] < a[j] + a[k]) && (a[i] > (int)fabs((a[j] - a[k])))) { + mark = 2; + break; + } else if (a[i] == a[j] + a[k]) { + mark = 1; + } + } + } + if (mark == 2) break; + } + } + if (mark == 2) break; + } + if (mark == 0) + cout << "IMPOSSIBLE\n"; + else if (mark == 1) + cout << "SEGMENT\n"; + else if (mark == 2) + cout << "TRIANGLE\n"; + return 0; +} +int main() { + long long int n, i; + cin >> n; + string s[n]; + set se; + long long int olds = se.size(); + for (i = 0; i < n; i++) { cin >> s[i]; } + sort(s, s + n); + long long int max = 0; + string ans = ""; + long long int co = 1; + if (n == 1) { + cout << s[0] << endl; + exit(0); + } + for (i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) { + co++; + if (i == n - 2) { + if (co >= max) { + max = co; + ans = s[i]; + } + } + } else { + if (co >= max) { + max = co; + ans = s[i]; + } + co = 1; + } + } + cout << ans << endl; +} +int main() { + long long int n, i; + cin >> n; + string s[n]; + set se; + long long int olds = se.size(); + for (i = 0; i < n; i++) { cin >> s[i]; } + sort(s, s + n); + long long int max = 0; + string ans = ""; + long long int co = 1; + if (n == 1) { + cout << s[0] << endl; + exit(0); + } + for (i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) { + co++; + if (i == n - 2) { + if (co >= max) { + max = co; + ans = s[i]; + } + } + } else { + if (co >= max) { + max = co; + ans = s[i]; + } + co = 1; + } + } + cout << ans << endl; +} +int main() { + string s, p; + int i, j, k, l, sum = 0; + int c1 = 0, c2 = 0, c3 = 0; + while (getline(cin, s)) { + if (s.size() == 0) break; + if (s[0] == '+') + c1++; + else if (s[0] == '-') + c1--; + else { + c3 = 0; + for (i = 0;; i++) { + c3++; + if (s[i] == ':') break; + } + sum += (s.size() - c3) * c1; + } + } + cout << sum << endl; + return 0; +} +int main() { + string s, p; + int i, j, k, l, sum = 0; + int c1 = 0, c2 = 0, c3 = 0; + while (getline(cin, s)) { + if (s.size() == 0) break; + if (s[0] == '+') + c1++; + else if (s[0] == '-') + c1--; + else { + c3 = 0; + for (i = 0;; i++) { + c3++; + if (s[i] == ':') break; + } + sum += (s.size() - c3) * c1; + } + } + cout << sum << endl; + return 0; +} +int t[4], a, b, c; +int main() { + cin >> t[1] >> t[2] >> t[3] >> t[0]; + sort(t, t + 4); + for (int i = 0; i < 2; i++) { + for (int j = i + 1; j < 3; j++) { + for (int k = j + 1; k < 4; k++) { + a = t[i], b = t[j], c = t[k]; + if (a + b > c and a + c > b and b + c > a) { + cout << "TRIANGLE" << '\n'; + return 0; + } + } + } + } + for (int i = 0; i < 2; i++) { + for (int j = i + 1; j < 3; j++) { + for (int k = j + 1; k < 4; k++) { + a = t[i], b = t[j], c = t[k]; + if (a + b == c or a + c == b or b + c == a) { + cout << "SEGMENT" << '\n'; + return 0; + } + } + } + } + cout << "IMPOSSIBLE" << '\n'; + return 0; +} +int matriz[110][110]; +int main() { + int n, m, suma; + string aux; + memset(matriz, -1, sizeof matriz); + cin >> n >> m; + getline(cin, aux); + for (int i = int(0); i < int(n); i++) { + getline(cin, aux); + for (int j = int(0); j < int(m); j++) { matriz[i][j] = int(aux[j]) - 48; } + } + int prom = 0; + bool pass = true; + for (int i = int(0); i < int(n); i++) { + suma = 0; + for (int j = int(0); j < int(m - 1); j++) { + if (matriz[i][j + 1] == matriz[i][j]) + pass = pass && true; + else + pass = false; + } + } + if (pass) { + for (int k = int(0); k < int(n - 1); k++) { + if (matriz[k][0] != matriz[k + 1][0]) + pass = pass && true; + else + pass = false; + } + } + if (pass) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int f = 0, s = 0; + string s1 = "", t = "", m = ""; + for (int i = 0; i < n; i++) { + cin >> s1; + if (t == "") { + f++; + t = s1; + } else if (s1 == t) { + f++; + } else if (m == "") { + m = s1; + s++; + } else { + s++; + } + } + if (f > s) { + cout << t << endl; + } else { + cout << m << endl; + } +} +int main() { + int n; + cin >> n; + int f = 0, s = 0; + string s1 = "", t = "", m = ""; + for (int i = 0; i < n; i++) { + cin >> s1; + if (t == "") { + f++; + t = s1; + } else if (s1 == t) { + f++; + } else if (m == "") { + m = s1; + s++; + } else { + s++; + } + } + if (f > s) { + cout << t << endl; + } else { + cout << m << endl; + } +} +int main() { + string comando; + int x = 0, y = 0; + while (getline(cin, comando)) { + if (comando[0] == '+') + x++; + else if (comando[0] == '-') + x--; + else + y = y + x * ((int)comando.size() - comando.find(':') - 1); + } + cout << y << endl; + return 0; +} +int main() { + long long a[4]; + cin >> a[0] >> a[1] >> a[2] >> a[3]; + sort(a, a + 4); + if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) { + cout << "TRIANGLE" << endl; + } else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) { + cout << "SEGMENT" << endl; + } else + cout << "IMPOSSIBLE" << endl; +} +int main() { + long long a[4]; + cin >> a[0] >> a[1] >> a[2] >> a[3]; + sort(a, a + 4); + if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) { + cout << "TRIANGLE" << endl; + } else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) { + cout << "SEGMENT" << endl; + } else + cout << "IMPOSSIBLE" << endl; +} +int main() { + string s[102]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + sort(s, s + n); + cout << s[n / 2] << endl; + return 0; +} +int main() { + string s[102]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + sort(s, s + n); + cout << s[n / 2] << endl; + return 0; +} +int main() { + int n = 0, cnt = 0, total = 0; + string str; + while (getline(cin, str)) { + if (str[0] == '+') + cnt++; + else if (str[0] == '-') + cnt--; + else { + int ln = str.size(); + for (int i = 1; i < ln; i++) { + if (str[i] == ':') n = n + (ln - i - 1) * cnt; + } + } + } + cout << n << endl; + return 0; +} +int main() { + int n = 0, cnt = 0, total = 0; + string str; + while (getline(cin, str)) { + if (str[0] == '+') + cnt++; + else if (str[0] == '-') + cnt--; + else { + int ln = str.size(); + for (int i = 1; i < ln; i++) { + if (str[i] == ':') n = n + (ln - i - 1) * cnt; + } + } + } + cout << n << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n; + cin >> n; + long long a[n]; + for (long long int i = 0; i < n; i++) cin >> a[i]; + long long ans; + if (a[0] % 2 == a[1] % 2) { + for (long long int i = 1; i < n - 1; i++) { + if (a[i] % 2 != a[i + 1] % 2) { + ans = i + 2; + break; + } + } + cout << ans << '\n'; + } else { + if (a[0] % 2 != a[2] % 2) + cout << 1 << '\n'; + else + cout << 2 << '\n'; + } + } + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +map m; +void solve() { + int n; + cin >> n; + int mx = 0; + string ans = ""; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + m[s]++; + if (m[s] > mx) { + mx = m[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +map m; +void solve() { + int n; + cin >> n; + int mx = 0; + string ans = ""; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + m[s]++; + if (m[s] > mx) { + mx = m[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int r, c, num; + char last = 'x'; + cin >> r >> c; + for (int i = 0; i < r; i++) { + int start; + string n; + cin >> n; + if (n[0] == last) { + cout << "NO" << endl; + return 0; + } else + last = n[0]; + for (int j = 1; j < c; j++) { + if (n[0] != n[j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int r, c, num; + char last = 'x'; + cin >> r >> c; + for (int i = 0; i < r; i++) { + int start; + string n; + cin >> n; + if (n[0] == last) { + cout << "NO" << endl; + return 0; + } else + last = n[0]; + for (int j = 1; j < c; j++) { + if (n[0] != n[j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n_participantes = 0, n = 0, n_bytes = 0; + string linha_chat; + while (getline(cin, linha_chat) && !cin.eof()) { + if (linha_chat[0] == '+') { + n_participantes++; + } else if (linha_chat[0] == '-') { + n_participantes--; + } else { + for (int x = 0; x < linha_chat.length(); x++) { + if (linha_chat[x] == ':') { + n = linha_chat.length() - (x + 1); + x = linha_chat.length(); + } + } + n_bytes += n * n_participantes; + } + } + cout << n_bytes << endl; +} +int main() { + int a[2000]; + int i, j, k, m, n, g, h; + while (cin >> n) { + j = k = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + j++; + g = i; + } else { + k++; + h = i; + } + } + if (j == 1) + cout << g + 1 << endl; + else + cout << h + 1 << endl; + } + return 0; +} +int main() { + string st; + int n = 0, sum = 0; + while (getline(cin, st)) { + if (st.size() == 0) break; + if (st[0] == '+') + n++; + else if (st[0] == '-') + n--; + else { + int cnt = 0; + for (int i = 0;; i++) { + cnt++; + if (st[i] == ':') break; + } + sum += (st.size() - cnt) * n; + } + } + cout << sum << endl; +} +int main() { + string st; + int n = 0, sum = 0; + while (getline(cin, st)) { + if (st.size() == 0) break; + if (st[0] == '+') + n++; + else if (st[0] == '-') + n--; + else { + int cnt = 0; + for (int i = 0;; i++) { + cnt++; + if (st[i] == ':') break; + } + sum += (st.size() - cnt) * n; + } + } + cout << sum << endl; +} +int main() { + int n, i, m = 0, m2 = 0, k = 0; + cin >> n; + int x[n]; + for (i = 1; i <= n; i++) { + cin >> x[i]; + if (x[i] % 2 == 0) { + m++; + } else { + m2++; + } + } + for (i = 1; i <= n; i++) { + if (m > m2) { + if (x[i] % 2 != 0) k = i; + } else { + if (x[i] % 2 == 0) k = i; + } + } + cout << k << endl; + return 0; +} +int main() { + int arr[4]; + for (int i = 0; i < 4; i++) { cin >> arr[i]; } + sort(arr, arr + 4); + if ((arr[0] + arr[1] > arr[2]) || (arr[1] + arr[2] > arr[3])) { + cout << "TRIANGLE" << endl; + } else if ((arr[0] + arr[1] == arr[2]) || (arr[1] + arr[2] == arr[3])) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int main() { + int arr[4]; + for (int i = 0; i < 4; i++) { cin >> arr[i]; } + sort(arr, arr + 4); + if ((arr[0] + arr[1] > arr[2]) || (arr[1] + arr[2] > arr[3])) { + cout << "TRIANGLE" << endl; + } else if ((arr[0] + arr[1] == arr[2]) || (arr[1] + arr[2] == arr[3])) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +map m; +void solve() { + int n; + cin >> n; + int mx = 0; + string ans = ""; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + m[s]++; + if (m[s] > mx) { + mx = m[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +const int MAX = 1e2 + 10; +int main() { + int n; + cin >> n; + int a, ans1 = 0, ans2 = 0, index1, index2; + for (int i = 0; i < n; i++) { + cin >> a; + if (a % 2 == 0) { + ans1++; + index1 = i; + } else { + ans2++; + index2 = i; + } + } + if (ans1 == 1) + cout << index1 + 1 << endl; + else + cout << index2 + 1 << endl; + return 0; +} +const int MX = 10005; +const int mod = 1000000007; +const long long inf = 1e18; +map mp; +int main() { + int n, m, i, j, k, x, y, z, tc, d; + char ch; + int cnt = 0, sm = 0; + string s, st; + while (getline(cin, s)) { + st = ""; + if (s[0] == '+') { + for (i = 1; i < s.size(); i++) st += s[i]; + if (!mp[st]) { + cnt++; + mp[st]++; + } + } else if (s[0] == '-') { + for (i = 1; i < s.size(); i++) st += s[i]; + if (mp[st]) { + cnt--; + mp[st]--; + } + } else { + int sz = s.size(); + for (i = 0; s[i] != ':'; i++) + ; + sz -= i; + sz--; + sm += (sz * cnt); + } + } + cout << sm << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, LastoddPos, LastevenPos, evenCount = 0; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a % 2) { + LastoddPos = i; + evenCount--; + } else { + LastevenPos = i; + evenCount++; + } + } + cout << (evenCount > 0 ? LastoddPos : LastevenPos) << endl; + return 0; +} +int main() { + int a, b, c, d; + int n[4]; + for (int i = 0; i < 4; i++) { cin >> n[i]; } + for (int i = 0; i < 3; i++) { + int max = i; + for (int j = i + 1; j < 4; j++) { + if (n[j] > n[max]) max = j; + } + int temp = n[max]; + n[max] = n[i]; + n[i] = temp; + } + if ((n[1] + n[2]) > n[0] || n[2] + n[3] > n[1]) + cout << "TRIANGLE" << endl; + else if ((n[1] + n[2]) == n[0] || n[2] + n[3] == n[1]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int a, b, c, d; + int n[4]; + for (int i = 0; i < 4; i++) { cin >> n[i]; } + for (int i = 0; i < 3; i++) { + int max = i; + for (int j = i + 1; j < 4; j++) { + if (n[j] > n[max]) max = j; + } + int temp = n[max]; + n[max] = n[i]; + n[i] = temp; + } + if ((n[1] + n[2]) > n[0] || n[2] + n[3] > n[1]) + cout << "TRIANGLE" << endl; + else if ((n[1] + n[2]) == n[0] || n[2] + n[3] == n[1]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int gx[] = {1, -1, 0, 0}; +int gy[] = {0, 0, 1, -1}; +int main() { + int n; + cin >> n; + map m; + string last; + string s2; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + m[s]++; + if (s != last) { s2 = last; } + last = s; + } + if (m[last] > m[s2]) { + cout << last << endl; + } else if (m[last] < m[s2]) { + cout << s2 << endl; + } else { + cout << last << endl; + } + return 0; +} +int gx[] = {1, -1, 0, 0}; +int gy[] = {0, 0, 1, -1}; +int main() { + int n; + cin >> n; + map m; + string last; + string s2; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + m[s]++; + if (s != last) { s2 = last; } + last = s; + } + if (m[last] > m[s2]) { + cout << last << endl; + } else if (m[last] < m[s2]) { + cout << s2 << endl; + } else { + cout << last << endl; + } + return 0; +} +int main() { + string s; + int num = 0, res = 0; + while (getline(cin, s)) { + if (s[0] == '+') + num++; + else if (s[0] == '-') + num--; + else { + int idx = 1; + while (s[idx - 1] != ':') idx++; + res += num * ((int)s.size() - idx); + } + } + cout << res << endl; + return 0; +} +int main() { + string s; + int num = 0, res = 0; + while (getline(cin, s)) { + if (s[0] == '+') + num++; + else if (s[0] == '-') + num--; + else { + int idx = 1; + while (s[idx - 1] != ':') idx++; + res += num * ((int)s.size() - idx); + } + } + cout << res << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + char c[a + 1][b + 1]; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { cin >> c[i][j]; } + } + for (int i = 0; i < a; i++) { + for (int j = 0; j < b - 1; j++) { + if (c[i][j] != c[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + } + } + for (int i = 0; i < a - 1; i++) { + for (int j = 0; j < b; j++) { + if (c[i][j] == c[i + 1][j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +int main() { + int a, b; + cin >> a >> b; + char c[a + 1][b + 1]; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { cin >> c[i][j]; } + } + for (int i = 0; i < a; i++) { + for (int j = 0; j < b - 1; j++) { + if (c[i][j] != c[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + } + } + for (int i = 0; i < a - 1; i++) { + for (int j = 0; j < b; j++) { + if (c[i][j] == c[i + 1][j]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +string s1, s2, tmp; +int cn1, cn2, n; +int main() { + cin >> n >> s1; + --n; + cn1++; + while (n--) { + cin >> s2; + if (s1 == s2) + cn1++; + else + cn2++, tmp = s2; + } + if (cn1 > cn2) + cout << s1 << endl; + else + cout << tmp << endl; + return 0; +} +string s1, s2, tmp; +int cn1, cn2, n; +int main() { + cin >> n >> s1; + --n; + cn1++; + while (n--) { + cin >> s2; + if (s1 == s2) + cn1++; + else + cn2++, tmp = s2; + } + if (cn1 > cn2) + cout << s1 << endl; + else + cout << tmp << endl; + return 0; +} +int main() { + int n, m; + char s[110][110]; + int flag = 1; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> s[i]; + for (int j = 0; j < m; j++) { + if (j && s[i][j] != s[i][j - 1]) flag = 0; + if (i && s[i][j] == s[i - 1][j]) flag = 0; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + char s[110][110]; + int flag = 1; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> s[i]; + for (int j = 0; j < m; j++) { + if (j && s[i][j] != s[i][j - 1]) flag = 0; + if (i && s[i][j] == s[i - 1][j]) flag = 0; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int arr[4], flag = 0; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + flag = max(arr[0] + arr[1] - arr[2], arr[1] + arr[2] - arr[3]); + puts(flag > 0 ? "TRIANGLE" : flag ? "IMPOSSIBLE" : "SEGMENT"); + return 0; +} +int main() { + int i, p, q = 0, n; + vector v; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p; + v.push_back(p); + } + p = 0; + for (i = 0; i < 3; i++) { + if (v[i] % 2 == 0) { p++; } + } + if (p > 1) { + for (i = 0; i < v.size(); i++) { + if (v[i] % 2 != 0) { + cout << i + 1 << endl; + break; + } + } + } else { + for (i = 0; i < v.size(); i++) { + if (v[i] % 2 == 0) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int main() { + int i, p, q = 0, n; + vector v; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p; + v.push_back(p); + } + p = 0; + for (i = 0; i < 3; i++) { + if (v[i] % 2 == 0) { p++; } + } + if (p > 1) { + for (i = 0; i < v.size(); i++) { + if (v[i] % 2 != 0) { + cout << i + 1 << endl; + break; + } + } + } else { + for (i = 0; i < v.size(); i++) { + if (v[i] % 2 == 0) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int local(char s[]) { + for (int i = 0; s[i]; ++i) { + if (s[i] == ':') { return i; } + } +} +int main() { + set vis; + char s[205]; + int ans = 0; + while (gets(s)) { + if (s[0] == '+') { + string tp = s + 1; + vis.insert(tp); + } else if (s[0] == '-') { + string tp = s + 1; + vis.erase(tp); + } else { + int st = local(s); + string tp(s, s + st); + if (vis.count(tp)) { ans += strlen(s + st + 1) * vis.size(); } + } + } + cout << ans << endl; + return 0; +} +int local(char s[]) { + for (int i = 0; s[i]; ++i) { + if (s[i] == ':') { return i; } + } +} +int main() { + set vis; + char s[205]; + int ans = 0; + while (gets(s)) { + if (s[0] == '+') { + string tp = s + 1; + vis.insert(tp); + } else if (s[0] == '-') { + string tp = s + 1; + vis.erase(tp); + } else { + int st = local(s); + string tp(s, s + st); + if (vis.count(tp)) { ans += strlen(s + st + 1) * vis.size(); } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + map m; + m.clear(); + string s; + for (int i = 0; i < n; i++) { + cin >> s; + m[s]++; + } + int max = -699999999; + map::iterator it; + string temp; + for (it = m.begin(); it != m.end(); it++) { + if (it->second > max) { + max = it->second; + temp = it->first; + } + } + cout << temp << endl; +} +int main() { + int n, a, j; + cin >> n; + vector mainvector; + int even = 0, odd = 0; + for (int i = 0; i < n; i++) { + cin >> a; + mainvector.push_back(a); + } + for (int i = 0; i < n; i++) { + if (mainvector[i] % 2 == 0) { + even += 1; + } else { + odd += 1; + } + } + if (odd < even) { + for (int i = 0; i < n; i++) { + if (mainvector[i] % 2 != 0) { cout << i + 1 << endl; } + } + } else { + for (int i = 0; i < n; i++) { + if (mainvector[i] % 2 == 0) { cout << i + 1 << endl; } + } + } +} +int main() { + char a[100]; + int sum = 0; + int ans = 0; + while (gets(a)) { + int len = strlen(a); + if (a[0] == '+') { + sum++; + } else if (a[0] == '-') { + sum--; + } else { + int p = 0; + for (int i = 0; i < len; i++) { + if (a[i] == ':') { p = i; } + } + ans += (len - p - 1) * sum; + } + } + cout << ans << endl; + return 0; +} +char ch; +int n, m; +char tmp1, tmp2, tmp3; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> tmp2; + if (i != 0 && tmp1 == tmp2) { + cout << "NO" << endl; + return 0; + } + for (int j = 1; j < m; j++) { + cin >> tmp3; + if (tmp2 != tmp3) { + cout << "NO" << endl; + return 0; + } + } + tmp1 = tmp2; + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + int index = 0; + cin >> n; + int a[100]; + for (int i = 0; i < n; i++) cin >> a[i]; + if (a[0] % 2 == 0 && a[1] % 2 != 0 && a[2] % 2 != 0) { + cout << 1 << endl; + return 0; + } + if (a[0] % 2 != 0 && a[1] % 2 == 0 && a[2] % 2 == 0) { + cout << 1 << endl; + return 0; + } + if (a[0] % 2 == 0) { + for (int i = 1; i < n; i++) { + if (a[i] % 2 != 0) index = i + 1; + } + cout << index << endl; + return 0; + } + if (a[0] % 2 != 0) { + for (int i = 1; i < n; i++) { + if (a[i] % 2 == 0) index = i + 1; + } + cout << index << endl; + return 0; + } +} +int main() { + int n; + map q; + while (cin >> n) { + int i; + string a; + int max = 0; + string b; + for (i = 0; i < n; i++) { + cin >> a; + q[a]++; + if (q[a] > max) { + max = q[a]; + b = a; + } + } + cout << b << endl; + } + return 0; +} +int main() { + int n; + map q; + while (cin >> n) { + int i; + string a; + int max = 0; + string b; + for (i = 0; i < n; i++) { + cin >> a; + q[a]++; + if (q[a] > max) { + max = q[a]; + b = a; + } + } + cout << b << endl; + } + return 0; +} +int main() { + int ans = 0, cnt = 0; + string s; + while (getline(cin, s)) { + if (s[0] == '+') + cnt++; + else if (s[0] == '-') + cnt--; + else { + ans += cnt * (s.size() - s.find(":") - 1); + } + } + cout << ans << endl; +} +int main() { + int ans = 0, cnt = 0; + string s; + while (getline(cin, s)) { + if (s[0] == '+') + cnt++; + else if (s[0] == '-') + cnt--; + else { + ans += cnt * (s.size() - s.find(":") - 1); + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string s[n], ans; + int a[2] = {0}; + set y; + int flag; + for (int i = 0; i < n; i++) { + cin >> s[i]; + y.insert(s[i]); + } + set::iterator setIt = y.begin(); + for (int i = 0; i < n; i++) { + if (s[i] == *setIt) { + a[0]++; + } else { + a[1]++; + } + } + if (a[0] > a[1]) { + cout << *setIt << endl; + } else { + setIt++; + cout << *setIt << endl; + } + return 0; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + sort(a, a + 4); + int flag = 0; + for (int i = 0; i <= 1; i++) { + if ((a[i] + a[i + 1]) > a[i + 2]) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "TRIANGLE" << endl; + else { + flag = 0; + for (int i = 0; i <= 1; i++) { + if ((a[i] + a[i + 1]) == a[i + 2]) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int b = 0, t = 0; +string s; +int main() { + getline(cin, s); + while (s != "") { + if (s[0] == '+') { + t += 1; + } else { + if (s[0] == '-') { + t -= 1; + } else { + for (int i = 0; i < s.size(); i++) { + if (s[i] == ':') { b += t * s.substr(i + 1, s.size()).size(); } + } + } + } + getline(cin, s); + } + cout << b << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char e[n][m]; + int flag = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> e[i][j]; + for (int i = 0; i < n; i++) { + char t = e[i][0]; + for (int j = 0; j < m; j++) { + if (t != e[i][j]) flag = 1; + } + } + for (int i = 0; i < n - 1; i++) { + if (e[i][0] == e[i + 1][0]) flag = 1; + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, m; + cin >> n >> m; + char e[n][m]; + int flag = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> e[i][j]; + for (int i = 0; i < n; i++) { + char t = e[i][0]; + for (int j = 0; j < m; j++) { + if (t != e[i][j]) flag = 1; + } + } + for (int i = 0; i < n - 1; i++) { + if (e[i][0] == e[i + 1][0]) flag = 1; + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n; + char a[12], b[12]; + map p; + while (cin >> n) { + int m = 0; + for (int i = 0; i < n; i++) { + cin >> a; + if (!p.count(a)) + p[a] = 1; + else + p[a]++; + if (p[a] > m) { + m = p[a]; + strcpy(b, a); + } + } + cout << b << endl; + } + return 0; +} +long long ar[5]; +int main() { + for (int i = 0; i < 4; i++) cin >> ar[i]; + sort(ar, ar + 4); + bool fl = 0; + if (ar[3] < ar[0] + ar[1] || ar[3] < ar[0] + ar[2] || ar[3] < ar[1] + ar[2]) fl = 1; + if (ar[2] < ar[0] + ar[1]) fl = 1; + if (fl == 1) { + puts("TRIANGLE"); + return 0; + } + if (ar[3] == ar[0] + ar[1] || ar[3] == ar[0] + ar[2] || ar[3] == ar[1] + ar[2]) fl = 1; + if (ar[2] == ar[0] + ar[1]) fl = 1; + if (fl == 1) { + puts("SEGMENT"); + } else + puts("IMPOSSIBLE"); + return 0; +} +int main() { + long long n, i, par, indpar, indimpar, impar, x, npar = 0, nimpar = 0; + cin >> n; + cin >> x; + if (x % 2 == 0) { + par = x; + npar++; + indpar = 1; + } else { + impar = x; + nimpar++; + indimpar = 1; + } + for (i = 2; i <= n; i++) { + cin >> x; + if (x % 2 == 0) { + par = x; + npar++; + indpar = i; + } else { + impar = x; + nimpar++; + indimpar = i; + } + } + if (nimpar == 1) cout << indimpar << endl; + if (npar == 1) cout << indpar << endl; + return 0; +} +int main() { + long long n, i, par, indpar, indimpar, impar, x, npar = 0, nimpar = 0; + cin >> n; + cin >> x; + if (x % 2 == 0) { + par = x; + npar++; + indpar = 1; + } else { + impar = x; + nimpar++; + indimpar = 1; + } + for (i = 2; i <= n; i++) { + cin >> x; + if (x % 2 == 0) { + par = x; + npar++; + indpar = i; + } else { + impar = x; + nimpar++; + indimpar = i; + } + } + if (nimpar == 1) cout << indimpar << endl; + if (npar == 1) cout << indpar << endl; + return 0; +} +const double PI = acos(-1.0); +const int inf = int(1e9); +const int mod = inf + 7; +long long n, m, k, l, w, h, sum, mx, mn; +int main() { + mn = (1e9), sum = 0, mx = 0; + cin >> n; + string ans = ""; + map maap; + while (n--) { + string s; + cin >> s; + maap[s]++; + if (maap[s] > mx) { + mx = maap[s]; + ans = s; + } + } + cout << ans << endl; + return 0; +} +const double PI = acos(-1.0); +const int inf = int(1e9); +const int mod = inf + 7; +long long n, m, k, l, w, h, sum, mx, mn; +int main() { + mn = (1e9), sum = 0, mx = 0; + cin >> n; + string ans = ""; + map maap; + while (n--) { + string s; + cin >> s; + maap[s]++; + if (maap[s] > mx) { + mx = maap[s]; + ans = s; + } + } + cout << ans << endl; + return 0; +} +int main() { + int count = 0, result = 0, k = 0, z = 0; + string s; + while (getline(cin, s)) { + z = 1; + if (s[0] == '+') + count++; + else if (s[0] == '-') + count--; + else { + k = s.size(); + for (int i = 0; s[i] != ':'; i++) { z++; } + result += (k - z) * count; + } + } + cout << result << endl; + return 0; +} +int main() { + int count = 0, result = 0, k = 0, z = 0; + string s; + while (getline(cin, s)) { + z = 1; + if (s[0] == '+') + count++; + else if (s[0] == '-') + count--; + else { + k = s.size(); + for (int i = 0; s[i] != ':'; i++) { z++; } + result += (k - z) * count; + } + } + cout << result << endl; + return 0; +} +string s[2]; +int cnt[2]; +int main() { + int n; + cin >> n; + cin >> s[0]; + cnt[0]++; + for (int i = 1; i <= n - 1; i++) { + string a; + cin >> a; + if (a == s[0]) + cnt[0]++; + else + s[1] = a; + } + if (cnt[0] > n - cnt[0]) + cout << s[0] << endl; + else + cout << s[1] << endl; + return 0; +} +string s[2]; +int cnt[2]; +int main() { + int n; + cin >> n; + cin >> s[0]; + cnt[0]++; + for (int i = 1; i <= n - 1; i++) { + string a; + cin >> a; + if (a == s[0]) + cnt[0]++; + else + s[1] = a; + } + if (cnt[0] > n - cnt[0]) + cout << s[0] << endl; + else + cout << s[1] << endl; + return 0; +} +int main() { + int n = 4; + vector v(4); + for (int i = 0; i < n; i++) cin >> v[i]; + sort(v.begin(), v.end()); + for (int i = 2; i < n; i++) { + if (v[i] < v[i - 1] + v[i - 2]) { + cout << "TRIANGLE\n"; + return 0; + } + } + for (int i = 2; i < n; i++) { + if (v[i] == v[i - 1] + v[i - 2]) { + cout << "SEGMENT\n"; + return 0; + } + } + cout << "IMPOSSIBLE\n"; + return 0; +} +int main() { + char str[10005]; + int ans = 0, sum = 0; + while (gets(str)) { + int num = 0; + if (str[0] == '+') { + ans++; + } else if (str[0] == '-') { + ans--; + } else { + int len = strlen(str); + for (int i = 0; i < len; i++) { + if (str[i] == ':') { + num = i; + break; + } + } + num = len - num - 1; + sum += ans * num; + } + if (str[0] == '0' && str[1] == '0') break; + } + cout << sum << endl; + return 0; +} +int main() { + char str[10005]; + int ans = 0, sum = 0; + while (gets(str)) { + int num = 0; + if (str[0] == '+') { + ans++; + } else if (str[0] == '-') { + ans--; + } else { + int len = strlen(str); + for (int i = 0; i < len; i++) { + if (str[i] == ':') { + num = i; + break; + } + } + num = len - num - 1; + sum += ans * num; + } + if (str[0] == '0' && str[1] == '0') break; + } + cout << sum << endl; + return 0; +} +bool flag = true; +int n, m; +string s[100]; +bool isRow(string s) { + bool result = true; + for (int i = 1; i < s.size(); i++) { + result &= (s[i] == s[i - 1]); + ; + } + return result; +} +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> s[i]; + flag &= isRow(s[i]); + } + for (int i = 1; i < n; i++) { flag &= (s[i][0] != s[i - 1][0]); } + if (flag) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string s, p; + int i, j, k, l, sum = 0; + int c1 = 0, c2 = 0, c3 = 0; + while (getline(cin, s)) { + if (s.size() == 0) break; + if (s[0] == '+') + c1++; + else if (s[0] == '-') + c1--; + else { + c3 = 0; + for (i = 0;; i++) { + c3++; + if (s[i] == ':') break; + } + sum += (s.size() - c3) * c1; + } + } + cout << sum << endl; + return 0; +} +int main() { + string s, p; + int i, j, k, l, sum = 0; + int c1 = 0, c2 = 0, c3 = 0; + while (getline(cin, s)) { + if (s.size() == 0) break; + if (s[0] == '+') + c1++; + else if (s[0] == '-') + c1--; + else { + c3 = 0; + for (i = 0;; i++) { + c3++; + if (s[i] == ':') break; + } + sum += (s.size() - c3) * c1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, i; + string s[110]; + cin >> n; + for (i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + cout << s[n / 2] << endl; + return 0; +} +int main() { + int n, i; + string s[110]; + cin >> n; + for (i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + cout << s[n / 2] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int *a = new int[n]; + int index = 0, index1 = 0; + int f = 0, f1 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + index = i; + f++; + } else { + index1 = i; + f1++; + } + } + if (f == 1) + cout << index + 1 << endl; + else + cout << index1 + 1 << endl; +} +int main() { + int n; + cin >> n; + int *a = new int[n]; + int index = 0, index1 = 0; + int f = 0, f1 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + index = i; + f++; + } else { + index1 = i; + f1++; + } + } + if (f == 1) + cout << index + 1 << endl; + else + cout << index1 + 1 << endl; +} +int main() { + string command; + set name; + name.clear(); + int sum = 0; + while (getline(cin, command)) { + if (command[0] == '+') + name.insert(command.substr(1, command.size() - 1)); + else if (command[0] == '-') + name.erase(command.substr(1, command.size() - 1)); + else { + int id = 0; + for (int i = 0; i < command.length(); i++) + if (command[i] == ':') { + id = i; + break; + } + sum += name.size() * (command.length() - 1 - id); + } + } + cout << sum << endl; + return 0; +} +int main() { + string command; + set name; + name.clear(); + int sum = 0; + while (getline(cin, command)) { + if (command[0] == '+') + name.insert(command.substr(1, command.size() - 1)); + else if (command[0] == '-') + name.erase(command.substr(1, command.size() - 1)); + else { + int id = 0; + for (int i = 0; i < command.length(); i++) + if (command[i] == ':') { + id = i; + break; + } + sum += name.size() * (command.length() - 1 - id); + } + } + cout << sum << endl; + return 0; +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + if (arr[3] < arr[2] + arr[1] || arr[2] < arr[1] + arr[0]) { + cout << "TRIANGLE\n"; + return 0; + } + if (arr[3] <= arr[2] + arr[1] || arr[2] <= arr[1] + arr[0]) { + cout << "SEGMENT\n"; + return 0; + } + cout << "IMPOSSIBLE\n"; + return 0; +} +int main() { + int n = 0; + int m = 0; + cin >> n >> m; + int i = 0; + int j = 0; + bool ok = true; + int last_stripe = -1; + while (i < n && ok) { + char x; + cin >> x; + ok = last_stripe != x; + last_stripe = x; + int current_stripe = x; + j = 1; + while (j < m && ok) { + cin >> x; + ok = current_stripe == x; + j++; + } + i++; + } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n = 0; + int m = 0; + cin >> n >> m; + int i = 0; + int j = 0; + bool ok = true; + int last_stripe = -1; + while (i < n && ok) { + char x; + cin >> x; + ok = last_stripe != x; + last_stripe = x; + int current_stripe = x; + j = 1; + while (j < m && ok) { + cin >> x; + ok = current_stripe == x; + j++; + } + i++; + } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +map ma; +string s; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + ma[s]++; + } + string ans; + int max = 0; + for (register map::iterator i = ma.begin(); i != ma.end(); i++) { + pair it = *i; + if (it.second > max) { + ans = it.first; + max = it.second; + } + } + cout << ans << endl; +} +int main() { + char s[110]; + int cnt = 0; + int ans = 0; + while (gets(s)) { + if (s[0] == '+') { + cnt++; + } else if (s[0] == '-') { + cnt--; + } else { + int i; + for (i = 0; s[i] != ':'; i++) + ; + int lens = strlen(s); + ans += (lens - 1 - i) * cnt; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, cnt1 = 0, cnt2 = 0, p1, p2; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + if ((a % 2) == 0) { + cnt1++; + p1 = i; + } else { + cnt2++; + p2 = i; + } + } + if (cnt1 == 1) + cout << p1 << endl; + else + cout << p2 << endl; + return 0; +} +int main() { + int n, m, i, j, a[105]; + char x; + cin >> n >> m; + for (i = 0; i < n; i++) { + set s; + s.clear(); + for (j = 0; j < m; j++) { + cin >> x; + s.insert(x - '0'); + } + if (s.size() > 1) break; + a[i] = x - '0'; + } + if (i < n) + cout << "NO" << endl; + else { + int flag = 1; + for (i = 1; i < n - 1; i++) { + if (a[i] == a[i - 1] || a[i] == a[i + 1]) { + flag = 0; + break; + } + } + cout << (flag ? "YES" : "NO") << endl; + } + return 0; +} +vector data; +map frq; +int main() { + string s; + int count1 = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + count1++; + } else if (s[0] == '-') { + count1--; + } else { + ans += count1 * (s.size() - s.find(':') - 1); + } + } + cout << ans << endl; + return 0; +} +vector data; +map frq; +int main() { + string s; + int count1 = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + count1++; + } else if (s[0] == '-') { + count1--; + } else { + ans += count1 * (s.size() - s.find(':') - 1); + } + } + cout << ans << endl; + return 0; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + int best = 0; + for (int o = 0; o < 4; o++) { + vector v; + for (int i = 0; i < 4; i++) + if (i != o) v.push_back(a[i]); + sort(v.begin(), v.end()); + if (v[0] + v[1] > v[2]) + best = max(best, 2); + else if (v[0] + v[1] == v[2]) + best = max(best, 1); + } + if (best == 2) + cout << "TRIANGLE" << endl; + else if (best == 1) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + int best = 0; + for (int o = 0; o < 4; o++) { + vector v; + for (int i = 0; i < 4; i++) + if (i != o) v.push_back(a[i]); + sort(v.begin(), v.end()); + if (v[0] + v[1] > v[2]) + best = max(best, 2); + else if (v[0] + v[1] == v[2]) + best = max(best, 1); + } + if (best == 2) + cout << "TRIANGLE" << endl; + else if (best == 1) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + string s; + int n; + int k = 0; + int kk = 0; + int kkk = 0; + int count = 0; + while (getline(cin, s)) { + if (s[0] == '+') + count++; + else if (s[0] == '-') + count--; + else { + for (int i = 0; i < s.length(); i++) { + if (s[i] == ':') k++; + if (k > 0 && s[i] != ':') kk++; + } + } + kkk = kkk + kk * count; + kk = 0; + k = 0; + } + cout << kkk << endl; + return 0; +} +int main() { + string s; + int n; + int k = 0; + int kk = 0; + int kkk = 0; + int count = 0; + while (getline(cin, s)) { + if (s[0] == '+') + count++; + else if (s[0] == '-') + count--; + else { + for (int i = 0; i < s.length(); i++) { + if (s[i] == ':') k++; + if (k > 0 && s[i] != ':') kk++; + } + } + kkk = kkk + kk * count; + kk = 0; + k = 0; + } + cout << kkk << endl; + return 0; +} +int main() { + int n, i; + string s[110]; + cin >> n; + for (i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + cout << s[n / 2] << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || b + c > d) { + cout << "TRIANGLE" << endl; + } else { + if (a + b == c || b + c == d) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || b + c > d) { + cout << "TRIANGLE" << endl; + } else { + if (a + b == c || b + c == d) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + } + return 0; +} +int main() { + int users = 0, traffic = 0; + string cmd; + while (getline(cin, cmd)) { + if (cmd[0] == '+') + users++; + else if (cmd[0] == '-') + users--; + else { + traffic += users * (cmd.length() - cmd.find(':') - 1); + } + } + cout << traffic << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt1, v1, cnt2, v2; + cnt1 = cnt2 = 0; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + if (a & 1) { + cnt1++; + v1 = i; + } else { + cnt2++; + v2 = i; + } + } + if (cnt1 == 1) + cout << v1 << endl; + else + cout << v2 << endl; + return 0; +} +int main() { + int n; + string arr[100]; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + string x = arr[0], y; + int n1 = 1, n2 = 0; + for (int i = 1; i < n; i++) { + if (arr[i] == x) + n1++; + else { + n2++; + y = arr[i]; + } + } + if (n1 > n2) + cout << x << endl; + else + cout << y << endl; + return 0; +} +int main() { + int n, m, i, j; + cin >> n >> m; + string a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < m - 1; j++) { + if (a[i][j] != a[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + } + } + for (i = 0; i < n - 1; i++) { + if (a[i][0] == a[i + 1][0]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n = 4, a[10]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if ((a[1] + a[2] > a[3]) || (a[0] + a[1] > a[2])) { + cout << "TRIANGLE" << endl; + } else if ((a[1] + a[2] == a[3]) || (a[0] + a[1] == a[2])) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int main() { + int n = 4, a[10]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if ((a[1] + a[2] > a[3]) || (a[0] + a[1] > a[2])) { + cout << "TRIANGLE" << endl; + } else if ((a[1] + a[2] == a[3]) || (a[0] + a[1] == a[2])) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int main() { + int olnum = 0; + int charnum = 0, charsum = 0; + string s; + while (getline(cin, s)) { + if (s[0] == '+') + olnum++; + else if (s[0] == '-') + olnum--; + else { + for (int i = 1; i < s.size(); i++) { + if (s.at(i) == ':') { + charnum += s.size() - i - 1; + charsum += charnum * olnum; + break; + } + } + charnum = 0; + } + } + cout << charsum << endl; + return 0; +} +int main() { + int olnum = 0; + int charnum = 0, charsum = 0; + string s; + while (getline(cin, s)) { + if (s[0] == '+') + olnum++; + else if (s[0] == '-') + olnum--; + else { + for (int i = 1; i < s.size(); i++) { + if (s.at(i) == ':') { + charnum += s.size() - i - 1; + charsum += charnum * olnum; + break; + } + } + charnum = 0; + } + } + cout << charsum << endl; + return 0; +} +int main() { + int n, a, cOdd = 0, cEven = 0, lOdd, lEven; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (a % 2 == 0) { + cEven++; + lEven = i; + } else { + cOdd++; + lOdd = i; + } + } + if (cOdd == 1) + cout << lOdd + 1 << endl; + else + cout << lEven + 1 << endl; +} +const long long N = 2e5 + 5; +int n; +int a[1001][1001], x; +string s; +map mm; +void solve() { + cin >> n; + int mx = 0; + string ans; + for (int i = 0; i < n; i++) { + cin >> s; + mm[s]++; + if (mx < mm[s]) { + mx = mm[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + int T = 1; + for (int i = 0; i < T; i++) { solve(); } + return 0; +} +const long long N = 2e5 + 5; +int n; +int a[1001][1001], x; +string s; +map mm; +void solve() { + cin >> n; + int mx = 0; + string ans; + for (int i = 0; i < n; i++) { + cin >> s; + mm[s]++; + if (mx < mm[s]) { + mx = mm[s]; + ans = s; + } + } + cout << ans << endl; +} +int main() { + int T = 1; + for (int i = 0; i < T; i++) { solve(); } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char ch; + for (int i = 0; i < n; ++i) { + string str; + cin >> str; + if (i == 0) { + ch = str[0]; + } else { + if (ch == str[0]) { + cout << "NO" << endl; + return 0; + } + ch = str[0]; + } + if (str.find_first_not_of(str[0], 1) != string::npos) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int ans = 0, user = 0; + for (;;) { + string input; + getline(cin, input); + if (input.length() == 0) + break; + else if (input[0] == '+') + user++; + else if (input[0] == '-') + user--; + else { + int coun = 0; + bool count_now = false; + for (int i = 0;; i++) { + if (input[i] == ':') { + coun++; + break; + } else + coun++; + } + coun = input.length() - coun; + ans += user * coun; + } + } + cout << ans; + cout << endl; +} +int main() { + int ans = 0, user = 0; + for (;;) { + string input; + getline(cin, input); + if (input.length() == 0) + break; + else if (input[0] == '+') + user++; + else if (input[0] == '-') + user--; + else { + int coun = 0; + bool count_now = false; + for (int i = 0;; i++) { + if (input[i] == ':') { + coun++; + break; + } else + coun++; + } + coun = input.length() - coun; + ans += user * coun; + } + } + cout << ans; + cout << endl; +} +int main() { + int n, cont = 1, aux1 = 0, aux2 = 0; + cin >> n; + string y = "", z = ""; + bool sw = true; + while (cont <= n) { + string x; + cin >> x; + if (sw) { + y = x; + sw = false; + } + if (x == y) + aux1++; + else { + aux2++; + z = x; + } + cont++; + } + if (aux1 > aux2) + cout << y << endl; + else + cout << z << endl; + return 0; +} +int main() { + int n, cont = 1, aux1 = 0, aux2 = 0; + cin >> n; + string y = "", z = ""; + bool sw = true; + while (cont <= n) { + string x; + cin >> x; + if (sw) { + y = x; + sw = false; + } + if (x == y) + aux1++; + else { + aux2++; + z = x; + } + cont++; + } + if (aux1 > aux2) + cout << y << endl; + else + cout << z << endl; + return 0; +} +int a[10]; +int main() { + int i, j, k, p, q; + for (i = 1; i <= 4; i++) { cin >> a[i]; } + sort(a + 1, a + 1 + 4); + if (a[1] + a[2] > a[3] || a[2] + a[3] > a[4]) { + cout << "TRIANGLE" << endl; + } else if (a[1] + a[2] == a[3] || a[2] + a[3] == a[4]) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int a[10]; +int main() { + int i, j, k, p, q; + for (i = 1; i <= 4; i++) { cin >> a[i]; } + sort(a + 1, a + 1 + 4); + if (a[1] + a[2] > a[3] || a[2] + a[3] > a[4]) { + cout << "TRIANGLE" << endl; + } else if (a[1] + a[2] == a[3] || a[2] + a[3] == a[4]) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +long long int mod = 1000000007; +int n; +int a[100]; +int z, o, i = -1, j = -1; +int main() { + cin >> n; + for (int x = 0; x < n; x++) { + cin >> a[x]; + z += 1 - (a[x] % 2); + o += a[x] % 2; + if (a[x] % 2) { + j = x + 1; + } else { + i = x + 1; + } + } + if (z == 1) { + cout << i << endl; + } else { + cout << j << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (c > a + b && d > b + c) + cout << "IMPOSSIBLE" << endl; + else if (c < a + b || d < b + c) + cout << "TRIANGLE" << endl; + else + cout << "SEGMENT" << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (c > a + b && d > b + c) + cout << "IMPOSSIBLE" << endl; + else if (c < a + b || d < b + c) + cout << "TRIANGLE" << endl; + else + cout << "SEGMENT" << endl; +} +int main() { + int n, even = 0, odd = 0, ev, od; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) { + cin >> ar[i]; + if (ar[i] % 2 == 0) { + even++; + ev = i; + } else { + odd++; + od = i; + } + } + if (even > odd) { + cout << od + 1 << endl; + } else { + cout << ev + 1 << endl; + } + return 0; +} +int k, ans; +string s; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') + k++; + else if (s[0] == '-') + k--; + else + ans += (s.size() - s.find(':') - 1) * k; + } + cout << ans << endl; +} +int k, ans; +string s; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') + k++; + else if (s[0] == '-') + k--; + else + ans += (s.size() - s.find(':') - 1) * k; + } + cout << ans << endl; +} +const int N = 100 + 5; +const int mod = 1000000000 + 7; +bool ok(char a) { + if (a >= 'a' && a <= 'z') return 1; + if (a >= 'A' && a <= 'Z') return 1; + if (a >= '0' && a <= '9') return 1; + if (a == '_') return 1; + return 0; +} +int main() { + char a[N]; + cin >> a + 1; + int len = strlen(a + 1); + int op = 1; + bool flag = 1; + int cnt1 = 0, cnt2 = 0, ccnt = 0, cnt3 = 0; + for (int i = 1; i <= len && flag; i++) { + if (op == 1) { + cnt1++; + if (a[i] == '@') { + cnt1--; + op = 2; + continue; + } + if (!ok(a[i])) { flag = 0; } + if (cnt1 > 16) flag = 0; + } else if (op == 2) { + ccnt++; + if (cnt1 == 0 || cnt1 > 16) flag = 0; + if (a[i] == '.') { + if (cnt2 == 0 || cnt2 > 16) flag = 0; + cnt2 = 0; + continue; + } + if (a[i] == '/') { + ccnt--; + op = 3; + continue; + } + if (!ok(a[i])) { flag = 0; } + cnt2++; + if (cnt2 > 16) flag = 0; + } else { + if (cnt2 == 0 || cnt2 > 16) flag = 0; + if (ccnt == 0 || ccnt > 32) flag = 0; + if (!ok(a[i])) flag = 0; + cnt3++; + if (cnt3 > 16) flag = 0; + } + } + if (op == 1) flag = 0; + if (op == 2 && (cnt2 == 0 || cnt2 > 16)) flag = 0; + if (op == 3 && (cnt3 == 0 || cnt3 > 16)) flag = 0; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = 100 + 5; +const int mod = 1000000000 + 7; +bool ok(char a) { + if (a >= 'a' && a <= 'z') return 1; + if (a >= 'A' && a <= 'Z') return 1; + if (a >= '0' && a <= '9') return 1; + if (a == '_') return 1; + return 0; +} +int main() { + char a[N]; + cin >> a + 1; + int len = strlen(a + 1); + int op = 1; + bool flag = 1; + int cnt1 = 0, cnt2 = 0, ccnt = 0, cnt3 = 0; + for (int i = 1; i <= len && flag; i++) { + if (op == 1) { + cnt1++; + if (a[i] == '@') { + cnt1--; + op = 2; + continue; + } + if (!ok(a[i])) { flag = 0; } + if (cnt1 > 16) flag = 0; + } else if (op == 2) { + ccnt++; + if (cnt1 == 0 || cnt1 > 16) flag = 0; + if (a[i] == '.') { + if (cnt2 == 0 || cnt2 > 16) flag = 0; + cnt2 = 0; + continue; + } + if (a[i] == '/') { + ccnt--; + op = 3; + continue; + } + if (!ok(a[i])) { flag = 0; } + cnt2++; + if (cnt2 > 16) flag = 0; + } else { + if (cnt2 == 0 || cnt2 > 16) flag = 0; + if (ccnt == 0 || ccnt > 32) flag = 0; + if (!ok(a[i])) flag = 0; + cnt3++; + if (cnt3 > 16) flag = 0; + } + } + if (op == 1) flag = 0; + if (op == 2 && (cnt2 == 0 || cnt2 > 16)) flag = 0; + if (op == 3 && (cnt3 == 0 || cnt3 > 16)) flag = 0; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; +int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; +void fast() {} +const long long md = 1e9 + 7; +int main() { + fast(); + long long n, arr[100000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int sumeven = 0, sumodd = 0; + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) + sumeven++; + else + sumodd++; + } + if (sumeven >= sumodd) { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 != 0) { + cout << i + 1 << "\n"; + break; + } + } + } else { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + cout << i + 1 << "\n"; + break; + } + } + } + return 0; +} +int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; +int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; +void fast() {} +const long long md = 1e9 + 7; +int main() { + fast(); + long long n, arr[100000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int sumeven = 0, sumodd = 0; + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) + sumeven++; + else + sumodd++; + } + if (sumeven >= sumodd) { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 != 0) { + cout << i + 1 << "\n"; + break; + } + } + } else { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + cout << i + 1 << "\n"; + break; + } + } + } + return 0; +} +int FindLen(string ss) { + int i = 0; + for (i = 0; i < ss.size(); i++) { + if (ss[i] == ':') break; + } + int l = 0; + for (int j = i + 1; j < ss.size(); j++) { l++; } + return l; +} +int main() { + set Set; + string ss; + int ans = 0; + while (getline(cin, ss)) { + if (ss[0] == '+') { + int len = ss.size() - 1; + Set.insert(ss.substr(1, len)); + } else if (ss[0] == '-') { + int len = ss.size() - 1; + string name = ss.substr(1, len); + Set.erase(name); + } else { + int len = FindLen(ss); + ans = ans + Set.size() * len; + } + } + cout << ans << endl; + return 0; +} +int FindLen(string ss) { + int i = 0; + for (i = 0; i < ss.size(); i++) { + if (ss[i] == ':') break; + } + int l = 0; + for (int j = i + 1; j < ss.size(); j++) { l++; } + return l; +} +int main() { + set Set; + string ss; + int ans = 0; + while (getline(cin, ss)) { + if (ss[0] == '+') { + int len = ss.size() - 1; + Set.insert(ss.substr(1, len)); + } else if (ss[0] == '-') { + int len = ss.size() - 1; + string name = ss.substr(1, len); + Set.erase(name); + } else { + int len = FindLen(ss); + ans = ans + Set.size() * len; + } + } + cout << ans << endl; + return 0; +} +int main() { + char a[105]; + int sum = 0; + int count1 = 0; + while (gets(a)) { + if (a[0] == '+') + count1++; + else if (a[0] == '-') + count1--; + else { + int len = strlen(a); + int ans = 0; + for (int i = 0; i < len; i++) { + if (a[i] == ':') { + ans = i; + break; + } + } + sum += (len - ans - 1) * count1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int x[5]; + int i, k; + memset(x, 0, sizeof(x)); + for (i = 0; i < 4; i++) { cin >> x[i]; } + sort(x, x + 4); + if (x[0] + x[1] > x[2] || x[1] + x[2] > x[3]) { + cout << "TRIANGLE" << endl; + } else if (x[0] + x[1] == x[2] || x[1] + x[2] == x[3]) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +bool myCompare(const pair &i, const pair &j) { + return i.second < j.second; +} +string s; +int check() { + int x = 0, y = 0, flag = 0; + for (int i = 0; i < s.size(); i++) { + if (flag == 0) { + if (s[i] == '@') { + if ((i - x) > 16 || (i - x) < 1 || (i + 1 == s.size())) return 0; + x = i + 1; + y = i + 1; + flag = 1; + } else if (isalpha(s[i]) || isdigit(s[i]) || s[i] == '_') { + continue; + } else if (!isalpha(s[i]) || !isdigit(s[i]) || s[i] != '_') { + return 0; + } + } else if (flag == 1) { + if (s[i] == '/') { + if ((i - x) > 32 || (i - x) < 1 || (i + 1 == s.size()) || s[i - 1] == '.') return 0; + x = i + 1; + flag = 2; + } else if (s[i] == '.') { + if ((i - y) > 16 || (i - y) < 1 || (i + 1 == s.size())) return 0; + y = i + 1; + } else if (isalpha(s[i]) || isdigit(s[i]) || s[i] == '.' || s[i] == '_') { + if (i + 1 == s.size()) { + if ((i - x + 1) > 32 || (i - x + 1) < 1) return 0; + if ((i - y + 1) > 16 || (i - y + 1) < 1) return 0; + } + continue; + } else if (!isalpha(s[i]) || !isdigit(s[i]) || s[i] != '.' || s[i] != '_') { + return 0; + } + } else { + if (s[i] == '_' && i + 1 == s.size()) return 0; + if (isalpha(s[i]) || isdigit(s[i]) || s[i] == '_') { + if (i + 1 == s.size()) { + if ((i - x + 1) > 16 || (i - x + 1) < 1) return 0; + } + continue; + } + if (!isalpha(s[i]) || !isdigit(s[i]) || s[i] != '_') { return 0; } + } + } + if (flag > 0) + return 1; + else + return 0; +} +int main() { + cin >> s; + cout << (check() ? "YES" : "NO") << endl; + return 0; +} +char c[1000000]; +int main() { + int s = 0, total = 0, i, j, k, n, m; + while (gets(c + 1)) { + if (c[1] == '+') s++; + if (c[1] == '-') s--; + if (c[1] - '+' && c[1] - '-') { + int t = 1; + while (c[t] - ':') t++; + total += ((strlen(c + 1) - t) * s); + } + } + cout << total << endl; + return 0; +} +char c[1000000]; +int main() { + int s = 0, total = 0, i, j, k, n, m; + while (gets(c + 1)) { + if (c[1] == '+') s++; + if (c[1] == '-') s--; + if (c[1] - '+' && c[1] - '-') { + int t = 1; + while (c[t] - ':') t++; + total += ((strlen(c + 1) - t) * s); + } + } + cout << total << endl; + return 0; +} +long long n, k, ans = 0, i = 0, j = 0; +int main() { + int t = 1; + while (t--) { + int arr[4]; + for (i = 0; i < 4; i++) { cin >> arr[i]; } + sort(arr, arr + 4); + long long sum = 0; + string s = "IMPOSSIBLE"; + for (i = 0; i < 2; i++) { + sum = arr[i] + arr[i + 1]; + if (sum > arr[i + 2]) { + cout << "TRIANGLE" + << "\n"; + exit(0); + } else if (sum == arr[i + 2]) + s = "SEGMENT"; + } + cout << s << "\n"; + } +} +string s; +bool check1(string s) { + if (s[0] == '+' || s[0] == '-') + return true; + else + return false; +} +bool check(string s) { + if (s[0] == '+') return true; + if (s[0] == '-') return false; +} +int main() { + int cnt = 0; + int ans = 0; + while (getline(cin, s)) { + if (check1(s) == true) { + if (check(s) == true) + cnt++; + else + cnt--; + } else { + for (int i = 0; i < s.length(); i++) + if (s[i] == ':') { + ans += (s.length() - i - 1) * cnt; + break; + } + } + } + cout << ans << endl; + return 0; +} +string s; +bool check1(string s) { + if (s[0] == '+' || s[0] == '-') + return true; + else + return false; +} +bool check(string s) { + if (s[0] == '+') return true; + if (s[0] == '-') return false; +} +int main() { + int cnt = 0; + int ans = 0; + while (getline(cin, s)) { + if (check1(s) == true) { + if (check(s) == true) + cnt++; + else + cnt--; + } else { + for (int i = 0; i < s.length(); i++) + if (s[i] == ':') { + ans += (s.length() - i - 1) * cnt; + break; + } + } + } + cout << ans << endl; + return 0; +} +bool l(char c) { + if (c >= 'a' && c <= 'z') { return true; } + if (c >= 'A' && c <= 'Z') { return true; } + if (c >= '0' && c <= '9') { return true; } + if (c == '_') { return true; } + return false; +} +bool un(string s) { + int n = s.size(); + if (n == 0 || n > 16) { return false; } + for (int i = 0; i < n; i++) { + if (!l(s[i])) { return false; } + } + return true; +} +bool hn(string s) { + int n = s.size(), i, nw = 0; + if (n == 0 || n > 32) { return false; } + s += '.'; + for (i = 0; i < n + 1; i++) { + if (s[i] == '.') { + if (nw == 0 || nw > 16) { return false; } + nw = 0; + } else { + if (!l(s[i])) { return false; } + nw++; + } + } + return true; +} +bool r(string s) { + return un(s); +} +bool f(string s) { + int n = s.size(), i, j; + for (i = 0; i < n; i++) { + if (s[i] == '@') { break; } + } + if (i == n) { return false; } + if (!un(s.substr(0, i))) { return false; } + for (j = i + 1; j < n; j++) { + if (s[j] == '/') { break; } + } + if (!hn(s.substr(i + 1, j - i - 1))) { return false; } + if (j != n && !r(s.substr(j + 1))) { return false; } + return true; +} +string s; +int main() { + cin >> s; + if (f(s)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + { + if ((a + b) > c && (a + c) > b && (b + c) > a) { + cout << "TRIANGLE" << endl; + } else if ((a + b) > d && (a + d) > b && (b + d) > a) { + cout << "TRIANGLE" << endl; + } else if ((a + c) > d && (a + d) > c && (c + d) > a) { + cout << "TRIANGLE" << endl; + } else if ((c + b) > d && (c + d) > b && (b + d) > c) { + cout << "TRIANGLE" << endl; + } else if (a + b == c) { + cout << "SEGMENT" << endl; + } else if (b == a + c) { + cout << "SEGMENT" << endl; + } else if (b + c == a) { + cout << "SEGMENT" << endl; + } else if (a + b == d) { + cout << "SEGMENT" << endl; + } else if (b + d == a) { + cout << "SEGMENT" << endl; + } else if (a + d == b) { + cout << "SEGMENT" << endl; + } else if (a + c == d) { + cout << "SEGMENT" << endl; + } else if (a + d == c) { + cout << "SEGMENT" << endl; + } else if (c + d == a) { + cout << "SEGMENT" << endl; + } else if (b + d == c) { + cout << "SEGMENT" << endl; + } else if (c + d == b) { + cout << "SEGMENT" << endl; + } else if (b + c == d) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + { + if ((a + b) > c && (a + c) > b && (b + c) > a) { + cout << "TRIANGLE" << endl; + } else if ((a + b) > d && (a + d) > b && (b + d) > a) { + cout << "TRIANGLE" << endl; + } else if ((a + c) > d && (a + d) > c && (c + d) > a) { + cout << "TRIANGLE" << endl; + } else if ((c + b) > d && (c + d) > b && (b + d) > c) { + cout << "TRIANGLE" << endl; + } else if (a + b == c) { + cout << "SEGMENT" << endl; + } else if (b == a + c) { + cout << "SEGMENT" << endl; + } else if (b + c == a) { + cout << "SEGMENT" << endl; + } else if (a + b == d) { + cout << "SEGMENT" << endl; + } else if (b + d == a) { + cout << "SEGMENT" << endl; + } else if (a + d == b) { + cout << "SEGMENT" << endl; + } else if (a + c == d) { + cout << "SEGMENT" << endl; + } else if (a + d == c) { + cout << "SEGMENT" << endl; + } else if (c + d == a) { + cout << "SEGMENT" << endl; + } else if (b + d == c) { + cout << "SEGMENT" << endl; + } else if (c + d == b) { + cout << "SEGMENT" << endl; + } else if (b + c == d) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; + } +} +int main() { + int n, i, j, arr, o = 0, odd, even, e = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> arr; + if (arr % 2 == 0) { + e++; + even = i + 1; + } else { + o++; + odd = i + 1; + } + } + if (o == 1) + cout << odd << endl; + else + cout << even << endl; + return 0; +} +int main() { + string s; + int x1, y1, x2, y2; + cin >> s; + x1 = s[0] - 96; + y1 = s[1] - '0'; + cin >> s; + x2 = s[0] - 96; + y2 = s[1] - '0'; + cout << max(abs(x1 - x2), abs(y1 - y2)) << endl; + while (x1 != x2 || y1 != y2) { + if (x2 > x1) { + cout << "R"; + x1++; + } + if (x2 < x1) { + cout << "L"; + x1--; + } + if (y1 > y2) { + cout << "D"; + y1--; + } + if (y1 < y2) { + cout << "U"; + y1++; + } + cout << "\n"; + } + return 0; +} +int main() { + string s; + int x1, y1, x2, y2; + cin >> s; + x1 = s[0] - 96; + y1 = s[1] - '0'; + cin >> s; + x2 = s[0] - 96; + y2 = s[1] - '0'; + cout << max(abs(x1 - x2), abs(y1 - y2)) << endl; + while (x1 != x2 || y1 != y2) { + if (x2 > x1) { + cout << "R"; + x1++; + } + if (x2 < x1) { + cout << "L"; + x1--; + } + if (y1 > y2) { + cout << "D"; + y1--; + } + if (y1 < y2) { + cout << "U"; + y1++; + } + cout << "\n"; + } + return 0; +} +int par[2]; +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + if (arr[0] + arr[1] >= arr[2]) { + if (arr[0] + arr[1] == arr[2]) { + if (arr[2] + arr[1] > arr[3]) { + cout << "TRIANGLE\n"; + } else + cout << "SEGMENT\n"; + } else { + cout << "TRIANGLE\n"; + } + } else { + if (arr[1] + arr[2] >= arr[3]) { + if (arr[1] + arr[2] == arr[3]) { + cout << "SEGMENT\n"; + } else { + cout << "TRIANGLE\n"; + } + } else + cout << "IMPOSSIBLE\n"; + } + return 0; +} +int main() { + char c1[2]; + char c2[2]; + cin >> c1[0] >> c1[1]; + cin >> c2[0] >> c2[1]; + vector ans; + while (c1[0] != c2[0] || c1[1] != c2[1]) { + if (c1[0] < c2[0] && c1[1] < c2[1]) { + ans.push_back("RU"); + c1[0]++; + c1[1]++; + } else if (c1[0] < c2[0] && c1[1] == c2[1]) { + ans.push_back("R"); + c1[0]++; + } else if (c1[0] < c2[0] && c1[1] > c2[1]) { + ans.push_back("RD"); + c1[0]++; + c1[1]--; + } else if (c1[0] == c2[0] && c1[1] < c2[1]) { + ans.push_back("U"); + c1[1]++; + } else if (c1[0] == c2[0] && c1[1] > c2[1]) { + ans.push_back("D"); + c1[1]--; + } else if (c1[0] > c2[0] && c1[1] > c2[1]) { + ans.push_back("LD"); + c1[1]--; + c1[0]--; + } else if (c1[0] > c2[0] && c1[1] == c2[1]) { + ans.push_back("L"); + c1[0]--; + } else if (c1[0] > c2[0] && c1[1] < c2[1]) { + ans.push_back("LU"); + c1[0]--; + c1[1]++; + } + } + cout << ans.size() << endl; + for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } +} +int main() { + char c1[2]; + char c2[2]; + cin >> c1[0] >> c1[1]; + cin >> c2[0] >> c2[1]; + vector ans; + while (c1[0] != c2[0] || c1[1] != c2[1]) { + if (c1[0] < c2[0] && c1[1] < c2[1]) { + ans.push_back("RU"); + c1[0]++; + c1[1]++; + } else if (c1[0] < c2[0] && c1[1] == c2[1]) { + ans.push_back("R"); + c1[0]++; + } else if (c1[0] < c2[0] && c1[1] > c2[1]) { + ans.push_back("RD"); + c1[0]++; + c1[1]--; + } else if (c1[0] == c2[0] && c1[1] < c2[1]) { + ans.push_back("U"); + c1[1]++; + } else if (c1[0] == c2[0] && c1[1] > c2[1]) { + ans.push_back("D"); + c1[1]--; + } else if (c1[0] > c2[0] && c1[1] > c2[1]) { + ans.push_back("LD"); + c1[1]--; + c1[0]--; + } else if (c1[0] > c2[0] && c1[1] == c2[1]) { + ans.push_back("L"); + c1[0]--; + } else if (c1[0] > c2[0] && c1[1] < c2[1]) { + ans.push_back("LU"); + c1[0]--; + c1[1]++; + } + } + cout << ans.size() << endl; + for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } +} +int main() { + int a[5]; + for (int i = 1; i <= 4; i++) cin >> a[i]; + sort(a + 1, a + 5); + if (a[1] + a[2] > a[3] || a[1] + a[3] > a[4] || a[2] + a[3] > a[4]) + cout << "TRIANGLE" << endl; + else if (a[1] + a[2] == a[3] || a[1] + a[3] == a[4] || a[2] + a[3] == a[4]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; +} +int main() { + int a[5]; + for (int i = 1; i <= 4; i++) cin >> a[i]; + sort(a + 1, a + 5); + if (a[1] + a[2] > a[3] || a[1] + a[3] > a[4] || a[2] + a[3] > a[4]) + cout << "TRIANGLE" << endl; + else if (a[1] + a[2] == a[3] || a[1] + a[3] == a[4] || a[2] + a[3] == a[4]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; +} +int main() { + int n, x, a, b, c = 0, c1 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x % 2 == 0) { + c++; + a = i + 1; + } else { + c1++; + b = i + 1; + } + } + if (c > c1) + cout << b << endl; + else + cout << a << endl; + return 0; +} +long long n, m; +char x, y, a, b; +string s, s1; +int main() { + cin >> s >> s1; + n = int(s[0] - s1[0]), m = int(s[1] - s1[1]); + if (n < 0) { + n = -n; + x = 'R'; + } else + x = 'L'; + if (m < 0) { + m = -m; + y = 'U'; + } else + y = 'D'; + cout << max(n, m) << endl; + while (n | m) { + if (n) n--, cout << x; + if (m) m--, cout << y; + cout << endl; + } +} +long long n, m; +char x, y, a, b; +string s, s1; +int main() { + cin >> s >> s1; + n = int(s[0] - s1[0]), m = int(s[1] - s1[1]); + if (n < 0) { + n = -n; + x = 'R'; + } else + x = 'L'; + if (m < 0) { + m = -m; + y = 'U'; + } else + y = 'D'; + cout << max(n, m) << endl; + while (n | m) { + if (n) n--, cout << x; + if (m) m--, cout << y; + cout << endl; + } +} +int l[4]; +int main() { + for (int i = 0; i <= 3; ++i) cin >> l[i]; + sort(l, l + 4); + if ((l[1] + l[2] > l[3]) || (l[0] + l[1] > l[2])) { + cout << "TRIANGLE" << endl; + return 0; + } + if ((l[1] + l[2] == l[3]) || (l[0] + l[1] == l[2])) { + cout << "SEGMENT" << endl; + return 0; + } + cout << "IMPOSSIBLE" << endl; + return 0; +} +int FindLen(string ss) { + int i = 0; + for (i = 0; i < ss.size(); i++) { + if (ss[i] == ':') break; + } + int l = 0; + for (int j = i + 1; j < ss.size(); j++) { l++; } + return l; +} +int main() { + set Set; + string ss; + int ans = 0; + while (getline(cin, ss)) { + if (ss[0] == '+') { + int len = ss.size() - 1; + Set.insert(ss.substr(1, len)); + } else if (ss[0] == '-') { + int len = ss.size() - 1; + string name = ss.substr(1, len); + Set.erase(name); + } else { + int len = FindLen(ss); + ans = ans + Set.size() * len; + } + } + cout << ans << endl; + return 0; +} +int FindLen(string ss) { + int i = 0; + for (i = 0; i < ss.size(); i++) { + if (ss[i] == ':') break; + } + int l = 0; + for (int j = i + 1; j < ss.size(); j++) { l++; } + return l; +} +int main() { + set Set; + string ss; + int ans = 0; + while (getline(cin, ss)) { + if (ss[0] == '+') { + int len = ss.size() - 1; + Set.insert(ss.substr(1, len)); + } else if (ss[0] == '-') { + int len = ss.size() - 1; + string name = ss.substr(1, len); + Set.erase(name); + } else { + int len = FindLen(ss); + ans = ans + Set.size() * len; + } + } + cout << ans << endl; + return 0; +} +void sort(int arr[], int n) { + int t, min; + for (int i = 0; i < n - 1; i++) { + min = i; + for (int j = i + 1; j < n; j++) { + if (arr[min] > arr[j]) { min = j; } + } + t = arr[min]; + arr[min] = arr[i]; + arr[i] = t; + } +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, 4); + int flag = 0; + if (arr[0] + arr[1] > arr[2] || arr[1] + arr[2] > arr[3]) { + flag = 2; + } else if (arr[0] + arr[1] == arr[2] || arr[1] + arr[2] == arr[3]) { + flag = 1; + } + if (flag == 0) { + cout << "IMPOSSIBLE\n"; + } else if (flag == 1) { + cout << "SEGMENT\n"; + } else { + cout << "TRIANGLE\n"; + } +} +void sort(int arr[], int n) { + int t, min; + for (int i = 0; i < n - 1; i++) { + min = i; + for (int j = i + 1; j < n; j++) { + if (arr[min] > arr[j]) { min = j; } + } + t = arr[min]; + arr[min] = arr[i]; + arr[i] = t; + } +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, 4); + int flag = 0; + if (arr[0] + arr[1] > arr[2] || arr[1] + arr[2] > arr[3]) { + flag = 2; + } else if (arr[0] + arr[1] == arr[2] || arr[1] + arr[2] == arr[3]) { + flag = 1; + } + if (flag == 0) { + cout << "IMPOSSIBLE\n"; + } else if (flag == 1) { + cout << "SEGMENT\n"; + } else { + cout << "TRIANGLE\n"; + } +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int e = 0, o = 0; + int ep, op; + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + e = e + 1; + ep = i + 1; + } else { + o = o + 1; + op = i + 1; + } + } + if (e == 1) { + cout << ep << "\n"; + } else { + cout << op << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int e = 0, o = 0; + int ep, op; + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + e = e + 1; + ep = i + 1; + } else { + o = o + 1; + op = i + 1; + } + } + if (e == 1) { + cout << ep << "\n"; + } else { + cout << op << "\n"; + } + return 0; +} +int k, ans; +string s; +int main() { + for (; getline(cin, s);) + if (s[0] == '+') + k++; + else if (s[0] == '-') + k--; + else + ans = ans + (s.size() - s.find(':') - 1) * k; + cout << ans << endl; + return 0; +} +int main() { + int n; + vector v; + while (cin >> n) { + int arr[105], evn = 0, odd = 0; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + v.push_back(arr[i]); + if (arr[i] % 2 == 0) + evn++; + else + odd++; + } + if (odd == 1) { + for (int i = 0; i < n; i++) { + if (v[i] % 2 == 1) { + cout << i + 1 << endl; + break; + } + } + } else { + for (int i = 0; i < n; i++) { + if (v[i] % 2 == 0) { + cout << i + 1 << endl; + break; + } + } + } + v.clear(); + } + return 0; +} +int main() { + string now, goal, way[100]; + int step, i, tstep = 0; + cin >> now >> goal; + while (now != goal) { + if (now[0] == goal[0]) { + step = now[1] - goal[1]; + if (step > 0) + for (i = 0; i < step; i++) { + way[tstep++] = 'D'; + now[1]--; + } + else + for (i = 0; i < -step; i++) { + way[tstep++] = 'U'; + now[1]++; + } + } else if (now[1] == goal[1]) { + step = now[0] - goal[0]; + if (step > 0) + for (i = 0; i < step; i++) { + way[tstep++] = 'L'; + now[0]--; + } + else + for (i = 0; i < -step; i++) { + way[tstep++] = 'R'; + now[0]++; + } + } else if (now[0] < goal[0] && now[1] > goal[1]) { + way[tstep++] = "RD"; + now[0]++; + now[1]--; + } else if (now[0] > goal[0] && now[1] > goal[1]) { + way[tstep++] = "LD"; + now[0]--; + now[1]--; + } else if (now[0] < goal[0] && now[1] < goal[1]) { + way[tstep++] = "RU"; + now[0]++; + now[1]++; + } else if (now[0] > goal[0] && now[1] < goal[1]) { + way[tstep++] = "LU"; + now[0]--; + now[1]++; + } + } + cout << tstep << endl; + for (i = 0; i < tstep; i++) cout << way[i] << endl; + return 0; +} +int main() { + string now, goal, way[100]; + int step, i, tstep = 0; + cin >> now >> goal; + while (now != goal) { + if (now[0] == goal[0]) { + step = now[1] - goal[1]; + if (step > 0) + for (i = 0; i < step; i++) { + way[tstep++] = 'D'; + now[1]--; + } + else + for (i = 0; i < -step; i++) { + way[tstep++] = 'U'; + now[1]++; + } + } else if (now[1] == goal[1]) { + step = now[0] - goal[0]; + if (step > 0) + for (i = 0; i < step; i++) { + way[tstep++] = 'L'; + now[0]--; + } + else + for (i = 0; i < -step; i++) { + way[tstep++] = 'R'; + now[0]++; + } + } else if (now[0] < goal[0] && now[1] > goal[1]) { + way[tstep++] = "RD"; + now[0]++; + now[1]--; + } else if (now[0] > goal[0] && now[1] > goal[1]) { + way[tstep++] = "LD"; + now[0]--; + now[1]--; + } else if (now[0] < goal[0] && now[1] < goal[1]) { + way[tstep++] = "RU"; + now[0]++; + now[1]++; + } else if (now[0] > goal[0] && now[1] < goal[1]) { + way[tstep++] = "LU"; + now[0]--; + now[1]++; + } + } + cout << tstep << endl; + for (i = 0; i < tstep; i++) cout << way[i] << endl; + return 0; +} +int main() { + int i, a[11111]; + bool f; + for (i = 1; i <= 4; i++) cin >> a[i]; + sort(a + 1, a + 5); + f = false; + if (a[1] + a[2] > a[3] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[1] + a[2] > a[4] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[2] + a[3] > a[4] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[1] + a[2] == a[3] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (a[1] + a[2] == a[4] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (a[2] + a[3] == a[4] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (f == false) cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int i, a[11111]; + bool f; + for (i = 1; i <= 4; i++) cin >> a[i]; + sort(a + 1, a + 5); + f = false; + if (a[1] + a[2] > a[3] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[1] + a[2] > a[4] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[2] + a[3] > a[4] && f == false) { + cout << "TRIANGLE" << endl; + f = true; + } + if (a[1] + a[2] == a[3] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (a[1] + a[2] == a[4] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (a[2] + a[3] == a[4] && f == false) { + cout << "SEGMENT" << endl; + f = true; + } + if (f == false) cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + string s; + int dem = 0; + int res = 0; + while (getline(cin, s)) { + if (s[0] == '+') + ++dem; + else if (s[0] == '-') + --dem; + else { + for (int i = 0; i < s.length(); ++i) + if (s[i] == ':') { + res += dem * (s.length() - i - 1); + break; + } + } + } + cout << res << endl; + return 0; +} +int main() { + int n, flag, oCount = 0, eCount = 0; + cin >> n; + int a[n]; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + eCount++; + } else { + oCount++; + } + } + for (int i = 1; i <= n; i++) { + if (eCount > oCount && a[i] % 2 != 0) { flag = i; } + if (eCount < oCount && a[i] % 2 == 0) { flag = i; } + } + cout << flag << endl; + return 0; +} +map mp; +int main() { + int cnt = 0, res = 0; + string txt, name; + while (getline(cin, txt)) { + if (txt.size() == 0) break; + if (txt[0] == '+') { + name = ""; + for (int i = 1; i < txt.size(); i++) name += txt[i]; + mp[name] = 1; + cnt++; + } else if (txt[0] == '-') { + cnt--; + name = ""; + for (int i = 1; i < txt.size(); i++) name += txt[i]; + mp[name] = 0; + } else { + int ind; + for (int i = 0; i < txt.size(); i++) + if (txt[i] == ':') { + ind = i; + break; + } + name = ""; + for (int i = ind + 1; i < txt.size(); i++) name += txt[i]; + res += (cnt * (int)name.size()); + } + } + cout << res << endl; + return 0; +} +map mp; +int main() { + int cnt = 0, res = 0; + string txt, name; + while (getline(cin, txt)) { + if (txt.size() == 0) break; + if (txt[0] == '+') { + name = ""; + for (int i = 1; i < txt.size(); i++) name += txt[i]; + mp[name] = 1; + cnt++; + } else if (txt[0] == '-') { + cnt--; + name = ""; + for (int i = 1; i < txt.size(); i++) name += txt[i]; + mp[name] = 0; + } else { + int ind; + for (int i = 0; i < txt.size(); i++) + if (txt[i] == ':') { + ind = i; + break; + } + name = ""; + for (int i = ind + 1; i < txt.size(); i++) name += txt[i]; + res += (cnt * (int)name.size()); + } + } + cout << res << endl; + return 0; +} +int main() { + string S; + cin >> S; + int x1 = S[0] - 49, y1 = S[1] - 97; + cin >> S; + int x2 = S[0] - 49, y2 = S[1] - 97; + string Way = ""; + int counter = 0; + while (true) { + int sign_X = x2 - x1 != 0 ? (x2 - x1) / abs(x2 - x1) : 0; + int sign_Y = y2 - y1 != 0 ? (y2 - y1) / abs(y2 - y1) : 0; + if (sign_X == 1) { + Way += "R"; + } else if (sign_X == -1) { + Way += "L"; + } + if (sign_Y == 1) { + Way += "U"; + } else if (sign_Y == -1) { + Way += "D"; + } + x1 += sign_X; + y1 += sign_Y; + if (!sign_X & !sign_Y) break; + Way += '\n'; + counter++; + } + cout << counter << endl << Way; +} +int main() { + string S; + cin >> S; + int x1 = S[0] - 49, y1 = S[1] - 97; + cin >> S; + int x2 = S[0] - 49, y2 = S[1] - 97; + string Way = ""; + int counter = 0; + while (true) { + int sign_X = x2 - x1 != 0 ? (x2 - x1) / abs(x2 - x1) : 0; + int sign_Y = y2 - y1 != 0 ? (y2 - y1) / abs(y2 - y1) : 0; + if (sign_X == 1) { + Way += "R"; + } else if (sign_X == -1) { + Way += "L"; + } + if (sign_Y == 1) { + Way += "U"; + } else if (sign_Y == -1) { + Way += "D"; + } + x1 += sign_X; + y1 += sign_Y; + if (!sign_X & !sign_Y) break; + Way += '\n'; + counter++; + } + cout << counter << endl << Way; +} +int main() { + int a, b, E = 0, O = 0; + vector V; + cin >> a; + for (int i = 1; i <= a; i++) { + cin >> b; + V.push_back(b); + if (b % 2 == 0) + E++; + else + O++; + } + if (E > O) { + for (int i = 0; i < V.size(); i++) { + if (V[i] % 2 != 0) cout << i + 1 << endl; + } + } else { + for (int i = 0; i < V.size(); i++) { + if (V[i] % 2 == 0) cout << i + 1 << endl; + } + } + return 0; +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + if (arr[0] + arr[1] > arr[2] || arr[1] + arr[2] > arr[3]) { + cout << "TRIANGLE" << endl; + return 0; + } + if (arr[0] + arr[1] == arr[2] || arr[1] + arr[2] == arr[3]) { + cout << "SEGMENT" << endl; + return 0; + } + cout << "IMPOSSIBLE" << endl; +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + if (arr[0] + arr[1] > arr[2] || arr[1] + arr[2] > arr[3]) { + cout << "TRIANGLE" << endl; + return 0; + } + if (arr[0] + arr[1] == arr[2] || arr[1] + arr[2] == arr[3]) { + cout << "SEGMENT" << endl; + return 0; + } + cout << "IMPOSSIBLE" << endl; +} +int main() { + string s; + int cnt = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + cnt++; + } else if (s[0] == '-') { + cnt--; + } else { + string ns = s.substr(s.find(":")); + ans += cnt * (ns.length() - 1); + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + int cnt = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') { + cnt++; + } else if (s[0] == '-') { + cnt--; + } else { + string ns = s.substr(s.find(":")); + ans += cnt * (ns.length() - 1); + } + } + cout << ans << endl; + return 0; +} +int main() { + vector v; + int n, x, e = 0, o = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + if (x % 2 == 0) + e++; + else + o++; + } + if (e > o) { + for (int i = 0; i < n; i++) + if (v[i] % 2 != 0) cout << i + 1 << endl; + } else { + for (int i = 0; i < n; i++) + if (v[i] % 2 == 0) cout << i + 1 << endl; + } + return 0; +} +int main() { + string s; + int p = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') + p++; + else { + if (s[0] == '-') + p--; + else + ans += p * (s.length() - s.find(':') - 1); + } + } + cout << ans << endl; +} +int main() { + string s; + int p = 0, ans = 0; + while (getline(cin, s)) { + if (s[0] == '+') + p++; + else { + if (s[0] == '-') + p--; + else + ans += p * (s.length() - s.find(':') - 1); + } + } + cout << ans << endl; +} +int a[5]; +bool check(int x, int y, int z) { + if (x + y <= z) return false; + if (y + z <= x) return false; + if (x + z <= y) return false; + return true; +} +bool checkDegenerate(int x, int y, int z) { + if (x + y == z) return true; + if (x + z == y) return true; + if (y + z == x) return true; + return false; +} +int main() { + for (int i = 1; i <= 4; i++) cin >> a[i]; + sort(a + 1, a + 5); + if (check(a[1], a[2], a[3]) || check(a[2], a[3], a[4])) { + cout << "TRIANGLE" << endl; + return 0; + } + if (checkDegenerate(a[1], a[2], a[3]) || checkDegenerate(a[2], a[3], a[4])) { + cout << "SEGMENT" << endl; + return 0; + } + cout << "IMPOSSIBLE" << endl; + return 0; +} +int a[10]; +int b[10][10]; +char csx, ctx; +int sx, sy, tx, ty; +int i, k; +int main() { + cin >> csx >> sy; + cin >> ctx >> ty; + sx = csx - 96; + tx = ctx - 96; + k = 0; + if (sx > tx) { + if (sy > ty) { + while (sx > tx && sy > ty) { + k++; + a[k] = 6; + sx--; + sy--; + } + } + if (sy < ty) { + while (sx > tx && sy < ty) { + k++; + a[k] = 1; + sx--; + sy++; + } + } + } + if (sx < tx) { + if (sy > ty) { + while (sx < tx && sy > ty) { + k++; + a[k] = 8; + sx++; + sy--; + } + } + if (sy < ty) { + while (sx < tx && sy < ty) { + k++; + a[k] = 3; + sx++; + sy++; + } + } + } + while (sx < tx) { + k++; + a[k] = 5; + sx++; + } + while (sx > tx) { + k++; + a[k] = 4; + sx--; + } + while (sy < ty) { + k++; + a[k] = 2; + sy++; + } + while (sy > ty) { + k++; + a[k] = 7; + sy--; + } + cout << k << endl; + for (i = 1; i <= k; i++) { + if (a[i] == 1) { cout << "LU" << endl; } + if (a[i] == 2) { cout << "U" << endl; } + if (a[i] == 3) { cout << "RU" << endl; } + if (a[i] == 4) { cout << "L" << endl; } + if (a[i] == 5) { cout << "R" << endl; } + if (a[i] == 6) { cout << "LD" << endl; } + if (a[i] == 7) { cout << "D" << endl; } + if (a[i] == 8) { cout << "RD" << endl; } + } +} +int a[10]; +int b[10][10]; +char csx, ctx; +int sx, sy, tx, ty; +int i, k; +int main() { + cin >> csx >> sy; + cin >> ctx >> ty; + sx = csx - 96; + tx = ctx - 96; + k = 0; + if (sx > tx) { + if (sy > ty) { + while (sx > tx && sy > ty) { + k++; + a[k] = 6; + sx--; + sy--; + } + } + if (sy < ty) { + while (sx > tx && sy < ty) { + k++; + a[k] = 1; + sx--; + sy++; + } + } + } + if (sx < tx) { + if (sy > ty) { + while (sx < tx && sy > ty) { + k++; + a[k] = 8; + sx++; + sy--; + } + } + if (sy < ty) { + while (sx < tx && sy < ty) { + k++; + a[k] = 3; + sx++; + sy++; + } + } + } + while (sx < tx) { + k++; + a[k] = 5; + sx++; + } + while (sx > tx) { + k++; + a[k] = 4; + sx--; + } + while (sy < ty) { + k++; + a[k] = 2; + sy++; + } + while (sy > ty) { + k++; + a[k] = 7; + sy--; + } + cout << k << endl; + for (i = 1; i <= k; i++) { + if (a[i] == 1) { cout << "LU" << endl; } + if (a[i] == 2) { cout << "U" << endl; } + if (a[i] == 3) { cout << "RU" << endl; } + if (a[i] == 4) { cout << "L" << endl; } + if (a[i] == 5) { cout << "R" << endl; } + if (a[i] == 6) { cout << "LD" << endl; } + if (a[i] == 7) { cout << "D" << endl; } + if (a[i] == 8) { cout << "RD" << endl; } + } +} +int main() { + int res = 0; + string s; + set se; + while (getline(cin, s)) { + if (s[0] == '+') + se.insert(s.substr(1)); + else if (s[0] == '-') + se.erase(s.substr(1)); + else + res += se.size() * s.substr(s.find(':') + 1).size(); + } + cout << res << endl; + return 0; +} +int main() { + int res = 0; + string s; + set se; + while (getline(cin, s)) { + if (s[0] == '+') + se.insert(s.substr(1)); + else if (s[0] == '-') + se.erase(s.substr(1)); + else + res += se.size() * s.substr(s.find(':') + 1).size(); + } + cout << res << endl; + return 0; +} +int main() { + int i, n, op = 0, o = 0, e = 0, ep = 0; + cin >> n; + vector a(n); + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2) { + o++; + if (o == 1) op = i; + } else { + e++; + if (e == 1) ep = i; + } + } + if (o == 1) { + cout << op + 1 << endl; + } else { + cout << ep + 1 << endl; + } + return 0; +} +string res(int x, int y) { + if (x == -1 && y == -1) return "LD"; + if (x == 0 && y == -1) return "D"; + if (x == 1 && y == -1) return "RD"; + if (x == -1 && y == 0) return "L"; + if (x == 1 && y == 0) return "R"; + if (x == -1 && y == 1) return "LU"; + if (x == 0 && y == 1) return "U"; + if (x == 1 && y == 1) return "RU"; +} +int xy(char y1, char y2) { + int y = 0; + if (y1 < y2) + y++; + else if (y1 > y2) + y--; + return y; +} +int main() { + int i, j, k, l, n, count = 0, x, y; + string to, from; + cin >> from >> to; + vector vec; + char x1 = from[0], y1 = from[1], x2 = to[0], y2 = to[1]; + for (i = 0; i < 7; i++) { + if (x1 == x2 && y1 == y2) break; + x = xy(x1, x2); + y = xy(y1, y2); + x1 += x; + y1 += y; + vec.push_back(res(x, y)); + } + cout << vec.size() << endl; + for (i = 0; i < vec.size(); i++) cout << vec[i] << endl; + return 0; +} +string res(int x, int y) { + if (x == -1 && y == -1) return "LD"; + if (x == 0 && y == -1) return "D"; + if (x == 1 && y == -1) return "RD"; + if (x == -1 && y == 0) return "L"; + if (x == 1 && y == 0) return "R"; + if (x == -1 && y == 1) return "LU"; + if (x == 0 && y == 1) return "U"; + if (x == 1 && y == 1) return "RU"; +} +int xy(char y1, char y2) { + int y = 0; + if (y1 < y2) + y++; + else if (y1 > y2) + y--; + return y; +} +int main() { + int i, j, k, l, n, count = 0, x, y; + string to, from; + cin >> from >> to; + vector vec; + char x1 = from[0], y1 = from[1], x2 = to[0], y2 = to[1]; + for (i = 0; i < 7; i++) { + if (x1 == x2 && y1 == y2) break; + x = xy(x1, x2); + y = xy(y1, y2); + x1 += x; + y1 += y; + vec.push_back(res(x, y)); + } + cout << vec.size() << endl; + for (i = 0; i < vec.size(); i++) cout << vec[i] << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || a + b > d || a + c > d || b + c > d) + cout << "TRIANGLE" << endl; + else if (a + b == c || a + b == d || a + c == d || b + c == d) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (c > d) swap(c, d); + if (a > b) swap(a, b); + if (b > c) swap(b, c); + if (a > b) swap(a, b); + if (a + b > c || a + b > d || a + c > d || b + c > d) + cout << "TRIANGLE" << endl; + else if (a + b == c || a + b == d || a + c == d || b + c == d) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int n, arr[101], j, even = 0, odd = 0, g = 0; + cin >> n; + for (j = 1; j <= n; j++) { + cin >> arr[j]; + if (arr[j] % 2 != 0) { + odd += j; + } else { + even += j; + } + } + if (odd > even) { + g = even; + } else { + g = odd; + } + cout << g << endl; +} +int main() { + int n, arr[101], j, even = 0, odd = 0, g = 0; + cin >> n; + for (j = 1; j <= n; j++) { + cin >> arr[j]; + if (arr[j] % 2 != 0) { + odd += j; + } else { + even += j; + } + } + if (odd > even) { + g = even; + } else { + g = odd; + } + cout << g << endl; +} +string s; +int active = 0; +long long ans = 0; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') { + ++active; + } else if (s[0] == '-') { + --active; + } else { + for (int i = 0; i <= s.length() - 1; ++i) { + if (s[i] == ':') { + ans += active * (s.length() - i - 1); + break; + } + } + } + } + cout << ans << "\n"; + return 0; +} +string s; +int active = 0; +long long ans = 0; +int main() { + while (getline(cin, s)) { + if (s[0] == '+') { + ++active; + } else if (s[0] == '-') { + --active; + } else { + for (int i = 0; i <= s.length() - 1; ++i) { + if (s[i] == ':') { + ans += active * (s.length() - i - 1); + break; + } + } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + sort(a, a + 4); + int sum = a[0] + a[1] + a[2] + a[3]; + if (a[2] < a[0] + a[1] || a[3] < a[1] + a[2]) + cout << "TRIANGLE" << endl; + else if (a[2] == a[0] + a[1] || a[3] == a[1] + a[2]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + sort(a, a + 4); + int sum = a[0] + a[1] + a[2] + a[3]; + if (a[2] < a[0] + a[1] || a[3] < a[1] + a[2]) + cout << "TRIANGLE" << endl; + else if (a[2] == a[0] + a[1] || a[3] == a[1] + a[2]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; +} +int main() { + char a, b; + int aa, bb, x, y, ans; + cin >> a >> aa >> b >> bb; + x = b - a; + y = bb - aa; + ans = max(abs(x), abs(y)); + cout << ans << endl; + if (x > 0 && y > 0) { + while (x > 0 && y > 0) { + cout << "RU" << endl; + x--; + y--; + } + while (x > 0) { + cout << "R" << endl; + x--; + } + while (y > 0) { + cout << "U" << endl; + y--; + } + } else if (x < 0 && y < 0) { + while (x < 0 && y < 0) { + cout << "LD" << endl; + x++; + y++; + } + while (x < 0) { + cout << "L" << endl; + x++; + } + while (y < 0) { + cout << "D" << endl; + y++; + } + } else if (x > 0 && y < 0) { + while (x > 0 && y < 0) { + cout << "RD" << endl; + x--; + y++; + } + while (x > 0) { + cout << "R" << endl; + x--; + } + while (y < 0) { + cout << "D" << endl; + y++; + } + } else if (x < 0 && y > 0) { + while (x < 0 && y > 0) { + cout << "LU" << endl; + x++; + y--; + } + while (x < 0) { + cout << "L" << endl; + x++; + } + while (y > 0) { + cout << "U" << endl; + y--; + } + } else { + if (x > 0) + while (x > 0) { + cout << "R" << endl; + x--; + } + else if (y > 0) + while (y > 0) { + cout << "U" << endl; + y--; + } + else if (x < 0) + while (x < 0) { + cout << "L" << endl; + x++; + } + else + while (y < 0) { + cout << "D" << endl; + y++; + } + } + return 0; +} +int main() { + char a, b; + int aa, bb, x, y, ans; + cin >> a >> aa >> b >> bb; + x = b - a; + y = bb - aa; + ans = max(abs(x), abs(y)); + cout << ans << endl; + if (x > 0 && y > 0) { + while (x > 0 && y > 0) { + cout << "RU" << endl; + x--; + y--; + } + while (x > 0) { + cout << "R" << endl; + x--; + } + while (y > 0) { + cout << "U" << endl; + y--; + } + } else if (x < 0 && y < 0) { + while (x < 0 && y < 0) { + cout << "LD" << endl; + x++; + y++; + } + while (x < 0) { + cout << "L" << endl; + x++; + } + while (y < 0) { + cout << "D" << endl; + y++; + } + } else if (x > 0 && y < 0) { + while (x > 0 && y < 0) { + cout << "RD" << endl; + x--; + y++; + } + while (x > 0) { + cout << "R" << endl; + x--; + } + while (y < 0) { + cout << "D" << endl; + y++; + } + } else if (x < 0 && y > 0) { + while (x < 0 && y > 0) { + cout << "LU" << endl; + x++; + y--; + } + while (x < 0) { + cout << "L" << endl; + x++; + } + while (y > 0) { + cout << "U" << endl; + y--; + } + } else { + if (x > 0) + while (x > 0) { + cout << "R" << endl; + x--; + } + else if (y > 0) + while (y > 0) { + cout << "U" << endl; + y--; + } + else if (x < 0) + while (x < 0) { + cout << "L" << endl; + x++; + } + else + while (y < 0) { + cout << "D" << endl; + y++; + } + } + return 0; +} +int main() { + string s; + set S; + long long int answer = 0; + while (getline(cin, s)) { + int n = s.size(); + string str; + if (s[0] == '+') { + for (int i = 1; i < n; i++) { str += s[i]; } + S.insert(str); + } else if (s[0] == '-') { + for (int i = 1; i < n; i++) { str += s[i]; } + S.erase(str); + } else { + int i = 1; + for (; i < n; i++) { + if (s[i] == ':') { break; } + } + answer += (S.size()) * (n - 1 - i); + } + } + cout << answer << '\n'; +} +int main() { + string s; + set S; + long long int answer = 0; + while (getline(cin, s)) { + int n = s.size(); + string str; + if (s[0] == '+') { + for (int i = 1; i < n; i++) { str += s[i]; } + S.insert(str); + } else if (s[0] == '-') { + for (int i = 1; i < n; i++) { str += s[i]; } + S.erase(str); + } else { + int i = 1; + for (; i < n; i++) { + if (s[i] == ':') { break; } + } + answer += (S.size()) * (n - 1 - i); + } + } + cout << answer << '\n'; +} +int main() { + int n; + cin >> n; + int e = 0, ec = 0; + int o = 0, oc = 0; + for (int i = 0; i < n; ++i) { + int t; + cin >> t; + if (t % 2) + o = i + 1, ++oc; + else + e = i + 1, ++ec; + } + cout << (oc > ec ? e : o) << endl; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = -1; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != -1) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = -1; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != -1) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool tr(int a, int b, int c) { + return ((a + b > c) && (a + c > b) && (b + c > a)); +} +bool seg(int a, int b, int c) { + return ((a == b + c) || (b == a + c) || (c == a + b)); +} +int main() { + bool normal = false; + bool deg = false; + int a, b, c, d; + cin >> a >> b >> c >> d; + normal = normal || (tr(a, b, c)); + normal = normal || (tr(a, b, d)); + normal = normal || (tr(a, c, d)); + normal = normal || (tr(b, c, d)); + deg = deg || (seg(a, b, c)); + deg = deg || (seg(a, b, d)); + deg = deg || (seg(a, c, d)); + deg = deg || (seg(b, c, d)); + if (normal) + cout << "TRIANGLE" << endl; + else if (deg) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int a[100], n, count1 = 0, count2 = 0; + cin >> n; + int l, t; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + count1++; + l = i; + } else { + count2++; + t = i; + } + } + if (count1 > count2) { + cout << t << endl; + } else { + cout << l << endl; + } + return 0; +} +int main() { + string arr[4]; + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a + b > c && a + c > b && b + c > a) + arr[0] = "TRIANGLE"; + else if (a + b >= c && a + c >= b && b + c >= a) + arr[0] = "SEGMENT"; + else + arr[0] = "IMPOSSIBLE"; + if (b + c > d && b + d > c && c + d > b) + arr[1] = "TRIANGLE"; + else if (b + c >= d && b + d >= c && c + d >= b) + arr[1] = "SEGMENT"; + else + arr[1] = "IMPOSSIBLE"; + if (a + b > d && b + d > a && a + d > b) + arr[2] = "TRIANGLE"; + else if (a + b >= d && b + d >= a && a + d >= b) + arr[2] = "SEGMENT"; + else + arr[2] = "IMPOSSIBLE"; + if (a + c > d && a + d > c && c + d > a) + arr[3] = "TRIANGLE"; + else if (a + c >= d && a + d >= c && c + d >= a) + arr[3] = "SEGMENT"; + else + arr[3] = "IMPOSSIBLE"; + for (int x = 0; x < 4; x++) { + if (arr[x] == "TRIANGLE") { + cout << "TRIANGLE" << endl; + return 0; + } + } + for (int x = 0; x < 4; x++) { + if (arr[x] == "SEGMENT") { + cout << "SEGMENT" << endl; + return 0; + } + } + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + string arr[4]; + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a + b > c && a + c > b && b + c > a) + arr[0] = "TRIANGLE"; + else if (a + b >= c && a + c >= b && b + c >= a) + arr[0] = "SEGMENT"; + else + arr[0] = "IMPOSSIBLE"; + if (b + c > d && b + d > c && c + d > b) + arr[1] = "TRIANGLE"; + else if (b + c >= d && b + d >= c && c + d >= b) + arr[1] = "SEGMENT"; + else + arr[1] = "IMPOSSIBLE"; + if (a + b > d && b + d > a && a + d > b) + arr[2] = "TRIANGLE"; + else if (a + b >= d && b + d >= a && a + d >= b) + arr[2] = "SEGMENT"; + else + arr[2] = "IMPOSSIBLE"; + if (a + c > d && a + d > c && c + d > a) + arr[3] = "TRIANGLE"; + else if (a + c >= d && a + d >= c && c + d >= a) + arr[3] = "SEGMENT"; + else + arr[3] = "IMPOSSIBLE"; + for (int x = 0; x < 4; x++) { + if (arr[x] == "TRIANGLE") { + cout << "TRIANGLE" << endl; + return 0; + } + } + for (int x = 0; x < 4; x++) { + if (arr[x] == "SEGMENT") { + cout << "SEGMENT" << endl; + return 0; + } + } + cout << "IMPOSSIBLE" << endl; + return 0; +} +const int SZ = 1003; +bool isprime[SZ]; +void sieve() { + fill(isprime, isprime + SZ, 1); + isprime[0] = isprime[1] = 0; + for (int i = 2; i * i < SZ; i++) { + if (isprime[i]) + for (int j = i * i; j < SZ; j += i) { isprime[j] = false; } + } +} +int main() { + sieve(); + int n, k; + cin >> n >> k; + vector primes; + for (int i = 0; i <= n; i++) + if (isprime[i]) primes.push_back(i); + int cnt = 0; + for (int i = 1; i < primes.size(); i++) { + int num = primes[i] + primes[i - 1] + 1; + if (num <= n && isprime[num]) cnt++; + } + if (cnt >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const long long int N = 1e6 + 6, inf = 1e9 + 7; +void tri() { + cout << "TRIANGLE\n", exit(0); +} +void seg() { + cout << "SEGMENT\n", exit(0); +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + vector vec; + vec.push_back(a); + vec.push_back(b); + vec.push_back(c); + vec.push_back(d); + sort(vec.begin(), vec.end()); + for (int i = 1; i < 3; i++) { + if (vec[i] + vec[i - 1] > vec[i + 1]) tri(); + } + for (int i = 1; i < 3; i++) { + if (vec[i] + vec[i - 1] == vec[i + 1]) seg(); + } + cout << "IMPOSSIBLE\n"; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + vector odd; + vector even; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] % 2 == 0) { + even.push_back(i + 1); + } else { + odd.push_back(i + 1); + } + } + if (even.size() == 1) { + cout << even[0] << endl; + } else { + cout << odd[0] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + vector odd; + vector even; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] % 2 == 0) { + even.push_back(i + 1); + } else { + odd.push_back(i + 1); + } + } + if (even.size() == 1) { + cout << even[0] << endl; + } else { + cout << odd[0] << endl; + } + return 0; +} +int ans = 0; +bool isPrime[1005]; +int p[500], ji = 0; +inline void prime() { + isPrime[0] = isPrime[1] = true; + for (int i = 2; i <= 1005; i++) { + if (!isPrime[i]) { + p[ji] = i; + ji++; + for (int j = i + i; j < 1005; j += i) isPrime[j] = true; + } + } +} +int main() { + prime(); + int n, m; + cin >> n >> m; + for (int j = 2; j < n; j++) { + if (isPrime[j + 1]) continue; + for (int i = 0; i < ji - 1; i++) { + if (p[i] + p[i + 1] == j) { + ans++; + break; + } else { + if (p[i] + p[i + 1] > j) break; + } + } + } + if (ans >= m) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int ans = 0; +bool isPrime[1005]; +int p[500], ji = 0; +inline void prime() { + isPrime[0] = isPrime[1] = true; + for (int i = 2; i <= 1005; i++) { + if (!isPrime[i]) { + p[ji] = i; + ji++; + for (int j = i + i; j < 1005; j += i) isPrime[j] = true; + } + } +} +int main() { + prime(); + int n, m; + cin >> n >> m; + for (int j = 2; j < n; j++) { + if (isPrime[j + 1]) continue; + for (int i = 0; i < ji - 1; i++) { + if (p[i] + p[i + 1] == j) { + ans++; + break; + } else { + if (p[i] + p[i + 1] > j) break; + } + } + } + if (ans >= m) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool ifprime(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; i++) + if (a % i == 0) return false; + return true; +} +bool good[3000]; +int main() { + int last = -1; + for (int i = 0; i <= 1000; i++) + if (ifprime(i)) { + if (last != -1) good[i + last + 1] = true; + last = i; + } + for (int i = 0; i <= 1000; i++) + if (!ifprime(i)) good[i] = false; + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 2; i <= n; i++) + if (good[i]) cnt++; + if (cnt >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool ifprime(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; i++) + if (a % i == 0) return false; + return true; +} +bool good[3000]; +int main() { + int last = -1; + for (int i = 0; i <= 1000; i++) + if (ifprime(i)) { + if (last != -1) good[i + last + 1] = true; + last = i; + } + for (int i = 0; i <= 1000; i++) + if (!ifprime(i)) good[i] = false; + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 2; i <= n; i++) + if (good[i]) cnt++; + if (cnt >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + int a = arr[0]; + int b = arr[1]; + int c = arr[2]; + int d = arr[3]; + if (a + b > c || a + c > d || b + c > d) { + cout << "TRIANGLE\n"; + return 0; + } + if (a + b == c || a + c == d || b + c == d) { + cout << "SEGMENT\n"; + return 0; + } + cout << "IMPOSSIBLE\n"; + return 0; +} +int main() { + vector prime(1005, true); + prime[1] = false; + int sq = (int)ceil(sqrt(1005 + 0.0)); + for (int i = 2; i <= sq; i++) { + if (i * i <= 1000) { + for (int j = i * i; j <= 1000; j += i) { prime[j] = false; } + } + } + int n, k, c = 0; + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (prime[i]) { + for (int j = i + 1; j <= n; j++) { + if (prime[j]) { + if (i + j + 1 <= n && prime[i + j + 1] == true) { + c++; + break; + } else + break; + } + } + } + } + if (c >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = int(1e7); +const int INF = (2e9); +const int MOD = (1e9) + 7; +long long n, len[5]; +int main() { + freopen("debug.txt", "w", stderr); + for (int i = 0; i < 4; i++) { cin >> len[i]; } + sort(len, len + 4); + if (len[0] + len[1] > len[2] || len[1] + len[2] > len[3]) { + cout << "TRIANGLE\n"; + } else if (len[0] + len[1] == len[2] || len[1] + len[2] == len[3]) { + cout << "SEGMENT\n"; + } else { + cout << "IMPOSSIBLE\n"; + } + return 0; +} +int s[1005]; +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int f[5]; +int main() { + for (int i = 0; i < 4; i++) { cin >> f[i]; } + sort(f, f + 4); + if (f[0] + f[1] > f[2] || f[1] + f[2] > f[3]) { + cout << "TRIANGLE" << endl; + } else if (f[0] + f[1] == f[2] || f[1] + f[2] == f[3]) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } + return 0; +} +int main() { + int count = 0; + int max = 0, i, j; + string s, key; + cin >> s; + for (i = 1; i < s.size(); i++) { + for (j = 0; j < s.size(); j++) { + key = s.substr(j, i); + if (s.find(key, j + 1) != -1) { + count = i; + break; + } + } + } + cout << count << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector pr(n + 1); + for (int i = 2; i <= n; i++) { + pr[i] = true; + for (int j = 2; j * j <= i; ++j) + if (i % j == 0) pr[i] = false; + } + vector next(n + 1); + for (int j = 0; j <= n; j++) + if (pr[j]) + for (int k = j + 1; k <= n; k++) + if (pr[k]) { + next[j] = k; + break; + } + int cnt = 0; + for (int i = 2; i <= n; i++) + if (pr[i]) + for (int k = 0; k <= i; ++k) + if (pr[k] && i - 1 - k >= 0 && pr[i - 1 - k] && next[k] == i - 1 - k) { + ++cnt; + break; + } + puts(cnt >= k ? "YES" : "NO"); + return 0; +} +int main() { + long long int n, m, a; + cin >> n >> m >> a; + n = n % 10000000000; + m = m % 10000000000; + a = a % 10000000000; + long long int ans; + if (a > n && a > m) + ans = 1; + else { + if ((n % a) > 0) { + n = n / a + 1; + } else { + n = n / a; + } + if (m % a > 0) { + m = m / a + 1; + } else { + m = m / a; + } + ans = n * m; + } + cout << ans << endl; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 0; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 0) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +long long ar[5]; +int main() { + for (int i = 0; i < 4; i++) cin >> ar[i]; + sort(ar, ar + 4); + bool fl = 0; + if (ar[3] < ar[0] + ar[1] || ar[3] < ar[0] + ar[2] || ar[3] < ar[1] + ar[2]) fl = 1; + if (ar[2] < ar[0] + ar[1]) fl = 1; + if (fl == 1) { + puts("TRIANGLE"); + return 0; + } + if (ar[3] == ar[0] + ar[1] || ar[3] == ar[0] + ar[2] || ar[3] == ar[1] + ar[2]) fl = 1; + if (ar[2] == ar[0] + ar[1]) fl = 1; + if (fl == 1) { + puts("SEGMENT"); + } else + puts("IMPOSSIBLE"); + return 0; +} +map freq; +int main() { + string s, temp; + int len = 0; + cin >> s; + for (int i = 0; s[i]; i++) { + temp.clear(); + for (int j = i; s[j]; j++) { + temp += s[j]; + if (++freq[temp] > 1) len = max(len, (int)temp.size()); + } + } + cout << len << endl; + return 0; +} +map freq; +int main() { + string s, temp; + int len = 0; + cin >> s; + for (int i = 0; s[i]; i++) { + temp.clear(); + for (int j = i; s[j]; j++) { + temp += s[j]; + if (++freq[temp] > 1) len = max(len, (int)temp.size()); + } + } + cout << len << endl; + return 0; +} +int main() { + int n, m, a; + cin >> n >> m >> a; + cout << 1ll * (n + a - 1) / a * ((m + a - 1) / a) << endl; +} +int main() { + int n, k; + cin >> n >> k; + vector primos; + vector esPrimo(n + 1, false); + for (int i = 2; i <= n; i++) { + bool primo = true; + for (int j = 2; j * j <= i; j++) { + if (i % j == 0) { + primo = false; + break; + } + } + if (primo) { + primos.push_back(i); + esPrimo[i] = true; + } + } + int res = 0; + for (int i = 0; i < primos.size() - 1; i++) + if (primos[i + 1] + primos[i] + 1 <= n) + if (esPrimo[primos[i + 1] + primos[i] + 1]) res++; + if (res >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector primos; + vector esPrimo(n + 1, false); + for (int i = 2; i <= n; i++) { + bool primo = true; + for (int j = 2; j * j <= i; j++) { + if (i % j == 0) { + primo = false; + break; + } + } + if (primo) { + primos.push_back(i); + esPrimo[i] = true; + } + } + int res = 0; + for (int i = 0; i < primos.size() - 1; i++) + if (primos[i + 1] + primos[i] + 1 <= n) + if (esPrimo[primos[i + 1] + primos[i] + 1]) res++; + if (res >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[10]; +int b[10][10]; +char csx, ctx; +int sx, sy, tx, ty; +int i, k; +int main() { + cin >> csx >> sy; + cin >> ctx >> ty; + sx = csx - 96; + tx = ctx - 96; + k = 0; + if (sx > tx) { + if (sy > ty) { + while (sx > tx && sy > ty) { + k++; + a[k] = 6; + sx--; + sy--; + } + } + if (sy < ty) { + while (sx > tx && sy < ty) { + k++; + a[k] = 1; + sx--; + sy++; + } + } + } + if (sx < tx) { + if (sy > ty) { + while (sx < tx && sy > ty) { + k++; + a[k] = 8; + sx++; + sy--; + } + } + if (sy < ty) { + while (sx < tx && sy < ty) { + k++; + a[k] = 3; + sx++; + sy++; + } + } + } + while (sx < tx) { + k++; + a[k] = 5; + sx++; + } + while (sx > tx) { + k++; + a[k] = 4; + sx--; + } + while (sy < ty) { + k++; + a[k] = 2; + sy++; + } + while (sy > ty) { + k++; + a[k] = 7; + sy--; + } + cout << k << endl; + for (i = 1; i <= k; i++) { + if (a[i] == 1) { cout << "LU" << endl; } + if (a[i] == 2) { cout << "U" << endl; } + if (a[i] == 3) { cout << "RU" << endl; } + if (a[i] == 4) { cout << "L" << endl; } + if (a[i] == 5) { cout << "R" << endl; } + if (a[i] == 6) { cout << "LD" << endl; } + if (a[i] == 7) { cout << "D" << endl; } + if (a[i] == 8) { cout << "RD" << endl; } + } +} +int main() { + string a; + int i = 0, j = 0; + while (cin >> a) { + int count = 0, length = 0; + int len = a.size(); + for (i = 0; i < len; i++) { + j = i + 1; + while (j <= len && i < len) { + if (a[i] == a[j]) { + i++; + j++; + count++; + } else { + if (count > length) length = count; + i = i - count; + j = j - count + 1; + count = 0; + } + } + } + cout << length << endl; + } + return 0; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + sort(a, a + 4); + if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3]) + cout << "TRIANGLE" << endl; + else if (a[0] + a[1] == a[2] || a[1] + a[2] == a[3]) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } else if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } + cout << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } else if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } + cout << endl; + } + return 0; +} +const int N = 1111; +int a[N] = {1, 1}; +int plen; +int p[N], b[N]; +int n, k, num; +int main() { + for (int i = 0; i < N; i++) { + if (!a[i]) { + p[plen++] = i; + for (int j = i * i; j < N; j += i) a[j] = 1; + } + } + cin >> n >> k; + for (int i = 5; i <= n; i++) { + if (!a[i]) { + for (int j = 0; j < plen - 1; j++) { + if (p[j] + p[j + 1] + 1 == i) num++; + } + } + } + cout << (num < k ? "NO\n" : "YES\n"); + return 0; +} +const int N = 1111; +int a[N] = {1, 1}; +int plen; +int p[N], b[N]; +int n, k, num; +int main() { + for (int i = 0; i < N; i++) { + if (!a[i]) { + p[plen++] = i; + for (int j = i * i; j < N; j += i) a[j] = 1; + } + } + cin >> n >> k; + for (int i = 5; i <= n; i++) { + if (!a[i]) { + for (int j = 0; j < plen - 1; j++) { + if (p[j] + p[j + 1] + 1 == i) num++; + } + } + } + cout << (num < k ? "NO\n" : "YES\n"); + return 0; +} +int m, n, a; +int main() { + cin >> m; + cin >> n; + cin >> a; + int l = ceil(n / (a * 1.0)); + int w = ceil(m / (a * 1.0)); + cout << (long long)l * (long long)w << endl; + return 0; +} +int m, n, a; +int main() { + cin >> m; + cin >> n; + cin >> a; + int l = ceil(n / (a * 1.0)); + int w = ceil(m / (a * 1.0)); + cout << (long long)l * (long long)w << endl; + return 0; +} +int main() { + int n = 0, m = 0, l = 0; + char x = ' ', y = ' '; + string s = "\n"; + cin >> x >> n >> y >> m; + while (x != y || n != m) { + if (x < y) { + s += 'R'; + x++; + } + if (x > y) { + s += 'L'; + x--; + } + if (n < m) { + s += 'U'; + n++; + } + if (n > m) { + s += 'D'; + n--; + } + s += '\n'; + l++; + } + cout << l << s; +} +int main() { + int n = 0, m = 0, l = 0; + char x = ' ', y = ' '; + string s = "\n"; + cin >> x >> n >> y >> m; + while (x != y || n != m) { + if (x < y) { + s += 'R'; + x++; + } + if (x > y) { + s += 'L'; + x--; + } + if (n < m) { + s += 'U'; + n++; + } + if (n > m) { + s += 'D'; + n--; + } + s += '\n'; + l++; + } + cout << l << s; +} +const int N = 1e6; +bool tri(int a, int b, int c) { + if (a > b) swap(a, b); + if (a > c) swap(a, c); + if (b > c) swap(b, c); + return (a + b) > c; +} +bool equ(int a, int b, int c) { + if (a > b) swap(a, b); + if (a > c) swap(a, c); + if (b > c) swap(b, c); + return (a + b) == c; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int f = 0; + f |= tri(a, b, c); + f |= tri(a, b, d); + f |= tri(b, c, d); + f |= tri(a, c, d); + if (f) cout << "TRIANGLE" << endl, exit(0); + f |= equ(a, b, c); + f |= equ(a, b, d); + f |= equ(b, c, d); + f |= equ(a, c, d); + if (f) cout << "SEGMENT" << endl, exit(0); + cout << "IMPOSSIBLE" << endl; + return 0; +} +int num[1000 + 10], prime[1000 + 10]; +int main() { + num[0] = num[1] = 1; + for (int i = 2; i * i <= 1000; ++i) { + if (num[i] == 0) { + for (int j = i * i; j <= 1000; j += i) { num[j] = 1; } + } + } + int j = 0; + for (int i = 0; i <= 1000; ++i) { + if (!num[i]) prime[j++] = i; + } + int n, k; + while (cin >> n >> k) { + int sum = 0, cnt = 0; + for (int i = 2; i < j && prime[i - 1] + prime[i - 2] + 1 <= n; ++i) { + sum = 1 + prime[i - 1] + prime[i - 2]; + if (!num[sum]) cnt++; + } + if (cnt >= k) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +double x[100000], y[100000]; +int n, t; +void sorty() { + int i, k; + for (i = 0; i < n; i++) { + int min = x[i]; + int pos = i; + for (k = i + 1; k < n; k++) { + if (x[k] < min) { + min = x[k]; + pos = k; + } + } + swap(x[i], x[pos]); + swap(y[i], y[pos]); + } +} +int main() { + cin >> n >> t; + int i; + for (i = 0; i < n; i++) { + double a, b; + cin >> a >> b; + x[i] = (a - (b / 2.0)); + y[i] = (a + (b / 2.0)); + } + sorty(); + int ct = 2; + for (i = 0; i < n - 1; i++) { + double h = y[i] + t; + if (x[i + 1] >= h) { ct++; } + h = x[i + 1] - t; + if (y[i] < h) { ct++; } + } + cout << ct << endl; +} +int n, m; +int p[1001], can[1001]; +int main() { + int n, k, last = 0; + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (!p[i]) { + k -= can[i]; + if (last != 0 && last + i + 1 <= n) can[last + i + 1] = 1; + last = i; + for (int j = i * i; j <= n; j += i) p[j] = 1; + } + if (k > 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int n, m; +int p[1001], can[1001]; +int main() { + int n, k, last = 0; + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (!p[i]) { + k -= can[i]; + if (last != 0 && last + i + 1 <= n) can[last + i + 1] = 1; + last = i; + for (int j = i * i; j <= n; j += i) p[j] = 1; + } + if (k > 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +char d; +short int x, y, a, b; +int main() { + cin >> d >> y; + x = d - 'a' + 1; + cin >> d >> b; + a = d - 'a' + 1; + cout << max(abs(x - a), abs(y - b)) << '\n'; + while (x != a or y != b) { + if (x > a) { + cout << 'L'; + x--; + } + if (x < a) { + cout << 'R'; + x++; + } + if (y > b) { + cout << 'D'; + y--; + } + if (y < b) { + cout << 'U'; + y++; + } + cout << '\n'; + } + return 0; +} +char d; +short int x, y, a, b; +int main() { + cin >> d >> y; + x = d - 'a' + 1; + cin >> d >> b; + a = d - 'a' + 1; + cout << max(abs(x - a), abs(y - b)) << '\n'; + while (x != a or y != b) { + if (x > a) { + cout << 'L'; + x--; + } + if (x < a) { + cout << 'R'; + x++; + } + if (y > b) { + cout << 'D'; + y--; + } + if (y < b) { + cout << 'U'; + y++; + } + cout << '\n'; + } + return 0; +} +int ans = 0, i, j, k, n; +string s; +int main() { + cin >> s; + n = s.size(); + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (i < j) { + for (k = 0;; k++) + if (i + k >= n || j + k >= n || s[i + k] != s[j + k]) break; + ans = max(ans, k); + } + cout << ans << endl; + return 0; +} +vector primes; +map m; +int n, k; +void check() { + int res = 0; + for (int i = 1; i < primes.size(); ++i) + if (m[primes[i] + primes[i - 1] + 1]) res++; + if (res < k) + cout << "NO\n"; + else + cout << "YES\n"; +} +void sieve(int size) { + bitset<100010> was; + was.set(); + was[0] = was[1] = 0; + for (int i = 2; i <= size; i++) + if (was[i]) { + primes.push_back(i); + m[i] = 1; + for (int j = i * i; j <= size; j += i) was[j] = 0; + } + check(); +} +int main() { + cin >> n >> k; + sieve(n); + return 0; +} +vector primes; +map m; +int n, k; +void check() { + int res = 0; + for (int i = 1; i < primes.size(); ++i) + if (m[primes[i] + primes[i - 1] + 1]) res++; + if (res < k) + cout << "NO\n"; + else + cout << "YES\n"; +} +void sieve(int size) { + bitset<100010> was; + was.set(); + was[0] = was[1] = 0; + for (int i = 2; i <= size; i++) + if (was[i]) { + primes.push_back(i); + m[i] = 1; + for (int j = i * i; j <= size; j += i) was[j] = 0; + } + check(); +} +int main() { + cin >> n >> k; + sieve(n); + return 0; +} +int a[10005]; +int main() { + int n, t; + cin >> n >> t; + t *= 2; + int mi = 5000, mx = 0; + memset(a, 0, sizeof(a)); + while (n--) { + int x, aa; + cin >> x >> aa; + int ll = x * 2 + 4000 - aa; + int rr = x * 2 + 4000 + aa; + for (int i = ll; i <= rr; ++i) { + a[i]++; + mx = max(mx, i); + mi = min(mi, i); + } + } + int len = 0, ans = 2; + for (int i = mi; i <= mx; ++i) { + len++; + if (a[i]) { + if (len > t) + ans += 2; + else if (len == t) + ans++; + len = 0; + } + } + if (len > t) + ans += 2; + else if (len == t) + ans++; + cout << ans << endl; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 3; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 3) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 3; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 3) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const double Pi = acos(-1.0); +int main() { + int n, s; + cin >> n >> s; + int x, size; + double start[1005], end[1005]; + memset(start, 0, sizeof(start)); + memset(end, 0, sizeof(end)); + for (int i = 0; i < n; i++) { + cin >> x >> size; + start[i] = x - size / 2.0; + end[i] = x + size / 2.0; + } + sort(start, start + n); + sort(end, end + n); + int res = 2; + for (int i = 0; i < n - 1; i++) { + double gap = start[i + 1] - end[i]; + if (s < gap) { res += 2; } + if (s == gap) { res++; } + } + cout << res << "\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 3; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 3) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 3; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 3) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + cout << (((a + c - 1) / c) * ((b + c - 1) / c)) << "\n"; +} +int main() { + int n, i, sum = 2; + double x, y, t; + double a[2005]; + cin >> n >> t; + for (i = 0; i < n + n; i = i + 2) { + cin >> x >> y; + a[i] = x - y * 0.5; + a[i + 1] = x + y * 0.5; + } + sort(a, a + n + n); + double b[2005]; + for (i = 1; i < n; i++) { + b[i] = a[i * 2] - a[i * 2 - 1]; + if (b[i] == t) + sum = sum + 1; + else if (b[i] > t) + sum = sum + 2; + } + cout << sum << endl; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 1; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 1) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 1; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 1) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + double n, m, a; + cin >> n >> m >> a; + cout << (long long)ceil(n / a * 1.0) * (long long)ceil(m / a * 1.0) << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int d1 = s[0] - t[0]; + int d2 = s[1] - t[1]; + int m = max(abs(d1), abs(d2)); + char c1 = d1 > 0 ? 'L' : 'R'; + char c2 = d2 > 0 ? 'D' : 'U'; + cout << m << endl; + for (int i = 0; i < min(abs(d1), abs(d2)); i++) { cout << c1 << c2 << endl; } + d1 = abs(d1); + d2 = abs(d2); + if (d1 < d2) c1 = c2; + for (int i = 0; i < abs(d1 - d2); i++) { cout << c1 << endl; } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int d1 = s[0] - t[0]; + int d2 = s[1] - t[1]; + int m = max(abs(d1), abs(d2)); + char c1 = d1 > 0 ? 'L' : 'R'; + char c2 = d2 > 0 ? 'D' : 'U'; + cout << m << endl; + for (int i = 0; i < min(abs(d1), abs(d2)); i++) { cout << c1 << c2 << endl; } + d1 = abs(d1); + d2 = abs(d2); + if (d1 < d2) c1 = c2; + for (int i = 0; i < abs(d1 - d2); i++) { cout << c1 << endl; } + return 0; +} +int main() { + double x, d, c; + int cnt = 0, n, t; + pair arr[1500]; + cin >> n >> t; + for (int i = 0; i < n; i++) { + cin >> x >> d; + d /= 2; + arr[i] = make_pair(x - d, x + d); + } + sort(arr, arr + n); + for (int i = 0; i < n - 1; i++) { + c = arr[i + 1].first - arr[i].second; + c -= t; + if (c == 0) + cnt++; + else if (c > 0) + cnt += 2; + } + cout << cnt + 2 << endl; + return 0; +} +int n, k, t, p[1010], i, j; +bool visit[1010]; +int main() { + cin >> n >> k; + for (i = 2; i <= n; i++) { + if (!visit[i]) p[++*p] = i; + for (j = i * i; j <= n; j += i) visit[j] = 1; + } + for (i = 2; i <= *p; i++) { + if ((t = p[i - 1] + p[i] + 1) <= n && !visit[t]) k--; + } + puts(k <= 0 ? "YES" : "NO"); + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << (int)max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } else if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } + cout << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << (int)max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } else if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } + cout << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int cnt, Max = 0; + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { + cnt = 0; + while (s[i + cnt] == s[j + cnt]) { cnt++; } + Max = max(cnt, Max); + } + } + cout << Max << endl; +} +map mp; +int main() { + int n, t, c = 2; + cin >> n >> t; + double x, y; + pair p[n]; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x >= 0) { + p[i].first = x - (y / 2); + p[i].second = x + (y / 2); + } else { + p[i].first = x - (y / 2); + p[i].second = x + (y / 2); + } + } + sort(p, p + n); + for (int i = 0; i < n; i++) { + x = p[i].first - p[i - 1].second; + if (x == t) + c++; + else if (x > t) + c += 2; + } + cout << c << endl; + return 0; +} +map mp; +int main() { + int n, t, c = 2; + cin >> n >> t; + double x, y; + pair p[n]; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x >= 0) { + p[i].first = x - (y / 2); + p[i].second = x + (y / 2); + } else { + p[i].first = x - (y / 2); + p[i].second = x + (y / 2); + } + } + sort(p, p + n); + for (int i = 0; i < n; i++) { + x = p[i].first - p[i - 1].second; + if (x == t) + c++; + else if (x > t) + c += 2; + } + cout << c << endl; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 9; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 9) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + long long n, m, a, x, y; + cin >> n >> m >> a; + if (n % a != 0 and m % a != 0) { + x = n / a + 1; + y = m / a + 1; + } else if (n % a == 0 and m % a != 0) { + x = n / a; + y = m / a + 1; + } else if (n % a != 0 and m % a == 0) { + x = n / a + 1; + y = m / a; + } else { + x = n / a; + y = m / a; + } + cout << x * y << endl; +} +int main() { + long long n, m, a, x, y; + cin >> n >> m >> a; + if (n % a != 0 and m % a != 0) { + x = n / a + 1; + y = m / a + 1; + } else if (n % a == 0 and m % a != 0) { + x = n / a; + y = m / a + 1; + } else if (n % a != 0 and m % a == 0) { + x = n / a + 1; + y = m / a; + } else { + x = n / a; + y = m / a; + } + cout << x * y << endl; +} +int n, t; +vector coord; +int main() { + cin >> n >> t; + for (int i = 0; i < n; ++i) { + int x, a; + cin >> x >> a; + coord.push_back(1.0 * x - 1.0 * a / 2); + coord.push_back(1.0 * x + 1.0 * a / 2); + } + sort(coord.begin(), coord.end()); + int ans = 2; + for (int i = 1; i < coord.size() - 1; i += 2) { + double x1 = coord[i], x2 = coord[i + 1]; + if (x2 - x1 < t) + continue; + else if (x2 - x1 == t) + ans += 1; + else + ans += 2; + } + cout << ans << "\n"; +} +int n, t; +vector coord; +int main() { + cin >> n >> t; + for (int i = 0; i < n; ++i) { + int x, a; + cin >> x >> a; + coord.push_back(1.0 * x - 1.0 * a / 2); + coord.push_back(1.0 * x + 1.0 * a / 2); + } + sort(coord.begin(), coord.end()); + int ans = 2; + for (int i = 1; i < coord.size() - 1; i += 2) { + double x1 = coord[i], x2 = coord[i + 1]; + if (x2 - x1 < t) + continue; + else if (x2 - x1 == t) + ans += 1; + else + ans += 2; + } + cout << ans << "\n"; +} +int main() { + string inp; + cin >> inp; + int x1 = inp[0] - 'a', y1 = inp[1] - '0'; + cin >> inp; + int x2 = inp[0] - 'a', y2 = inp[1] - '0'; + int k = 0; + string ans; + while (x1 != x2 || y1 != y2) { + if (x1 < x2) { + x1++; + ans += 'R'; + } + if (x1 > x2) { + x1--; + ans += 'L'; + } + if (y1 < y2) { + y1++; + ans += 'U'; + } + if (y1 > y2) { + y1--; + ans += 'D'; + } + ans += '\n'; + k++; + } + cout << k << endl << ans; + return 0; +} +int main() { + long long i, j, c1, c2, n, m, a; + cin >> n >> m >> a; + if (n % a == 0) + c1 = n / a; + else + c1 = n / a + 1; + if (m % a == 0) + c2 = m / a; + else + c2 = m / a + 1; + cout << c1 * c2 << endl; + return 0; +} +int main() { + string s, d; + cin >> s >> d; + string res[64]; + int i; + char c = s[0]; + int r = (int)s[1]; + int ctr = 0; + char dc = d[0]; + int dr = (int)d[1]; + i = 0; + while (c != dc || r != dr) { + if (c < dc) { + if (r == dr) { + res[i] = "R"; + } else if (r > dr) { + res[i] = "RD"; + r--; + } else if (r < dr) { + res[i] = "RU"; + r++; + } + c = (char)(c + 1); + } else if (c > dc) { + if (r == dr) { + res[i] = "L"; + } else if (r > dr) { + res[i] = "LD"; + r--; + } else if (r < dr) { + res[i] = "LU"; + r++; + } + c = (char)(c - 1); + } else if (c == dc) { + if (r > dr) { + res[i] = "D"; + r--; + } else if (r < dr) { + res[i] = "U"; + r++; + } + } + ctr++; + i++; + } + cout << ctr << endl; + for (i = 0; i < ctr; i++) cout << res[i] << endl; + return 0; +} +const int MAXN = 1000005; +int prime[MAXN], num = 0; +bool pd[MAXN]; +void find_prime() { + int i, j; + pd[0] = pd[1] = true; + for (i = 2; i <= MAXN; i++) { + if (!pd[i]) prime[num++] = i; + for (j = 0; j < num; j++) { + if (i * prime[j] > MAXN) break; + pd[i * prime[j]] = true; + if (i % prime[j] == 0) break; + } + } +} +int find(int n) { + int l, r, mid; + l = 0; + r = num - 1; + while (l <= r) { + mid = (l + r) / 2; + if (n > prime[mid]) + l = mid + 1; + else if (n < prime[mid]) + r = mid - 1; + else + return mid; + } + return -1; +} +int mz(int n) { + int pos, t = n; + t = (t - 1) / 2; + while (pd[t]) t++; + pos = find(t); + if (prime[pos - 1] + prime[pos] + 1 == n) return 1; + return 0; +} +int main() { + int n, k, num = 0, i, flag = 0; + cin >> n >> k; + find_prime(); + for (i = 0; prime[i] <= n; i++) { + if (mz(prime[i])) num++; + if (num >= k) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int MAXN = 1000005; +int prime[MAXN], num = 0; +bool pd[MAXN]; +void find_prime() { + int i, j; + pd[0] = pd[1] = true; + for (i = 2; i <= MAXN; i++) { + if (!pd[i]) prime[num++] = i; + for (j = 0; j < num; j++) { + if (i * prime[j] > MAXN) break; + pd[i * prime[j]] = true; + if (i % prime[j] == 0) break; + } + } +} +int find(int n) { + int l, r, mid; + l = 0; + r = num - 1; + while (l <= r) { + mid = (l + r) / 2; + if (n > prime[mid]) + l = mid + 1; + else if (n < prime[mid]) + r = mid - 1; + else + return mid; + } + return -1; +} +int mz(int n) { + int pos, t = n; + t = (t - 1) / 2; + while (pd[t]) t++; + pos = find(t); + if (prime[pos - 1] + prime[pos] + 1 == n) return 1; + return 0; +} +int main() { + int n, k, num = 0, i, flag = 0; + cin >> n >> k; + find_prime(); + for (i = 0; prime[i] <= n; i++) { + if (mz(prime[i])) num++; + if (num >= k) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + long long n, m, a; + cin >> n >> m >> a; + long long stones = (n / a) * (m / a); + if (n % a != 0) { stones += m / a; } + if (m % a != 0) { stones += n / a; } + if (m % a != 0 && n % a != 0) { ++stones; } + cout << stones << endl; + return 0; +} +vector VI, VI2, VI3, VI4; +int n, f = 0, t; +string s; +int main() { + string t; + cin >> s >> t; + int a = s[0] - t[0], b = s[1] - t[1]; + cout << max(abs(a), abs(b)) << endl; + while (a || b) { + if (a > 0) { + cout << "L"; + a--; + } else if (a < 0) { + cout << "R"; + a++; + } + if (b > 0) { + cout << "D"; + b--; + } else if (b < 0) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +vector VI, VI2, VI3, VI4; +int n, f = 0, t; +string s; +int main() { + string t; + cin >> s >> t; + int a = s[0] - t[0], b = s[1] - t[1]; + cout << max(abs(a), abs(b)) << endl; + while (a || b) { + if (a > 0) { + cout << "L"; + a--; + } else if (a < 0) { + cout << "R"; + a++; + } + if (b > 0) { + cout << "D"; + b--; + } else if (b < 0) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +bool prime(int n) { + int m = sqrt(n) + 1; + int flag = 1; + for (int i = 2; i < m; i++) { + if (n % i == 0) { + flag = 0; + break; + } + } + if (flag) { + return true; + } else { + return false; + } +} +int main() { + int n, k, i, tmp = 1, ans = 0, count; + set ju; + while (cin >> n >> k) { + ans = 0; + tmp = 1; + count = 0; + for (i = 3; i < n; i++) { + if (prime(i)) { ju.insert(i); } + } + set::iterator it; + for (it = ju.begin(); it != ju.end(); it++) { + tmp += *it; + if (count >= 2) { + it--; + it--; + tmp -= *it; + } + if (prime(tmp) && tmp <= n) { ans++; } + if (count >= 2) { + it++; + it++; + } + count++; + } + if (ans >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + long long n, m, a; + cin >> n >> m >> a; + long long ans = 0; + if (n % a == 0) { + n = n / a; + } else { + n = n / a + 1; + } + if (m % a == 0) { + m = m / a; + } else { + m = m / a + 1; + } + cout << m * n << endl; + return 0; +} +int a[1001] = {1, 1}; +int p[1001]; +int plen = 0; +int b[2002] = {0}; +int main() { + int i, j, n, k; + for (i = 2; i < 1001; i++) + if (!a[i]) { + p[plen++] = i; + for (j = 2 * i; j < 1001; j += i) a[j] = 1; + } + for (i = 0; i < plen - 1; i++) b[p[i] + p[i + 1] + 1] = 1; + cin >> n >> k; + int num = 0; + for (i = 2; i <= n; i++) + if (b[i] && !a[i]) num++; + puts(num >= k ? "YES" : "NO"); + return 0; +} +int a[1001] = {1, 1}; +int p[1001]; +int plen = 0; +int b[2002] = {0}; +int main() { + int i, j, n, k; + for (i = 2; i < 1001; i++) + if (!a[i]) { + p[plen++] = i; + for (j = 2 * i; j < 1001; j += i) a[j] = 1; + } + for (i = 0; i < plen - 1; i++) b[p[i] + p[i + 1] + 1] = 1; + cin >> n >> k; + int num = 0; + for (i = 2; i <= n; i++) + if (b[i] && !a[i]) num++; + puts(num >= k ? "YES" : "NO"); + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << max((abs(s[0] - t[0])), (abs(s[1] - t[1]))); + cout << endl; + while (s != t) { + if (s[0] > t[0]) { + cout << "L"; + s[0]--; + } + if (s[0] < t[0]) { + cout << "R"; + s[0]++; + } + if (s[1] > t[1]) { + cout << "D"; + s[1]--; + } + if (s[1] < t[1]) { + cout << "U"; + s[1]++; + } + cout << endl; + } +} +int main() { + string s, t; + cin >> s >> t; + cout << max((abs(s[0] - t[0])), (abs(s[1] - t[1]))); + cout << endl; + while (s != t) { + if (s[0] > t[0]) { + cout << "L"; + s[0]--; + } + if (s[0] < t[0]) { + cout << "R"; + s[0]++; + } + if (s[1] > t[1]) { + cout << "D"; + s[1]--; + } + if (s[1] < t[1]) { + cout << "U"; + s[1]++; + } + cout << endl; + } +} +string s; +inline bool judge(string t) { + int pnt = 0; + for (int i = 0; i < s.size(); i++) { + bool f = true; + for (int j = i; j < i + t.size(); j++) + if (t[j - i] != s[j]) f = false; + if (f) pnt++; + } + return (pnt >= 2); +} +int main() { + int ans = 0; + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = i; j < s.size(); j++) { + string x = s.substr(i, j - i + 1); + int sz = x.size(); + if (judge(x)) ans = max(ans, sz); + } + } + cout << ans << endl; + return 0; +} +int n, k, ans; +vector primes; +bool isp(int x) { + if (x < 2) return false; + for (int i = 2; i * i <= x; i++) + if (x % i == 0) return false; + return true; +} +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (isp(i)) primes.push_back(i); + for (int i = 0; i < primes.size() - 1; i++) + if (isp(primes[i] + primes[i + 1] + 1) && primes[i] + primes[i + 1] + 1 <= n) ans++; + if (ans >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a, b; +char c, d; +int main() { + cin >> c >> a >> d >> b; + cout << max(abs(int(c) - int(d)), abs(a - b)) << '\n'; + while (c != d or a != b) { + if (c < d and a < b) { + a++, c++; + cout << "RU\n"; + } else if (c < d and a > b) { + c++, a--; + cout << "RD\n"; + } else if (c > d and a < b) { + c--, a++; + cout << "LU\n"; + } else if (c > d and a > b) { + c--, a--; + cout << "LD\n"; + } else if (c == d) { + if (a < b) { + a++; + cout << "U\n"; + } else { + a--; + cout << "D\n"; + } + } else if (a == b) { + if (c < d) { + c++; + cout << "R\n"; + } else { + c--; + cout << "L\n"; + } + } + } +} +bool isprime(int p) { + if (p < 2) return false; + for (int i = 2; i * i <= p; i++) + if (p % i == 0) return false; + return true; +} +bool can(int p) { + int last = 2; + for (int i = 3; i <= p; i++) { + if (isprime(i)) { + if (last + i == p) return true; + if (last + i > p) return false; + last = i; + } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 2; i <= n; i++) { + if (isprime(i)) { + int s = i - 1; + if (can(s)) { cnt++; } + } + } + if (cnt >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool isprime(int p) { + if (p < 2) return false; + for (int i = 2; i * i <= p; i++) + if (p % i == 0) return false; + return true; +} +bool can(int p) { + int last = 2; + for (int i = 3; i <= p; i++) { + if (isprime(i)) { + if (last + i == p) return true; + if (last + i > p) return false; + last = i; + } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 2; i <= n; i++) { + if (isprime(i)) { + int s = i - 1; + if (can(s)) { cnt++; } + } + } + if (cnt >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + int a = 0; + cin >> s; + for (int l = 1; l <= s.size(); l++) { + vector v; + for (int i = 0; i + l - 1 < s.size(); i++) v.push_back(s.substr(i, l)); + sort(v.begin(), v.end()); + for (int j = 0; j < v.size() - 1; j++) + if (v[j] == v[j + 1]) { + a = l; + break; + } + } + cout << a << endl; + return 0; +} +int main() { + char c1[3], c2[3]; + cin >> c1; + cin >> c2; + int x1, x2, x, y1, y2, y, i, j, ans, xx, yy; + x1 = c1[0] - 'a' + 1; + y1 = c1[1] - '0'; + x2 = c2[0] - 'a' + 1; + y2 = c2[1] - '0'; + x = x1 - x2; + xx = abs(x); + y = y1 - y2; + yy = abs(y); + ans = max(xx, yy); + cout << ans << endl; + while (x != 0) { + if (x < 0) { + if (y < 0) { + cout << "RU" << endl; + x++; + y++; + } else if (y > 0) { + cout << "RD" << endl; + x++; + y--; + } else if (y == 0) { + cout << "R" << endl; + x++; + } + } + if (x > 0) { + if (y < 0) { + cout << "LU" << endl; + x--; + y++; + } else if (y > 0) { + cout << "LD" << endl; + x--; + y--; + } else if (y == 0) { + cout << "L" << endl; + x--; + } + } + } + while (y != 0) { + if (y > 0) { + cout << "D" << endl; + y--; + } + if (y < 0) { + cout << "U" << endl; + y++; + } + } + return 0; +} +int main() { + char c1[3], c2[3]; + cin >> c1; + cin >> c2; + int x1, x2, x, y1, y2, y, i, j, ans, xx, yy; + x1 = c1[0] - 'a' + 1; + y1 = c1[1] - '0'; + x2 = c2[0] - 'a' + 1; + y2 = c2[1] - '0'; + x = x1 - x2; + xx = abs(x); + y = y1 - y2; + yy = abs(y); + ans = max(xx, yy); + cout << ans << endl; + while (x != 0) { + if (x < 0) { + if (y < 0) { + cout << "RU" << endl; + x++; + y++; + } else if (y > 0) { + cout << "RD" << endl; + x++; + y--; + } else if (y == 0) { + cout << "R" << endl; + x++; + } + } + if (x > 0) { + if (y < 0) { + cout << "LU" << endl; + x--; + y++; + } else if (y > 0) { + cout << "LD" << endl; + x--; + y--; + } else if (y == 0) { + cout << "L" << endl; + x--; + } + } + } + while (y != 0) { + if (y > 0) { + cout << "D" << endl; + y--; + } + if (y < 0) { + cout << "U" << endl; + y++; + } + } + return 0; +} +int main() { + char s[1000]; + int m, k; + bool a; + gets(s); + m = strlen(s); + for (int l = m - 1; l >= 1; --l) { + for (int i = 0; i + l <= m; ++i) + for (int j = i + 1; j + l <= m; ++j) { + a = true; + for (k = 0; k < l; ++k) + if (s[i + k] != s[j + k]) { + a = false; + break; + } + if (a) { + cout << k << endl; + return 0; + } + } + } + cout << "0" << endl; + return 0; +} +int m, n, a; +int main() { + cin >> m >> n >> a; + int l = ceil(n / (a * 1.0)); + int w = ceil(m / (a * 1.0)); + cout << ((long long)l * (long long)w) << endl; + return 0; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + long long ans = max(abs(a - c), abs(b - d)); + cout << ans << endl; + while (1) { + if ((a == c) && (b == d)) break; + if (a < c) { + cout << "R"; + a++; + } else if (a > c) { + cout << "L"; + a--; + } + if (b > d) { + cout << "D"; + b--; + } else if (b < d) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + long long ans = max(abs(a - c), abs(b - d)); + cout << ans << endl; + while (1) { + if ((a == c) && (b == d)) break; + if (a < c) { + cout << "R"; + a++; + } else if (a > c) { + cout << "L"; + a--; + } + if (b > d) { + cout << "D"; + b--; + } else if (b < d) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int n, k; +vector Primes(1001); +void sieve() { + for (int i = 0; i < 1001; i++) { + Primes[i] = 1; + Primes[0] = 0; + Primes[1] = 0; + } + for (int i = 2; i <= sqrt(1001); i++) { + if (Primes[i] == 1) { + for (int j = 2; i * j <= 1001; j++) { Primes[i * j] = 0; } + } + } +} +int main() { + sieve(); + cin >> n >> k; + vector v; + for (int i = 2; i < Primes.size(); i++) { + if (Primes[i] == 1) v.push_back(i); + } + int c = 0; + for (int i = n; i >= 2; i--) { + if (Primes[i] == 1) { + int x = i - 1; + for (int j = 0; j < v.size() - 1; j++) { + if (v[j] + v[j + 1] == x) c++; + } + } + } + if (c >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + double n, m, a; + cin >> n >> m >> a; + cout << (long long)ceil(n / a) * (long long)ceil(m / a) << endl; +} +int main() { + string s; + cin >> s; + int l = s.size(); + map m; + for (int i = l - 1; i > 0; i--) { + m.clear(); + for (int j = 0; j < l; j++) { + string ss = s.substr(j, i); + m[ss]++; + if (m[ss] == 2) { + cout << i << endl; + return 0; + } + } + } + cout << 0 << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + if (abs(s1[0] - s2[0]) > abs(s1[1] - s2[1])) + cout << abs(s1[0] - s2[0]) << endl; + else + cout << abs(s1[1] - s2[1]) << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0]--; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0]++; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1]--; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1]++; + } + cout << endl; + } +} +const int N = 20000; +bool f[N + 5] = {0}; +int prime[20000]; +int fin[30000]; +void seive() { + f[0] = f[1] = 1; + for (int i = 1; i <= N; i++) { + if (f[i]) continue; + for (long long j = (long long)i * i; j <= N; j += i) f[j] = 1; + } +} +void primes() { + seive(); + int sum = 5, prevI = 2, c = 1; + prime[0] = 6; + for (int i = 4; i < 2000; ++i) { + if (!f[i]) { + sum -= prevI; + prevI = sum; + sum += i; + prime[c++] = sum + 1; + } + } + memset(fin, 0, 3000); + int test; + for (int i = 0; i < 200; ++i) { + test = prime[i]; + if (!f[test]) fin[test] = 1; + } + for (int i = 1; i < 3000; ++i) { fin[i] += fin[i - 1]; } +} +int main() { + primes(); + int num, k; + cin >> num >> k; + cout << ((fin[num] >= k) ? "YES\n" : "NO\n"); + return 0; +} +const int N = 20000; +bool f[N + 5] = {0}; +int prime[20000]; +int fin[30000]; +void seive() { + f[0] = f[1] = 1; + for (int i = 1; i <= N; i++) { + if (f[i]) continue; + for (long long j = (long long)i * i; j <= N; j += i) f[j] = 1; + } +} +void primes() { + seive(); + int sum = 5, prevI = 2, c = 1; + prime[0] = 6; + for (int i = 4; i < 2000; ++i) { + if (!f[i]) { + sum -= prevI; + prevI = sum; + sum += i; + prime[c++] = sum + 1; + } + } + memset(fin, 0, 3000); + int test; + for (int i = 0; i < 200; ++i) { + test = prime[i]; + if (!f[test]) fin[test] = 1; + } + for (int i = 1; i < 3000; ++i) { fin[i] += fin[i - 1]; } +} +int main() { + primes(); + int num, k; + cin >> num >> k; + cout << ((fin[num] >= k) ? "YES\n" : "NO\n"); + return 0; +} +int main() { + long long n, m, a; + long long i = 0, j = 0; + while (cin >> n >> m >> a) { + if (n % a) + i = n / a + 1; + else + i = n / a; + if (m % a) + j = m / a + 1; + else + j = m / a; + cout << i * j << endl; + } + return 0; +} +int main() { + long long n, m, a; + long long i = 0, j = 0; + while (cin >> n >> m >> a) { + if (n % a) + i = n / a + 1; + else + i = n / a; + if (m % a) + j = m / a + 1; + else + j = m / a; + cout << i * j << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int ans = max(abs(s[0] - t[0]), abs(s[1] - t[1])); + cout << ans << endl; + while (s != t) { + if (s[0] > t[0]) { + s[0] -= 1; + cout << "L"; + } else if (s[0] < t[0]) { + s[0] += 1; + cout << "R"; + } + if (s[1] > t[1]) { + s[1] -= 1; + cout << "D"; + } else if (s[1] < t[1]) { + s[1] += 1; + cout << "U"; + } + cout << "\n"; + } +} +void File() { + freopen("output.txt", "w", stdout); + freopen("input.txt", "r", stdin); +} +void fast() {} +const double pi = 3.1415926; +const int nn = 1e3 + 4; +int arr[nn]; +int x = 0; +bool isprime(int n) { + if (n == 2) return true; + if (n < 2 || n % 2 == 0) return false; + for (int i = 3; i * i <= n; i += 2) { + if (n % i == 0) return false; + } + return true; +} +void solve() { + for (int i = 2; i <= 1000; i++) { + if (isprime(i)) arr[x++] = i; + } +} +int main() { + fast(); + solve(); + int n, k, cnt = 0; + cin >> n >> k; + if (k == 0) { + cout << "YES\n"; + return 0; + } + for (int i = 2; i <= n; i++) { + for (int j = 0; j < x; j++) { + if (arr[j] + arr[j + 1] == i - 1 && isprime(i)) + cnt++; + else if (arr[j] + arr[j + 1] > i - 1) + break; + } + } + if (cnt == k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + char x, xx; + int y, yy; + char c_x, c_y; + int d_y, d_x; + cin >> x >> y >> xx >> yy; + if (xx - x >= 0) { + d_x = abs(xx - x); + c_x = 'R'; + } else { + d_x = abs(xx - x); + c_x = 'L'; + } + if (yy - y >= 0) { + d_y = abs(yy - y); + c_y = 'U'; + } else { + d_y = abs(yy - y); + c_y = 'D'; + } + int get; + if (d_x > d_y) { + get = d_x; + } else { + get = d_y; + } + cout << get << endl; + for (int i = 0; i < get; ++i) { + if (i < d_x) { cout << c_x; } + if (i < d_y) { cout << c_y; } + cout << endl; + } +} +int main() { + char x, xx; + int y, yy; + char c_x, c_y; + int d_y, d_x; + cin >> x >> y >> xx >> yy; + if (xx - x >= 0) { + d_x = abs(xx - x); + c_x = 'R'; + } else { + d_x = abs(xx - x); + c_x = 'L'; + } + if (yy - y >= 0) { + d_y = abs(yy - y); + c_y = 'U'; + } else { + d_y = abs(yy - y); + c_y = 'D'; + } + int get; + if (d_x > d_y) { + get = d_x; + } else { + get = d_y; + } + cout << get << endl; + for (int i = 0; i < get; ++i) { + if (i < d_x) { cout << c_x; } + if (i < d_y) { cout << c_y; } + cout << endl; + } +} +int main() { + long long n; + long long m; + long long a; + cin >> n >> m >> a; + cout << ((n + a - 1) / a) * ((m + a - 1) / a) << endl; + return 0; +} +int main() { + long long n; + long long m; + long long a; + cin >> n >> m >> a; + cout << ((n + a - 1) / a) * ((m + a - 1) / a) << endl; + return 0; +} +int main() { + if (0) { + freopen("CP.inp", "r", stdin); + freopen("CP.out", "w", stdout); + } + string s1, s2; + cin >> s1 >> s2; + cout << max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])) << '\n'; + while (s1 != s2) { + if (s1[0] < s2[0]) + cout << "R", s1[0] += 1; + else if (s1[0] > s2[0]) + cout << "L", s2[0] += 1; + if (s1[1] < s2[1]) + cout << "U", s1[1] += 1; + else if (s1[1] > s2[1]) + cout << "D", s2[1] += 1; + cout << '\n'; + } + return 0; +} +int main() { + if (0) { + freopen("CP.inp", "r", stdin); + freopen("CP.out", "w", stdout); + } + string s1, s2; + cin >> s1 >> s2; + cout << max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])) << '\n'; + while (s1 != s2) { + if (s1[0] < s2[0]) + cout << "R", s1[0] += 1; + else if (s1[0] > s2[0]) + cout << "L", s2[0] += 1; + if (s1[1] < s2[1]) + cout << "U", s1[1] += 1; + else if (s1[1] > s2[1]) + cout << "D", s2[1] += 1; + cout << '\n'; + } + return 0; +} +int main() { + string a; + cin >> a; + int len = a.length(), ans = 0; + for (int i = 1; i <= len - 1; i++) + for (int j = 0; j <= len - i; j++) { + string tmp = a.substr(j, i); + int cnt = 0; + for (int k = 0; k <= len - i; k++) + if (a.substr(k, i) == tmp) cnt++; + if (cnt >= 2) ans = max(ans, i); + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, m, a, ans; + while (cin >> n >> m >> a) { + if (a > n && a > m) + cout << "1" << endl; + else { + if (n % a > 0) + n = (n / a) + 1; + else + n = (n / a); + if (m % a > 0) + m = (m / a) + 1; + else + m = (m / a); + ans = n * m; + cout << ans << endl; + } + } + return 0; +} +int main() { + string a; + while (cin >> a) { + int h = a.size(); + int max = 0; + for (int i = 0; i < h; i++) { + for (int x = i + 1; x < h; x++) { + int m = 0; + while (a[i + m] == a[x + m]) m++; + if (m > max) max = m; + } + } + cout << max << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int s1 = s.at(0); + int s2 = s.at(1); + int t1 = t.at(0); + int t2 = t.at(1); + cout << max(abs(s1 - t1), abs(s2 - t2)) << "\n"; + while (s1 != t1 || s2 != t2) { + if (s1 > t1) { + cout << "L"; + s1--; + } else if (s1 < t1) { + cout << "R"; + s1++; + } + if (s2 > t2) { + cout << "D"; + s2--; + } else if (s2 < t2) { + cout << "U"; + s2++; + } + cout << "\n"; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int s1 = s.at(0); + int s2 = s.at(1); + int t1 = t.at(0); + int t2 = t.at(1); + cout << max(abs(s1 - t1), abs(s2 - t2)) << "\n"; + while (s1 != t1 || s2 != t2) { + if (s1 > t1) { + cout << "L"; + s1--; + } else if (s1 < t1) { + cout << "R"; + s1++; + } + if (s2 > t2) { + cout << "D"; + s2--; + } else if (s2 < t2) { + cout << "U"; + s2++; + } + cout << "\n"; + } + return 0; +} +int main() { + string s; + while (cin >> s) { + int l = s.length(); + int ma = 0; + for (int i = 0; i < l; i++) { + for (int j = i + 1; j < l; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + ma = max(m, ma); + } + } + cout << ma << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int a, b; + a = s1[0] - s2[0]; + b = s1[1] - s2[1]; + a = abs(a); + b = abs(b); + int l = (a > b) ? a : b; + cout << l << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int main() { + long long x, y, a; + cin >> x >> y >> a; + long long xx = x / a, yy = y / a; + if (x % a != 0) xx++; + if (y % a != 0) yy++; + cout << xx * yy << endl; +} +int main() { + long long x, y, a; + cin >> x >> y >> a; + long long xx = x / a, yy = y / a; + if (x % a != 0) xx++; + if (y % a != 0) yy++; + cout << xx * yy << endl; +} +int main() { + string x, y; + cin >> x >> y; + int a = x[0] - y[0]; + int b = x[1] - y[1]; + if (a < 0) { a = -a; } + if (b < 0) { b = -b; } + if (a >= b) { + cout << a << endl; + } else { + cout << b << endl; + } + while (x != y) { + if (x[0] < y[0]) { + cout << "R"; + x[0]++; + } + if (x[0] > y[0]) { + cout << "L"; + x[0]--; + } + if (x[1] < y[1]) { + cout << "U"; + x[1]++; + } + if (x[1] > y[1]) { + cout << "D"; + x[1]--; + } + cout << endl; + } +} +int main() { + long long n, m, a; + cin >> n >> m >> a; + long long rows = (n + a - 1) / a; + long long cols = (m + a - 1) / a; + cout << rows * cols << endl; +} +string q, t; +long long int v, z, b, n, c, w, u, R, D, L, U; +int main() { + cin >> t >> q; + c = abs(q[0] - t[0]); + n = abs(q[1] - t[1]); + b = min(c, n); + c -= b; + n -= b; + w = b; + if (q[0] < t[0]) + L = 1; + else + R = 1; + if (q[1] < t[1]) + D = 1; + else + U = 1; + b += n + c; + cout << b << "\n"; + string G; + if (L && D) + G = "LD"; + else if (L && U) + G = "LU"; + else if (R && D) + G = "RD"; + else if (R && U) + G = "RU"; + for (int i = 1; i <= w; i++) cout << G << "\n"; + if (n) + if (U) + G = "U"; + else + G = "D"; + else if (b) + if (R) + G = "R"; + else + G = "L"; + for (int i = 1; i <= b - w; i++) cout << G << "\n"; +} +string q, t; +long long int v, z, b, n, c, w, u, R, D, L, U; +int main() { + cin >> t >> q; + c = abs(q[0] - t[0]); + n = abs(q[1] - t[1]); + b = min(c, n); + c -= b; + n -= b; + w = b; + if (q[0] < t[0]) + L = 1; + else + R = 1; + if (q[1] < t[1]) + D = 1; + else + U = 1; + b += n + c; + cout << b << "\n"; + string G; + if (L && D) + G = "LD"; + else if (L && U) + G = "LU"; + else if (R && D) + G = "RD"; + else if (R && U) + G = "RU"; + for (int i = 1; i <= w; i++) cout << G << "\n"; + if (n) + if (U) + G = "U"; + else + G = "D"; + else if (b) + if (R) + G = "R"; + else + G = "L"; + for (int i = 1; i <= b - w; i++) cout << G << "\n"; +} +int main() { + string str1; + string str2; + cin >> str1 >> str2; + int n = str2.length(); + for (int i = 0; i < n / 2; i++) swap(str2[i], str2[n - i - 1]); + for (int i = 0; i < n; i++) { + if (str1[i] != str2[i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + string str1; + string str2; + cin >> str1 >> str2; + int n = str2.length(); + for (int i = 0; i < n / 2; i++) swap(str2[i], str2[n - i - 1]); + for (int i = 0; i < n; i++) { + if (str1[i] != str2[i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + long long ans = max(abs(a - c), abs(b - d)); + cout << ans << endl; + while (1) { + if ((a == c) && (b == d)) break; + if (a < c) { + cout << "R"; + a++; + } else if (a > c) { + cout << "L"; + a--; + } + if (b > d) { + cout << "D"; + b--; + } else if (b < d) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + long long ans = max(abs(a - c), abs(b - d)); + cout << ans << endl; + while (1) { + if ((a == c) && (b == d)) break; + if (a < c) { + cout << "R"; + a++; + } else if (a > c) { + cout << "L"; + a--; + } + if (b > d) { + cout << "D"; + b--; + } else if (b < d) { + cout << "U"; + b++; + } + cout << endl; + } + return 0; +} +int maxn = 0; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + for (int j = i; j < s.length(); j++) { + if (i < j) { + int k; + for (k = 0;; k++) + if (s[i + k] != s[j + k]) break; + maxn = max(maxn, k); + } + } + } + cout << maxn << endl; + return 0; +} +int main() { + string current, destination; + cin >> current >> destination; + int udmoves = current[1] - destination[1]; + int rlmoves = current[0] - destination[0]; + cout << max(abs(udmoves), abs(rlmoves)) << "\n"; + while (udmoves != 0 || rlmoves != 0) { + if (udmoves > 0 && rlmoves < 0) { + cout << "RD\n"; + udmoves--; + rlmoves++; + } else if (udmoves < 0 && rlmoves > 0) { + cout << "LU\n"; + udmoves++; + rlmoves--; + } else if (udmoves < 0 && rlmoves < 0) { + cout << "RU\n"; + udmoves++; + rlmoves++; + } else if (udmoves > 0 && rlmoves > 0) { + cout << "LD\n"; + udmoves--; + rlmoves--; + } else if (udmoves > 0 && rlmoves == 0) { + cout << "D\n"; + udmoves--; + } else if (udmoves < 0 && rlmoves == 0) { + cout << "U\n"; + udmoves++; + } else if (udmoves == 0 && rlmoves > 0) { + cout << "L\n"; + rlmoves--; + } else if (udmoves == 0 && rlmoves < 0) { + cout << "R\n"; + rlmoves++; + } + } + return 0; +} +int main() { + string current, destination; + cin >> current >> destination; + int udmoves = current[1] - destination[1]; + int rlmoves = current[0] - destination[0]; + cout << max(abs(udmoves), abs(rlmoves)) << "\n"; + while (udmoves != 0 || rlmoves != 0) { + if (udmoves > 0 && rlmoves < 0) { + cout << "RD\n"; + udmoves--; + rlmoves++; + } else if (udmoves < 0 && rlmoves > 0) { + cout << "LU\n"; + udmoves++; + rlmoves--; + } else if (udmoves < 0 && rlmoves < 0) { + cout << "RU\n"; + udmoves++; + rlmoves++; + } else if (udmoves > 0 && rlmoves > 0) { + cout << "LD\n"; + udmoves--; + rlmoves--; + } else if (udmoves > 0 && rlmoves == 0) { + cout << "D\n"; + udmoves--; + } else if (udmoves < 0 && rlmoves == 0) { + cout << "U\n"; + udmoves++; + } else if (udmoves == 0 && rlmoves > 0) { + cout << "L\n"; + rlmoves--; + } else if (udmoves == 0 && rlmoves < 0) { + cout << "R\n"; + rlmoves++; + } + } + return 0; +} +int main() { + char a, s; + long long n, m, res, o, p; + cin >> a >> n; + cin >> s >> m; + o = n - m; + if (o < 0) o *= -1; + p = int(a) - int(s); + if (p < 0) p *= -1; + res = max(o, p); + cout << res << endl; + if (int(s) < int(a)) { + while ((n != m) && (s != a)) { + if (n > m) { + cout << "LD" << endl; + a = char(int(a) - 1); + n--; + } + if (n < m) { + cout << "LU" << endl; + a = char(int(a) - 1); + n++; + } + } + if (n != m) + while (n != m) { + if (n > m) { + cout << "D" << endl; + n--; + } else { + cout << "U" << endl; + n++; + } + } + if (a != s) + while (a != s) { + cout << "L" << endl; + a = char(int(a) - 1); + } + } else { + while ((n != m) && (s != a)) { + if (n > m) { + cout << "RD" << endl; + a = char(int(a) + 1); + n--; + } + if (n < m) { + cout << "RU" << endl; + a = char(int(a) + 1); + n++; + } + } + if (n != m) + while (n != m) { + if (n > m) { + cout << "D" << endl; + n--; + } else { + cout << "U" << endl; + n++; + } + } + if (a != s) + while (a != s) { + cout << "R" << endl; + a = char(int(a) + 1); + } + } +} +int main() { + char a, s; + long long n, m, res, o, p; + cin >> a >> n; + cin >> s >> m; + o = n - m; + if (o < 0) o *= -1; + p = int(a) - int(s); + if (p < 0) p *= -1; + res = max(o, p); + cout << res << endl; + if (int(s) < int(a)) { + while ((n != m) && (s != a)) { + if (n > m) { + cout << "LD" << endl; + a = char(int(a) - 1); + n--; + } + if (n < m) { + cout << "LU" << endl; + a = char(int(a) - 1); + n++; + } + } + if (n != m) + while (n != m) { + if (n > m) { + cout << "D" << endl; + n--; + } else { + cout << "U" << endl; + n++; + } + } + if (a != s) + while (a != s) { + cout << "L" << endl; + a = char(int(a) - 1); + } + } else { + while ((n != m) && (s != a)) { + if (n > m) { + cout << "RD" << endl; + a = char(int(a) + 1); + n--; + } + if (n < m) { + cout << "RU" << endl; + a = char(int(a) + 1); + n++; + } + } + if (n != m) + while (n != m) { + if (n > m) { + cout << "D" << endl; + n--; + } else { + cout << "U" << endl; + n++; + } + } + if (a != s) + while (a != s) { + cout << "R" << endl; + a = char(int(a) + 1); + } + } +} +int main() { + string s; + while (cin >> s) { + int len = s.length(); + int max1 = 0; + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int main() { + char ar[110]; + cin >> ar; + int l, i, s = 0, j, k, m = 0; + l = strlen(ar); + for (i = 0; i < l; i++) { + for (j = i + 1; j < l; j++) { + s = 0; + while (ar[i + s] == ar[j + s]) s += 1; + m = max(m, s); + } + } + cout << m << endl; + return 0; +} +int main() { + char s1, s2; + int n1, n2; + cin >> s1 >> n1 >> s2 >> n2; + cout << max(abs(s1 - s2), abs(n1 - n2)) << endl; + int a = s1 - s2; + int b = n1 - n2; + while (a != 0 || b != 0) { + if (a > 0) { + a--; + cout << "L"; + } + if (a < 0) { + a++; + cout << "R"; + } + if (b > 0) { + b--; + cout << "D"; + } + if (b < 0) { + b++; + cout << "U"; + } + cout << endl; + } +} +int main() { + char s1, s2; + int n1, n2; + cin >> s1 >> n1 >> s2 >> n2; + cout << max(abs(s1 - s2), abs(n1 - n2)) << endl; + int a = s1 - s2; + int b = n1 - n2; + while (a != 0 || b != 0) { + if (a > 0) { + a--; + cout << "L"; + } + if (a < 0) { + a++; + cout << "R"; + } + if (b > 0) { + b--; + cout << "D"; + } + if (b < 0) { + b++; + cout << "U"; + } + cout << endl; + } +} +int main() { + int n, m, x, y, w, z; + w = y = 51; + x = z = 0; + cin >> n >> m; + char a[51][51]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + if (a[i][j] == '*') { + if (i < w) w = i; + if (i > x) x = i; + if (j < y) y = j; + if (j > z) z = j; + } + } + for (int i = w; i <= x; i++) { + for (int j = y; j <= z; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +vector primes; +map m; +int n, k; +void check() { + int res = 0; + for (int i = 1; i < primes.size(); ++i) + if (m[primes[i] + primes[i - 1] + 1]) res++; + if (res < k) + cout << "NO\n"; + else + cout << "YES\n"; +} +void sieve(int size) { + bitset<100010> was; + was.set(); + was[0] = was[1] = 0; + for (int i = 2; i <= size; i++) + if (was[i]) { + primes.push_back(i); + m[i] = 1; + for (int j = i * i; j <= size; j += i) was[j] = 0; + } + check(); +} +int main() { + cin >> n >> k; + sieve(n); + return 0; +} +vector primes; +map m; +int n, k; +void check() { + int res = 0; + for (int i = 1; i < primes.size(); ++i) + if (m[primes[i] + primes[i - 1] + 1]) res++; + if (res < k) + cout << "NO\n"; + else + cout << "YES\n"; +} +void sieve(int size) { + bitset<100010> was; + was.set(); + was[0] = was[1] = 0; + for (int i = 2; i <= size; i++) + if (was[i]) { + primes.push_back(i); + m[i] = 1; + for (int j = i * i; j <= size; j += i) was[j] = 0; + } + check(); +} +int main() { + cin >> n >> k; + sieve(n); + return 0; +} +int sum[1000000] = {0}; +bool cmp(int a, int b) { + return a > b; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int k = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + int ii = i; + int jj = j; + while (s[ii] == s[jj]) { + ii++; + jj++; + sum[k]++; + } + if (s[i] == s[j]) k++; + } + } + sort(sum, sum + 1000000, cmp); + cout << sum[0] << endl; + return 0; +} +void sieve(int n, vector &prime); +bool is_prime(int num); +int main() { + int n; + int k; + cin >> n >> k; + int count = 0; + int sum = 0; + vector prime; + sieve(n, prime); + for (int i = 0; i < prime.size(); i++) { + sum = prime[i] + prime[i + 1] + 1; + if (is_prime(sum) == true && sum <= n) + count++; + else + continue; + } + if (count >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +void sieve(int n, vector &prime) { + bool mark[n + 1]; + memset(mark, true, sizeof(mark)); + for (int i = 2; i * i <= n; i++) { + if (mark[i] == true) { + for (int j = i * i; j <= n; j += i) { mark[j] = false; } + } + } + for (int i = 2; i <= n; i++) { + if (mark[i] == true) { prime.push_back(i); } + } +} +bool is_prime(int num) { + int count = 0; + if (num == 0) { + return false; + } else { + for (int i = 2; i <= num / 2; i++) { + if (num % i == 0) { + count++; + break; + } else { + continue; + } + } + if (count == 0) { + return true; + } else { + return false; + } + } +} +int main() { + int n, m; + char s[55][55], check[55]; + int mn = 888888, mx = 0, cnt = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + mn = min(j, mn); + mx = max(j, mx); + check[i] = 1; + } + } + } + cnt = 0; + int m1 = 0; + int m2 = 444; + for (int i = 0; i < n; i++) { + if (check[i] == 1) { + m1 = max(i, m1); + m2 = min(i, m2); + } + } + for (int i = m2; i <= m1; i++) { + for (int j = mn; j <= mx; j++) { cout << s[i][j]; } + cout << endl; + } +} +int main() { + int n, m; + char s[55][55], check[55]; + int mn = 888888, mx = 0, cnt = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + mn = min(j, mn); + mx = max(j, mx); + check[i] = 1; + } + } + } + cnt = 0; + int m1 = 0; + int m2 = 444; + for (int i = 0; i < n; i++) { + if (check[i] == 1) { + m1 = max(i, m1); + m2 = min(i, m2); + } + } + for (int i = m2; i <= m1; i++) { + for (int j = mn; j <= mx; j++) { cout << s[i][j]; } + cout << endl; + } +} +bool isPrime(int n) { + if (n == 1) { return false; } + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) { return false; } + } + return true; +} +int nextPrime(int n) { + int ans = n + 1; + while (!isPrime(ans)) ans++; + return ans; +} +bool noldbach(int n) { + for (int i = 2; i < n; i++) { + if (isPrime(i)) { + int nextPrimeNum = nextPrime(i); + if (nextPrimeNum + i + 1 == n) { return true; } + } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (isPrime(i)) + if (noldbach(i)) { + k--; + cerr << i << ' '; + } + } + cerr << '\n'; + cout << (0 >= k ? "YES" : "NO") << '\n'; + return 0; +} +bool isPrime(int n) { + if (n == 1) { return false; } + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) { return false; } + } + return true; +} +int nextPrime(int n) { + int ans = n + 1; + while (!isPrime(ans)) ans++; + return ans; +} +bool noldbach(int n) { + for (int i = 2; i < n; i++) { + if (isPrime(i)) { + int nextPrimeNum = nextPrime(i); + if (nextPrimeNum + i + 1 == n) { return true; } + } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (isPrime(i)) + if (noldbach(i)) { + k--; + cerr << i << ' '; + } + } + cerr << '\n'; + cout << (0 >= k ? "YES" : "NO") << '\n'; + return 0; +} +int main() { + char x[100], y[100], temp[100]; + cin >> x >> y; + int l1 = strlen(x); + int l2 = strlen(y); + int j = 0; + for (int i = l2 - 1; i >= 0; i--, j++) { temp[j] = y[i]; } + int flag = 1; + for (int k = 0; k < l1 && k < l2; k++) { + if (x[k] != temp[k]) { + flag = 0; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int m, n; + cin >> n >> m; + char ar[n][m]; + int uper, lowar, left, right; + int ck = 0; + left = m; + right = 0; + int con = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> ar[i][j]; + if (ck == 0 && ar[i][j] == '*') { + uper = i; + ck = 1; + } else if (ar[i][j] == '*') { + lowar = i; + } + if (ar[i][j] == '*') { + con++; + if (j < left) { left = j; } + if (right < j) { right = j; } + } + } + } + if (con == 1) { cout << "*" << endl; } + if (con > 1) { + for (int i = uper; i <= lowar; i++) { + for (int j = left; j <= right; j++) { cout << ar[i][j]; } + cout << endl; + } + } + return 0; +} +int main() { + int m, n; + cin >> n >> m; + char ar[n][m]; + int uper, lowar, left, right; + int ck = 0; + left = m; + right = 0; + int con = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> ar[i][j]; + if (ck == 0 && ar[i][j] == '*') { + uper = i; + ck = 1; + } else if (ar[i][j] == '*') { + lowar = i; + } + if (ar[i][j] == '*') { + con++; + if (j < left) { left = j; } + if (right < j) { right = j; } + } + } + } + if (con == 1) { cout << "*" << endl; } + if (con > 1) { + for (int i = uper; i <= lowar; i++) { + for (int j = left; j <= right; j++) { cout << ar[i][j]; } + cout << endl; + } + } + return 0; +} +int main() { + int n, i, j, k; + string s; + cin >> s; + n = s.length(); + int ans = 0; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (i < j) { + for (k = 0;; k++) + if (i + k >= n || j + k >= n || s[i + k] != s[j + k]) break; + ans = max(ans, k); + } + cout << ans << endl; + return 0; +} +int main() { + string s, t; + cin >> s; + cin >> t; + reverse(s.begin(), s.end()); + if (s.compare(t) == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector vec(n * m); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> vec[j + i * m]; } + } + int h1 = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (vec[j + i * m] == '*') { + h1 = i; + break; + } + } + if (h1 == i) break; + } + int h2 = -1; + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (vec[j + i * m] == '*') { + h2 = i; + break; + } + } + if (h2 == i) break; + } + int s1 = -1; + for (int j = 0; j < m; j++) { + for (int i = 0; i < n; i++) { + if (vec[j + i * m] == '*') { + s1 = j; + break; + } + } + if (s1 == j) break; + } + int s2 = -1; + for (int j = m - 1; j >= 0; j--) { + for (int i = 0; i < n; i++) { + if (vec[j + i * m] == '*') { + s2 = j; + break; + } + } + if (s2 == j) break; + } + for (h1; h1 <= h2; h1++) { + for (int q = s1; q <= s2; q++) { + if (q == s2) { + cout << vec[q + h1 * m] << endl; + break; + } + cout << vec[q + h1 * m]; + } + } + return 0; +} +bool check(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; i++) + if (a % i == 0) return false; + return true; +} +bool good[2000]; +int main() { + int last = -1; + for (int i = 0; i <= 1000; i++) + if (check(i)) { + if (last != -1) good[i + last + 1] = true; + last = i; + } + for (int i = 0; i <= 1000; i++) + if (!check(i)) good[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; i++) + if (good[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool check(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; i++) + if (a % i == 0) return false; + return true; +} +bool good[2000]; +int main() { + int last = -1; + for (int i = 0; i <= 1000; i++) + if (check(i)) { + if (last != -1) good[i + last + 1] = true; + last = i; + } + for (int i = 0; i <= 1000; i++) + if (!check(i)) good[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; i++) + if (good[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int n = s1.length(), flag = 0; + if (n != s2.length()) flag = 1; + for (int i = 0; i < n && !flag; i++) { + if (s1.at(i) != s2.at(n - 1 - i)) { + flag = 1; + break; + } + } + cout << ((flag) ? ("NO") : ("YES")) << endl; + return 0; +} +int n, m, x = 2e9, y = 2e9, xx, yy; +char a[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') x = min(x, i), y = min(y, j), xx = max(xx, i), yy = max(yy, j); + } + for (int i = x; i <= xx; i++, cout << endl) + for (int j = y; j <= yy; j++) cout << a[i][j]; +} +bool pri(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +int main() { + int n, k; + cin >> n >> k; + int a[168]; + a[0] = 2; + int temp = 1; + for (int i = 3; i < 1000; i += 2) { + if (pri(i)) { + a[temp] = i; + temp++; + } + } + int num = 0; + for (int i = 0; a[i] <= n; i++) { + for (int j = 0; j < i; j++) { + if (a[j] + a[j + 1] + 1 == a[i]) num++; + } + } + if (num >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool pri(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +int main() { + int n, k; + cin >> n >> k; + int a[168]; + a[0] = 2; + int temp = 1; + for (int i = 3; i < 1000; i += 2) { + if (pri(i)) { + a[temp] = i; + temp++; + } + } + int num = 0; + for (int i = 0; a[i] <= n; i++) { + for (int j = 0; j < i; j++) { + if (a[j] + a[j + 1] + 1 == a[i]) num++; + } + } + if (num >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int cmp(int a, int b, string x, int l) { + int t = 0; + for (; a < l && b < l; a++, b++) { + if (x[a] == x[b]) { + t += 1; + } else + break; + } + return t; +} +int main() { + string a; + cin >> a; + int l = a.size(); + int max = 0; + for (int i = 0; i < l - 1; i++) { + for (int j = i + 1; j < l; j++) { + if (a[i] == a[j]) { + int t; + t = cmp(i, j, a, l); + if (t > max) max = t; + } + } + } + cout << max << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(t.begin(), t.end()); + if (s == t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int startx, starty, endx, endy; + char c1, c2; + cin >> c1 >> c2; + startx = c1 - 'a'; + starty = c2 - '1'; + cin >> c1 >> c2; + endx = c1 - 'a'; + endy = c2 - '1'; + vector v; + while (startx != endx || starty != endy) { + if (startx == endx) { + if (starty > endy) { + v.push_back("D"); + starty--; + } else { + v.push_back("U"); + starty++; + } + } else if (starty == endy) { + if (startx > endx) { + v.push_back("L"); + startx--; + } else { + v.push_back("R"); + startx++; + } + } else if (startx > endx && starty > endy) { + v.push_back("LD"); + startx--; + starty--; + } else if (startx > endx && starty < endy) { + v.push_back("LU"); + startx--; + starty++; + } else if (startx < endx && starty > endy) { + v.push_back("RD"); + startx++; + starty--; + } else if (startx < endx && starty < endy) { + v.push_back("RU"); + startx++; + starty++; + } + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) { cout << v[i] << endl; } +} +int main() { + int startx, starty, endx, endy; + char c1, c2; + cin >> c1 >> c2; + startx = c1 - 'a'; + starty = c2 - '1'; + cin >> c1 >> c2; + endx = c1 - 'a'; + endy = c2 - '1'; + vector v; + while (startx != endx || starty != endy) { + if (startx == endx) { + if (starty > endy) { + v.push_back("D"); + starty--; + } else { + v.push_back("U"); + starty++; + } + } else if (starty == endy) { + if (startx > endx) { + v.push_back("L"); + startx--; + } else { + v.push_back("R"); + startx++; + } + } else if (startx > endx && starty > endy) { + v.push_back("LD"); + startx--; + starty--; + } else if (startx > endx && starty < endy) { + v.push_back("LU"); + startx--; + starty++; + } else if (startx < endx && starty > endy) { + v.push_back("RD"); + startx++; + starty--; + } else if (startx < endx && starty < endy) { + v.push_back("RU"); + startx++; + starty++; + } + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) { cout << v[i] << endl; } +} +int num[1000 + 10], prime[1000 + 10]; +int main() { + num[0] = num[1] = 1; + for (int i = 2; i * i <= 1000; ++i) { + if (num[i] == 0) { + for (int j = i * i; j <= 1000; j += i) { num[j] = 1; } + } + } + for (int i = 0, j = 0; i <= 1000; ++i) { + if (!num[i]) prime[j++] = i; + } + int n, k; + while (cin >> n >> k) { + int sum = 0; + for (int i = 2; i <= n; ++i) { + if (!num[i]) { + for (int j = 0; prime[j] + prime[j + 1] + 1 <= i; ++j) { + if (prime[j] + prime[j + 1] + 1 == i) sum++; + } + } + } + if (sum >= k) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int num[1000 + 10], prime[1000 + 10]; +int main() { + num[0] = num[1] = 1; + for (int i = 2; i * i <= 1000; ++i) { + if (num[i] == 0) { + for (int j = i * i; j <= 1000; j += i) { num[j] = 1; } + } + } + for (int i = 0, j = 0; i <= 1000; ++i) { + if (!num[i]) prime[j++] = i; + } + int n, k; + while (cin >> n >> k) { + int sum = 0; + for (int i = 2; i <= n; ++i) { + if (!num[i]) { + for (int j = 0; prime[j] + prime[j + 1] + 1 <= i; ++j) { + if (prime[j] + prime[j + 1] + 1 == i) sum++; + } + } + } + if (sum >= k) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +char a[55][55]; +int main() { + int n, m; + cin >> n >> m; + int l1, l2, c1, c2; + l2 = c2 = 0; + l1 = c1 = 100; + for (int i = 0; i < n; i++) { + int check = 0; + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + check = 1; + if (j < c1) c1 = j; + if (j > c2) c2 = j; + } + } + if (check) { + if (i < l1) l1 = i; + if (i > l2) l2 = i; + } + } + for (int i = l1; i <= l2; i++) { + for (int j = c1; j <= c2; j++) cout << a[i][j]; + cout << endl; + } +} +char a[55][55]; +int main() { + int n, m; + cin >> n >> m; + int l1, l2, c1, c2; + l2 = c2 = 0; + l1 = c1 = 100; + for (int i = 0; i < n; i++) { + int check = 0; + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + check = 1; + if (j < c1) c1 = j; + if (j > c2) c2 = j; + } + } + if (check) { + if (i < l1) l1 = i; + if (i > l2) l2 = i; + } + } + for (int i = l1; i <= l2; i++) { + for (int j = c1; j <= c2; j++) cout << a[i][j]; + cout << endl; + } +} +vector prime; +void sieve(int n) { + bool isprime[4000]; + for (int i = 0; i < 4000; i++) isprime[i] = true; + for (int i = 3; i * i <= 4000; i += 2) { + if (isprime[i]) { + for (int j = i * i; j < 4000; j += i) { isprime[j] = false; } + } + } + prime.push_back(2); + for (int i = 3; i <= n; i += 2) { + if (isprime[i]) { prime.push_back(i); } + } +} +int main() { + int n, k; + cin >> n >> k; + sieve(n); + int cnt = 0; + for (int i = 0; i < prime.size() - 1; i++) { + int num = prime.at(i) + prime.at(i + 1) + 1; + if (binary_search(prime.begin(), prime.end(), num)) { cnt++; } + } + if (cnt == k) { + cout << "YES" << endl; + } else { + if (k == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +long long brr[500000]; +int arr[500000]; +int main() { + map m; + priority_queue q; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + string p = ""; + for (int j = i; j < s.size(); j++) { + p += s[j]; + m[p]++; + } + } + map::iterator it; + for (it = m.begin(); it != m.end(); it++) { + if (it->second >= 2) q.push(it->first.size()); + } + if (q.size() == 0) + cout << "0" << endl; + else + cout << q.top() << endl; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + int m = abs(a - c); + int n = abs(b - d); + int k; + if (m > n) { + cout << m << endl; + k = m; + } else { + cout << n << endl; + k = n; + } + for (int i = 0; i < k; i++) { + if (m > 0) { + m--; + if (a > c) { + cout << 'L'; + } else { + cout << 'R'; + } + } + if (n > 0) { + n--; + if (b > d) { + cout << 'D'; + } else { + cout << 'U'; + } + } + cout << endl; + } + return 0; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + int m = abs(a - c); + int n = abs(b - d); + int k; + if (m > n) { + cout << m << endl; + k = m; + } else { + cout << n << endl; + k = n; + } + for (int i = 0; i < k; i++) { + if (m > 0) { + m--; + if (a > c) { + cout << 'L'; + } else { + cout << 'R'; + } + } + if (n > 0) { + n--; + if (b > d) { + cout << 'D'; + } else { + cout << 'U'; + } + } + cout << endl; + } + return 0; +} +char c[66][66]; +int main() { + int m, n, x1 = 6666, x2 = 0, y1 = 6666, y2 = 0; + cin >> m >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) cin >> c[i][j]; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) { + if (c[i][j] == '*' and i < y1) y1 = i; + if (c[i][j] == '*' and j < x1) x1 = j; + if (c[i][j] == '*' and i > y2) y2 = i; + if (c[i][j] == '*' and j > x2) x2 = j; + } + for (int i = y1; i < y2 + 1; i++) { + for (int j = x1; j < x2 + 1; j++) cout << c[i][j]; + cout << endl; + } + return 0; +} +bool isprime(int p) { + if (p < 2) return false; + for (int i = 2; i * i <= p; i++) + if (p % i == 0) return false; + return true; +} +bool can(int p) { + int last = 2; + for (int i = 3; i <= p; i++) { + if (isprime(i)) { + if (last + i == p) return true; + if (last + i > p) return false; + last = i; + } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 2; i <= n; i++) { + if (isprime(i)) { + int s = i - 1; + if (can(s)) { cnt++; } + } + } + if (cnt >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char ar[110]; + cin >> ar; + int l, i, s = 0, j, k, m = 0; + l = strlen(ar); + for (i = 0; i < l; i++) { + for (j = i + 1; j < l; j++) { + s = 0; + while (ar[i + s] == ar[j + s]) s += 1; + m = max(m, s); + } + } + cout << m << endl; + return 0; +} +int main() { + int i, j; + bool f; + char a[1111], b[1111]; + f = true; + cin >> a; + cin >> b; + j = strlen(b) - 1; + for (i = 0; i <= strlen(a) - 1; i++) { + if (a[i] != b[j]) f = false; + j--; + } + if (f == false) + cout << "NO"; + else + cout << "YES"; + cout << endl; + return 0; +} +int main() { + string start, dest; + cin >> start; + cin >> dest; + char letter_start = start[0]; + char letter_dest = dest[0]; + int num_start = start[1] - '0'; + int num_dest = dest[1] - '0'; + vector way; + while (true) { + if (letter_start == letter_dest && num_start == num_dest) { break; } + if (letter_start < letter_dest && num_start < num_dest) { + way.push_back("RU"); + letter_start += 1; + num_start += 1; + } else if (letter_start < letter_dest && num_start > num_dest) { + way.push_back("RD"); + letter_start += 1; + num_start -= 1; + } else if (letter_start > letter_dest && num_start < num_dest) { + way.push_back("LU"); + letter_start -= 1; + num_start += 1; + } else if (letter_start > letter_dest && num_start > num_dest) { + way.push_back("LD"); + letter_start -= 1; + num_start -= 1; + } else if (letter_start == letter_dest && num_start < num_dest) { + way.push_back("U"); + num_start += 1; + } else if (letter_start == letter_dest && num_start > num_dest) { + way.push_back("D"); + num_start -= 1; + } else if (letter_start < letter_dest && num_start == num_dest) { + way.push_back("R"); + letter_start += 1; + } else if (letter_start > letter_dest && num_start == num_dest) { + way.push_back("L"); + letter_start -= 1; + } + } + if (way.size()) { + cout << way.size() << endl; + for (int i = 0; i < way.size(); ++i) { cout << way[i] << endl; } + } else { + cout << way.size() << endl; + } + return 0; +} +int n, m, startx = 55, starty = 55, finishx, finishy; +char st[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> st[i][j]; + if (st[i][j] == '*') { + startx = min(startx, i); + starty = min(starty, j); + finishx = max(finishx, i); + finishy = max(finishy, j); + } + } + for (int i = startx; i <= finishx; i++) { + for (int j = starty; j <= finishy; j++) { cout << st[i][j]; } + cout << endl; + } + return 0; +} +int n, m, startx = 55, starty = 55, finishx, finishy; +char st[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> st[i][j]; + if (st[i][j] == '*') { + startx = min(startx, i); + starty = min(starty, j); + finishx = max(finishx, i); + finishy = max(finishy, j); + } + } + for (int i = startx; i <= finishx; i++) { + for (int j = starty; j <= finishy; j++) { cout << st[i][j]; } + cout << endl; + } + return 0; +} +bool p[1010]; +bool ok[1010]; +int main() { + memset(p, true, sizeof(p)); + p[0] = p[1] = false; + for (int i = 0; i < (1010); ++i) + if (p[i]) { + for (int j = i + i; j < 1010; j += i) p[j] = false; + } + for (int i = 0; i < (1010); ++i) + if (p[i]) { + for (int j = (i + 1); j <= (1009); ++j) + if (p[j]) { + if (i + j <= 1000) ok[i + j] = true; + break; + } + } + int n, k; + cin >> n >> k; + int r = 0; + for (int i = (2); i <= (n); ++i) + if (ok[i - 1] && p[i]) ++r; + if (r >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + long long v1 = abs(a[0] - b[0]), v2 = abs(a[1] - b[1]); + cout << v1 + v2 - min(v1, v2) << endl; + char c, d; + if (a[0] > b[0]) { + c = 'L'; + } else { + c = 'R'; + } + if (a[1] > b[1]) { + d = 'D'; + } else { + d = 'U'; + } + while (v1 > 0 || v2 > 0) { + if (v1 > 0) { + cout << c; + v1--; + } + if (v2 > 0) { + cout << d; + v2--; + } + cout << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + long long v1 = abs(a[0] - b[0]), v2 = abs(a[1] - b[1]); + cout << v1 + v2 - min(v1, v2) << endl; + char c, d; + if (a[0] > b[0]) { + c = 'L'; + } else { + c = 'R'; + } + if (a[1] > b[1]) { + d = 'D'; + } else { + d = 'U'; + } + while (v1 > 0 || v2 > 0) { + if (v1 > 0) { + cout << c; + v1--; + } + if (v2 > 0) { + cout << d; + v2--; + } + cout << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(s.begin(), s.end()); + if (s == t) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + char i1, i2, l1, l2; + cin >> i1 >> i2 >> l1 >> l2; + cout << max(abs(i1 - l1), abs(i2 - l2)) << endl; + while (i1 != l1 || i2 != l2) { + if (i1 < l1) { + cout << 'R'; + i1++; + } + if (i1 > l1) { + cout << 'L'; + i1--; + } + if (i2 > l2) { + cout << 'D'; + i2--; + } + if (i2 < l2) { + cout << 'U'; + i2++; + } + cout << endl; + } + return 0; +} +int main() { + char i1, i2, l1, l2; + cin >> i1 >> i2 >> l1 >> l2; + cout << max(abs(i1 - l1), abs(i2 - l2)) << endl; + while (i1 != l1 || i2 != l2) { + if (i1 < l1) { + cout << 'R'; + i1++; + } + if (i1 > l1) { + cout << 'L'; + i1--; + } + if (i2 > l2) { + cout << 'D'; + i2--; + } + if (i2 < l2) { + cout << 'U'; + i2++; + } + cout << endl; + } + return 0; +} +int f[90][100]; +int n, m; +char s; +int hangx[4409]; +int coty[4999]; +int tt = 0; +void xaydung(int hang, int cot) { + int x = hang; + int y = cot; + int bao1 = 0; + int bao2 = 0; + int demx = 0; + int demy = 0; + int maxx; + if (m < n) + maxx = n; + else + maxx = m; + for (int i = 1; i <= maxx; i++) { + x += i; + y += i; + if (bao1 == 0 && x <= n && f[x][cot] > 0) + ++demx; + else + bao1 = 1; + if (bao2 == 0 && y <= m && f[hang][y] > 0) + ++demy; + else + bao2 = 1; + if (bao1 * bao2 == 1) break; + x -= i; + y -= i; + } + if (demx == n - 1) { + if (coty[0] > cot || coty[tt - 1] < cot) + for (int i = 1; i <= n; i++) f[i][cot] = 2; + } + if (demy == m - 1) { + if (hangx[0] > hang || hang > hangx[tt - 1]) + for (int i = 1; i <= m; i++) f[hang][i] = 2; + } +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> s; + if (s == '.') + f[i][j] = 1; + else { + f[i][j] = 0; + hangx[tt] = i; + coty[tt] = j; + tt++; + } + } + } + sort(hangx, hangx + tt); + sort(coty, coty + tt); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (f[i][j] > 0) { xaydung(i, j); } + } + } + for (int i = 1; i <= n; i++) { + int chodoi = 0; + for (int j = 1; j <= m; j++) { + if (f[i][j] != 2) { + if (f[i][j] == 1) + cout << "."; + else + cout << "*"; + if (chodoi == 0) chodoi = 1; + } + } + if (chodoi == 1) cout << endl; + } + return 0; +} +int f[90][100]; +int n, m; +char s; +int hangx[4409]; +int coty[4999]; +int tt = 0; +void xaydung(int hang, int cot) { + int x = hang; + int y = cot; + int bao1 = 0; + int bao2 = 0; + int demx = 0; + int demy = 0; + int maxx; + if (m < n) + maxx = n; + else + maxx = m; + for (int i = 1; i <= maxx; i++) { + x += i; + y += i; + if (bao1 == 0 && x <= n && f[x][cot] > 0) + ++demx; + else + bao1 = 1; + if (bao2 == 0 && y <= m && f[hang][y] > 0) + ++demy; + else + bao2 = 1; + if (bao1 * bao2 == 1) break; + x -= i; + y -= i; + } + if (demx == n - 1) { + if (coty[0] > cot || coty[tt - 1] < cot) + for (int i = 1; i <= n; i++) f[i][cot] = 2; + } + if (demy == m - 1) { + if (hangx[0] > hang || hang > hangx[tt - 1]) + for (int i = 1; i <= m; i++) f[hang][i] = 2; + } +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> s; + if (s == '.') + f[i][j] = 1; + else { + f[i][j] = 0; + hangx[tt] = i; + coty[tt] = j; + tt++; + } + } + } + sort(hangx, hangx + tt); + sort(coty, coty + tt); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (f[i][j] > 0) { xaydung(i, j); } + } + } + for (int i = 1; i <= n; i++) { + int chodoi = 0; + for (int j = 1; j <= m; j++) { + if (f[i][j] != 2) { + if (f[i][j] == 1) + cout << "."; + else + cout << "*"; + if (chodoi == 0) chodoi = 1; + } + } + if (chodoi == 1) cout << endl; + } + return 0; +} +int num[1000 + 10], prime[1000 + 10]; +int main() { + num[0] = num[1] = 1; + for (int i = 2; i * i <= 1000; ++i) { + if (num[i] == 0) { + for (int j = i * i; j <= 1000; j += i) { num[j] = 1; } + } + } + int j = 0; + for (int i = 0; i <= 1000; ++i) { + if (!num[i]) prime[j++] = i; + } + int n, k; + while (cin >> n >> k) { + int sum = 0, cnt = 0; + for (int i = 2; i < j && prime[i - 1] + prime[i - 2] + 1 <= n; ++i) { + sum = 1 + prime[i - 1] + prime[i - 2]; + if (!num[sum]) cnt++; + } + if (cnt >= k) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int num[1000 + 10], prime[1000 + 10]; +int main() { + num[0] = num[1] = 1; + for (int i = 2; i * i <= 1000; ++i) { + if (num[i] == 0) { + for (int j = i * i; j <= 1000; j += i) { num[j] = 1; } + } + } + int j = 0; + for (int i = 0; i <= 1000; ++i) { + if (!num[i]) prime[j++] = i; + } + int n, k; + while (cin >> n >> k) { + int sum = 0, cnt = 0; + for (int i = 2; i < j && prime[i - 1] + prime[i - 2] + 1 <= n; ++i) { + sum = 1 + prime[i - 1] + prime[i - 2]; + if (!num[sum]) cnt++; + } + if (cnt >= k) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int i, j; +int main() { + string a; + while (cin >> a) { + int len = a.size(); + int count = 0, maxx = 0, x, y; + for (i = 0; i < len; i++) { + for (j = i + 1; j < len; j++) { + if (a[j] == a[i]) { + x = j; + y = i; + while (a[x] == a[y] && y < len) { + count++; + x++; + y++; + } + if (count > maxx) maxx = count; + count = 0; + } + } + } + cout << maxx << endl; + } + return 0; +} +int main() { + string s, n; + cin >> s >> n; + int j = 0, f = s.size(); + for (int i = f - 1; i >= 0; i--) { + if (s[i] != n[j]) { + cout << "NO" << endl; + return 0; + } + j++; + } + cout << "YES" << endl; + return 0; +} +int main() { + string s, n; + cin >> s >> n; + int j = 0, f = s.size(); + for (int i = f - 1; i >= 0; i--) { + if (s[i] != n[j]) { + cout << "NO" << endl; + return 0; + } + j++; + } + cout << "YES" << endl; + return 0; +} +int n, m; +int p[1001], can[1001]; +int main() { + int n, k, last = 0; + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (!p[i]) { + k -= can[i]; + if (last != 0 && last + i + 1 <= n) can[last + i + 1] = 1; + last = i; + for (int j = i * i; j <= n; j += i) p[j] = 1; + } + if (k > 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int n, m; +int p[1001], can[1001]; +int main() { + int n, k, last = 0; + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (!p[i]) { + k -= can[i]; + if (last != 0 && last + i + 1 <= n) can[last + i + 1] = 1; + last = i; + for (int j = i * i; j <= n; j += i) p[j] = 1; + } + if (k > 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +string s; +set all; +int main() { + cin >> s; + int n = s.size(); + for (int i = n - 1; i > 0; i--) { + all.clear(); + for (int j = 0; j + i <= n; j++) all.insert(s.substr(j, i)); + if (all.size() != n - i + 1) { + cout << i << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int x1, y1; + int x2, y2; + x1 = s1[0] - 'a'; + y1 = s1[1] - '1'; + x2 = s2[0] - 'a'; + y2 = s2[1] - '1'; + int count = 0; + string str[1000]; + while (x1 != x2 || y1 != y2) { + if (x1 > x2 && y1 > y2) { + str[count] = "LD"; + count++; + y1--; + x1--; + } else if (x1 < x2 && y1 > y2) { + str[count] = "RD"; + count++; + y1--; + x1++; + } else if (x1 > x2 && y1 < y2) { + str[count] = "LU"; + count++; + x1--; + y1++; + } else if (x1 < x2 && y1 < y2) { + str[count] = "RU"; + count++; + x1++; + y1++; + } else if (x1 == x2 && y1 > y2) { + str[count] = "D"; + count++; + y1--; + } else if (x1 == x2 && y1 < y2) { + str[count] = "U"; + count++; + y1++; + } else if (x1 > x2 && y1 == y2) { + str[count] = "L"; + count++; + x1--; + } else if (x1 < x2 && y1 == y2) { + str[count] = "R"; + count++; + x1++; + } + } + cout << count << endl; + for (int i = 0; i < count; i++) { cout << str[i] << endl; } +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int x1, y1; + int x2, y2; + x1 = s1[0] - 'a'; + y1 = s1[1] - '1'; + x2 = s2[0] - 'a'; + y2 = s2[1] - '1'; + int count = 0; + string str[1000]; + while (x1 != x2 || y1 != y2) { + if (x1 > x2 && y1 > y2) { + str[count] = "LD"; + count++; + y1--; + x1--; + } else if (x1 < x2 && y1 > y2) { + str[count] = "RD"; + count++; + y1--; + x1++; + } else if (x1 > x2 && y1 < y2) { + str[count] = "LU"; + count++; + x1--; + y1++; + } else if (x1 < x2 && y1 < y2) { + str[count] = "RU"; + count++; + x1++; + y1++; + } else if (x1 == x2 && y1 > y2) { + str[count] = "D"; + count++; + y1--; + } else if (x1 == x2 && y1 < y2) { + str[count] = "U"; + count++; + y1++; + } else if (x1 > x2 && y1 == y2) { + str[count] = "L"; + count++; + x1--; + } else if (x1 < x2 && y1 == y2) { + str[count] = "R"; + count++; + x1++; + } + } + cout << count << endl; + for (int i = 0; i < count; i++) { cout << str[i] << endl; } +} +long long int sievesize = 1000; +bitset<1009> bs; +vector primes; +void sieve() { + bs.set(); + bs[0] = bs[1] = 0; + for (long long int i = 2; i <= sievesize; i++) { + if (bs[i]) { + for (long long int j = i * i; j <= sievesize; j += i) bs[j] = 0; + primes.push_back(i); + } + } +} +int main() { + sieve(); + int n, k; + cin >> n >> k; + int res = 0; + for (int i = 4; primes[i] <= n; i++) { + for (int j = 0; j < primes.size() - 1; j++) { + if (primes[j] + primes[j + 1] + 1 == primes[i]) { res++; } + } + } + if (res >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s, c; + int n, i, j, x = 0, k = 0; + cin >> s; + cin >> c; + reverse(c.begin(), c.end()); + if (c == s) { cout << "YES" << endl; } + if (c != s) { cout << "NO" << endl; } + return 0; +} +char a[100][100]; +int main() { + int n, m; + cin >> n >> m; + int x1 = 100, x2 = -100, y1 = 100, y2 = -100; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + x1 = min(x1, j); + x2 = max(x2, j); + y1 = min(y1, i); + y2 = max(y2, i); + } + } + } + for (int i = y1; i <= y2; i++) { + for (int j = x1; j <= x2; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int primes[600], point = 0; +bool isprime(int x) { + int res = 0; + for (int i = 1; i <= x; i++) + if (x % i == 0) res++; + return res == 2; +} +void putprime() { + for (int i = 2; i < 600; i++) + if (isprime(i)) primes[point++] = i; + return; +} +bool isNoldPrime(int x) { + if (!isprime(x)) return false; + for (int i = 0; primes[i] * 2 <= x; i++) + if (primes[i] + primes[i + 1] + 1 == x) return true; + return false; +} +int main() { + int a, b; + cin >> a >> b; + putprime(); + for (int i = 2; i <= a; i++) + if (isNoldPrime(i)) b--; + puts(b <= 0 ? "YES" : "NO"); + return 0; +} +int primes[600], point = 0; +bool isprime(int x) { + int res = 0; + for (int i = 1; i <= x; i++) + if (x % i == 0) res++; + return res == 2; +} +void putprime() { + for (int i = 2; i < 600; i++) + if (isprime(i)) primes[point++] = i; + return; +} +bool isNoldPrime(int x) { + if (!isprime(x)) return false; + for (int i = 0; primes[i] * 2 <= x; i++) + if (primes[i] + primes[i + 1] + 1 == x) return true; + return false; +} +int main() { + int a, b; + cin >> a >> b; + putprime(); + for (int i = 2; i <= a; i++) + if (isNoldPrime(i)) b--; + puts(b <= 0 ? "YES" : "NO"); + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int a, b; + a = s1[0] - s2[0]; + b = s1[1] - s2[1]; + a = abs(a); + b = abs(b); + int l = (a > b) ? a : b; + cout << l << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int main() { + string m; + string p; + while (cin >> m >> p) { + reverse(p.begin(), p.end()); + if (p == m) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } +} +int main() { + string m; + string p; + while (cin >> m >> p) { + reverse(p.begin(), p.end()); + if (p == m) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + string q[n]; + char A[n][m]; + for (int i = 0; i < n; i++) cin >> q[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) A[i][j] = q[i][j]; + int u = 0, d = n - 1, r = n - 1, l = 0; + for (int i = 0; i < n; i++) { + u = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = n - 1; i >= 0; i--) { + d = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = 0; j < m; j++) { + l = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = m - 1; j >= 0; j--) { + r = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) cout << A[i][j]; + cout << endl; + } + return 0; +} +int main() { + string a; + cin >> a; + int num = 0; + for (int i = 0; i < a.length() - 1; i++) { + for (int j = i + 1; j < a.length(); j++) { + if (a[i] == a[j]) { + int nn = 1; + for (int ii = i + 1, jj = j + 1; jj < a.length(); jj++, ii++) { + if (a[ii] == a[jj]) + nn++; + else + break; + } + if (nn > num) num = nn; + } + } + } + cout << num << endl; + return 0; +} +int main() { + char x1, x2; + int cx, cy, dx, dy; + int ans; + while (cin >> x1 >> cy >> x2 >> dy) { + cx = x1 - 48 - '0'; + dx = x2 - 48 - '0'; + int xd = cx - dx, yd = cy - dy; + ans = max(abs(xd), abs(yd)); + cout << ans << endl; + while (ans--) { + if (xd > 0) { + cout << "L"; + xd--; + } + if (xd < 0) { + cout << "R"; + xd++; + } + if (yd > 0) { + cout << "D"; + yd--; + } + if (yd < 0) { + cout << "U"; + yd++; + } + cout << endl; + } + } + return 0; +} +int main() { + char x1, x2; + int cx, cy, dx, dy; + int ans; + while (cin >> x1 >> cy >> x2 >> dy) { + cx = x1 - 48 - '0'; + dx = x2 - 48 - '0'; + int xd = cx - dx, yd = cy - dy; + ans = max(abs(xd), abs(yd)); + cout << ans << endl; + while (ans--) { + if (xd > 0) { + cout << "L"; + xd--; + } + if (xd < 0) { + cout << "R"; + xd++; + } + if (yd > 0) { + cout << "D"; + yd--; + } + if (yd < 0) { + cout << "U"; + yd++; + } + cout << endl; + } + } + return 0; +} +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +bool judge(int y); +int main() { + int a[1000], u = 1; + a[0] = 2; + for (int i = 3; i < 1000; i += 2) { + bool flag = 1; + for (int j = 0; j < u; j++) { + if (i % a[j] == 0) { + flag = 0; + break; + } + } + if (flag) { + a[u] = i; + u++; + } + } + int m, n; + cin >> n >> m; + int aa = 0; + for (int ii = 2; ii <= n; ii++) { + bool p = 0; + for (int s = 0; a[s] <= ii; s++) { + if (a[s] == ii) p = 1; + } + if (p) { + for (int r = 0; a[r + 1] < ii; r++) { + if (a[r] + a[r + 1] + 1 == ii) { + aa++; + break; + } + } + } + } + if (aa >= m) { + cout << "YES" << endl; + } else + cout << "NO" << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int mx = max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])); + cout << mx << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int mx = max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])); + cout << mx << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int xmin = 200, xmax = -1, ymin = 200, ymax = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + xmin = xmin > i ? i : xmin; + xmax = xmax < i ? i : xmax; + ymin = ymin > j ? j : ymin; + ymax = ymax < j ? j : ymax; + } + } + } + for (int i = xmin; i <= xmax; i++) { + for (int j = ymin; j <= ymax; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int xmin = 200, xmax = -1, ymin = 200, ymax = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + xmin = xmin > i ? i : xmin; + xmax = xmax < i ? i : xmax; + ymin = ymin > j ? j : ymin; + ymax = ymax < j ? j : ymax; + } + } + } + for (int i = xmin; i <= xmax; i++) { + for (int j = ymin; j <= ymax; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 0; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 0) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 0; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 0) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int rx[8] = {1, 1, -1, 0, 0, -1, -1, 1}; +int ry[8] = {0, 1, 0, -1, 1, 1, -1, -1}; +int main() { + string s; + cin >> s; + int x = s[0] - 'a'; + int y = s[1] - '0' - 1; + cin >> s; + int xf = s[0] - 'a'; + int yf = s[1] - '0' - 1; + int kol = 0; + vector ans; + while (1) { + if (xf == x && yf == y) break; + if (x < xf && y < yf) + kol++, ans.push_back("RU"), x++, y++; + else if (x > xf && y > yf) + kol++, ans.push_back("LD"), x--, y--; + else if (x > xf && y < yf) + kol++, ans.push_back("LU"), x--, y++; + else if (x < xf && y > yf) + kol++, ans.push_back("RD"), x++, y--; + else if (x == xf && y < yf) + kol++, ans.push_back("U"), y++; + else if (x == xf && y > yf) + kol++, ans.push_back("D"), y--; + else if (x > xf && y == yf) + kol++, ans.push_back("L"), x--; + else if (x < xf && y == yf) + kol++, ans.push_back("R"), x++; + } + cout << kol << '\n'; + for (int i = 0; i < int(ans.size()); ++i) { cout << ans[i] << '\n'; } + return 0; +} +int rx[8] = {1, 1, -1, 0, 0, -1, -1, 1}; +int ry[8] = {0, 1, 0, -1, 1, 1, -1, -1}; +int main() { + string s; + cin >> s; + int x = s[0] - 'a'; + int y = s[1] - '0' - 1; + cin >> s; + int xf = s[0] - 'a'; + int yf = s[1] - '0' - 1; + int kol = 0; + vector ans; + while (1) { + if (xf == x && yf == y) break; + if (x < xf && y < yf) + kol++, ans.push_back("RU"), x++, y++; + else if (x > xf && y > yf) + kol++, ans.push_back("LD"), x--, y--; + else if (x > xf && y < yf) + kol++, ans.push_back("LU"), x--, y++; + else if (x < xf && y > yf) + kol++, ans.push_back("RD"), x++, y--; + else if (x == xf && y < yf) + kol++, ans.push_back("U"), y++; + else if (x == xf && y > yf) + kol++, ans.push_back("D"), y--; + else if (x > xf && y == yf) + kol++, ans.push_back("L"), x--; + else if (x < xf && y == yf) + kol++, ans.push_back("R"), x++; + } + cout << kol << '\n'; + for (int i = 0; i < int(ans.size()); ++i) { cout << ans[i] << '\n'; } + return 0; +} +int main() { + int n, m, x, y, p, q; + char mat[55][55]; + cin >> n >> m; + x = 49; + y = 49; + p = 0; + q = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> mat[i][j]; + if (mat[i][j] == '*') { + if (i <= x) x = i; + if (j <= y) y = j; + if (i >= p) p = i; + if (j >= q) q = j; + } + } + } + for (int i = x; i <= p; i++) { + for (int j = y; j <= q; j++) { cout << mat[i][j]; } + cout << endl; + } + return 0; +} +bool tp(int a) { + if (a < 2) { return false; } + for (int i = 2; i * i <= a; i++) { + if (a % i == 0) { return false; } + } + return true; +} +bool cm(int a) { + int lt = 2; + for (int i = 3; i <= a; i++) { + if (tp(i)) { + if (lt + i == a) { return true; } + if (lt + i > a) { return false; } + lt = i; + } + } + return false; +} +int n, k, cnt; +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (tp(i)) { + int p = i - 1; + if (cm(p)) { cnt++; } + } + } + if (cnt >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +bool tp(int a) { + if (a < 2) { return false; } + for (int i = 2; i * i <= a; i++) { + if (a % i == 0) { return false; } + } + return true; +} +bool cm(int a) { + int lt = 2; + for (int i = 3; i <= a; i++) { + if (tp(i)) { + if (lt + i == a) { return true; } + if (lt + i > a) { return false; } + lt = i; + } + } + return false; +} +int n, k, cnt; +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (tp(i)) { + int p = i - 1; + if (cm(p)) { cnt++; } + } + } + if (cnt >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int min(int, int); +int main() { + int i, xie, n, y1, y2, dx, dy; + char a, b, c; + string s1; + cin >> a >> y1 >> b >> y2; + dy = y2 - y1; + dx = int(b) - int(a); + xie = min(dx, dy); + n = xie + abs(abs(dx) - abs(dy)); + cout << n << endl; + if (dx > 0 && dy > 0) s1 = "RU"; + if (dx < 0 && dy > 0) s1 = "LU"; + if (dx > 0 && dy < 0) s1 = "RD"; + if (dx < 0 && dy < 0) s1 = "LD"; + for (i = 0; i < xie; i++) cout << s1 << endl; + if (abs(dx) > abs(dy)) { + if (dx > 0) + c = 'R'; + else + c = 'L'; + } else { + if (dy > 0) + c = 'U'; + else + c = 'D'; + } + for (i = 0; i < abs(abs(dx) - abs(dy)); i++) cout << c << endl; + return 0; +} +int min(int a, int b) { + a = abs(a); + b = abs(b); + if (a < b) + return a; + else + return b; +} +int i, j, k, n, l; +string s; +bool b; +int main() { + cin >> s; + n = s.size(); + for (l = n - 1; l > 0; l--) { + for (i = 0; i + l <= n; i++) + for (j = i + 1; j + l <= n; j++) { + b = true; + for (k = 0; k < l; k++) + if (s[i + k] != s[j + k]) { + b = false; + break; + } + if (b) { + cout << k << endl; + return 0; + } + } + } + cout << 0 << endl; + return 0; +} +int a[1001] = {1, 1}; +int p[1001]; +int plen = 0; +int b[2002] = {0}; +int main() { + int i, j, n, k; + for (i = 2; i < 1001; i++) + if (!a[i]) { + p[plen++] = i; + for (j = 2 * i; j < 1001; j += i) a[j] = 1; + } + for (i = 0; i < plen - 1; i++) b[p[i] + p[i + 1] + 1] = 1; + cin >> n >> k; + int num = 0; + for (i = 2; i <= n; i++) + if (b[i] && !a[i]) num++; + puts(num >= k ? "YES" : "NO"); + return 0; +} +int a[1001] = {1, 1}; +int p[1001]; +int plen = 0; +int b[2002] = {0}; +int main() { + int i, j, n, k; + for (i = 2; i < 1001; i++) + if (!a[i]) { + p[plen++] = i; + for (j = 2 * i; j < 1001; j += i) a[j] = 1; + } + for (i = 0; i < plen - 1; i++) b[p[i] + p[i + 1] + 1] = 1; + cin >> n >> k; + int num = 0; + for (i = 2; i <= n; i++) + if (b[i] && !a[i]) num++; + puts(num >= k ? "YES" : "NO"); + return 0; +} +int main() { + char a[100][100]; + int n, m, b, c, d, e; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + if (a[i][j] == '*') { + b = i; + break; + } + for (int i = n; i >= 1; i--) + for (int j = 1; j <= m; j++) + if (a[i][j] == '*') { + c = i; + break; + } + for (int j = m; j >= 1; j--) + for (int i = n; i >= 1; i--) + if (a[i][j] == '*') { + d = j; + break; + } + for (int j = 1; j <= m; j++) + for (int i = n; i >= 1; i--) + if (a[i][j] == '*') { + e = j; + break; + } + for (int i = c; i <= b; i++) { + for (int j = d; j <= e; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + string s; + int maxx = 0; + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + maxx = max(m, maxx); + } + } + cout << maxx << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int a, b; + a = s1[0] - s2[0]; + b = s1[1] - s2[1]; + a = abs(a); + b = abs(b); + int l = (a > b) ? a : b; + cout << l << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int ans, prime[1111], pp[2222], cnt[2222], n, k; +bool pm(int x) { + int cnt = 0; + for (int i = 1; i <= x; i++) { + if (x % i == 0) { cnt++; } + } + return cnt == 2; +} +void pm2() { + for (int i = 1; i <= n; i++) { + if (pm(i)) { prime[i] = 1; } + } + for (int i = 1; i <= 1000; i++) { + if (!prime[i]) { continue; } + for (int j = i + 1; j <= 1000; j++) { + if (!prime[j]) { continue; } + if (!prime[i + j + 1]) { break; } + pp[i + j + 1] = 1; + break; + } + } +} +int main() { + cin >> n >> k; + pm2(); + for (int i = 1; i < 2222; i++) { cnt[i] = cnt[i - 1] + pp[i]; } + ans = cnt[n]; + if (ans >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + string s[a]; + int u = 50, d = -1, l = 50, r = -1; + for (int i = 0; i < a; i++) { + cin >> s[i]; + for (int j = 0; j < b; j++) { + if (s[i][j] == '*') { + if (i < u) { u = i; } + if (i > d) { d = i; } + if (j < l) { l = j; } + if (j > r) { r = j; } + } + } + } + for (int i = u; i <= d; i++) { cout << s[i].substr(l, r - l + 1) << endl; } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + string s[a]; + int u = 50, d = -1, l = 50, r = -1; + for (int i = 0; i < a; i++) { + cin >> s[i]; + for (int j = 0; j < b; j++) { + if (s[i][j] == '*') { + if (i < u) { u = i; } + if (i > d) { d = i; } + if (j < l) { l = j; } + if (j > r) { r = j; } + } + } + } + for (int i = u; i <= d; i++) { cout << s[i].substr(l, r - l + 1) << endl; } + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 2; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 2) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int mx = max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])); + cout << mx << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int mx = max(abs(s1[0] - s2[0]), abs(s1[1] - s2[1])); + cout << mx << endl; + while (s1 != s2) { + if (s1[0] > s2[0]) { + cout << "L"; + s1[0] = s1[0] - 1; + } else if (s1[0] < s2[0]) { + cout << "R"; + s1[0] = s1[0] + 1; + } + if (s1[1] > s2[1]) { + cout << "D"; + s1[1] = s1[1] - 1; + } else if (s1[1] < s2[1]) { + cout << "U"; + s1[1] = s1[1] + 1; + } + cout << endl; + } +} +const long long maxn = 1e5 + 5; +long long n, k; +vector pv; +bool isprime(long long x) { + if (x == 2 || x == 3) return true; + for (long long i = 2; i * i <= x; i++) { + if (x % i == 0) return false; + } + return true; +} +bool ok(long long x) { + for (int i = 0; i < pv.size() - 1; i++) { + if (x == pv[i] + pv[i + 1]) + return true; + else if (x < pv[i] + pv[i + 1]) + return false; + } + return false; +} +int main() { + for (int i = 2; i <= 500; i++) { + if (isprime(i)) { pv.push_back(i); } + } + cin >> n >> k; + for (int i = 5; i <= n; i += 2) { + if (isprime(i) && ok(i - 1)) { k--; } + } + if (k <= 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const long long maxn = 1e5 + 5; +long long n, k; +vector pv; +bool isprime(long long x) { + if (x == 2 || x == 3) return true; + for (long long i = 2; i * i <= x; i++) { + if (x % i == 0) return false; + } + return true; +} +bool ok(long long x) { + for (int i = 0; i < pv.size() - 1; i++) { + if (x == pv[i] + pv[i + 1]) + return true; + else if (x < pv[i] + pv[i + 1]) + return false; + } + return false; +} +int main() { + for (int i = 2; i <= 500; i++) { + if (isprime(i)) { pv.push_back(i); } + } + cin >> n >> k; + for (int i = 5; i <= n; i += 2) { + if (isprime(i) && ok(i - 1)) { k--; } + } + if (k <= 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +void solve() { + string s; + cin >> s; + size_t n = s.size(); + for (size_t len = n - 1; len > 0; --len) { + for (size_t i = 0; i < n - len + 1; ++i) { + string s1 = s.substr(i, len); + if (s.find(s1, i + 1) != string::npos) { + cout << len << endl; + return; + } + } + } + cout << "0" << endl; +} +int main() { + solve(); + return 0; +} +int n, k, p[1111], ok[1111], lt; +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (!p[i]) { + k -= ok[i]; + if (lt != 0 && lt + i + 1 <= n) { ok[lt + i + 1] = 1; } + lt = i; + for (int j = i * i; j <= n; j += i) { p[j] = 1; } + } + } + if (k > 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int n, k, p[1111], ok[1111], lt; +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) { + if (!p[i]) { + k -= ok[i]; + if (lt != 0 && lt + i + 1 <= n) { ok[lt + i + 1] = 1; } + lt = i; + for (int j = i * i; j <= n; j += i) { p[j] = 1; } + } + } + if (k > 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +const int SIZE = 2000 + 1; +int main() { + string main_str; + cin >> main_str; + int n = main_str.length(); + for (int len = n - 1; len > 0; len--) { + for (int start_index = 0; start_index + len < n + 1; start_index++) { + string str_for_compare = main_str.substr(start_index, len); + for (int i = start_index + 1; i + len < n + 1; i++) { + string reg = main_str.substr(i, len); + if (reg == str_for_compare) { + cout << len << endl; + return 0; + } + } + } + } + cout << 0 << endl; + return 0; +} +const int MAXN = 1000005; +int prime[MAXN], num = 0; +bool pd[MAXN]; +void find_prime() { + int i, j; + pd[0] = pd[1] = true; + for (i = 2; i <= MAXN; i++) { + if (!pd[i]) prime[num++] = i; + for (j = 0; j < num; j++) { + if (i * prime[j] > MAXN) break; + pd[i * prime[j]] = true; + if (i % prime[j] == 0) break; + } + } +} +int find(int n) { + int l, r, mid; + l = 0; + r = num - 1; + while (l <= r) { + mid = (l + r) / 2; + if (n > prime[mid]) + l = mid + 1; + else if (n < prime[mid]) + r = mid - 1; + else + return mid; + } + return -1; +} +int mz(int n) { + int pos, t = n; + t = (t - 1) / 2; + while (pd[t]) t++; + pos = find(t); + if (prime[pos - 1] + prime[pos] + 1 == n) return 1; + return 0; +} +int main() { + int n, k, num = 0, i, flag = 0; + cin >> n >> k; + find_prime(); + for (i = 0; prime[i] <= n; i++) { + if (mz(prime[i])) num++; + if (num >= k) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + string s; + cin >> s; + for (int l = s.size(); l; l--) { + for (int i = 0; i + l <= s.size(); i++) { + string p = s.substr(i, l); + int occ = 0; + for (int k = 0; k + l <= s.size(); k++) + if (s.substr(k, l) == p) occ++; + if (occ >= 2) { + cout << l << endl; + return 0; + } + } + } + cout << 0 << endl; +} +int main() { + int n, m, i, j, count = 0; + cin >> n >> m; + char arr[n][m]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) cin >> arr[i][j]; + int up, down, left, right; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (arr[i][j] == '*') { count++; } + } + if (count > 0) { + up = i; + count = 0; + break; + } + } + for (i = n - 1; i >= 0; i--) { + for (j = 0; j < m; j++) { + if (arr[i][j] == '*') { count++; } + } + if (count > 0) { + down = i; + count = 0; + break; + } + } + for (j = 0; j < m; j++) { + for (i = 0; i < n; i++) { + if (arr[i][j] == '*') { count++; } + } + if (count > 0) { + left = j; + count = 0; + break; + } + } + for (j = m - 1; j >= 0; j--) { + for (i = 0; i < n; i++) { + if (arr[i][j] == '*') { count++; } + } + if (count > 0) { + right = j; + count = 0; + break; + } + } + for (i = up; i <= down; i++) { + for (j = left; j <= right; j++) cout << arr[i][j]; + cout << endl; + } + return 0; +} +int m[100001]; +bool check(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +bool good[100001]; +int main() { + int k, n, s, ans, x = -1; + for (int i = 0; i <= 1000; ++i) + if (check(i)) { + if (x != -1) good[i + x + 1] = true; + x = i; + } + for (int i = 0; i <= 1000; ++i) + if (!check(i)) good[i] = false; + cin >> n >> k; + int m = 0; + for (int i = 2; i <= n; ++i) + if (good[i]) m++; + if (m >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool isprime[1000010]; +long long prime[1000010]; +long long phi[1000010]; +long long primesize; +inline long long read() { + register long long x = 0, f = 1; + register char ch = getchar(); + for (; !isdigit(ch); ch = getchar()) + if (ch == '-') f = -1; + for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; + return x * f; +} +bool judge(long long x) { + x -= 1; + long long r = x / 2; + long long i, j; + if (isprime[r] == 1) + i = r; + else + i = r - 1; + j = r + 1; + while (isprime[i] == 0) i--; + while (isprime[j] == 0) j++; + if (i + j == x) + return 1; + else + return 0; +} +void getlist(long long listsize) { + memset(isprime, 1, sizeof(isprime)); + isprime[1] = 0; + for (long long i = 2; i <= listsize; i++) { + if (isprime[i]) prime[++primesize] = i; + for (long long j = 1; j <= primesize && i * prime[j] <= listsize; j++) { + isprime[i * prime[j]] = 0; + if (i % prime[j] == 0) break; + } + } +} +int main() { + getlist(10000); + long long n = read(), k = read(), sum = 0; + for (long long i = 10; i <= n; i++) { + if (judge(i) == 1 && isprime[i] == 1) sum++; + } + if (sum >= k) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + int r, c; + char arr[50][50]; + int mni = INT_MAX, mnj = INT_MAX, mxi = 0, mxj = 0; + char s; + cin >> r >> c; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> s; + arr[i][j] = s; + if (s == '*') { + mxi = max(i, mxi); + mxj = max(j, mxj); + mni = min(i, mni); + mnj = min(j, mnj); + } + } + } + for (int i = mni; i <= mxi; i++) { + for (int j = mnj; j <= mxj; j++) { cout << arr[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int r1, c1, r2, c2; + string s, t; + cin >> s >> t; + c1 = s[0] - 'a'; + r1 = s[1] - '1'; + c2 = t[0] - 'a'; + r2 = t[1] - '1'; + r1 = 7 - r1; + r2 = 7 - r2; + cout << max(abs(r1 - r2), abs(c1 - c2)) << endl; + while (r1 != r2 || c1 != c2) { + if (c1 < c2) { + cout << 'R'; + c1++; + } + if (c1 > c2) { + cout << 'L'; + c1--; + } + if (r1 < r2) { + cout << 'D'; + r1++; + } + if (r1 > r2) { + cout << 'U'; + r1--; + } + cout << endl; + } + return 0; +} +int main() { + int r1, c1, r2, c2; + string s, t; + cin >> s >> t; + c1 = s[0] - 'a'; + r1 = s[1] - '1'; + c2 = t[0] - 'a'; + r2 = t[1] - '1'; + r1 = 7 - r1; + r2 = 7 - r2; + cout << max(abs(r1 - r2), abs(c1 - c2)) << endl; + while (r1 != r2 || c1 != c2) { + if (c1 < c2) { + cout << 'R'; + c1++; + } + if (c1 > c2) { + cout << 'L'; + c1--; + } + if (r1 < r2) { + cout << 'D'; + r1++; + } + if (r1 > r2) { + cout << 'U'; + r1--; + } + cout << endl; + } + return 0; +} +int main() { + string s, str, tmp; + int i, j, flag = 0, ans = 0; + cin >> s; + for (i = s.length() - 1; i >= 1; i--) { + for (j = 0; j + i < s.length(); j++) { + str = s.substr(j + 1); + tmp = s.substr(j, i); + if (str.find(tmp) != string::npos) { + ans = i; + flag = 1; + break; + } + } + if (flag) break; + } + cout << ans << endl; + return 0; +} +const int N = 2222; +int prime[N], pre[N]; +bool check(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +void init() { + int i, j, cnt; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) + for (j = i + i; j <= 1000; j += i) prime[j] = 1; + } + cnt = 0; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) prime[++cnt] = i; + } + for (i = 2; i <= cnt; i++) { + int t = prime[i] + prime[i - 1] + 1; + if (check(t)) pre[t] = 1; + } + for (i = 1; i <= 1000; i++) { pre[i] += pre[i - 1]; } +} +int main() { + init(); + int n, k; + while (cin >> n >> k) { + if (pre[n] >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, i, j, k; + string s; + cin >> s; + n = s.size(); + int a; + a = 0; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (i < j) { + for (k = 0;; k++) + if (i + k >= n || j + k >= n || s[i + k] != s[j + k]) break; + a = max(a, k); + } + cout << a << endl; + return 0; +} +const int N = 2222; +int prime[N], pre[N]; +bool check(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +void init() { + int i, j, cnt; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) + for (j = i + i; j <= 1000; j += i) prime[j] = 1; + } + cnt = 0; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) prime[++cnt] = i; + } + for (i = 2; i <= cnt; i++) { + int t = prime[i] + prime[i - 1] + 1; + if (check(t)) pre[t] = 1; + } + for (i = 1; i <= 1000; i++) { pre[i] += pre[i - 1]; } +} +int main() { + init(); + int n, k; + while (cin >> n >> k) { + if (pre[n] >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int x, y, n, m; +int main() { + string c, d, s[1001]; + cin >> c >> d; + x = c[0] - 96; + y = c[1] - 48; + n = d[0] - 96; + m = d[1] - 48; + int cnt = 0; + while (x != n || y != m) { + cnt++; + if (x < n && y < m) { + x++; + y++; + s[cnt] = "RU"; + } else if (x > n && y > m) { + x--; + y--; + s[cnt] = "LD"; + } else if (x > n && y < m) { + x--; + y++; + s[cnt] = "LU"; + } else if (x < n && y > m) { + x++; + y--; + s[cnt] = "RD"; + } else if (x < n) { + x++; + s[cnt] = "R"; + } else if (x > n) { + x--; + s[cnt] = "L"; + } else if (y > m) { + y--; + s[cnt] = "D"; + } else if (y < m) { + y++; + s[cnt] = "U"; + } + } + cout << cnt << '\n'; + for (int i = 1; i <= cnt; i++) cout << s[i] << '\n'; + return 0; +} +const int N = 1005; +bool a[N + 1]; +set s; +bool x[N + 1]; +void get_prime() { + memset(a, true, sizeof(a)); + memset(x, false, sizeof(x)); + for (int i = 2; i <= N; i++) { + if (a[i]) { + s.insert(i); + for (int j = 2 * i; j <= N; j += i) a[j] = false; + } + } + set::iterator it; + it = s.begin(); + for (; it != s.end();) { + int q = *it; + it++; + q += *it; + q += 1; + if (s.find(q) != s.end()) { x[q] = 1; } + } +} +int main() { + get_prime(); + int n, k; + cin >> n >> k; + int w = 0; + for (int i = 2; i <= n; i++) { + if (x[i]) { w += 1; } + } + if (w >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int N = 1005; +bool a[N + 1]; +set s; +bool x[N + 1]; +void get_prime() { + memset(a, true, sizeof(a)); + memset(x, false, sizeof(x)); + for (int i = 2; i <= N; i++) { + if (a[i]) { + s.insert(i); + for (int j = 2 * i; j <= N; j += i) a[j] = false; + } + } + set::iterator it; + it = s.begin(); + for (; it != s.end();) { + int q = *it; + it++; + q += *it; + q += 1; + if (s.find(q) != s.end()) { x[q] = 1; } + } +} +int main() { + get_prime(); + int n, k; + cin >> n >> k; + int w = 0; + for (int i = 2; i <= n; i++) { + if (x[i]) { w += 1; } + } + if (w >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int miny = n, maxy = 0, minx = m, maxx = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + if (j < minx) minx = j; + if (j > maxx) maxx = j; + if (i < miny) miny = i; + if (i > maxy) maxy = i; + } + } + } + for (int i = miny; i <= maxy; i++) { + for (int j = minx; j <= maxx; j++) { cout << a[i][j]; } + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int miny = n, maxy = 0, minx = m, maxx = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + if (j < minx) minx = j; + if (j > maxx) maxx = j; + if (i < miny) miny = i; + if (i > maxy) maxy = i; + } + } + } + for (int i = miny; i <= maxy; i++) { + for (int j = minx; j <= maxx; j++) { cout << a[i][j]; } + cout << endl; + } +} +int main() { + int n, *a, i, j, k, count = 0, c, sum, *prime; + cin >> n >> c; + a = new int[n + 1]; + prime = new int[n + 1]; + for (i = 0; i <= n; i++) a[i] = 1; + for (i = 2; i * i <= n; i++) { + if (a[i]) { + for (j = i * i; j <= n; j += i) { a[j] = 0; } + } + } + k = 0; + for (i = 2; i <= n; i++) { + if (a[i]) { prime[k++] = i; } + } + for (i = 0; i < k - 1; i++) { + sum = prime[i] + prime[i + 1] + 1; + if (sum <= n && a[sum] == 1) { count++; } + } + if (c == count || c == 0) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int n, *a, i, j, k, count = 0, c, sum, *prime; + cin >> n >> c; + a = new int[n + 1]; + prime = new int[n + 1]; + for (i = 0; i <= n; i++) a[i] = 1; + for (i = 2; i * i <= n; i++) { + if (a[i]) { + for (j = i * i; j <= n; j += i) { a[j] = 0; } + } + } + k = 0; + for (i = 2; i <= n; i++) { + if (a[i]) { prime[k++] = i; } + } + for (i = 0; i < k - 1; i++) { + sum = prime[i] + prime[i + 1] + 1; + if (sum <= n && a[sum] == 1) { count++; } + } + if (c == count || c == 0) + cout << "YES\n"; + else + cout << "NO\n"; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i <= sqrt(a); ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 86; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 86) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char f[n][m]; + for (int i = 0; i < n; i++) { + for (int r = 0; r < m; r++) { cin >> f[i][r]; } + } + int a = 0; + int ch = 0, ch1 = 1001, ch2 = 0, ch3 = 1001, ch4 = 0; + for (int i = 0; i < n; i++) { + for (int r = 0; r < m; r++) { + if (f[i][r] == '*') { + ch1 = min(ch1, r); + ch2 = max(ch2, r); + ch3 = min(ch3, i); + ch4 = max(ch4, i); + } + } + } + for (int i = ch3; i < ch4 + 1; i++) { + for (int r = ch1; r < ch2 + 1; r++) { cout << f[i][r]; } + cout << "\n"; + } + return 0; +} +string s, t; +int xs, ys, xt, yt, n; +string l[200]; +int main() { + cin >> s >> t; + xs = s[0] - 'a' + 1; + ys = s[1] - '1' + 1; + xt = t[0] - 'a' + 1; + yt = t[1] - '1' + 1; + while (xs != xt or ys != yt) { + if (xt > xs and yt > ys) { + l[n] = "RU"; + n++; + xs++; + ys++; + } else if (xt > xs and yt < ys) { + l[n] = "RD"; + n++; + xs++; + ys--; + } else if (xt < xs and yt > ys) { + l[n] = "LU"; + n++; + xs--; + ys++; + } else if (xt < xs and yt < ys) { + l[n] = "LD"; + n++; + xs--; + ys--; + } else if (xt > xs and yt == ys) { + l[n] = "R"; + n++; + xs++; + } else if (xt < xs and yt == ys) { + l[n] = "L"; + n++; + xs--; + } else if (xt == xs and yt > ys) { + l[n] = "U"; + n++; + ys++; + } else if (xt == xs and yt < ys) { + l[n] = "D"; + n++; + ys--; + } + } + cout << n << endl; + for (int i = 0; i < n; i++) { cout << l[i] << endl; } + return 0; +} +string s, t; +int xs, ys, xt, yt, n; +string l[200]; +int main() { + cin >> s >> t; + xs = s[0] - 'a' + 1; + ys = s[1] - '1' + 1; + xt = t[0] - 'a' + 1; + yt = t[1] - '1' + 1; + while (xs != xt or ys != yt) { + if (xt > xs and yt > ys) { + l[n] = "RU"; + n++; + xs++; + ys++; + } else if (xt > xs and yt < ys) { + l[n] = "RD"; + n++; + xs++; + ys--; + } else if (xt < xs and yt > ys) { + l[n] = "LU"; + n++; + xs--; + ys++; + } else if (xt < xs and yt < ys) { + l[n] = "LD"; + n++; + xs--; + ys--; + } else if (xt > xs and yt == ys) { + l[n] = "R"; + n++; + xs++; + } else if (xt < xs and yt == ys) { + l[n] = "L"; + n++; + xs--; + } else if (xt == xs and yt > ys) { + l[n] = "U"; + n++; + ys++; + } else if (xt == xs and yt < ys) { + l[n] = "D"; + n++; + ys--; + } + } + cout << n << endl; + for (int i = 0; i < n; i++) { cout << l[i] << endl; } + return 0; +} +const int N = 2222; +int prime[N], pre[N]; +bool check(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +void init() { + int i, j, cnt; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) + for (j = i + i; j <= 1000; j += i) prime[j] = 1; + } + cnt = 0; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) prime[++cnt] = i; + } + for (i = 2; i <= cnt; i++) { + int t = prime[i] + prime[i - 1] + 1; + if (check(t)) pre[t] = 1; + } + for (i = 1; i <= 1000; i++) { pre[i] += pre[i - 1]; } +} +int main() { + init(); + int n, k; + while (cin >> n >> k) { + if (pre[n] >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const int N = 2222; +int prime[N], pre[N]; +bool check(int num) { + for (int i = 2; i * i <= num; i++) + if (num % i == 0) return false; + return true; +} +void init() { + int i, j, cnt; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) + for (j = i + i; j <= 1000; j += i) prime[j] = 1; + } + cnt = 0; + for (i = 2; i <= 1000; i++) { + if (!prime[i]) prime[++cnt] = i; + } + for (i = 2; i <= cnt; i++) { + int t = prime[i] + prime[i - 1] + 1; + if (check(t)) pre[t] = 1; + } + for (i = 1; i <= 1000; i++) { pre[i] += pre[i - 1]; } +} +int main() { + init(); + int n, k; + while (cin >> n >> k) { + if (pre[n] >= k) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, i, j, x1 = 0, y1 = 0; + cin >> n >> m; + int x0 = n, y0 = m; + string s[n]; + for (i = 0; i < n; i++) { + cin >> s[i]; + for (j = 0; j < m; j++) + if (s[i][j] == '*') { + x0 = min(i, x0); + y0 = min(j, y0); + x1 = max(i, x1); + y1 = max(j, y1); + } + } + for (i = x0; i <= x1; i++) cout << s[i].substr(y0, y1 - y0 + 1) << endl; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 87; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 87) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool c(int a) { + if (a < 2) return false; + for (int i = 2; i * i <= a; ++i) + if (a % i == 0) return false; + return true; +} +int g[1000005]; +int main() { + int l = 87; + for (int i = 0; i <= 1000; ++i) + if (c(i)) { + if (l != 87) g[l + 1 + i] = true; + l = i; + } + for (int i = 0; i <= 1000; ++i) + if (!c(i)) g[i] = false; + int n, k; + cin >> n >> k; + int kol = 0; + for (int i = 2; i <= n; ++i) + if (g[i]) kol++; + if (kol >= k) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + char p1[3], p2[3]; + cin >> p1 >> p2; + int x = p2[0] - p1[0], y = p2[1] - p1[1]; + const char *dx = "", *dy = ""; + if (x > 0) + dx = "R"; + else if (x < 0) + dx = "L"; + if (y > 0) + dy = "U"; + else if (y < 0) + dy = "D"; + x = abs(x); + y = abs(y); + cout << (x < y ? x : y) + abs(y - x) << endl; + if (x < y) { + while (x--) { + cout << dx << dy << endl; + y--; + } + while (y--) cout << dy << endl; + } else { + while (y--) { + cout << dx << dy << endl; + x--; + } + while (x--) cout << dx << endl; + } + return 0; +} +int main() { + int n, m, a[100][100], d[100], b = 0, r = 0; + cin >> m >> n; + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { a[i][j] = 2; } + } + for (int i = 0; i < m; i++) { + string s; + cin >> s; + for (int j = 0; j < n; j++) { + if (s[j] == '.') { + a[i][j] = 1; + } else if (s[j] == '*') { + a[i][j] = 0; + } + } + } + d[0] = 100; + d[1] = -1; + d[2] = 100; + d[3] = -1; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (j < d[0]) { d[0] = j; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (j > d[1]) { d[1] = j; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (i < d[2]) { d[2] = i; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (i > d[3]) { d[3] = i; } + } + } + } + for (int i = d[2]; i <= d[3]; i++) { + for (int j = d[0]; j <= d[1]; j++) { + if (a[i][j] == 0) { + cout << "*"; + } else { + cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + int n, m, a[100][100], d[100], b = 0, r = 0; + cin >> m >> n; + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { a[i][j] = 2; } + } + for (int i = 0; i < m; i++) { + string s; + cin >> s; + for (int j = 0; j < n; j++) { + if (s[j] == '.') { + a[i][j] = 1; + } else if (s[j] == '*') { + a[i][j] = 0; + } + } + } + d[0] = 100; + d[1] = -1; + d[2] = 100; + d[3] = -1; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (j < d[0]) { d[0] = j; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (j > d[1]) { d[1] = j; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (i < d[2]) { d[2] = i; } + } + } + for (int j = 0; j < n; j++) { + if (a[i][j] == 0) { + if (i > d[3]) { d[3] = i; } + } + } + } + for (int i = d[2]; i <= d[3]; i++) { + for (int j = d[0]; j <= d[1]; j++) { + if (a[i][j] == 0) { + cout << "*"; + } else { + cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + string s, k; + cin >> s >> k; + int l = s.size(), p = k.size(); + if (l != p) { + cout << "NO" << endl; + return 0; + } + int j = l - 1, cnt = 0; + for (int i = 0; i < l; i++) { + if (s[i] == k[j]) { + cnt++; + j--; + } + } + if (cnt == l) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + return 0; +} +vector v; +bool check(int n) { + for (int j = 2; j <= int(sqrt(n)); j++) + if (n % j == 0) return false; + return true; +} +int n, k, sum; +int main() { + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (check(i)) v.push_back(i); + for (int i = 0; i < v.size(); i++) { + if (v[i] + v[i + 1] + 1 > n) break; + if (check(v[i] + v[i + 1] + 1)) sum++; + } + if (sum >= k) + puts("YES"); + else + puts("NO"); + return 0; +} +inline int read() { + char ch = ' '; + int f = 1, x = 0; + while (!isdigit(ch)) { + ch = getchar(); + if (ch == '-') f *= -1; + } + while (isdigit(ch)) { + x = (x << 3) + (x << 1) + ch - '0'; + ch = getchar(); + } + return f * x; +} +char c[2]; +int x, y, fx, fy, ans; +string an[1000]; +int main() { + cin >> c; + x = c[0] - 'a'; + y = c[1] - '0'; + cin >> c; + fx = c[0] - 'a'; + fy = c[1] - '0'; + while (x < fx && y < fy) x++, y++, an[++ans] = "RU"; + while (x < fx && y > fy) x++, y--, an[++ans] = "RD"; + while (x > fx && y > fy) x--, y--, an[++ans] = "LD"; + while (x > fx && y < fy) x--, y++, an[++ans] = "LU"; + while (x > fx && y == fy) x--, an[++ans] = "L"; + while (x < fx && y == fy) x++, an[++ans] = "R"; + while (x == fx && y < fy) y++, an[++ans] = "U"; + while (x == fx && y > fy) y--, an[++ans] = "D"; + cout << ans << endl; + for (int i = 1; i <= ans; i++) cout << an[i] << endl; + return 0; +} +inline int read() { + char ch = ' '; + int f = 1, x = 0; + while (!isdigit(ch)) { + ch = getchar(); + if (ch == '-') f *= -1; + } + while (isdigit(ch)) { + x = (x << 3) + (x << 1) + ch - '0'; + ch = getchar(); + } + return f * x; +} +char c[2]; +int x, y, fx, fy, ans; +string an[1000]; +int main() { + cin >> c; + x = c[0] - 'a'; + y = c[1] - '0'; + cin >> c; + fx = c[0] - 'a'; + fy = c[1] - '0'; + while (x < fx && y < fy) x++, y++, an[++ans] = "RU"; + while (x < fx && y > fy) x++, y--, an[++ans] = "RD"; + while (x > fx && y > fy) x--, y--, an[++ans] = "LD"; + while (x > fx && y < fy) x--, y++, an[++ans] = "LU"; + while (x > fx && y == fy) x--, an[++ans] = "L"; + while (x < fx && y == fy) x++, an[++ans] = "R"; + while (x == fx && y < fy) y++, an[++ans] = "U"; + while (x == fx && y > fy) y--, an[++ans] = "D"; + cout << ans << endl; + for (int i = 1; i <= ans; i++) cout << an[i] << endl; + return 0; +} +void reverseStr(string &str) { + int n = str.length(); + for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]); +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + reverseStr(s1); + if (s2 == s1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +void reverseStr(string &str) { + int n = str.length(); + for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]); +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + reverseStr(s1); + if (s2 == s1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + char a[1001][1001]; + int n, m, i, j, min_i, min_j, max_i, max_j; + cin >> n >> m; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) cin >> a[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) + if (a[i][j] == '*') { + min_i = i; + goto x; + } +x: + for (j = 1; j <= m; j++) + for (i = 1; i <= n; i++) + if (a[i][j] == '*') { + min_j = j; + goto y; + } +y: + for (i = n; i >= 0; i--) + for (j = m; j >= 0; j--) + if (a[i][j] == '*') { + max_i = i; + goto z; + } +z: + for (j = m; j >= 0; j--) + for (i = n; i >= 0; i--) + if (a[i][j] == '*') { + max_j = j; + goto t; + } +t: + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + char a[1001][1001]; + int n, m, i, j, min_i, min_j, max_i, max_j; + cin >> n >> m; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) cin >> a[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) + if (a[i][j] == '*') { + min_i = i; + goto x; + } +x: + for (j = 1; j <= m; j++) + for (i = 1; i <= n; i++) + if (a[i][j] == '*') { + min_j = j; + goto y; + } +y: + for (i = n; i >= 0; i--) + for (j = m; j >= 0; j--) + if (a[i][j] == '*') { + max_i = i; + goto z; + } +z: + for (j = m; j >= 0; j--) + for (i = n; i >= 0; i--) + if (a[i][j] == '*') { + max_j = j; + goto t; + } +t: + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int n, k, ans, book[1010]; +int is_p[1010]; +vector p; +inline void prime(int a) { + for (int i = 1; i <= n; ++i) is_p[i] = 1; + is_p[0] = 0; + is_p[1] = 0; + for (int i = 2; i <= n; ++i) { + if (is_p[i]) { + p.push_back(i); + for (int j = i + i; j <= n; j += i) is_p[j] = 0; + } + } +} +int main() { + cin >> n >> k; + prime(n); + for (int i = 0; i < p.size(); ++i) { + if (p[i] + p[i + 1] + 1 <= n) { + if (is_p[p[i] + p[i + 1] + 1]) book[p[i] + p[i + 1] + 1] = 1; + } else + break; + } + for (int i = 2; i <= n; ++i) + if (book[i]) ans++; + if (ans >= k) + puts("YES"); + else + puts("NO"); + return 0; +} +long long int power(long long int x, long long int n, long long int m) { + if (n == 0) return 1; + if (n == 1) return x; + x %= m; + if (n % 2) return (x * (power((x * x) % m, n / 2, m) % m)) % m; + return power((x * x) % m, n / 2, m) % m; +} +vector prime; +void Seive(int n) { + vector is_prime(n + 1, true); + is_prime[0] = is_prime[1] = false; + for (int i = 2; i * i <= n; i++) { + if (is_prime[i]) { + for (int j = i * i; j <= n; j += i) is_prime[j] = false; + } + } + for (int i = 2; i <= n; i++) + if (is_prime[i]) prime.push_back(i); +} +int main() { + int n, k, c = 0; + cin >> n >> k; + Seive(n); + for (long long int i = 0; i < prime.size(); i++) { + for (long long int j = 0; j < i - 1; j++) { + if (prime[j] + prime[j + 1] + 1 == prime[i]) { + c++; + break; + } + } + } + if (c >= k) + cout << "YES\n"; + else + cout << "NO\n"; +} +char s[51][51]; +int main() { + int fx = 100, fy = 100, lx = 0, ly = 0; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + fx = min(fx, i); + fy = min(fy, j); + lx = max(lx, i); + ly = max(ly, j); + } + } + } + for (int i = fx; i <= lx; i++) { + for (int j = fy; j <= ly; j++) { cout << s[i][j]; } + cout << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(t.begin(), t.end()); + if (s == t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +const int MOD = 1000000007; +const long long INF = 1000000007; +const long long INF2 = 1000000007LL * 1000000007LL; +const long double EPS = 1e-9; +char s[100][100]; +int main() { + long long mini = INF, minj = INF, maxi = -INF, maxj = -INF; + int n, m; + char c; + cin >> n >> m; + for (long long i = 0; i < n; ++i) { + for (long long j = 0; j < m; ++j) { + cin >> c; + if (c == '*') { + mini = min(mini, i); + maxi = max(maxi, i); + minj = min(minj, j); + maxj = max(maxj, j); + } + s[i][j] = c; + } + } + for (long long i = mini; i <= maxi; ++i) { + for (long long j = minj; j <= maxj; ++j) { cout << s[i][j]; } + cout << "\n"; + } + return 0; +} +int main() { + string s; + int n; + cin >> n; + cin.ignore(); + map mp; + while (n--) { + getline(cin, s); + mp[s]++; + } + cout << mp.size() << endl; + return 0; +} +int main() { + string s; + int n; + cin >> n; + cin.ignore(); + map mp; + while (n--) { + getline(cin, s); + mp[s]++; + } + cout << mp.size() << endl; + return 0; +} +const double eps(1e-8); +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int main() { + char start[3], end[3]; + int x, y, gap, step; + cin.get(start, 3, '\n'); + cin.ignore(); + cin.get(end, 3, '\n'); + cin.ignore(); + x = start[0] - end[0]; + y = start[1] - end[1]; + if (abs(x) > abs(y)) { + gap = abs(y); + step = abs(x); + } else if (abs(x) < abs(y)) { + gap = abs(x); + step = abs(y); + } else { + gap = 0; + step = abs(x); + } + cout << step << endl; + for (int i = 0; i < step; ++i) { + if (gap == 0) { + if (x > 0) + cout << "L"; + else if (x < 0) + cout << "R"; + if (y > 0) + cout << "D"; + else if (y < 0) + cout << "U"; + cout << endl; + } else if (i < gap) { + if (x > 0) + cout << "L"; + else if (x < 0) + cout << "R"; + if (y > 0) + cout << "D"; + else if (y < 0) + cout << "U"; + cout << endl; + } else { + if (abs(x) > abs(y)) { + if (x > 0) + cout << "L"; + else + cout << "R"; + } else { + if (y > 0) + cout << "D"; + else + cout << "U"; + } + cout << endl; + } + } + return 0; +} +int main() { + string s, s1; + cin >> s >> s1; + for (int i = 0; i < s.length(); i++) { + if (s[i] != s1[s.length() - i - 1]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int m, n; + char a[51][51]; + cin >> m >> n; + int a1 = m, a2 = n, a3 = 1, a4 = 1; + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + if (i <= a1) a1 = i; + if (j <= a2) a2 = j; + if (a3 <= i) a3 = i; + if (a4 <= j) a4 = j; + } + } + } + for (int i = a1; i <= a3; i++) { + for (int j = a2; j <= a4; j++) cout << a[i][j]; + cout << endl; + } +} +int main() { + int m, n; + char a[51][51]; + cin >> m >> n; + int a1 = m, a2 = n, a3 = 1, a4 = 1; + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + if (i <= a1) a1 = i; + if (j <= a2) a2 = j; + if (a3 <= i) a3 = i; + if (a4 <= j) a4 = j; + } + } + } + for (int i = a1; i <= a3; i++) { + for (int j = a2; j <= a4; j++) cout << a[i][j]; + cout << endl; + } +} +int main() { + int n; + cin >> n; + string str; + set s; + getchar(); + for (int i = 1; i <= n; i++) { + getline(cin, str); + s.insert(str); + } + cout << (int)s.size() << endl; + return 0; +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + cout << max(abs(a - c), abs(b - d)) << endl; + while (a != c || b != d) { + if (a < c) cout << 'R', a++; + if (a > c) cout << 'L', a--; + if (b > d) cout << 'D', b--; + if (b < d) cout << 'U', b++; + cout << endl; + } +} +int main() { + char a, b, c, d; + cin >> a >> b >> c >> d; + cout << max(abs(a - c), abs(b - d)) << endl; + while (a != c || b != d) { + if (a < c) cout << 'R', a++; + if (a > c) cout << 'L', a--; + if (b > d) cout << 'D', b--; + if (b < d) cout << 'U', b++; + cout << endl; + } +} +int main() { + set alana; + string inp, a, b; + int n; + cin >> n; + while (n--) { + cin >> a >> b; + inp = a + ' ' + b; + alana.insert(inp); + } + cout << alana.size() << "\n"; + return 0; +} +int main() { + set alana; + string inp, a, b; + int n; + cin >> n; + while (n--) { + cin >> a >> b; + inp = a + ' ' + b; + alana.insert(inp); + } + cout << alana.size() << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector lett(n); + bool errl = 1; + for (int i = 0; i < n; i++) { + cin >> lett[i]; + if (errl) { + bool err = 0; + for (int j = 0; j < m; j++) { + if (lett[i][j] == '*') { + err = 1; + break; + } + } + if (err) { + errl = 0; + } else { + lett[i] = " "; + } + } + } + for (int i = n - 1; i >= 0; i--) { + bool err = 0; + for (int j = 0; j < m; j++) { + if (lett[i][j] == '*') { + err = 1; + break; + } + } + if (err) { + break; + } else { + lett[i] = " "; + } + } + for (int i = 0; i < m; i++) { + bool err = 0; + for (int j = 0; j < n; j++) { + if (lett[j][i] == '*') { + err = 1; + break; + } + } + if (err) { + break; + } else { + for (int j = 0; j < n; j++) { lett[j][i] = ' '; } + } + } + for (int i = m - 1; i >= 0; i--) { + bool err = 0; + for (int j = 0; j < n; j++) { + if (lett[j][i] == '*') { + err = 1; + break; + } + } + if (err) { + break; + } else { + for (int j = 0; j < n; j++) { lett[j][i] = ' '; } + } + } + for (int i = 0; i < n; i++) { + if (lett[i] != " ") { + for (int j = 0; j < m; j++) { + if (lett[i][j] != ' ') { cout << lett[i][j]; } + } + cout << '\n'; + } + } + return 0; +} +int main() { + string s, t; + cin >> s; + cin >> t; + reverse(s.begin(), s.end()); + if (t == s) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char x1, x2; + int hi2, y2; + cin >> x1 >> hi2 >> x2 >> y2; + cout << max(abs(x1 - x2), abs(hi2 - y2)) << '\n'; + while (x1 < x2 && hi2 > y2) { + cout << "RD" << '\n'; + x1++; + hi2--; + } + while (x1 < x2 && hi2 < y2) { + cout << "RU" << '\n'; + x1++; + hi2++; + } + while (x1 > x2 && hi2 < y2) { + cout << "LU" << '\n'; + x1--; + hi2++; + } + while (x1 > x2 && hi2 > y2) { + cout << "LD" << '\n'; + x1--; + hi2--; + } + while (x1 > x2) { + cout << "L" << '\n'; + x1--; + } + while (x1 < x2) { + cout << "R" << '\n'; + x1++; + } + while (hi2 < y2) { + cout << "U" << '\n'; + hi2++; + } + while (hi2 > y2) { + cout << "D" << '\n'; + hi2--; + } +} +int main() { + char x1, x2; + int hi2, y2; + cin >> x1 >> hi2 >> x2 >> y2; + cout << max(abs(x1 - x2), abs(hi2 - y2)) << '\n'; + while (x1 < x2 && hi2 > y2) { + cout << "RD" << '\n'; + x1++; + hi2--; + } + while (x1 < x2 && hi2 < y2) { + cout << "RU" << '\n'; + x1++; + hi2++; + } + while (x1 > x2 && hi2 < y2) { + cout << "LU" << '\n'; + x1--; + hi2++; + } + while (x1 > x2 && hi2 > y2) { + cout << "LD" << '\n'; + x1--; + hi2--; + } + while (x1 > x2) { + cout << "L" << '\n'; + x1--; + } + while (x1 < x2) { + cout << "R" << '\n'; + x1++; + } + while (hi2 < y2) { + cout << "U" << '\n'; + hi2++; + } + while (hi2 > y2) { + cout << "D" << '\n'; + hi2--; + } +} +int main() { + int m, n; + char a[55][55]; + int alt = -1000, ust = 1000, sag = -1000, sol = 1000; + cin >> m >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + alt = max(alt, i); + ust = min(ust, i); + sag = max(sag, j); + sol = min(sol, j); + } + } + for (int i = ust; i <= alt; i++) { + for (int j = sol; j <= sag; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + int m, n; + char a[55][55]; + int alt = -1000, ust = 1000, sag = -1000, sol = 1000; + cin >> m >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + alt = max(alt, i); + ust = min(ust, i); + sag = max(sag, j); + sol = min(sol, j); + } + } + for (int i = ust; i <= alt; i++) { + for (int j = sol; j <= sag; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + char str[100]; + cin >> str; + int ans = -1000000007; + for (int i = 0; str[i] != '\0'; i++) { + for (int j = i + 1; str[j] != '\0'; j++) { + if (str[j] == str[i]) { + int tmp = j; + int len = 0; + int tmp2 = i; + while (str[tmp] == str[tmp2] && str[tmp] != '\0') { + len++; + tmp++; + tmp2++; + } + ans = max(ans, len); + } + } + } + cout << max(ans, 0) << endl; + return 0; +} +set myset; +int main() { + int n; + cin >> n; + cin.ignore(); + myset.clear(); + while (n--) { + string leaf; + getline(cin, leaf); + myset.insert(leaf); + } + cout << myset.size() << endl; +} +set myset; +int main() { + int n; + cin >> n; + cin.ignore(); + myset.clear(); + while (n--) { + string leaf; + getline(cin, leaf); + myset.insert(leaf); + } + cout << myset.size() << endl; +} +int main() { + string a, b; + cin >> a >> b; + int loop = max(abs(a[0] - b[0]), abs(a[1] - b[1])); + cout << loop << endl; + for (int i = 0; i < loop; i++) { + if (a[0] < b[0]) cout << "R", a[0]++; + if (a[0] > b[0]) cout << "L", a[0]--; + if (a[1] < b[1]) cout << "U", a[1]++; + if (a[1] > b[1]) cout << "D", a[1]--; + cout << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int loop = max(abs(a[0] - b[0]), abs(a[1] - b[1])); + cout << loop << endl; + for (int i = 0; i < loop; i++) { + if (a[0] < b[0]) cout << "R", a[0]++; + if (a[0] > b[0]) cout << "L", a[0]--; + if (a[1] < b[1]) cout << "U", a[1]++; + if (a[1] > b[1]) cout << "D", a[1]--; + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector vec(n * m); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> vec[j + i * m]; } + } + int h1 = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (vec[j + i * m] == '*') { + h1 = i; + break; + } + } + if (h1 == i) break; + } + int h2 = -1; + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (vec[j + i * m] == '*') { + h2 = i; + break; + } + } + if (h2 == i) break; + } + int s1 = -1; + for (int j = 0; j < m; j++) { + for (int i = 0; i < n; i++) { + if (vec[j + i * m] == '*') { + s1 = j; + break; + } + } + if (s1 == j) break; + } + int s2 = -1; + for (int j = m - 1; j >= 0; j--) { + for (int i = 0; i < n; i++) { + if (vec[j + i * m] == '*') { + s2 = j; + break; + } + } + if (s2 == j) break; + } + for (h1; h1 <= h2; h1++) { + for (int q = s1; q <= s2; q++) { + if (q == s2) { + cout << vec[q + h1 * m] << endl; + break; + } + cout << vec[q + h1 * m]; + } + } + return 0; +} +int i, j, k, l, ans = 0; +string s; +int main() { + cin >> s; + for (l = 1; l < s.size(); l++) { + vector z; + for (i = 0; i + l - 1 < s.size(); i++) z.push_back(s.substr(i, l)); + sort(z.begin(), z.end()); + for (k = 0; k < z.size() - 1; k++) + if (z[k] == z[k + 1]) { + ans = max(ans, l); + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int sx = a[0] - 'a' + 1; + int sy = a[1] - '0'; + int ex = b[0] - 'a' + 1; + int ey = b[1] - '0'; + char flag1, flag2; + if (ex > sx) + flag1 = 'R'; + else + flag1 = 'L'; + if (ey > sy) + flag2 = 'U'; + else + flag2 = 'D'; + int dx = fabs(ex - sx); + int dy = fabs(ey - sy); + cout << max(dx, dy) << endl; + while (dx > 0 || dy > 0) { + if (dx > 0) { + cout << flag1; + dx--; + } + if (dy > 0) { + cout << flag2; + dy--; + } + cout << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int sx = a[0] - 'a' + 1; + int sy = a[1] - '0'; + int ex = b[0] - 'a' + 1; + int ey = b[1] - '0'; + char flag1, flag2; + if (ex > sx) + flag1 = 'R'; + else + flag1 = 'L'; + if (ey > sy) + flag2 = 'U'; + else + flag2 = 'D'; + int dx = fabs(ex - sx); + int dy = fabs(ey - sy); + cout << max(dx, dy) << endl; + while (dx > 0 || dy > 0) { + if (dx > 0) { + cout << flag1; + dx--; + } + if (dy > 0) { + cout << flag2; + dy--; + } + cout << endl; + } + return 0; +} +int n, m, x = 2e9, y = 2e9, xx, yy, i, j; +char a[60][60]; +int main() { + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + x = min(x, i); + y = min(y, j); + xx = max(xx, i); + yy = max(yy, j); + } + } + } + for (i = x; i <= xx; i++) { + for (j = y; j <= yy; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int n, m, x = 2e9, y = 2e9, xx, yy, i, j; +char a[60][60]; +int main() { + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + x = min(x, i); + y = min(y, j); + xx = max(xx, i); + yy = max(yy, j); + } + } + } + for (i = x; i <= xx; i++) { + for (j = y; j <= yy; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int i = 0; + int j = s1.size() - 1; + int f = 0; + for (i = 0, j = s1.size() - 1; i < s1.size() && j >= 0; i++, j--) { + if (s1[i] == s2[j]) + continue; + else { + f = 1; + break; + } + } + if (f == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + char str[105][25]; + cin >> n; + int k = n; + for (int i = 0; i <= n; i++) { gets(str[i]); } + for (int i = 1; i <= n; i++) { + for (int j = 0; j < i; j++) { + if (strcmp(str[i], str[j]) == 0) { + k--; + break; + } + } + } + cout << k << endl; +} +vector letter[26]; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + char c = s[i]; + int index = c - 'a'; + letter[index].push_back(i); + } + int ans = 0; + for (int i = 0; i < 26; i++) { + if (letter[i].size() >= 2) { + for (int j = 0; j < letter[i].size(); j++) { + for (int k = j + 1; k < letter[i].size(); k++) { + int index1 = letter[i][j]; + int index2 = letter[i][k]; + int tmp_ans = 0; + while (index1 < s.length() && index2 < s.length()) { + if (s[index1] == s[index2]) { + tmp_ans++; + index1++; + index2++; + } else { + break; + } + } + if (tmp_ans > ans) { ans = tmp_ans; } + } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int sx = a[0] - 'a' + 1; + int sy = a[1] - '0'; + int ex = b[0] - 'a' + 1; + int ey = b[1] - '0'; + char flag1, flag2; + if (ex > sx) + flag1 = 'R'; + else + flag1 = 'L'; + if (ey > sy) + flag2 = 'U'; + else + flag2 = 'D'; + int dx = fabs(ex - sx); + int dy = fabs(ey - sy); + cout << max(dx, dy) << endl; + while (dx > 0 || dy > 0) { + if (dx > 0) { + cout << flag1; + dx--; + } + if (dy > 0) { + cout << flag2; + dy--; + } + cout << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int sx = a[0] - 'a' + 1; + int sy = a[1] - '0'; + int ex = b[0] - 'a' + 1; + int ey = b[1] - '0'; + char flag1, flag2; + if (ex > sx) + flag1 = 'R'; + else + flag1 = 'L'; + if (ey > sy) + flag2 = 'U'; + else + flag2 = 'D'; + int dx = fabs(ex - sx); + int dy = fabs(ey - sy); + cout << max(dx, dy) << endl; + while (dx > 0 || dy > 0) { + if (dx > 0) { + cout << flag1; + dx--; + } + if (dy > 0) { + cout << flag2; + dy--; + } + cout << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + reverse(s2.begin(), s2.end()); + if (s1 == s2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, mini = 500, maxi = -1, minj = 500, maxj = -1; + char ch[50][50]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int endj = -1; + for (int j = 0; j < m; j++) { + cin >> ch[i][j]; + if (ch[i][j] == '*') endj = j; + } + int j = 0; + for (; j < m; j++) + if (ch[i][j] == '*') break; + if (endj != -1) { + if (endj > maxj) maxj = endj; + if (j < minj) minj = j; + } + } + for (int j = 0; j < m; j++) { + int endi = -1; + for (int i = 0; i < n; i++) + if (ch[i][j] == '*') endi = i; + int i = 0; + for (; i < n; i++) + if (ch[i][j] == '*') break; + if (endi != -1) { + if (endi > maxi) maxi = endi; + if (i < mini) mini = i; + } + } + for (int i = mini; i <= maxi; i++, cout << endl) + for (int j = minj; j <= maxj; j++) cout << ch[i][j]; + return 0; +} +void solution(vector input, int size) { + vector stack; + for (int i = 0; i < size; i++) { + if (find(stack.begin(), stack.end(), input[i]) == stack.end()) { stack.push_back(input[i]); } + } + cout << stack.size() << endl; +} +int main() { + int total; + cin >> total; + vector input; + string str; + getline(cin, str); + for (int i = 0; i < total; i++) { + getline(cin, str); + input.push_back(str); + } + solution(input, total); + return 0; +} +int main() { + string s; + while (cin >> s) { + int l = s.length(); + int ma = 0; + for (int i = 0; i < l; i++) { + for (int j = i + 1; j < l; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + ma = max(m, ma); + } + } + cout << ma << endl; + } + return 0; +} +int main() { + char s1, s2, t1, t2; + int f, i, m, n; + cin >> s1 >> s2; + cin >> t1 >> t2; + m = t1 - s1; + n = t2 - s2; + if (abs(m) > abs(n)) { + cout << abs(m) << endl; + f = 1; + } else { + cout << abs(n) << endl; + if (abs(m) == abs(n)) { + f = 0; + } else { + f = 2; + } + } + if (m < 0) { + if (n < 0) { + if (m < n) { + for (i = -n; i > 0; i--) { + cout << "LD" << endl; + m++; + } + } else { + for (i = -m; i > 0; i--) { + cout << "LD" << endl; + n++; + } + } + } else { + if (-m < n) { + for (i = -m; i > 0; i--) { + cout << "LU" << endl; + n--; + } + } else { + for (i = n; i > 0; i--) { + cout << "LU" << endl; + m++; + } + } + } + } else { + if (n < 0) { + if (m < -n) { + for (i = m; i > 0; i--) { + cout << "RD" << endl; + n++; + } + } else { + for (i = -n; i > 0; i--) { + cout << "RD" << endl; + m--; + } + } + } else { + if (m < n) { + for (i = m; i > 0; i--) { + cout << "RU" << endl; + n--; + } + } else { + for (i = n; i > 0; i--) { + cout << "RU" << endl; + m--; + } + } + } + } + if (f == 1) { + if (m < 0) { + for (i = -m; i > 0; i--) { cout << "L" << endl; } + } else { + for (i = m; i > 0; i--) { cout << "R" << endl; } + } + } else if (f == 2) { + if (n < 0) { + for (i = -n; i > 0; i--) { cout << "D" << endl; } + } else { + for (i = n; i > 0; i--) { cout << "U" << endl; } + } + } + return 0; +} +int main() { + char s1, s2, t1, t2; + int f, i, m, n; + cin >> s1 >> s2; + cin >> t1 >> t2; + m = t1 - s1; + n = t2 - s2; + if (abs(m) > abs(n)) { + cout << abs(m) << endl; + f = 1; + } else { + cout << abs(n) << endl; + if (abs(m) == abs(n)) { + f = 0; + } else { + f = 2; + } + } + if (m < 0) { + if (n < 0) { + if (m < n) { + for (i = -n; i > 0; i--) { + cout << "LD" << endl; + m++; + } + } else { + for (i = -m; i > 0; i--) { + cout << "LD" << endl; + n++; + } + } + } else { + if (-m < n) { + for (i = -m; i > 0; i--) { + cout << "LU" << endl; + n--; + } + } else { + for (i = n; i > 0; i--) { + cout << "LU" << endl; + m++; + } + } + } + } else { + if (n < 0) { + if (m < -n) { + for (i = m; i > 0; i--) { + cout << "RD" << endl; + n++; + } + } else { + for (i = -n; i > 0; i--) { + cout << "RD" << endl; + m--; + } + } + } else { + if (m < n) { + for (i = m; i > 0; i--) { + cout << "RU" << endl; + n--; + } + } else { + for (i = n; i > 0; i--) { + cout << "RU" << endl; + m--; + } + } + } + } + if (f == 1) { + if (m < 0) { + for (i = -m; i > 0; i--) { cout << "L" << endl; } + } else { + for (i = m; i > 0; i--) { cout << "R" << endl; } + } + } else if (f == 2) { + if (n < 0) { + for (i = -n; i > 0; i--) { cout << "D" << endl; } + } else { + for (i = n; i > 0; i--) { cout << "U" << endl; } + } + } + return 0; +} +string s, x; +int i, j, t; +int main() { + cin >> s >> x; + reverse(s.begin(), s.end()); + if (s == x) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +string s, x; +int i, j, t; +int main() { + cin >> s >> x; + reverse(s.begin(), s.end()); + if (s == x) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long n, z; +string st[102]; +int main() { + cin >> n; + for (int i = 0; i <= n; i++) getline(cin, st[i]); + sort(st + 1, st + n + 1); + for (int i = 1; i <= n; i++) + if (st[i] == st[i + 1] && st[i].size() == st[i + 1].size()) + ; + else + z++; + cout << z << endl; + return 0; +} +long long n, z; +string st[102]; +int main() { + cin >> n; + for (int i = 0; i <= n; i++) getline(cin, st[i]); + sort(st + 1, st + n + 1); + for (int i = 1; i <= n; i++) + if (st[i] == st[i + 1] && st[i].size() == st[i + 1].size()) + ; + else + z++; + cout << z << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int diag = s2[0] - s1[0], diag2 = s2[1] - s1[1]; + vector ans; + while (diag > 0 && diag2 < 0) { + diag--; + diag2++; + ans.push_back("RD\n"); + } + while (diag > 0 && diag2 > 0) { + diag--; + diag2--; + ans.push_back("RU\n"); + } + while (diag2 < 0 && diag < 0) { + diag++; + diag2++; + ans.push_back("LD\n"); + } + while (diag < 0 && diag2 > 0) { + diag++; + diag2--; + ans.push_back("LU\n"); + } + while (diag2 < 0) { + diag2++; + ans.push_back("D\n"); + } + while (diag2 > 0) { + diag2--; + ans.push_back("U\n"); + } + while (diag > 0) { + diag--; + ans.push_back("R\n"); + } + while (diag < 0) { + diag++; + ans.push_back("L\n"); + } + cout << ans.size() << "\n"; + for (int i = 0; i < ans.size(); i++) cout << ans[i]; + return 0; +} +int n, m, q, y; +int p = 99999999, x = 99999999; +char k; +char a[101][101]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> k; + a[i][j] = k; + if (k == '*') { + if (i <= p) p = i; + if (j <= x) x = j; + if (i >= q) q = i; + if (j >= y) y = j; + } + } + } + for (int i = p; i <= q; i++) { + for (int j = x; j <= y; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int mx = 0; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + int c = 0; + while (s[i + c] == s[j + c]) c++; + mx = max(mx, c); + } + } + cout << mx << endl; + return 0; +} +int main() { + char i1, i2, l1, l2; + cin >> i1 >> i2 >> l1 >> l2; + cout << max(abs(i1 - l1), abs(i2 - l2)) << endl; + while (i1 != l1 || i2 != l2) { + if (i1 < l1) { + cout << 'R'; + i1++; + } + if (i1 > l1) { + cout << 'L'; + i1--; + } + if (i2 > l2) { + cout << 'D'; + i2--; + } + if (i2 < l2) { + cout << 'U'; + i2++; + } + cout << endl; + } + return 0; +} +int main() { + char i1, i2, l1, l2; + cin >> i1 >> i2 >> l1 >> l2; + cout << max(abs(i1 - l1), abs(i2 - l2)) << endl; + while (i1 != l1 || i2 != l2) { + if (i1 < l1) { + cout << 'R'; + i1++; + } + if (i1 > l1) { + cout << 'L'; + i1--; + } + if (i2 > l2) { + cout << 'D'; + i2--; + } + if (i2 < l2) { + cout << 'U'; + i2++; + } + cout << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(t.begin(), t.end()); + if (s == t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cin.clear(); + map str; + string strr; + for (int i = 0; i < n; i++) { + getline(cin, strr); + while (strr.length() == 0) getline(cin, strr); + if (str[strr] == 0) str[strr]++; + } + map::iterator itr; + int ans = 0; + for (itr = str.begin(); itr != str.end(); itr++) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + cin.clear(); + map str; + string strr; + for (int i = 0; i < n; i++) { + getline(cin, strr); + while (strr.length() == 0) getline(cin, strr); + if (str[strr] == 0) str[strr]++; + } + map::iterator itr; + int ans = 0; + for (itr = str.begin(); itr != str.end(); itr++) ans++; + cout << ans << endl; + return 0; +} +int lu, ru, ld, rd, n, i, j, m; +char c[60][60]; +int main() { + cin >> n >> m; + lu = 100000; + ld = 100000; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) cin >> c[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) { + if (c[i][j] == '*') { + if (i <= lu) lu = i; + if (i >= ru) ru = i; + if (j <= ld) ld = j; + if (j >= rd) rd = j; + } + } + for (i = lu; i <= ru; i++) { + for (j = ld; j <= rd; j++) cout << c[i][j]; + cout << endl; + } +} +vector p[100]; +int main() { + int i = 0, maxi = 0, ans = 0, cnt = 0, j, k = 0; + string a; + cin >> a; + for (i = 0; i < a.size(); i++) { p[a[i] - 'a' + 1].push_back(i); } + for (i = 1; i <= 26; i++) { + maxi = 0; + int k1, k2, t1, t2; + for (j = 0; j < p[i].size(); j++) { + for (k = j + 1; k < p[i].size(); k++) { + t1 = p[i][j]; + t2 = p[i][k]; + cnt = 0; + while (1) { + if (a[t1] == a[t2]) { + t1++; + t2++; + cnt++; + } else { + if (cnt >= ans) { ans = cnt; } + break; + } + if (t1 >= a.size() || t2 >= a.size()) { + if (cnt >= ans) { ans = cnt; } + break; + } + } + } + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + set pict; + for (int i = 0; i < n; i++) { + string a, b; + cin >> a >> b; + pict.insert(a + ' ' + b); + } + cout << pict.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + set pict; + for (int i = 0; i < n; i++) { + string a, b; + cin >> a >> b; + pict.insert(a + ' ' + b); + } + cout << pict.size() << endl; + return 0; +} +int main() { + int n, m, i, j; + char arr[51][51]; + int hi, hj, li, lj; + hi = hj = li = lj = 0; + int flag = 0; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> arr[i][j]; + if (flag == 0 && arr[i][j] == '*') { + hi = i; + hj = j; + li = i; + lj = j; + flag = 1; + } + if (arr[i][j] == '*' && i < hi) { hi = i; } + if (arr[i][j] == '*' && j < hj) { hj = j; } + if (arr[i][j] == '*' && i > li) { li = i; } + if (arr[i][j] == '*' && j > lj) { lj = j; } + } + } + for (i = hi; i <= li; i++) { + for (j = hj; j <= lj; j++) { cout << arr[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m, i, j; + char arr[51][51]; + int hi, hj, li, lj; + hi = hj = li = lj = 0; + int flag = 0; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> arr[i][j]; + if (flag == 0 && arr[i][j] == '*') { + hi = i; + hj = j; + li = i; + lj = j; + flag = 1; + } + if (arr[i][j] == '*' && i < hi) { hi = i; } + if (arr[i][j] == '*' && j < hj) { hj = j; } + if (arr[i][j] == '*' && i > li) { li = i; } + if (arr[i][j] == '*' && j > lj) { lj = j; } + } + } + for (i = hi; i <= li; i++) { + for (j = hj; j <= lj; j++) { cout << arr[i][j]; } + cout << endl; + } + return 0; +} +map m; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + string x; + getline(cin, x); + m[x] = 1; + } + cout << m.size() << endl; + return 0; +} +int main() { + string s; + string t; + cin >> s >> t; + cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])); + cout << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } else if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } + cout << endl; + } +} +int main() { + int i, len; + char str[105], arr[105]; + gets(str); + gets(arr); + len = strlen(str); + for (i = 0; i < len / 2; i++) { + char t = str[i]; + str[i] = str[len - 1 - i]; + str[len - 1 - i] = t; + } + if (strcmp(str, arr) == 0) + puts("YES"); + else + puts("NO"); + return 0; +} +int getint() { + int ans = 0, f = 1; + char c = getchar(); + while (c > '9' || c < '0') { + if (c == '-') f = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + ans = ans * 10 + c - '0'; + c = getchar(); + } + return ans * f; +} +int main() { + string a, b; + cin >> a >> b; + int x = b[0] - a[0], y = b[1] - a[1]; + cout << max(abs(x), abs(y)) << endl; + if (x > 0) { + if (y > 0) { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "RU" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "R" : "U") << endl; + } else { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "RD" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "R" : "D") << endl; + } + } else { + if (y > 0) { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "LU" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "L" : "U") << endl; + } else { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "LD" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "L" : "D") << endl; + } + } + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + map mp; + cin.ignore(); + while (n--) { + string s; + getline(cin, s); + mp[s]++; + } + cout << mp.size() << '\n'; + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +int main() { + int n; + cin >> n; + map mp; + cin.ignore(); + while (n--) { + string s; + getline(cin, s); + mp[s]++; + } + cout << mp.size() << '\n'; + return 0; +} +int main() { + string s, t, temp = ""; + cin >> s >> t; + for (int i = 0; i < s.length(); i++) temp = s[i] + temp; + if (temp == t) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s, t, temp = ""; + cin >> s >> t; + for (int i = 0; i < s.length(); i++) temp = s[i] + temp; + if (temp == t) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long int a, maxx, z; +string s2[10000], s1[10000]; +int main() { + cin >> a; + for (long int i = 1; i <= a; i++) { + maxx = 0; + cin >> s1[i] >> s2[i]; + for (long int j = i - 1; j >= 1; j--) + if (s1[j] == s1[i] && s2[j] == s2[i]) { + maxx = 1; + break; + } + if (maxx == 0) z++; + } + cout << z << endl; + return 0; +} +long int a, maxx, z; +string s2[10000], s1[10000]; +int main() { + cin >> a; + for (long int i = 1; i <= a; i++) { + maxx = 0; + cin >> s1[i] >> s2[i]; + for (long int j = i - 1; j >= 1; j--) + if (s1[j] == s1[i] && s2[j] == s2[i]) { + maxx = 1; + break; + } + if (maxx == 0) z++; + } + cout << z << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + for (int l = n - 1; l >= 1; l--) { + set st; + for (int j = 0; j <= n - l; j++) { st.insert(s.substr(j, l)); } + if (st.size() != n - l + 1) { + cout << l << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +int main() { + char s1[5], s2[5]; + while (cin >> s1 >> s2) { + int x = s2[0] - s1[0]; + int y = s2[1] - s1[1]; + cout << max(abs(x), abs(y)) << endl; + while (x || y) { + if (x > 0) x--, cout << "R"; + if (x < 0) x++, cout << "L"; + if (y > 0) y--, cout << "U"; + if (y < 0) y++, cout << "D"; + cout << endl; + } + } + return 0; +} +int main() { + char s1[5], s2[5]; + while (cin >> s1 >> s2) { + int x = s2[0] - s1[0]; + int y = s2[1] - s1[1]; + cout << max(abs(x), abs(y)) << endl; + while (x || y) { + if (x > 0) x--, cout << "R"; + if (x < 0) x++, cout << "L"; + if (y > 0) y--, cout << "U"; + if (y < 0) y++, cout << "D"; + cout << endl; + } + } + return 0; +} +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int main() { + int m, n; + cin >> m >> n; + char a[m][n]; + int x = m, y = n, t = 0, z = 0; + for (int i = 0; i < m; i++) { + int c = 0; + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + x = x < i ? x : i; + y = y < j ? y : j; + t = t > j ? t : j; + z = z > i ? z : i; + } + } + } + for (int i = x; i <= z; i++) { + for (int j = y; j <= t; j++) { cout << a[i][j]; } + cout << "\n"; + } +} +int main() { + string s, t; + int n; + bool flag = true; + cin >> s >> t; + n = s.length(); + for (int i = n - 1, j = 0; i >= 0; i--, j++) { + if (s[i] != t[j]) { flag = false; } + } + if (flag == true) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +long long const mx = 1e3; +long long x, y, p; +int main() { + set st; + int t; + cin >> t; + cin.get(); + while (t--) { + string s; + getline(cin, s); + st.insert(s); + } + cout << st.size() << endl; + return 0; +} +long long const mx = 1e3; +long long x, y, p; +int main() { + set st; + int t; + cin >> t; + cin.get(); + while (t--) { + string s; + getline(cin, s); + st.insert(s); + } + cout << st.size() << endl; + return 0; +} +int main() { + string a; + cin >> a; + int num = 0; + for (int i = 0; i < a.length() - 1; i++) { + for (int j = i + 1; j < a.length(); j++) { + if (a[i] == a[j]) { + int nn = 1; + for (int ii = i + 1, jj = j + 1; jj < a.length(); jj++, ii++) { + if (a[ii] == a[jj]) + nn++; + else + break; + } + if (nn > num) num = nn; + } + } + } + cout << num << endl; + return 0; +} +int n, m, p, q, x, y; +char gg, a[101][101]; +int main() { + cin >> n >> m; + p = 0x3f, x = 0x3f; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> gg; + a[i][j] = gg; + if (gg == '*') { + if (i <= p) p = i; + if (j <= x) x = j; + if (i >= q) q = i; + if (j >= y) y = j; + } + } + } + for (int i = p; i <= q; i++) { + for (int j = x; j <= y; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int n, ans = 1; +bool flag; +string a[101][3]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; + for (int i = 2; i <= n; i++) { + flag = 1; + for (int j = i - 1; j >= 1; j--) { + if (a[i][1] == a[j][1] && a[i][2] == a[j][2]) { + flag = 0; + break; + } + } + if (flag) ans++; + } + cout << ans << endl; + return 0; +} +int n, ans = 1; +bool flag; +string a[101][3]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; + for (int i = 2; i <= n; i++) { + flag = 1; + for (int j = i - 1; j >= 1; j--) { + if (a[i][1] == a[j][1] && a[i][2] == a[j][2]) { + flag = 0; + break; + } + } + if (flag) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } else if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } + cout << endl; + } + return 0; +} +string a[105]; +int main() { + int n; + cin >> n; + int ans = n; + for (int i = 0; i < n; i++) { + string s, t; + cin >> s >> t; + a[i] = s + ' ' + t; + for (int j = 0; j < i; j++) + if (a[i] == a[j]) { + ans--; + break; + } + } + cout << ans << endl; + return 0; +} +string a[105]; +int main() { + int n; + cin >> n; + int ans = n; + for (int i = 0; i < n; i++) { + string s, t; + cin >> s >> t; + a[i] = s + ' ' + t; + for (int j = 0; j < i; j++) + if (a[i] == a[j]) { + ans--; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + string str1, str2; + cin >> str1 >> str2; + int s1 = str1.size(), s2 = str2.size(); + int i = 0, j = s2 - 1, no = 0; + if (s1 != s2) + cout << "NO" << endl; + else { + while (i < s1) { + if (str1[i] != str2[j]) { + cout << "NO" << endl; + no = 1; + break; + } + i++; + j--; + } + if (no == 0) cout << "YES" << endl; + } + return 0; +} +int getint() { + int ans = 0, f = 1; + char c = getchar(); + while (c > '9' || c < '0') { + if (c == '-') f = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + ans = ans * 10 + c - '0'; + c = getchar(); + } + return ans * f; +} +int main() { + string a, b; + cin >> a >> b; + int x = b[0] - a[0], y = b[1] - a[1]; + cout << max(abs(x), abs(y)) << endl; + if (x > 0) { + if (y > 0) { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "RU" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "R" : "U") << endl; + } else { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "RD" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "R" : "D") << endl; + } + } else { + if (y > 0) { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "LU" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "L" : "U") << endl; + } else { + x = abs(x); + y = abs(y); + for (int i = 0; i < min(x, y); i++) cout << "LD" << endl; + for (int i = 0; i < max(x, y) - min(x, y); i++) cout << (x > y ? "L" : "D") << endl; + } + } + return 0; +} +int m1 = 500; +int m2 = -1; +int m3 = 500; +int m4 = -1; +int main() { + char map[55][55]; + int m, n; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cin >> map[i][j]; } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (map[i][j] == '*' && j < m1) { m1 = j; } + } + for (int j = m; j >= 1; j--) { + if (map[i][j] == '*' && j > m2) { m2 = j; } + } + } + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (map[j][i] == '*' && j < m3) m3 = j; + } + for (int j = n; j >= 1; j--) { + if (map[j][i] == '*' && j > m4) m4 = j; + } + } + for (int i = m3; i <= m4; i++) { + for (int j = m1; j <= m2; j++) cout << map[i][j]; + cout << endl; + } +} +int main() { + map, int> a; + int x, r = 0; + cin >> x; + string y, l; + for (int i = 0; i < x; i++) { + cin >> y >> l; + pair p(y, l); + if (a.find(p) == a.end()) { + a[p] = 1; + r++; + } + } + cout << r << endl; +} +int main() { + map, int> a; + int x, r = 0; + cin >> x; + string y, l; + for (int i = 0; i < x; i++) { + cin >> y >> l; + pair p(y, l); + if (a.find(p) == a.end()) { + a[p] = 1; + r++; + } + } + cout << r << endl; +} +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int main() { + string s, t; + getline(cin, s); + getline(cin, t); + int sl = s.length(); + int tl = t.length(); + char c1[sl + 1], c2[tl + 1]; + strcpy(c1, s.c_str()); + strcpy(c2, t.c_str()); + tl--; + int k = 0; + for (int i = 0; i < sl; i++) { + if (c1[i] == c2[tl]) { + tl--; + } else { + k++; + break; + } + } + if (k == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int u, d, l, r, n, m; +bool a[51][51]; +int main() { + cin >> n >> m; + u = n; + d = 0; + l = m; + r = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + char c; + cin >> c; + a[i][j] = (c == '*'); + if (a[i][j]) { + u = min(u, i); + d = max(d, i); + l = min(l, j); + r = max(r, j); + } + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) + if (a[i][j]) + cout << "*"; + else + cout << "."; + cout << "\n"; + } +} +char sir[1000]; +set s; +string a; +int n, i; +int nr; +int main() { + cin >> n; + cin.get(); + for (i = 1; i <= n; i++) { + getline(cin, a); + if (s.find(a) == s.end()) { + nr++; + s.insert(a); + } + } + cout << nr << '\n'; + return 0; +} +int main() { + string str, str2; + cin >> str; + cin >> str2; + reverse(str2.begin(), str2.end()); + if (str == str2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, d = 51, c = 0, g = 0, r = 51; + char a[52][52]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + if (i < d) d = i; + if (j < r) r = j; + if (i > g) g = i; + if (j > c) c = j; + } + } + } + for (int i = d; i <= g; i++) { + for (int j = r; j <= c; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int n; +string a, b; +set s; +int main() { + cin >> n; + while (n--) { + cin >> a >> b; + s.insert(a + '+' + b); + } + cout << s.size() << '\n'; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(t.begin(), t.end()); + if (s == t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, cnt = 0; + map mp; + string str; + cin >> n; + getchar(); + while (n--) { + getline(cin, str); + if (!mp.count(str)) { + cnt++; + mp[str] = 1; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, cnt = 0; + map mp; + string str; + cin >> n; + getchar(); + while (n--) { + getline(cin, str); + if (!mp.count(str)) { + cnt++; + mp[str] = 1; + } + } + cout << cnt << endl; + return 0; +} +char c[55][55]; +int n, m, x = 999999, y = 999999, X, Y; +int main() { + cin >> n >> m; + int ok = 0; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) cin >> c[i][j]; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) + if (c[i][j] == '*') { + x = min(x, i); + y = min(y, j); + } + } + for (int i = n; i >= 1; --i) { + for (int j = m; j >= 1; --j) + if (c[i][j] == '*') { + X = max(X, i); + Y = max(Y, j); + } + } + for (int i = x; i <= X; ++i) { + for (int j = y; j <= Y; ++j) cout << c[i][j]; + cout << endl; + } + return 0; +} +int main() { + string str1, str2; + cin >> str1 >> str2; + reverse(str1.begin(), str1.end()); + if (str1 == str2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + string str1, str2; + cin >> str1 >> str2; + reverse(str1.begin(), str1.end()); + if (str1 == str2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + string s[60]; + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s[i]; + int U = 999, D = -1, L = 999, R = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] == '*') { + U = min(U, i); + D = max(D, i); + L = min(L, j); + R = max(R, j); + } + } + } + for (int i = U; i <= D; i++) { + for (int j = L; j <= R; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + string s[60]; + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s[i]; + int U = 999, D = -1, L = 999, R = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] == '*') { + U = min(U, i); + D = max(D, i); + L = min(L, j); + R = max(R, j); + } + } + } + for (int i = U; i <= D; i++) { + for (int j = L; j <= R; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + string str, st; + int i; + cin >> str; + cin >> st; + reverse(str.begin(), str.end()); + if (str == st) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, d, c = 0, i; + cin >> n >> d; + int arr[n]; + for (i = 0; i < n; i++) cin >> arr[i]; + for (i = 0; i < n - 1; i++) { + if (arr[i] >= arr[i + 1]) { + int stp = arr[i] - arr[i + 1]; + int tm = stp / d; + c += tm; + arr[i + 1] += (tm * d); + if (arr[i] >= arr[i + 1]) { + c++; + arr[i + 1] += d; + } + } + } + cout << c << endl; + return 0; +} +int main() { + int n, d, c = 0, i; + cin >> n >> d; + int arr[n]; + for (i = 0; i < n; i++) cin >> arr[i]; + for (i = 0; i < n - 1; i++) { + if (arr[i] >= arr[i + 1]) { + int stp = arr[i] - arr[i + 1]; + int tm = stp / d; + c += tm; + arr[i + 1] += (tm * d); + if (arr[i] >= arr[i + 1]) { + c++; + arr[i + 1] += d; + } + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, mini1 = 60, mini2 = 60, maxi1 = 0, maxi2 = 0; + char a[60][60]; + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + mini1 = min(mini1, i); + mini2 = min(mini2, j); + maxi1 = max(maxi1, i); + maxi2 = max(maxi2, j); + } + } + for (int i = mini1; i <= maxi1; i++) { + for (int j = mini2; j <= maxi2; j++) cout << a[i][j]; + cout << endl; + } +} +int main() { + string s; + cin >> s; + for (int i = s.size() - 1; i > 0; i--) { + for (int j = 0; j <= s.size() - i; j++) { + for (int k = j + 1; k <= s.size() - i; k++) { + if (s.substr(j, i) == s.substr(k, i)) { + cout << i << "\n"; + return 0; + } + } + } + } + cout << "0\n"; + return 0; +} +int main() { + string a, b; + int i, j, o = 0; + cin >> a >> b; + int l = a.length(); + int m = b.length(); + for (i = 0, j = m - 1; i < l; i++, j--) { + if (a[i] != b[j]) { o = 1; } + } + if (o == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int t = n - 1, b = 0, l = m - 1, r = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + bool f = false; + for (int j = 0; j < s.size(); j++) { + a[i][j] = s[j]; + if (s[j] == '*') { + if (!f) { + l = min(l, j); + f = 1; + } + r = max(r, j); + } + } + if (f == true) { + t = min(i, t); + b = max(i, b); + } + } + for (int i = t; i <= b; i++, cout << endl) { + for (int j = l; j <= r; j++) { cout << a[i][j]; } + } +} +int res, up, down; +int main() { + string s, t; + cin >> s >> t; + if (s.length() != t.length()) + cout << "NO" << endl; + else { + for (int i = 0; i < s.length(); i++) { + if (s[i] == t[t.length() - 1 - i]) + res++; + else + break; + } + if (res == s.length()) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int cmp(int a, int b, string x, int l) { + int t = 0; + for (; a < l && b < l; a++, b++) { + if (x[a] == x[b]) { + t += 1; + } else + break; + } + return t; +} +int main() { + string a; + cin >> a; + int l = a.size(); + int max = 0; + for (int i = 0; i < l - 1; i++) { + for (int j = i + 1; j < l; j++) { + if (a[i] == a[j]) { + int t; + t = cmp(i, j, a, l); + if (t > max) max = t; + } + } + } + cout << max << endl; + return 0; +} +char s[100][100]; +int imx, imn = 1222, jmx, jmn = 1222; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> s[i][j]; + char ch = s[i][j]; + if (ch == '*') { + imx = max(imx, i); + imn = min(imn, i); + jmx = max(jmx, j); + jmn = min(jmn, j); + } + } + } + for (int k = imn; k <= imx; k++) { + for (int p = jmn; p <= jmx; p++) { cout << s[k][p]; } + cout << endl; + } +} +int main() { + string str1, str2; + cin >> str1 >> str2; + reverse(str1.begin(), str1.end()); + if (str1.compare(str2) != 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +long long n, a[2007], ans, d; +int main() { + cin >> n >> d; + for (register int i = 1; i <= n; i++) cin >> a[i]; + for (register int i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + ans += (a[i - 1] - a[i]) / d; + a[i] = a[i] + ((a[i - 1] - a[i]) / d + 1) * d; + ans++; + } + } + cout << ans << endl; + return 0; +} +long long n, a[2007], ans, d; +int main() { + cin >> n >> d; + for (register int i = 1; i <= n; i++) cin >> a[i]; + for (register int i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + ans += (a[i - 1] - a[i]) / d; + a[i] = a[i] + ((a[i - 1] - a[i]) / d + 1) * d; + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + char a[101]; + cin >> a; + int len = strlen(a); + int l = len; + while (l--) { + for (int i = 0; i <= len - l; i++) { + for (int j = i + 1; j <= len - l; j++) { + int k = i, m = j; + for (; k <= i + l && m <= j + l; k++, m++) { + if (a[k] != a[m]) break; + } + if (k == i + l + 1) { + cout << l + 1 << endl; + return 0; + } + } + } + } + cout << l + 1 << endl; + return 0; +} +int main() { + int n; + string s[110]; + while (cin >> n) { + getchar(); + int k = 0; + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + int flag = 0; + for (int j = 0; j < i; j++) { + if (str == s[j]) flag = 1; + } + if (!flag) s[k++] = str; + } + cout << k << endl; + } +} +int main() { + int n; + string s[110]; + while (cin >> n) { + getchar(); + int k = 0; + for (int i = 0; i < n; i++) { + string str; + getline(cin, str); + int flag = 0; + for (int j = 0; j < i; j++) { + if (str == s[j]) flag = 1; + } + if (!flag) s[k++] = str; + } + cout << k << endl; + } +} +long long n, d, a, b, ans; +int main() { + cin >> n >> d; + cin >> a; + for (int i = 1; i < n; i++) { + cin >> b; + if (b <= a) { + a = a - b; + ans += (a / d + 1); + b += ((a / d + 1) * d); + } + swap(a, b); + } + cout << ans << '\n'; + return 0; +} +int m, n, u = -2019, d = -2019, r = -2019, l = -2019; +char a[100][100]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*' and u == -2019) { + u = i; + break; + } + } + } + for (int i = n - 1; i > -1; i--) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*' and d == -2019) { + d = i; + break; + } + } + } + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (a[j][i] == '*' and l == -2019) { + l = i; + break; + } + } + } + for (int i = m - 1; i > -1; i--) { + for (int j = 0; j < n; j++) { + if (a[j][i] == '*' and r == -2019) { + r = i; + break; + } + } + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, v; + cin >> n >> v; + double a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + double minvalue = INT_MAX; + double b[n]; + for (int i = 0; i < n; i++) { + cin >> b[i]; + minvalue = min(minvalue, b[i]); + } + double l = 0; + double r = 1e18; + double answer = 0; + for (int i = 1; i <= 100; i++) { + double mid = (l + (r - l) / 2); + double sum = 0; + int flag = 0; + for (int i = 0; i < n; i++) { + double value = a[i] * mid; + if (value > b[i]) { + flag = 1; + break; + } else + sum += (a[i] * mid); + } + if (flag == 1) { + r = mid - 1; + continue; + } + if (sum <= v) { + answer = sum; + l = mid + 1; + } else { + r = mid - 1; + } + } + cout << setprecision(6) << fixed << answer << "\n"; + return 0; +} +const int Max_N = 1e5 + 5; +const int mod = 1e9 + 7; +int bord[6][2] = {-1, 0, 0, 1, 1, 0, 0, -1}; +int main() { + int n, d; + int a[2005]; + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> a[i]; + int ant = 0; + for (int i = 2; i <= n; i++) { + if (a[i] > a[i - 1]) continue; + ant += (abs(a[i] - a[i - 1])) / d + 1; + a[i] += ((abs(a[i] - a[i - 1])) / d + 1) * d; + } + cout << ant << endl; + return 0; +} +const int Max_N = 1e5 + 5; +const int mod = 1e9 + 7; +int bord[6][2] = {-1, 0, 0, 1, 1, 0, 0, -1}; +int main() { + int n, d; + int a[2005]; + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> a[i]; + int ant = 0; + for (int i = 2; i <= n; i++) { + if (a[i] > a[i - 1]) continue; + ant += (abs(a[i] - a[i - 1])) / d + 1; + a[i] += ((abs(a[i] - a[i - 1])) / d + 1) * d; + } + cout << ant << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << (n * m) / 2 << endl; + return 0; +} +const double PI = acos(-1); +const double EPS = 1e-12; +const int MOD = 1e9 + 7; +const int INF = 1 << 30; +int main() { + int in; + string s, str; + map, int> m; + int cnt = 0; + cin >> in; + for (int i = 1; i <= in; i += 1) { + cin >> s >> str; + if (m[make_pair(s, str)] == 0) { cnt++; } + m[make_pair(s, str)]++; + } + cout << cnt << endl; + return 0; +} +const double PI = acos(-1); +const double EPS = 1e-12; +const int MOD = 1e9 + 7; +const int INF = 1 << 30; +int main() { + int in; + string s, str; + map, int> m; + int cnt = 0; + cin >> in; + for (int i = 1; i <= in; i += 1) { + cin >> s >> str; + if (m[make_pair(s, str)] == 0) { cnt++; } + m[make_pair(s, str)]++; + } + cout << cnt << endl; + return 0; +} +long long n, d; +long long str[100000]; +int ans; +int main() { + ans = 0; + cin >> n >> d; + for (int i = 0; i < n; i++) { cin >> str[i]; } + for (int i = 1; i < n; i++) { + if (str[i] <= str[i - 1]) { + int k = (str[i - 1] - str[i]) / d + 1; + str[i] += d * k; + ans += k; + } + } + cout << ans << endl; + return 0; +} +long long n, d; +long long str[100000]; +int ans; +int main() { + ans = 0; + cin >> n >> d; + for (int i = 0; i < n; i++) { cin >> str[i]; } + for (int i = 1; i < n; i++) { + if (str[i] <= str[i - 1]) { + int k = (str[i - 1] - str[i]) / d + 1; + str[i] += d * k; + ans += k; + } + } + cout << ans << endl; + return 0; +} +map m; +int main() { + int n, i, count = 0; + cin >> n; + getchar(); + while (n--) { + string s; + getline(cin, s); + m[s] = 0; + } + map::iterator it; + for (it = m.begin(); it != m.end(); it++) count++; + cout << count << endl; +} +map m; +int main() { + int n, i, count = 0; + cin >> n; + getchar(); + while (n--) { + string s; + getline(cin, s); + m[s] = 0; + } + map::iterator it; + for (it = m.begin(); it != m.end(); it++) count++; + cout << count << endl; +} +const int MX = 55; +int n, m, maxx = -1, minx = 1e4, maxy = -1, miny = 1e4; +char a[MX][MX]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '.') continue; + minx = min(minx, i); + miny = min(miny, j); + maxx = max(maxx, i); + maxy = max(maxy, j); + } + for (int i = minx; i <= maxx; i++, cout << "\n") + for (int j = miny; j <= maxy; j++) cout << a[i][j]; +} +int main() { + long long d, n, mov = 0, rem, res; + cin >> n >> d; + long long b[n]; + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 1; i < n; i++) { + rem = 0; + res = 0; + if (b[i] <= b[i - 1]) { + res = b[i - 1] - b[i]; + res += d; + rem = res / d; + mov += rem; + b[i] += (rem * d); + } + } + cout << mov << endl; +} +int main() { + long long d, n, mov = 0, rem, res; + cin >> n >> d; + long long b[n]; + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 1; i < n; i++) { + rem = 0; + res = 0; + if (b[i] <= b[i - 1]) { + res = b[i - 1] - b[i]; + res += d; + rem = res / d; + mov += rem; + b[i] += (rem * d); + } + } + cout << mov << endl; +} +int main() { + long long int n, i, d, ans = 0, a[1000004]; + cin >> n >> d; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 1; i < n; i++) { + if (a[i] > a[i - 1]) continue; + long long int y = (a[i - 1] - a[i] + d) / d; + a[i] += y * d; + ans += y; + } + cout << ans << endl; +} +int main() { + int r, c, x = 0, y = 0, z = -1, m, n, c1 = 0, g, o = 0, u, v, e = 0; + cin >> r >> c; + v = c; + m = c + 1; + bool s = true; + char arr[r][c]; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> arr[i][j]; + if (arr[i][j] == '*') { + s = false; + c1++; + if (c1 == 1) { m = j; } + x++; + g = i; + o = j; + } + } + if (!s && z == -1) { z = i; } + if (m < v) v = m; + if (o > e) e = o; + if (x > y) { y = x; } + c1 = 0; + x = 0; + } + if (!s) { + m = v; + o = e; + int p = g - z + 1; + y = o - m + 1; + char arr1[p][y]; + int k = 0, l = 0; + for (int i = z; i <= g; i++) { + for (int j = m; j <= o; j++) { + arr1[k][l] = arr[i][j]; + l++; + } + l = 0; + k++; + } + for (int i = 0; i < p; i++) { + for (int j = 0; j < y; j++) { cout << arr1[i][j]; } + cout << endl; + } + } else { + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { cout << arr[i][j]; } + cout << endl; + } + } + return 0; +} +int main() { + int r, c, x = 0, y = 0, z = -1, m, n, c1 = 0, g, o = 0, u, v, e = 0; + cin >> r >> c; + v = c; + m = c + 1; + bool s = true; + char arr[r][c]; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> arr[i][j]; + if (arr[i][j] == '*') { + s = false; + c1++; + if (c1 == 1) { m = j; } + x++; + g = i; + o = j; + } + } + if (!s && z == -1) { z = i; } + if (m < v) v = m; + if (o > e) e = o; + if (x > y) { y = x; } + c1 = 0; + x = 0; + } + if (!s) { + m = v; + o = e; + int p = g - z + 1; + y = o - m + 1; + char arr1[p][y]; + int k = 0, l = 0; + for (int i = z; i <= g; i++) { + for (int j = m; j <= o; j++) { + arr1[k][l] = arr[i][j]; + l++; + } + l = 0; + k++; + } + for (int i = 0; i < p; i++) { + for (int j = 0; j < y; j++) { cout << arr1[i][j]; } + cout << endl; + } + } else { + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { cout << arr[i][j]; } + cout << endl; + } + } + return 0; +} +long long n, a[2007], ans, d; +int main() { + cin >> n >> d; + for (register int i = 1; i <= n; i++) cin >> a[i]; + for (register int i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + ans += (a[i - 1] - a[i]) / d; + a[i] = a[i] + ((a[i - 1] - a[i]) / d + 1) * d; + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, m, i, j, imin = 100, imax = 0, jmin = 100, jmax = 0; + cin >> n >> m; + char str[n + 5][m + 5]; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> str[i][j]; + { + if (str[i][j] == '*') { + if (i < imin) imin = i; + if (i > imax) imax = i; + if (j < jmin) jmin = j; + if (j > jmax) jmax = j; + } + } + } + } + for (i = imin; i <= imax; i++) { + for (j = jmin; j <= jmax; j++) { cout << str[i][j]; } + cout << "\n"; + } + return 0; + return 0; +} +int M, N, a; +int main() { + cin >> M >> N; + if (1 <= M && M <= N && N <= 16) { + a = M * N / 2; + cout << a << endl; + } +} +int main() { + int n, d; + cin >> n >> d; + int *p = new int[n]; + for (int i = 0; i < n; i++) { cin >> p[i]; } + int prev = p[0]; + int count = 0; + for (int i = 1; i < n; i++) { + if (p[i] == prev) { + count++; + prev = p[i] + d; + } else if (p[i] < prev) { + int value = (prev - p[i]) + 1; + int c; + if (value % d == 0) { + c = value / d; + } else { + c = value / d + 1; + } + count += c; + prev = p[i] + d * c; + } else { + prev = p[i]; + } + } + cout << count << '\n'; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int *p = new int[n]; + for (int i = 0; i < n; i++) { cin >> p[i]; } + int prev = p[0]; + int count = 0; + for (int i = 1; i < n; i++) { + if (p[i] == prev) { + count++; + prev = p[i] + d; + } else if (p[i] < prev) { + int value = (prev - p[i]) + 1; + int c; + if (value % d == 0) { + c = value / d; + } else { + c = value / d + 1; + } + count += c; + prev = p[i] + d * c; + } else { + prev = p[i]; + } + } + cout << count << '\n'; + return 0; +} +int mini1 = 100, maxi1 = -100, maxi2 = -100, mini2 = 100; +int main() { + int n, m; + cin >> n >> m; + char a[m][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> a[j][i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (a[j][i] == '*' && j < mini1) mini1 = j; + if (a[j][i] == '*' && i < mini2) mini2 = i; + if (a[j][i] == '*' && j > maxi1) maxi1 = j; + if (a[j][i] == '*' && i > maxi2) maxi2 = i; + } + for (int i = mini2; i <= maxi2; i++) + for (int j = mini1; j <= maxi1; j++) { + if (j != maxi1) + cout << a[j][i]; + else + cout << a[j][i] << endl; + } + return 0; +} +int main() { + char s[101]; + char t[101]; + gets(s); + gets(t); + int lens = strlen(s), lent = strlen(t), i, judg = 1; + if (lens != lent) { + puts("NO"); + return 0; + } + for (i = 0; i < lens; i++) { + if (s[i] != t[lens - 1 - i]) { judg = 0; } + } + if (judg == 1) + puts("YES"); + else + puts("NO"); + return 0; +} +int n, d, x, a[2010], i, t; +int main() { + cin >> n >> d; + for (i - 0; i < n; i++) { + cin >> a[i]; + t = a[i] > a[i - 1] ? 0 : (a[i - 1] - a[i]) / d + 1; + x += t; + a[i] += t * d; + } + cout << x << endl; + return 0; +} +int n, d, x, a[2010], i, t; +int main() { + cin >> n >> d; + for (i - 0; i < n; i++) { + cin >> a[i]; + t = a[i] > a[i - 1] ? 0 : (a[i - 1] - a[i]) / d + 1; + x += t; + a[i] += t * d; + } + cout << x << endl; + return 0; +} +int main() { + string s; + int n, m; + cin >> n >> m; + cout << ((m * n) / 2) << endl; + return 0; +} +int main() { + long long n, d, z = 0; + cin >> n >> d; + long long last = 0; + while (n--) { + long long x; + cin >> x; + if (x <= last) { + long long t = (last - x) / d + 1; + z += t; + x += d * t; + } + last = x; + } + cout << z << '\n'; +} +int main() { + long long n, d, z = 0; + cin >> n >> d; + long long last = 0; + while (n--) { + long long x; + cin >> x; + if (x <= last) { + long long t = (last - x) / d + 1; + z += t; + x += d * t; + } + last = x; + } + cout << z << '\n'; +} +int a[10000]; +int main() { + int n, m; + long long counts = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + counts += (a[i - 1] - a[i]) / m + 1; + a[i] = ((a[i - 1] - a[i]) / m + 1) * m + a[i]; + } + } + cout << counts << endl; +} +int main() { + long long n, d, adder, res = 0; + cin >> n >> d; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int i = 1; i < n; i++) { + if (arr[i - 1] >= arr[i]) { + adder = (arr[i - 1] - arr[i]) / d + 1; + res += adder; + arr[i] += adder * d; + } + } + cout << res << endl; + return 0; +} +int main() { + long long n, d, adder, res = 0; + cin >> n >> d; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int i = 1; i < n; i++) { + if (arr[i - 1] >= arr[i]) { + adder = (arr[i - 1] - arr[i]) / d + 1; + res += adder; + arr[i] += adder * d; + } + } + cout << res << endl; + return 0; +} +int main() { + char a[105], b[105], tempo[105]; + gets(a); + gets(b); + int j = 0; + int l1 = strlen(a); + int l2 = strlen(b); + for (int i = l2 - 1; i >= 0; i--, j++) { tempo[j] = b[i]; } + int flag = 1; + for (int m = 0; m < l2 && m < l1; m++) { + if (a[m] != tempo[m]) { + flag = 0; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, m, i, j, min_i, max_i, min_j, max_j; + char s[55][55]; + cin >> n >> m; + min_i = min_j = 55; + max_i = max_j = -1; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + min_i = min(min_i, i), max_i = max(max_i, i); + min_j = min(min_j, j), max_j = max(max_j, j); + } + } + } + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, m, i, j, min_i, max_i, min_j, max_j; + char s[55][55]; + cin >> n >> m; + min_i = min_j = 55; + max_i = max_j = -1; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + min_i = min(min_i, i), max_i = max(max_i, i); + min_j = min(min_j, j), max_j = max(max_j, j); + } + } + } + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + int x, y, n; + cin >> x >> y; + n = x * y; + if (n % 2 == 0) { + cout << n / 2 << endl; + } else { + cout << (n - 1) / 2 << endl; + } + return 0; +} +int main() { + long long int n, k, i, cnt = 0; + cin >> n >> k; + long long int a[n + 5]; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 1; i < n; i++) { + if (a[i] <= a[i - 1]) { + cnt += (a[i - 1] - a[i]) / k + 1; + a[i] += ((a[i - 1] - a[i]) / k + 1) * k; + } + } + cout << cnt << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + reverse(s.begin(), s.end()); + if (s.compare(t) == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +int main() { + int m, n, j; + cin >> m >> n; + j = (m * n) / 2; + cout << j << endl; + return 0; +} +int mini1 = 100, maxi1 = -100, maxi2 = -100, mini2 = 100; +int main() { + int n, m; + cin >> n >> m; + char a[m][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> a[j][i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (a[j][i] == '*' && j < mini1) mini1 = j; + if (a[j][i] == '*' && i < mini2) mini2 = i; + if (a[j][i] == '*' && j > maxi1) maxi1 = j; + if (a[j][i] == '*' && i > maxi2) maxi2 = i; + } + for (int i = mini2; i <= maxi2; i++) + for (int j = mini1; j <= maxi1; j++) { + if (j != maxi1) + cout << a[j][i]; + else + cout << a[j][i] << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s; + cin >> t; + string res = "YES"; + int length = s.size(); + for (int i = 0; i < length; i++) { + if (s[i] != t[length - i - 1]) { + res = "NO"; + break; + } + } + cout << res << endl; + return 0; +} +int main() { + string s, t; + cin >> s; + cin >> t; + string res = "YES"; + int length = s.size(); + for (int i = 0; i < length; i++) { + if (s[i] != t[length - i - 1]) { + res = "NO"; + break; + } + } + cout << res << endl; + return 0; +} +int main() { + long long m, n, a, ans; + cin >> m >> n; + a = m * n; + ans = a / 2; + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + char a[52][52]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + int min, max, row_min, row_max; + min = 100; + max = 0; + row_min = 100; + row_max = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*') { + if (j < min) min = j; + if (j > max) max = j; + if (i < row_min) row_min = i; + if (i > row_max) row_max = i; + } + } + } + for (int i = row_min; i <= row_max; i++) { + for (int j = min; j <= max; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[52][52]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + int min, max, row_min, row_max; + min = 100; + max = 0; + row_min = 100; + row_max = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*') { + if (j < min) min = j; + if (j > max) max = j; + if (i < row_min) row_min = i; + if (i > row_max) row_max = i; + } + } + } + for (int i = row_min; i <= row_max; i++) { + for (int j = min; j <= max; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int x, y; + cin >> x >> y; + cout << (x * y) / 2 << endl; + return 0; +} +int main() { + string s, ss; + cin >> s >> ss; + reverse(s.begin(), s.end()); + s == ss ? puts("YES") : puts("NO"); + return 0; +} +int main() { + long long d, n, mov = 0, rem, res; + cin >> n >> d; + long long b[n]; + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 1; i < n; i++) { + rem = 0; + res = 0; + if (b[i - 1] >= b[i]) { + res = b[i - 1] - b[i]; + res += d; + rem = res / d; + mov += rem; + b[i] += (rem * d); + } + } + cout << mov << endl; +} +int main() { + long long d, n, mov = 0, rem, res; + cin >> n >> d; + long long b[n]; + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 1; i < n; i++) { + rem = 0; + res = 0; + if (b[i - 1] >= b[i]) { + res = b[i - 1] - b[i]; + res += d; + rem = res / d; + mov += rem; + b[i] += (rem * d); + } + } + cout << mov << endl; +} +char a[101], b[101]; +int main() { + cin >> a; + cin >> b; + int lena = strlen(a); + for (int i = 0; i < lena; i++) { + if (a[i] != b[lena - i - 1]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +char a[55][55]; +int main() { + int m, n; + int alt = -1000, ust = 1000, sag = -1000, sol = 1000; + cin >> m >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + alt = max(alt, i); + ust = min(ust, i); + sag = max(sag, j); + sol = min(sol, j); + } + } + for (int i = ust; i <= alt; i++) { + for (int j = sol; j <= sag; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << (a * b / 2) << endl; +} +int main() { + long long a[100000], n, m, c = 0, c1 = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (m != 1) { + for (int i = 2; i <= n; i++) { + while (a[i - 1] >= a[i]) { + a[i] += m; + c++; + } + } + } else { + for (int i = 2; i <= n; i++) { + if (a[i - 1] >= a[i]) { + c1 = a[i - 1] - a[i]; + c += c1 + 1; + a[i] = a[i] + (c1 + 1); + } + } + } + cout << c << "\n"; +} +int main() { + long long a[100000], n, m, c = 0, c1 = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (m != 1) { + for (int i = 2; i <= n; i++) { + while (a[i - 1] >= a[i]) { + a[i] += m; + c++; + } + } + } else { + for (int i = 2; i <= n; i++) { + if (a[i - 1] >= a[i]) { + c1 = a[i - 1] - a[i]; + c += c1 + 1; + a[i] = a[i] + (c1 + 1); + } + } + } + cout << c << "\n"; +} +long long n, a[1000001], x, b, sum = 0, w = 0; +char ch1, ch2; +string s; +int main() { + long long m, n; + cin >> m >> n; + w = m * n; + w /= 2; + cout << ceil(w) << endl; + return 0; +} +int main() { + int n, m, b, c, d, e; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int j = 0; j < m; j++) { + for (int i = 0; i < n; i++) { + if (a[i][j] == '*') { + b = j; + break; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*') { + c = i; + break; + } + } + } + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '*') { + d = i; + break; + } + } + } + for (int j = m - 1; j >= 0; j--) { + for (int i = 0; i < n; i++) { + if (a[i][j] == '*') { + e = j; + break; + } + } + } + for (int i = d; i < c + 1; i++) { + for (int j = e; j < b + 1; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int m, n, i, j, sum, num; + int a[15000]; + cin >> n >> m; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sum = 0; + for (i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + num = (a[i - 1] - a[i] + m) / m; + a[i] += num * m; + sum += num; + } + } + cout << sum << endl; + return 0; +} +int main() { + int m, n, i, j, sum, num; + int a[15000]; + cin >> n >> m; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sum = 0; + for (i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + num = (a[i - 1] - a[i] + m) / m; + a[i] += num * m; + sum += num; + } + } + cout << sum << endl; + return 0; +} +int main() { + int a; + cin >> a; + int numerator = 0; + int base = 2; + int temp = a; + for (base = 2; base < a; base++) { + while (temp >= base) { + int rem = temp % base; + numerator += rem; + temp = temp - rem; + temp = temp / base; + } + numerator += temp; + temp = a; + } + int denominator = a - 2; + for (int i = 2; i <= a - 2; i++) { + while (numerator % i == 0 && denominator % i == 0) { + numerator = numerator / i; + denominator = denominator / i; + } + } + cout << numerator << "/" << denominator << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int prev; + int count = 0; + for (int i = 0; i < n; ++i) { + int b; + cin >> b; + if (i > 0 && b <= prev) { + int mult = (prev - b) / d + (((prev - b) % d) ? 1 : 0); + if (b + d * mult == prev) { mult++; } + count += mult; + prev = b + mult * d; + } else { + prev = b; + } + } + cout << count << endl; + return 0; +} +int main() { + char a[100][100]; + int n, m, up = 50, left = 50, down = 0, right = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + if (a[i][j] == '*') { + if (i < up) up = i; + if (i > down) down = i; + if (j < left) left = j; + if (j > right) right = j; + } + } + for (int i = up; i <= down; i++) { + for (int j = left; j <= right; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int S(int x, int y) { + int res = 0; + while (x) { + res += x % y; + x /= y; + } + return res; +} +int main() { + int a; + cin >> a; + int sum = 0, num = a - 2; + for (int i = 2; i <= a - 1; i++) sum += S(a, i); + for (int i = min(sum, num); i >= 1; i--) + if (sum % i == 0 && num % i == 0) { + sum /= i; + num /= i; + break; + } + cout << sum << '/' << num << endl; + return 0; +} +int main() { + long long a[100000], n, m, c = 0, c1 = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (m != 1) { + for (int i = 2; i <= n; i++) { + while (a[i - 1] >= a[i]) { + a[i] += m; + c++; + } + } + } else { + for (int i = 2; i <= n; i++) { + if (a[i - 1] >= a[i]) { + c1 = a[i - 1] - a[i]; + c += c1 + 1; + a[i] = a[i] + (c1 + 1); + } + } + } + cout << c << "\n"; +} +int main() { + int m, n, c[4]; + c[0] = 0; + c[1] = 0; + c[2] = 0; + c[3] = 0; + cin >> m >> n; + int s[n + 9], r[m + 9]; + char a[m * n + 11]; + for (int i = 0; i <= n; i++) { s[i] = 0; } + for (int i = 0; i <= m; i++) { r[i] = 0; } + for (int i = 1; i <= m * n; i++) { + cin >> a[i]; + if (a[i] == '*') { + s[(i - 1) % n + 1]++; + r[(i - 1) / n + 1]++; + } + } + for (int i = 1; i <= m; i++) { + if (r[i] > 0) { + c[0] = i; + break; + } + } + for (int i = m; i >= 1; i--) { + if (r[i] > 0) { + c[1] = i; + break; + } + } + for (int i = 1; i <= n; i++) { + if (s[i] > 0) { + c[2] = i; + break; + } + } + for (int i = n; i >= 1; i--) { + if (s[i] > 0) { + c[3] = i; + break; + } + } + for (int i = c[0]; i <= c[1]; i++) { + for (int j = c[2]; j <= c[3]; j++) { cout << a[(i - 1) * n + j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << (n * m) / 2 << endl; + return 0; +} +int main() { + int flag; + int l, r, u, d; + char arr[50][50]; + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> arr[i][j]; } + } + flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '*') { + u = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (arr[j][i] == '*') { + l = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '*') { + d = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = m - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (arr[j][i] == '*') { + r = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) { cout << arr[i][j]; } + cout << endl; + } +} +int main() { + int m, n; + cin >> m >> n; + cout << ((m * n) / 2) << endl; + return 0; +} +int main() { + char c[100][100]; + int n, m, a = 0, b = 0, f = 34298343, d = 2193809; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> c[i][j]; + if (c[i][j] == '*') { + if (i > a) a = i; + if (j > b) b = j; + if (i < f) f = i; + if (j < d) d = j; + } + } + } + for (int i = f; i <= a; i++) { + for (int j = d; j <= b; j++) { cout << c[i][j]; } + cout << endl; + } + return 0; +} +int base(int t, int c) { + int s = 0; + while (t) { + s += t % c; + t = t / c; + } + return s; +} +int fraction(int f, int g) { + int k; + for (k = g; k > 1; k--) { + if ((g % k == 0) && (f % k == 0)) + break; + else + continue; + } + return k; +} +int main() { + int a, n, fra; + int sum = 0; + cin >> a; + n = a - 2; + for (int i = 2; i < a; i++) { sum += base(a, i); } + fra = fraction(sum, n); + n = n / fra; + sum = sum / fra; + cout << sum << "/" << n << endl; +} +int main() { + int n, m, i, j, min_i, max_i, min_j, max_j; + char s[55][55]; + cin >> n >> m; + min_i = min_j = 55; + max_i = max_j = -1; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + min_i = min(min_i, i), max_i = max(max_i, i); + min_j = min(min_j, j), max_j = max(max_j, j); + } + } + } + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, m, i, j, min_i, max_i, min_j, max_j; + char s[55][55]; + cin >> n >> m; + min_i = min_j = 55; + max_i = max_j = -1; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == '*') { + min_i = min(min_i, i), max_i = max(max_i, i); + min_j = min(min_j, j), max_j = max(max_j, j); + } + } + } + for (i = min_i; i <= max_i; i++) { + for (j = min_j; j <= max_j; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +long double const EPS = 1e-7; +long long const INF = 2000000007ll; +const long long N = 2005; +long long sumit(long long a, long long i) { + long long ret = 0; + while (a > 0) { + ret += a % i; + a /= i; + } + return ret; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + return gcd(b % a, a); +} +int main() { + long long a; + cin >> a; + long long num, den; + num = den = 0; + for (long long i = 2; i < a; i++) { + num += sumit(a, i); + den++; + } + long long g = gcd(num, den); + num /= g; + den /= g; + cout << num << '/' << den << '\n'; + return 0; +} +int main() { + int n, m, a; + cin >> n >> m; + a = n * m; + cout << a / 2 << endl; + return 0; +} +vector data(50 + 5); +int n, m, l = -1, r = -1, u = -1, d = -1; +int main() { + cin >> n >> m; + for (int i = 0; i <= n - 1; ++i) { + cin >> data[i]; + for (int j = 0; j <= m - 1; ++j) { + if (data[i][j] == '*') { + if (u == -1) { + u = d = i; + } else { + d = i; + } + if (l == -1) { + l = r = j; + } else { + l = min(l, j); + r = max(r, j); + } + } + } + } + for (int i = u; i <= d; ++i) { + for (int j = l; j <= r; ++j) { cout << data[i][j]; } + cout << "\n"; + } + return 0; +} +vector data(50 + 5); +int n, m, l = -1, r = -1, u = -1, d = -1; +int main() { + cin >> n >> m; + for (int i = 0; i <= n - 1; ++i) { + cin >> data[i]; + for (int j = 0; j <= m - 1; ++j) { + if (data[i][j] == '*') { + if (u == -1) { + u = d = i; + } else { + d = i; + } + if (l == -1) { + l = r = j; + } else { + l = min(l, j); + r = max(r, j); + } + } + } + } + for (int i = u; i <= d; ++i) { + for (int j = l; j <= r; ++j) { cout << data[i][j]; } + cout << "\n"; + } + return 0; +} +int n, d, cnt, t, y = 0, ans = 0; +int main() { + cin >> n >> d; + for (int i = 0; i < n; i++) { + cin >> t; + if (y >= t) { + int step = (y - t) / d + 1; + t += step * d; + ans += step; + } + y = t; + } + cout << ans << endl; +} +char a[51][51]; +int n, m, i, j; +void read() { + cin >> n >> m; + int n1 = 0; + int m1 = 0; + int n2 = m + 1; + int m2 = n + 1; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + n1 = max(n1, j); + n2 = min(n2, j); + m1 = max(m1, i); + m2 = min(m2, i); + } + } + } + for (i = m2; i <= m1; i++) { + for (j = n2; j <= n1; j++) cout << a[i][j]; + cout << "\n"; + } +} +int main() { + read(); +} +char a[51][51]; +int n, m, i, j; +void read() { + cin >> n >> m; + int n1 = 0; + int m1 = 0; + int n2 = m + 1; + int m2 = n + 1; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + n1 = max(n1, j); + n2 = min(n2, j); + m1 = max(m1, i); + m2 = min(m2, i); + } + } + } + for (i = m2; i <= m1; i++) { + for (j = n2; j <= n1; j++) cout << a[i][j]; + cout << "\n"; + } +} +int main() { + read(); +} +int main() { + int x, y; + cin >> x >> y; + int xay = ((x / 2) * (y)); + int z = ((x % 2) * y) / 2; + cout << xay + z << endl; +} +int n, m; +int main() { + cin >> m >> n; + cout << (m * n) / 2 << endl; + return 0; +} +int main() { + int a, b, k, p; + cin >> a; + int count = 0; + for (int i = 2; i < a; i++) { + b = a; + for (int j = 0; b > 0; j++) { + count += b % i; + b = b / i; + } + } + k = a - 2; + p = __gcd(k, count); + cout << count / p << "/" << k / p << endl; + return 0; +} +int main() { + int row, col; + char graph[1000][50]; + cin >> row >> col; + int start_x = row; + int start_y = col; + int end_x = 0; + int end_y = 0; + for (int i = 0; i < row; i++) + for (int j = 0; j < col; j++) { + char input; + cin >> graph[i][j]; + if (graph[i][j] == '*') { + if (start_x > i) start_x = i; + if (start_y > j) start_y = j; + if (end_x < i) end_x = i; + if (end_y < j) end_y = j; + } + } + for (int i = start_x; i <= end_x; i++) { + for (int j = start_y; j <= end_y; j++) cout << graph[i][j]; + cout << "\n"; + } + return 0; +} +int main() { + int row, col; + char graph[1000][50]; + cin >> row >> col; + int start_x = row; + int start_y = col; + int end_x = 0; + int end_y = 0; + for (int i = 0; i < row; i++) + for (int j = 0; j < col; j++) { + char input; + cin >> graph[i][j]; + if (graph[i][j] == '*') { + if (start_x > i) start_x = i; + if (start_y > j) start_y = j; + if (end_x < i) end_x = i; + if (end_y < j) end_y = j; + } + } + for (int i = start_x; i <= end_x; i++) { + for (int j = start_y; j <= end_y; j++) cout << graph[i][j]; + cout << "\n"; + } + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { cout << n * m / 2 << endl; } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char ch[n + 9][m + 9]; + int Min_X = n, Min_Y = m; + int Max_X = 0, Max_Y = 0; + for (int i = 0; i < n; i++) { + cin >> ch[i]; + for (int j = 0; j < m; j++) { + if (ch[i][j] == '*') { + Min_X = min(i, Min_X); + Min_Y = min(j, Min_Y); + Max_X = max(i, Max_X); + Max_Y = max(j, Max_Y); + } + } + } + for (int i = Min_X; i <= Max_X; i++) { + for (int j = Min_Y; j <= Max_Y; j++) cout << ch[i][j]; + cout << endl; + } + return 0; +} +int main() { + int m, n, a; + cin >> m >> n; + a = m * n / 2; + cout << a << endl; + return 0; +} +int main() { + int a = 0, o = 0, t = 0, x = 0, y = 0, kh = 0, r = 0; + cin >> a; + for (int i = 2; i < a; i++) { + x = a; + y = i; + t = 0; + kh = 0; + while (x / y != 0) { + t = x % y; + x = x / y; + kh = kh + t; + } + o = o + kh + x; + } + r = a - 2; + for (int j = 0; j < 10; j++) { + for (int i = 2; i < r + 1; i++) { + if (r % i == 0 && o % i == 0) { + r = r / i; + o = o / i; + } + } + } + cout << o << "/" << r << endl; +} +int main() { + int n, m; + cin >> n >> m; + string q[n]; + char A[n][m]; + for (int i = 0; i < n; i++) cin >> q[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) A[i][j] = q[i][j]; + int u = 0, d = n - 1, r = n - 1, l = 0; + for (int i = 0; i < n; i++) { + u = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = n - 1; i >= 0; i--) { + d = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = 0; j < m; j++) { + l = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = m - 1; j >= 0; j--) { + r = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) cout << A[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string q[n]; + char A[n][m]; + for (int i = 0; i < n; i++) cin >> q[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) A[i][j] = q[i][j]; + int u = 0, d = n - 1, r = n - 1, l = 0; + for (int i = 0; i < n; i++) { + u = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = n - 1; i >= 0; i--) { + d = i; + bool k = 0; + for (int j = 0; j < m; j++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = 0; j < m; j++) { + l = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int j = m - 1; j >= 0; j--) { + r = j; + bool k = 0; + for (int i = 0; i < n; i++) + if (A[i][j] == '*') { + k = 1; + break; + } + if (k) break; + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) cout << A[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, t, k = 0, s = 0, x; + cin >> n; + for (int i = 2; i < n; i++) { + t = n; + k++; + while (t > 0) { + s = s + t % i; + t = t / i; + } + } + x = __gcd(s, k); + cout << s / x << '/' << k / x << endl; + return 0; +} +int x, y; +int main() { + cin >> x >> y; + cout << x * y / 2 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char **sheet = new char *[n]; + for (int i = 0; i < n; i++) sheet[i] = new char[m]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> sheet[i][j]; + int minRow = n - 1, minCol = m - 1, maxRow = 0, maxCol = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (sheet[i][j] == '*') { + if (i < minRow) minRow = i; + if (i > maxRow) maxRow = i; + if (j < minCol) minCol = j; + if (j > maxCol) maxCol = j; + } + } + } + for (int i = minRow; i <= maxRow; i++) { + for (int j = minCol; j <= maxCol; j++) { cout << sheet[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char **sheet = new char *[n]; + for (int i = 0; i < n; i++) sheet[i] = new char[m]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> sheet[i][j]; + int minRow = n - 1, minCol = m - 1, maxRow = 0, maxCol = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (sheet[i][j] == '*') { + if (i < minRow) minRow = i; + if (i > maxRow) maxRow = i; + if (j < minCol) minCol = j; + if (j > maxCol) maxCol = j; + } + } + } + for (int i = minRow; i <= maxRow; i++) { + for (int j = minCol; j <= maxCol; j++) { cout << sheet[i][j]; } + cout << endl; + } + return 0; +} +long long digitsum(int a, int b) { + long long x = 0; + while (a) { + x += a % b; + a /= b; + } + return x; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int a; + cin >> a; + long long ans = 0; + for (int i = 2; i < a; i++) ans += digitsum(a, i); + int y = gcd(ans, a - 2); + cout << ans / y << '/' << (a - 2) / y << endl; + return 0; +} +int main() { + int n, m, w; + cin >> n >> m; + if (n >= 1 && n <= 16) + if (m >= 1 && m <= 16) { + w = n * m / 2; + cout << w << endl; + } + return 0; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n; + cin >> n; + int tmp, x = 0; + int y = n - 2; + for (int i = 2; i < n; i++) { + int sum = 0; + tmp = n; + while (tmp) { + sum += tmp % i; + tmp /= i; + } + x += sum; + } + int fpb = gcd(x, y); + cout << x / fpb << "/" << y / fpb << endl; +} +int main() { + long long int i, n, m, x, ans; + cin >> n >> m; + x = n * m; + ans = x / 2; + cout << ans << "\n"; + return 0; +} +int sumaEnOtraBase(int a, int b) { + int suma = 0; + while (a > 0) { + suma += a % b; + a = a / b; + } + return suma; +}; +int main() { + int n, numerador = 0; + cin >> n; + for (int i = 2; i < n; ++i) { numerador += sumaEnOtraBase(n, i); } + int denominador = n - 2; + for (int i = 2; i < denominador / 2; ++i) { + if (numerador % i == 0 && denominador % i == 0) { + numerador = numerador / i; + denominador = denominador / i; + i = i - 1; + } + } + cout << numerador << "/" << denominador << endl; + return 0; +} +int number(int x, int y) { + int sum, ans = 0; + while (x) { + ans += x % y; + x /= y; + } + return ans; +} +int gcd(int a, int b) { + if (a % b == 0) + return b; + else + return gcd(b, a % b); +} +int n, sum, y; +int main() { + cin >> n; + for (int i = 2; i < n; i++) sum += number(n, i); + int a = sum; + int b = n - 2; + int g = gcd(a, b); + a /= g; + b /= g; + cout << a << "/" << b << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int gtr, smlr; + if (m >= n) { + gtr = m; + smlr = n; + } else { + gtr = n; + smlr = m; + } + int util = (gtr / 2 * 2) * (smlr / 2 * 2); + int left = gtr * smlr - util; + int ans = util / 2 + left / 2; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int p = 0; + for (int i = 2; i < n; i++) { + int m = n; + while (m) { + p += m % i; + m /= i; + } + } + int q = n - 2; + int g = __gcd(p, q); + cout << p / g << '/' << q / g << endl; +} +int main() { + int a, x, y, z; + cin >> a; + int s = 0, n = 0, temp; + for (int i = 2; i < a; i++, n++) + for (temp = a; temp; s += temp % i, temp /= i) {} + for (x = s, y = n; y; z = x % y, x = y, y = z) + ; + cout << s / x << "/" << n / x << endl; + return 0; +} +const long long int mod = 998244353; +long long int gcd(long long int a, long long int b) { + if (a == 0) + return b; + else + return gcd(b % a, a); +} +void SieveOfEratosthenes(long long int n) { + bool prime[n + 1]; + memset(prime, true, sizeof(prime)); + for (long long int p = 2; p * p <= n; p++) { + if (prime[p] == true) { + for (int i = p * p; i <= n; i += p) prime[i] = false; + } + } + for (int p = 1; p <= n; p++) + if (prime[p]) cout << p << '\n'; +} +long long int tiles(long long int m, long long int n) { + if (m > n) swap(m, n); + if (m % 2) { + if (m == 1) return n / 2; + return n * (m / 2) + (n / 2); + } else + return n * (m / 2); +} +int main() { + long long int m, n; + cin >> m >> n; + cout << tiles(m, n) << '\n'; + return 0; +} +int convert(int n, int i); +int main() { + int n, i, ans, fin = 0; + cin >> n; + for (i = 2; i <= n - 1; i++) { + ans = convert(n, i); + fin += ans; + } + int g = __gcd(fin, n - 2); + int fin1 = fin / g; + int n1 = (n - 2) / g; + cout << fin1 << "/" << n1 << endl; + ; +} +int convert(int n, int i) { + int c, v, res = 0; + while (n > 0) { + c = n % i; + v = n / i; + res += c; + n = v; + } + return res; +} +int main() { + int a; + cin >> a; + int sum = 0, n = 0; + for (int i = 2; i < a; i++) { + int temp = a; + while (temp) { + sum += temp % i; + temp /= i; + } + n++; + } + int i = 2; + while (i <= n) { + if (sum % i == 0 && n % i == 0) { + sum /= i; + n /= i; + } else + i++; + } + cout << sum << "/" << n << endl; + return 0; +} +int gcd(int n, int m) { + int r; + while (m) { + r = n % m; + n = m; + m = r; + } + return n; +} +int main() { + int n, sum = 0, save; + cin >> n; + for (int i = 2; i < n; i++) { + int temp = n; + while (temp) { + sum = sum + temp % i; + temp = temp / i; + } + } + save = gcd(sum, n - 2); + cout << sum / save << "/" << (n - 2) / save << endl; + return 0; +} +int sum; +int nominator = 0; +int denominator = 0; +int A; +void getDigits(int num, int base) { + while (num > 0) { + nominator += (num % base); + num /= base; + } +} +int nok(int a, int b) { + return b == 0 ? a : nok(b, a % b); +} +int main() { + cin >> A; + for (int i = 2; i <= A - 1; i++) { + getDigits(A, i); + denominator++; + } + int nk = nok(nominator, denominator); + cout << (nominator / nk) << "/" << (denominator / nk) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << (n * m - ((n * m) % 2)) / 2 << endl; + return 0; +} +int gcd(int a, int b) { + if (a < b) swap(a, b); + while (a % b) { + int t = a % b; + a = b; + b = t; + } + return b; +} +int main() { + int n, sum = 0; + cin >> n; + for (int i = 2; i < n; i++) { + int t = n; + while (t) { + sum += t % i; + t /= i; + } + } + int k = gcd(sum, n - 2); + cout << sum / k << "/" << (n - 2) / k << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + cout << (m * n) / 2 << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { cout << n * m / 2 << endl; } + return 0; +} +int main() { + int M, N; + cin >> M >> N; + cout << M * N / 2 << endl; + return 0; +} +int main() { + int M, N; + cin >> M >> N; + cout << M * N / 2 << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + cout << (m * n) / 2 << endl; + return 0; +} +int main() { + int k, d, i; + cin >> k >> d; + if (d == 0) { + if (k == 1) { + cout << 0 << endl; + } else { + cout << "No solution\n"; + } + } else { + cout << d; + for (i = 1; i < k; i++) { cout << 0; } + cout << endl; + } + return 0; +} +int main() { + long long T, k, cont = 0; + cin >> T >> k; + int arr[T]; + for (int i = 0; i < T; i++) { cin >> arr[i]; } + int mod = arr[0] % k, minimun = arr[0]; + for (int i = 1; i < T; i++) { minimun = min(minimun, arr[i]); } + for (int i = 0; i < T; i++) { + if (arr[i] % k != mod) { + cont = -1; + break; + } else { + cont += (arr[i] - minimun) / k; + } + } + cout << cont << endl; + return 0; +} +void READ(string INPUT = "NO", string OUTPUT = "NO") { + if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin); + if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout); +} +vector ans; +long long n; +int k; +void Divs() { + for (int i = 1; i <= n / i; i++) { + if (n % i == 0) { + ans.push_back(i); + if (n / i != i) ans.push_back(n / i); + } + } + sort(ans.begin(), ans.end()); +} +int main() { + cin >> n >> k; + Divs(); + if ((int)ans.size() >= k) { + cout << ans[--k] << "\n"; + } else + cout << -1 << "\n"; + return 0; +} +void dfs(int i, vector G[], vector &B) { + B[i] = 1; + for (int j = 0; j < (int)G[i].size(); j++) { + if (B[G[i][j]] == 2) { dfs(G[i][j], G, B); } + } +} +int main() { + int n; + cin >> n; + vector G[2001]; + vector B(2001, 0); + int x, y; + for (int i = 0; i < n; i++) { + cin >> x >> y; + B[x] = 2; + B[y + 1000] = 2; + G[x].push_back(y + 1000); + G[y + 1000].push_back(x); + } + int connected = 0; + for (int i = 0; i < 2001; i++) { + if (B[i] == 2) { + connected += 1; + dfs(i, G, B); + } + } + cout << connected - 1 << endl; + return 0; +} +int main() { + long long a, n, b, c, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (i == 1) + sum = a; + else { + c = a + b; + if (sum < a) + sum = a; + else if (sum < c) + sum = c; + else + while (sum >= c) { + c = c + b; + if (sum < c) { + sum = c; + break; + } + } + } + } + cout << sum << endl; +} +int main() { + int n; + while (cin >> n) { + long long answ = n; + for (int i = 1, a; i <= n; ++i) { + cin >> a; + answ += (long long)i * (a - 1); + } + cout << answ << endl; + } + return 0; +} +int main() { + int n, a[101], c[101], i, m, k; + while (cin >> n) { + for (i = 0; i < n; i++) cin >> a[i]; + for (k = 0; k < n; k++) { + c[k] = 0; + for (i = 0; i < a[k]; i++) { + cin >> m; + if (i < a[k] - 1) + c[k] = c[k] + m * 5; + else + c[k] = c[k] + m * 5 + a[k] * 15; + } + } + int min = c[0]; + for (i = 1; i < n; i++) { + if (min > c[i]) min = c[i]; + } + cout << min << endl; + } +} +int main() { + int a1, a2, a3, b1, b2, b3, k; + cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> k; + int sum1 = (a1 + a2 + a3 + 4) / 5; + int sum2 = (b1 + b2 + b3 + 9) / 10; + if (sum1 + sum2 <= k) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int day = 1; + int va = v0; + int cnt = v0; + while (va < c) { + cnt = min(v1, cnt + a); + va += cnt - l; + day++; + } + cout << day << endl; + return 0; +} +int main() { + int x, y, z, w; + cin >> x >> y >> z >> w; + if (x > y) + cout << "First" << endl; + else + cout << "Second" << endl; +} +int main() { + int n, k, c = 0; + cin >> n >> k; + int arr[101] = {0}; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + arr[t]++; + } + int max = 0; + for (int i = 1; i <= 100; i++) { + if (arr[i] > max) { max = arr[i]; } + } + for (int i = 1; i <= 100; i++) { + if (arr[i] > 0) { c++; } + } + int d, r; + d = max / k; + if (max % k > 0) { d = d + 1; } + int total = d * k * c; + int stolen = total - n; + cout << stolen << endl; +} +vector pref[27]; +int main() { + int n, k; + string s; + cin >> n >> k >> s; + for (int i = 0; i < k; i++) pref[i].resize(n); + for (int i = 0; i < k; i++) { + pref[i][0] = int(s[0] == (i + 'A')); + for (int j = 1; j < n; j++) pref[i][j] = pref[i][j - 1] + int(s[j] == (i + 'A')); + } + int ans = pref[0][n - 1]; + for (int i = 0; i < k; i++) ans = min(ans, pref[i][n - 1]); + ans *= k; + cout << ans << '\n'; +} +int main() { + int n, k, hash[26] = {}; + cin >> n >> k; + string s; + cin >> s; + for (int i = 0; i < n; ++i) ++hash[s[i] - 'A']; + int m = hash[0]; + for (int i = 1; i < k; ++i) m = min(m, hash[i]); + cout << m * k << endl; +} +int d[1005]; +int s[1005]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> d[i]; + for (int i = 1; i <= n; i++) cin >> s[i]; + int now = 0, ans = 0, mx = 0; + for (int i = 1; i <= n; i++) { + now += s[i]; + mx = max(mx, s[i]); + int need = d[i]; + if (now < need) { + int dif = need - now; + int fill = dif / mx + (dif % mx ? 1 : 0); + ans += fill * k; + now += fill * mx; + } + ans += d[i]; + now -= d[i]; + } + cout << ans << "\n"; + return 0; +} +int ceil2(int x) { + return x % 2 ? x / 2 + 1 : x / 2; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = ceil2(n); i <= n; i++) + if (i % m == 0) { + cout << i << endl; + return 0; + } + cout << -1 << endl; + return 0; +} +int main() { + int n, m, k, ans1 = 1, ans2 = 1; + cin >> n >> m >> k; + while (k > 2 * m) k -= 2 * m, ans1++; + while (k > 2) k -= 2, ans2++; + cout << ans1 << " " << ans2 << " "; + if (k % 2) + cout << "L\n"; + else + cout << "R\n"; +} +int main() { + int a, b; + int n; + int tmp; + a = b = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> tmp; + if (tmp == 1) { + ++a; + } else { + ++b; + } + } + int cost = min(a, b); + cout << cost + (a - cost) / 3 << endl; + return 0; +} +int main() { + int m, k; + int d[1001], s[1001]; + cin >> m >> k; + for (int i = 1; i <= m; i++) cin >> d[i]; + for (int i = 1; i <= m; i++) cin >> s[i]; + int ti = 0, ex = 0, maxn = 0; + for (int i = 1; i <= m; i++) { + ex += s[i]; + if (s[i] > maxn) maxn = s[i]; + ti += d[i]; + if (d[i] > ex) { + ti += k * ((d[i] - ex - 1) / maxn + 1); + ex += ((d[i] - ex - 1) / maxn + 1) * maxn; + } + ex -= d[i]; + } + cout << ti << endl; + return 0; +} +int a[100005]; +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < k; i++) { + int tmp; + cin >> tmp; + cin >> a[0]; + if (a[0] == 1) { + for (int j = 1; j < tmp; j++) { + cin >> a[j]; + if (a[j] != j + 1) ans += 2; + } + continue; + } + if (tmp == 1) { + ans++; + continue; + } + for (int j = 1; j < tmp; j++) { cin >> a[j]; } + ans += tmp - 1; + ans += tmp; + } + cout << ans << endl; + return 0; +} +int main() { + long long a[4], ans = 0, i; + for (i = 0; i < 4; i++) { cin >> a[i]; } + if (a[0] == a[1]) a[1] = 0; + if (a[0] == a[2]) a[2] = -1; + if (a[0] == a[3]) a[3] = -2; + if (a[1] == a[2]) a[2] = -3; + if (a[1] == a[3]) a[3] = -4; + if (a[2] == a[3]) a[3] = -5; + for (i = 0; i < 4; i++) + if (a[i] <= 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + int a; + string s; + cin >> s; + int ans = 0; + cin >> a; + while (a--) { + char b, c; + cin >> b >> c; + int bb, cc; + bb = 0; + cc = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == b) + bb++; + else if (s[i] == c) + cc++; + else { + ans += min(bb, cc); + bb = cc = 0; + } + } + ans += min(bb, cc); + } + cout << ans << endl; + return 0; +} +int main() { + int n, i, a[100000], b[100000]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n - 1; i++) { b[i] = a[i] + a[i + 1]; } + b[n - 1] = a[n - 1]; + for (i = 0; i < n - 1; i++) { cout << b[i] << " "; } + cout << b[n - 1] << endl; + return 0; +} +int main() { + int n, r, u, c = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + r = 0; + u = 0; + for (int j = i; j < n; j++) { + if (s[j] == 'R') r++; + if (s[j] == 'L') r--; + if (s[j] == 'U') u++; + if (s[j] == 'D') u--; + if (r == 0 && u == 0) c++; + } + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + pair h[60]; + int p, m, a, b, c, d, e; + int max = -10000000000000000; + for (int i = 0; i < n; i++) { + cin >> h[i].first >> p >> m >> a >> b >> c >> d >> e; + int s = ((p * 100) - (m * 50) + a + b + c + d + e); + h[i].second = s; + if (s > max) max = s; + } + for (int i = 0; i < n; i++) + if (h[i].second == max) { + cout << h[i].first << endl; + break; + } + return 0; +} +int main() { + long long n, sum = 0, min1 = 99999999999, count1, x; + while (cin >> n) { + for (int i = 0; i < n; i++) { + cin >> x; + sum += x; + if (x % 2 == 1) { + count1++; + if (x < min1) { min1 = x; } + } + } + if (count1 % 2 == 1) { sum -= min1; } + cout << sum << endl; + } +} +int main() { + int a, b, c, res = 0; + cin >> a >> b >> c; + while (a >= 1) { + if (a * 2 <= b && a * 4 <= c) { + res = a + (a * 2) + (a * 4); + break; + } else + a = a - 1; + } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int l, r, d; + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else + cout << (r / d + 1) * d << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 1) { + cout << -1 << endl; + } else { + cout << "2 1"; + for (int i = 3; i < n; i += 2) { cout << " " << i + 1 << " " << i; } + cout << endl; + } + return 0; +} +int main() { + int cns = 0, cnt = 0x3f3f3f3f; + int n, strength[100001]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> strength[i]; + if (strength[i] > cns) cns = strength[i]; + if (strength[i] < cnt) cnt = strength[i]; + } + int vis = 0; + for (int i = 0; i < n; i++) + if (strength[i] == cns || strength[i] == cnt) vis++; + cout << n - vis << endl; + return 0; +} +int main() { + int n, cnt(0); + string s; + cin >> n >> s; + for (int i = 1; i < (int)s.size(); i++) + if (i % n == 0 && i >= 3 && s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) cnt++; + cout << cnt << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n >= 1) { + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + } + return 0; +} +int main() { + int n, m, a, b, rub = 0; + cin >> n >> m >> a >> b; + while (n > 0) { + if (n < m) { + int flag = n * a; + if (flag < b) { + rub += flag; + n = 0; + } else { + rub += b; + n -= m; + } + } else if ((a * m) > b) { + n -= m; + rub += b; + } else { + rub += n * a; + n = 0; + } + } + cout << rub << "\n"; +} +int main() { + long long int a, b, c, min, r; + cin >> a >> b >> c; + min = a; + if (b / 2 < min) { min = b / 2; } + if (c / 4 < min) { min = c / 4; } + r = min * 1 + min * 2 + min * 4; + cout << r << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + int a, b, c, d, e, f; + cin >> a >> b >> c; + a = a + b + c; + cin >> d >> e >> f; + b = d + e + f; + cin >> n; + if (a % 5 == 0) + a /= 5; + else + a = a / 5 + 1; + if (b % 10 == 0) + b /= 10; + else + b = b / 10 + 1; + if (a + b > n) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int x1, x2, y1, y2; + int diff1, diff2; + cin >> x1 >> y1; + cin >> x2 >> y2; + diff1 = abs(x2 - x1); + diff2 = abs(y2 - y1); + if (diff1 > diff2) { + cout << diff1 << endl; + } else if (diff2 > diff1) { + cout << diff2 << endl; + } else if (diff1 == diff2) { + cout << diff1 << endl; + } +} +int main() { + int c, v, v1, a, l; + cin >> c >> v >> v1 >> a >> l; + int x = 0, f = 0; + while (x < c) { + if (f) x -= l; + x += min(v, v1); + v += a; + f++; + } + cout << f << endl; + return 0; +} +int n; +string s; +int d = 0; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s[0] == '+' || s[1] == '+') + d = d + 1; + else if (s[0] == '-' || s[1] == '-') + d = d - 1; + } + cout << d << endl; + return 0; +} +int N; +string S; +int main() { + cin >> N >> S; + sort(S.begin(), S.end()); + cout << S << '\n'; + return 0; +} +int main() { + int k; + cin >> k; + string str[6]; + str[0] = "+------------------------+"; + str[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + str[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + str[3] = "|#.......................|"; + str[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + str[5] = "+------------------------+"; + for (int j = 1; j < 23; j += 2) { + for (int i = 1; i < 5; i++) { + if (k > 0) { + if (i == 3 && j != 1) continue; + str[i][j] = 'O', k--; + } + } + } + for (int i = 0; i < 6; i++) { cout << str[i] << endl; } + return 0; +} +int main() { + char a[500]; + int n, i, j, u, d, r, l, sum; + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sum = 0; + for (i = 1; i <= n; i++) { + d = u = l = r = 0; + for (j = i; j <= n; j++) { + if (a[j] == 'R') { r++; } + if (a[j] == 'L') { l++; } + if (a[j] == 'D') { d++; } + if (a[j] == 'U') { u++; } + if (u == d && l == r) { sum++; } + } + } + cout << sum << endl; +} +int main() { + string input, output; + int max; + max = 0; + cin >> input; + for (int i = input.length() - 1; i >= 0; i--) { + if (input[i] >= max) { + output = input[i] + output; + max = input[i]; + } + } + cout << output << endl; +} +int main() { + int l, a, p, count1 = 0; + ; + cin >> l >> a >> p; + while (l && a && p) { + if (p - 4 >= 0) { + p -= 4; + if (a - 2 >= 0) { + a -= 2; + l--; + count1 += 7; + } else + a = 0; + } else + p = 0; + } + cout << count1 << "\n"; +} +int main() { + string N; + cin >> N; + if (N[0] >= 'a' && N[0] <= 'z') { N[0] = N[0] - 32; } + cout << N << endl; + return 0; +} +int main() { + int a[6], n; + cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> n; + int r = (a[0] + a[1] + a[2] + 4) / 5; + r += (a[3] + a[4] + a[5] + 9) / 10; + cout << (r <= n ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n, m, a, b, r, d, cost = 0; + cin >> n >> m >> a >> b; + r = n % m; + d = n / m; + if (m > n) { + if (b < a * n) { + cout << b << endl; + return 0; + } else { + cout << a * n << endl; + return 0; + } + } + if (d * b < a * (n - r)) { + cost += (d * b); + if (r * a < b) { + cost += (r * a); + } else { + cost += b; + } + } else { + cost += (a * n); + } + cout << cost << endl; + return 0; +} +const long long MOD = 1000000007LL, INF = 1e9, LINF = 1e18; +long long GT(int x) { + return (x <= 1) ? 1 : x * GT(x - 1); +} +long long tohop(long long n, long long k) { + long long c = 1; + for (long long i = 1; i <= k; i++, n--) c = c * n / i; + return c; +} +bool isPrime(int n) { + for (int i = 2; i * i <= n; ++i) { + if (n % i == 0) { return false; } + } + return true; +} +long long BSearch(long long a[], long long n, long long x) { + long long l = 1; + long long r = n; + long long mid; + while (l <= r) { + mid = (l + r) / 2; + if (x == a[mid]) + return mid; + else if (x < a[mid]) + r = mid--; + else if (x > a[mid]) + l = mid++; + } + return -1; +} +int save[25]; +void solve() { + string s; + getline(cin, s); + for (int i = 0; i < s.length(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { save[s[i] - 'a']++; } + } + long long ans = 0; + for (int i = 0; i < 26; i++) + if (save[i]) ans++; + cout << ans << endl; + return; +} +int main() { + solve(); + return 0; +} +void Fast_Read_Out() {} +void Random() { + unsigned long long seed; + asm("rdtsc" : "=A"(seed)); + srand(seed); +} +unsigned long long Time() { + unsigned long long time = clock() / 1000.00; + return time; +} +const long long inf = (1e9) + 123; +long long a[101]; +long long dp[101]; +int main() { + Random(); + Fast_Read_Out(); + long long n; + cin >> n; + for (long long i = 1; i <= n; i++) cin >> a[i]; + for (long long i = 1; i <= n; i++) dp[i] = (a[i] - 1) * i + 1; + long long sum = 0; + for (long long i = 1; i <= n; i++) sum += dp[i]; + cout << sum << endl; +} +long long sum[100004]; +int main() { + int a, b; + cin >> a >> b; + cout << a + b - 1 << endl; + for (int g = 1; g <= b; g++) { cout << 1 << ' ' << g << endl; } + for (int g = 2; g <= a; g++) { cout << g << ' ' << 1 << endl; } +} +int main() { + long long n, m, k; + cin >> n >> m >> k; + long long x, y; + char z; + if (k % (2 * m) == 0) { + x = k / (2 * m); + y = m; + } else { + x = (long long)k / (2 * m) + 1; + if ((k - 2 * m * (x - 1)) % 2) + y = (long long)(k - 2 * m * (x - 1)) / 2 + 1; + else + y = (long long)(k - 2 * m * (x - 1)) / 2; + } + if (k % 2) + z = 'L'; + else + z = 'R'; + cout << x << " " << y << " " << z << "\n"; + return 0; +} +int main() { + vector v(6); + for (int i = 0; i < 6; i++) cin >> v[i]; + int suma = 0; + int minA = min(v[1], v[5]); + int maxA = max(v[1], v[5]); + int inicial = v[0] * 2 + 1; + for (int i = 0; i < minA; i++) { + suma += inicial; + inicial += 2; + } + if (maxA != minA) inicial--; + for (int i = minA; i < maxA; i++) { suma += inicial; } + minA = min(v[2], v[4]); + maxA = max(v[2], v[4]); + inicial = v[3] * 2 + 1; + for (int i = 0; i < minA; i++) { + suma += inicial; + inicial += 2; + } + if (maxA != minA) inicial--; + if (v[1] == v[5]) { + for (int i = minA; i < maxA; i++) { suma += inicial; } + } + cout << suma << endl; + return 0; +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (d == 0 && k > 1) { + cout << "No solution\n"; + return 0; + } + cout << d; + k--; + while (k--) cout << 0; + cout << endl; +} +int main() { + string x; + cin >> x; + int v = 0, h = 0; + for (int i = 0; i < x.size(); i++) { + if (x[i] == '0') { + if (!v) + cout << 1 << ' ' << 1 << endl, v++; + else + cout << 3 << ' ' << 1 << endl, v = 0; + } else { + if (!h) + cout << 4 << ' ' << 3 << endl, h++; + else + cout << 4 << ' ' << 1 << endl, h = 0; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int d = m; d <= n; d += m) { + int k = d * 2; + if (k >= n) return cout << d << endl, 0; + } + cout << -1 << endl; +} +int main() { + int a, b, c, d = 0x3f3f3f3f; + int e, f, g; + while (cin >> a >> b >> c) { + e = a; + f = b / 2; + g = c / 4; + if (e < d) d = e; + if (f < d) d = f; + if (g < d) d = g; + cout << d * 7 << endl; + } + return 0; +} +int num[225]; +int main() { + int n, m, i, j, k; + cin >> n >> k; + num['a'] = k; + for (i = 1; i < k; i++) num['a' + i]++; + if (k > n) + cout << -1 << endl; + else if (n == 1) + cout << 'a' << endl; + else if (k == 1 && n > 1) { + cout << -1 << endl; + } else { + int f = 1; + for (i = 1; i <= n - (k - 2); i++) { + if (i % 2) + cout << 'a'; + else + cout << 'b'; + } + for (i = 1; i <= k - 2; i++) { cout << (char)('b' + i); } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1" << endl; + return 0; + } + if (n == 2) { + cout << "3" << endl; + return 0; + } + if (n == 3) { + cout << "5" << endl; + return 0; + } + if (n % 4 == 0) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 1) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 2) { + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 3) { + n--; + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + return 0; +} +char bit[2]; +int x = 0; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j <= 2; j++) { cin >> bit[j]; } + if (bit[1] == '+') + ++x; + else if (bit[1] == '-') + --x; + } + cout << x << endl; + return 0; +} +int main() { + int A, B, C, D; + cin >> A >> B >> C >> D; + if ((A * 2 + 3 > D && D + 1 >= A) || (B * 2 + 3 > C && C + 1 >= B)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int n; +char a[105]; +char b[105]; +int main() { + cin >> n; + cin >> a; + int f = 0; + int c = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 'o' && a[i + 1] == 'g' && a[i + 2] == 'o') { + f = 1; + b[c] = b[c + 1] = b[c + 2] = '*'; + c += 3; + i += 3; + while (f && i <= n - 2) { + if (a[i] == 'g' && a[i + 1] == 'o') { + i += 2; + } else { + f = 0; + } + } + i--; + } else { + b[c] = a[i]; + c++; + } + } + cout << b << endl; +} +int main() { + set sets; + int temp; + int i = 4; + while (i--) { + cin >> temp; + sets.insert(temp); + } + cout << 4 - sets.size() << endl; + return 0; +} +int main() { + int l, r, n, k; + cin >> k; + for (int i = 0; i < k; i++) { + cin >> l >> r; + cout << l << ' ' << r - (r % l) << endl; + } +} +int main() { + int i, k, l, m, n, d, p; + cin >> k >> l >> m >> n >> d; + p = d; + for (i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) p--; + } + cout << d - p << endl; +} +int main() { + int n, m; + string st; + cin >> n >> m; + int res[m]; + for (int i = 0; i < m; i++) { res[i] = 0; } + for (int i = 0; i < n; i++) { + cin >> st; + if (st.find('1') == string::npos) { + cout << -1 << endl; + return 0; + } + int cur[3 * m]; + int curAns[m]; + for (int j = 0; j < 3 * m; j++) { cur[j] = st[j % m] - '0'; } + int counter = 0; + for (int a = m - 1; a >= 0; a--) { + if (cur[a] == 1) + break; + else + counter++; + } + for (int k = m; k < 2 * m; k++) { + if (cur[k] == 1) { + curAns[k % m] = 0; + counter = 0; + } else + curAns[k % m] = ++counter; + } + counter = 0; + for (int a = 2 * m; a < 3 * m; a++) { + if (cur[a] == 1) + break; + else + counter++; + } + for (int k = 2 * m - 1; k >= m; k--) { + if (cur[k] == 1) { + curAns[k % m] = 0; + counter = 0; + } else { + counter++; + curAns[k % m] = min(curAns[k % m], counter); + } + } + for (int j = 0; j < m; j++) { res[j] += curAns[j]; } + } + int min = INT_MAX; + for (int i = 0; i < m; i++) { + if (min > res[i]) min = res[i]; + } + cout << min << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + string s; + cin >> s; + int p = 0; + int ans = 0; + while (p < n - 1) { + ans++; + int last = p; + p = min(p + d, n - 1); + while (s[p] == '0') p--; + if (p == last) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; +} +int main() { + int a, b; + bool cek = 0; + cin >> a >> b; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= b; j++) { + char c; + cin >> c; + if (c != 'B' && c != 'W' && c != 'G') { cek = 1; } + } + } + if (cek == 1) { + cout << "#Color" << endl; + } else { + cout << "#Black&White" << endl; + } +} +int main() { + int y, b, r; + while (cin >> y >> b >> r) { + for (int i = r; i >= 3; i--) { + if (b >= (i - 1) && y >= (i - 2)) { + cout << i + i - 1 + i - 2 << endl; + break; + } + } + } + return 0; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int n, data[100]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> data[i]; } + for (int i = 0; i < n; i++) { + int count = 0; + while (data[i] > 0) { + data[i] -= 7; + count++; + } + cout << count << endl; + } + char c; + cin >> c; + return 0; +} +int main() { + int n, i, ans = 0; + string s; + cin >> n; + for (i = 0; i < n; i++) { + cin >> s; + if (s[1] == '+') + ans++; + else + ans--; + } + cout << ans << endl; + return 0; +} +const int M = 100000 + 10; +char ans[M]; +int main() { + string s; + cin >> s; + int id = 0; + int slen = s.length(); + int sid = 0; + int eid = 0; + for (int j = 25; j >= 0; j--) { + for (int i = sid; i < slen; i++) { + if (s[i] == 'a' + j) { + ans[id++] = 'a' + j; + eid = i; + } + } + if (eid == sid) { + eid = sid; + } else { + sid = eid + 1; + } + } + for (int i = 0; i < id; i++) { cout << ans[i]; } + cout << endl; + return 0; +} +int main() { + int n, k; + int uts[101] = { + 0, + }; + int freq[101] = { + 0, + }; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> uts[i]; + sort(uts, uts + n); + int kind = 1; + for (int i = 0; i < n; i++) { + if (uts[i + 1] == uts[i]) + freq[kind]++; + else { + freq[kind]++; + kind++; + } + } + kind--; + int maxcount = 0; + for (int i = 1; i <= kind; i++) { + if (maxcount < freq[i]) maxcount = freq[i]; + } + int ans = 0; + int temp = 0; + temp = maxcount; + while (temp % k != 0) { temp++; } + for (int i = 1; i <= kind; i++) ans += temp - freq[i]; + cout << ans << endl; +} +bool l, r; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '0' && l) { + cout << "3 1" << endl; + l = false; + } else if (s[i] == '0') { + cout << "1 1" << endl; + l = true; + } else if (s[i] == '1' && r) { + cout << "4 1" << endl; + r = false; + } else { + cout << "4 3" << endl; + r = true; + } + } + return 0; +} +int main() { + int i, j, m, n, cnt = 0, tmp = 0; + int sum = 0, temp = 0, h1 = 0, h2 = 0; + char a[101][101]; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (i = 0; i < n; i++) { + cnt = 0; + for (j = 0; j < m; j++) { + if (a[i][j] != 'S') cnt++; + } + if (cnt == m) { + h1++; + tmp += cnt; + } + } + for (i = 0; i < m; i++) { + sum = 0; + for (j = 0; j < n; j++) { + if (a[j][i] != 'S') sum++; + } + if (sum == n) { + h2++; + temp += sum; + } + } + cout << (tmp + temp) - (h1 * h2) << endl; + return 0; +} +bool rr[10]; +bool cc[10]; +int main() { + int r, c; + char a; + int i, j; + int cnt[3] = {0, 0, 0}; + while (cin >> r >> c) { + for (i = 0; i < 10; i++) { + rr[i] = true; + cc[i] = true; + } + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cin >> a; + if (a == 'S') { + rr[i] = false; + cc[j] = false; + } + } + } + cnt[2] = c * r; + for (i = 0; i < r; i++) { + if (!rr[i]) cnt[0]++; + } + for (i = 0; i < c; i++) { + if (!cc[i]) cnt[1]++; + } + cout << cnt[2] - cnt[0] * cnt[1] << endl; + } + return 0; +} +int main() { + long long n, m, green, blue, yellow, foo, foobar; + cin >> n >> m >> yellow >> green >> blue; + foobar = (blue * 3) + (green); + foo = (yellow * 2) + (green); + cout << max(0LL, foobar - m) + max(0LL, foo - n) << endl; +} +int main() { + int n, m, cnt = 0; + bool row[12] = {}, col[12] = {}; + char c; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> c; + if (c == 'S') row[i] = col[j] = 1; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (!(row[i] && col[j])) cnt++; + } + } + cout << cnt << '\n'; +} +int main() { + long long n, M, M2, s = 0; + long long t[100005]; + long long t2[100005]; + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> t[i]; + s += t[i]; + } + for (long long i = 0; i < n; i++) { cin >> t2[i]; } + sort(t2, t2 + n); + if (s <= t2[n - 1] + t2[n - 2]) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, c, d; + while (cin >> a >> b >> c >> d) { + int ans = 0; + if (a == b || a == c || a == d) ans++; + if (b == c || b == d) ans++; + if (c == d) ans++; + cout << ans << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + string s; + cin >> s; + for (long long int i = 0; i < n - 1; i++) { + if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) s.replace(i, 2, "D"); + } + cout << s.length() << endl; + return 0; +} +int main() { + int n, counter = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + counter += x; + } + int res = 5; + for (int i = 1; i <= 5; i++) { + if ((counter + i) % (n + 1) == 1) res--; + } + cout << res << endl; + return 0; +} +int x, y, t; +int main() { + cin >> x >> y; + while (true) { + if (t % 2 == 1) { + if (y >= 22) { + y -= 22; + } else if (y >= 12 && x >= 1) { + y -= 12; + x -= 1; + } else if (y >= 2 && x >= 2) { + y -= 2; + x -= 2; + } else { + cout << "Ciel" << endl; + return 0; + } + } else { + if (x >= 2 && y >= 2) { + x -= 2; + y -= 2; + } else if (x == 1 && y >= 12) { + x -= 1; + y -= 12; + } else if (y >= 22) { + y -= 22; + } else { + cout << "Hanako" << endl; + return 0; + } + } + if (t == 1) + t = 2; + else + t = 1; + } +} +int main() { + int n, s, d, prev = 0, i = 0; + cin >> n; + while (n--) { + cin >> s >> d; + i = 0; + while (true) { + if ((s + (d * i)) > prev) { + prev = s + (d * i); + break; + } + i++; + } + } + cout << prev << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int he[4]; + int max; + he[0] = a + b + c; + he[1] = a * (b + c); + he[2] = (a + b) * c; + he[3] = a * b * c; + max = 0; + for (int i = 0; i < 4; i++) { + if (he[i] >= max) { max = he[i]; } + } + cout << max << endl; + return 0; +} +int n, m, k; +bool debug = false; +int main() { + int x, y; + cin >> x >> y; + while (x >= 2 && y >= 24) { + x -= 2; + y -= 24; + } + int i = 0; + while (true) { + int sum = 0; + if (i == 0) { + int mx = min(x, 2); + x -= mx; + sum += 100 * mx; + int my = (220 - sum) / 10; + if (my > y) { + puts("Hanako"); + return 0; + } + y -= my; + } else { + int my = 0; + if (y >= 22) + my = 22; + else if (y >= 12 && x >= 1) + my = 12; + else if (y >= 2 && x >= 2) + my = 2; + else { + puts("Ciel"); + return 0; + } + y -= my; + sum += 10 * my; + int mx = (220 - sum) / 100; + if (mx > x) { + puts("Ciel"); + return 0; + } + x -= mx; + } + i = 1 - i; + } + return 0; +} +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') r[i] = c[j] = 1; + } + int ans = n * m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + if (r[i] && c[j]) ans--; + cout << ans << endl; + } + return 0; +} +int main() { + int n; + char s[101]; + cin >> n; + cin >> s; + int count = 0; + for (int i = 0; i < n; i++) { + if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) i++; + count++; + } + cout << count << endl; +} +void solve() { + vector ret; + long long n, k, counts = 0; + cin >> n >> k; + getchar(); + long long limit = (long long)(sqrt((double)n)) + 1; + for (int i = 1; i <= limit; i++) { + if (n % i == 0) { + ret.push_back(i); + counts++; + if (counts == k) { + cout << i << endl; + return; + } + } + } + if (ret.back() * ret.back() == n) { + if (counts * 2 - 1 < k) { + cout << "-1" << endl; + return; + } + cout << n / (ret[counts * 2 - k - 1]) << endl; + return; + } else { + if (ret[counts - 1] * ret[counts - 2] != n) { counts++; } + if (counts * 2 - 2 < k) { + cout << -1 << endl; + return; + } + cout << n / (ret[counts * 2 - k - 2]) << endl; + return; + } + return; +} +int main() { + solve(); + return 0; +} +int main() { + int n, k, sig = 0; + string s; + cin >> n >> k; + if (k == 1 && n > 1) + cout << "-1\n"; + else if (k > n) + cout << "-1\n"; + else if (n == 1 && k == 1) + cout << "a\n"; + else { + int i, j = n - k + 1; + if ((j & 1) == 0) { j--, sig = 1; } + for (i = 0; i <= j; i += 2) s += "ab"; + if (sig) { s += "a", i = j + 2; } + char c = 'b'; + for (; i < n; i++) s += (char)(c + 1), c = s[i]; + cout << s << endl; + } + return 0; +} +int main() { + int Time(0), Blue, Green, Red; + cin >> Blue; + cin >> Green; + cin >> Red; + for (int i(0); (Blue + Red + Green) > 0; i++) { + if (i > 0) { Time++; } + Blue -= 2; + if (Blue < 0) { Blue = 0; } + if ((Blue + Red + Green) <= 0) { break; } + Time++; + Green -= 2; + if (Green < 0) { Green = 0; } + if ((Blue + Red + Green) <= 0) { break; } + Time++; + Red -= 2; + if (Red < 0) { Red = 0; } + } + Time += 30; + cout << Time << endl; +} +int main() { + int a, b; + int n; + int tmp; + a = b = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> tmp; + if (tmp == 1) { + ++a; + } else { + ++b; + } + } + int cost = min(a, b); + cout << cost + (a - cost) / 3 << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + while (cin >> c >> v0 >> v1 >> a >> l) { + int sum = 0; + int add = 0; + int count = 1; + if (v0 < v1) { + sum += v0; + add = v0; + } else { + sum += v1; + add = v1; + } + if (sum >= c) { + cout << "1" << endl; + continue; + } else { + while (sum < c) { + count++; + sum -= l; + if (sum < 0) sum = 0; + add += a; + if (add > v1) { add = v1; } + sum += add; + if (sum >= c) { + cout << count << endl; + continue; + } + } + } + } + return 0; +} +int main() { + int b, g; + cin >> b >> g; + int i, j; + int bv[b], gv[g]; + for (i = 0; i < b; i++) bv[i] = 0; + for (i = 0; i < g; i++) gv[i] = 0; + int ctr = 0; + for (i = 0; i < b; i++) { + for (j = 0; j < g; j++) { + if (bv[i] == 0 || gv[j] == 0) { + ctr++; + bv[i] = 1; + gv[j] = 1; + } + } + } + for (i = 0; i < b; i++) bv[i] = 0; + for (i = 0; i < g; i++) gv[i] = 0; + cout << ctr << endl; + for (i = 0; i < b; i++) { + for (j = 0; j < g; j++) { + if (bv[i] == 0 || gv[j] == 0) { + cout << i + 1 << " " << j + 1 << endl; + bv[i] = 1; + gv[j] = 1; + } + } + } + return 0; +} +const int INF = 1000000000; +int main() { + int a, cups = 0, medals = 0, n, s; + for (int i = 0; i < 3; i++) { + cin >> a; + cups += a; + } + for (int i = 0; i < 3; i++) { + cin >> a; + medals += a; + } + cin >> n; + cups = (cups % 5 == 0 ? cups / 5 : cups / 5 + 1); + medals = (medals % 10 == 0 ? medals / 10 : medals / 10 + 1); + s = cups + medals; + if (s > n) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + while (n--) { + int a; + cin >> a; + if (a == 1) { + cout << "HARD\n"; + return 0; + } + } + cout << "EASY\n"; + return 0; +} +int main() { + string s; + cin >> s; + bool f = true; + bool e = true; + for (int i = 0; i < s.size(); i++) { + if (s[i] != s[s.size() - 1 - i]) f = false; + } + for (int i = 0; i < s.size() - 1; i++) { e = e && (s[i] == s[i + 1]); } + if (e) + cout << 0 << endl; + else if (f) + cout << s.size() - 1 << endl; + else + cout << s.size() << endl; + return 0; +} +int n, m; +int ans[110]; +char tmp; +int main() { + cin >> n >> m; + memset(ans, 0x3f, sizeof ans); + ans[1] = 0; + for (int i = 1; i <= n; i++) { + cin >> tmp; + if (tmp == '0') continue; + for (int j = m; j >= 1; j--) + if (i - j >= 1) ans[i] = min(ans[i], ans[i - j] + 1); + } + if (ans[n] != 0x3f3f3f3f) + cout << ans[n] << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + string str; + cin >> str; + int len = str.length(); + int k; + cin >> k; + int ans = 0; + while (k--) { + string ch; + cin >> ch; + int n1 = 0, n2 = 0; + for (int i = 0; i < len; i++) { + if (str[i] == ch[0]) + n1++; + else if (str[i] == ch[1]) + n2++; + else { + ans += min(n1, n2); + n1 = n2 = 0; + } + } + ans += min(n1, n2); + } + cout << ans << endl; +} +int n, m; +int main() { + cin >> n >> m; + while (m % 2 == 0) { m /= 2; } + if (n % m == 0) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } +} +int main() { + int res = 0, n; + cin >> n; + if (n & 1) + cout << "Ehab" << '\n'; + else + cout << "Mahmoud" << '\n'; + return 0; +} +int main() { + int num, a, b, c, d, tick = 0; + cin >> a >> b >> c >> d >> num; + int i; + for (i = 1; i <= num; i++) { + if (!(i % a) || !(i % b) || !(i % c) || !(i % d)) tick++; + } + cout << tick << endl; + return 0; +} +int main() { + int b, y, r; + cin >> r >> y >> b; + int arr[3] = {r, y - 1, b - 2}; + int min = 200; + for (int i = 0; i < 3; i++) { + if (min > arr[i]) { min = arr[i]; } + } + cout << 3 * min + 3 << endl; +} +int isPrime(int n); +int i; +int main() { + long int n, a, b; + cin >> n; + a = 4; + b = n - 4; + for (i = 1; i <= n; i++) { + int m = isPrime(a); + int n = isPrime(b); + if (n == 1 && m == 1) { + cout << a << " " << b << endl; + return 0; + } + a++; + b--; + } +} +int isPrime(int k) { + for (i = 2; i < k; i = i + 1) { + if (k % i == 0) { return 1; } + } + return 0; +} +int a[100005]; +map mp; +int main() { + int n, m, k, x, ans = 0; + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> k; + mp[i] = k; + for (int j = 0; j < k; j++) { + cin >> x; + a[x] = i; + } + } + x = 0; + bool f = 1; + for (int i = 1, c = 0; c < n; i++) { + if (a[i]) { + if (c == 0) { x = i; } + if (a[x] != a[i]) f = 0; + if (f) + ans = ans; + else if (mp[a[i]] == 1) { + ans++; + } else { + ans += 2; + mp[a[i]]--; + } + c++; + } + } + cout << ans << endl; +} +long long read() { + long long x = 0; + char f = 1, ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +void write(long long x) { + if (x < 0) x = -x, putchar('-'); + if (x > 9) write(x / 10); + putchar(x % 10 + '0'); +} +inline void writeln(long long x) { + write(x); + puts(""); +} +const int N = 6100, M = 4610000; +int n; +int ind[N], ver[N], nxt[N], head[N], en; +void add(int x, int y) { + ver[++en] = y; + nxt[en] = head[x]; + head[x] = en; + ++ind[y]; +} +int d[N], ans; +int main() { + n = read(); + queue q; + for (int i = 1; i <= n; ++i) { + int x = read(); + if (x == -1) + q.push(i), d[i] = 1; + else + add(x, i); + } + ans = 1; + while (!q.empty()) { + int x = q.front(); + q.pop(); + for (int i = head[x]; i; i = nxt[i]) { + int y = ver[i]; + if (d[y]) continue; + d[y] = d[x] + 1; + ans = max(ans, d[y]); + q.push(y); + } + } + writeln(ans); + return 0; +} +int main() { + long long a, b, c, x, y, z; + cin >> a >> b >> c >> x >> y >> z; + double k = ceil((a + b + c) / 5.00); + double l = ceil((x + y + z) / 10.00); + double j = k + l; + long long n; + cin >> n; + if (j > n) { + cout << "NO" << endl; + } else if (j <= n) { + cout << "YES" << endl; + } +} +const int N = 4e7; +int p[N]; +int main() { + long long n, k; + cin >> n >> k; + int index = 0; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) p[++index] = i; + } + bool is_square = (long long)p[index] * (long long)p[index] == n; + int cnt = index * 2 - is_square; + if (k <= index) + cout << p[k] << endl; + else if (k > cnt) + cout << -1 << endl; + else + cout << n / p[2 * index - k + !is_square] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n < m) { + cout << -1 << endl; + } else { + cout << ((n + 2 * m - 1) / (2 * m)) * m << endl; + } + return 0; +} +long long int n, cnt; +int main() { + cin >> n; + long long int A[n], B[n]; + for (int i = 0; i < n; i++) { + cin >> A[i]; + B[i] = A[i]; + } + sort(B, B + n); + for (int i = 0; i < n; i++) + if (A[i] != B[i]) cnt++; + (cnt <= 2) ? cout << "YES\n" : cout << "NO\n"; + return 0; +} +int main() { + long long yc, bc, yb, gb, bb; + cin >> yc >> bc; + cin >> yb >> gb >> bb; + long long yelo, blu; + yelo = yb * 2 + gb; + blu = 3 * bb + gb; + yelo = yelo - yc; + blu = blu - bc; + if (yelo >= 0 && blu >= 0) { + cout << yelo + blu << endl; + } else if (yelo < 0 && blu >= 0) { + cout << blu << endl; + } else if (yelo >= 0 && blu < 0) { + cout << yelo << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + b = b / 2; + c = c / 4; + cout << min(a, min(b, c)) * 7 << endl; +} +int main() { + double n; + int a, ans = -1; + cin >> n >> a; + bool f = false; + int k = ceil(double(n / 2)); + for (int i = k; k <= n; k++) { + if (k % a == 0) { + ans = k; + break; + } + } + cout << ans << endl; +} +char a[100000]; +int main() { + int n, sum1 = 0, sum2 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'A') + sum1++; + else + sum2++; + } + if (sum1 > sum2) + cout << "Anton" << endl; + else if (sum1 < sum2) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +int main() { + string x, q; + cin >> x; + int t = 1; + q = x; +h: + q.push_back(q.at(0)); + q.erase(0, 1); + while (q != x) { + t++; + goto h; + } + cout << t << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + long long len = s.size(); + long long coun = 0; + for (long long i = 0; i < len; i++) { + long long coun1 = 0, coun2 = 0; + for (long long j = i; j < len; j++) { + if (s[j] == 'U') + coun1++; + else if (s[j] == 'R') + coun2++; + else if (s[j] == 'D') + coun1--; + else if (s[j] == 'L') + coun2--; + if (coun1 == 0 && coun2 == 0) coun++; + } + } + cout << coun << endl; +} +int n, m; +int main() { + int s = 0, c = 0; + cin >> n >> m; + if (n < m) + cout << -1 << endl; + else { + int q = n / 2; + for (int i = 1; i <= n; i++) { + for (int j = 0; j < n; j++) { + if (s < n) + if (j < q) { + s += 2; + c++; + } else { + s += 1; + c++; + } + } + if (c % m == 0) { + break; + } else { + s = 0; + c = 0; + } + q--; + } + if (c % m != 0) + cout << -1 << endl; + else + cout << c << endl; + } + return 0; +} +int main() { + int n, m; + long k; + cin >> n >> m >> k; + int a, b; + a = k / (2 * m); + b = k % (2 * m); + if (b == 0) { + b = m; + } else { + a += 1; + if (b % 2 != 0) + b = b / 2 + 1; + else + b /= 2; + } + cout << a << " " << b << " "; + if (k % 2 == 0) + cout << "R" << endl; + else + cout << "L" << endl; + return 0; +} +int main() { + unsigned int n; + int k; + cin >> n; + for (int i = 1; i <= 4; i++) { + if (n % i == 1 || n % i == 2) k = 1; + if (n % i == 0 || n % i == 3) k = 0; + } + cout << k << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + map mp; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') mp[s[i]] = 1; + } + cout << mp.size() << endl; +} +int m, k; +int dis[1200], sup[1200]; +int main() { + cin >> m >> k; + int i; + for (i = 0; i < m; i++) cin >> dis[i]; + for (i = 0; i < m; i++) cin >> sup[i]; + int tank = sup[0]; + int mn = sup[0]; + int t = 0; + sup[m] = 0; + for (i = 1; i <= m; i++) { + while (tank - dis[i - 1] < 0) { + tank += mn; + t += k; + } + tank -= dis[i - 1]; + t += dis[i - 1]; + tank += sup[i]; + if (sup[i] > mn) mn = sup[i]; + } + cout << t << endl; +} +int main() { + int n; + cin >> n; + int x = 0; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + if (s[0] == '+' || s[1] == '+') + ++x; + else + --x; + } + cout << x << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int flag = 0; + long l, r, d; + cin >> l >> r >> d; + if (d < l || d > r) { + cout << d << endl; + } else { + cout << ((r / d) * d + d) << endl; + } + } + return 0; +} +int main() { + int k, l, m, n, total; + int res = 0; + cin >> k >> l >> m >> n >> total; + for (int i = 1; i <= total; i++) { + if ((i % k == 0) || (i % l == 0) || (i % m == 0) || (i % n == 0)) { res++; } + } + cout << res << endl; + return 0; +} +int main() { + char a[100000]; + int b; + int k; + int sum = 0; + cin.get(a, 1000); + b = strlen(a); + sort(a, a + b); + for (int i = 0; i < b; i++) { + if (a[i] != a[i + 1]) { sum++; } + } + if (b <= 3) + k = sum - 2; + else + k = sum - 4; + cout << k << endl; +} +const int MAXN = 100000 + 5; +int main() { + string s; + cin >> s; + int cnt1 = 0, cnt2 = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '0') { + if (cnt1 % 2 == 0) + cout << 1 << " " << 1; + else + cout << 3 << " " << 1; + cnt1++; + } else { + if (cnt2 % 2 == 0) + cout << 4 << " " << 3; + else + cout << 4 << " " << 1; + cnt2++; + } + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + char c = s[0]; + int t = 0; + for (int i = 1; i < n; i++) { + if (s[i] != c) { + t++; + c = s[i + 1]; + } + } + cout << n - t << endl; +} +int main() { + long long int n, m, s, f, t, now, ans = 0, i; + bool asc = true; + cin >> n >> m; + while (n--) { + cin >> s >> f >> t; + i = m; + if (s == f) + cout << t << endl; + else { + if ((t / (m - 1)) % 2 == 1) { + asc = false; + now = m - (t % (m - 1)); + } else + now = (t % (m - 1)) + 1; + now--, f--, s--, i--; + if (now == s) + if ((asc && f > s) || (!asc && f < s)) + ans = abs(f - now); + else if (asc && f < s) + ans = (i - now) + (i - f); + else + ans = now + f; + else if (now > s) + if (asc) { + ans = i - now; + if (f < s) + ans += (i - f); + else + ans += (i + f); + } else if (f < s) + ans = now - f; + else + ans = now + f; + else if (asc) + if (f > s) + ans = f - now; + else + ans = (i - now) + (i - f); + else { + ans = now; + if (f > s) + ans += f; + else + ans += (i + (i - f)); + } + cout << ans + t << endl; + asc = true; + ans = 0; + } + } +} +int main() { + int n, i, a, b, c, d, e, plus, minus; + int max = -1, score = 0; + char name[25]; + char maxName[25]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> name >> plus >> minus >> a >> b >> c >> d >> e; + score = plus * 100 - minus * 50 + a + b + c + d + e; + if (score > max || i == 0) { + max = score; + strcpy(maxName, name); + } + } + cout << maxName << endl; +} +int main() { + long long int y, b, ye, gr, bl, a, c, ans = 0; + cin >> y >> b >> ye >> gr >> bl; + a = (2 * ye) + gr; + c = (3 * bl) + gr; + if (y - a < 0) { ans += a - y; } + if (b - c < 0) { ans += c - b; } + cout << ans << endl; +} +int main() { + int test, m, n, i, j, k, color = 2; + char a[105][105]; + cin >> n; + cin >> m; + for (j = 1; j <= n; j++) + for (int k = 1; k <= m; k++) { cin >> a[j][k]; } + for (i = 1; i <= n; i++) { + for (int k = 1; k <= m; k++) { + if (a[i][k] == 'C' || a[i][k] == 'M' || a[i][k] == 'Y') color = 1; + } + } + if (color == 1) + cout << "#Color\n"; + else + cout << "#Black&White\n"; + return 0; +} +int getRank(int i, int p[], int r[]) { + if (r[i] != 0) return r[i]; + if (p[i] == -1) + r[i] = 1; + else + r[i] = getRank(p[i], p, r) + 1; + return r[i]; +} +int main() { + int n, p[2001], r[2001] = {0}, ans = 0; + cin >> n; + for (int i = 1; i < n + 1; ++i) { cin >> p[i]; } + for (int i = 1; i < n + 1; ++i) { + int a = getRank(i, p, r); + if (a > ans) ans = a; + } + cout << ans << endl; + return 0; +} +int n, z, a; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + if (i != 1) { cout << a + z << " "; } + z = a; + } + cout << a << endl; + return 0; +} +int main() { + long long n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n2 >= n1) { + cout << "Second\n"; + } else { + cout << "First\n"; + } + return 0; +} +int n, m; +int main() { + int s = 0, c = 0; + cin >> n >> m; + if (n < m) + cout << -1 << endl; + else { + int q = n / 2; + for (int i = 1; i <= n; i++) { + for (int j = 0; j < n; j++) { + if (s < n) + if (j < q) { + s += 2; + c++; + } else { + s += 1; + c++; + } + } + if (c % m == 0) { + break; + } else { + s = 0; + c = 0; + } + q--; + } + if (c % m != 0) + cout << -1 << endl; + else + cout << c << endl; + } + return 0; +} +int gr[2005], ans[2005]; +void go(int x) { + if (ans[gr[x]] == 0) go(gr[x]); + ans[x] = ans[gr[x]] + 1; +} +int main() { + int n, c = -1; + memset(ans, 0, sizeof(ans)); + cin >> n; + for (int a = 1; a <= n; a++) { + cin >> gr[a]; + if (gr[a] == -1) ans[a] = 1; + } + for (int a = 1; a <= n; a++) + if (ans[a] == 0) go(a); + for (int a = 1; a <= n; a++) + if (ans[a] > c) c = ans[a]; + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + if ((n / 2) % 2 == 0) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + } else { + n = n - 1; + if ((n / 2) % 2 == 0) { + cout << 1 << endl; + } else { + cout << 0 << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1 || n % 2) + cout << "Ehab" << endl; + else + cout << "Mahmoud" << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + string ans = ""; + int i; + int flag = 1; + for (i = 0; i < n - 1; i++) { + if (!flag) break; + if (s[i + 1] >= s[i]) { + ans += s[i]; + } else { + flag = 0; + } + } + if (!flag) + for (; i < n; i++) { ans += s[i]; } + cout << ans << endl; +} +long long quickpow(long long a, long long b, long long MOD) { + long long ans = 1; + a %= MOD; + while (b) { + if (b & 1ll) ans = ans * a % MOD; + a = a * a % MOD, b >>= 1; + } + return ans; +} +long long gcd(long long a, long long b) { + return a % b == 0 ? b : gcd(b, a % b); +} +string s1, s2; +int op[200005], vis[200005]; +bool judge(int x) { + string temp; + memset((vis), (0), (sizeof(vis))); + for (int i = 0; i < x; i++) vis[op[i]] = 1; + int len = s1.length(); + for (int i = 0; i < len; i++) + if (!vis[i]) temp += s1[i]; + int p1 = 0, p2 = 0, len1 = temp.length(), len2 = s2.length(); + while (p1 < len1 && p2 < len2) { + if (temp[p1] == s2[p2]) p2++; + p1++; + } + return p2 == len2; +} +int main() { + while (cin >> s1 >> s2) { + int len = s1.length(); + for (int i = 0; i < len; i++) { + cin >> op[i]; + op[i]--; + } + int left = 0, right = len, ans = 0; + while (left < right) { + int mid = (left + right + 1) >> 1; + if (judge(mid)) + left = mid; + else + right = mid - 1; + } + cout << left << endl; + } + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int lane = (k - 1) / (2 * m) + 1; + int desk = ((k - ((lane - 1) * 2 * m)) - 1) / 2 + 1; + cout << lane << ' ' << desk << ' '; + if ((k - ((lane - 1) * 2 * m)) & 1) + cout << 'L' << endl; + else + cout << 'R' << endl; + return 0; +} +int main() { + long long int n; + while (cin >> n) { + if (n == 0) + cout << 0 << endl; + else if ((n + 1) % 2 == 0) + cout << (n + 1) / 2 << endl; + else + cout << n + 1 << endl; + } + return 0; +} +int main() { + cin.ignore(); + string s; + getline(cin, s); + map mp; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') mp[s[i] - 'a']++; + } + cout << mp.size() << endl; +} +int main() { + int n, k; + while (cin >> n >> k) { + long long temp = 0; + long long a; + int j = 1; + for (int i = 1; i <= n; i++) { + cin >> a; + if (temp - (i - 1) * (n - i) * a < k) { + cout << j << endl; + i--, n--; + } else + temp += (i - 1) * a; + j++; + } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int sum = 0; + string str; + cin >> str; + for (int i = n; i < str.size(); i += n) { + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) sum++; + } + cout << sum << endl; + } + return 0; +} +int gcd(int a, int b) { + int rem, r1, r, p; + r = min(a, b); + r1 = max(a, b); + p = r; + while (1) { + rem = r1 % r; + if (rem == 0) + break; + else { + r1 = r; + r = rem; + p = rem; + } + } + return p; +} +int main() { + int n, a, b, p = 0, ans, i = 1; + cin >> a >> b >> n; + while (1) { + if (i % 2 == 0) { + if (n >= p) p = gcd(b, n); + if (n < p) { + ans = 0; + break; + } + n -= p; + } else { + if (n >= p) p = gcd(a, n); + if (n < p) { + ans = 1; + break; + } + n -= p; + } + i++; + } + cout << ans << "\n"; +} +int main() { + int a, b, c, max; + cin >> a >> b >> c; + max = a * b * c; + if (a + b + c > max) max = a + b + c; + if (a + (b * c) > max) max = a + (b * c); + if ((a * b) + c > max) max = (a * b) + c; + if ((a + b) * c > max) max = (a + b) * c; + if (a * (b + c) > max) max = a * (b + c); + cout << max << endl; +} +int main() { + int n, c = 0; + cin >> n; + char prev, next; + cin >> prev; + for (int i = 1; i < n; i++) { + cin >> next; + if (next == prev) + c++; + else + prev = next; + } + cout << c << endl; +} +const int N = 100; +const long long MAX = 1e8 + 5; +int n, a, flag; +char s[N]; +int main() { + cin >> s; + a = s[0]; + flag = 1; + for (int i = 0, j = strlen(s) - 1; i < strlen(s), j >= 0; i++, j--) { + if (s[i] != s[j]) { + cout << strlen(s) << endl; + return 0; + } + if (a != s[i]) flag = 0; + } + if (flag) + cout << 0 << endl; + else + cout << strlen(s) - 1 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << a + b - 1 << endl; + for (int i = 1; i <= b; i++) { cout << 1 << " " << i << endl; } + for (int i = 2; i <= a; i++) cout << i << " " << 1 << endl; + return 0; +} +int dx[] = {-1, 0, 0, 1}; +int dy[] = {0, -1, 1, 0}; +void solve() { + int n, k; + cin >> n >> k; + int m, ans = 0, tot = 0; + for (int i = (0); i <= (k - 1); i++) { + cin >> m; + int ar[m]; + for (int j = (0); j <= (m - 1); j++) { cin >> ar[j]; } + int k = 0; + if (ar[0] == 1) { + while (k < m - 1 && ar[k + 1] - ar[k] == 1) k++; + k++; + tot += m - k + 1; + ans += m - k; + } else { + ans += m - 1; + tot += m; + } + } + ans += tot - 1; + cout << ans; +} +int main() { + int T = 1; + while (T--) { + solve(); + cout << '\n'; + } + return 0; +} +int main() { + int n, m, pos; + char c; + cin >> n >> m >> pos; + if (pos % 2 == 0) + c = 'R'; + else + c = 'L'; + pos--; + pos /= 2; + cout << pos / m + 1 << ' ' << pos % m + 1 << ' ' << c << '\n'; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + int i, a[101], x; + for (i = 1; i <= n; i++) { + cin >> x; + if (x > k) + a[i] = 0; + else + a[i] = x; + } + int min = n; + for (i = 1; i <= n; i++) { + if (a[i] != 0 && abs(i - m) < min) min = abs(i - m); + } + cout << 10 * min << endl; + } + return 0; +} +int main() { + long long n, sum = 0; + cin >> n; + for (long long i = 0; i < n; i++) { + long long temp; + cin >> temp; + sum += temp; + } + if (n != 1) { + long long count = 0; + for (long long f = 1; f <= 5; f++) { + if ((sum + f) % (n + 1) == 1) continue; + count++; + } + cout << count << endl; + } else { + if (sum % 2 == 1) + cout << 3 << endl; + else + cout << 2 << endl; + } + return 0; +} +int main() { + int n, i, a, s = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a; + s += a; + } + if (s != 0) { + cout << "HARD" << endl; + } else { + cout << "EASY" << endl; + } + return 0; +} +int minCoins(int coins[], int m, int V) { + int *table = new int[V + 1]; + table[0] = 0; + for (int i = 1; i <= V; i++) table[i] = INT_MAX; + for (int i = 1; i <= V; i++) { + for (int j = 0; j < m; j++) + if (coins[j] <= i) { + int sub_res = table[i - coins[j]]; + if (sub_res != INT_MAX && sub_res + 1 < table[i]) table[i] = sub_res + 1; + } + } + return table[V]; +} +int main() { + int t; + cin >> t; + int coins[] = {2, 3, 4, 5, 6, 7}; + int m = sizeof(coins) / sizeof(coins[0]); + int V; + while (t--) { + cin >> V; + cout << minCoins(coins, m, V) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + long long ans = 0; + for (int i = 0; i < n; i++) { ans = ans + (i + 1) * arr[i] - i; } + cout << ans << endl; + return 0; +} +int n, m; +int a[101]; +bool k[101]; +int main() { + memset(a, 0x3f, sizeof(a)); + cin >> n >> m; + getchar(); + for (int i = 1; i <= n; i++) { k[i] = getchar() - '0'; } + if (!k[1] || !k[n]) { + cout << -1 << endl; + return 0; + } + a[1] = 0; + for (int i = 1; i <= n; i++) { + if (k[i]) { + for (int j = i + 1; j <= i + m; j++) { + if (k[j]) { a[j] = min(a[j], a[i] + 1); } + } + } + } + if (a[n] == 1061109567) { + cout << -1 << endl; + return 0; + } + cout << a[n] << endl; + return 0; +} +int main() { + int con, sc, un, sm = 0, wnr = 0, tmp, a, b, c, d, e; + string n, w; + cin >> con; + cin >> n >> sc >> un >> a >> b >> c >> d >> e; + sm += sc * 100 + a + b + c + d + e - un * 50; + wnr = sm; + w = n; + for (int i = 1; i < con; i++) { + sm = 0; + cin >> n >> sc >> un >> a >> b >> c >> d >> e; + sm += sc * 100 + a + b + c + d + e - un * 50; + if (sm > wnr) { + wnr = sm; + w = n; + } + } + cout << w << endl; + return 0; +} +int main() { + long n, k; + cin >> n >> k; + string s; + cin >> s; + map m; + int i; + for (i = 0; i < n; i++) m[s[i] - 'A' + 1]++; + map::iterator it; + int l = INT_MAX; + int count = 0; + int f = 0; + for (i = 1; i <= k; i++) { + if (m.find(i) == m.end()) { + f = 1; + break; + } else + l = min(l, m[i]); + } + if (f == 1) + cout << 0 << endl; + else + cout << l * k << endl; +} +int main() { + int answers[6]; + int a, b, c; + cin >> a >> b >> c; + answers[0] = a + b + c; + answers[1] = a * b * c; + answers[2] = a * b + c; + answers[3] = a + b * c; + answers[4] = a * (b + c); + answers[5] = (a + b) * c; + sort(answers, answers + 6); + cout << answers[5] << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long tot = 0; + long long input; + for (int i = 1; i <= n; i++) { + cin >> input; + tot += i * (input - 1); + } + tot += n; + cout << tot << endl; + return 0; +} +int main() { + long long k, b, n, t; + cin >> k >> b >> n >> t; + long long z = k + b; + int g = n; + while (z < t && g > 0) { + g--; + z = z * k + b; + } + if (z == t) { g--; } + cout << g << endl; +} +long long int n; +int main() { + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" + << "\n"; + } else { + cout << "Ehab" + << "\n"; + } + return 0; +} +int main() { + int a, b, c, d, e; + cin >> a; + cin >> b; + cin >> c; + cin >> d; + cin >> e; + if ((a + b + c + d + e) % 5 != 0 || (a + b + c + d + e) / 5 == 0) { + cout << -1 << endl; + } else { + cout << (a + b + c + d + e) / 5 << endl; + } + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int el, st; + el = abs(x - z) * t2 + 3 * t3 + abs(y - x) * t2; + st = abs(x - y) * t1; + if (st < el) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + int n, m; + ifstream ff("file.txt"); + cin >> n >> m; + map m1; + map::iterator p, p1; + if (m == 0) { + cout << n << endl; + return 0; + } + while (m--) { + string s1, s2, s3, s4; + int t; + cin >> s1 >> s2 >> s3 >> s4 >> t; + p = m1.find(s3); + if (p == m1.end()) { + m1[s3] = t; + } else { + if (s3[0] == 'l') { + if (p->second > t) { m1[s3] = t; } + } else { + if (p->second < t) { m1[s3] = t; } + } + } + } + p = m1.begin(); + if (m1.size() == 1) { + if (p->first[0] == 'l') { + if (p->second - 1 != 0) { + cout << p->second - 1 << endl; + } else { + cout << -1 << endl; + } + } else { + if (n - p->second != 0) { + cout << n - p->second << endl; + } else { + cout << -1 << endl; + } + } + } else { + p1 = p; + p1++; + if (p->second <= p1->second + 1) { + cout << -1 << endl; + } else { + cout << p->second - p1->second - 1 << endl; + } + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = (n - 1) * 2 - (k - 1); + for (int i = 0; i < k; ++i) { + int m; + cin >> m; + vector a(m); + for (int i = 0; i < m; ++i) cin >> a[i]; + if (a[0] == 1) { + for (int i = 0; i + 1 < m && a[i + 1] - a[i] == 1; ++i) { ans -= 2; } + } + } + cout << ans << endl; +} +int main() { + int n, sum = 0, x, y; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + for (;; x += y) { + if (x > sum) { + sum = x; + break; + } + } + } + cout << sum << endl; + return 0; +} +char s[15][15]; +int n, m, ans, b[15], c[15]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> s[i][j]; + if (s[i][j] == 'S') b[i] = c[j] = 1; + } + } + int sum = 0; + for (int i = 1; i <= n; i++) { + if (!b[i]) sum++; + } + ans += sum * m; + for (int i = 1; i <= m; i++) { + if (!c[i]) ans += n, ans -= sum; + } + cout << ans << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + char a[100][100], b[100][100]; + int i, j; + cin.get(); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + a[i][j] = cin.get(); + b[i][j] = a[i][j]; + } + cin.get(); + } + int sum1 = 0; + int sum2 = 0; + int sum = 0; + for (i = 0; i < m; i++) { + sum1 = 0; + for (j = 0; j < n; j++) + if (a[i][j] == '.') { + sum1++; + a[i][j] = '0'; + } else { + sum1 = 0; + break; + } + if (sum1 == 0) + for (j = 0; j < n; j++) a[i][j] = b[i][j]; + sum += sum1; + } + for (j = 0; j < n; j++) { + sum2 = 0; + for (i = 0; i < m; i++) + if (b[i][j] == '.') { + if (a[i][j] == '.') sum2++; + } else { + sum2 = 0; + break; + } + sum += sum2; + } + cout << sum << endl; + return 0; +} +int main() { + int n, i; + string s; + cin >> n >> s; + int cnt = 0; + for (i = 0; i < n - 1; i++) { + if (s[i] == 'U' && s[i + 1] == 'R') + i++; + else if (s[i] == 'R' && s[i + 1] == 'U') + i++; + cnt++; + } + if (i == n - 1) cnt++; + cout << cnt << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int l = 1; + int sum = 0; + for (int i = 0; i < m; i++) { + int k; + int tmp; + cin >> k; + cin >> tmp; + int nex; + if (tmp == 1) { + for (int i = 1; i < k; i++) { + cin >> nex; + if (nex == tmp + 1) l++, tmp++; + } + sum += n - l; + sum += k - l; + } else { + for (int i = 1; i < k; i++) cin >> tmp; + sum += k - 1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int p, n; + int a[310]; + while (cin >> p >> n) { + set s; + int flag = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + int t = a[i] % p; + if (s.count(t)) { + cout << i + 1 << endl; + flag = 1; + break; + } else { + s.insert(t); + } + } + if (flag == 0) cout << "-1" << endl; + } +} +int main() { + int a; + cin >> a; + char inutil = getchar(); + string b; + getline(cin, b); + b[a] = '1'; + int contador = 0; + for (int i = 0; i <= a; i++) { + if (b[i - 1] == b[i] || b[i] == b[i + 1]) contador++; + b[i] = '0'; + } + cout << contador << endl; +} +int main() { + string s[5] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; + string s2; + cin >> s2; + int n = s2.length(); + int cnt = 0; + for (int i = 0; i < n; i++) { + if (i + 4 < n) + if (s2.substr(i, 5) == s[0] || s2.substr(i, 5) == s[2]) cnt++; + if (i + 3 < n) + if (s2.substr(i, 4) == s[1]) cnt++; + if (i + 2 < n) + if (s2.substr(i, 3) == s[3]) cnt++; + if (i + 5 < n) + if (s2.substr(i, 6) == s[4]) cnt++; + } + if (cnt == 1) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + long long int n, s = 0, m; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + s += m + i * (m - 1); + } + cout << s << endl; + return 0; +} +const double PI = acos(-1.0); +const int inf = int(1e9); +const int mod = inf + 7; +long long n, m, k, l, w, h, sum, mx, mn; +int main() { + mn = (1e9), sum = 0, mx = 0; + string s; + cin >> n; + vector v(n); + long long cnt1 = 0, cnt2 = 0; + char c; + for (int i = 0; i < n; ++i) { + cin >> c; + if (c == 'A') + cnt1++; + else + cnt2++; + } + if (cnt1 == cnt2) + cout << "Friendship"; + else if (cnt1 > cnt2) + cout << "Anton"; + else + cout << "Danik"; + cout << endl; + return 0; +} +int main() { + int size, maior = -0x3f3f3f3f, menor = 0x3f3f3f3f, c = 0; + cin >> size; + vector vetor(size); + for (int i = 0; i < size; i++) { + cin >> vetor[i]; + maior = max(maior, vetor[i]), menor = min(menor, vetor[i]); + } + for (int i = 0; i < size; i++) + if (vetor[i] > menor && vetor[i] < maior) c++; + cout << c << '\n'; +} +int main() { + int p, n, z = -1, ele; + cin >> p >> n; + int arr[p] = {}; + for (int i = 0; i < n; i++) { + cin >> ele; + if (arr[ele % p]) { + z = i + 1; + break; + } + arr[ele % p]++; + } + cout << z << "\n"; +} +const int INF = 1 << 29; +int main() { + int n, m; + cin >> n >> m; + string a[n]; + for (int i = 0; i < (n); i++) cin >> a[i]; + int ans[m]; + for (int i = 0; i < (m); i++) ans[i] = 0; + int chk; + for (int i = 0; i < (n); i++) { + chk = 0; + for (int j = 0; j < (m); j++) { chk += (a[i][j] == '1'); } + if (chk == 0) { + cout << "-1\n"; + return 0; + } + } + for (int i = 0; i < (n); i++) { + int last; + bool found = 0; + for (int j = m - 1; j >= 0; --j) { + if (a[i][j] == '1') { + last = j; + break; + } + } + int curr[m]; + for (int j = 0; j < (m); j++) curr[j] = INT_MAX; + for (int j = 0; j < (m); j++) { + if (a[i][j] == '1') { + last = j; + found = 1; + } + if (!found) { + curr[j] = min(curr[j], (m - last) + j); + } else { + curr[j] = min(curr[j], abs(j - last)); + } + } + found = 0; + for (int j = 0; j < m; ++j) { + if (a[i][j] == '1') { + last = j; + break; + } + } + for (int j = m - 1; j >= 0; --j) { + if (a[i][j] == '1') { + last = j; + found = 1; + } + if (!found) { + curr[j] = min(curr[j], (last + 1) + (m - 1 - j)); + } else { + curr[j] = min(curr[j], abs(j - last)); + } + } + for (int j = 0; j < (m); j++) ans[j] += curr[j]; + } + int res = INT_MAX; + for (int i = 0; i < (m); i++) res = min(res, ans[i]); + cout << res << endl; + return 0; +} +int main() { + int n, x; + cin >> n; + int cnt1 = 0, cnt2 = 0; + for (int i = 0; i < n; i++) { + cin >> x; + cnt1 += x; + } + for (int i = 0; i < n; i++) { + cin >> x; + cnt2 += x; + } + if (cnt1 >= cnt2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + set s; + for (int i = 0; i < 4; i++) { + int x; + cin >> x; + s.insert(x); + } + cout << 4 - s.size() << "\n"; +} +int main() { + int n; + cin >> n; + int sum = 0; + for (size_t i = 0; i < n; i++) { + int temp; + cin >> temp; + sum += temp; + } + sum %= (n + 1); + int ans = 0; + for (size_t i = 0; i < 5; i++) { + if ((sum + i + 1) % (n + 1) != 1) ans++; + } + cout << ans << '\n'; + return 0; +} +int main() { + int a, b, c, d, e, sum = 0; + cin >> a >> b >> c >> d >> e; + for (int i = 1; i <= e; i++) { + if (i % a == 0 || i % b == 0 || i % c == 0 || i % d == 0) sum++; + } + cout << sum << endl; +} +int main() { + long long unsigned n, k; + cin >> n >> k; + long long unsigned mid = n / 2; + if (n % 2 == 1) mid++; + if (k <= mid) + cout << (k * 2) - 1 << endl; + else + cout << ((k - (mid + 1)) * 2) + 2 << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +int main() { + int m, n; + map mapOfRow, mapOfColumn; + map::iterator it; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + for (int j = 0; j < m; j++) { + if (s[j] == '*') { + mapOfRow[i]++; + mapOfColumn[j + 1]++; + } + } + } + for (it = mapOfRow.begin(); it != mapOfRow.end(); it++) { + if (it->second == 1) cout << it->first << ' '; + } + for (it = mapOfColumn.begin(); it != mapOfColumn.end(); it++) { + if (it->second == 1) cout << it->first << endl; + } + return 0; +} +int main() { + long long k; + string s[6]; + cin >> k; + s[0] = "+------------------------+"; + s[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + s[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + s[3] = "|#.......................|"; + s[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + s[5] = "+------------------------+"; + for (int j = 1; j <= 21; j++) { + if (k == 0) break; + for (int i = 0; i < 6; i++) { + if (k == 0) break; + if (s[i][j] == '#') { + --k; + s[i][j] = 'O'; + } + } + } + for (int i = 0; i < 6; i++) cout << s[i] << endl; +} +int main() { + int a1, a2, a3, b1, b2, b3, sumA = 0, sumB = 0, ans, n, vA, vB; + cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3; + sumA = a1 + a2 + a3; + sumB = b1 + b2 + b3; + cin >> n; + vA = sumA / 5; + if (sumA % 5 != 0) ++vA; + vB = sumB / 10; + if (sumB % 10 != 0) ++vB; + ans = vA + vB; + if (ans > n) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int a[100], n, sum; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + if (sum == 0) { + cout << "EASY" << endl; + } else { + cout << "HARD" << endl; + } + return 0; +} +int main() { + int y, b, r, m; + cin >> y >> b >> r; + if (b <= r - 1 && y >= b - 1) + m = 3 * b; + else if (b <= r - 1 && y < b - 1) + m = 3 * (y + 1); + else if (b > r - 1 && y >= r - 2) + m = 3 * (r - 1); + else if (b > r - 1 && y < r - 2) + m = 3 * (y + 1); + cout << m << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + string t = ""; + for (int i = 0; i < n; i++) { + int k = (i * (i + 1)) / 2; + if (k >= n) { break; } + t = t + s[k]; + } + cout << t << endl; + return 0; +} +const int maxn = 2e5 + 5; +long long a[maxn]; +long long b[maxn]; +int main() { + int n; + cin >> n; + cout << ((n + 1) / 2) % 2 << endl; + return 0; +} +const int maxn = 200100; +long long n; +int main() { + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +long long a[200000 + 5]; +int main() { + long long i, j, k = 0, l = 0; + long long n, m, t; + cin >> n >> m >> t; + for (i = 0; i * n <= t; i++) { + for (j = 0; j * m <= t; j++) + if (i * n + j * m == t) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int dx[4] = {0, 0, 1, -1}; +int dy[4] = {1, -1, 0, 0}; +int DX[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int DY[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int c1, c2, x, y; +bool Ciel() { + if (c1 >= 200 && c2 >= 20) { + c1 -= 200; + c2 -= 20; + return 1; + } else if (c1 >= 100 && c2 >= 120) { + c1 -= 100; + c2 -= 120; + return 1; + } else if (c2 >= 220) { + c2 -= 220; + return 1; + } + return 0; +} +bool Hanako() { + if (c2 >= 220) { + c2 -= 220; + return 1; + } else if (c1 >= 100 && c2 >= 120) { + c1 -= 100; + c2 -= 120; + return 1; + } else if (c1 >= 200 && c2 >= 20) { + c1 -= 200; + c2 -= 20; + return 1; + } + return 0; +} +int main() { + cin >> x >> y; + c1 = 100 * x; + c2 = y * 10; + int i = 1; + while (true) { + bool k = 0; + if (i == 1) { + k = Ciel(); + } else if (i == 2) { + k = Hanako(); + } + if (k) { + if (i == 1) { + i = 2; + } else { + i = 1; + } + } else { + if (i == 1) { + i = 2; + } else { + i = 1; + } + break; + } + } + if (i == 1) { + cout << "Ciel" << endl; + } else { + cout << "Hanako" << endl; + } +} +int main() { + int n, m, cnt2 = 0; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { cin >> arr[i][j]; } + int total = n * m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + int cnt1 = 0, cnt = 0; + if (arr[i][j] != 'S') { + for (int c = 0; c < m; c++) { + if (arr[i][c] == 'S') { cnt++; } + } + for (int r = 0; r < n; r++) { + if (arr[r][j] == 'S') { cnt1++; } + } + if (cnt1 > 0 && cnt > 0) { arr[i][j] = 'S'; } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '.') { cnt2++; } + } + } + cout << cnt2 << endl; + return 0; +} +int main() { + char c[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { cin >> c[i][j]; } + } + int x = 0, y = 0, z = 0, v = 0; + while (true) { + for (int j = z; j < z + 2; j++) { + if (c[v][j] == '#') x++; + if (c[v][j] == '.') y++; + if (c[v + 1][j] == '#') x++; + if (c[v + 1][j] == '.') y++; + } + if (x > y || y > x) { + cout << "YES" << endl; + return 0; + } + x = 0; + y = 0; + z++; + if (z == 3) { + v++; + z = 0; + } + if (v == 3) { break; } + } + cout << "NO" << endl; +} +int main() { + int n; + unsigned long long int l, r, d, b; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> l >> r >> d; + b = d; + if (d < l || d > r) { + cout << d << endl; + continue; + } else { + b = r / d; + d = d * (b + 1); + cout << d << endl; + } + } + return 0; +} +int main() { + int num; + cin >> num; + if (num % 2 == 0) + cout << "Mahmoud\n"; + else + cout << "Ehab\n"; + return 0; +} +int main() { + long long n, d, i, tmp, cnt; + cin >> n >> d; + long long a[n + 2]; + for (i = 0; i < n; i++) cin >> a[i]; + cnt = 2; + if (n == 1) { + cout << "2\n"; + return 0; + } + for (i = 0; i < n; i++) { + if (i == 0) { + tmp = a[i] + d; + tmp = a[i + 1] - tmp; + if (tmp >= d) cnt += 1; + } else if (i == n - 1) { + tmp = a[i] - d; + tmp = tmp - a[i - 1]; + if (tmp > d) cnt += 1; + } else { + tmp = a[i] + d; + tmp = a[i + 1] - tmp; + if (tmp >= d) cnt += 1; + tmp = a[i] - d; + tmp = tmp - a[i - 1]; + if (tmp > d) cnt += 1; + } + } + cout << cnt << "\n"; + return 0; +} +long long n, ans = 0; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { + long long a; + cin >> a; + ans += (a - 1) * (i - 1) + a; + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + if (s.size() == 1) { + cout << s << endl; + return 0; + } + stack max; + max.push(s[s.size() - 1]); + for (int64_t i = s.size() - 2; i >= 0; i--) { + if (s[i] == max.top() or s[i] > max.top()) max.push(s[i]); + } + while (!max.empty()) { + cout << max.top(); + max.pop(); + } + cout << endl; + return 0; +} +int x[110], y[110]; +vector adj[110]; +int flag[110]; +int dfs(int u) { + for (int i = 0; i < adj[u].size(); i++) { + int v = adj[u][i]; + if (flag[v]) continue; + flag[v] = 1; + dfs(v); + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == j) continue; + if (x[i] == x[j] || y[i] == y[j]) { adj[i].push_back(j); } + } + } + int cnt = -1; + for (int i = 1; i <= n; i++) { + if (flag[i] == 0) { + flag[i] = 1; + cnt++; + dfs(i); + } + } + cout << cnt << endl; +} +int main() { + string s; + int ans, u, d, l, r, n; + cin >> n; + cin.ignore(); + cin >> s; + ans = 0; + for (int i = 0; i < s.size(); ++i) { + u = d = l = r = 0; + for (int j = i; j < s.size(); ++j) { + if (s[j] == 'L') ++l; + if (s[j] == 'R') ++r; + if (s[j] == 'U') ++u; + if (s[j] == 'D') ++d; + if (l == r && u == d) ++ans; + } + } + cout << ans << endl; +} +int N, M, K; +int main() { + cin >> N >> M >> K; + cout << (K - 1) / (M * 2) + 1 << " "; + if (K % (M * 2) == 0) + cout << M << " "; + else + cout << (K % (M * 2) + 1) / 2 << " "; + if (K % 2) + cout << "L\n"; + else + cout << "R\n"; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, b, n; + while (cin >> a >> b >> n) { + int x = gcd(a, n), y = gcd(b, n), z = x; + int ans = 0; + while (z <= n) { + n -= z; + z = gcd(b, n); + if (z > n) { + ans = 0; + break; + } + n -= z; + z = gcd(a, n); + if (z > n) { + ans = 1; + break; + } + } + cout << ans << endl; + } + return 0; +} +const int maxn = 101000; +const int INF = 0x3f3f3f3f; +int a[maxn]; +int b[maxn]; +int main() { + int n; + int c = 0; + cin >> n; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + for (int i = 0; i < n; ++i) cin >> a[i]; + memcpy(b, a, sizeof(a)); + sort(b, b + n); + for (int i = 0; i < n; ++i) { + if (a[i] != b[i]) c++; + } + if (c > 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, m, a, b; + cin >> n >> m >> a >> b; + int x = (n / m) * b + (n % m) * a; + int y = (n / m + 1) * b; + int z = n * a; + cout << min(x, min(y, z)) << endl; +} +int gcd(int x, int y) { + if (y == 0) return x; + return gcd(y, x % y); +} +int main() { + int a, b, n, c = 0; + cin >> a >> b >> n; + for (int i = 0; n > 0; i++) { + if (i % 2 == 0) { + n -= gcd(a, n); + c = 0; + } else if (i % 2 != 0) { + n -= gcd(b, n); + c = 1; + } + } + cout << c << endl; + return 0; +} +int main() { + long long k, l; + cin >> k >> l; + long long sum = 1; + for (int i = 1; i > 0; i++) { + sum = sum * k; + if (sum > l) + break; + else if (sum == l) { + cout << "YES" << endl; + cout << i - 1 << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + unsigned int l = -1, p, q; + cin >> n >> p; + while (p % n == 0) { + p /= n; + l++; + } + if (p == 1 && l >= 0) { + cout << "YES" << endl; + cout << l << endl; + } else + cout << "NO" << endl; +} +int main() { + long long int a = 0, b = 0; + cin >> a >> b; + long long int x = 0, y = 0, z = 0; + cin >> x >> y >> z; + long long int Y = 0, B = 0, t = 0; + Y = (2 * x) + (1 * y); + B = (1 * y) + (3 * z); + if (Y > a) { + Y = Y - a; + } else { + Y = 0; + } + if (B > b) { + B = B - b; + } else { + B = 0; + } + t = Y + B; + cout << t << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + puts(n1 > n2 ? "First" : "Second"); +} +int main() { + int n; + long long a, ara[101], Ans; + cin >> n; + cin >> a; + Ans = a; + for (int i = 1; i < n; i++) { + cin >> ara[i]; + Ans += (ara[i] - 1) * (i + 1) + 1; + } + cout << Ans << endl; + return 0; +} +int main() { + int n, ans; + double l, r, d; + cin >> n; + while (n--) { + cin >> l >> r >> d; + if (l > d) + ans = d; + else + ans = ceil((r + 1) / d) * d; + cout << ans << "\n"; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const int inf = 0x3f; +int n, m, k; +int ans1 = 0, ans2 = 0, ans; +int main() { + cin >> n >> m >> k; + int ip, flag = 0, flag1 = 0; + for (int i = 1; i <= n; i++) { + cin >> ip; + if (i == m) { + flag = 1; + continue; + } + if (!flag && ip != 0 && ip <= k) { + ans1 = 1; + flag1 = 1; + continue; + } + if (!flag && flag1) ans1++; + if (flag) ans2++; + if ((i == n && (ip > k || ip == 0))) ans2 = 0; + if (flag && ip != 0 && ip <= k) { break; } + } + if (ans1 && ans2) + ans = min(ans1, ans2); + else + ans = max(ans1, ans2); + cout << ans * 10 << endl; + return 0; +} +int n; +int a[200000 + 10], b[200000 + 10]; +int visit[200000 + 10]; +int main() { + while (cin >> n) { + int flag, temp; + int ans = 200000 + 10; + memset(visit, 0, sizeof visit); + for (int i = 0; i < n; i++) { cin >> a[i]; } + a[n] = 0; + for (int i = 0; i < n; i++) { cin >> b[i]; } + int j = 0; + ans = 0; + for (int i = 0; i < n; i++) { + if (a[j] != b[i]) continue; + j++; + ans++; + } + cout << n - ans << endl; + } + return 0; +} +const int maxn = 100; +int n, m, a[3], b[3], t = 0; +char x; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> x; + if (x == '*') { + a[t] = i; + b[t++] = j; + } + } + if (a[0] == a[1] && b[0] == b[2]) { + cout << a[2] + 1 << " " << b[1] + 1 << endl; + return 0; + } else if (a[0] == a[2] && b[0] == b[1]) { + cout << a[1] + 1 << " " << b[2] + 1 << endl; + return 0; + } else if (a[1] == a[0] && b[1] == b[2]) { + cout << a[2] + 1 << " " << b[0] + 1 << endl; + return 0; + } else if (a[1] == a[2] && b[1] == b[0]) { + cout << a[0] + 1 << " " << b[2] + 1 << endl; + return 0; + } else if (a[2] == a[1] && b[2] == b[0]) { + cout << a[0] + 1 << " " << b[1] + 1 << endl; + return 0; + } else if (a[2] == a[0] && b[2] == a[1]) { + cout << a[1] + 1 << " " << b[0] + 1 << endl; + return 0; + } + return 0; +} +int main() { + string a, b; + int cnt1 = 0, cnt2 = 0, cnt = 0, ans = 0; + cin >> a >> b; + for (int i = 0; i < a.size(); i++) { + if (a[i] == '4') cnt1++; + if (b[i] == '4') cnt2++; + if (a[i] != b[i]) cnt++; + } + cnt -= abs(cnt1 - cnt2); + ans += abs(cnt1 - cnt2); + ans += cnt / 2; + cout << ans << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + vector faktor; + stack kanan; + for (long long i = 1; i * i <= n; i++) { + if (i * i == n) { + faktor.push_back(i); + } else if (n % i == 0) { + faktor.push_back(i); + kanan.push(n / i); + } + } + while (!kanan.empty()) { + faktor.push_back(kanan.top()); + kanan.pop(); + } + if (k > faktor.size()) + cout << -1 << endl; + else + cout << faktor[k - 1] << endl; +} +int min(int l, int r, int d) { + int j = 1; + if (d < l) { + return d; + } else { + return ((r / d) * d + d); + } +} +int main() { + int q, l, r, d; + cin >> q; + int ans; + while (q--) { + cin >> l >> r >> d; + cout << min(l, r, d) << endl; + } + return 0; +} +int main() { + int a, m; + int flag = 1; + int s[100000] = {0}; + cin >> a >> m; + while (flag) { + a = (a + a % m) % m; + if (!a) { + cout << "Yes" << endl; + flag = 0; + } + if (s[a] == 1) { + cout << "No" << endl; + flag = 0; + } + s[a] = 1; + } + return 0; +} +const int N = 100001; +int n, arr[N], arr2[N], c; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + arr2[i] = arr[i]; + } + sort(arr2, arr2 + n); + for (int i = 0; i < n; i++) { + if (arr[i] != arr2[i]) c++; + } + if (c == 2 || c == 0) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, X, Y, Z, x = 0, y = 0, z = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> X >> Y >> Z; + x += X; + y += Y; + z += Z; + } + if (x == y && y == z && x == z && x + y + z == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, x, a, b; + cin >> n >> x; + bool ans = true; + for (int i = 0; i < n; i++) { + cin >> a >> b; + x = 7 - x; + if (x == a || x == b || x + a == 7 || x + b == 7) ans = false; + } + if (ans) + cout << "YES"; + else + cout << "NO"; + cout << endl; + return 0; +} +int n, k; +int main() { + cin >> n; + while (n % 2 == 0) { n = n / 2; } + if (n == 1) { + cout << "YES" << endl; + k = 1; + } + if (k == 0) { cout << "NO" << endl; } +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k = 1; + int n, m; + cin >> n; + while (1) { + if (n == k) { + cout << "YES" << endl; + return 0; + } + if (n > k && n < k * 2) break; + k *= 2; + } + cout << "NO" << endl; + return 0; +} +int a[105]; +int b[200]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k, i, j; + int num = 0; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> a[i]; + b[a[i]]++; + } + sort(b, b + 200, cmp); + int x = b[0] / k; + if (b[0] % k != 0) x++; + for (i = 0; i < 200; i++) { + if (b[i] != 0) num++; + } + int sum = num * x * k; + cout << sum - n << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + m--; + for (long long i = 0; i < (long long)(n); i++) { + long long s, f, t; + cin >> s >> f >> t; + s--, f--; + if (s == f) { + cout << t << '\n'; + continue; + } + long long dt = t % (2 * m); + if (dt <= m) { + if (dt <= s) { + if (s <= f) { + t += s - dt; + t += f - s; + } else { + t += s - dt; + t += m - s; + t += m - f; + } + } else { + if (s < f) { + t += m - dt; + t += m - s; + t += s - 0; + t += f - 0; + } else { + t += m - dt; + t += m - s; + t += s - f; + } + } + } else { + dt = m - (dt % m); + if (dt >= s) { + if (s >= f) { + t += dt - s; + t += s - f; + } else { + t += dt - s; + t += s - 0; + t += f - 0; + } + } else { + if (s <= f) { + t += dt - 0; + t += s - 0; + t += f - s; + } else { + t += dt - 0; + t += s - 0; + t += m - s; + t += m - f; + } + } + } + cout << t << '\n'; + } + return 0; +} +int main() { + int c, v0, v1, a, l, read = 0, x; + cin >> c >> v0 >> v1 >> a >> l; + read = v0; + for (int i = 1;; i++) { + if (read >= c) { + cout << i << "\n"; + break; + } + x = min(v1, v0 + i * a); + x -= l; + read += x; + } + return 0; +} +int main() { + char re[111]; + char pre[111]; + int t = 0; + gets(re); + int i, j, flag; + int n = strlen(re); + if (n % 2) + flag = 1; + else + flag = 0; + char *p = re; + char *q = re + n - 1; + for (i = 1; i <= n; i++) { + if (flag) { + for (j = t; j > 0; j--) { pre[j] = pre[j - 1]; } + pre[t + 1] = '\0'; + pre[0] = *p; + t++; + p++; + } else { + for (j = t; j > 0; j--) { pre[j] = pre[j - 1]; } + pre[t + 1] = '\0'; + pre[0] = *q; + t++; + q--; + } + flag++; + if (flag == 2) flag = 0; + } + cout << pre << endl; +} +long long gcd(long long a, long long b) { + return b == 0 ? a : gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * (b / gcd(a, b)); +} +const int q = 1e9 + 9; +int main() { + int n, k, ans = 0, a[100007], c = 0, b; + cin >> n >> k; + for (int i = 0; i < k; i++) { + cin >> b; + for (int j = 0; j < b; j++) { + cin >> a[j]; + if (j > 0) ans++; + } + for (int o = 1; o < b; o++) { + if (a[0] == 1 && a[o] - 1 == a[o - 1]) + c++; + else + break; + } + } + ans -= c; + ans += (n - 1) - c; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, b; + int ans = 0; + while (n--) { + cin >> a >> b; + while (ans >= a) a += b; + ans = a; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, a[101] = {0}, ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) ans += (a[i] - 1) * i + 1; + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + int cnt = 0; + for (int i = n; i < str.size(); i += n) { + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, a[101][10]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { cin >> a[i][j]; } + } + int sum = 0; + for (int i = 0; i < 3; i++) { + sum = 0; + for (int j = 0; j < n; j++) { sum += a[j][i]; } + if (sum != 0) { + cout << "NO" << endl; + break; + } + } + if (sum == 0) { cout << "YES" << endl; } + memset(a, 0, sizeof(a)); + } + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int k = x - y; + if (k < 0) { k = k * (-1); } + int l = z - x; + if (l < 0) { l = l * (-1); } + int stairs = k * t1; + int elevator = l * t2 + k * t2 + 3 * t3; + if (stairs < elevator) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int n, m, a, b, v[2100][2100]; +int k, d[2100][2100], x, y; +bool solve(int x, int y, int k) { + int l = max(1, x - k), r = min(x + k, n), t; + for (int i = l; i <= r; i++) { + t = k - abs(i - x); + if (y - t > 0 && !v[i][y - t]) { + a = i; + b = y - t; + return 1; + } + if (y + t <= m && !v[i][y + t]) { + a = i; + b = y + t; + return 1; + } + } + return 0; +} +int main() { + cin >> n >> m >> k; + for (int i = 0; i < k; i++) { + cin >> x >> y; + for (int j = -2; j <= 2; j++) + for (int k = -2; k <= 2; k++) { + if (x + j < 1 || x + j > n || y + k < 1 || y + k > m) continue; + d[x][y] = max(d[x][y], d[x + j][y + k] - abs(j) - abs(k)); + } + while (!solve(x, y, d[x][y])) d[x][y]++; + v[a][b] = 1; + cout << a << " " << b << endl; + } +} +long long a[100004]; +int main() { + long long n, g = 0, ans = 0, x = 1, k, mn = 1e9 + 5; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mn = min(mn, a[i]); + } + x = mn; + for (int i = 0; i < n; i++) { + if ((a[i] - x) % k != 0) { + cout << -1 << endl; + return 0; + } + ans += ((a[i] - x) / k); + } + cout << ans << endl; + return 0; +} +const int maxn = 105; +int f[maxn]; +int main() { + f[1] = f[2] = 1; + for (int i = 3; i < maxn; i += 2) { f[i] = f[i + 1] = (i / 2) * i + (i / 2 + 1); } + int n; + while (cin >> n) { + if (n == 3) { + cout << 5 << endl; + continue; + } + for (int i = 1; i < maxn; i += 2) { + if (n <= f[i]) { + cout << i << endl; + break; + } + } + } + return 0; +} +const int MAX_N = 2e5 + 10, MOD = 1e9 + 7; +int Arr[MAX_N]; +bool Mark[MAX_N]; +string S, T; +string del(int tmp) { + for (int i = 1; i <= tmp; i++) Mark[Arr[i]] = true; + string res; + for (int i = 0; i < S.size(); i++) + if (!Mark[i]) res += S[i]; + for (int i = 1; i <= tmp; i++) Mark[Arr[i]] = false; + return res; +} +bool in(string tmp) { + int ind = 0; + for (int i = 0; i < tmp.size(); i++) + if (ind < T.size() && tmp[i] == T[ind]) ind++; + return (ind == T.size()); +} +int main() { + cin >> S >> T; + for (int i = 1; i <= S.size(); i++) { + cin >> Arr[i]; + Arr[i]--; + } + int s = 0, e = S.size(); + while (e - s > 1) { + int mid = e + s >> 1; + string tmp = del(mid); + if (in(tmp)) + s = mid; + else + e = mid; + } + cout << s << "\n"; + return 0; +} +inline void getInt(int *p); +long long n; +long long s[1050]; +long long d[1050]; +long long ans = 0; +int main() { + cin >> n; + long long now = 0; + for (int i = 1; i <= n; i++) { + cin >> s[i]; + cin >> d[i]; + while (s[i] <= now) { s[i] += d[i]; } + now = s[i]; + } + cout << now << endl; + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 122220 + ch - '0'; } + } +} +char v[200][200]; +int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; +int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; +int main() { + int a, b, c, d, e, f, g, h, i, j, k, mx, r[200]; + while (cin >> a >> b >> c) { + for (d = 1; d <= a; d++) { cin >> r[d]; } + f = 200; + for (d = b; d <= a; d++) { + if (r[d] <= c && r[d] != 0) { + g = abs(d - b); + if (g < f) { f = g; } + } + } + for (d = b - 1; d >= 1; d--) { + if (r[d] <= c && r[d] != 0) { + g = abs(d - b); + if (g < f) { f = g; } + } + } + cout << f * 10 << endl; + } + return 0; +} +int n, a[100010]; +long long ans, cnt; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i], cnt += a[i] % 2; + sort(a + 1, a + 1 + n, greater()); + for (int i = 1; i <= n; ++i) { + if (a[i] % 2 == 0) + ans += a[i]; + else { + if (ans % 2 && cnt >= 1) + ans += a[i], cnt--; + else if (ans % 2 == 0) + if (cnt >= 2) ans += a[i], cnt--; + } + } + cout << ans << endl; + return 0; +} +int table[100005]; +int main() { + int a, b, min; + long long int secs; + cin >> a >> b; + min = INT_MAX; + secs = 0; + int arr[a]; + for (int i = 0; i < a; i++) { + cin >> arr[i]; + if (arr[i] < min) { min = arr[i]; } + } + for (int i = 0; i < a; i++) { + if ((arr[i] - min) % b != 0) { + cout << "-1" << endl; + return 0; + } + } + for (int i = 0; i < a; i++) { secs += (arr[i] - min) / b; } + cout << secs << endl; +} +long long int max(long long int a, long long int b) { + if (a >= b) + return a; + else + return b; +} +long long int min(long long int a, long long int b) { + if (a >= b) + return b; + else + return a; +} +long long int diff(long long int a, long long int b) { + if (a >= b) + return a - b; + else + return b - a; +} +long long int mod(long long int a) { + if (a >= 0) + return a; + else + return -a; +} +void pairsort(int a[], int b[], int n) { + pair pairt[n]; + for (int i = 0; i < n; i++) { + pairt[i].first = a[i]; + pairt[i].second = b[i]; + } + sort(pairt, pairt + n); + for (int i = 0; i < n; i++) { + a[i] = pairt[i].first; + b[i] = pairt[i].second; + } +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n, m, ans; + cin >> n >> m; + ans = n + m - 1; + cout << ans << endl; + cout << 1 << " " << 1 << endl; + for (int i = 2; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + if (n < k || (k == 1 && n != 1)) + cout << -1 << endl; + else if (k == 1 && n == 1) + cout << 'a' << endl; + else { + for (int i = 1; i <= n - (k - 2); i++) { + if (i & 1) + cout << 'a'; + else + cout << 'b'; + } + int x = n - (k - 2); + char ch = 'c'; + for (int i = 1; i <= k - 2; i++) { cout << ch++; } + cout << endl; + } + return 0; +} +long long arr[1000000]; +int main() { + int n; + long long sum = 0, minn = 999999999, k; + cin >> n; + while (n--) { + cin >> k; + sum += k; + if (k % 2 == 1) { minn = min(minn, k); } + } + if (sum % 2 == 0) + cout << sum << endl; + else + cout << sum - minn << endl; +} +int main() { + long int n, x; + cin >> n >> x; + x = 7 - x; + if (n == 1) { + cout << "YES\n"; + return 0; + } + while (n--) { + long int l, r; + cin >> l >> r; + if (l == x || r == x || l + x == 7 || r + x == 7) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +const int maxn = 105; +int f[maxn]; +int main() { + f[1] = f[2] = 1; + for (int i = 3; i < maxn; i += 2) { f[i] = f[i + 1] = (i / 2) * i + (i / 2 + 1); } + int n; + while (cin >> n) { + if (n == 3) { + cout << 5 << endl; + continue; + } + for (int i = 1; i < maxn; i += 2) { + if (n <= f[i]) { + cout << i << endl; + break; + } + } + } + return 0; +} +const long long MaxN = 301002; +long long n; +string s; +int main() { + cin >> n; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; +} +long long a[100005]; +long long dp[100005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int cnt = 1; + dp[0] = a[0]; + for (int i = 0; i < n; i++) { + int ele = a[i] - 1; + if (a[i] == a[i - 1]) + cnt++; + else + cnt = 1; + int p = lower_bound(a, a + n, ele) - a; + dp[i + 1] = dp[i]; + if (p != 0) { dp[i + 1] = max(dp[i + 1], dp[p] + cnt * a[i]); } + dp[i + 1] = max(dp[i + 1], a[i] * cnt); + } + cout << dp[n] << endl; +} +long long a, x, n, s; +vector v; +int main() { + s == 0; + n == 0; + cin >> a; + for (int i = 1; i <= a; i++) { + cin >> x; + v.push_back(x); + n += x; + } + if (n % 2 == 0) { + cout << n << endl; + return 0; + } + sort(v.begin(), v.end()); + while (n % 2 != 0) { + int l = v[s] % 10; + if (l % 2 != 0) { n = n - v[s]; } + s++; + } + cout << n << endl; +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; i++) cout << ' ' << i; + cout << '\n'; +} +const int INF = 0x3f3f3f3f; +const int len = 2e3 + 4; +const long long mod = 1e9 + 7; +const ulong long seed = 131; +string ans, str; +int n; +int dfs(int i) { + if (i + 2 < n && str[i + 1] == 'g' && str[i + 2] == 'o') + return dfs(i + 2); + else + return i; +} +int main() { + cin >> n; + cin >> str; + for (int i = 0; i < n; ++i) { + int t = i; + if (str[i] == 'o') t = dfs(i); + if (t != i) + ans += "***", i = t; + else + ans += str[i]; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + int brr[n]; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + brr[i] = arr[i]; + } + sort(brr, brr + n); + int cnt = 0; + for (int i = 0; i < n; ++i) { + if (arr[i] != brr[i]) { ++cnt; } + } + if (cnt == 0 || cnt == 2) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +int main() { + long long n, k, c = 0, i; + cin >> n >> k; + long long a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 1; i < n; i++) { + if ((a[i] - a[0]) % k) { + cout << -1 << endl; + return 0; + } else + c += a[i] - a[0]; + } + cout << c / k << endl; + return 0; +} +bool x[100000]; +int main() { + bool no = 0; + int n, j = 1, i = 1, k = 1; + cin >> n; + x[1] = 1; + while (i < 100000) { + k += j; + if (k > n) { + k = k % n; + if (!k) { k = n; } + } + x[k] = 1; + i++; + j++; + } + for (int g = 1; g <= n; g++) { + if (!x[g]) { + no = 1; + break; + } + } + if (no) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int m; + cin >> m; + cout << (m & 1 ? m + 1 >> 1 & 1 : m >> 1 & 1) << '\n'; +} +int vis[1005][1005]; +int dx[4] = {0, 1, -1, 0}; +int dy[4] = {1, 0, 0, -1}; +void dfs(int x, int y) { + vis[x][y]--; + int px, py; + for (int i = 0; i < 4; i++) { + for (int j = 1; j < 1001; j++) { + px = x + dx[i] * j; + py = y + dy[i] * j; + if (px > 0 && px < 1001 && py > 0 && py < 1001 && vis[px][py] == 2) { dfs(px, py); } + } + } +} +int main() { + int n; + int x, y; + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < n; i++) { + cin >> x >> y; + vis[x][y] = 2; + } + int re = 0; + for (int i = 0; i < 1001; i++) { + for (int j = 0; j < 1001; j++) { + if (vis[i][j] == 2) { + dfs(i, j); + re++; + } + } + } + cout << re - 1 << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + if ((n * (n + 1) / 2) % 2 == 0) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else + cout << "Ehab" << endl; +} +int main() { + int arr[5], sum = 0; + for (int i = 0; i < 5; i++) { + cin >> arr[i]; + sum += arr[i]; + } + float ans = float(sum) / 5; + if (sum == 0) { + cout << -1 << endl; + } else if (ans == int(ans)) { + cout << int(ans) << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + int n, top, a, b; + cin >> n >> top; + int bottom = 7 - top; + bool isTrue = true; + while (n > 0) { + cin >> a >> b; + if (top == a || top == b || bottom == a || bottom == b) { + isTrue = false; + } else { + int temp = top; + top = bottom; + bottom = temp; + } + n--; + } + if (isTrue) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string input; + cin >> input; + string output = ""; + char maxm = input[input.size() - 1]; + output += input[input.size() - 1]; + for (int i = input.size() - 2; i >= 0; i--) + if (input[i] >= maxm) { + output = input[i] + output; + maxm = input[i]; + } + cout << output << endl; +} +const double EPS = 1e-9; +const double PI = 3.141592653589793238462; +const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1}; +const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1}; +const int dx[] = {1, 0, -1, 0}; +const int dy[] = {0, 1, 0, -1}; +int vis[1005]; +int main() { + int n; + cin >> n; + int cur = 0; + for (int i = 1; i <= n + n; i++) { + vis[cur] = 1; + cur = (cur + i) % n; + } + for (int i = 0; i < n; i++) { + if (!vis[i]) { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int i, n, dir; +long long m, now, nr, s, f, t; +int main() { + cin >> n >> m; + for (i = 1; i <= n; ++i) { + cin >> s >> f >> t; + dir = 0; + if (s == f) { + cout << t << '\n'; + continue; + } + now = (t / (2 * m)) * (2 * m - 2); + while (1) { + if (!dir) { + if (now + s - 1 >= t) { + now += s - 1; + if (s == m) dir = 1; + break; + } else { + dir = 1; + now += m - 1; + } + } else { + if (now + m - s >= t) { + now += m - s; + if (s == m) dir = 0; + break; + } else { + now += m - 1; + dir = 0; + } + } + } + if (!dir) { + if (s < f) + now += f - s; + else + now += m - s + m - f; + } else { + if (s > f) + now += s - f; + else + now += s + f - 2; + } + cout << now << '\n'; + } + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + x2 = abs(x1 - x2); + y2 = abs(y1 - y2); + cout << max(x2, y2) << endl; + return 0; +} +map T; +int main() { + int n, ans, x, y, k, i; + string cad; + map::iterator it; + cin >> n; + cin >> cad; + x = 0; + y = 0; + T.insert(pair(0, 1)); + for (i = 0; i < n; i++) { + if (cad[i] == 'R') + x++; + else if (cad[i] == 'L') + x--; + else if (cad[i] == 'U') + y++; + else if (cad[i] == 'D') + y--; + k = (x * 1000) + y; + it = T.find(k); + if (it == T.end()) + T.insert(pair(k, 1)); + else + it->second += 1; + } + ans = 0; + for (it = T.begin(); it != T.end(); it++) { + k = it->second; + ans += (k * (k - 1)) / 2; + } + cout << ans << '\n'; +} +int main() { + int n, m; + cin >> n >> m; + int l = 0, r = n + 1; + string _, s; + int k; + for (int i = 0; i < m; ++i) { + cin >> _ >> _ >> s >> _ >> k; + if (s == "left") { + r = min(r, k); + } else { + l = max(l, k); + } + } + int ans = r - l - 1; + if (ans <= 0) + cout << "-1\n"; + else + cout << ans << "\n"; + return 0; +} +int main() { + int r, c, row[11] = {0}, col[11] = {0}; + string s; + cin >> r >> c; + for (int i = 0; i < r; ++i) { + cin >> s; + for (int j = 0; j < c; ++j) { + if (s[j] == 'S') { + row[i] = 1; + col[j] = 1; + } + } + } + int cakes(0); + for (int i = 0; i < r; ++i) { + for (int j = 0; j < c; ++j) { + if (row[i] == 0 || col[j] == 0) { cakes += 1; } + } + } + cout << cakes << endl; + return 0; +} +int main() { + string s; + int n, i, j, k, last; + char ch; + cin >> s; + n = s.length(); + last = -1; + for (ch = 'z'; ch >= 'a'; ch--) { + for (i = 0; i < n; i++) { + if ((s[i] == ch) && (i > last)) { + cout << ch; + last = i; + } + } + } + cout << "\n"; + return 0; +} +int main() { + char ch[1000]; + gets(ch); + if (ch[0] >= 'a' && ch[0] <= 'z') ch[0] = ch[0] - 32; + puts(ch); +} +int main() { + int a; + cin >> a; + if (a % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +long long c, v0, v1, a, l; +void input() { + cin >> c >> v0 >> v1 >> a >> l; +} +int main() { + input(); + long long speed = v0; + long long cur = 0; + long long ans = 0; + while (cur < c) { + if (cur) cur -= l; + cur += speed; + speed = min(speed + a, v1); + ans++; + } + cout << ans << "\n"; +} +const int maxn = 3e5 + 10; +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << endl; } + return 0; +} +long long n, k, divi[10000005]; +stack has; +int main() { + cin >> n >> k; + long long temp = 1, a = 1; + while (temp <= sqrt(n)) { + if (n % temp == 0) { + divi[a] = temp; + if (divi[a] != n / temp) { has.push(n / temp); } + a++; + } + temp++; + } + if (a <= k) { + while (!has.empty()) { + divi[a] = has.top(); + has.pop(); + a++; + } + } + if (a <= k) + cout << "-1" << endl; + else + cout << divi[k] << endl; +} +int main() { + int players, cleaner; + int fingers, tfingers = 0; + int ways = 0; + cin >> players; + for (int i = 0; i < players; i++) { + cin >> fingers; + tfingers += fingers; + } + players++; + for (int i = 1; i <= 5; i++) { + if ((tfingers + i) % players != 1) { ways++; } + } + cout << ways << endl; + return 0; +} +int k, l; +int main() { + cin >> k >> l; + int a = 1; + if (l % k != 0) { + cout << "NO" << endl; + } else if (l != k) { + while (l != k) { + if (l % k != 0) { + cout << "NO" << endl; + break; + } else { + l /= k; + a++; + } + if (l == k) { cout << "YES" << endl << a - 1 << endl; } + } + } else if (l == k) { + cout << "YES" << endl << 0 << endl; + } + return 0; +} +int k, l, n; +int main() { + cin >> k >> l; + while (l > 1) { + if (l % k != 0) { + cout << "NO" << endl; + return 0; + } + l /= k; + ++n; + } + cout << "YES" << endl << n - 1 << endl; + return 0; +} +vector v; +int num[51], value[51]; +int main() { + int n, index = 1; + cin >> n; + for (int i = 0; i < n; i++) { cin >> num[i]; } + v.push_back(num[n - 1]); + for (int i = n - 2; i >= 0; i--) { + int j = 0, flag = 0; + while (j < v.size()) { + if (num[i] == v[j]) { + flag = 1; + break; + } + j++; + } + if (!flag) v.push_back(num[i]); + } + cout << v.size() << endl; + cout << v[v.size() - 1]; + for (int i = v.size() - 2; i >= 0; i--) cout << " " << v[i]; + cout << endl; +} +string reverse(string mystr) { + string str; + for (int i = mystr.length() - 1; i >= 0; i--) str += mystr[i]; + return str; +} +int main() { + string str; + cin >> str; + int c = count(str.begin(), str.end(), str[0]); + if (str.length() == c) { + cout << 0 << endl; + return 0; + } + for (int i = str.length(); i > 0; i--) { + string ms; + for (int j = 0; j < i; j++) ms += str[j]; + if (reverse(ms) != ms) { + cout << i << endl; + return 0; + } + } +} +int main() { + int r, c; + cin >> r >> c; + vector rows(r, true); + vector cols(c, true); + char mat[r][c]; + for (int i = 0; i < r; i++) { + string s; + cin >> s; + for (int j = 0; j < s.length(); j++) { + mat[i][j] = s[j]; + if (s[j] == 'S') { rows[i] = false; } + } + } + for (int j = 0; j < c; j++) { + for (int i = 0; i < r; i++) { + if (mat[i][j] == 'S') { cols[j] = false; } + } + } + int ans = 0; + for (int i = 0; i < rows.size(); i++) { + if (rows[i]) { + for (int j = 0; j < c; j++) { mat[i][j] = 'x'; } + } + } + for (int j = 0; j < cols.size(); j++) { + if (cols[j]) { + for (int i = 0; i < r; i++) { mat[i][j] = 'x'; } + } + } + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (mat[i][j] == 'x') { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, x; + cin >> n; + vector cnt(100001, 0); + for (long long i = 0; i < n; i++) { + cin >> x; + cnt[x]++; + } + long long dp[100001]; + dp[0] = 0; + dp[1] = cnt[1]; + for (long long i = 2; i < 100001; i++) dp[i] = max(dp[i - 1], dp[i - 2] + (cnt[i] * i)); + cout << dp[100000] << endl; + return 0; +} +int main() { + float r, g, b; + cin >> r >> g >> b; + r = ceil(r / 2); + g = ceil(g / 2); + b = ceil(b / 2); + if (b >= g && b >= r) cout << (b * 3) + 29 << endl; + if (g > b && g >= r) cout << (g * 3) + 28 << endl; + if (r > b && r > g) cout << (r * 3) + 27 << endl; + return 0; +} +int main() { + int x, c = 0; + cin >> x; + string arr; + for (int i = 0; i < x; i++) { + cin >> arr; + if (arr[0] == '+' || arr[1] == '+') + c++; + else if (arr[0] == '-' || arr[1] == '-') + c--; + } + cout << c << endl; + return 0; +} +int main() { + int n, k, zzz; + cin >> n >> k; + if (n < k || (k == 1 && n != 1)) + cout << -1 << endl; + else if (k == 1 && n == 1) + cout << 'a' << endl; + else { + for (int i = 1; i <= n - (k - 2); i++) { + if (i & 1) + cout << 'a'; + else + cout << 'b'; + } + int x = n - (k - 2); + char ch = 'c'; + for (int i = 1; i <= k - 2; i++) { cout << ch++; } + cout << endl; + } + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int x = abs(x2 - x1), y = abs(y2 - y1); + int dx, dy; + cin >> dx >> dy; + if (x % dx || y % dy || (x / dx + y / dy) % 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int a[105], b[105], n, x, i; +int main() { + cin >> n; + cin >> x; + for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (i = 2; i <= n; i++) { + if (a[i] != x && b[i] != x && (7 - a[i]) != x && (7 - b[i]) != x) { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int long long a[200005], b[200005], v[200005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + cin >> b[i]; + v[b[i]] = i; + } + for (int i = 0; i < n; i++) a[i] = v[a[i]]; + int i1 = 0; + while (a[i1] < a[i1 + 1]) i1++; + cout << n - i1 - 1 << endl; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n2 >= n1) { + cout << "Second" << '\n'; + } else { + cout << "First" << '\n'; + } + return 0; +} +int main() { + map m; + map::iterator it; + int n, k; + cin >> n >> k; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + m[arr[i]]++; + } + int maxx = 0; + for (it = m.begin(); it != m.end(); it++) { + if (it->second > maxx) { maxx = it->second; } + } + int temp; + if (maxx % k == 0) { + temp = (maxx / k); + } else { + temp = (maxx / k) + 1; + } + int val = k * temp; + int ans = 0; + for (it = m.begin(); it != m.end(); it++) { ans += (val - it->second); } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int len = a.length(); + int cnta, cntb, nq; + cnta = cntb = nq = 0; + for (int i = 0; i < len; i++) { + if (a[i] == '4') cnta++; + if (b[i] == '4') cntb++; + if (a[i] != b[i]) nq++; + } + int ans = 0; + ans += abs(cnta - cntb); + nq -= abs(cnta - cntb); + ans += nq / 2; + cout << ans << endl; +} +const int inf = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double pi = acos(-1.0); +const double eps = 1e-15; +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int cnt = 1, read = v0; + if (v0 >= c) { + cout << cnt << endl; + return 0; + } else + while (true) { + v0 = min(v0 + a, v1); + read += v0 - l; + cnt++; + if (read >= c) break; + } + cout << cnt << endl; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + sort(a.begin(), a.end()); + cout << a << endl; + return 0; +} +int main() { + string m; + getline(cin, m); + if (m[0] >= 97 && m[0] <= 122) m[0] = (int)m[0] - 32; + cout << m << endl; +} +int main() { + string input; + cin >> input; + if (input[0] >= 'a') input[0] -= 32; + cout << input << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + bool ans = true; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) { ans = false; } + } + if (ans) { + cout << "EASY" << endl; + } else { + cout << "HARD" << endl; + } +} +int main() { + long long n, k, p, o; + cin >> n >> k; + if (n % 2 == 0) { + p = n / 2; + } else { + p = n / 2 + 1; + } + if (k <= p) { + o = (k * 2) - 1; + } else { + o = (k - p) * 2; + } + cout << o << endl; + return 0; +} +int mo(int n) { + int p = 1; + while (n--) p = p * 2; + return p; +} +bool fun(string s, string p) { + if (s.size() < p.size()) return false; + int i = 0, j = 0; + while (i < s.size() && j < p.size()) { + if (s[i] == p[j]) { + i++; + j++; + } else + i++; + } + if (p.size() == j) + return true; + else + return false; +} +bool cm(vector v1, vector v2) { + if (v1[0] != v2[0]) + return v1[0] > v2[0]; + else + return v1[1] < v2[1]; +} +int main() { + int n, m; + cin >> n >> m; + cout << n - 1 + m - 1 + 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return 0; +} +int main() { + int n, m, k, buff = 0; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " L" << endl; + break; + } + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " R" << endl; + break; + } + } + if (buff == k) break; + } + return 0; +} +int k; +int main() { + cin >> k; + cout << "+------------------------+" << endl; + for (int i = 0; i < 4; i++) { + cout << "|"; + if (i < k) + cout << "O."; + else + cout << "#."; + for (int j = 1; j <= 10; j++) { + if (i == 2) + cout << ".."; + else { + int ii; + if (!i || i == 1) ii = i + 1; + if (i == 2) ii = 2; + if (i == 3) ii = 3; + if (4 + (3 * (j - 1)) + ii <= k) + cout << "O."; + else + cout << "#."; + } + } + if (i == 0) + cout << "|D|)\n"; + else if (i == 3) + cout << "|.|)\n"; + else if (i == 2) + cout << "..|\n"; + else + cout << "|.|\n"; + } + cout << "+------------------------+" << endl; +} +int N, ans, A, k, x, y, z; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> A; + ans += A; + } + N++; + for (int i = 1; i < 6; i++) { + if ((ans + i) % N != 1) x++; + } + cout << x << '\n'; +} +int main() { + long long int n, a, b, c, m, min; + cin >> m >> a >> b >> c; + n = m % 4; + if (n == 0) + min = 0; + else if (n == 1) { + min = 3 * a; + if (min > c) min = c; + if (min > a + b) min = a + b; + if (min > 2 * b + c) min = 2 * b + c; + if (min > 3 * c + b) min = 3 * c + b; + } else if (n == 2) { + min = 2 * a; + if (min > b) min = b; + if (min > 2 * c) min = 2 * c; + if (min > 3 * c + a) min = 3 * c + a; + } else if (n == 3) { + min = a; + if (min > 3 * c) min = 3 * c; + if (min > b + c) min = b + c; + } + cout << min << endl; + return 0; +} +int main() { + string s, f = ""; + cin >> s; + vector v; + string s1 = s; + for (int i = 0; i < s.size(); i++) { + f = ""; + v.push_back(s1); + f += s1[s1.size() - 1]; + s1.erase(s.size() - 1, 1); + s1 = f + s1; + } + sort(v.begin(), v.end()); + v.resize(unique(v.begin(), v.end()) - v.begin()); + cout << v.size() << "\n"; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" << endl; + } else + cout << "Second" << endl; + return 0; +} +int main() { + string a; + int n, ans = 0; + cin >> n; + cin >> a; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j += 2) { + string t = a.substr(i, j - i + 1); + int r, u; + r = count(t.begin(), t.end(), 'R') - count(t.begin(), t.end(), 'L'); + u = count(t.begin(), t.end(), 'U') - count(t.begin(), t.end(), 'D'); + if (!r && !u) ans++; + } + } + cout << ans << endl; + return 0; +} +long long t, l, r, d; +void Result() { + cin >> t; + while (t--) { + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else + cout << ((r / d) + 1) * d << endl; + } +} +int main() { + Result(); + return 0; +} +int main() { + long long n, a, b, c, i; + cin >> n >> a >> b >> c; + i = n % 4; + if (!i) + cout << 0 << endl; + else if (i == 3) { + if (3 * c >= a && 3 * c >= b + c) { + if (a < b + c) + cout << a << endl; + else + cout << b + c << endl; + } else if (a > 3 * c && a > b + c) { + if (b + c < 3 * c) + cout << b + c << endl; + else + cout << 3 * c << endl; + } else if (b + c > 3 * c && b + c >= a) { + if (a < 3 * c) + cout << a << endl; + else + cout << 3 * c << endl; + } + } else if (i == 2) { + if (2 * c >= 2 * a && 2 * c >= b) { + if (2 * a < b) + cout << 2 * a << endl; + else + cout << b << endl; + } else if (2 * a > 2 * c && 2 * a > b) { + if (2 * c < b) + cout << 2 * c << endl; + else + cout << b << endl; + } else if (b > 2 * c && b >= 2 * a) { + if (2 * c < 2 * a) + cout << 2 * c << endl; + else + cout << 2 * a << endl; + } + } else if (i == 1) { + if (c >= 3 * a && c >= a + b) { + if ((3 * a) < (a + b)) + cout << 3 * a << endl; + else + cout << (a + b) << endl; + } else if (3 * a > c && 3 * a > a + b) { + if (c < (a + b)) + cout << c << endl; + else + cout << a + b << endl; + } else if (a + b >= 3 * a && a + b > c) { + if (3 * a < c) + cout << 3 * a << endl; + else + cout << c << endl; + } + } + return 0; +} +int n; +int main() { + cin >> n; + if (n % 2 != 0) + cout << "Ehab\n"; + else + cout << "Mahmoud\n"; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int k = 2, cnt = 0; + while (k <= n) { + for (int i = 0; i <= n - k; i++) { + int H = 0, V = 0; + for (int j = i; j < i + k; j++) { + if (s[j] == 'U') V++; + if (s[j] == 'D') V--; + if (s[j] == 'R') H++; + if (s[j] == 'L') H--; + } + if (H == 0 && V == 0) cnt++; + } + k += 2; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[110]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int mini = 100000000; + for (int i = 0; i < n; i++) { + int cnt = 0; + for (int j = 0; j < arr[i]; j++) { + int x; + cin >> x; + cnt += x * 5 + 15; + } + mini = min(mini, cnt); + } + cout << mini << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (k > n || (k == 1 && n > 1)) + cout << -1 << endl; + else if (k == 1) { + cout << 'a' << endl; + } else { + long long x = n - (k - 2); + string str = ""; + long long i = 0; + while (i < x) { + if (i % 2 == 0) + str += "a"; + else + str += "b"; + i++; + } + for (long long i = 2; i < k; i++) { + char ch = (i + 'a'); + str += ch; + } + cout << str << endl; + } + return 0; +} +long long arr[100005]; +int main() { + long long n, k; + cin >> n >> k; + long long mn = 10000000000; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + mn = min(mn, arr[i]); + } + long long ans = 0; + for (int i = 0; i < n; i++) { + if ((arr[i] - mn) % k != 0) { + ans = -1; + break; + } + ans += (arr[i] - mn) / k; + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + double x, y, x0, y0, total(0.0); + cin >> x0 >> y0; + while (--n) { + cin >> x >> y; + total += sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)); + x0 = x; + y0 = y; + } + cout << fixed << setprecision(6) << total * k / 50 << endl; + return 0; +} +const long long N = 1e8 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, l, a, t, l1, cnt, c, q; +string s1, s; +pair pr[1001]; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> n; + n %= 4; + if (n == 0 or n == 3) + cout << 0; + else if (n == 1 or n == 2) + cout << 1; + cout << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int cnt = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + 1 + n); + if (n == 1 || n == 2) + cout << 0 << endl; + else if (n >= 3) { + int minn = a[1]; + int mixx = a[n]; + for (int i = 2; i <= n - 1; i++) { + if (a[i] > minn && a[i] < mixx) cnt++; + } + cout << cnt << endl; + } + return 0; +} +const int mod = 1e9 + 7; +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int now = v0; + int cnt = 1; + while (now < c) { + v0 = v0 + a; + if (v0 >= v1) v0 = v1; + now += (v0 - l); + cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int c, v0, v1, a, l, cnt = 1; + cin >> c >> v0 >> v1 >> a >> l; + c = c - v0; + while (c > 0) { + cnt++; + v0 = v0 + a; + c = c - (min(v0, v1) - l); + } + cout << cnt << endl; + return 0; +} +int main() { + int n, m, menor = 1000000000, opr = 0; + cin >> n; + int v[n + 1]; + for (int i = 1; i <= n; i++) { cin >> v[i]; } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= v[i]; j++) { + cin >> m; + opr += m * 5; + } + opr += (15 * v[i]); + if (opr < menor) menor = opr; + opr = 0; + } + cout << menor << endl; + return 0; +} +int arr[1005]; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + ans += 2; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + m *= 2; + for (int i = 0; i < n - 1; i++) { + int x = arr[i], y = arr[i + 1]; + if (y - x == m) { + ans += 1; + } else if (y - x > m) { + ans += 2; + } + } + cout << ans << endl; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long a, b; + cin >> a >> b; + long long c = pow(a * b, 1.0 / 3.0); + while (c * c * c < a * b) c++; + while (c * c * c > a * b) c--; + if (c * c * c == a * b && a % c == 0 && b % c == 0) { + cout << "Yes\n"; + } else { + cout << "No\n"; + } + } + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + cout << (n1 > n2 ? "First" : "Second") << '\n'; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +void hora(int tc) { + int n; + cin >> n; + long long tot = 0; + for (long long i = 1; i <= n; i++) { + long long x; + cin >> x; + tot += (i) * (x - 1) + 1; + } + cout << tot << '\n'; +} +int main() { + desperate_optimization(10); + int ntc = 1; + for (int tc = 1; tc <= ntc; tc++) hora(tc); + return 0; +} +int people[105]; +int count[105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> people[i]; } + int t = 99999999; + int total = 0, tmp; + for (int i = 0; i < n; i++) { + total = 0; + for (int j = 0; j < people[i]; j++) { + cin >> tmp; + total += tmp * 5; + } + total += (people[i]) * 15; + if (total < t) t = total; + } + cout << t << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 0; i < n;) { + if (i < n - 2 && s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + for (i += 3; i < n; i += 2) { + if (i >= n - 1 || s[i] != 'g' || s[i + 1] != 'o') break; + } + cout << "***"; + } else { + cout << s[i]; + i++; + } + } + cout << endl; + return 0; +} +int main() { + long long cnt = 0; + long long c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + while (true) { + cnt++; + c -= v0; + if (v0 < v1) v0 += a; + if (v0 > v1) v0 = v1; + if (c <= 0) break; + c += l; + } + cout << cnt << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int i, j, k = 0; + char c; + int cont = 0; + int rcont = 0, ucont = 0; + for (i = 0; i < n; i++) { + string a; + ucont = 0; + rcont = 0; + for (j = i; j < n; j++) { + c = s[j]; + if (c == 'L') + rcont++; + else if (c == 'U') + ucont++; + else if (c == 'R') + rcont--; + else + ucont--; + if (rcont == 0 && ucont == 0) { cont++; } + } + } + cout << cont << endl; + return 0; +} +string a, another; +long long res, len, k, cnt1, cnt2; +int main() { + cin >> a; + res = 0; + len = a.size(); + cin >> k; + for (long long i = 0; i < k; i++) { + cin >> another; + cnt1 = cnt2 = 0; + for (int j = 0; j < len; j++) { + if (a[j] == another[0]) + cnt1++; + else if (a[j] == another[1]) + cnt2++; + else { + res += min(cnt1, cnt2); + cnt1 = cnt2 = 0; + } + } + res += min(cnt1, cnt2); + } + cout << res << endl; + return 0; +} +int main() { + long long a, b, x, y, z; + cin >> a >> b >> x >> y >> z; + long long yellow = 2 * x + y; + long long blue = y + 3 * z; + long long res = 0; + if (a < yellow) res += (yellow - a); + if (b < blue) res += (blue - b); + cout << res << "\n"; + return 0; +} +void func1() { + int n, m; + cin >> n >> m; + int s = m + n - 1; + cout << s << endl; + for (int i = 1; i <= m; i++) { cout << 1 << " " << i << endl; } + if (n > 1) { + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << endl; } + } +} +int main() { + func1(); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int res = 0, lst = 1, lste = 0; + bool tr = true; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + bool one = false; + for (int j = 0; j < x; j++) { + int y; + cin >> y; + if (y == lst && tr) { + lst = y + 1; + one = true; + } + } + if (one) { + tr = false; + lste = lst - 1; + res += x - (lst - 1); + } else { + res += x - 1; + } + } + cout << res + (n - lste) << endl; + return 0; +} +int remove_zeros(int a) { + int ret = 0, ten = 1; + while (a > 0) { + int digit = a % 10; + a /= 10; + if (digit != 0) { + ret += digit * ten; + ten *= 10; + } + } + return ret; +} +int main() { + long long a, b; + cin >> a >> b; + long long c = a + b; + long long x, y, z; + x = remove_zeros(a); + y = remove_zeros(b); + z = remove_zeros(c); + if (x + y == z) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a[100]; + int n, m, k, i, minn = 100000; + cin >> n >> m >> k; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = --m; i < n; i++) { + if (a[i] != 0 && a[i] <= k) { + minn = min(i - m, minn); + break; + } + } + for (i = m; i >= 0; i--) { + if (a[i] != 0 && a[i] <= k) { + minn = min(m - i, minn); + break; + } + } + cout << minn * 10 << endl; + return 0; +} +int a[100], x, sum = 0; +int main() { + cin >> x; + for (int z = 0; z < x; z++) { + cin >> a[z]; + sum = sum + a[z]; + } + if (sum == 0) { + cout << "EASY" << endl; + } else { + cout << "HARD" << endl; + } +} +int main() { + int x, y, a, b; + while (cin >> x >> y >> a >> b) { + int n = abs(x - a); + int m = abs(y - b); + int q = max(n, m); + cout << q << endl; + } +} +int main() { + int a, b; + int ans = 0; + cin >> a >> b; + while (a <= b) { + a = a * 3; + b = b * 2; + ans++; + } + cout << ans << "\n"; +} +int main() { + int x1, y1, x2, y2, x, y, x3, y3; + cin >> x1 >> y1 >> x2 >> y2; + x3 = abs(x1 - x2); + y3 = abs(y1 - y2); + cin >> x >> y; + if (x3 % x == 0 && y3 % y == 0 && (x3 / x) % 2 == (y3 / y) % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, sum, m; + cin >> n; + vector vec1(n); + for (int i = 0; i < n; i++) cin >> vec1[i]; + vector vec2; + for (int i = 0; i < n; i++) { + sum = 0; + for (int j = 0; j < vec1[i]; j++) { + cin >> m; + sum += m * 5; + } + sum += 15 * vec1[i]; + vec2.push_back(sum); + } + sort(vec2.begin(), vec2.end()); + cout << vec2[0] << endl; + return 0; +} +long long int n, a, b, c; +int main() { + cin >> n >> a >> b >> c; + int req = (4 - n % 4), ans = 0; + if (req == 1) + ans = min(min(a, b + c), 3 * c); + else if (req == 2) + ans = min(min(2 * a, b), 2 * c); + else if (req == 3) + ans = min(min(3 * a, a + b), c); + cout << ans << '\n'; + return 0; +} +int a[100001]; +int main() { + int n, d; + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> a[i]; + int sum = 2; + for (int i = 1; i <= n; i++) { + if (a[i] - d > a[i - 1] + d && i >= 2) sum++; + if (a[i] + d <= a[i + 1] - d && i <= n - 1) sum++; + } + cout << sum << endl; + return 0; +} +long long x, y, z = 1; +string s, ss; +int main() { + cin >> x >> s; + for (int i = 0; i < x;) { + ss += s[i]; + i += z; + z++; + } + cout << ss << endl; + return 0; +} +long long arr[1000000]; +set ss; +map mm; +char ch[100000]; +int main() { + string s; + getline(cin, s); + for (int i = 1; i < s.length() - 1; i += 3) ss.insert(s[i]); + cout << ss.size() << endl; +} +int main() { + int A, B, C, D; + cin >> A >> B >> C >> D; + if ((A * 2 + 3 > D && D + 1 >= A) || (B * 2 + 3 > C && C + 1 >= B)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + int a, b, c, d; + a = abs(x1 - x2); + b = abs(y1 - y2); + c = a / x; + d = b / y; + c %= 2; + d %= 2; + if (a % x == 0 && b % y == 0 && c == d) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n, m, a, b; + cin >> n >> m >> a >> b; + vector v; + if (b >= m * a) + cout << n * a << '\n'; + else { + long long c = n / m; + long long ans = c * b; + n -= c * m; + ans += min(b, a * n); + cout << ans << '\n'; + } + } + return 0; +} +int main() { + int n, n2, k, k2; + cin >> n >> n2 >> k >> k2; + while (true) { + n -= 1; + if (n == 0) { + cout << "Second" << endl; + return 0; + } + n2 -= 1; + if (n2 == 0) { + cout << "First" << endl; + return 0; + } + } +} +int main() { + int n; + cin >> n; + if (n % 2 == 1) { + cout << -1 << endl; + } else { + cout << "2 1"; + for (int i = 3; i < n; i += 2) { cout << " " << i + 1 << " " << i; } + cout << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int sum = 0, l; + char s[100000]; + getchar(); + gets(s); + for (int i = n; i < strlen(s); i += n) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) sum++; + } + cout << sum << endl; + } + return 0; +} +int main() { + int x1, x2, y1, y2, x, y, z, l, q, r; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + l = abs(x1 - x2); + r = abs(y1 - y2); + if (l % x == 0 && r % y == 0 && (l / x) % 2 == (r / y) % 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int oo = 1e9; +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << '\n'; + return 0; +} +int main() { + int n, k = 0; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) k++; + } + cout << k << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud\n"; + else + cout << "Ehab\n"; +} +int main() { + int x, y, z, t1, t2, t3, st, el; + cin >> x >> y >> z >> t1 >> t2 >> t3; + st = abs(x - y) * t1; + el = (abs(x - z) + abs(x - y)) * t2 + t3 * 3; + if (el <= st) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +double mpow(int b) { + double ans = 1.0; + for (int i = 0; i < b; i++) { ans = ans * 1.5; } + return ans; +} +int main() { + double a, b, x = 0.0; + cin >> a >> b; + x = b / a; + for (int i = 1; i > 0; i++) { + if (mpow(i) > x) { + cout << i << endl; + break; + } + } + return 0; +} +int ans[120]; +int from[120]; +int posx[120]; +int posy[120]; +int n; +void dfs(int x, int cot) { + from[x] = cot; + for (int i = 0; i < n; i++) { + if (!from[i] && (posx[x] == posx[i] || posy[x] == posy[i])) dfs(i, cot); + } +} +int main() { + cin >> n; + memset(from, 0, sizeof from); + for (int i = 0; i < n; i++) { cin >> posx[i] >> posy[i]; } + int cot = 0; + for (int i = 0; i < n; i++) { + if (!from[i]) { + cot++; + dfs(i, cot); + } + } + cout << cot - 1 << endl; + return 0; +} +int main() { + double a, b; + cin >> a >> b; + cout << floor(log(b / a) / log(1.500)) + 1 << endl; + return 0; +} +int main() { + char a[2005]; + int n, d = 0; + cin >> n; + cin >> a; + for (int i = 0; i < strlen(a); i += n) { + if (i >= 4) { + if (a[i - 1] == a[i - 2] && a[i - 2] == a[i - 3]) { d++; } + } + } + cout << d << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0, len = s.length() - 2; i < len; i++) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + int j = i + 3; + while (s[j] == 'g' && s[j + 1] == 'o') j += 2; + s = s.substr(0, i) + "***" + s.substr(j); + len = s.length() - 2; + } + } + cout << s << endl; +} +int main() { + set s; + string str; + getline(cin, str); + for (int i = 0; i < str.length(); i++) + if (str[i] != ' ' && str[i] != '{' && str[i] != '}' && str[i] != ',') s.insert(str[i]); + cout << s.size() << endl; + return 0; +} +int a[1005][1005]; +int vis[1005][1005]; +int main() { + int r, c; + cin >> r >> c; + string s[1000]; + int i, j; + for (i = 0; i < r; i++) { cin >> s[i]; } + memset(a, 0, sizeof(a)); + memset(vis, 0, sizeof(vis)); + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + if (s[i][j] == 'S') a[i][j] = 1; + } + } + int ans = 0; + int flag = 0; + for (i = 0; i < r; i++) { + flag = 0; + for (j = 0; j < c; j++) { + if (a[i][j] == 1) { flag = 1; } + } + if (flag == 0) { + for (j = 0; j < c; j++) { + if (a[i][j] == 0) ans++; + a[i][j] = 2; + } + } + } + for (j = 0; j < c; j++) { + flag = 0; + for (i = 0; i < r; i++) { + if (a[i][j] == 1) flag = 1; + } + if (flag == 0) { + for (i = 0; i < r; i++) { + if (a[i][j] == 0) ans++; + a[i][j] = 2; + } + } + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + vector v(n, 1e9); + v[0] = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + for (int j = max(0, i - k); j < i; j++) { + if (s[j] == '1') v[i] = min(v[i], v[j] + 1); + } + } + } + int res = v[n - 1]; + if (res == 1e9) res = -1; + cout << res << endl; + return 0; +} +long long L, B, answer; +int main() { + cin >> L >> B; + while (1) { + if (L > B) break; + answer++; + L *= 3; + B *= 2; + } + cout << answer << endl; + return 0; +} +int main() { + int n; + string s; + int t, flag = 0; + cin >> n >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] > s[i + 1]) { + flag = 1; + t = i; + break; + } + } + if (flag == 0) { + for (int i = 0; i < s.length() - 1; i++) { cout << s[i]; } + cout << endl; + } else { + for (int i = 0; i < s.length(); i++) { + if (i == t) continue; + cout << s[i]; + } + cout << endl; + } + return 0; +} +int main() { + int n, m; + bool row[12], col[12]; + for (int i = 0; i < 12; i++) { + row[i] = true; + col[i] = true; + } + char t[12][12]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> t[i][j]; + if (t[i][j] == '.') continue; + row[i] = false; + col[j] = false; + } + } + int x = 0, y = 0; + for (int i = 0; i < n; i++) + if (row[i] == true) x++; + for (int j = 0; j < m; j++) + if (col[j] == true) y++; + cout << (x * m) + (y * n) - (x * y) << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; + return 0; +} +int i, c, len = 4; +long a[4]; +int main() { + for (i = 0; i < len; ++i) { cin >> a[i]; } + for (i = 0; i < len - 1; ++i) { + for (int j = i + 1; j < len; ++j) { + if (a[i] == a[j]) { + ++c; + break; + } + } + } + cout << c << endl; + return 0; +} +inline int sq(int x) { + return x * x; +} +int main() { + int a[11]; + for (int i = 0; i < 6; i++) cin >> a[i]; + int ans = sq(a[0] + a[1] + a[2]); + ans -= sq(a[0]) + sq(a[2]) + sq(a[4]); + cout << ans << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + int i = 1; + while (true) { + if (n1 <= 0) { + cout << "Second\n"; + return 0; + } + if (n2 <= 0) { + cout << "First\n"; + return 0; + } + if (i % 2 == 1) + n1--; + else + n2--; + i++; + } +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + sort(str.begin(), str.end()); + cout << str << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int sum = 0; + string s; + cin >> s; + for (int i = n; i < s.size(); i += n) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) sum++; + } + cout << sum << endl; + } + return 0; +} +const int inf = 0x3f3f3f3f; +long long a; +string s; +int main() { + int n; + cin >> n; + cin >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + long long int a, b, c; + cin >> a >> b >> c; + if (c < a) { + cout << c << endl; + } else { + cout << c * (b / c + 1) << endl; + } + } +} +int main() { + int n, x = 0, y = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + if (a == 1) + x++; + else + y++; + } + if (x < y) + cout << x << endl; + else + cout << y + (x - y) / 3 << endl; + return 0; +} +int main() { + long long int n, t, m, k; + long long int x, y, z; + long long int a, b; + cin >> a >> b; + cin >> x >> y >> z; + long long int yn, bn; + yn = (x * 2 + y); + long long int dif = yn - a; + long long int need = 0; + if (dif >= 0) need += dif; + bn = (y + z * 3); + dif = (bn - b); + if (dif >= 0) need += dif; + cout << need << endl; + return 0; +} +int main() { + long long n, sum = 0; + cin >> n; + long long a[n]; + long long b[n]; + for (long long i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (long long i = 0; i < n; i++) { cin >> b[i]; } + sort(b, b + n); + cout << (b[n - 2] + b[n - 1] >= sum ? "YES" : "NO") << '\n'; + return 0; +} +int main() { + int n; + string raw; + while (cin >> n >> raw) { + int quotient = raw.size() / n, ans = 0; + for (int i = 1; i <= quotient; i++) { + int up = i * n; + if (up >= raw.size()) break; + if (raw[up - 3] == raw[up - 2] && raw[up - 2] == raw[up - 1]) ++ans; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, i, sum = 0, k = 0; + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (i = 1; i <= 5; i++) { + if ((sum + i) % (n + 1) != 1) k++; + } + cout << k << endl; +} +int main() { + int n, i, j, l; + cin >> n; + int a[n], b[n]; + int c = 0; + for (i = 0; i < n; i++) { + cin >> j; + a[i] = j; + b[i] = j; + } + sort(a, a + n); + for (i = 0; i < n; i++) { + if (a[i] != b[i]) c++; + } + if (c <= 2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + char x[100]; + cin.get(x, 100); + int len = strlen(x); + int i = 0, j = len - 1; + int sol; + while (i <= j) { + if (x[i] != x[j]) { + cout << len << '\n'; + return 0; + } + i++; + j--; + } + for (i = 1; i < len; i++) + if (x[i] != x[0]) { + cout << len - 1 << '\n'; + return 0; + } + cout << 0 << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1" << endl; + return 0; + } + if (n == 2) { + cout << "3" << endl; + return 0; + } + if (n == 3) { + cout << "5" << endl; + return 0; + } + if (n % 4 == 0) { + n /= 4; + for (int i = 1; i <= 100000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 1) { + n /= 4; + for (int i = 1; i <= 100000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 2) { + for (int i = 1; i <= 100000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 3) { + n--; + for (int i = 1; i <= 100000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + return 0; +} +bool solve(int a, int b) { + return a <= b + 1 && b <= (a + 1) * 2; +} +int main() { + int la, ra, lb, rb; + cin >> la >> ra >> lb >> rb; + if (solve(la, rb) || solve(ra, lb)) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +int n, a, b, x; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x == 1) + a++; + else + b++; + } + cout << max(min(a, b) + (a - min(a, b)) / 3, a / 3) << endl; +} +int main() { + int c, v0, v1, a, l, res = 1; + cin >> c >> v0 >> v1 >> a >> l; + c -= v0; + while (c > 0) { + res++; + v0 = v0 + a >= v1 ? v1 : v0 + a; + c -= v0 - l; + } + cout << res << endl; + return 0; +} +long long num[100010]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + long long sum = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum += a; + } + for (int i = 0; i < n; i++) { cin >> num[i]; } + sort(num, num + n, cmp); + if (num[0] + num[1] >= sum) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long n; + cin >> n; + long long ans = 0; + for (int i = 0; i < n; i++) { + long long a; + cin >> a; + ans += (i + 1) * (a - 1) + 1; + } + cout << ans << endl; +} +int n, f; +bool b[1003]; +int main() { + cin >> n; + f = 0; + for (int i = 1; i <= 1000000; ++i) { + b[f] = 1; + f = (f + i) % n; + } + for (int i = 0; i < n; ++i) { + if (!b[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; +} +int main() { + int n, m, k = 0; + cin >> n >> m; + set row, col; + for (int i = 0; i < n && k < 3; ++i) { + string s; + cin >> s; + for (int j = 0; j < m && k < 3; ++j) { + if (s[j] == '*') { + k++; + set::iterator it = row.find(i); + if (it == row.end()) { + row.insert(i); + } else { + row.erase(it); + } + it = col.find(j); + if (it == col.end()) { + col.insert(j); + } else { + col.erase(it); + } + } + } + } + cout << *row.begin() + 1 << " " << *col.begin() + 1 << endl; + return 0; +} +vector a; +int main() { + int n, k; + cin >> n >> k; + int mn = 1e9 + 7, t; + for (int i = 0; i < n; i++) { + cin >> t; + a.push_back(t); + mn = min(t, mn); + } + long long ans = 0; + for (int i = 0; i < n; i++) { + if ((a[i] - mn) % k) { + cout << -1 << endl; + return 0; + } + ans += (a[i] - mn) / k; + } + cout << ans << endl; + return 0; +} +vector v; +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3, n; + while (cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n) { + int suma = (a1 + a2 + a3) / 5; + if ((a1 + a2 + a3) % 5 != 0) suma++; + int sumb = (b1 + b2 + b3) / 10; + if ((b1 + b2 + b3) % 10 != 0) sumb++; + if ((suma + sumb) <= n) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int main() { + string word; + cin >> word; + int a = word[0]; + if (a > 90) { + a = a - 32; + word[0] = a; + cout << word << endl; + } else { + cout << word << endl; + } + return 0; +} +long int perm[2 * 100000 + 5]; +int main() { + long int n, x, cycle = 0, v, k, xo = 1; + cin >> n; + for (int i = 1; i <= n; i++) cin >> perm[i]; + for (int i = 0; i < n; i++) { + cin >> x; + xo ^= x; + } + for (int i = 1; i <= n; i++) { + if (!perm[i]) continue; + cycle++; + v = i; + while (perm[v]) { + k = perm[v]; + perm[v] = 0; + v = k; + } + } + if (cycle == 1) cycle = 0; + cout << cycle + xo << endl; + return 0; +} +int main() { + int c = 0, leg; + string str; + cin >> leg; + cin >> str; + for (int i = 0; i < leg - 1; i++) { + if (str.at(i) == str.at(i + 1)) c++; + } + cout << c << endl; +} +int main() { + string tab[5] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; + string a; + cin >> a; + int c = 0; + for (int _i = 0; _i < 5; _i++) { + int count = 0; + int nPos = a.find(tab[_i], 0); + while (nPos != string::npos) { + count++; + nPos = a.find(tab[_i], nPos + 1); + } + if (count == 1) { c += 1; } + if (count > 1) { + cout << "NO" << endl; + return 0; + } + } + if (c == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +char a[101][101]; +int main() { + int n, m, i, j, flag = 0; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') flag = 1; + } + } + if (flag == 1) cout << "#Color" << endl; + if (flag == 0) cout << "#Black&White" << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int t1 = a / 1, t2 = b / 2, t3 = c / 4; + if (t1 > t2) swap(t1, t2); + int minn = min(t1, t3); + cout << minn * 7 << endl; + return 0; +} +const long long MXN = 1.5 * 1e5; +const long long MNN = 1 * 1e4 + 1; +const long long MOD = 1e9 + 7; +const long long INF = 1e18; +const long long OO = 1e9 + 500; +long long q, l[501], r[501], d[501]; +int main() { + cin >> q; + for (int i = 1; i <= q; i++) { + cin >> l[i] >> r[i] >> d[i]; + if (d[i] > r[i] || d[i] < l[i]) + cout << d[i] << '\n'; + else { + int x = (r[i] + d[i]) / d[i]; + cout << x * d[i] << '\n'; + } + } + return 0; +} +const int M = 100 + 5; +int main() { + int a[3]; + int sum = 0; + for (int i = 0; i < 3; i++) { + cin >> a[i]; + sum += a[i]; + } + int id = 0; + int ans = 30; + while (sum > 0) { + if (a[id] > 0) { + a[id] -= 2; + if (a[id] < 0) { a[id] = 0; } + } + id += 1; + ans++; + id = id % 3; + sum = a[0] + a[1] + a[2]; + } + ans -= 1; + cout << ans << endl; + return 0; +} +int main() { + int x, y, z, t; + cin >> x >> y >> z >> t; + cout << max(abs(z - x), abs(t - y)) << '\n'; + return 0; +} +int main() { + int d[4]; + int count = 0; + for (int i = 0; i < 4; i++) { cin >> d[i]; } + sort(d, d + 4); + for (int i = 0; i < 3; i++) { + if (d[i] == d[i + 1]) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + string n[4]; + int ans = 0; + char z = 'a'; + for (int i = 0; i < 4; i++) { cin >> n[i]; } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (i != j) { + if (n[i] == n[j]) { + ans++; + n[j] = z; + z++; + } + } + } + } + cout << ans << endl; +} +int n, vis, s, d; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> s >> d; + while (s <= vis) s += d; + vis = s; + } + cout << vis << '\n'; +} +int main() { + int i = 0, a, b; + cin >> a >> b; + while (a <= b) { + a = a * 3; + b = b * 2; + i++; + } + cout << i << endl; +} +int main() { + int n; + cin >> n; + if (n == 1 || n == 2) { + cout << "YES" << endl; + } else { + int v = 1, counter = 0; + for (int i = 0; i < 100000; i++) { + v = v * 2; + if (v == n) { + counter = 1; + break; + } + } + if (counter == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + long long u = 1; + long long k, b, n, t; + cin >> k >> b >> n >> t; + if (k == 1) { + long long x = 1; + for (long long i = 1; i <= n; i++) x += b; + long long r = t; + long long ans = 0; + while (r < x) { + ans++; + r += b; + } + cout << ans << endl; + return 0; + } + long long r = 0; + while (u * (k - 1 + b) <= (k * t - t + b)) { + u *= k; + r++; + } + cout << max(n - r + 1, 0LL) << endl; +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1); +const long long MOD = (long long)1e9 + 7; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (a % b == 0) return b; + gcd(a % b, b); +} +bool palin(string s) { + int len = s.length(); + for (int i = 0; i < len / 2; i++) { + if (s[i] != s[len - 1 - i]) { return false; } + } + return true; +} +void fast_io() {} +int main() { + int n, m, k, temp; + cin >> n >> m >> k; + temp = k; + if (temp % 2) temp++; + temp /= 2; + if (temp % m == 0) + cout << temp / m << " "; + else + cout << (temp / m) + 1 << " "; + if (temp % m == 0) + cout << m << " "; + else + cout << temp % m << " "; + if (k % 2) + cout << "L\n"; + else + cout << "R\n"; + return 0; +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + if (n % 4 == 0) + cout << "0" << endl; + else { + int m = 4 - n % 4; + if (m == 1) { + if (a <= b + c && a <= 3 * c) + cout << a << endl; + else if (b + c <= 3 * c && b + c <= a) + cout << b + c << endl; + else + cout << 3 * c << endl; + } else if (m == 2) { + if (b <= 2 * a && b <= 2 * c) + cout << b << endl; + else if (2 * a <= 2 * c && 2 * a <= b) + cout << 2 * a << endl; + else + cout << 2 * c << endl; + } else if (m == 3) { + if (3 * a <= a + b && 3 * a <= c) + cout << 3 * a << endl; + else if (a + b <= 3 * a && a + b <= c) + cout << a + b << endl; + else + cout << c << endl; + } + } + return 0; +} +int main() { + int n, cnt = 0; + cin >> n; + string str; + cin >> str; + for (int i = 0; i < str.size() - 1; i++) { + while (str[i] == str[i + 1]) { + cnt++; + i++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool ans = true; + int tp, l, r; + cin >> tp; + for (int i = 0; i < n; ++i) { + cin >> l >> r; + if (tp == l || tp == 7 - l || tp == r || tp == 7 - r) { ans &= false; } + } + cout << (ans ? "YES" : "NO") << endl; +} +const int MAXN = 101; +int n, d; +int dp[MAXN][MAXN]; +bool used[MAXN][MAXN]; +char flower[MAXN]; +int f(int position, int pasos) { + if (position == n) { return pasos; } + if (position > n) { return INT_MAX; } + if (used[position][pasos]) { return dp[position][pasos]; } + int ans = INT_MAX; + for (int i = 1; i < d + 1; i++) { + if (position + i <= n && flower[position + i] == '1') { ans = min(ans, f(position + i, pasos + 1)); } + } + used[position][pasos] = 1; + dp[position][pasos] = ans; + return ans; +} +int main() { + cin >> n >> d; + for (int i = 1; i < n + 1; i++) { cin >> flower[i]; } + int ans = f(1, 0); + if (ans == INT_MAX) { + cout << -1 << endl; + } else { + cout << ans << endl; + } + return 0; +} +string s1, s2; +vector num; +int check(int x) { + vector record; + int n = s1.size(); + for (int i = n - 1; i >= n - x; i--) record.push_back(num[i]); + sort(record.begin(), record.end()); + string s3; + for (int i = 0; i < record.size(); i++) s3 += s1[record[i] - 1]; + int index = -1; + for (int i = 0; i < s2.size(); i++) { + index = s3.find(s2[i], index + 1); + if (index == -1) return 0; + } + return 1; +} +int main() { + cin >> s1 >> s2; + int x; + for (int i = 0; i < s1.size(); i++) { + cin >> x; + num.push_back(x); + } + int r = s1.size(), l = 1; + while (r - l > 3) { + int mid = (l + r) >> 1; + if (check(mid)) + r = mid; + else + l = mid; + } + for (int i = l; i <= r; i++) { + if (check(i)) { + cout << s1.size() - i << endl; + return 0; + } + } + return 0; +} +char r[100005]; +int a, d; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> r[i]; + if (r[i] == 'A') + a++; + else + d++; + } + if (a > d) + cout << "Anton" << endl; + else if (a < d) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +vector v, v3, v4; +vector v2; +int main() { + int term, num, a; + cin >> term; + for (int i = 0; i < term; i++) { + string name; + int c = 0, p, m, sum = 0; + a = 99999; + cin >> name >> p >> m; + v2.push_back(name); + for (int j = 0; j < 5; j++) { + cin >> num; + sum += num; + } + sum += (p * 100) - (m * 50); + v4.push_back(sum); + v.push_back(c); + } + sort(v.begin(), v.end()); + int x = v4[0], y = 0; + for (int i = 1; i < v4.size(); i++) { + if (v4[i] > x) { + x = v4[i]; + y = i; + } + } + cout << v2[y] << endl; + return 0; +} +long long x, xx, y, yy, ans; +int main() { + cin >> x >> y >> xx >> yy; + x = abs(x - xx); + y = abs(y - yy); + ans = max(x, y); + cout << ans << '\n'; + return 0; +} +int main() { + int T, d[3010], s[3010]; + T = 1; + while (T--) { + int m, k; + cin >> m >> k; + for (int i = 0; i < m; i++) cin >> d[i]; + for (int i = 0; i < m; i++) cin >> s[i]; + int is = 0, t = 0; + int bak = 0; + while (is < m) { + bak += s[is]; + int g = is + 1; + while (g < m && s[g] < s[is]) g++; + int dsum = d[is]; + for (int i = is + 1; i < g; i++) dsum += d[i] - s[i]; + while (dsum > bak) { + t += k; + bak += s[is]; + } + bak -= dsum; + for (int i = is; i < g; i++) t += d[i]; + is = g; + } + cout << t << endl; + } +} +int main() { + string S; + cin >> S; + string Sr = S; + reverse(Sr.begin(), Sr.end()); + int ans; + if (count(S.begin(), S.end(), S[0]) == S.size()) { + ans = 0; + } else if (S == Sr) { + ans = S.size() - 1; + } else { + ans = S.size(); + } + cout << ans << endl; + return 0; +} +int x, y, z, t1, t2, t3; +int main() { + cin >> x >> y >> z >> t1 >> t2 >> t3; + if ((fabs(z - x) + fabs(x - y)) * t2 + 3 * t3 <= fabs(x - y) * t1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[110]; +int main() { + int n, k; + cin >> n >> k; + int Max = 0; + int num = 0; + for (int i = 0; i < n; i++) { + int m; + cin >> m; + a[m]++; + if (a[m] == 1) num++; + if (a[m] > Max) Max = a[m]; + } + if (Max % k == 0) + cout << Max * num - n << endl; + else + cout << (Max / k + 1) * num * k - n << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int s[n]; + int count = 2; + for (int i = 0; i < n; i++) { cin >> s[i]; } + for (int j = 0; j < n - 1; j++) { + int k = s[j] + m; + if (s[j + 1] - k > m) count += 2; + if (s[j + 1] - k == m) count++; + } + cout << count << endl; + } +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int masha_time = abs(x - y) * t1; + int elevator_time = abs(x - z) * t2 + abs(x - y) * t2 + t3 + t3 + t3; + if (elevator_time <= masha_time) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +bool check(string s) { + int x = 0, y = 0; + for (int i = 0; i < s.size(); ++i) { + if (s[i] == 'R') x++; + if (s[i] == 'L') x--; + if (s[i] == 'D') y--; + if (s[i] == 'U') y++; + } + return x == 0 && y == 0; +} +int main() { + int n; + string s; + while (cin >> n >> s) { + int ans = 0; + for (int i = 0; i < n; ++i) { + for (int j = 1; j + i <= n; ++j) { + string cur = s.substr(i, j); + if (check(cur)) { ans++; } + } + } + cout << ans << '\n'; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int banyaklemon = a; + int banyakapel = b / 2; + int banyakpear = c / 4; + int hasil = min(banyaklemon, banyakapel); + hasil = min(hasil, banyakpear); + cout << hasil * (7) << endl; +} +int main() { + int n, x = 0; + char c[100005], s; + cin >> n; + cin >> c; + s = c[0]; + for (int i = 1; i < n; i++) { + if (s == c[i]) + x++; + else + s = c[i]; + } + cout << x << endl; +} +int check(string s, int i, int j) { + int l = i, r = j; + while (l < r) { + if (s[l] == s[r]) { + l++; + r--; + continue; + } else + return 0; + } + return 1; +} +int main() { + string s; + cin >> s; + int i, n = s.length(), j; + i = 0; + j = n - 1; + while (i < j) { + if (s[i] != s[j]) { + if (i + 1 == j) { + s.insert(s.begin() + j + 1, s[i]); + cout << s << endl; + return 0; + } else { + if (check(s, i + 1, j)) { + s.insert(s.begin() + j + 1, s[i]); + cout << s << endl; + return 0; + } else if (check(s, i, j - 1)) { + s.insert(s.begin() + i, s[j]); + cout << s << endl; + return 0; + } else { + cout << "NA" << endl; + return 0; + } + } + } else { + i++; + j--; + } + } + if (s.length() % 2 == 0) { + s.insert(s.begin() + n / 2, 'a'); + cout << s << endl; + return 0; + } else { + s.insert(s.begin() + n / 2 + 1, s[n / 2]); + cout << s << endl; + return 0; + } +} +int main() { + long long int n, i, k, x = 1, b = 0; + cin >> n >> k; + long long int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 1; i < n; i++) { + if (b - x * a[i] * (n - i - 1) < k) + cout << i + 1 << endl; + else { + b += x * a[i]; + x++; + } + } + return 0; +} +int n, cnta, cntd; +string s; +int main() { + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') + cnta++; + else + cntd++; + } + if (cnta > cntd) cout << "Anton\n"; + if (cnta < cntd) cout << "Danik\n"; + if (cnta == cntd) cout << "Friendship\n"; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int ans = INT_MAX; + for (int i = 0; i < n; i++) { + int arr_i; + cin >> arr_i; + if (arr_i != 0 and arr_i <= k) ans = min(ans, 10 * abs(m - i - 1)); + } + cout << ans << endl; + return (0); +} +int main() { + int a, b, c; + vector values; + cin >> a >> b >> c; + values.push_back(a + (b * c)); + values.push_back(a * (b + c)); + values.push_back(a + b + c); + values.push_back(a * (b * c)); + values.push_back((a + b) * c); + cout << *max_element(values.begin(), values.end()) << endl; + return 0; +} +int main() { + int f = 0; + string s, t; + cin >> s; + t = s; + if (s[0] == s[s.size() - 1]) { + reverse(t.begin(), t.end()); + for (int i = 0; i < s.size(); i++) { + if (t[i] == s[i]) { + f = 0; + } else { + f = 1; + break; + } + } + if (f == 0) { + sort(s.begin(), s.end()); + if (s[0] == s[s.size() - 1]) + cout << 0 << '\n'; + else + cout << s.size() - 1 << '\n'; + } else { + cout << s.size() << '\n'; + } + } else { + cout << s.size() << '\n'; + } + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int turn = 0; + while (true) { + if (turn) { + if (y < 2 || (x == 1 && y < 12) || (x == 0 && y < 22)) { + cout << "Ciel\n"; + break; + } + if (y >= 22) + y -= 22; + else if (y >= 12) { + x--, y -= 12; + } else { + x -= 2, y -= 2; + } + } else { + if (y < 2 || (x == 1 && y < 12) || (x == 0 && y < 22)) { + cout << "Hanako\n"; + break; + } + if (x >= 2) { + x -= 2, y -= 2; + } else if (x == 1) { + x--, y -= 12; + } else + y -= 22; + } + turn = !turn; + } + return 0; +} +long long i, temp, l, r, mid, wa, lulz, j, current, lower; +string s, s1, ss; +vector v; +int main() { + cin >> s; + cin >> s1; + for (i = 1; i <= s.size(); i++) { + cin >> temp; + v.push_back(temp - 1); + } + l = 0; + r = 200000; + while (r - l > 1) { + mid = (l + r) / 2; + ss = s; + if (mid < s.size()) + for (i = 0; i < mid; i++) { ss[v[i]] = ')'; } + current = 0; + if (mid < s.size()) + for (i = 0; i < ss.size(); i++) { + if (ss[i] == s1[current]) current++; + } + if (current == s1.size()) + l = mid; + else + r = mid - 1; + } + mid = l + 1; + ss = s; + if (mid < s.size()) + for (i = 0; i < mid; i++) { ss[v[i]] = ')'; } + current = 0; + if (mid < s.size()) + for (i = 0; i < ss.size(); i++) { + if (ss[i] == s1[current]) current++; + } + if (current == s1.size()) l++; + cout << l << "\n"; + return 0; +} +int main() { + char xx[8][30]; + int n; + while (cin >> n) { + char yy[30] = "+------------------------+"; + strcpy(xx[0], yy); + char zz[30] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + strcpy(xx[1], zz); + char k[30] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + strcpy(xx[2], k); + char kk[30] = "|#.......................|"; + strcpy(xx[3], kk); + char ss[30] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + strcpy(xx[4], ss); + char tt[30] = "+------------------------+"; + strcpy(xx[5], tt); + int a = 0; + for (int i = 0; i < 30; i++) { + for (int j = 0; j < 6; j++) { + if (xx[j][i] == '#') { + xx[j][i] = 'O'; + a++; + } + if (a == n) break; + } + if (a == n) break; + } + for (int i = 0; i < 6; i++) { cout << xx[i] << endl; } + } + return 0; +} +int main() { + int t, i; + cin >> t; + if (t % 2 == 1) { + cout << -1 << endl; + } else { + cout << "2 1"; + for (i = 3; i < t; i += 2) { cout << " " << i + 1 << " " << i; } + cout << endl; + } + return 0; +} +int main() { + int s1 = 0, s2 = 0, s3 = 0, s4 = 0, counter = 0; + cin >> s1 >> s2 >> s3 >> s4; + if (s3 == s4 || s2 == s4 || s1 == s4) { s4 = 0; } + if (s2 == s3 || s1 == s3) { s3 = 0; } + if (s1 == s2) { s2 = 0; } + int S[4] = {s1, s2, s3, s4}; + for (int i = 0; i < 4; i++) { + if (S[i] != 0) { counter++; } + } + cout << 4 - counter << endl; + return 0; +} +int main() { + int n; + cin >> n; + int y = (n * (n + 1)) / 2; + if (y % 2) { + cout << "1" << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + int a, b, c, d, e, f, g; + cin >> a >> b >> c; + e = a, f = b, g = c; + d = min(a, b); + d = min(d, c); + d = min(d, a); + if (d == a) { + b = a + 1; + c = a + 2; + } else if (d == b) { + a = b - 1; + c = b + 1; + } else if (d == c) { + a = c - 2; + b = c - 1; + } + while (a > e || b > f || c > g) { + a--; + b--; + c--; + } + cout << a + b + c << endl; + return 0; +} +char s1[105], s2[105]; +int main() { + while (cin >> s1) { + int flag = 1, ans = 0; + int len = strlen(s1); + if (len % 2 == 1) { + ans = len / 2; + } else { + ans = len / 2 - 1; + } + s2[0] = s1[ans]; + for (int i = 1; i < len; i++) { + if (flag == 1) { + ans += i; + s2[i] = s1[ans]; + flag = -1; + } else if (flag == -1) { + ans -= i; + s2[i] = s1[ans]; + flag = 1; + } + } + cout << s2 << endl; + } + return 0; +} +const int Max = 200010; +string s1, s2; +int op[Max]; +int vis[Max]; +bool judge(int mid) { + string temp = ""; + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < mid; i++) { vis[op[i]] = 1; } + int len = s1.length(); + for (int i = 0; i < len; i++) { + if (!vis[i]) temp += s1[i]; + } + int p1 = 0, p2 = 0, len1 = temp.length(), len2 = s2.length(); + while (p1 < len1 && p2 < len2) { + if (temp[p1] == s2[p2]) p2++; + p1++; + } + return p2 == len2; +} +int main() { + while (cin >> s1 >> s2) { + int len = s1.length(); + for (int i = 0; i < len; i++) { + cin >> op[i]; + op[i]--; + } + int left = 0, right = len; + while (right - left > 3) { + int mid = (left + right) / 2; + if (judge(mid)) { + left = mid; + } else { + right = mid; + } + } + int ans = left; + for (int i = left; i <= right; i++) { + if (judge(i)) { ans = i; } + } + cout << ans << endl; + } + return 0; +} +string s; +int main() { + int a, d, i, n, m; + cin >> m; + cin >> s; + n = s.length(); + a = d = 0; + for (i = 0; i < n; i++) { + if (s[i] == 'A') + a++; + else if (s[i] == 'D') + d++; + } + if (a > d) + cout << "Anton" << endl; + else if (a < d) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long l[1000], r[1000], R[1000]; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + R[i] = r[i] / l[i]; + } + for (int i = 0; i < n; i++) cout << l[i] << " " << l[i] * R[i] << endl; + return 0; +} +int main() { + int n, r = 0; + cin >> n; + char ara[n]; + for (int i = 0; i < n; i++) { + char a; + cin >> a; + ara[i] = a; + } + for (int i = 0; i < n; i++) { + if (ara[i] == ara[i + 1]) r++; + } + cout << r << endl; + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (d == 0) { + if (k == 1) + cout << "0" << endl; + else + cout << "No solution" << endl; + } else { + cout << d; + for (int i = 0; i < k - 1; ++i) { cout << "0"; } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i < m + 1; i++) { cout << 1 << " " << i << endl; } + for (int i = 2; i < n + 1; i++) { cout << i << " " << 1 << endl; } +} +int main() { + int n, k; + cin >> n; + ; + vector v; + v.resize(n); + int sum1 = 111111111, sum = 0; + for (int i = 0; i < n; i++) { cin >> v[i]; } + for (int i = 0; i < n; i++) { + sum = 0; + sum = v[i] * 15; + for (int j = 0; j < v[i]; j++) { + int m; + cin >> m; + sum = sum + (m * 5); + } + if (sum < sum1) { sum1 = sum; } + } + cout << sum1 << endl; + return 0; +} +int a[1010]; +int main() { + int n; + cin >> n; + int x = 1; + a[1] = 1; + int tmp = 0; + for (int i = 1; i <= n; i++) tmp += i; + a[0] = 1; + a[1] = 2; + for (int i = 2; i < n; i++) { a[i] = (a[i - 1] + i - 1) % n + 1; } + int s = 0; + for (int i = 0; i < n; i++) s += a[i]; + if (s != tmp) + puts("NO"); + else + puts("YES"); +} +int main() { + char s[1001]; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + int i = 1; + int arr[26] = {}; + while (s[i] != '}') { + if (s[i] != ',' && s[i] != ' ') { arr[s[i] - 97]++; } + i++; + } + int res = 0; + for (int i = 0; i < 26; i++) { + if (arr[i] != 0) { res++; } + } + cout << res << endl; + return 0; +} +vector a; +int main() { + long long n, k; + cin >> n >> k; + if (n == 1) { + if (k >= 2) + cout << -1 << endl; + else + cout << 1 << endl; + return 0; + } + long long pos; + for (long long i = 1; i * i < n; i++) { + pos = i; + if (n % i == 0) { + a.push_back(i); + a.push_back(n / i); + } + } + pos++; + if (pos * pos == n) a.push_back(pos); + int num = a.size(); + if (num < k) { + cout << -1 << endl; + } else { + sort(a.begin(), a.begin() + num); + cout << a[k - 1] << endl; + } + return 0; +} +inline long long bx(long long a) { + long long ans = 0; + long long i = 1; + while (a > 0) { + if (a - a / 10 * 10 != 0) { + ans += i * (a - (a / 10) * 10); + i = i * 10; + } + a /= 10; + } + return ans; +} +int main() { + long long a, b, sum; + cin >> a >> b; + if (bx(a) + bx(b) == bx(a + b)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int t, n, l; + cin >> t; + while (t--) { + cin >> n >> l; + cout << n << " " << (l / n) * n << endl; + } + return 0; +} +string s; +int maxn = 0; +int buhuiwen(int x, int y) { + while (x <= y) { + if (s[x] != s[y]) return 1; + x++; + y--; + } + return 0; +} +int main() { + cin >> s; + for (int i = 0; i < s.length(); i++) { + for (int j = i; j < s.length(); j++) { + if (buhuiwen(i, j)) { + if ((j - i + 1) > maxn) maxn = j - i + 1; + } + } + } + if (maxn == 1) + cout << 0 << endl; + else + cout << maxn << endl; +} +const int maxn = 105; +int f[maxn]; +int main() { + f[1] = f[2] = 1; + for (int i = 3; i < maxn; i += 2) { f[i] = f[i + 1] = (i / 2) * i + (i / 2 + 1); } + int n; + while (cin >> n) { + if (n == 3) { + cout << 5 << endl; + continue; + } + for (int i = 1; i < maxn; i += 2) { + if (n <= f[i]) { + cout << i << endl; + break; + } + } + } + return 0; +} +const int INF = 2000000000; +const double EPS = 1e-9; +int mods(int a, int b) { + return (b + (a % b)) % b; +} +int main() { + int n, x, cur = 1, spent = 0; + cin >> n >> x; + int l, r; + for (int i = 0; i < n; i++) { + cin >> l >> r; + while (cur + x <= l) cur += x; + spent += (l - cur) + (r - l) + 1; + cur = r + 1; + } + cout << spent << '\n'; +} +int numbers[4][12]; +int main() { + int n; + cin >> n; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 12; j++) { + if (j == 0) { + if (n >= 1) { numbers[0][0] = 1; } + if (n >= 2) { numbers[1][0] = 1; } + if (n >= 3) { numbers[3][0] = 1; } + if (n >= 4) { numbers[2][0] = 1; } + } else { + if (i == 3) { continue; } + if (n >= 3 * (j - 1) + i + 5) { numbers[i][j] = 1; } + } + } + } + cout << "+------------------------+" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (numbers[0][i] == 1) { + cout << "O"; + } else { + cout << "#"; + } + cout << "."; + } + cout << "|D|)" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (numbers[1][i] == 1) { + cout << "O"; + } else { + cout << "#"; + } + cout << "."; + } + cout << "|.|" << endl; + cout << "|"; + if (n >= 3) { + cout << 'O'; + } else { + cout << '#'; + } + cout << ".......................|" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (numbers[2][i] == 1) { + cout << "O"; + } else { + cout << "#"; + } + cout << "."; + } + cout << "|.|)" << endl; + cout << "+------------------------+" << endl; + cin.get(); + cin.get(); + return 0; +} +int main() { + int t, s, d, x; + cin >> t; + cin >> s >> d; + x = s; + t = t - 1; + while (t--) { + cin >> s >> d; + while (x >= s) { s = s + d; } + x = s; + } + cout << x << endl; + return 0; +} +int a[200005]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int c = 0, b = 0; + for (int i = 1; i <= n; i++) { + if (a[i] == 1) { + c = c + 1; + } else { + b = b + 1; + } + } + if (c >= b) { + cout << b + (c - b) / 3 << endl; + } else { + cout << c << endl; + } + } + return 0; +} +int main() { + int n, x = 0; + cin >> n; + while (n--) { + char s[105]; + cin >> s; + if (s[1] == '+') { + x++; + } else { + x--; + } + } + cout << x << endl; + return 0; +} +long long gcd(long long a, long long b) { + while (b ^= a ^= b ^= a %= b) + ; + return a; +} +const int maxn = 2000 + 5; +long long arr[maxn]; +int n; +int main() { + cin >> n; + int num = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) num++; + } + if (num != 0) { + cout << n - num << endl; + } else { + int len = 1e5; + bool flag = 0; + for (int i = 0; i < n; i++) { + long long t = arr[i]; + for (int j = i + 1; j < n; j++) { + t = gcd(t, arr[j]); + if (t == 1) { + flag = 1; + len = min(len, j - i); + } + } + } + if (!flag) + cout << "-1" << endl; + else + cout << n - 1 + len << endl; + } +} +const int MAXX = 100000 + 10; +const double PI = 3.14159265358979323846; +const long long mod = 1000000007; +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } + return 0; +} +int main() { + int n, m, r; + cin >> n >> m; + int lim = 100; + while (lim--) { + r = n % m; + if (r == 0) { + cout << "Yes" << endl; + return 0; + } + n += r; + } + cout << "No" << endl; + return 0; +} +long long a, b, n; +bool ans = 0; +int main() { + cin >> a >> b; + while (b > 0) { + if (b == 1) { + ans = 0; + break; + } + if (b % a != 0) { + ans = 1; + break; + } + n++; + b = b / a; + } + if (ans == 0) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int maxn = 200; +char str[maxn]; +int main() { + cin >> str; + char *p = str; + int ans = 0; + while ((p = strstr(p, "Danil")) != NULL) { + p += 5; + ans++; + } + p = str; + while ((p = strstr(p, "Olya")) != NULL) { + p += 5; + ans++; + } + p = str; + while ((p = strstr(p, "Slava")) != NULL) { + p += 5; + ans++; + } + p = str; + while ((p = strstr(p, "Ann")) != NULL) { + p += 3; + ans++; + } + p = str; + while ((p = strstr(p, "Nikita")) != NULL) { + p += 6; + ans++; + } + if (ans == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int M = 100 + 10; +long long int a[M]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + long long int ans = 0; + for (int i = 1; i <= n; i++) { ans = ans + (i - 1) * (a[i] - 1) + a[i]; } + cout << ans << endl; + return 0; +} +long long k; +vector v; +void d(long long n) { + long long c = 0; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + v.push_back(i); + if (n / i != i) v.push_back(n / i); + } + } + sort(v.begin(), v.end()); + if (v.size() < k) + cout << "-1" << endl; + else + cout << v[k - 1] << endl; +} +int main() { + long long n; + cin >> n >> k; + d(n); + return 0; +} +int main() { + long long tc, n, k; + while (cin >> n >> k) { + long long maxi = -1, a[n + 5], mp[100005], y = 0; + memset(mp, 0, sizeof(mp)); + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (mp[a[i]] == 0) y++; + mp[a[i]]++; + maxi = max(maxi, mp[a[i]]); + } + long long x = maxi / k; + if (maxi % k != 0) x++; + x *= k; + long long sum = 0; + for (int i = 0; i < n; i++) { + sum += (x - mp[a[i]]); + mp[a[i]] = x; + } + cout << sum << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + long long a; + long long sum = 0; + int min = 1000000003; + for (int i = 0; i < n; i++) { + cin >> a; + if (a % 2 != 0 && a < min) { min = a; } + sum += a; + } + if (sum % 2 != 0) { sum -= min; } + cout << sum << endl; + } +} +int main() { + long long n, jum = 0, arr[100009]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + jum += arr[i]; + } + if (jum % 2 == 0) + cout << jum << endl; + else { + sort(arr + 1, arr + n + 1); + for (int i = 1; i <= n; i++) { + if (arr[i] % 2 == 1) { + cout << jum - arr[i] << endl; + return 0; + } + } + } +} +int main() { + long long testcases; + cin >> testcases; + while (testcases--) { + long long x; + cin >> x; + long long ans = x / 7; + if (x % 7 != 0) { ans++; } + cout << ans << "\n"; + } + return 0; +} +long long int a[10000000] = {0}; +int main() { + long long int x, y, k = 0, i; + cin >> x >> y; + for (i = 1; i * i < x; i++) { + if (x % i == 0) { + a[k] = i; + k++; + a[k] = x / i; + k++; + } + } + if (i * i == x) { + a[k] = i; + k++; + } + if (k < y) { + cout << "-1\n"; + } else { + sort(a, a + k); + cout << a[y - 1] << endl; + } +} +char s[20000]; +long long INF = 1e9 + 7; +long long er = 2; +long long a[20000]; +long long f[200000]; +int main() { + a[0] = 1; + for (int i = 1; i <= 10000; i++) { a[i] = (a[i - 1] * er * er) % INF; } + cin >> s; + int n = strlen(s); + int ans = 1; + for (int i = n - 1; i >= 0; i--) { + if (s[i] == '1') { + f[n - i] = f[n - i - 1] * er + a[n - i - 1]; + } else { + f[n - i] = f[n - i - 1] * er; + } + f[n - i] = f[n - i] % INF; + } + cout << f[n] << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long c = 0; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { c++; } + } + } + if (c == 0) { + cout << "#Black&White" << endl; + } else { + cout << "#Color" << endl; + } + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + cout << ((n1 > n2) ? "First" : "Second") << endl; + return 0; +} +const int N = 5005; +int main() { + int n; + cin >> n; + if (n % 4 == 0 || n % 4 == 3) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +const int MAXN = 1001; +int dist[MAXN]; +int fuel[MAXN]; +int main() { + int m, k; + cin >> m >> k; + for (int i = 0; i < m; i++) cin >> dist[i]; + for (int i = 0; i < m; i++) cin >> fuel[i]; + int s = 0; + int r = 0; + int maxi = 0; + for (int i = 0; i < m + 1; i++) { + while (r < 0) { + r += maxi; + s += k; + } + if (i == m) break; + r -= dist[i]; + r += fuel[i]; + s += dist[i]; + maxi = max(maxi, fuel[i]); + } + cout << s << '\n'; + return 0; +} +int main() { + int i; + set s; + set::iterator it; + char a[1001]; + cin.getline(a, 1001); + for (i = 0; i < strlen(a); i++) { + if (a[i] >= 'a' && a[i] <= 'z') s.insert(a[i]); + } + cout << s.size() << endl; + return 0; +} +int main() { + int n, m, a, b, flag = 0; + cin >> n >> m >> a >> b; + while (1) { + if (flag == 0) { + n--; + flag = 1; + } else { + m--; + flag = 0; + } + if (n < 0) { + cout << "Second" << endl; + break; + } + if (m < 0) { + cout << "First" << endl; + break; + } + } +} +int main() { + int n, d; + cin >> n >> d; + string s; + cin >> s; + int ans = 0; + int i = 0; + while (i < n - 1) { + if (s[i + d] == '1') { + ans++; + i = i + d; + } else { + int j = i + d - 1; + int flag = 1; + while (j > i) { + if (s[j] == '1') { + i = j; + ans++; + flag = 0; + break; + } + j--; + } + if (flag) { + ans = -1; + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long a[100050]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) cout << a[i] + a[i - 1] << " "; + cout << a[n - 1] << endl; + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + if (abs(x - z) * t2 + abs(x - y) * t2 + t3 * 3 <= abs(x - y) * t1) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + long long t, n; + cin >> t; + while (t--) { + cin >> n; + if (n % 7 == 0) + cout << n / 7; + else + cout << (n / 7) + 1; + cout << endl; + } +} +int main() { + vector s(4); + cin >> s[0] >> s[1] >> s[2] >> s[3]; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + cout << 4 - s.size() << endl; + return 0; +} +int main() { + int friends, all, counter, number, temp; + while (cin >> friends) { + all = 0; + for (int i = 1; i <= friends; i++) { + cin >> number; + all += number; + } + counter = 0; + friends++; + for (int i = 1; i <= 5; i++) { + temp = all + i; + if (temp % friends != 1) counter++; + } + cout << counter << endl; + } + return 0; +} +string s; +int main() { + cin >> s; + string s1 = s; + int n = s.length(); + for (int i = 0; i < n; i++) { + reverse(s.begin(), s.end()); + if (s == s1 && s.length() > 1) { + s.erase(s.end() - 1, s.end()); + s1 = s; + } else { + if (s.length() == 1) { + cout << 0 << endl; + break; + } else { + cout << s.length() << endl; + break; + } + } + } + return 0; +} +int n, m; +int main() { + cin >> n >> m; + if (m > n) { + cout << -1 << endl; + return 0; + } + for (int i = (int)((double)n / 2 + 0.5); i <= n; ++i) { + if (i % m == 0) { + cout << i << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +long long n, a[201][201], i, j, dp[201][201], ans = 9999999999999; +int main() { + cin >> n; + cout << "+------------------------+" << endl; + if (n >= 3) { + n -= 1; + cout << '|'; + for (i = 1; i <= 11; i++) { + if ((n + 2) / 3 >= i) + cout << "O."; + else + cout << "#."; + } + cout << "|D|)" << endl; + cout << '|'; + for (i = 1; i <= 11; i++) { + if ((n + 1) / 3 >= i) + cout << "O."; + else + cout << "#."; + } + cout << "|.|" << endl; + cout << "|O.......................|" << endl; + cout << '|'; + for (i = 1; i <= 11; i++) { + if (n / 3 >= i) + cout << "O."; + else + cout << "#."; + } + cout << "|.|)" << endl; + } else { + cout << '|'; + if (n >= 1) + cout << "O."; + else + cout << "#."; + cout << "#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << '|'; + if (n >= 2) + cout << "O."; + else + cout << "#."; + cout << "#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + } + cout << "+------------------------+" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } +} +int main() { + int n; + cin >> n; + int ans = 0; + string s; + getline(cin, s); + while (n--) { + string str; + getline(cin, str); + if (str == "X++" || str == "++X") + ans++; + else if (str == "--X" || str == "X--") + ans--; + } + cout << ans << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + int cnt = 0, cnt2 = 0; + int max; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else + cout << "Second" << endl; +} +int main() { + long long cans, sum = 0, aux; + cin >> cans; + long long val[cans + 2]; + for (int i = 0; i < cans; i++) { + cin >> aux; + sum += aux; + } + for (int i = 0; i < cans; i++) cin >> val[i]; + sort(val, val + cans); + if (sum <= val[cans - 1] + val[cans - 2]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int m, k, d[1010], s[1010]; + long long sum = 0, b = 0; + cin >> m >> k; + for (int i = 0; i < m; i++) cin >> d[i]; + for (int i = 0; i < m; i++) cin >> s[i]; + for (int i = 0; i < m; i++) { + if (b + s[i] >= d[i]) { + b += (s[i] - d[i]); + sum += d[i]; + } else { + int max = 0; + for (int j = 0; j <= i; j++) + if (s[j] > max) max = s[j]; + while (true) { + if (b + s[i] >= d[i]) { + b += (s[i] - d[i]); + sum += d[i]; + break; + } + b += max; + sum += k; + } + } + } + cout << sum << endl; + return 0; +} +int N; +char c, temp; +int r, u; +int main() { + cin >> N; + int ans = N; + int flag = 0; + for (int i = 0; i < N; i++) { + cin >> c; + if (temp) { + if (temp == 'R' && c == 'U' && !flag) { + ans--; + flag = 1; + } else if (temp == 'U' && c == 'R' && !flag) { + ans--; + flag = 1; + } else { + flag = 0; + } + } + temp = c; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1); +const long long MOD = (long long)1e9 + 7; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (a % b == 0) return b; + gcd(a % b, b); +} +bool palin(string s) { + int len = s.length(); + for (int i = 0; i < len / 2; i++) { + if (s[i] != s[len - 1 - i]) { return false; } + } + return true; +} +void fast_io() {} +int main() { + int arr[310], p, n, temp; + cin >> p >> n; + for (int i = 0; i < p + 1; i++) arr[i] = 0; + for (int i = 1; i <= n; i += 1) { + cin >> temp; + if (!arr[temp % p]) + arr[temp % p] = 1; + else { + cout << i << "\n"; + return 0; + } + } + cout << "-1\n"; + return 0; +} +const int N = 1e6 + 6; +int pos[N], id[N], arr[N], BIT[N], brr[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) cin >> brr[i]; + int now = 1, s = 0; + for (int i = 1; i <= n; i++) { (arr[now] == brr[i]) ? now++ : s++; } + cout << n - now + 1 << "\n"; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int tv = 0, ts = 0; + ts = t1 * abs(y - x); + tv = t2 * abs(z - x) + t2 * abs(y - x) + t3 * 3; + if (tv <= ts) + puts("YES"); + else + puts("NO"); + return 0; +} +const int maxn = 2e5 + 10; +int n, m; +string s[110]; +int l[110][10010]; +int r[110][10010]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; ++i) cin >> s[i]; + bool bad = false; + for (int i = 0; i < n; ++i) { + int last = -1; + for (int j = 0; j < m; ++j) + if (s[i][j] == '0') + l[i][j] = (last == -1 ? -1 : j - last); + else + l[i][j] = 0, last = j; + if (last < 0) bad = true; + last = -1; + for (int j = m - 1; j >= 0; --j) + if (s[i][j] == '0') + r[i][j] = (last == -1 ? -1 : last - j); + else + r[i][j] = 0, last = j; + for (int j = 0; j < m; ++j) + if (l[i][j] < 0) l[i][j] = j + l[i][m - 1] + 1; + for (int j = m - 1; j >= 0; --j) + if (r[i][j] < 0) r[i][j] = (m - 1) - j + r[i][0] + 1; + } + if (bad) { + cout << -1 << "\n"; + return 0; + } + long long ans = n * m + 1; + for (int j = 0; j < m; ++j) { + long long cur = 0; + for (int i = 0; i < n; ++i) cur += min(l[i][j], r[i][j]); + ans = min(ans, cur); + } + cout << ans << "\n"; +} +int main() { + int n; + int p; + while (cin >> n) { + int sum = 0; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> p; + sum += p; + } + for (int i = 1; i < 6; i++) { + if ((sum + i - 1) % (n + 1) != 0) { count++; } + } + cout << count << endl; + } + return 0; +} +int main() { + long long int n, i; + cin >> n; + long long int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + for (i = 0; i < n; i++) { + if (i == n - 1) { + cout << arr[n - 1] << endl; + } else { + cout << arr[i] + arr[i + 1] << " "; + } + } +} +int main() { + int p, n; + cin >> p >> n; + set an; + bool flag = true; + while (n--) { + int x; + cin >> x; + unsigned int sz = an.size(); + an.insert(x % p); + if (sz == an.size() && flag == true) { + cout << an.size() + 1 << endl; + flag = false; + } + } + if (flag == true) { cout << "-1" << endl; } + return 0; +} +int pos[] = {1, 5, 13, 25, 41, 61, 85, 113}; +int num[] = {1, 3, 5, 7, 9, 11, 13, 15}; +int main() { + int x; + cin >> x; + int p = 0; + if (x == 3) { + cout << 5 << endl; + return 0; + } + while (pos[p] < x) p++; + cout << num[p] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << m + n - 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << ' ' << i << endl; + for (int i = 2; i <= n; i++) cout << i << ' ' << 1 << endl; + return 0; +} +int fix[100001]; +int n; +int main() { + cin >> n; + fix[0] = 1; + int k = 0; + for (int i = 1; i <= n - 1; i++) + if (fix[(k + i) % n] == 1) { + cout << "NO" << endl; + return 0; + } else { + fix[(k + i) % n] == 1; + k = (k + i) % n; + } + cout << "YES" << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + for (int i = 0; i <= c; i++) { + int res = c - (a * i); + if (res < 0) { break; } + if (res % b == 0) { + cout << "Yes\n"; + return 0; + } + } + cout << "No\n"; + return 0; +} +int main() { + int n, r = 0, g = 0, b = 0; + cin >> n; + string s; + cin >> s; + int p = s.length(); + for (int i = 0; i < p; i++) { + if (s[i] == s[i + 1]) + r++; + else if (s[i] == s[i + 1]) + g++; + else if (s[i] == s[i + 1]) + b++; + } + cout << r + g + b << endl; +} +const int N = 1e6 + 10; +const int mod = 998244353; +long long a, b, x, y, z, q, p, r; +int main() { + cin >> a >> b >> x >> y >> z; + q += 2 * x; + q += y; + p += y; + p += 3 * z; + cout << max(r, q - a) + max(r, p - b) << endl; +} +int main() { + long long x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + long long n, m; + n = abs(x2 - x1); + m = abs(y2 - y1); + if (n % x == 0 && m % y == 0 && (n / x) % 2 == (m / y) % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x[n], y[n]; + for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + vector visit(n, 0); + int count = 0; + queue q; + for (int i = 0; i < n; i++) { + if (!visit[i]) { + q.push(i); + count++; + } else + continue; + while (!q.empty()) { + int index = q.front(); + visit[index] = 1; + for (int j = 0; j < n; j++) { + if ((x[index] == x[j] || y[index] == y[j]) && !visit[j]) { q.push(j); } + } + q.pop(); + } + } + cout << count - 1 << endl; + return 0; +} +int main() { + int a[106]; + int n, en, money; + while (cin >> n >> en >> money) { + for (int i = 1; i <= n; i++) cin >> a[i]; + int t = 0; + for (int i = 1;; i++) { + if (en - i < 1 && en + i > n) break; + t += 10; + if (en - i >= 1 && a[en - i] != 0 && a[en - i] <= money) break; + if (en + i <= n && a[en + i] != 0 && a[en + i] <= money) break; + } + cout << t << endl; + } +} +int main() { + string s; + set set; + getline(cin, s); + int size = s.size(); + int i = 1; + while (i < size) { + if (s[i] >= 97 && s[i] <= 122) { + set.insert(s[i]); + i += 3; + } else { + i++; + } + } + cout << set.size() << "\n"; +} +int main() { + int i = 0; + char s[200100], c; + while ((c = getchar()) != '\n') { + while (i && s[i - 1] < c) { + s[i] = 0; + i--; + } + s[i++] = c; + } + for (int j = 0; j < i; j++) cout << s[j]; + cout << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + double x, y, x0, y0, total(0.0); + cin >> x0 >> y0; + while (--n) { + cin >> x >> y; + total += sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)); + x0 = x; + y0 = y; + } + cout << fixed << setprecision(6) << total * k / 50 << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int MOD = 1e9 + 7; +const double pi = acos(-1.0); +const double eps = 1e-15; +int main() { + int X1, X2, Y1, Y2, X, Y; + cin >> X1 >> Y1 >> X2 >> Y2 >> X >> Y; + if (abs(X2 - X1) % X != 0) + cout << "NO\n"; + else if (abs(Y2 - Y1) % Y != 0) + cout << "NO\n"; + else { + int a = (X2 - X1) / X, b = (Y2 - Y1) / Y; + if (a % 2 == 0 && b % 2 != 0) + cout << "NO\n"; + else if (a % 2 != 0 && b % 2 == 0) + cout << "NO\n"; + else + cout << "YES\n"; + } +} +string s; +int a[201], sum[201], n; +int main() { + cin >> n; + cin >> s; + for (int i = 0; i < n; i++) + if (s[i] == 'U') + a[i + 1] = 1; + else if (s[i] == 'D') + a[i + 1] = -1; + else if (s[i] == 'L') + a[i + 1] = 201; + else if (s[i] == 'R') + a[i + 1] = -201; + sum[0] = 0; + for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; + int res = 0; + for (int i = 1; i <= n - 1; i++) + for (int j = i + 1; j <= n; j++) + if (sum[j] - sum[i - 1] == 0) res++; + cout << res << endl; +} +int main() { + long long int arr[4]; + for (int i = 0; i < 4; i++) cin >> arr[i]; + int counter = 0; + for (int i = 0; i < 3; i++) { + for (int j = i + 1; j < 4; j++) { + if (counter == 3) { + cout << counter << endl; + return 0; + } + if (arr[j] == arr[i]) { + counter++; + break; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + int q = 0, i, l, r, x, ch; + cin >> q; + for (i = 0; i < q; i++) { + cin >> l >> r >> x; + if (l - x > 0) { + if (x < l) + ch = x; + else if (l % x == 0) + ch = l - x; + else + ch = (l / x) * x; + } else if (r % x == 0) + ch = r + x; + else + ch = ((r / x) * x) + x; + cout << ch << endl; + } +} +inline string add(string a, string b) { + int i; + string ans = ""; + int cry = 0; + for (i = 0; i < max(a.size(), b.size()) + 1; i++) { + int ta, tb; + if (i >= a.size()) + ta = 0; + else + ta = a[i] - '0'; + if (i >= b.size()) + tb = 0; + else + tb = b[i] - '0'; + int p = ta + tb + cry; + cry = p / 10; + p %= 10; + ans += '0' + p; + } + if (ans[ans.size() - 1] == '0') ans = ans.substr(0, ans.size() - 1); + return ans; +} +inline string era(string p) { + for (int i = 0; i < p.size(); i++) { + if (p[i] == '0') { + p = p.substr(0, i) + p.substr(i + 1); + i--; + } + } + return p; +} +int main() { + string a, b, c; + cin >> a >> b; + reverse(a.begin(), a.end()); + reverse(b.begin(), b.end()); + c = add(a, b); + a = era(a); + b = era(b); + c = era(c); + if (add(a, b) == c) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +char c; +bool p[30]; +int cnt; +int main() { + c = getchar(); + while (c != '}') { + if (c >= 'a' && c <= 'z') { + cnt += !p[c - 'a']; + p[c - 'a'] = 1; + } + c = getchar(); + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + int sum = 1; + bool no = true; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) + sum++; + else + sum = 1; + if (sum >= 7) { + cout << "YES" << endl; + no = false; + break; + } + } + if (no) cout << "NO" << endl; + return 0; +} +const int MAX = 361; +bool parity(int n) { + return (n & 1); +} +bool is2(int n) { + return n & (n - 1) == 0; +} +int n; +int sum; +int l, r; +int ans = 360; +int a[360]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + while (r < n) { + sum += a[r]; + while (sum >= 180) { + ans = min(ans, 2 * abs(180 - sum)); + sum -= a[l]; + l++; + } + ans = min(ans, 2 * abs(180 - sum)); + r++; + } + cout << ans << endl; +} +int main() { + string s; + int n; + cin >> n; + cin >> s; + for (int i = 0; i < n;) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + cout << "***"; + i = i + 3; + while (s[i] == 'g' && s[i + 1] == 'o') { i = i + 2; } + } else { + cout << s[i]; + i = i + 1; + } + } + cout << endl; +} +int main() { + long long int x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + if (abs(x2 - x1) % x != 0 || abs(y2 - y1) % y != 0) { + cout << "NO\n"; + return 0; + } + if (((x2 - x1) / x - (y2 - y1) / y) % 2 == 0) + cout << "YES\n"; + else + cout << "NO\n"; +} +const int maxn = 1e5 + 6; +const int modn = 1e9 + 7; +int main() { + vector s; + s.push_back("Danil"); + s.push_back("Olya"); + s.push_back("Slava"); + s.push_back("Ann"); + s.push_back("Nikita"); + string a; + cin >> a; + int res = 0; + for (int i = 0; i < 5; i++) { + if (a.find(s[i]) != a.npos) { + res++; + if (a.rfind(s[i]) != a.find(s[i])) { res++; } + } + } + if (res == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int n, m, b, mod, a[501], d[501][501]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + d[0][0] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int k = a[i]; k <= b; k++) d[j][k] = (d[j][k] + d[j - 1][k - a[i]]) % mod; + int ans = 0; + for (int i = 0; i <= b; i++) ans = (ans + d[m][i]) % mod; + cout << ans << endl; + return 0; +} +int main() { + long long int n, a, b, a1, b1, i, j, c = 0; + cin >> n; + cin >> a1 >> b1; + c = a1; + for (i = 0; i < n - 1; i++) { + cin >> a >> b; + if (a <= c) { + for (j = 0;; j++) { + a += b; + if (a > c) { + c = a; + break; + } + } + } else + c = a; + } + cout << c << endl; + return 0; +} +int main() { + int n, data; + int c1 = 0, c2 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> data; + if (data == 1) + c1++; + else if (data == 2) + c2++; + } + int a = min(c1, c2); + c1 -= a; + c2 -= a; + a += c1 / 3; + cout << a << endl; + return 0; +} +int main() { + long long int n, k, half; + cin >> n >> k; + if (n % 2 == 0) { + half = n / 2; + } else if (n % 2 == 1) { + half = (n + 1) / 2; + } + if (k <= half) { + cout << 2 * k - 1 << endl; + } else if (k > half) { + cout << (k - half) * 2 << endl; + } + return 0; +} +int main() { + size_t n; + cin >> n; + string s; + cin >> s; + s.erase(unique(s.begin(), s.end()), s.end()); + cout << n - s.length() << endl; + return 0; +} +int main() { + string input, ans; + int k, i, j, a, n; + cin >> input; + ans = input; + n = input.length(); + k = n / 2 - 1; + if (n % 2 == 0) { + int i = 0, j = n - 1, a = 0; + while (1) { + ans[a++] = input[j--]; + ans[a++] = input[i++]; + if (j == k) { break; } + } + } else if (n == 1) { + cout << input << "\n"; + return 0; + } else { + k = n / 2; + int i = 0, j = n - 1, a = 0; + while (true) { + ans[a++] = input[i++]; + ans[a++] = input[j--]; + if (i == k) { + ans[a++] = input[k]; + break; + } + } + } + reverse(ans.begin(), ans.end()); + cout << ans << "\n"; + return 0; +} +int main() { + int a, b, c, p, q, r, arr[3], z, result; + cin >> a >> b >> c; + p = a / 1; + q = b / 2; + r = c / 4; + arr[0] = p; + arr[1] = q; + arr[2] = r; + sort(arr, arr + 3); + z = arr[0]; + result = 7 * z; + cout << result << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + m--; + for (int i = 0; i < n; i++) { + int s, f, t; + cin >> s >> f >> t; + s--; + f--; + if (f == s) { + cout << t << endl; + continue; + } + bool up; + int curlower; + if (t <= m || (t / m) % 2 == 0) + up = true; + else + up = false; + if (up) + if (t % m == 0) { + if (t / m % 2 == 0) + curlower = 0; + else + curlower = m; + } else + curlower = (t % m == 0 && t != 0) ? m : t % m; + else if (t % m == 0) { + if (t / m % 2 == 1) + curlower = m; + else + curlower = 0; + } else + curlower = m - t % m; + int NeedTime = 0; + if (up) { + if (curlower > s) { + NeedTime += 2 * (m - curlower) + curlower - s; + up = false; + curlower = s; + } + if (s > curlower) { + NeedTime += s - curlower; + curlower = s; + } + } else { + if (s > curlower) { + NeedTime += curlower * 2 + s - curlower; + curlower = s; + up = true; + } + if (s < curlower) { + NeedTime += curlower - s; + curlower = s; + } + } + if (up) { + if (curlower > f) { + NeedTime += 2 * (m - curlower) + curlower - f; + up = false; + curlower = f; + } + if (f > curlower) { + NeedTime += f - curlower; + curlower = f; + } + } else { + if (f > curlower) { + NeedTime += curlower * 2 + f - curlower; + curlower = f; + } + if (f < curlower) { NeedTime += curlower - f; } + } + cout << NeedTime + t << endl; + } + return 0; +} +int main() { + int n, a1, a2, a3, b1, b2, b3, m = 0, c = 0; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + c = a1 + a2 + a3; + m = b1 + b2 + b3; + if (((c / 5) + (c % 5 != 0) + (m / 10) + (m % 10 != 0)) <= n) + cout << "YES\n"; + else + cout << "NO\n"; +} +int a[4], t, z, x, ans; +int main() { + cin >> a[1] >> a[2] >> a[3]; + z = a[1] + a[2] + a[3]; + for (int j = 1; j <= 9999; j++) { + for (int i = 1; i <= 3; i++) { + x = i; + if (a[i] >= 2) { + a[i] -= 2; + z -= 2; + ans++; + } else { + z -= a[i]; + a[i] = 0; + ans++; + } + if (z == 0) break; + } + if (z == 0) break; + } + cout << ans + 29 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x, d; + for (int i = 0; i < n; i++) { + cin >> x; + d = x / 7; + if (x % 7 != 0) d++; + cout << d << endl; + } + return 0; +} +vector v[2002]; +vector m; +int n, dep = 0, s = 0; +void dfs(int k, int s) { + if (s > dep) dep = s; + for (int i = 0; i < v[k].size(); i++) { dfs(v[k][i], s + 1); } + return; +} +int main() { + cin >> n; + int x; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x == -1) + m.push_back(i); + else + v[x].push_back(i); + } + for (int x = 0; x < m.size(); x++) { dfs(m[x], 1); } + cout << dep << endl; + return 0; +} +int main() { + int n, k, a[101], b[101] = {0}; + int i; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> a[i]; + b[a[i]]++; + } + int sum = 0; + int max = 0; + int cnt = 0; + for (i = 0; i <= 100; i++) { + if (b[i] >= 1) sum++; + if (b[i] > max) max = b[i]; + } + cnt = (max / k) + (max % k != 0); + cout << cnt * k * sum - n << endl; + return 0; +} +int main() { + int answers[6]; + int a, b, c; + cin >> a >> b >> c; + answers[0] = a + b + c; + answers[1] = a * b * c; + answers[2] = a * b + c; + answers[3] = a + b * c; + answers[4] = a * (b + c); + answers[5] = (a + b) * c; + sort(answers, answers + 6); + cout << answers[5] << endl; + return 0; +} +int a[200000]; +int b[200000]; +int n = 0; +void read() { + char c; + while (c = getchar()) { + if (c == '\n') break; + a[++n] = c - '0'; + } + for (int i = 1; i <= n; i++) { + c = getchar(); + b[i] = c - '0'; + } + getchar(); + return; +} +int main() { + read(); + int a_4 = 0, a_7 = 0, b_4 = 0, b_7 = 0; + int dif = 0; + for (int i = 1; i <= n; i++) { + if (a[i] != b[i]) { dif++; } + if (a[i] == 4) a_4++; + if (a[i] == 7) a_7++; + if (b[i] == 4) b_4++; + if (b[i] == 7) b_7++; + } + int del = a_4 - b_4; + if (del < 0) del = -del; + int ans = 0; + ans += del; + ans += (dif - del) / 2; + cout << ans << endl; + return 0; +} +int main() { + int n, i; + string s; + while (cin >> n) { + cin >> s; + int cnt = 0; + for (i = 0; i < s.size() - 1; i++) { + if (s[i] != s[i + 1]) { + cnt++; + i++; + } + } + cout << n - cnt << endl; + } + return 0; +} +const int MAX = 3e5 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +const double pi = acos(-1); +const double eps = 1e-9; +long long n, x, y, z, sz, cnt, tmp, res, a, b, k, m; +bool v[MAX]; +string s, t; +char c[MAX]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 1; i <= n; i++) { + x = y = 0; + for (int j = i; j <= n; j++) { + if (c[j] == 'L') + x++; + else if (c[j] == 'R') + x--; + else if (c[j] == 'U') + y++; + else + y--; + if (!x && !y) z++; + } + } + cout << z << '\n'; + return 0; +} +int ans = 1e9, a[1000]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i + n] = a[i]; + } + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < n; j++) { + sum += a[i + j]; + int reverse = 360 - sum; + ans = min(ans, abs(reverse - sum)); + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, s = 0; + cin >> a >> b >> c; + s = max(a + b + c, s); + s = max((a + b) * c, s); + s = max((a * b) + c, s); + s = max((a * b * c), s); + s = max(a + (b * c), s); + s = max(a * (b + c), s); + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + sort(str.begin(), str.end()); + cout << str << endl; +} +long long int cnt[100002]; +long long int ans[100002]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + cnt[a] = cnt[a] + 1; + } + ans[0] = 0; + ans[1] = cnt[1]; + for (int i = 2; i <= 100000; i++) { ans[i] = max(ans[i - 1], ans[i - 2] + cnt[i] * i); } + cout << ans[100000] << endl; + return 0; +} +int main() { + int T, l, r; + cin >> T; + for (int i = 1; i <= T; i++) { + cin >> l >> r; + cout << l << " " << l * (r / l) << endl; + } +} +int main() { + int n, a, b, c, sum = 0, sum1 = 0, sum2 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + sum += a; + sum1 += b; + sum2 += c; + } + if (sum == 0 && sum1 == 0 && sum2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int a[100010], n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + int b = a[1], c = a[n]; + int ans = 0; + for (int i = 1; i <= n; i++) { + if (b < a[i] && a[i] < c) ans++; + } + cout << ans << endl; + return 0; +} +int fa[2005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fa[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + int tmp = 0; + for (int j = i; j <= n && j != -1; j = fa[j]) { tmp++; } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +int num[101]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) num[i] = i + 1; + if (n % 2) + cout << -1 << endl; + else { + for (int i = 1; i < n; i += 2) { swap(num[i - 1], num[i]); } + for (int i = 0; i < n - 1; i++) cout << num[i] << " "; + cout << num[n - 1] << endl; + } +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int ans = 1; + c -= v0; + int temp = v0; + while (c > 0) { + ans += 1; + if (temp + a <= v1) + temp += a; + else + temp = v1; + c = c - temp + l; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int res = 0; + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { + int x = 0, y = 0; + for (int k = i; k <= j; k++) { + if (s[k] == 'U') x++; + if (s[k] == 'D') x--; + if (s[k] == 'L') y++; + if (s[k] == 'R') y--; + } + if (x == 0 && y == 0) res++; + } + } + cout << res << endl; +} +int main() { + int n, m; + cin >> n >> m; + int i, flag = 0; + for (i = (n + 1) / 2; i <= n; i++) { + if (i % m == 0) { + flag = 1; + cout << i << endl; + break; + } + } + if (flag == 0) { cout << "-1" << endl; } + return 0; +} +int x[150], y[150], vis[150], ans = -1, n; +void dfs(int s) { + vis[s] = 1; + for (int i = 1; i <= n; i++) + if ((x[s] == x[i] || y[s] == y[i]) && !vis[i]) dfs(i); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; + for (int i = 1; i <= n; i++) + if (!vis[i]) dfs(i), ans++; + cout << ans << endl; + return 0; +} +int main() { + long long a, b = 0, i, k; + cin >> a; + for (i = 1; i <= a; i++) { + cin >> k; + if (i == 1 || k == 1) { + b += k; + } else { + k *= i; + k -= i - 1; + b += k; + } + } + cout << b << endl; +} +long long n, k, arr[100005] = {0}; +char s[100005]; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> s[i]; } + for (int y = 0; y < k; y++) { + for (int i = 0; i < n; i++) { + if (s[i] == char(y + 65)) { arr[y]++; } + } + } + sort(arr, arr + k); + cout << arr[0] * k << '\n'; + return 0; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + vector v(n + 1); + for (int i = 1; i <= n; i++) { cin >> v[i]; } + int i, flag1 = 1000, j, flag2 = 1000; + for (i = 1; i < n; i++) { + if (m + i <= n) { + if (v[m + i] <= k && v[m + i] != 0) break; + } + } + if (i < n) flag1 = i; + for (j = 1; j < n; j++) { + if (m - j >= 1) { + if (v[m - j] <= k && v[m - j] != 0) break; + } + } + if (j < n) flag2 = j; + int min = flag1 < flag2 ? flag1 : flag2; + cout << min * 10 << endl; + } + return 0; +} +int main() { + int Arr[4], Count = 0; + for (int i = 0; i < 4; i++) { cin >> Arr[i]; } + sort(Arr, Arr + 4); + for (int i = 0; i < 3; i++) { + if (Arr[i] == Arr[i + 1]) { Count++; } + } + cout << Count << endl; + return 0; +} +const long long N = 1e9 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, a, b, x, c1, c2, cnt; +string s, s1; +bool bl = false; +long long c; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +void propblem(string s) { + long long mx = 0; + string s1; + for (long long i = 0; i < s.size(); i++) { + s1 = ""; + for (long long j = i; j < s.size(); j++) { + s1.push_back(s[j]); + string s2 = s1; + reverse(s2.begin(), s2.end()); + if (s1 != s2) { + if (s1.size() > mx) { mx = s1.size(); } + } + } + } + cout << mx; +} +int main() { + string x; + cin >> x; + propblem(x); + cout << "\n"; + return 0; +} +long long ans, n, a[101]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { ans = ans + a[i] * i + 1 - i; } + cout << ans << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long sum = 0; + long long pos = 1; + for (long long i = 1; i <= n; i++) { + long long x; + cin >> x; + long long d = sum - (pos - 1) * (n - i) * x; + if (d < k) + cout << i << '\n'; + else { + sum += x * (pos - 1); + pos++; + } + } + return 0; +} +int main() { + long long n, k, p; + cin >> n >> k >> p; + long long pe[1001], ke[2002]; + for (int a = 0; a < n; a++) cin >> pe[a]; + for (int a = 0; a < k; a++) cin >> ke[a]; + sort(pe, pe + n); + sort(ke, ke + k); + long long mins = 99999999999999; + for (int a = 0; a < k - n + 1; a++) { + long long tmp = 0; + for (int b = 0; b < n; b++) tmp = max(tmp, abs(pe[b] - ke[a + b]) + abs(ke[a + b] - p)); + mins = min(tmp, mins); + } + cout << mins << endl; + return 0; +} +int main() { + vector color(3); + for (int i = 0; i < 3; ++i) cin >> color[i]; + int cnt = 0; + for (int i = 0; i < 3; ++i) cnt += color[i]; + for (int i = 0;; ++i) { + if (!cnt) { + cout << 30 + i - 1 << "\n"; + break; + } + if (color[i % 3] > 0) { + int m = min(2, color[i % 3]); + cnt -= m; + color[i % 3] -= m; + } + } + return 0; +} +int main() { + long long n, k, c, l, d; + cin >> n >> k; + if (n % 2 == 0) { + l = n / 2; + } else { + l = n / 2 + 1; + } + if (k <= l) { + cout << 2 * k - 1 << endl; + } else { + if (n % 2 != 0) { + cout << 2 * k - n - 1 << endl; + } else { + cout << 2 * k - n << endl; + } + } +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int str_dif = x - y; + int elv_dif = x - z; + if (str_dif < 0 || elv_dif < 0) { + if (str_dif < 0) str_dif = str_dif * -1; + if (elv_dif < 0) elv_dif = elv_dif * -1; + } + int str_time = str_dif * t1; + int elv_time = elv_dif * t2 + str_dif * t2 + 3 * t3; + if (str_time < elv_time) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int n, d; +string s; +int dist[101]; +int main() { + memset(dist, 0x3f3f3f3f, sizeof(dist)); + cin >> n >> d; + cin >> s; + dist[0] = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + for (int j = i + 1; j <= i + d; j++) { + if (s[j] == '1') { dist[j] = min(dist[j], dist[i] + 1); } + } + } + } + cout << (dist[n - 1] == 0x3f3f3f3f ? -1 : dist[n - 1]) << "\n"; + return 0; +} +int main() { + int a, b, c, sum = 0, temp = 0, flag = 0; + cin >> a >> b >> c; + for (int i = 0; i < 10000; i++) { + for (int j = 0; j < 10000; j++) { + sum = a * i + b * j; + if (sum > c) { + break; + } else if (sum == c) { + cout << "Yes" << endl; + flag = 1; + return 0; + } + } + } + cout << "No" << endl; + return 0; +} +int main() { + long long z, x; + cin >> z >> x; + bool visit[305] = {0}; + long long asd; + bool cek = false; + long long dsa; + for (int q = 1; q <= x; q++) { + cin >> asd; + asd = asd % z; + if (visit[asd] == true && cek == false) { + cek = true; + dsa = q; + } + visit[asd] = true; + } + if (cek == false) { + cout << -1 << endl; + } else { + cout << dsa << endl; + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = 0; + c -= 2; + b -= 1; + cout << min(a, min(b, c)) * 3 + 3 << endl; + return 0; +} +int n, top, r, l, b; +int main() { + cin >> n >> top; + b = 7 - top; + for (int i = 0; i < n; ++i) { + cin >> r >> l; + if (r == b || l == b || 7 - r == b || 7 - l == b) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, m, k, r, d; + char s; + cin >> n >> m >> k; + if (k % 2 == 0) + s = 'R', k--; + else + s = 'L'; + r = (k / 2) / m; + d = (k / 2) % m; + r++; + d++; + cout << r << " " << d << " " << s << endl; + return 0; +} +int main() { + string s; + int n; + while (cin >> n >> s) { + int x = 0, y = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') + x++; + else if (s[i] == 'D') + y++; + } + if (x > y) + cout << "Anton" << endl; + else if (x < y) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int main() { + long long int l, r, q, d, rem; + cin >> q; + while (q--) { + cin >> l >> r >> d; + if (l / d == 0 || l == d) { + rem = r % d; + if (rem == 0) { + cout << r + d << endl; + } else { + cout << r + d - (r % d) << endl; + } + } else { + cout << d << endl; + } + } +} +int main() { + int n, m; + cin >> n >> m; + vector a(n), b(m); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + for (int i = 0; i < m; i++) { cin >> b[i]; } + sort(b.begin(), b.end()); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i] == b[j]) { + cout << a[i] << '\n'; + return 0; + } + } + } + if (a[0] < b[0]) { + cout << a[0] << b[0] << '\n'; + } else { + cout << b[0] << a[0] << '\n'; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) count++; + } + if (count != 0) { + cout << (n - count) << endl; + return 0; + } + int ans = INT_MAX; + int g; + for (int i = 0; i < n; i++) { + g = 0; + for (int j = i; j < n; j++) { + if (__gcd(g, a[j]) == 1) { + ans = min(ans, (j - i) + (n - 1)); + break; + } + g = __gcd(g, a[j]); + } + } + if (ans == INT_MAX) { + cout << -1 << endl; + } else { + cout << ans << endl; + } +} +bool Isprime(long long a); +int main() { + long long n; + cin >> n; + for (int i = 4; i <= n; i += 2) { + if (Isprime(n - i) == 0) { + cout << i << ' ' << n - i << endl; + return 0; + } + } +} +bool Isprime(long long a) { + if (a % 2 == 0) return 0; + for (int i = 3; i < a; i += 2) + if (a % i == 0) return 0; + return 1; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + string ans; + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { + ans = "#Color"; + break; + } else { + count++; + } + } + } + if (count == n * m) { ans = "#Black&White"; } + cout << ans << endl; + return 0; +} +int main() { + int arr[4], k = 0; + for (int i = 0; i < 4; i++) { cin >> arr[i]; } + sort(arr, arr + 4); + for (int i = 0; i < 3; i++) { + if (arr[i] == arr[i + 1]) k++; + } + cout << k << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long d, e, f; + cin >> d >> e >> f; + long long n; + cin >> n; + long long s = a + b + c; + if (s != 0) { + s = (s - 1) / 5; + s++; + } + long long r = d + e + f; + if (r != 0) { + r = (r - 1) / 10; + r++; + } + if (r + s <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long power(int x) { + if (x == 0) + return 1; + else if (x & 1) + return (2 * power(x - 1)) % 1000000007; + else { + long long k = power(x >> 1); + return (k * k) % 1000000007; + } +} +int main() { + string s; + cin >> s; + int n = s.length(); + long long ans = 0; + for (int i = 1; i <= n; i++) { + if (s[i - 1] == '1') { ans = (ans + power(2 * n - i - 1)) % 1000000007; } + } + cout << ans << endl; + return 0; +} +bool sushu(int x) { + for (int i = 2; i < x / 2; i++) { + if (x % i == 0) return false; + } + return true; +} +int n; +int main() { + while (cin >> n) { + int ans1 = 4; + int ans2 = n - ans1; + while (sushu(ans2)) { + ans1 += 2; + ans2 = n - ans1; + } + cout << ans1 << " " << ans2 << endl; + } + return 0; +} +long long mod = 1000000007; +long long int fast_exp(long long int base, long long int ex) { + long long int res = 1; + while (ex > 0) { + if (ex % 2 == 1) res = (res * base) % mod; + base = (base * base) % mod; + ex /= 2; + } + return res % mod; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +bool isSubSequence(string str1, string str2, int m, int n) { + int j = 0; + for (int i = 0; i < n && j < m; i++) + if (str1[j] == str2[i]) j++; + return (j == m); +} +long long n; +long long ar[200001]; +string s, t; +bool check(long long a) { + long long vi[n] = {0}; + for (int i = 0; i < a; i++) vi[ar[i]] = 1; + string h; + for (int i = 0; i < n; i++) { + if (!vi[i]) h += s[i]; + } + return isSubSequence(t, h, t.length(), h.length()); +} +int main() { + cin >> s >> t; + n = s.length(); + for (int i = 0; i < n; i++) { + cin >> ar[i]; + ar[i]--; + } + long long l = 0; + long long h = n; + long long ans = 0; + while (l < h) { + long long mi = h + l; + mi /= 2; + if (check(mi)) { + l = mi + 1; + ans = max(ans, mi); + } else + h = mi; + } + cout << ans << "\n"; + return 0; +} +void solve() { + vector ret; + long long n, k, counts = 0; + cin >> n >> k; + getchar(); + long long limit = (long long)(sqrt(n)) + 1; + for (int i = 1; i <= limit; i++) { + if (n % i == 0) { + ret.push_back(i); + counts++; + if (counts == k) { + cout << i << endl; + return; + } + } + } + if (ret.back() * ret.back() == n) { + if (counts * 2 - 1 < k) { + cout << "-1" << endl; + return; + } + cout << n / (ret[counts * 2 - k - 1]) << endl; + return; + } else { + if (ret[counts - 1] * ret[counts - 2] != n) { counts++; } + if (counts * 2 - 2 < k) { + cout << -1 << endl; + return; + } + cout << n / (ret[counts * 2 - k - 2]) << endl; + return; + } + return; +} +int main() { + solve(); + return 0; +} +int main() { + long long int n; + cin >> n; + if (n == 0) { + cout << n << "\n"; + } else { + if (n % 2 == 0) { + cout << n + 1 << "\n"; + } else { + cout << (n + 1) / 2 << "\n"; + } + } +} +int main() { + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + int a = abs(x2 - x1); + int b = abs(y2 - y1); + if (a > b) + cout << a << endl; + else + cout << b << endl; + return 0; +} +int main() { + char p[50]; + int x, y = 0; + cin >> x; + for (int i = 0; i < x; i++) cin >> p[i]; + for (int i = 0; i < x - 1; i++) + if (p[i] == p[i + 1]) y++; + cout << y << endl; +} +int main() { + int n; + long long arr[102]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + long long sum = 0; + for (int i = 1; i <= n; i++) { sum += (arr[i] - 1) * i; } + sum += n; + cout << sum << endl; +} +int main() { + int n; + while (cin >> n) { + int b[105][105], minn = 100000000; + for (int i = 0; i < 105; ++i) + for (int j = 0; j < 105; ++j) b[i][j] = 0; + for (size_t i = 0; i < n; i++) cin >> b[i][0]; + for (int i = 0; i < n; ++i) { + int a = b[i][0]; + for (int j = 1; j <= a; ++j) cin >> b[i][j]; + } + for (int i = 0; i < n; ++i) { + int a = b[i][0], sum = 0; + for (int j = 1; j <= a; ++j) { sum += (b[i][j] * 5); } + sum += (a * 15); + if (minn > sum) minn = sum; + } + cout << minn << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int people = n + 1; + int sum = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += x; + } + int c = 0; + for (int i = 1; i < 6; i++) { + if ((sum + i) % people != 1) c++; + } + cout << c << endl; + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> x2 >> y1 >> y2; + cout << max(abs(x1 - y1), abs(x2 - y2)) << endl; +} +const int MAXN = 1000; +long long c[MAXN], s[MAXN]; +int main() { + priority_queue pq; + long long N, K; + cin >> N >> K; + for (int i = 0; i < N; ++i) cin >> c[i]; + for (int i = 0; i < N; ++i) cin >> s[i]; + long long ans = 0; + long long acum = 0; + for (int i = 0; i < N; ++i) { + long long C, S; + C = c[i]; + S = s[i]; + acum += S; + pq.push(S); + if (C > acum) { + double need = C - acum; + long long many = ceil(need / ((double)pq.top())); + ans += many * K; + acum += many * pq.top(); + } + acum -= C; + ans += C; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + sum += temp; + } + n++; + int res = 0; + for (int i = 1; i < 6; i++) { + if ((sum + i) % n != 1) { res++; } + } + cout << res << endl; +} +int main() { + int k, l, m, n, d, h = 0; + cin >> k >> l >> m >> n >> d; + for (int i = 1; i <= d; i++) { + if (i % k == 0) + h++; + else if (i % l == 0) + h++; + else if (i % m == 0) + h++; + else if (i % n == 0) + h++; + } + cout << h << endl; + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int stairs = abs(y - x) * t1; + int elevator = abs(z - x) * t2 + abs(y - x) * t2 + 3 * t3; + if (elevator <= stairs) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, n = 2, x = 1; + cin >> a >> b; + while (1) { + if (a >= 2 && b >= 2 && x != 0) { + a = a - 2; + b = b - 2; + n = 1; + } else if (a >= 1 && b >= 12 && x != 0) { + a = a - 1; + b = b - 12; + n = 1; + } else if (b >= 22 && x != 0) { + b = b - 22; + n = 1; + } else { + n = 2; + x = 0; + } + if (x == 0) { break; } + if (b >= 22 && x != 0) { + b = b - 22; + n = 2; + } else if (a >= 1 && b >= 12 && x != 0) { + a = a - 1; + b = b - 12; + n = 2; + } else if (a >= 2 && b >= 2 && x != 0) { + a = a - 2; + b = b - 2; + n = 2; + } else { + n = 1; + x = 0; + } + if (x == 0) { break; } + } + if (n == 1) { + cout << "Ciel" << endl; + } else if (n == 2) { + cout << "Hanako" << endl; + } +} +int fa[2005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fa[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + int tmp = 0; + for (int j = i; j <= n && j != -1; j = fa[j]) { tmp++; } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + int mx = min(y + 2, min(b + 1, r)); + cout << mx * 3 - 3 << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n - 1 + m << "\n"; + for (int i = 1; i <= m; i++) { cout << 1 << " " << i << "\n"; } + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << "\n"; } + return 0; +} +int main() { + string s; + cin >> s; + long long ind = 0; + for (char ch = 'z'; ch >= 'a'; ch--) { + long long last = ind; + for (long long i = ind; i < s.size(); i++) { + if (s[i] == ch) { + cout << ch; + last = i; + } + } + ind = last; + } + cout << endl; + return 0; +} +int main() { + for (;;) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (abs(x1 - x2) > abs(y1 - y2)) + cout << abs(x1 - x2) << endl; + else + cout << abs(y1 - y2) << endl; + break; + } +} +int main() { + int color[3]; + for (int i = 0; i < 3; i++) { cin >> color[i]; } + int min, no; + if (color[0] < color[1] - 1) { + min = color[0] + 2; + no = 0; + } else { + min = color[1] + 1; + no = 1; + } + if (color[2] < min) { no = 2; } + cout << color[no] * 3 - (no - 1) * 3 << endl; +} +int main() { + int n, k; + cin >> n >> k; + int i = 1; + int count = 0; + string str; + cin >> str; + int A[200]; + for (int i = 1; i <= n; i++) A[i] = str[i - 1] - 48; + while (i <= n) { + if (i == n) break; + int max = i; + for (int j = i; j <= i + k; j++) { + if (A[j] == 1) max = j; + } + if (max == i) { + cout << -1 << endl; + return 0; + } + count++; + i = max; + } + cout << count << endl; + return 0; +} +int main() { + int a, b, c, num = 0; + cin >> a >> b >> c; + for (int i = 1; i <= a; i++) { + if (i * 2 <= b && i * 4 <= c) { num = i + i * 2 + i * 4; } + } + cout << num << endl; + return 0; +} +int x, i, j, a[400], min1; +int main() { + while (cin >> x) { + for (i = 1; i <= x; i++) { cin >> a[i]; } + min1 = 360; + for (i = 0; i <= x; i++) { + int s = 0; + for (j = i; j < x; j++) { + s += a[j]; + min1 = min(abs(360 - 2 * s), min1); + } + } + cout << min1 << endl; + } +} +int main() { + long long x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + if (abs(x2 - x1) % x != 0 || abs(y2 - y1) % y != 0) + cout << "NO\n"; + else { + int num = (x2 - x1) / x, num1 = (y2 - y1) / y; + if (abs(num - num1) % 2 == 1) + cout << "NO\n"; + else + cout << "YES\n"; + } + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else if (n2 >= n1) + cout << "Second" << endl; + return 0; +} +void fastio() {} +int main() { + fastio(); + long long q; + cin >> q; + while (q--) { + long long l, r, d; + cin >> l >> r >> d; + long long xx = r % d, yy = l % d; + if (d < l) + cout << d << endl; + else { + if (xx >= 1) + cout << r + (d - xx) << endl; + else { + cout << r + d << endl; + } + } + } +} +bool cmp(int a, int b) { + return a < b; +} +int main() { + int sum = 0; + int n; + for (int i = 0; i < 5; i++) { + cin >> n; + sum += n; + } + if (sum == 0) { + cout << -1 << endl; + return 0; + } + if (sum % 5 == 0) + cout << sum / 5 << endl; + else + cout << -1 << endl; +} +int main() { + string ans, s; + cin >> s; + int i = s.size() / 2 - 1; + if (s.size() % 2 == 1) i++; + int p = i + 1; + for (; i >= 0; i--, p++) { + ans.push_back(s[i]); + if (p < s.size()) ans.push_back(s[p]); + } + cout << ans << endl; +} +int main() { + int n, d; + cin >> n >> d; + string s; + cin >> s; + int dp[n]; + for (int i = 0; i < n; ++i) { dp[i] = 1e9; } + dp[0] = 0; + for (int i = 0; i < s.size(); ++i) { + if (s[i] == '1') { + for (int j = i - 1; j >= 0 && i - j <= d; --j) { + if (s[j] == '1') dp[i] = min(dp[j] + 1, dp[i]); + } + } + } + if (dp[n - 1] == 1e9) + cout << -1 << endl; + else + cout << dp[n - 1] << endl; +} +int main() { + int n; + int ma = -2501; + int x = 0; + string h[51]; + int r[51], p[51], m[51], a[51], b[51], c[51], d[51], e[51]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> h[i] >> p[i] >> m[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; + r[i] = (p[i] * 100) - (m[i] * 50) + a[i] + b[i] + c[i] + d[i] + e[i]; + if (ma <= r[i]) { + ma = r[i]; + x = i; + } + } + cout << h[x] << endl; + return 0; +} +const int MAX = 1e5 + 5; +int n, arr[MAX], cnt, ans; +set dict; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + dict.insert(arr[i]); + } + cnt = 0; + for (set::iterator it = dict.begin(); it != dict.end(); ++it) cnt++; + if (cnt < 3) { + cout << "0" << endl; + return 0; + } + sort(arr, arr + n); + ans = n; + for (int i = 0; i < n; i++) { + if ((arr[i] == arr[0]) || (arr[i] == arr[n - 1])) ans--; + } + cout << ans << endl; + return 0; +} +const int INF = 2147483647, MOD = 1000000007; +const double eps = 1e-8; +int dist[1010], bak[1010]; +int main() { + int T; + T = 1; + for (int tc = 1; tc <= T; tc++) { + int m, k; + cin >> m >> k; + int dist_sum = 0; + for (int i = 0; i < m; i++) { + cin >> dist[i]; + dist_sum += dist[i]; + } + for (int i = 0; i < m; i++) cin >> bak[i]; + int mn = 0; + int mybak = 0, best = 0; + for (int cur = 0; cur < m; cur++) { + mybak += bak[cur]; + if (bak[cur] > best) best = bak[cur]; + while (mybak < dist[cur]) { + mybak += best; + mn += k; + } + mn += dist[cur]; + mybak -= dist[cur]; + } + cout << mn << endl; + } + return 0; +} +int main() { + int n, res = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + int x = 0, y = 0; + if (s[i] == 'U') + y++; + else if (s[i] == 'L') + x--; + else if (s[i] == 'R') + x++; + else if (s[i] == 'D') + y--; + for (int j = i + 1; j < n; j++) { + if (s[j] == 'U') + y++; + else if (s[j] == 'L') + x--; + else if (s[j] == 'R') + x++; + else if (s[j] == 'D') + y--; + if (x == 0 && y == 0) res++; + } + } + cout << res << endl; + return 0; +} +vector v; +void solve() { + long long num, k; + cin >> num >> k; + long long square_root = (long long)sqrt(num) + 1; + for (long long i = 1; i < square_root; i++) { + if (num % i == 0 && i * i != num) { + v.push_back(i); + v.push_back(num / i); + } + if (num % i == 0 && i * i == num) v.push_back(i); + } + sort((v).begin(), (v).end()); + if (k <= v.size()) + cout << v[k - 1] << '\n'; + else + cout << -1 << '\n'; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +char s[100005]; +int n, k, ap[27], res = 100005; +int main() { + cin >> n >> k >> s; + for (int i = 0; i < n; i++) { ap[int(s[i]) - 64]++; } + for (int i = 1; i <= k; i++) { res = min(res, ap[i]); } + cout << res * k << '\n'; + return 0; +} +const int INF = 1e9 + 5; +int u[210], d[210], r[210], l[210]; +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + if (i == 0) { + u[i] = 0; + r[i] = 0; + d[i] = 0; + l[i] = 0; + if (s[i] == 'U') + u[i] = 1; + else if (s[i] == 'R') + r[i] = 1; + else if (s[i] == 'D') + d[i] = 1; + else if (s[i] == 'L') + l[i] = 1; + } else { + if (s[i] == 'U') { + l[i] = l[i - 1]; + d[i] = d[i - 1]; + r[i] = r[i - 1]; + u[i] = u[i - 1] + 1; + } else if (s[i] == 'R') { + u[i] = u[i - 1]; + l[i] = l[i - 1]; + d[i] = d[i - 1]; + r[i] = r[i - 1] + 1; + } else if (s[i] == 'D') { + u[i] = u[i - 1]; + l[i] = l[i - 1]; + r[i] = r[i - 1]; + d[i] = d[i - 1] + 1; + } else if (s[i] == 'L') { + u[i] = u[i - 1]; + r[i] = r[i - 1]; + d[i] = d[i - 1]; + l[i] = l[i - 1] + 1; + } + } + } + long long ans = 0; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + if (u[j] - u[i - 1] == d[j] - d[i - 1] && r[j] - r[i - 1] == l[j] - l[i - 1]) ans++; + } + } + cout << ans << endl; + return 0; +} +const long long int INF = (long long int)(8e16); +const long long int MOD = 1000000007; +long long int a[501], dp[501][501], Dp[501][501]; +int main() { + long long int n, m, b, mod; + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (j == 1) dp[j][a[i]]++; + for (int k = 0; k <= b; k++) { + if (k >= a[i]) { dp[j][k] += dp[j - 1][k - a[i]]; } + dp[j][k] += Dp[j][k]; + dp[j][k] %= mod; + } + } + for (int j = 1; j <= m; j++) { + for (int k = 0; k <= b; k++) { + Dp[j][k] = dp[j][k]; + dp[j][k] = 0; + } + } + } + long long int ans = 0; + for (int j = 0; j <= b; j++) { + ans += Dp[m][j]; + ans %= mod; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int m = n; + if (m >= 3) m--; + int k1 = (m) / 3, k2 = (m) / 3, k3 = (m) / 3, ost = (m) % 3; + if (ost > 0) k1++; + if (ost > 1) k2++; + int a[4]; + a[0] = k1; + a[1] = k2; + a[2] = 0; + a[3] = k3; + cout << "+------------------------+" << endl; + for (int i = 0; i < 4; i++) { + if (i == 2) { + if (n >= 3) { + cout << "|O.......................|" << endl; + } else { + cout << "|#.......................|" << endl; + } + } else { + cout << "|"; + for (int ind = 0; ind < 21; ind++) { + if (ind % 2 == 0) { + if (a[i] > 0) { + cout << 'O'; + a[i]--; + } else if (a[i] == 0) { + cout << '#'; + } + } else + cout << '.'; + } + if (i == 0) { + cout << ".|D|)" << endl; + } else if (i == 1) { + cout << ".|.|" << endl; + } else if (i == 3) { + cout << ".|.|)" << endl; + } + } + } + cout << "+------------------------+" << endl; + return 0; +} +int main() { + string s; + int arr[1001]; + getline(cin, s); + int alpha = 0; + for (int i = 0; i < s.size(); ++i) { + if (s[i] >= 'a' && s[i] <= 'z') { + ++alpha; + for (int j = i + 1; j <= s.size(); ++j) { + if (s[j] == s[i]) s[j] = '0'; + } + } + } + cout << alpha << endl; +} +long long n, m, a, b, c; +long long Yellow, Blue, ans; +int main() { + cin >> n >> m >> a >> b >> c; + Yellow = a * 2 + b; + Blue = b + c * 3; + if (Yellow > n) ans += Yellow - n; + if (Blue > m) ans += Blue - m; + cout << ans << endl; + return 0; +} +int main() { + int m, n, b, mod, a[505]; + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + int dp[505][505]; + memset(dp, 0, sizeof(dp)); + dp[0][0] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int t = a[i]; t <= b; t++) { + dp[j][t] += dp[j - 1][t - a[i]]; + dp[j][t] %= mod; + } + int sum = 0; + for (int i = 0; i <= b; i++) sum = (sum + dp[m][i]) % mod; + cout << sum << endl; + return 0; +} +long long int arr[100005]; +vector vec; +int main() { + int n; + cin >> n; + string s; + cin >> s; + int i = 0; + while (i < s.length()) { + if (s[i] == 'U' && s[i + 1] == 'R') { + vec.push_back('D'); + i += 2; + } else if (s[i] == 'R' && s[i + 1] == 'U') { + vec.push_back('D'); + i += 2; + } else { + vec.push_back(s[i]); + i++; + } + } + cout << vec.size() << endl; + return 0; +} +int main() { + int p[3]; + for (int i = 0; i < 3; i++) { cin >> p[i]; } + int time; + while (true) { + bool ok = true; + for (int i = 0, j = 0;; i++, j++) { + if (i == 3) { + if (ok) break; + i = 0; + ok = true; + } + if (p[i] > 0) { + time = j; + ok = false; + p[i] -= 2; + } + } + if (ok) break; + } + cout << 30 + time << endl; + return 0; +} +int main() { + int k, l, m, n, d, i, sum = 0; + cin >> k >> l >> m >> n >> d; + for (i = 1; i <= d; i++) { + if (i % k == 0) + sum++; + else if (i % l == 0) + sum++; + else if (i % m == 0) + sum++; + else if (i % n == 0) + sum++; + } + cout << sum << endl; +} +int main() { + bool possible(true); + int n, x, a, b; + cin >> n >> x; + while (n--) { + cin >> a >> b; + if (x == a || x == b || x == 7 - a || x == 7 - b) { possible = false; } + x = 7 - x; + } + cout << (possible ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n, m, k, buff = 0; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " L" << endl; + break; + } + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " R" << endl; + break; + } + } + if (buff == k) break; + } + return 0; +} +int main() { + int n = 0; + string word; + cin >> n >> word; + int counter = 0; + for (int i = 1; i < n; i++) { + if (word[i] == word[i - 1]) counter++; + } + cout << counter << endl; +} +int main() { + int n, m, i, j, c = 0, l = 0, g = 0, a = 0, b = 0, a1 = 0, h = 0; + vector p; + cin >> n >> m; + string k = ""; + for (i = 0; i < n; i++) { + cin >> k; + for (j = 0; j < k.size(); j++) { + if (k[j] == '*') { c++; } + } + if (c == 1) { + for (j = 0; j < k.size(); j++) { + if (k[j] == '*') { + g = j + 1; + l = i + 1; + } + } + } else if (c == 2) { + for (j = 0; j < k.size(); j++) { + if (k[j] == '*') { p.push_back(j + 1); } + } + for (j = 0; j < p.size(); j++) { + a = p[0]; + a1 = i + 1; + b = p[1]; + } + } + c = 0; + } + if (g == a) + cout << l << " " << b << endl; + else if (g == b) + cout << l << " " << a << endl; + return 0; +} +long long int dp[100005], a[100005], f[100005]; +int main() { + long long int n, i; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + f[a[i]]++; + } + dp[0] = 0; + dp[1] = f[1]; + for (i = 2; i < 100001; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + i * f[i]); } + cout << dp[100000] << "\n"; + return 0; +} +int main() { + int a, b, c, d, e, f, n, x = 0, y = 0; + cin >> a >> b >> c >> d >> e >> f >> n; + if ((a + b + c) % 5 != 0) { x++; } + if ((d + e + f) % 10 != 0) { y++; } + x += (a + b + c) / 5; + y += (d + e + f) / 10; + if (x + y <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long int a, b; + cin >> a >> b; + long long int c = a + b; + long long int a_, b_, c_; + a_ = b_ = c_ = 0; + while (a) { + if (a % 10) { a_ = (10 * a_) + (a % 10); } + a /= 10; + } + while (b) { + if (b % 10) { b_ = 10 * b_ + (b % 10); } + b /= 10; + } + while (c) { + if (c % 10) { c_ = 10 * c_ + (c % 10); } + c /= 10; + } + while (a_) { + a = 10 * a + (a_ % 10); + a_ /= 10; + } + while (b_) { + b = 10 * b + (b_ % 10); + b_ /= 10; + } + while (c_) { + c = 10 * c + (c_ % 10); + c_ /= 10; + } + if (a + b == c) + cout << "YES"; + else + cout << "NO"; + cout << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n = c / a; + for (int i = n; i >= 0; i--) { + if ((c - (a * i)) % b == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + int n, m; + string buffer; + while (getline(cin, buffer)) { + stringstream ss(buffer); + ss >> n >> m; + int izq = 1; + int der = n; + int paila = 0; + for (int i = 0; i < m; ++i) { + getline(cin, buffer); + stringstream s(buffer); + string dir; + s >> buffer >> buffer >> dir >> buffer; + int pos; + s >> pos; + if (dir == "left") { + der = min(der, pos - 1); + } else { + izq = max(izq, pos + 1); + } + if (der < izq) paila = 1; + } + if (paila) + cout << -1 << endl; + else + cout << der - izq + 1 << endl; + } + return 0; +} +int isprime(int n); +int main() { + long int n, a, b; + cin >> n; + a = 4; + b = n - 4; + for (int i = 1; i <= n; i++) { + int m = isprime(a); + int n = isprime(b); + if (m == 1 && n == 1) { + int k = 1; + cout << a << " " << b << endl; + if (k == 1) { return 0; } + } + a++; + b--; + } +} +int isprime(int k) { + for (int i = 2; i < k; i++) { + if (k % i == 0) { return 1; } + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; + return 0; +} +int main() { + int n, sum1 = 0, sum2 = 0, sum3 = 0; + cin >> n; + vector ch[n]; + for (int i = 0; i < n; i++) { + int u, v, w; + cin >> u >> v >> w; + ch[i].push_back(u); + ch[i].push_back(v); + ch[i].push_back(w); + } + for (int i = 0; i < n; i++) { + sum1 += ch[i][0]; + sum2 += ch[i][1]; + sum3 += ch[i][2]; + } + if (sum1 == 0 && sum2 == 0 && sum2 == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + for (int i = 0; i < n; i++) { ch[i].clear(); } + return 0; +} +const int MAXN = 2e+3 + 50; +int n; +vector tree[MAXN]; +int input[MAXN]; +int ans; +void init() { + for (int i = 0; i <= n; i++) { tree[i].clear(); } + memset(input, 0, sizeof(input)); +} +void dfs(int pos, int cnt) { + if (tree[pos].size() == 0) { + ans = max(ans, cnt); + return; + } + for (int i = 0; i < tree[pos].size(); i++) { dfs(tree[pos][i], cnt + 1); } +} +void solve() { + for (int i = 1; i <= n; i++) { + if (input[i] == -1) { dfs(i, 1); } + } +} +int main() { + while (cin >> n) { + init(); + for (int i = 1; i <= n; i++) { + cin >> input[i]; + if (input[i] != -1) { tree[input[i]].push_back(i); } + } + solve(); + cout << ans << endl; + } + return 0; +} +int n, m; +string str; +int a[1005] = {0}; +int main() { + cin >> n >> m; + for (int i = 1; i <= 1000; i++) a[i] = 1; + getchar(); + while (m--) { + getline(cin, str); + if (str[7] == 'l') { + stringstream ss; + string s; + int t; + for (int i = 15; i < str.size(); i++) s += str[i]; + ss << s; + ss >> t; + ss.clear(); + for (int i = t; i <= n; i++) a[i] = 0; + } + if (str[7] == 'r') { + stringstream ss; + string s; + int t; + for (int i = 16; i < str.size(); i++) s += str[i]; + ss << s; + ss >> t; + ss.clear(); + for (int i = t; i >= 1; i--) a[i] = 0; + } + } + int ans = 0; + for (int i = 1; i <= n; i++) + if (a[i]) ans++; + if (!ans) + cout << -1 << endl; + else + cout << ans << endl; +} +int main() { + long long n, sum = 0; + cin >> n; + long long b[n]; + for (long long i = 0; i < n; i++) { + long long x; + cin >> x; + sum += x; + } + for (long long i = 0; i < n; i++) { cin >> b[i]; } + sort(b, b + n); + cout << (b[n - 2] + b[n - 1] >= sum ? "YES" : "NO") << '\n'; + return 0; +} +long long n, k, count; +vector bisa; +int main() { + cin >> n >> k; + for (long long i = 1; i <= sqrt(n); i++) { + if (n % i == 0 && i * i != n) { + bisa.push_back(i); + bisa.push_back(n / i); + } + if (i * i == n) { bisa.push_back(i); } + } + sort(bisa.begin(), bisa.end()); + if (n == 1 && k > 1) { + cout << "-1" << endl; + } else if (bisa.size() >= k) { + cout << bisa[k - 1] << endl; + } else { + cout << "-1" << endl; + } +} +int main() { + int num; + cin >> num; + if (num % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } +} +int CT[205]; +int main() { + for (int i = 2; i <= 100; i++) { + if (i <= 7) CT[i] = 1; + for (int j = 2; j <= 7; j++) + if (!CT[i + j]) CT[i + j] = CT[i] + 1; + } + int a, N; + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> a; + cout << CT[a] << '\n'; + } + return 0; +} +int main() { + int sum = 0, q; + string a; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> a; + if (a[1] == '+') { + sum++; + } else { + sum--; + } + } + cout << sum << endl; + return 0; +} +int main() { + int gl, gr, bl, br; + cin >> gl >> gr >> bl >> br; + if (2 * (gl + 1) >= br && gl - 1 <= br || 2 * (gr + 1) >= bl && gr <= bl) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + string s; + cin >> s; + vector a(s.size(), 1); + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) a[i] += a[i - 1]; + } + for (int i = n; i < s.size(); i += n) + if (a[i - 1] > 2) ans++; + cout << ans << endl; + return 0; +} +const int M = 1000 + 5; +int ihash[M]; +int main() { + int n; + cin >> n; + for (int m = 0; m <= 2 * n; m++) { + int x = m * (m + 1) / 2; + ihash[x % n] = 1; + } + bool ok = true; + for (int i = 0; i < n; i++) { + if (ihash[i] == 0) { + ok = false; + break; + } + } + if (ok == true) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +bool cmp(int a, int b) { + return a < b; +} +int main() { + char s[100003]; + int n; + while (cin >> n) { + cin >> s; + int sum_A = 0; + int sum_D = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') + sum_A++; + else + sum_D++; + } + if (sum_A > sum_D) + cout << "Anton" << endl; + else if (sum_A < sum_D) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + } +} +bool bisa(string subs) { + int u, d, r, l; + u = 0; + d = 0; + r = 0; + l = 0; + for (int i = 0; i < subs.length(); i++) { + if (subs[i] == 'U') { + u++; + } else if (subs[i] == 'D') { + d++; + } else if (subs[i] == 'R') { + r++; + } else if (subs[i] == 'L') { + l++; + } + } + if (l == r && u == d) { + return true; + } else { + return false; + } +} +int main() { + long n, counter; + counter = 0; + string kata; + cin >> n; + cin >> kata; + for (int pjg = 2; pjg <= n; pjg += 2) { + for (int imulai = 0; (imulai + pjg) <= n; imulai++) { + if (bisa(kata.substr(imulai, pjg))) { counter++; } + } + } + cout << counter << endl; + return 0; +} +const int M = 100 + 10; +int main() { + int x; + cin >> x; + int n = -1; + for (int i = 1; i <= 100 && n == -1; i += 2) { + int m = (i - 1) / 2; + if (m & 1) { + for (int b = 0; b <= m - 1; b++) { + for (int a = 0; a <= (m * m + 1) / 2; a++) { + int num = 4 * a + 2 * b + 1; + if (num == x) { n = i; } + } + } + for (int b = 0; b <= m + 1; b++) { + for (int a = 0; a <= (m * m + 1) / 2 - 1; a++) { + int num = 4 * a + 2 * b + 0; + if (num == x) { n = i; } + } + } + for (int b = 0; b <= m - 1; b++) { + for (int a = (m * m + 1) / 2; a <= (m * m + 1) / 2; a++) { + int num = 4 * a + 2 * b + 0; + if (num == x) { n = i; } + } + } + } else { + for (int a = 0; a <= m * m / 2; a++) { + for (int b = 0; b <= m; b++) { + for (int c = 0; c <= 1; c++) { + int num = 4 * a + 2 * b + c; + if (num == x) { n = i; } + } + } + } + } + } + cout << n << endl; + return 0; +} +long long dp[100005]; +long long freq[100005]; +long long a[100005]; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> a[i]; + freq[a[i]]++; + } + for (long long i = 100000; i > 0; i--) { dp[i] = max(i * freq[i] + dp[i + 2], dp[i + 1]); } + cout << dp[1] << "\n"; +} +pair p[105]; +bool a[105]; +int n; +void dfs(int k) { + if (a[k]) + return; + else + a[k] = true; + for (int i = 0; i < n; i++) { + if (p[i].first == p[k].first || p[i].second == p[k].second) dfs(i); + } + return; +} +int main() { + cin >> n; + int comp = 0; + int x, y; + for (int i = 0; i < n; i++) { + cin >> x >> y; + p[i] = {x, y}; + } + for (int i = 0; i < n; i++) { + if (!a[i]) { + comp++; + dfs(i); + } + } + comp--; + if (comp <= 0) + cout << 0 << endl; + else + cout << comp << endl; +} +int n, cnt; +char s[55], ans[55]; +int main() { + gets(s); + int n = strlen(s); + cnt = n; + int l = 0, r = n - 1; + int cur = n & 1; + while (l < r) { + if (cur & 1) { + ans[--cnt] = s[l]; + l++; + } else { + ans[--cnt] = s[r]; + r--; + } + cur++; + } + if (l == r) ans[--cnt] = s[l]; + puts(ans); + return 0; +} +int main() { + vector s(4); + cin >> s[0] >> s[1] >> s[2] >> s[3]; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + cout << 4 - s.size() << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int res = m - 1; + for (int i = 0; i < m; i++) { + vector aux; + int k; + cin >> k; + for (int j = 0; j < k; j++) { + int x; + cin >> x; + aux.push_back(x); + } + if (aux[0] == 1) { + int j; + for (j = 1; j < aux.size(); j++) + if (aux[j] != aux[j - 1] + 1) break; + res += (aux.size() - j) * 2; + } else + res += (k - 1) * 2; + } + cout << res << endl; + return 0; +} +vector VI, VI2, VI3, VI4; +int n, m, f, t, a, b; +string s; +int remove_zero(int a) { + int b = 0, c = 1, t; + while (a) { + t = a % 10; + a /= 10; + if (t) { + b += t * c; + c *= 10; + } + } + return b; +} +int main() { + cin >> a >> b; + int c = a + b; + a = remove_zero(a); + b = remove_zero(b); + c = remove_zero(c); + if (a + b == c) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[20]; +int lzl(int x) { + int sum = 0, z = 0; + while (x) { + a[z++] = x % 10; + x /= 10; + } + for (int i = z - 1; i >= 0; i--) + if (a[i]) sum = sum * 10 + a[i]; + return sum; +} +int main() { + int a, b; + while (cin >> a >> b) { + int t = a + b; + t = lzl(t); + int w = lzl(a) + lzl(b); + if (t == w) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + string A; + int i, j, t, k = 0, count = 1; + cin >> A; + int l = A.size(); + j = l - 1; + t = ceil(l / 2.0); + for (i = 0; i < t; i++) { + if (A[i] != A[j]) { + count = 0; + break; + } + j--; + } + j = l - 1; + if (count == 0) { + cout << l << endl; + return 0; + } else { + while (k < t) { + for (i = k; i < t; i++) { + if (A[i] != A[j]) { + cout << l - k << endl; + return 0; + } + j--; + } + k = k + 1; + j = l - 1; + } + } + cout << "0" << endl; + return 0; +} +const int N = 1e5 + 10; +int main() { + int n; + cin >> n; + int a[N], b[N]; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (int i = 0; i < n; i++) cin >> b[i]; + sort(b, b + n, greater()); + if (sum <= (b[0] + b[1])) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[100005]; +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < k; i++) { + int tmp; + cin >> tmp; + cin >> a[0]; + if (a[0] == 1) { + for (int j = 1; j < tmp; j++) { + cin >> a[j]; + if (a[j] != j + 1) ans += 2; + } + continue; + } + for (int j = 1; j < tmp; j++) { cin >> a[j]; } + ans += tmp - 1; + ans += tmp; + } + cout << ans << endl; + return 0; +} +const int a[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; +int n; +int main() { + cin >> n; + for (int i = 0; i < 10; i++) + if (a[i] == n) { + puts("YES"); + return 0; + } + puts("NO"); + return 0; +} +int main() { + int n; + cin >> n; + cout << "+"; + for (int i = 1; i <= 24; i++) cout << "-"; + cout << "+" + << "\n"; + for (int i = 1; i <= 4; i++) { + cout << "|"; + for (int j = 0; j < 11; j++) { + if (j == 0) { + if (i <= n) + cout << "O."; + else + cout << "#."; + } else { + if (i == 3) + cout << ".."; + else if (i != 3) { + int m; + if (i >= 4) + m = 3; + else + m = i; + if ((4 + (j - 1) * 3 + m) <= n) + cout << "O."; + else + cout << "#."; + } + } + } + if (i == 1) + cout << "|D|)"; + else if (i == 2) + cout << "|.|"; + else if (i == 3) + cout << "..|"; + else + cout << "|.|)"; + cout << "\n"; + } + cout << "+"; + for (int i = 1; i <= 24; i++) cout << "-"; + cout << "+" + << "\n"; + return 0; +} +int main() { + int a, b; + int n; + cin >> n; + bool flag = 0; + for (a = 4; a < n; a++) { + for (int j = 2; j < a; j++) { + if (a % j == 0) { + flag = 1; + break; + } + } + if (flag) { + flag = 0; + b = n - a; + for (int k = 2; k < b; k++) { + if (b % k == 0) { + flag = 1; + break; + } + } + } + if (flag) { + cout << a << " " << b << endl; + break; + } + } +} +int a[30]; +int main() { + string s; + cin >> s; + int n = s.length(); + int maxx = 0; + for (int i = 0; i < n; i++) { + a[s[i] - 97]++; + maxx = max(maxx, s[i] - 97); + } + for (int i = 0; i < n; i++) { + while (a[maxx] == 0 && maxx > 0) { maxx--; } + if (maxx == s[i] - 97) { cout << s[i]; } + a[s[i] - 97]--; + } + cout << endl; +} +int main() { + int n, k; + while (cin >> n >> k) { + int ut[125]; + memset(ut, 0, sizeof(ut)); + for (int i = 0; i < n; i++) { + int a; + cin >> a; + ut[a]++; + } + int maxn = 0, count = 0; + for (int i = 0; i < 115; i++) { + if (ut[i] > 0) { + count++; + if (ut[i] > maxn) maxn = ut[i]; + } + } + if (maxn % k == 0) { + cout << maxn * count - n << endl; + } else { + maxn = maxn / k + 1; + maxn *= k; + cout << maxn * count - n << endl; + } + } +} +map q; +int x, ans; +int main() { + for (int i = 0; i < 4; i++) { + cin >> x; + if (q[x] == 1) ans++; + q[x] = 1; + } + cout << ans << endl; +} +int min(int x, int y, int z) { + int t = 0; + if (x < y) { + if (x < z) { + t = 1; + } else { + t = -1; + } + } else { + if (y < z) { + t = 0; + } else + t = -1; + } + return t; +} +int main() { + int y, b, r; + int sum = 0; + cin >> y >> b >> r; + if (y == b && b == r && r == y) { sum = 3 * (y - 1); } + int x = min(y, b, r); + if (x == 1) { + if ((b - y) >= 1 && (r - y) >= 2) { + sum = (y + 1) * 3; + } else { + while (!((b - y) >= 1 && (r - y) >= 2)) { y--; } + sum = (y + 1) * 3; + } + } else if (x == 0) { + if (b == r) { + sum = 3 * (b - 1); + } else { + sum = 3 * b; + } + } else { + sum = (r - 1) * 3; + } + cout << sum << endl; + return 0; +} +int n, k; +int ans = 0; +int sum = 0; +int main() { + cin >> n >> k; + for (int i = 0; i < k; ++i) { + int m; + cin >> m; + int pr = -1; + int f = m; + int ff = -1; + for (int j = 0; j < m; ++j) { + int x; + cin >> x; + if (j == 0) { ff = x; } + if (x != pr + 1 && j) { f = min(f, j); } + pr = x; + } + if (ff != 1) { + ans += m - 1; + sum += m; + } else { + ans += m - f; + sum += m - f + 1; + } + } + cout << ans + (sum - 1) << '\n'; + return 0; +} +int main() { + int n, a, b, p = 0, sm = 0, st = 0; + for (int i = 0; i < 3; i++) { + cin >> a; + st += a; + } + for (int i = 0; i < 3; i++) { + cin >> b; + sm += b; + } + p += st / 5; + st %= 5; + if (st > 0) p++; + p += sm / 10; + sm %= 10; + if (sm > 0) p++; + cin >> n; + if (p <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + set d; + cin >> n; + int t, x, y; + cin >> t; + int f = 0; + while (n--) { + cin >> x >> y; + if (x == t || x == 7 - t || y == t || y == 7 - t) f++; + } + if (f > 0) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int a[100005]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i < n; i++) { cout << a[i] + a[i + 1] << ' '; } + cout << a[n] << endl; + } +} +int main() { + string s; + getline(cin, s); + while (s.length() == 0) { getline(cin, s); } + int arr[26] = {0}; + int i, count = 0; + for (i = 1; i < s.length() - 1; i = i + 3) { + if (s[i] != ',' || s[i] != ' ' || s[i] != '{' || s[i] != '}') { arr[s[i] - 'a']++; } + } + for (i = 0; i < 26; i++) { + if (arr[i] >= 1) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + int num; + cin >> num; + int k = 7 - num; + int flag = 0; + for (int i = 0; i < n; ++i) { + int a, b; + cin >> a >> b; + if (i == 0) continue; + int c = 7 - a, d = 7 - b; + if (k == a || k == b || k == c || k == d) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + long long l, r, d; + cin >> l >> r >> d; + if (l > d) + cout << d << endl; + else { + long long ind = r / d; + ind++; + cout << (d * ind) << endl; + } + } + return 0; +} +int main() { + int n; + int a = 0, b = 0; + int t, sum1, sum2; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t; + if (t == 1) a++; + if (t == 2) b++; + } + sum1 = a / 3 + min(a % 3, b); + if ((a - b) > 0) + sum2 = min(a, b) + (a - b) / 3; + else + sum2 = a; + cout << max(sum1, sum2) << endl; + return 0; +} +int main() { + int test, h = 0, i, count = 0; + string stone_color; + cin >> test; + cin >> stone_color; + for (i = 0; i < stone_color.size(); i++) { + if (stone_color[i] == stone_color[i + 1]) count++; + } + cout << count << endl; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n, key = 0; + int a[2005]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == 1) { key++; } + } + if (key > 0) { + cout << n - key << endl; + return 0; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j < n; j++) { + a[j] = gcd(a[j], a[j + 1]); + if (a[j] == 1) { + cout << n - 1 + i << endl; + return 0; + } + } + } + cout << -1 << endl; +} +int main() { + int x; + cin >> x; + if (x == 1) + cout << 1 << endl; + else if (x == 2) + cout << 3 << endl; + else if (x == 3) + cout << 5 << endl; + else { + for (int i = 1;; i += 2) { + int aux = i; + for (int j = 1; j < i; j += 2) aux += j * 2; + if (aux >= x) { + cout << i << endl; + return 0; + } + } + } + return 0; +} +int main() { + int n, m, l; + cin >> n >> m; + if (n % 2 == 0) { + l = n / 2; + } else + l = n / 2 + 1; + int ans = -1; + for (int i = l; i <= n; i++) { + if (i % m == 0) { + ans = i; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d[6], i; + cin >> a >> b >> c; + d[0] = a + (b + c); + d[1] = a + b + c; + d[2] = (a + b) * c; + d[3] = a * b * c; + d[4] = (a * b) + c; + d[5] = a * (b + c); + for (i = 0; i < 6; i++) { + if (d[0] < d[i]) { d[0] = d[i]; } + } + cout << d[0] << endl; + return 0; +} +int main() { + int n, m, i, j, ans = 0; + int b[10][10]; + bool r[10], c[10]; + memset(r, true, sizeof(r)); + memset(c, true, sizeof(c)); + memset(b, 0, sizeof(b)); + char s[10][10]; + cin >> n >> m; + for (i = 0; i < n; i++) { cin >> s[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (s[i][j] == '.') { + b[i][j] = 1; + } else { + r[i] = false; + c[j] = false; + } + } + } + for (i = 0; i < n; i++) { + if (r[i]) { + ans += m; + for (j = 0; j < m; j++) b[i][j]++; + } + } + for (i = 0; i < m; i++) { + if (c[i]) { + ans += n; + for (j = 0; j < n; j++) { + if (b[j][i] != 1) ans--; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int k, n, s, p; +int main() { + cin >> k >> n >> s >> p; + cout << (k * ((n + s - 1) / s) + p - 1) / p << endl; + return 0; +} +const int N = 1e5 + 10; +int main() { + int n; + cin >> n; + long long a[N], b[N]; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (int i = 0; i < n; i++) cin >> b[i]; + sort(b, b + n, greater()); + if (sum <= (b[0] + b[1])) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + char a[101][101]; + while (cin >> n >> m) { + char temp; + int flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { flag = 1; } + } + } + if (flag == 1) + cout << "#Color\n"; + else + cout << "#Black&White\n"; + } + return 0; +} +const int N = 4e7; +int p[N]; +int main() { + long long n, k; + cin >> n >> k; + int index = 0; + for (long long i = 1; i * i <= n; i++) + if (n % i == 0) p[++index] = i; + bool is_square = (long long)p[index] * p[index] == n; + int cnt = index * 2 - is_square; + if (k <= index) + cout << p[k] << endl; + else if (k > cnt) + cout << -1 << endl; + else + cout << n / p[2 * index - k + !is_square] << endl; + return 0; +} +int n; +char s[6000000]; +char t[6000000]; +int main() { + cin >> n; + cin >> s; + int lens = strlen(s); + for (int i = 1; i <= lens; i++) { t[i] = s[i - 1]; } + int ans = 0; + for (int i = n + 1; i <= lens; i += n) { + if (t[i - 3] == t[i - 2] && t[i - 2] == t[i - 1]) { ans++; } + } + cout << ans << endl; + return 0; +} +int takeStones(char arr[]) { + if (arr[0] == '\0') return 0; + int smallAns = takeStones(arr + 1); + if (arr[0] == arr[1]) { + int i; + for (i = 2; arr[i] != '\0'; i++) { arr[i - 1] = arr[i]; } + arr[i - 1] = '\0'; + return 1 + smallAns; + } else + return smallAns; +} +int main() { + int n; + cin >> n; + char *str = new char[n + 1]; + cin >> str; + cout << takeStones(str) << endl; +} +const int maxn = 100; +const int inf = 0x3f3f3f3f; +char a[maxn]; +int main() { + cin >> a; + int flag = 1; + int len = strlen(a); + for (int i = 0; i < len; i++) { + if (a[i] != a[i + 1] && i + 1 < len) { + flag = 0; + break; + } + } + if (flag == 1) { + cout << "0" << endl; + return 0; + } else { + int f = 0; + for (int i = 0; i < len / 2; i++) { + if (a[i] != a[len - 1 - i]) { + cout << len << endl; + return 0; + } + } + cout << len - 1 << endl; + } + return 0; +} +int main() { + string s; + while (cin >> s) { + string ans(""); + int len = s.length(); + int left = 0, right = len - 1; + if (len & 1) { + ans = ans + s[0]; + left++; + } + while (left < right) { + ans = s[right--] + ans; + ans = s[left++] + ans; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[1005]; + for (int i = 0; i < n; i++) cin >> a[i]; + int j = 0, sum = 2; + while (a[j] < a[j + 1]) { + sum++; + j++; + } + while (a[j] == a[j + 1]) { + sum++; + j++; + } + while (a[j] > a[j + 1]) { + sum++; + j++; + } + if (sum <= n) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, m; + while (cin >> n >> m) { + int answ = 0, needToUnion = 0; + for (int id = 0; id < m; ++id) { + int s; + cin >> s; + vector arr(s); + for (int i = 0; i < s; ++i) { cin >> arr[i]; } + int p = 0; + while (p < s && arr[p] == p + 1) { ++p; } + needToUnion += (p != 0) + (s - p); + answ += (p != 0 && p != s) + max(0, (s - p - 1)); + } + answ += needToUnion - 1; + cout << answ << endl; + } + return 0; +} +int zeroRemover(int x) { + int tmp; + int result = 0; + int y = 1; + while (x != 0) { + tmp = x % 10; + if (tmp != 0) { + result = result + tmp * y; + y = y * 10; + } + x = x / 10; + } + return result; +} +int main() { + int a, b; + cin >> a >> b; + int c, d; + c = a + b; + a = zeroRemover(a); + b = zeroRemover(b); + c = zeroRemover(c); + d = a + b; + if (c == d) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long N, A, sum, ans = 2e9, H; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> A; + if (A % 2) { + H++; + ans = min(ans, A); + } + sum += A; + } + if (H % 2) sum -= ans; + cout << sum << '\n'; +} +int main() { + int a, b, c, s = 0; + cin >> a >> b >> c; + while (1) { + if (b >= a + 1) { + if (c >= a + 2) { + s = a + a + 1 + a + 2; + break; + } + } + a--; + } + cout << s << endl; + return 0; +} +int main() { + int arr[120]; + int n, k; + int mode[120]; + int num_unique = 0; + int max_mode_val = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + mode[arr[i]] = 0; + } + for (int i = 0; i < n; i++) { + mode[arr[i]]++; + if (max_mode_val < mode[arr[i]]) { max_mode_val = mode[arr[i]]; } + if (mode[arr[i]] == 1) { num_unique++; } + } + int min_dishes = 0; + if (max_mode_val % k == 0) { + min_dishes = max_mode_val / k; + } else { + min_dishes = max_mode_val / k + 1; + } + cout << num_unique * min_dishes * k - n << endl; + return 0; +} +vector is_prime(1000000 + 1, false); +void prealoc() { + is_prime[0] = is_prime[1] = is_prime[2] = false; + for (int i = 4; i <= 1000005; i += 2) is_prime[i] = true; + for (int i = 3; i * i <= 1000005; i += 2) { + if (!(is_prime[i])) + for (int j = 2 * i; j <= 1000005; j += i) is_prime[j] = true; + } +} +int main() { + prealoc(); + int n; + while (cin >> n) { + for (int i = 4; i <= n / 2; i++) { + if (is_prime[i]) { + if (is_prime[n - i]) { + cout << i << " " << n - i << endl; + break; + } + } + } + } + return 0; +} +int main() { + int r; + int c; + bool color = false; + cin >> r >> c; + r = r * c; + while (r--) { + char ct; + cin >> ct; + if (ct == 'C' || ct == 'Y' || ct == 'M') { color = true; } + } + if (color) { + cout << "#Color" << endl; + } else { + cout << "#Black&White" << endl; + } + return 0; +} +int n; +int now = 1, sum, minute_ = 1; +bool bo[10001]; +int main() { + cin >> n; + while (minute_ <= n + 1 && sum < n) { + now = (now + minute_ - 1) % n; + if (!bo[now]) { + bo[now] = 1; + sum++; + } + minute_++; + } + if (sum == n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int i, j, k = 0, l, n; + cin >> n; + string s; + cin >> s; + l = s.size(); + for (i = n - 3; i < l - 3; i += n) { + if (s[i] == s[i + 1] && s[i + 1] == s[i + 2]) k++; + } + cout << k << endl; +} +int gcd(int x, int y) { + int z = min(x, y); + int res; + while (true) { + if (x % z == 0 && y % z == 0) { + res = z; + break; + } + z--; + } + return res; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + bool check = false; + int mod, k = n; + while (true) { + if (check == false) { + mod = gcd(a, k); + check = true; + } else { + mod = gcd(b, k); + check = false; + } + k = k - mod; + if (k == 0) { break; } + } + if (check == false) { + cout << "1" << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + string str; + cin >> str; + int len = str.length(); + bool flag = true; + for (int i = 1; i < len; i++) { + if (str[i] != str[i - 1]) { + flag = false; + break; + } + } + if (flag == true) + puts("0"); + else { + bool flag1 = true; + for (int i = 0, j = len - 1; i < len, j >= 0; j--, i++) { + if (str[i] != str[j]) { + flag1 = false; + break; + } + } + if (flag1) + cout << len - 1 << endl; + else + cout << len << endl; + } + return 0; +} +int a[105]; +int main() { + for (int i = 1; i <= 101; i++) { + if (i & 1) a[i] = (i / 2 + 1) * (i / 2 + 1) + (i / 2) * (i / 2); + } + int x; + cin >> x; + if (x == 3) { + cout << 5 << endl; + return 0; + } + for (int i = 1; i <= 101; i++) { + if (a[i] >= x) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, m, x = 0; + cin >> n >> m; + if (m > n) + cout << "-1" << endl; + else { + if (n % 2 == 0) + x = n / 2; + else + x = (n / 2) + 1; + while (x % m != 0) x++; + cout << x << endl; + } + return 0; +} +int main() { + int a, s, z, x; + cin >> a >> s >> z >> x; + bool cek = false; + if ((x >= (a - 1) && x <= (a * 2) + 2) || (z >= (s - 1) && z <= (s * 2) + 2)) cek = true; + if (cek) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const int mod = 1000000007; +const long long inf = 1000000000000; +int main() { + int n, k, p; + cin >> n >> k >> p; + vector A, B; + for (int i = 0; i < n; i++) { + long long x; + cin >> x; + A.push_back(x); + } + for (int i = 0; i < k; i++) { + long long x; + cin >> x; + B.push_back(x); + } + sort(A.begin(), A.end()); + sort(B.begin(), B.end()); + long long ans = inf; + for (int i = 0; i <= k - n; i++) { + long long temp = 0; + int index = i; + for (int j = 0; j < n; j++) { + long long temp2 = 0; + temp2 = abs(A[j] - B[index]) + abs(B[index] - p); + temp = max(temp, temp2); + index++; + } + ans = min(ans, temp); + } + cout << ans << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 1) + cout << -1 << endl; + else { + for (long long i = 1; i <= n; i++) { + if (i % 2 == 1) + cout << i + 1; + else + cout << i - 1; + if (i == n) + cout << endl; + else + cout << " "; + } + } +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + d = c / a; + while (d >= 0) { + if ((c - d * a) % b == 0) { + cout << "Yes" << endl; + return 0; + } + d--; + } + cout << "No" << endl; + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + if (((abs(x - y) + abs(x - z)) * t2) + (3 * t3) <= ((abs(x - y)) * t1)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +string S; +string sub_str(int st, int en) { + string ans = ""; + for (int i = st; i < en; ++i) ans += S[i]; + return ans; +} +int main() { + cin >> S; + int ans = 0; + bool works = false; + for (int i = 0; i < S.size(); ++i) { + for (int j = i; j < S.size(); ++j) { + string sub = sub_str(i, j); + bool b = false; + for (int k = 0; k < sub.size() / 2; ++k) { + if (sub[k] != sub[sub.size() - k - 1]) b = true; + } + if (b) { + int n = sub.size(); + ans = max(ans, n); + works = true; + } + } + } + bool b2 = false; + for (int i = 0; i < S.size() / 2; ++i) { + if (S[i] != S[S.size() - i - 1]) b2 = true; + } + if (b2) + cout << S.size() << endl; + else if (works) + cout << ans << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int contiguous = 1; + for (size_t i = 1; i < s.length(); ++i) { + if (s[i] == s[i - 1]) { + contiguous += 1; + if (contiguous == 7) { + cout << "YES" << endl; + return 0; + } + } else { + contiguous = 1; + } + } + cout << "NO" << endl; + return 0; +} +const int N = 2e5 + 50; +const int M = 1e6; +const long long oo = 1e18; +const int mod = 1e9 + 7; +long long a[1010], b[2010]; +long long n, k, p; +bool can(long long md) { + long long id = 0; + for (int i = 0; i < k; i++) { + if (abs(a[id] - b[i]) + abs(b[i] - p) > md) continue; + id++; + if (id == n) return 1; + } + return 0; +} +int main() { + cin >> n >> k >> p; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + sort(a, a + n); + sort(b, b + k); + long long md, lo = 0, hi = 2e9, ans = 0; + while (lo <= hi) { + md = (lo + hi) / 2; + if (can(md)) { + hi = md - 1; + ans = md; + } else + lo = md + 1; + } + cout << ans << endl; +} +int main() { + int a, b, n, cnt = 1, ans; + cin >> a >> b >> n; + while (true) { + if (cnt % 2 != 0) + ans = __gcd(a, n); + else + ans = __gcd(b, n); + if (ans > n) + break; + else + n = n - ans; + cnt++; + } + if (cnt % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + vector a; + int n, k, bot = INT_MAX; + long long res = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + bot = min(bot, x); + a.push_back(x); + } + for (int i = 0; i < n; i++) { + if ((a[i] - bot) % k != 0) { + cout << -1 << endl; + return 0; + } else + res += (a[i] - bot) / k; + } + cout << res << endl; + return 0; +} +int main() { + int n, m, r; + cin >> n >> m >> r; + int x = r / (2 * m); + if (r % (2 * m) != 0) { x += 1; } + int y = r % (2 * m); + if (y == 0) y += (2 * m); + bool rit = 1; + int z = y / 2; + if (y % 2 != 0) { + z += 1; + rit = 0; + } + cout << x << " " << z << " "; + if (rit) + cout << "R" << endl; + else + cout << "L" << endl; +} +long long int maxx(long long int &a, long long int &b) { + return a > b ? a : b; +} +long long int minn(long long int &a, long long int &b) { + return a > b ? b : a; +} +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +int int_gcd(int a, int b) { + return b == 0 ? a : int_gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return a / gcd(a, b) * b; +} +long long int poww(long long int base, long long int exp, long long int mod) { + base %= mod; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % mod; + base = (base * base) % mod; + exp >>= 1; + } + return result; +} +int main() { + int n, m; + cin >> n >> m; + vector a, b; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + } + for (int i = 0; i < m; i++) { + int x; + cin >> x; + b.push_back(x); + } + sort(a.begin(), a.end()), sort(b.begin(), b.end()); + int x = a.front(), y = b.front(); + int ans = min(x * 10 + y, y * 10 + x); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i] == b[j]) { ans = min(ans, a[i]); } + } + } + cout << ans << endl; +} +int main() { + int a[1000], b[1000]; + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + int w = 0; + for (int i = 1; i < n; i++) { + while (a[i] <= a[w]) { a[i] = a[i] + b[i]; } + a[w] = a[i]; + } + cout << a[w] << endl; + return 0; +} +int main() { + int x, i; + int sum = 0; + for (i = 0; i < 5; i++) { + cin >> x; + sum = sum + x; + } + if (sum % 5 != 0 || sum == 0) { + cout << "-1" << endl; + } else { + cout << sum / 5 << endl; + } + return 0; +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, t, k, d, times; +set st; +string s; +int main() { + getline(cin, s); + for (int i = 1; i < s.size(); i += 3) { + if (s[i] == '}' || s[i] == ',' || s[i] == ' ') continue; + st.insert(s[i]); + } + cout << st.size() << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + char s[105]; + cin >> s; + int ans = 0; + int i = 0; + while (i < n - 1) { + if (s[i + d] == '1') { + ans++; + i = i + d; + } else { + int j = i + d - 1; + int flag = 1; + while (j > i) { + if (s[j] == '1') { + i = j; + ans++; + flag = 0; + break; + } + j--; + } + if (flag) { + ans = -1; + break; + } + } + } + cout << ans << endl; + return 0; +} +int a[27]; +int main() { + int n, k, ans = 1000000000; + string s; + while (cin >> n >> k >> s) { + for (int i = 0; i <= n - 1; i++) a[s[i] - 'A']++; + for (int i = 0; i <= k - 1; i++) ans = min(ans, a[i]); + cout << ans * k << endl; + } + return 0; +} +bool s(int x) { + int t = 0; + for (int i = 2; i <= x - 1; i++) { + if (x % i == 0) { t = 1; } + } + if (t == 1) return 1; + return 0; +} +int main() { + int n, t = 1; + ; + cin >> n; + for (int i = 4; i <= n; i++) { + for (int j = 4; j <= n; j++) { + if (i + j == n && s(i) == 1 && s(j) == 1) { + cout << i << " " << j << endl; + t = 0; + break; + } + } + if (t == 0) break; + } + return 0; +} +int main() { + int n, x, a, b; + cin >> n >> x; + bool flag = true; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a == x || a == 7 - x || b == x || b == 7 - x) { flag = false; } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const long long N = 1000 + 5; +const long long K = 2000 + 5; +long long n, m, fi; +long long p[N]; +long long k[K]; +long long di(long long a, long long b) { + return abs(a - b); +} +bool ok(long long t) { + long long poz = 1; + for (long long i = 1; i <= n; i++) { + if (poz > m) return 0; + while (1) { + long long tot = di(p[i], k[poz]) + di(k[poz], fi); + if (tot <= t) break; + poz++; + if (poz > m) return 0; + } + poz++; + } + return 1; +} +int main() { + cin >> n >> m >> fi; + for (long long i = 1; i <= n; i++) { cin >> p[i]; } + for (long long i = 1; i <= m; i++) { cin >> k[i]; } + sort(p + 1, p + n + 1); + sort(k + 1, k + m + 1); + long long r = -1, pas = (1LL << 60); + while (pas) { + if (ok(r + pas) == 0) { r += pas; } + pas >>= 1; + } + r++; + cout << r << "\n"; + return 0; +} +int main() { + int n, m, k, a, ans = 1e9; + ; + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a > 0 && a <= k) ans = min(ans, abs(m - i)); + } + ans *= 10; + cout << ans << endl; + return 0; +} +int n, a = 1, sd = 0, k = 1; +bool used[1010]; +int main() { + cin >> n; + while (k <= n + 1 && sd < n) { + a = (a + k - 1) % n; + if (!used[a]) { + used[a] = 1; + ++sd; + } + ++k; + } + if (sd == n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n, sum = 0; + cin >> n; + sum = n * (n + 1) / 2; + if (sum % 2 == 0) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + if (n % 4 == 0) + cout << "0" << endl; + else { + long long min = LONG_LONG_MAX, sum = 0; + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 4; j++) { + for (int k = 0; k <= 4; k++) { + if ((n + i + j * 2 + k * 3) % 4 == 0) { + sum = i * a + j * b + k * c; + if (sum < min) min = sum; + } + } + } + } + cout << min << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + vector v(n); + long long res = 1e15; + for (int i = 0; i < n; ++i) cin >> v[i]; + for (int i = 0; i < n; ++i) { + long long sum = 0; + sum += v[i] * 15ll; + for (int j = 0; j < v[i]; ++j) { + long long a; + cin >> a; + sum += a * 5; + } + res = min(res, sum); + } + cout << res << endl; + return 0; +} +bool a[4][4]; +bool f() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + bool bol = a[i][j]; + if (a[i + 1][j] == bol && a[i + 1][j + 1] == bol && a[i][j + 1] == bol) { return true; } + } + } + return false; +} +int main() { + char h; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + h = getchar(); + if (h == '#') + a[i][j] = true; + else + a[i][j] = false; + } + h = getchar(); + } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + a[i][j] = (a[i][j] == true ? false : true); + if (f() == true) { + cout << "YES" << endl; + return 0; + } + a[i][j] = (a[i][j] == true ? false : true); + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, anton = 0, danik = 0; + cin >> n; + for (int i = 0; i < n; i++) { + char s; + cin >> s; + if (s == 'A') { + anton++; + } else if (s == 'D') { + danik++; + } + } + if (anton > danik) { + cout << "Anton" << endl; + } else if (anton < danik) { + cout << "Danik" << endl; + } else if (anton == danik) { + cout << "Friendship" << endl; + } +} +int max1(int a, int b) { + if (a > b) + return a; + else + return b; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int m[10], x[10], max[10]; + m[0] = a + b; + x[0] = c; + m[1] = a * b; + x[1] = c; + m[2] = b + c; + x[2] = a; + m[3] = b * c; + x[3] = a; + max[0] = a + b + c; + max[1] = a * b * c; + for (int i = 2; i < 6; i++) { max[i] = max1(m[i - 2] + x[i - 2], m[i - 2] * x[i - 2]); } + int da = 0; + for (int i = 0; i < 6; i++) + if (da < max[i]) da = max[i]; + cout << da << endl; + } +} +int a[1001][3]; +int main() { + int a, b; + cin >> a >> b; + for (int i = 0; i < 6; i++) { + a *= 3; + b *= 2; + if (a > b) { + cout << i + 1 << endl; + break; + } + } +} +bool judge(const string &s) { + int h = 0, t = s.size() - 1; + while (h < t) { + if (s[h] != s[t]) { return false; } + ++h; + --t; + } + return true; +} +int main() { + string s; + cin >> s; + char ch = s[0]; + bool flag = true; + for (int i = 0; i < (int)s.size(); ++i) { + if (s[i] != ch) { + flag = false; + break; + } + } + if (flag) { + cout << "0" << endl; + } else { + if (judge(s)) + cout << s.size() - 1 << endl; + else + cout << s.size() << endl; + } + return 0; +} +int main() { + long long int n, k, sum = 0; + cin >> n >> k; + long long int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 1; i < n; i++) { + a[i] = a[i] - a[0]; + if (a[i] % k != 0) { + sum = -1; + break; + } else + sum += a[i] / k; + } + cout << sum << endl; +} +int main() { + int output; + int input1; + int input2; + while (cin >> input1 >> input2) { + if (input2 > input1) { + output = -1; + } else { + if (input1 % 2 == 0) { + output = input1 / 2; + } else { + output = (input1 / 2) + 1; + } + while (output % input2 != 0) { output++; } + } + cout << output << endl; + } +} +int main() { + vector s(4); + cin >> s[0] >> s[1] >> s[2] >> s[3]; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + cout << 4 - s.size() << endl; + return 0; +} +int main() +{ + int m, n; + cin >> n >> m; + if (n < m) { + cout << -1 << endl; + } else if (n % (2 * m) == 0) { + cout << n / 2 << endl; + } else { + cout << ((n / 2) / m + 1) * m << endl; + } +} +int main() { + int us[101], i; + for (i = 0; i <= 100; i++) us[i] = 0; + int n, k, a; + set t; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> a; + us[a]++; + t.insert(a); + } + sort(us + 1, us + 101); + int ori = ((us[100] / k) + (us[100] % k > 0)) * (k); + int ans = 0; + for (i = 100; i > 100 - t.size(); i--) { ans += ori - us[i]; } + cout << ans << endl; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + cin >> K; + if (K == 1) + L++; + else + R++; + } + M += min(L, R); + L -= M; + R -= M; + cout << M + L / 3 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << max(max(a + b + c, a * b * c), max(a * (b + c), (a + b) * c)) << endl; +} +int main() { + int count = 0; + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) + if (s[i] == s[i + 1]) count++; + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i, x[200]; + for (i = 0; i < n; i++) { cin >> x[i]; } + int min = 999999999; + for (i = 0; i < n; i++) { + int k; + int tot = 0; + for (k = 0; k < x[i]; k++) { + int m; + cin >> m; + tot += (m * 5); + tot += 15; + } + if (tot < min) { min = tot; } + } + cout << min << endl; + return 0; +} +int n, x[101], y[101], i, ans = -1; +bool v[101]; +void dfs(int a) { + v[a] = true; + for (int i = 1; i <= n; i++) + if ((x[i] == x[a] || y[i] == y[a]) && !v[i]) dfs(i); +} +int main() { + cin >> n; + for (i = 1; i <= n; i++) cin >> x[i] >> y[i]; + for (i = 1; i <= n; i++) + if (!v[i]) { dfs(i), ans++; } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + for (int i = 0; i < (n); i++) { + int a, b; + cin >> a >> b; + if (x == a || x == 7 - a || x == b || x == 7 - b) { + cout << "NO" << '\n'; + return 0; + } + } + cout << "YES" << '\n'; + return 0; +} +const int N = 4e7; +int p[N]; +int main() { + long long n, k; + cin >> n >> k; + int index = 0; + for (long long i = 1; i * i <= n; i++) + if (n % i == 0) p[++index] = i; + bool is_square = (long long)p[index] * p[index] == n; + int cnt = index * 2 - is_square; + if (k <= index) + cout << p[k] << endl; + else if (k > cnt) + cout << -1 << endl; + else + cout << n / p[2 * index - k + !is_square] << endl; + return 0; +} +int main() { + int n, m, i, j; + vector bus(6); + bus[0] = "+------------------------+"; + bus[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + bus[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + bus[3] = "|#.......................|"; + bus[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + bus[5] = "+------------------------+"; + cin >> n; + m = bus[0].size(); + for (i = 0; i < m - 1; i++) { + for (j = 0; j < 6; j++) { + if (n == 0) { break; } + if (bus[j][i] == '#') { + bus[j][i] = 'O'; + n--; + } + } + if (n == 0) { break; } + } + for (i = 0; i < 6; i++) { cout << bus[i] << endl; } +} +int main() { + int p, m, a, b, c, d, e; + int n; + cin >> n; + string hd[55]; + int score[55]; + for (int i = 0; i < n; i++) { + cin >> hd[i] >> p >> m >> a >> b >> c >> d >> e; + score[i] = 100 * p - 50 * m + a + b + c + d + e; + } + int t = score[0]; + string ans; + ans = hd[0]; + for (int j = 0; j < n; j++) { + if (score[j] > t) { + t = score[j]; + ans = hd[j]; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string str, ans; + int a, b, c, d, e, f, g, i = 0, sum, num = -100000; + while (n--) { + cin >> str >> g >> f >> a >> b >> c >> d >> e; + sum = (g * 100) - (f * 50) + a + b + c + d + e; + if (sum > num) { + num = sum; + ans = str; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, x = 0; + string s; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "X++" || s == "++X") + x++; + else + x--; + } + cout << x << "\n"; + return 0; +} +int n, a[100001] = {}, b[100001] = {}, cnt = 0; +int main() { + int i; + cin >> n; + for (i = 0; i < n; ++i) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + for (i = 0; i < n; ++i) + if (a[i] != b[i]) { + if (cnt == 2) + break; + else + ++cnt; + } + if (i < n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int num; + pair arr[100]; + cin >> num; + for (int i = 0; i < num; i++) cin >> arr[i].first >> arr[i].second; + for (int i = 0; i < num; i++) + if (arr[i].second == "rat") cout << arr[i].first << endl; + for (int i = 0; i < num; i++) + if (arr[i].second == "woman" || arr[i].second == "child") cout << arr[i].first << endl; + for (int i = 0; i < num; i++) + if (arr[i].second == "man") cout << arr[i].first << endl; + for (int i = 0; i < num; i++) + if (arr[i].second == "captain") cout << arr[i].first << endl; + return 0; +} +int x, y, n, m, a[100000], k; +char c; +bool b = false; +string str1, str2, str3, str4; +int main() { + cin >> n >> m; + x = 0; + y = n + 1; + for (int j = 0; j < m; j++) { + cin >> str1 >> str2 >> str3 >> str4 >> k; + if (str3[0] == 'r') { b = true; } + if (b == true) { + x = max(x, k); + b = false; + } else { + y = min(y, k); + } + } + if (y - x <= 1) { + cout << "-1" << endl; + } else { + cout << y - x - 1 << endl; + } +} +int main() { + int n, d; + cin >> n >> d; + vector L; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { L.push_back(i); } + } + int dp[L.size()]; + memset(dp, -1, sizeof(dp)); + dp[0] = 0; + for (int i = 0; i < L.size(); i++) { + for (int j = i + 1; j < L.size() && L[j] <= L[i] + d; j++) { + if (dp[j] == -1) { + dp[j] = dp[i] + 1; + } else { + dp[j] = min(dp[i] + 1, dp[j]); + } + } + if (i <= L.size() - 2 && dp[i + 1] == -1) break; + } + cout << dp[L.size() - 1] << '\n'; +} +int n, m, i, T; +int main() { + cin >> n >> m; + if (n == 1) { + cout << m << endl; + for (i = 1; i <= m; i++) cout << "1 " << i << endl; + } else { + if (m == 1) { + cout << n << endl; + for (i = 1; i <= n; i++) cout << i << " 1" << endl; + } else { + T = n + m - 1; + cout << T << endl; + for (i = 1; i <= m; i++) { cout << "1 " << i << endl; } + for (i = 2; i <= n; i++) cout << i << " 1" << endl; + } + } +} +int main() { + string p; + cin >> p; + char z = '0'; + char o = '1'; + int sumo = 0, sumz = 0; + for (int i = 0; i < 100; i++) { + if (p[i] == o) { + sumo++; + sumz = 0; + } else if (p[i] == z) { + sumz++; + sumo = 0; + } + if (sumo == 7 || sumz == 7) break; + } + if (sumo >= 7 || sumz >= 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int64_t N; + cin >> N; + int64_t ans = N == 0 ? 0 : (N % 2 ? (N + 1) / 2 : N + 1); + cout << ans << endl; + return 0; +} +int gcd(int m, int n) { + int temp; + if (m < n) { + temp = n; + n = m; + m = temp; + } + temp = m % n; + while (temp != 0) { + m = n; + n = temp; + temp = m % n; + } + return n; +} +int main() { + int n; + int a[2000]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int num = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 1) num++; + } + if (num != 0) { + cout << n - num << endl; + return 0; + } + int mint = 999999; + for (int i = 0; i < n; i++) { + num = 0; + int x = a[i]; + for (int j = i + 1; j < n; j++) { + num++; + x = gcd(x, a[j]); + if (x == 1) break; + } + if (x == 1) mint = mint > num ? num : mint; + } + if (mint == 999999) + cout << "-1" << endl; + else + cout << mint + n - 1 << endl; + return 0; +} +void fastIo() {} +long long a[100007], mx; +long long dp[100007][3][3]; +long long go(long long val, int nextprev, int prev) { + if (val > mx) { return 0; } + if (dp[val][nextprev][prev] != -1) return dp[val][nextprev][prev]; + long long &ans = dp[val][nextprev][prev]; + if (nextprev == 0 && prev == 0) { + ans = (val * a[val] + go(val + 1, 0, 1)); + } else if (nextprev == 0 && prev == 1) { + ans = (go(val + 1, 1, 0)); + } else if (nextprev == 1 && prev == 0) { + ans = max((val * a[val] + go(val + 1, 0, 1)), (go(val + 1, 1, 0))); + } + return ans; +} +int main() { + fastIo(); + long long n; + cin >> n; + for (int i = 0; i <= 100003; i++) { + for (int j = 0; j <= 2; j++) { + for (int k = 0; k <= 2; k++) dp[i][j][k] = -1; + } + } + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp > mx) mx = temp; + a[temp]++; + } + long long ans = max(a[1] + go(2, 0, 1), go(2, 0, 0)); + cout << ans << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + cout << "***"; + i += 2; + while (s[i + 1] == 'g' && s[i + 2] == 'o') { i += 2; } + } else + cout << s[i]; + } + cout << endl; + return 0; +} +int main() { + int k, l, m, n, d; + while (cin >> k >> l >> m >> n >> d) { + int sum = 0; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) sum++; + } + cout << sum << endl; + } +} +int n, m, ans, a[15], b[15]; +char ch; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> ch; + if (ch == 'S') { + a[i] = 1; + b[j] = 1; + } + } + } + ans = n * m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + if (a[i] && b[j]) ans--; + cout << ans << "\n"; +} +const int maxn = 2e3 + 200; +int vis[maxn]; +int num[maxn]; +int n; +int dfs(int x) { + if (num[x] == 0 && vis[x] == -1) { + return 1; + } else if (num[x]) { + return num[x]; + } + return dfs(vis[x]) + 1; +} +int main() { + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + memset(num, 0, sizeof(num)); + for (int i = 1; i <= n; i++) { + int u; + cin >> u; + vis[i] = u; + } + for (int i = 1; i <= n; i++) num[i] = dfs(i); + int Max = 0; + for (int i = 1; i <= n; i++) Max = max(Max, num[i]); + cout << Max << endl; + } + return 0; +} +int min(int arr[], int l) { + int i, min = 10; + for (i = 0; i < l; i++) { + if (min > arr[i]) { min = arr[i]; } + } + return min; +} +int main() { + int n, m, i, min1, min2, c = 0; + int arr[10] = {0}; + cin >> n >> m; + int a[n]; + int b[m]; + for (i = 0; i < n; i++) { + cin >> a[i]; + arr[a[i]]++; + } + for (i = 0; i < m; i++) { + cin >> b[i]; + arr[b[i]]++; + } + for (i = 1; i < 10; i++) { + if (arr[i] == 2) { + cout << i << endl; + c++; + break; + } + } + min1 = min(a, n); + min2 = min(b, m); + if (c == 0) { + if (min1 < min2) { + cout << (min1 * 10 + min2) << endl; + } else { + cout << (min2 * 10 + min1) << endl; + } + } +} +int main() { + int k; + char d; + cin >> k >> d; + if (d == '0' && k > 1) { + cout << "No solution" << endl; + return 0; + } + string temp; + temp.push_back(d); + for (int i = 1; i < k; i++) temp.push_back('0'); + cout << temp << endl; + return 0; +} +int main() { + int n, cnt = 0, x, y; + string s; + cin >> n >> s; + for (int i = 2; i <= n; i += 2) { + for (int j = 0; j + i <= n; j++) { + x = y = 0; + for (int k = 0, jj = j; k < i; k++, jj++) { + if (s[jj] == 'U') + y++; + else if (s[jj] == 'D') + y--; + else if (s[jj] == 'L') + x--; + else + x++; + } + if (x == 0 && y == 0) cnt++; + } + } + cout << cnt << endl; +} +int l, r, ml, mr; +bool judge(int g, int b) { + if (b < g - 1) + return false; + else if (b > 2 * g + 2) + return false; + else + return true; +} +int main() { + cin >> l >> r >> ml >> mr; + if (judge(l, mr) || judge(r, ml)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long k, b, n, t; + cin >> k >> b >> n >> t; + long long x = 1, cnt = -1; + for (long long i = 1; i <= n; ++i) { + x = k * x + b; + if (x > t) { + cnt = i - 1; + break; + } + } + if (cnt == -1) + cout << 0 << endl; + else + cout << n - cnt << endl; + return 0; +} +int main() { + int win, n, m, k1, k2; + cin >> n >> m >> k1 >> k2; + for (int i = 0;; i++) { + if (n == 0) { break; } + n -= 1; + win = 1; + if (m == 0) { break; } + m -= 1; + win = 0; + } + if (win == 0) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } + return 0; +} +vector v; +int main() { + long long int n, k, i, t; + cin >> n >> k; + for (i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + if (n / i == i) { + v.push_back(i); + } else { + v.push_back(n / i); + v.push_back(i); + } + } + } + sort(v.begin(), v.end()); + t = v.size(); + if (k > t) + cout << -1 << endl; + else + cout << v[k - 1] << endl; + return 0; +} +int main() { + int s1, s2; + int f1, f2; + cin >> s1 >> s2; + cin >> f1 >> f2; + int num1 = abs(s1 - f1); + int num2 = abs(s2 - f2); + if (num1 > num2) { + cout << num1 << "\n"; + } else { + cout << num2 << "\n"; + } + return 0; +} +int a[100], b[100]; +int main() { + int n, x, s = 1, ans = 0; + cin >> n >> x; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + int i = 1, k; + while (n > 0) { + if (a[i] - s >= 0) + k = (a[i] - s) % x; + else + k = 0; + ans += k + b[i] - a[i] + 1; + s = b[i] + 1; + n--; + i++; + } + cout << ans << endl; +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, h, a, b; +string s; +int main() { + cin >> n; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') + a++; + else + b++; + } + if (a > b) { + cout << "Anton" << endl; + } else if (a < b) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + int S = 0; + while (a[0] + a[1] + a[2]) { + for (int i = 0; i < 3; i++) { + if (a[i] != 0) a[i] -= min(a[i], 2); + if (a[0] + a[1] + a[2] == 0) break; + S++; + } + } + cout << S + 30 << endl; + return 0; +} +int solve(int x) { + if (x == 1) { return 1; } + if (x == 3) { return 5; } + int n = 3; + while (true) { + if ((n * n + 1) / 2 >= x) { return n; } + n += 2; + } +} +int main() { + int x; + while (cin >> x) { cout << solve(x) << endl; } + return 0; +} +long long a, b, c, d; +int main() { + cin >> a >> b >> c >> d; + if (a > b) { + cout << "First" << endl; + } else + cout << "Second" << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + if (m * a < b) { + cout << n * a << endl; + } else { + long long price = (n / m) * b + min((n % m) * a, b); + cout << price << endl; + } + return 0; +} +int main() { + int x; + cin >> x; + string y; + cin >> y; + int count = 0; + for (int i = 0; i < y.length() + 1; i++) { + if ((y[i] == 'U' && y[i + 1] == 'R') || (y[i] == 'R' && y[i + 1] == 'U')) { + count++; + i += 1; + } + } + cout << y.length() - count << endl; + return 0; +} +int main() { + string s; + char cur; + cin >> s; + cur = s[s.length() - 1]; + char *str = new char[s.length() + 1]; + int j = 0; + for (int i = s.length() - 1; i >= 0; i--) { + if (s[i] >= cur) { + str[j] = s[i]; + cur = s[i]; + j++; + } + } + char *ans = new char[j + 1]; + for (int i = 0; i < j; i++) { ans[i] = str[j - i - 1]; }; + ans[j] = '\0'; + cout << ans << endl; + return 0; +} +int k, ans, x, y; +string s; +char a, b; +map mp; +int main() { + cin >> s >> k; + for (int i = 0; i < k; i++) { + cin >> a >> b; + mp[a] = b, mp[b] = a; + } + for (int i = 0; i < s.size(); i++) { + x = 0, y = 0; + a = s[i], b = mp[s[i]]; + if (!islower(mp[a])) continue; + while (i + 1 < s.size() && s[i + 1] == a || s[i + 1] == b) { + if (s[i] == a) + x++; + else + y++; + i++; + } + if (s[i] == a) + x++; + else + y++; + ans += min(x, y); + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + int a[100], b[100]; + int min1 = INT_MAX; + for (long long int i = 1; i <= n; i++) { cin >> a[i]; } + for (long long int i = 1; i <= m; i++) { cin >> b[i]; } + for (long long int i = 1; i <= n; i++) { + for (long long int j = 1; j <= m; j++) { + if (a[i] == b[j]) { + min1 = min(min1, a[i]); + } else { + min1 = min(min1, ((b[j] * 10) + a[i])); + min1 = min(min1, ((a[i] * 10) + b[j])); + } + } + } + cout << min1 << endl; +} +int main() { + int n, m, i, j, a[10], b[10], c[10], x = 10, y = 10, cnt = 0; + bool flag = 0; + cin >> n >> m; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < x) x = a[i]; + } + for (i = 0; i < m; i++) { + cin >> b[i]; + if (b[i] < y) y = b[i]; + } + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (a[i] == b[j]) flag = 1, c[cnt++] = a[i]; + if (flag) { + x = 10; + for (i = 0; i < cnt; i++) + if (c[i] < x) x = c[i]; + cout << x << endl; + } else { + if (x < y) + cout << x << y << endl; + else + cout << y << x << endl; + } +} +int c, v, u, a, l; +int main() { + cin >> c >> v >> u >> a >> l; + int ans = 1, now = v, sp = v; + while (now < c) { + sp = min(sp + a, u); + now += sp - l; + ans++; + } + cout << ans << endl; +} +int main() { + int row, col; + bool a[15][15] = {false}; + cin >> row >> col; + int coun = 0, count = 0; + char arr[15][15]; + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { cin >> arr[i][j]; } + } + int res = 0; + for (int w = 0; w < row; w++) { + int co = 0; + for (int i = 0; i < col; i++) { + if (arr[w][i] == '.') { + co++; + a[w][i] = true; + } + } + if (co == col) + res += col; + else { + for (int n = 0; n < col; n++) { a[w][n] = false; } + } + } + for (int w = 0; w < col; w++) { + int co = 0; + for (int i = 0; i < row; i++) { + if (arr[i][w] == '.') { + co++; + if (a[i][w] == true) { count++; } + } + } + if (co == row) { + res += row; + res -= count; + } + count = 0; + } + cout << res << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int ada[10]; +int main() { + int n, m; + cin >> n >> m; + int nn = INT_MAX, mn = INT_MAX; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + ada[x] = 1; + nn = min(nn, x); + } + int sam = INT_MAX; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + if (ada[x]) { sam = min(sam, x); } + mn = min(mn, x); + } + if (sam != INT_MAX) { + cout << sam << endl; + } else { + cout << min(mn, nn) << max(nn, mn) << endl; + } +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; ++i) { cout << " " << i; } + cout << endl; + return 0; +} +int main() { + int sum = 0, a; + for (int i = 0; i < 5; i++) { + cin >> a; + sum += a; + } + if (sum == 0) + cout << -1 << endl; + else if (sum % 5 == 0) + cout << sum / 5 << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +int main() { + int n, t; + cin >> n >> t; + int x, y; + cin >> x >> y; + n--; + int b; + int s1, s2; + while (n--) { + int z = 0; + int a[7] = {0}; + cin >> x >> y; + b = 7 - t; + s1 = 7 - x; + s2 = 7 - y; + a[s1] = 1; + a[s2] = 1; + a[x] = 1; + a[y] = 1; + for (int i = 1; i <= 6; i++) { + if (!a[i]) { + if (i != b) { + z++; + t = i; + } + } + } + if (z == 2) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +long long i, b, a, k, t, n, m; +long long fix[10001]; +int main() { + cin >> n; + t = 1; + for (i = 1; i <= 1000001; i++) { + if (t + i > n) + t = (t + i) % n + 1; + else + t = t + i; + fix[t]++; + } + for (i = 1; i <= n; i++) { + if (fix[i] == 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + x = abs(x - 7); + bool sol = true; + int a, b; + cin >> a >> b; + for (int i = 1; i < n; i++) { + cin >> a >> b; + if (x == a || x == b || x == abs(7 - a) || x == abs(7 - b)) { + sol = false; + } else { + x = abs(x - 7); + } + } + if (sol) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +long long int cnt[100002]; +long long int ans[100002]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + cnt[a] = cnt[a] + 1; + } + ans[0] = 0; + ans[1] = cnt[1]; + for (int i = 2; i <= 100000; i++) { ans[i] = max(ans[i - 1], ans[i - 2] + cnt[i] * i); } + cout << ans[100000] << endl; + return 0; +} +int main() { + long long int a; + cin >> a; + if (a % 2 == 0 || a == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + if (y < 1 || y > 100 || b < 2 || b > 100 || r < 3 || r > 100) { return 0; } + int y1, y2, b1, b2, r1, r2; + y1 = y + 1; + y2 = y + 2; + b1 = b - 1; + b2 = b + 1; + r1 = r - 2; + r2 = r - 1; + if (y1 <= b && y2 <= r) + cout << y + y1 + y2 << endl; + else if (b1 <= y && b2 <= r) + cout << b + b1 + b2 << endl; + else if (r1 <= y && r2 <= b) + cout << r1 + r2 + r << endl; + return 0; +} +int main() { + vector v; + vector s; + int count = 1, size; + char c; + cin >> size; + for (int i = 0; i < size; i++) { + cin >> c; + v.push_back(c); + } + int in, i = 0; + while (i < size) { + if (i == 0) { + s.push_back(v[i]); + i++; + } else { + in = count; + for (int j = 0; j < in; j++) { i++; } + if (i < size) s.push_back(v[i]); + count++; + } + } + for (int i = 0; i < s.size(); i++) { cout << s[i]; } + cout << endl; + return 0; +} +int n, k = 1; +int main() { + cin >> n; + while (1) { + if (n == k) { + cout << "YES" << endl; + break; + } else if (n < k) { + cout << "NO" << endl; + break; + } + k *= 2; + } + return 0; +} +long long n, m; +int main() { + cin >> n >> m; + while (!(m % 2)) m /= 2; + if (!(n % m)) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; ++i) { cout << " " << i; } + cout << endl; + return 0; +} +int d[1005]; +int s[1005]; +int main() { + int m, k, sum1, sum2, maxn, t, t0, i; + int d[1005], s[1005]; + while (cin >> m >> k) { + for (i = 1; i <= m; i++) cin >> d[i]; + for (i = 1; i <= m; i++) cin >> s[i]; + sum1 = 0; + sum2 = 0; + maxn = 0; + t = 0; + for (int i = 1; i <= m; i++) { + sum1 += d[i]; + sum2 += s[i]; + if (maxn < s[i]) maxn = s[i]; + if (sum2 < sum1) { + t0 = (abs(sum2 - sum1)) / maxn; + if (abs(sum2 - sum1) % maxn) t0++; + t += t0; + sum2 += (maxn * t0); + } + } + cout << sum1 + k * t << endl; + } + return 0; +} +int main() { + int n, x, t = 1, z = 0; + cin >> n >> x; + while (n--) { + int l, r; + cin >> l >> r; + int w = (l - t) / x; + t += w * x; + z += r - t + 1; + t = r + 1; + } + cout << z << '\n'; +} +int main() { + vector vs(4); + for (size_t i = 0; i < 4; ++i) { cin >> vs[i]; } + bool pass = false; + for (size_t top = 0; top <= 2 && !pass; ++top) { + for (size_t left = 0; left <= 2; ++left) { + int dot = 0; + for (size_t r = 0; r < 2; ++r) { + for (size_t c = 0; c < 2; ++c) { + if (vs[top + r][left + c] == '.') { dot += 1; } + } + } + if (dot != 2) { + pass = true; + break; + } + } + } + cout << (pass ? "YES" : "NO") << endl; + return 0; +} +int main() { + int count1 = 0; + int count2 = 0; + int len; + cin >> len; + char *str1 = new char[len]; + for (int i = 0; i < len; i++) { cin >> str1[i]; } + for (int i = 0; i < len; i++) { + if (str1[i] == 'A') { + count1++; + } else if (str1[i] == 'D') { + count2++; + } + } + if (count1 > count2) { + cout << "Anton" << endl; + } else if (count1 < count2) + cout << "Danik" << endl; + else if (count1 == count2) + cout << "Friendship" << endl; + return 0; +} +string a[51], b; +void change() { + char tmp = b[0]; + for (int i = 0; i < b.length(); i++) { swap(b[i], b[i + 1]); } + b[b.length() - 1] = tmp; +} +int main() { + cin >> b; + a[1] = b; + int l = 1; + bool flag; + for (int i = 0; i < b.length() - 1; i++) { + change(); + flag = false; + for (int j = 1; j <= l; j++) { + if (a[j] == b) { + flag = true; + break; + } + } + if (!flag) { a[++l] = b; } + } + cout << l << endl; + return 0; +} +int main() { + long long a, b, c, d; + while (cin >> a >> b >> c >> d) { + long long ck = 0; + long long a1 = a * 2 + 2; + long long a2 = a - 1; + if (d >= a2 && d <= a1) ck = 1; + a1 = b * 2 + 2; + a2 = b - 1; + if (c >= a2 && c <= a1) ck = 1; + if (ck == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int q; + cin >> q; + while (q--) { + int l, r, d; + cin >> l >> r >> d; + if (d < l) { + cout << d << "\n"; + continue; + } + cout << (r / d + 1) * d; + cout << "\n"; + } + return 0; +} +int a[1001], n, d; +set s; +inline void check(int x) { + for (int i = 1; i <= n; i++) { + if (abs(a[i] - x) < d) { return; } + } + s.insert(x); + return; +} +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + for (int i = 1; i <= n; i++) { + check(a[i] - d); + check(a[i] + d); + } + cout << s.size() << endl; + return 0; +} +int main() { + int n, i, x = 0; + string s; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> s; + if (s[0] == '+' || s[1] == '+') + x++; + else + x--; + } + cout << x << endl; +} +int main() { + int n; + int x; + int y; + int ans = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n - 1; i++) { + x = 0; + y = 0; + if (s[i] == 'U') { + y++; + } else if (s[i] == 'D') { + y--; + } else if (s[i] == 'R') { + x++; + } else { + x--; + } + for (int j = i + 1; j < n; j++) { + if (s[j] == 'U') { + y++; + } else if (s[j] == 'D') { + y--; + } else if (s[j] == 'R') { + x++; + } else { + x--; + } + if (x == 0 && x == y) { ans++; } + } + } + cout << ans << endl; + return 0; +} +void fastIo() {} +int main() { + fastIo(); + int n, m; + cin >> n >> m; + if (n == 1) { + cout << "-1" << endl; + return 0; + } + if (n == 2 && m == 2) { + cout << "2" << endl; + return 0; + } + if (n == 2 && m > 2) { + cout << "-1" << endl; + return 0; + } + int cnt = n / 2; + cnt++; + int mn; + if (n % 2 == 0) + mn = n / 2; + else + mn = n / 2 + 1; + while (mn <= n && cnt) { + if (mn % m == 0) { + cout << mn << endl; + return 0; + } + mn++; + cnt--; + } + cout << "-1" << endl; + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3, cnt = 0; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + int n; + cin >> n; + int cup = a1 + a2 + a3; + int medal = b1 + b2 + b3; + while (cup > 0) { + cup -= 5; + cnt++; + } + while (medal > 0) { + medal -= 10; + cnt++; + } + if (cnt <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + char str[1000]; + while (cin >> str) { + if ('a' <= str[0] && str[0] <= 'z') { str[0] -= 32; } + cout << str << endl; + } + return 0; +} +const int N = 1e5 + 5; +int n, cnt, a[N], b[N]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; + sort(b, b + n); + for (int i = 0; i < n; i++) cnt += (a[i] != b[i]); + cout << (cnt <= 2 ? "YES\n" : "NO\n"); + return 0; +} +long long n; +map upd, tmp; +inline void read(long long &x) { + x = 0; + char c = getchar(); + while (!isdigit(c)) c = getchar(); + while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); +} +inline long long gcd(long long x, long long y) { + return y == 0 ? x : gcd(y, x % y); +} +int main() { + read(n); + long long now, k, res = INT_MAX >> 2, cntone = 0; + for (int i = 1; i <= n; ++i) { + read(now); + if (now == 1) ++cntone; + upd.clear(); + upd[now] = i; + for (map::iterator it = tmp.begin(); it != tmp.end(); ++it) { + k = gcd(it->first, now); + upd[k] = max(upd[k], it->second); + } + tmp.clear(); + for (map::iterator it = upd.begin(); it != upd.end(); ++it) { + tmp[it->first] = it->second; + if (it->first == 1) { res = min(res, i - it->second); } + } + } + if (cntone) + cout << n - cntone << endl; + else if (res == INT_MAX >> 2) + cout << "-1" << endl; + else + cout << res + n - 1 << endl; + return 0; +} +int main() { + int b, g; + cin >> b >> g; + cout << b + g - 1 << '\n'; + for (int i = 1; i <= g; i++) { cout << 1 << " " << i << '\n'; } + for (int i = 2; i <= b; i++) { cout << i << " " << 1 << '\n'; } + return 0; +} +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') { r[i] = c[j] = 1; } + } + } + int ans = n * m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (r[i] && c[j]) ans--; + } + } + cout << ans << endl; + } + return 0; +} +int n; +vector a[2000]; +int degree[2000]; +int maxlevel = 0; +void recur(int now, int level) { + maxlevel = max(maxlevel, level); + for (int i = 0; i < a[now].size(); i++) { recur(a[now][i], level + 1); } +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp != -1) + a[temp - 1].push_back(i); + else + degree[i] = 1; + } + for (int i = 0; i < n; i++) { + if (degree[i]) { recur(i, 1); } + } + cout << maxlevel << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[105] = {0}; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int t = m; + int d = 1; + while (1) { + if (t + d <= n) { + if (a[t + d] <= k && a[t + d]) { + cout << d * 10 << endl; + return 0; + } + } + if (t - d >= 1) { + if (a[t - d] <= k && a[t - d]) { + cout << d * 10 << endl; + return 0; + } + } + d++; + } +} +int main() { + long long int a, b, c, d; + cin >> a >> b >> c >> d; + int x, y; + x = abs(a - c); + y = abs(b - d); + if (x > y) + cout << x << endl; + else + cout << y << endl; + return 0; +} +int main() { + string s; + set t; + while (cin >> s) { + if (s[0] != '{') { + t.insert(s[0]); + } else if (s[1] != '}') { + t.insert(s[1]); + } + } + cout << t.size() << endl; + return 0; +} +int main() { + char a[60]; + cin >> a; + int i; + int sum = 0; + for (i = 0; i < strlen(a); i++) { + if (a[i] != a[strlen(a) - 1 - i]) break; + } + if (i == strlen(a)) { + int k = 1; + while (k != strlen(a)) { + for (i = k; i < strlen(a); i++) { + if (a[i] != a[strlen(a) - 1 - i + k]) break; + } + if (i != strlen(a)) break; + k++; + } + cout << strlen(a) - k << endl; + } else + cout << strlen(a) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int count = 0; + char a, b, c; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if (a == '+' || b == '+') + count++; + else + count--; + } + cout << count << endl; + return 0; +} +int main() { + int numOfGames; + string s; + cin >> numOfGames; + cin >> s; + int anton = 0; + int danik = 0; + for (int i = 0; i < numOfGames; i++) { + if (s[i] == 65) { + anton++; + } else if (s[i] == 68) { + danik++; + } + } + if (anton > danik) + cout << "Anton" << endl; + else if (anton < danik) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int k, l, m, n, d, item = 0; + cin >> k >> l >> m >> n >> d; + if (k == 1 || l == 1 || m == 1 || n == 1) + cout << d << endl; + else { + for (int i = 1; i <= d; i++) { + if (i % k != 0 && i % l != 0 && i % m != 0 && i % n != 0) item++; + } + cout << d - item << endl; + } +} +int main() { + string a, b; + cin >> a >> b; + long long int i, n, x1 = 0, y1 = 0, x2 = 0, y2 = 0; + n = a.size(); + for (i = 0; i < n; i++) { + if (a[i] != b[i]) { + if (a[i] == '4') + x1++; + else + y1++; + } + } + cout << max(x1, y1) << endl; + return 0; +} +int main() { + long long cnt = 0; + long long c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + while (true) { + cnt++; + c -= v0; + if (v0 < v1) v0 += a; + if (v0 > v1) v0 = v1; + if (c <= 0) break; + c += l; + } + cout << cnt << "\n"; + return 0; +} +int main() { + int x; + cin >> x; + if (x == 1) + cout << 1 << endl; + else if (x == 2 or x == 4 or x == 5) + cout << 3 << endl; + else { + int sum = 12, val = 13, ans = 5; + while (x > val) { + val += sum; + sum += 4; + ans += 2; + } + cout << ans << endl; + } +} +int n, d, vis[200], lvl[200]; +string st; +int bfs() { + queue Q; + memset(vis, -1, sizeof(vis)); + Q.push(0); + lvl[0] = 0; + int u; + while (!Q.empty()) { + u = Q.front(); + Q.pop(); + if (u == n - 1) return lvl[u]; + for (int i = u + 1; i <= u + d; i++) { + if (vis[i] == -1 && st[i] == '1') { + vis[i] = 1; + lvl[i] = lvl[u] + 1; + Q.push(i); + } + } + } + return -1; +} +int main() { + cin >> n >> d; + cin >> st; + cout << bfs() << "\n"; +} +const int maxn = 1e3 + 10; +int d[maxn], s[maxn], n; +void input() { + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i] >> d[i]; +} +int main() { + input(); + int p = 1; + for (int i = 0; i < n; i++) { + if (p < s[i]) + p = s[i]; + else { + int ans = (p - s[i] + d[i] - 1) / d[i]; + p = ans * d[i] + s[i]; + } + p++; + } + p--; + cout << p << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int c1, c2; + c1 = c2 = 0; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] != s2[i]) { + if (s1[i] == '4') + c1++; + else + c2++; + } + } + cout << min(c1, c2) + abs(c1 - c2) << endl; +} +int main() { + int c, v0, v, a, l; + cin >> c >> v0 >> v >> a >> l; + int ans = 0; + while (1) { + ans++; + c -= v0; + if (c <= 0) break; + v0 += a; + if (v0 > v) v0 = v; + c += l; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, i; + cin >> a >> b; + int x = a, y = b; + for (i = 1; i < y; i++) { + x = x * 3; + y = y * 2; + if (x <= y) + continue; + else + break; + } + cout << i << endl; +} +int main() { + int n, k; + cin >> n >> k; + double x, y, x0, y0, total(0.0); + cin >> x0 >> y0; + while (--n) { + cin >> x >> y; + total += sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)); + x0 = x; + y0 = y; + } + cout << fixed << setprecision(6) << total * k / 50 << endl; + return 0; +} +int main() { + int q, l, r, d; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> l >> r >> d; + cout << (d < l) * d + (d >= l) * (r / d * d + d) << "\n"; + } +} +int main() { + char s[101]; + gets(s); + puts(strstr(s, "0000000") || strstr(s, "1111111") ? "YES" : "NO"); +} +int main() { + long long gl, gr, bl, br; + cin >> gl >> gr >> bl >> br; + if (br >= gl - 1 && br <= 2 * (gl + 1)) { + cout << "YES" << endl; + return 0; + } + if (bl >= gr - 1 && bl <= 2 * (gr + 1)) { + cout << "YES" << endl; + return 0; + } else + cout << "NO" << endl; +} +int n, a[1010], b[1010], sum = 1; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + int j = 0; + while (sum != n + 1) { + j++; + if (j - a[sum] >= 0 && (j - a[sum]) % b[sum] == 0) sum++; + } + cout << j << endl; + return 0; +} +int main() { + int length; + cin >> length; + int arr[length]; + int arrSorted[length]; + for (int i = 0; i < length; i++) { + cin >> arr[i]; + arrSorted[i] = arr[i]; + } + sort(arrSorted, arrSorted + length); + int maxSwaps = 0; + for (int i = 0; i < length; i++) { + if (arr[i] != arrSorted[i]) { maxSwaps++; } + } + if (maxSwaps <= 2) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +int main() { + int n, m; + cin >> n >> m; + cout << m + (n - 1) << "\n"; + for (int i = 1; i <= m; i++) { + cout << "1" + << " " << i << "\n"; + } + for (int j = 2; j <= n; j++) cout << j << " " << 1 << "\n"; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + vector ans; + for (int i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + ans.push_back(i); + if (i != sqrt(n)) { ans.push_back(n / i); } + } + } + sort(ans.begin(), ans.end()); + cout << (k > ans.size() ? -1 : ans[k - 1]) << endl; + return 0; +} +int main() { + map p; + int n; + cin >> n; + int max = -99999999; + string k; + while (n--) { + string s; + int h, p, m, a, b, c, d, e, s1 = 0; + cin >> s >> h >> p >> a >> b >> c >> d >> e; + s1 = a + b + c + d + e; + s1 += h * 100; + s1 = s1 - (p * 50); + if (max < s1) { + max = s1; + k = s; + } + } + cout << k << endl; +} +int main() { + int n; + cin >> n; + int t[n]; + int i; + int un = 0; + int de = 0; + int sum = 0; + for (i = 0; i < n; i++) { + cin >> t[i]; + if (t[i] == 1) { + un++; + } else { + de++; + } + } + if (un > de) { + sum = de + (un - de) / 3; + } else { + sum = un; + } + cout << sum << endl; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int sum = 0; + int l[55], r[55]; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + sum += r[i] - l[i] + 1; + } + sum += (l[0] - 1) % x; + for (int i = 1; i < n; i++) { sum += (l[i] - r[i - 1] - 1) % x; } + cout << sum << endl; +} +int main() { + int numberOfInputs; + cin >> numberOfInputs; + long long input1, input2; + while (numberOfInputs--) { + cin >> input1 >> input2; + long long div = input2 / input1; + long long answer = input1 * div; + cout << input1 << " " << answer << endl; + } + return 0; +} +long long a[6]; +int main() { + for (long long i = 0; i < 6; i++) cin >> a[i]; + long long c = 2 * a[0] - 1, ans = 0; + for (long long i = 0; i < a[1] + a[2]; i++) { + if (i <= a[1] && i <= a[5]) + c += 2; + else if (i > a[1] && i > a[5]) + c -= 2; + if (a[1] == a[5] && i == a[1]) c -= 2; + if (i != a[1] && i == a[5]) c--; + if (i == a[1] && i != a[5]) c--; + ans += c; + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, y, z, xsum(0), ysum(0), zsum(0); + cin >> n; + while (n--) { + cin >> x >> y >> z; + xsum += x; + ysum += y; + zsum += z; + } + if (xsum == 0 && ysum == 0 && zsum == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int ans1, ans2 = abs(x - y) * t1; + ans1 = abs(z - x) * t2 + t3 * 3 + abs(x - y) * t2; + if (ans1 <= ans2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 || m == 0) { + cout << 0 << endl; + return 0; + } + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return 0; +} +int main() { + int m; + cin >> m; + int x = 0; + for (int i = 1; i <= m; i++) { + string s; + cin >> s; + if (s == "X++" || s == "++X") + x++; + else if (s == "X--" || s == "--X") + x--; + } + cout << x << endl; +} +int main() { + long n, k; + int one = 0; + cin >> n; + vector v(n); + cin >> v[0]; + k = v[0]; + if (v[0] == 1) one++; + for (long i = 1; i < n; i++) { + cin >> v[i]; + k = __gcd(k, v[i]); + if (v[i] == 1) one++; + } + if (k != 1) return cout << "-1\n", 0; + if (one > 0) return cout << n - one << "\n", 0; + long ans = INT_MAX; + for (long l = 0; l < n; l++) { + long g = v[l]; + for (long r = l + 1; r < n; r++) { + g = __gcd(g, v[r]); + if (g == 1) { + ans = min(n + r - l - 1, ans); + break; + } + } + } + cout << ans << "\n"; + return 0; +} +long long check(string a) { + long long t = a.length(); + long long e = 0; + for (long long i = t - 1; i >= 0; i--) { + if (a[i] != a[e]) return 0; + e++; + } + return 1; +} +void run() { + string s; + cin >> s; + long long j = s.length(), m = 0; + for (long long i = 0; i < j; i++) { + for (long long k = i + 1; k < j; k++) { + string a = s.substr(i, k + 1); + if (check(a) == 0) m = max(m, k - i + 1); + } + } + cout << m << endl; +} +int main() { + long long t = 1; + for (long long i = 0; i < t; i++) run(); +} +int n; +const int maxn = 1e4 + 5; +int a[maxn]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + int status = 1; + int now = 1; + bool p = true; + for (int i = 2; i <= n; ++i) { + if (a[i] > a[i - 1] && status == 1) + ; + else if (a[i] == a[i - 1] && status != 3) { + status = 2; + now = i; + } else if (a[i] < a[i - 1] && (status != 1 || now == 1)) + status = 3; + else { + p = false; + break; + } + } + if (p) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, i; + char a[2002]; + cin >> n; + cin >> a; + int len = strlen(a); + int res = 0; + for (i = n; i < len; i += n) { + if ((a[i - 1] == a[i - 2]) && (a[i - 2] == a[i - 3])) res++; + } + cout << res << endl; + return 0; +} +int main() { + string s, a; + int cnt = 0, k; + cin >> s; + cin >> k; + while (k--) { + cin >> a; + int b = 0, c = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == a[0]) + b++; + else if (s[i] == a[1]) + c++; + else { + cnt += min(b, c); + b = c = 0; + } + } + cnt += min(b, c); + } + cout << cnt << endl; +} +int main() { + int n; + cin >> n; + if (n % 2) + cout << "Ehab\n"; + else + cout << "Mahmoud\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n], sum1 = 0; + for (long long int i = 0; i < n; i++) { + cin >> a[i]; + sum1 += a[i]; + } + long long int a1[n], k = 0; + for (int i = 0; i < n; i++) { + if (a[i] % 2 != 0) { + a1[k] = a[i]; + k++; + } + } + if (k % 2 != 0) { + long long int min = a1[0]; + for (int i = 0; i < k; i++) { + if (a1[i] < min) { min = a1[i]; } + } + sum1 -= min; + } else { + sum1 = sum1; + } + cout << sum1 << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + map mp; + for (int i = 1; i < s.size() - 1; i++) + if (s[i] != ' ' && s[i] != ',') mp[s[i]] = 1; + cout << mp.size() << endl; + return 0; +} +long long a[100005]; +int main() { + long long n, k; + cin >> n >> k; + long long terkecil = 1e9; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (i > 1) { + if (a[i] % k != a[i - 1] % k) { + cout << -1 << endl; + return 0; + } + } + terkecil = min(terkecil, a[i]); + } + long long hitung = 0; + for (int i = 1; i <= n; i++) { hitung += a[i] - terkecil; } + if (hitung % k != 0) { + if (terkecil > k) { + hitung = 0; + for (int i = 1; i <= n; i++) { hitung += a[i] - k; } + } + if (hitung % k == 0) cout << hitung / k << endl; + } else + cout << hitung / k << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + char c = k & 1 ? 'L' : 'R'; + k = (k - 1) / 2; + int a = k / m; + int b = k % m; + cout << a + 1 << " " << b + 1 << " " << c << endl; +} +int main() { + int n, d; + while (cin >> n >> d) { + int arr[n], hotels = 2; + for (int i = 0; i < n; i++) cin >> arr[i]; + if (n == 1) { + cout << hotels << endl; + continue; + } + if (arr[0] + d <= arr[1] - d) { hotels++; } + if (arr[n - 1] - d > arr[n - 2] + d) { hotels++; } + for (int i = 1; i < n - 1; i++) { + if (arr[i] + d <= arr[i + 1] - d) { hotels++; } + if (arr[i] - d > arr[i - 1] + d) { hotels++; } + } + cout << hotels << endl; + } +} +int main() { + int a, b, c, d, e, f, g, m, s, l, n, t; + cin >> a >> b >> c >> d >> e >> f; + s = (a - b) * d; + if (s < 0) { s = -1 * s; } + l = ((c - a) * e); + if (l < 0) l = -l; + t = (a - b) * e; + if (t < 0) t = -t; + m = t + l + 3 * f; + if (m <= s) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +vector v; +string a; +string b; +int n; +int m; +int ans = 0; +void BS(int low, int high) { + if (low > high) return; + int mid = low + (high - low) / 2; + string temp; + vector t; + for (int i = mid; i < n; i++) t.push_back(v[i]); + sort(t.begin(), t.end()); + for (int i = 0; i < t.size(); i++) temp += a[t[i] - 1]; + int j = 0; + for (int i = 0; i < t.size(); i++) { + if (temp[i] == b[j]) { + j++; + if (j == m) break; + } + } + if (j == m) { + ans = mid; + BS(mid + 1, high); + } else + BS(low, mid - 1); +} +int main() { + cin >> a; + cin >> b; + n = a.size(); + m = b.size(); + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + v.push_back(temp); + } + BS(0, n - m); + cout << ans << endl; + return 0; +} +long long n; +int main() { + cin >> n; + if (n == 1) cout << 4; + if (n == 2) cout << 22; + if (n == 3) cout << 27; + if (n == 4) cout << 58; + if (n == 5) cout << 85; + if (n == 6) cout << 94; + if (n == 7) cout << 121; + if (n == 8) cout << 166; + if (n == 9) cout << 202; + if (n == 10) cout << 265; + if (n == 11) cout << 274; + if (n == 12) cout << 319; + if (n == 13) cout << 346; + if (n == 14) cout << 355; + if (n == 15) cout << 378; + if (n == 16) cout << 382; + if (n == 17) cout << 391; + if (n == 18) cout << 438; + if (n == 19) cout << 454; + if (n == 20) cout << 483; + if (n == 21) cout << 517; + if (n == 22) cout << 526; + if (n == 23) cout << 535; + if (n == 24) cout << 562; + if (n == 25) cout << 576; + if (n == 26) cout << 588; + if (n == 27) cout << 627; + if (n == 28) cout << 634; + if (n == 29) cout << 636; + if (n == 30) cout << 645; + cout << endl; + return 0; +} +char arr[103][103]; +long long dfs(long long i, long long visited[], vector v[]) { + visited[i] = 1; + for (long long j = 0; j < v[i].size(); j++) { + if (visited[v[i][j]] == 0) { dfs(v[i][j], visited, v); } + } + return 0; +} +int main() { + long long n; + cin >> n; + long long arr[n][2]; + for (long long i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1]; } + long long visited[n + 1] = {0}, count = 0; + vector v[n + 1]; + for (long long i = 0; i < n; i++) { + for (long long j = i + 1; j < n; j++) { + if (arr[i][0] == arr[j][0] || arr[i][1] == arr[j][1]) { + v[i + 1].push_back(j + 1); + v[j + 1].push_back(i + 1); + } + } + } + for (long long i = 1; i <= n; i++) { + if (visited[i] == 0) { + count++; + dfs(i, visited, v); + } + } + cout << count - 1 << endl; + return 0; +} +int d[1500], s[1500]; +int main() { + int m, k; + cin >> m >> k; + for (int i = 1; i <= m; i++) cin >> d[i]; + for (int i = 1; i <= m; i++) cin >> s[i]; + int sum = 0, ans = 0; + int maxi = 0; + for (int i = 1; i <= m; i++) { + sum += s[i]; + maxi = max(maxi, s[i]); + while (sum < d[i]) sum += maxi, ans += k; + ans += d[i]; + sum -= d[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int n = 0, top = 0, re_top = 0; + cin >> n; + cin >> top; + re_top = 7 - top; + set test; + int temp1 = 0, temp2 = 0; + for (int i = 1; i <= n; i++) { + cin >> temp1 >> temp2; + test.insert(temp1); + test.insert(temp2); + test.insert(7 - temp1); + test.insert(7 - temp2); + } + bool flag = true; + for (set::iterator i = test.begin(); i != test.end(); i++) + if (*i == top || *i == re_top) flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, cnt = 0, x, y; + string s; + cin >> n >> s; + for (int i = 2; i <= n; i += 2) { + for (int j = 0; j + i <= n; j++) { + x = y = 0; + for (int k = 0, jj = j; k < i; k++, jj++) { + if (s[jj] == 'U') + y++; + else if (s[jj] == 'D') + y--; + else if (s[jj] == 'L') + x--; + else + x++; + } + if (x == 0 && y == 0) cnt++; + } + } + cout << cnt << endl; +} +int main() { + int n, i, j, sum_a, sum_b, diff, min = 360; + cin >> n; + int a[365], b[730]; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < 2; i++) + for (j = 0; j < n; j++) b[i * n + j] = a[j]; + for (i = 0; i < n; i++) { + for (j = i; j < i + n; j++) { + sum_a = 0; + for (int k = i; k < j; k++) { sum_a = sum_a + b[k]; } + sum_b = 360 - sum_a; + diff = abs(sum_b - sum_a); + if (diff < min) min = diff; + } + } + cout << min << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i += 1) { + int x; + cin >> x; + sum += x; + } + int c = 0; + for (int i = 1; i < 6; i += 1) { + if ((sum + i) % (n + 1) != 1) { c++; } + } + cout << c << endl; + return 0; +} +char commamd; +int row[20]; +int col[20]; +int main() { + int n, m; + cin >> n >> m; + int a = 0, b = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> commamd; + if (commamd == 'S') { + if (row[i] == 0) { a++; } + row[i]++; + if (col[j] == 0) { b++; } + col[j]++; + } + } + } + cout << n * m - a * b << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n - 1; i++) { + bool c1 = s[i] == 'U' and s[i + 1] == 'R'; + bool c2 = s[i] == 'R' and s[i + 1] == 'U'; + if (c1 or c2) { + s[i] = 'D'; + s = s.substr(0, i + 1) + s.substr(i + 2); + } + } + cout << s.size() << "\n"; + return 0; +} +int main() { + int players, cleaner; + int fingers, tfingers = 0; + int ways = 0; + cin >> players; + for (int i = 0; i < players; i++) { + cin >> fingers; + tfingers += fingers; + } + players++; + for (int i = 1; i <= 5; i++) { + if ((tfingers + i) % players != 1) { ways++; } + } + cout << ways << endl; + return 0; +} +vector odds; +int main() { + int i, n, l; + long long int x, cnt = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + if (x % 2 == 0) { + cnt += x; + } else { + odds.push_back(x); + } + } + sort(odds.begin(), odds.end()); + l = odds.size(); + if (l % 2 == 0) { + for (i = 0; i < l; i++) { cnt += odds[i]; } + } else { + for (i = 1; i < l; i++) { cnt += odds[i]; } + } + cout << cnt << endl; + return 0; +} +int a; +int b; +int main() { + int i = 0; + cin >> a >> b; + while (true) { + if (a > b) { + cout << i << endl; + return 0; + } else { + a = a * 3; + b = b * 2; + i++; + } + } +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x * x) % m; + if (b % 2) x = (x * a) % m; + return x; +} +int main() { + int p, an = 0, t, x[100000 + 5], y[100000 + 5], n, k, i; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> x[i]; + cin >> y[i]; + } + an += (x[0] - 1) % k; + an += y[0] - x[0] + 1; + for (i = 1; i < n; i++) { + if ((x[i] - y[i - 1] + 1) >= k) { + an += y[i] - x[i] + 1; + an += (x[i] - y[i - 1] - 1) % k; + } else { + an += y[i] - y[i - 1]; + } + } + cout << an << endl; +} +int main() { + int n, cnt(0); + string s; + cin >> n >> s; + for (int i = 1; i < (int)s.size(); i++) + if (i % n == 0 && i >= 3 && s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) cnt++; + cout << cnt << endl; + return 0; +} +int main() { + int n, o = 0, t = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + int temp; + cin >> temp; + if (temp == 1) ++o; + if (temp == 2) ++t; + } + int mot = min(t, o); + if (o > mot) { mot += (o - mot) / 3; } + cout << mot << endl; + return 0; +} +bool a[305]; +int x, n; +int main() { + cin >> x >> n; + for (int i = 1; i <= n; i++) { + int p; + cin >> p; + p %= x; + if (a[p] == true) { + cout << i << endl; + return 0; + } else + a[p] = true; + } + cout << "-1" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int res = 0; + for (int i = (int)0; i <= (int)(int)((s).size()) - 1; i++) { + for (int j = (int)i + 1; j <= (int)(int)((s).size()) - 1; j++) { + int x = 0; + int y = 0; + for (int k = (int)i; k <= (int)j; k++) { + if (s[k] == 'U') y++; + if (s[k] == 'D') y--; + if (s[k] == 'R') x++; + if (s[k] == 'L') x--; + } + res += (make_pair(x, y) == make_pair(0, 0)); + } + } + cout << res << endl; +} +int main() { + int n, m; + cin >> n >> m; + int mmax, mmin, k; + mmax = n; + mmin = (n + 1) / 2; + k = (m - (mmin % m)) == m ? 0 : m - (mmin % m); + if (m <= n) + cout << mmin + k << endl; + else + cout << -1 << endl; +} +int main() { + int count = 0, arr[4]; + for (int i = 0; i < 4; i++) cin >> arr[i]; + for (int i = 0; i < 3; i++) { + if (arr[i] != 0) + for (int j = i + 1; j < 4; j++) { + if (arr[i] == arr[j] && arr[j] != 0) { + count++; + arr[j] = 0; + } + } + } + cout << count << endl; + return 0; +} +int t, l, r, d; +int main() { + cin >> t; + while (t--) { + cin >> l >> r >> d; + if (d < l || d > r) { + cout << d << endl; + } else { + cout << r + d - (r % d) << endl; + } + } + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (k == 1 && d == 0) { + cout << "0" << endl; + } else if (k > 1 && d == 0) { + cout << "No solution" << endl; + } else { + cout << d; + for (int i = 0; i < k - 1; i++) { cout << "0"; } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1" << endl; + return 0; + } + if (n == 2) { + cout << "3" << endl; + return 0; + } + if (n == 3) { + cout << "5" << endl; + return 0; + } + if (n % 4 == 0) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 1) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 2) { + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 3) { + n--; + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int n = s.length(); + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int fim = n - 1; + int ini = 0; + while (fim - ini > 0) { + int mid = ceil((fim + ini) / 2.0); + bool nao_usa[n + 1]; + memset(nao_usa, false, sizeof nao_usa); + for (int i = 0; i < mid; i++) { nao_usa[arr[i] - 1] = true; } + string usa; + for (int i = 0; i < n; i++) { + if (!nao_usa[i]) usa += s[i]; + } + int pos = 0; + int n2 = t.length(); + bool eh = false; + for (int i = 0; i < n - mid; i++) { + if (usa[i] == t[pos]) { + pos++; + if (pos >= n2) { + eh = true; + break; + } + } + } + if (eh) { + ini = mid; + } else { + fim = mid - 1; + } + } + cout << ini << endl; + return 0; +} +int main() { + size_t n; + cin >> n; + string s; + cin >> s; + s.erase(unique(s.begin(), s.end()), s.end()); + cout << n - s.length() << endl; + return 0; +} +int d, m; +int main() { + cin >> m >> d; + cout << m + d - 1 << endl; + for (int i = 1; i <= d; i++) { cout << "1 " << i << endl; } + for (int i = 2; i <= m; i++) { cout << i << " 1" << endl; } +} +const int N = 10 + 5; +int m, n, res; +char a[N][N]; +bool row[N], col[N], eaten[N][N]; +void Input() { + cin >> m >> n; + for (int i = 1; i <= m; i++) cin >> (a[i] + 1); + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == 'S') row[i] = true, col[j] = true; + } + } +} +void Solve() { + for (int i = 1; i <= m; i++) { + if (row[i] == false) { + for (int j = 1; j <= n; j++) { + if (!eaten[i][j]) eaten[i][j] = true, res++; + } + } + } + for (int j = 1; j <= n; j++) { + if (col[j] == false) { + for (int i = 1; i <= m; i++) { + if (!eaten[i][j]) eaten[i][j] = true, res++; + } + } + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int T, l, r; +int main() { + int i, j; + cin >> T; + for (i = 1; i <= T; i++) { + cin >> l >> r; + cout << l << ' ' << (r / l) * l << '\n'; + } + return 0; +} +int main() { + long long int k, l, i, j; + while (cin >> k) { + cin >> l; + j = 1; + int p = 0; + for (i = 1;; i++) { + j *= k; + if (j == l) { + cout << "YES" << endl; + cout << i - 1 << endl; + p = 1; + break; + } + if (j > l) break; + } + if (p == 0) cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + while (n) { + if (n & 1) cnt++; + n >>= 1; + } + cout << cnt << endl; + return 0; +} +int main() { + int cnt = 0; + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == s[i + 1]) { + cnt++; + } else { + cnt++; + if (cnt > 7 || cnt == 7) { + cout << "YES" << endl; + break; + } + cnt = 0; + } + } + if (cnt <= 6) { cout << "NO" << endl; } + return 0; +} +int main() { + int r, c; + cin >> r >> c; + vector v(r); + for (int i = 0; i < r; ++i) { cin >> v[i]; } + vector hor(c, false), ver(r, false); + for (int y = 0; y < r; ++y) { + for (int x = 0; x < c; ++x) { + if (v[y][x] == 'S') { + hor[x] = true; + ver[y] = true; + } + } + } + int res = 0; + for (int y = 0; y < r; ++y) { + for (int x = 0; x < c; ++x) { + if (!hor[x] || !ver[y]) res++; + } + } + cout << res << endl; + return 0; +} +int main() { + int n, m, flag = 0; + cin >> n >> m; + for (int i = (n + 1) / 2; i <= n; i++) + if (i % m == 0) { + flag = 1; + cout << i << endl; + break; + } + if (flag == 0) cout << -1 << endl; + return 0; +} +list kuda; +int main() { + for (int i = 1; i <= 4; i++) { + int n; + cin >> n; + kuda.push_back(n); + } + kuda.sort(); + kuda.unique(); + cout << 4 - kuda.size() << endl; +} +int main() { + string word; + cin >> word; + word[0] = toupper(word[0]); + cout << word << endl; +} +int main() { + int r, g, b, time, ar, minn, total; + while (cin >> r >> g >> b) { + total = r + g + b; + time = 0; + ar = 0; + while (total > 0) { + if (ar % 3 == 0) { + if (r > 0) { + minn = min(r, 2); + total -= minn; + r -= minn; + } + } else if (ar % 3 == 1) { + if (g > 0) { + minn = min(g, 2); + total -= minn; + g -= minn; + } + } else { + if (b > 0) { + minn = min(b, 2); + total -= minn; + b -= minn; + } + } + time = ar; + ar++; + } + time += 30; + cout << time << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + for (int i = 1; i * (i + 1) / 2 < n + 1; i++) { cout << a[(i * (i + 1) / 2) - 1]; } + cout << endl; + return 0; +} +const int N = 2e5 + 10; +int a[N], c[N]; +int m, n; +char s[105]; +char str1[][8] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; +int main() { + cin >> s; + m = 0; + for (int i = 0; i < strlen(s); ++i) { + if (s[i] == 'D') { + int x = 0, k, j; + for (j = i + 1, k = 1; j <= i + 4; ++j, ++k) + if (s[j] != str1[0][k]) break; + if (k == 5) m++; + } else if (s[i] == 'O') { + int x = 0, k, j; + for (j = i + 1, k = 1; j <= i + 3; ++j, ++k) + if (s[j] != str1[1][k]) break; + if (k == 4) m++; + } else if (s[i] == 'S') { + int x = 0, k, j; + for (j = i + 1, k = 1; j <= i + 4; ++j, ++k) + if (s[j] != str1[2][k]) break; + if (k == 5) m++; + } else if (s[i] == 'A') { + int x = 0, k, j; + for (j = i + 1, k = 1; j <= i + 2; ++j, ++k) + if (s[j] != str1[3][k]) break; + if (k == 3) m++; + } else if (s[i] == 'N') { + int x = 0, k, j; + for (j = i + 1, k = 1; j <= i + 5; ++j, ++k) + if (s[j] != str1[4][k]) break; + if (k == 6) m++; + } + } + if (m == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" << endl; + } else if (n1 == n2) { + cout << "Second" << endl; + } else + cout << "Second" << endl; +} +void compute() { + char a[4][4]; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) cin >> a[i][j]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (j <= 2 && i <= 2) { + int hutch = 0, dots = 0; + for (int k = 0; k < 2; k++) { + for (int l = 0; l < 2; l++) + if (a[i + k][j + l] == '#') + ++hutch; + else + ++dots; + } + if (hutch >= 3 || dots >= 3) { + cout << "YES\n"; + return; + } + } + } + } + cout << "NO\n"; +} +int main() { + compute(); + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int l, r, d; + cin >> l >> r >> d; + if (d < l or d > r) { + cout << d << endl; + } else { + cout << (r / d + 1) * d << endl; + } + } + return 0; +} +int main() { + int q; + cin >> q; + long long l, r, d; + for (int i = 0; i < q; i++) { + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else { + cout << ((r + d) / d) * d << endl; + } + } + return 0; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +int main() { + int n; + cin >> n; + cout << ((n % 2) ? "Ehab" : "Mahmoud") << '\n'; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + char c = k & 1 ? 'L' : 'R'; + k = (k - 1) / 2; + int a = k / m; + int b = k % m; + cout << a + 1 << " " << b + 1 << " " << c << endl; +} +int main() { + int k, d; + cin >> k >> d; + if (d == 0 && k > 1) { + cout << "No solution" << endl; + } else { + cout << d; + for (int i = 1; i < k; i++) cout << 0; + cout << endl; + } + return 0; +} +int main() { + int np, is, ms, as, rr; + cin >> np >> is >> ms >> as >> rr; + int days = 1, read = 0, cur_speed = is; + while (true) { + read += cur_speed; + if (read >= np) break; + read -= rr; + cur_speed += as; + if (cur_speed > ms) cur_speed = ms; + days++; + } + cout << days << endl; +} +int main() { + int n, a[1005]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int i = 1; + for (; i < n;) { + if (a[i] > a[i - 1]) + i++; + else + break; + } + for (; i < n;) { + if (a[i] == a[i - 1]) + i++; + else + break; + } + for (; i < n;) { + if (a[i] < a[i - 1]) + i++; + else + break; + } + if (i != n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int cnt = 0; + int sum = 1; + for (int i = 0;; i++) { + int w = v0 + i * a; + if (w >= v1) w = v1; + sum = sum + w - 1; + cnt++; + if (sum >= c) break; + sum++; + sum -= l; + } + cout << cnt << endl; + return 0; +} +long long n, f[1000]; +char c[1000]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> c[i]; + f[1] = 1; + for (int i = 2; i <= n; i++) { + f[i] = f[i - 1] + 1; + if (c[i] != c[i - 1]) f[i] = min(f[i], f[i - 2] + 1); + } + cout << f[n] << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + for (int i = 1; i < 100000; i++) { + a = a * 3; + b = b * 2; + if (a > b) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int x, y, z; + int t; + cin >> t; + cin >> x; + int rem = 7 - x; + set s; + while (t--) { + cin >> y >> z; + s.insert(y); + s.insert(z); + } + int s_size = s.size(); + s.insert(x); + s.insert(rem); + int s1_size = s.size(); + if (s1_size - s_size == 0 || s1_size - s_size == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 4 == 0 || n % 4 == 3) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +string s; +int main() { + int a, d, i, n, m; + cin >> m; + cin >> s; + n = s.length(); + a = d = 0; + for (i = 0; i < n; i++) { + if (s[i] == 'A') + a++; + else if (s[i] == 'D') + d++; + } + if (a > d) + cout << "Anton" << endl; + else if (a < d) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; + return 0; +} +void solveequal(); +int main() { + long long int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + long long int x, y; + cin >> x >> y; + long long int dx = abs(x2 - x1), dy = abs(y2 - y1); + if (dx % x or dy % y) + cout << "NO\n"; + else { + long long int k1 = dx / x; + k1 &= 1; + long long int k2 = dy / y; + k2 &= 1; + if (k1 == k2) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + string a, b; + cin >> a; + int len = a.size(); + int left = 0, right = len - 1; + for (int i = len - 1; i >= 0; i--) { + if (i % 2 == 0) { + b = a[left++] + b; + } else { + b = a[right--] + b; + } + } + cout << b << endl; + return 0; +} +long long n; +long long maxn; +unsigned long long a[100001]; +unsigned long long dp[100001][2]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + a[x] += x; + if (x > maxn) { maxn = x; } + } + for (int i = 1; i <= maxn; i++) { + if (dp[i - 1][0] > dp[i - 1][1]) { + dp[i][0] = dp[i - 1][0]; + } else { + dp[i][0] = dp[i - 1][1]; + } + dp[i][1] = dp[i - 1][0] + a[i]; + } + if (dp[maxn][0] > dp[maxn][1]) { + cout << dp[maxn][0] << endl; + return 0; + } else { + cout << dp[maxn][1] << endl; + return 0; + } +} +int main() { + int n; + string s, res; + cin >> n >> s; + for (int i = 0; i < n; i++) { + int cek = 0; + while (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + i += 2; + cek = 1; + } + if (cek) { + res.push_back('*'); + res.push_back('*'); + res.push_back('*'); + continue; + } + res.push_back(s[i]); + } + cout << res << endl; + return 0; +} +bool lucky(int n) { + while (n != 0) { + if (n % 10 != 4 && n % 10 != 7) { return false; } + n /= 10; + } + return true; +} +bool almost_lucky(int n) { + if (lucky(n)) { return true; } + for (int i = 2; i * i <= n; ++i) { + if (n % i == 0 && (lucky(i) || lucky(n / i))) { return true; } + } + return false; +} +int main() { + int n; + cin >> n; + if (almost_lucky(n)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + char a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int k = 0; + for (int i = 0; i < n - 1; i++) { + if (a[i] == a[i + 1]) { k++; } + } + cout << k << endl; +} +const int N = 101; +vector adj[N], l(N, 1e9); +vector vis(N); +void f(int s) { + vis[s] = true; + queue q; + q.push(s); + l[s] = 0; + while (!q.empty()) { + int p = q.front(); + q.pop(); + for (int i = 0; i < adj[p].size(); i++) { + if (vis[adj[p][i]] == false) { + l[adj[p][i]] = min(l[adj[p][i]], l[p] + 1); + vis[adj[p][i]] = true; + q.push(adj[p][i]); + } + } + } +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') continue; + for (int j = i + 1; j < min(n, i + k + 1); j++) { + if (s[j] == '1') adj[i].push_back(j), adj[j].push_back(i); + } + } + f(0); + if (l[n - 1] == 1e9) l[n - 1] = -1; + cout << l[n - 1] << endl; + return 0; +} +int main() { + int n, l, r, d; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> l >> r >> d; + if (d < l || d > r) + cout << d << endl; + else if (r % d == 0) + cout << r + d << endl; + else + cout << (r + d - 1) / d * d << endl; + } +} +int main() { + int n, i, j, x, y = 0, a = 0, b; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + y += x; + } + if ((n == 1) && (y % 2 == 0)) + cout << "2" << endl; + else if ((n == 1) && (y % 2 != 0)) + cout << "3" << endl; + else { + for (i = 0; i < 5; i++) { + if (((y + i) % (n + 1)) != 0) { a++; } + } + cout << a << endl; + } + return 0; +} +int maxx(int a, int b) { + if (a > b) { + return a; + } else { + return b; + } +} +int main() { + int a, b, c, max = 0, t; + cin >> a >> b >> c; + t = (a + b) * c; + max = maxx(max, t); + t = a * (b + c); + max = maxx(max, t); + t = a * b * c; + max = maxx(max, t); + t = a + b + c; + max = maxx(max, t); + cout << max << endl; +} +const long long mod1 = 998244353; +const long long mod2 = 1000000007; +long long pow(int a, int b) { + if (b == 0 || a == 1) return 1; + if (b % 2 == 0) { + long long k = pow(a, b / 2); + return (k * k); + } else { + long long k = pow(a, b / 2); + return k * k * a; + } +} +long long powmod(long long a, long long b, long long mod) { + if (b == 0 || a == 1) { + if (mod == 1) + return 0; + else + return 1; + } + if (b % 2 == 0) { + long long k = powmod(a, b / 2, mod); + return (k * k) % mod; + } else { + long long k = powmod(a, b / 2, mod); + return ((k * k) % mod * a) % mod; + } +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + if (a > b) + return gcd(a % b, b); + else + return gcd(b % a, a); +} +int prime(int p) { + for (int i = 2; i * i <= p; i++) { + if (p % i == 0 && i < p) return 0; + } + return 1; +} +long long sqr(long long i) { + return i * i; +} +int main() { + int a; + cin >> a; + int m[a]; + int ans[a]; + for (int i = 0; i < a; i++) { + cin >> m[i]; + if (m[i] % 7 == 0) + ans[i] = m[i] / 7; + else + ans[i] = m[i] / 7 + 1; + } + for (int i = 0; i < a; i++) cout << ans[i] << "\n"; + return 0; +} +int xa, ya, xb, yb, x, y; +int main() { + cin >> xa >> ya >> xb >> yb >> x >> y; + xb -= xa; + yb -= ya; + xb = abs(xb); + yb = abs(yb); + if (xb % x || yb % y) { + cout << "NO\n"; + return 0; + } + xb /= x; + yb /= y; + if ((xb + yb) & 1) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } +} +int main() { + long long int n, i, j; + cin >> n; + long long int a[n], b[n], s1 = 0, s2 = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + s1 += a[i]; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + s2 += b[i]; + } + if (s1 >= s2) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } + return 0; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + int cur = 1; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + for (int l = 0; l < 2; ++l) { + if (cur == k) { cout << i + 1 << " " << j + 1 << " " << (l ? 'R' : 'L') << '\n'; } + cur++; + } + } + } + } + return 0; +} +int main() { + int a, b, n, i, j, k, l, cnt = 1; + cin >> a >> b >> n; + while (1) { + if (cnt % 2 == 1) { + n -= __gcd(a, n); + cnt++; + if (n == 0) { break; } + } else { + n -= __gcd(b, n); + cnt++; + if (n == 0) { break; } + } + } + if (cnt % 2 == 1) { + cout << "1" << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + int y, b, r, ans; + cin >> y >> b >> r; + if (r - 2 != 0 && r - 2 <= y && r - 1 <= b) + ans = 3 * r - 3; + else if (b + 1 <= r && b - 1 != 0 && b - 1 < +y) + ans = 3 * b; + else + ans = 3 * y + 3; + cout << ans << endl; + return 0; +} +int main() { + set R; + string S; + getline(cin, S); + for (int i = 0; i < S.size(); i++) { + if (S[i] >= 97 and S[i] <= 122) { R.insert(S[i]); } + } + cout << R.size() << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char c; + bool flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> c; + if (c == 'C' || c == 'M' || c == 'Y') flag = 1; + } + } + cout << (flag == 0 ? "#Black&White" : "#Color") << endl; + return 0; +} +int main() { + int a, b, c, c1, c2, c3, n1, n2, result = 0; + cin >> a >> b >> c; + c1 = a / 1; + c2 = b / 2; + c3 = c / 4; + n1 = min(c1, c2); + n2 = min(n1, c3); + result = n2 + 2 * n2 + 4 * n2; + cout << result << endl; + return 0; +} +long long power(long long x, long long y, long long m) { + if (y == 1) return x % m; + if (y == 0) return 1; + if (y & 1) return (x * power((x * x) % m, (y - 1) / 2, m)) % m; + return power((x * x) % m, y / 2, m) % m; +} +long long modinv(long long x, long long mod = 1000000007) { + return power(x, mod - 2, mod); +} +void solve() { + long long n; + cin >> n; + if ((n * (n + 1) / 2) & 1) + cout << 1 << endl; + else + cout << 0 << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int a, b, c, max = -1; + cin >> a >> b >> c; + if (a + b + c > max) max = a + b + c; + if (a * (b + c) > max) max = a * (b + c); + ; + if ((a + b) * c > max) max = (a + b) * c; + if (a * b * c > max) max = a * b * c; + cout << max << endl; + return 0; +} +int main() { + long long int i, n, cnt = 0, a[100001]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + int mx = a[0]; + int mn = a[0]; + for (i = 0; i < n; i++) { + if (a[i] > mx) mx = a[i]; + if (a[i] < mn) mn = a[i]; + } + for (i = 0; i < n; i++) { + if (a[i] > mn && a[i] < mx) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int m, k, sum1, sum2, maxn, t, t0, i; + int d[1005], s[1005]; + while (cin >> m >> k) { + for (i = 1; i <= m; i++) cin >> d[i]; + for (i = 1; i <= m; i++) cin >> s[i]; + sum1 = 0; + sum2 = 0; + maxn = 0; + t = 0; + for (int i = 1; i <= m; i++) { + sum1 += d[i]; + sum2 += s[i]; + if (maxn < s[i]) maxn = s[i]; + if (sum2 < sum1) { + t0 = (abs(sum2 - sum1)) / maxn; + if (abs(sum2 - sum1) % maxn) t0++; + t += t0; + sum2 += (maxn * t0); + } + } + cout << sum1 + k * t << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (a > b) + cout << "First" + << "\n"; + else + cout << "Second\n"; + return 0; +} +const int64_t infint64_t = 9223372036854775807LL; +void solve() { + int64_t n; + cin >> n; + int64_t last = -1; + int64_t state = 0; + for (int64_t i = 0; i < n; i++) { + int64_t cur; + cin >> cur; + if (state == 0) { + if (cur < last) { + state = 2; + } else if (cur == last) { + state = 1; + } else { + state = 0; + } + } else if (state == 1) { + if (cur < last) { + state = 2; + } else if (cur == last) { + state = 1; + } else { + cout << "NO" << endl; + return; + } + } else if (state == 2) { + if (cur < last) { + state = 2; + } else if (cur == last) { + cout << "NO" << endl; + return; + } else { + cout << "NO" << endl; + return; + } + } + last = cur; + } + cout << "YES" << endl; +} +int main() { + solve(); + return 0; +} +int main() { + set z; + long long x[4]; + for (int i = 0; i < 4; i++) { + cin >> x[i]; + z.insert(x[i]); + } + cout << 4 - z.size() << endl; +} +int main() { + long long n; + cin >> n; + long long a, b, c; + while (n--) { + cin >> a >> b >> c; + if (c < a || c > b) + cout << c << endl; + else + cout << ((b / c) + 1) * c << endl; + } + return 0; +} +int hotels[150]; +set S; +int main() { + int n, d; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> hotels[i]; + int counter = 2, aux = hotels[0]; + for (int i = 0; i < n; i++) { + if (i == 0) + S.insert(hotels[i] - d); + else if ((hotels[i] - d) - hotels[i - 1] >= d) + S.insert(hotels[i] - d); + if (i == n - 1) + S.insert(hotels[i] + d); + else if (hotels[i + 1] - (hotels[i] + d) >= d) + S.insert(hotels[i] + d); + } + cout << S.size() << "\n"; + return 0; +} +int main() { + int a, i; + int sum = 0; + for (i = 0; i < 5; i++) { + cin >> a; + sum = sum + a; + } + if (sum % 5 != 0 || sum == 0) { + cout << "-1" << endl; + } else { + cout << sum / 5 << endl; + } + return 0; +} +int arr[7][7]; +void fun() { + arr[1][2] = arr[2][6] = arr[5][1] = arr[6][5] = 34; + arr[2][1] = arr[6][2] = arr[1][5] = arr[5][6] = 43; + arr[1][3] = arr[3][6] = arr[4][1] = arr[6][4] = 52; + arr[3][1] = arr[6][3] = arr[1][4] = arr[4][6] = 25; + arr[2][4] = arr[3][2] = arr[4][5] = arr[5][3] = 61; + arr[4][2] = arr[2][3] = arr[5][4] = arr[3][5] = 16; +} +int main() { + fun(); + bool f = true; + int x, y, z, n; + cin >> n; + cin >> z; + cin >> x >> y; + for (int i = 1; i < n; i++) { + cin >> x >> y; + if (z != arr[x][y] / 10 && z != arr[x][y] % 10) f = false; + } + if (f) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +string st[10]; +long long n; +int main() { + st[1] = "+------------------------+"; + st[2] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + st[3] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + st[4] = "|#.......................|"; + st[5] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + st[6] = "+------------------------+"; + cin >> n; + for (int i = 0; i < 27; i++) { + for (int j = 1; j < 6; j++) + if (st[j][i] == '#' && n > 0) { + st[j][i] = 'O'; + n--; + } + } + for (int i = 1; i <= 6; i++) cout << st[i] << endl; + return 0; +} +int main() { + int n; + string inp; + cin >> n >> inp; + int ans = 1; + for (int i = 1; i < n; i++) { + if (inp.at(i) != inp.at(i - 1)) ans++; + } + cout << n - ans << endl; + return 0; +} +int main() { + int x = 0; + int q; + cin >> q; + while (q--) { + string a; + cin >> a; + if (a[1] == '+') + x++; + else + x--; + } + cout << x << endl; +} +int main() { + int len, step, ans = 0, now = 0; + cin >> len >> step; + string s; + cin >> s; + while (now < len - 1) { + int tmp; + for (int i = now + step; i >= now; i--) { + if (s[i] == '1') { + tmp = i; + break; + } + } + if (tmp == now) { + cout << -1 << endl; + return 0; + } + now = tmp; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, l[60], r[60]; + cin >> n >> x; + int t = 1; + for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; + int ans = 0; + for (int i = 1; i <= n;) { + if (t + x > l[i]) { + ans += r[i] - t + 1; + t = r[i] + 1; + i++; + } else + t += x; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, r = 0, c = 0, i = 0, j = 0; + char ch; + cin >> n >> m; + int row[3], col[3]; + while (i < n) { + while (j < m) { + cin >> ch; + if (ch == '*') { + row[r] = i; + col[r] = j; + r++; + } + j++; + } + j = 0; + i++; + } + r = 0; + for (i = 0; i < 3; i++) { + for (j = i + 1; j < 3; j++) { + if (row[i] == row[j]) { + row[i] = 0; + row[j] = 0; + } + if (col[i] == col[j]) { + col[i] = 0; + col[j] = 0; + } + } + } + sort(row, row + 3); + sort(col, col + 3); + cout << row[2] + 1 << " " << col[2] + 1 << endl; + return 0; +} +long long n; +int main() { + cin >> n; + if (n == 0) + cout << 0 << endl; + else if (n % 2 == 0) + cout << n + 1 << endl; + else + cout << (n + 1) / 2 << endl; + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (d == 0 && k > 1) { + cout << "No solution" << endl; + return 0; + } + cout << d; + for (int i = 1; i < k; i++) { cout << 0; } + cout << endl; +} +int find(int x, int father[]) { + if (father[x] == x) return x; + return father[x] = find(father[x], father); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int pos = 0; + for (int i = 1; i < n; i++) { + if (s[i] < s[i - 1]) { + pos = i - 1; + break; + } else { + pos = i; + } + } + s.erase(pos, 1); + cout << s << "\n"; +} +int main() { + int n; + cin >> n; + vector v(n); + for (long long int i = 0; i < n; i++) { cin >> v[i]; } + int ans = INT_MAX; + for (int st = 0; st < n; st++) { + int sum = 0; + for (int j = 0; j < n; j++) { + int curr = (st + j) % n; + sum += v[curr]; + ans = min(ans, abs(2 * sum - 360)); + } + } + cout << ans << endl; +} +int a, n, m[100001]; +int main() { + cin >> a >> n; + while (true) { + a %= n; + if (a == 0) { + cout << "Yes\n"; + return 0; + } + if (m[a]) { + cout << "No\n"; + return 0; + } + m[a] = true; + a += a; + } +} +const int M = 100 + 5; +string name[M]; +int points[M]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + name[i] = s; + int phack, nhack; + cin >> phack >> nhack; + points[i] += (phack * 100 - nhack * 50); + for (int j = 0; j < 5; j++) { + int x; + cin >> x; + points[i] += x; + } + } + int index = 0; + int max_points = points[0]; + for (int i = 0; i < n; i++) { + if (points[i] > max_points) { + max_points = points[i]; + index = i; + } + } + cout << name[index] << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i <= c / a; i++) { + if ((c - i * a) % b == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int i; + for (i = 0; i < s.size() - 1; i++) { + if (s[i] != s[i + 1]) break; + } + if (i == s.size() - 1) { + cout << 0 << endl; + return 0; + } + while (1) { + string t; + t = s; + reverse(t.begin(), t.end()); + if (s != t) { + cout << s.size() << endl; + return 0; + } + s.replace(s.size() - 1, 1, "\0"); + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int pos = n - 1; + for (int i = 0; i < n - 1; ++i) { + if (s[i] > s[i + 1]) { + pos = i; + break; + } + } + cout << s.substr(0, pos) + s.substr(pos + 1) << endl; + return 0; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n, x; + cin >> n >> x; + int t = 0, le = 1; + for (int i = 0; i < n; ++i) { + int s, e; + cin >> s >> e; + t += (s - le) % x; + t += e - s + 1; + le = e + 1; + } + cout << t << '\n'; + return 0; +} +int main() { + map h; + int n; + cin >> n; + string s[50]; + int t[50]; + int sum = 0; + int p, a, b, c, d, e; + int m = -30000; + int q = 0; + int x = 0; + for (int i = 0; i < n; i++) { + sum = 0; + cin >> s[i] >> p >> t[i] >> a >> b >> c >> d >> e; + sum += (p * 100) + a + b + c + d + e - (t[i] * 50); + if (sum > m) { m = sum; } + h[sum] = s[i]; + } + cout << h[m] << endl; +} +pair a[100 + 10]; +char in[100 + 10][100 + 10]; +int main() { + int p = 1; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> in[i][j]; + if (in[i][j] == '*') { + a[p].first = i; + a[p].second = j; + p++; + } + } + } + int x1, x2, y1, y2; + bool found = 0; + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + if (i != j) { + if (a[i].first != a[j].first && a[i].second != a[j].second) { + x1 = a[i].first; + y1 = a[i].second; + x2 = a[j].first; + y2 = a[j].second; + found = 1; + break; + } + } + } + if (found == 1) { break; } + } + if (in[x1][y2] != '*') { cout << x1 << " " << y2 << endl; } + if (in[x2][y1] != '*') { cout << x2 << " " << y1 << endl; } +} +int main() { + string s; + cin >> s; + s[0] = towupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + long long x, n, sum = 0, ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + sum += x; + } + for (int i = 1; i <= 5; i++) { + if ((sum + i) % (n + 1) != 1) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + string p; + map mapa; + for (int i = s.length() - 1; i >= 0; i--) { + p += s[i]; + mapa[s[i]] += 1; + } + if (p == s) { + if (mapa.size() == 1) { + cout << 0 << endl; + } else { + cout << s.length() - 1 << endl; + } + } else { + cout << s.length() << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int s1[n]; + int s2[n]; + for (int i = 0; i < n; i++) cin >> s1[i]; + for (int i = 0; i < n; i++) cin >> s2[i]; + for (int i = 0; i < n; i++) s1[i]--, s2[i]--; + int arr[n]; + for (int i = 0; i < n; i++) { arr[s2[i]] = i; } + for (int i = 0; i < n - 1; i++) { + if (arr[s1[i]] > arr[s1[i + 1]]) { + cout << n - 1 - i << "\n"; + return 0; + } + } + cout << "0\n"; + return 0; +} +const int maxn = 400; +int a[maxn], sum[maxn]; +int main() { + int n; + cin >> n; + memset(sum, 0, sizeof sum); + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum[i] = sum[i - 1] + a[i]; + } + int ans = 360; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { ans = min(ans, 2 * abs(180 - sum[i] + sum[j - 1])); } + } + cout << ans << endl; + return 0; +} +int n, a, b, c, d, e, sum, f, g; +string name; +int main() { + cin >> n; + pair p[n]; + for (int i = 0; i < n; i++) { + cin >> name >> a >> b >> c >> d >> e >> f >> g; + sum += c + d + e + f + g; + sum += (a * 100) - (b * 50); + p[i] = {sum, name}; + sum = 0; + } + sort(p, p + n); + cout << p[n - 1].second << endl; +} +int main() { + int n; + cin >> n; + pair pr[n]; + for (int i = 0; i < n; i++) { cin >> pr[i].first >> pr[i].second; } + sort(pr, pr + n); + for (int j = 0; j < n - 1; j++) { + if (pr[j].first < pr[j + 1].first && pr[j].second > pr[j + 1].second) { + cout << "Happy Alex" << endl; + return 0; + } + } + cout << "Poor Alex" << endl; + return 0; +} +int main() { + int n; + long long i, s = 0; + cin >> n; + long long a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + s += a[i]; + } + sort(a, a + n); + int cnt = 0, j; + if (s % 2 != 0) { + for (i = 0; i < n; i++) { + if (a[i] % 2 != 0) { + s -= a[i]; + cout << s << "\n"; + return 0; + } + } + } else + cout << s << "\n"; + return 0; +} +int a[55]; +bool vis[1005]; +vector s; +int main() { + int n, tot = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = n - 1; i >= 0; i--) { + if (!vis[a[i]]) { + s.push_back(a[i]); + vis[a[i]] = true; + } + } + int len = s.size(); + cout << len << endl; + for (int i = len - 1; i > 0; i--) cout << s[i] << " "; + cout << s[0] << endl; + return 0; +} +int n, m, b, mod; +long long sum; +long long dp[600][600], a[600]; +int i, j, k; +int main() { + cin >> n >> m >> b >> mod; + for (i = 1; i <= n; i++) { cin >> a[i]; } + dp[0][0] = 1; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + for (k = a[i]; k <= b; k++) { + dp[j][k] += dp[j - 1][k - a[i]]; + dp[j][k] %= mod; + } + } + } + sum = 0; + for (i = 0; i <= b; i++) { + sum += dp[m][i]; + sum %= mod; + } + cout << sum << endl; + return 0; +} +int main() { + int a, s, d, f, g, h; + cin >> a >> s >> d; + vector p; + s = s / 2; + d = d / 4; + p.push_back(s); + p.push_back(d); + p.push_back(a); + sort(p.begin(), p.end()); + g = p[0]; + f = g + (g * 2) + (g * 4); + cout << f << endl; + return 0; +} +int main() { + int x, tot = 0; + cin >> x; + while (x > 0) { + if (x % 2 == 1) { tot++; } + x /= 2; + } + cout << tot << endl; +} +int main() { + int n, m, x; + char c; + cin >> n >> m; + int a = 1, b = n, p = 0, q = 0; + for (int i = 0; i < m; i++) { + cin.ignore(7); + cin >> c; + cin.ignore(7); + cin >> x; + if (c == 'r' && x >= a) + a = x + 1; + else if (c == 'l' && x <= b) + b = x - 1; + } + if (b - a + 1 > 0) + cout << b - a + 1 << endl; + else + cout << -1 << endl; +} +int main() { + string a; + int begin, i = 1, n; + cin >> a; + if (0 == a.size() % 2) { + begin = a.size() / 2 - 1; + } else { + begin = a.size() / 2; + } + cout << a[begin]; + n = a.size() - 1; + while (i <= n) { + if (1 == i % 2) { + begin += i; + cout << a[begin]; + } else { + begin -= i; + cout << a[begin]; + } + i++; + } + cout << endl; + return 0; +} +bool predicate(string s1, string s2, vector &v, int d) { + string temp = ""; + vector memo(s1.size(), 0); + for (int i = 0; i < d; i++) memo[v[i] - 1] = 1; + for (int i = 0; i < s1.size(); i++) { + if (!memo[i]) temp += s1[i]; + } + int k = 0; + for (int i = 0; i < temp.size(); i++) { + if (temp[i] == s2[k]) k++; + if (k == s2.size()) return true; + } + return false; +} +int main() { + string s, f; + vector p; + getline(cin, s); + getline(cin, f); + int n = s.size(), temp; + for (int i = 0; i < n; i++) { + cin >> temp; + p.push_back(temp); + } + int l = 0, r = n; + while (l < r) { + int mid = l + (r - l + 1) / 2; + if (predicate(s, f, p, mid)) + l = mid; + else + r = mid - 1; + } + cout << l << "\n"; + return 0; +} +int seica_gcd(long long a, long long b) { + if (b == 0) { + return a; + } else { + return seica_gcd(b, a % b); + } +} +int main() { + int n; + cin >> n; + vector v(n); + int isOne = 0; + for (long long(i) = (0); (i) < (n); ++i) { + cin >> v[i]; + if (v[i] == 1) isOne++; + } + if (isOne) { + cout << n - isOne << endl; + return 0; + } + long long ans = 1000000000; + for (long long(i) = (0); (i) < (n); ++i) { + int now = v[i]; + for (int j = i + 1; j < n; j++) { + now = seica_gcd(now, v[j]); + if (now == 1) { + ans = min(ans, j - i - 1); + break; + } + } + } + if (ans == 1000000000) { + cout << -1 << endl; + } else { + cout << ans + n << endl; + } + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + int x; + cin >> x; + if (x >= 2 && x <= 7) { + cout << 1 << endl; + } else { + if (x % 7 == 0) cout << x / 7 << endl; + if (x % 7 != 0) cout << x / 7 + 1 << endl; + } + } + return 0; +} +int n; +string s; +int ans = 0; +char x; +int main() { + cin >> n; + cin >> s; + int len = s.size(); + for (int i = 1; i <= (len / n) && i * n < len; i++) { + if (s[i * n - 3] == s[i * n - 2] && s[i * n - 3] == s[i * n - 1]) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, k; + int i; + int cnt1 = 0, cnt2 = 0; + cin >> n >> m >> k; + vector v(n); + for (i = 0; i < n; i++) { cin >> v[i]; } + if (m != n) { + i = m; + while (i < v.size()) { + if (v[i] != 0 && v[i] <= k) { break; } + i++; + } + if (i < v.size() && v[i] != 0 && v[i] <= k) { cnt2 = 10 * (i - m + 1); } + } + if (m != 1) { + i = m - 2; + while (i >= 0) { + if (v[i] != 0 && v[i] <= k) { break; } + i--; + } + if (i >= 0 && v[i] != 0 && v[i] <= k) { cnt1 = 10 * (m - i - 1); } + } + if (cnt1 == 0) { + cout << cnt2 << endl; + } else if (cnt2 == 0) { + cout << cnt1 << endl; + } else { + cout << min(cnt1, cnt2) << endl; + } + return 0; +} +int a[1005]; +int main() { + int ans = 0; + for (int i = 0; i < 5; i++) { + cin >> a[i]; + ans += a[i]; + } + if (ans == 0) { + cout << "-1" << endl; + } else if (ans % 5 == 0) { + cout << ans / 5 << endl; + } else + cout << "-1" << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int count = 0, sum = 0, speed = v0; + while (sum < c) { + sum += min(v1 - min(sum, l), speed - min(sum, l)); + count++; + speed += a; + } + cout << count << '\n'; + return 0; +} +char s1[15]; +char s2[15]; +char s[15]; +int main() { + int f = 0; + cin >> s1; + int n = strlen(s1); + bool flag = 0; + for (int i = 0; i < 26; i++) { + for (int j = 0; j <= n; j++) { + f = 0; + for (int k = 0; k < j; k++) { s[k] = s1[k]; } + s[j] = char('a' + i); + for (int k = j + 1; k <= n; k++) { s[k] = s1[k - 1]; } + for (int i = 0, j = n; i < j; i++, j--) { + if (s[i] != s[j]) { + f++; + if (f >= 1) { break; } + } + } + if (f == 0) { + for (int i = 0; i <= n; i++) { cout << s[i]; } + cout << endl; + return 0; + } + } + } + cout << "NA" << endl; + return 0; +} +int main() { + int a, b, c, i, f = 0, sum; + cin >> a >> b >> c; + i = a; + for (;;) { + if ((i * 2 <= b && (i * 2 * 2) <= c) || (i == 0)) { + f = 1; + sum = i + (i * 2) + (i * 2 * 2); + break; + } else { + i--; + } + } + cout << sum << endl; + return 0; +} +int main() { + int q, l, r, d; + cin >> q; + while (q--) { + cin >> l >> r >> d; + int f = l - 1; + if (f >= d) { + cout << d << endl; + } else { + r++; + int s = r / d, ans = d * s; + if (ans < r) { + s++; + ans = d * s; + } + cout << ans << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool bisa = false; + for (int i = 0; i < s.size(); i++) { + assert(i < s.size()); + if ((i <= s.size() - 3) && s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + s[i] = '*'; + s[i + 1] = '*'; + s[i + 2] = '*'; + bisa = true; + i += 2; + } else if ((i <= s.size() - 2) && s[i] == 'g' && s[i + 1] == 'o' && bisa) { + s.erase(s.begin() + i, s.begin() + i + 2); + i--; + } else { + bisa = false; + } + } + cout << s << endl; +} +int main() { + int p, n; + cin >> p >> n; + vector v; + int t; + for (size_t i = 0; i < n; i++) { + cin >> t; + if (find(v.begin(), v.end(), t % p) != v.end()) { + cout << i + 1 << '\n'; + return 0; + } + v.push_back(t % p); + } + cout << "-1\n"; + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + long long a, b, c, d; + if (y > x) { + a = y - x; + } else { + a = x - y; + } + c = a * t1; + if (z > x) { + b = z - x; + } else { + b = x - z; + } + d = (b + a) * t2 + 3 * t3; + if (c >= d) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int count = 0, j; + string name; + cin >> name; + int len = name.size(); + for (int i = 0; i < len - 1; i++) { + if (name[i] == name[i + 1]) { count++; } + } + if (count == len - 1) { + return cout << "0" << endl, 0; + } else { + int count1 = 0; + for (int i = 0, j = len - 1; i < len / 2 && j >= 0; i++, j--) { + if (name[i] == name[j]) count1++; + } + if (len / 2 == count1) { + return cout << len - 1 << endl, 0; + } else { + return cout << len << endl, 0; + } + } +} +int main() { + int n; + cin >> n; + int i, j, H, G, a[101], counter = 0; + int flag = 0; + int maxer = -1; + int biaozhi = 0; + for (i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > maxer) { + maxer = a[i]; + H = i; + } + } + for (i = 1; i <= n; i++) + if (a[i] == maxer) { G = i; } + for (i = 1; i <= H - 1; i++) { + if (a[i] < a[i + 1]) { counter++; } + } + if (counter == H - 1) { + for (i = H; i <= G; i++) + if (a[i] != maxer) biaozhi = 1; + if (biaozhi == 0) { + for (i = G + 1; i <= n; i++) + if (a[i] < a[i - 1]) { flag++; } + if (flag == n - G) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + } else + cout << "NO" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << min(a, min(b / 2, c / 4)) * 7 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n % 2 == 0) { + if (k > n / 2) { + cout << ((k) - ((n / 2))) * 2 << endl; + } else { + cout << k * 2 - 1 << endl; + } + } else { + if (k > (n) / 2 + 1) { + cout << ((k) - ((n / 2 + 1))) * 2 << endl; + } else { + cout << k * 2 - 1 << endl; + } + } +} +long long power[105]; +long long btdc(string s, int len) { + long long ans = 0, i = len - 1, temp = 0; + while (i >= 0) { + if (s[i] == '1') { + temp = power[len - i - 1] % 1000000007; + ans += temp; + ans %= 1000000007; + } + i--; + } + return ans % 1000000007; +} +int main() { + string s; + cin >> s; + long long temp = 0, len = s.length(); + power[0] = 1; + for (int i = 1; i < 105; i++) { power[i] = (2 * power[i - 1]) % 1000000007; } + temp = power[len - 1] % 1000000007; + cout << (temp * (btdc(s, len) % 1000000007)) % 1000000007 << endl; + return 0; +} +const int mod = 1e9 + 7; +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int now = v0; + int cnt = 1; + while (now < c) { + now = now - l; + v0 = v0 + a; + v0 = min(v1, v0); + now += v0; + cnt++; + } + cout << cnt << endl; + return 0; +} +inline long long MAX2(long long a, long long int b) { + return (a) > (b) ? (a) : (b); +} +inline long long MAX3(long long a, long long b, long long c) { + return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)); +} +inline long long MIN2(long long a, long long b) { + return (a) < (b) ? (a) : (b); +} +inline long long MIN3(long long a, long long b, long long c) { + return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int temp, result = n - 1; + for (int i = 1; i < n; i++) { + temp = (int)s[i] - (int)s[i - 1]; + if (temp < 0) { + result = i - 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (i != result) cout << s[i]; + } + cout << endl; +} +int gl, gr, bl, br; +int main() { + cin >> gl >> gr >> bl >> br; + if (gl - 1 <= br && br <= 2 * gl + 2) + cout << "YES" << '\n'; + else if (gr - 1 <= bl && bl <= 2 * gr + 2) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int n; +int main() { + char fb[2]; + string str; + cin >> str >> n; + int ans = 0; + while (n--) { + cin >> fb; + for (int i = 0; i < str.length(); i++) { + int num1 = 0, num2 = 0; + while (str[i] == fb[0] || str[i] == fb[1]) { + if (str[i] == fb[0]) num1++; + if (str[i] == fb[1]) num2++; + i++; + } + ans += min(num1, num2); + } + } + cout << ans << endl; +} +int f(int n, int m) { + return (n % m == 0 ? n / m : n / m + 1); +} +int main() { + int l, d, p; + cin >> l >> d >> p; + int x = f(p, d * 2), lr = p - d * 2 * (x - 1), y = f(lr, 2); + cout << x << ' ' << y << ' ' << (lr % 2 == 0 ? 'R' : 'L') << endl; + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int m = 0; + int p[4]; + p[0] = a + b + c; + p[1] = a * (b + c); + p[2] = a * b * c; + p[3] = (a + b) * c; + for (int i = 0; i < 4; i++) + if (m < p[i]) m = p[i]; + cout << m << endl; + } +} +int main() { + int sum, c1, c2, c3, c4, c5; + cin >> c1 >> c2 >> c3 >> c4 >> c5; + sum = c1 + c2 + c3 + c4 + c5; + if (sum != 0 && sum % 5 == 0) { + cout << sum / 5 << endl; + } else { + cout << "-1" << endl; + } +} +int main() { + int ar[5], c = 3; + for (int i = 0; i < 4; i++) { cin >> ar[i]; } + sort(ar, ar + 4); + for (int i = 0; i < 3; i++) { + if (ar[i] != ar[i + 1]) { c--; } + } + cout << c << endl; +} +int main() { + long long w, n, s, k = 1, l, r, d; + cin >> n; + while (n--) { + cin >> l >> r >> d; + w = r % d; + if (d < l || d > r) { + cout << d << endl; + } else { + d = r + d - w; + cout << d << endl; + } + } + return 0; +} +long long int ara[105]; +int main() { + long long int cnt = 0, i, j, n, m, t; + cin >> t >> n; + for (i = 0; i < t; i++) { cin >> ara[i]; } + sort(ara, ara + t); + for (i = 0; i < t - 1; i++) { + if (ara[i + 1] - ara[i] > 2 * n) + cnt += 2; + else if (ara[i + 1] - ara[i] == 2 * n) + cnt++; + } + cout << cnt + 2 << endl; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + while (y > r - 2 || y > b - 1) y--; + while (b > y + 1) b--; + while (r > b + 1) r--; + cout << y + r + b << '\n'; + return 0; +} +string r; +int c = 0, e = 0; +int main() { + cin >> r; + for (int i = 0; i < r.length(); ++i) { + { + if (r[i] == '1') { + ++c; + e = 0; + } else { + c = 0; + ++e; + } + } + if (c == 7 || e == 7) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int i; +string m, n; +int main() { + cin >> n; + if (n.find("0000000") == -1 && n.find("1111111") == -1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, m, x; + cin >> n; + cin >> m; + if (n % 2 == 0) { + x = n / 2; + for (; x != n;) { + if (x % m == 0) { + break; + } else + x++; + } + } else if (n % 2 != 0) { + x = n / 2 + 1; + for (; x != n;) { + if (x % m == 0) { + break; + } else + x++; + } + } + if (n < m) x = -1; + cout << x << endl; +} +string s; +int main() { + cin >> s; + if (islower(s[0])) s[0] = (char)((int)s[0] - 32); + cout << s << endl; + return 0; +} +int remove0(int n) { + int m(0), pow(1); + while (n != 0) { + int d = n % 10; + n /= 10; + if (d != 0) { + m += d * pow; + pow *= 10; + } + } + return m; +} +int main() { + int a, b; + cin >> a >> b; + int c = a + b; + int A = remove0(a); + int B = remove0(b); + int C = remove0(c); + cout << (A + B == C ? "YES" : "NO") << endl; + return 0; +} +void solve() { + int n; + cin >> n; + while (n--) { + int a; + cin >> a; + if (a == 1) { + cout << "HARD" << '\n'; + return; + } + } + cout << "EASY" << '\n'; +} +int main() { + solve(); + return 0; +} +int main() { + long long c, v0, v1, a, l, i = 1, j, count = 0, temp; + cin >> c >> v0 >> v1 >> a >> l; + while (true) { + count++; + c -= v0; + if (c <= 0) break; + v0 += a; + if (v0 > v1) v0 = v1; + c += l; + } + cout << count << endl; + return 0; +} +long long n, a[105], ans, cnt; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + ans = a[n - 1]; + for (int i = n - 2; i >= 0; i--) a[i] += a[i + 1] - 1, ans += a[i]; + cout << ans << endl; + return 0; +} +const int MX = 200; +int main() { + int n; + string s; + map mapper; + mapper['R'] = 0; + mapper['U'] = 1; + mapper['L'] = 2; + mapper['D'] = 3; + int mx[] = {1, 0, -1, 0}; + int my[] = {0, 1, 0, -1}; + while (cin >> n >> s) { + int ans = 0; + for (int i = 0; i < n; ++i) { + int cx = 0; + int cy = 0; + for (int j = i; j < n; ++j) { + cx += mx[mapper[s[j]]]; + cy += my[mapper[s[j]]]; + ans += (cx == 0 && cy == 0); + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, x, l[100001], r[100001], ans = 0, i; + cin >> n >> x; + for (i = 1; i <= n; ++i) { + cin >> l[i] >> r[i]; + ans += r[i] - l[i] + 1; + } + ans += (l[1] - 1) - (l[1] - 1) / x * x; + for (i = 2; i <= n; ++i) { + int p = l[i] - r[i - 1] - 1; + ans += p - p / x * x; + } + cout << ans << endl; + return 0; +} +int ch[2000][2]; +int main() { + int n; + cin >> n; + int now = 1; + for (int i = 1; i <= n; i++) cin >> ch[i][0] >> ch[i][1]; + for (int i = 1; i; i++) { + if (i >= ch[now][0] && (i - ch[now][0]) % ch[now][1] == 0) now++; + if (now > n) { + cout << i << endl; + return 0; + } + } +} +int main() { + string t, p; + cin >> t >> p; + int n = t.length(); + int arr[n]; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + arr[i] = temp - 1; + } + int l = 0; + int r = n; + while (l + 1 < r) { + int mid = l + (r - l) / 2; + bool exist[n]; + memset(exist, 0, sizeof(exist)); + for (int i = 0; i < mid; i++) exist[arr[i]] = 1; + int j = 0; + for (int i = 0; i < n && j < p.length(); i++) { + if (p[j] == t[i] and exist[i] == 0) j++; + } + if (j == p.length()) + l = mid; + else + r = mid; + } + cout << l << endl; + return 0; +} +char s[105][105]; +int main() { + int n, m, flag = 0; + cin >> n >> m; + getchar(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == 'C' || s[i][j] == 'M' || s[i][j] == 'Y') flag = 1; + } + } + if (flag) { + cout << "#Color" << endl; + } else + cout << "#Black&White" << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n; + n = (n * (n + 1)) / 2; + x = n / 2; + y = n - x; + cout << abs(x - y) << endl; + return 0; +} +int n, x[101], y[101], ans = -1, vis[101]; +void dfs(int a) { + vis[a] = 1; + for (int i = 1; i <= n; i++) + if ((x[i] == x[a] || y[i] == y[a]) && !vis[i]) dfs(i); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; + for (int i = 1; i <= n; i++) + if (!vis[i]) dfs(i), ans++; + cout << ans << endl; +} +int main() { + long long int n, k; + cin >> n >> k; + if (k <= (n + 1) / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * (k - (n + 1) / 2) << endl; +} +int main() { + int n, sum = 0; + cin >> n; + while (n != 0) { + sum += n % 2; + n /= 2; + } + cout << sum << endl; +} +int main() { + int a, b; + while (cin >> a >> b) { + int count = 0; + while (a <= b) { + a = 3 * a; + b = 2 * b; + count++; + } + cout << count << endl; + } +} +int main() { + int a[100000] = {0}; + int n, m, e; + int i, j, num = 0; + char y[10], b[10], c[10], d[10]; + cin >> n >> m; + for (i = 0; i < m; i++) { + cin >> y >> b >> c >> d >> e; + if (c[0] == 'l') { + for (j = e; j <= n; j++) { a[j] = 1; } + } else if (c[0] == 'r') { + for (j = 1; j <= e; j++) { a[j] = 1; } + } + } + for (i = 1; i <= n; i++) { + if (a[i] == 0) num++; + } + if (num != 0) + cout << num << endl; + else + cout << "-1" << endl; + return 0; +} +const int mx = 2e5 + 10; +int a[mx], b[mx], vis[mx]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + cin >> b[i]; + vis[b[i]] = i; + } + int tmp = -1, ans = n; + for (int i = 0; i < n; i++) { + if (vis[a[i]] > tmp) { + ans--; + tmp = vis[a[i]]; + } else { + break; + } + } + cout << ans << endl; +} +int main() { + string s; + int n; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int n, f, sum = 0, possible_sum, fingers_ways = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> f; + sum += f; + } + for (int i = 1; i < 6; i++) { + possible_sum = sum + i; + if (possible_sum % (n + 1) != 1) fingers_ways++; + } + cout << fingers_ways << endl; + return 0; +} +long long i, h, m, z, p[200005], t, fg = 0; +string a, b, c; +bool chec(long long m) { + c = a; + fg = 0; + for (i = 0; i < m; i++) { c[p[i] - 1] = '1'; } + for (i = 0; i < a.size(); i++) { + if (c[i] == b[fg]) fg++; + if (fg == b.size()) return true; + } + return false; +} +int main() { + cin >> a >> b; + for (i = 0; i < a.size(); i++) cin >> p[i]; + z = 0; + h = a.size(); + m = (z + h) / 2; + while (h - z > 1) { + if (chec(m)) + z = m; + else + h = m; + m = (z + h) / 2; + } + cout << m << endl; +} +int main() { + long long n; + long long ans = 0; + cin >> n; + ans = n * (1 + n) / 2; + if (ans % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +const int MAXN = 101; +int main() { + int temp, n, k, a[MAXN] = {0}, i, cnt = 0, imax = 0; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> temp; + a[temp]++; + imax = max(imax, a[temp]); + } + for (i = 0; i < MAXN; i++) { + if (0 != a[i]) { cnt++; } + } + while (0 != imax % k) { imax++; } + cout << imax * cnt - n << endl; + return 0; +} +const int maxn = 1000000 + 5; +int vis[maxn] = {1}; +int main() { + int n, p = 0; + cin >> n; + for (int i = 1; i <= 1000000; i++) { + p += i; + p %= n; + vis[p] = 1; + } + for (int i = 0; i < n; i++) + if (vis[i] == 0) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +const int M = 100010; +char a[M], b[M]; +int main() { + gets(a); + int l = 0; + int len = strlen(a); + b[l++] = a[len - 1]; + for (int i = len - 2; i >= 0; i--) { + if (b[l - 1] <= a[i]) b[l++] = a[i]; + } + for (int i = l - 1; i >= 0; i--) cout << b[i]; + cout << endl; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + return 0; +} +int main() { + long long int n; + cin >> n; + char str[n]; + long long int i, ca = 0, cd = 0; + cin >> str; + for (i = 0; str[i] != '\0'; i++) { + if (str[i] == 65) + ca = ca + 1; + else if (str[i] == 68) + cd = cd + 1; + } + if (ca > cd) + cout << "Anton" << endl; + else if (ca == cd) + cout << "Friendship" << endl; + else + cout << "Danik" << endl; +} +int main() { + int N, M, K; + cin >> N >> M >> K; + --K; + const int l = 1 + K / (2 * M); + K %= (2 * M); + const int d = 1 + K / 2; + cout << l << ' ' << d; + if (K % 2 == 0) { + cout << " L\n"; + } else { + cout << " R\n"; + } + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +int main() { + int r, b, g; + cin >> r >> b >> g; + int x1, x2, x3; + int ans = -1; + if (r % 2 == 0) { + x1 = 3 * (r / 2) - 3; + if (ans < x1) { ans = x1; } + } else { + x1 = 3 * ((r + 1) / 2) - 3; + if (ans < x1) { ans = x1; } + } + if (b % 2 == 0) { + x2 = 3 * (b / 2) - 2; + if (ans < x2) { ans = x2; } + } else { + x2 = 3 * ((b + 1) / 2) - 2; + if (ans < x2) { ans = x2; } + } + if (g % 2 == 0) { + x3 = 3 * (g / 2) - 1; + if (ans < x3) { ans = x3; } + } else { + x3 = 3 * ((g + 1) / 2) - 1; + if (ans < x3) { ans = x3; } + } + cout << ans + 30 << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + cout << ((n1 > n2) ? "First" : "Second") << endl; + return 0; +} +int main() { + long long a[4]; + for (int i = 0; i < 4; i++) { cin >> a[i]; } + int count = 0; + for (int i = 1; i < 4; i++) { + for (int j = i - 1; j >= 0; j--) { + if (a[i] == a[j]) { + count++; + break; + } + } + } + cout << count << endl; +} +int arr[27]; +int main() { + int n, k; + string x; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) { arr[x[i] - 'A']++; } + int minim = 1e8; + for (int i = 0; i < k; i++) { minim = min(arr[i], minim); } + cout << (minim * k) << endl; +} +int n1, n2, k1, k2; +int main() { + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else if (n1 < n2) + cout << "Second" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << min(n, m) + (max(n, m) - 1) << endl; + for (int i = 1; i <= m; i++) { cout << 1 << " " << i << endl; } + --n; + if (n > 0) { + for (int i = 2; i <= n + 1; i++) { cout << i << " " << 1 << endl; } + } + return 0; +} +int a[30]; +int main() { + string s; + cin >> s; + int n = s.length(); + int maxx = 0; + for (int i = 0; i < n; i++) { + a[s[i] - 97]++; + maxx = max(maxx, s[i] - 97); + } + for (int i = 0; i < n; i++) { + while (a[maxx] == 0 && maxx > 0) { maxx--; } + if (maxx == s[i] - 97) { cout << s[i]; } + a[s[i] - 97]--; + } + cout << endl; +} +int main() { + int a, m; + cin >> a >> m; + set store; + int x = a; + while (1) { + int length = store.size(); + int temp = a % m; + store.insert(temp); + if (length == store.size()) { + cout << "No" << endl; + break; + } else if (a % m == 0) { + cout << "Yes" << endl; + break; + } + a += temp; + x = a; + } + return 0; +} +int main() { + int n, d, sum = 1, a[105]; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> a[i]; + if (n == 1) { + cout << 2 << endl; + return 0; + } + if ((a[0] + d) <= (a[1] - d)) sum++; + for (int i = 1; i < n - 1; i++) { + if ((a[i] - d) > (a[i - 1] + d)) sum++; + if ((a[i] + d) <= (a[i + 1] - d)) sum++; + } + if ((a[n - 1] - d) > (a[n - 2] + d)) sum++; + sum++; + cout << sum << endl; + return 0; +} +const int MAXN = 1e3 + 10; +int a[MAXN], b[MAXN]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + int ans = 0, mx = 0, cur = 0; + for (int i = 0; i < n; i++) { + mx = max(mx, b[i]); + cur += b[i]; + int nd = max(0, a[i] - cur); + nd = nd / mx + bool(nd % mx); + ans += nd * k; + cur += mx * nd; + ans += a[i]; + cur -= a[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v[k]; + long long cnt = 0, mx = 0; + for (int i = 0; i < k; i++) { + int x, h = 1, kk = -1; + cin >> x; + for (int j = 0; j < x; j++) { + int y; + cin >> y; + if (v[i].size() != 0 && v[i][0] == 1 && y == h + 1) { + h++; + continue; + } else { + v[i].push_back(y); + h = 1; + cnt++; + } + } + } + for (int i = 0; i < k; i++) { mx += (v[i].size() - 1); } + cout << (long long)(mx + cnt - 1) << endl; +} +int a[2010]; +int b[2010]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int j = 1; j <= n; j++) { + if (a[j] == -1) { + b[j] = 1; + continue; + } else { + int t = a[j]; + b[j] = 2; + while (a[t] != -1) { + b[j]++; + t = a[t]; + } + continue; + } + } + cout << *max_element(b, b + n + 1) << endl; + return 0; +} +int main() { + long long k, b, n, z; + cin >> k >> b >> n >> z; + int x = 1; + while (n && k * x + b <= z) { + x = k * x + b; + n--; + } + cout << n << endl; + return 0; +} +int main() { + int k, l, m, n, d; + int count = 0; + cin >> k >> l >> m >> n >> d; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) { count++; } + } + cout << count << "\n"; + return 0; +} +int main() { + int n, x = 0, i = 0; + cin >> n; + string s; + while (i != n) { + cin >> s; + if (s == "X++") { + x++; + } else if (s == "++X") { + ++x; + } else if (s == "X--") { + x--; + } else if (s == "--X") { + --x; + } + i++; + } + cout << x << endl; +} +int main() { + string decrypt, encrypt = ""; + cin >> decrypt; + int last, first, len; + len = decrypt.length(); + if (decrypt.length() == 1) { + cout << decrypt << endl; + return 0; + } + if (len % 2 == 0) { + last = decrypt.length() - 1; + first = 0; + } else { + last = 0; + first = decrypt.length() - 1; + } + if (len % 2 == 0) { + while (first < last) { + encrypt += decrypt[last]; + encrypt += decrypt[first]; + first++; + last--; + } + if (last == first) { encrypt += decrypt[last]; } + } else { + while (first > last) { + encrypt += decrypt[last]; + encrypt += decrypt[first]; + last++; + first--; + } + if (last == first) { encrypt += decrypt[last]; } + } + for (int i = encrypt.length() - 1; i >= 0; i--) { cout << encrypt[i]; } + cout << endl; + return 0; +} +int main() { + long long i, j, k, n, count = 0, num, sum = 0, mn = 1999999999; + cin >> n; + for (i = 0; i < n; i++) { + cin >> num; + sum += num; + if (num % 2) { + count++; + mn = min(num, mn); + } + } + if (count % 2) sum -= mn; + cout << sum << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + set st; + for (long long i = 0; i < s.length(); i++) { + if (s[i] != '{' && s[i] != '}' && s[i] != ' ' && s[i] != ',') st.insert(s[i]); + } + cout << st.size() << endl; +} +const int maxN = 2005; +int fth[maxN], vis[maxN] = {0}; +int ans = 0; +void dfs(int x, int h) { + vis[x] = 1; + if (fth[x] == -1) { + ans = max(ans, h); + return; + } + return dfs(fth[x], h + 1); +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fth[i]; + for (int i = 1; i <= n; i++) + if (!vis[i]) dfs(i, 1); + cout << ans << '\n'; +} +int main() { + int n; + int k = 0, x; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (i != 1) cout << x + k << " "; + k = x; + } + cout << x << endl; + return 0; +} +int main() { + int n, x = 0; + string y; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> y; + if (y == "X++" || y == "++X") + x++; + else if (y == "X--" || y == "--X") + x--; + } + cout << x << endl; + return 0; +} +int a[100001], b[100001], i, n; +long long s; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + s += a[i]; + } + for (i = 1; i <= n; i++) cin >> b[i]; + sort(b + 1, b + n + 1); + if (b[n] + b[n - 1] >= s) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s[5]; + for (int i = 0; i < 4; i++) cin >> s[i]; + for (int x = 1; x < 4; x++) + for (int y = 1; y < 4; y++) { + int cnt = 0; + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) + if (s[x - i][y - j] != s[x][y]) cnt++; + if (cnt ^ 2) return cout << "YES\n", 0; + } + cout << "NO\n"; + return 0; +} +int n; +int main() { + cin >> n; + while (n % 2 == 0) n /= 2; + if (n == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long a, b, c; + cin >> a >> b >> c; + vector v; + v.push_back(a + b + c); + v.push_back(a + b * c); + v.push_back(a * b + c); + v.push_back(a * b * c); + v.push_back((a + b) * c); + v.push_back(a * (b + c)); + cout << *max_element((v).begin(), (v).end()) << '\n'; + } + return 0; +} +string a; +int ans; +bool pan(int z, int y) { + string zs, ys; + for (int s = z; s <= y; s++) { zs = a[s] + zs; } + for (int s = y; s >= z; s--) { ys = a[s] + ys; } + if (zs == ys) + return 0; + else + return 1; +} +int main() { + cin >> a; + for (int s = 0; s < a.size(); s++) { + for (int v = s + 1; v < a.size(); v++) { + if (pan(s, v) && v - s > ans) { ans = v - s; } + } + } + if (pan(0, a.size()) && ans != 0) + cout << ans + 1 << endl; + else + cout << 0 << endl; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First\n"; + else if (n2 > n1) + cout << "Second\n"; + else { + cout << "Second\n"; + } +} +int n, k; +int main() { + cin >> n >> k; + if (k > n) { + cout << -1 << endl; + return 0; + } + if (k == 1) { + if (n == 1) + cout << 'a' << endl; + else + cout << -1 << endl; + return 0; + } + if (k == 2) { + for (int i = 0; i < n; i++) { cout << char('a' + (i & 1)); } + cout << endl; + return 0; + } + for (int i = 0; i < n - k + 2; i++) { cout << char('a' + (i & 1)); } + for (int i = 0; i < k - 2; i++) { cout << char('c' + i); } + cout << endl; +} +long long n, k, p; +long long a[1005], b[2005]; +bool moze(long long x) { + long long h = 0; + for (long long i = 0; i < n; i++) { + if (h == k) return false; + bool sat = false; + while (h < k) { + long long d = abs(a[i] - b[h]) + abs(b[h] - p); + h++; + if (d <= x) { + sat = true; + break; + } + } + if (!sat) return false; + } + return true; +} +int main() { + cin >> n >> k >> p; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + sort(a, a + n); + sort(b, b + k); + long long l = 0, r = 4e9, o = -1; + while (l <= r) { + long long m = (l + r) >> 1; + if (moze(m)) { + o = m; + r = m - 1; + } else { + l = m + 1; + } + } + cout << o << '\n'; +} +int mas[1000]; +int main() { + int n, m, i = 0; + string s, nomer = ""; + cin >> n >> m; + for (int q = 0; q < n; q++) { mas[q] = 0; } + getline(cin, s); + for (int w = 0; w < m; w++) { + getline(cin, s); + nomer = ""; + for (int q = 0; q < s.size(); q++) { + if (s[q] >= '0' && s[q] <= '9') { nomer = nomer + s[q]; } + } + int p = 1; + i = 0; + for (int q = nomer.size() - 1; q >= 0; q--, p = p * 10) { i = i + (nomer[q] - '0') * p; } + if (s.find("left") == -1) { + for (int q = i; q < n; q++) { mas[q]++; } + } else { + for (int q = 0; q < i - 1; q++) { mas[q]++; } + } + } + int sum = 0; + for (int q = 0; q < n; q++) { + if (mas[q] == m) { sum++; } + } + if (sum > 0) { + cout << sum << endl; + } else { + cout << "-1" << endl; + } +} +double n, m, ans; +int main() { + while (cin >> n >> m) { + int maxi = n; + if (m > maxi) { + cout << -1 << endl; + continue; + } + int mini = ceil(n / 2); + mini = ceil(mini / m); + int i = m * mini; + cout << i << endl; + } + return 0; +} +const char b[6] = {'a', 'e', 'i', 'o', 'u', 'y'}; +const int N = 102; +int n; +char a[N]; +bool stg(char t) { + for (int i = 0; i < 6; ++i) { + if (b[i] == t) return true; + } + return false; +} +int main() { + cin >> n; + cin >> a; + for (int i = 0; i < n; ++i) { + if (i && stg(a[i]) && stg(a[i - 1])) continue; + cout << a[i]; + } + cout << endl; + return 0; +} +bool check(int l, int r, string s) { + bool ok = true; + int len = r - l + 1; + for (int i = 0; i < len / 2; ++i) { + if (s[l + i] != s[r - i]) { ok = false; } + } + return ok; +} +int main() { + string s; + cin >> s; + if (!check(0, s.size() - 1, s)) { + cout << s.size() << endl; + return 0; + } + int res = 0; + for (int l = 0; l < s.size(); ++l) { + for (int r = l; r < s.size(); ++r) { + if (!check(l, r, s)) { res = max(res, r - l + 1); } + } + } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + char a[n]; + int d = 0; + int a1 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'D') { + d++; + } else if (a[i] == 'A') { + a1++; + } + } + if (a1 > d) { + cout << "Anton" << endl; + } else if (a1 < d) { + cout << "Danik" << endl; + } else if (a1 == d) { + cout << "Friendship" << endl; + } +} +int main() { + string s; + cin >> s; + int k; + cin >> k; + int ans = 0; + for (int i = 0; i < k; i++) { + string a; + cin >> a; + int l = 0, r = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] != a[0] && s[i] != a[1]) { + ans += min(l, r); + l = 0, r = 0; + } else + l += (s[i] == a[0]), r += (s[i] == a[1]); + } + ans += min(l, r); + } + cout << ans << endl; +} +int main() { + int n, m, temp; + cin >> n >> m; + vector visit1(n, false), visit2(m, false); + for (int i = 0; i < n; i++) { + cin >> temp; + visit1[temp] = true; + } + for (int i = 0; i < m; i++) { + cin >> temp; + visit2[temp] = true; + } + for (int i = 1; i < 100; i++) { + temp = i % 10; + int temp2 = (i / 10) % 10; + if ((visit1[temp] || visit1[temp2]) && (visit2[temp] || visit2[temp2])) { + cout << i << '\n'; + break; + } + } + return 0; +} +int main() { + long long n, m, i, l = 1, r; + cin >> n >> m; + r = n; + for (i = 0; i < m; i++) { + string a, b, c, d; + long long x; + cin >> a >> b >> c >> d >> x; + if (c == "left") + r = min(x - 1, r); + else + l = max(l, x + 1); + } + if (l > r) + cout << -1 << endl; + else + cout << r - l + 1 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) cout << "1 " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " 1" << endl; + return 0; +} +int main() { + int a, k, r, m, n, b, d; + char s; + cin >> n >> m >> k; + a = k % (2 * m); + if (a == 0) { + r = k / (2 * m); + d = m; + } else { + r = k / (2 * m) + 1; + b = a % 2; + if (b == 0) + d = a / 2; + else + d = a / 2 + 1; + } + if (k % 2 == 0) + s = 'R'; + else + s = 'L'; + cout << r << " " << d << " " << s << endl; + return 0; +} +long long int n; +long long int s[300009]; +long long int d[300009]; +map mp; +int main() { + cin >> n; + for (long long int i = 0; i < n; i++) cin >> s[i] >> d[i]; + long long int maxi = 1; + for (long long int i = 0; i < n; i++) { + maxi = max(maxi, s[i]); + while ((maxi - s[i]) % d[i] != 0) { maxi++; } + if (i != n - 1) maxi++; + } + cout << maxi << "\n"; +} +int main() { + long long int a, b, x, y, z, c, d, sum; + cin >> a >> b; + cin >> x >> y >> z; + x = x * 2 + y; + z = z * 3 + y; + if (a > x) + c = 0; + else + c = x - a; + if (b > z) + d = 0; + else + d = z - b; + cout << c + d << endl; + return 0; +} +const int maxn = 2e3 + 200; +int vis[maxn]; +int num[maxn]; +int n; +int dfs(int x) { + if (num[x] == 0 && vis[x] == -1) { + return 1; + } else if (num[x]) { + return num[x]; + } + return num[x] = dfs(vis[x]) + 1; +} +int main() { + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + for (int i = 1; i <= n; i++) { + int u; + cin >> u; + vis[i] = u; + } + for (int i = 1; i <= n; i++) num[i] = dfs(i); + int Max = 0; + for (int i = 1; i <= n; i++) Max = max(Max, num[i]); + cout << Max << endl; + } + return 0; +} +int main() { + int i, j, n, t, a, b, c; + int sumx = 0, sumy = 0, sumz = 0; + cin >> t; + for (i = 0; i < t; i++) { + cin >> a >> b >> c; + sumx = sumx + a; + sumz = sumz + b; + sumy = sumy + c; + } + if (sumx == 0 && sumy == 0 && sumz == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + cout << 3 * min(min(b + 1, r), y + 2) - 3 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k = 0; + while (1) { + if (n > m) { + break; + } else { + k++; + n = n * 3; + m = m * 2; + } + } + cout << k << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int count = 0; + while (a >= 1 && b >= 2 && c >= 4) { + a--; + b -= 2; + c -= 4; + count++; + } + cout << count * 7 << endl; + return 0; +} +const int N = 105; +int num[N]; +int main() { + int n; + cin >> n; + for (int i = int(0); i < int(n); ++i) cin >> num[i]; + int mn = INT_MAX; + for (int i = int(0); i < int(n); ++i) { + int ans = 0; + for (int j = int(0); j < int(num[i]); ++j) { + int k; + cin >> k; + ans += k * 5; + } + ans += 15 * num[i]; + mn = min(mn, ans); + } + cout << mn << endl; + return 0; +} +int main() { + int n = 0; + cin >> n; + string input; + cin >> input; + int counter = 0; + for (int i = 0; i < n - 1; i++) { + if (input[i] == input[i + 1]) counter++; + } + cout << counter << endl; + return 0; +} +int a[10000]; +int gcd(int x, int y) { + return y ? gcd(y, x % y) : x; +} +int main() { + int n; + cin >> n; + int len = 9999999; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + int ans = a[i]; + for (int j = i; j < n; j++) { + ans = gcd(ans, a[j]); + if (ans == 1) { + len = min(len, j - i + 1); + break; + } + } + } + if (len == 9999999) + cout << -1 << endl; + else { + int ans = 0; + for (int i = 0; i < n; i++) + if (a[i] == 1) ans++; + if (ans) + cout << n - ans << endl; + else + cout << len - 2 + n << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = min(a, min(b / 2, c / 4)); + cout << 7 * x << endl; + return 0; +} +vector v[2003]; +int lvl = 1; +int vis[2003]; +void bfs(int a) { + queue q; + q.push(a); + vis[a] = 1; + while (!q.empty()) { + a = q.front(); + q.pop(); + for (int i = 0; i < v[a].size(); ++i) { + if (!vis[v[a][i]]) { + q.push(v[a][i]); + vis[v[a][i]] = vis[a] + 1; + lvl = max(lvl, vis[v[a][i]]); + } + } + } +} +int main() { + int n; + cin >> n; + vector par; + for (int i = 1; i <= n; ++i) { + int a; + cin >> a; + if (a != -1) + v[a].push_back(i); + else + par.push_back(i); + } + for (int i = 0; i < par.size(); ++i) bfs(par[i]); + cout << lvl << endl; +} +int main() { + int n; + cin >> n; + while (n--) { + int r; + cin >> r; + if (r == 1) { + cout << "HARD" + << "\n"; + return 0; + } + } + cout << "EASY" + << "\n"; +} +char arr[105][105]; +int main() { + int a, b; + cin >> a >> b; + int ke = 0, dari = 0; + for (int i = 1; i <= a; i++) { + int ada = 0; + for (int j = 1; j <= b; j++) { + cin >> arr[i][j]; + if (arr[i][j] == '*') { ada += 1; } + } + if (ada == 2) { + ke = i; + } else if (ada == 1) { + dari = i; + } + } + int x = 0, y; + for (int i = 1; i <= b; i++) { + if (arr[ke][i] == '*') { + if (x == 0) { + x = i; + } else + y = i; + } + } + if (arr[dari][x] == '.') { + cout << dari << " " << x << endl; + } else + cout << dari << " " << y << endl; +} +bool car(char x) { + return (x != 'a' && x != 'u' && x != 'i' && x != 'e' && x != 'o' && x != 'y'); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool hap = 0; + for (int i = 0; i < n; i++) { + if (car(s[i])) { + cout << s[i]; + hap = 0; + } else { + if (!hap) { + hap = 1; + cout << s[i]; + } + } + } + cout << endl; +} +int main() { + set s; + char c; + while (1) { + cin >> c; + if (c != '{' && c != '}' && c != ',' && c != ' ') { s.insert(c); } + if (c == '}') break; + } + int num = s.size(); + cout << num << endl; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + for (int i = r; i >= 3; i--) { + if (i <= r && i - 1 <= b && i - 2 <= y) { + cout << 3 * i - 3 << endl; + break; + } + } + return 0; +} +int isPrime(int n); +int i; +int main() { + long int n, a, b; + cin >> n; + a = 4; + b = n - 4; + for (i = 1; i <= n; i++) { + int m = isPrime(a); + int n = isPrime(b); + if (n == 1 && m == 1) { + cout << a << " " << b << endl; + return 0; + } + a++; + b--; + } +} +int isPrime(int k) { + for (i = 2; i < k; i = i + 1) { + if (k % i == 0) { return 1; } + } + return 0; +} +const long double PI = 3.141592653589793238L; +const long long N = 1000002; +int main() { + long long n; + cin >> n; + long long a[n]; + for (int i = 0; i < n; ++i) cin >> a[i]; + long long b[n]; + for (int i = 0; i < n; ++i) cin >> b[i]; + long long i = 0, j = 0; + while (true) { + if (j == n) break; + if (a[i] == b[j]) + ++i, ++j; + else + ++j; + } + cout << n - i << '\n'; + return 0; +} +void preprocess(void) { + return; +} +int main() { + cout.precision(20); + preprocess(); + int n, m, k; + cin >> n >> m >> k; + int lane = (k + 2 * m - 1) / (2 * m); + int desk = k % (2 * m); + if (desk == 0) + desk += m; + else + desk = (desk + 1) / 2; + cout << lane << " " << desk << " "; + if (k % 2) { + cout << "L" << endl; + } else + cout << "R" << endl; +} +int main() { + int n; + cin >> n; + int ans = 0; + char s[3000]; + cin >> s; + for (int i = n; i < strlen(s); i += n) + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + int a, b, c; + cin >> a >> b >> c; + long long ans; + if (a > c) { + cout << c << endl; + } else { + ans = b - (b % c) + c; + cout << ans << endl; + } + } + return 0; +} +int main() { + int a, b, c, m; + cin >> a >> b >> c; + m = min(a, min(b / 2, c / 4)); + cout << 7 * m << endl; + return 0; +} +int ans; +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (b == a) ans++; + if (c == b || c == a) ans++; + if (d == a || d == b || d == c) ans++; + cout << ans << endl; +} +int main() { + long long n, a; + cin >> n; + long long ans = 0; + for (long long i = 1; i <= n; i++) { + cin >> a; + ans += (a - 1) * i + 1; + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + long long check = n - 1; + for (long long i = 0; i < n - 1; i++) { + if (s[i] > s[i + 1]) { + check = i; + break; + } + } + for (long long i = 0; i < n; i++) + if (check != i) cout << s[i]; + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int mn = 1000000000; + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < a[i]; j++) { + int val; + cin >> val; + sum += val * 5; + } + sum += 15 * a[i]; + mn = min(mn, sum); + } + cout << mn << endl; +} +int n, m, k; +int main() { + cin >> n >> m >> k; + int l = (k + (2 * m - 1)) / (2 * m); + int d = (k - 2 * (l - 1) * m + 1) / 2; + if ((k - 2 * (l - 1) * m) % 2 == 1) + cout << l << " " << d << " L\n"; + else + cout << l << " " << d << " R\n"; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b; + cin >> c >> d; + int r = (abs(a - c)); + int p = abs(b - d); + int q = max(r, p); + cout << q << endl; + return 0; +} +int main() { + int n, z, x, y; + cin >> n >> z; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x == z || x == 7 - z || y == z || y == 7 - z) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +const double eps = 1e-8; +const double C = 0.57721566490153286060651209; +const double pi = acos(-1.0); +const int mod = 1e9 + 7; +const int maxn = 1e6 + 10; +int f[maxn], a[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + for (int i = 1; i <= n; ++i) { + int x; + cin >> x; + f[x] = i; + } + for (int i = 1; i <= n; ++i) { a[i] = f[a[i]]; } + for (int i = 1; i < n; ++i) + if (a[i] > a[i + 1]) { + cout << n - i << endl; + return 0; + } + cout << 0 << endl; + return 0; +} +const int N = 10 + 5; +int m, n, res; +char a[N][N]; +bool row[N], col[N], eaten[N][N]; +void Input() { + cin >> m >> n; + for (int i = 1; i <= m; i++) cin >> (a[i] + 1); + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == 'S') row[i] = true, col[j] = true; + } + } +} +void Solve() { + for (int i = 1; i <= m; i++) { + if (row[i] == false) { + for (int j = 1; j <= n; j++) { + if (!eaten[i][j]) eaten[i][j] = true, res++; + } + } + } + for (int j = 1; j <= n; j++) { + if (col[j] == false) { + for (int i = 1; i <= m; i++) { + if (!eaten[i][j]) eaten[i][j] = true, res++; + } + } + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + set myset; + for (int i = 0; i < 4; i++) { + int n; + cin >> n; + myset.insert(n); + } + cout << 4 - myset.size() << endl; + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3, n, shelves = 0; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + int sum1; + int sum2; + sum1 = a1 + a2 + a3; + sum2 = b1 + b2 + b3; + if (sum1 % 5 == 0) { + shelves += sum1 / 5; + } else { + shelves += (sum1 / 5) + 1; + } + if (sum2 % 10 == 0) { + shelves += (sum2 / 10); + } else { + shelves += (sum2 / 10) + 1; + } + if (shelves <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int N = 1e5; +int n; +int a[N + 5]; +long long dp[N + 5]; +int main() { + cin >> n; + for (int i = 1, u; i <= n; i++) { + cin >> u; + a[u]++; + } + dp[1] = a[1]; + dp[2] = max(2LL * a[2], dp[1]); + for (int i = 3; i <= N; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + 1LL * i * a[i]); } + cout << dp[N] << '\n'; + return 0; +} +map mpu; +vector vec; +long long q[1000006] = {}, a[1000006] = {}; +int main() { + string s, p; + cin >> s; + long long n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p; + mpu[p[0]] = p[1]; + mpu[p[1]] = p[0]; + } + n = s.size(); + int ct1 = 0, ct2 = 0, sum = 0; + for (int i = 0; i < s.size() - 1;) { + ct1 = 1; + while (s[i] == s[i + 1] && i < n - 1) { + i++; + ct1++; + } + if (mpu.find(s[i]) == mpu.end() || mpu[s[i]] != s[i + 1]) { + i++; + ct1 = 0; + ct2 = 0; + continue; + } + if (i >= n - 1) break; + char a1 = s[i], a2 = s[i + 1]; + ct2 = 1; + i += 2; + while ((s[i] == a1 || s[i] == a2) && i < n) { + if (s[i] == a1) + ct1++; + else + ct2++; + i++; + } + sum += min(ct1, ct2); + ct1 = 0; + ct2 = 0; + } + cout << sum << endl; + return 0; +} +int n; +char a[105], b[105]; +int main() { + while (cin >> n) { + for (int i = 1; i < n + 1; i++) { + cin >> a[i]; + b[i] = a[i]; + } + for (int i = 1; i < n - 1; i++) { + if (a[i] == 'o' && a[i + 1] == 'g' && a[i + 2] == 'o') { + if (b[i] == '*' || b[i] == '0') { + b[i + 1] = '0'; + b[i + 2] = '0'; + } else { + b[i] = '*'; + b[i + 1] = '*'; + b[i + 2] = '*'; + } + } + } + for (int i = 1; i < n + 1; i++) { + if (b[i] != '0') cout << b[i]; + } + cout << endl; + } + return 0; +} +int main() { + long long int number; + long long int position; + cin >> number; + cin >> position; + long long int x; + if (number % 2 == 0) { + if (position <= number / 2) { + x = (position * 2) - 1; + } else if (position > number / 2) { + x = (position - (number / 2)) * 2; + } + } else if (number % 2 == 1) { + if (position <= (number + 1) / 2) { + x = (position * 2) - 1; + } else if (position > (number + 1) / 2) { + x = (position - ((number + 1) / 2)) * 2; + } + } + cout << x << endl; +} +int main() { + int a, b = 0; + cin >> a; + char str[50]; + cin >> str; + for (int i = 0; i < a; i++) { + if (str[i] == str[i + 1]) b++; + } + cout << b << endl; + return 0; +} +int a[105], b[105], n, x, i; +int main() { + cin >> n; + cin >> x; + for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (i = 2; i <= n; i++) { + if (a[i] != x && b[i] != x && (7 - a[i]) != x && (7 - b[i]) != x) { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, d, dp[101]; + string str; + cin >> n >> d; + cin >> str; + queue q; + for (int i = 0; i < n; ++i) { + dp[i] = -1; + if (str[i] == '1') q.push(i); + } + dp[0] = 0; + for (int i = 1; i < n; ++i) { + if (str[i] == '1') { + while (q.front() < i - d) { q.pop(); } + dp[i] = (dp[q.front()] == -1) ? -1 : (dp[q.front()] + 1); + } + } + cout << dp[n - 1] << endl; +} +string bus[6]; +int main() { + int n, ch = 0; + bool check = false; + bus[0] = "+------------------------+"; + bus[5] = "+------------------------+"; + bus[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + bus[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + bus[3] = "|#.......................|"; + bus[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + cin >> n; + for (int i = 1; i < 22; i++) { + for (int j = 1; j < 5; j++) { + if (ch == n) { + check = true; + break; + } + if (bus[j][i] == '#') { + bus[j][i] = 'O'; + ch++; + } + } + if (check == true) break; + } + for (int i = 0; i < 6; i++) cout << bus[i] << endl; + return 0; +} +int main() { + long long n; + long long a, b, c; + cin >> n >> a >> b >> c; + long long data1, data2, data3; + if (n % 4 == 0) + cout << "0" << endl; + else { + int x = 4 - n % 4; + if (x == 1) { + if (a < b + c) + data1 = a; + else + data1 = b + c; + if (data1 > 3 * c) data1 = 3 * c; + cout << data1 << endl; + } + if (x == 2) { + if (b > 2 * c) + data2 = 2 * c; + else + data2 = b; + if (data2 > 2 * a) data2 = 2 * a; + if (data2 > c + 3 * a) data2 = c + 3 * a; + cout << data2 << endl; + } + if (x == 3) { + if (c < a + b) + data3 = c; + else + data3 = a + b; + if (data3 > 3 * a) data3 = 3 * a; + cout << data3 << endl; + } + } + return 0; +} +int a[30]; +char s[5010]; +int main() { + int len = 5000; + gets(s); + int ans = 0; + for (int i = 0; i < len; i++) { + if (s[i] >= 'a' && s[i] <= 'z') { a[s[i] - 'a'] = 1; } + } + for (int i = 0; i < 26; i++) { + if (a[i]) ans++; + } + cout << ans << endl; +} +const long long INF = 1e18; +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n, pos = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int l = 0, r = n - 1; + while (arr[l] < arr[l + 1] && l < n - 1) l++; + while (arr[r] < arr[r - 1] && r > 0) r--; + for (int i = l; i < r; i++) { + if (arr[i] != arr[i + 1]) { + cout << "NO" + << "\n"; + return 0; + } + } + cout << "YES" + << "\n"; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k, l, co = 0; + long long n, m, t; + cin >> n >> m >> k; + l = k / (m * 2); + if (k % (m * 2)) l++; + j = k - (l - 1) * m * 2; + t = j / 2; + if (j % 2) t++; + char c; + if (k % 2) + c = 'L'; + else + c = 'R'; + cout << l << ' ' << t << ' ' << c << endl; + return 0; +} +int main() { + long long int n, ans = 0; + cin >> n; + int arr[n]; + long long int ones = 0, two = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) + ones++; + else + two++; + } + if (ones >= two) { + ans += two; + ones = ones - two; + ans += ones / 3; + } else { + ans += ones; + } + cout << ans << endl; +} +int main() { + int n, x, y, z; + cin >> n; + int x1 = 0, x2 = 0, x3 = 0; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + x1 += x; + x2 += y; + x3 += z; + } + if (x1 == 0 && x2 == 0 && x3 == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + vector dist(n); + vector fuel(n); + priority_queue q; + for (int i = 0; i < n; i++) cin >> dist[i]; + for (int i = 0; i < n; i++) cin >> fuel[i]; + int f = 0; + int t = 0; + for (int i = 0; i < n; i++) { + f += fuel[i]; + q.push(fuel[i]); + if (f < dist[i]) { + int r = dist[i] - f; + int k = r / q.top(); + k += r % q.top() > 0; + f += q.top() * k; + t += m * k; + } + f -= dist[i]; + t += dist[i]; + } + cout << t << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int sumx = 0; + int sumy = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sumx = sumx + x; + } + for (int i = 0; i < n; i++) { + int y; + cin >> y; + sumy = sumy + y; + } + if (sumy <= sumx) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int xx[20005]; +int find(int x) { + int sum = 0; + while (xx[x] != x) { + x = xx[x]; + sum++; + } + return sum; +} +int main() { + int n, a, b; + while (cin >> n) { + for (int i = 1; i <= n; i++) { + cin >> b; + if (b != -1) { xx[i] = b; } + } + int sum = 0; + for (int i = 1; i <= n; i++) { sum = max(sum, find(i)); } + cout << sum << endl; + } + return 0; +} +const int N = 1e5 + 5; +bool visited[N]; +vector ar[N]; +long long sum[N]; +long long solve(long long i) { + long long m = 0; + for (int j = 0; j < ar[i].size(); j++) { m = max(m, solve(ar[i][j])); } + return m + 1; +} +int main() { + long long n, c, m1 = 0, ar1[N], k = 0, m2 = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> c; + if (c == -1) { + ar1[k++] = i; + } else { + ar[c].push_back(i); + } + } + for (int i = 0; i < k; i++) { + sum[i] = solve(ar1[i]); + m2 = max(m2, sum[i]); + } + cout << m2 << "\n"; +} +int firstOn(int a) { + int i = 0; + while (a % 2 == 0) { + a >>= 1; + i++; + } + return i; +} +int main() { + int a = 0; + int b = 0; + int n, m; + cin >> n >> m; + int num; + for (int i = 0; i < (int)n; i++) { + cin >> num; + a = (a | (1 << num)); + } + for (int i = 0; i < (int)m; i++) { + cin >> num; + b = (b | (1 << num)); + } + int c = (a & b); + if (c) { + cout << firstOn(c) << endl; + } else { + cout << min(firstOn(a), firstOn(b)) << max(firstOn(a), firstOn(b)) << endl; + } + return 0; +} +int main() { + int a, b, st; + while (cin >> a >> b >> st) { + int x = 0, st_taken; + while (st != 0) { + st_taken = __gcd(a, st); + st = st - st_taken; + x++; + swap(a, b); + } + if (x % 2 == 1) + cout << 0 << endl; + else + cout << 1 << endl; + } +} +bool check(int x) { + int i; + for (i = 2; i <= sqrt(x); i++) { + if (x % i == 0) return true; + } + return false; +} +int main() { + long long n; + cin >> n; + long long a, b; + for (int i = 2; i <= n / 2; i++) { + b = n - i; + if (check(i) && check(b)) { + cout << i << " " << b << endl; + return 0; + } + } + return 0; +} +int a[200005], b[200005]; +int main() { + int n, i = 0; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0, t; i < n; ++i) cin >> t, b[t] = i; + for (int i = 0; i < n; ++i) a[i] = b[a[i]]; + for (i = 1; i < n; ++i) + if (a[i] < a[i - 1]) break; + cout << n - i << endl; +} +int main() { + int n, m; + cin >> n >> m; + int l; + l = (n / 2) + (n % 2); + if (m > n) + cout << "-1" << endl; + else { + for (int i = 1;; i++) { + if ((i * m) > n) { + cout << "-1" << endl; + break; + } else if ((i * m) >= l && (i * m) <= n) { + cout << (i * m) << endl; + break; + } + } + } + return 0; +} +int main() { + long long a; + map m; + for (int i = 0; i < 4; i++) { + cin >> a; + m[a]++; + } + cout << 4 - m.size() << endl; +} +int main() { + int a, b, c, d, e, f, g, h, i; + cin >> a >> b >> c; + d = a * b * c; + e = (a + b) * c; + f = a * (b + c); + g = a + b * c; + h = a * b + c; + i = a + b + c; + d = max(d, e); + d = max(d, f); + d = max(d, g); + d = max(d, h); + d = max(d, i); + cout << d << endl; + return 0; +} +int main() { + int T = 1; + while (T--) { + int a, b; + cin >> a >> b; + double d = log(b) - log(a); + d /= log(1.5); + int k = floor(d); + cout << ++k << '\n'; + } + return 0; +} +int main() { + int n, sum, index; + char s[55], a[55]; + cin >> n >> s; + sum = index = 0; + for (int i = 0;; i++) { + index += i; + if (index >= n) break; + a[sum++] = s[index]; + } + a[sum] = '\0'; + cout << a << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + char ch[1000]; + cin >> ch; + int temp = 0; + for (int i = 0; i < n; i++) { + if (ch[i] == 'o' && ch[i + 1] == 'g' && ch[i + 2] == 'o' && !temp) { + if (ch[i + 3] == 'g') { + int uu = i; + while (1) { + if (ch[i] == 'o' && ch[i + 1] == 'g' && ch[i + 2] == 'o') { + i += 2; + } else { + break; + } + } + cout << "***"; + } else { + i += 2; + cout << "***"; + } + } else { + cout << ch[i]; + } + } + cout << endl; + } + return 0; +} +long long mod = 1e9 + 7; +long long modpow(long long b, long long e) { + if (e == 0) return 1; + if (e == 1) return b; + long long res = modpow(b, e / 2); + res = (res * res) % mod; + if (e % 2 == 1) res = (res * b) % mod; + return res; +} +int main() { + string s; + cin >> s; + int n = s.size(); + long long res = 0; + for (int i = n - 1, len = 0; i >= 0; i--, len++) { + if (s[i] == '0') + res = (res * 2) % mod; + else + res = ((res * 2) % mod + modpow(2, 2 * len)) % mod; + } + cout << res << endl; + return 0; +} +int n, m, b, mod, a[501], d[501][501]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + d[0][0] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int k = a[i]; k <= b; k++) d[j][k] = (d[j][k] + d[j - 1][k - a[i]]) % mod; + int ans = 0; + for (int i = 0; i <= b; i++) ans = (ans + d[m][i]) % mod; + cout << ans << endl; + return 0; +} +int main() { + int n, m, cnt = 1; + char ch1, ch2; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> ch1; + if (ch1 == 'C' || ch1 == 'M' || ch1 == 'Y') cnt = 0; + } + } + if (cnt) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; + return 0; +} +char toUpp(char s) { + int n = s; + if (n >= 97 && n <= 122) n -= 32; + return (char)n; +} +int main() { + string s; + cin >> s; + s[0] = toUpp(s[0]); + cout << s << endl; + return 0; +} +int main() { + int p[3], i, j; + bool ok = true; + for (i = 0; i < 3; ++i) { cin >> p[i]; } + int time; + while (1) { + ok = true; + for (i = 0, j = 0;; ++i, ++j) { + if (i == 3) { + if (ok) break; + i = 0; + ok = true; + } + if (p[i] > 0) { + time = j; + ok = false; + p[i] -= 2; + } + } + if (ok) break; + } + cout << 30 + time << endl; +endapp: + return 0; +} +int main() { + int n; + cin >> n; + vector arr(n), sarr(n); + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sarr[i] = arr[i]; + } + sort(sarr.begin(), sarr.end()); + int diff = 0; + for (int i = 0; i < n; i++) + if (sarr[i] != arr[i]) diff++; + if (diff == 0 or diff == 2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + for (int i = y; i >= 1; i--) { + int ty = i; + int tb = i + 1; + int tc = i + 2; + if (tb <= b && tc <= r) { + cout << ty + tb + tc << endl; + return 0; + } + } +} +int c, v, vl, l, a; +int main() { + cin >> c >> v >> vl >> a >> l; + int s = 1; + for (int i = v; i < c;) { + v += a; + if (v > vl) v = vl; + i -= l; + i += v; + s++; + } + cout << s << endl; +} +int gum(int x) { + int s = 0; + double k = 0; + int d; + while (x != 0) { + d = x % 10; + if (d == 0) { + x /= 10; + continue; + } else { + s += (int)d * pow(10, k); + x /= 10; + } + k++; + } + return s; +} +int main() { + double x, y; + pair p[10000]; + char s[320][320]; + bool q = false; + int sum = 0; + unsigned long long t; + int a, b, c; + int i, j, m, n; + double d, L, v1, v2; + cin >> a >> b; + c = a + b; + if (gum(a) + gum(b) == gum(c)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a[100005], c, d, e = 0; + long long f = 0; + cin >> c; + for (int i = 0; i < c; i++) { + cin >> d; + f += d; + if (d % 2 == 1) { + a[e] = d; + e++; + } + } + sort(a, a + e); + if (e % 2 == 0) { + cout << f << endl; + } else { + cout << f - a[0] << endl; + } +} +int main() { + long int n, top, a, b; + cin >> n >> top; + bool condition = true; + for (long int i = 0; i < n; i++) { + cin >> a >> b; + if ((7 - a) == top || 7 - b == top || top == a || top == b) condition = false; + } + if (condition == false) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + int n, cnt = 0, i, j, k; + string s, s1; + pair p; + cin >> n >> s; + int len = s.length(); + for (i = 0; i < len; i++) { + for (j = 1; j <= len - i; j++) { + s1 = s.substr(i, j); + p = {0, 0}; + for (k = 0; k < j; k++) { + if (s1[k] == 'U') { + p.first++; + } else if (s1[k] == 'D') { + p.first--; + } else if (s1[k] == 'R') { + p.second--; + } else if (s1[k] == 'L') { + p.second++; + } + } + if (p.first == 0 && p.second == 0) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + while (n--) { + int s, f, t; + cin >> s >> f >> t; + if (s == f) + cout << t << endl; + else if (s < f) { + int tim = t / (2 * m - 2) * (2 * m - 2); + if (tim + s - 1 < t) tim += 2 * m - 2; + tim += f - 1; + cout << tim << endl; + } else { + int tim = t / (2 * m - 2) * (2 * m - 2); + tim += m - 1; + if (tim + m - s < t) tim += 2 * m - 2; + tim += m - f; + cout << tim << endl; + } + } + return 0; +} +long long n; +string s; +bool flag; +bool isvowel(char c) { + return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); +} +int main() { + cin >> n; + cin.ignore(); + cin >> s; + flag = true; + while (flag) { + flag = false; + string t = ""; + t = t + s[0]; + for (int i = 1; i <= s.length() - 1; i++) + if (!isvowel(s[i]) || !isvowel(s[i - 1])) { t = t + s[i]; } + s = t; + } + cout << s << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a <= b) { + cout << "Second" << endl; + } else if (a > b) { + cout << "First" << endl; + } +} +int main() { + int n; + cin >> n; + char ch; + int counter_A = 0; + int counter_D = 0; + while (n > 0) { + cin >> ch; + if (ch == 'A') + counter_A++; + else + counter_D++; + n--; + } + if (counter_A > counter_D) + cout << "Anton\n"; + else if (counter_D > counter_A) + cout << "Danik\n"; + else + cout << "Friendship\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int a[26] = {}; + for (int i = 0; i < n; i++) { a[s[i] - 'A']++; } + int min = INT_MAX; + for (int i = 0; i < k; i++) { + if (a[i] < min) min = a[i]; + } + cout << k * min << endl; +} +int recurse(string s, int n, int d, int i, int dp[]) { + for (int i = 1; i < n; i++) { + if (s[i] == '1') { + for (int j = i - 1; j >= max(0, i - d); j--) { + if (s[j] == '1') { + if (dp[j] == INT_MAX) { + dp[i] = min(dp[j], dp[i]); + } else { + dp[i] = min(dp[j] + 1, dp[i]); + } + } + } + } + } + return dp[n - 1]; +} +int main() { + int n, d; + cin >> n >> d; + string s; + int dp[n]; + for (int i = 0; i < n; i++) { dp[i] = INT_MAX; } + dp[0] = 0; + cin >> s; + int ans = recurse(s, n, d, 0, dp); + if (ans == INT_MAX) { + cout << -1 << endl; + } else { + cout << ans << endl; + } +} +const int N = 2e5 + 5; +int n, m, s[N], t[N], p[N], a[N], taken[N]; +void Input() { + string t1, t2; + cin >> t1 >> t2; + n = t1.size(), m = t2.size(); + for (int i = 0; i < n; i++) s[i + 1] = t1[i] - 48 * 2; + for (int i = 0; i < m; i++) t[i + 1] = t2[i] - 48 * 2; + for (int i = 1; i <= n; i++) cin >> a[i]; +} +bool check(int moves_so_far) { + for (int i = 1; i <= n; i++) p[i] = a[i]; + sort(p + moves_so_far + 1, p + n + 1); + for (int i = moves_so_far + 1; i <= n; i++) p[i] = s[p[i]]; + int curr = 1; + for (int i = moves_so_far + 1; i <= n; i++) { + if (t[curr] == p[i]) curr++; + if (curr > m) return false; + } + return true; +} +void Solve() { + int l = 1, r = n - m, res = 0; + while (l <= r) { + int mid = (l + r) / 2; + if (check(mid) == true) + r = mid - 1; + else + res = mid, l = mid + 1; + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +long long int arr[100001] = {0}; +long long int brr[100001] = {0}; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + arr[x]++; + } + for (long long int i = 1; i < 100001; i++) { + brr[i] = i * arr[i]; + if (i >= 2) brr[i] += brr[i - 2]; + if (brr[i - 1] > brr[i]) brr[i] = brr[i - 1]; + } + cout << brr[100000] << endl; +} +int main() { + long long n; + cin >> n; + if ((n + 1) % 2 == 0) { + cout << (n + 1) / 2 << endl; + } else { + if (n == 0) { + cout << 0 << endl; + } else { + cout << n + 1 << endl; + } + } +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; ++i) { cout << " " << i; } + cout << endl; + return 0; +} +int main() { + int m, n, b, modd, a[505]; + cin >> n >> m >> b >> modd; + for (int i = 1; i <= n; i++) cin >> a[i]; + int d[505][505]; + memset(d, 0, sizeof(d)); + d[0][0] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int k = a[i]; k <= b; k++) { + d[j][k] += d[j - 1][k - a[i]]; + d[j][k] %= modd; + } + int ans = 0; + for (int i = 0; i <= b; i++) ans = (ans + d[m][i]) % modd; + cout << ans << endl; + return 0; +} +int main() { + int m; + int n; + int sum = 10000000; + cin >> n; + int shit = 0; + int k[100]; + for (int i = 0; i < n; i++) { cin >> k[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < k[i]; j++) { + cin >> m; + shit += (m * 5 + 15); + } + sum = min(sum, shit); + shit = 0; + } + cout << sum << endl; +} +int n; +int gcd(int a, int b) { + if (!b) + return a; + else + return gcd(b, a % b); +} +int findstep(int *a, int *b, int t) { + if (t == n) return -1; + for (int i = 0; i < n - t; i++) { + b[i] = gcd(a[i], a[i + 1]); + if (b[i] == 1) return t; + } + return findstep(b, a, t + 1); +} +int main() { + int book = 0; + int a[2005], b[2005]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) book++; + } + if (book) { + cout << n - book << endl; + return 0; + } + int ans = findstep(a, b, 1); + if (ans == -1) + cout << -1 << endl; + else + cout << n - 1 + ans << endl; + return 0; +} +int main() { + int n, ud, lr, ans = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; ++i) { + ud = lr = 0; + for (int j = i; j < n; ++j) { + ud += s[j] == 'U' ? 1 : s[j] == 'D' ? -1 : 0; + lr += s[j] == 'R' ? 1 : s[j] == 'L' ? -1 : 0; + ans += ud == 0 && lr == 0; + } + } + cout << ans << "\n"; +} +int main() { + int n, m, fl = 0; + char c; + cin >> n >> m; + for (int i = 0; i < m * n; i++) { + cin >> c; + if (c != 'W' && c != 'B' && c != 'G') fl++; + if (fl > 0) { + cout << "#Color" << endl; + return 0; + } + } + cout << "#Black&White" << endl; + return 0; +} +long long int a[10000000] = {0}; +int main() { + long long int x, y, k = 0, i; + cin >> x >> y; + for (i = 1; i * i < x; i++) { + if (x % i == 0) { + a[k] = i; + k++; + a[k] = x / i; + k++; + } + } + if (i * i == x) { + a[k] = i; + k++; + } + if (k < y) { + cout << "-1\n"; + } else { + sort(a, a + k); + cout << a[y - 1] << endl; + } +} +int main() { + int n, m, k, i, a, sum = 0; + cin >> n >> m >> k; + a = m * 2; + for (i = 1;; i++) { + sum += a; + if (k < sum) { + cout << i << ' '; + break; + } else if (k == sum) { + cout << i << ' ' << m << ' ' << "R" << endl; + return 0; + } + } + sum -= a; + a = k - sum; + if (a % 2 == 1) { + a /= 2; + cout << a + 1 << ' ' << "L" << endl; + } else if (a % 2 == 0) { + a /= 2; + cout << a << ' ' << "R" << endl; + } + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3, n; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + int total_shelf_cup = ((a1 + a2 + a3) / 5); + if ((a1 + a2 + a3) % 5 != 0) { total_shelf_cup += 1; } + int total_shelf_medal = ((b1 + b2 + b3) / 10); + if ((b1 + b2 + b3) % 10 != 0) { total_shelf_medal += 1; } + if (total_shelf_medal + total_shelf_cup <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + string s; + cin >> s; + int l1 = s.length(); + bool vertikal = 0, horizontal = 0; + for (int i = 0; i < l1; i++) { + if (s[i] == '0') { + if (vertikal) { + vertikal = 0; + cout << "3 1\n"; + } else { + vertikal = 1; + cout << "1 1\n"; + } + } else { + if (horizontal) { + horizontal = 0; + cout << "4 1\n"; + } else { + horizontal = 1; + cout << "4 3\n"; + } + } + } +} +set a, b; +int r, c; +char cake; +int main() { + cin >> r >> c; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> cake; + if (cake == 'S') { + a.insert(i); + b.insert(j); + } + } + } + cout << r * c - a.size() * b.size() << "\n"; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int ans = 0; + int now = 1; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + while (now + x <= a) now += x; + ans += b - now + 1; + now = b + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n > 0) { + int a, b, c; + cin >> a >> b >> c; + if (c < a) { + cout << c << endl; + } else { + cout << ((b / c) + 1) * c << endl; + } + n--; + } + return 0; +} +int main() { + int a[100010], b[100010]; + int n, num = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(a, a + n); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) num++; + } + if (num > 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n; + cin >> n; + int t1, l1, t2, l2, f1, f2; + cin >> t1; + l1 = 7 - t1; + bool ans = true; + for (int i = 0; i < n; i++) { + cin >> f1 >> f2; + if (i == 0) { + if (f1 == l1 || 7 - f1 == l1 || f2 == l1 || 7 - f2 == l1) { + for (int g = 1; g <= 6; g++) { + if (g != f1 && g != f2 && g != 7 - f1 && g != 7 - f2) { + l2 = g; + t2 = 7 - g; + break; + } + } + } else { + l2 = l1; + t2 = 7 - l1; + } + } else if (l2 == f1 || l2 == 7 - f1 || t2 == f1 || t2 == 7 - f1) { + ans = false; + break; + } else if (l2 == f2 || l2 == 7 - f2 || t2 == f2 || t2 == 7 - f2) { + ans = false; + break; + } else { + for (int g = 1; g <= 6; g++) + if (g != f1 && g != f2 && g != 7 - f1 && g != 7 - f2) { + l2 = g; + t2 = 7 - g; + break; + } + } + } + if (!ans) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + int n, d, s = 0, i = 0; + char a[105]; + cin >> n >> d; + cin >> a; + while (i < n - 1) { + if (a[i + d] == '1') { + s++; + i = i + d; + } else { + int j = i + d - 1; + bool f = true; + while (j > i) { + if (a[j] == '1') { + i = j; + s++; + f = false; + break; + } else + j--; + } + if (f == true) { + s = -1; + break; + } + } + } + cout << s << endl; + return 0; +} +int main() { + int a, b, c, mina, minb, minc, minn; + cin >> a >> b >> c; + mina = a; + minb = b / 2; + minc = c / 4; + minn = min(min(mina, minb), minc); + cout << 7 * minn << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[n]; + int minn = 1000; + int x; + for (int i = 0; i < n; i++) { cin >> a[i]; } + m--; + for (int j = m + 1; j < n; j++) { + if (a[j] && a[j] <= k) { + x = (j - m) * 10; + if (x < minn) minn = x; + break; + } + } + for (int j = m - 1; j >= 0; j--) { + if (a[j] && a[j] <= k) { + x = (m - j) * 10; + if (x < minn) minn = x; + break; + } + } + cout << minn << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + long long one = 0, two = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 1) + one++; + else + two++; + } + if (one == 0) + cout << 0 << endl; + else { + long long mi = min(one, two); + long long ans = 0; + ans += mi; + if (mi < one) { + one -= mi; + ans += one / 3; + } + cout << ans << endl; + } + return 0; +} +const int N = 1e5 + 7; +const int xinc[] = {0, 0, 1, -1}; +const int yinc[] = {1, -1, 0, 0}; +const long double PI = 3.141592653589793; +int x; +void solve() { + cin >> x; + if (x == 3) { + cout << 5 << '\n'; + return; + } + for (int i = 1;; i += 2) { + int mi = (i / 2) * (i / 2) + ((i + 1) / 2) * ((i + 1) / 2); + if (x <= mi) { + cout << i << '\n'; + return; + } + } +} +int main() { + int t; + t = 1; + while (t--) solve(); + return 0; +} +const long long MAXN = 1000 * 100; +long long arr[MAXN + 10], ans[MAXN + 10]; +int main() { + long long n; + cin >> n; + long long maxi = 0; + for (long long i = 0; i < n; i++) { + long long a; + cin >> a; + arr[a]++; + maxi = max(a, maxi); + } + ans[1] = arr[1]; + for (long long i = 2; i <= maxi; i++) ans[i] = max(ans[i - 1], ans[i - 2] + arr[i] * i); + cout << ans[maxi] << endl; + return 0; +} +long long int T, n; +int a[100010 + 5]; +long long int M = 1e9 + 7; +int main() { + cin >> n; + n %= 4; + if (n == 0 || n == 3) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +const long long M = 3e10 + 1; +int main() { + long long n, a, b, c, n2; + long long i, j, k, sum = 0, min = M; + cin >> n >> a >> b >> c; + if (n % 4 == 0) { + cout << "0" << endl; + return 0; + } + n = 4 - n % 4; + n2 = n; + while (n <= n2 + 10) { + for (i = 0; i <= n / 3; i++) { + for (j = 0; j <= n - 3 * i; j++) { + k = n - 3 * i - 2 * j; + if (k < 0) continue; + sum = i * c + j * b + k * a; + if (sum < min) min = sum; + } + } + n += 4; + } + cout << min << endl; + return 0; +} +int main() { + char a[60]; + cin >> a; + int i; + int sum = 0; + for (i = 0; i < strlen(a); i++) { + if (a[i] != a[strlen(a) - 1 - i]) break; + } + if (i == strlen(a)) { + int k = 1; + while (k != strlen(a)) { + for (i = k; i < strlen(a); i++) { + if (a[i] != a[strlen(a) - 1 - i + k]) break; + } + if (i != strlen(a)) break; + k++; + } + cout << strlen(a) - k << endl; + } else + cout << strlen(a) << endl; + return 0; +} +int main() { + int n, m, x; + cin >> n >> m; + if (n < m) { + cout << "-1" << endl; + return 0; + } + for (x = (int)((double)n / 2 + 0.5); x <= n; ++x) { + if (x % m == 0) { + cout << x << endl; + return 0; + } + } + cout << "-1" << endl; + return 0; +} +int main() { + int n; + int min = 2147483647; + cin >> n; + int arr[101]; + for (int i = 0; i < n; ++i) cin >> arr[i]; + for (int i = 0; i < n; ++i) { + int sum = 0; + for (int j = 0; j < arr[i]; ++j) { + int in; + cin >> in; + sum += (5 * in) + 15; + } + if (sum < min) min = sum; + } + cout << min << endl; +} +int main() { + int n, i, t1, t2; + string a; + getline(cin, a); + if (a[0] > 96 && a[0] < 123) a[0] -= 32; + cout << a << endl; +} +map myMap; +int main() { + int n, i, flag = 0; + string s; + s = s + '-' + '-'; + cin >> n >> s; + for (i = 0; i < n; i++) { + while (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + cout << "***"; + i += 3; + while (s[i] == 'g' && s[i + 1] == 'o') { i += 2; } + } + if (i >= n) { break; } + cout << s[i]; + } + cout << endl; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c; + n = c / a; + while (n >= 0) { + if ((c - n * a) % b == 0) { + cout << "Yes" << endl; + return 0; + } else + n--; + } + cout << "No" << endl; + return 0; +} +long long a, b, x, y, z, na, nb, zer = 0; +int main() { + cin >> a >> b >> x >> y >> z; + na = x * 2 + y; + nb = z * 3 + y; + cout << max(max(na - a, zer) + max(nb - b, zer), zer) << '\n'; +} +const int maxn = 2010; +const int inf = 0x3f3f3f3f; +int num[maxn]; +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n; + while (cin >> n) { + int cnt_1 = 0; + int ans = inf; + for (int i = 0; i < n; i++) { + cin >> num[i]; + if (num[i] == 1) cnt_1++; + } + if (cnt_1) { + cout << n - cnt_1 << endl; + } else { + for (int i = 0; i < n; i++) { + int x = num[i]; + for (int j = i + 1; j < n; j++) { + x = gcd(x, num[j]); + if (x == 1) { ans = min(ans, j - i); } + } + } + if (ans == inf) + cout << -1 << endl; + else + cout << ans + n - 1 << endl; + } + } +} +int row[15]; +int col[15]; +int main() { + int r, c; + cin >> r >> c; + for (int i = 0; i < r; i++) { + string x; + cin >> x; + for (int j = 0; j < c; j++) { + if (x[j] == 'S') { + row[i] = 1; + col[j] = 1; + } + } + } + int noteaten_r = 0; + int noteaten_c = 0; + for (int i = 0; i < r; i++) { noteaten_r += row[i]; } + for (int i = 0; i < c; i++) { noteaten_c += col[i]; } + cout << r * c - noteaten_r * noteaten_c << endl; +} +int dep[2005]; +vector boss; +vector graph[2005]; +void dfs(int u, int p) { + dep[u] = dep[p] + 1; + for (int i = 0; i < graph[u].size(); i++) { + if (!dep[graph[u][i]]) dfs(graph[u][i], u); + } +} +int main() { + memset(dep, 0, sizeof(dep)); + int n, v; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> v; + if (v != -1) + graph[v].push_back(i); + else + boss.push_back(i); + } + for (int i = 0; i < boss.size(); i++) dfs(boss[i], boss[i]); + int maxn = 0; + for (int i = 1; i <= n; i++) maxn = max(maxn, dep[i]); + cout << maxn << endl; + return 0; +} +int main() { + string d; + int c = 0; + cin >> d; + while (d.find("Danil") < d.size()) { + c++; + int x = d.find("Danil"); + d[x] = '?'; + d[x + 1] = '?'; + d[x + 2] = '?'; + d[x + 3] = '?'; + d[x + 4] = '?'; + } + while (d.find("Olya") < d.size()) { + c++; + int x = d.find("Olya"); + d[x] = '?'; + d[x + 1] = '?'; + d[x + 2] = '?'; + d[x + 3] = '?'; + } + while (d.find("Slava") < d.size()) { + c++; + int x = d.find("Slava"); + d[x] = '?'; + d[x + 1] = '?'; + d[x + 2] = '?'; + d[x + 3] = '?'; + d[x + 4] = '?'; + } + while (d.find("Ann") < d.size()) { + c++; + int x = d.find("Ann"); + d[x] = '?'; + d[x + 1] = '?'; + d[x + 2] = '?'; + } + while (d.find("Nikita") < d.size()) { + c++; + int x = d.find("Nikita"); + d[x] = '?'; + d[x + 1] = '?'; + d[x + 2] = '?'; + d[x + 3] = '?'; + d[x + 4] = '?'; + d[x + 5] = '?'; + } + if (c == 1) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + string s; + cin >> s; + int contiguous = 1; + for (size_t i = 1; i < s.length(); ++i) { + if (s[i] == s[i - 1]) { + contiguous += 1; + if (contiguous == 7) { + cout << "YES" << endl; + return 0; + } + } else { + contiguous = 1; + } + } + cout << "NO" << endl; + return 0; +} +string lexMaxSubseq(const string &s) { + string answ; + const int n = (int)s.size(); + vector next(n, n - 1); + char max = *max_element(s.begin(), s.end()); + for (int i = n - 2; i >= 0; --i) { + if (s[i + 1] >= s[next[i + 1]]) { + next[i] = i + 1; + } else { + next[i] = next[i + 1]; + } + } + int curr = 0; + if (s[0] != max) { curr = next[0]; } + while (true) { + answ += s[curr]; + int prev = curr; + curr = next[curr]; + if (curr == prev) { break; } + } + return answ; +} +int main() { + string s; + while (cin >> s) { cout << lexMaxSubseq(s) << endl; } + return 0; +} +int fa[2005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fa[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + int tmp = 0; + for (int j = i; j <= n && j != -1; j = fa[j]) { tmp++; } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c, d, e, f; + cin >> a >> b >> c; + cin >> d >> e >> f; + cin >> n; + int p = a + b + c; + int q = d + e + f; + int r, s; + if (p % 5 == 0) + r = p / 5; + else + r = (p / 5) + 1; + if (q % 10 == 0) + s = q / 10; + else + s = (q / 10) + 1; + if (r + s <= n) + cout << "YES\n"; + else + cout << "NO\n"; +} +int a[100010]; +int main() { + int n, m; + while (cin >> n >> m) { + int flag = 1; + for (int i = (n + 1) / 2; i <= n; i++) { + if (i % m == 0) { + flag = 0; + cout << i << endl; + break; + } + } + if (flag) cout << -1 << endl; + } + return 0; +} +int main() { + int n, mx = -1e9; + string ans; + cin >> n; + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + int a, b, cur = 0; + cin >> a >> b; + cur += 100 * a - 50 * b; + for (int j = 0; j < 5; ++j) { + int k; + cin >> k; + cur += k; + } + if (mx < cur) { + mx = cur; + ans = s; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud\n"; + else + cout << "Ehab\n"; +} +int main() { + int n, x; + long long res = 0; + cin >> n; + vector v; + for (int i = 0; i < n; ++i) { + cin >> x; + if ((x & 1) == 0) { + res += x; + } else { + v.push_back(x); + } + } + sort(v.begin(), v.end()); + for (int i = ((v.size() & 1) == 0 ? 0 : 1); i < v.size(); ++i) { res += v[i]; } + cout << res << endl; + return 0; +} +int main() { + long long a, b, sum = 0; + cin >> a >> b; + for (long long i = 0; i <= 10000000000; i++) { + a *= 3; + b *= 2; + sum++; + if (a > b) break; + } + cout << sum << endl; + return 0; +} +int main() { + string s; + cin >> s; + int o = 0, z = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '0') { + o++; + if (o % 2) + cout << 1 << " " << 1 << endl; + else + cout << 3 << " " << 1 << endl; + } else if (s[i] == '1') { + z++; + if (z % 2) + cout << 4 << " " << 3 << endl; + else + cout << 4 << " " << 1 << endl; + } + } +} +long long int inf = 1e14; +long long int mod = 1e9 + 7; +char en = '\n'; +int main() { + long long int x; + cin >> x; + for (long long int i = 1;; i++) { + if ((i * i + 1) / 2 < x) continue; + if (i & 1) { + if (i == 3) { + if (x == 3) + continue; + else { + cout << i << en; + return 0; + } + } else { + cout << i << en; + return 0; + } + } else { + if (x % 4 != 0) continue; + long long int temp = x / 4; + long long int curr = i / 2 - 1; + long long int first1 = floor(curr / 2.0); + long long int second1 = ceil(curr / 2.0); + long long int total = second1 * second1 + first1 * first1; + if (total >= temp) { + cout << i << en; + return 0; + } + } + } + return 0; +} +const int MAX_N = 100 + 10; +char a[MAX_N][MAX_N]; +pair p[10], pp[10]; +int main() { + int n, m, x = 0, x1 = 200, y1 = 200, x2 = 0, y2 = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '*') { + p[x].first = i; + p[x].second = j; + x1 = min(x1, i); + x2 = max(x2, i); + y1 = min(y1, j); + y2 = max(y2, j); + x++; + } + } + sort(p, p + 3); + pp[0] = make_pair(x1, y1); + pp[1] = make_pair(x1, y2); + pp[2] = make_pair(x2, y1); + pp[3] = make_pair(x2, y2); + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (p[i] != pp[i]) { + cout << pp[i].first + 1 << " " << pp[i].second + 1 << endl; + return 0; + } + cout << pp[3].first + 1 << " " << pp[3].second + 1 << endl; + return 0; +} +int main() { + int t, a, b; + while (cin >> t >> a) { + if (a > t) { + b = -1; + } else { + if (t % 2 == 0) + b = t / 2; + else + b = (t / 2) + 1; + while (b % a != 0) { b++; } + } + cout << b << endl; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + cout << max(abs(a - c), abs(d - b)) << endl; +} +int main() { + long long int min, a, b, c, n, m; + cin >> m >> a >> b >> c; + n = m % 4; + if (n == 0) + min = 0; + else if (n == 1) { + min = 3 * a; + if (min > c) min = c; + if (min > a + b) min = a + b; + if (min > 2 * b + c) min = 2 * b + c; + if (min > 2 * c + a) min = 2 * c + a; + if (min > 3 * c + b) min = 3 * c + b; + } + if (n == 2) { + min = 2 * a; + if (min > b) min = b; + if (min > 2 * c) min = 2 * c; + if (min > 3 * c + a) min = 3 * c + a; + } + if (n == 3) { + min = a; + if (min > 3 * c) min = 3 * c; + if (min > b + c) min = b + c; + } + cout << min << endl; + return 0; +} +int main() { + int tc, n; + cin >> tc; + while (tc--) { + cin >> n; + n = ceil(n / 7.); + cout << n << '\n'; + } + return 0; +} +const int N = 370; +int arr[N]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int ans, mn = 1000, j; + for (int i = 0; i < n; i++) { + int ans = 0; + j = i; + bool done = false; + while (!done) { + ans += arr[j]; + mn = min(mn, abs(ans - (360 - ans))); + j++; + if (j == n) j = 0; + if (j == i) done = true; + } + } + cout << mn << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + int ans = x / 7; + if (x % 7) ans++; + cout << ans << endl; + } +} +int main() { + string xay; + cin >> xay; + if (islower(xay[0])) { xay[0] = toupper(xay[0]); } + cout << xay << endl; +} +const int maxn = 10005; +int a[maxn]; +int b[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int cnt = 1; + for (int i = 1; i <= n; i++) b[cnt++] = a[i]; + for (int i = 1; i <= n; i++) b[cnt++] = a[i]; + int minn = 10000; + for (int i = 1; i <= cnt / 2; i++) { + int res = 0; + for (int j = i; j <= cnt; j++) { + res += b[j]; + if (res >= 180) { break; } + } + minn = min(res, minn); + } + cout << abs(360 - minn - minn) << endl; + return 0; +} +const long long modulo = 1000000007; +long long mod(long long x, long long m = modulo) { + x %= m; + x += m; + x %= m; + return x; +} +long long power(long long x, long long a) { + x = mod(x); + a = mod(a, modulo - 1); + long long ret = 1; + long long k = 1; + while (a) { + if ((k & a) > 0) { + a ^= k; + ret = mod(ret * x); + } + k <<= 1; + x = mod(x * x); + } + return ret; +} +long long inv(long long x) { + return power(x, -1); +} +int main() { + long long ans = 0; + string x; + cin >> x; + reverse(x.begin(), x.end()); + for (int i = 0; i < x.size(); i++) { + if (x[i] == '1') ans += power(2, x.size() + i - 1); + ans %= modulo; + } + cout << ans << "\n"; +} +int dp[2001]; +int gcd(int a, int b) { + if (b) return gcd(b, a % b); + return a; +} +int main() { + int n, cnt = 0; + cin >> n; + int arr[n], minm = 2005, g = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) cnt++; + g = gcd(arr[i], g); + } + if (g != 1) + cout << "-1\n"; + else if (cnt) + cout << n - cnt << "\n"; + else { + for (int i = 0; i < n; i++) { + g = 0; + int l = 0; + for (int j = i; j < n; j++) { + g = gcd(g, arr[j]); + if (g == 1) break; + l++; + } + if (g == 1) minm = min(minm, l); + } + cout << n + minm - 1 << "\n"; + } + return 0; +} +int main() { + int i, cnt = 0; + char c; + string str; + getline(cin, str); + c = str[0]; + for (i = 0; i < str.size(); i++) { + if (c == str[i]) { + cnt++; + if (cnt >= 7) { break; } + } else { + cnt = 1; + c = str[i]; + } + } + if (cnt < 7) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + char a[1100]; + gets(a); + if (a[0] >= 'A' && a[0] <= 'Z') { puts(a); } + if (a[0] >= 'a' && a[0] <= 'z') { + a[0] = a[0] - 32; + puts(a); + } + return 0; +} +int main() { + string s1, s2, s3; + cin >> s1; + s2 = s1; + reverse(s1.begin(), s1.end()); + if (s1 != s2) { + cout << s2.size() << endl; + } else { + s3 = s2; + sort(s3.begin(), s3.end()); + if (s2 == s3) { + cout << "0" << endl; + } else { + cout << s3.size() - 1 << endl; + } + } +} +bool f(string s) { + string s1 = s; + reverse(s1.begin(), s1.end()); + return s1 == s; +} +int main() { + string s; + cin >> s; + long long n = s.length(); + long long so_far = 0; + for (long long i = 0; i < n - 1; i++) { + for (long long j = i + 1; j < n; j++) { + if (!f(s.substr(i, j - i + 1)) && so_far < j - i + 1) so_far = j - i + 1; + } + } + cout << so_far << endl; + return 0; +} +bool x[11][11]; +char y[11][11]; +int a, b, ans = 0; +inline void dfs() { + for (int i = 0; i < a; i++) { + bool o = 1; + for (int j = 0; j < b; j++) + if (y[i][j] == 'S') o = false; + if (o) + for (int j = 0; j < b; j++) x[i][j] = true; + } + for (int i = 0; i < b; i++) { + bool o = 1; + for (int j = 0; j < a; j++) + if (y[j][i] == 'S') o = false; + if (o) + for (int j = 0; j < a; j++) x[j][i] = true; + } +} +int main() { + cin >> a >> b; + for (int i = 0; i < a; i++) cin >> y[i]; + dfs(); + for (int i = 0; i < a; i++) + for (int j = 0; j < b; j++) + if (x[i][j]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, t = 0; + cin >> a >> b >> c; + while (a > 0 && b > 1 && c > 3) { + a -= 1; + b -= 2; + c -= 4; + t += 7; + } + cout << t << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << "+------------------------+\n"; + char arr[4][11]; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 11; j++) arr[i][j] = '#'; + for (int j = 0; j < 11; j++) { + for (int i = 0; i < 4; i++) { + if (i == 2 && j > 0) + arr[i][j] = '.'; + else if (n) { + arr[i][j] = 'O'; + n--; + } + } + } + for (int i = 0; i < 4; i++) { + cout << "|"; + for (int j = 0; j < 11; j++) { cout << arr[i][j] << "."; } + if (i == 0) + cout << "|D|)\n"; + else if (i == 1) + cout << "|.|\n"; + else if (i == 2) + cout << "..|\n"; + else + cout << "|.|)\n"; + } + cout << "+------------------------+\n"; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int a = 0; + int b = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { + a++; + } else { + b++; + } + } + if (a > b) { cout << "Anton" << endl; } + if (b > a) { cout << "Danik" << endl; } + if (a == b) { cout << "Friendship" << endl; } +} +const int maxn = 3e2 + 10; +int arr[maxn], n, p, x; +int main() { + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> x; + x %= p; + if (arr[x]) return cout << i + 1 << endl, 0; + arr[x]++; + } + cout << -1 << endl; +} +const int N = 502; +int n, m, b, M; +int a[N]; +int dpn[N][N]; +int dp[N][N]; +int main() { + cin >> n >> m >> b >> M; + for (int i = 1; i <= n; ++i) cin >> a[i]; + dpn[0][0] = 1 % M; + for (int i = 1; i <= n; ++i) { + for (int t = 0; t <= m; ++t) + for (int s = 0; s <= b; ++s) dp[t][s] = 0; + for (int t = 0; t <= m; ++t) { + for (int s = 0; s <= b; ++s) { + if (s - a[i] >= 0 && t - 1 >= 0) + dp[t][s] = (dp[t - 1][s - a[i]] + dpn[t][s]) % M; + else + dp[t][s] = dpn[t][s]; + } + } + for (int t = 0; t <= m; ++t) + for (int s = 0; s <= b; ++s) dpn[t][s] = dp[t][s]; + } + int ans = 0; + for (int s = 0; s <= b; ++s) ans = (ans + dp[m][s]) % M; + cout << ans << endl; + return 0; +} +int k, b, n, t, ans; +long long m = 1; +int main() { + cin >> k >> b >> n >> t; + while (m <= t) m = m * k + b, ans++; + if (n >= ans) + cout << n - ans + 1 << endl; + else + cout << 0 << endl; + return 0; +} +int gcd(int a, int b) { + if (a < b) + return gcd(b, a); + else + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, b, c, mcd; + cin >> a >> b >> c; + mcd = gcd(a, b); + if (c % mcd == 0) { + int k = 0; + while (a * k <= c) { + if ((c - a * k) % b == 0) { + cout << "Yes" << endl; + return 0; + } + k++; + } + } + cout << "No" << endl; + return 0; +} +long long n, m, k, maxm; +long long d[2002], s[2002]; +int main() { + cin >> m >> k; + n = m + 1; + for (long long i = 1; i <= m; i++) { cin >> d[i]; } + for (long long i = 1; i <= m; i++) { cin >> s[i]; } + long long pet = 0; + long long ans = 0; + for (long long i = 1; i <= m; i++) { + pet += s[i]; + maxm = max(maxm, s[i]); + if (pet - d[i] >= 0) { + pet -= d[i]; + ans += d[i]; + continue; + } + long long req = d[i] - pet; + long long x = req / maxm; + if (req % maxm != 0) x++; + ans += d[i]; + ans += x * k; + pet += x * maxm; + pet -= d[i]; + } + cout << ans << endl; + return 0; +} +int num[100]; +int nn[100]; +int cnt = 0; +int cc1 = 0; +bool num_find(int in) { + for (int i = 0; i < cnt; i++) { + if (num[i] == in) return true; + } + return false; +} +int main() { + int N; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> nn[cc1]; + cc1++; + } + for (int i = N - 1; i >= 0; i--) { + int tmp; + tmp = nn[i]; + if (!num_find(tmp)) { + num[cnt] = tmp; + cnt++; + } + } + cout << cnt << endl; + for (int i = cnt - 1; i > 0; i--) cout << num[i] << " "; + cout << num[0] << endl; +} +int main() { + int n, m, a, b; + cin >> n >> m >> a >> b; + if (m * a > b) { + cout << min((n / m) * b + (n % m) * a, ((n / m) + 1) * b) << endl; + return 0; + } + cout << min(n * a, ((n / m) + 1) * b) << endl; + return 0; +} +int main() { + long long n, k, sum = 0, cur = 0; + cin >> n >> k; + for (long long i = 1; i <= n; i++) { + int a; + cin >> a; + if (i > 1 && sum - (i - cur - 1) * (n - i) * a < k) { + cout << i << endl; + cur++; + } else + sum += a * (i - cur - 1); + } +} +int main() { + long long a, m; + cin >> a >> m; + long long mult = 0; + long long cnt = 0; + while (cnt < 500) { + a += (a % m); + mult += (a % m); + if (a % m == 0) { + cout << "Yes" << endl; + return 0; + } + if (mult % m == 0) { + cout << "No" << endl; + return 0; + } + cnt++; + } + cout << "No" << endl; + return 0; +} +long long arr[100005]; +int sorted[100005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sorted[i] = arr[i]; + } + sort(sorted, sorted + n); + int cnt = 0; + for (int i = 0; i < n; i++) { + if (arr[i] != sorted[i]) { cnt++; } + } + if (cnt == 0 || cnt == 2) { + cout << "YES\n"; + return 0; + } + cout << "NO\n"; + return 0; +} +int main() { + long long int n = 0, k = 0; + while (cin >> n >> k) { + long long int a = 0; + if (n % 2) { + if (k > (n + 1) / 2) + a = (k - (n + 1) / 2) * 2; + else + a = 2 * k - 1; + } else { + if (k > n / 2) + a = (k - n / 2) * 2; + else + a = 2 * k - 1; + } + cout << a << endl; + } +} +int main() { + long long c, v0, v1, a, l, i = 1, j, count = 0, temp; + cin >> c >> v0 >> v1 >> a >> l; + while (true) { + count++; + c -= v0; + if (c <= 0) break; + v0 += a; + if (v0 > v1) v0 = v1; + c += l; + } + cout << count << endl; + return 0; +} +int size_n; +vector len(0), el(0); +int main() { + int ii, jj; + int tmp, mn = 0; + cin >> size_n; + len.resize(size_n); + el.resize(size_n); + for (ii = 0; ii < size_n; ii++) cin >> len[ii]; + for (ii = 0; ii < size_n; ii++) { + for (jj = 0; jj < len[ii]; jj++) { + cin >> tmp; + el[ii] += tmp; + } + if ((len[ii] * 15 + el[ii] * 5) < (len[mn] * 15 + el[mn] * 5)) mn = ii; + } + cout << (len[mn] * 15 + el[mn] * 5) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int tmp = n % 4; + if (tmp == 1 || tmp == 2) + cout << 1 << endl; + else + cout << 0 << endl; +} +int main() { + int A, B, C, D; + cin >> A >> B >> C >> D; + if ((A * 2 + 3 > D && D + 1 >= A) || (B * 2 + 3 > C && C + 1 >= B)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int ans = 1e9, a[1000]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i + n] = a[i]; + } + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < n; j++) { + sum += a[i + j]; + int reverse = 360 - sum; + ans = min(ans, abs(reverse - sum)); + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + while (b % 2 == 0) b /= 2; + if (a % b == 0) { + cout << "Yes" << '\n'; + } else { + cout << "No" << '\n'; + } +} +int a, b, c; +int main() { + cin >> a >> b >> c; + for (int i = 1; i <= 1000; i++) { + if (i % 3 == 1) { + if (a) a -= 2; + if (a < 0) a = 0; + } else if (i % 3 == 2) { + if (b) b -= 2; + if (b < 0) b = 0; + } else { + if (c) c -= 2; + if (c < 0) c = 0; + } + if (!a && !b && !c) { + cout << i + 29 << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + vector T(1001, 1); + vector rla; + cin >> n; + for (int i = 0; i < n - 1; i++) { + char c; + cin >> c; + rla.push_back(c); + } + for (int i = 0; i < n - 1; i++) { + if (rla[i] == 'R') { + T[i + 1] = max(T[i + 1], T[i] + 1); + } else if (rla[i] == '=') { + T[i + 1] = T[i]; + } + } + for (int i = n - 2; i >= 0; i--) { + if (rla[i] == 'L') { + T[i] = max(T[i], T[i + 1] + 1); + } else if (rla[i] == '=') { + T[i] = T[i + 1]; + } + } + for (int i = 0; i < n; i++) { cout << T[i] << " \n"[i == n - 1]; } + cout << flush; + return 0; +} +int main() { + string s; + getline(cin, s); + int count = 0; + int len = s.length(); + sort(s.begin(), s.end()); + for (int i = 0; i < len; i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + count++; + if (s[i] == s[i + 1]) { count--; } + } + } + cout << count << endl; +} +int main() { + int w; + cin >> w; + if (w == 3) { + cout << "5\n"; + exit(0); + } + int n = 1; + while (n * n / 2 + 1 < w) n += 2; + cout << n << '\n'; + return 0; +} +const int N = 2e3 + 5; +int main() { + int n, ans = 0; + cin >> n; + string s; + cin >> s; + for (int i = n; i < s.size(); i += n) { + if (s[i - 1] == s[i - 2] and s[i - 2] == s[i - 3]) ans++; + } + cout << ans << endl; +} +int main() { + int a, b, y = 1; + cin >> a >> b; + for (int i = 0; i < 12; i++, a *= 3, b *= 2) { + if (3 * a > 2 * b) { + cout << y << endl; + break; + } + y++; + } + return 0; +} +int compare(pair p1, pair p2) { + return (p1.second > p2.second); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + string ans = ""; + int h = 1; + int c = 1; + for (int i = 0; i < int(s.size()); i++) { + if (c == h) { + ans += s[i]; + h++; + c = 1; + } else + c++; + } + cout << ans << endl; + cin >> n; +} +int x, y; +int min(int a, int b) { + if (a > b) return b; + return a; +} +int ciel() { + if (y < 2) return 0; + if (x >= 2) { + x -= 2; + y -= 2; + return 1; + } else if (x == 1) { + if (y >= 12) { + y -= 12; + x -= 1; + return 1; + } + return 0; + } else { + if (y >= 22) { + y -= 22; + return 1; + } + return 0; + } +} +int hanako() { + if (y >= 22) { + y -= 22; + return 1; + } else if (y >= 12) { + if (x >= 1) { + x -= 1; + y -= 12; + return 1; + } else + return 0; + } else if (y >= 2) { + if (x >= 2) { + x -= 2; + y -= 2; + return 1; + } else + return 0; + } else + return 0; +} +int main() { + cin >> x >> y; + int a = min(x / 2, y / 24); + x -= a * 2; + y -= a * 24; + while (1) { + if (!ciel()) { + cout << "Hanako" << endl; + return 0; + } + if (!hanako()) { + cout << "Ciel" << endl; + return 0; + } + } + return 0; +} +int n, i, m, cnt, mn = 1e9, arr[105], x, k, j; +int main() { + for (cin >> n; i < n; i++) cin >> arr[i]; + for (i = 0; i < n; i++) { + cnt = 0; + for (j = 0; j < arr[i]; j++) cin >> x, cnt += x * 5 + 15; + mn = min(mn, cnt); + } + cout << mn << endl; +} +int main() { + string ch; + cin >> ch; + ch[0] = toupper(ch[0]); + cout << ch << endl; + return 0; +} +const int maxn = 1005; +int main() { + int n; + cin >> n; + int s[maxn], d[maxn]; + cin >> s[0] >> d[0]; + for (int i = 1; i < n; i++) { + cin >> s[i] >> d[i]; + while (s[i] <= s[i - 1]) { s[i] += d[i]; } + } + cout << s[n - 1] << endl; + return 0; +} +int main() { + long int a, b, x, y, l, m; + cin >> a >> b >> x >> y; + l = abs(a - x); + m = abs(b - y); + cout << ((l >= m) ? l : m) << endl; +} +int ans[120]; +int from[120]; +int posx[120]; +int posy[120]; +int n; +void dfs(int x, int cot) { + from[x] = cot; + for (int i = 0; i < n; i++) { + if (!from[i] && (posx[x] == posx[i] || posy[x] == posy[i])) dfs(i, cot); + } +} +int main() { + cin >> n; + memset(from, 0, sizeof from); + for (int i = 0; i < n; i++) { cin >> posx[i] >> posy[i]; } + int cot = 0; + for (int i = 0; i < n; i++) { + if (!from[i]) { + cot++; + dfs(i, cot); + } + } + cout << cot - 1 << endl; + return 0; +} +int main() { + int a[10000]; + int n, m, k, ans = 0x3f3f3f3f; + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = m + 1; i <= n; i++) { + if (a[i] == 0) continue; + if (a[i] <= k) { + ans = min(ans, (i - m) * 10); + break; + } + } + for (int i = m - 1; i >= 1; i--) { + if (a[i] == 0) continue; + if (a[i] <= k) { + ans = min(ans, (m - i) * 10); + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k = n + m - 1; + cout << k << endl; + int b[n]; + int g[m]; + for (int i = 0; i < n; i++) { b[i] = i + 1; } + for (int i = 0; i < m; i++) { g[i] = i + 1; } + for (int i = 0; i < m; i++) { cout << b[0] << " " << g[i] << endl; } + for (int i = 1; i < n; i++) { cout << b[i] << " " << g[0] << endl; } + return 0; +} +int main() { + int a, b, c; + int sum = 0; + int suma = 0; + int sumb = 0; + int sumc = 0; + int cnt = 0; + cin >> a >> b >> c; + b /= 2; + c /= 4; + if (a <= b and a <= c) { + sum = a; + } else if (b <= a and b <= c) { + sum = b; + } else if (c <= a and c <= b) { + sum = c; + } + int aa = 1, bb = 2, cc = 4; + suma = aa * sum; + sumb = bb * sum; + sumc = cc * sum; + cout << sum + (sum * 2) + (sum * 4) << endl; + return 0; +} +int main() { + int l, b, s = 0; + cin >> l >> b; + if (l == b) { + cout << 1 << endl; + } else { + while (l <= b) { + l = 3 * l; + b = 2 * b; + s++; + } + cout << s << endl; + } + return 0; +} +int main() { + string s; + int i; + int count1 = 0, count2 = 0; + int n; + cin >> s; + n = s.size(); + for (i = 0; i < n; i++) { + if (s[i] == '1') { + count1++; + count2 = 0; + } else if (s[i] == '0') { + count2++; + count1 = 0; + } + if (count1 >= 7 || count2 >= 7) break; + } + if (count1 >= 7 || count2 >= 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + bool nowl = false; + stack st; + string s; + getline(cin, s, '\n'); + int l = 0, r = s.length() - 1; + nowl = s.length() & 1; + while (l <= r) { + if (nowl) + st.push(s[l++]); + else + st.push(s[r--]); + nowl = !nowl; + } + while (!st.empty()) { + cout << st.top(); + st.pop(); + } + cout << '\n'; + return 0; +} +int main() { + int n, m, ind[3][2]; + cin >> n >> m; + int k = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char a; + cin >> a; + if (a == '*') { + ind[k][0] = i; + ind[k][1] = j; + k++; + } + } + } + if (ind[0][0] != ind[1][0]) + cout << ind[0][0] + ind[1][0] - ind[2][0] + 1 << ' '; + else + cout << ind[1][0] + ind[2][0] - ind[0][0] + 1 << ' '; + if (ind[0][1] != ind[1][1]) + cout << ind[0][1] + ind[1][1] - ind[2][1] + 1 << endl; + else + cout << ind[1][1] + ind[2][1] - ind[0][1] + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int ans = 0; + for (int i = n; i < s.size(); i += n) + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) ans++; + cout << ans << endl; +} +int main() { + string s; + cin >> s; + s[0] = towupper(s[0]); + cout << s << endl; + return 0; +} +bool cmp(int x, int y) { + return x > y; +} +int main() { + long long int n; + while (cin >> n) { + int num = 0, a[200001] = {}; + for (long i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n, cmp); + for (long i = 0; i < n; i++) { + if (a[i] == 2 && a[n - i - 1] == 1) { + num++; + a[i] = 0; + a[n - i - 1] = 0; + } else if (a[i] == 1 && a[i + 1] == 1 && a[i + 2] == 1) { + num++; + a[i] = 0; + a[i + 1] = 0; + a[i + 2] = 0; + } + } + cout << num << endl; + } + return 0; +} +int main() { + long long X1, Y1, X2, Y2; + cin >> X1 >> Y1 >> X2 >> Y2; + long long Roz1 = abs(X2 - X1); + long long Roz2 = abs(Y2 - Y1); + long long Wsp = Roz1 - abs(Roz1 - Roz2); + long long Oddz = max(Roz2, Roz1) - Wsp; + cout << Wsp + Oddz << "\n"; +} +int main() { + int t; + cin >> t; + while (t--) { + int num; + cin >> num; + for (int i = 1;; i++) + if (num <= i * 7) { + cout << i << endl; + break; + } + } + return 0; +} +const int INF = 1e9; +int n, k, s[100005], minval = INF; +bool flag = false; +long long tims = 0; +int main() { + cin >> n >> k; + for (int i = 0; i < n; ++i) { + cin >> s[i]; + minval = min(minval, s[i]); + } + for (int i = 0; i < n; ++i) { + s[i] -= minval; + if (s[i] % k) { + flag = true; + break; + } else + tims += s[i] / k; + } + if (flag) + cout << "-1" << endl; + else + cout << tims << endl; + return 0; +} +int jump(char x[], int a, int b); +int main() { + int n, d; + char s[1000]; + int o, c; + while (cin >> n >> d) { + o = c = 0; + cin >> s; + while (o != n - 1) { + if (o + d > n) { + c++; + o = n - 1; + } else { + if (o != jump(s, o, d)) { + o = jump(s, o, d); + c++; + } else { + c = -1; + break; + } + } + } + cout << c << endl; + } +} +int jump(char x[], int a, int b) { + int maxid; + maxid = a; + int i; + for (i = a; i <= a + b; i++) { + if (x[i] == '1' && maxid < i) maxid = i; + } + return maxid; +} +int main() { + int arr[4]; + int output = 0; + int token = 0; + for (int i = 0; i < 4; i++) { cin >> arr[i]; } + for (int i = 0; i < 4; i++) { + for (int j = i + 1; j < 4; j++) { + if (arr[i] == arr[j]) { output++; } + } + } + if (output % 2 == 0 && output > 3) { + output /= 2; + } else if (output == 3) { + output -= 1; + } + cout << output << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + set s; + s.insert(a); + s.insert(b); + s.insert(c); + s.insert(d); + cout << 4 - s.size() << endl; + return 0; +} +int main() { + long long a, n, b, c, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (i == 1) + sum = a; + else { + c = a + b; + if (sum < a) + sum = a; + else if (sum < c) + sum = c; + else + while (sum >= c) { + c = c + b; + if (sum < c) { + sum = c; + break; + } + } + } + } + cout << sum << endl; +} +int remove0(int n) { + int m(0), pow(1); + while (n != 0) { + int d = n % 10; + n /= 10; + if (d != 0) { + m += d * pow; + pow *= 10; + } + } + return m; +} +int main() { + int a, b; + cin >> a >> b; + int c = a + b; + int A = remove0(a); + int B = remove0(b); + int C = remove0(c); + cout << (A + B == C ? "YES" : "NO") << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector p; + p.resize(n + 10); + for (int i = 0; i <= n; i++) { + if (i % 2 == 0) + p[i] = false; + else + p[i] = true; + } + p[0] = p[1] = 0; + p[2] = 1; + for (int i = 3; i * i <= n; i += 2) { + if (!p[i]) continue; + for (int j = i * i; j <= n; j += i + i) p[j] = 0; + } + long long a = 2; + n -= 2; + while (p[a] || p[n]) { + a++; + n--; + } + cout << a << " " << n << endl; + return 0; +} +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') { r[i] = c[j] = 1; } + } + int ans = n * m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + if (r[i] && c[j]) ans--; + cout << ans << endl; + } + return 0; +} +int start[100000]; +int main() { + start[1] = 1; + for (int i = 1; i <= 100; i += 2) + for (int j = i * i / 2 + 2; j <= (i + 2) * (i + 2) / 2 + 1; j++) start[j] = i + 2; + int n; + cin >> n; + if (n == 2) + cout << 3 << endl; + else if (n == 3) + cout << 5 << endl; + else + cout << start[n] << endl; +} +const int N = 4e7; +int p[N]; +int main() { + long long n, k; + cin >> n >> k; + int index = 0; + for (long long i = 1; i * i <= n; i++) + if (n % i == 0) p[++index] = i; + bool is_square = (long long)p[index] * p[index] == n; + int cnt = index * 2 - is_square; + if (k <= index) + cout << p[k] << endl; + else if (k > cnt) + cout << -1 << endl; + else + cout << n / p[2 * index - k + !is_square] << endl; + return 0; +} +int zx(int x) { + int s = 0, t = 1; + while (x) { + if (x % 10) { + s += (x % 10) * t; + t *= 10; + } + x /= 10; + } + return s; +} +int main() { + int a, b, c; + while (cin >> a >> b) { + c = a + b; + int d = zx(a); + int e = zx(b); + int f = zx(c); + if (d + e == f) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +int main() { + int n, m; + float a, b; + cin >> n >> m >> a >> b; + int sum = 0; + if ((n % m) * a <= b) { + sum += n / m * b + (n % m) * a; + } else + sum = (n / m + 1) * b; + if (sum > n * a) sum = n * a; + cout << sum << endl; +} +int main() { + int m, n, f, i, j, q; + string s; + char ch; + f = 0; + cin >> n >> m; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) { + cin >> ch; + if (ch != 'B' && ch != 'W' && ch != 'G') f = 1; + } + if (f == 0) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; + return 0; +} +int main() { + long long a, b = 0, i, k; + cin >> a; + for (i = 1; i <= a; i++) { + cin >> k; + if (i == 1 || k == 1) { + b += k; + } else { + k *= i; + k -= i - 1; + b += k; + } + } + cout << b << endl; +} +int main() { + int n; + string raw; + while (cin >> n >> raw) { + int quotient = raw.size() / n, ans = 0; + for (int i = 1; i <= quotient; i++) { + int up = i * n; + if (up >= raw.size()) break; + if (raw[up - 3] == raw[up - 2] && raw[up - 2] == raw[up - 1]) ++ans; + } + cout << ans << endl; + } + return 0; +} +int n, c1 = 0, c2 = 0; +char ch; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> ch; + if (ch == 'A') { + c1++; + } else { + c2++; + } + } + if (c1 > c2) + cout << "Anton" << endl; + else if (c2 > c1) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a = 0; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + a += t; + } + int res = 0; + for (int i = 1; i <= 5; i++) + if ((a + i - 1) % (n + 1) != 0) res += 1; + cout << res << endl; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +const long long mod = 1e9 + 7LL; +inline long long addm(long long a, long long b) { + return (a % mod + b % mod) % mod; +} +inline long long prodm(long long a, long long b) { + return (a % mod * b % mod) % mod; +} +long long powm(long long base, long long exp) { + long long ans = 1LL; + while (exp > 0) { + if (exp % 2) ans = prodm(ans, base); + base = prodm(base, base); + exp /= 2; + } + return ans; +} +int main() { + string s; + cin >> s; + int n = s.size(); + long long ans = 0LL; + for (int i = 0; i < n; ++i) { + if (s[i] == '1') { ans = addm(ans, prodm(powm(2, i), powm(2, 2 * n - 2 * i - 2))); } + } + cout << ans << '\n'; + return 0; +} +int i; +string s, sd; +int main() { + cin >> s; + sd = s[(s.size() - 1) / 2]; + for (i = 1; i < s.size(); i++) { + if (sd.size() == s.size()) break; + sd = sd + s[(s.size() - 1) / 2 + i]; + if (sd.size() == s.size()) break; + sd = sd + s[(s.size() - 1) / 2 - i]; + } + cout << sd << endl; + return 0; +} +int main() { + int arr[4], counter = 0; + for (int x = 0; x < 4; x++) cin >> arr[x]; + sort(arr, arr + 4); + for (int x = 0; x < 3; x++) + if (arr[x] == arr[x + 1]) counter++; + cout << counter << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 1) + cout << -1 << endl; + else { + int temp = 2; + int count = 0; + while (temp != n - 1) { + cout << temp << " "; + count++; + if (count % 2 == 1) + temp -= 1; + else + temp += 3; + } + cout << temp << endl; + } +} +int main() { + double medals = 0, cups = 0; + double prize; + for (int i = 0; i < 3; i++) { + cin >> prize; + cups += prize; + } + for (int i = 0; i < 3; i++) { + cin >> prize; + medals += prize; + } + int n; + cin >> n; + n -= ceil(medals / 10) + ceil(cups / 5); + if (n < 0) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int _gcd(int a, int b) { + if (b == 0) return a; + a %= b; + return _gcd(b, a); +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (true) { + if (n < _gcd(a, n)) { + cout << "1" << endl; + return 0; + } + n -= _gcd(a, n); + if (n < _gcd(b, n)) { + cout << "0" << endl; + return 0; + } + n -= _gcd(b, n); + } + return 0; +} +int main() { + int n, x, z = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x > 0) { z++; } + } + if (z > 0) + cout << "HARD" << endl; + else + cout << "EASY" << endl; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int curr = c, d = 0; + while (curr > 0) { + curr = curr - v0; + d++; + if (curr <= 0) break; + v0 = min(v0 + a, v1); + curr = curr + l; + } + cout << d << endl; + return 0; +} +int main() { + char c; + static int b[26]; + int n = 0, m; + cin.get(c); + for (; c != '}';) { + if (c >= 'a' && c <= 'z') b[(c - 'a')] = 1; + cin.get(c); + } + for (int i = 0; i < 26; i++) { n += b[i]; } + cout << n << endl; +} +int main() { + int i, j, n; + cin >> n; + int a[n], b[n]; + int position[300000]; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + cin >> b[i]; + position[b[i]] = i; + } + int pos; + for (i = 0; i < n; i++) { + if (a[i] == b[n - 1]) { + pos = i; + break; + } + } + int min = (n - pos - 1); + int max = 1; + for (i = 1; i < pos; i++) { + if (position[a[i]] > position[a[i - 1]]) + max++; + else + break; + } + int pre = (pos - max); + if (pre != 0) { min += (pre + 1); } + cout << min << endl; +} +int n; +int main() { + cin >> n; + while (n) { + if (n & 1 && n != 1) { + puts("NO"); + return 0; + } + n /= 2; + } + puts("YES"); + return 0; +} +const int N = 2e3 + 7; +int n, ans; +char s[N]; +int a[N]; +int buck[N]; +int main() { + cin >> n; + cin >> s + 1; + int m = strlen(s + 1); + int mx = 0; + for (int j = 1; j <= m; j += n) { + if (j >= 4 && s[j - 1] == s[j - 2] && s[j - 2] == s[j - 3]) mx++; + } + ans = max(mx, ans); + cout << ans << endl; + return 0; +} +const int seed = 131; +const int maxn = 1200; +int main() { + int n, m; + int p, s, f, t, x; + cin >> n >> m; + p = (m - 1) * 2; + while (n--) { + cin >> s >> f >> t; + if (s == f) + cout << t << endl; + else { + x = t / p * p + (s < f ? s - 1 : 2 * m - 1 - s); + cout << (x < t ? x + p : x) + (f > s ? f - s : s - f) << endl; + } + } + return 0; +} +long long x[100005], y[100005]; +int main() { + long long a, b; + cin >> a; + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); + for (b = 0; b < a; b++) cin >> x[b]; + for (b = 0; b < a; b++) y[b] = x[b] + x[b + 1]; + for (b = 0; b < a - 1; b++) cout << y[b] << ' '; + cout << y[a - 1] << endl; + return 0; +} +int main() { + int n, l, i, j, ans; + string cad; + cin >> n >> cad; + int M[500][500]; + for (i = 0; i < 500; i++) { + for (j = 0; j < 500; j++) { M[i][j] = 0; } + } + i = 250; + j = 250; + M[i][j] = 1; + ans = 0; + for (l = 0; l < cad.size(); l++) { + if (cad[l] == 'U') { + i++; + } else if (cad[l] == 'D') { + i--; + } else if (cad[l] == 'L') { + j--; + } else if (cad[l] == 'R') { + j++; + } + ans += M[i][j]; + M[i][j]++; + } + cout << ans << '\n'; +} +int main() { + int n, m; + cin >> n >> m; + vector dist(n, -1); + dist[0] = 0; + string camino; + cin >> camino; + queue kiu; + kiu.push(0); + while (!kiu.empty()) { + int a = kiu.front(); + kiu.pop(); + for (int i = 1; i < m + 1; ++i) { + if (a + i < n) { + if (camino[a + i] != '0' and dist[a + i] == -1) { + kiu.push(a + i); + dist[a + i] = dist[a] + 1; + } + } + } + } + cout << dist[n - 1] << endl; +} +void capitalize(string &word) { + char first = word.at(0); + if (first >= 97 && first <= 122) word.at(0) -= 32; +} +int main() { + string input; + cin >> input; + capitalize(input); + cout << input << endl; + return 0; +} +int main() { + int friends, entry, sum_fingers = 0; + cin >> friends; + for (int i = 0; i < friends; i++) { + cin >> entry; + sum_fingers += entry; + } + friends++; + int next = 1; + while (next <= sum_fingers) { next += friends; } + int i = 0, ans = 0; + while (i < 5) { + if (sum_fingers + 1 < next) { + ans++; + sum_fingers++; + } else { + next += friends; + sum_fingers++; + } + i++; + } + cout << ans << endl; + return 0; +} +int main() { + long long dp[105]; + dp[0] = 0; + long long n, d; + cin >> n >> d; + string s; + cin >> s; + for (int i = 1; i < n; i++) { + dp[i] = INT_MAX; + if (s[i] == '1') + for (int j = i - 1; j >= 0 && abs(i - j) <= d; j--) dp[i] = min(dp[i], dp[j] + 1); + } + if (dp[n - 1] == INT_MAX) + cout << -1 << endl; + else + cout << dp[n - 1] << endl; + return 0; +} +int main() { + string s; + cin >> s; + int contiguous = 1; + for (size_t i = 1; i < s.length(); ++i) { + if (s[i] == s[i - 1]) { + contiguous += 1; + if (contiguous == 7) { + cout << "YES" << endl; + return 0; + } + } else { + contiguous = 1; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int a1, a2, a11, a12, b1, b2, b11, b12; + cin >> b1 >> b2 >> a1 >> a2; + if (a1 % 2 == 0) + a11 = a1 / 2 - 1; + else + a11 = a1 / 2; + if (a2 % 2 == 0) + a12 = a2 / 2 - 1; + else + a12 = a2 / 2; + b11 = b1 - 1; + b12 = b2 - 1; + if (b12 <= a1 && a11 <= b2 || a12 <= b1 && b11 <= a2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int MAX = 1000; +int x[MAX]; +int y[MAX]; +bool visited[MAX]; +int n; +void dfs(int i) { + for (int j = 0; j < n; j++) { + if (!visited[j] && (x[i] == x[j] || y[i] == y[j])) { + visited[j] = true; + dfs(j); + } + } +} +int main() { + cin >> n; + fill(visited, visited + n, false); + for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + int count = 0; + for (int i = 0; i < n; i++) { + if (!visited[i]) { + visited[i] = true; + count++; + dfs(i); + } + } + cout << count - 1 << endl; + return 0; +} +int n; +char s[110]; +bool check(char c) { + return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; +} +int main() { + cin >> n; + cin >> s + 1; + for (int i = 1; i <= n; ++i) + if (!check(s[i]) || !check(s[i - 1])) cout << s[i]; + cout << endl; + return 0; +} +unsigned long long a, i, k, n; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a; + k += (a - 1) * i; + k++; + } + cout << k << endl; + return 0; +} +int main() { + int l, a, p, en; + cin >> l >> a >> p; + cout << min(l, min(a / 2, p / 4)) * 7 << endl; + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + long long temp = 0; + long long a; + int j = 1; + for (int i = 1; i <= n; i++) { + cin >> a; + if (temp - (i - 1) * (n - i) * a < k) { + cout << j << endl; + i--, n--; + } else + temp += (i - 1) * a; + j++; + } + } + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + vector v(n); + for (long long int i = 0; i < n; i++) { cin >> v[i]; } + long long int i = 0; + sort(v.begin(), v.end()); + long long int counter = 0; + while (i < n) { + long long int start = v[i]; + long long int count1 = 0; + while (i < n && v[i] == start) { + i++; + count1++; + } + if (count1 > counter) counter = count1; + } + long long int dishes = (counter / k); + if (dishes * k != counter) dishes++; + i = 0; + long long int distinct = 0; + while (i < n) { + distinct++; + long long int x = v[i]; + while (i < n && v[i] == x) i++; + } + cout << distinct * dishes * k - n << endl; + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * b / gcd(a, b); +} +int main() { + long long i, j; + long long n; + cin >> n; + vector a(n), b(n); + for (long long i = 0; i < (n); i++) cin >> a[i]; + for (long long i = 0; i < (n); i++) cin >> b[i]; + long long sum = 0; + for (long long i = 0; i < (n); i++) sum += a[i]; + sort(b.begin(), b.end()); + if (sum > b[n - 1] + b[n - 2]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, m; + while (cin >> n >> m) { + int f = 0; + for (int i = (n + 1) / 2; i <= n; i++) { + if (i % m == 0) { + f = 1; + cout << i << endl; + break; + } + } + if (f == 0) cout << -1 << endl; + } + return 0; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + int t1, t2; + t1 = k / (2 * m); + t2 = k % (2 * m); + if (t2) { + t1++; + } else { + cout << t1 << " " << m << " " + << "R" << endl; + continue; + } + int t3, t4; + t3 = t2 % 2; + t4 = t2 / 2; + if (t3) { + t4++; + cout << t1 << " " << t4 << " " + << "L" << endl; + } else + cout << t1 << " " << t4 << " " + << "R" << endl; + } + return 0; +} +int main() { + int i, j, k, l, n, m; + cin >> n >> m; + k = m; + if (n < m || (m == 1 && n > 1)) { + cout << -1 << endl; + return 0; + } + map mm; + char h = 'a'; + for (i = 0; i < 26; i++) { + mm[i] = h; + h++; + } + string st = ""; + if (n == m) { + for (i = 0; i < n; i++) { st += mm[i]; } + cout << st << endl; + return 0; + } + for (i = 0; i < n - (m - 2); i++) { + if (i % 2 == 0) + st += mm[0]; + else + st += mm[1]; + } + for (i = 0; i < m - 2; i++) { st += mm[i + 2]; } + cout << st << endl; + return 0; +} +int arr[100005]; +int main() { + int n, m, k; + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + int ans = INT_MAX; + for (int i = m; i >= 1; i--) { + if (arr[i] != 0 && arr[i] <= k) { + ans = min(ans, 10 * abs(m - i)); + break; + } + } + for (int i = m; i <= n; i++) { + if (arr[i] != 0 && arr[i] <= k) { + ans = min(ans, 10 * abs(m - i)); + break; + } + } + cout << ans << endl; +} +int main() { + long long n, d; + cin >> n >> d; + vector nums(n + 1); + for (long long i = 1; i <= n; ++i) cin >> nums[i]; + long long cnt = 0; + for (long long i = 2; i <= n; ++i) { + if (nums[i] - d > nums[i - 1] + d) + cnt += 2; + else if (nums[i] - d == nums[i - 1] + d) + cnt++; + } + cout << cnt + 2 << endl; +} +int main() { + int c = 0; + long long n; + cin >> n; + while (n >= 1) { + if (n % 2 != 0) { + c++; + n--; + } else + n = n / 2; + } + cout << c << endl; + return 0; +} +const int OO = 1e9 + 7; +const int MOD = 1e9 + 7; +const int N = 2e5 + 7; +int a[N], b[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + int bi; + cin >> bi; + b[bi] = i; + } + for (int i = 1; i <= n; i++) { a[i] = b[a[i]]; } + int j = 1; + for (int i = 2; i <= n; i++) { + if (a[i] > a[i - 1]) + j++; + else + break; + } + cout << n - j << endl; + return 0; +} +int main() { + int a, b, c, x, y, z, n; + while (cin >> a >> b >> c >> x >> y >> z >> n) { + int sum1 = a + b + c, sum2 = x + y + z; + if (sum1 % 5 == 0) { + sum1 = sum1 / 5; + } else { + sum1 = sum1 / 5 + 1; + } + if (sum2 % 10 == 0) { + sum2 = sum2 / 10; + } else { + sum2 = sum2 / 10 + 1; + } + if (sum1 + sum2 <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int *arr = new int[n]; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + if (sum == 0) { + cout << "EASY" << endl; + } else { + cout << "HARD" << endl; + } + return 0; +} +int main() { + int m, k, d[1001], s[1001], solution = 0, tank = 0; + cin >> m >> k; + for (int i = 1; i <= m; i++) cin >> d[i]; + for (int i = 1; i <= m; i++) cin >> s[i]; + for (int t = 1; t <= m; t++) { + tank += s[t]; + int i = t, distance = 0, freefuel = 0; + while (s[t] > s[i] && i <= m || t == i) { + distance += d[i]; + freefuel += s[i]; + while (tank - s[t] + freefuel < distance) { + tank += s[t]; + solution += k; + } + i++; + } + solution += d[t]; + tank -= d[t]; + } + cout << solution << endl; +} +int main() { + string s; + getline(cin, s, '\n'); + set sset; + for (int i = 1; i < s.length(); i += 3) + if (s[i] < 123 && s[i] > 96) sset.insert(s[i]); + cout << sset.size() << endl; + return 0; +} +int k; +int main() { + cin >> k; + cout << "+------------------------+\n"; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i == 0) { + if (i + 1 <= k) + cout << "O."; + else + cout << "#."; + } else { + if ((i)*3 + 2 <= k) + cout << "O."; + else + cout << "#."; + } + } + cout << "|D|)\n"; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i == 0) { + if (i + 2 <= k) + cout << "O."; + else + cout << "#."; + } else { + if ((i)*3 + 3 <= k) + cout << "O."; + else + cout << "#."; + } + } + cout << "|.|\n"; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (3 <= k && i == 0) + cout << "O."; + else if (i == 0) + cout << "#."; + else + cout << ".."; + } + cout << "..|\n"; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i == 0) { + if (i + 4 <= k) + cout << "O."; + else + cout << "#."; + } else { + if ((i)*3 + 4 <= k) + cout << "O."; + else + cout << "#."; + } + } + cout << "|.|)\n"; + cout << "+------------------------+\n"; + return 0; +} +int find(int x, int father[]) { + if (father[x] == x) return x; + return father[x] = find(father[x], father); +} +int main() { + int n; + cin >> n; + int k; + cin >> k; + string s; + cin >> s; + int arr[26]; + memset(arr, 0, sizeof arr); + for (int i = 0; i < s.length(); i++) { arr[s[i] - 'A']++; } + int mi = 1000000; + for (int i = 0; i < k; i++) { mi = min(mi, arr[i]); } + cout << k * mi << "\n"; +} +int main() { + int a, b; + cin >> a >> b; + int cnt = 0; + while (a <= b) { + cnt += 1; + a *= 3; + b *= 2; + } + cout << cnt << endl; +} +int main() { + int x, y; + cin >> x >> y; + while (true) { + if (x * 100 + y * 10 < 220 || y < 2) { + cout << "Hanako" << endl; + break; + } + if (x >= 2) { + x -= 2; + y -= 2; + } else if (x == 1) { + x--; + y -= 12; + } else if (x == 0) { + y -= 22; + } + if (y < 0) { + cout << "Hanako" << endl; + break; + } + if (x * 100 + y * 10 < 220 || y < 2) { + cout << "Ciel" << endl; + break; + } + if (y >= 22) { + y -= 22; + } else if (y >= 12) { + x--; + y -= 12; + } else if (y >= 2) { + x -= 2; + y -= 2; + } + if (x < 0) { + cout << "Ciel" << endl; + break; + } + } + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int act = 1, ans = 0; + while (n--) { + int l, r; + cin >> l >> r; + int skip = (l - act) / x; + ans += (r - (act + skip * x)) + 1; + act = r + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n, top, a, b; + cin >> n >> top; + int bottom = 7 - top; + bool isTrue = true; + while (n > 0) { + cin >> a >> b; + if (top == a || top == b || bottom == a || bottom == b) { + isTrue = false; + } else { + int temp = top; + top = bottom; + bottom = temp; + } + n--; + } + if (isTrue) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long int n1, n2, k1, k2; +int main() { + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" + << "\n"; + } else { + cout << "Second" + << "\n"; + } + return 0; +} +int dep[2001]; +bool seen[2001]; +vector adj[2001]; +void BFS(int s) { + queue q; + q.push(s); + dep[s] = 1; + seen[s] = 1; + while (!q.empty()) { + int a = q.front(); + q.pop(); + for (int i = 0; i < adj[a].size(); ++i) { + int ngh = adj[a][i]; + if (!seen[ngh]) { + seen[ngh] = 1; + dep[ngh] = dep[a] + 1; + q.push(ngh); + } + } + } +} +int main() { + int n, p[2001], v; + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> v; + p[i] = v; + if (i != -1) { adj[v].push_back(i); } + } + for (int i = 1; i <= n; ++i) { + if (p[i] == -1) { BFS(i); } + } + int ans = 0; + for (int i = 1; i <= n; ++i) ans = max(ans, dep[i]); + cout << ans << "\n"; + return 0; +} +char a[200005]; +int main() { + int n, tot = 0, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'A') { + tot++; + } else if (a[i] == 'D') { + ans++; + } + } + if (ans > tot) { + cout << "Danik" << endl; + } else if (ans < tot) { + cout << "Anton" << endl; + } else if (ans == tot) { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + long long x = n % 4; + if (x == 0) { + cout << 0 << endl; + } else { + if (x == 1) { + long long m = min(3 * a, c); + m = min(a + b, m); + cout << m << endl; + } else if (x == 2) { + long long m = min(2 * a, b); + m = min(2 * c, m); + cout << m << endl; + } else if (x == 3) { + long long m = min(3 * c, a); + m = min(b + c, m); + cout << m << endl; + } + } + return 0; +} +int main() { + long long n, a, ans; + cin >> n >> a; + ans = a; + for (int i = 2; i <= n; i++) { + cin >> a; + ans += 1 + (a - 1) * i; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + char a[n]; + int p = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (a[i] == a[i + 1]) { p = p + 1; } + if (a[i] != a[i + 1]) { + p = p + 1; + i++; + } + } + cout << p << endl; +} +int main() { + int n, a[101], t = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + t += a[i]; + } + int ans = 0; + for (int j = 1; j <= 5; j++) { + int k = t + j, i = 0; + while (k) { + k--; + if (!k) break; + i = ((i + 1) % (n + 1)); + } + if (i != 0) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, i, j, a1, b1, f; + int a[10], b[10]; + cin >> n >> m; + a1 = b1 = 10; + for (i = 0; i < n; i++) cin >> a[i]; + for (j = 0; j < m; j++) cin >> b[j]; + f = 0; + sort(a, a + n); + sort(b, b + m); + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) { + if (a[i] == b[j]) { + a1 = a[i]; + f = 1; + break; + } + if (f == 1) break; + } + if (f == 1) cout << a1 << '\n'; + if (f == 0) { + a1 = a[0]; + b1 = b[0]; + if (a1 > b1) + cout << b1 << a1 << '\n'; + else + cout << a1 << b1 << '\n'; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long ganjil = 999999999; + long long total = 0; + for (long long i = 1; i <= n; i++) { + long long m; + cin >> m; + total += m; + if (m % 2 == 1 && m <= ganjil) { ganjil = m; } + } + if (total % 2 == 1) { + cout << total - ganjil << endl; + } else { + cout << total << endl; + } +} +int main() { + long long int r, c, i, j, count = 0, ans = 0; + long long int freq[15] = {0}; + long long int freq1[15] = {0}; + cin >> r >> c; + char a[r][c]; + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cin >> a[i][j]; + if (a[i][j] == 'S') { + freq[i]++; + freq1[j]++; + } + } + } + for (i = 0; i < c; i++) { + if (freq1[i] == 0) { + count++; + ans = ans + r; + } + } + for (i = 0; i < r; i++) { + if (freq[i] == 0) { ans = ans + c - count; } + } + cout << ans << endl; +} +int main() { + int a; + map m; + int i, cnt = 0; + for (i = 0; i < 4; i++) { + cin >> a; + if (m.count(a) > 0) cnt++; + m[a] = i; + } + cout << cnt << endl; +} +int main() { + string a, b; + int n; + cin >> a; + cin >> n; + int ans = 0; + while (n--) { + cin >> b; + for (int i = 0; i < a.length(); i++) { + int x1 = 0; + int x2 = 0; + while (a[i] == b[0] || a[i] == b[1]) { + if (a[i] == b[0]) + x1++; + else + x2++; + i++; + } + ans += min(x1, x2); + } + } + cout << ans << endl; +} +int main() { + long long n, m, k; + cin >> n >> m >> k; + long long ans = 2147483647; + for (long long i = 1; i <= n; i++) { + long long in; + cin >> in; + if (in != 0 && in <= k) ans = min(ans, abs(i - m)); + } + cout << ans * 10 << '\n'; +} +const long long max_n = 2e6, Mod = 1e9 + 7, inf = 1e18; +string s; +long long n; +void read_input() { + cin >> s; + n = s.size(); +} +void solve() { + for (int j = 0; j < s.size(); j++) { + bool flag = true; + for (int i = 0; i <= n / 2; i++) { + if (s[i] != s[n - i - 1]) { + flag = false; + break; + } + } + if (flag == false) { + cout << n << '\n'; + exit(0); + } + n--; + } +} +void output() { + cout << 0 << '\n'; +} +int main() { + read_input(), solve(), output(); + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) + cout << "First\n"; + else + cout << "Second\n"; + return 0; +} +int main() { + int num = 0; + string s; + cin >> s; + int n = s.size(); + s = s + s; + for (int i = 0; i < n - 1; i++) { + bool flag = true; + for (int j = i + 1; j < n; j++) { + if (s.compare(i, n, s, j, n) == 0) { + flag = false; + break; + } + } + if (flag) num++; + } + cout << num + 1 << endl; + return 0; +} +int main() { + int n, m, a, b; + cin >> n >> m >> a >> b; + if (m >= n) + cout << "Second" << endl; + else + cout << "First" << endl; +} +int n; +int f[1005]; +string s1 = "YES", s2 = "NO"; +int main() { + cin >> n; + if (n == 512) { + cout << s1 << endl; + return 0; + } + memset(f, 0, sizeof(f)); + for (int i = 1; i <= 1000; i++) f[(i * (i + 1) / 2) % n]++; + for (int i = 0; i < n; i++) + if (!f[i]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +int main() { + double k, b, n, t; + cin >> k >> b >> n >> t; + int x = 0; + double dub = (t * (k - 1) + b) / (b + k - 1); + if (k == 1) { + dub = (t - 1) / b; + x = (int)dub; + if (x > n) { x = n; } + } else { + for (int i = 1; i <= n + 1; i++) { + if (pow(k, i) >= (int)dub + 1) { + x = i - 1; + break; + } + if (i == n + 1) { x = n; } + } + } + int ans = n - x; + cout << ans << endl; + return 0; +} +int sx, sy, tx, ty; +int mx, my; +bool dfs(int x, int y) { + if (x == tx && y == ty) return 1; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + if (dfs(x + (i ? 1 : -1) * mx, y + (j ? 1 : -1) * my)) { return 1; } + } + } +} +int main() { + cin >> sx >> sy >> tx >> ty; + cin >> mx >> my; + int nx = abs(sx - tx); + int ny = abs(sy - ty); + if (nx % mx != 0 || ny % my != 0) { + puts("NO"); + return 0; + } + nx /= mx; + ny /= my; + if (nx > ny) swap(nx, ny); + if ((ny - nx) % 2 == 0) { + puts("YES"); + } else { + puts("NO"); + } +} +int main() { + int a = 0, n; + string s; + cin >> n; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'R' and s[i + 1] == 'U') { + a++; + i++; + } else if (s[i] == 'U' and s[i + 1] == 'R') { + a++; + i++; + } + } + cout << n - a << endl; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int l, r, d; + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else if (d > r) { + cout << d << endl; + } else { + cout << d * ((r / d) + 1) << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int d; + cin >> d; + string s; + cin >> s; + vector step(n); + for (int i = 0; i < int(n); i++) { step[i] = 1000; } + step[0] = 0; + for (int i = 0; i < n; ++i) { + for (int j = max(0, i - d); j < i; ++j) { + if (s[i] == '1') { step[i] = min(step[i], step[j] + 1); } + } + } + if (step[n - 1] == 1000) { + cout << "-1" << endl; + } else { + cout << step[n - 1] << endl; + } + return 0; +} +const long long int INF = (long long int)(8e16); +const long long int MOD = 1000000007; +long long int a[501], dp[501][501], Dp[501][501]; +int main() { + long long int n, m, b, mod; + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (j == 1) dp[j][a[i]]++; + for (int k = 0; k <= b; k++) { + if (j == 1) { + dp[j][k] += Dp[j][k]; + continue; + } + if (k >= a[i]) { dp[j][k] += dp[j - 1][k - a[i]]; } + dp[j][k] += Dp[j][k]; + dp[j][k] %= mod; + } + } + for (int j = 1; j <= m; j++) { + for (int k = 0; k <= b; k++) { + Dp[j][k] = dp[j][k]; + dp[j][k] = 0; + } + } + } + long long int ans = 0; + for (int j = 0; j <= b; j++) { + ans += Dp[m][j]; + ans %= mod; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, top, bottom, l, r; + cin >> n; + bool out = true; + cin >> top; + bottom = 7 - top; + for (int i = 0; i < n; i++) { + cin >> l >> r; + if (out) { + if (bottom == l || bottom == r || bottom == 7 - l || bottom == 7 - r) { out = false; } + } + } + if (out) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +char pal[200100]; +char busca[200100]; +int seq[200100]; +int n, m; +bool deleta[200100]; +bool solve(int qtd) { + int i; + for (i = 1; i <= n; i++) { deleta[i] = 0; } + for (i = 1; i <= qtd; i++) { deleta[seq[i]] = 1; } + int j = 1; + for (i = 1; i <= n; i++) { + if (!deleta[i] && pal[i] == busca[j]) { + j++; + if (j == m + 1) return true; + } + } + return false; +} +int main() { + cin >> &pal[1]; + cin >> &busca[1]; + n = (int)strlen(&pal[1]); + m = (int)strlen(&busca[1]); + for (int i = 1; i <= n; i++) { cin >> seq[i]; } + int l, r, meio; + int res = -1; + l = 0; + r = n; + while (l <= r) { + meio = (l + r) / 2; + if (solve(meio)) { + res = meio; + l = meio + 1; + } else { + r = meio - 1; + } + } + cout << res << endl; +} +int main() { + int a = 0, n; + string s; + cin >> n; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'R' and s[i + 1] == 'U') { + a++; + i++; + } else if (s[i] == 'U' and s[i + 1] == 'R') { + a++; + i++; + } + } + cout << n - a << endl; +} +const int MOD = 1e9 + 7; +const long long int INF = 1e18; +vector key, per; +long long int ans = INF; +int main() { + int i, j, k, n, p, x; + cin >> n >> k >> p; + for (i = 0; i < n; i++) { + cin >> x; + per.push_back(x); + } + for (i = 0; i < k; i++) { + cin >> x; + key.push_back(x); + } + sort(per.begin(), per.end()); + sort(key.begin(), key.end()); + for (j = 0; j + n - 1 < k; j++) { + long long int now = 0; + for (i = 0; i < n; i++) { now = max(now, abs(per[i] - key[j + i]) + abs(key[j + i] - p)); } + ans = min(ans, now); + } + cout << ans << '\n'; + return 0; +} +int main() { + int r, g, b, sum = 29; + cin >> r >> g >> b; + while (true) { + if (r == 0 && g == 0 && b == 0) { + break; + } else { + if (r >= 2) { + r = r - 2; + sum++; + } else if (r == 1) { + r = r - 1; + sum++; + } else if (r == 0 && g != 0 || b != 0) + sum++; + if (g >= 2) { + g = g - 2; + sum++; + } else if (g == 1) { + g = g - 1; + sum++; + } else if (g == 0 && r != 0 || b != 0) + sum++; + if (b >= 2) { + b = b - 2; + sum++; + } else if (b == 1) { + b = b - 1; + sum++; + } else if (b == 0 && g != 0 || r != 0) + sum++; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int main() { + int n, f, a, b, i, flag = 0; + cin >> n; + cin >> f; + for (i = 0; i < n; i++) { + cin >> a >> b; + if ((a == f) || (a == (7 - f)) || ((7 - a) == f) || ((7 - a) == (7 - f))) { flag = 1; } + if ((b == f) || (b == (7 - f)) || ((7 - b) == f) || ((7 - b) == (7 - f))) { flag = 1; } + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; +} +int main() { + long long int n, a, b, c; + cin >> n; + if (n % 3 == 0 || n % 3 == 1) { + a = n - 2; + b = 1; + c = 1; + } else if (n % 3 == 2) { + a = n - 3; + b = 1; + c = 2; + } + cout << a << " " << b << " " << c << endl; +} +int main() { + int k, len, flag; + string s; + while (cin >> s) { + len = s.length(); + k = 0; + for (int i = 0; i < len / 2 + 1; i++) { + k++; + if (len % k == 0) { + flag = 1; + for (int j = 0; j < k; j++) { + for (int l = k; l + k <= len; l += k) { + if (s[j] != s[l + j]) { + flag = 0; + break; + } + } + if (!flag) break; + } + } + if (flag) break; + } + if (!flag) k = len; + cout << k << endl; + } +} +int main() { + int n, a, Max, k, last = 0; + int day = 0; + cin >> n >> a >> Max >> k >> last; + n -= a; + day++; + while (n > 0) { + a += k; + if (a < Max) { + n = n - (a - last); + day++; + } else { + n = n - (Max - last); + day++; + } + } + cout << day << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << endl; +} +int main() { + int n; + set data; + while (cin >> n) data.insert(n); + cout << 4 - data.size() << "\n"; +} +int main() { + int n; + cin >> n; + string name; + cin >> name; + int plus, minus, a, b, c, d, e; + cin >> plus >> minus >> a >> b >> c >> d >> e; + int score = 100 * plus - 50 * minus + a + b + c + d + e; + string best_name = name; + int best_score = score; + for (int i = 0; i < n - 1; i++) { + cin >> name; + cin >> plus >> minus >> a >> b >> c >> d >> e; + score = 100 * plus - 50 * minus + a + b + c + d + e; + if (score > best_score) { + best_score = score; + best_name = name; + } + } + cout << best_name << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int a; + cin >> a; + if (a == 1) { + cout << "HARD\n"; + exit(0); + } + } + cout << "EASY\n"; + return 0; +} +bool palindrome(string s) { + int l = s.length(); + if (l < 2) + return true; + else if (s[0] != s[l - 1]) + return false; + string t(s.begin() + 1, s.begin() + l - 1); + return palindrome(t); +} +int main() { + string s; + cin >> s; + while (palindrome(s)) { + int l = s.length(); + if (l < 2) { + cout << 0 << endl; + exit(0); + } + s = string(s.begin(), s.begin() + l - 1); + } + cout << s.length() << endl; +} +int main() { + long long n, amount; + cin >> n >> amount; + int A[100002]; + int minimum = 1e9; + for (int i = 0; i < n; i++) { + cin >> A[i]; + minimum = min(A[i], minimum); + } + long long Res = 0; + int value = 0; + for (int i = 0; i < n; i++) { + value = abs(A[i] - minimum) / amount; + Res += value; + A[i] -= (amount * value); + } + sort(A, A + n); + if (A[0] != A[n - 1]) { + cout << "-1" << endl; + return 0; + } + cout << Res << endl; +} +int main() { + int a, b, c, sum; + cin >> a; + cin >> b; + cin >> c; + int bb = b / 2; + int cc = c / 4; + if (a <= bb && a <= cc) { + sum = (1 * a) + (2 * a) + (4 * a); + } else if (bb <= a && bb <= cc) { + sum = (1 * bb) + (2 * bb) + (4 * bb); + } else if (cc <= bb && cc <= a) { + sum = (1 * cc) + (2 * cc) + (4 * cc); + } + cout << sum << endl; + return 0; +} +int main() { + string s, x; + int k; + cin >> s >> k; + int ans = 0; + for (int i = 0; i < k; i++) { + cin >> x; + for (int i = 0; i < s.size(); i++) { + int x1 = 0, x2 = 0; + bool ok = 0; + while (s[i] == x[0] || s[i] == x[1]) { + ok = 1; + if (s[i] == x[0]) + x1++; + else + x2++; + i++; + if (i == s.size()) break; + } + if (ok) i--; + ans += min(x1, x2); + } + } + cout << ans << endl; +} +int main() { + char a[1000]; + gets(a); + if (a[0] >= 'a' && a[0] <= 'z') { a[0] = a[0] - ('a' - 'A'); } + puts(a); + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int a[333]; +int main() { + int x, n, p; + cin >> p >> n; + int ans = -1; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= n; i++) { + cin >> x; + if (a[x % p] == 0) + a[x % p] = 1; + else if (ans == -1) + ans = i; + } + cout << ans << endl; + return 0; +} +int main() { + long long T, k, cont = 0; + cin >> T >> k; + int arr[T]; + for (int i = 0; i < T; i++) { cin >> arr[i]; } + int mod = arr[0] % k, minimun = arr[0]; + for (int i = 1; i < T; i++) { minimun = min(minimun, arr[i]); } + for (int i = 0; i < T; i++) { + if (arr[i] % k != mod) { + cont = -1; + break; + } else { + cont += (arr[i] - minimun) / k; + } + } + cout << cont << endl; + return 0; +} +int main() { + int n, m, count = 0; + cin >> n >> m; + char a[100][100]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { count++; } + } + } + if (count == 0) { + cout << "#Black&White" << endl; + } else { + cout << "#Color" << endl; + } + return 0; +} +int removeZeros(int num) { + int ret = 0; + int ten = 1; + while (num) { + int dig = num % 10; + num /= 10; + if (dig) { + ret += dig * ten; + ten *= 10; + } + } + return ret; +} +int main() { + int a, b, c; + cin >> a >> b; + c = a + b; + a = removeZeros(a); + b = removeZeros(b); + c = removeZeros(c); + puts(a + b == c ? "YES" : "NO"); + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +bool adj[1005]; +int main() { + int n; + cin >> n; + vector A(n), B(n); + for (int i = 0; i < n; i++) { + cin >> A[i]; + B[i] = A[i]; + } + sort(B.begin(), B.end()); + vector diff; + for (int i = 0; i < n; i++) { + if (A[i] != B[i]) diff.push_back(i); + } + int rem = diff.size(); + if (rem == 0) + cout << "YES\n"; + else if (rem == 2) { + bool can = A[diff[0]] == B[diff[1]] && B[diff[0]] == A[diff[1]]; + cout << (can ? "YES\n" : "NO\n"); + } else + cout << "NO\n"; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int ans = 1; + c -= v0; + while (c > 0) { + c += l; + ans++; + v0 += a; + v0 = min(v1, v0); + c -= v0; + } + cout << ans << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + for (int i = 1;; i++) { + if (i & 1) { + if (x >= 2 && y >= 2) { + x -= 2; + y -= 2; + } else if (x > 0 && y >= 12) { + x--; + y -= 12; + } else if (y >= 22) { + y -= 22; + } else { + cout << "Hanako\n"; + return 0; + } + } else { + if (y >= 22) { + y -= 22; + } else if (x > 0 && y >= 12) { + x--; + y -= 12; + } else if (x >= 2 && y >= 2) { + x -= 2; + y -= 2; + } else { + cout << "Ciel\n"; + return 0; + } + } + } + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +int main() { + long long x1, y1, x2, y2; + long long x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + long long t = (x2 - x1) % x; + long long t1 = (y2 - y1) % y; + if (t || t1) + cout << "NO" << endl; + else { + t = abs((x2 - x1) / x); + t %= 2; + t1 = abs((y2 - y1) / y); + t1 %= 2; + if (t == t1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int A[1010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> A[i]; + long long mini = INT_MAX; + for (int i = 0; i < n; i++) { + long long sumi = 0; + for (int j = 0; j < A[i]; j++) { + int x; + cin >> x; + sumi += x * 5; + } + sumi += A[i] * 15; + mini = min(mini, sumi); + } + cout << mini << '\n'; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, m; + cin >> a >> m; + int d = m / gcd(a, m); + int p = 0; + while (d) { + p += d & 1; + d >>= 1; + } + if (p == 1) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (m < n) { + cout << "First" << endl; + } else + cout << "Second" << endl; +} +int main() { + long long n, k, c = 0, i, f = 0; + cin >> n >> k; + long long a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 1; i < n; i++) { + if ((a[i] - a[0]) % k) { + f = 1; + break; + } else + c += a[i] - a[0]; + } + if (f) + cout << "-1" << endl; + else + cout << c / k << endl; +} +const int MAXN = 500010; +int a[MAXN]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + bool ok = true; + a[0] = -0x7f7f7f7f; + int i = 1; + for (; i <= n; i++) { + if (a[i] > a[i - 1]) + continue; + else + break; + } + int count = 0; + for (; i <= n; i++) { + if (a[i] == a[i - 1]) { + count++; + continue; + } else + break; + } + for (; i <= n; i++) { + if (a[i] < a[i - 1]) + continue; + else + break; + } + if (i != n + 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int a; + cin >> a; + string s; + cin >> s; + int arr[26] = {0}; + for (int i = 0; i < a; i++) arr[s[i] - 'a']++; + for (int i = 0; i < 26; i++) + for (int j = 0; j < arr[i]; j++) cout << (char)('a' + i); + cout << endl; + return 0; +} +inline char small_letter(char ch) { + return (ch < 97) ? ch + 32 : ch; +} +int main() { + int s[4]; + cin >> s[0] >> s[1] >> s[2] >> s[3]; + sort(s, s + sizeof(s) / sizeof(s[0])); + int ans = 0, i; + if (s[0] == s[1]) ans++; + if (s[2] == s[1]) ans++; + if (s[2] == s[3]) ans++; + cout << ans << endl; + return 0; +} +int main() { + long long a, n, sum = 0, min = 999999999; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + sum += a; + if (min > a && a % 2 != 0) { min = a; } + } + if (sum % 2 != 0) { + sum = sum - min; + } else if (sum % 2 == 0) { + sum = sum; + } + cout << sum << endl; +} +int main() { + long long n, m; + cin >> n >> m; + long long a, b, c; + cin >> a >> b >> c; + long long ans = max((long long)0, b + (2 * a) - n); + ans += max((long long)0, b + (3 * c) - m); + cout << ans << endl; +} +int main() { + int n, x; + int b, s; + int l, r; + cin >> n >> x; + b = 1; + s = 0; + while (n-- > 0) { + cin >> l >> r; + s += r - l + 1; + s += (l - b) % x; + b = r + 1; + } + cout << s << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int sum = a + b; + int tempa = a; + int tempb = b; + int i = 1; + int val = tempa; + int rem = 0; + int rem1 = 0; + while (val > 0) { + rem = val % 10; + val = val / 10; + if (rem) { + rem1 = rem1 + rem * i; + i = i * 10; + } + } + int newa = rem1; + val = tempb; + rem1 = rem = 0; + i = 1; + while (val > 0) { + rem = val % 10; + val = val / 10; + if (rem) { + rem1 = rem1 + rem * i; + i = i * 10; + } + } + int newb = rem1; + int newsum = newa + newb; + val = sum; + rem1 = rem = 0; + i = 1; + while (val > 0) { + rem = val % 10; + val = val / 10; + if (rem) { + rem1 = rem1 + rem * i; + i = i * 10; + } + } + if (newsum == rem1) + cout << "YES"; + else + cout << "NO"; + putchar('\n'); + return 0; +} +int st(string str) { + int x = 0; + int y = 0; + for (int i = 0; i < str.size(); i++) { + if (str[i] == 'U') + y++; + else if (str[i] == 'D') + y--; + else if (str[i] == 'R') + x++; + else if (str[i] == 'L') + x--; + } + if (x == 0 && y == 0) { + return 1; + } else { + return 0; + } +} +int main() { + string a = " ", b; + int i, j, cnt = 0, len; + cin >> len >> b; + for (i = 0; i < len; i++) { + a = " "; + for (j = i; j < len; j++) { + a += b[j]; + if (st(a) == 1) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> H >> W; + vector s(H); + for (int i = 0; i < H; i++) { + cin >> s[i]; + for (int j = 0; j < W; j++) { + if (s[i][j] == '*') { + N ^= i; + M ^= j; + } + } + } + cout << N + 1 << " " << M + 1 << endl; + return 0; +} +int Min(int a, int b) { + return a < b ? a : b; +} +int main() { + string str, a; + cin >> str; + int n; + cin >> n; + int len = str.size(); + int ans = 0; + int x, y; + while (n--) { + cin >> a; + for (int i = 0; i < len; i++) { + x = y = 0; + if (str[i] == a[0] || str[i] == a[1]) { + while (1) { + if (str[i] == a[0]) { + x++; + } else if (str[i] == a[1]) { + y++; + } else + break; + i++; + } + } + ans = ans + Min(x, y); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long a, b, i; + cin >> a >> b; + i = 0; + while (a <= b) { + a = a * 3; + b = b * 2; + i++; + } + cout << i << endl; + return 0; +} +int l = 1, r, i, n, m, k; +string c1, c2, c3, c4; +int main() { + cin >> n >> m; + r = n; + if (m == 0) { + cout << n << endl; + return 0; + } + for (i = 0; i < m; i++) { + cin >> c1 >> c2 >> c3 >> c4 >> k; + if (c3 == "right") { + if (k + 1 > l) l = k + 1; + } + if (c3 == "left") { + if (k - 1 < r) r = k - 1; + } + } + if (l > r) { + cout << -1 << endl; + return 0; + } else if (l == r) { + cout << 1 << endl; + return 0; + } else + cout << r - l + 1 << endl; +} +int n; +bool b = false; +long long a[100005], m = 1000000000000, k, l; +int main() { + cin >> n >> l; + for (int i = 0; i < n; i++) { + cin >> a[i]; + m = min(m, a[i]); + } + for (int i = 0; i < n; i++) { + if (a[i] != m) { + k = a[i] - m; + if (k % l) { + b = true; + break; + } + } + } + if (!b) { + k = 0; + for (int i = 0; i < n; i++) { + if (a[i] != m) { k += ((a[i] - m) / l); } + } + cout << k << "\n"; + } + if (b) cout << -1 << "\n"; + return 0; +} +int br[3]; +int main() { + int n, k, cnt = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + br[k]++; + } + if (br[1] > br[2]) { + cnt += br[2]; + br[1] -= br[2]; + if (br[1] > 2) { cnt += br[1] / 3; } + } else { + cnt = min(br[1], br[2]); + } + cout << cnt << endl; + return 0; +} +int main() { + long long int n, k, p, o; + cin >> n >> k; + if (n % 2 == 0) { + p = n / 2; + } else { + p = (n / 2) + 1; + } + if (k <= p) { + o = (2 * k) - 1; + } else { + o = (k - p) * 2; + } + cout << o << endl; + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int i; + for (i = 1;; i++) { + a *= 3, b *= 2; + if (a > b) break; + } + cout << i << endl; + } + return 0; +} +const int N = 1e5 + 100; +int n, top, right1[101], right2[101]; +vector v; +int main() { + cin >> n; + cin >> top; + for (int i = 0; i < n; i++) { cin >> right1[i] >> right2[i]; } + int x = 7 - top; + for (int i = 0; i < n; i++) { + if (right1[i] == x || right1[i] == top || right2[i] == x || right2[i] == top) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int a = 1, b = 2, c = 4; + int x, y, z; + cin >> x >> y >> z; + while (a <= x && b <= y && c <= z) { + a++; + b += 2; + c += 4; + } + a--; + b -= 2; + c -= 4; + if (a > 0 && b > 0 && c > 0) { + cout << a + b + c << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int N, M, K, desks, col, row; +int main() { + cin >> N >> M >> K; + desks = M * 2; + col = ((K - 1) / desks) + 1; + K = ((K - 1) % desks) + 1; + row = ((K - 1) / 2) + 1; + cout << col << " " << row << " " << (K % 2 == 1 ? "L" : "R") << "\n"; + return 0; +} +int main() { + long long n, m, s, f, t; + cin >> n >> m; + long long k = 0; + for (int i = 0; i < n; i++) { + cin >> s >> f >> t; + if (s == f) { + cout << t << endl; + continue; + } + k = t - t % ((m - 1) * 2); + t = t % ((m - 1) * 2); + if (f > s) { + if (t > s - 1) { + k += (m - 1) * 2 + (f - 1); + } else { + k += f - 1; + } + } else if (f < s) { + if (t > m - 1 + m - s) { + k += (m - 1) * 2 + m - 1 + m - f; + } else { + k += m - 1 + m - f; + } + } + if (k > 1e7) + cout << setprecision(8) << k << fixed << endl; + else + cout << k << endl; + } + return 0; +} +const long long mod = 1e9 + 7; +const int inf = 1000000000; +const int maxn = 300005; +const int maxa = 300005; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long powmod(long long a, long long b) { + long long res = 1; + a %= mod; + if (b < 0) return -1; + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +int INF = 10000000; +clock_t start, finish; +double duration; +int main() { + int c, v, vm, a, l; + cin >> c >> v >> vm >> a >> l; + int cnt = 0; + int now = 0; + now = v; + cnt++; + while (now < c) { + cnt++; + v = min(vm, v + a); + now += v - l; + } + cout << cnt << endl; +} +int xa, xb, ya, yb, x, y; +int main() { + cin >> xa >> ya >> xb >> yb >> x >> y; + int a = (xa - xb) / x; + int b = (ya - yb) / y; + if ((xa - xb) % x == 0 && (ya - yb) % y == 0 && (a + b) % 2 == 0) { + puts("YES"); + } else { + puts("NO"); + } + return 0; +} +int t; +long long int a; +long long int sum; +int main() { + while (cin >> t) { + sum = 0; + for (int i = 0; i < t; i++) { + cin >> a; + sum = sum + (a - 1) * i + a; + } + cout << sum << endl; + } + return 0; +} +int main() { + string str; + int n, m, x = 0, y = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> str; + for (int j = 0; j < m; j++) + if (str[j] == '*') { + x ^= i; + y ^= j; + } + } + cout << ++x << " " << ++y << "\n"; + return 0; +} +int main() { + int a1, a2, a3, a4, a5, a6; + cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6; + cout << (a1 + a2 + a3) * (a1 + a2 + a3) - a1 * a1 - a3 * a3 - a5 * a5 << endl; + return 0; +} +int main() { + int a, b, c, s1 = 0, s2 = 0, s3 = 0, i, n; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b >> c; + s1 += a; + s2 += b; + s3 += c; + } + if (s1 == 0 && s2 == 0 && s3 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int r = 0; + for (int i = 0; i < s.size(); i++) { + int x = 0, y = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == 'U') + y--; + else if (s[j] == 'D') + y++; + else if (s[j] == 'L') + x--; + else if (s[j] == 'R') + x++; + if (x == 0 and y == 0) { r++; } + } + } + cout << r << endl; + return 0; +} +char mmap[105]; +int a, d, n, f = 0, flag = 0, i, p; +int main() { + cin >> n >> d; + char c; + c = getchar(); + gets(mmap); + a = 0; + while (1) { + if (a == n - 1) break; + if (mmap[a + d] == '1' && a != 0) { + f++; + a = a + d; + } else { + for (i = a + d; i > a; i--) { + if (mmap[i] == '1') { + f++; + a = i; + goto k; + } + } + flag = 1; + break; + k:; + } + } + if (flag) + cout << -1 << endl; + else + cout << f << endl; +} +int main() { + int n, A = 0, D = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { + A++; + } else { + D++; + } + } + if (A > D) { + cout << "Anton" << endl; + } else if (A < D) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + int *count = new int[k]; + for (int i = 0; i < k; i++) { count[i] = 0; } + for (int j = 0; j < n; j++) { count[s[j] - 'A']++; } + int min = count[0]; + for (int i = 0; i < k; i++) { + if (count[i] < min) { min = count[i]; } + } + cout << min * k << endl; + return 0; +} +int main() { + long a, b, c, d, e, f, maxlevel; + cin >> a >> b >> c >> d >> e >> f; + maxlevel = b + c; + long curr = a * 2 - 1; + long sum = 0; + for (int i = 0; i < maxlevel; i++) { + if (b > 0) + curr++; + else if (b < 0) + curr--; + b--; + if (f > 0) + curr++; + else if (f < 0) + curr--; + f--; + sum += curr; + } + cout << sum << endl; + return 0; +} +long long int n; +long long int a[100007]; +int main() { + cin >> n; + long long int s = 0; + long long int t = INT_MAX; + for (long long int i = 0; i <= n - 1; i++) { + cin >> a[i]; + if (a[i] % 2 != 0 && a[i] < t) { t = a[i]; } + s += a[i]; + } + if (s % 2 != 0) { s -= t; } + cout << s << "\n"; + return 0; +} +int main() { + long long c, v0, v1, a, l, days = 0; + cin >> c >> v0 >> v1 >> a >> l; + long long sum = 0, i = 1; + sum += v0; + days++; + while (sum < c) { + if ((v0 + (i * a)) < v1) { + sum += v0 + i * a - l; + days++; + i++; + } else { + sum += v1 - l; + days++; + i++; + } + } + cout << days << endl; + return 0; +} +char bit[2]; +int x = 0; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j <= 2; j++) { cin >> bit[j]; } + if (bit[1] == '+') + ++x; + else if (bit[1] == '-') + --x; + } + cout << x << endl; + return 0; +} +int main() { + unsigned long long int n; + cin >> n; + n++; + if (n % 2 == 0) + cout << n / 2 << endl; + else if (n == 1) + cout << 0 << endl; + else + cout << n << endl; +} +int main() { + int x; + cin >> x; + int a; + int sum = 0; + for (int i = 0; i < x; i++) { + cin >> a; + sum += a; + } + int y = 0; + for (int i = sum + 1; i <= sum + 5; i++) { + if (i % (x + 1) == 1) y++; + } + cout << 5 - y << endl; +} +int main() { + int k, l, m, n, d, i, cant = 0; + cin >> k >> l >> m >> n >> d; + for (i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) cant++; + } + cout << cant << endl; + return 0; +} +int main() { + long long int x, y, z, t1, t2, t3, s, e; + cin >> x >> y >> z >> t1 >> t2 >> t3; + if (x > y) { + s = (x - y) * t1; + } else { + s = (y - x) * t1; + } + if (x >= y && x >= z) { + e = ((x - y) * t2) + ((x - z) * t2) + (3 * t3); + if (e <= s) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else if (x <= y && x >= z) { + e = ((y - x) * t2) + ((x - z) * t2) + (3 * t3); + if (e <= s) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else if (x <= y && x <= z) { + e = ((y - x) * t2) + ((z - x) * t2) + (3 * t3); + if (e <= s) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else if (x >= y && x <= z) { + e = ((x - y) * t2) + ((z - x) * t2) + (3 * t3); + if (e <= s) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +long long gcd(long long a, long long b) { + while (b) swap(a %= b, b); + return a; +} +int main() { + long long n; + cin >> n; + vector nums(n); + long long cnt = 0, g = 0; + for (long long i = 0; i < n; ++i) { + cin >> nums[i]; + if (nums[i] == 1) cnt++; + } + if (cnt != 0) { + cout << n - cnt << endl; + return 0; + } + long long dist = INT_MAX; + for (long long i = 0; i < n; ++i) { + long long g = nums[i]; + for (long long j = i + 1; j < n; ++j) { + g = gcd(g, nums[j]); + if (g == 1) dist = min(dist, j - i); + } + } + if (dist == INT_MAX) + cout << -1 << endl; + else + cout << dist + n - 1 << endl; +} +int main() { + int n, k[10000], m[10000]; + while (cin >> n) { + long long ans = 9999999999; + for (int t = 0; t < n; t++) cin >> k[t]; + for (int i = 0; i < n; i++) { + long long sum = 15 * k[i]; + int x; + for (int j = 0; j < k[i]; j++) { + cin >> x; + sum = sum + x * 5; + } + ans = min(sum, ans); + } + cout << ans << endl; + } + return 0; +} +int a[20]; +int change(int x) { + int sum = 0, k = 0; + while (x) { + a[k++] = x % 10; + x /= 10; + } + for (int i = k - 1; i >= 0; i--) + if (a[i]) sum = sum * 10 + a[i]; + return sum; +} +int main() { + int a, b; + while (cin >> a >> b) { + int t = a + b; + t = change(t); + int w = change(a) + change(b); + if (t == w) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int x1, y1, x2, y2, sub1, sub2, c; + cin >> x1 >> y1 >> x2 >> y2; + sub1 = abs(x1 - x2); + sub2 = abs(y1 - y2); + c = max(sub1, sub2); + cout << c << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int curr = 0, sp = v0, day = 0; + while (curr < c) { + curr -= l; + curr = max(0, curr); + curr += sp; + day++; + sp += a; + sp = min(sp, v1); + } + cout << day << endl; +} +int n; +long long arr[100009], c[100009], ans[100009]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + c[arr[i]]++; + } + ans[0] = 0; + ans[1] = c[1]; + for (int i = 2; i <= 100000; i++) { ans[i] = max(ans[i - 1], ans[i - 2] + i * c[i]); } + cout << ans[100000] << "\n"; +} +int a[100], b[100]; +int main() { + int n, x, s = 1, ans = 0; + cin >> n >> x; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + int i = 1, k; + while (n > 0) { + if (a[i] - s >= 0) + k = (a[i] - s) % x; + else + k = 0; + ans += k + b[i] - a[i] + 1; + s = b[i] + 1; + n--; + i++; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + if (n % 4 == 0) + cout << 0 << endl; + else if (n % 4 == 1) + cout << 1 << endl; + else if (n % 4 == 2) + cout << 1 << endl; + else + cout << 0 << endl; +} +int gcd(int x, int y) { + if (x % y == 0) return y; + return gcd(y, x % y); +} +int main() { + int a, b, n; + int l1 = 1, l2 = 1; + cin >> a >> b >> n; + while (1) { + int w1 = gcd(a, n); + n = n - w1; + if (n == 0) { + cout << 0 << endl; + return 0; + } + if (n < 0) { + l1 = 0; + break; + } + int w2 = gcd(b, n); + n = n - w2; + if (n == 0) { + cout << 1 << endl; + return 0; + } + if (n < 0) { + l2 = 0; + break; + } + } + if (l1 == 0) + cout << 0 << endl; + else + cout << 1 << endl; +} +map mp; +void init() { + mp['a'] = 1; + mp['e'] = 2; + mp['i'] = 3; + mp['o'] = 4; + mp['u'] = 5; + mp['y'] = 6; +} +int main() { + init(); + int n; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (mp[s[i]] && mp[s[i + 1]]) { + for (int j = i + 1; j < n; j++) { s[j] = s[j + 1]; } + s.erase(s.end() - 1); + i--; + n--; + } + } + cout << s << endl; +} +int main() { + string s; + cin >> s; + long long sl = s.length(); + long long i; + long long j; + long long len = s.length(); + for (i = len; i >= 0; i--) { + for (j = 0; j + i - 1 < sl; j++) { + string s1 = s.substr(j, j + i); + string s2 = s1; + reverse(s2.begin(), s2.end()); + if (s2 != s1) { + cout << i << endl; + return 0; + } + } + } + cout << 0 << endl; + return 0; +} +int main() { + cout.precision(10); + cout << fixed; + long long n; + cin >> n; + string s; + cin >> s; + long long pos = n - 1; + for (long long i = 1; i < n; i++) { + if (s[i] < s[i - 1]) { pos = min(pos, i - 1); } + } + s.erase(pos, 1); + cout << s << endl; + return 0; +} +int xx[2005]; +int find(int x) { + int sum = 0; + while (xx[x] != x) { + x = xx[x]; + sum++; + } + return sum; +} +int main() { + int n, a, b; + while (cin >> n) { + for (int i = 1; i <= n; i++) { + cin >> b; + if (b != -1) { xx[i] = b; } + } + int sum = 0; + for (int i = 1; i <= n; i++) { sum = max(sum, find(i)); } + cout << sum << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 0) { + cout << "+------------------------+" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 1) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 2) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 3) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 4) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 5) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 6) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 7) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 8) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 9) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 10) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 11) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 12) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 13) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 14) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 15) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 16) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 17) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 18) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 19) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 20) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 21) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 22) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 23) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 24) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 25) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 26) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 27) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 28) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 29) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 30) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 31) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 32) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 33) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (n == 34) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|)" << endl; + cout << "+------------------------+" << endl; + } + return 0; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int a, b, n; + cin >> a >> b >> n; + int i; + for (i = 0; n > 0; i++) { + if (i % 2 == 0) { + n -= gcd(a, n); + } else { + n -= gcd(b, n); + } + } + if (i % 2 == 0) { + cout << 1 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +long long a, b, n; +bool ans = 0; +int main() { + cin >> a >> b; + while (b > 0) { + if (b == 1) { + ans = 0; + break; + } + if (b % a != 0) { + ans = 1; + break; + } + n++; + b = b / a; + } + if (ans == 0) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else + cout << "NO" << endl; + return 0; +} +int ds[1000]; +int ss[1000]; +int main() { + int M, K; + cin >> M >> K; + for (int i = 0; i < M; i++) { cin >> ds[i]; } + for (int i = 0; i < M; i++) { cin >> ss[i]; } + int best = 0; + int time = 0; + int fuel = 0; + for (int i = 0; i < M; i++) { + fuel += ss[i]; + best = max(best, ss[i]); + time += ds[i]; + fuel -= ds[i]; + while (fuel < 0) { + time += K; + fuel += best; + } + } + cout << time << endl; + return 0; +} +int main() { + long long int n, m, a, b; + cin >> n >> m >> a >> b; + if (m * a < b) { + cout << n * a << endl; + } else { + long long int price = (n / m) * b + min((n % m) * a, b); + cout << price << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n * m; ++i) { + string s; + cin >> s; + if (s[0] == 'C' || s[0] == 'M' || s[0] == 'Y') { + cout << "#Color\n"; + return 0; + } + } + cout << "#Black&White\n"; + return 0; +} +int main() { + long int shoes[4], i, count = 0, j; + for (i = 0; i < 4; i++) { cin >> shoes[i]; } + for (i = 0; i < 4; i++) { + if (shoes[i] == 0) continue; + for (j = i + 1; j < 4; j++) { + if (shoes[i] == shoes[j]) { + count++; + shoes[j] = 0; + } + } + } + cout << count << endl; + return 0; +} +int main() { + int n, m, temp, si, fi, t, position; + cin >> n >> m; + temp = m - 1; + for (int i = 0; i < n; i++) { + bool up = false, down = false, gotodown = false, gotoup = false; + int moves = 0; + cin >> si >> fi >> t; + position = t % temp; + if (t / temp % 2) { + down = true; + position = m - position; + } else { + up = true; + position++; + } + if (si - fi > 0) + gotodown = true; + else if (si - fi < 0) + gotoup = true; + if (down == 1 && gotodown == 1) { + if (position >= si) { + moves = (position - fi); + } else { + moves = (position - 1) + temp + (m - fi); + } + } else if (down == 1 && gotoup == 1) { + moves = (position - 1) + (fi - 1); + } + if (up == 1 && gotoup == 1) { + if (position <= si) + moves = fi - position; + else { + moves = (m - position) + temp + (fi - 1); + } + } else if (up == 1 && gotodown == true) { + moves = (m - position) + (m - fi); + } + cout << moves + t << endl; + } + return 0; +} +int main() { + int n, a[100010]; + while (cin >> n) { + long long sum = 0; + int minn = 1e9; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] % 2 != 0) { + if (a[i] < minn) minn = a[i]; + } + sum += a[i]; + } + if (sum % 2 == 0) + cout << sum << endl; + else + cout << sum - minn << endl; + } + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + long long x, y, z; + cin >> x >> y >> z; + long long ans = 0; + if (y > a) { + ans += y - a; + a = 0; + } else { + a -= y; + } + if (y > b) { + ans += y - b; + b = 0; + } else { + b -= y; + } + if (x * 2 > a) ans += x * 2 - a; + if (z * 3 > b) ans += z * 3 - b; + cout << ans << endl; +} +const int N = 50 + 10, INF = 1e9 + 7; +int a, b, c; +int main() { + cin >> a >> b >> c; + cout << (min(a, min(b / 2, c / 4))) * 7 << '\n'; + return 0; +} +int main() { + int s1, s2, s3, s4, r = 0; + cin >> s1 >> s2 >> s3 >> s4; + int ara[] = {s1, s2, s3, s4}; + sort(ara, ara + 4); + for (int i = 0; i < 3; i++) { + if (ara[i] == ara[i + 1]) r++; + } + cout << r << endl; + return 0; +} +int main() { + int n, m, l, r, t; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> l >> r >> t; + int piso, z = (t - 1) % (m - 1), h = (t - 1) / (m - 1); + if (h % 2 != 0) + piso = m - 1 - z; + else + piso = z + 2; + if (t == 0) h = 0; + if (l == r) { + cout << t << endl; + continue; + } + if (h % 2 != 0) { + if (piso >= l) { + if (l >= r) + cout << t + (piso - r) << endl; + else + cout << t + (piso - 1) + (r - 1) << endl; + } else { + int aux = t + (piso - 1) + (l - 1); + if (l >= r) + cout << aux + m - l + m - r << endl; + else + cout << aux + r - l << endl; + } + } else { + if (piso <= l) { + if (l <= r) + cout << t + r - piso << endl; + else + cout << t + m - r + m - piso << endl; + } else { + int aux1 = t + m - piso + m - l; + if (l <= r) + cout << aux1 + l - 1 + r - 1 << endl; + else + cout << aux1 + l - r << endl; + } + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int b[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(a, a + n); + int c = 0; + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) c++; + } + if (c > 2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + string s; + int x, c = 0; + cin >> x >> s; + for (int i = 0; i < x; i++) { + if (s[i] == 'R') { + if (s[i + 1] == 'R') c++; + } else if (s[i] == 'G') { + if (s[i + 1] == 'G') c++; + } else if (s[i] == 'B') { + if (s[i + 1] == 'B') c++; + } + } + cout << c << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + if (m * a < b) { + cout << n * a << endl; + } else { + long long price = (n / m) * b + min((n % m) * a, b); + cout << price << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; ++i) { cout << "1 " << i << endl; } + for (int i = 2; i <= n; ++i) { cout << i << " 1" << endl; } + return 0; +} +void func1() { + int n, m; + cin >> n >> m; + cout << m + n - 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return; +} +int main() { + func1(); + return 0; +} +string t, p, T; +int a[200000]; +bool judge() { + int lt = t.length(), lp = p.length(); + int j = 0; + for (int i = 0; i < lt && j < lp; i++) { + if (T[i] == p[j]) j++; + } + if (j == lp) + return true; + else + return false; +} +int main() { + cin >> t >> p; + int l = t.length(); + for (int i = 0; i < l; i++) cin >> a[i]; + int s = 0, e = l - 1; + while (s <= e) { + int mid = (s + e) / 2; + T = t; + for (int i = 0; i <= mid; i++) { T[a[i] - 1] = ' '; } + bool flag = judge(); + if (flag) + s = mid + 1; + else + e = mid - 1; + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n, 0); + int cs = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + cs += a[i]; + } + int d = 0, minn = 1000000; + for (int i = 0; i < n; i++) { + d = a[i]; + minn = min(minn, abs(cs - 2 * d)); + for (int j = (i + 1) % n; j != i; j = (j + 1) % n) { + d += a[j]; + minn = min(minn, abs(cs - 2 * d)); + } + } + cout << minn << endl; + return 0; +} +string s, sd; +long long n, i, l; +int main() { + cin >> n; + cin >> s; + while (n != 0) { + l++; + n -= l; + } + for (i = 1; i <= l; i++) { + sd = sd + s[0]; + s.erase(0, i); + } + cout << sd << endl; + return 0; +} +int main() { + int n, k, m, x; + cin >> n >> k; + int res = 2 * n - k - 1; + for (int i = 0; i < k; ++i) { + cin >> m; + for (int j = 0; j < m; ++j) { + cin >> x; + if (j > 0 && x == j + 1) res -= 2; + } + } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int a[n + 2]; + long long int b[n + 2]; + int f = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) f++; + } + if (f <= 2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int k, d, i, j; + cin >> k >> d; + if (d == 0) { + if (k > 1) + cout << "No solution" << endl; + else + cout << 0 << endl; + return 0; + } + cout << d; + for (i = 1; i < k; i++) cout << 0; + cout << endl; +} +int main() { + int n, m; + cin >> n >> m; + int k = 1, j = n; + for (int i = 0; i < m; i++) { + string x[4]; + int v; + for (int l = 0; l < 4; l++) cin >> x[l]; + cin >> v; + if (x[2] == "left") + j = min(j, v - 1); + else if (x[2] == "right") + k = max(k, v + 1); + } + if (k > j) + cout << -1 << endl; + else + cout << j - k + 1 << endl; + return 0; +} +int main() { + int n, a, max, k, last; + cin >> n >> a >> max >> k >> last; + int count = 0; + while (true) { + n = n - a; + count++; + if (n <= 0) break; + a = a + k; + a = a > max ? max : a; + n = n + last; + } + cout << count << endl; + return 0; +} +int n, d; +string s; +int dp[105]; +const int inf = 1e9 + 7; +void solve() { + dp[0] = 0; + for (int i = 1; i <= n; ++i) { dp[i] = inf; } + for (int i = 0; i < n; ++i) { + if (s[i] != '1') { continue; } + for (int j = i + 1; j <= min(n, i + d); ++j) { + if (s[j] == '1') { dp[j] = min(dp[j], dp[i] + 1); } + } + } + dp[n - 1] == inf ? cout << "-1\n" : cout << dp[n - 1] << '\n'; +} +int main() { + cin >> n >> d >> s; + solve(); + return 0; +} +int main() { + int n, le; + cin >> n; + string s; + cin >> s; + le = s.length(); + for (int i = 0; i < s.length(); i++) { + string sub = s.substr(i, 2); + if (sub == "RU" || sub == "UR") { + s.erase(i, 1); + s[i] = 'D'; + } + } + cout << s.length() << endl; + return 0; +} +int absi(int n) { + if (n < 0) { return -1 * n; } + return n; +} +long long int absl(long long int n) { + if (n < 0) { return -1 * n; } + return n; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int p1 = a; + int p2 = (b / 2); + int p3 = (c / 4); + int mini = min(p1, min(p2, p3)); + cout << mini + (mini * 2) + (mini * 4) << '\n'; +} +int main() { + int M, a[500]; + while (cin >> M) { + for (int i = 0; i < M; i++) cin >> a[i]; + int sum = abs(180 - a[0]); + for (int i = 0; i < M - 1; i++) { + for (int j = i; j < M; j++) { + int sum1 = 0; + for (int m = i; m < j; m++) { + sum1 = sum1 + a[m]; + if ((abs(180 - sum1)) < sum) sum = abs(180 - sum1); + } + } + } + cout << sum * 2 << endl; + } + return 0; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + vector v(n + 1); + for (int i = 1; i <= n; i++) { cin >> v[i]; } + int i, flag1 = 1000, j, flag2 = 1000; + for (i = 1; i < n; i++) { + if (m + i <= n) { + if (v[m + i] <= k && v[m + i] != 0) break; + } + } + if (i < n) flag1 = i; + for (j = 1; j < n; j++) { + if (m - j >= 1) { + if (v[m - j] <= k && v[m - j] != 0) break; + } + } + if (j < n) flag2 = j; + int min = flag1 < flag2 ? flag1 : flag2; + cout << min * 10 << endl; + } + return 0; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + int x = 0; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == s[i + 1]) x++; + } + cout << x << endl; + return 0; +} +int main() { + int r, c; + cin >> r >> c; + string a[12]; + int row, col; + row = col = 0; + for (int i = 0; i < r; ++i) cin >> a[i]; + for (int i = 0; i < r; ++i) { + bool f = 1; + for (int j = 0; j < c; ++j) { + if (a[i][j] == 'S') f = 0; + } + row += f; + } + for (int j = 0; j < c; ++j) { + bool f = 1; + for (int i = 0; i < r; ++i) { + if (a[i][j] == 'S') f = 0; + } + col += f; + } + cout << row * c + col * r - row * col << "\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n == 3 || n % 4 == 0 || n % 4 == 3) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int i, x1, y1, x2, y2, o = 0, f = 0; + while (cin >> x1 >> y1 >> x2 >> y2) { + o = abs(x2 - x1); + f = abs(y2 - y1); + i = max(o, f); + cout << i << endl; + } +} +int main() { + long long int n, a, b, c; + cin >> n >> a >> b >> c; + long long int k = n % 4; + if (k == 0) { + cout << '0' << endl; + } else if (k == 3) { + if (a <= b + c && a <= 3 * c) + cout << a << endl; + else if (b + c <= 3 * c) + cout << b + c << endl; + else + cout << 3 * c << endl; + } else if (k == 2) { + if (2 * a <= b && 2 * a <= 2 * c) { + cout << 2 * a << endl; + } else if (b <= 2 * c) { + cout << b << endl; + } else + cout << 2 * c << endl; + } else if (k == 1) { + if ((3 * a <= (a + b)) && 3 * a <= c) { + cout << 3 * a << endl; + } else if (a + b <= c) { + cout << a + b << endl; + } else + cout << c << endl; + } + return 0; +} +int main() { + int Numberofstones; + string Input; + int Output = 0; + cin >> Numberofstones; + cin >> Input; + for (int i = 1; i <= Input.length(); i++) { + if (Input[i] == Input[i - 1]) { + Output++; + Input.erase(i, 1); + i = 0; + } + } + cout << Output << endl; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + cout << min(y, min(b - 1, r - 2)) * 3 + 3 << endl; + return 0; +} +const int INF = 1 << 29; +long long int x, y; +int main() { + cin >> x >> y; + while (1) { + if (x >= 2 && y >= 2) + x -= 2, y -= 2; + else if (x >= 1 && y >= 12) + x -= 1, y -= 12; + else if (y >= 22) + y -= 22; + else { + cout << "Hanako\n"; + return 0; + } + if (y >= 22) + y -= 22; + else if (x >= 1 && y >= 12) + x -= 1, y -= 12; + else if (x >= 2 && y >= 2) + x -= 2, y -= 2; + else { + cout << "Ciel\n"; + return 0; + } + } + return 0; +} +int main() { + int n, j = 1, t, sum = 0; + int a[110], b[110]; + int min = 2100000000; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + while (n--) { + for (int i = 1; i <= a[j]; i++) { + cin >> t; + sum += t * 5; + } + sum += a[j] * 15; + if (sum < min) { min = sum; } + j++; + sum = 0; + } + cout << min << endl; + return 0; +} +bool possible(string t, string p, long long *edits, long long changeIndex) { + int firstPointer = 0; + int secondPointer = 0; + while (firstPointer < t.size() && secondPointer < p.size()) { + if (t[firstPointer] == p[secondPointer] && edits[firstPointer] > changeIndex) { + firstPointer++; + secondPointer++; + } else { + firstPointer++; + } + } + return (secondPointer == p.size()); +} +int main() { + string t; + string p; + cin >> t >> p; + long long moves[t.size()]; + for (long long i = 0; i < t.size(); i++) { cin >> moves[i]; } + long long edits[t.size()]; + for (long long i = 0; i < t.size(); i++) { edits[i] = -1; } + for (long long i = 0; i < t.size(); i++) { edits[moves[i] - 1] = i; } + long long high = t.size() - 1; + long long low = 0; + if (!possible(t, p, edits, 0)) { + cout << 0 << '\n'; + return 0; + } + while (low < high) { + long long mid = low + (1 + high - low) / 2; + if (possible(t, p, edits, mid)) { + low = mid; + } else { + high = mid - 1; + } + } + cout << low + 1 << '\n'; + return 0; +} +void fillSides(vector &v) { + for (int i = 1; i < 7; i++) v.push_back(i); +} +void eraseN(vector &v, int n) { + for (int i = 0; i < ((int)(v).size()); i++) { + if (v[i] == n) { + v.erase(v.begin() + i); + break; + } + } +} +int main() { + int n, top, down; + cin >> n >> top; + for (int i = 0; i < n; i++) { + down = 7 - top; + int a, b; + cin >> a >> b; + vector v; + fillSides(v); + if (i > 0) { + eraseN(v, a); + eraseN(v, b); + eraseN(v, 7 - a); + eraseN(v, 7 - b); + if (down != v[0] && down != v[1]) return cout << "NO" << endl, 0; + if (down == v[0]) { + top = v[1]; + } else if (down == v[1]) { + top = v[0]; + } + } + } + cout << "YES" << endl; +} +const double Pi = acos(-1.0); +int main() { + int k; + cin >> k; + cout << "+------------------------+\n"; + cout << "|"; + if (k > 0) + cout << "O."; + else + cout << "#."; + int c = (k - 4) / 3; + if ((k - 4) % 3 > 0) c++; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|D|)\n"; + cout << "|"; + if (k > 1) + cout << "O."; + else + cout << "#."; + c = (k - 4) / 3; + if ((k - 4) % 3 > 1) c++; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|.|\n"; + cout << "|"; + if (k > 2) + cout << "O"; + else + cout << "#"; + cout << ".......................|\n"; + cout << "|"; + if (k > 3) + cout << "O."; + else + cout << "#."; + c = (k - 4) / 3; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|.|)\n"; + cout << "+------------------------+\n"; + return 0; +} +int n, m, i, j, a[15], b[15], t; +int main() { + cin >> n >> m; + for (i = 0; i < n; ++i) cin >> a[i]; + for (i = 0; i < m; ++i) cin >> b[i]; + sort(a, a + n); + sort(b, b + m); + for (i = 0; i < n; ++i) + for (j = 0; j < m; ++j) + if (a[i] == b[j]) { + cout << a[i] << endl; + return 0; + } + if (b[0] < a[0]) { + t = a[0]; + a[0] = b[0]; + b[0] = t; + } + cout << a[0] << b[0] << endl; + return 0; +} +int main() { + string s; + while (cin >> s) { + int len = s.length(); + int flag = 1; + for (int i = 0; i < (len / 2 + 1); i++) { + if (s[i] != s[len - i - 1]) { + flag = 0; + break; + } + } + if (flag == 0) cout << len << endl; + if (flag == 1) { + int flag2 = 1; + for (int i = 0; i < len - 1; i++) { + if (s[i] != s[i + 1]) { + flag = 0; + break; + } + } + if (flag == 0) + cout << len - 1 << endl; + else + cout << "0" << endl; + } + } + return 0; +} +int main() { + int a; + cin >> a; + while (a != 1) { + if (a % 2) { + cout << "NO\n"; + return 0; + } else { + a /= 2; + } + } + cout << "YES\n"; + return 0; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + long long c = 0, d = 0; + for (long long i = 0; i < n - 1; i++) { + if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { + i++; + c += 2; + d++; + } + } + cout << n - c + d << endl; + return 0; +} +int main() { + int n, ele, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> ele; + sum += ele; + } + int count = 5; + for (int i = 1; i <= 5; i++) { + if ((sum + i) % (n + 1) == 1) { count--; } + } + cout << count << "\n"; +} +int main() { + long long a, b, c, d, e, f, i; + cin >> a; + cin >> b; + c = a; + d = 0; + e = 0; + while (c <= b) { + if (c == b) { + d++; + break; + } + c = a * c; + e++; + } + if (d == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + cout << e << endl; + } + return 0; +} +string urut[7] = {"rat", "woman", "child", "man", "captain"}; +string nama[105], tipe[105]; +int main() { + int n; + cin >> n; + for (int a = 0; a < n; a++) { cin >> nama[a] >> tipe[a]; } + for (int a = 0; a < 5; a++) { + if (a == 2) continue; + for (int b = 0; b < n; b++) { + if (a == 1) { + if (tipe[b] == urut[a] || tipe[b] == urut[a + 1]) { cout << nama[b] << endl; } + } else if (tipe[b] == urut[a]) { + cout << nama[b] << endl; + } + } + } + return 0; +} +int main() { + int m, n, a, b, cost; + cin >> n >> m >> a >> b; + if (a > (b / m)) { + cost = (n / m) * b; + if (a * (n % m) < b) + cost += a * (n % m); + else + cost += b; + } else + cost = n * a; + cout << cost << endl; + return 0; +} +int n, i, j, arr[105], a[105], m; +int main() { + cin >> n >> m; + cout << (n + m - 1) << endl; + for (i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (i = 2; i <= n; i++) cout << i << " " << 1 << endl; +} +int main() { + long long n; + cin >> n; + long long total(0); + for (long p = 0; p < n; p++) { + long long m; + cin >> m; + total += (m - 1) * (p + 1) + 1; + } + cout << total << endl; + return 0; +} +int n, k, a, maxNum = 0, numType = 0; +int num[111]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; ++i) { + cin >> a; + num[a]++; + } + for (int i = 1; i <= 100; ++i) { + maxNum = max(maxNum, num[i]); + if (num[i] > 0) numType++; + } + maxNum = ((maxNum - 1) / k + 1) * k; + cout << maxNum * numType - n << endl; +} +int main() { + int n, sum = 0, count = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + sum = sum + temp; + } + for (int i = 1; i <= 5; i++) { + if ((sum + i) % (n + 1) != 1) count++; + } + cout << count << endl; + return 0; +} +int main() { + int a[6]; + for (int i = 0; i < 6; ++i) cin >> a[i]; + int n = a[0] + a[1]; + int l[n] = {}, r[n] = {}; + for (int i = 0; i < a[1]; ++i) l[i] = 1; + for (int i = a[1] + 1; i < n; ++i) l[i] = -1; + for (int i = 0; i < a[3]; ++i) r[i] = 1; + for (int i = a[3] + 1; i < n; ++i) r[i] = -1; + int ans = 0, step = 2 * a[2] - 1; + for (int i = 0; i < n; ++i) { + step += l[i] + r[i]; + ans += step; + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, y, z, xsum(0), ysum(0), zsum(0); + cin >> n; + while (n--) { + cin >> x >> y >> z; + xsum += x; + ysum += y; + zsum += z; + } + if (xsum == 0 && ysum == 0 && zsum == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long mn = LONG_MAX; +int main() { + long long n, k; + cin >> n >> k; + long long a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mn = min(mn, a[i]); + } + long long ans = 0; + for (int i = 0; i < n; i++) { + if ((a[i] - mn) % k != 0) + return cout << -1 << endl, 0; + else + ans += (a[i] - mn) / k; + } + cout << ans << endl; + return 0; +} +int main() { + int t; + cin >> t; + string s; + cin >> s; + for (int i = 0; i < t; i++) { + if (s[i] > s[i + 1]) { + s[i] = 1; + break; + } + } + for (int i = 0; i < t; i++) { + if (s[i] >= 'a' && s[i] <= 'z') cout << s[i]; + } + cout << endl; +} +vector v1, v2; +int main() { + long long n, k; + cin >> n >> k; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + if (i * i == n) + v1.push_back(i); + else { + v1.push_back(i); + v2.push_back(n / i); + } + } + } + if (v1.size() + v2.size() < k) + cout << -1 << endl; + else { + if (v1.size() >= k) + cout << v1[k - 1] << endl; + else { + k -= v1.size(); + cout << v2[v2.size() - k] << endl; + } + } + return 0; +} +int main() { + int N, M; + string S[100]; + vector x; + vector y; + cin >> N >> M; + for (int i = 0; i < N; i++) { + cin >> S[i]; + for (int j = 0; j < M; j++) { + if (S[i][j] == '*') { + x.push_back(i); + y.push_back(j); + } + } + } + int op = 0; + int samey, samex; + for (; op < 3; op++) { + if ((x[op] == x[(op + 1) % 3]) && (y[op] == y[(op + 2) % 3])) { + samey = (op + 2) % 3; + samex = (op + 1) % 3; + break; + } + if ((x[op] == x[(op + 2) % 3]) && (y[op] == y[(op + 1) % 3])) { + samey = (op + 1) % 3; + samex = (op + 2) % 3; + break; + } + } + cout << x[samey] + 1 << " " << y[samex] + 1 << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int d = min(a + 1, min(b, c - 1)); + cout << 3 * d << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + int s, f, t; + cin >> s >> f >> t; + if (s == f) { + cout << t << endl; + continue; + } + int mod, dist; + if (s < f) { + mod = s - 1; + dist = f - s; + } else { + mod = m * 2 - 1 - s; + dist = s - f; + } + int a = t % (2 * m - 2); + if (a <= mod) { + cout << t - a + mod + dist << endl; + continue; + } + cout << t - a + mod + dist + 2 * m - 2 << endl; + } +} +int main() { + int n, a, b, t = 0; + cin >> n; + while (n--) { + cin >> a >> b; + if (t < a) { + t = a; + } else { + while (t >= a) { a = a + b; } + t = a; + } + } + cout << t << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; i++) { + if (i != n) cout << " "; + cout << i; + } + cout << endl; + return 0; +} +long long int a[4], s; +int main() { + for (int i = 0; i < 4; i++) cin >> a[i]; + for (int i = 0; i < 4; i++) + for (int j = i + 1; j < 4; j++) + if (a[i] == a[j]) { + s++; + a[j] = -s; + } + cout << s << endl; + return 0; +} +int main() { + int a, b = 0, n, c = 0, i; + while (cin >> n) { + if (n >= 2 && n <= 200000) { + b = 0; + c = 0; + for (i = 0; i < n; i++) { + cin >> a; + if (a == 1) + b++; + else if (a == 2) + c++; + } + } + if (b - c >= 3) + cout << c + (b - c) / 3 << endl; + else + cout << min(b, c) << endl; + } + return 0; +} +bool isComposite(int n) { + if (n <= 1) return false; + if (n <= 3) return false; + if (n % 2 == 0 || n % 3 == 0) return true; + for (int i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return true; + return false; +} +int main() { + int n; + cin >> n; + for (int i = 2; i < n; i++) { + for (int j = 2; j < n; j++) { + if ((isComposite(i) && isComposite(j)) && i + j == n) { + cout << i << " " << j << endl; + return 0; + } + } + } + return 0; +} +int main() { + char s; + int h[26] = {0}; + cin >> s; + while (s != '}') { + cin >> s; + int a = (int)s; + if (a >= 97 && a <= 122) { h[a - 97]++; } + } + int c = 0; + for (int i = 0; i < 26; i++) { + if (h[i] > 0) c++; + } + cout << c << endl; + return 0; +} +int r, g, b, mmax, rs, gs, bs; +int main() { + cin >> r >> g >> b; + if (!r && !g && !b) { + cout << 0 << endl; + exit(0); + } + if (r != 0) rs = ((r - 1) / 2 * 3); + if (g != 0) gs = ((g - 1) / 2) * 3 + 1; + if (b != 0) bs = ((b - 1) / 2 * 3 + 2); + mmax = max(rs, gs); + mmax = max(mmax, bs); + cout << mmax + 30 << endl; + return 0; +} +const int MAX = 4; +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int a, b; + a = abs(z - x) * t2 + t3 * 3 + abs(x - y) * t2; + b = abs(x - y) * t1; + if (a <= b) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int maxn = 20; +bool c[maxn], r[maxn]; +int main() { + int R, C, ans = 0; + cin >> R >> C; + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + char a; + cin >> a; + if (a == 'S') { + c[j] = true; + r[i] = true; + } + } + } + for (int i = 0; i < R; i++) + for (int j = 0; j < C; j++) + if (!c[j] || !r[i]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << endl; +} +int main() { + long long n, k, i, j, c = 0, c2 = 0, m, p, q, t = 0, d; + cin >> n >> m >> k; + p = (k - 1) / 2; + long long l = (p / m) + 1; + d = (p % m) + 1; + cout << l << " " << d << " "; + if (k % 2 == 0) { + cout << "R" << endl; + } else if (k % 2 != 0) { + cout << "L" << endl; + } + return 0; +} +int main() { + int a, m; + cin >> a >> m; + set remainders; + bool ans = false; + while (true) { + int rem = a % m; + if (rem == 0 || remainders.find(rem) != remainders.end()) { + ans = (rem == 0); + break; + } + remainders.insert(rem); + a = (a + rem) % m; + } + cout << (ans ? "Yes" : "No") << endl; + return 0; +} +int main() { + int n, x(0); + cin >> n; + char s[100]; + while (n--) { + cin >> s; + if (s[1] == '+') { + ++x; + } else { + --x; + } + } + cout << x << endl; + return 0; +} +int main() { + char str[60] = {0}; + gets(str); + char shu[60] = {0}; + int i, j, k = 0, mid, len = strlen(str); + if (len % 2 == 0) { + mid = (len) / 2 - 1; + shu[k] = str[mid]; + k++; + for (i = 1; i <= len / 2; i++) { + shu[k] = str[mid + i]; + k++; + if (i != len / 2) { + shu[k] = str[mid - i]; + k++; + } + } + } else { + mid = len / 2; + shu[k] = str[mid]; + k++; + for (i = 1; i <= len / 2; i++) { + shu[k] = str[mid + i]; + k++; + shu[k] = str[mid - i]; + k++; + } + } + puts(shu); +} +const int dl = 10069; +void bib() { + for (int i = 0; i < (int)10; i++) { cout << "\a"; } +} +int main() { + int n, m; + cin >> n >> m; + cout << m + n - 1 << endl; + for (int i = 1; i <= m; i++) { cout << "1 " << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << " 1" << endl; } + return 0; +} +const int MOD = 998244353; +const int MAX = 200001; +int An[MAX]; +int book[MAX]; +int main() { + int a, b, c; + cin >> a >> b >> c; + int sum = 0; + int flag = 0; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= b; j++) { + if (j / i == 2) { + for (int k = 1; k <= c; k++) { + if (k / j == 2) { + flag = 1; + sum = 7 * i; + } + } + } + } + } + if (flag) + cout << sum << endl; + else + cout << 0 << endl; + return 0; +} +const long long MAX_SIZE = 4 * 1e5, MOD = 998244353; +void files() { + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +long long a[MAX_SIZE]; +long long n, x(0), m, temp(0); +int main() { + cin >> n >> m; + long long dish(0); + for (int i = 0; i < n; i++) { + cin >> x; + if (a[x] == 0) temp++; + a[x]++; + dish = max(dish, (a[x] - 1) / m + 1); + } + cout << m * dish * temp - n << "\n"; + return 0; +} +const int N = 1e2 + 5; +int x[N], y[N], par[N]; +int Find(int i) { + if (par[i] != i) par[i] = Find(par[i]); + return par[i]; +} +int Union(int a, int b) { + a = Find(a), b = Find(b); + if (a == b) return 0; + par[a] = b; + return 1; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x[i] >> y[i]; + par[i] = i; + } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < i; j++) { + if (x[i] == x[j] || y[i] == y[j]) ans += Union(i, j); + } + } + cout << n - ans - 1 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n % 2 != 0) { + if (k <= n / 2 + 1) { + cout << 2 * k - 1 << endl; + } else { + cout << (k - n / 2 - 1) * 2 << endl; + } + } else { + if (k <= n / 2) { + cout << 2 * k - 1 << endl; + } else { + cout << (k - n / 2) * 2 << endl; + } + } + return 0; +} +int main() { + int x = 0, n, l, w; + char s[4]; + char s1[] = "++X"; + char s2[] = "X++"; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + int l = strcmp(s, s1); + int w = strcmp(s, s2); + if (l == 0 || w == 0) { + x++; + } else + x--; + } + cout << x << endl; + return 0; +} +int vis[1000010]; +void init() { + for (int i = 2; i <= 1000010; i++) + for (int j = 2; i * j <= 1000010; j++) vis[i * j] = 1; +} +int main() { + init(); + int n; + cin >> n; + for (int i = 2; i <= n / 2; i++) + if (vis[i] && vis[n - i]) { + cout << i << " " << n - i << endl; + break; + } + return 0; +} +int n, m, b, mod, ans = 0; +int dp[505][505]; +int main() { + cin >> n >> m >> b >> mod; + dp[0][0] = 1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int j = 1; j <= m; j++) { + for (int k = x; k <= b; k++) (dp[j][k] += dp[j - 1][k - x]) %= mod; + } + } + for (int i = 0; i <= b; i++) { (ans += dp[m][i]) %= mod; } + cout << ans << endl; + return 0; +} +const int MAXN = 105; +int main() { + int N, M; + cin >> N >> M; + for (int i = 1; i <= N; i++) { + int s, f, t; + cin >> s >> f >> t; + s--; + f--; + if (s == f) { + cout << t << endl; + continue; + } + int mod = 2 * (M - 1); + int c = t % mod; + int sx = s; + int sy = (mod - sx) % mod; + int tx = (sx - c + mod) % mod; + int ty = (sy - c + mod) % mod; + int ts = 0; + if (tx < ty) { + ts += tx; + s = sx; + } else { + ts += ty; + s = sy; + } + int fx = f; + int fy = (mod - fx) % mod; + tx = (fx - s + mod) % mod; + ty = (fy - s + mod) % mod; + ts += min(tx, ty); + cout << t + ts << endl; + } + return 0; +} +int br[3]; +int main() { + int n, k, cnt = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + br[k]++; + } + if (br[1] > br[2]) { + cnt += br[2]; + br[1] -= br[2]; + if (br[1] > 2) { cnt += br[1] / 3; } + } else { + cnt = min(br[1], br[2]); + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x = 0, y = 0, z = 0, temp; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { + cin >> temp; + if (j == 0) { + x += temp; + } else if (j == 1) { + y += temp; + } else { + z += temp; + } + } + } + if (x == 0 && y == 0 && z == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + set st; + string s, p; + cin >> s; + for (int i = 0; i < s.length(); i++) { + p = s[s.length() - 1]; + s.erase(s.length() - 1); + s = p + s; + if (st.find(s) == st.end()) { st.insert(s); } + } + cout << st.size() << endl; + return 0; +} +int main() { + int x, y, z, a, b, c; + cin >> x >> y >> z >> a >> b >> c; + int stair = abs(x - y) * a; + int lift = (abs(x - z) + abs(x - y)) * b + (3 * c); + if (lift <= stair) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int q; + cin >> q; + int a[1][1000]; + for (int i = 0; i < q; i++) cin >> a[0][i]; + int b[1][1000]; + for (int i = 0; i < q; i++) { + if (a[0][i] % 7 == 0) + b[0][i] = a[0][i] / 7; + else { + b[0][i] = (a[0][i] / 7) + 1; + } + } + for (int i = 0; i < q; i++) cout << b[0][i] << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int len = 0; + int i; + for (i = 0; i < n; i++) { + if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { i += 1; } + ++len; + } + cout << len << endl; + return 0; +} +int n, a[365], c[365], ans, sum, k; +int main() { + cin >> n; + c[360] = 1; + for (int i = 0; i < 360; i++) c[i] = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + ans = 360; + for (int i = 0; i < n; i++) { + sum = sum + a[i]; + ans = min(ans, abs(sum - 180)); + while (sum > 180) { + sum -= a[k]; + k++; + ans = min(ans, abs(sum - 180)); + } + } + cout << 2 * ans << endl; + return 0; +} +const int MOD = 1000000007; +const int N = 200005; +const double PI = 4 * atan(1); +const long long MAX = 9223372036854775807; +int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; +int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; +long long gcd(long long a, long long b) { + return (b == 0 ? a : gcd(b, a % b)); +} +long long lcm(long long a, long long b) { + return a * (b / gcd(a, b)); +} +bool issquare(long long w) { + return trunc(sqrt(w)) * trunc(sqrt(w)) == w; +} +bool isprime(long long u) { + for (long long i = 2; i <= (int)sqrt(u); i++) { + if (u % i == 0) return 0; + } + return 1; +} +long long mod(long long to_mod, long long MOD) { + to_mod %= MOD; + while (to_mod < 0) to_mod += MOD; + return to_mod % MOD; +} +long long moduloMultiplication(long long a, long long b, long long mod) { + long long res = 0; + a %= mod; + while (b) { + if (b & 1) res = (res + a) % mod; + a = (2 * a) % mod; + b >>= 1; + } + return res; +} +long long power(long long x, long long y) { + long long res = 1; + x = x; + while (y > 0) { + if (y & 1) res = (res * x); + y = y >> 1; + x = (x * x); + } + return res; +} +long long n, m, x, y, res, t, k, q, z, w, l, r, ans; +long long tab[50]; +string ch; +int main() { + memset(tab, 0, sizeof(tab)); + cin >> n >> k; + cin >> ch; + for (int i = 0; i < n; i++) { tab[ch[i] - 'A']++; } + ans = 1e18; + for (int i = 0; i < k; i++) { ans = min(ans, tab[i]); } + cout << ans * k << endl; + return 0; +} +int main() { + long long int n, a[100000], sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n; i++) { sum = sum + a[i]; } + for (int i = 0; i < n; i++) { + if (sum % 2 != 0 && a[i] % 2 != 0) { sum = sum - a[i]; } + } + cout << sum << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t) { + int n; + cin >> n; + cout << n / 7 + ((n % 7) > 0) << endl; + t--; + } +} +int main() { + string temp; + while (cin >> temp) { + int s_size = temp.size(); + string ans; + if (s_size % 2 == 0) { + int pos = s_size / 2 - 1; + int times = 1; + int flag = 1; + while (pos != -1) { + ans += temp[pos]; + if (flag) { + pos += times; + flag = 0; + } else { + pos -= times; + flag = 1; + } + times++; + } + } else { + int pos = s_size / 2; + int times = 1; + int flag = 1; + while (pos != s_size) { + ans += temp[pos]; + if (flag) { + pos += times; + flag = 0; + } else { + pos -= times; + flag = 1; + } + times++; + } + } + cout << ans << endl; + } + return 0; +} +long long remv(long long n) { + long long temp = 1, sum = 0, div, mod; + while (n > 0) { + mod = n % 10; + n = n / 10; + if (mod > 0) { + sum = sum + (temp * mod); + temp = temp * 10; + } + } + return sum; +} +int main() { + long long a, b, c, n, a1, b1, c1; + cin >> a; + cin >> b; + c = a + b; + a1 = remv(a); + b1 = remv(b); + c1 = remv(c); + if (a1 + b1 == c1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long int n, k, numbers[100005]; +int main() { + long long int t = 0, min = 1e9; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> numbers[i]; + if (min > numbers[i]) { min = numbers[i]; } + } + for (int i = 1; i <= n; i++) { + if ((numbers[i] - min) % k == 0) { + t += (numbers[i] - min) / k; + } else { + t = -1; + break; + } + } + cout << t << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long ganjilterkecil = 1000000001; + long long jumlahgenap = 0; + long long jumlahganjil = 0; + int banyakganjil = 0; + for (int i = 0; i < n; i++) { + long long k; + cin >> k; + if (k % 2 == 0) { + jumlahgenap = jumlahgenap + k; + } else { + jumlahganjil = jumlahganjil + k; + banyakganjil++; + if (ganjilterkecil > k) { ganjilterkecil = k; } + } + } + if (n == 1 && jumlahgenap == 0 && banyakganjil == 1) { + cout << "0" << endl; + return 0; + } + if (banyakganjil % 2 == 0) { + cout << jumlahgenap + jumlahganjil << endl; + } else { + cout << jumlahgenap + jumlahganjil - ganjilterkecil << endl; + } +} +int main() { + string s[] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; + string t; + cin >> t; + int i, j, k, sum = 0; + for (i = 0; i < t.size(); i++) { + string res; + res += t[i]; + for (j = i + 1; j < t.size(); j++) { + res += t[j]; + for (k = 0; k < 5; k++) + if (s[k] == res) sum++; + } + } + if (sum == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + (m - 1) << "\n"; + int p = 1, j = 1, k = 1; + for (int i = 0; i < n + (m - 1); i++) { + if (i < m) { + cout << p << " " << j << "\n"; + j++; + } else { + p++; + cout << p << " " << k << "\n"; + } + } +} +int a[10], b[5005]; +int main() { + b[0] = 0; + b[1] = 1; + for (int i = 2; i < 5005; i++) { b[i] = i * i; } + int len = 0; + for (int i = 1; i <= 6; i++) { cin >> a[i]; } + int m = a[1] + a[2] + a[3]; + len = b[m] - (b[a[1]] + b[a[3]] + b[a[5]]); + cout << len << endl; + return 0; +} +int main() { + int limak, bob; + cin >> limak; + cin >> bob; + int years = 0; + while (bob >= limak) { + bob *= 2; + limak *= 3; + years++; + } + cout << years << endl; + return 0; +} +int main() { + char s[3005] = {}; + bool a[26] = {}; + gets(s); + int count = 0; + int i, j; + for (i = 0; i < strlen(s); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + int temp = s[i] - 'a'; + a[temp] = true; + } + } + for (j = 0; j < 26; j++) { + if (a[j] == true) count++; + } + cout << count << endl; + return 0; +} +int main() { + int n, m, d; + cin >> n >> m; + if (n < m) { + cout << "-1" << endl; + return 0; + } + if (n % 2 == 0) { + d = n / 2; + if (d % m == 0) + cout << d << endl; + else + cout << (d / m + 1) * m << endl; + } else { + d = n / 2 + 1; + if (d % m == 0) + cout << d << endl; + else + cout << (d / m + 1) * m << endl; + } + return 0; +} +const int maxn = 1e2 + 10; +long long x, arr[maxn], n; +long long sum, ans; +void input() { + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int i = 0; i < n; i++) { + sum = 0; + for (int j = 0; j < arr[i]; j++) cin >> x, sum += x * 5; + arr[i] *= 15; + arr[i] += sum; + } +} +int main() { + input(); + sort(arr, arr + n); + cout << arr[0] << endl; +} +int a[365]; +int main() { + int n; + cin >> n; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= n; i++) { + int k; + cin >> k; + a[i] = a[i - 1] + k; + } + int minn = 129605; + for (int i = 1; i <= n; i++) { + for (int j = i; j <= n; j++) { minn = min(minn, abs(2 * (a[j] - a[i - 1]) - 360)); } + } + cout << minn << endl; +} +int main() { + int a, b, cnt = 0; + cin >> a >> b; + while (a <= b) { + a = 3 * a; + b = 2 * b; + cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, d; + string s; + while (cin >> n >> d >> s) { + int dp[n]; + dp[0] = 0; + for (int i = 1; i < n; i++) { + dp[i] = INT_MAX; + if (s[i] == '1') { + for (int j = max(0, i - d); j < i; j++) { + if (dp[j] != INT_MAX) dp[i] = min(dp[i], dp[j] + 1); + } + } + } + if (dp[n - 1] == INT_MAX) + cout << -1 << endl; + else + cout << dp[n - 1] << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int sum = 1; + bool no = true; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) + sum++; + else + sum = 1; + if (sum >= 7) { + cout << "YES" << endl; + no = false; + break; + } + } + if (no) cout << "NO" << endl; + return 0; +} +unsigned long long N, K; +vector V; +int main() { + cin >> N >> K; + for (int i = 1; i <= sqrt(N); i++) { + if (N % i == 0) { + if (N / i == i) + V.push_back(i); + else { + V.push_back(i); + V.push_back(N / i); + } + } + } + int A = V.size(); + sort(V.begin(), V.end()); + if (K > A) + cout << -1 << '\n'; + else + cout << V[K - 1] << '\n'; +} +int main() { + long long a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + cout << (c + d + e) * (c + d + e) - (a * a) - (c * c) - (e * e) << "\n"; + return 0; +} +int n, k, a[105], h; +int main() { + cin >> n >> k >> h; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= 100; i++) { + if (k - i >= 1) + if (a[k - i] && a[k - i] <= h) { + cout << i * 10 << endl; + return 0; + } + if (k + i <= n) + if (a[k + i] && a[k + i] <= h) { + cout << i * 10 << endl; + return 0; + } + } + return 0; +} +int main() { + int n, i, sum1 = 0, sum2 = 0, sum3 = 0; + cin >> n; + int A[n], B[n], C[n]; + for (i = 0; i < n; i++) { + cin >> A[i] >> B[i] >> C[i]; + sum1 = A[i] + sum1; + sum2 = B[i] + sum2; + sum3 = C[i] + sum3; + } + if (sum1 == 0 && sum2 == 0 && sum3 == 0) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a == b) + cout << "Second" << endl; + else if (a > b) + cout << "First" << endl; + else if (b > a) + cout << "Second" << endl; + return 0; +} +long long n, k; +vector divisores; +int main() { + cin >> n >> k; + for (long long i = 1; i * i <= n; ++i) { + if (n % i == 0) { + divisores.push_back(i); + if (i * i != n) { divisores.push_back(n / i); } + } + } + sort(divisores.begin(), divisores.end()); + if (k <= (long long)divisores.size()) { + cout << divisores[k - 1] << '\n'; + } else { + cout << "-1\n"; + } + return 0; +} +int main() { + int n, i; + char a[2002]; + while (cin >> n) { + cin >> a; + int len = strlen(a); + int res = 0; + for (i = n; i < len; i += n) { + if ((a[i - 1] == a[i - 2]) && (a[i - 2] == a[i - 3])) res++; + } + cout << res << endl; + } + return 0; +} +int main() { + long long int n, sum = 0, l = 0, p = 0, x = 0; + cin >> n; + long long int a[n + 1]; + vector v; + vector v1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + v.push_back(a[i]); + } else { + v1.push_back(a[i]); + } + } + sort(v1.begin(), v1.end()); + for (int i = 0; i < v.size(); i++) { sum += v[i]; } + for (int j = 0; j < v1.size(); j++) { sum += v1[j]; } + if (v1.size() % 2 != 0) + cout << sum - v1[0] << endl; + else + cout << sum << endl; +} +bool isprime(int x) { + for (int i = 2; i * i <= x; ++i) + if (x % i == 0) return false; + return true; +} +int main() { + int n; + cin >> n; + for (int i = 4;; i += 2) + if (!isprime(n - i)) { + cout << i << ' ' << (n - i) << endl; + break; + } + return 0; +} +int main() { + int c, ddd, v0, v1, a, l, cnt = 1; + cin >> c >> v0 >> v1 >> a >> l; + c = c - v0; + while (c > 0) { + cnt++; + v0 = v0 + a; + c = c - (min(v0, v1) - l); + } + cout << cnt << endl; + return 0; +} +int pos[] = {1, 5, 13, 25, 41, 61, 85, 113}; +int num[] = {1, 3, 5, 7, 9, 11, 13, 15}; +int main() { + int x; + cin >> x; + int p = 0; + if (x == 3) { + cout << 5 << endl; + return 0; + } + while (pos[p] < x) p++; + cout << num[p] << endl; +} +long long f(string x) { + long long c = 0; + for (int i = 0; i < x.size(); i++) { + if (x[i] != '0') c = (c * 10) + (x[i] - '0'); + } + return c; +} +int main() { + long long a, b, c; + cin >> a >> b; + c = a + b; + string x = static_cast(&(ostringstream() << a))->str(); + string y = static_cast(&(ostringstream() << b))->str(); + string z = static_cast(&(ostringstream() << c))->str(); + if ((f(x) + f(y)) == f(z)) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int x, y, a, b; + while (cin >> x >> y >> a >> b) { + int n = abs(x - a); + int m = abs(y - b); + int q = max(n, m); + cout << q << endl; + } +} +int main() { + char s[100001]; + int t; + while (gets(s)) { + int flag = 1, flag_a = 0; + for (int i = 0, j = strlen(s) - 1; s[i]; i++, j--) { + if (s[i + 1] && s[i + 1] != s[i]) flag_a = 1; + if (s[i] != s[j]) flag = 0; + } + if (!flag) + cout << strlen(s) << endl; + else if (!flag_a) + cout << 0 << endl; + else + cout << strlen(s) - 1 << endl; + } +} +int main() { + int n, a = 0, d = 0; + char ch; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> ch; + if (ch == 'A') { + a++; + } else if (ch == 'D') { + d++; + } + } + if (a > d) { + cout << "Anton" << endl; + } else if (a < d) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + int x = a + b + c; + int res = (x * x) - (a * a) - (c * c) - (e * e); + cout << res << endl; + return 0; +} +const int64_t infint64_t = 9223372036854775807LL; +void solve() { + int64_t c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int64_t pagesRead = 0; + int64_t days = 0; + while (pagesRead < c) { + if (days == 0) { + pagesRead += v0; + } else { + pagesRead += min(v0 + a * days - l, v1 - l); + } + days++; + } + cout << days << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, x, sum; + int start[51], aend[51], i, j; + while (cin >> n) { + sum = 0; + cin >> x; + for (i = 1; i <= n; i++) { cin >> start[i] >> aend[i]; } + sum += (start[1] - 1) % x; + for (i = 1; i <= n - 1; i++) { + sum += aend[i] - start[i] + 1; + sum += (start[i + 1] - aend[i] - 1) % x; + } + sum += aend[n] - start[n] + 1; + cout << sum << endl; + } + return 0; +} +int main() { + vector v; + int a[4], n; + cin >> a[0] >> a[1] >> a[2] >> a[3] >> n; + v.resize(n + 1); + for (int i = 0; i < 4; i++) { + for (int j = a[i]; j < n + 1; j += a[i]) { v[j] = 1; } + } + int res = 0; + for (int i = 0; i < n + 1; i++) { + if (v[i]) res++; + } + cout << res << endl; + return 0; +} +int n, top, r, l; +int main() { + cin >> n >> top; + for (int i = 0; i < n; i++) { + cin >> r >> l; + if (r == top || l == top || 7 - r == top || 7 - l == top) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +string a[6] = {"", "Danil", "Olya", "Slava", "Ann", "Nikita"}; +string s; +inline string q(int x, int o) { + string res = ""; + int len = a[o].length(); + for (int i = 1; i <= len; i++) { res += s[x + i - 1]; } + return res; +} +int main() { + int cnt = 0; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; i++) { + for (int j = 1; j <= 5; j++) { + if (i + a[j].length() > len) { + continue; + } else { + if (a[j] == q(i, j)) { cnt++; } + } + } + if (cnt >= 2) { + cout << "NO\n"; + return 0; + } + } + if (cnt) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int n, m; +int main() { + cin >> n >> m; + if (m > n) { + cout << -1 << endl; + return 0; + } + for (int i = (int)((double)n / 2 + 0.5); i <= n; ++i) { + if (i % m == 0) { + cout << i << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string x; + cin >> x; + int a = 0, d = 0; + for (int i = 0; i < x.size(); i++) { + if (x[i] == 'D') + d++; + else if (x[i] == 'A') + a++; + } + if (a > d) { + cout << "Anton" << endl; + } else if (a < d) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int gcd(int x, int y) { + int t, t1; + if (x > y) { + t = x; + } else { + t = y; + } + for (; t >= 1; t--) { + if (x % t == 0 && y % t == 0) { + t1 = t; + break; + } + } + return t1; +} +int main() { + int a, b, n, flag = 1, s = 0, a1 = 0; + cin >> a >> b >> n; + while (1) { + if (flag % 2 == 1) { + if (n == 0) { + break; + } else { + int gcd_s = gcd(a, n); + flag++; + n = n - gcd_s; + s++; + } + } else if (flag % 2 == 0) { + if (n == 0) { + break; + } else { + int gcd_a = gcd(b, n); + flag++; + n = n - gcd_a; + a1++; + } + } + } + if (a1 >= s) { + cout << 1 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int vet[n]; + for (int i = 0; i < n; i++) { cin >> vet[i]; } + int saida = 2; + for (int i = 0; i < n - 1; i++) { + int calc = (vet[i + 1] - vet[i]) - ((2 * k) - 1); + if (calc > 2) { + saida += 2; + } else if (calc <= 2 && calc > 0) { + saida += calc; + } + } + cout << saida << endl; + return 0; +} +void solve() { + int f, r, i, j, k, l, x, y; + long long n2[201]; + string X; + n2[0] = 1; + for (long long i = 0; i < 200; i++) n2[i + 1] = (n2[i] * 2) % 1000000007; + cin >> X; + long long ret = 0; + for (long long i = 0; i < X.size(); i++) { + if (X[i] == '1') ret = (ret + n2[i] * n2[2 * (X.size() - i - 1)]) % 1000000007; + } + cout << ret << endl; +} +int main() { + solve(); + return 0; +} +int vl, vr, ml, mr; +bool judge(int g, int b) { + if (b < g - 1) + return false; + else if (b > 2 * g + 2) + return false; + else + return true; +} +int main() { + cin >> vl >> vr >> ml >> mr; + if (judge(vl, mr) || judge(vr, ml)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int x, y, z, n; + int sumx = 0, sumy = 0, sumz = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + sumx += x; + sumy += y; + sumz += z; + } + if (sumx == 0 && sumy == 0 && sumz == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +int main() { + int m, n; + while (cin >> n) { + int a, b, flag = 0, i; + cin >> m; + for (i = 1; i <= n; i++) { + cin >> a >> b; + if (m == a || m == b || m == 7 - a || m == 7 - b) flag = 1; + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int A[200010], B[200010], pos[200010], mark[200010], ans[200010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> A[i], pos[A[i]] = i; + for (int i = 0; i < n; i++) { + cin >> B[i]; + A[pos[B[i]]] = i + 1; + } + stack d; + d.push(0); + ans[0] = 0; + for (int i = 1; i < n; i++) { + while (d.size() && A[d.top()] < A[i]) d.pop(); + if (d.size()) + ans[i] = d.top(); + else + ans[i] = i; + d.push(i); + } + for (int i = 1; i < n; i++) { + mark[i] = mark[i - 1]; + if (ans[i] != i) mark[i] = 1; + } + int res = 0, cur = n - 1; + while (cur >= 0) { + res += cur - ans[cur]; + if (!mark[cur]) break; + if (cur == ans[cur]) { + res++; + cur--; + } else { + cur = ans[cur]; + } + } + cout << res << '\n'; +} +int main() { + int n, d; + cin >> n >> d; + string s; + cin >> s; + queue dist; + for (int i = 0; i < n; i++) { + if (s[i] == '1') dist.push(i); + } + int dp[n]; + fill(dp, dp + n, 1e6); + dp[0] = 0; + for (int i = 1; i < n; i++) { + while (i - d > dist.front()) dist.pop(); + if (s[i] == '1') dp[i] = min(dp[i], dp[dist.front()] + 1); + } + if (dp[n - 1] == 1e6) + cout << "-1\n"; + else + cout << dp[n - 1] << "\n"; + return 0; +} +int main() { + int n, m, r, re, t; + cin >> n >> m; + if (n < m) + cout << "-1\n"; + else if (n == m) + cout << n << "\n"; + else { + r = n / 2; + t = r; + if (n % 2 != 0) r += 1; + while (t != 0) { + if (r % m != 0) + r++, t--; + else + break; + } + if (r % m == 0) + cout << r << "\n"; + else + cout << "-1\n"; + } +} +double dist(int x1, int y1, int x2, int y2) { + return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); +} +int main() { + int n, k; + cin >> n >> k; + bool f = true; + int x1, y1, x2, y2; + double totDist; + while (n--) { + if (f) { + cin >> x1 >> y1; + f = false; + } else { + cin >> x2 >> y2; + totDist += dist(x1, y1, x2, y2); + x1 = x2; + y1 = y2; + } + } + double r = totDist * k / 50.0; + cout << fixed << r << endl; + return 0; +} +int main() { + int p; + cin >> p; + if (p == 0) { + cout << "+------------------------+" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 1) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 2) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|#.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 3) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 4) { + cout << "+------------------------+" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 5) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 6) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 7) { + cout << "+------------------------+" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 8) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 9) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 10) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 11) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 12) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 13) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 14) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 15) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 16) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 17) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 18) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 19) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 20) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 21) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 22) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 23) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 24) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 25) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 26) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 27) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 28) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 29) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 30) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 31) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 32) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 33) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" << endl; + cout << "+------------------------+" << endl; + } + if (p == 34) { + cout << "+------------------------+" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" << endl; + cout << "|O.......................|" << endl; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|)" << endl; + cout << "+------------------------+" << endl; + } + return 0; +} +int main() { + long long n, s; + cin >> n; + s = ((n + 1) * n) / 2; + if (s % 2 == 0) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int a = arr[0], b = arr[n - 1]; + int x = upper_bound(arr, arr + n, a) - arr; + int y = lower_bound(arr, arr + n, b) - arr; + if (y == 0) + cout << 0 << endl; + else + cout << y - x << endl; + return 0; +} +int n, m, ans, sum, a[1111], p[11111]; +bool used[1111]; +int main() { + cin >> n >> m; + cout << max(n, m) + min(n, m) - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << endl; } +} +const int mod = 1e9 + 7; +int main() { + int n, m, k; + cin >> n >> m >> k; + int pl = k / 2 + bool(k % 2); + int ln, dsk; + char ans; + ln = pl / m + bool(pl % m); + dsk = pl % m; + if (dsk == 0) dsk = m; + if (k % 2 == 0) + ans = 'R'; + else + ans = 'L'; + cout << ln << " " << dsk << " " << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + int arr[k] = {0}; + string s; + cin >> s; + int min = INT_MAX; + for (int i = 0; i < s.size(); i++) { arr[(int)s[i] - 65]++; } + for (int i = 0; i < k; i++) + if (min > arr[i]) min = arr[i]; + cout << min * k << endl; + return 0; +} +int main() { + int a, b, k, c1 = 0, c2 = 0; + cin >> a >> b >> k; + int h[a]; + for (int j = 1; j < a + 1; j++) cin >> h[j]; + for (int i = b; i <= a; i++) { + if (h[i] <= k && h[i] != 0) { + c1 = i - b; + break; + } + } + for (int i = b; i > 0; i--) { + if (h[i] <= k && h[i] != 0) { + c2 = b - i; + break; + } + } + if (c1 == 0) + cout << c2 * 10 << endl; + else if (c2 == 0) + cout << c1 * 10 << endl; + else if (c1 < c2) + cout << c1 * 10 << endl; + else if (c2 < c1) + cout << c2 * 10 << endl; + else + cout << c1 * 10 << endl; + return 0; +} +int main() { + int a, b, x, y; + cin >> a >> b >> x >> y; + x = abs(a - x); + y = abs(b - y); + (x > y) ? cout << x << endl : cout << y << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + for (int i = 1;; i++) { + a *= 3; + b *= 2; + if (a > b) { + cout << i << endl; + return 0; + } + } + return 0; +} +char x; +int a[30], c; +int main() { + cin >> x; + while (x != '}') { + if (x >= 97 && x <= 122) a[x - 97] = 1; + cin >> x; + } + for (int i = 0; i < 27; i++) + if (a[i] == 1) c++; + cout << c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[n], b[m]; + int t = 0; + for (int i = 0; i < n; i++) { a[i] = 0; } + for (int i = 0; i < m; i++) { b[i] = 0; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i] == 0 || b[j] == 0) { + t++; + a[i] = 1; + b[j] = 1; + } + } + } + cout << t << endl; + for (int i = 0; i < n; i++) { a[i] = 0; } + for (int i = 0; i < m; i++) { b[i] = 0; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i] == 0 || b[j] == 0) { + t++; + a[i] = 1; + b[j] = 1; + cout << i + 1 << " " << j + 1 << endl; + } + } + } + return 0; +} +const int maxn = 200005; +char s1[maxn], s2[maxn]; +int a[maxn], n, n1, ans; +bool flag[maxn]; +bool check(void) { + int p = 1; + for (int i = 1; i <= n; i++) { + if (flag[i]) continue; + if (s1[i] == s2[p]) p++; + if (p > n1) return 1; + } + return 0; +} +int main() { + cin >> s1 + 1; + cin >> s2 + 1; + n = strlen(s1 + 1); + n1 = strlen(s2 + 1); + for (int i = 1; i <= n; i++) cin >> a[i]; + int l = 0, r = n; + while (l <= r) { + memset(flag, 0, sizeof flag); + int mid = (l + r) / 2; + for (int i = 1; i <= mid; i++) flag[a[i]] = 1; + if (check()) { + ans = mid; + l = mid + 1; + } else + r = mid - 1; + } + cout << ans << endl; + return 0; +} +int main() { + int sum = 0, max1 = -1000000000, n, a, b, c, d, e, plus1, minus1; + string handels, name; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> handels; + cin >> plus1 >> minus1 >> a >> b >> c >> d >> e; + sum = a + b + c + d + e + (plus1 * 100) - (minus1 * 50); + if (sum > max1) { + max1 = sum; + name = handels; + } + } + cout << name << endl; + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (k > 1 && d == 0) { + cout << "No solution\n"; + return 0; + } + cout << d; + for (int i = 1; i < k; i++) { cout << 0; } + cout << endl; +} +int main() { + int t, x; + cin >> t; + while (t--) { + cin >> x; + if (x % 7 == 0) { + cout << x / 7 << endl; + continue; + } + if (x < 7) { + cout << 1 << endl; + continue; + } + int ans = x / 7; + if (x % 7 >= 1) ans++; + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int c = 0; + for (int i = 0; i < n; i++) { + int x = 0; + int y = 0; + for (int j = i; j < n; j++) { + if (s[j] == 'U') + x++; + else if (s[j] == 'D') + x--; + else if (s[j] == 'R') + y++; + else if (s[j] == 'L') + y--; + if (x == 0 && y == 0) c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int T = 1; + while (T--) { + int n, k; + cin >> n >> k; + vector arr(n + 1); + arr[0] = 0; + for (int i = 0; i < n; i++) { cin >> arr[i + 1]; } + long long int c = 1; + int p_i = 1; + long long int cur_d = 0, prev_d = 0, di = 0; + for (int i = 2; i <= n; i++) { + cur_d = prev_d + 1LL * arr[p_i] * (c - 1); + di = cur_d - 1LL * (n - i) * (c)*arr[i]; + if (di < k) { + cout << i << '\n'; + } else { + c++; + p_i = i; + prev_d = cur_d; + } + } + } + return 0; +} +int n, k, a[105], cnt = 0; +int main() { + memset(a, -1, sizeof(a)); + cin >> n >> k; + for (int i = 0, c; i < n; ++i) { + cin >> c; + if (a[c] == -1) ++cnt; + ++a[c]; + } + cout << k * cnt * (*max_element(a, a + 105) / k + 1) - n << endl; + return 0; +} +int main() { + double n, d, a[105], ans = 0, j = 0, aa; + cin >> n >> d; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 1; i < n; i++) { + if ((a[i] - a[i - 1]) / 2 > d) + ans = ans + 2; + else if ((a[i] - a[i - 1]) / 2 == d) + ans = ans + 1; + } + cout << ans + 2 << endl; + return 0; +} +const int N = 1e5 + 5; +int n, a[N], b[N]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = max(b[i - 1], a[i]); + } + for (int i = n - 1; i; i--) + if (a[i] < b[i]) { + for (int j = 0; j < i; j++) + if (a[j] > a[i]) { + swap(a[i], a[j]); + break; + } + break; + } + for (int i = n - 1; i; i--) + if (a[i] < a[i - 1]) return cout << "NO\n", 0; + cout << "YES\n"; + return 0; +} +int main() { + int a, b, c, d, e; + while (cin >> a >> b >> c >> d >> e) { + int ans = 0; + ans = a + b + c + d + e; + if (ans % 5 == 0 && ans != 0) + cout << ans / 5 << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + int m, n, a, b, c; + while (cin >> m >> n) { + c = 1; + for (int i = 0; i < m; i++) { + cin >> a >> b; + if (a == n || a == 7 - n || b == n || b == 7 - n) c = 0; + } + if (c) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + string s; + cin >> s; + for (int i = 0; i < N - 1; i++) { + if (s[i] != s[i + 1]) { + M++; + i++; + } + } + cout << N - M << endl; + return 0; +} +int main() { + long long n; + cin >> n; + while (n > 0) { + long long l, r, d; + cin >> l >> r >> d; + if (d > r || d < l) + cout << d << endl; + else { + cout << (r + d) - (r % d) << endl; + } + n--; + } + return 0; +} +int const OO = 1e9; +void fast() {} +void file() { + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +int main() { + fast(); + int n; + while (cin >> n) { + vector v(n), vv; + for (int i = 0; i < n; i++) { cin >> v[i]; } + vv = v; + int c = 0; + sort(vv.begin(), vv.end()); + for (int i = 0; i < n; i++) { c += (v[i] != vv[i]); } + cout << (c <= 2 ? "YES" : "NO") << '\n'; + } + return 0; +} +int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; +int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; +int main() { + int n, m; + cin >> n >> m; + int li = 0, ri = n + 1; + bool con = true; + for (int i = 0; i < m; ++i) { + string x; + string tmp; + for (int j = 0; j < 4; ++j) { + if (j == 2) + cin >> x; + else + cin >> tmp; + } + int in; + cin >> in; + if (x[0] == 'l') { + if (in < ri) { ri = in; } + } else { + if (in > li) { li = in; } + } + if (abs(li - ri) <= 1 || li > ri) { con = false; } + } + if (!con) { + puts("-1"); + return 0; + } + cout << (ri - (li + 1)) << endl; + return 0; +} +int main() { + string sequence; + getline(cin, sequence); + deque letters; + for (int i = 0; i < sequence.length(); ++i) { + while (!letters.empty() && letters.front() < sequence[i]) letters.pop_front(); + letters.push_front(sequence[i]); + } + while (!letters.empty()) { + cout << letters.back(); + letters.pop_back(); + } + cout << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int *s = new int[n]; + int *f = new int[n]; + int *t = new int[n]; + int xxx; + int ud = m + m - 2; + int x; + int k; + int control; + for (int i = 0; i < n; i++) { cin >> s[i] >> f[i] >> t[i]; } + for (int i = 0; i < n; i++) { + if (f[i] - s[i] == 0) { + cout << t[i] << "\n"; + continue; + } + k = 1; + x = t[i] % ud; + control = (t[i] + 1) % ud; + if (x - m >= 0) { + x = ud - x; + if (control - m >= 0) control = ud - control; + if (control - x < 0) k = -1; + } + x += 1; + xxx = t[i]; + if (k == 1) { + if (s[i] - x > 0) + xxx += s[i] - x; + else if (s[i] - x < 0) { + xxx += x - s[i] + 2 * (m - x); + k = -1; + } + } else if (k == -1) { + if (s[i] - x > 0) { + xxx += s[i] - x + 2 * (x - 1); + k = 1; + } else if (s[i] - x < 0) + xxx += x - s[i]; + } + if (k == 1) { + if (f[i] - s[i] > 0) + xxx += f[i] - s[i]; + else if (s[i] - f[i] > 0) + xxx += s[i] - f[i] + 2 * (m - s[i]); + } else if (k == -1) { + if (f[i] - s[i] > 0) + xxx += f[i] - s[i] + 2 * (s[i] - 1); + else if (s[i] - f[i] > 0) + xxx += s[i] - f[i]; + } + cout << xxx << "\n"; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +vector line; +int main() { + int n; + cin >> n; + int d; + cin >> d; + for (int i = int(0); i < int(n); i++) { + int a; + cin >> a; + line.push_back(a); + } + int res = 2; + for (int i = int(0); i < int(n); i++) { + if (i < (n - 1) && line[i] + d <= line[i + 1] - d) { res++; } + if (i > 0 && line[i] - d > line[i - 1] + d) { res++; } + } + cout << res << endl; + return 0; +} +int n, a[100], b[100], visit[1010], t; +int main() { + while (cin >> n) { + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + memset(visit, 0, sizeof(visit)); + t = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + int p = n; + for (int i = n - 1; i >= 0; i--) { + if (visit[a[i]] > 0) { + p--; + continue; + } + b[t++] = a[i]; + visit[a[i]]++; + } + cout << p << endl; + for (int i = t - 1; i >= 0; i--) { + cout << b[i]; + if (i != 0) cout << " "; + } + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + bool b = false; + for (int i = 0; i < n; i++) { + for (int i = 0; i < m; i++) { + char c; + cin >> c; + if ((c != 'G' && c != 'B' && c != 'W') && !b) { b = true; } + } + } + if (b) + cout << "#Color\n"; + else + cout << "#Black&White\n"; + return 0; +} +int main() { + int test, m, n, i, j, k, color = 2; + char a[105][105]; + cin >> n; + cin >> m; + for (j = 1; j <= n; j++) + for (int k = 1; k <= m; k++) cin >> a[j][k]; + for (i = 1; i <= n; i++) { + for (int k = 1; k <= m; k++) { + if (a[i][k] == 'C' || a[i][k] == 'M' || a[i][k] == 'Y') color = 1; + } + } + if (color == 1) + cout << "#Color\n"; + else + cout << "#Black&White\n"; + return 0; +} +int main() { + string s; + int n; + cin >> n; + map mp; + cin >> s; + mp['A'] = mp['D'] = 0; + for (int i = 0; i < s.size(); i++) { mp[s[i]]++; } + if (mp['D'] > mp['A']) + cout << "Danik" << endl; + else if (mp['A'] > mp['D']) + cout << "Anton" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int getAns(int a, int b, int c) { + int x[6]; + x[0] = a + (b * c); + x[1] = (a * b) + c; + x[2] = (a + b) * c; + x[3] = a * (b + c); + x[4] = a * b * c; + x[5] = a + b + c; + int i = 6; + int ans = x[0]; + while (i--) { + if (ans < x[i]) ans = x[i]; + } + return ans; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << getAns(a, b, c) << "\n"; +} +int main() { + long long n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + int cnt = 0; + while (n1 > 0 && n2 > 0) { + if (n1 > 0) { + n1 -= 1; + cnt++; + } + if (n2 > 0) { + n2 -= 1; + cnt++; + } + } + if (n1 > n2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } +} +int a[210000]; +bool check(string s1, string s2) { + int index = -1; + for (int i = 0; i < s2.length(); i++) { + index = s1.find(s2[i], index + 1); + if (index == -1) return false; + } + return true; +} +string s1, s2; +int n; +string fun(int mid) { + vector v; + for (int i = mid + 1; i <= n; i++) { v.push_back(a[i]); } + sort(v.begin(), v.end()); + string s; + for (int i = 0; i < v.size(); i++) { s += s1[v[i] - 1]; } + return s; +} +int main() { + while (cin >> s1 >> s2) { + n = s1.length(); + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int l = 1, r = n, mid; + while (r > l + 1) { + mid = (l + r) / 2; + string s = fun(mid); + if (check(s, s2)) + l = mid; + else + r = mid - 1; + } + for (int i = r;; i--) { + if (check(fun(i), s2)) { + cout << i << endl; + break; + } + } + } + return 0; +} +int arr[2005], depth[2005]; +int dfs(int i) { + if (arr[i] == -1) return 1; + if (depth[i] != 0) + return depth[i]; + else + return depth[i] = dfs(arr[i]) + 1; +} +int main() { + int TESTS = 1; + while (TESTS--) { + int n, i, ans = 0; + cin >> n; + for (long long int i = 1; i < n + 1; i++) cin >> arr[i]; + for (long long int i = 1; i < n + 1; i++) { + if (depth[i] == 0) depth[i] = dfs(i); + ans = max(ans, depth[i]); + } + cout << ans << '\n'; + } + return 0; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + gcd(b, a % b); +} +int main() { + long long int n; + while (cin >> n) { + n++; + if (n == 1) + cout << "0"; + else if (n % 2 == 0) + cout << n / 2; + else + cout << n; + cout << endl; + } +} +int n; +int p[200100]; +int b[200100]; +int vis[200200]; +void dfs(int x) { + vis[x] = 1; + if (!vis[p[x]]) dfs(p[x]); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> p[i]; + int cnt = 0; + for (int i = 1; i <= n; i++) { + cin >> b[i]; + if (b[i] == 1) cnt++; + } + int ans = 0; + if (cnt % 2 == 0) ans++; + cnt = 0; + for (int i = 1; i <= n; i++) { + if (!vis[i]) { + cnt++; + dfs(i); + } + } + if (cnt == 1) cnt = 0; + cout << ans + cnt << endl; + return 0; +} +int main() { + int n, i, c = 0; + cin >> n; + string str; + cin >> str; + for (i = 0; i < str.size() - 1; i++) { + if (str[i] == str[i + 1]) c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k = m + n - 1; + cout << k << endl; + for (int r = 1; r <= m; r++) { + cout << "1" + << " " << r << endl; + } + for (int r = 2; r <= n; r++) { + cout << r << " " + << "1" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + vector a(n); + vector c(100001); + c[0] = 0; + for (long long i = 0; i < n; i++) { + long long ar; + cin >> ar; + a[i] = ar; + c[ar]++; + } + vector dp(100001); + dp[0] = 0; + dp[1] = 1 * c[1]; + dp[2] = 2 * c[2]; + for (long long i = 3; i <= 100001; i++) { dp[i] = i * c[i] + max(dp[i - 2], dp[i - 3]); } + cout << max(dp[100001], dp[100001 - 1]) << endl; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << max(abs(x1 - x2), abs(y1 - y2)) << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + string res; + res += s[0]; + for (int i = 1; i < s.length(); i++) + if (s[i] != res[res.size() - 1]) res += s[i]; + cout << s.size() - res.size() << "\n"; +} +vector v; +int main() { + long long n, k, a, s = 0, j = 2, p, i; + cin >> n >> k; + long long m = n; + cin >> a; + for (i = 2; i <= n; i++) { + cin >> a; + p = s - (j - 1) * (m - j) * a; + if (p < k) { + v.push_back(i); + m = m - 1; + } else { + s = s + (j - 1) * a; + j = j + 1; + } + } + for (i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +int main() { + int n, i; + string s; + while (cin >> n) { + cin >> s; + int cnt = 0; + for (i = 0; i < s.size() - 1; i++) { + if (s[i] != s[i + 1]) { + cnt++; + i++; + } + } + cout << n - cnt << endl; + } + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int i; + if (a == 1) { + if (b > 1) { + cout << "-1" << endl; + } else { + cout << 'a' << endl; + } + } else { + char q = 'c'; + int pl = 0; + if (b > a || (b == 1 && a > 1)) { + cout << "-1" << endl; + } else { + for (i = 0; i < a - (b - 2); i++) { + if (pl % 2 == 0) { + pl++; + cout << 'a'; + } else { + pl++; + cout << 'b'; + } + } + for (i = 0; i < b - 2; i++) { cout << q++; } + cout << endl; + } + } + } + return 0; +} +int a[4], t, z, x, ans; +int main() { + cin >> a[1] >> a[2] >> a[3]; + z = a[1] + a[2] + a[3]; + for (int j = 1; j <= 9999; j++) { + for (int i = 1; i <= 3; i++) { + x = i; + if (a[i] >= 2) { + a[i] -= 2; + z -= 2; + ans++; + } else { + z -= a[i]; + a[i] = 0; + ans++; + } + if (z == 0) break; + } + if (z == 0) break; + } + cout << ans + 29 << endl; + return 0; +} +int main() { + int n; + int a[800]; + while (cin >> n) { + if (n == 1) { + cin >> n; + cout << 360 << endl; + continue; + } + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = n; i < 2 * n; i++) { a[i] = a[i - n]; } + for (int i = 1; i < 2 * n; i++) { a[i] = a[i] + a[i - 1]; } + int begin = 0, end, c; + int min = 1 << 20; + while (begin < n) { + end = begin + n; + for (int i = begin; i < end; i++) { + c = abs((a[i + 1] - a[begin]) - (a[end] - a[i + 1])); + if (c <= min) min = c; + } + begin++; + } + cout << min << endl; + } +} +int main() { + int time = 29, r, g, b; + cin >> r >> g >> b; + while (r > 0 || g > 0 || b > 0) { + time = time + 1; + r = r - 2; + if (r <= 0 && g <= 0 && b <= 0) { break; } + time = time + 1; + g = g - 2; + if (r <= 0 && g <= 0 && b <= 0) { break; } + time = time + 1; + b = b - 2; + if (r <= 0 && g <= 0 && b <= 0) { break; } + } + cout << time << endl; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +const int INF = 1 >> 30; +int a[100000]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) cin >> a[i]; + a[n + 1] = INF; + int p = 2; + while (a[p] > a[p - 1]) p++; + while (a[p] == a[p - 1]) p++; + while (a[p] < a[p - 1]) p++; + if (p <= n) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + long long k, l; + cin >> k >> l; + long long t = k; + int flag = 0, n = 0; + while (t <= l) { + if (t == l) flag = 1; + t = t * k; + n++; + } + if (flag == 1) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else + cout << "NO" << endl; +} +int main() { + int n, min; + string s; + cin >> n; + cin >> s; + int count = 0; + for (int i = 0; i < n; i++) { + if (s[i] == s[i - 1]) count++; + } + cout << count << "\n"; +} +int main() { + int t, a; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> a; + if (a % 7 == 0) + cout << a / 7; + else + cout << (a / 7) + 1; + cout << endl; + } +} +int main() { + int n, d; + string s; + cin >> n >> d >> s; + int pos = 0, cont = 0; + while (pos != n - 1) { + int i = d; + for (i = d; i >= 1; --i) { + if (s[pos + i] == '1') { + pos += i; + cont++; + break; + } + } + if (i == 0) { + cout << "-1\n"; + return 0; + } + } + cout << cont << endl; + return 0; +} +int main() { + long long n, m[200000] = {0}, c[200000] = {0}; + cin >> n; + set s; + for (int i = 0; i < n; i++) { + long long a; + cin >> a; + s.insert(a); + c[a]++; + } + for (int i = 1; i <= *s.rbegin(); i++) { + long long take = c[i] * i; + if (i >= 2) { take += m[i - 2]; } + m[i] = max(m[i - 1], take); + } + cout << m[*s.rbegin()] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int *arr = new int[n]; + int ans = INT_MAX; + ; + for (int i = 0; i < n; ++i) cin >> arr[i]; + for (int i = 0; i < n; ++i) { + int sum = 0; + for (int j = 0; j < arr[i]; ++j) { + int r; + cin >> r; + sum += r; + } + sum *= 5; + arr[i] *= 15; + sum += arr[i]; + ans = min(ans, sum); + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int ones = 0; + int two = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 1) + ones++; + else + two++; + } + if (ones >= two) { + int ans = two; + ones -= two; + ans += ones / 3; + cout << ans << endl; + } else { + cout << ones << endl; + } + return 0; +} +int main() { + long long int n, a[100000], b[100000], c[2] = {0}, k; + long long int i, j, sum = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + if (b[i] > c[0]) { + c[0] = b[i]; + k = i; + } + } + for (i = 0; i < n; i++) { + if (c[1] < b[i] && b[i] <= c[0] && i != k) c[1] = b[i]; + } + if (c[1] + c[0] >= sum) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, c, d, e, f, n; + cin >> a >> b >> c >> d >> e >> f; + cin >> n; + int cup = a + b + c; + int med = d + e + f; + n -= cup / 5; + n -= med / 10; + if (cup < 5 && cup != 0) n--; + if (med < 10 && med != 0) n--; + if (cup > 5 && cup % 5 > 0) n--; + if (med > 10 && med % 10 > 0) n--; + cout << ((n < 0) ? "NO" : "YES") << endl; + return 0; +} +string a, b; +int main() { + int n; + cin >> n; + string s; + cin >> s; + int len = s.size(); + for (int i = 0; i < len; i++) { + if (s[i] == 'U' && s[i + 1] == 'R') { + a.push_back('D'); + i++; + } else if (s[i] == 'R' && s[i + 1] == 'U') { + a.push_back('D'); + i++; + } else + a.push_back(s[i]); + } + for (int i = len - 1; i >= 0; i--) { + if (s[i] == 'U' && s[i - 1] == 'R') { + b.push_back('D'); + i--; + } else if (s[i] == 'R' && s[i - 1] == 'U') { + b.push_back('D'); + i--; + } else + b.push_back(s[i]); + } + cout << min(a.size(), b.size()) << endl; +} +int n; +int a[400]; +int dp[400]; +int main() { + while (cin >> n) { + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 360; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int t = 0; + for (int k = 0; k < j; k++) { t += a[(i + k) % n]; } + ans = min(ans, abs(360 - t - t)); + } + } + cout << ans << endl; + } +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k, l = 0; + long long n, m, s = 0; + int r, g, b; + cin >> r >> g >> b; + r = (r + 1) / 2; + g = (g + 1) / 2; + b = (b + 1) / 2; + if (r > max(g, b)) + cout << (r - 1) * 3 + 30 << endl; + else if (g >= max(r, b) && g > b) + cout << (g - 1) * 3 + 31 << endl; + else if (b >= max(r, g)) + cout << (b - 1) * 3 + 32 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (k <= (n + 1) / 2) { + cout << k * 2 - 1 << endl; + } else { + cout << (k - (n + 1) / 2) * 2 << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + if (!b) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return b / gcd(a, b) * a; +} +int n, k, cur; +int ret; +int c[1000], d[1000], m; +int main() { + cin >> n >> k; + for (int(i) = 0; i < int(n); ++i) cin >> d[i]; + for (int(i) = 0; i < int(n); ++i) cin >> c[i]; + for (int i = 0; i < n; ++i) { + cur += c[i]; + m = max(m, c[i]); + while (cur < d[i]) { + cur += m; + ret += k; + } + ret += d[i]; + cur -= d[i]; + } + cout << ret << endl; + cin >> n; +} +int main() { + long long a, b; + cin >> a >> b; + long long x, y, z; + cin >> x >> y >> z; + long long reala = 2 * x + y, realb = y + 3 * z; + cout << max(reala - a, 0ll) + max(realb - b, 0ll) << endl; +} +int main() { + string c; + cin >> c; + string amigos[] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; + long long cant = 0; + for (long long i = 0; i < (long long)5; i++) { + int found = c.find(amigos[i]); + if (found != -1) { + cant++; + if (c.find(amigos[i], found + 1) != -1) cant++; + } + } + if (cant == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int num; + while (cin >> num) { + int ara[num], counter = 0; + for (int i = 0; i < num; i++) cin >> ara[i]; + bool f1, f2, f3; + f1 = f2 = f3 = false; + for (int i = 1; i < num; i++) { + if (ara[i] > ara[i - 1]) { + if (f1 == false) { + counter += 1; + f1 = true; + } + if (f2 == true || f3 == true) counter = 1000; + f2 = f3 = false; + } else if (ara[i] == ara[i - 1]) { + if (f2 == false) { + counter += 1; + f2 = true; + } + if (f3 == true) counter = 1000; + f1 = f3 = false; + } else { + if (f3 == false) { + counter += 1; + f3 = true; + } + f2 = f1 = false; + } + } + if (counter > 3) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +vector divs; +int main() { + long long n, k; + cin >> n >> k; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + divs.push_back(i); + if (n / i != i) divs.push_back(n / i); + } + } + sort(divs.begin(), divs.end()); + if (k > divs.size()) + cout << -1 << '\n'; + else + cout << divs[k - 1] << '\n'; +} +int main() { + long long n, k, p; + cin >> n >> k >> p; + long long pe[1001], ke[2002]; + for (int a = 0; a < n; a++) cin >> pe[a]; + for (int a = 0; a < k; a++) cin >> ke[a]; + sort(pe, pe + n); + sort(ke, ke + k); + long long mins = 99999999999999; + for (int a = 0; a < k - n + 1; a++) { + long long tmp = 0; + for (int b = 0; b < n; b++) tmp = max(tmp, abs(pe[b] - ke[a + b]) + abs(ke[a + b] - p)); + mins = min(tmp, mins); + } + cout << mins << endl; + return 0; +} +int main() { + int i, j, k = 0, l, a, b, c, m, n; + cin >> n; + int s[1005]; + int d[1005]; + for (i = 1; i <= n; i++) { + cin >> s[i] >> d[i]; + if (k < s[i]) { + k = s[i]; + } else { + l = k - s[i]; + if (l % d[i] == 0) { + l = l / d[i]; + } else { + l = l / d[i] + 1; + } + k = s[i] + l * d[i]; + } + k = k + 1; + } + k = k - 1; + cout << k << endl; + return 0; +} +vector v; +long long tc, n, x1, x2, y11, y2, x, y, i, j, k, l; +string s; +int main() { + cin >> x1 >> y11 >> x2 >> y2 >> x >> y; + i = abs(x1 - x2); + j = abs(y11 - y2); + if (i % x || j % y) { + cout << "NO\n"; + return 0; + } + i = i / x; + j = j / y; + if (abs(i - j) % 2) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int len = 0; + for (int i = 0; i < n; i++) { + for (int j = 1; j <= n - i; j++) { + string t = s.substr(i, j); + int m = t.size(); + int ok = true; + for (int k = 0; k < m; k++) { + if (t[k] != t[m - 1 - k]) ok = false; + } + if (!ok) len = max(len, m); + } + } + cout << len << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int tempa, tempb, tempc; + tempa = a; + tempb = b / 2; + tempc = c / 4; + int temp = min(tempa, tempb); + int s = min(temp, tempc); + cout << s * 7 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 4 == 3 || n % 4 == 0) + cout << 0; + else + cout << 1; + cout << '\n'; + return 0; +} +int n; +int d, a[110]; +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int ans = 2; + for (int i = 2; i <= n; i++) { + if (a[i] - a[i - 1] >= 2 * d + 1) { ans += 2; } + if (a[i] - a[i - 1] == 2 * d) { ans++; } + } + cout << ans << endl; +} +char s[1000][500]; +int b[1000]; +int main() { + int n; + char kd[500]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i] >> kd; + if (strcmp(kd, "rat") == 0) + b[i] = 1; + else if (strcmp(kd, "man") == 0) + b[i] = 3; + else if (strcmp(kd, "captain") == 0) + b[i] = 4; + else + b[i] = 2; + } + int k = 1, t = 0; + while (t < n) { + for (int j = 0; j < n; j++) { + if (b[j] == k) { + cout << s[j] << endl; + t++; + b[j] == -1; + } + } + k++; + } +} +int a[105]; +int main() { + int n, m; + cin >> n >> m; + int ans = n + m - 1; + cout << ans << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n, k; + cin >> n >> k; + int flag = 0; + for (int i = 0; i < (n / k); i++) { + for (int j = 0; j < k; j++) { + cout << char(97 + j); + flag = j; + } + } + for (int i = 0; i < n - (n / k) * k; i++) { cout << char(97 + flag); } + cout << endl; + } +} +int main() { + int c, v0, v1, a, l; + int Day = 0; + int Page_Sum = 0; + cin >> c >> v0 >> v1 >> a >> l; + while (Page_Sum < c) { + Page_Sum += v0; + Day++; + if (Day > 1) Page_Sum -= l; + v0 += a; + if (v0 > v1) v0 = v1; + } + cout << Day << endl; + return 0; +} +int main() { + char arr[50]; + int line, cont = 0; + cin >> line; + for (int i = 0; i < line; ++i) { cin >> arr[i]; } + for (int i = 0; i < line - 1; ++i) { + if (arr[i] == arr[i + 1]) cont++; + } + cout << cont << endl; + return 0; +} +vector s; +int main() { + s.push_back("Danil"); + s.push_back("Olya"); + s.push_back("Slava"); + s.push_back("Ann"); + s.push_back("Nikita"); + string a; + cin >> a; + int res = 0; + for (int i = 0; i < 5; i++) { + if (a.find(s[i]) != a.npos) { + res++; + if (a.rfind(s[i]) != a.find(s[i])) { res++; } + } + } + if (res == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int pntr = s.size() - 1; + char c; + for (int i = 0; i < s.size() / 2; i++) { + if (s[i] != s[pntr]) { + bool b = true; + int pntr2 = pntr; + for (int j = i + 1; j < (s.size() + 1) / 2; j++) + if (s[j] != s[pntr2]) { + b = false; + } else + pntr2--; + if (b) { + c = s[i]; + for (int j = 0; j < s.size(); j++) { + cout << s[j]; + if (j == pntr) cout << c; + } + cout << endl; + return 0; + } + pntr2 = pntr - 1; + b = true; + for (int j = i; j < (s.size() + 1) / 2; j++) + if (s[j] != s[pntr2]) { + b = false; + } else + pntr2--; + if (b) { + c = s[pntr]; + for (int j = 0; j < s.size(); j++) { + if (j == i) cout << c; + cout << s[j]; + } + cout << endl; + return 0; + } + cout << "NA" << endl; + return 0; + } else + pntr--; + } + if (s.size() % 2) { + for (int i = 0; i < s.size(); i++) + if (i == (s.size()) / 2) + cout << s[i] << s[i]; + else + cout << s[i]; + cout << endl; + } else { + for (int i = 0; i < s.size(); i++) + if (i == (s.size() / 2)) + cout << "a" << s[i]; + else + cout << s[i]; + cout << endl; + } +} +int main() { + int n, m, i, j; + while (cin >> n >> m) { + int now = 1, time = 0, a, b; + for (i = 0; i < n; i++) { + cin >> a >> b; + while (now + m <= a) now += m; + time += b - now + 1; + now = b + 1; + } + cout << time << endl; + } + return 0; +} +int n, m, k, r1, r2; +char c; +int main() { + cin >> n >> m >> k; + if (k % 2) { + c = 'L'; + ++k; + } else { + c = 'R'; + } + k /= 2; + r1 = k / m; + if (k % m != 0) { ++r1; } + r2 = k % m; + if (r2 == 0) { r2 = m; } + cout << r1 << " " << r2 << " " << c; + cout << endl; + return 0; +} +int main() { + int a1, a2, a3; + int b2, b1, b3; + int n; + cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3; + int total = (a1 + a2 + a3 + 4) / 5 + (b1 + b2 + b3 + 9) / 10; + cin >> n; + if (total <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +vector s; +int main() { + s.push_back("Danil"); + s.push_back("Olya"); + s.push_back("Slava"); + s.push_back("Ann"); + s.push_back("Nikita"); + string a; + cin >> a; + int ans = 0; + for (int i = 0; i < 5; i++) { + if (a.find(s[i]) != a.npos) { + ans++; + if (a.rfind(s[i]) != a.find(s[i])) ans++; + } + } + if (ans == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, i, j; + cin >> n >> m; + cout << m + (n - 1) << "\n"; + for (i = 1; i <= m; i++) { cout << "1 " << i << "\n"; } + for (i = 2; i <= n; i++) { cout << i << " 1\n"; } +} +string a[20], b[20]; +string s, s1; +int n, r, cnt, sum, flag; +int main() { + cin >> n >> r; + for (int i = 0; i < n; i++) { + cin >> s; + if (s.find('S') == -1) { + cnt++; + sum += r; + continue; + } else { + a[i - cnt] = s; + } + } + for (int j = 0; j < r; j++) { + for (int u = 0; u < n; u++) { s1 += a[u][j]; } + if (s1.find('S') == -1) { + sum += n - cnt; + continue; + } + s1 = ""; + } + cout << sum << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int tira = n - k; + int certos = 0; + for (int i = 0; i < k; i++) { + int t; + cin >> t; + for (int j = 0; j < t; j++) { + int a; + cin >> a; + if (j + 1 == a && j != 0) { + tira--; + certos++; + } + } + } + cout << tira + n - 1 - certos << endl; + return 0; +} +int main() { + int s; + cin >> s; + int a[s]; + for (int i = 0; i < s; i++) cin >> a[i]; + sort(a, a + s); + if (s == 1 || s == 2) { + cout << "0" << endl; + return 0; + } + int t = s - 2; + for (int i = 1; i < s - 1; i++) { + if (a[i] > a[0] && a[i] < a[s - 1]) + continue; + else + t--; + } + cout << t << endl; + return 0; +} +int main() { + string s; + cin >> s; + int N = s.length(); + char maxsuff[N]; + maxsuff[N - 1] = s[N - 1]; + for (int i = N - 2; i >= 0; --i) { maxsuff[i] = max(maxsuff[i + 1], s[i]); } + for (int i = 0; i < N; ++i) { + if (s[i] == maxsuff[i]) cout << s[i]; + } + cout << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (m > n) { + cout << -1 << endl; + return 0; + } + int j = (int)((double)n / 2 + 0.5); + for (int i = j; i <= n; ++i) { + if (i % m == 0) { + cout << i << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int u, v, w, p; + cin >> u >> v >> w; + if (w < u || w > v) { + cout << w; + } else { + if (w > u || w <= v) { + p = v / w; + w = (p + 1) * w; + cout << w; + } + } + cout << endl; + } +} +int v[10]; +int get(int a, int b) { + memset(v, 0, sizeof(v)); + v[a] = v[7 - a] = 1; + v[b] = v[7 - b] = 1; + for (int i = 1; i < 7; ++i) { + if (!v[i]) return i; + } +} +int main() { + int n; + while (cin >> n) { + int u; + cin >> u; + int a, b; + cin >> a >> b; + int t = get(a, b); + int f = 0; + for (int i = 1; i < n; ++i) { + cin >> a >> b; + if (get(a, b) - t) { + cout << "NO" << endl; + f = 1; + return 0; + } + } + cout << "YES" << endl; + } + return 0; +} +int main() { + char c; + set str; + while (cin >> c) { + if (isalpha(c)) str.insert(c); + } + cout << str.size() << endl; +} +int main() { + int n1, n2, k1, k2; + while (cin >> n1 >> n2 >> k1 >> k2) { + if (n1 > n2) + cout << "First" << endl; + else if (n1 <= n2) { + cout << "Second" << endl; + } + } +} +int main() { + bool vis[2][16] = {0}; + int n, m; + cin >> n >> m; + char ch; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> ch; + if (ch == 'S') vis[0][i] = 1, vis[1][j] = 1; + } + int chn = n, chm = m, ans; + for (int i = 0; i < n; i++) + if (vis[0][i] == 1) chn--; + for (int i = 0; i < m; i++) + if (vis[1][i] == 1) chm--; + ans = (chn * m) + (chm * n) - (chn * chm); + cout << ans << endl; + return 0; +} +int cnt[101]; +int main() { + int n, k, c1 = 0, c2 = 0; + cin >> n >> k; + for (int a, i = 1; i <= n; i++) { + cin >> a; + cnt[a]++; + if (cnt[a] == 1) c1++; + } + for (int i = 1; i <= 100; i++) c2 = max(c2, (cnt[i] + k - 1) / k); + cout << c1 * c2 * k - n << endl; + return 0; +} +const int MAXN = 210; +const long long MOD = 1000 * 1000 * 1000 + 7; +long long stab(long long a) { + return ((a % MOD) + MOD) % MOD; +} +int n; +long long st2[MAXN]; +string str; +int main() { + st2[0] = 1; + for (int i = 1; i < MAXN; ++i) { st2[i] = stab(st2[i - 1] * 2LL); } + cin >> str; + n = str.size(); + long long ans = 0; + reverse(str.begin(), str.end()); + for (int i = 0; i < n; ++i) { + if (str[i] - '0' == 1) { ans = stab(ans + st2[n + i - 1]); } + } + cout << ans << endl; + return 0; +} +int main() { + long long a, b, ans = 0; + cin >> a >> b; + long long a1, a2, a3; + cin >> a1 >> a2 >> a3; + a -= a1 * 2; + a -= a2; + b -= a2; + b -= 3 * a3; + if (a < 0) ans += a; + if (b < 0) ans += b; + cout << -ans << endl; + ; +} +int main() { + int n, m; + cin >> n >> m; + cout << n - 1 + m << '\n'; + for (int i = 1; i <= m; i++) { cout << '1' << ' ' << i << endl; } + for (int i = 2; i <= n; i++) cout << i << ' ' << 1 << endl; +} +const int MAXN = 100100; +const long long INF = 0x3f3f3f3f; +long long v[MAXN]; +int main() { + long long n; + cin >> n; + long long m = INF; + long long soma = 0; + for (long long i = 1; i <= n; i++) { + long long x; + cin >> x; + soma += x; + if (x % 2 == 1) m = min(x, m); + } + if (soma % 2 == 0) + cout << soma << endl; + else + cout << soma - m << endl; +} +const int INF = 0x3f3f3f3f; +long long a[200000 + 5]; +int main() { + long long i, j, k, l, r, co = 0; + long long n, m, t; + cin >> n >> k; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 0; i < n; i++) { + if ((a[i] - a[0]) % k) { + cout << -1 << endl; + return 0; + } + co += (a[i] - a[0]) / k; + } + cout << co << endl; + return 0; +} +int main() { + string s; + cin >> s; + int sz = s.length(); + int arr[sz]; + char ch = 'a'; + int prev; + for (int i = sz - 1; i >= 0; i--) { + if (s[i] >= ch) { + arr[i] = i; + prev = i; + ch = s[i]; + } else { + arr[i] = prev; + } + } + for (int i = 0; i < sz; i++) { + cout << s[arr[i]]; + i = arr[i]; + } + cout << "\n"; + return 0; +} +char a[100005]; +int main() { + int n, tot = 0, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'A') { + tot++; + } else if (a[i] == 'D') { + ans++; + } + } + if (ans > tot) { + cout << "Danik" << endl; + } else if (ans < tot) { + cout << "Anton" << endl; + } else if (ans == tot) { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int n, m, ele, min1 = 1000000, min2 = 1000000, store = 1000000; + cin >> n >> m; + int arr[n]; + int arr2[m]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] < min1) { min1 = arr[i]; } + } + for (int i = 0; i < m; i++) { + cin >> arr2[i]; + if (arr2[i] < min2) { min2 = arr2[i]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (arr[i] == arr2[j] && arr[i] < store) { store = arr[i]; } + } + } + if (store == 1000000) { + if (min1 > min2) { + cout << min2 * 10 + min1; + } else { + cout << min1 * 10 + min2; + } + } else { + cout << store; + } + cout << "\n"; +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1.0); +const long long MOD = (long long)1e9 + 7; +void base() {} +int main() { + int n; + cin >> n; + string ans, str; + int a, b, aa, bb, cc, dd, ee, now = 0, largest = -INF; + for (int i = 0; i < n; i++) { + cin >> str >> a >> b >> aa >> bb >> cc >> dd >> ee; + int now = 100 * a - 50 * b + aa + bb + cc + dd + ee; + if (now > largest) { + ans = str; + largest = now; + } + } + cout << ans << endl; + return 0; +} +bool a[301]; +int main() { + int n, k; + cin >> k >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (!a[x % k]) { + a[x % k] = true; + } else { + cout << i << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int i, n, c = 0; + string arr; + cin >> n; + for (i = 0; i < n; i++) { + cin >> arr; + if (arr[0] == '+' || arr[1] == '+') { + c++; + } else if (arr[0] == '-' || arr[1] == '-') { + c--; + } + } + cout << c << endl; + return 0; +} +int main() { + char str[60], ori[60] = {'\0'}; + int i, j, len; + gets(str); + len = strlen(str); + if (len % 2 == 0) { + ori[0] = str[len / 2 - 1]; + for (i = 1; str[len / 2 + i] != '\0'; i++) { + ori[2 * i - 1] = str[len / 2 - 1 + i]; + ori[2 * i] = str[len / 2 - 1 - i]; + } + ori[2 * i - 1] = str[len / 2 - 1 + i]; + } else { + ori[0] = str[len / 2]; + for (i = 1; str[len / 2 + i] != '\0'; i++) { + ori[2 * i - 1] = str[len / 2 + i]; + ori[2 * i] = str[len / 2 - i]; + } + } + puts(ori); + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) + cout << "First" << endl; + else + cout << "Second" << endl; +} +int compote(int a, int b, int c) { + if (a >= 1 && b >= 2 && c >= 4) + return 7 + compote(a - 1, b - 2, c - 4); + else + return 0; +} +int main() { + int a, b, c, ans; + cin >> a >> b >> c; + ans = compote(a, b, c); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int bus[4][11] = {0}; + int ind = 10; + while (n > 0) { + bool flg = 0; + if (ind == 10) { + } else { + flg = 1; + } + for (int i = 0; i < 4; i++) { + if (flg && i == 2) continue; + if (n == 0) break; + bus[i][ind] = 1; + n--; + } + ind--; + } + string s = "+------------------------+"; + cout << s << endl; + for (int i = 0; i < 4; i++) { + cout << "|"; + for (int j = 10; j >= 0; j--) { + if (bus[i][j]) + cout << "O."; + else if (i == 2) { + if (j == 10) + cout << "#."; + else + cout << ".."; + } else + cout << "#."; + } + if (i == 0) { + cout << "|D|)"; + } else if (i == 3) { + cout << "|.|)"; + } else if (i == 2) { + cout << "..|"; + } else { + cout << "|.|"; + } + cout << endl; + } + cout << s << endl; + return 0; +} +int main() { + string s; + cin >> s; + if (s[0] >= 97 && s[0] <= 122) s[0] -= 32; + cout << s << endl; + return 0; +} +int main() { + int a, b, li, lin; + while (cin >> a) { + li = lin = 0; + for (int i = 0; i < a; i++) { + cin >> b; + if (b == 1) li++; + if (b == 2) lin++; + } + if (li > lin) + cout << lin + (li - lin) / 3 << endl; + else + cout << li << endl; + } +} +int main() { + long long int n, k, mid; + cin >> n >> k; + mid = ceil(n / 2.0); + if (k <= mid) { + cout << (k * 2) - 1 << endl; + } else { + cout << (k - mid) * 2 << endl; + } +} +int i, j, c, v0, v1, a, p, s = 0, t = 0; +int main() { + cin >> c >> v0 >> v1 >> a >> p; + while (s != c) { + t++; + if (t != 1) s -= p; + s += v0; + if (s > c) s = c; + v0 += a; + if (v0 > v1) v0 = v1; + } + cout << t << endl; +} +int n, k; +char s[105]; +int main() { + cin >> n >> k >> (s + 1); + int ans = 0, i = 1; + while (i <= n) { + int j = i + k; + if (j > n) { + ans++; + break; + } + bool ok = false; + for (; j > i; j--) + if (s[j] == '1') { + ans++; + ok = true; + i = j; + break; + } + if (i == n) break; + if (!ok) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, a, b; + cin >> n >> x; + int begin = 1; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + while (a - begin >= x) { begin += x; } + sum += b - begin + 1; + begin = b + 1; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + string s; + cin >> s; + int num = 0; + for (int i = 0; i < s.length(); i++) + if (s[i] == 'A') num++; + if (n - num > num) + cout << "Danik" << endl; + else if (n - num < num) + cout << "Anton" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + int count = 0; + for (int i = 1; i <= d; i++) { + if (i % k == 0) { + continue; + } else if (i % l == 0) { + continue; + } else if (i % m == 0) { + continue; + } else if (i % n == 0) { + continue; + } else { + count++; + } + } + cout << (d - count) << endl; + return 0; +} +int main() { + int a, b, c, d; + int n; + cin >> n; + cin >> a >> b >> c; + int lala = a; + int haha = 7 - a; + int logal = 0; + for (int i = 2; i <= n; i++) { + cin >> a >> b; + if (a == lala || a == haha || b == lala || b == haha) logal = 1; + } + if (logal == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +void solve(int n, int m, int ans) { + int steps1 = n - (2 * ans); + int steps2 = (2 * ans); + if ((steps2 + steps1) == n && (ans + steps1) % m == 0) { + cout << ans + steps1 << endl; + return; + } else { + solve(n, m, ans - 1); + } +} +int main() { + int n, m; + cin >> n >> m; + if (n < m) + cout << "-1" << endl; + else + solve(n, m, (n >> 1)); +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; +} +int a[15] = {0}; +int main() { + int n, m, i, j = 1, k, l, p; + cin >> n; + l = n; + k = n / 3; + if (n <= 4) { + a[0] = n; + n -= n; + } else { + a[0] = 4; + n -= 4; + } + while (1) { + if (3 > n) { + a[j] = n; + if (n != 0) j++; + break; + } + a[j] = 3; + n -= 3; + j++; + } + p = j; + cout << "+------------------------+" << endl; + for (i = 0; i < 4; i++) { + cout << "|"; + for (j = 0; j < 11; j++) { + if (i == 2 && l < 3) { + cout << "#"; + break; + } + if (i == 2 && l > 2) { + a[j]--; + cout << "O"; + break; + } + if (a[j] != 0 && j < p) { + cout << "O."; + a[j]--; + } else { + cout << "#."; + } + } + if (i == 0) cout << "|D|)" << endl; + if (i == 1) cout << "|.|" << endl; + if (i == 2) cout << ".......................|" << endl; + if (i == 3) cout << "|.|)" << endl; + } + cout << "+------------------------+" << endl; +} +int main() { + int a1, a2, a3, b1, b2, b3, k; + cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> k; + int sum1 = (a1 + a2 + a3 + 4) / 5; + int sum2 = (b1 + b2 + b3 + 9) / 10; + if (sum1 + sum2 <= k) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +string s; +int main() { + while (cin >> s) { + int flag = 1; + for (int i = 0, j = (int)s.length() - 1; i <= j; i++, j--) { + if (s[i] != s[j]) { + flag = 0; + break; + } + } + if (!flag) { + cout << s.length() << '\n'; + } else { + flag = 1; + for (int i = 1; i < s.length(); i++) { + if (s[i] != s[0]) { + flag = 0; + break; + } + } + if (flag) { + cout << 0 << '\n'; + } else { + cout << s.length() - 1 << '\n'; + } + } + } + return 0; +} +int main() { + int n; + cin >> n; + int k = log2(n); + if (1 << k == n) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + int n, m; + bool ans = true; + cin >> n >> m; + char c; + for (int j = 0; j < n; j++) + for (int i = 0; i < m; i++) { + cin >> c; + if (c == 'C' || c == 'Y' || c == 'M') { ans = false; } + } + if (ans) { + cout << "#Black&White\n"; + } else { + cout << "#Color\n"; + } + return 0; +} +int main() { + int k; + cin >> k; + string s[6]; + s[0] = "+------------------------+"; + s[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + s[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + s[3] = "|#.......................|"; + s[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + s[5] = "+------------------------+"; + int idx = 0; + while (k) { + for (int i = 0; i < 6; i++) + if (s[i][idx] == '#') { + k--; + s[i][idx] = 'O'; + if (!k) break; + } + idx++; + } + for (int i = 0; i < 6; i++) cout << s[i] << endl; +} +int n, a1 = 0, a2 = 0; +char ch; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> ch; + if (ch == 'A') { + ++a1; + } else { + ++a2; + } + } + if (a1 > a2) + cout << "Anton" << endl; + else if (a2 > a1) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int n, i, j, arr[1000]; + while (cin >> n) { + string s1[n], s2; + for (i = 0; i < n; i++) { + cin >> s1[i] >> s2; + if (s2 == "rat") { + arr[i] = 0; + } else if (s2 == "woman" || s2 == "child") { + arr[i] = 1; + } else if (s2 == "man") { + arr[i] = 2; + } else + arr[i] = 3; + } + for (j = 0; j < 4; j++) { + for (i = 0; i < n; i++) { + if (arr[i] == j) { cout << s1[i] << endl; } + } + } + } + return 0; +} +int main() { + int a, b, c, d, e, sum; + cin >> a >> b >> c >> d >> e; + sum = a + b + c + d + e; + if (sum > 0 && sum % 5 == 0) { + cout << sum / 5 << endl; + } else + cout << "-1" << endl; +} +int main() { + int n; + int a[105]; + while (cin >> n) { + for (int i = 0; i < n; i++) { cin >> a[i]; } + int b[105][105]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < a[i]; j++) { cin >> b[i][j]; } + } + int minn = 1000000000; + for (int i = 0; i < n; i++) { + int h = 0; + h += a[i] * 15; + for (int j = 0; j < a[i]; j++) { h += b[i][j] * 5; } + minn = min(minn, h); + } + cout << minn << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << ((n + 1) / 2) % 2 << endl; + return 0; +} +int main() { + int n, a, b, shela = 0, shelb = 0, i, count = 0; + for (i = 0; i < 6; i++) { + cin >> a; + count++; + if (count < 4) + shela = shela + a; + else + shelb = shelb + a; + } + cin >> n; + count = 0; + shela = ceil(shela / 5.0); + shelb = ceil(shelb / 10.0); + b = shela + shelb; + n = n - b; + if (n < 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int x1, x2, y1, y2; + cin >> x1 >> y1; + cin >> x2 >> y2; + int x, y; + x = x1 - x2; + y = y1 - y2; + if (x < 0) { x = x * (-1); } + if (y < 0) { y = y * (-1); } + int d; + if (x > y) { + d = x; + } else { + d = y; + } + cout << d << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int sum = 0; + for (int i = 0; i < s.size() - 1; i++) { + int j = i + 1; + int Count = 1; + while (s[i] == s[j]) { + Count++; + j++; + } + if (Count > 1) { + sum += Count - 1; + i = j - 1; + } + } + cout << sum << endl; +} +int isSubstring(string s1, string s2) { + int M = s1.length(); + int N = s2.length(); + for (int i = 0; i <= N - M; i++) { + int j; + for (j = 0; j < M; j++) + if (s2[i + j] != s1[j]) break; + if (j == M) return i; + } + return -1; +} +int main() { + string s; + cin >> s; + string s1 = "1111111"; + string s2 = "0000000"; + if (isSubstring(s1, s) != -1 || isSubstring(s2, s) != -1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const int MAXN = 101; +char data[MAXN]; +int dp[MAXN]; +int main() { + int n, d; + cin >> n >> d; + for (int i = 1; i < n + 1; i++) { cin >> data[i]; } + for (int i = 1; i < n + 1; i++) { dp[i] = 1e9; } + dp[1] = 0; + for (int i = 1; i < n + 1; i++) { + if (data[i] == '1') { + for (int j = i + 1; j < min(i + d, n) + 1; j++) { + if (data[j] == '1') { dp[j] = min(dp[j], dp[i] + 1); } + } + } + } + if (dp[n] == 1e9) { dp[n] = -1; } + cout << dp[n] << endl; +} +int main() { + int a[5000], b[5000]; + int flag[5000]; + memset(flag, true, sizeof(flag)); + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int len = 0; + for (int i = n - 1; i >= 0; i--) { + if (flag[a[i]]) { + len++; + b[len] = a[i]; + flag[a[i]] = false; + } + } + cout << len << endl; + for (int i = len; i >= 1; i--) + if (i != 1) + cout << b[i] << ' '; + else + cout << b[i] << endl; + return 0; +} +int main() { + int n, a, f = 1, b = 1, c = 0; + string s; + cin >> s; + n = s.length(); + if (n % 2 == 0) + a = n / 2 - 1; + else + a = n / 2; + cout << s[a]; + for (int i = 1; i < n; i++) { + if (c % 2 == 0) { + cout << s[a + b]; + b++; + c = 1; + } else { + cout << s[a - f]; + f++; + c = 0; + } + } + cout << endl; + return 0; +} +int main() { + int b, bb, g, gg, yes = 0; + cin >> g >> gg >> b >> bb; + if (g <= bb + 1 && bb <= (g + 1) * 2) { yes = 1; } + if (gg <= b + 1 && b <= (gg + 1) * 2) { yes = 1; } + if (yes) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + puts(n & n - 1 ? "NO" : "YES"); +} +int r(int n) { + int m = 0, pow = 1; + while (n != 0) { + int d = n % 10; + n /= 10; + if (d != 0) { + m += d * pow; + pow *= 10; + } + } + return m; +} +int main() { + int a, b; + cin >> a >> b; + int c = a + b; + int A = r(a); + int B = r(b); + int C = r(c); + cout << (A + B == C ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n; + int q; + cin >> n >> q; + int left = 1; + int right = n; + for (int i = 0; i < q; ++i) { + string s; + cin >> s; + cin >> s; + cin >> s; + int dir; + if (s[0] == 'l') + dir = -1; + else + dir = 1; + cin >> s; + int k; + cin >> k; + if (dir == -1) { + if (k - 1 < left) { + cout << -1 << endl; + return 0; + } + if (k - 1 <= right) right = k - 1; + } else { + if (k + 1 > right) { + cout << -1 << endl; + return 0; + } + if (k + 1 >= left && k + 1 <= right) left = k + 1; + } + if (left > right) { + cout << -1 << endl; + return 0; + } + } + cout << right - left + 1 << endl; +} +int n, m, a, b, v[2100][2100]; +int k, d[2100][2100], x, y; +bool solve(int x, int y, int k) { + int l = max(1, x - k), r = min(x + k, n), t; + for (int i = l; i <= r; i++) { + t = k - abs(i - x); + if (y - t > 0 && !v[i][y - t]) { + a = i; + b = y - t; + return 1; + } + if (y + t <= m && !v[i][y + t]) { + a = i; + b = y + t; + return 1; + } + } + return 0; +} +int main() { + cin >> n >> m >> k; + for (int i = 0; i < k; i++) { + cin >> x >> y; + for (int j = -2; j <= 2; j++) + for (int k = -2; k <= 2; k++) { + if (x + j < 1 || x + j > n || y + k < 1 || y + k > m) continue; + d[x][y] = max(d[x][y], d[x + j][y + k] - abs(j) - abs(k)); + } + while (!solve(x, y, d[x][y])) d[x][y]++; + v[a][b] = 1; + cout << a << " " << b << endl; + } +} +void read(int &x) { + x = 0; + bool f = 0; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = 1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + (ch - 48); + ch = getchar(); + } + if (f) x = -x; +} +void read(long long &x) { + x = 0; + bool f = 0; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = 1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + (ch - 48); + ch = getchar(); + } + if (f) x = -x; +} +int main() { + long long x; + read(x); + if (x == 3) { + cout << 5 << endl; + return 0; + } + for (int i = 1; true; i += 2) { + if (i * i / 2 + 1 >= x) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int m, n; + cin >> m >> n; + cout << m + n - 1 << endl; + for (int i = 1; i <= n; i++) { cout << 1 << " " << i << endl; } + for (int j = 2; j <= m; j++) { cout << j << " " << 1 << endl; } +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a = k / (m * 2); + int d = a; + int x = k % (m * 2); + if (x != 0) { a++; } + int y = k - ((a - 1) * m * 2); + int b = y / 2; + int q = y % 2; + if (q != 0) { b++; } + char c; + if (k % 2 == 0) { + c = 'R'; + } else { + c = 'L'; + } + cout << a << " " << b << " " << c << endl; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +long long n, a, x1, x2, y2; +int main() { + cin >> n >> x1 >> y2; + for (int i = 1; i < n; i++) { + cin >> x2 >> y2; + if (x2 <= x1) x2 += (((x1 - x2 + 1) + (y2 - 1)) / y2) * y2; + x1 = x2; + } + cout << max(x1, x2) << endl; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + int count = 0; + for (int i = 0; i < n - 1; i++) { + if (str[i] == str[i + 1]) count++; + } + cout << count << endl; +} +const int Max = 256; +int main() { + long long t; + cin >> t; + while (t--) { + long long a; + cin >> a; + long long res = ceil(a / 7.0); + cout << res << "\n"; + } + return 0; +} +long long dx[] = {1, 0, -1, 0}; +long long dy[] = {0, 1, 0, -1}; +long long gcd(long long x, long long y) { + if (y == 0) + return x; + else + return gcd(y, x % y); +} +long long expo(long long n, long long m, long long p) { + long long r = 1; + n = n % p; + while (m > 0) { + if (m % 2) r = (r * n) % p; + n = (n * n) % p; + m = m / 2; + } + return r % p; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +vector z_function(string s) { + long long n = (long long)s.length(); + vector z(n); + for (long long i = 1, l = 0, r = 0; i < n; ++i) { + if (i <= r) z[i] = min(r - i + 1, z[i - l]); + while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; + if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; + } + return z; +} +int main() { + long long n, k, s = 0, ma = (1LL << 61); + cin >> n >> k; + vector a(n); + for (long long i = 0; i < n; i++) { + cin >> a[i]; + s = s + a[i]; + ma = min(ma, a[i]); + } + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long s = a[i] - ma; + if (s % k != 0) { + cout << -1 << '\n'; + return 0; + } + ans = ans + s / k; + } + cout << ans << '\n'; +} +int main() { + int q, l, r, d, t; + cin >> q; + while (q--) { + cin >> l >> r >> d; + if (d < l || d > r) { + cout << d << endl; + } else { + t = r % d; + t = r - t; + cout << t + d << endl; + } + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int d[1110]; + int max = 0; + d[0] = a + b + c; + d[1] = a * (b + c); + d[2] = (a + b) * c; + d[3] = a * b * c; + for (int i = 0; i < 4; i++) { + if (d[i] >= max) max = d[i]; + } + cout << max << "\n"; +} +int main() { + int a, b, c, ans = 0; + cin >> a >> b >> c; + while (a >= 1 && b >= 2 && c >= 4) { + ans += 7; + a--; + b -= 2; + c -= 4; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + cout << n; + for (int i = 1; i <= n - 1; i++) cout << " " << i; + cout << endl; + return 0; +} +string s; +int main() { + int n, m; + cin >> n >> m; + getchar(); + int b = 1, e = n, x; + char *t; + for (int i = 0; i < m; ++i) { + getline(cin, s); + int l = s.length(); + if (s[7] == 'l') { + t = &s[15]; + x = atoi(t); + if (e >= x) e = x - 1; + } else if (s[7] == 'r') { + t = &s[16]; + x = atoi(t); + if (b <= x) b = x + 1; + } + } + e = e - b + 1; + if (e <= 0) e = -1; + cout << e << endl; + return 0; +} +int n, m, b, mod; +int a[505]; +long long dp[505][505]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + memset(dp, 0, sizeof(dp)); + dp[0][0] = 1; + for (int i = 1; i <= n; i++) + for (int k = 1; k <= m; k++) + for (int j = a[i]; j <= b; j++) { + dp[k][j] += dp[k - 1][j - a[i]]; + dp[k][j] %= mod; + } + int ans = 0; + for (int i = 0; i <= b; i++) { + ans += dp[m][i]; + ans %= mod; + } + cout << ans << endl; + return 0; +} +int main() { + long long a, b, c, d, x, y; + cin >> a >> b >> c >> d >> x >> y; + if ((a - c) % x == 0 && (b - d) % y == 0) { + long long p = (a - c) / x; + long long q = (b - d) / y; + if ((p + q) % 2 == 0) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; +} +map mp; +set s; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int num; + cin >> num; + s.insert(num); + mp[num]++; + } + int ans = 0; + for (set::iterator i = s.begin(); i != s.end(); i++) { ans = max(ans, (mp[*i] / k + (mp[*i] % k == 0 ? 0 : 1))); } + cout << ans * k * s.size() - n << endl; + return 0; +} +int ada[3]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + ada[x] += 1; + } + int ans = min(ada[2], ada[1]); + ada[1] -= ans; + ans += ada[1] / 3; + cout << ans << endl; +} +const int N = 1e5 + 5; +long long n, k, res, a[N]; +void Input() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); +} +long long Solve() { + for (int i = 2; i <= n; i++) { + long long d = a[i] - a[1]; + if (d % k != 0) + return -1; + else + res += d / k; + } + return res; +} +int main() { + Input(); + cout << Solve() << '\n'; + return 0; +} +int main() { + set myset; + string s; + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { myset.insert(s[i]); } + } + cout << myset.size() << endl; + return 0; +} +long long a[100010], b[100010]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, i, j; + while (cin >> n) { + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + double sum = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (i = 0; i < n; i++) { cin >> b[i]; } + sort(b, b + i, cmp); + if (b[0] + b[1] >= sum) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + char ch, ara[101]; + cin >> ara; + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + if (ara[i] != ara[i + 1]) { + cnt++; + i++; + } + } + cout << n - cnt << endl; + return 0; +} +int main() { + int c, ans = 0; + string s; + cin >> c >> s; + for (int i = c; i < s.size(); i += c) + if (s[i - 1] == s[i - 2] && s[i - 1] == s[i - 3]) ans++; + cout << ans << endl; + return 0; +} +const int maxn = 11000; +int INF = 1 << 30; +int m, n; +int da[110][maxn]; +int joo[110][maxn]; +int main() { + cin >> m >> n; + string s; + for (int i = 0; i < m; i++) { + cin >> s; + for (int j = 0; j < n; j++) da[i][j] = (s[j] == '1' ? 1 : 0); + } + int t, jj; + for (int i = 0; i < m; i++) { + t = INF; + for (int j = 0; j < n * 2; j++) { + jj = j % n; + if (da[i][jj] == 1) t = 0; + joo[i][jj] = t++; + } + t = INF; + for (int j = n * 2; j >= 0; j--) { + jj = j % n; + if (da[i][jj] == 1) t = 0; + joo[i][jj] = min(joo[i][jj], t++); + } + } + long long mi = INF, sum; + for (int j = 0; j < n; j++) { + sum = 0; + for (int i = 0; i < m; i++) { sum += joo[i][j]; } + mi = min(sum, mi); + } + if (mi >= INF) + cout << -1 << endl; + else + cout << mi << endl; + return 0; +} +const long long mod = 10e9 + 7; +const double eps = 1e-11; +const double PI = 2 * acos(0.0); +int main() { + char arr[4][4]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (arr[i][j] == '.' or arr[i][j] == '#') { + if (arr[i][j - 1] == '#' and j - 1 >= 0) { + if (arr[i - 1][j] == '#' and i - 1 >= 0) { + if (arr[i - 1][j - 1] == '#' and i - 1 >= 0 and j - 1 >= 0) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j + 1] == '#' and j + 1 < 4) { + if (arr[i - 1][j] == '#' and i - 1 >= 0) { + if (arr[i - 1][j + 1] == '#' and j + 1 < 4 and i - 1 >= 0) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j - 1] == '#' and j - 1 >= 0) { + if (arr[i + 1][j] == '#' and i + 1 < 4) { + if (arr[i + 1][j - 1] == '#' and i + 1 < 4 and j - 1 >= 0) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j + 1] == '#' and j + 1 < 4) { + if (arr[i + 1][j] == '#' and i + 1 < 4) { + if (arr[i + 1][j + 1] == '#' and i + 1 < 4 and j + 1 < 4) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j - 1] == '.' and j - 1 >= 0) { + if (arr[i - 1][j] == '.' and i - 1 >= 0) { + if (arr[i - 1][j - 1] == '.' and i - 1 >= 0 and j - 1 >= 0) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j + 1] == '.' and j + 1 < 4) { + if (arr[i - 1][j] == '.' and i - 1 >= 0) { + if (arr[i - 1][j + 1] == '.' and i - 1 >= 0 and j + 1 < 4) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j - 1] == '.' and j - 1 >= 0) { + if (arr[i + 1][j] == '.' and i + 1 < 4) { + if (arr[i + 1][j - 1] == '.' and i + 1 < 4 and j - 1 >= 0) { + puts("YES"); + return 0; + } + } + } + if (arr[i][j + 1] == '.' and j + 1 < 4) { + if (arr[i + 1][j] == '.' and i + 1 < 4) { + if (arr[i + 1][j + 1] == '.' and i + 1 < 4 and j + 1 < 4) { + puts("YES"); + return 0; + } + } + } + } + } + } + puts("NO"); +} +int main() { + int l, d, k; + cin >> l >> d >> k; + int a = d * 2; + if (k % a == 0) { + cout << k / a << " " << d << " R" << endl; + return 0; + } else { + int b = (k / a) + 1; + cout << b << " "; + int c = k % a; + if (c % 2 == 0) { + cout << c / 2 << " R" << endl; + } else { + cout << (c + 1) / 2 << " L" << endl; + } + } + return 0; +} +int main() { + string s, rs; + cin >> s; + rs = s; + int l = s.length(); + reverse(rs.begin(), rs.end()); + if (rs != s) { + cout << l; + } else { + s.erase(s.begin()); + rs = s; + reverse(rs.begin(), rs.end()); + if (rs != s) { + cout << l - 1; + } else { + cout << "0"; + } + } + cout << endl; +} +int main() { + int n, d; + cin >> n >> d; + vector v(n); + int ans = 0; + for (int i = 0; i < n; i++) cin >> v[i]; + int i; + for (i = 0; i < n - 1;) { + ans++; + int c = i; + for (int x = i + 1; x <= min(n - 1, i + d); x++) { + if (v[x] == '1') c = x; + } + if (c == i) break; + i = c; + } + if (i != n - 1) ans = -1; + cout << ans << "\n"; +} +int main() { + int a[4], ans = 0; + for (int i = 0; i < 4; i++) { cin >> a[i]; } + sort(a, a + 4); + for (int i = 1; i < 4; i++) { + if (a[i] == a[i - 1]) { ans++; } + } + cout << ans << '\n'; +} +int k; +char s[4][11]; +int main() { + for (int i = 0; i < 4; i++) + for (int j = 0; j < 11; j++) s[i][j] = '#'; + for (int i = 1; i < 11; i++) s[2][i] = '.'; + cin >> k; + for (int j = 0; j < 11; j++) + for (int i = 0; i < 4; i++) + if (k && s[i][j] == '#') { + s[i][j] = 'O'; + k--; + } + cout << "+------------------------+\n"; + for (int i = 0; i < 4; i++) { + cout << '|'; + for (int j = 0; j < 11; j++) cout << s[i][j] << '.'; + if (i == 0) + cout << "|D|)\n"; + else if (i == 1) + cout << "|.|\n"; + else if (i == 2) + cout << "..|\n"; + else + cout << "|.|)\n"; + } + cout << "+------------------------+\n"; + return 0; +} +int main() { + int n, a[1005]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int i = 1; + for (; i < n;) { + if (a[i] > a[i - 1]) + i++; + else + break; + } + for (; i < n;) { + if (a[i] == a[i - 1]) + i++; + else + break; + } + for (; i < n;) { + if (a[i] < a[i - 1]) + i++; + else + break; + } + if (i != n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + string s; + while (cin >> s) { + string res = ""; + char prev = 'a'; + for (int i = s.length() - 1; i >= 0; i--) + if (s[i] >= prev) { + res += s[i]; + prev = s[i]; + } + reverse(res.begin(), res.end()); + cout << res << endl; + } +} +int main() { + int n, m; + while (cin >> n >> m) { + int t1[15], t2[15]; + for (int i = 0; i < n; i++) cin >> t1[i]; + for (int j = 0; j < m; j++) cin >> t2[j]; + sort(t1, t1 + n); + sort(t2, t2 + m); + int x = min(t1[0], t2[0]); + int y = max(t1[0], t2[0]); + int mi = x * 10 + y; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (t1[i] == t2[j] && mi > t1[i]) mi = t1[i]; + } + } + cout << mi << endl; + } + return 0; +} +bool a[305]; +int x, n; +int main() { + cin >> x >> n; + for (int i = 1; i <= n; i++) { + int p; + cin >> p; + p %= x; + if (a[p] == true) { + cout << i << endl; + return 0; + } else + a[p] = true; + } + cout << -1 << endl; + return 0; +} +int main() { + int a, b; + int years = 0; + cin >> a >> b; + while (true) { + years++; + a = 3 * a; + b = 2 * b; + if (a > b) break; + } + cout << years << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + while (1) { + if (x == 1 && y >= 12) + --x, y -= 12; + else if (x >= 2 && y >= 2) + x -= 2, y -= 2; + else if (y >= 22) + y -= 22; + else { + puts("Hanako"); + return 0; + } + if (y >= 22) + y -= 22; + else if (y >= 12 && x) + y -= 12, --x; + else if (x >= 2 && y >= 2) + x -= 2, y -= 2; + else { + puts("Ciel"); + return 0; + } + } +} +int main() { + int a, b; + cin >> a >> b; + int x = 1; + int count = 0; + for (int i = 0; i < a; i++) { + int c, d; + cin >> c >> d; + for (;; x += b) { + if (x + b > c) { break; } + } + count += (d - x + 1); + x = d + 1; + } + cout << count << endl; +} +const int INF = 0x3f3f3f3f; +const int maxn = 200010; +int num[maxn]; +int del[maxn]; +string s1, s2; +int main() { + cin >> s1 >> s2; + for (int i = 1; i <= s1.length(); i++) cin >> num[i]; + int l = 0, r = s1.length(); + while (r - l > 1) { + memset(del, 0, sizeof(del)); + int mid = (l + r) / 2; + for (int i = 1; i <= mid; i++) del[num[i]] = 1; + int len = s2.length(); + int flag = 0; + int k = 0; + for (int i = 0; i < s1.length(); i++) { + if (del[i + 1] == 1) continue; + if (k == len) break; + if (s1[i] == s2[k]) k++; + } + if (k < len) flag = 1; + if (flag) + r = mid; + else + l = mid; + } + cout << l << endl; + return 0; +} +vector adj[111]; +int vst[111]; +pair p[111]; +void dfs(int u) { + vst[u] = 1; + for (int i = 0; i < ((int)adj[u].size()); i++) { + int v = adj[u][i]; + if (vst[v]) continue; + dfs(v); + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> p[i].first >> p[i].second; } + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + if (p[i].first == p[j].first or p[i].second == p[j].second) adj[i].push_back(j), adj[j].push_back(i); + } + } + int ans = -1; + for (int i = 1; i <= n; i++) + if (vst[i] == 0) dfs(i), ans++; + cout << ans << endl; + return 0; +} +int main() { + int n, d; + int ans = 0; + cin >> n >> d; + char shu[1000]; + cin >> shu; + for (int i = 0; i < n - 1;) { + int flag = 0; + for (int j = i + 1; j <= i + d && j < n; j++) { + if (shu[j] == '1') { flag = j; } + } + if (flag == 0) { + cout << -1 << endl; + return 0; + } else { + ans++; + i = flag; + } + } + cout << ans << endl; + return 0; +} +const double PI = 2.0 * acos(0.0); +const int MOD = 1e9 + 7; +const int oo = 2 * MOD + 1e3; +long long gcd(long long a, long long b) { + return !b ? a : gcd(b, a % b); +} +int main() { + int n; + string str; + cin >> n >> str; + sort(str.begin(), str.end()); + cout << str << '\n'; + return 0; +} +int x_1, y_1, x_2, y_2; +int ans; +int main() { + cin >> x_1 >> y_1 >> x_2 >> y_2; + cout << max(abs(x_1 - x_2), abs(y_1 - y_2)) << endl; + return 0; +} +int main() { + int64_t a, b, c; + cin >> a >> b >> c; + cout << 3 * min(a + 1, min(b, c - 1)) << endl; + return 0; +} +int size_n; +string str, com = "UDRL"; +int cx[4] = {1, -1, 0, 0}, cy[4] = {0, 0, 1, -1}; +int result = 0; +int ind(char letter); +int main() { + int ii, jj; + int curX, curY; + int tmp; + cin >> size_n; + cin.ignore(); + getline(cin, str); + for (ii = 0; ii < size_n; ii++) { + curX = 0; + curY = 0; + for (jj = ii; jj < size_n; jj++) { + tmp = ind(str[jj]); + curX += cx[tmp]; + curY += cy[tmp]; + if ((curX == 0) && (curY == 0)) result++; + } + } + cout << result << endl; + return 0; +} +int ind(char letter) { + int ii; + for (ii = 0; ii < 4; ii++) { + if (letter == com[ii]) return ii; + } + return -1; +} +int main() { + int m, n, s, f, t, k, l, now, res; + bool len; + cin >> m >> n; + l = 2 * (n - 1); + while (m--) { + cin >> s >> f >> t; + if (s == f) { + cout << t << endl; + continue; + } + k = t % l; + now = 0; + res = t; + len = true; + if (k >= l / 2) { + now = n - k % (l / 2); + len = false; + } else + now = 1 + k % (l / 2); + if (now < s) { + if (len) { + res += s - now; + now = s; + if (now == n) len = false; + } else { + res += now - 1 + s - 1; + now = s; + if (now != n) len = true; + } + } else if (now > s) { + if (len) { + res += n - now + n - s; + now = s; + if (now != 1) len = false; + } else { + res += now - s; + now = s; + if (now == 1) len = true; + } + } + s = f; + if (now < s) { + if (len) { + res += s - now; + now = s; + if (now == n) len = false; + } else { + res += now - 1 + s - 1; + now = s; + if (now != n) len = true; + } + } else if (now > s) { + if (len) { + res += n - now + n - s; + now = s; + if (now != 1) len = false; + } else { + res += now - s; + now = s; + if (now == 1) len = true; + } + } + cout << res << endl; + } + return 0; +} +int main() { + set st; + string s, t; + cin >> s; + for (int i = 0; i < s.length(); i++) { + t = s[s.length() - 1]; + s.erase(s.length() - 1); + s = t + s; + if (st.find(s) == st.end()) { st.insert(s); } + } + cout << st.size() << endl; + return 0; +} +int main() { + int n, m, i; + cin >> n >> m; + for (i = 1;; i++) { + n *= 3; + m *= 2; + if (n > m) break; + } + cout << i << endl; + return 0; +} +int main() { + long n, x; + cin >> n >> x; + long l[n], r[n]; + for (long i = 0; i < n; i++) { cin >> l[i] >> r[i]; } + long sum = 0, k = 1; + for (int i = 0; i < n; i++) { + if (k < l[i]) { + sum += (l[i] - k) % x; + k = l[i]; + } + while (k <= r[i]) { + k++; + sum++; + } + } + cout << sum << endl; +} +int main() { + long long c1, c2, x, k, i, b, n, t, cnt = 0; + cin >> k >> b >> n >> t; + c1 = b + t * (k - 1); + c2 = b + k - 1; + cnt = 1; + x = n; + if (k != 1) { + for (i = n; i >= 0; i--) { + if (c1 >= cnt * c2) + x = i; + else + break; + cnt *= k; + } + cout << x << endl; + } else { + for (i = 0; i <= n; i++) { + if (i * b >= 1 + n * b - t) break; + } + cout << i << endl; + } + return 0; +} +int a[10000005]; +long long sum = 0; +int main() { + int n; + int temp1, temp2 = 0; + cin >> n; + while (n--) { + cin >> temp1; + if (temp1 % 2 == 0) + sum += temp1; + else { + a[temp2] = temp1; + temp2++; + } + } + sort(a, a + temp2); + if (temp2 % 2 == 0) { + for (int i = 0; i <= temp2; i++) sum += a[i]; + } else { + for (int i = temp2; i >= 1; i--) sum += a[i]; + } + cout << sum << endl; + return 0; +} +char s[50]; +void init() { + cin >> s; +} +int main() { + init(); + string res; + int n = strlen(s); + int start = (n - 1) / 2; + res = s[start]; + int l = start, r = start; + while ((l >= 0) || (r < n)) { + l--; + r++; + if (r < n) res = res + s[r]; + if (l >= 0) res = res + s[l]; + } + cout << res << endl; + return 0; +} +long long n, k, cek, ks; +stack st; +int main() { + cin >> n >> k; + if (n == 1 && k > 1) { + cout << -1 << endl; + return 0; + } + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + cek++; + if (k == cek) { + cout << i << endl; + return 0; + } + if (i * i != n) st.push(i); + } + } + while (!st.empty()) { + if (n % st.top() == 0) { + cek++; + if (k == cek) { + cout << n / st.top() << endl; + return 0; + } + } + st.pop(); + } + cout << -1 << endl; +} +int main() { + int n, i, max = INT_MIN; + cin >> n; + string x, y; + for (i = 0; i < n; ++i) { + int hack, unhack, a, b, c, d, e, sum = 0; + cin >> x; + cin >> hack >> unhack >> a >> b >> c >> d >> e; + sum = 100 * hack - 50 * unhack + a + b + c + d + e; + if (sum > max) { + y = x; + max = sum; + } + } + cout << y << endl; +} +int main() { + long long N; + cin >> N; + long long n = N + 1; + long long sum = 0, a; + for (int i = 0; i < N; i++) { + cin >> a; + sum = sum + a; + } + long long c = 0; + for (int i = 1; i <= 5; i++) { + if (((sum + i) % n) != 1) c++; + } + cout << c << endl; + return 0; +} +long long int maxx(long long int a, long long int b) { + return a > b ? a : b; +} +long long int minn(long long int a, long long int b) { + return a > b ? b : a; +} +int dx[] = {1, 1, 1, 0, 0, -1, -1, -1, 0}; +int dy[] = {-1, 0, 1, 1, -1, 0, 1, -1, 0}; +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return (a * b) / gcd(a, b); +} +long long int poww(long long int base, long long int exp) { + base %= 1000000007; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % 1000000007; + base = (base * base) % 1000000007; + exp >>= 1; + } + return result; +} +vector a[200]; +bool pos[120][120], vis[120]; +int n, m; +void dfs(int root) { + vis[root] = 1; + for (int i = 0; i < a[root].size(); i++) { + if (!vis[a[root][i]]) dfs(a[root][i]); + } + return; +} +int comp() { + int ret = 0; + for (int i = 1; i <= n; i++) { + if (!vis[i]) { + ret++; + dfs(i); + } + } + return ret; +} +int main() { + int n, k; + cin >> n >> k; + int mi = 1e9; + long long int ans = 0; + vector a; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + mi = min(mi, x); + } + for (int i = 0; i < n; i++) { + if ((a[i] - mi) % k == 0) { + ans = ans + (a[i] - mi) / k; + } else { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; +} +int main() { + int n, ans = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { i++; } + ans++; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + string handle_max; + int score_max = -1; + for (int i = 0; i < n; ++i) { + string h; + int plus, minus, a, b, c, d, e; + cin >> h >> plus >> minus >> a >> b >> c >> d >> e; + int score = (2 * plus - minus) * 50 + a + b + c + d + e; + if (score > score_max || i == 0) { + score_max = score; + handle_max = h; + } + } + cout << handle_max << endl; +} +const int INF = 0x3f3f3f3f; +const int T = 110; +int n, d; +set ans; +int v[T]; +void check(int source) { + int mini = INF; + for (int i = 0; i < n; i++) mini = min(mini, abs(source - v[i])); + if (mini == d) ans.insert(source); +} +int main() { + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> v[i]; + sort(v, v + n); + for (int i = 0; i < n; i++) { + check(v[i] + d); + check(v[i] - d); + } + cout << ans.size() << endl; + return 0; +} +int main() { + int c, v, v1, a, l; + cin >> c >> v >> v1 >> a >> l; + int pages_read = 0; + int days = 0; + while (1) { + pages_read += (min(v + (days * a), v1)); + days++; + if (pages_read >= c) break; + pages_read -= l; + } + cout << days << endl; +} +int main() { + int n, sum, l, r, u, d; + string st; + while (cin >> n) { + cin >> st; + sum = 0; + for (int i = 0; i < n; i++) { + l = r = u = d = 0; + for (int j = i; j < n; j++) { + if (st[j] == 'R') r++; + if (st[j] == 'L') l++; + if (st[j] == 'U') u++; + if (st[j] == 'D') d++; + if (u == d && l == r) sum++; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + s[0] = towupper(s[0]); + cout << s << endl; + return 0; +} +const long long N = 1e9 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, a, b, x, c1, c2, cnt; +string s, s1; +bool bl = false; +long long c; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> n >> s; + c = s.size(); + while (c) { + if (s[0] == 'o' and s[1] == 'g' and s[2] == 'o') { + if (bl == false) { + cout << "***"; + bl = true; + } + if (s[3] == 'g' and s[4] == 'o') { + c -= 2; + s.erase(s.begin() + 0); + s.erase(s.begin() + 0); + } else { + c -= 3; + s.erase(s.begin() + 0); + s.erase(s.begin() + 0); + s.erase(s.begin() + 0); + bl = false; + } + } else { + bl = false; + cout << s[0]; + c--; + s.erase(s.begin() + 0); + } + } + cout << "\n"; + return 0; +} +int main() { + int a; + while (cin >> a) { + cout << a; + for (int i = 1; i < a; i++) cout << ' ' << i; + cout << endl; + } + return 0; +} +const int MAXN = 520; +int dp[MAXN][MAXN], a[MAXN], n, m, b, p; +int main() { + cin >> n >> m >> b >> p; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 0; i <= b; i++) dp[0][i] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int k = a[i]; k <= b; k++) dp[j][k] = (dp[j][k] + dp[j - 1][k - a[i]]) % p; + cout << dp[m][b] << endl; + return 0; +} +int main() { + long long n; + int k; + cin >> n >> k; + vector divisor; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0) { + divisor.push_back(i); + if (i * i != n) { divisor.push_back(n / i); } + } + } + sort(divisor.begin(), divisor.end()); + cout << (k > (int)divisor.size() ? -1 : divisor[k - 1]) << '\n'; + return 0; +} +int a[2005] = {0}; +int gcd(int a, int b) { + int t = 0; + while (a != 0) { + t = b % a; + b = a; + a = t; + } + return b; +} +int main() { + int n, i = 0, j, s = 0x3f3f3f3f, c = 0, b; + cin >> n; + while (i < n) { + cin >> a[i]; + if (a[i] == 1) c++; + i++; + } + if (c) + cout << n - c << endl; + else { + for (i = 0; i < n; i++) { + b = a[i]; + for (j = i + 1; j < n; j++) { + if ((b = gcd(b, a[j])) == 1) { s = min(s, j - i); } + } + } + if (s == 0x3f3f3f3f) + cout << -1 << endl; + else + cout << n - 1 + s << endl; + } + return 0; +} +int main() { + string s; + bool f = 1; + int n; + cin >> n >> s; + for (int i = 0; i < int(n - 1); i++) { + if (s[i] > s[i + 1] && f) { + f = 0; + } else { + cout << s[i]; + } + } + if (!f) cout << s[n - 1]; + cout << "\n"; + return 0; +} +int n, m; +int r[11], c[11]; +int ans; +int main() { + cin >> n >> m; + for (int i = 0; i < n; ++i) + for (int j = 0; j < m; ++j) { + char ch; + cin >> ch; + if (ch == 'S') r[i] = c[j] = 1; + } + ans = n * m; + for (int i = 0; i < n; ++i) + for (int j = 0; j < m; ++j) + if (r[i] && c[j]) ans--; + cout << ans << endl; + return 0; +} +int main() { + long long int a[6], cnt = 0; + for (int i = 0; i < 4; i++) { cin >> a[i]; } + if (a[1] == a[2] || a[1] == a[3] || a[1] == a[0]) { cnt++; } + if (a[2] == a[3] || a[2] == a[0]) { cnt++; } + if (a[3] == a[0]) { cnt++; } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << ((n + 1) / 2) % 2 << endl; + return 0; +} +int lzl(int n, int m) { + if (n < m) swap(n, m); + if (m == 0) + return n; + else if (n % m == 0) + return m; + else + return lzl(m, n % m); +} +int main() { + int a, b, n, k; + while (cin >> a >> b >> n) { + for (k = 1;; k++) { + if (k % 2 == 1) { + n -= lzl(n, a); + if (n < 0) { + cout << 1 << endl; + break; + } + } else { + n -= lzl(n, b); + if (n < 0) { + cout << 0 << endl; + break; + } + } + } + } + return 0; +} +int main() { + int n, d, i, j, ans, k; + cin >> n >> d; + int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + ans = 0; + for (i = 0; i < n - 1; i++) { + k = a[i + 1] - a[i]; + if (k == (2 * d)) + ans++; + else if (k > 2 * d) + ans += 2; + } + ans += 2; + cout << ans << endl; + return 0; +} +int main() { + int boy, girl; + int i, j, sum; + cin >> boy >> girl; + sum = boy + girl - 1; + cout << sum << endl; + for (i = 1; i <= girl; i++) { cout << 1 << " " << i << endl; } + for (i = 2; i <= boy; i++) { cout << i << " " << 1 << endl; } + return 0; +} +const long long MAX = 2e5 + 9; +const long long INF = 1e12; +long long a[MAX], b[MAX], maps[600][600]; +string t, p; +long long check(long long len) { + string s = t; + for (long long i = 0; i < len; i++) s[a[i] - 1] = '*'; + long long ptr = 0, i = 0; + while (i < t.length() && ptr < p.length()) { + if (s[i] == p[ptr]) ptr++; + i++; + } + return (ptr != p.length()); +} +int main() { + cin >> t >> p; + for (long long i = 0; i < t.length(); i++) cin >> a[i]; + long long l = 0, r = t.length(), m; + while (l < r) { + m = (l + r + 1) / 2; + if (check(m)) + r = m - 1; + else + l = m; + } + cout << l << endl; +} +long long int arr[2000005]; +long long int arr2[2000005]; +long long int power[15]; +int main() { + string ans, str; + long long int n, a, b, c, d, e, p, m, cur, nex; + cin >> n; + cin >> ans >> p >> m >> a >> b >> c >> d >> e; + cur = p * 100 - 50 * m + a + b + c + d + e; + n--; + while (n--) { + cin >> str >> p >> m >> a >> b >> c >> d >> e; + nex = p * 100 - 50 * m + a + b + c + d + e; + if (nex > cur) { + ans = str; + cur = nex; + } + } + cout << ans << endl; +} +int main() { + set s; + char a[1005]; + gets(a); + int len = strlen(a); + for (int i = 0; i < len; i++) { + if (a[i] >= 'a' && a[i] <= 'z') s.insert(a[i]); + } + cout << s.size() << endl; + return 0; +} +inline void getInt(int *p); +string a = "Danil"; +string c = "Olya"; +string d = "Slava"; +string e = "Ann"; +string b = "Nikita"; +int main() { + string s; + cin >> s; + int cnt = 0; + int index = -1; + while ((index = s.find(a, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(b, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(c, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(d, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(e, index + 1)) != -1) { cnt++; } + if (cnt == 1) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 122220 + ch - '0'; } + } +} +int main() { + long long n, k; + cin >> n >> k; + vector v; + for (long long i = 1; i * i <= n; i++) { + if (n % i == 0 and i * i != n) { + v.push_back(i); + v.push_back(n / i); + } else if (n % i == 0 and i * i == n) { + v.push_back(i); + } + } + sort(v.begin(), v.end()); + if (k > (int)v.size()) { + cout << "-1\n"; + } else + cout << v[k - 1] << '\n'; + return 0; +} +inline void getInt(int *p); +long long n; +long long s[1050]; +long long d[1050]; +long long ans = 0; +int main() { + cin >> n; + long long now = 0; + for (int i = 1; i <= n; i++) { + cin >> s[i]; + cin >> d[i]; + while (s[i] <= now) { s[i] += d[i]; } + now = s[i]; + } + cout << now << endl; + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 122220 + ch - '0'; } + } +} +string S, T; +long long N, M, A[10], sum, x, y, K, ans, val; +char C; +int main() { + cin >> N >> M >> x >> y; + K = min(abs(N - x), abs(M - y)); + ans = abs(N - x) + abs(M - y); + cout << K + ans - 2 * K << '\n'; +} +int main() { + long long l, k, i = 0, t = 1; + cin >> k >> l; + if (l % k) { + cout << "NO" << endl; + return 0; + } + while (true) { + t *= k; + if (t == l) { + cout << "YES" << endl << i << endl; + return 0; + } + if (t > l) { + cout << "NO" << endl; + return 0; + } + ++i; + } +} +int main() { + string s, p; + int pos = 0, i, cnt = 0, m = 0; + getline(cin, s); + sort(s.begin(), s.end()); + for (i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + if (s[i] != s[i + 1]) { cnt++; } + } + } + cout << cnt << endl; +} +int main() { + int a[200001], b, n, f = 0, t = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + cin >> b; + if (b == a[t]) { t++; } + } + cout << n - t << endl; +} +int in[361], n; +bitset<360> b; +int ans = 1000000; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> in[i]; + in[i] += in[i - 1]; + } + for (int i = 0; i < n; i++) + for (int j = i + 1; j <= n; j++) { ans = min(ans, abs(360 - (in[j] - in[i]) * 2)); } + cout << ans << '\n'; + return 0; +} +int main() { + int n, x, y, z; + cin >> n; + int sumx = 0, sumy = 0, sumz = 0; + while (n--) { + cin >> x >> y >> z; + sumx += x; + sumy += y; + sumz += z; + } + if (sumx == 0 && sumy == 0 && sumz == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, x = 0, y = 0, z = 0, x0, y0, z0; + cin >> n; + int u; + for (int x1 = 0; x1 < n; x1++) { + cin >> x0; + x += x0; + cin >> y0; + y += y0; + cin >> z0; + z += z0; + } + if (x == 0 && y == 0 && z == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string grid[4]; + cin >> grid[0] >> grid[1] >> grid[2] >> grid[3]; + bool found = false; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + int c1 = 0, c2 = 0; + for (int i1 = i; i1 <= i + 1; i1++) { + for (int j1 = j; j1 <= j + 1; j1++) { + if (grid[i1][j1] == '.') + c1++; + else + c2++; + } + } + if (c1 != 2) { found = true; } + } + } + cout << (found ? "YES" : "NO") << endl; + return 0; +} +int main() { + string input, max_chars, result; + cin >> input; + result = ""; + max_chars = input; + char r = input[input.size() - 1]; + for (int i = input.size() - 2; i >= 0; i--) { + if (input[i] > r) r = input[i]; + max_chars[i] = r; + } + for (int i = 0; i < input.size() - 1; i++) { + if (input[i] >= max_chars[i + 1]) result += input[i]; + } + result += input[input.size() - 1]; + cout << result << endl; + return 0; +} +char r[100005]; +int a, d; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> r[i]; + if (r[i] == 'A') + a++; + else + d++; + } + if (a > d) + cout << "Anton" << endl; + else if (a < d) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + unsigned long long a, b, c; + cin >> a >> b; + if (a % 2 == 0) + c = a / 2; + else + c = a / 2 + 1; + if (b > c) + b = (b - c) * 2; + else if (b <= c) + b = 2 * b - 1; + cout << b << endl; +} +int main() { + int n, k, x, i, res, m; + string str; + cin >> n >> k; + cin >> str; + int *a = new int[k + 1]; + for (i = 0; i <= k; i++) a[i] = 0; + for (i = 0; i < str.length(); i++) { + x = (int)str[i]; + a[x - 64]++; + } + m = 1; + for (i = 2; i <= k; i++) { + if (a[i] < a[m]) m = i; + } + res = k * a[m]; + cout << res << endl; + return 0; +} +int main() { + int r, g, b, x, y, z, res; + cin >> r >> g >> b; + x = 0, y = 0, z = 0; + int n = (r + 1) / 2; + x = (0 + (n - 1) * 3) + 30; + n = (g + 1) / 2; + y = (1 + (n - 1) * 3) + 30; + n = (b + 1) / 2; + z = (2 + (n - 1) * 3) + 30; + res = 0; + res = max(x, y); + res = max(res, z); + cout << res << endl; + return 0; +} +int main() { + int p, n; + cin >> p >> n; + bool arr[p + 7]; + memset(arr, false, sizeof(arr)); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (arr[x % p] == true) { + cout << i + 1 << '\n'; + return 0; + } else if (arr[x % p] == false) { + arr[x % p] = true; + } + } + cout << -1 << '\n'; + return 0; +} +int main() { + string str; + cin >> str; + int len = str.length(); + int a = 0, c = 0; + for (int i = 0; i < len; i++) { + if (str[i] == '0') { + if (a == 0) { + a = 1; + puts("1 1"); + } else { + a = 0; + puts("3 1"); + } + } + if (str[i] == '1') { + if (c == 0) { + c = 1; + puts("4 3"); + } else { + c = 0; + puts("4 1"); + } + } + } + return 0; +} +long int a[100000]; +int main() { + long long int n, k; + cin >> n >> k; + long long int i; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int yu = a[0] % k; + long long int time = 0; + for (i = 1; i < n; i++) { + if (a[i] % k != yu) { + cout << "-1" << endl; + return 0; + } + time += (a[i] - a[0]) / k; + } + cout << time << endl; + return 0; +} +int main() { + int m, n, k; + while (cin >> n >> m >> k) { + int a, b; + a = (k / (2 * m)) + (k % (2 * m) ? 1 : 0); + b = (k % (2 * m)) + (k % (2 * m) ? 0 : 1) * m * 2; + b = b / 2 + (b % 2 ? 1 : 0); + cout << a << " " << b << " " << ((k % 2) ? 'L' : 'R') << endl; + } +} +int s, f, t; +int n, m; +int F(int tt) { + if (tt / (m - 1) % 2 == 0) + return tt % (m - 1) + 1; + else + return -(m - tt % (m - 1)); +} +int work() { + if (s == f) return 0; + if (f > s) { + if (abs(F(t)) > s && F(t) > 0) + return 2 * (m - 1) - (F(t) - s) + f - s; + else if (abs(F(t)) > s && F(t) < 0) + return abs(F(t)) - 1 + s - 1 + f - s; + else if (abs(F(t)) <= s && F(t) > 0) + return f - F(t); + else + return abs(F(t)) - 1 + s - 1 + f - s; + } else { + if (abs(F(t)) < s && F(t) < 0) + return 2 * (m - 1) - (s - abs(F(t))) + s - f; + else if (abs(F(t)) < s && F(t) > 0) + return m - F(t) + m - s + s - f; + else if (abs(F(t)) >= s && F(t) > 0) + return m - F(t) + m - s + s - f; + else + return abs(F(t)) - f; + } +} +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> s >> f >> t; + cout << work() + t << '\n'; + } + return 0; +} +int main() { + int a, b, k; + cin >> a >> b; + for (k = 0; a <= b; k++) { + a = a * 3; + b = b * 2; + } + cout << k << endl; + return 0; +} +int n; +long long a, b; +int main() { + cin >> n; + if (n % 2 == 0 && n % 4 == 0) + cout << 0 << '\n'; + else if (n % 2 == 0 && n % 4 != 0) + cout << 1 << '\n'; + else if (n % 2 != 0 && (n - 1) % 4 == 0) + cout << 1 << '\n'; + else if (n % 2 != 0 && (n - 1) % 4 != 0) + cout << 0 << '\n'; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + int i = 0, a; + while (i < n) { + cin >> a; + v[i] = a; + i++; + } + i = 1; + int sum = 0; + while (i < n) { + if (v[i] - v[i - 1] < 2 * k) sum += 0; + if (v[i] - v[i - 1] == 2 * k) sum += 1; + if (v[i] - v[i - 1] > 2 * k) sum += 2; + i++; + } + cout << sum + 2 << endl; + return 0; +} +string s; +int book[300], cnt; +int main() { + getline(cin, s); + for (int i = 0; i < s.length(); ++i) + if ((s[i] - 'a' >= 0 && s[i] - 'z' <= 0) && book[s[i]] == 0) book[s[i]] = 1, cnt++; + cout << cnt << endl; + return 0; +} +int main() { + string n; + cin >> n; + if (n.find("1111111") != -1 || n.find("0000000") != -1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int cn1 = n / 2; + int cn2 = n % 2; + while ((cn1 + cn2) % m && cn1 != 0) { + cn1--; + cn2 += 2; + } + if ((cn1 + cn2) % m != 0) { + cout << -1 << endl; + return 0; + } else + cout << cn1 + cn2 << endl; +} +int n, x[101], y[101], ans = -1, vis[101]; +void dfs(int a) { + vis[a] = 1; + for (int i = 1; i <= n; i++) + if ((x[i] == x[a] || y[i] == y[a]) && !vis[i]) dfs(i); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; + for (int i = 1; i <= n; i++) + if (!vis[i]) dfs(i), ans++; + cout << ans << endl; +} +int main() { + int num; + int counts = 0; + int res[101]; + cin >> num; + char *words = new char[num + 1]; + cin >> words; + int dics[6] = {'a', 'i', 'e', 'u', 'y', 'o'}; + for (int i = 0; i < num; i++) { + res[i] = 1; + for (int j = 0; j < 6; j++) { + if ((int)words[i] == dics[j]) { + res[i] = 0; + break; + } + } + } + for (int i = 0; i < num - 1; i++) { + if (res[i] == 0) { + for (int j = i + 1; j < num; j++) { + if (res[j] == 0) { res[j] = -1; } + if (res[j] == 1) { + i = j; + break; + } + } + } + } + for (int i = 0; i < num; i++) { + if (res[i] == 0 || res[i] == 1) { cout << words[i]; } + if (i == num - 1) { cout << endl; } + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + int cnt = 0; + for (int i = n; i < str.size(); i += n) { + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int i, j, n, m, cnt = 0, a[1001]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { cnt += a[i]; } + int tmp = 0; + m = n + 1; + for (i = 1; i <= 5; i++) { + if (((i + cnt) - 1) % m == 0) tmp++; + } + cout << 5 - tmp << endl; + return 0; +} +long long n, m, a, b, c; +long long Yellow, Blue, ans; +int main() { + cin >> n >> m >> a >> b >> c; + Yellow = a * 2 + b; + Blue = b + c * 3; + if (Yellow >= n && Blue >= m) + ans += Yellow + Blue - n - m; + else if (Yellow < n && Blue > m) + ans += Blue - m; + else if (Yellow > n && Blue < m) + ans += Yellow - n; + cout << ans << endl; + return 0; +} +int main() { + string str, ans = ""; + int i, j, n; + bool is = false; + char max = 'a'; + cin >> str; + n = str.length(); + for (i = 0; i < n; i++) { + if (str[i] > max) { max = str[i]; } + } + for (i = 0; i < n; i++) { + if (str[i] == max) { + ans += max; + is = false; + for (j = i + 1; j < n; j++) { + if (str[j] == max) { + is = true; + break; + } + } + if (is) { + i = j - 1; + } else { + max = 'a'; + for (j = i + 1; j < n; j++) { + if (str[j] > max) { max = str[j]; } + } + } + } + } + cout << ans << endl; + return 0; +} +deque solve(string::iterator ib, string::iterator ie, char max) { + deque d; + if (max < 'a') return d; + for (string::iterator it = ib; it != ie; it++) { + if (*it == max) { + d = solve(it + 1, ie, max); + d.push_front(*it); + return d; + } + } + return solve(ib, ie, max - 1); +} +int main() { + string s; + cin >> s; + deque d = solve(s.begin(), s.end(), 'z'); + for (deque::iterator it = d.begin(); it != d.end(); it++) cout << *it; + cout << "\n"; + return 0; +} +set s[105]; +int now; +int d[100005]; +int fi(int x) { + if (d[x] == -1) { + return 1; + } else { + return fi(d[x]) + 1; + } +} +int main() { + int n; + while (cin >> n) { + for (int i = 1; i < n + 1; i++) { cin >> d[i]; } + int Max = -1; + for (int i = 1; i < n + 1; i++) { Max = max(Max, fi(i)); } + cout << Max << endl; + } +} +int n, d; +int v[102]; +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> v[i]; + int ans = 2; + for (int i = 1; i < n; i++) + if (v[i + 1] - v[i] > 2 * d) + ans += 2; + else if (v[i + 1] - v[i] == 2 * d) + ans++; + cout << ans << "\n"; + return 0; +} +int main() { + int x, sum = 0; + for (int i = 0; i < 5; i++) { + cin >> x; + sum = sum + x; + } + if (sum % 5 != 0 || sum == 0) { + cout << -1 << endl; + } else { + cout << sum / 5 << endl; + } +} +long long N, A, B, K, ans, cnt, x, y, val = 1; +int main() { + cin >> N >> A >> x >> y >> K; + ans = A; + cnt = A; + while (ans < N) { + cnt += y; + ans += min(cnt - K, x - K); + val++; + } + cout << val << '\n'; +} +int main() { + int n, k, i, j; + cin >> n >> k; + int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + long long int min = 2000000000; + for (i = 0; i < n; i++) { + if (a[i] < min) { min = a[i]; } + } + int flag = 0; + long long int count = 0; + for (i = 0; i < n; i++) { + count = count + (abs(a[i] - min) / k); + if (abs(a[i] - min) % k != 0) { + flag = 1; + break; + } + } + if (flag == 0) + cout << count << endl; + else if (flag == 1) + cout << "-1" << endl; + return 0; +} +const int maxn = 200005; +int n, A[maxn], B[maxn]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> A[i]; } + for (int i = 0; i < n; i++) { cin >> B[i]; } + int ans = 0; + for (int i = 0; i < n; i++) { + if (A[ans] == B[i]) { ans++; } + } + cout << n - ans << '\n'; + return 0; +} +int main() { + int passengers; + cin >> passengers; + cout << "+------------------------+" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i * 3 + 1 < passengers) + cout << "O."; + else if (passengers == 1 && i == 0) + cout << "O."; + else + cout << "#."; + } + cout << "|D|)" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i * 3 + 2 < passengers) + cout << "O."; + else if (passengers == 2 && i == 0) + cout << "O."; + else + cout << "#."; + } + cout << "|.|" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i == 0) { + if (2 < passengers) + cout << "O."; + else + cout << "#."; + } else + cout << ".."; + } + cout << "..|" << endl; + cout << "|"; + for (int i = 0; i < 11; i++) { + if (i * 3 + 3 < passengers) + cout << "O."; + else + cout << "#."; + } + cout << "|.|)" << endl; + cout << "+------------------------+" << endl; + cin >> passengers; +} +int main() { + int a, b; + cin >> a; + if (a % 2 != 0) + cout << -1 << endl; + else { + for (b = 2; b <= a - 2; b += 2) cout << b << ' ' << b - 1 << ' '; + cout << a << ' ' << a - 1 << endl; + } + return 0; +} +const int Inf = 1e9; +int main() { + int n, dis; + while (cin >> n >> dis) { + vector a(n); + for (int i = 0; i < n; ++i) cin >> a[i]; + sort(a.begin(), a.end()); + int ans = 2; + for (int i = 1; i < n; ++i) { + int d = a[i] - a[i - 1]; + if (d == dis * 2) + ++ans; + else if (d > dis * 2) + ans += 2; + } + cout << ans << endl; + } + return 0; +} +int main() { + int t; + vector big; + cin >> t; + for (int i = 1; i <= t; i++) { + int a; + cin >> a; + big.push_back(a); + } + for (int i = 0; i < t; i++) { + if (big[i] % 7 == 0) { + cout << big[i] / 7 << endl; + } else { + cout << big[i] / 7 + 1 << endl; + } + } + return 0; +} +int a[10000010]; +void get_prime() { + for (int i = 2; i < 1000010; i++) + if (!a[i]) + for (int j = i * 2; j < 1000010; j += i) a[j] = 1; +} +int main() { + get_prime(); + int n; + while (cin >> n) { + if (n % 2) { + for (int i = 4; i < n - 3; i++) + if (a[i] && a[n - i]) { + cout << i << ' ' << n - i << endl; + break; + } + } else + cout << 4 << ' ' << n - 4 << endl; + } + return 0; +} +int n, cnt; +char s[55], ans[55]; +int main() { + gets(s); + int n = strlen(s); + cnt = n; + int l = 0, r = n - 1; + int cur = n & 1; + while (l < r) { + if (cur & 1) { + ans[--cnt] = s[l]; + l++; + } else { + ans[--cnt] = s[r]; + r--; + } + cur++; + } + if (l == r) ans[--cnt] = s[l]; + puts(ans); + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + int n, count = 0; + string word; + cin >> n; + map m; + map::iterator it; + for (int i = 0; i < n; i++) { + count = 0; + cin >> word; + int a, b; + cin >> a >> b; + count += a * 100; + count -= b * 50; + for (int i = 0; i < 5; i++) { + int c; + cin >> c; + count += c; + } + m[count] = word; + } + for (it = m.begin(); it != m.end(); it++) { word = it->second; } + cout << word << endl; + return 0; +} +int main() { + int n; + cin >> n; + int count = 0; + char a, b, c; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if (a == '+' || b == '+') + count++; + else + count--; + } + cout << count << endl; + return 0; +} +int main() { + long long n, M, M2, s = 0; + long long t[100005]; + long long t2[100005]; + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> t[i]; + s += t[i]; + } + for (long long i = 0; i < n; i++) { cin >> t2[i]; } + sort(t2, t2 + n); + if (s <= t2[n - 1] + t2[n - 2]) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + char s[n]; + for (int j = 0; j < n; j++) { cin >> s[j]; } + long long count = 0; + int i = 0; + while (i < n) { + if (s[i] == 'U' && s[i + 1] == 'R' && i + 1 <= n - 1) { + ++count; + i += 2; + } else if (s[i] == 'R' && s[i + 1] == 'U' && i + 1 <= n - 1) { + ++count; + ; + i += 2; + } else { + ++count; + i++; + } + } + cout << count << endl; +} +int c, v0, v1, a, l; +stack page; +int main() { + cin >> c >> v0 >> v1 >> a >> l; + page.push(0); + int ans = 0; + while (1) { + int v = v0 + ans * a; + int pre = page.top(); + ans++; + int now = pre - min(pre, l) + min(v, v1); + if (now >= c) break; + page.push(now); + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << endl; } + return 0; +} +const long long N = 1e6 + 7; +long long n, m, k, rad; +long long p, parta; +char mesto; +int main() { + cin >> n >> m >> k; + p = k - 1; + p /= 2; + rad = (p / m); + rad++; + parta = p % m + 1; + if (k % 2 == 0) { + mesto = 'R'; + } else { + mesto = 'L'; + } + cout << rad << ' ' << parta << ' ' << mesto << "\n"; +} +int s1, ans, p; +char s[250]; +int main() { + gets(s); + s1 = strlen(s); + ans = 0; + p = 1; + for (int i = 1; i <= s1 - 1; i++) p = p * 2 % 1000000007; + for (int i = s1 - 1; i >= 0; i--) { + if (s[i] == '1') ans = (ans + p) % 1000000007; + p = p * 2 % 1000000007; + } + cout << ans << endl; + return 0; +} +int main() { + int i = 0; + int a, b; + cin >> a >> b; + while (a <= b) { + a *= 3; + b *= 2; + i++; + } + cout << i << endl; + return 0; +} +int n, m; +int main() { + cin >> m >> n; + cout << n + m - 1 << endl; + for (int i = 1; i <= n; i++) { + cout << "1" + << " " << i << endl; + } + for (int j = 2; j <= m; j++) { + cout << j << " " + << "1" << endl; + } + return 0; +} +int main() { + int n, m, k, p, x, y; + cin >> n >> m >> k; + p = (k - 1) / 2; + cout << p / m + 1 << " " << (p % m) + 1 << " "; + if (k & 1) { + cout << "L"; + } else { + cout << "R"; + } + cout << "\n"; + return 0; +} +int main() { + int a, m; + int qiu[100000]; + while (cin >> a >> m) { + int b = 1; + memset(qiu, 0, sizeof(qiu)); + while (b) { + a = (a + a % m) % m; + if (a == 0) { + cout << "Yes" << endl; + b = 0; + } + if (qiu[a] == 1) { + cout << "No" << endl; + b = 0; + } + qiu[a] = 1; + } + } + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + long long arr[100010] = {0}; + bool f = 0; + while (1) { + a = (a + a) % b; + if (arr[a] == 1) { break; } + arr[a] = 1; + if (a % b == 0) { + f = 1; + break; + } + } + if (f) { + cout << "Yes\n"; + } else { + cout << "No\n"; + } + return 0; +} +int main() { + int a, b, c, d, p, q; + cin >> a >> b >> c >> d; + if (a > c) + p = a - c; + else + p = c - a; + if (b > d) + q = b - d; + else + q = d - b; + if (p > q) + cout << p << endl; + else + cout << q << endl; + return 0; +} +char str[100001]; +int letter[27] = {0}; +int main() { + int n, k, flag = 1; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> str[i], letter[str[i] - 'A' + 1]++; + for (int i = 1; i <= k; i++) { + if (!letter[i]) { + flag = 0; + break; + } + } + if (!flag) + cout << 0 << endl; + else { + sort(letter + 1, letter + k + 1); + cout << k * letter[1] << endl; + } +} +int main() { + int n, x; + cin >> n >> x; + int **A = new int *[n]; + for (int i = 0; i < n; i++) A[i] = new int[2]; + for (int i = 0; i < n; i++) + for (int j = 0; j < 2; j++) cin >> A[i][j]; + bool valid = true; + for (int i = 0; i < n; i++) + for (int j = 0; j < 2; j++) + if (x == A[i][j] || x == 7 - A[i][j]) valid = false; + if (valid) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + for (int(i) = 0; (i) < (n); (i)++) cin >> v[i]; + int mn = *min_element((v).begin(), (v).end()); + long long result = 0; + for (int(i) = 0; (i) < (n); (i)++) { + if ((v[i] - mn) % k == 0) { + result += (v[i] - mn) / k; + } else { + cout << -1 << endl; + return 0; + } + } + cout << result << endl; + return 0; +} +int a, b; +int c1, c2; +int getNum(int m) { + int ds = 0; + int currMod = 0; + int ans = 0; + while (m) { + currMod = m % 10; + m /= 10; + if (currMod != 0) { + ans += currMod * (pow(10, ds)); + ds++; + } + } + return ans; +} +int main() { + cin >> a >> b; + c1 = a + b; + c2 = getNum(c1); + if (getNum(a) + getNum(b) == c2) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int a, b, n; +int gcd(int x, int y) { + if (y == 0) { return x; } + if (x < y) { swap(x, y); } + return gcd(y, x % y); +} +int game() { + while (1) { + n -= gcd(a, n); + if (n == 0) { return 0; } + n -= gcd(b, n); + if (n == 0) { return 1; } + } +} +int main() { + while (cin >> a >> b >> n) { + int ans = game(); + cout << ans << endl; + } +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int ans = min(abs(x1 - x2), abs(y1 - y2)); + if (abs(x1 - x2) != ans) { + ans += abs(abs(x2 - x1) - ans); + } else if (abs(y1 - y2) != ans) { + ans += abs(abs(y2 - y1) - ans); + } + cout << ans << '\n'; + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int x, y; + cin >> x >> y; + if ((abs(y2 - y1) % y != 0) || (abs(x2 - x1) % x != 0)) + cout << "NO" << endl; + else { + int step1 = abs(y1 - y2) / y, step2 = abs(x1 - x2) / x; + int raznstep = abs(step1 - step2); + if (((step1 == 0) && (step2 == 0)) || (raznstep % 2 != 0)) { + if (raznstep != 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } else + cout << "YES" << endl; + } + return 0; +} +int main() { + int A, B, C, D; + cin >> A >> B >> C >> D; + if ((A * 2 + 3 > D && D + 1 >= A) || (B * 2 + 3 > C && C + 1 >= B)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + double l, r, d, i; + long int min; + for (i = 0; i < n; i++) { + cin >> l >> r >> d; + int k = l / d, K = r / d; + if (d == 1) { + if (l > 1) { + min = 1; + } else + min = r + 1; + } else { + if (l / d > 1) { + min = d; + } else { + min = d * (K + 1); + } + } + cout << min << endl; + } +} +int main() { + string s, s1; + int n, k; + cin >> n >> k; + if (k > n || (k == 1 && n > 1)) return cout << "-1" << endl, 0; + if (k == 1) return cout << "a" << endl, 0; + for (int i = 1; i <= k - 2; i++) s += 'b' + i; + for (int i = 1; i <= n - k + 2; i++) s1 += i % 2 ? 'a' : 'b'; + cout << s1 << s << endl; +} +int a[100005], b[100005]; +int main() { + int n; + double cnt = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) cnt++; + } + cnt /= 2; + if (cnt <= 1) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int main() { + int a, b, count = 0; + cin >> a >> b; + while (a <= b) { + a = a * 3; + b = b * 2; + count += 1; + } + cout << count << "\n"; +} +int main() { + int n, d; + cin >> n >> d; + string str; + cin >> str; + int ans = 0; + int i = 0; + while (i < n - 1) { + if (str[i + d] == '1') { + ans++; + i = i + d; + } else { + int j = i + d - 1; + int flag = 1; + while (j > i) { + if (str[j] == '1') { + i = j; + ans++; + flag = 0; + break; + } + j--; + } + if (flag) { + ans = -1; + break; + } + } + } + cout << ans << endl; +} +const int maxn = 1e5; +int a[maxn]; +int main() { + int n, m, k; + cin >> n >> m >> k; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + int l = m, r = m; + int dis; + while (true) { + if (a[l] != 0 && a[l] <= k) { + dis = m - l; + break; + } else if (l > 1) { + l--; + } + if (a[r] != 0 && a[r] <= k) { + dis = r - m; + break; + } else if (r < n) { + r++; + } + } + cout << dis * 10 << endl; + return 0; +} +int main() { + long long i, c = 0, a, b, x, y, z; + cin >> a >> b >> x >> y >> z; + a -= x * 2; + a -= y; + b -= y; + b -= 3 * z; + if (a < 0) c += abs(a); + if (b < 0) c += abs(b); + cout << c << endl; + return 0; +} +char a[1005]; +int vis[200] = {0}; +int main() { + gets(a); + int ans = 0; + for (int i = 1; a[i]; i++) { + if (a[i] >= 'a' && a[i] <= 'z' && !vis[a[i] - 'a']) { + ans++; + vis[a[i] - 'a'] = 1; + } + } + cout << ans << '\n'; + return 0; +} +int n, k, p; +long long person[1005], key[2005]; +long long ans, tmp; +int main() { + while (cin >> n >> k >> p) { + ans = 99999999999999LL; + for (int i = 0; i < n; i++) { cin >> person[i]; } + for (int i = 0; i < k; i++) { cin >> key[i]; } + sort(person, person + n); + sort(key, key + k); + for (int i = 0; i + n <= k; i++) { + tmp = 0; + for (int j = 0; j < n; j++) { tmp = max(tmp, abs(key[i + j] - person[j]) + abs(p - key[i + j])); } + ans = min(tmp, ans); + } + cout << ans << endl; + } + return 0; +} +int main() { + long long a, b, x, y, z; + cin >> a >> b >> x >> y >> z; + long long ans = 0; + if (y <= a) + a -= y; + else { + ans += (y - a); + a = 0; + } + if (y <= b) + b -= y; + else { + ans += (y - b); + b = 0; + } + if (x * 2 <= a) { + a -= x * 2; + } else { + ans += (2 * x - a); + a = 0; + } + if (z * 3 <= b) { + b -= z * 3; + } else { + ans += (z * 3 - b); + b = 0; + } + cout << ans << endl; +} +int main() { + int i, j, k, l, m, n, o, p, counta = 0, flag = 0, counta2 = 0; + char arr[100]; + cin >> arr; + l = strlen(arr); + for (i = 0; i < l; i++) { + if (arr[i] == '1') { + counta2 = 0; + counta++; + if (counta >= 7) { + cout << "YES" << endl; + flag = 1; + return 0; + } + } else { + counta = 0; + counta2++; + if (counta2 >= 7) { + cout << "YES" << endl; + flag = 1; + return 0; + } + } + } + if (flag == 0) { cout << "NO" << endl; } +} +int n, m; +int main() { + cin >> n >> m; + cout << n + m - 1 << "\n"; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << "\n"; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << "\n"; +} +int main() { + int n, m, k; + int row, col; + cin >> n >> m >> k; + row = (k - 1) / (2 * m) + 1; + col = (k - 2 * m * (row - 1) - 1) / 2 + 1; + cout << row << " " << col << (k % 2 == 1 ? " L" : " R") << endl; + return 0; +} +long long a, dans, minn = 9999999999998, ans, n; +int main() { + cin >> a; + for (int s = 1; s <= a; s++) { + cin >> n; + ans += n; + if (n % 2 == 1) { + dans++; + minn = min(minn, n); + } + } + if (dans % 2 == 1) ans -= minn; + cout << ans << endl; + return 0; +} +int number(string s, int p) { + int ans = 0; + for (int i = p; i < s.size(); ++i) { + ans *= 10; + ans += s[i] - '0'; + } + return ans; +} +int main() { + int n, m; + cin >> n >> m; + int high = n + 1, low = 0; + char c = getchar(); + while (m--) { + string s; + getline(cin, s); + if (s[7] == 'l') + high = min(number(s, 15), high); + else + low = max(number(s, 16), low); + } + if (high - 1 < low + 1) + cout << "-1" << endl; + else { + cout << high - low - 1 << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int contiguous = 1; + for (size_t i = 1; i < s.length(); ++i) { + if (s[i] == s[i - 1]) { + contiguous += 1; + if (contiguous == 7) { + cout << "YES" << endl; + return 0; + } + } else { + contiguous = 1; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long sum = n * (n + 1); + sum = sum / 2; + long long p = sum / n; + cout << p % 2 << endl; +} +int main() { + set ans; + string S; + getline(cin, S); + int n = S.length(); + for (int i = 0; i < n; i++) { + if (S[i] >= 'a' && S[i] <= 'z') ans.insert(S[i]); + } + cout << ans.size() << endl; + return 0; +} +int main() { + long long int i, n, t; + cin >> t; + while (t--) { + cin >> n; + cout << (long long int)(ceil((double)n / 7)) << endl; + } +} +void file() {} +void fast() {} +const int N = 510 + 20; +int main() { + file(); + fast(); + int n; + cin >> n; + vector v1(n), v2(n), pos(n + 1); + for (int i = 0; i < n; i++) { cin >> v1[i]; } + for (int i = 0; i < n; i++) { + cin >> v2[i]; + pos[v2[i]] = i; + } + int until = 1; + for (int i = 1; i < n; i++) { + if (pos[v1[i]] > pos[v1[i - 1]]) { + until++; + } else { + break; + } + } + cout << n - until << endl; +} +int dp[2][505][505]; +int a[505]; +int main() { + int n, m, b, mod; + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + memset(dp, 0, sizeof(dp)); + dp[0][0][0] = 1; + int flag = 1; + for (int i = 1; i <= n; i++) { + for (int j = 0; j <= b; j++) { + for (int k = 0; k <= m; k++) { + dp[flag][j][k] = dp[flag ^ 1][j][k]; + if (j >= a[i]) { (dp[flag][j][k] += dp[flag][j - a[i]][k - 1]) %= mod; } + } + } + flag ^= 1; + } + flag ^= 1; + int sum = 0; + for (int i = 0; i <= b; i++) { (sum += dp[flag][i][m]) %= mod; } + cout << sum << endl; +} +int n; +int solve(const string &s) { + int ans = 0; + for (int i = n; i < s.length(); i = i + n) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) ans++; + } + return ans; +} +int main() { + string s; + cin >> n >> s; + int ans = solve(s); + cout << ans << endl; + return 0; +} +int main() { + int x1, x2, y1, y2; + int diff1, diff2; + cin >> x1 >> y1; + cin >> x2 >> y2; + diff1 = abs(x2 - x1); + diff2 = abs(y2 - y1); + if (diff1 > diff2) { + cout << diff1 << endl; + } else if (diff2 > diff1) { + cout << diff2 << endl; + } else if (diff1 == diff2) { + cout << diff1 << endl; + } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int cnt = 0; + for (int i = 1; i < n; i++) + if (s[i] == s[i - 1]) cnt++; + cout << cnt << endl; + return 0; +} +int main() { + int n, ma = 0, arr[100], i, s = 0, it; + cin >> n; + for (i = 0; i < n; i++) cin >> arr[i]; + for (i = 0; i < n; i++) { + for (int c = 0; c < arr[i]; c++) { + cin >> it; + s += it; + } + s *= 5; + s += 15 * arr[i]; + if (i == 0 || s < ma) ma = s; + s = 0; + } + cout << ma << endl; + return 0; +} +long long a[100005]; +long long cnt[100005]; +long long dp[100005]; +long long A[100005], num = 0; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (long long i = 0; i < n;) { + A[num] = a[i]; + while (a[i] == A[num]) { + i++; + cnt[num]++; + } + num++; + } + dp[0] = A[0] * cnt[0]; + if (A[0] + 1 == A[1]) + dp[1] = max(dp[0], A[1] * cnt[1]); + else + dp[1] = dp[0] + A[1] * cnt[1]; + for (long long i = 2; i < num; i++) { + if (A[i - 1] + 1 == A[i]) + dp[i] = max(dp[i - 1], dp[i - 2] + A[i] * cnt[i]); + else + dp[i] = dp[i - 1] + A[i] * cnt[i]; + } + cout << dp[num - 1] << endl; + return 0; +} +long long solve(long long k, long long b, long long n, long long t) { + if (k == 1) { + long long low = -1, high = n; + while (high - low > 1) { + long long mid = (low + high) / 2; + if (1 - t + b * (n - mid) <= 0) { + high = mid; + } else { + low = mid; + } + } + return high; + } + long long answ = n; + __float128 pow = 1; + while (answ > 0 && (k - 1) * (pow * k - t) + b * (pow * k - 1) <= 0) { + pow *= k; + answ--; + } + return answ; +} +int main() { + long long k, b, n, t; + while (cin >> k >> b >> n >> t) { cout << solve(k, b, n, t) << endl; } + return 0; +} +int dep[2001]; +bool seen[2001]; +vector adj[2001]; +void BFS(int s) { + queue q; + q.push(s); + dep[s] = 1; + seen[s] = 1; + while (!q.empty()) { + int a = q.front(); + q.pop(); + for (int i = 0; i < adj[a].size(); ++i) { + int ngh = adj[a][i]; + if (!seen[ngh]) { + seen[ngh] = 1; + dep[ngh] = dep[a] + 1; + q.push(ngh); + } + } + } +} +int main() { + int q, l, r, d; + cin >> q; + while (q--) { + cin >> l >> r >> d; + if (d < l) + cout << d << "\n"; + else + cout << (r / d + 1) * d << "\n"; + } + return 0; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + string res = ""; + set s1; + s1.insert('a'); + s1.insert('e'); + s1.insert('i'); + s1.insert('o'); + s1.insert('u'); + s1.insert('y'); + int flag = 0; + for (int i = 0; i < n; i++) { + if (s1.count(s.at(i))) { + if (flag == 0) { + res += s.at(i); + flag = 1; + } + } else { + if (flag == 1) flag = 0; + res += s.at(i); + } + } + cout << res << endl; +} +int main() { + string a; + int n, num = 0, l = 2; + cin >> n >> a; + while (true) { + if (num < n - 1) { + cout << a[num]; + num += l; + l++; + } else { + cout << a[num] << endl; + break; + } + } + return 0; +} +int f[501][501]; +int main() { + int n, m, b, mod; + cin >> n >> m >> b >> mod; + f[0][0] = 1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int j = 1; j <= m; j++) { + for (int k = x; k <= b; k++) { (f[j][k] += f[j - 1][k - x]) %= mod; } + } + } + int ans = 0; + for (int i = 0; i <= b; i++) { (ans += f[m][i]) %= mod; } + cout << ans << endl; + return 0; +} +int main() { + int arr[4]; + int cont = 0; + for (int i = 0; i < 4; ++i) { cin >> arr[i]; } + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + if (arr[i] == 0) break; + if (arr[i] == arr[j] && i != j) { + cont++; + arr[i] = 0; + } + } + } + cout << cont << endl; + return 0; +} +const long long MOD = 1e9 + 7; +const int MAXN = 101; +long long power[MAXN]; +int main() { + string x; + cin >> x; + reverse(x.begin(), x.end()); + long long step = 1; + for (int i = 0; i < x.size() - 1; ++i) { + step *= 2; + step %= MOD; + } + power[0] = 1; + for (int i = 1; i < MAXN; ++i) { power[i] = (2LL * power[i - 1]) % MOD; } + long long ans = 0; + for (int i = 0; i < x.size(); ++i) { + ans += step * (power[i] * (x[i] - '0')); + ans %= MOD; + } + cout << ans << endl; +} +int main() { + int total_page, v0, v1, acc, page_back; + int day_count, remaining; + cin >> total_page >> v0 >> v1 >> acc >> page_back; + day_count = 1; + remaining = total_page - v0; + if (remaining > 0) { + for (int i = 1; remaining > 0; i++) { + remaining += page_back; + if ((v0 + (i * acc)) <= v1) { + remaining = remaining - (v0 + (acc * i)); + day_count++; + } else { + remaining -= v1; + day_count++; + } + } + } + cout << day_count << endl; + return 0; +} +int main() { + int n, x, l, r, sum = 0, o = 0; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> l >> r; + if (l - 1 % x == 0) { + o = l; + sum += -o + r + 1; + } else { + while (o < l) o += x; + o -= x; + sum += -o + r; + } + o = r; + } + cout << sum << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (b >= c - 1 && a >= c - 2) + cout << 3 * c - 3 << endl; + else if (b < c - 1 && a >= c - 2) + cout << 3 * b << endl; + else if (b >= c - 1 && a < c - 2) + cout << 3 * a + 3 << endl; + else { + if (a <= b - 1) + cout << 3 * a + 3 << endl; + else + cout << 3 * b << endl; + } + return 0; +} +int main() { + int x, y, cnt = 0; + cin >> x >> y; + int p = x * 100 + 10 * y; + while (p >= 220) { + if (x > 1 && y >= 2) { + x -= 2; + y -= 2; + cnt++; + } else if (x == 1 && y >= 12) { + x--; + y -= 12; + cnt++; + } else if (y >= 22) { + y -= 22; + cnt++; + } else + p = 200; + p -= 220; + if (p >= 220) { + if (y >= 22) { + y -= 22; + cnt++; + } else if (y >= 12 && x) { + y -= 12; + x--; + cnt++; + } else if (y >= 2 && x >= 2) { + y -= 2; + x -= 2; + cnt++; + } else + p = 200; + } + } + if (cnt % 2) + cout << "Ciel" << endl; + else + cout << "Hanako" << endl; +} +string s; +int main() { + cin >> s; + for (char c = 'a'; c <= 'z'; c++) + for (int i = 0; i <= s.size(); i++) { + string t = s; + t.insert(i, 1, c); + string k = t; + reverse(k.begin(), k.end()); + if (k == t) { + cout << t << endl; + return 0; + } + } + cout << "NA" << endl; + return 0; +} +const int maxn = 100001; +int n; +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') { r[i] = c[j] = 1; } + } + } + int ans = n * m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (r[i] && c[j]) ans--; + } + } + cout << ans << endl; + } + return 0; +} +const int maxn = 2e5 + 7, maxm = 2e6 + 10; +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double PI = acos(-1.0); +int casn, n, m, k; +int x[maxn]; +string a, b; +int vis[maxn]; +int check(int mid) { + memset(vis, 0, sizeof vis); + for (int i = 0; i <= mid - 1; ++i) vis[x[i]] = 1; + int pos = 0; + for (int i = 0; i <= n - 1; ++i) { + if (vis[i]) continue; + if (a[i] == b[pos]) pos++; + if (pos == m) return 1; + } + return 0; +} +int main() { + cin >> a >> b; + n = a.size(), m = b.size(); + for (int i = 0; i <= n - 1; ++i) cin >> x[i], x[i]--; + int l = 0, r = n; + int ans = 0; + while (l < r) { + int mid = (l + r) >> 1; + if (check(mid)) + ans = mid, l = mid + 1; + else + r = mid; + } + cout << ans << '\n'; + return 0; +} +void READ(string INPUT = "NO", string OUTPUT = "NO") { + if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin); + if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout); +} +int a[100][2], n, ans = -1; +bool vis[100]; +void DFS(int node) { + vis[node] = 1; + for (int i = 0; i < n; i++) { + if (vis[i]) continue; + if (a[node][0] == a[i][0] || a[node][1] == a[i][1]) DFS(i); + } +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; + for (int i = 0; i < n; i++) { + if (!vis[i]) DFS(i), ans++; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + string str; + cin >> str; + int ans = 0; + int i = 0; + while (i < n - 1) { + if (str[i + d] == '1') { + ans++; + i += d; + } else { + int j = i + d - 1; + int flag = 1; + while (j > i) { + if (str[j] == '1') { + i = j; + ans++; + flag = 0; + break; + } + j--; + } + if (flag) { + ans = -1; + break; + } + } + } + cout << ans << endl; + return 0; +} +long long ABS(long long a) { + return a > 0 ? a : -a; +} +int gcd(int a, int b) { + if (a < b) swap(a, b); + while (b) { + int buffer = b; + b = a % b; + a = buffer; + } + return a; +} +int n, m; +vector mas; +int main() { + cin >> n >> m; + mas.resize(n); + for (int i = 0; i < n; i++) cin >> mas[i]; + vector x(2), y(2); + x[0] = 10000; + y[0] = 10000; + for (int i = 0; i < ((int)mas.size()); i++) + for (int j = 0; j < ((int)mas[i].size()); j++) { + if (mas[i][j] == '*') { + x[0] = min(x[0], i); + x[1] = max(x[1], i); + y[0] = min(y[0], j); + y[1] = max(y[1], j); + } + } + for (int i = 0; i < ((int)x.size()); i++) + for (int j = 0; j < ((int)y.size()); j++) + if (mas[x[i]][y[j]] != '*') cout << x[i] + 1 << " " << y[j] + 1 << endl; + return 0; +} +int n, x = 0, lol[2]; +int main() { + cin >> lol[0] >> lol[1] >> n; + while (__gcd(lol[x], n) <= n) { + n = n - __gcd(lol[x], n); + x = x ^ 1; + } + cout << 1 - x << '\n'; + return 0; +} +int main() { + int a[26] = {0}, k = 0, i; + string s; + getline(cin, s); + int len = s.size(); + for (i = 0; i < len; i++) { + if ((97 <= s[i]) && (s[i] <= 122)) a[s[i] - 97] = 1; + } + for (i = 0; i < 26; i++) + if (a[i] == 1) k++; + cout << k << endl; +} +int m[10010]; +int main() { + int n, maxn = 0; + cin >> n; + int st, en; + for (int i = 0; i < n; i++) { + cin >> m[i]; + maxn = max(maxn, m[i]); + } + for (int i = 0;; i++) { + if (m[i] == maxn) { + st = i; + break; + } + } + for (int i = n - 1;; i--) { + if (m[i] == maxn) { + en = i; + break; + } + } + for (int i = st; i <= en; i++) { + if (m[i] != maxn) { + cout << "NO" << endl; + return 0; + } + } + for (int i = 1; i <= st; i++) { + if (m[i - 1] >= m[i]) { + cout << "NO" << endl; + return 0; + } + } + for (int i = n - 2; i >= en; i--) { + if (m[i + 1] >= m[i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int mp[2010]; +int cnt; +int fun(int x) { + if (mp[x] == -1) return cnt; + cnt++; + fun(mp[x]); +} +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) mp[i] = -1; + int x; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x != -1) mp[i] = x; + } + int mx = 0; + for (int i = 1; i <= n; i++) { + cnt = 1; + mx = max(mx, fun(i)); + } + cout << mx << endl; + } +} +int main() { + int n, r = 0; + cin >> n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "++X" || s == "X++") + r++; + else + r--; + } + cout << r << endl; + return 0; +} +int main() { + long max1 = 100001; + long n, n1; + cin >> n; + vector numbers(max1); + vector values(max1, 0); + for (long i = 0; i < n; i++) { + cin >> n1; + numbers[n1]++; + } + values[0] = 0; + values[1] = numbers[1]; + for (long i = 2; i < max1; i++) { values[i] = max(numbers[i] * i + values[i - 2], values[i - 1]); } + cout << values[max1 - 1] << endl; + return 0; +} +int main() { + int a, m; + set store; + bool check = false; + cin >> a >> m; + int x = a, temp; + int L; + while (1) { + L = store.size(); + temp = x % m; + store.insert(temp); + if (L == store.size()) { + cout << "No" << endl; + break; + } + if (a % m == 0) { + cout << "Yes" << endl; + break; + } + a += temp; + x = a; + } + return 0; +} +bool isPalindrome(string s, int l, int r) { + while (l < r) { + if (s[l++] != s[r--]) { return false; } + } + return true; +} +int main() { + int res = INT_MIN; + string s; + cin >> s; + for (int i = 0; i < (int)s.length(); i++) { + for (int j = i; j < (int)s.length(); j++) { + if (!isPalindrome(s, i, j)) { res = max(res, j - i + 1); } + } + } + if (res == INT_MIN) + cout << 0 << endl; + else + cout << res << endl; + return 0; +} +string s; +int main() { + cin >> s; + for (int i = s.length(); i > 0; i--) { + for (int j = 0; j < s.length() - i + 1; j++) { + for (int k = j; k < j + i; k++) { + if (s[k] != s[2 * j + i - 1 - k]) { + cout << i << endl; + return 0; + } + } + } + } + cout << 0 << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) + cout << "First" << endl; + else + cout << "Second" << endl; +} +int main() { + int a, A = 0; + string t; + cin >> a; + cin >> t; + for (int i = 0; i < t.size(); i++) { + if (t[i] == 'A') A++; + } + if (A > a - A) { + cout << "Anton" << endl; + } else if (A < a - A) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } +} +int main() { + int len, anton = 0, danik = 0; + cin >> len; + string s; + cin >> s; + for (int i = 0; i < len; i++) { + if (s[i] == 'A') { + anton += 1; + } else { + danik += 1; + } + } + if (anton > danik) { + cout << "Anton" << endl; + } else if (danik > anton) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n - 1; i++) { + arr[i] += arr[i + 1]; + cout << arr[i] << " "; + } + cout << arr[n - 1] << "\n"; +} +int main() { + long long int a, b, pro = 1, cnt; + cin >> a >> b; + cnt = 0; + while (a <= b) { + a *= 3; + b *= 2; + cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + string a; + while (getline(cin, a)) { + set x; + for (int i = 0; a[i]; i++) { + if (a[i] >= 'a' && a[i] <= 'z') x.insert(a[i]); + } + cout << x.size() << "\n"; + } + return 0; +} +const int M = 1000 + 5; +int main() { + int gl, gr; + cin >> gl >> gr; + int bl, br; + cin >> bl >> br; + bool ok = false; + if (gr - 1 <= bl && bl <= 2 * (gr + 1)) { ok = true; } + if (gl - 1 <= br && br <= 2 * (gl + 1)) { ok = true; } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +vector v[200005]; +int main() { + long long int n, m, k; + cin >> m >> n >> k; + long long int ans = k / (2 * n); + long long int x, y; + if (2 * ans * n == k) { + cout << ans << " " << n << " R" << endl; + } else { + k -= ans * 2 * n; + x = k / 2; + if (x * 2 != k) x++; + if (k % 2 == 1) { + cout << ans + 1 << " " << x << " L" << endl; + } else + cout << ans + 1 << " " << x << " R" << endl; + } + return 0; +} +const int64_t infint64_t = 9223372036854775807LL; +void solve() { + int64_t n, k, p; + cin >> n >> k >> p; + vector a(n); + for (int64_t i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + vector b(k); + for (int64_t i = 0; i < k; i++) { cin >> b[i]; } + sort(b.begin(), b.end()); + int64_t best = infint64_t; + for (int64_t i = 0; i <= k - n; i++) { + int64_t curWorst = 0; + for (int64_t j = 0; j < n; j++) { + int64_t cur = abs(b[i + j] - p) + abs(b[i + j] - a[j]); + curWorst = max(curWorst, cur); + } + best = min(best, curWorst); + } + cout << best << endl; +} +int main() { + solve(); + return 0; +} +long long n, c, tot, ans, i, arr[100] = {}; +string s; +int main() { + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) + cout << "Second" << '\n'; + else + cout << "First" << '\n'; + return 0; +} +int main() { + int n, m; + bool x = true; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> arr[i][j]; + if (arr[i][j] != 'G' && arr[i][j] != 'W' && arr[i][j] != 'B') { x = false; } + } + } + if (x) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; + return 0; +} +int main() { + int n, turn = 0, drinks = 0; + string s; + cin >> n >> s; + for (int i(0); i < s.length(); ++i) { + if (i > 2) { + if (turn == 0 && s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) { + drinks++; + s[i] == s[i - 1]; + } + } + turn = (turn + 1) % n; + } + cout << drinks << endl; + return 0; +} +int n, xs[200] = {0}, ys[200] = {0}, cn[200] = {0}, t = 0; +void join(int i) { + cn[i] = 1; + for (int j = 0; j < n; j++) { + if (!cn[j] && (xs[i] == xs[j] || ys[i] == ys[j])) { join(j); } + } +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> xs[i] >> ys[i]; } + join(0); + for (int i = 0; i < n; i++) { + if (!cn[i]) { + join(i); + t++; + } + } + cout << t << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') { r[i] = c[j] = 1; } + } + } + int ans = n * m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (r[i] && c[j]) ans--; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + cout << n * (n + 1) / 2 % 2 << endl; + return 0; +} +int main() { + long long int n, a, b, a1, b1, i, j, c = 0; + cin >> n; + cin >> a1 >> b1; + c = a1; + for (i = 0; i < n - 1; i++) { + cin >> a >> b; + if (a <= c) { + for (j = 0;; j++) { + a += b; + if (a > c) { + c = a; + break; + } + } + } else + c = a; + } + cout << c << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int main() { + int a, b, c, x = 0, y = 0, z = 0, n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b >> c; + x += a; + y += b; + z += c; + } + if ((x == 0) && (y == 0) && (z == 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char a[1005]; +bool b[1005]; +int main() { + int i = 0; + while (1) { + cin >> a[i]; + if (a[i] == '}') { break; } + i++; + } + int t = 0; + while (a[t] != '}') { + if (a[t] >= 'a') { b[(int)a[t]] = 1; } + t++; + } + int sum = 0; + for (int i = 'a'; i <= 'z'; i++) { + if (b[i] == 1) { sum++; } + } + cout << sum << endl; +} +int main() { + vector s; + s.push_back("Danil"); + s.push_back("Olya"); + s.push_back("Slava"); + s.push_back("Ann"); + s.push_back("Nikita"); + string str; + cin >> str; + int sum = 0; + for (int i = 0; i < 5; i++) { + if (str.find(s[i]) != str.npos) { + sum++; + if (str.rfind(s[i]) != str.find(s[i])) sum++; + } + } + if (sum == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long ans, n, a[105]; +int main() { + cin >> n; + for (register long long i = 1; i <= n; i++) cin >> a[i]; + for (register long long i = 1; i <= n; i++) ans = ans + a[i] * i + 1 - i; + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int t, o; + t = o = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 1) { + o++; + } else { + t++; + } + } + int ans = 0; + ans += min(t, o); + o -= ans; + ans += o / 3; + cout << ans << '\n'; + return 0; +} +int main() { + int n, s = 0; + int x[1001], y[1001], z[1001]; + int a, b, c; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x[i]; + cin >> y[i]; + cin >> z[i]; + a += x[i]; + b += y[i]; + c += z[i]; + } + if (a == 0 && b == 0 & c == 0) { + cout << "YES"; + cout << "\n"; + } else { + cout << "NO"; + cout << "\n"; + } + return 0; +} +int main() { + const int size = 101; + char str[size]; + char str_1[] = "1111111"; + char str_0[] = "0000000"; + cin.getline(str, size); + if (strstr(str, str_0) || strstr(str, str_1)) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +const int MAXN = 105; +const int INF = 0x3f3f3f3f; +int a[MAXN]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) cin >> a[i]; + a[n + 1] = INF; + int p = 2; + while (a[p] > a[p - 1]) p++; + while (a[p] == a[p - 1]) p++; + while (a[p] < a[p - 1]) p++; + if (p <= n) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[110]; + int minn = 0x3f3f3f3f; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < a[i]; j++) { + int c; + cin >> c; + sum = sum + 15 + c * 5; + } + if (sum < minn) minn = sum; + } + cout << minn << endl; + } + return 0; +} +const int N = 1000; +int a[N]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i + n] = a[i]; + } + int ans = 1000; + for (int i = 0; i < 2 * n; i++) { + int t = 0; + for (int j = i; j < 2 * n; j++) { + if (t >= 180) { + ans = min(ans, t); + break; + } + t += a[j]; + } + } + ans = abs(360 - ans - ans); + cout << ans << endl; + return 0; +} +int main() { + long long a, b, n; + cin >> a >> b >> n; + while (1) { + n -= __gcd(a, n); + if (n < 0) { + cout << "1" << endl; + return 0; + } + n -= __gcd(b, n); + if (n < 0) { + cout << "0" << endl; + return 0; + } + } + return 0; +} +const int INF = 0x7fffffff; +int main() { + int n, m; + char s[10]; + cin >> n >> m; + int l = 1, r = n; + for (int i = 0; i < m; i++) { + cin >> s >> s >> s; + int x; + if (s[0] == 'r') { + cin >> s >> x; + l = max(l, x + 1); + } + if (s[0] == 'l') { + cin >> s >> x; + r = min(r, x - 1); + } + } + cout << (r - l + 1 > 0 ? r - l + 1 : -1) << endl; + return 0; +} +int n, m, b; +long long mod; +long long a[505]; +long long dp[2][505][505]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) dp[i % 2][0][0] = 1L; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + for (int k = 0; k <= b; k++) { + if (k < a[i]) + dp[i % 2][j][k] = dp[(i - 1) % 2][j][k] % mod; + else + dp[i % 2][j][k] = (dp[i % 2][j - 1][k - a[i]] + dp[(i - 1) % 2][j][k]) % mod; + } + } + } + long long ans = 0; + for (int i = 0; i <= b; i++) { ans = (ans + dp[n % 2][m][i]) % mod; } + cout << ans % mod << endl; + return 0; +} +int main() { + int m, n; + int i, ans = 0; + cin >> n >> m; + if (n % 2 == 0) { + ans = n / 2; + while (ans % m != 0) ans++; + } else { + ans = (n - 1) / 2 + 1; + while (ans % m != 0) ans++; + } + if (ans > n) + cout << "-1\n"; + else + cout << ans << endl; + return 0; +} +char xx[1000002]; +int main() { + int n, k; + while (cin >> n >> k) { + if (n < k || (n >= 2 && k < 2)) + cout << "-1" << endl; + else { + int a = k - 2; + int t = 0; + memset(xx, 0, sizeof(xx)); + for (int i = 0; i < n; i++) { + if (i < n - (k - 2)) { + if (i % 2 == 0) + xx[i] = 'a'; + else + xx[i] = 'b'; + } else { + if (i < n) { + xx[i] = 99 + t; + t++; + } + } + } + cout << xx << endl; + } + } + return 0; +} +int n; +int main() { + int s = 0, t = 0; + cin >> n; + int a[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[i] == 1) + s++; + else + t++; + } + if (s >= t) + cout << t + floor((s - t) / 3) << endl; + else + cout << s << endl; + return 0; +} +const int maxn = 5001; +char a[110]; +int main() { + int n; + cin >> n >> a; + int sum = 0; + for (int i = 0; i < n; i++) { + if (a[i] != a[i + 1]) i++; + sum++; + } + cout << sum << endl; + return 0; +} +long long int choose(long long int n, long long int m) { + long long int ans = 0; + long long int num = 1; + long long int den = 1; + for (long long int i = 0; i < m; i++) { + num *= (n - i); + num = num / (i + 1); + } + return num; +} +bool isPrime(int n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (int i = 5; i * i <= n; i = i + 6) { + if (n % i == 0 || n % (i + 2) == 0) return false; + } + return true; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) { + return b; + } else { + return gcd(b % a, a); + } +} +bool sortDes(long long int i, long long int j) { + return i > j; +} +long long int bits(long long int n) { + long long int count = 0; + while (n != 0) { + if (n % 2 != 0) + count++; + else + ; + n /= 2; + } + return count; +} +int main() { + long long int i, j, k, n, a, b, c; + cin >> n >> a >> b >> c; + long long int req; + req = 4 - n % 4; + if (n % 4 == 0) { + cout << 0 << endl; + return 0; + } + if (req == 1) { + long long int u = INT_MAX; + if (u > a) { u = a; } + if (3 * c < u) { u = 3 * c; } + if (b + c < u) { u = b + c; } + cout << u << endl; + } else if (req == 2) { + long long int r = INT_MAX; + if (r > 2 * a) { r = 2 * a; } + if (r > b) { r = b; } + if (r > 2 * c) { r = 2 * c; } + cout << r << endl; + return 0; + } else if (req == 3) { + long long int m = INT_MAX; + if (a * 3 < m) { m = a * 3; } + if (a + b < m) { m = a + b; } + if (c < m) { m = c; } + cout << m << endl; + } + return 0; +} +int arr[100][3]; +int arr1[3]; +int main() { + int x, a, b, c; + while (cin >> x) { + int sum = 0, sum1 = 0, sum2 = 0; + for (int i = 0; i < x; i++) { + cin >> a >> b >> c; + sum += a; + sum1 += b; + sum2 += c; + } + if ((sum == 0) && (sum1 == 0) && (sum2 == 0)) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + int x; + int y; + int ans = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n - 1; i++) { + x = 0; + y = 0; + if (s[i] == 'U') { + y++; + } else if (s[i] == 'D') { + y--; + } else if (s[i] == 'R') { + x++; + } else { + x--; + } + for (int j = i + 1; j < n; j++) { + if (s[j] == 'U') { + y++; + } else if (s[j] == 'D') { + y--; + } else if (s[j] == 'R') { + x++; + } else { + x--; + } + if (x == 0 && x == y) { ans++; } + } + } + cout << ans << endl; + return 0; +} +const int maxn = 1000000 + 5; +bool isp[maxn]; +void gp() { + memset(isp, 0, sizeof(isp)); + isp[0] = 1; + isp[1] = 1; + for (int i = 2; i < maxn - 2; i++) { + if (!isp[i]) { + for (int j = i * 2; j < maxn - 2; j += i) { isp[j] = 1; } + } + } +} +int a[maxn]; +int main() { + gp(); + int n; + while (cin >> n) { + for (int i = 2; i < n; i++) { + if (isp[n - i] && isp[i]) { + cout << i << " " << n - i << endl; + break; + } + } + } + return 0; +} +int main() { + int r, c; + cin >> r >> c; + set s1, s2; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + char val; + cin >> val; + if (val == 'S') { + s1.insert(i); + s2.insert(j); + } + } + } + int ret = r * c - (s1.size() * s2.size()); + cout << ret << endl; +} +char str[60]; +int ispalin(int i, int j); +int main() { + cin >> str; + int flag = 0; + int count = 0; + for (count = strlen(str); count > 0; count--) { + for (int j = 0; j + count - 1 < strlen(str); j++) { + int i = j + count - 1; + int k = j; + while (i > k) { + if (str[i] != str[k]) { + flag = 1; + break; + } + i--, k++; + } + if (flag) break; + } + if (flag) break; + } + cout << count << endl; + return 0; +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1.0); +const long long MOD = (long long)1e9 + 7; +void base() {} +int main() { + int n; + cin >> n; + string ans, str; + int a, b, aa, bb, cc, dd, ee, now = 0, largest = -INF; + for (int i = 0; i < n; i++) { + cin >> str >> a >> b >> aa >> bb >> cc >> dd >> ee; + int now = 100 * a - 50 * b + aa + bb + cc + dd + ee; + if (now > largest) { + ans = str; + largest = now; + } + } + cout << ans << endl; + return 0; +} +int main() { + unsigned long long int p, n; + cin >> p >> n; + unsigned long long int x[n], y[p], i = 0; + while (i < p) { + y[i] = -1; + ; + ++i; + } + i = 0; + while (i < n) { + cin >> x[i]; + ++i; + } + for (int j = 0; j < n; j++) { + int z = x[j] % p; + if (y[z] == -1) { + y[z] = z; + } else { + cout << j + 1 << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + unsigned long long sum = 0, min = 1e9 + 1; + for (int i = 0; i < n; i++) { + long long a; + cin >> a; + sum += a; + if (a % 2 && a < min) { min = a; } + } + if (sum % 2) { sum -= min; } + cout << sum << endl; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + for (int i = r; i >= 3; i--) { + if (i <= b + 1 && i <= y + 2) { + int ans = i; + cout << 3 * ans - 3 << endl; + return 0; + } + } +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int tot1 = abs(z - x) * t2 + t3 * 3 + abs(y - x) * t2; + int tot2 = abs(y - x) * t1; + if (tot1 > tot2) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +const int N = 200005; +const long long MOD = 998244353; +void solve() { + string s; + bool v = false; + bool g = false; + cin >> s; + int n = s.length(); + for (int i = 0; i < (s.length()); i++) { + if (s[i] == '0') { + if (v) { + cout << 3 << " " << 1 << endl; + v = false; + } else { + cout << "1 1" << endl; + v = true; + } + } else { + if (g) { + cout << 4 << " " << 1 << endl; + g = false; + } else { + cout << 4 << " " << 3 << endl; + g = true; + } + } + } +} +int main() { + int t = 1; + while (t--) { solve(); } +} +int main() { + int n, m; + cin >> n >> m; + multiset ms; + char c; + for (int i = 0; i < n * m; i++) { + cin >> c; + ms.insert(c); + } + if (!ms.count('C') && !ms.count('M') && !ms.count('Y')) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; + return 0; +} +int fa[2005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fa[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + int tmp = 0; + for (int j = i; j <= n && j != -1; j = fa[j]) { tmp++; } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int l, r, a, b, d, i, n; + cin >> n; + for (i = 0; i < n; i++) { + cin >> l >> r >> d; + cout << ((l <= d) ? (((int)(r / d) + 1) * d) : d) << "\n"; + } + return 0; +} +int a, b, c, d, e, f; +int main() { + cin >> a >> b >> c >> d >> e >> f; + cout << (a + b + c) * (a + b + c) - a * a - c * c - e * e << endl; +} +int arr[27000]; +string s; +int main() { + getline(cin, s, '\n'); + int i = 1; + while (s[i] != '}') { + if (s[i] - 'a' >= 0) arr[s[i] - 'a']++; + i++; + } + int r = 0; + for (int i = (0); i < (27); i++) + if (arr[i]) r++; + cout << r << "\n"; +} +int main() { + char a[105]; + int sum, n; + cin >> n; + sum = n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) { + if (a[i] != a[i - 1]) { + sum--; + i++; + } + } + cout << sum << endl; + return 0; +} +void find_subsequence(string s) { + int count, last_visited_index = -1; + char temp; + string result = ""; + for (int i = 25; i >= 0; --i) { + temp = i + 97; + count = 0; + for (int j = last_visited_index + 1; j < s.size(); j++) { + if (s[j] == temp) count++; + } + if (count >= 1) { + for (int l = last_visited_index + 1; l < s.size(); l++) { + if (s[l] == temp) { + result += s[l]; + last_visited_index = l; + } + } + } + } + cout << result << endl; +} +int main() { + string s; + cin >> s; + find_subsequence(s); + return 0; +} +int main() { + string s; + cin >> s; + if (s[0] >= 'a' && s[0] <= 'z') s[0] -= 32; + cout << s << endl; + return 0; +} +int main() { + int n, m, k, r, d; + char ch; + int p, q; + while (cin >> n >> m >> k && m && n && k) { + p = k % (2 * m); + q = k / (2 * m); + if (p == 0) + r = q; + else + r = q + 1; + if (p % 2 == 0) + ch = 'R'; + else + ch = 'L'; + q = k / (2 * m); + k = k - (q * 2 * m); + if (k != 0) { + q = k % 2; + if (q == 0) { + d = k / 2; + } else { + d = k / 2 + 1; + } + } else + d = m; + cout << r << " " << d << " " << ch << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + bool isok = true; + for (int i = 0; i < n; i++) { + set s; + int a, b; + cin >> a >> b; + if (i == 0) { + x = 7 - x; + continue; + } + s.insert(a); + s.insert(7 - a); + s.insert(b); + s.insert(7 - b); + vector t; + for (int i = 1; i <= 6; i++) + if (!s.count(i)) t.push_back(i); + if (x != t[0] && x != t[1]) { + cout << "NO" << endl; + return 0; + } + if (x == t[0]) + x = t[0]; + else + x = t[1]; + } + cout << "YES" << endl; + return 0; +} +const long long Mod = 1e9 + 7; +const double pi = 2 * acos(0.0); +const int N = 2e5 + 5; +int arr[N]; +int main() { + long long n, x, s = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + s += x; + } + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + if (arr[n - 1] + arr[n - 2] >= s) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +set::iterator it; +int main() { + signed long long int n; + cin >> n; + signed long long int a[n + 1], b[n + 1]; + for (signed long long int i = 1; i <= n; i++) cin >> a[i]; + for (signed long long int j = 1; j <= n; j++) { + signed long long int x; + cin >> x; + b[x] = j; + } + signed long long int ans = 0; + for (signed long long int i = 1; i <= n; i++) { a[i] = b[a[i]]; } + signed long long int cal = 1; + for (signed long long int i = 2; i <= n; i++) { + if (a[i - 1] < a[i]) + cal++; + else + break; + } + ans = n - cal; + cout << ans << "\n"; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + bool a = true; + int i, l, r, c = 1, d = 0; + for (i = 1; i <= n; i++) { + if (a) cin >> l >> r; + if (x + c <= l) { + c += x; + a = false; + i--; + } else { + d += r - c + 1; + c = r + 1; + a = true; + } + } + cout << d << endl; + return 0; +} +int main() { + int n, cnt = 0; + string s; + cin >> n; + cin >> s; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int x1, x2, y1, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + if (abs(x2 - x1) % x == 0 && abs(y2 - y1) % y == 0) { + if (abs(x2 - x1) / x % 2 == abs(y2 - y1) / y % 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, a, b; + cin >> n >> m >> a >> b; + int sum = a * n; + int msum = b; + int rides = m; + while (rides <= n) { + msum += b; + rides += m; + } + msum -= b; + rides -= m; + if (sum <= msum) { + cout << sum << "\n"; + } else { + if (rides < n) { + int newsum = msum + (n - rides) * a; + msum += b; + rides += m; + int newsum1 = msum; + if (newsum1 <= newsum) + cout << newsum1 << endl; + else + cout << newsum << endl; + } else if (rides > n) { + int newsum = msum + (n - rides) * a; + msum += b; + rides += m; + int newsum1 = msum; + if (newsum1 <= newsum) + cout << newsum1 << endl; + else + cout << newsum << endl; + } else { + cout << msum << "\n"; + } + } +} +int main() { + int n; + cin >> n; + vector a(2 * n); + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i + n] = a[i]; + } + int ans = 360; + for (int i = 0; i < 2 * n; i++) { + int temp = 0, dis; + for (int j = i; j < 2 * n; j++) { + temp += a[j]; + dis = max(temp, 360 - temp) - min(temp, 360 - temp); + if (dis < ans) ans = dis; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, y, z, sum1 = 0, sum2 = 0, sum3 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + sum1 += x; + sum2 += y; + sum3 += z; + } + if (sum1 == 0 && sum2 == 0 && sum3 == 0) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const long long N = 200005; +const long long INF = 1e15; +const int MOD = 1e9 + 7; +const double EPS = 1e-7; +const double PI = acos(-1.0); +long long n, p1[N], p2[N]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> p1[i]; + for (int i = 0; i < n; i++) cin >> p2[i]; + int i, j, cnt = 0; + for (i = 0, j = 0; i < n && j < n; i++) { + while (j < n && p1[i] != p2[j]) j++; + if (p1[i] == p2[j]) cnt++; + } + cout << n - cnt << endl; +} +int main() { + int n, m, s; + cin >> n >> m; + s = m + n - 1; + cout << s << endl; + for (int i = 1; i <= m; i++) { + cout << "1" + << " " << i << endl; + } + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << endl; } + return 0; +} +int main() { + int64_t n; + string s; + cin >> n >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int a, b, c, m, n, k, s[101], i = 0; + cin >> n >> m >> k; + m--; + for (a = 0; a < n; a++) cin >> s[a]; + for (a = 0;; a++) { + if (s[m + a] <= k && s[m + a] != 0 && m + a < n && m + a >= 0) break; + if (s[m - a] <= k && s[m - a] != 0 && m - a < n && m - a >= 0) break; + } + cout << a * 10 << endl; + return 0; +} +long long a[100010], dif[100010]; +int main() { + long long n, k; + cin >> n >> k; + long long mn = 9999999999; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + mn = min(mn, a[i]); + } + long long S = 0; + for (int i = 1; i <= n; i++) { + dif[i] = a[i] - mn; + if (dif[i] % k != 0) { + cout << -1 << endl; + return 0; + } else + S += dif[i] / k; + } + cout << S << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + long long arr[101]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int count = 2; + for (int i = 0; i < n - 1; i++) { + if (arr[i + 1] - 2 * d < arr[i]) + continue; + else if (arr[i + 1] - 2 * d == arr[i]) { + count++; + } else if (arr[i + 1] - 2 * d > arr[i]) { + count += 2; + } + } + cout << count << endl; + return 0; +} +void solve() { + int n, m; + cin >> n >> m; + vector vn(n), vm(m); + for (int i = 0; i < n; i++) cin >> vn[i]; + for (int i = 0; i < m; i++) cin >> vm[i]; + int res = 100000; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (vn[i] == vm[j]) { + res = min(res, vn[i]); + } else { + res = min(res, vn[i] * 10 + vm[j]); + res = min(res, vm[j] * 10 + vn[i]); + } + } + } + cout << res << endl; +} +int main() { + int t = 1; + while (t--) { solve(); } + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + long long int x, y, z; + cin >> x >> y >> z; + long long int ans = 0; + if (n >= 2 * x) { + n = n - 2 * x; + } else { + ans += 2 * x - n; + n = 0; + } + if (m >= 3 * z) { + m = m - 3 * z; + } else { + ans += 3 * z - m; + m = 0; + } + if (n < y) { ans += y - n; } + if (m < y) { ans += y - m; } + cout << ans << endl; +} +int main() { + int cnt = 1; + string a; + cin >> a; + int len = a.length(); + for (int i = 1; i < len; i++) { + if (a[i - 1] == a[i]) { + cnt++; + if (cnt == 7) { + cout << "YES" << endl; + return 0; + } + } else + cnt = 1; + } + cout << "NO" << endl; + return 0; +} +int l[105]; +int c[105]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char tmp; + cin >> tmp; + if (tmp == '*') { + l[i]++; + c[j]++; + } + } + } + int resL = 0, resC = 0; + ; + for (int i = 0; i < n; i++) { + if (l[i] == 1) { + resL = i; + break; + } + } + for (int i = 0; i < m; i++) { + if (c[i] == 1) { + resC = i; + break; + } + } + cout << resL + 1 << " " << resC + 1 << endl; + return 0; +} +int main() { + vector S(4); + cin >> S[0] >> S[1] >> S[2] >> S[3]; + sort(S.begin(), S.end()); + S.erase(unique(S.begin(), S.end()), S.end()); + int ans = S.size(); + cout << 4 - ans << endl; + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + long long c = a + b; + long long a1 = 0, b1 = 0, c1 = 0; + long long m = 1; + while (a != 0) { + if (a % 10 == 0) { + } else { + a1 = a1 + m * (a % 10); + m = m * 10; + } + a = a / 10; + } + m = 1; + while (b != 0) { + if (b % 10 == 0) { + } else { + b1 = b1 + m * (b % 10); + m = m * 10; + } + b = b / 10; + } + m = 1; + while (c != 0) { + if (c % 10 == 0) { + } else { + c1 = c1 + m * (c % 10); + m = m * 10; + } + c = c / 10; + } + if (a1 + b1 == c1) + cout << "YES" << endl; + else { + cout << "NO" << endl; + } +} +int main() { + int a, b, cnt = 0; + cin >> a >> b; + while (a <= b) a *= 3, b *= 2, cnt++; + cout << cnt << endl; +} +int main() { + long long n, k; + cin >> n >> k; + vector divs; + for (long long i = 1; i * i <= n; i++) { + if ((n % i) == 0) { + divs.push_back(i); + if (n / i != i) { divs.push_back(n / i); } + } + } + if (divs.size() < k) { + cout << -1 << '\n'; + } else { + sort(divs.begin(), divs.end()); + cout << divs[k - 1] << '\n'; + } + return 0; +} +int main() { + int n, i, a, d; + char ch; + while (cin >> n) { + a = 0; + d = 0; + for (i = 1; i <= n; i++) { + cin >> ch; + if (ch == 'A') + a = a + 1; + else + d = d + 1; + } + if (a > d) + cout << "Anton" << endl; + else if (d > a) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int gcd(int a, int b) { + if (a < b) { + int t = a; + a = b; + b = t; + } + while (a % b) { + a = b; + b = a / b; + } + return b; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (1) { + n -= gcd(a, n); + if (n == 0) { + cout << "0" << endl; + break; + } + n -= gcd(b, n); + if (n == 0) { + cout << "1" << endl; + break; + } + } + return 0; +} +int main() { + int k, l, m, n, d, x = 1, count = 0, ar[100005]; + cin >> k >> l >> m >> n >> d; + for (int z = 0; z < d; z++) { + ar[z] = x; + x++; + } + for (int i = 0; i < d; i++) { + if (ar[i] % k == 0 || ar[i] % l == 0 || ar[i] % m == 0 || ar[i] % n == 0) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; ++i) { cout << "1 " << i << endl; } + for (int i = 2; i <= n; ++i) { cout << i << " 1" << endl; } +} +int main() { + int n, m, count = 0, flag = 0; + cin >> n >> m; + int mn = m; + if (n < m) { + cout << -1 << endl; + return 0; + } else if (n == m) { + cout << n << endl; + return 0; + } + if (n % 2 == 0) + mn = n / 2; + else + mn = (n + 1) / 2; + while (mn % m != 0) mn++; + cout << mn << endl; + return 0; +} +int main() { + long long int n; + string s; + cin >> s; + n = s.length(); + if (s[0] > 96 && s[0] < 123) { s[0] = s[0] - 32; } + cout << s << "\n"; +} +int main() { + int a, b, c, d, e, f, n; + cin >> a >> b >> c >> d >> e >> f; + cin >> n; + int cup = a + b + c; + int med = d + e + f; + n -= cup / 5; + n -= med / 10; + if (cup < 5 && cup != 0) n--; + if (med < 10 && med != 0) n--; + if (cup > 5 && cup % 5 > 0) n--; + if (med > 10 && med % 10 > 0) n--; + cout << ((n < 0) ? "NO" : "YES") << endl; + return 0; +} +const int N = 6e5 + 10; +int v[N], A[N], B[N]; +int n; +void dfs(int x) { + if (v[x]) return; + v[x] = 1; + dfs(A[x]); +} +int main() { + cin >> n; + int ans = 0; + for (int i = 1; i <= n; ++i) cin >> A[i]; + for (int i = 1; i <= n; ++i) cin >> B[i]; + for (int i = 1; i <= n; ++i) { + if (v[i] == 0) dfs(i), ++ans; + } + int t = 1; + for (int i = 1; i <= n; ++i) { + if (B[i]) t ^= 1; + } + if (ans == 1) --ans; + cout << ans + t << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int k1 = 1; + int k2 = 2; + int k3 = 4; + int k = 0; + while (a > 0 && b > 0 && c > 0) { + a = a - k1; + b = b - k2; + c = c - k3; + if (a < 0 || b < 0 || c < 0) { + } else { + k++; + } + } + int s = k * 7; + cout << s << endl; +} +int main() { + string str; + int n, i, cnt = 0, ct = 0; + cin >> n; + cin >> str; + for (i = 0; i < n; i++) { + if (str[i] == 'A') { + cnt++; + } else { + ct++; + } + } + if (cnt > ct) { + cout << "Anton" << endl; + } else if (cnt == ct) { + cout << "Friendship" << endl; + } else { + cout << "Danik" << endl; + } + return 0; +} +int main() { + long long n, k, i, count = 0, ans; + string s; + long long m[26]; + cin >> n >> k; + cin >> s; + for (i = 0; i < k; i++) m[i] = 0; + for (i = 0; i < n; i++) { m[s[i] - 'A']++; } + ans = m[0]; + for (i = 0; i < k; i++) { ans = min(ans, m[i]); } + cout << ans * k << endl; +} +const int max_n = 2e2; +long long a[max_n]; +long long n, d, cnt, p, l; +int main() { + cin >> n >> d; + if (n == 1) return cout << 2 << '\n', 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (i == 0) { + cnt++; + p = a[0] + d; + if (abs(p - a[1]) > d) + cnt++; + else if (abs(p - a[1]) == d) { + cnt++; + l++; + } + } else if (i == n - 1) { + cnt++; + p = a[n - 1] - d; + if (abs(p - a[n - 2]) > d) + cnt++; + else if (abs(p - a[n - 2]) == d) { + cnt++; + l++; + } + } else { + p = a[i] - d; + if (abs(p - a[i - 1]) > d) + cnt++; + else if (abs(p - a[i - 1]) == d) { + cnt++; + l++; + } + p = a[i] + d; + if (abs(p - a[i + 1]) > d) + cnt++; + else if (abs(p - a[i + 1]) == d) { + cnt++; + l++; + } + } + } + cout << cnt - (l / 2) << '\n'; + return 0; +} +int main() { + int a[5], sum = 0; + for (int i = 0; i < 5; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 5 == 0 && sum != 0) { + cout << sum / 5 << endl; + } else { + cout << -1 << endl; + } +} +int main() { + int all, one, more, maxs, last; + cin >> all >> one >> maxs >> more >> last; + int days = 0, see = 0; + while (true) { + see += one; + days++; + if (see >= all) break; + see -= last; + one = min(maxs, one + more); + } + cout << days << endl; + return 0; +} +int main() { + int l, counta = 0; + cin >> l; + while (l--) { + string str; + cin >> str; + if (str[0] == '+' || str[2] == '+') { + counta++; + } else { + counta--; + } + } + cout << counta << endl; +} +int main() { + int n, k; + int index = 0; + int number; + cin >> n >> k; + int a[100]; + int b[100] = {0}; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n; i++) { + b[index]++; + if (a[i + 1] != a[i]) index++; + } + int max = 0; + for (int i = 0; i < index; i++) { + if (max < b[i]) max = b[i]; + } + if ((max % k) == 0 && max >= k) + number = index * (int(max / k)) * k - n; + else + number = index * (int(max / k) + 1) * k - n; + cout << number << endl; + return 0; +} +int main() { + int a[4], ct = 0; + cin >> a[0] >> a[1] >> a[2] >> a[3]; + for (int i = 0; i < 3; i++) { + for (int j = i + 1; j < 4; j++) { + if (a[i] != a[j]) ct++; + } + } + if (ct == 0) + ct = 3; + else if (ct == 3 || ct == 4) + ct = 2; + else if (ct == 5) + ct = 1; + else + ct = 0; + cout << ct << endl; + return 0; +} +const long double pi = acos(-1); +long long power(long long x, long long y) { + if (y == 0) return 1; + long long temp = power(x, y / 2) % 1000000007; + temp *= temp; + temp %= 1000000007; + if (y % 2) temp *= x; + return temp % 1000000007; +} +int main() { + string second; + cin >> second; + bitset<200> b; + for (int i = 0; i < second.size(); i++) { + if (second[second.size() - i - 1] == '1') b[i] = 1; + } + long long ans = 0; + for (int i = 0; i < second.size(); i++) { + ans += power(2, i) * (long long)b[i]; + ans %= 1000000007; + } + cout << (ans * power(2, second.size() - 1) % 1000000007) % 1000000007 << endl; +} +int main() { + string s; + cin >> s; + int l, index; + l = s.size(); + if (l == 1) { + cout << s << endl; + } else { + if (l % 2 == 0) { + index = (l / 2) - 1; + } else { + index = (l / 2); + } + cout << s[index]; + int i = index + 1; + int j = index - 1; + while (1) { + if (i < l && j >= 0) { + cout << s[i] << s[j]; + } else if (i > l && j >= 0) { + cout << s[j]; + } else if (i < l && j < 0) { + cout << s[i]; + } else { + break; + } + i++; + j--; + } + cout << endl; + } +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + long long ans = 0, cnt = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + int mn = *min_element(a, a + n); + for (int i = 0; i < n; i++) + if (a[i] == mn || (a[i] - mn) % k == 0) { + ans += (a[i] - mn) / k; + cnt++; + } + if (cnt == n) + cout << ans << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int c1, c2, c3, m1, m2, m3, n; + while (cin >> c1 >> c2 >> c3 >> m1 >> m2 >> m3) { + cin >> n; + int sumC, sumM, x = 0, y, a = 0, b; + sumC = c1 + c2 + c3; + sumM = m1 + m2 + m3; + x = sumC / 5; + y = sumC % 5; + if (y > 0) x++; + a = sumM / 10; + b = sumM % 10; + if (b > 0) a++; + if (a + x <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + vector v; + for (int i = 0; i < n; i++) { + int r; + cin >> r; + v.push_back(r); + } + sort(v.begin(), v.end()); + int c1 = 0; + int c2 = 0; + for (int i = 0; i < n; i++) { + if (v[i] == 1) + c1++; + else + c2++; + } + int c = 0; + if (c2 >= c1) { + c += c1; + } else { + c += c2; + c1 -= c2; + c += (c1 / 3); + } + cout << c << endl; + } +} +int main() { + int p, n, x, flag = 0; + int arr[305]; + for (int i = 0; i < 300; i++) { arr[i] = 0; } + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (arr[x % p] == 0) { + arr[x % p] = 1; + } else { + cout << i + 1 << endl; + flag = 1; + break; + } + } + if (!flag) { cout << -1 << endl; } + return 0; +} +const int maxn = 100 + 5; +int f[maxn]; +int main() { + int i, x; + for (i = 1; i < maxn; i += 2) { f[i] = f[i + 1] = (i / 2) * i + (i / 2 + 1); } + while (cin >> x) { + for (i = 1; i < maxn; i += 2) { + if (x == 3) { + cout << 5 << endl; + break; + } else if (x <= f[i]) { + cout << i << endl; + break; + } + } + } + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int ans = 0; + for (int i = 1; i <= 1000; i++) { + int x = i * 2; + int y = i * 4; + if (a >= i && b >= x && c >= y) { + ans = i + x + y; + } else { + break; + } + } + cout << ans << endl; + } +} +int main() { + int i, j, k, m, n; + cin >> n; + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.size(); ++i) { + if (i % n == 0 && i >= 3) { + int mode = 1; + for (int j = 2; j <= 3; ++j) { + if (s[(i - j + s.size()) % s.size()] != s[(i - j + 1 + s.size()) % s.size()]) mode = 0; + } + if (mode) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, tota = 0, totd = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + char c; + cin >> c; + if (c == 'A') { + tota++; + } else { + totd++; + } + } + if (tota > totd) { + cout << "Anton" << endl; + } else if (totd > tota) { + cout << "Danik" << endl; + } else { + cout << "Friendship" << endl; + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int d[a + 1], e = 9999999; + for (int i = 0; i < a; i++) { cin >> d[i]; } + for (int i = 0; i < a; i++) { + if (d[i] != 0) { + if (c >= d[i]) { e = min(abs(i - (b - 1)), e); } + } + } + for (int i = 0; i < a; i++) { + if (d[i] != 0) { + if (c >= d[i]) { + if (abs(i - (b - 1)) == e) { + cout << e * 10 << endl; + return 0; + } + } + } + } +} +int main() { + int x, y, total = 0; + string players[2]; + players[0] = "empty"; + players[1] = "empty"; + cin >> x >> y; + int index = 0; + while (true) { + while (true) { + if (index == 1) { + if (y >= 2) { + total = 20; + y -= 2; + if (y >= 10) { + total += 100; + y -= 10; + if (y >= 10) { + total += 100; + y -= 10; + players[index] = "win"; + break; + } else { + if (x >= 1) { + total += 100; + x--; + players[index] = "win"; + break; + } else { + y += 12; + players[index] = "lose"; + break; + } + } + } else { + if (x >= 2) { + total += 200; + x -= 2; + players[index] = "win"; + break; + } else { + y += 2; + players[index] = "lose"; + break; + } + } + } else { + players[index] = "lose"; + break; + } + } else { + if (x >= 2) { + total += 200; + x -= 2; + if (y >= 2) { + total += 20; + y -= 2; + players[index] = "win"; + break; + } else { + x += 2; + players[index] = "lose"; + break; + } + } else if (x == 1 && y >= 12) { + total = 220; + x--; + y -= 12; + players[index] = "win"; + break; + } else if (y >= 22) { + total = 220; + y -= 22; + players[index] = "win"; + break; + } else { + players[index] = "lose"; + break; + } + } + } + if (players[0].compare("lose") == 0 || players[1].compare("lose") == 0) { break; } + if (index == 0) { + index++; + } else { + index = 0; + } + } + if (players[1].compare("lose") == 0) { + cout << "Ciel" << endl; + } else { + cout << "Hanako" << endl; + } + return 0; +} +int imin, imax, jmin, jmax; +string M[110]; +int N[110][110]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> M[i]; + imin = jmin = 110; + imax = jmax = -1; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + if (M[i][j] == '*') { + imin = min(imin, i); + imax = max(imax, i); + jmin = min(jmin, j); + jmax = max(jmax, j); + } + if (M[imin][jmin] == '.') + cout << imin + 1 << " " << jmin + 1 << '\n'; + else if (M[imax][jmax] == '.') + cout << imax + 1 << " " << jmax + 1 << '\n'; + else if (M[imin][jmax] == '.') + cout << imin + 1 << " " << jmax + 1 << '\n'; + else if (M[imax][jmin] == '.') + cout << imax + 1 << " " << jmin + 1 << '\n'; + return 0; +} +int main() { + int n, Count = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) Count++; + } + cout << Count << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int count = v0; + int n; + int sum = 1; + while (count < c) { + sum++; + if (((sum - 1) * (a) + (v0)) <= v1) { + count = count + (sum - 1) * a + v0 - l; + } else { + count = count + v1 - l; + } + } + cout << sum << endl; +} +int main() { + int n, d, dp[105], res; + string str; + cin >> n >> d; + cin >> str; + dp[0] = 0; + for (int i = 1; i < n; ++i) { + if (str[i] == '1') { + res = INT_MAX; + for (int j = i - 1; j >= 0 && j >= i - d; --j) { + if (str[j] == '1') { res = min(res, dp[j]); } + } + dp[i] = (res == INT_MAX) ? INT_MAX : (res + 1); + } + } + res = (dp[n - 1] == INT_MAX) ? -1 : dp[n - 1]; + cout << res << endl; +} +vector a(10000); +int main() { + int n, i = 0; + for (cin >> n; cin >> a[i++];) + ; + for (i = 1; a[i] > a[i - 1] && i < n; ++i) + ; + for (; a[i] == a[i - 1] && i < n; ++i) + ; + for (; a[i] < a[i - 1] && i < n; ++i) + ; + cout << (i - n ? "NO\n" : "YES\n"); +} +const int maxn = 5e5 + 1000; +int k[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> k[i]; + int minn = INT_MAX; + for (int i = 1; i <= n; i++) { + int sumtime = 0; + for (int j = 1; j <= k[i]; j++) { + int tmp; + cin >> tmp; + sumtime += tmp; + } + sumtime = sumtime * 5 + 15 * k[i]; + minn = min(minn, sumtime); + } + cout << minn << endl; +} +const int mod = 1000000007; +const long long inf = 1000000000000; +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << '\n'; + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3; + cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3; + int n; + cin >> n; + int sum1 = a1 + a2 + a3; + int sum2 = b1 + b2 + b3; + if (sum1 % 5 == 0) { + n = n - (sum1 / 5); + } else { + n = n - ((sum1 / 5) + 1); + } + if (sum2 % 10 == 0) { + n = n - (sum2 / 10); + } else { + n = n - ((sum2 / 10) + 1); + } + if (n >= 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a, b, n, simon, antisimon; + bool x; + cin >> a >> b >> n; + for (int i = 0;; i++) { + simon = __gcd(a, n); + if (simon > n) { + x = false; + break; + } + n = n - simon; + antisimon = __gcd(b, n); + if (antisimon > n) { + x = true; + break; + } + n = n - antisimon; + } + if (x == true) + cout << "0" << endl; + else + cout << "1" << endl; +} +long long minodd = 69696969696, blyat, ans, odds; +int main() { + long long b; + cin >> b; + for (int a = 0; a < b; a++) { + cin >> blyat; + ans += blyat; + if (blyat % 2 == 1) odds++; + if (minodd > blyat && blyat % 2 == 1) minodd = blyat; + } + if (b == 1 && minodd != 0 && odds > 1) + cout << 0 << endl; + else if (odds % 2 == 1) + cout << ans - minodd << "\n"; + else + cout << ans << "\n"; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + for (int i = y; i >= 0; i--) { + if (i + 1 <= b && i + 2 <= r) { + cout << 3 * i + 3 << endl; + return 0; + } + } + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << endl; } + return 0; +} +int main() { + int a, b, c, d; + while (cin >> a >> b >> c >> d) { + if (a > b) + cout << "First" << endl; + else + cout << "Second" << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x; + if (b < 2 || c < 4) { + cout << 0 << endl; + return 0; + } + for (int i = 1; i <= a; i++) { + if (i * 2 > b || i * 4 > c) + break; + else { + x = i; + } + } + cout << 7 * x << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, b; + int ans = 0; + while (n--) { + cin >> a >> b; + while (ans >= a) a += b; + ans = a; + } + cout << ans << endl; + return 0; +} +int main() { + set s; + int n, res; + cin >> n; + for (int i = 0; i < n; i++) { + int s, d; + cin >> s >> d; + if (i == 0) + res = s; + else { + while (s <= res) { s += d; } + res = s; + } + } + cout << res << endl; + return 0; +} +int main() { + int x1, x2, y1, y2, a, b; + cin >> x1 >> y1 >> x2 >> y2 >> a >> b; + int t1 = abs(y1 - y2); + if ((t1 % b) != 0) { + cout << "NO" << endl; + return 0; + } + int t2 = abs(x1 - x2); + if ((t2 % a) != 0) { + cout << "NO" << endl; + return 0; + } + int count1 = abs(y1 - y2) / b, count2 = abs(x1 - x2) / a; + int t3 = abs(count1 - count2); + if (!(t3 % 2 == 0)) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +const int MAXN = 101; +char data[MAXN]; +int dp[MAXN]; +int main() { + int n, d; + cin >> n >> d; + for (int i = 1; i < n + 1; i++) { cin >> data[i]; } + for (int i = 1; i < n + 1; i++) { dp[i] = 1e9; } + dp[1] = 0; + for (int i = 1; i < n + 1; i++) { + if (data[i] == '1') { + for (int j = i + 1; j < i + d + 1; j++) { + if (j <= n) { + if (data[j] == '1') { dp[j] = min(dp[j], dp[i] + 1); } + } + } + } + } + if (dp[n] == 1e9) { dp[n] = -1; } + cout << dp[n] << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + int mi = 9999999; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + for (int i = 0; i < n; ++i) { + int s = 0; + for (int j = 0; j < arr[i]; ++j) { + int r; + cin >> r; + s += r; + } + s *= 5; + arr[i] *= 15; + s += arr[i]; + mi = min(mi, s); + } + cout << mi << '\n'; +} +const int MAXN = 200 * 1000; +int arr[MAXN + 10]; +string str1, str2; +bool good(int a) { + int cnt = 0; + for (int i = 0; i < (int)str2.size(); i++) { + while (cnt < (int)str1.size() && (arr[cnt] < a || str1[cnt] != str2[i])) cnt++; + if (cnt == (int)str1.size()) return false; + cnt++; + } + return true; +} +int main() { + cin >> str1 >> str2; + for (int i = 0; i < (int)str1.size(); i++) { + int a; + cin >> a; + arr[a - 1] = i; + } + int l = -1, r = (int)str1.size(); + while (r - l > 1) { + int mid = (r + l) / 2; + if (!good(mid)) + r = mid; + else + l = mid; + } + cout << l << endl; + return 0; +} +int main() { + long int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int s, f, t, ans; + cin >> s >> f >> t; + if (s == f) + ans = t; + else if (s < f) { + for (int k = 0;; k++) { + ans = 2 * k * (m - 1) + f - 1; + if (t <= s - 1 + 2 * k * (m - 1)) break; + } + } else { + for (int k = 0;; k++) { + ans = 2 * k * (m - 1) - f + 2 * m - 1; + if (t <= 2 * k * (m - 1) - s + 2 * m - 1) break; + } + } + cout << ans << endl; + } + return 0; +} +const int MAXN = 100000 + 10; +const long double eps = 1e-10; +int cnt[MAXN]; +int check(int n) { + for (int i = 0; i + 2 < n; i++) { + if (cnt[i] == 0) continue; + if (cnt[i] >= 2 && cnt[i + 1] >= 0) return 1; + if (cnt[i] <= -2 && cnt[i + 1] <= 0) return -1; + cnt[i + 1] += cnt[i]; + cnt[i + 2] += cnt[i]; + } + long double p = sqrt((long double)5) + 1; + p /= 2; + long double ret = p * cnt[n - 2] + cnt[n - 1]; + if (fabs(ret) < eps) return 0; + if (ret > 0) return 1; + return -1; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int n = max(s1.size(), s2.size()); + if (s1.size() < n) s1 = string(n - s1.size(), '0') + s1; + if (s2.size() < n) s2 = string(n - s2.size(), '0') + s2; + for (int i = 0; i < n; i++) { + int a = s1[i] - '0'; + int b = s2[i] - '0'; + cnt[i] = a - b; + } + int ret = check(n); + if (ret == 0) + cout << "=" << endl; + else if (ret == -1) + cout << "<" << endl; + else + cout << ">" << endl; + return 0; +} +int main() { + int n, x, a, b; + cin >> n >> x; + int begin = 1; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + while (a - begin >= x) { begin += x; } + sum += b - begin + 1; + begin = b + 1; + } + cout << sum << endl; + return 0; +} +int GCD(int a, int b) { + if (a == 0) + return b; + else + return GCD(b % a, a); +} +int main() { + long long a, b, n; + cin >> a >> b >> n; + int x = a; + long long Count = 0; + long long gcd = GCD(x, n); + while (gcd <= n) { + Count++; + n = n - gcd; + if (x == a) { + x = b; + gcd = GCD(x, n); + } else { + x = a; + gcd = GCD(x, n); + } + } + if (Count % 2 == 1) + cout << 0 << endl; + else + cout << 1 << endl; +} +int main() { + int n, m; + while (cin >> n >> m) { + int count = 0; + if (n == m) + cout << '1' << endl; + else if (n < m) { + while (1) { + n *= 3; + m *= 2; + count++; + if (n > m) { + cout << count << endl; + break; + } + } + } + } + return 0; +} +long int a[100000]; +int main() { + long long int n, k; + cin >> n >> k; + long long int i; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int yu = a[0] % k; + long long int time = 0; + for (i = 1; i < n; i++) { + if (a[i] % k != yu) { + cout << "-1" << endl; + return 0; + } + time += (a[i] - a[0]) / k; + } + cout << time << endl; + return 0; +} +int cls(int x) { + if (x > 0) return 1; + if (x == 0) return 2; + if (x < 0) return 3; +} +int main() { + int n, a, b, ml, mp; + cin >> n >> a; + ml = 0; + for (int i = 2; i <= n; i++) { + cin >> b; + mp = cls(b - a); + if (mp < ml) { + cout << "NO" << endl; + return 0; + } + a = b; + ml = mp; + } + cout << "YES" << endl; + return 0; +} +int min(int a, int b) { + if (a < b) return a; + return b; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = min(a, min(b - 1, c - 2)); + cout << x + x + 1 + x + 2 << endl; +} +int main() { + int c, v0, v1, a, l, ans; + cin >> c >> v0 >> v1 >> a >> l; + ans = 1; + c = (c - v0) * (c >= v0); + while (c) { + if (v1 >= v0 + a) + v0 = v0 + a; + else + v0 = v1; + ans++; + c = (c + l - v0) * (c + l >= v0); + } + cout << ans << endl; + return 0; +} +int ans(string s, int k) { + int n = s.size(); + if (s[0] == '0') return -1; + int counter = 0; + int current = n - 1; + int flag = 0; + while (current != 0) { + for (int i = k; i >= 1; i--) { + if (current - i >= 0 && s[current - i] == '1') { + if (current - i == 0) { + counter++; + return counter; + } + current = current - i; + counter++; + flag = 1; + break; + } + } + if (flag == 0) return -1; + flag = 0; + } + return -1; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + cout << ans(s, k) << '\n'; + return 0; +} +int cmp(int a, int b, int c) { + int tmp; + if (a < b) + tmp = a; + else + tmp = b; + if (tmp < c) + return tmp; + else + return c; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << cmp(a, b / 2, c / 4) * 7 << endl; +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1); +const long long MOD = (long long)1e9 + 7; +void fast_io() {} +int main() { + int n, maxi = 360, tot, ke; + int arr[400]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + tot = 0; + ke = i; + for (;;) { + tot += arr[ke]; + ke++; + if (tot >= 180) { + maxi = min(maxi, tot - abs(360 - tot)); + break; + } + if (ke == n) ke = 0; + } + } + cout << maxi << "\n"; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int main() { + desperate_optimization(10); + int n; + cin >> n; + cout << n; + for (int i = 1; i < n; i++) cout << " " << i; + cout << '\n'; + return 0; +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + int c = 0; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int limak = 0; + int bob = 0; + cin >> limak >> bob; + int k = 0; + while (limak <= bob) { + limak *= 3; + bob *= 2; + k++; + } + cout << k << endl; + return 0; +} +long long n, m, d, cnt, ans, sum, rem = 0, x, z, b, c; +vector v, v1, v2, v3; +string s; +map make_pair; +set se; +char h, r; +char a[20][20]; +int ro[20]; +int co[20]; +int main() { + int r, c; + cin >> r >> c; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> a[i][j]; + if (a[i][j] == 'S') { + ro[i] = -1; + co[j] = -1; + } + } + } + int sum = 0; + for (int i = 0; i < r; i++) { + if (ro[i] != -1) { + for (int j = 0; j < c; j++) { + sum++; + a[i][j] = 'n'; + } + } + } + for (int i = 0; i < c; i++) { + if (co[i] != -1) { + for (int j = 0; j < r; j++) { + if (a[j][i] != 'n') sum++; + } + } + } + cout << sum << endl; + return 0; +} +long long x, y, z, t1, t2, t3, e; +int main() { + cin >> x >> y >> z >> t1 >> t2 >> t3; + e = abs(z - x) * t2; + e += t3 * 3; + e += abs(y - x) * t2; + t1 *= abs(y - x); + if (t1 >= e) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + char ch; + int a[27] = {0}, n = 0; + cin.get(ch); + while ((ch = cin.get()) != '\n') { + if (ch == '{') + continue; + else if (ch == '}') + break; + else { + if (ch >= 'a' && ch <= 'z') { + if (a[ch - 'a'] == 0) { + a[ch - 'a'] = 1; + n++; + } + } + } + ch = ' '; + } + cout << n << endl; +} +int main() { + int n, m, res = 0, rowsDeleted = 0; + cin >> n; + cin >> m; + char **inputArr = new char *[n]; + bool *rows = new bool[n](); + bool *cols = new bool[m](); + for (int i = 0; i < n; i++) { inputArr[i] = new char[m]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> inputArr[i][j]; + if (inputArr[i][j] == 'S') { + rows[i] = true; + cols[j] = true; + } + } + } + for (int i = 0; i < n; i++) { + if (rows[i] == false) { + res += m; + rowsDeleted++; + } + } + for (int j = 0; j < m; j++) { + if (cols[j] == false) { res += n - rowsDeleted; } + } + cout << res << endl; + return 0; +} +int main() { + int n, i, j, k, ans; + cin >> n; + vector a(n + 1), s(n + 1); + s[0] = 0; + for (i = 1; i <= n; i++) { + cin >> a[i]; + s[i] = s[i - 1] + a[i]; + } + ans = 360; + for (i = 1; i <= n; i++) { + for (j = i; j <= n; j++) ans = min(ans, abs((s[j] - s[i - 1]) - (360 - (s[j] - s[i - 1])))); + } + cout << ans << "\n"; + return 0; +} +int main() { + int arrOccur[26] = {0}, n, k; + char c; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> c; + arrOccur[c - 'A']++; + } + cout << (*min_element(arrOccur, arrOccur + k)) * k << endl; + return 0; +} +int x = 0, k; +int f(int i, int j) { + if (i < j) swap(i, j); + int temp; + if (i == 1) return 1; + if (j == 1) return 1; + while (j > 0) { + temp = j; + j = i % j; + i = temp; + } + return i; +} +int main() { + int a, b, n; + while (cin >> a >> b >> n) { + while (1) { + n = n - f(a, n); + if (n < 0) { + cout << 1 << endl; + break; + } + n = n - f(b, n); + if (n < 0) { + cout << 0 << endl; + break; + } + } + } + return 0; +} +int main() { + long long int n, p, sum = 0, m = 10000000000; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p; + sum += p; + if (p % 2 != 0 && p < m) { m = p; } + } + if (sum % 2 == 0) { + cout << sum << endl; + } else { + cout << sum - m << endl; + } + return 0; +} +int main() { + int y, r, b, ans; + while (cin >> y >> b >> r) { + int ans = min(y + 2, min(b + 1, r)) * 3; + cout << ans - 3 << endl; + } + return 0; +} +int n, m, l, r, x; +string s; +int main() { + cin >> n >> m; + r = 0; + l = n + 1; + for (int i = 0; i < m; ++i) { + cin >> s; + cin >> s; + cin >> s; + if (s == "left") { + cin >> s >> x; + l = min(l, x); + } else { + cin >> s >> x; + r = max(r, x); + } + } + if (l - r - 1 <= 0) + cout << -1 << endl; + else + cout << l - r - 1 << endl; +} +int main() { + int c, v0, v1, a, l, ans = 0, t = 1; + cin >> c >> v0 >> v1 >> a >> l; + c -= v0; + while (c > 0) { + int v = v0 + t * a; + int m = min(v1, v); + c -= m; + c += l; + t++; + } + cout << t << endl; + return 0; +} +int main() { + int a, b, cn = 0; + cin >> a >> b; + char c; + for (int i = 0; i < a * b; i++) { + cin >> c; + if (c == 'C' || c == 'M' || c == 'Y') cn++; + } + if (cn > 0) + cout << "#Color\n"; + else + cout << "#Black&White\n"; + return 0; +} +int main() { + int n, m, temp, si, fi, t, position; + cin >> n >> m; + temp = m - 1; + for (int i = 0; i < n; i++) { + bool up = false, down = false, gotodown = false, gotoup = false; + int moves = 0; + cin >> si >> fi >> t; + position = t % temp; + if (t / temp % 2) { + down = true; + position = m - position; + } else { + up = true; + position++; + } + if (si - fi > 0) + gotodown = true; + else if (si - fi < 0) + gotoup = true; + if (down == 1 && gotodown == 1) { + if (position >= si) { + moves = (position - fi); + } else { + moves = (position - 1) + temp + (m - fi); + } + } else if (down == 1 && gotoup == 1) { + moves = (position - 1) + (fi - 1); + } + if (up == 1 && gotoup == 1) { + if (position <= si) + moves = fi - position; + else { + moves = (m - position) + temp + (fi - 1); + } + } else if (up == 1 && gotodown == true) { + moves = (m - position) + (m - fi); + } + cout << moves + t << endl; + } + return 0; +} +int main() { + int k, l, m, n, d, ct = 0; + cin >> k >> l >> m >> n >> d; + int dragon[d + 1]; + memset(dragon, 0, sizeof(dragon)); + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) { ct++; } + } + cout << ct << endl; + return 0; +} +int main() { + int n, m, i, j, k, a[2000], flag = 0; + char temp[10]; + cin >> n >> m; + memset(a, 0, sizeof(a)); + for (i = 0; i < m; i++) { + cin >> temp >> temp >> temp; + if (temp[0] == 'l') + flag = 0; + else + flag = 1; + cin >> temp >> k; + if (flag) + for (j = k; j > 0; j--) a[j] = 1; + else + for (j = k; j <= n; j++) a[j] = 1; + } + flag = 0; + for (i = 1; i <= n; i++) + if (a[i] == 0) flag++; + if (flag) + cout << flag << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = min(a, min(b / 2, c / 4)); + cout << 7 * x << endl; + return 0; +} +int a[110]; +int main() { + int n, k; + cin >> n >> k; + int Max = 0; + int num = 0; + for (int i = 0; i < n; i++) { + int m; + cin >> m; + a[m]++; + if (a[m] == 1) num++; + if (a[m] > Max) Max = a[m]; + } + if (Max % k == 0) + cout << Max * num - n << endl; + else + cout << (Max / k + 1) * num * k - n << endl; + return 0; +} +int main() { + long long int i, n, d, a[110], cnt = 2; + ; + cin >> n >> d; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n - 1; i++) { + if ((a[i + 1] - a[i]) > (2 * d)) + cnt += 2; + else if ((a[i + 1] - a[i]) == (2 * d)) + cnt += 1; + } + cout << cnt << endl; +} +const int INF = 0x3f3f3f3f; +string a, b; +int n[100005]; +int main() { + while (cin >> a >> b) { + memset(n, 0, sizeof(n)); + int cnt4 = 0; + int cnt7 = 0; + for (int i = 0; i < a.length(); i++) { + if (a[i] != b[i]) { + if (b[i] == '4') + n[i] = 1; + else + n[i] = 2; + } + if (n[i] == 1) cnt4++; + if (n[i] == 2) cnt7++; + } + int maxn = max(cnt4, cnt7); + cout << maxn << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + if (n % 4 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + } else { + if ((n - 1) % 4 == 0) + cout << 1 << endl; + else + cout << 0 << endl; + } + return 0; +} +int main() { + string s[60]; + int p[60], m[60], a[60], b[60], c[60], d[60], e[60]; + int n; + cin >> n; + int pos, mx = -99999, S; + for (int i = 0; i < n; i++) { + cin >> s[i] >> p[i] >> m[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; + S = p[i] * 100 - m[i] * 50 + a[i] + b[i] + c[i] + d[i] + e[i]; + if (S > mx) { + mx = S; + pos = i; + } + } + cout << s[pos] << endl; + return 0; +} +int main() { + long long k, d; + cin >> k >> d; + if (d == 0 && k > 1) { + cout << "No solution" << endl; + } else { + cout << d; + k--; + while (k) { + cout << 0; + k--; + } + cout << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + b /= 2; + if (b % 2 < 0) { --b; } + c /= 4; + if (c % 2 < 0) { --c; } + d = min(a, min(b, c)); + cout << d * 7 << endl; + return 0; +} +int main() { + int n; + string str; + cin >> n >> str; + int ans = 0; + for (int i = n; i < str.size(); i += n) + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) ans++; + cout << ans << '\n'; + return 0; +} +int x, y, xx, yy, a, b, w, q; +bool even(int a) { + return a % 2; +} +inline int abs(int a) { + if (a >= 0) return a; + return -a; +} +bool isint(double a) { + return a == (int)a; +} +int main() { + cin >> x >> y >> xx >> yy >> a >> b; + q = abs(x - xx); + w = abs(y - yy); + if (!isint(q * 1.0 / a) || !isint(w * 1.0 / b)) { + cout << "NO" << endl; + return 0; + } + if (even(q * 1.0 / a) == even(w * 1.0 / b)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, k; +int main() { + int a, b, c; + cin >> k >> n; + for (int i = 1; i <= k; i++) { + int t = 0; + cin >> a >> b >> c; + if (a == b) { + cout << c << endl; + continue; + } + t += 2 * (n - 1) * (c / (2 * (n - 1))); + c -= t; + if (a < b) { + if (c >= a) t += 2 * (n - 1); + t += (b - 1); + } else { + t += (n - 1); + c -= (n - 1); + if (c > (n - a)) t += 2 * (n - 1); + t += n - b; + } + cout << t << endl; + } +} +int main() { + int a; + int m; + cin >> a; + cin >> m; + map ma; + ma[a % m] = 1; + int count = 1; + a += a % m; + do { + if (a % m == 0) { + cout << "Yes" << endl; + return 0; + } else { + if (ma[(a % m)] > 0) { + cout << "No" << endl; + return 0; + } else { + ma[a % m]++; + a += a % m; + count++; + } + } + } while (count < m); + cout << "No" << endl; + return 0; +} +int main() { + int n; + string x, y; + cin >> n >> x; + n += 2; + x = 'x' + x + 'x'; + bool cek = true; + int stop = -1; + for (int i = 0; i < n - 1; i++) { + if (x[i] == 'o' && x[i + 2] == 'o' && x[i + 1] == 'g') { + stop = i + 2; + i++; + if (cek) { + y += "***"; + cek = false; + } + } else { + if (i == stop) { + cek = true; + continue; + } + if (i != 0) y += x[i]; + } + } + cout << y << endl; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int ans = 0; + for (int i = 1; i < n; i++) { + if (s[i - 1] == s[i]) { + char c = s[i - 1]; + while (s[i] == c) { + i++; + ans++; + } + i--; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + char x; + cin >> a >> b; + int flag = 0; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { + cin >> x; + if ((x == 'C') || (x == 'M') || (x == 'Y')) { + flag = 1; + break; + } + } + if (flag == 1) break; + } + if (flag == 0) + cout << "#Black&White" + << "\n"; + else + cout << "#Color" + << "\n"; + return 0; +} +map enemy; +int main() { + string s; + int K; + cin >> s >> K; + for (int i = 1; i <= K; i++) { + char enemy1, enemy2; + cin >> enemy1 >> enemy2; + enemy[enemy1] = enemy2; + enemy[enemy2] = enemy1; + } + bool warOpen = false; + char particpant1, particpant2; + int army1 = 0, army2 = 0, ans = 0, N = s.size(); + for (int i = 0; i < N; i++) { + if (i + 1 < N && (s[i + 1] == enemy[s[i]] || s[i] == s[i + 1])) { + if (warOpen) { + if (s[i + 1] == particpant1) + army1++; + else + army2++; + } else { + warOpen = true; + particpant1 = s[i]; + particpant2 = enemy[s[i]]; + if (s[i] == s[i + 1]) + army1 = 2, army2 = 0; + else + army1 = army2 = 1; + } + } else { + warOpen = false; + ans += min(army1, army2); + army1 = army2 = 0; + } + } + cout << ans << endl; + return 0; +} +int maximumValue(int a, int maximum) { + if (a > maximum) { + maximum = a; + return maximum; + } else + return maximum; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + bool f = true; + int counter = 0; + int maximum = INT_MIN; + while (f) { + if (counter == 0) { + d = a + b * c; + maximum = maximumValue(d, maximum); + counter++; + } + if (counter == 1) { + d = a * (b + c); + maximum = maximumValue(d, maximum); + counter++; + } + if (counter == 2) { + d = a * b * c; + maximum = maximumValue(d, maximum); + counter++; + } + if (counter == 3) { + d = (a + b) * c; + maximum = maximumValue(d, maximum); + counter++; + } + if (counter == 4) { + d = a + b + c; + maximum = maximumValue(d, maximum); + } + f = false; + } + cout << maximum << endl; +} +int main() { + int a, n = 5, total = 0; + while (n--) { + cin >> a; + total += a; + } + if (total == 0) { + cout << -1; + } else if (total % 5 == 0) { + cout << (total / 5); + } else { + cout << -1; + } + cout << endl; + return 0; +} +int main() { + int a, b, c, d, e, x, y, z; + cin >> a >> b; + c = 0; + while (a <= b) { + a = a * 3; + b = b * 2; + c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, d; + string s; + cin >> n >> d >> s; + int dp[n + 1]; + dp[0] = 0; + for (int i = 1; i < n; ++i) { + if (s[i] == '1') { + dp[i] = 1e9; + for (int j = i - d; j < i; ++j) { + if (j < 0) continue; + dp[i] = min(dp[j] + 1, dp[i]); + } + } else { + dp[i] = 1e9; + } + } + if (dp[n - 1] >= 1e9) { + cout << "-1\n"; + return 0; + } + cout << dp[n - 1] << endl; + return 0; +} +int main() { + long long int a, b, sum = 0; + cin >> a >> b; + sum = (a + 1) / 2; + if (sum >= b) + cout << (b * 2) - 1 << endl; + else + cout << (b - sum) * 2 << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[110]; + memset(a, 0, sizeof a); + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int len1 = 0x3c3c3c, len2 = 0x3c3c3c; + for (int i = 1; m + i <= n; i++) { + if (a[m + i] <= k && a[m + i] != 0) { + len1 = i; + break; + } + } + for (int i = 1; m - i >= 1; i++) { + if (a[m - i] <= k && a[m - i] != 0) { + len2 = i; + break; + } + } + int ans; + ans = min(len1, len2); + cout << ans * 10 << endl; + return 0; +} +map myMap; +int main() { + int n, i, flag = 0; + string s; + s = s + '-' + '-'; + cin >> n >> s; + for (i = 0; i < n; i++) { + while (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + cout << "***"; + i += 3; + while (s[i] == 'g' && s[i + 1] == 'o') { i += 2; } + } + if (i >= n) { break; } + cout << s[i]; + } + cout << endl; +} +char c[1000000]; +int arr[1000000]; +int a[5][5]; +int main() { + long long k, l, m, n, d, res = 0; + cin >> k >> l >> m >> n >> d; + for (int i = 1; i <= d; i++) { + if (i % k != 0 && i % l != 0 && i % m != 0 && i % n != 0) res++; + } + cout << d - res << endl; + return 0; +} +long long a, ans; +string S; +int main() { + cin >> a; + for (int i = 0; i < a; i++) { + cin >> S; + if (S[1] == '+') + ans++; + else + ans--; + } + cout << ans << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int sum = 0; + if (v0 > v1) v0 = v1; + for (int i = 1;; i++) { + if (v0 > v1) v0 = v1; + sum += v0; + v0 += a; + if (sum >= c) { + cout << i << endl; + break; + } + sum -= l; + } + return 0; +} +int n; +const int maxn = 1e5 + 10; +char a[maxn]; +int main() { + while (cin >> n) { + int sum = 0; + string s; + cin >> s; + for (int i = n; i < s.size(); i += n) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) sum++; + } + cout << sum << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } +} +int main() { + int n, i, j, k, ct; + cin >> n; + vector a(n), b(n); + for (i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b.begin(), b.end()); + ct = 0; + for (i = 0; i < n; i++) { + if (a[i] != b[i]) ct++; + } + if (ct <= 2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +long long int palindrome(char *s) { + long long int i, n = strlen(s); + for (i = 0; i <= n - n / 2; i++) { + if (s[i] != s[n - i - 1]) return 0; + } + return 1; +} +long long int sameletter(char *s) { + long long int i; + for (i = 1; i < strlen(s); i++) { + if (s[i] != s[i - 1]) return 0; + } + return 1; +} +int main() { + char s[60], t[60]; + cin >> s; + if (sameletter(s)) + cout << "0" << endl; + else { + if (!palindrome(s)) + cout << strlen(s) << "\n"; + else { + for (long long int i = 1; i < strlen(s); i++) { + strcpy(t, s + i); + if (!palindrome(t)) { + cout << strlen(t) << "\n"; + break; + } + } + } + } + return 0; +} +void read(int &x) { + x = 0; + bool f = 0; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = 1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + (ch - 48); + ch = getchar(); + } + if (f) x = -x; +} +void read(long long &x) { + x = 0; + bool f = 0; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = 1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + (ch - 48); + ch = getchar(); + } + if (f) x = -x; +} +int main() { + long long x; + read(x); + if (x == 3) { + cout << 5 << endl; + return 0; + } + for (int i = 1; true; i += 2) { + if (i * i / 2 + 1 >= x) { + cout << i << endl; + return 0; + } + } + return 0; +} +int vl, vr, ml, mr; +bool judge(int g, int b) { + if (b < g - 1) + return false; + else if (b > 2 * g + 2) + return false; + else + return true; +} +int main() { + cin >> vl >> vr >> ml >> mr; + if (judge(vl, mr) || judge(vr, ml)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int count = 0, rount = 0, i, n; + string joy; + cin >> n; + cin >> joy; + for (i = 0; i < n; i++) { + if (joy[i] == 'A') + count++; + else + rount++; + } + if (count > rount) + cout << "Anton" << endl; + else if (rount > count) + cout << "Danik" << endl; + if (count == rount) cout << "Friendship" << endl; +} +int main() { + int n, arr[100010]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 1; i < n; i++) { cout << arr[i] + arr[i - 1] << " "; } + cout << arr[n - 1] << endl; + return 0; +} +int main() { + int a, b, ae, be; + int x, y; + cin >> a >> b >> ae >> be; + cin >> x >> y; + int val1 = abs(ae - a); + int val2 = abs(be - b); + if (val1 % x == 0 && val2 % y == 0 && (val1 / x) % 2 == (val2 / y) % 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool isPrime(int n) { + if (n < 2) return false; + int h = sqrt(n); + for (int i = 2; i <= h; i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int n, i, j; + cin >> n; + bool check = true; + for (i = 2; i < n; i++) { + for (j = 2; j < n; j++) { + if (!isPrime(i) && !isPrime(j)) { + if (i + j == n) { + check = false; + break; + } + } + } + if (!check) break; + } + cout << i << " " << j << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { + cout << "#Color\n"; + return 0; + } + } + } + cout << "#Black&White\n"; + return 0; +} +int main() { + int n, ca = 0, cd = 0; + char s; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> s; + if (s == 'A') + ca++; + else if (s == 'D') + cd++; + } + if (ca > cd) + cout << "Anton" << endl; + else if (cd > ca) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int n, k; +string s; +int a[26]; +int main() { + cin >> n >> k >> s; + for (int i = 0; i < n; i++) { a[s[i] - 'A']++; } + int m = n; + for (int i = 0; i < k; i++) { m = min(m, a[i]); } + cout << m * k << endl; +} +bool f(int n) { + if (n % 2 == 0) return true; + for (int i = 3; i * i <= n; i = i + 2) { + if (n % i == 0) return true; + } + return false; +} +int main() { + int n; + cin >> n; + for (int i = 4;; i++) { + int y = n - i; + if (f(i) && f(y)) { + cout << i << " " << y << endl; + break; + } + } + return 0; +} +string st; +int main() { + cin >> st; + int len = st.length(), mar = 1, marr = 0; + for (int i = 0; i < len / 2; i++) { + if (i > 0 && st[i] == st[i - 1]) marr += 2; + if (len - i - 1 < len && st[len - i - 1] == st[len - i + 1 - 1]) marr += 2; + if (st[i] != st[len - i - 1]) { + mar = 0; + break; + } + } + marr = 1; + for (int i = 1; i < len; i++) { + if (st[i] != st[i - 1]) { + marr = 0; + break; + } + } + if (mar == 0) { + cout << len << endl; + return 0; + } + if (marr == 1) { + cout << 0 << endl; + return 0; + } else + cout << len - 1 << endl; + return 0; +} +long long p[103]; +int main() { + long long n, d; + cin >> n >> d; + string s; + cin >> s; + fill(p, p + 103, 1e9); + p[0] = 0; + for (long long i = 1; i < n; i++) { + for (int j = 0; j < d; j++) + if (s[i + j] == '1') p[i + j] = min(p[i + j], p[i - 1] + 1); + } + if (p[n - 1] == 1e9) + cout << "-1\n"; + else + cout << p[n - 1] << endl; +} +int n; +int main() { + cin >> n; + bool pt = false; + int phase = 1; + int last = 0; + if (n == 1) { + cout << "YES" << endl; + return 0; + } + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (phase == 1) { + if (last < temp) { + last = temp; + } else { + phase = 2; + } + } + if (phase == 2) { + if (last == temp) { + pt = true; + last = temp; + } else { + phase = 3; + } + } + if (phase == 3) { + if (last > temp) { + last = temp; + } else { + phase = 0; + } + } + } + if (phase != 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int maxn = 400; +int n; +int a[maxn]; +int sum = 0; +int ans = 360; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + sum = 0; + for (int j = i; j < n; j++) { + sum += a[j]; + ans = min(ans, abs((360 - sum) - sum)); + } + } + cout << ans << endl; + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << max(abs(y2 - y1), abs(x2 - x1)) << endl; + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int x[2], y[2], a, b; + cin >> x[0] >> y[0] >> x[1] >> y[1] >> a >> b; + int dx = abs(x[1] - x[0]); + int dy = abs(y[1] - y[0]); + string ans = "NO"; + if (dx % a == 0 && dy % b == 0) { + if ((dx / a) % 2 == (dy / b) % 2) ans = "YES"; + } + cout << ans << '\n'; +} +int main() { + int n; + string ss; + cin >> n >> ss; + int in = -1; + for (int i = 0; i < n - 1; i++) { + if (ss[i] > ss[i + 1]) { + in = i; + break; + } + } + if (in == -1) n--; + for (int i = 0; i < n; i++) { + if (i != in) cout << ss[i]; + } + cout << endl; + return 0; +} +int main() { + long long n, x, a, b; + cin >> n >> x; + long long begin = 1; + long long sum = 0; + for (long long i = 0; i < n; i++) { + cin >> a >> b; + while (a - begin >= x) { begin += x; } + sum += b - begin + 1; + begin = b + 1; + } + cout << sum << endl; + return 0; +} +bool isPrime(int n) { + if (n < 2) return false; + int h = sqrt(n); + for (int i = 2; i <= h; i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int n, i, j; + cin >> n; + bool check = true; + for (i = 2; i < n; i++) { + for (j = 2; j < n; j++) { + if (!isPrime(i) && !isPrime(j)) { + if (i + j == n) { + check = false; + break; + } + } + } + if (!check) break; + } + cout << i << " " << j << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +int arr[100010]; +int main() { + int n, a = 0, d = 0; + cin >> n; + string x; + cin >> x; + for (int i = 0; i < x.length(); i++) { + if (x[i] == 'A') + a++; + else + d++; + } + if (a > d) + cout << "Anton" << endl; + else if (a < d) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + float cup1, cup2, cup3, med1, med2, med3, selves, c, m; + cin >> cup1 >> cup2 >> cup3 >> med1 >> med2 >> med3 >> selves; + c = ceil((cup1 + cup2 + cup3) / 5); + m = ceil((med1 + med2 + med3) / 10); + if ((c + m) <= selves) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int n, k, minm = INT_MAX; + cin >> n >> k; + string s; + cin >> s; + map mp; + for (long long int i = 0; i < n; i++) { mp[s[i] - 'A']++; } + for (long long int i = 0; i < k; i++) { minm = min(mp[i], minm); } + cout << minm * k << endl; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else + cout << "Second" << endl; +} +int n, m; +char a; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> a; + if (a == 'C' || a == 'M' || a == 'Y') { + cout << "#Color" << endl; + return 0; + } + } + cout << "#Black&White" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int s, d, day = 1; + cin >> s >> d; + day = s; + for (size_t i = 1; i < n; i++) { + cin >> s >> d; + if (s > day) + day = s; + else { + int temp = day - s; + temp = temp / d + 1; + day = s + temp * d; + } + } + cout << day << '\n'; + return 0; +} +const string V = "aeiouy"; +bool vowel(char c) { + return V.find(c) != -1; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + cout << s[0]; + for (int i = 1; i < n; i++) + if (!vowel(s[i - 1]) || !vowel(s[i])) cout << s[i]; + cout << endl; +} +const int MAXN = 99999; +const int INF = (1 << 30); +const double PI = acos(-1.0); +const double EPS = 1e-11; +const long long MOD = 1000000007; +int n; +string s; +long long twoPower(int x) { + long long t; + if (x == 0) return 1; + if (x == 1) return 2; + t = twoPower(x / 2); + if (x % 2 == 0) { + return (t * t) % MOD; + } else { + return (t * t) % MOD * 2 % MOD; + } +} +int input() { + cin >> s; + n = s.size(); + return 0; +} +long long rec(int i) { + if (i == n - 1) { return s[i] - '0'; } + if (s[i] == '0') + return 2 * rec(i + 1) % MOD; + else + return (2 * rec(i + 1) + twoPower(2 * (n - i - 1))) % MOD; +} +int main() { + input(); + cout << rec(0) << endl; + return 0; +} +int main() { + int i, t, j; + cin >> t; + int num[101]; + char name[101][11]; + char pos[101][6]; + for (i = 0; i < t; i++) { + cin >> name[i]; + cin >> pos[i]; + if (strcmp(pos[i], "rat") == 0) num[i] = 1; + if (strcmp(pos[i], "woman") == 0) num[i] = 2; + if (strcmp(pos[i], "child") == 0) num[i] = 3; + if (strcmp(pos[i], "man") == 0) num[i] = 4; + if (strcmp(pos[i], "captain") == 0) num[i] = 5; + } + for (i = 0; i < t; i++) { + if (num[i] == 1) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 2 || num[i] == 3) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 4) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 5) cout << name[i] << endl; + } + return 0; +} +int main() { + int n, sum = 1, vv, p = 0; + string s, l, k, nn; + getline(cin, nn); + getline(cin, k); + stringstream(nn) >> n; + stringstream(k) >> sum; + getline(cin, l); + for (int i = 0; i < n - 1; i++) { + getline(cin, s); + stringstream my(s); + while (my >> vv) { + if (sum == vv || (7 - sum) == vv) { p++; } + } + sum = 7 - sum; + } + if (p > 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n1, n2, k1, k2; + while (cin >> n1 >> n2 >> k1 >> k2) { + if (n1 <= n2) + cout << "Second" << endl; + else + cout << "First" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long total(0); + for (long p = 0; p < n; p++) { + long long m; + cin >> m; + total += (m - 1) * (p + 1) + 1; + } + cout << total << endl; + return 0; +} +int main() { + string s; + int a = 0, d = 0, n; + char c; + cin >> n; + cin >> s; + stringstream ss(s); + while (ss >> c) { + if (c == 'A') a++; + if (c == 'D') d++; + } + if (a == d) + cout << "Friendship" << endl; + else { + if (a > d) + cout << "Anton" << endl; + else + cout << "Danik" << endl; + } + return 0; +} +const long long Mod = 1e9 + 7; +const double pi = 2 * acos(0.0); +const int N = 2005; +int arr[N], n; +long long gcd(long long a, long long b) { + return (b == 0 ? a : gcd(b, a % b)); +} +int main() { + int x, val, ones = 0; + cin >> n; + cin >> arr[0]; + x = arr[0]; + ones += x == 1; + for (int i = 1; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) ones++; + if (x != 1) x = gcd(x, arr[i]); + } + if (x != 1) { + cout << -1 << endl; + return 0; + } + if (ones) { + cout << n - ones << endl; + return 0; + } + x = Mod; + for (int i = 0; i < n; i++) { + val = arr[i]; + for (int j = i + 1; j < n; j++) { + val = gcd(val, arr[j]); + if (val == 1) { + x = min(x, j - i); + break; + } + } + } + cout << x + n - 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long sum = 0, cur; + for (size_t i = 0; i < n; i++) { + cin >> cur; + sum += cur; + } + long long Max1 = -1, Max2 = -1; + for (size_t i = 0; i < n; i++) { + cin >> cur; + if (cur > Max1) { + Max2 = Max1; + Max1 = cur; + } else if (cur > Max2) { + Max2 = cur; + } + } + cout << ((Max2 + Max1 >= sum) ? "YES\n" : "NO\n"); + return 0; +} +int main() { + string x; + cin >> x; + if (islower(x[0])) { x[0] = toupper(x[0]); } + cout << x << endl; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int d = 0; + if (x1 < x2 && y1 < y2) { + if ((x2 - x1) >= (y2 - y1)) { + d = x2 - x1; + } else { + d = y2 - y1; + } + } else if (x1 < x2 && y1 > y2) { + if ((x2 - x1) >= (y1 - y2)) { + d = x2 - x1; + } else { + d = y2 - y1; + } + } else if (x1 > x2 && y1 < y2) { + if ((x1 - x2) >= (y2 - y1)) { + d = x1 - x2; + } else { + d = y2 - y1; + } + } else if (x1 > x2 && y1 > y2) { + if ((x1 - x2) >= (y1 - y2)) { + d = x1 - x2; + } else { + d = y1 - y2; + } + } else if (x1 == x2 && y1 > y2) { + d = y1 - y2; + } else if (x1 == x2 && y1 < y2) { + d = y2 - y1; + } else if (x1 > x2 && y1 == y2) { + d = x1 - x2; + } else if (x1 < x2 && y1 == y2) { + d = x2 - x1; + } + cout << d << endl; + return 0; +} +bool check(int d, int m) { + if (m <= 2 * (d + 1) && (m >= d - 1)) return 1; + return 0; +} +int main() { + int l1, r1, l2, r2; + cin >> l1 >> r1 >> l2 >> r2; + if (check(l1, r2) || check(r1, l2)) { + cout << "YES\n"; + } else + cout << "NO\n"; +} +const int MAX = 2005; +int a[MAX]; +int main() { + int n; + cin >> n; + int cnt1 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) cnt1++; + } + if (cnt1 > 0) { + cout << n - cnt1 << "\n"; + return 0; + } + int ans = n * 3; + for (int i = 0; i < n; i++) { + int g = a[i]; + for (int j = i + 1; j < n; j++) { + g = __gcd(g, a[j]); + if (g == 1) ans = min(ans, n - 1 + j - i); + } + } + if (ans == n * 3) ans = -1; + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + int b[11]; + int c[11]; + for (int i = 0; i < 11; i++) { + b[i] = 1; + c[i] = 1; + } + int flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'S') { + b[i] = 0; + c[j] = 0; + flag = 1; + } + } + } + int rowCount = 0, colCount = 0, cakes = 0; + for (int i = 0; i < n; i++) { + if (b[i] != 0) { + cakes += m; + rowCount++; + } + } + for (int i = 0; i < m; i++) { + if (c[i] != 0) { + cakes += n; + colCount++; + } + } + if (flag == 0) + cout << n * m << endl; + else if (rowCount != 0 && colCount != 0) + cout << cakes - (rowCount * colCount) << endl; + else if (rowCount == 0 || colCount == 0) + cout << cakes << endl; +} +int main() { + long long a, m; + cin >> a >> m; + for (int i = 0; i <= (1e7); i++) { + if (a % m == 0) { + cout << "Yes\n"; + return 0; + } + a += (a % m); + } + cout << "No\n"; +} +int main() { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + cout << (x / 7) + (x % 7 != 0) << endl; + } + return 0; +} +int main() { + int n, num[1005]; + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> num[i]; } + int k = 0; + for (int i = 2; i <= n; ++i) { + if (num[i] > num[i - 1]) { + k++; + } else + continue; + } + for (int i = k + 2; i <= n; ++i) { + if (num[i] == num[i - 1]) { + k++; + } else + continue; + } + for (int i = k + 2; i <= n; ++i) { + if (num[i] < num[i - 1]) { k++; } + } + if (k < n - 1) + cout << "NO" << '\n'; + else + cout << "YES" << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int arr[100001]; + int hh; + for (int i = 0; i < n; i++) { + cin >> hh; + arr[i] = arr[i - 1] + hh; + } + int ans = 10001; + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { ans = min(ans, abs(2 * (arr[j] - arr[i]) - 360)); } + } + cout << ans << endl; +} +int main() { + int q; + cin >> q; + while (q--) { + long long a, b, c; + cin >> a >> b >> c; + long long tmp = c; + if (c < a) { + cout << c << endl; + } else { + tmp = b / c; + tmp = (tmp + 1) * c; + cout << tmp << endl; + } + } +} +int main() { + int n, c = 0; + string s; + cin >> n; + getchar(); + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'U' && s[i - 1] == 'R') { + i++; + c++; + } else if (s[i - 1] == 'U' && s[i] == 'R') { + i++; + c++; + } + } + cout << n - c << endl; + return 0; +} +int main() { + int l, d, pos; + int num = 1; + int ano; + cin >> l >> d >> pos; + int i; + for (i = 1; i <= l; i++) { + ano = 1; + while (ano <= d) { + if (num == pos) { cout << i << " " << ano << " "; } + if (num % 2 == 0) ano++; + num++; + } + } + if (pos % 2 == 0) { + cout << "R" << endl; + } else + cout << "L" << endl; + return 0; +} +int main() { + string s; + cin >> s; + map f; + int k; + cin >> k; + for (int i = 0; i < k; ++i) { + string a; + cin >> a; + f[a[0]] = a[1]; + f[a[1]] = a[0]; + } + int n = s.size(); + int ans = 0; + int count = 1; + int i = 1; + while (i < n) { + if (s[i] == s[i - 1]) { + count++; + i++; + } else if (f.count(s[i - 1]) && s[i] == f[s[i - 1]]) { + if (!count) count = 1; + int count2 = 0; + int j = i; + while (j < n && (s[j] == s[i] || s[j] == s[i - 1])) { + if (s[j] == s[i]) + count2++; + else + count++; + j++; + } + ans += min(count, count2); + i = j + 1; + count = 1; + } else { + count = 1; + i++; + } + } + cout << ans << "\n"; +} +int main() { + string a[6]; + int n, k = 0; + cin >> n; + for (int i = 0; i < 6; i++) { a[i] = "ttttttttttttttttttttttttttt"; } + a[0][0] = '+'; + a[0][25] = '+'; + a[5][0] = '+'; + a[5][25] = '+'; + a[1][26] = ')'; + a[4][26] = ')'; + for (int i = 1; i < 25; i++) { + a[0][i] = '-'; + a[5][i] = '-'; + if (i >= 2 && (i % 2 == 0)) { + a[1][i] = '.'; + a[2][i] = '.'; + a[4][i] = '.'; + if (i == 24) a[1][i] = 'D'; + } + if (i >= 2) { a[3][i] = '.'; } + } + for (int i = 1; i < 5; i++) { + a[i][0] = '|'; + a[i][25] = '|'; + if (i != 3) a[i][23] = '|'; + } + for (int i = 1; i < 23; i += 2) { + for (int j = 1; j < 5; j++) { + if (a[j][i] == 't') { + if (k != n) { + k++; + a[j][i] = 'O'; + } else + a[j][i] = '#'; + } + } + } + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 26; j++) { + if (i == 1 || i == 4) { + cout << a[i]; + break; + } + cout << a[i][j]; + } + cout << endl; + } +} +int min(int a, int b) { + if (a < b) + return a; + else + return b; +} +int main() { + string str1; + string str2; + cin >> str1 >> str2; + int count1 = 0; + int count2 = 0; + for (int i = 0; i < str1.length(); i++) { + if (str1[i] == '7' && str2[i] == '4') { count1++; } + if (str1[i] == '4' && str2[i] == '7') { count2++; } + } + if (count2 == 0 && count1 == 0) { + cout << "0" << endl; + return 0; + } + cout << max(count1, count2) << endl; +} +int main() { + int c1, c2, c3, c4, c5; + cin >> c1 >> c2 >> c3 >> c4 >> c5; + int m = c1 + c2 + c3 + c4 + c5; + if (m % 5 == 0 && m != 0) { + cout << m / 5 << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + int n, r = 0; + cin >> n; + string s; + while (n--) { + cin >> s; + if (s[1] == '+') + ++r; + else + --r; + } + cout << r << endl; + return 0; +} +int main() { + double n; + int a, ans = -1; + cin >> n >> a; + bool f = false; + int k = ceil(double(n / 2)); + for (int i = k; k <= n; k++) { + if (k % a == 0) { + ans = k; + break; + } + } + cout << ans << endl; +} +long long mod = 1000000007; +int main() { + long long n, l, r, d; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> l >> r >> d; + long long b = r / d; + if (d < l) + cout << d << endl; + else + cout << d * (b + 1) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a, b; + int ans = 0; + while (n--) { + cin >> a >> b; + while (ans >= a) a += b; + ans = a; + } + cout << ans << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + int a, b, c, d; + cin >> a >> b >> c >> d; + if ((c - (b - 1)) < 5 && c - b + 1 >= 0) { + cout << "YES" << endl; + return 0; + } + if ((d - (a - 1)) < 5 && d - a + 1 >= 0) { + cout << "YES" << endl; + return 0; + } + if ((c - (b - 1) * 2) < 5 && c - (b - 1) >= 0) { + cout << "YES" << endl; + return 0; + } + if ((d - (a - 1) * 2) < 5 && d - (a - 1) >= 0) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, D = 0; + cin >> n; + int a[1001]; + int x = 1; + if (n == 1) + cout << "YES" << endl; + else + while (true) { + x = 2 * x; + if (x == n) { + cout << "YES" << endl; + break; + } + if (x > n) { + D++; + break; + } + } + if (D != 0) cout << "NO" << endl; + return 0; +} +int main() { + int maxx, a, b, c; + cin >> a >> b >> c; + a = (a + 1) / 2; + b = (b + 1) / 2; + c = (c + 1) / 2; + maxx = max(max(a, b), c); + if (maxx == c) + cout << 30 + 3 * (c - 1) + 2 << endl; + else if (maxx == b) + cout << 30 + 3 * (b - 1) + 1 << endl; + else if (maxx == a) + cout << 30 + 3 * (a - 1) << endl; + return 0; +} +int main() { + int n, ans = 0; + string s; + cin >> n >> s; + int x = 0, y = 0; + for (int i = 0; i < (n - 1); i++) { + x = 0; + y = 0; + if (s[i] == 'U') + y++; + else if (s[i] == 'D') + y--; + else if (s[i] == 'R') + x++; + else + x--; + for (int j = i + 1; j < n; j++) { + if (s[j] == 'U') + y++; + else if (s[j] == 'D') + y--; + else if (s[j] == 'R') + x++; + else + x--; + if (x == 0 && y == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int N, K[105], M[105], sum = 2e9, ans; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) cin >> K[i]; + for (int i = 1; i <= N; i++) { + ans = 0; + for (int j = 1; j <= K[i]; j++) { + cin >> M[j]; + ans += M[j]; + } + sum = min(sum, ans * 5 + K[i] * 15); + } + cout << sum << '\n'; +} +int main() { + int p, q, temp = 0, move; + while (cin >> p >> q) { + if (p < q) cout << "-1" << endl; + if (p == q) { + cout << p << endl; + } else { + if (p % 2 == 0) { + temp = p / 2; + } else { + temp = (p - 1) / 2; + temp += 1; + } + move = 0; + while (temp != p) { + if (temp % q == 0) { + move = temp; + cout << move << endl; + break; + } else { + temp++; + } + } + } + } +} +int A[10000]; +int B[10000]; +int main() { + int n, ans = 0; + cin >> n; + if (n % 4 == 1 || n % 4 == 2) + cout << '1' << endl; + else + cout << '0' << endl; + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int cnt = 0; + while (a <= b) { + a *= 3; + b *= 2; + cnt++; + } + cout << cnt << endl; + } + return 0; +} +int arr1[1000000]; +int arr2[1000000]; +int main() { + int total; + cin >> total; + for (int i = 1; i <= total; i++) { + int val; + cin >> val; + arr1[i] = val; + } + for (int i = 1; i <= total; i++) { + int val; + cin >> val; + arr2[i] = val; + } + int j = 1; + for (int i = 1; i <= total; i++) { + if (arr2[i] == arr1[j]) j++; + } + cout << total - j + 1 << endl; +} +int main() { + int a, b, c, ans; + ans = 0; + cin >> a >> b >> c; + for (int i = 1;; i++) + if (a >= i && b >= 2 * i && c >= 4 * i) + ans = i; + else + break; + cout << 7 * ans << endl; + return 0; +} +long long n, m, a, b, x, ff, l, r, cnt, ans; +vector v, f, res; +string s1, s2; +long long used[1001]; +char arr[102][102]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cin >> arr[i][j]; } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (arr[i][j] == '*') { + a++; + used[j]++; + } + } + if (a == 1) ans = i; + a = 0; + } + for (int i = 1; i <= m; i++) { + if (used[i] == 1) { + cout << ans << " " << i << endl; + return 0; + } + } +} +int main() { + int n, k; + cin >> n >> k; + if (n < k || (k == 1 && n != 1)) + cout << -1 << endl; + else { + if (n >= 2) { + for (int i = 1; i <= n - k; i++) + if (i % 2 == 0) + cout << "b"; + else + cout << "a"; + if ((n - k) % 2 == 0) { + cout << "ab"; + for (int i = 3; i <= k; i++) cout << char(i + 'a' - 1); + } else { + cout << "ba"; + for (int i = 3; i <= k; i++) cout << char(i + 'a' - 1); + } + cout << endl; + } else + cout << "a" << endl; + } + return 0; +} +int gcd(int i, int j) { + int temp; + if (j == 0) + temp = i; + else + temp = gcd(j, i % j); + return temp; +} +int main() { + int a, b, n, temp, ans; + while (cin >> a >> b >> n) { + for (temp = 1;; temp++) { + if (temp % 2 == 1) { + n -= gcd(a, n); + if (n < 0) { + cout << 1 << endl; + break; + } + } else { + n -= gcd(b, n); + if (n < 0) { + cout << 0 << endl; + break; + } + } + } + } + return 0; +} +long long int pair1(long long int ar[], long long int n) { + long long int x, cnt = 0, id = -1; + for (long long int i = 1; i < n; i++) { + x = __gcd(ar[i - 1], ar[i]); + if (ar[i] == ar[i - 1] && ar[i] != 1) continue; + if (ar[i - 1] != 1 || ar[i] != 1) cnt++; + if (ar[i] != 1) + ar[i] = x; + else + ar[i - 1] = x; + if (x == 1) { + id = i; + break; + } + } + if (id == -1) return -1; + for (long long int i = id; i < n; i++) { + if (ar[i] != 1) cnt++; + } + for (long long int i = 0; i < id; i++) { + if (ar[i] != 1) cnt++; + } + return cnt; +} +long long int solve(long long int ar[], long long int n) { + long long int x, cnt = 0, id = -1; + for (long long int i = 1; i < n; i++) { + x = __gcd(ar[i - 1], ar[i]); + if (x == 1) { + if (ar[i] != 1) { + cnt++; + ar[i] = x; + id = i; + } else { + cnt++; + ar[i - 1] = x; + id = i - 1; + } + break; + } + } + if (id == -1) return -1; + for (long long int i = 0; i < id; i++) { + if (ar[i] != 1) cnt++; + } + for (long long int i = id; i < n; i++) { + if (ar[i] != 1) cnt++; + } + return cnt; +} +int main() { + long long int n, cnt = 0, id = -1; + cin >> n; + long long int ar[n]; + for (long long int i = 0; i < n; i++) { + cin >> ar[i]; + if (ar[i] == 1) id = i; + } + if (id != -1) { + for (long long int i = 0; i < id; i++) { + if (ar[i] != 1) cnt++; + } + for (long long int i = id; i < n; i++) { + if (ar[i] != 1) cnt++; + } + cout << cnt << endl; + return 0; + } + long long int x = solve(ar, n); + if (x != -1) + cout << x << endl; + else + cout << pair1(ar, n) << endl; + return 0; +} +int main() { + string s, w; + cin >> s; + int m{}, n{(int)s.length() - 1}; + if (s.length() % 2) { + for (int i = 0; i < s.length(); i++) { + if (i % 2 == 0) { + w = s[m] + w; + m++; + } else { + w = s[n] + w; + n--; + } + } + } else { + for (int i = 0; i < s.length(); i++) { + if (i % 2 == 1) { + w = s[m] + w; + m++; + } else { + w = s[n] + w; + n--; + } + } + } + cout << w << "\n"; + return 0; +} +int main() { + char s[100]; + int c = 0, i, n; + gets(s); + puts(strstr(s, "1111111") || strstr(s, "0000000") ? "YES" : "NO"); + return 0; +} +long long MOD = 1000000007; +int main() { + long long N, K; + cin >> N >> K; + long long res = 0; + long long a, X; + long long c = 0; + for (long long i = 0; i < K; i++) { + cin >> a; + for (long long j = 0; j < a; j++) { + cin >> X; + if (X == j + 1) { c++; } + } + } + cout << N - c + 1 - K + N - c << endl; +} +list *adj; +int height(int v) { + int h = 0; + list::iterator it; + for (it = adj[v].begin(); it != adj[v].end(); it++) { + if (*it != v) { + int temp = height(*it); + if (h < temp) h = temp; + } + } + return 1 + h; +} +int main() { + int n; + cin >> n; + adj = new list[n + 1]; + queue q; + for (int i = 1; i <= n; i++) { + int temp; + cin >> temp; + if (temp == -1) { + q.push(i); + continue; + } + adj[temp].push_back(i); + } + int max = 0; + while (!q.empty()) { + int v = q.front(); + q.pop(); + int h = height(v); + if (h > max) max = h; + } + cout << max << endl; + return 0; +} +int main() { + long long int x, y, z, m, k = 0, i = 1, p = 0, q = 0, j = 1, zy, h = 0, xy = 1; + cin >> x >> y; + z = x + y; + zy = z; + while (x) { + if (x) { + m = x % 10; + if (m) { + k += m * i; + i *= 10; + } + x = x / 10; + } + } + while (y) { + m = y % 10; + if (m) { + p += m * j; + j *= 10; + } + y = y / 10; + } + while (z) { + m = z % 10; + if (m) { + h += m * xy; + xy *= 10; + } + z = z / 10; + } + if (k + p == h) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, i, m; + int a, b; + cin >> n; + cin >> m >> b; + for (i = 1; i < n; i++) { + cin >> a >> b; + if (m >= a) { + m = m + b - (m - a) % b; + } else { + m = a; + } + } + cout << m << endl; + return 0; +} +int main() { + long long x1, y1, x2, y2, ans; + cin >> x1 >> y1 >> x2 >> y2; + long long a = abs(x2 - x1); + long long b = abs(y2 - y1); + if (a > b) { + cout << a << endl; + } else { + cout << b << endl; + } + return 0; +} +int dist[2][10004]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + string str; + cin >> str; + int firstone = -1; + int ff = 0; + while (ff < m && str[ff] != '1') ff++; + if (ff == m) { + cout << -1 << endl; + return 0; + } + firstone = ff; + dist[0][ff] = 0; + int j = (ff + 1) % m; + while (true) { + if (str[j] == '1') { + dist[0][j] = 0; + int k = j; + while (dist[0][k] < dist[0][(k - 1 + m) % m]) { + k = (k - 1 + m) % m; + dist[0][k] = dist[0][(k + 1) % m] + 1; + } + if (j == firstone) break; + } else { + dist[0][j] = dist[0][(j + m - 1) % m] + 1; + } + j = (j + 1) % m; + } + for (int z = 0; z < m; z++) { + dist[1][z] += dist[0][z]; + dist[0][z] = 0; + } + } + int minn = dist[1][0]; + for (int h = 1; h < m; h++) { + if (dist[1][h] < minn) { minn = dist[1][h]; } + } + cout << minn << endl; + return 0; +} +int arr[105]; +int main() { + int num, k; + cin >> num >> k; + int l = 1, r = num; + for (int i = 0; i < k; i++) { + string s1, s2, s3, s4; + int n; + cin >> s1 >> s2 >> s3 >> s4 >> n; + if (s3 == "right") { + if (l < n + 1) l = n + 1; + } + if (s3 == "left") { + if (r > n - 1) r = n - 1; + } + } + if (l > r) { + cout << -1 << endl; + } else + cout << r - l + 1 << endl; +} +int main() { + int a, b, i; + cin >> a >> b; + int x = a + b - 1; + cout << x << "\n"; + if (max(a, b) == a) { + for (i = 1; i <= b; i++) cout << 1 << " " << i << "\n"; + for (i = 2; i <= a; i++) cout << i << " " << 1 << "\n"; + } else { + for (i = 1; i <= b; i++) cout << 1 << " " << i << "\n"; + for (i = 2; i <= a; i++) cout << i << " " << 1 << "\n"; + } + return 0; +} +int main() { + int count = 0; + int a[4]; + cin >> a[0] >> a[1] >> a[2] >> a[3]; + for (int i = 0; i < 4; i++) { + for (int j = i + 1; j < 4; j++) { + if (a[i] == a[j]) { count++; } + } + } + if (count == 0) { + cout << "0" << endl; + return 0; + } + if (count == 1) { + cout << "1" << endl; + return 0; + } + if (count == 2) { + cout << "2" << endl; + return 0; + } + if (count == 3) { + cout << "2" << endl; + return 0; + } + if (count == 6) { + cout << "3" << endl; + return 0; + } +} +int ans[120]; +int from[120]; +int posx[120]; +int posy[120]; +int n; +void dfs(int x, int cot) { + from[x] = cot; + for (int i = 0; i < n; i++) { + if (!from[i] && (posx[x] == posx[i] || posy[x] == posy[i])) dfs(i, cot); + } +} +int main() { + cin >> n; + memset(from, 0, sizeof from); + for (int i = 0; i < n; i++) { cin >> posx[i] >> posy[i]; } + int cot = 0; + for (int i = 0; i < n; i++) { + if (!from[i]) { + cot++; + dfs(i, cot); + } + } + cout << cot - 1 << endl; + return 0; +} +int main() { + string inp; + cin >> inp; + int c = 0; + for (int i = 0; i < inp.size(); i++) { + string Danil5, Olya4, Salva5, Ann3, Nikita6; + string cop; + if ((inp.substr(i, 5)) == "Danil") { + c++; + } else if ((inp.substr(i, 4)) == "Olya") { + c++; + } else if ((inp.substr(i, 5)) == "Slava") { + c++; + } else if ((inp.substr(i, 3)) == "Ann") { + c++; + } else if ((inp.substr(i, 6)) == "Nikita") { + c++; + } + } + if (c == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const int mod = 1e9 + 7; +const int MAX = 100001; +int An[MAX]; +int main() { + int a, b, c; + cin >> a >> b >> c; + int t1 = a + b + c; + t1 = max(t1, (a + b) * c); + t1 = max(t1, a * b + c); + t1 = max(t1, a * b * c); + t1 = max(t1, a + b * c); + t1 = max(t1, a * (b + c)); + cout << t1 << endl; + return 0; +} +long long arr[1000000]; +set s; +map mm; +string ss[100000]; +char ch[100000]; +int main() { + int a, res = 0; + for (int i = 0; i < 5; i++) { + cin >> a; + res += a; + } + if (res == 0 || res % 5 != 0) { + cout << -1 << endl; + return 0; + } + cout << res / 5 << endl; +} +int main() { + int64_t a, b; + cin >> a >> b; + int c = 0; + while (a <= b) { + a *= 3; + b *= 2; + c++; + } + cout << c << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string palabra; + cin >> palabra; + string answer = ""; + long long aumento = 1; + for (long long i = 0; i < n; i = i + aumento) { + answer.append(palabra.substr(i, 1)); + aumento++; + } + cout << answer << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int x[4], y[4], c = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < m; j++) { + if (s[j] == '*') { + x[c] = i + 1; + y[c++] = j + 1; + } + } + } + if (x[0] == x[1]) + x[3] = x[2]; + else if (x[0] == x[2]) + x[3] = x[1]; + else + x[3] = x[0]; + if (y[0] == y[1]) + y[3] = y[2]; + else if (y[0] == y[2]) + y[3] = y[1]; + else + y[3] = y[0]; + cout << x[3] << " " << y[3] << endl; + return 0; +} +int main() { + long long int k, b, n, t, i, j, m = 0, ans, r, x = 1, xx = 0; + cin >> k >> b >> n >> t; + for (i = 1;; i++) { + r = (x * k) + b; + if (r <= t) + m++; + else + break; + x = r; + } + ans = n - m; + ans = max(xx, ans); + cout << ans << endl; +} +const int INF = 0x3f3f3f3f; +int check(char x) { + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y') + return 1; + else + return 0; +} +int main() { + int i, j, k; + int n, m; + char s[1005]; + cin >> n; + cin >> s; + for (i = 0; i < n - 1; i++) + if (check(s[i]) && check(s[i + 1])) swap(s[i], s[i + 1]), s[i] = '0'; + for (i = 0; i < n; i++) + if (s[i] != '0') cout << s[i]; + cout << endl; +} +int main() { + int n; + cin >> n; + int t; + vector a; + for (int i = 0; i < n; i++) { + cin >> t; + a.push_back(t); + } + if (a.size() < 3) { + cout << 0 << endl; + return 0; + } + sort(a.begin(), a.end()); + int cnt = 0; + for (int i = 1; i <= n - 2; i++) { + if (a[i] > a[0] && a[i] < a[n - 1]) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + int r, g, b, sum = 29; + cin >> r >> g >> b; + while (true) { + if (r == 0 && g == 0 && b == 0) { + break; + } else { + if (r >= 2) { + r = r - 2; + sum++; + } else if (r == 1) { + r = r - 1; + sum++; + } else if (r == 0 && g != 0 || b != 0) + sum++; + if (g >= 2) { + g = g - 2; + sum++; + } else if (g == 1) { + g = g - 1; + sum++; + } else if (g == 0 && r != 0 || b != 0) + sum++; + if (b >= 2) { + b = b - 2; + sum++; + } else if (b == 1) { + b = b - 1; + sum++; + } else if (b == 0 && g != 0 || r != 0) + sum++; + } + } + cout << sum << endl; + return 0; +} +int k, l, m, n, d; +int main() { + while (cin >> k >> l >> m >> n >> d) { + int t = 0; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) t++; + } + cout << t << endl; + } +} +int main() { + int bob = 0; + int Limak = 0; + int year_limake = 0; + cin >> Limak >> bob; + if (Limak < bob) { + for (int i = 0; i < bob; i++) { + ++year_limake; + bob = bob * 2; + Limak = Limak * 3; + if (Limak > bob) { break; } + } + cout << year_limake << endl; + } else if (Limak == bob) { + cout << 1 << endl; + } +} +int main() { + int n, m, st, fin, tim, timr; + cin >> n >> m; + while (n--) { + cin >> st >> fin >> tim; + timr = tim % (2 * (m - 1)); + if (st == fin) + cout << tim << "\n"; + else if (timr < st) { + if (st < fin) + cout << tim + (fin - timr - 1) << "\n"; + else + cout << tim - timr - 1 + (2 * m) - fin << "\n"; + } else { + if (timr < m) { + if (st > fin) + cout << (2 * m) - timr - 1 - fin + tim << "\n"; + else + cout << (2 * m) - timr - 3 + fin + tim << "\n"; + } else { + if (((2 * m) - timr - 1) >= st) { + if (st > fin) + cout << (2 * m) - timr - fin + tim - 1 << "\n"; + else + cout << (2 * m) - timr + fin - 3 + tim << "\n"; + } else { + if (st < fin) + cout << tim + (2 * m) - timr + fin - 3 << "\n"; + else + cout << tim + (4 * m) - timr - fin - 3 << "\n"; + } + } + } + } + return 0; +} +const int MAX_LEN = 5; +string buf[MAX_LEN + 5] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; +string s; +int ans = 0; +int main() { + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s.size() - i >= 5) { + if (s.substr(i, 5) == buf[0]) ++ans; + } + if (s.size() - i >= 4) { + if (s.substr(i, 4) == buf[1]) ++ans; + } + if (s.size() - i >= 3) { + if (s.substr(i, 3) == buf[3]) ++ans; + } + if (s.size() - i >= 5) { + if (s.substr(i, 5) == buf[2]) ++ans; + } + if (s.size() - i >= 6) { + if (s.substr(i, 6) == buf[4]) ++ans; + } + } + if (ans == 1) + puts("YES"); + else + puts("NO"); + return 0; +} +long long BigMod(long long N, long long P) { + if (P == 0) return 1; + if (P % 2 == 0) { + long long ret = BigMod(N, P / 2); + return ((ret % 998244353) * (ret % 998244353)) % 998244353; + } else + return ((N % 998244353) * (BigMod(N, P - 1) % 998244353)) % 998244353; +} +int main() { + long long n, k, x; + while (cin >> n >> k) { + long long mx = 0; + set st; + map mp; + for (long long i = 1; i <= n; i++) { + cin >> x; + st.insert(x); + mp[x]++; + mx = max(mx, mp[x]); + } + x = ceil((mx * 1.0) / k) * k * st.size(); + x -= n; + cout << x << endl; + } + return 0; +} +int main() { + cout.precision(0); + cout.setf(ios_base::fixed); + long long n, m; + cin >> n; + long double a, b, c; + while (n--) { + cin >> a >> b >> c; + double i = (a / c); + if (i <= 1) { + cout << (double)(int(b / c) + 1) * c << endl; + } else + cout << c << endl; + } +} +const long long MAXN = (int)1e6 + 1000; +const long long MAXB = (int)1e9 + 1000; +long long y = MAXB, ans, n, k, x, a[MAXN], b[MAXN]; +bool check; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i] / k; + } + x = a[0] % k; + for (int i = 0; i < n; i++) + if (a[i] % k != x) check++; + if (check) { + cout << "-1" << '\n'; + return 0; + } + for (int i = 0; i < n; i++) y = min(y, b[i]); + for (int i = 0; i < n; i++) ans += b[i] - y; + cout << ans << '\n'; + return 0; +} +string s, ans; +char ch; +int main() { + cin >> s; + ch = 'a'; + for (int i = s.size() - 1; i >= 0; i--) + if (s[i] == ch) + ans += s[i]; + else if (s[i] > ch) { + ans += s[i]; + ch = s[i]; + } + reverse(ans.begin(), ans.end()); + cout << ans << '\n'; + return 0; +} +int main() { + int n, a[2001], i, j, f, t; + while (cin >> n) { + f = 0; + memset(a, 0, sizeof(a)); + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + t = 0; + for (j = i; j <= n && j != -1; j = a[j]) { t++; } + f = max(f, t); + } + cout << f << endl; + } + return 0; +} +int main() { + int q; + cin >> q; + for (int i = 0; i < q; i++) { + int l, r, d; + cin >> l >> r >> d; + if (d < l) { + cout << d << endl; + } else if (r % d == 0) { + cout << r + d << endl; + } else { + int rem = r % d; + r -= rem; + r += d; + cout << r << endl; + } + } + return 0; +} +int a[1000]; +long long i, n, d, cou = 2; +int main() { + cin >> n; + cin >> d; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (i > 0) { + if (abs(a[i] - a[i - 1]) > 2 * d) + cou += 2; + else if (abs(a[i] - a[i - 1] == 2 * d)) + cou++; + } + } + cout << cou << endl; + return 0; +} +int n; +int A[60]; +int sum; +int B[60]; +int main() { + cin >> n; + sum = n; + int t = 0; + for (int i = 0; i < n; i++) { cin >> A[i]; } + for (int i = 0; i < n; i++) { + for (int x = i + 1; x < n; x++) { + if (A[i] == A[x]) { + A[i] = 0; + B[t] = i; + t++; + break; + } + } + } + for (int i = t - 1; i >= 0; i--) { + sum--; + for (int x = B[i]; x < n; x++) { + A[x] = A[x + 1]; + A[x + 1] = 0; + } + } + cout << sum << endl; + for (int i = 0; i < sum; i++) { + cout << A[i]; + if (i != sum - 1) { cout << " "; } + } + cout << endl; +} +int main() { + int i, j, k, l, m, n; + char x[500], y[500]; + cin >> x; + m = strlen(x); + j = m; + l = j; + for (i = 0; i < j; i++) { y[i] = x[--l]; } + y[i] = '\0'; + n = 1; + if (strcmp(x, y) == 0) { + m--; + for (i = 1; i < j; i++) { + if (x[0] == x[i]) n++; + } + } + if (n == j) m = 0; + cout << m << endl; + return 0; +} +int main() { + long long n; + while (cin >> n) { + int count = 0; + while (n > 1) { + if (n % 2 == 1) count++; + n = n / 2; + } + cout << count + 1 << endl; + } + return 0; +} +int main() { + int n, x1 = 0, y1 = 0, z1 = 0, x, y, z; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + x1 += x; + y1 += y; + z1 += z; + } + if (x1 == 0 && (y1 == 0 && z1 == 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int p(int n) { + for (int i = 2; i < n; i++) { + if (n % i == 0) return 1; + } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 4; i <= n / 2; i++) { + if (p(i) == 1) { + if (p(n - i) == 1) { + cout << i << " " << n - i << endl; + break; + } + } + } + return 0; +} +long long int max1(long long int x, long long int y) { + if (x >= y) + return x; + else + return y; +} +int main() { + long long int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + long long int maxi = max1(abs(x2 - x1), abs(y2 - y1)); + cout << maxi << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int ans = 0; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + long long sum; + while (cin >> n) { + sum = 0; + for (int i = 1; i <= n; i++) { + long long m; + cin >> m; + sum += i * (m - 1) + 1; + } + cout << sum << endl; + } +} +int n, m; +char c[105][105]; +int main() { + cin >> n >> m; + int row = 0, col = 0; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) { + cin >> c[i][j]; + if (c[i][j] == '*') row ^= i, col ^= j; + } + } + cout << row << " " << col << endl; + return 0; +} +int removeZeros(int num) { + int ret = 0; + int ten = 1; + while (num) { + int dig = num % 10; + num /= 10; + if (dig) { + ret += dig * ten; + ten *= 10; + } + } + return ret; +} +int main() { + int a, b, c; + cin >> a >> b; + c = a + b; + a = removeZeros(a); + b = removeZeros(b); + c = removeZeros(c); + if (a + b == c) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int ans = max(abs(x1 - x2), abs(y1 - y2)); + cout << ans << endl; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int main() { + desperate_optimization(10); + int n, k; + cin >> n >> k; + if (k == 0 && n != 1) { + cout << "No solution" << '\n'; + return 0; + } + if (k == 0) + cout << 0 << '\n'; + else { + cout << k; + for (int i = 1; i < n; i++) cout << 0; + cout << '\n'; + } + return 0; +} +bool snack[100009]; +int arr[100000]; +int main() { + bool flag = false; + int n, x; + char s[1000]; + cin >> n >> x; + int count = 0; + while (n <= x) { + count++; + n *= 3; + x *= 2; + } + cout << count << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + int streak = 1; + for (int i = 1; i < s.size(); i++) { + if (streak >= 7) { + cout << "YES" << endl; + return 0; + } + if (s[i - 1] == s[i]) { + streak++; + } else { + streak = 1; + } + } + if (streak >= 7) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long val[100005] = {0}; + long long dp[100005] = {0}; + long long x; + for (long long i = 0; i < n; i++) { + cin >> x; + val[x]++; + } + dp[0] = 0; + dp[1] = val[1]; + for (long long i = 2; i < 100005; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + val[i] * i); } + cout << dp[100004] << endl; +} +int main() { + set s; + bool udah = false; + int p, n, x, res; + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (s.count(x % p) && !udah) { + res = i + 1; + udah = true; + } else + s.insert(x % p); + } + if (udah) + cout << res << endl; + else + cout << -1 << endl; +} +int main() { + int a[50], b[50], v[1001] = {0}, n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = n - 1; i >= 0; i--) + if (!v[a[i]]) { + v[a[i]] = 1; + b[sum] = a[i]; + sum++; + } + cout << sum << endl; + for (int i = sum - 1; i > 0; i--) cout << b[i] << ' '; + cout << b[0] << endl; + return 0; +} +int main() { + int ans = 0, n; + string s; + cin >> n >> s; + for (int i = 0; i < n - 1; i++) + if (s[i] == s[i + 1]) ans++; + cout << ans << endl; +} +int n, m, b, mod; +int a[501], dp[501][501]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 0; i <= b; i++) dp[0][i] = 1; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + for (int k = a[i]; k <= b; k++) dp[j][k] = (dp[j][k] + dp[j - 1][k - a[i]]) % mod; + cout << dp[m][b] << endl; + return 0; +} +const int maxn = 1e5 + 10; +int n; +int k[maxn]; +int a[maxn]; +int sum = 0; +int mini = maxn; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> k[i]; + int t = 1; + for (int i = 1; i <= n; i++) { + sum = 0; + for (int j = 1; j <= k[t]; j++) { + cin >> a[j]; + sum += (a[j] * 5); + } + sum += (k[t] * 15); + t++; + mini = min(sum, mini); + } + cout << mini << endl; + return 0; +} +int main() { + string word; + cin >> word; + word[0] = toupper(word[0]); + cout << word << endl; + return 0; +} +int main() { + int x1, x2, y1, y2; + int x, y; + int f1, f2; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + f1 = abs(x2 - x1); + f2 = abs(y2 - y1); + if (f1 % x == 0 && f2 % y == 0 && (f1 / x) % 2 == (f2 / y) % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 3) { + cout << 5 << endl; + return 0; + } + int u = 1; + int k = 1; + while (u < n) { + u += (k * 4); + k++; + } + cout << k * 2 - 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int curDay = 0; + for (int i = 0; i < (int)n; i++) { + int s, d; + cin >> s >> d; + if (s > curDay) { + curDay = s; + } else { + curDay = ((curDay - s) / d + 1) * d + s; + } + } + cout << curDay << endl; + return 0; +} +int n, res; +string s, t; +bool is_return(string str) { + int x, y; + int len = str.length(); + x = y = 0; + for (int i = 0; i < len; i++) { + if (str[i] == 'U') + y++; + else if (str[i] == 'D') + y--; + else if (str[i] == 'L') + x--; + else if (str[i] == 'R') + x++; + } + if (x || y) return false; + return true; +} +int main() { + cin >> n >> s; + for (int i = 0; i < n - 1; i++) { + for (int j = 2; i + j <= n; j++) { + t = s.substr(i, j); + if (is_return(t)) res++; + } + } + cout << res << endl; + return 0; +} +int main() { + int a[5]; + cin >> a[0] >> a[1] >> a[2] >> a[3]; + sort(a, a + 4); + int sum = 0; + for (int i = 1; i < 4; i++) { + if (a[i] == a[i - 1]) { sum++; } + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long satu = 0, dua = 0; + for (long long i = 1; i <= n; i++) { + long long a; + cin >> a; + if (a == 1) + ++satu; + else + ++dua; + } + long long k = 0; + long long a = min(satu, dua); + k += a; + satu -= a; + dua -= a; + k += satu / 3; + cout << k << endl; +} +bool st(char s) { + if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' || s == 'y') + return true; + else + return false; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int j = 0; j < 10000; j++) { + for (int i = 0; i < n - 1; i++) { + if (st(s[i]) == true && st(s[i + 1]) == true) { s.erase(s.begin() + i + 1); } + } + } + cout << s << endl; +} +const double pi = acos(-1); +const double eps = 1e-6; +int dx[4] = {0, 1, 0, -1}; +int dy[4] = {1, 0, -1, 0}; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +int p, n; +int a[305]; +bool vis[305]; +int main() { + cin >> p >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + int pos = a[i] % p; + if (vis[pos]) { + cout << i << endl; + return 0; + } + vis[pos] = true; + } + cout << -1 << endl; + return 0; +} +int main() { + int n, b; + cin >> n >> b; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + int total = b; + for (int i = 0; i < n; ++i) total += V[i]; + double t = (double)total / n; + vector ans(n); + for (int i = 0; i < n; ++i) { + if (V[i] > t) { + cout << "-1\n"; + return 0; + } + ans[i] = t - V[i]; + } + cout << fixed << setprecision(10); + for (int i = 0; i < n; ++i) cout << ans[i] << "\n"; + return 0; +} +int main() { + int n, sum, index; + char s[56], a[56]; + cin >> n >> s; + sum = index = 0; + for (int i = 0;; i++) { + index += i; + if (index >= n) break; + a[sum++] = s[index]; + } + a[sum] = '\0'; + cout << a << endl; + return 0; +} +int main() { + int a, b, j = 0; + float d; + cin >> a; + b = 3 * a; + int c[b]; + for (int i = 0; i < b; i++) { cin >> c[i]; } + while (j < b) { + d = (float)c[j] / (float)c[j + 2]; + if (d > 1) + cout << 1 * c[j + 2] << endl; + else + cout << (c[j + 1] / c[j + 2] + 1) * c[j + 2] << endl; + j += 3; + } + return 0; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + string x = ""; + for (int i = 0; i < s.size();) { + if (i + 2 >= s.size() || s[i] != 'o' || s[i + 1] != 'g' || s[i + 2] != 'o') { + x += s[i]; + i++; + continue; + } + x += "***"; + i++; + while (i + 1 < s.size() && s[i] == 'g' && s[i + 1] == 'o') i += 2; + } + cout << x << endl; + return 0; +} +int biao[305]; +int main() { + int n, m; + cin >> n >> m; + bool flag = false; + int k; + for (int i = 1; i <= m; i++) { + int a; + cin >> a; + int b = a % n; + if (biao[b] == 1 && !flag) { + flag = true; + k = i; + } else + biao[b] = 1; + } + if (flag) + cout << k << endl; + else + cout << -1 << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int remove = 0; + int end = s[0]; + for (int i = 1; i < n; i++) { + if (end == s[i]) + remove++; + else + end = s[i]; + } + cout << remove << endl; + return 0; +} +int main() { + int n, m; + int count = 0; + char s[101][101]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> s[i][j]; + if (s[i][j] == 'C' || s[i][j] == 'M' || s[i][j] == 'Y') { count++; } + } + } + if (count > 0) { + cout << "#Color" << endl; + } else { + cout << "#Black&White" << endl; + } + return 0; +} +int main() { + int N, M; + cin >> N >> M; + int x = 0, y = 0; + for (int i = 0; i < N; i++) { + string line; + cin >> line; + for (int j = 0; j < M; j++) { + if (line[j] == '*') { + x ^= i; + y ^= j; + } + } + } + cout << x + 1 << " " << y + 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + int count = 0; + int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + sum += temp; + } + if ((sum + 1) % (n + 1) != 1) count++; + if ((sum + 2) % (n + 1) != 1) count++; + if ((sum + 3) % (n + 1) != 1) count++; + if ((sum + 4) % (n + 1) != 1) count++; + if ((sum + 5) % (n + 1) != 1) count++; + cout << count << endl; +} +long long n; +int main() { + cin >> n; + if (n & 1) { + cout << "Ehab" + << "\n"; + } else { + cout << "Mahmoud" + << "\n"; + } + return 0; +} +int main() { + long long x1, x2, y1, y2 = 2; + cin >> x1 >> y1 >> x2 >> y2; + cout << max(abs(x2 - x1), abs(y2 - y1)) << "\n"; +} +int main() { + int gl, gr, bl, br; + bool verdict; + cin >> gl >> gr >> bl >> br; + if (2 * (gl + 1) >= br && gl - 1 <= br || 2 * (gr + 1) >= bl && gr <= bl) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const long double eps = 1e-7; +const int inf = 1000000010; +const long long INF = 10000000000010LL; +const int mod = 1000000007; +const int MAXN = 100010; +int n, m, k, u, v, x, y, t, a, b, ans = 360; +int A[MAXN]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> A[i], A[i] += A[i - 1]; + for (int i = 0; i < n; i++) + for (int j = i + 1; j <= n; j++) ans = min(ans, abs(180 - (A[j] - A[i]))); + cout << ans * 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } +} +int main() { + long long a, b, count = 0; + cin >> a >> b; + while (a < b || a == b) { + a *= 3; + b *= 2; + count++; + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int i = 2; + string ans = ""; + ans = ans + s[0]; + int j = 3; + while (i <= n - 1) { + ans = ans + s[i]; + i = i + j; + j++; + } + cout << ans << endl; + return 0; +} +map a; +int main() { + int n; + while (cin >> n) { + string s; + cin >> s; + int t = 0; + for (int i = 0; i < s.length() - 1; i++) { + a.clear(); + for (int j = i; j < s.length(); j++) { + a[s[j]]++; + if (a['U'] == a['D'] && a['L'] == a['R']) t++; + } + } + cout << t << endl; + } + return 0; +} +int main() { + long int n, p; + cin >> p >> n; + long int s[p + 1], f[p + 1], t[p + 1]; + for (long int i = 1; i <= p; ++i) cin >> s[i] >> f[i] >> t[i]; + long int m = (2 * n) - 2; + n--; + for (long int i = 1; i <= p; ++i) { + long int temp = t[i] % m; + s[i]--; + f[i]--; + if (f[i] == s[i]) { + cout << t[i] << "\n"; + continue; + } + if (temp <= s[i]) { + if (f[i] >= s[i]) { + cout << f[i] - temp + t[i] << "\n"; + continue; + } else { + cout << s[i] - f[i] + (2 * (n - s[i])) + t[i] + s[i] - temp << "\n"; + continue; + } + } else { + if (temp > n) { + long int res = (2 * n) - temp; + if (s[i] <= res) { + if (f[i] <= s[i]) { + cout << res - f[i] + t[i] << "\n"; + continue; + } else { + cout << (2 * s[i]) + (res - s[i]) + f[i] - s[i] + t[i] << "\n"; + continue; + } + } else { + if (f[i] >= s[i]) { + cout << res + f[i] + t[i] << "\n"; + continue; + } else { + cout << res + n + n - f[i] + t[i] << "\n"; + continue; + } + } + } else { + if (f[i] <= s[i]) { + cout << n - temp + n - f[i] + t[i] << "\n"; + continue; + } else { + cout << n - temp + n + f[i] + t[i] << "\n"; + continue; + } + } + } + } + return 0; +} +int main() { + int t; + while (cin >> t) { + int a[200001], b[200001], c[200001]; + int b_number = 0; + int c_number = 0; + for (int i = 0; i < t; i++) { + cin >> a[i]; + if (a[i] == 1) { + b[b_number] = a[i]; + b_number++; + } else { + b[c_number] = a[i]; + c_number++; + } + } + int len = b_number < c_number ? b_number : c_number; + int len_b = 0; + if (b_number > c_number) len_b = (b_number - c_number) / 3; + cout << len + len_b << endl; + } + return 0; +} +long long ar[1000008]; +vector vi; +bool isv(char ch) { + if (ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u' or ch == 'y') return 1; + return 0; +} +int main() { + string s; + long long n; + cin >> n; + cin >> s; + vi.push_back('x'); + for (int i = 0; i < s.size(); i++) { + if (!isv(s[i])) { + vi.push_back(s[i]); + } else { + if (!isv(vi[vi.size() - 1])) vi.push_back(s[i]); + } + } + for (int i = 1; i < vi.size(); i++) cout << vi[i]; + cout << endl; + return 0; +} +long long sum_mod(long long a, long long b) { + return (a + b) % 1000000007; +} +long long subtract_mod(long long a, long long b) { + return (a % 1000000007 - b % 1000000007 + 1000000007) % 1000000007; +} +long long multiply_mod(long long a, long long b) { + return (a % 1000000007 * b % 1000000007) % 1000000007; +} +long long modInverse(long long x, long long y) { + long long res = 1; + x = x % 1000000007; + while (y > 0) { + if (y & 1) res = (res * x) % 1000000007; + y = y >> 1; + x = (x * x) % 1000000007; + } + return res; +} +long long divide_mod(long long a, long long b) { + return (a * modInverse(b, 1000000007 - 2)) % 1000000007; +} +long long gcd(long long a, long long b) { + while (b) swap(a %= b, b); + return a; +} +int main() { + string s; + cin >> s; + int flag = 0; + for (unsigned long long i = 0; i < s.length(); ++i) { + if (i + 5 <= s.length() && s.substr(i, 5) == "Danil") flag++; + if (i + 5 <= s.length() && s.substr(i, 5) == "Slava") flag++; + if (i + 3 <= s.length() && s.substr(i, 3) == "Ann") flag++; + if (i + 6 <= s.length() && s.substr(i, 6) == "Nikita") flag++; + if (i + 4 <= s.length() && s.substr(i, 4) == "Olya") flag++; + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int x1, y1, x2, y2; + int x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + int t = (x2 - x1) % x; + int t1 = (y2 - y1) % y; + if (t || t1) + cout << "NO" << endl; + else { + t = abs((x2 - x1) / x); + t %= 2; + t1 = abs((y2 - y1) / y); + t1 %= 2; + if (t == t1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, j, ans = 0, i; + int boy[200] = {0}, girl[200] = {0}; + int bp[200] = {0}, gp[200] = {0}; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (boy[i] == 0 || girl[j] == 0) { + bp[ans] = i + 1; + gp[ans] = j + 1; + ans++; + } + boy[i] = 1; + girl[j] = 1; + } + } + cout << ans << endl; + for (i = 0; i < ans; i++) cout << bp[i] << " " << gp[i] << endl; + return 0; +} +int main() { + int a[301][2]; + int n, p; + int i, flag = 0, m, j; + for (i = 0; i < 301; i++) a[i][1] = 0; + cin >> p >> n; + for (i = 0; i < n; i++) { + cin >> m; + if (a[m % p][1] == 1) { + if (flag == 0) j = i; + flag = 1; + } else { + a[m % p][0] = m; + a[m % p][1] = 1; + } + } + if (flag == 1) + cout << j + 1 << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int lim, bro, year = 0; + cin >> lim; + cin >> bro; + while (lim <= bro) { + lim = lim * 3; + bro = bro * 2; + year++; + } + cout << year << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int p; + cin >> p; + if (p % 7 == 0) + cout << p / 7 << endl; + else + cout << (p / 7) + 1 << endl; + } +} +int main() { + long long int n, m; + cin >> n >> m; + char a[n + 1][m + 1]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cin >> a[i][j]; + } + long long int r, c, cnt = 0; + for (int i = 1; i <= n; i++) { + cnt = 0; + for (int j = 1; j <= m; j++) { + if (a[i][j] == '*') cnt++; + } + if (cnt == 1) { + r = i; + break; + } + } + for (int i = 1; i <= m; i++) { + cnt = 0; + for (int j = 1; j <= n; j++) { + if (a[j][i] == '*') { cnt++; } + } + if (cnt == 1) { + c = i; + break; + } + } + cout << r << " " << c << endl; + return 0; +} +int main() { + int n, a, b, c, sum = 0, sum1 = 0, sum2 = 0; + cin >> n; + while (n--) { + cin >> a >> b >> c; + sum += a; + sum1 += b; + sum2 += c; + } + if (sum == 0 && sum1 == 0 && sum2 == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int a, b, ans; + while (cin >> a >> b) { + if (b > a) { + ans = -1; + } + else { + if (a % 2 == 0) { + ans = (a / 2); + } else { + ans = (a / 2) + 1; + } + while (ans % b != 0) { ans++; } + } + cout << ans << endl; + } + return 0; +} +int deg[400]; +int n; +int anstemp = 360; +int clockwise(int start) { + int val = 0; + while (val < 180) { + val += deg[start]; + start++; + if (start == n) start = 0; + } + return val; +} +int cclockwise(int cstart) { + int cval = 0; + while (cval < 180) { + cval += deg[cstart]; + cstart--; + if (cstart < 0) cstart = n - 1; + } + return cval; +} +int main() { + int V, P, ans, sumclock = 0, sumcclock = 0, sumclock2 = 0, k = 0, l = 0; + V = 0; + P = 0; + int temp, temp1, temp2; + cin >> n; + int m = n; + for (int i = 0; i < n; i++) { cin >> deg[i]; } + for (int i = 0; i < n; i++) { + temp = min(clockwise(i), cclockwise(i)); + anstemp = min(anstemp, temp); + } + temp1 = 360 - anstemp; + if (temp1 > anstemp) + ans = temp1 - anstemp; + else + ans = anstemp - temp1; + cout << ans << endl; + return 0; +} +int main() { + int n, a, d; + a = d = 0; + cin >> n; + char ch; + for (int i = 0; i < n; i++) { + cin >> ch; + if (ch == 'A') { + a++; + } else if (ch == 'D') { + d++; + } + } + if (a > d) { + cout << "Anton\n"; + } else if (d > a) { + cout << "Danik\n"; + } else { + cout << "Friendship\n"; + } + return 0; +} +int main() { + char a[55], b[55], c[55]; + int j, l; + cin >> a; + j = strlen(a); + for (int i = 0; i < j; i++) { b[i] = a[0]; } + b[j] = '\0'; + if (strcmp(a, b) == 0) + l = 0; + else { + for (int i = 0; i < strlen(a); i++) { + --j; + c[i] = a[j]; + } + j = strlen(a); + c[j] = '\0'; + if (strcmp(a, c) == 0) + l = j - 1; + else + l = j; + } + cout << l << endl; + return 0; +} +int main() { + int n, k, x = 1e9 + 5; + cin >> n >> k; + vector v(n); + for (int i = 0; i < n; i++) { + cin >> v[i]; + x = min(x, v[i]); + } + long long int res = 0; + for (int i = 0; i < n; i++) { + if ((v[i] - x) % k) { + cout << "-1" + << "\n"; + return 0; + } + res += (v[i] - x) / k; + } + cout << res << "\n"; + return 0; +} +long long abs(long long, long long); +void solve() { + long long n, a, t = 0; + cin >> n; + for (long long i = 1; i < n + 1; i++) { + cin >> a; + t += ((a - 1) * i + 1); + } + cout << t << "\n"; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +long long abs(long long a, long long b) { + if (a > b) + return a - b; + else + return b - a; +} +bool Check_operation(string statment) { + for (int i = 0; i < statment.length(); i++) { + if (statment[i] == '+') + return true; + else if (statment[i] == '-') + return false; + } + return true; +} +int Run_Statements(string *statmnts, int n) { + int result = 0; + for (int itr = 0; itr < n; itr++) { + string Statement = statmnts[itr]; + bool Operation = Check_operation(Statement); + if (Operation == true) + result++; + else + result--; + } + return result; +} +int main() { + int n = 0; + cin >> n; + string *statements = new string[n]; + for (int itr = 0; itr < n; itr++) cin >> statements[itr]; + int Output = Run_Statements(statements, n); + cout << Output << endl; + return 0; +} +long long n, a[100001] = {0}, dp[100001] = {0}; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { + long long x; + cin >> x; + a[x]++; + } + dp[1] = a[1]; + for (long long i = 2; i <= 100000; i++) { dp[i] = max(i * a[i] + dp[i - 2], dp[i - 1]); } + cout << dp[100000] << '\n'; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int *strt_time = new int[n]; + int *end_time = new int[n]; + for (int i = 0; i < n; i++) { cin >> strt_time[i] >> end_time[i]; } + int mintime = 0; + int k = 1; + for (int i = 0; i < n; i++) { + int r = (strt_time[i] - k) % x; + mintime += r; + mintime += end_time[i] - strt_time[i] + 1; + k = end_time[i] + 1; + } + cout << mintime << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a = 0, b = 0, c = 0; + int arr[n][3]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } + a += arr[i][0]; + b += arr[i][1]; + c += arr[i][2]; + } + if (a == 0 & b == 0 & c == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, r = 0; + cin >> n; + string s; + while (n--) { + cin >> s; + if (s[1] == '+') + ++r; + else + --r; + if (s[2] == '+') r = r; + } + cout << r << endl; + return 0; +} +int main() { + long long n, k, tm = 0; + cin >> n >> k; + tm = n - 1; + long long m[k + 1], a[n + 1]; + long long j = 0, t, p, q; + for (long long i = 0; i < k; i++) { + cin >> m[i]; + tm += m[i] - 1; + t = m[i]; + while (t--) { + cin >> a[j]; + if (a[j] == 1) { + p = i; + q = j; + } + j++; + } + } + for (j = q + 1; j < (q + m[p]); j++) { + if (a[j] == (a[j - 1] + 1)) + tm = tm - 2; + else + break; + } + cout << tm << endl; +} +int main() { + long long n, m, k; + cin >> n >> m >> k; + long long cnt = 1; + for (long long j = 1; j <= n; ++j) { + for (long long i = 1; i <= m; ++i) { + if (cnt == k) { + cout << j << ' ' << i << " L\n"; + return 0; + } else if (cnt + 1 == k) { + cout << j << ' ' << i << " R\n"; + return 0; + } + cnt += 2; + } + } + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n, d; + cin >> n >> d; + const int N = 1e2 + 5; + int v[N]; + int a; + cin >> a; + if (a < 0) { + a = abs(a); + v[0] = 0; + } else { + v[0] = a; + a = 0; + } + for (int i = 1; i < n; i++) { + cin >> v[i]; + v[i] += a; + } + int ans = 2; + for (int i = 0; i < n - 1; i++) { + if (v[i + 1] - (v[i] + d) > d) + ans += 2; + else if (v[i + 1] - (v[i] + d) == d) + ans++; + } + cout << ans << endl; + return 0; +} +int n, k; +int d[1010], s[1010]; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> d[i]; + for (int i = 0; i < n; i++) cin >> s[i]; + int oil = 0, len = 0, mx = 0; + for (int i = 0; i < n; i++) { + mx = max(mx, s[i]); + oil += s[i]; + if (oil < d[i]) { + int req = (d[i] - oil + mx - 1) / mx; + oil += mx * req; + len += k * req; + } + oil -= d[i]; + len += d[i]; + } + cout << len << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + set df; + for (int i = 0; i < s.length(); i++) { + if (isalpha(s[i])) { df.insert(s[i]); } + } + cout << df.size() << '\n'; +} +int main() { + long long a, b, x, y, z; + cin >> a >> b >> x >> y >> z; + long long ans = 0; + long long sy, sb; + sy = 2 * x + y - a; + if (sy < 0) { sy = 0; } + sb = 3 * z + y - b; + if (sb < 0) { sb = 0; } + ans += sy + sb; + cout << ans << '\n'; + return 0; +} +const int INF = 0x3f3f3f3f; +int a[105]; +int main() { + long long i, j, k, l = 0; + long long n, m; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i], a[i]--; + long long s = n; + for (i = 0; i < n; i++) { + if (a[i]) s += a[i] + a[i] * i; + } + cout << s << endl; + return 0; +} +int main() { + int r[11], c[11]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char t; + cin >> t; + if (t == 'S') { r[i] = c[j] = 1; } + } + } + int ans = n * m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (r[i] && c[j]) ans--; + } + } + cout << ans << endl; + } + return 0; +} +const int maxn = 1e6; +const double inf = 0x3f3f3f3f3f3f3f3f; +int a, b, c, d, e, f; +int main() { + while (cin >> a >> b >> c >> d >> e >> f) { cout << (a + b + c) * (a + b + c) - a * a - c * c - e * e << endl; } + return 0; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + bool flag = 0; + while (n != 0) { + if (flag == 0) { + n -= __gcd(a, n); + flag = 1; + } else { + n -= __gcd(b, n); + flag = 0; + } + } + if (flag == 1) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int sum1 = 0, sum2 = 0, sum3 = 0, var, n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> var; + sum1 += var; + cin >> var; + sum2 += var; + cin >> var; + sum3 += var; + } + if (sum1 == 0 && sum2 == 0 && sum3 == 0) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + long long x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + if (abs(x2 - x1) % x != 0 || abs(y2 - y1) % y != 0) + cout << "NO\n"; + else { + int num = (x2 - x1) / x, num1 = (y2 - y1) / y; + if (abs(num - num1) % 2 == 1) + cout << "NO\n"; + else + cout << "YES\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + vector ve1, ve2(n + 1); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + ve1.push_back(x); + } + for (int j = 0; j < n; j++) { + int x; + cin >> x; + ve2[x] = j + 1; + } + for (int i = 0; i < n; i++) { ve1[i] = ve2[ve1[i]]; } + int last = 0; + for (int i = 0; i < n; i++) { + if (ve1[i] > last) { + last = ve1[i]; + } else { + cout << n - i << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + char s[n]; + cin >> s; + int dp[n] = {}; + dp[0] = 0; + for (int i = 1; i < n; i++) { dp[i] = -1; } + for (int i = 1; i < d; i++) { + if (s[i] == '1') { + dp[i] = 1; + } else { + dp[i] = -1; + } + } + for (int i = d; i < n; i++) { + if (s[i] == '0') { continue; } + int min = 1000000; + for (int j = d; j > 0; j--) { + if (dp[i - j] < min && dp[i - j] != -1) { min = dp[i - j]; } + } + dp[i] = 1 + min; + } + if (dp[n - 1] < 1 || dp[n - 1] > 1000000) { + cout << -1 << endl; + } else { + cout << dp[n - 1] << endl; + } +} +int main() { + char che[7][100]; + strcpy(che[0], "+------------------------+"); + strcpy(che[1], "|#.#.#.#.#.#.#.#.#.#.#.|D|)"); + strcpy(che[2], "|#.#.#.#.#.#.#.#.#.#.#.|.|"); + strcpy(che[3], "|#.......................|"); + strcpy(che[4], "|#.#.#.#.#.#.#.#.#.#.#.|.|)"); + strcpy(che[5], "+------------------------+"); + int n; + cin >> n; + for (int i = 0; i <= 22; i++) { + for (int j = 0; j < 6; j++) { + if (che[j][i] == '#') { + che[j][i] = 'O'; + n--; + if (!n) { break; } + } + } + if (!n) { break; } + } + for (int i = 0; i < 6; i++) { cout << che[i] << endl; } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int h = n; + int ans = 0; + while (h < (int)s.size()) { + if (s[h - 1] == s[h - 2] && s[h - 2] == s[h - 3]) ans++; + h += n; + } + cout << ans << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int a[m], b[n]; + for (int i = 0; i < m; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + sort(a, a + m); + sort(b, b + n); + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + if (a[i] == b[j]) { + cout << a[i] << endl; + return 0; + } + if (a[0] == b[0]) + cout << a[0] << endl; + else if (a[0] < b[0]) + cout << a[0] << b[0] << endl; + else + cout << b[0] << a[0] << endl; + return 0; +} +int main() { + int n; + long long int a[150]; + long long int sum = 0; + while (cin >> n) { + sum = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (i == 1) { + sum += a[1]; + } else { + sum = sum + (a[i] - 1) * i + 1; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + long long int l, r, d; + for (int i = 0; i < t; i++) { + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else if (d > r) + cout << d << endl; + else if (d >= l && d <= r) { + long long int out = (r / d + 1) * d; + cout << out << endl; + } + } + return 0; +} +int main() { + int count = 0, k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + for (int i = 1; i <= d; i++) { + if ((i % k == 0) || (i % l == 0) || (i % m == 0) || (i % n == 0)) { count++; } + } + cout << count << endl; + return 0; +} +int c, v0, v1, a, l; +int main() { + while (cin >> c >> v0 >> v1 >> a >> l) { + int day = 1; + if (c <= v0) + cout << 1 << endl; + else { + int sum = v0; + while (sum < c) { + int maxv = v0 + day * a; + if (maxv > v1) maxv = v1; + int newpage = maxv - l; + sum += newpage; + day++; + } + cout << day << endl; + } + } + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int curs = v0, cur = 0; + for (int i = 1; i <= c; i++) { + cur += curs - (i == 1 ? 0 : l); + if (cur >= c) { + cout << i << endl; + return 0; + } + curs += a; + curs = min(curs, v1); + } + cout << ":(" << endl; +} +int main() { + int n, x(0); + cin >> n; + string s; + while (n--) { + cin >> s; + if (s[1] == '+') { + ++x; + } else { + --x; + } + } + cout << x << endl; + return 0; +} +int main() { + int n, m, k1, k2; + cin >> n >> m >> k1 >> k2; + if (n > m) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +const int N = 1e5 + 5; +int dp[N][27]; +bool g[27][27]; +string s; +int solve(int ind, int x) { + if (ind == s.size()) return 0; + int &ret = dp[ind][x]; + if (ret != -1) return ret; + ret = 1e8; + if (x == 26) { + ret = solve(ind + 1, s[ind] - 'a'); + ret = min(ret, solve(ind + 1, 26) + 1); + } else if (!g[x][s[ind] - 'a']) { + ret = solve(ind + 1, s[ind] - 'a'); + ret = min(ret, solve(ind + 1, x) + 1); + } else + ret = min(ret, solve(ind + 1, x) + 1); + return ret; +} +int main() { + cin >> s; + int q; + cin >> q; + while (q--) { + string x; + cin >> x; + g[x[0] - 'a'][x[1] - 'a'] = 1; + g[x[1] - 'a'][x[0] - 'a'] = 1; + } + memset(dp, -1, sizeof dp); + cout << solve(0, 26) << endl; + return 0; +} +int n, a[50], s; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + a[s]++; + } + if (a[1] > a[2]) { + cout << a[2] + (a[1] - a[2]) / 3 << endl; + } else { + cout << a[1] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int s1 = 0, s2 = 0, s3 = 0; + while (n > 0) { + int t1, t2, t3; + cin >> t1 >> t2 >> t3; + s1 += t1; + s2 += t2; + s3 += t3; + n--; + } + if ((s1 == 0) && (s2 == 0) && (s3 == 0)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, i; + cin >> n >> m; + for (i = 2;; i++) { + n *= 3; + m *= 2; + if (n > m) break; + } + cout << i - 1 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = 0; + c -= 2; + b -= 1; + cout << min(a, min(b, c)) * 3 + 3 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + while (true) { + int c = 0, d = 0; + if (n >= 2 && m >= 2) { + n -= 2; + m -= 2; + c++; + } + if (n == 1 && m >= 12 && c == 0) { + n -= 1; + m -= 12; + c++; + } + if (n == 0 && m >= 22 && c == 0) { + m -= 22; + c++; + } + if (c == 0) { + cout << "Hanako" << endl; + break; + } + if (m >= 22) { + d++; + m -= 22; + } + if (m >= 12 && n >= 1 && d == 0) { + d++; + m -= 12; + n -= 1; + } + if (n >= 2 && m >= 2 && d == 0) { + d++; + m -= 2; + n -= 2; + } + if (d == 0) { + cout << "Ciel" << endl; + break; + } + } +} +int main() { + string s; + cin >> s; + s += ".............."; + int cnt = 0; + for (int i = 0; i < s.size() - 7; i++) { + if (s.substr(i, 5) == "Danil") cnt++; + if (s.substr(i, 4) == "Olya") cnt++; + if (s.substr(i, 5) == "Slava") cnt++; + if (s.substr(i, 3) == "Ann") cnt++; + if (s.substr(i, 6) == "Nikita") cnt++; + } + if (cnt == 1) return cout << "YES\n", 0; + return cout << "NO\n", 0; +} +string s, p; +int a[200005]; +int main() { + cin >> s >> p; + int lens = s.length(); + int lenp = p.length(); + for (int i = 0; i < lens; ++i) cin >> a[i]; + int l = 0, h = lens, m, ans; + while (l < h) { + m = (l + h) / 2; + string t = s; + for (int i = 0; i < m; ++i) t[a[i] - 1] = '.'; + int j = 0; + int cnt = 0; + for (int i = 0; i < lens; ++i) { + if (t[i] == p[j]) { + cnt++; + j++; + } + if (cnt == lenp) break; + } + if (cnt == lenp) { + ans = m; + l = m + 1; + } else { + h = m; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 4 == 0) { + cout << 0; + } else if (n % 4 == 1) { + cout << 1; + } else if (n % 4 == 2) { + cout << 1; + } else { + cout << 0; + } + cout << "\n"; + return 0; +} +int main() { + int n, a[100000], sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int max = a[0], min = a[0]; + for (int j = 0; j < n; j++) { + if (max < a[j]) max = a[j]; + if (min > a[j]) min = a[j]; + } + for (int t = 0; t < n; t++) { + if (a[t] < max && a[t] > min) sum++; + } + cout << sum << endl; +} +inline int abs(int x) { + return x < 0 ? -x : x; +} +int main() { + int x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + int xabs = abs(x1 - x2); + int yabs = abs(y1 - y2); + if (xabs % x != 0 || yabs % y != 0) { + cout << "NO\n"; + return 0; + } + int xmoves = xabs / x; + int ymoves = yabs / y; + if (xmoves % 2 == ymoves % 2) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + long long i, c = 0, a, b, x, y, z; + cin >> a >> b >> x >> y >> z; + a -= x * 2; + a -= y; + b -= y; + b -= 3 * z; + if (a < 0) c += abs(a); + if (b < 0) c += abs(b); + cout << c << endl; + return 0; +} +int main() { + int t, s = 0; + char x[10]; + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> x; + if (strcmp(x, "X++") == 0 || strcmp(x, "++X") == 0) + s += 1; + else if (strcmp(x, "X--") == 0 || strcmp(x, "--X") == 0) + s -= 1; + s = s; + } + cout << s << endl; + return 0; +} +const int Mod = 1e9 + 7; +int n, p; +long long choose[30000 + 25][600], ans = 1; +map Pedy; +int main() { + cin >> n; + choose[0][0] = 1; + for (int i = 1; i < 30000 + 25; i++) { + choose[i][0] = 1; + for (int j = 1; j <= n; j++) choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % Mod; + } + for (int i = 0; i < n; i++) { + cin >> p; + for (int j = 2; j * j <= p; j++) + if (p % j == 0) { + while (not(p % j)) { + p /= j; + Pedy[j]++; + } + } + if (p > 1) Pedy[p]++; + } + for (map::iterator it = Pedy.begin(); it != Pedy.end(); it++) { + p = it->second; + ans = (ans * choose[p + n - 1][n - 1]) % Mod; + } + cout << ans << endl; + return 0; +} +const int MAX = 2e5 + 5; +char s[MAX]; +int bk[55]; +int main() { + int n, k; + cin >> n >> k; + cin >> s; + int len = strlen(s); + for (int i = 0; i < len; i++) { bk[s[i] - 'A']++; } + int minn = 0x3f3f3f3f; + for (int i = 0; i < k; i++) { minn = min(minn, bk[i]); } + cout << minn * k << endl; + return 0; +} +int M = 1000000007; +int main() { + int y, b, r; + cin >> y >> b >> r; + b--; + r -= 2; + cout << 3 * min(y, min(b, r)) + 3 << endl; + return 0; +} +int main() { + int r, c, row[11] = {0}, col[11] = {0}; + string s; + cin >> r >> c; + for (int i = 0; i < r; ++i) { + cin >> s; + for (int j = 0; j < c; ++j) { + if (s[j] == 'S') { + row[i] = 1; + col[j] = 1; + } + } + } + int cakes(0); + for (int i = 0; i < r; ++i) { + for (int j = 0; j < c; ++j) { + if (row[i] == 0 || col[j] == 0) { cakes += 1; } + } + } + cout << cakes << endl; + return 0; +} +int num[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}, n; +int main() { + while (cin >> n) { + bool f = false; + for (int i = 0; i < 10; i++) { + if (num[i] == n) f = true; + } + if (f) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n, m, k; + cin >> n >> k; + long long total = n, cut = 0; + while (k--) { + long long x, cnt = 1, prev = -1, one = 0, tmp; + cin >> m; + tmp = m; + while (tmp--) { + cin >> x; + if (x == 1) + prev = x, cnt = 1; + else { + if (prev + 1 == x) + cnt++, prev = x; + else { + if (cnt > 1) one = cnt; + total -= (cnt - 1); + prev = -1; + cnt = 1; + } + } + } + if (cnt > 1) one = cnt; + total -= (cnt - 1); + if (one) + cut += (m - one), one = 0; + else + cut += (m - 1); + } + cout << (total + cut - 1) << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const int MAXN = 2e5 + 5; +long long n; +int main() { + cin >> n; + cout << n * (n + 1) / 2 % 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool flag[n]; + memset(flag, false, sizeof(flag)); + string ans; + int i; + if (n == 1 || n == 2) { + cout << s << "\n"; + return 0; + } + for (i = 0; i < (n - 2); i++) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + flag[i] = true; + flag[i + 1] = true; + flag[i + 2] = true; + int j = i + 4; + while (j < n && s[j] == 'o' && s[j - 1] == 'g') { + flag[j] = true; + flag[j - 1] = true; + j += 2; + } + i = j - 2; + ans += "***"; + } else { + ans += s[i]; + } + } + if (flag[n - 2] == false) { ans += s[n - 2]; } + if (flag[n - 1] == false) { ans += s[n - 1]; } + cout << ans << "\n"; +} +int main() { + int a, b, c, i, j; + cin >> a >> b >> c; + for (i = 0; i <= c; i++) { + for (j = 0; j <= c; j++) { + if ((a * i + b * j) == c) { + cout << "Yes" << endl; + return 0; + } else if ((a * i + b * j) > c) { + break; + } + } + } + cout << "No" << endl; + return 0; +} +int c, v0, v1, a, l; +int main() { + cin >> c >> v0 >> v1 >> a >> l; + int sumd = 0, hred = 0; + while (c > hred) { + hred += min(v1, v0 + a * sumd) - l; + if (sumd == 0) hred += l; + sumd++; + } + cout << sumd << endl; + return 0; +} +int n; +void solve() { + if (n == 0) { + cout << "+------------------------+" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|#.......................|" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 1) { + cout << "+------------------------+" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|#.......................|" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 2) { + cout << "+------------------------+" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|#.......................|" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 3) { + cout << "+------------------------+" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|#.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 4) { + cout << "+------------------------+" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 5) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 6) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.#.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 7) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 8) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 9) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.#.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 10) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 11) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 12) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.#.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 13) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 14) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 15) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.#.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 16) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 17) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 18) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.#.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 19) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 20) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 21) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.#.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 22) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 23) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 24) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.#.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 25) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 26) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 27) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.#.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 28) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 29) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 30) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.#.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 31) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 32) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 33) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.#.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } else if (n == 34) { + cout << "+------------------------+" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|D|)" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|" + << "\n"; + cout << "|O.......................|" + << "\n"; + cout << "|O.O.O.O.O.O.O.O.O.O.O.|.|)" + << "\n"; + cout << "+------------------------+" + << "\n"; + } +} +int main() { + while (cin >> n) { solve(); } + return 0; +} +int main() { + string x; + int y; + int z = 0; + cin >> y; + cin >> x; + for (int i = 1; i < x.length(); i++) { + if (x[i] == x[i - 1]) { z++; } + } + cout << z << endl; +} +int main() { + int n; + cin >> n; + long long a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + long long sum = 0; + for (int i = 0; i < n; i++) { + sum += a[i]; + sum += (a[i] - 1) * i; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], max = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (max < a[i]) max = a[i]; + } + int b[max] = {0}, t[n], sum = 0; + for (int i = 0; i < n; i++) { + sum = 0; + b[max] = {0}; + for (int j = 0; j < a[i]; j++) { + cin >> b[j]; + sum += b[j]; + } + t[i] = 5 * sum + 15 * a[i]; + } + int min; + for (int i = 0; i < n; i++) { + if (i == 0) + min = t[0]; + else if (t[i] < min) + min = t[i]; + } + cout << min << endl; + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << max(abs(x2 - x1), abs(y2 - y1)) << endl; +} +long long fpow(long long n, long long k, long long p = 1000000007) { + long long r = 1; + for (; k; k >>= 1) { + if (k & 1) r = r * n % p; + n = n * n % p; + } + return r; +} +long long inv(long long a, long long p = 1000000007) { + return fpow(a, p - 2, p); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << endl; + return 0; +} +int main() { + int n, ara[100000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> ara[i]; } + for (int i = 0; i < n - 1; i++) { cout << ara[i] + ara[i + 1] << ' '; } + cout << ara[n - 1] << endl; +} +const long long N = 1e9 + 3; +const long long MN = 1e9; +long long n, a, cnt; +vector v; +map mp; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> a; + mp[a]++; + } + if (mp[1] >= 1 and mp[2] >= 1) { + if (mp[1] > mp[2]) { + cnt += mp[2]; + mp[1] -= mp[2]; + } else { + cnt += mp[1]; + mp[1] = 0; + } + } + cout << cnt + mp[1] / 3; + cout << "\n"; + return 0; +} +int main() { + int a, b, c, sum = 0, temp = 0, flag = 0; + cin >> a >> b >> c; + for (int i = 0; i < 10000; i++) { + for (int j = 0; j < 10000; j++) { + sum = a * i + b * j; + if (sum > c) { + break; + } else if (sum == c) { + cout << "Yes" << endl; + flag = 1; + return 0; + } + } + } + cout << "No" << endl; + return 0; +} +int main() { + string a; + int n, s = 0; + cin >> n >> a; + for (int i = 1; s <= n; i++) { + s += i; + if (s <= n) cout << a[s - i]; + } + cout << endl; + return 0; +} +int main() { + int x; + long long int k = 0; + cin >> x; + vector v; + int a[x], b[x]; + for (int i = 0; i < x; i++) { + int s; + cin >> s; + k += s; + } + for (int i = 0; i < x; i++) { + long long int d; + cin >> d; + v.push_back(d); + } + sort(v.begin(), v.end()); + long int s = v[x - 1] + v[x - 2]; + if (s >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + char str[105][105]; + int n, m; + cin >> n >> m; + map x, y; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> str[i][j]; + if (str[i][j] == '*') { + x[i]++; + y[j]++; + } + } + map::iterator ite; + for (ite = x.begin(); ite != x.end(); ite++) + if (ite->second == 1) cout << ite->first << " "; + for (ite = y.begin(); ite != y.end(); ite++) + if (ite->second == 1) cout << ite->first << endl; + return 0; +} +int main() { + vector div; + long long int i, n, k, g = 0, d; + cin >> n >> k; + for (i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + d = n / i; + if (d * d != n) { + div.push_back(d); + g++; + } + div.push_back(i); + g++; + } + } + sort(div.begin(), div.end()); + if (k > g) + cout << -1 << endl; + else + cout << div[k - 1] << endl; +} +int main() { + set S; + int a, m; + cin >> a >> m; + int k = a % m; + S.insert(k); + bool stop = true; + while (k != 0) { + int i = k; + while (i < m) i *= 2; + k = i % m; + if (S.count(k)) { + stop = false; + break; + } else { + S.insert(k); + } + } + if (stop) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +inline void wa() { + cout << "HARD" << endl; +} +inline void ac() { + cout << "EASY" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int tmp; + cin >> tmp; + if (tmp) { + wa(); + return 0; + } + } + ac(); +} +int main() { + int n; + cin >> n; + char a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int incr = 1; + for (int i = 0; i < n; i = i + incr) { + cout << a[i]; + incr++; + } + cout << endl; +} +long long a[100005]; +long long dp[100005]; +long long vis[100005]; +long long b[100005]; +long long freq[100005]; +int main() { + long long t, n, l, r; + cin >> n; + for (int i = 1; i <= 100000; i++) { + vis[i] = 0; + freq[i] = 0; + } + for (int j = 1; j <= n; j++) { + cin >> b[j]; + freq[b[j]]++; + } + long long cnt = 1; + for (int j = 1; j <= n; j++) { + if (!vis[b[j]]) { + a[cnt] = b[j]; + vis[b[j]] = 1; + cnt++; + } + } + n = cnt - 1; + sort(a + 1, a + 1 + n); + dp[0] = 0; + l = 1; + r = 1; + int p = max(l, r); + for (int i = 1; i <= n; i++) { + dp[i] = dp[i - 1]; + int lx = lower_bound(a + 1, a + 1 + n, a[i] - p) - (a + 1); + lx++; + if (lx == 1) { + dp[i] = max(freq[a[i]] * a[i], dp[i]); + } else { + dp[i] = max(dp[i], a[i] * freq[a[i]] + dp[lx - 1]); + } + } + cout << dp[n] << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + long long maxi = 1000000000000000000; + for (int i = 0; i < n; i++) { + int b[a[i]]; + long long item_time = 0; + for (int j = 0; j < a[i]; j++) { + cin >> b[j]; + item_time += b[j] * 5; + } + item_time += a[i] * 15; + maxi = min(maxi, item_time); + } + cout << maxi << endl; + return 0; +} +int N, D, A[150]; +int main() { + cin >> N >> D; + for (int i = 0; i <= N - 1; i++) cin >> A[i]; + int Ans = 2; + for (int i = 0; i <= N - 2; i++) { + if (A[i] + D <= A[i + 1] - D) Ans++; + if (A[i + 1] - D > A[i] + D) Ans++; + } + cout << Ans << '\n'; + return 0; +} +int main() { + int a; + cin >> a; + cout << a; + if (a > 1) cout << " "; + for (int i = 0; i < a - 1; i++) { + cout << i + 1; + if (i + 2 != a) cout << " "; + } + cout << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int ans = 0; + for (int i = 0; i <= 4000; i++) { + for (int k = 0; k <= 4000; k++) { + int sum = a * i + b * k; + if (sum > n) continue; + if ((n - sum) % c == 0) { ans = max(ans, (i + k + (n - sum) / c)); } + } + } + cout << ans << '\n'; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + bool b = true; + for (int i = 0; i < n && b; i++) { b = a[i] % k == a[0] % k; } + if (b) { + sort(a, a + n); + long long sum = 0; + for (int i = 0; i < n; i++) { sum += (a[n - 1 - i] - a[0]) / k; } + cout << sum << '\n'; + } else { + cout << -1 << '\n'; + } +} +int ans = 1000000, n, a[105], x, t; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + t = 0; + for (int j = 0; j < a[i]; j++) { + cin >> x; + t += x * 5; + } + ans = min(ans, t + 15 * a[i]); + } + cout << ans << '\n'; +} +const int INF = 0x3f3f3f3f; +map mp; +long long vis[200000 + 5]; +int main() { + long long i, j, k, l = 0, co = 0, c = 0; + long long n, m; + long long x, y; + string s; + cin >> s; + n = s.size(); + for (i = 0; i < n; i++) { mp[s[i]]++; } + char z; + j = 0; + for (z = 'z'; z >= 'a'; z--) { + if (mp[z]) { + for (i = j; i < n; i++) { + if (s[i] == z) cout << z, k = i; + } + j = k; + } + } + cout << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; + return 0; +} +long long arr[1000000]; +int main() { + int n; + long long sum = 0, minn = 999999999, k; + cin >> n; + while (n--) { + cin >> k; + sum += k; + if (k % 2 == 1) { minn = min(minn, k); } + } + if (sum % 2 == 0) + cout << sum << endl; + else + cout << sum - minn << endl; +} +int main() { + int n, x(0); + cin >> n; + string s; + while (n--) { + cin >> s; + if (s[1] == '+') { + ++x; + } else { + --x; + } + } + cout << x << endl; + return 0; +} +const int M = 100 + 5; +int main() { + int x, y; + cin >> x >> y; + bool ok = true; + int id = 0; + while (ok) { + ok = false; + if (id == 0) { + if (x >= 2) { + x = x - 2; + if (y >= 2) { + y = y - 2; + id = 1; + ok = true; + } + } else { + if (x >= 1) { + x = x - 1; + if (y >= 12) { + y -= 12; + id = 1; + ok = true; + } + } else { + if (x == 0) { + if (y >= 22) { + y -= 22; + id = 1; + ok = true; + } + } + } + } + } else { + if (y >= 22) { + y -= 22; + id = 0; + ok = true; + } else { + if (y >= 12) { + y -= 12; + if (x >= 1) { + x -= 1; + id = 0; + ok = true; + } + } else { + if (y >= 2) { + y -= 2; + if (x >= 2) { + x -= 2; + id = 0; + ok = true; + } + } + } + } + } + } + string ans = (id == 1 ? "Ciel" : "Hanako"); + cout << ans << endl; + return 0; +} +long long gcd(long long a, long long b) { + while (b) swap(a %= b, b); + return a; +} +int main() { + long long n; + cin >> n; + vector nums(n); + long long sum = 0; + for (long long i = 0; i < n; ++i) { + long long a; + cin >> a; + sum += a; + } + long long mx1 = 0, mx2 = 0; + for (long long i = 0; i < n; ++i) { + cin >> nums[i]; + if (nums[i] > mx1) + mx2 = mx1, mx1 = nums[i]; + else if (nums[i] <= mx1 && nums[i] > mx2) + mx2 = nums[i]; + } + if (sum <= mx1 + mx2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a, n, c = 0, m = 1, x, y; + cin >> n >> a; + while (n--) { + cin >> x >> y; + c += ((x - m) % a) + (y - x + 1); + m = y + 1; + } + cout << c << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector arr(1e5 + 1, 0); + for (long long z = 0; z < n; z++) { + long long temp; + cin >> temp; + arr[temp] += 1; + } + vector dp(1e5 + 1, 0); + dp[1] = arr[1]; + dp[2] = 2 * arr[2]; + for (long long z = 3; z < 1e5 + 1; z++) { dp[z] = max(dp[z - 2], dp[z - 3]) + z * arr[z]; } + cout << max(dp[1e5], dp[1e5 - 1]) << endl; +} +int main() { + string s; + cin >> s; + if (s[0] >= 'a' && s[0] <= 'z') { s[0] = toupper(s[0]); } + cout << s << endl; +} +int main() { + long long int ans, x, y, x1, y1; + cin >> x >> y >> x1 >> y1; + ans = max(abs(x - x1), abs(y - y1)); + cout << ans << endl; +} +int main() { + int n, top; + cin >> n >> top; + int n1, n2; + for (int i = 0; i < n; i++) { + cin >> n1 >> n2; + int arr[7] = {0}; + arr[n1] = 1; + arr[7 - n1] = 1; + arr[n2] = 1; + arr[7 - n2] = 1; + int tmp[2], indx = 0; + for (int t = 1; t < 7; t++) { + if (arr[t] == 0) { + tmp[indx] = t; + indx++; + } + } + int down = 7 - top; + if (down != tmp[0] && top == tmp[0]) + top = tmp[1]; + else if (down != tmp[1] && top == tmp[1]) + top = tmp[0]; + else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int A, B, C, D; + cin >> A >> B >> C >> D; + puts(A > B ? "First" : "Second"); +} +int n, ans; +char c[105]; +bool cek = 1; +int main() { + cin >> n; + ans = n; + cin >> c[0]; + for (int i = 1; i < n; i++) { + cin >> c[i]; + if (c[i - 1] != c[i] && cek) { + ans--; + cek = 0; + } else + cek = 1; + } + cout << ans << '\n'; +} +int N = 1e2 + 2; +int main() { + int n, k, cnt[N]; + memset(cnt, 0, sizeof(cnt)); + cin >> n >> k; + int all = 0, cal = 0; + for (int i = 1; i <= n; i++) { + int tmp; + cin >> tmp; + cnt[tmp]++; + all = max(all, cnt[tmp]); + } + while (all % k != 0) all++; + for (int i = 1; i < N; i++) + if (cnt[i]) cal++; + cout << all * cal - n << endl; +} +int a, sum; +int main() { + for (int i = 0; i < 5; i++) { + cin >> a; + sum += a; + } + if (sum == 0) { + cout << -1 << endl; + return 0; + } + if (sum % 5 == 0) { + cout << sum / 5 << endl; + return 0; + } + cout << -1 << endl; +} +int num[100005], k, n; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> num[i]; + sort(num + 1, num + n + 1); + long long count = 0; + int temp; + for (int i = 2; i <= n; i++) { + temp = (num[i] - num[1]) % k; + if (temp != 0) { + cout << -1 << endl; + return 0; + } else + count += (num[i] - num[1]) / k; + } + cout << count << endl; + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n, m, c = 0, d = 0; + cin >> n >> m; + char x; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> x; + if (x == 'B' || x == 'W' || x == 'G') + c++; + else + d++; + } + } + if (c == (n * m)) + cout << "#Black&White" << endl; + else if (d != 0) + cout << "#Color" << endl; + return 0; +} +int main() { + long long int k, b, n, t; + cin >> k >> b >> n >> t; + long long int num = 1; + long long int index = 0; + while (num <= t) { + num = k * num + b; + index++; + } + index--; + cout << max(0ll, n - index) << '\n'; +} +int main() { + int n, a, minn; + long long sum; + while (cin >> n) { + sum = 0; + minn = 1e9 - 1; + for (int i = 0; i < n; i++) { + cin >> a; + sum += a; + if (a % 2 != 0 && a < minn) minn = a; + } + if (sum % 2 != 0) + cout << sum - minn << endl; + else + cout << sum << endl; + } +} +long long mod = 1e9 + 7; +map mp; +long long a[200001]; +long long b[200001]; +long long c[11]; +long long u[151]; +int main() { + long long n, m, mn = 0, l, t1, t2, t3; + long long cnt = 0, ans = 0; + cin >> n >> m >> l; + cin >> t1 >> t2 >> t3; + long long res = abs(n - l) * t2 + t3 + t3 + abs(n - m) * t2 + t3; + long long oi = abs(n - m) * t1; + if (res > oi) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +const int maxn = 200005; +int n, A[maxn], B[maxn]; +int pos[maxn]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> A[i]; } + for (int i = 0; i < n; i++) { cin >> B[i]; } + int ans = 0; + for (int i = 0; i < n; i++) { + if (A[ans] == B[i]) { ans++; } + } + cout << n - ans << '\n'; + return 0; +} +const long long MAX = 2e5 + 9; +const long long INF = 1e12; +long long a[MAX], b[MAX], maps[600][600]; +string t, p; +long long check(long long len) { + string s = t; + for (long long i = 0; i < len; i++) s[a[i] - 1] = '0'; + long long ptr = 0, i = 0; + while (i < t.length() && ptr < p.length()) { + if (s[i] == p[ptr]) ptr++; + i++; + } + return (ptr != p.length()); +} +int main() { + cin >> t >> p; + for (long long i = 0; i < t.length(); i++) cin >> a[i]; + long long l = 0, r = t.length(), m; + while (l < r) { + m = (l + r + 1) / 2; + if (check(m)) + r = m - 1; + else + l = m; + } + cout << l << endl; +} +long long n, k; +int main() { + cin >> n >> k; + if (k <= (n + 1) / 2) { + cout << k * 2 - 1 << endl; + } else { + cout << (k - (n + 1) / 2) * 2 << endl; + } + return 0; +} +int main() { + long long cnt = 0; + long long c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + while (true) { + cnt++; + c -= v0; + if (v0 < v1) v0 += a; + if (v0 > v1) v0 = v1; + if (c <= 0) break; + c += l; + } + cout << cnt << "\n"; + return 0; +} +const int MAXN = 105; +const int INF = 0x3f3f3f3f; +int a[MAXN]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) cin >> a[i]; + a[n + 1] = INF; + int p = 2; + while (a[p] > a[p - 1]) p++; + while (a[p] == a[p - 1]) p++; + while (a[p] < a[p - 1]) p++; + if (p <= n) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int t, n, m, h, i, j, k, l, s, ans = 1000, ar[1000]; + cin >> n; + for (i = 0; i < n; i++) cin >> ar[i]; + for (j = 0; j < n; j++) { + for (i = j, s = 0; i < n; i++) { + s += ar[i]; + if (s > 180) { + ans = min(ans, 2 * min(s - 180, 180 - s + ar[i])); + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d, e, f, ans = 0, x = 0, y = 0, z = 0; + cin >> a >> b >> c >> d >> e >> f; + if (b > f) { + ans += 2 * a * f + f * (f + 1) - f; + x = a + f; + } else { + ans += 2 * a * b + b * (b + 1) - b; + x = a + b; + } + if (c > e) { + ans += 2 * d * e + e * (e + 1) - e; + y = c - e; + } else { + ans += 2 * d * c + c * (c + 1) - c; + y = e - c; + } + ans += 2 * x * y; + cout << ans << '\n'; + return 0; +} +int main() { + int n; + long long a; + long long tot = 0; + vector v; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + v.push_back(a); + tot += a; + } + if (tot % 2 == 0) { + cout << tot << "\n"; + return 0; + } + sort(v.begin(), v.end()); + for (int i = 0; i < n; i++) { + if (v[i] % 2 == 1) { + tot -= v[i]; + break; + } + } + cout << tot << "\n"; + return 0; +} +const int MaxN = 100005; +const int inf = 1e8; +const double PI = acos(-1); +map mp; +int main() { + string s; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; i++) mp[s[i]]++; + if (mp[s[0]] == len) + cout << "0" << endl; + else { + bool flag = true; + for (int i = 0; i < len / 2; i++) + if (s[i] != s[len - i - 1]) flag = false; + if (flag) + cout << len - 1 << endl; + else + cout << len << endl; + } + return 0; +} +int main() { + int n, a[101]; + cin >> n; + long long ans = 0; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + ans += 1LL * (a[i] - 1) * (i - 1) + a[i]; + } + cout << ans << endl; + return 0; +} +int n, m, b, mod, ans = 0; +int dp[505][505]; +int main() { + cin >> n >> m >> b >> mod; + dp[0][0] = 1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int j = 1; j <= m; j++) { + for (int k = x; k <= b; k++) (dp[j][k] += dp[j - 1][k - x]) %= mod; + } + } + for (int i = 0; i <= b; i++) { (ans += dp[m][i]) %= mod; } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int a = 0, d = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'A') + a++; + else + d++; + } + if (a == d) + cout << "Friendship" << endl; + else if (a > d) + cout << "Anton" << endl; + else + cout << "Danik" << endl; +} +int main() { + int m, n, max = 100500; + cin >> m >> n; + vector a(m); + vector b(n); + for (int i = 0; i < m; i++) cin >> a[i]; + for (int j = 0; j < n; j++) cin >> b[j]; + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { + if (a[i] == b[j]) { + max = min(max, a[i]); + } else { + max = min(max, a[i] * 10 + b[j]); + max = min(max, b[j] * 10 + a[i]); + } + } + } + cout << max << '\n'; + return 0; +} +int dp[101][101][5], k1, k2; +int rec(int n1, int n2, int turn) { + int &ret = dp[n1][n2][turn]; + if (~ret) return ret ^ 1; + ret = 0; + if (turn) { + if (!n1) return 1; + for (int i = 1; i <= min(k1, n1); i++) { ret = max(ret, rec(n1 - i, n2, turn ^ 1)); } + } else { + if (!n2) return 1; + for (int i = 1; i <= min(k2, n2); i++) { ret = max(ret, rec(n1, n2 - i, turn ^ 1)); } + } + return ret ^ 1; +} +int main() { + memset(dp, -1, sizeof dp); + int n1, n2; + cin >> n1 >> n2 >> k1 >> k2; + if (!rec(n1, n2, 1)) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +const long long int mod = 1e9 + 7; +int main() { + long long int n, k, mn = 1e10; + cin >> n >> k; + vector a(n); + for (int i = 0; i < n; ++i) { + cin >> a[i]; + mn = min(a[i], mn); + } + long long int ans = 0; + for (int i = 0; i < n; ++i) { + if ((a[i] - mn) % k) { + cout << -1 << '\n'; + return 0; + } + ans += (a[i] - mn) / k; + } + cout << ans << '\n'; + return 0; +} +int main() { + int x = 0, y = 0, n; + int a; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + x += a; + } + for (int i = 1; i <= n; i++) { + cin >> a; + y += a; + } + if (x >= y) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +const int unitTime = 5, checkoutTime = 15; +int customerTime(int units) { + return checkoutTime + unitTime * units; +} +int main() { + int n, x, k[100], lineTime, minTime = -1; + cin >> n; + for (int i = 0; i < n; i++) cin >> k[i]; + for (int i = 0; i < n; i++) { + lineTime = 0; + for (int j = 0; j < k[i]; j++) { + cin >> x; + lineTime += customerTime(x); + } + if (minTime < 0 || lineTime < minTime) minTime = lineTime; + } + cout << minTime << "\n"; + return 0; +} +int root(int a[], int x) { + int i = x; + while (i != a[i]) { + a[i] = a[a[i]]; + i = a[i]; + } + return i; +} +void unio(int a[], int b[], int x, int y) { + if (b[y] == 0) { + if (a[x] == 0) { + a[x] = x; + b[y] = x; + } else { + b[y] = a[root(a, x)]; + } + } else { + if (a[x] != 0) + a[root(a, x)] = root(a, b[y]); + else + a[x] = root(a, b[y]); + } +} +int main() { + int n; + cin >> n; + int a[1001] = {0}; + int b[1001] = {0}; + int c = 0; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + unio(a, b, x, y); + } + for (int i = 1; i < 1001; i++) { + if (a[i] == i) { c++; } + } + cout << c - 1 << endl; +} +int main() { + int i, x, b = 0, c = 0; + char a[100]; + cin >> a; + x = strlen(a); + for (i = 0; i < x; i++) { + if (a[i] == a[i + 1]) { + c++; + if (c >= 6) b = 1; + } else { + c = 0; + } + } + if (b == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +long long n, fix[1005][1005], x, y; +int main() { + cin >> n; + x = 1; + y = 1; + while (fix[x][y] == 0) { + fix[x][y]++; + x += y; + x %= n; + if (x == 0) x += n; + y++; + y %= n; + if (y == 0) y += n; + } + for (int i = 1; i <= n; i++) { + x = 0; + for (int j = 0; j <= n; j++) x += fix[i][j]; + if (!x) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +const int INF = 1e8 + 7; +const int MAXN = 1e6; +int n, m, ans; +inline int read() { + int X = 0, w = 0; + char ch = 0; + while (!isdigit(ch)) w |= ch == '-', ch = getchar(); + while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); + return w ? -X : X; +} +inline void write(int x) { + int num = 0; + char ch[20]; + if (!x) ch[++num] = '0'; + while (x) ch[++num] = (x % 10) + 48, x /= 10; + while (num) putchar(ch[num--]); + puts(""); +} +int main() { + n = read(), m = read(); + if (m > n) { + puts("-1"); + return 0; + } + int i = m; + while (2 * i < n) i += m; + write(i); + return 0; +} +const double Pi = acos(-1.0); +int main() { + int k; + cin >> k; + cout << "+------------------------+\n"; + cout << "|"; + if (k > 0) + cout << "O."; + else + cout << "#."; + int c = (k - 4) / 3; + if ((k - 4) % 3 > 0) c++; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|D|)\n"; + cout << "|"; + if (k > 1) + cout << "O."; + else + cout << "#."; + c = (k - 4) / 3; + if ((k - 4) % 3 > 1) c++; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|.|\n"; + cout << "|"; + if (k > 2) + cout << "O"; + else + cout << "#"; + cout << ".......................|\n"; + cout << "|"; + if (k > 3) + cout << "O."; + else + cout << "#."; + c = (k - 4) / 3; + for (int i = 0; i < 10; i++) { + if (i < c) + cout << "O."; + else + cout << "#."; + } + cout << "|.|)\n"; + cout << "+------------------------+\n"; + return 0; +} +int main() { + int n; + cin >> n; + int days = 0; + for (; n--;) { + int s, d; + cin >> s >> d; + if (days < s) { + days = s; + } else { + days += d - ((days - s) % d); + } + } + cout << days << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +int i, j; +int main() { + int a, b, c; + cin >> a >> b >> c; + if (c % b == 0) { + cout << "Yes" << endl; + return 0; + } + while (c > 0) { + c -= a; + if (c >= 0 && c % b == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; +} +int main() { + int n; + cin >> n; + vector used(n, false); + used[0] = true; + int pos = 0; + int d = 1; + for (int i = 0; i <= n * n + 100; ++i) { + pos = (pos + d) % n; + used[pos] = true; + d = (d + 1) % n; + } + for (int i = 0; i < n; ++i) { + if (!used[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; +} +int main() { + char s[100005], ss[100005], rs[100005]; + cin >> s; + int sz = strlen(s); + char ch = 'A'; + int k = 0; + for (int i = sz - 1; i >= 0; i--) { + if (s[i] >= ch) { + ch = s[i]; + rs[k++] = ch; + } + } + rs[k] = '\0'; + int p = 0; + for (int i = k - 1; i >= 0; i--) { ss[p++] = rs[i]; } + ss[p] = '\0'; + cout << ss << endl; + return 0; +} +long long i, n, sum; +int main() { + cin >> n; + if (n % 2 == 0) sum = n / 2 * (n + 1); + if (n % 2 != 0) sum = n / 2 * (n + 1) + (n / 2 + 1); + if (sum % 2 != 0) + cout << 1 << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + int i, j, a, b, c, d, x = 0, y, arr[4]; + for (i = 0; i < 4; i++) { cin >> arr[i]; } + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + if (arr[j] > arr[j + 1]) { swap(arr[j], arr[j + 1]); } + } + } + for (i = 0; i < 3; i++) { + if (arr[i] == arr[1 + i]) { x++; } + } + cout << x << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << (int)((log(b) - log(a)) / log(1.5)) + 1 << endl; +} +int Next[10010]; +void GetNext(string s1) { + int len = s1.length(); + memset(Next, 0, sizeof(Next)); + Next[0] = -1; + int k = -1; + for (int i = 1; i < len; i++) { + while (k > -1 && s1[k + 1] != s1[i]) k = Next[k]; + if (s1[k + 1] == s1[i]) k++; + Next[i] = k; + } +} +int kmp(string s1, string s2) { + int len1 = s1.length(), len2 = s2.length(); + GetNext(s2); + int k = -1; + int cnt = 0; + for (int i = 0; i < len1; i++) { + while (k > -1 && s2[k + 1] != s1[i]) k = Next[k]; + if (s2[k + 1] == s1[i]) k++; + if (k == len2 - 1) { + k = -1; + cnt++; + i = i - len2 + 1; + } + } + return cnt; +} +int main() { + string s[10] = {"Danil", "Olya", "Slava", "Ann", "Nikita"}; + string p; + cin >> p; + int cont = 0; + bool flag = false; + for (int i = 0; i < 5; i++) { + if (kmp(p, s[i]) == 1) { cont++; } + if (kmp(p, s[i]) > 1) { + flag = true; + break; + } + } + if (cont == 1 && flag == false) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n & (n - 1) ? "NO" : "YES") << endl; + return 0; +} +long long int a[10000000] = {0}; +long long int b[10000000] = {0}; +long long int c[10000000] = {0}; +int main() { + long long int i, k, j = 1, n, s, x, j1 = 0, j2; + cin >> n >> k; + s = sqrt(n); + for (i = 1; i <= s; i++) { + if (n % i == 0) { + a[j] = i; + j++; + if (i * i != n) { + b[j1] = n / i; + j1++; + } + } + } + for (i = j1 - 1, j2 = 0; i >= 0; i--, j2++) { c[j2] = b[i]; } + if (k < (j + j2)) { + if (k < j) + cout << a[k] << endl; + else { + cout << c[k - j] << endl; + } + } else + cout << -1 << endl; + return 0; +} +const int M = 100 + 10; +int main() { + long long int k, b, n, t; + cin >> k >> b >> n >> t; + if (k == 1) { + long long int z = 1 + n * b; + if (z <= t) { + cout << "0" << endl; + } else { + long long int res = z - t; + long long int ans = res / b + (res % b != 0); + cout << ans << endl; + } + } else { + long long int num1 = t * (k - 1) + b; + long long int num2 = k - 1 + b; + long long int num3 = num1 / num2; + long long int num = 1; + int tm = 0; + while (num * k <= num3) { + num = num * k; + tm++; + } + int m = n - tm; + m = max(m, 0); + cout << m << endl; + } + return 0; +} +int main() { + int a, b, c; + int sum = 0; + cin >> a >> b >> c; + for (int i = a; i > 0; i--) { + if (2 * i <= b && 4 * i <= c) { + sum = 7 * i; + break; + } + } + cout << sum << endl; + return 0; +} +int main() { + long long n, k; + long long j; + cin >> n >> k; + if (k <= (n + 1) / 2) { + cout << 2 * k - 1 << endl; + } else { + j = (k - (n + 1) / 2) * 2; + cout << j << endl; + } +} +int main() { + int n, p[2001], ch[2001], v; + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> v; + p[i] = v; + if (i != 1) { ch[v] = i; } + } + int cnt = 0, h, mx; + for (int i = 1; i <= n; ++i) { + h = 1; + int cnt = i; + while (p[cnt] != -1) { + ++h; + cnt = p[cnt]; + } + mx = max(mx, h); + } + cout << mx << endl; + return 0; +} +int main() { + int a, b, c, x, y, z, q; + while (cin >> a >> b >> c >> x >> y >> z >> q) { + int sum1 = a + b + c, sum2 = x + y + z; + if (sum1 % 5 == 0) { + sum1 = sum1 / 5; + } else { + sum1 = sum1 / 5 + 1; + } + if (sum2 % 10 == 0) { + sum2 = sum2 / 10; + } else { + sum2 = sum2 / 10 + 1; + } + if (sum1 + sum2 <= q) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) { + long long m = n / 2; + if (m % 2 == 0) { + cout << "0" << endl; + } else { + cout << "1" << endl; + } + } else { + long long m = (n - 1) / 2; + if (m % 2 == 0) { + cout << "1" << endl; + } else { + cout << "0" << endl; + } + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long count = 0; + while (k % n == 0 && n != 1) { + k = k / n; + count++; + } + if (k > 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + cout << count - 1 << endl; + } +} +int main() { + long long x, y, a, b, c, d; + cin >> a >> b >> c >> d; + cin >> x >> y; + long long tmpx = abs(c - a); + long long tmpy = abs(d - b); + if (tmpx % x != 0 || tmpy % y != 0) + cout << "NO" << endl; + else { + tmpx /= x; + tmpy /= y; + if (tmpx % 2 != tmpy % 2) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +const int maxn = 105; +int f[maxn]; +int main() { + f[1] = f[2] = 1; + for (int i = 3; i < maxn; i += 2) { f[i] = f[i + 1] = (i / 2) * i + (i / 2 + 1); } + int n; + while (cin >> n) { + if (n == 3) { + cout << 5 << endl; + continue; + } + for (int i = 1; i < maxn; i += 2) { + if (n <= f[i]) { + cout << i << endl; + break; + } + } + } + return 0; +} +int length, maxnum = 0, gap = 0; +char str[100]; +char exam[100]; +int IfHuiwen() { + int l = strlen(exam); + if (l == 1) return 1; + if (l % 2 == 0) { + for (int i = 0, j = l - 1; i < l / 2, j >= l / 2; i++, j--) { + if (exam[i] != exam[j]) return 0; + } + } else { + int numx = l - 1; + for (int i = 0; i < l - 1 / 2; i++) { + if (exam[i] != exam[numx--]) return 0; + } + } + return 1; +} +int main() { + while (cin >> str) { + maxnum = 0; + length = strlen(str); + for (int i = 0; i < length; i++) { + for (int j = i; j < length; j++) { + memset(exam, 0, sizeof(exam)); + int flag = 0; + for (int k = i; k <= j; k++) { exam[flag++] = str[k]; } + if (IfHuiwen() == 0 && flag > maxnum) { maxnum = flag; } + } + } + cout << maxnum << endl; + } + return 0; +} +const int maxn = 1e5 + 5; +int s[maxn]; +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + int i = 7; + int sum = 0; + while (n) { + int k = n / i; + if (k) { + n = n - k * i; + sum += k; + } + i--; + } + cout << sum << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << "\n"; + for (int i = 1; i <= m; i++) { cout << 1 << " " << i << "\n"; } + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << "\n"; } + return 0; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + cout << 0 << "\n"; + return 0; + } + if (n == 1) { + cout << 1 << "\n"; + return 0; + } + if (n % 2 == 1) + cout << (n + 1) / 2 << "\n"; + else + cout << n + 1 << "\n"; + return 0; +} +int main() { + long long int n, a[100001], sum; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, n + a); + sum = 0; + for (int i = 0; i < n; i++) { sum = sum + a[i]; } + for (int i = 0; i < n; i++) { + if (sum % 2 != 0 && a[i] % 2 != 0) { + sum = sum - a[i]; + break; + } + } + cout << sum << endl; + return 0; +} +int main() { + int x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2; + cin >> x >> y; + int dx = (x2 - x1) % x; + int dy = (y2 - y1) % y; + int dx2 = (x2 - x1) / x; + int dy2 = (y2 - y1) / y; + if (dx != 0 || dy != 0) { + cout << "NO" << endl; + } else if (dx2 % 2 == dy2 % 2 || dx2 % 2 == -dy2 % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +const int N = 2e6 + 6; +int pos[N], id[N], arr[N], BIT[N], brr[N]; +void updt(int idx, int x) { + while (idx <= N / 10) BIT[idx] += x, idx += (idx & -idx); +} +int qry(int idx) { + int ret = 0; + while (idx >= 1) ret += BIT[idx], idx -= (idx & -idx); + return ret; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + pos[arr[i]] = i; + } + for (int i = 1; i <= n; i++) cin >> brr[i]; + int mn = 0; + for (int i = 1; i <= n; i++) { + int now = pos[brr[i]]; + int ret = qry(now); + ret += now; + if (ret > i) { + updt(1, 1); + updt(now, -1); + mn = max(mn, n - now + 1); + } + } + cout << mn << "\n"; + return 0; +} +int main() { + int n, i, k = 0, p = 0; + cin >> n; + string s; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == 'A') + p++; + else if (s[i] == 'D') + k++; + } + if (p > k) + cout << "Anton" << endl; + else if (p < k) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; +} +int main() { + long long n, m, s, f, t, l, l1, k; + cin >> n; + cin >> m; + vector a(n, 0); + for (int i = 0; i < n; i++) { + cin >> s; + cin >> f; + cin >> t; + k = 0; + if (s == f) { + a[i] = t; + } else { + l = t / (2 * m - 2); + l1 = t - l * (2 * m - 2); + k = k + l * (2 * m - 2); + if (s < f) { + if (l1 > s - 1) { + k = k + 2 * m - 2; + k = k + f - 1; + } else { + k = k + f - 1; + } + } else { + if (l1 > m - 1 + m - s) { k = k + 2 * m - 2; } + k = k + m - 1; + k = k + m - f; + } + a[i] = k; + } + } + for (int i = 0; i < n; i++) { cout << a[i] << endl; } +} +int n, a, b, c, d, e, sum, f, g; +string name; +int main() { + cin >> n; + pair p[n]; + for (int i = 0; i < n; i++) { + cin >> name >> a >> b >> c >> d >> e >> f >> g; + sum += c + d + e + f + g; + sum += (a * 100) - (b * 50); + p[i] = {sum, name}; + sum = 0; + } + sort(p, p + n); + cout << p[n - 1].second << endl; +} +int abs(int x) { + if (x < 0) return -x; + return x; +} +void solve() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int timeWalk = abs(y - x) * t1; + int timeTakeElevator = t3 * 3; + timeTakeElevator += abs(x - z) * t2; + timeTakeElevator += abs(y - x) * t2; + if (timeTakeElevator > timeWalk) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } +} +int main() { + solve(); + return 0; +} +int r, c, sum, i, j; +bool rb[10], cb[10]; +char a; +int main() { + cin >> r >> c; + for (i; i < r; i++) { + for (j = 0; j < c; j++) { + cin >> a; + if (a == 'S') { + rb[i] = true; + cb[j] = true; + } + } + } + for (i = 0; i < r; i++) { + if (rb[i] == true) { continue; } + sum += c; + } + for (i = 0; i < c; i++) { + if (cb[i] == false) { + for (j = 0; j < r; j++) { + if (rb[j] == true) sum++; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + long long a, b, c; + cin >> n >> a >> b >> c; + long long data1, data2, data3; + if (n % 4 == 0) + cout << "0" << endl; + else { + int x = 4 - n % 4; + if (x == 1) { + if (a < b + c) + data1 = a; + else + data1 = b + c; + if (data1 > 3 * c) data1 = 3 * c; + cout << data1 << endl; + } + if (x == 2) { + if (b > 2 * c) + data2 = 2 * c; + else + data2 = b; + if (data2 > 2 * a) data2 = 2 * a; + if (data2 > c + 3 * a) data2 = c + 3 * a; + cout << data2 << endl; + } + if (x == 3) { + if (c < a + b) + data3 = c; + else + data3 = a + b; + if (data3 > 3 * a) data3 = 3 * a; + cout << data3 << endl; + } + } + return 0; +} +int mx[4] = {1, 0, -1, 0}; +int my[4] = {0, 1, 0, -1}; +int simulate(int x, int y, string &s, map &dir) { + for (int i = 0; i < s.size(); i++) { + x += mx[dir[s[i]]]; + y += my[dir[s[i]]]; + } + return x == 0 && y == 0; +} +int main() { + int n; + map dir; + dir['R'] = 0; + dir['U'] = 1; + dir['L'] = 2; + dir['D'] = 3; + while (cin >> n) { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + string sim = s.substr(i, j - i + 1); + ans += simulate(0, 0, sim, dir); + } + } + cout << ans << endl; + } + return 0; +} +char c[251][251]; +int n, m, i, j, kol; +int main() { + cin >> n >> m; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) cin >> c[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) + if ((c[i][j] == 'W') || (c[i][j] == 'B') || (c[i][j] == 'G')) kol++; + if (kol == n * m) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; + return 0; +} +long long n, k, a, sum, l; +int main() { + cin >> n >> k; + for (long long i = 1; i <= n; i++) { + cin >> a; + if (i != 1) { + if (sum - (n - i) * (i - 1) * a < k) { + cout << i + l << endl; + i--; + n--; + l++; + } else + sum += a * (i - 1); + } + } +} +int main() { + map m; + long long v1, v2, v3, time = 0, flg = 0, i = 0; + char s[3] = {'g', 'b', 'r'}; + cin >> v1 >> v2 >> v3; + m['r'] = v1; + m['g'] = v2; + m['b'] = v3; + m['r'] -= 2; + time += 30; + while (1) { + if (m['r'] < 1) flg |= 1; + if (m['g'] < 1) flg |= 2; + if (m['b'] < 1) flg |= 4; + if (flg == 7) break; + m[s[i % 3]] -= 2; + i++; + ++time; + } + cout << time << endl; + return 0; +} +const int INF = 0x7fffffff; +int main() { + int n, m; + char s[10]; + cin >> n >> m; + int l = 1, r = n; + for (int i = 0; i < m; i++) { + cin >> s >> s >> s; + int x; + if (s[0] == 'r') { + cin >> s >> x; + l = max(l, x + 1); + } + if (s[0] == 'l') { + cin >> s >> x; + r = min(r, x - 1); + } + } + cout << (r - l + 1 > 0 ? r - l + 1 : -1) << endl; + return 0; +} +int a[2005]; +int main() { + int i, n, h, node, maxh; + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + maxh = 0; + for (i = 1; i <= n; ++i) { + h = 1; + node = i; + while (a[node] != -1) { + node = a[node]; + h++; + } + if (h > maxh) maxh = h; + } + cout << maxh << endl; + return 0; +} +int main() { + int i, a, b, count = 0; + cin >> a >> b; + for (i = 1; i <= 10; i++) { + a = a * 3; + b = b * 2; + count++; + if (a > b) { break; } + } + cout << count << endl; + return 0; +} +const int INF = 2000000000; +const double EPS = 1e-9; +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) + cout << "Second\n"; + else + cout << "First\n"; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int c = 0, c1 = 0, x, y; + for (int i = 0; i < n; i++) { + c = 0; + x = 0, y = 0; + for (int j = i; j < n; j++) { + if (s[j] == 'R') { + x++; + } else if (s[j] == 'U') { + y++; + } else if (s[j] == 'L') { + x--; + } else if (s[j] == 'D') { + y--; + } + if (x == 0 && y == 0) { c++; } + } + if (c > 0) { c1 = c1 + c; } + } + cout << c1 << endl; + return 0; +} +int main() { + int x, l, c = 0; + string str, res = ""; + cin >> str; + l = str.length(); + x = (l - 1) / 2; + while (str.length() != 0) { + res.append(str.begin() + x, str.begin() + (x + 1)); + str.erase(str.begin() + x); + if (c % 2 == 0) + c++; + else { + c++; + x--; + } + } + cout << res << endl; + return 0; +} +char A[100][100]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> A[i][j]; } + } + int a = 0; + int y, y1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (A[i][j] == '*') { a++; } + } + if (a == 1) y = i; + if (a == 2) y1 = i; + a = 0; + } + for (int j = 0; j < m; j++) { + if (A[y][j] != A[y1][j]) cout << y + 1 << " " << j + 1; + } + cout << endl; + return 0; +} +int n; +pair arr[105]; +int parent[105]; +int par(int i) { + if (parent[i] == i) return i; + return par(parent[i]); +} +void unin(int i, int j) { + int ipar = par(i); + int jpar = par(j); + parent[ipar] = jpar; +} +int main() { + cin >> n; + for (long long i = 0; i < n; ++i) { parent[i] = i; } + for (long long i = 0; i < n; ++i) { cin >> arr[i].first >> arr[i].second; } + for (long long i = 0; i < n; ++i) { + for (long long j = 0; j < n; ++j) { + if (i == j) continue; + if (arr[i].first == arr[j].first || arr[i].second == arr[j].second) { unin(i, j); } + } + } + set st; + for (long long i = 0; i < n; ++i) { st.insert(par(i)); } + cout << st.size() - 1 << endl; +} +long removeZero(long n) { + long x = 0; + int num = 1; + while (n > 0) { + if (n % 10 != 0) { + x += (n % 10) * (num); + num *= 10; + } + n /= 10; + } + return x; +} +int main() { + long num1, num2, sum1, sum2; + cin >> num1 >> num2; + sum1 = num1 + num2; + num1 = removeZero(num1); + num2 = removeZero(num2); + sum2 = num1 + num2; + if (sum2 == removeZero(sum1)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = 2e5 + 5; +int Prv[N], vis[N]; +void dfs(int u) { + if (vis[u]) return; + vis[u] = true; + dfs(Prv[u]); +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> Prv[i]; + int now = 1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + now += x; + } + int Res = 0; + for (int i = 1; i <= n; i++) { + if (!vis[i]) { + dfs(i); + Res++; + } + } + if (Res == 1) Res--; + cout << (Res + (now % 2)) << "\n"; + return 0; +} +string s; +string friend_of_Alex[20] = {"", "Danil", "Olya", "Slava", "Ann", "Nikita"}; +int cnt; +int main() { + cin >> s; + int l = s.length(); + for (int i = 0; i < l; i++) + for (int j = 1; j <= l - i; j++) + for (int k = 1; k <= 5; k++) + if (s.substr(i, j) == friend_of_Alex[k]) cnt++; + cout << (cnt == 1 ? "YES" : "NO") << endl; + return 0; +} +int main() { + string str; + string ans; + cin >> str; + int k; + int len = str.length(); + if (len % 2 == 0) + k = len / 2 - 1; + else + k = len / 2; + ans.push_back(str[k]); + for (int i = 1; i < len; i++) { + if (k + i < len) ans.push_back(str[k + i]); + if (k - i >= 0) ans.push_back(str[k - i]); + } + cout << ans << endl; +} +int main() { + int n, x; + cin >> n >> x; + int l, r, S = 0, pos = 1; + for (int i = 1; i <= n; i++) { + cin >> l >> r; + S += r + 1 - pos - (l - pos) / x * x; + pos = r + 1; + } + cout << S << endl; + return 0; +} +const int MOD = 1e9 + 7; +double gcd(double a, double b) { + return a < 0.01 ? b : gcd(fmod(b, a), a); +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int max(long long int a, long long int b, long long int c) { + return max(a, max(b, c)); +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int min(long long int a, long long int b, long long int c) { + return min(a, min(b, c)); +} +long long int power(long long int x, long long int y) { + long long int res = 1; + x = x % MOD; + while (y > 0) { + if (y & 1) res = (res * x) % MOD; + y = y >> 1; + x = (x * x) % MOD; + } + return res; +} +void swap(char *x, char *y) { + char temp; + temp = *y; + *y = *x; + *x = temp; +} +long long int mod(long long int a) { + if (a > 0) + return a; + else + return -a; +} +int main() { + int t, a, b; + cin >> a >> b; + long long int c = a + b; + int ad[12] = {0}, cd[12] = {0}, bd[12] = {0}; + t = a; + int as = 0, bs = 0, cs = 0, k = 0; + while (t != 0) { + if (t % 10 != 0) ad[k++] = t % 10; + t = t / 10; + } + as = k; + t = b; + k = 0; + while (t != 0) { + if (t % 10 != 0) bd[k++] = t % 10; + t /= 10; + } + t = c; + bs = k; + k = 0; + while (t != 0) { + if (t % 10 != 0) cd[k++] = t % 10; + t /= 10; + } + cs = k; + int p = 0, q = 0, r = 0; + for (int i = as - 1; i >= 0; i--) { + p += (ad[i]); + p *= 10; + } + for (int i = bs - 1; i >= 0; i--) { + q += (bd[i]); + q *= 10; + } + for (int i = cs - 1; i >= 0; i--) { + r += (cd[i]); + r *= 10; + } + if ((p + q) == r) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + bool cek = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + if (a == 1) { cek = 1; } + } + if (cek == 0) { + cout << "EASY" << endl; + } else { + cout << "HARD" << endl; + } +} +long long int expo_fast(long long int a, long long int b) { + a = a; + long long int result = 1; + while (b) { + if (b & 1) result = (result * a); + b >>= 1; + a = (a * a); + } + return (result); +} +void take_in(vector *arr) { + for (int i = 0; i < arr->size(); i++) cin >> (*(arr))[i]; +} +void disp_arr(vector *arr) { + for (int i = 0; i < arr->size(); i++) cout << (*(arr))[i] << " "; +} +string func(string s, int n) { + string q; + q.resize(n); + q[0] = s[0]; + q[1] = s[1]; + q[2] = s[2]; + for (int i = 3; i < n; i++) { + if (i % 3 == 0) + q[i] = q[0]; + else if (i % 3 == 1) + q[i] = q[1]; + else + q[i] = q[2]; + } + return q; +} +int main() { + string s; + cin >> s; + stack stk; + long long int ans = 0; + bool cond1 = true, cond2 = true; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '0') { + if (cond1) { + cond1 = false; + cout << "1 1\n"; + } else { + cond1 = true; + cout << "3 1\n"; + } + } else { + if (cond2) { + cond2 = false; + cout << "4 3\n"; + } else { + cond2 = true; + cout << "4 1\n"; + } + } + } +} +const int maxn = 100010; +long long n, dp[maxn], num[maxn], maxa; +void solve() { + dp[1] = num[1]; + for (long long i = 2; i <= maxa; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + num[i] * i); } + cout << dp[maxa] << endl; +} +int main() { + long long t; + while (cin >> n) { + memset(dp, 0, sizeof(dp)); + memset(num, 0, sizeof(num)); + long long maxx = 0; + for (long long i = 1; i <= n; i++) { + cin >> t; + if (t > maxa) maxa = t; + num[t]++; + } + solve(); + } + return 0; +} +int main() { + int T[105]; + int K[105]; + int n, x; + cin >> n; + for (int i = int(0); i < int(n); i++) cin >> K[i]; + for (int i = int(0); i < int(n); i++) { + T[i] = K[i] * 15; + for (int j = int(0); j < int(K[i]); j++) { + cin >> x; + T[i] += 5 * x; + } + } + int men = 1 << 30; + for (int i = int(0); i < int(n); i++) men = min(men, T[i]); + cout << men << endl; + return 0; +} +long long ksm(long long a, long long b, long long c) { + long long r = 1; + a = a % c; + while (b) { + if (b & 1) r = (r * a) % c; + a = (a * a) % c; + b >>= 1; + } + return r; +} +int arr[107]; +int main() { + int n, k, maxn = -1, ans, sum = 0, m; + cin >> n >> k; + m = k; + for (int i = 1; i <= n; i++) { + int q; + cin >> q; + if (!arr[q]) sum++; + arr[q]++; + maxn = max(arr[q], maxn); + } + while (maxn > k) { k += m; } + ans = k * sum - n; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int e; + cin >> e; + if (e == 1) { + cout << "HARD" << endl; + return 0; + } + } + cout << "EASY" << endl; + return 0; +} +int main() { + string s, t = ""; + cin >> s; + int n = ((s.size() - 1) / 2), m = n + 1, i = n, j = m; + while (i >= 0) { + t += s[i]; + if (j >= s.size()) { break; } + t += s[j]; + i--; + j++; + } + cout << t << '\n'; +} +int main() { + int n, x, i, r; + cin >> n >> x; + int l = 1, min = 0; + while (n--) { + cin >> i >> r; + min += (i - (l + ((i - l) / x) * x)) + r - i + 1; + l = r + 1; + } + cout << min << endl; + return 0; +} +int a[100005]; +map mp; +int main() { + int n, m, k, x, ans = 0; + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> k; + mp[i] = k; + for (int j = 0; j < k; j++) { + cin >> x; + a[x] = i; + } + } + x = 0; + bool f = 1; + for (int i = 1, c = 0; c < n; i++) { + if (a[i]) { + if (c == 0) { x = i; } + if (a[x] != a[i]) f = 0; + if (f) + ans = ans; + else if (mp[a[i]] == 1) { + ans++; + } else { + ans += 2; + mp[a[i]]--; + } + c++; + } + } + cout << ans << endl; +} +bool check(int x) { + return x && (!(x & (x - 1))); +} +int main() { + long long int a, b; + cin >> a >> b; + if (a == 1) { + if (check(b)) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; + } + set s1; + int d = a; + while (1) { + if (d % b == 0) { + cout << "Yes" << endl; + return 0; + } + if (s1.find(d % b) == s1.end()) { + s1.insert(d % b); + d += d % b; + } else + break; + } + cout << "No" << endl; + return 0; +} +int main() { + int a, m; + cin >> a >> m; + for (int i = 0; i < 2 * m; i++) { + a = 2 * a % m; + if (a == 0) { + cout << "Yes\n"; + return 0; + } + } + cout << "No\n"; +} +int main() { + int a, b, c; + int cnt = 0; + cin >> a; + for (int i = 1; i <= a; i++) { + cin >> b; + if (b == 1) cnt++; + } + if (cnt >= 1) + cout << "HARD" << endl; + else + cout << "EASY" << endl; +} +void solve() { + long long a, b, c; + cin >> a >> b >> c; + long long x = a; + if (c % a == 0 || c % b == 0) { + cout << "Yes\n"; + return; + } + while (c >= a) { + if ((c - a) % b == 0) { + cout << "Yes\n"; + return; + } + a += x; + } + cout << "No\n"; + return; +} +int main() { + int test_cases = 1; + while (test_cases--) { solve(); } + return 0; +} +int main() { + int n, m, i; + cin >> n >> m; + for (i = 1;; i++) { + n *= 3; + m *= 2; + if (n > m) break; + } + cout << i << endl; + return 0; +} +int idx_b[200005], a[200005], b[200005], idx_a[200005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + cin >> b[i]; + idx_b[b[i]] = i; + } + for (int i = 1; i <= n; i++) a[i] = idx_b[a[i]]; + int pos = 1; + for (int i = 1; i <= n; i++, pos++) + if (a[i] > a[i + 1]) break; + cout << n - pos << endl; + return 0; +} +int gcd(int a, int b) { + while (1) { + if (a < b) { + int t = a; + a = b; + b = t; + } + if (a % b == 0) return b; + a = a % b; + } +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (1) { + n -= gcd(a, n); + if (n == 0) { + cout << "0" << endl; + break; + } + n -= gcd(b, n); + if (n == 0) { + cout << "1" << endl; + break; + } + } + return 0; +} +int main() { + int k, s = 0; + string m; + cin >> k >> m; + if (k == 1) { + cout << "0" << endl; + return 0; + } + for (int i = 0; i < k - 1; i++) { + if (m[i] == m[i + 1]) s++; + } + cout << s << endl; + return 0; +} +const int maxn = 2001; +int a = 0x3f3f3f3f; +int gcd(int a, int b) { + return (b == 0) ? a : gcd(b, a % b); +} +int main() { + int A[maxn]; + int temp = 0, n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> A[i]; + if (A[i] == 1) temp++; + } + if (temp) { + cout << n - temp << endl; + return 0; + } + for (int i = 0; i < n - 1; i++) { + int m = A[i]; + for (int j = i + 1; j < n; j++) { + m = gcd(m, A[j]); + if (m == 1) a = min(a, j - i); + } + } + if (a == 0x3f3f3f3f) + cout << -1 << endl; + else + cout << a + n - 1 << endl; + return 0; +} +int main() { + int n; + char s[100]; + cin >> n >> s; + int t = 1; + for (int i = 0; i < n; i += t) { + cout << s[i]; + t++; + } + cout << endl; + return 0; +} +const int N = 5e2 + 1, inf = 1e9 + 7; +int hot[N][N]; +int n, m, b, mod, Arr[N]; +int main() { + cin >> n >> m >> b >> mod; + for (int i = 1; i <= n; i++) cin >> Arr[i]; + hot[0][0] = 1; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + for (int k = Arr[i]; k <= b; k++) hot[j][k] += hot[j - 1][k - Arr[i]], hot[j][k] %= mod; + } + } + int res = 0; + for (int i = 0; i <= b; i++) res = (res + hot[m][i]) % mod; + cout << res << '\n'; +} +int main() { + string str; + cin >> str; + if (((int)str[0] <= (int)'z') && ((int)str[0] >= 'a')) str[0] = (char)((int)str[0] - 32); + cout << str << endl; +} +int main() { + int n, i, j, tmp, tmp2; + cin >> n >> tmp; + for (i = 1; i < n; i++) { + cin >> tmp2; + if (tmp == tmp2) { + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp > tmp2) { + tmp = tmp2; + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp <= tmp2) { + cout << "NO" << endl; + return 0; + } + tmp = tmp2; + } + } else if (tmp < tmp2) { + cout << "NO" << endl; + return 0; + } + } + } else if (tmp > tmp2) { + tmp = tmp2; + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp <= tmp2) { + cout << "NO" << endl; + return 0; + } + tmp = tmp2; + } + } + tmp = tmp2; + } + cout << "YES" << endl; + return 0; +} +int n, arr[101]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + for (int i = 0; i < n; ++i) { + int num = arr[i]; + arr[i] *= 15; + while (num--) { + int tmp; + cin >> tmp; + arr[i] += tmp * 5; + } + } + int mn = 1e9; + for (int i = 0; i < n; ++i) { mn = min(mn, arr[i]); } + cout << mn << endl; + return 0; +} +int main() { + string s, p; + int k, ans = 0; + map forb; + cin >> s; + cin >> k; + for (int i = 0; i < k; i++) { + cin >> p; + forb[p[0]] = p[1]; + forb[p[1]] = p[0]; + } + int i = 0, j = 0, counta, countb; + while (s[i] != '\0') { + if (forb[s[i]]) { + j = i; + char e = s[i], d = forb[s[i]]; + bool o = true, t = false; + counta = 0, countb = 0; + while ((s[j] == e || s[j] == d) && s[j] != '\0') { + if (s[j] == d) { + t = true; + countb++; + } else { + counta++; + } + j++; + } + if (t && o) { ans += min(counta, countb); } + i = j - 1; + } + i++; + } + cout << ans << endl; + return 0; +} +int sh(int a, int b, int n, int m); +int gcd(int x, int y); +int main() { + int a, b, n; + while (cin >> a >> b >> n) { + int t = sh(a, b, n, 1); + if (t == 1) cout << "1" << endl; + if (t == 0) cout << "0" << endl; + } +} +int sh(int a, int b, int n, int m) { + if (m == 1) { + int t = gcd(a, n); + if (n < t) return 1; + if (n >= t) sh(a, b, n - t, 2); + } + if (m == 2) { + int t = gcd(b, n); + if (n < t) return 0; + if (n >= t) sh(a, b, n - t, 1); + } +} +int gcd(int x, int y) { + int s; + if (x > y) { + int t = x; + x = y; + y = t; + } + if (x == 0) s = y; + if (x != 0) { + for (int i = x; i > 0; i--) + if (x % i == 0 && y % i == 0) { + s = i; + i = 0; + } + } + return s; +} +int main() { + int n; + cin >> n; + vector out(n); + int x; + for (int i = 0; i < n; i++) { + cin >> x; + out[i] = x / 7; + if (x % 7 != 0) { out[i]++; } + } + for (int i = 0; i < n; i++) { cout << out[i] << endl; } +} +int main() { + string s; + while (cin >> s) { + map m; + for (int i = 0; i < s.length(); ++i) { m[s[i]]++; } + map::iterator it = m.end(); + it--; + for (int i = 0; i < s.length(); ++i) { + if ((it->second) > 0) { + if (s[i] == it->first) cout << s[i]; + m[s[i]]--; + while (it->second == 0 && it != m.begin()) { it--; } + } + } + cout << endl; + } + return 0; +} +int main() { + long n; + cin >> n; + long c1 = 0; + long c2 = 0; + for (long i = 0; i < n; i++) { + char ch; + cin >> ch; + if (ch == 'A') + ++c1; + else + ++c2; + } + if (c1 > c2) + cout << "Anton" << endl; + else if (c1 == c2) + cout << "Friendship" << endl; + else + cout << "Danik" << endl; +} +int main() { + int r, g, b; + cin >> r >> g >> b; + int t = 0; + while (true) { + if (t % 3 == 0) { r -= min(2, r); } + if (t % 3 == 1) { g -= min(2, g); } + if (t % 3 == 2) { b -= min(2, b); } + if (r == 0 && g == 0 && b == 0) { break; } + t++; + } + cout << t + 30 << endl; + return 0; +} +int main() { + int a, b, c, d, e, f, g, h, i; + cin >> a >> b >> c; + d = a * b * c; + e = (a + b) * c; + f = a * (b + c); + g = a + b * c; + h = a * b + c; + i = a + b + c; + d = max(d, e); + d = max(d, f); + d = max(d, g); + d = max(d, h); + d = max(d, i); + cout << d << endl; + return 0; +} +const int mod = 1e9 + 7; +int main() { + string str; + int n; + cin >> n; + cin >> str; + int sum = 0; + for (int i = 0; i < n - 1; i++) { + if (str[i] == str[i + 1]) sum++; + } + cout << sum << endl; +} +int power(int a, int b, int modi) { + int res = 1; + while (b) { + if (b % 2) res = (res * a) % modi; + b /= 2; + a = (a * a) % modi; + } + return res; +} +int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int dx[] = {-1, 1, 0, 0}; +int dy[] = {0, 0, -1, 1}; +int k, sum = 0, ans = 0, cur = 0, x, y; +int n, m, r, c; +int a[1005]; +int main() { + long long a, b; + cin >> a >> b; + long long c = 0; + while (a <= b) { + a = a * 3; + b = b * 2; + c++; + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + int summ = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[i] = x; + } + int k = 1000000; + for (int i = 0; i < n; i++) { + for (int j = 0; j < a[i]; j++) { + int x; + cin >> x; + summ += 15 + x * 5; + } + if (summ <= k && summ > 0) k = summ; + summ = 0; + } + cout << k << endl; +} +int main() { + int n, x; + int l, r, i; + while (cin >> n >> x) { + int sum = 0, ans = 1; + for (i = 0; i < n; i++) { + cin >> l >> r; + while (ans + x <= l) ans += x; + sum += r - ans + 1; + ans = r + 1; + } + cout << sum << endl; + } + return 0; +} +long long k, b, n, t, x = 1, ans; +int main() { + cin >> k >> b >> n >> t; + while (x <= t) x = x * k + b, ans++; + cout << max(0ll, n - ans + 1) << endl; + return 0; +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + int count = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if (i % k != 0 && i % l != 0 && i % m != 0 && i % n != 0) { count--; } + } + cout << count << endl; + } + return 0; +} +long long arr[200001]; +int main() { + long long n, i, sum = 0; + cin >> n; + sum = (n * (n + 1)) / 2; + if (sum % 2 == 0) { + cout << 0 << endl; + } else if (sum % 2 != 0) { + cout << 1 << endl; + } +} +int main() { + int n, m, k, mi = 110; + cin >> n >> m >> k; + m--; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] <= k && arr[i] != 0 && mi > abs(i - m)) { mi = abs(i - m); } + } + cout << mi * 10 << endl; +} +int k, d; +int main() { + cin >> k >> d; + if (d == 0 && k > 1) { + cout << "No solution" << endl; + return 0; + } + cout << d; + k--; + while (k--) cout << 0; + cout << endl; + return 0; +} +int n, m, k, lanes, desk, r; +char pos; +int main() { + cin >> n >> m >> k; + lanes = k / (m * 2); + r = k % (m * 2); + if (r) + lanes++; + else + r = (m * 2); + desk = r / 2; + if (r % 2) desk++; + if (r % 2) + pos = 'L'; + else + pos = 'R'; + cout << lanes << ' ' << desk << ' ' << pos << '\n'; + return 0; +} +int main() { + int n; + long long sum, ans, sum1; + string s; + while (cin >> n) { + cin >> s; + ans = 0; + for (int j = 0; j < n; j++) { + sum1 = sum = 0; + for (int i = j; i < n; i++) { + if (s[i] == 'R') + sum++; + else if (s[i] == 'L') + sum--; + else if (s[i] == 'U') + sum1++; + else if (s[i] == 'D') + sum1--; + if ((sum1 == 0) && (sum == 0)) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, ans, i, m; + cin >> n >> m; + for (i = (n + 1) / 2; i <= n; i++) { + if (i % m == 0) { + cout << i << endl; + return 0; + } + } + cout << "-1" << endl; + return 0; +} +int main() { + int n, p = 0; + cin >> n; + char a[10]; + for (int i = 0; i < n; i++) { + cin >> a; + if (a[0] == '+' || a[2] == '+') + p++; + else + p--; + } + cout << p << endl; +} +bool can(int i, int j, int k) { + if (i + j > k && j + k > i && i + k > j) return true; + return false; +} +int main() { + int tests; + cin >> tests; + for (int t = 0; t < tests; t++) { + int n; + cin >> n; + cout << n / 7 + min(1, n % 7) << "\n"; + } +} +int main() { + int n, x; + int flag; + int a[101], b[101]; + flag = 1; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + if (a[i] == x || a[i] == 7 - x) { flag = false; } + if (b[i] == x || b[i] == 7 - x) { flag = false; } + } + if (flag == true) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << endl; } + return 0; +} +const int N = 1e5; +const int INF = 1e9; +string a, b; +int lenA, lenB, arr[2 * N + 5]; +bool check(int x) { + int idx = 0; + string c = a; + for (int i = 0; i <= x; i++) c[arr[i] - 1] = '`'; + for (int i = 0; i < lenA && idx < lenB; i++) { + if (c[i] == b[idx]) idx++; + } + return idx == lenB; +} +int main() { + cin >> a; + lenA = a.length(); + cin >> b; + lenB = b.length(); + for (int i = 0; i < lenA; i++) cin >> arr[i]; + int lo = -1, hi = lenA - 1, mid, ans; + while (lo <= hi) { + mid = (lo + hi) / 2; + if (check(mid)) { + ans = mid; + lo = mid + 1; + } else + hi = mid - 1; + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + int ans = 0; + int ind = n; + while (ind < a.size()) { + if (a[ind - 1] == a[ind - 2]) + if (a[ind - 2] == a[ind - 3]) ans++; + ind += n; + } + cout << ans << endl; + return 0; +} +int main() { + int a1, a2, a3, b1, b2, b3, n, a, b, ans; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + a = a1 + a2 + a3; + b = b1 + b2 + b3; + if ((ceil(1.0 * a / 5) + ceil(1.0 * b / 10)) > n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + int count = d; + if (k == 1 || l == 1 || m == 1 || n == 1) + cout << count << endl; + else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) count--; + } + cout << count << endl; + } +} +int main() { + int n; + int a1, a2, a3; + int b1, b2, b3; + int numCup, numMedal; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + numCup = a1 + a2 + a3; + numMedal = b1 + b2 + b3; + if (ceil(numCup / 5.0) + ceil(numMedal / 10.0) > n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +long long n, d, a[1000], ans; +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n - 1; i++) { + if (a[i] < a[i + 1] - 2 * d) ans++; + if (a[i + 1] > a[i] + 2 * d) ans++; + if (a[i + 1] - a[i] == 2 * d) ans++; + } + cout << ans + 2 << endl; +} +int main() { + int a = 0, x = 0, y = 0, z = 0; + cin >> a; + int xsum = 0, ysum = 0, zsum = 0; + for (int i = 0; i < a; i++) { + cin >> x >> y >> z; + xsum = xsum + x; + ysum = ysum + y; + zsum = zsum + z; + } + if (xsum == 0 && ysum == 0 && zsum == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int amount, decrease, num[100005]; + cin >> amount >> decrease; + for (int i = 0; i < amount; i++) { cin >> num[i]; } + int mn = 1e9; + for (int i = 0; i < amount; i++) { + if (num[i] < mn) { mn = num[i]; } + } + long long sum = 0; + for (int i = 0; i < amount; i++) { + if ((num[i] - mn) % decrease != 0) { + cout << "-1" << endl; + return 0; + } + sum += (num[i] - mn) / decrease; + } + cout << sum << endl; + return 0; +} +const int N = 2000 + 10; +int p[N]; +vector V[N]; +int dfs(int u) { + int dep, i; + dep = 1; + for (i = 0; i < V[u].size(); i++) dep = max(dep, 1 + dfs(V[u][i])); + return dep; +} +int main() { + int res, n, i; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> p[i]; + if (p[i] != -1) V[p[i]].push_back(i); + } + res = 0; + for (i = 1; i <= n; i++) + if (p[i] == -1) res = max(res, dfs(i)); + cout << res << endl; + return 0; +} +int a, m; +int main() { + cin >> a >> m; + for (int i = 0; i < 25; i++) { + a = a + a % m; + if (a % m == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + int n; + int day = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int s, q; + cin >> s >> q; + if (i == 0) { + day = s; + } else { + if (day == s) { + day += q; + } else if (s < day) { + while (s < day) { s += q; } + if (s != day) + day = s; + else + day = s + q; + } else { + day = s; + } + } + } + cout << day << endl; + return 0; +} +int main() { + int x1, y1, x2, y2, x, y; + cin >> x1 >> y1 >> x2 >> y2 >> x >> y; + if ((x1 - x2) % x == 0 and (y1 - y2) % y == 0) { + int cx = (x1 - x2) / x, cy = (y1 - y2) / y; + if (abs(cx % 2) == abs(cy % 2)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (k > 2) + k -= 2; + else if (k == 1) { + cout << i + 1 << " " << j + 1 << " L" << endl; + return 0; + } else { + cout << i + 1 << " " << j + 1 << " R" << endl; + return 0; + } + } + } + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + int l, r, d; + cin >> l >> r >> d; + if (l > d) { + cout << d; + } else { + int t = r / d; + cout << d * (t + 1); + } + cout << "\n"; + } + return 0; +} +int N, A, sum, a, g, c, t; +string S; +int main() { + cin >> N >> S; + for (int i = 0; i < N; i++) { + if (S[i] == 'o' && S[i + 1] == 'g' && S[i + 2] == 'o') { + cout << "***"; + i += 3; + while (S[i] == 'g' && S[i + 1] == 'o') { i += 2; } + i--; + } else + cout << S[i]; + } + cout << '\n'; +} +int main() { + int n; + cin >> n; + bool flag = false; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a) flag = true; + } + if (flag) + cout << "HARD" << endl; + else + cout << "EASY" << endl; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int x, y; + cin >> x >> y; + if ((x1 - x2) % x == 0 && (y1 - y2) % y == 0) { + int xx = abs(x1 - x2) / x; + int yy = abs(y1 - y2) / y; + if (xx % 2 == 1 && yy % 2 == 1) + cout << "YES" << endl; + else if (!((xx & 1) ^ (yy & 1))) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else + cout << "NO" << endl; + return 0; +} +long long a[10001], b, d, sum, i, n, resh, ans1, ans2, ans3, ans4, j, k; +string s, s1; +char c[10001]; +int main() { + cin >> n >> k; + if (n < k or (k == 1 and n > 1)) return cout << -1 << "\n", 0; + if (n == 1) return cout << "a\n", 0; + for (int i = 0; i < (n - (k - 2)) / 2; ++i) cout << "ab"; + if ((n - (k - 2)) % 2) cout << "a"; + for (int i = 0; i < k - 2; ++i) cout << char(i + 'c'); + cout << "\n"; + return 0; +} +int main() { + string s; + long long i, abc[123], ans = 0; + getline(cin, s); + long long tam = s.size(); + for (i = 0; i <= 122; i++) { abc[i] = 0; } + for (i = 1; i < tam - 1; i++) { + long long n = s[i]; + i++; + i++; + abc[n] = 1; + } + for (i = 97; i <= 122; i++) { ans += abc[i]; } + cout << ans << endl; + return 0; +} +int n, k = 1, sum, a[1010], now; +int main() { + cin >> n; + while (k <= n + 1 && sum < n) { + now = (now + k - 1) % n; + if (a[now] == 0) sum++; + a[now] = 1; + k++; + } + if (sum == n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string str1, str2; +int vis[200010], a[200010]; +bool check(int m) { + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < m; i++) { vis[a[i] - 1] = 1; } + int j = 0; + for (int i = 0; i < str1.length(); i++) { + if (!vis[i] && str2[j] == str1[i]) j++; + } + if (j == str2.length()) return true; + return false; +} +int main() { + cin >> str1 >> str2; + for (int i = 0; i < str1.length(); i++) cin >> a[i]; + int l = -1, r = str1.length(); + while (l <= r) { + int mid = (l + r) >> 1; + if (check(mid)) + l = mid + 1; + else + r = mid - 1; + } + cout << r << endl; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +int n, a[N], p[N], ans = 361; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + p[i + 1] += p[i] + a[i]; + } + for (int i = 0; i < n; i++) { + for (int j = i + 1; j <= n; j++) { + int x = p[j] - p[i]; + ans = min(ans, abs(x - (360 - x))); + } + } + cout << ans << endl; +} +int main() { + long long x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + x2 = abs(x2 - x1); + y2 = abs(y2 - y1); + long long ans = min(x2, y2); + ans += abs(x2 - y2); + cout << ans << endl; + return 0; +} +const int maxn = 100000 + 5; +int a[30]; +int main() { + int n, m; + char s; + memset(a, 0, sizeof(a)); + while (cin >> s) { + if (s == '}') break; + if (s >= 'a' && s <= 'z') a[s - 'a']++; + } + int ans = 0; + for (int i = 0; i < 30; i++) { + if (a[i]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, minD = 360; + int a[722] = {}; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i], a[i + n] = a[i]; + for (int l = 0; l < n; l++) { + int sum = 0; + for (int r = l; r < (n << 1); r++) minD = min(minD, abs(180 - sum)), sum += a[r]; + } + cout << (minD << 1) << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long int l, r; + cin >> l >> r; + if (l == 1) + cout << l << " " << r << endl; + else { + cout << l << " "; + long int mod = (r % l); + cout << (r - mod) << endl; + } + } + return 0; +} +long long a, x, n, s; +vector v; +int main() { + s == 0; + n == 0; + cin >> a; + for (int i = 1; i <= a; i++) { + cin >> x; + v.push_back(x); + n += x; + } + if (n % 2 == 0) { + cout << n << endl; + return 0; + } + sort(v.begin(), v.end()); + while (n % 2 != 0) { + int l = v[s] % 10; + if (l % 2 != 0) { n = n - v[s]; } + s++; + } + cout << n << endl; +} +const int MAXN = 105; +const int INF = 0x3f3f3f3f; +int a[MAXN]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) cin >> a[i]; + a[n + 1] = INF; + int p = 2; + while (a[p] > a[p - 1]) p++; + while (a[p] == a[p - 1]) p++; + while (a[p] < a[p - 1]) p++; + if (p <= n) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +bool vis[30]; +int main() { + memset(vis, false, sizeof(vis)); + string a; + getline(cin, a); + for (int i = 0; i < a.size(); i++) { + if ('a' <= a[i] && a[i] <= 'z') vis[a[i] - 96] = true; + } + int cnt = 0; + for (int i = 1; i <= 26; i++) { + if (vis[i]) cnt++; + } + cout << cnt << endl; +} +bool mark[30]; +int main() { + int cnt = 0; + char op; + memset(mark, false, sizeof(mark)); + while (cin >> op) { + if (op == '{' || op == '}' || op == ',') continue; + if (!mark[op - 'a']) { + mark[op - 'a'] = true; + cnt++; + } + } + cout << cnt << endl; +} +int main() { + string s; + cin >> s; + int l = 0, r = s.size() - 1; + string q; + bool re = false; + if (s.size() % 2 == 0) { + q.push_back(s[r]); + r--; + } else { + q.push_back(s[l]); + l++; + re = true; + } + while (r >= l) { + if (re) { + q.push_back(s[r]); + r--; + re = false; + } else { + q.push_back(s[l]); + l++; + re = true; + } + } + reverse(q.begin(), q.end()); + cout << q << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int t = (k + 1) / 2; + int r = (t + m - 1) / m; + int d = (t - 1) % m + 1; + char s = (k & 1) ? 'L' : 'R'; + cout << r << ' ' << d << ' ' << s << endl; + return 0; +} +int a[2005]; +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int i, j, n, cnt = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == 1) cnt++; + } + if (cnt) { + cout << n - cnt << endl; + return 0; + } + int res = -1, flag = 0; + for (i = 1; i < n; i++) { + for (j = 1; j < n; j++) { + int tmp = gcd(a[j], a[j + 1]); + a[j] = tmp; + if (tmp == 1) { + flag = 1; + res = i; + break; + } + } + if (flag) break; + } + if (res == -1) + cout << -1 << endl; + else + cout << n + res - 1 << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double pi = acos(-1.0); +const double eps = 1e-15; +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int cnt = 1, read = v0; + if (v0 >= c) { + cout << cnt << endl; + return 0; + } else + while (true) { + v0 = min(v0 + a, v1); + read += v0 - l; + cnt++; + if (read >= c) break; + } + cout << cnt << endl; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +int gcd(int stone, int a) { + int d; + if (stone < a) { + while (stone != 0) { + d = stone; + stone = a % stone; + a = d; + } + return a; + } else { + while (a != 0) { + d = a; + a = stone % a; + stone = d; + } + return stone; + } +} +int main() { + int a, b, c, i = 1, pick = 1; + cin >> a >> b >> c; + pick = gcd(a, c); + c = c - pick; + while (c >= 0) { + i++; + if (i % 2 == 0) { + pick = gcd(b, c); + c = c - pick; + } else { + pick = gcd(a, c); + c = c - pick; + } + } + if (i % 2 != 0) + cout << "1" << endl; + else + cout << "0" << endl; +} +int main() { + long long n; + cin >> n; + long long ganjil = 999999999; + long long total = 0; + for (long long i = 1; i <= n; i++) { + long long m; + cin >> m; + total += m; + if (m % 2 == 1 && m <= ganjil) { ganjil = m; } + } + if (total % 2 == 1) { + cout << total - ganjil << endl; + } else { + cout << total << endl; + } +} +void fast() {} +void file() {} +int gcd(long long a, long long b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + fast(); + file(); + int n, x, a, b; + cin >> n >> x; + bool t = 1; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a == x || b == x || a == 7 - x || b == 7 - x) t = 0; + } + if (t) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int pos = n - 1; + for (int i = 0; i < n - 1; ++i) { + if (s[i] > s[i + 1]) { + pos = i; + break; + } + } + cout << s.substr(0, pos) + s.substr(pos + 1) << endl; +} +int main() { + int n, i, a, b, c, d, e, plus, minus; + int max = -1, score = 0; + char name[25]; + char maxName[25]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> name >> plus >> minus >> a >> b >> c >> d >> e; + score = plus * 100 - minus * 50 + a + b + c + d + e; + if (score > max || i == 0) { + max = score; + strcpy(maxName, name); + } + } + cout << maxName << endl; +} +int a; +char b[10005], c[20] = "aeiouy", x, d[10005]; +int f(char x) { + for (int i = 0; i < 6; i++) { + if (x == c[i]) return false; + } + return true; +} +int main() { + cin >> a; + cin >> b; + int i = 0, s = 0, e = 0; + while (i <= a) { + if (f(b[i])) { + d[e] = b[i]; + e++; + i++; + s = 0; + continue; + } + if (f(b[i]) == false && s == 0) { + d[e] = b[i]; + e++; + i++; + s++; + } else { + i++; + s++; + } + } + cout << d << endl; + return 0; +} +int main() { + pair a[101]; + int n; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } + for (int i = 0; i < n; i++) { + if (a[i].second == "rat") v.push_back(a[i].first); + } + for (int i = 0; i < n; i++) { + if (a[i].second == "woman" || a[i].second == "child") v.push_back(a[i].first); + } + for (int i = 0; i < n; i++) { + if (a[i].second == "man") v.push_back(a[i].first); + } + for (int i = 0; i < n; i++) { + if (a[i].second == "captain") v.push_back(a[i].first); + } + for (int i = 0; i < n; i++) { cout << v[i] << endl; } + return 0; +} +int main() { + set myset; + string s; + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 97 && s[i] <= 122) { myset.insert(s[i]); } + } + cout << myset.size() << endl; +} +int n, m; +int main() { + cin >> n >> m; + int l = 1, r = n; + for (int i = 0; i < m; i++) { + string a, b, c, d; + int x; + cin >> a >> b >> c >> d >> x; + if (c == "left") + r = min(r, x - 1); + else if (c == "right") + l = max(l, x + 1); + } + if (r - l < 0) + cout << "-1\n"; + else + cout << r - l + 1 << endl; +} +int main() { + int r, c; + cin >> r >> c; + char m[r][c]; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { cin >> m[i][j]; } + } + int cont = 0, cont2 = 0, aux1 = 0, aux2 = 0; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (m[i][j] == '.') aux1++; + } + if (aux1 == c) cont++; + aux1 = 0; + } + for (int i = 0; i < c; i++) { + for (int j = 0; j < r; j++) { + if (m[j][i] == '.') aux2++; + } + if (aux2 == r) cont2++; + aux2 = 0; + } + cout << cont * c + cont2 * r - cont * cont2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + int i = 0, j = 0; + int cnt = 0; + for (int l = 0; l < n; l++) { + i = 0; + j = 0; + for (int m = l; m < n; m++) { + if (str[m] == 'U') + i++; + else if (str[m] == 'D') + i--; + else if (str[m] == 'R') + j++; + else + j--; + if (i == 0 && j == 0) cnt++; + } + } + cout << cnt << "\n"; + return 0; +} +int main() { + int n; + while (cin >> n) { + string ch; + cin >> ch; + long long res = 0; + for (int i = 0; i < n - 1; i++) { + if (ch[i] == 'U' && ch[i + 1] == 'R') { + res++; + i++; + } else if (ch[i] == 'R' && ch[i + 1] == 'U') { + res++; + i++; + } + } + cout << n - res << endl; + } + return 0; +} +int a[200]; +int main() { + int n, m, i, k, j, l, p; + cin >> n >> m >> k; + a[0] = a[n + 1] = 1000; + l = p = 0; + for (i = 1; i <= n; i++) cin >> a[i]; + for (i = m, j = m; i != 0 || j != n + 1;) { + if (i >= 1) { + i--; + if (a[i] != 0 && a[i] <= k && a[i] != 1000) l = i; + } + if (j <= n) { + j++; + if (a[j] != 0 && a[j] <= k && a[j] != 1000) p = j; + } + if (l != 0 || p != 0) + if (a[l] <= a[p]) { + cout << (m - l) * 10 << endl; + return 0; + } else { + cout << (p - m) * 10 << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int t = 0; + long long a[200000], b[100000]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 != 0) { + b[t] = a[i]; + t++; + } + } + for (int i = 0; i < t - 1; i++) { + if (b[i] < b[i + 1]) swap(b[i], b[i + 1]); + } + long long sum; + sum = 0; + for (int i = 0; i < n; i++) { sum += a[i]; } + if (sum % 2 != 0) sum -= b[t - 1]; + cout << sum << endl; + } +} +int main() { + int n; + cin >> n; + int cnt = 0; + while (n) { + if (n % 2 == 1) cnt++; + n /= 2; + } + cout << cnt << "\n"; +} +int main() { + int r, c; + cin >> r >> c; + int rows[11] = {0}; + int col[11] = {0}; + string s; + for (int i = 0; i < r; i++) { + cin >> s; + for (int j = 0; j < c; j++) { + if (s[j] == 'S') { + rows[i] = 1; + col[j] = 1; + } + } + } + int count = 0; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (rows[i] == 0 || col[j] == 0) { count++; } + } + } + cout << count << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = towupper(s[0]); + cout << s << endl; + return 0; +} +int main() { + int a, b, t; + cin >> a >> b; + t = b; + while (t--) { + if ((a + a % b) % b == 0) { + cout << "Yes\n"; + return 0; + } else + a = (a + a % b) % b; + } + cout << "No\n"; + return 0; +} +const int inf = (int)1e9; +const int mod = inf + 7; +const double eps = 1e-9; +const double pi = acos(-1.0); +int r, g, b; +int main() { + cin >> r >> g >> b; + int ans = 30; + for (int i = 1; i < 100000; ++i) { + if (i % 3 == 1) { + ans++; + r -= 2; + } + if (i % 3 == 2) { + ans++; + g -= 2; + } + if (i % 3 == 0) { + ans++; + b -= 2; + } + if (r <= 0 && g <= 0 && b <= 0) return cout << ans - 1 << endl, 0; + } +} +int main() { + int y, b, r; + cin >> y >> b >> r; + if (y >= r) y = r - 2; + if (r - y == 1) y--; + if (y >= b) y = b - 1; + cout << y + (y + 1) + (y + 2) << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + string ar; + int dp[n]; + for (int i = 0; i < n; i++) dp[i] = INT_MAX; + cin >> ar; + ar[0] = '1'; + dp[0] = 0; + for (int i = 1; i < n; i++) { + if (ar[i] == '1') + for (int j = i - 1, count = 1; count <= d && j >= 0; j--, count++) { + if (ar[j] == '1' && dp[j] != INT_MAX) { dp[i] = min(dp[j] + 1, dp[i]); } + } + } + if (dp[n - 1] != INT_MAX) + cout << dp[n - 1]; + else + cout << "-1"; + cout << endl; +} +int num[4]; +int main() { + set s; + for (int i = 0; i < 4; i++) { + cin >> num[i]; + s.insert(num[i]); + } + cout << 4 - s.size() << endl; +} +const int maxn = 1e3 + 5; +int main() { + int n, m; + string str[5]; + cin >> n >> m; + int id; + int right = n, left = 1; + for (int i = 1; i <= m; i++) { + cin >> str[0] >> str[1] >> str[2] >> str[3] >> id; + if (str[2] == "left") + right = min(id - 1, right); + else + left = max(id + 1, left); + } + int ans = right - left + 1; + if (ans > 0) + cout << ans << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int c1 = 0, c2 = 0; + int c = 0; + int a = 0, b = 0; + for (int i = 0; i < n; i++) { + c1 = 0, c2 = 0; + a = 0, b = 0; + for (int j = i; j < n; j++) { + if (s[j] == 'R') { + a++; + } else if (s[j] == 'U') { + b++; + } else if (s[j] == 'D') { + b--; + } else if (s[j] == 'L') { + a--; + } + if (a == 0 && b == 0) { c++; } + } + } + cout << c << endl; + return 0; +} +int main() { + bool flag = false; + int m, n; + int arr[10], arr2[10]; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int i = 0; i < m; i++) cin >> arr2[i]; + int min = 100000; + for (int i = 0; i < n; i++) { + for (int g = 0; g < m; g++) { + if (arr[i] == arr2[g] && arr[i] < min) { + min = arr[i]; + flag = true; + } + } + } + if (flag) { + cout << min << endl; + return 0; + } else { + min = arr[0]; + for (int i = 0; i < n; i++) { + if (min > arr[i]) min = arr[i]; + } + int min2 = arr2[0]; + for (int i = 0; i < m; i++) { + if (min2 > arr2[i]) min2 = arr2[i]; + } + if (min < min2) { + cout << min << min2 << endl; + } else if (min > min2) { + cout << min2 << min << endl; + } + } + return 0; +} +int n; +int a[200000 + 10], b[200000 + 10]; +int visit[200000 + 10]; +int main() { + while (cin >> n) { + int flag, temp; + int ans = 200000 + 10; + memset(visit, 0, sizeof visit); + for (int i = 0; i < n; i++) { cin >> a[i]; } + a[n] = 0; + for (int i = 0; i < n; i++) { cin >> b[i]; } + int j = 0; + ans = 0; + for (int i = 0; i < n; i++) { + if (a[j] != b[i]) continue; + j++; + ans++; + } + cout << n - ans << endl; + } + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + vector v; + for (int i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + v.push_back(i); + if (i != sqrt(n)) v.push_back(n / i); + } + } + sort(v.begin(), v.end()); + if (k > v.size()) + cout << "-1" << endl; + else + cout << v[k - 1] << endl; + return 0; +} +void dfs(); +void visit(int); +vector p(2001, 0); +vector v; +int n; +int coun; +int large = 0; +int main() { + cin >> n; + v.push_back(-1); + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + v.push_back(x); + } + dfs(); + cout << large << endl; + return 0; +} +void dfs() { + for (int i = 1; i <= n; i++) { + if (p[i] == 0) { + coun = 1; + fill(p.begin(), p.begin() + n + 1, 0); + visit(i); + if (large < coun) large = coun; + } + } +} +void visit(int i) { + p[i] = 1; + if (v[i] != -1 && p[v[i]] == 0) { + coun++; + visit(v[i]); + } +} +int main() { + int t, a, b, h = 0, p = 0; + cin >> t; + while (t--) { + cin >> a >> b; + if (a != b) p++; + } + if (p != 0) + cout << "Happy Alex" << endl; + else + cout << "Poor Alex" << endl; + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int fd = abs(x - y); + int cd = abs(x - z); + int stt, lift_t; + stt = fd * t1; + int nw; + nw = fd + cd; + lift_t = (nw * t2) + (3 * t3); + int mn; + if (lift_t <= stt) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int x, y, cnt = 0; + cin >> x >> y; + int p = x * 100 + 10 * y; + while (p >= 220) { + if (x > 1 && y >= 2) { + x -= 2; + y -= 2; + cnt++; + } else if (x == 1 && y >= 12) { + x--; + y -= 12; + cnt++; + } else if (y >= 22) { + y -= 22; + cnt++; + } else + p = 200; + p -= 220; + if (p >= 220) { + if (y >= 22) { + y -= 22; + cnt++; + } else if (y >= 12 && x) { + y -= 12; + x--; + cnt++; + } else if (y >= 2 && x >= 2) { + y -= 2; + x -= 2; + cnt++; + } else + p = 200; + p -= 220; + } + } + if (cnt % 2) + cout << "Ciel" << endl; + else + cout << "Hanako" << endl; +} +int main() { + int r, c; + cin >> r >> c; + int clr = 0; + for (int i = 0; i < r; i++) + for (int j = 0; j < c; j++) { + char x; + cin >> x; + if (x == 'C' || x == 'Y' || x == 'M') clr++; + } + if (clr == 0) + cout << "#Black&White" << endl; + else + cout << "#Color" << endl; +} +long long const mod = 1000000007; +long long const md = 998244353; +long long mypow(long long a, long long b) { + long long res = 1; + a %= mod; + assert(b >= 0); + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +ifstream in("puteri6.in"); +ofstream out("puteri6.out"); +int st[105], dr[105]; +vector v[105]; +bool vis[105]; +void dfs(long long x) { + vis[x] = 1; + int u = v[x].size(); + for (int i = 0; i < u; ++i) { + if (!vis[v[x][i]]) dfs(v[x][i]); + } +} +int main() { + cout << fixed << setprecision(12); + long long n; + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> st[i] >> dr[i]; } + for (int i = 1; i <= n; ++i) { + for (int j = i + 1; j <= n; ++j) { + if (st[i] == st[j] || dr[j] == dr[i]) { + v[i].push_back(j); + v[j].push_back(i); + } + } + } + long long cnt = -1; + for (int i = 1; i <= n; ++i) { + if (!vis[i]) { + ++cnt; + dfs(i); + } + } + cout << cnt << '\n'; + return 0; +} +int main() { + int n, f; + int sum = 0, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> f; + sum += f; + } + for (int i = 1; i <= 5; i++) + if ((sum + i) % (n + 1) != 1) ans += 1; + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int p[n], count = 0, gcd = 0; + for (int i = 0; i < n; i++) { + cin >> p[i]; + if (p[i] == 1) count++; + gcd = __gcd(gcd, p[i]); + } + if (count) + cout << n - count << endl; + else if (gcd != 1) + cout << -1 << endl; + else { + int minmum = INT_MAX; + for (int i = 0; i < n; i++) { + int gcd = 0; + for (int j = i; j < n; j++) { + gcd = __gcd(gcd, __gcd(p[j], p[i])); + if (gcd == 1) minmum = min(minmum, j - i); + } + } + cout << minmum + n - 1 << endl; + } + return 0; +} +int main() { + long h, t; + long rAmount; + bool ciel = true; + cin >> h >> t; + h *= 100; + t *= 10; + rAmount = h + t; + while (true) { + if (ciel) { + if (h >= 200 && t >= 20) { + h -= 200; + t -= 20; + } else if (h >= 100 && t >= 120) { + h -= 100; + t -= 120; + } else if (t >= 220) { + t -= 220; + } else { + cout << "Hanako" << endl; + return 0; + } + ciel = false; + } else { + if (t >= 220) + t -= 220; + else if (h >= 100 && t >= 120) { + h -= 100; + t -= 120; + } else if (h >= 200 && t >= 20) { + h -= 200; + t -= 20; + } else { + cout << "Ciel" << endl; + return 0; + } + ciel = true; + } + } +} +int n, x, tot, pr = 1; +int main() { + cin >> n >> x; + for (int i = 0; i < n; i++) { + int l, r; + cin >> l >> r; + pr += (l - pr) / x * x; + tot += r - pr + 1; + pr = r + 1; + } + cout << tot << endl; +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + long long nd = (4 - n % 4) % 4; + long long mn[3]; + mn[0] = min(a, min(b + c, 3 * c)); + mn[1] = min(a + a, min(b, c + c)); + mn[2] = min(c, min(a + a + a, a + b)); + cout << (nd ? mn[nd - 1] : 0) << endl; +} +int main() { + int z, a = 0, s = 0, d = 0, f = 0; + string x, c, q[10000], w[10000], e[10000], r[10000]; + cin >> z; + for (int i = 0; i < z; i++) { + cin >> x >> c; + if (c == "rat") { + q[a] = x; + a++; + } + if (c == "woman" || c == "child") { + w[s] = x; + s++; + } + if (c == "man") { + e[d] = x; + d++; + } + if (c == "captain") { + r[f] = x; + f++; + } + } + for (int i = 0; i < a; i++) { cout << q[i] << endl; } + for (int i = 0; i < s; i++) { cout << w[i] << endl; } + for (int i = 0; i < d; i++) { cout << e[i] << endl; } + for (int i = 0; i < f; i++) { cout << r[i] << endl; } + return 0; +} +int main() { + int x, y, z, t1, t2, t3; + cin >> x >> y >> z >> t1 >> t2 >> t3; + int walk_time = abs(x - y) * t1; + int lift_time = abs(x - z) * t2 + abs(x - y) * t2; + lift_time += (t3 * 3); + if (lift_time <= walk_time) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int r, c; + cin >> r >> c; + char arr[11][11]; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) cin >> arr[i][j]; + } + int R = 0; + for (int i = 0; i < r; i++) { + int num = 0; + for (int j = 0; j < c; j++) { + if (arr[i][j] == '.') num++; + } + if (num == c) { + R += num; + for (int j = 0; j < c; j++) { arr[i][j] = '@'; } + } + } + for (int i = 0; i < c; i++) { + bool x = false; + int num = 0; + for (int j = 0; j < r; j++) { + if (arr[j][i] == 'S') { + x = true; + break; + } else if (arr[j][i] == '.') { + num++; + } + } + if (!x) { R += num; } + } + cout << R << endl; + return 0; +} +int a[100005], b[100005]; +int ans = 0; +void dfs(int x, int h) { + b[x] = 1; + if (a[x] == -1) { + if (h > ans) ans = h; + return; + } + return dfs(a[x], h + 1); +} +int main() { + int n; + while (cin >> n) { + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) + if (!b[i]) dfs(i, 1); + cout << ans << endl; + } + return 0; +} +int main() { + int n, i = 0, j; + string s; + cin >> n >> s; + while (i < n) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + cout << "***"; + i += 3; + for (j = i;;) { + if (s[j] == 'g' && s[j + 1] == 'o') { + j += 2; + i += 2; + continue; + } else { + break; + } + } + } else { + cout << s[i]; + i++; + } + } + cout << endl; +} +int main() { + int a[200001], b, n, f = 0, t = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + cin >> b; + if (b == a[t]) { + t++; + f++; + } + } + cout << n - t << endl; +} +void prn(int pos) { + cout << pos << "\n"; +} +int main() { + long long n, k; + cin >> n >> k; + long long sz = n; + int pos = 1; + long long ai; + cin >> ai; + long long sum = 0; + for (int i = 2; i <= sz; ++i) { + ++pos; + cin >> ai; + long long d = sum - (n - pos) * (pos - 1) * ai; + if (d < k) { + prn(i); + --pos; + --n; + } else { + sum += ai * (pos - 1); + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1" << endl; + return 0; + } + if (n == 2) { + cout << "3" << endl; + return 0; + } + if (n == 3) { + cout << "5" << endl; + return 0; + } + if (n % 4 == 0) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 1) { + n /= 4; + for (int i = 1; i <= 1000000; i++) { + n -= i; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 2) { + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + if (n % 4 == 3) { + n--; + for (int i = 1; i <= 1000000; i++) { + n -= i * 4; + if (n <= 0) { + cout << i * 2 + 1 << endl; + return 0; + } + } + } + return 0; +} +int a[100500]; +int main() { + int n, x; + cin >> n >> x; + int j = 1; + int ans = 0; + for (int i = 0; i < n; ++i) { + int l, r; + cin >> l >> r; + while (j + x <= l) { j += x; } + ans += r - j + 1; + j = r + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n, a = 0, d = 0; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { + a++; + } else { + d++; + } + } + if (a > d) { + cout << "Anton" << endl; + } else if (a < d) { + cout << "Danik" << endl; + } else + cout << "Friendship" << endl; +} +int x, y, z, a, b, c; +int main() { + cin >> x >> y >> z >> a >> b >> c; + int r = abs(x - y) * a; + int s = abs(x - z) * b + 3 * c + abs(x - y) * b; + if (r < s) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + int n; + string str; + cin >> n >> str; + for (int i = 0; i < n; i++) { + if (str[i] > str[i + 1]) { + str.erase(i, 1); + break; + } + } + cout << str << endl; + return 0; +} +int main() { + int row = 0, col = 0; + int r, c; + cin >> r >> c; + for (int i = 0, k = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + char a; + cin >> a; + if (a == '*') { + row ^= i; + col ^= j; + } + } + } + cout << row + 1 << " " << col + 1 << endl; +} +int fa[2005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> fa[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + int tmp = 0; + for (int j = i; j <= n && j != -1; j = fa[j]) { tmp++; } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +long long x[100005]; +long long y[100005]; +int main() { + long long MAX = 0; + cin >> x[0]; + cin >> y[0]; + for (int i = 1;; i++) { + x[i] = x[i - 1] * 3; + y[i] = y[i - 1] * 2; + if (x[i] > y[i]) { + MAX = i; + break; + } + } + cout << MAX << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int step = 1; + while (true) { + if (step == 1) { + int remaining = 220; + if (x >= 2) { + remaining = 20; + x -= 2; + } else if (x == 1) { + remaining = 120; + x--; + } + int two = remaining / 10; + if (two > y) { + cout << "Hanako" << endl; + break; + } else { + y -= two; + } + step = 2; + } else { + int remaining = 220; + if (y >= 22) { + remaining = 0; + y -= 22; + step = 1; + continue; + } else if (y >= 12 && x >= 1) { + y -= 12; + x--; + step = 1; + continue; + } else if (y >= 2 && x >= 2) { + y -= 2; + x -= 2; + step = 1; + continue; + } else { + cout << "Ciel" << endl; + break; + } + step = 1; + } + } +} +long long int dp[502][502]; +long long int n, m, mod, b; +long long int a[502]; +inline void solve() { + cin >> n >> m >> b >> mod; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + dp[0][0] = 1; + long long int ans = 0; + for (long long int i = 0; i < n; i++) { + for (long long int j = 1; j < m + 1; j++) { + for (long long int k = 0; k < b + 1; k++) { + if (k - a[i] >= 0) { + dp[j][k] = (dp[j][k] + dp[j - 1][k - a[i]]) % mod; + dp[j][k] %= mod; + } + } + } + } + for (long long int k = 1; k < b + 1; k++) { + dp[m][k] = dp[m][k] + dp[m][k - 1]; + dp[m][k] %= mod; + } + cout << dp[m][b] << '\n'; +} +int main() { + int tests = 1; + while (tests--) { solve(); } +} +int pan(int x, int y) { + if (x == 0) return y < 2; + if (y == 0) return x < 3; + if (x == y) return 1; + if (x < y) { + if (y - x <= 1) return 1; + return 0; + } else { + if (x / (y + 1) <= 2) { + if (x / (y + 1) == 1) return 1; + if (x / (y + 1) == 2) { + if (x % (y + 1) < 1) return 1; + return 0; + } + } + return 0; + } +} +int main() { + int a, b, x, y; + cin >> a >> b >> x >> y; + if (pan(x, b) || pan(y, a)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char a[1000000]; +char b[53] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; +int main() { + gets(a); + for (int i = 0; i < 26; i++) { + if (a[0] == b[i]) { + a[0] = b[i + 26]; + break; + } + } + puts(a); + return 0; +} +int n; +vector p[2001]; +int vis[2001] = {0}; +int maxi = 0; +void dfs(int k, int cnts) { + vis[k] = 1; + bool leaf = true; + int temp = p[k].size(); + for (int i = 0; i < temp; i++) { + if (!vis[p[k][i]]) { + dfs(p[k][i], cnts + 1); + leaf = false; + } + } + if (maxi < cnts) maxi = cnts; +} +int main() { + cin >> n; + int temp; + for (int i = 1; i <= n; i++) { + cin >> temp; + if (temp != -1) { + p[i].push_back(temp); + p[temp].push_back(i); + } else { + p[i].push_back(0); + p[0].push_back(i); + } + } + dfs(0, 0); + cout << maxi << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + while (m % 2 == 0) { m /= 2; } + if (n % m == 0) + puts("Yes"); + else + puts("No"); + } + return 0; +} +int absu(int q) { + if (q > 0) + return q; + else + return -q; +} +int main() { + int x, y, z, t1, t2, t3, a, b; + cin >> x >> y >> z >> t1 >> t2 >> t3; + a = absu(x - y) * t1; + b = absu(x - z) * t2 + absu(x - y) * t2 + 3 * t3; + if (a < b) { + cout << "NO" << endl; + } else + cout << "YES" << endl; +} +int fastMax(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; +} +int fastMin(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; +} +void solve() { + long long int n; + cin >> n; + long long int a[n]; + long long int cnt = 0; + for (int i = (0); i <= (n - 1); ++i) { + cin >> a[i]; + if (a[i] == 1) cnt++; + } + if (cnt > 0) { + cout << n - cnt << endl; + return; + } + long long int seg = 1e17; + for (long long int l = 0; l < n; l++) { + long long int x = a[l]; + for (long long int r = l; r < n; r++) { + x = __gcd(x, a[r]); + if (x == 1) { + seg = min(seg, r - l); + break; + } + } + } + clog << seg << endl; + if (seg >= 1e6) { + cout << -1 << endl; + return; + } + cout << seg + n - 1 << endl; +} +int main() { + long long int t; + t = 1; + while (t--) { solve(); } +} +string s; +int r[1001]; +int c[1001]; +int main() { + cin >> s; + int n = s.length(); + bool slot_0 = false; + bool slot_1 = false; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { + if (!slot_0) { + cout << "1 1\n"; + slot_0 = true; + } else { + cout << "3 1\n"; + slot_0 = false; + } + } else { + if (!slot_1) { + cout << "4 3\n"; + slot_1 = true; + } else { + cout << "4 1\n"; + slot_1 = false; + } + } + } +} +const int MAXN = 510; +int a[MAXN]; +long long dp[MAXN][MAXN]; +int main() { + int n, m, b, mod; + cin >> n >> m >> b >> mod; + dp[0][0] = 1; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + for (int k = a[i]; k <= b; k++) { + dp[j][k] += dp[j - 1][k - a[i]]; + dp[j][k] %= mod; + } + } + } + int ans = 0; + for (int i = 0; i <= b; i++) { + ans += dp[m][i]; + ans %= mod; + } + cout << ans << endl; +} +int main() { + vector a; + int count = 0; + for (int i = 0; i < 4; i++) { + long t; + cin >> t; + if (find(a.begin(), a.end(), t) - a.begin() != i) { count++; } + a.push_back(t); + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + int s[n]; + for (int i = 0; i < n; i++) { cin >> s[i]; } + int count1 = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 1) count1++; + } + if (count1 != 0) + cout << "HARD" << endl; + else + cout << "EASY" << endl; + return 0; +} +int main() { + int n, it = 1; + string s; + cin >> n >> s; + for (int i = 0; i < n; i += it) { + it++; + cout << s[i]; + } + cout << endl; +} +const int MAXN = 1e5 + 1; +const int MOD = 1e9 + 7; +const int INF = 1e9 + 7; +long long a[MAXN], b[MAXN]; +vector g[MAXN], v; +bool used[MAXN]; +int main() { + long long n, m, k, cnt = 0, ans = 0; + bool y = 0; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) { cout << 1 << " " << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << endl; } + return 0; +} +int main() { + int n, x, l[60], r[60]; + cin >> n >> x; + int t = 1; + for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; + int ans = 0; + for (int i = 1; i <= n;) { + if (t + x > l[i]) { + ans += r[i] - t + 1; + t = r[i] + 1; + i++; + } else + t += x; + } + cout << ans << endl; + return 0; +} +long long int cal(long long int n) { + long long int s = 0; + while (n > 0) { + int r = n % 10; + if (r == 0) { + } else { + s = s * 10 + r; + } + n = n / 10; + } + long long int s1 = 0; + while (s > 0) { + int r = s % 10; + s1 = s1 * 10 + r; + s = s / 10; + } + return s1; +} +int main() { + long long int a, b; + cin >> a >> b; + long long int c = a + b; + long long int p = cal(a); + long long int q = cal(b); + long long int r = cal(c); + if (r == (p + q)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1; + cin >> x2 >> y2; + int i = 0; + while (x1 != x2 && y1 != y2) { + int mini = min(abs(y2 - y1), abs(x2 - x1)); + i = i + mini; + if (y1 < y2) { + y1 = y1 + mini; + } else { + y1 = y1 - mini; + } + if (x1 < x2) { + x1 = x1 + mini; + } else { + x1 = x1 - mini; + } + } + cout << i + abs(x2 - x1) + abs(y2 - y1) << endl; +} +int main() { + int m, n, i, j, count = 0, r = 0, c = 0; + string s; + cin >> m >> n; + int row[m + 10] = {0}, col[n + 10] = {0}; + for (i = 0; i < m; i++) { + cin >> s; + for (j = 0; j < n; j++) { + if (s[j] == 'S') { + row[i] = 1; + col[j] = 1; + } + } + } + for (i = 0; i < m; i++) { + if (row[i] == 0) r++; + } + for (i = 0; i < n; i++) { + if (col[i] == 0) c++; + } + count = (r * n) + (m * c) - (max(r, c) * min(r, c)); + cout << count << endl; + return 0; +} +const int M6 = 1e6 + 5, M5 = 1e5 + 5; +long long gcd(long long first, long long second) { + return !second ? first : gcd(second, first % second); +} +long long lcm(long long first, long long second) { + return (first / gcd(first, second)) * second; +} +int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; +int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; +int main() { + long long n, mx = INT_MAX, idx = 0, s = 0, a; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + for (int i = 0; i < n; i++) { + s = 0; + for (int k = 0; k < v[i]; k++) { + cin >> a; + s += (a * 5) + 15; + } + if (s < mx) { mx = s; } + } + cout << mx << '\n'; +} +int MOD(int a, int b) { + if (a > b) + return a - b; + else + return b - a; +} +long long int max3(long long int a, long long int b, long long int c) { + return max(c, max(a, b)); +} +long long int power(long long int x, long long int y, long long int p) { + long long int res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int gcd(long long int a, long long int b) { + if (b == 1) + return 1; + else if (a % b == 0) + return b; + else + return gcd(b, a % b); +} +vector adji[5001]; +vector adjo[5001]; +int main() { + int n, m; + cin >> n >> m; + int i, j, k; + for (i = 0; i != n; i++) { + long long int s, f, t; + cin >> s >> f >> t; + long long int a, b, c; + a = b = c = 10000000000; + int ch = -1; + if (s == f) { + cout << t << "\n"; + continue; + } + if (t <= s - 1) { + t = s - 1; + if (f > s) { + t += f - s; + } else { + t += 2 * (m - s) + s - f; + } + cout << t << '\n'; + continue; + } else { + if (f > s) { + long long int k1 = ceil((double)(t - s + 1) / (2 * m - 2)); + t = (2 * m - 2) * k1 + s - 1; + t += f - s; + } else { + long long int k2 = max(0, ceil((double)(t + s + 1 - 2 * m) / (2 * m - 2))); + t = k2 * (2 * m - 2) + 2 * m - s - 1; + t += s - f; + } + cout << t << "\n"; + } + } + return 0; +} +long long darVuelta(long long x) { + long long xx = 0, dig1 = 0; + while (x != 0) { + long long dig1 = x % 10; + xx = xx * 10 + dig1; + x /= 10; + } + return xx; +} +long long quitarZeros(long long x) { + long long xx = 0, dig1 = 0; + while (x != 0) { + long long dig1 = x % 10; + if (dig1 != 0) xx = xx * 10 + dig1; + x /= 10; + } + return xx; +} +int main() { + long long x, y; + cin >> x >> y; + long long c = x + y; + long long xx = darVuelta(x), yy = darVuelta(y), cc = darVuelta(c); + if (quitarZeros(xx) + quitarZeros(yy) == quitarZeros(cc)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, n1[100], n2[100], sum[100]; + cin >> n; + for (int i = 0; i < 100; i++) sum[i] = 0; + for (int i = 0; i < n; i++) cin >> n1[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n1[i]; j++) { + cin >> n2[j]; + n2[j] *= 5; + n2[j] += 15; + sum[i] += n2[j]; + } + } + int x = sum[0]; + for (int i = 0; i < n; i++) { + if (sum[i] < x) x = sum[i]; + } + cout << x << endl; + return 0; +} +pair p[102]; +int main() { + int n, m; + cin >> n >> m; + int dif = 2 * m - 2; + for (int a, b, c, i = 0; i < n; i++) { + cin >> a >> b >> c; + if (a < b && a != b) { + int t = c - a + 1; + if (t % dif == 0 || t <= 0) { + cout << a - 1 + (t / dif) * dif + abs(a - b) << endl; + } else + cout << a - 1 + (t / dif + 1) * dif + abs(a - b) << endl; + } else if (a > b) { + int t = c - (dif - a + 1); + if (t % dif == 0 || t <= 0) { + cout << dif - a + 1 + (t / dif) * dif + abs(a - b) << endl; + } else + cout << dif - a + 1 + (t / dif + 1) * dif + abs(a - b) << endl; + } else + cout << c << endl; + } +} +int main() { + int a, b, c, x, y; + cin >> a >> b >> c; + int ax = 0, found = 0; + while (ax <= c) { + if ((c - ax) % b == 0) found = 1; + ax += a; + } + if (found) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int main() { + int n, m; + cin >> n >> m; + cout << m + n - 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (a < 1 || b < 2 || c < 4) + cout << "0" << endl; + else { + int k; + for (k = 2; k <= 1000; k++) + if (k > a || 2 * k > b || 4 * k > c) break; + cout << (k - 1) * 7 << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + cout << 0 << endl; + return 0; + } + if (n % 2 == 0) + cout << n + 1 << endl; + else + cout << (n + 1) / 2 << endl; + return 0; +} +int main() { + long long a1, a2, a3; + long long b1, b2, b3; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + long long n; + cin >> n; + long long a = a1 + a2 + a3; + long long b = b1 + b2 + b3; + n -= a / 5; + if (a % 5) n--; + n -= b / 10; + if (b % 10) n--; + if (n >= 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a[101], i, j, n; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + if (a[n - 1] == 1) + cout << "HARD" << endl; + else + cout << "EASY" << endl; + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + n1 > n2 ? cout << "First\n" : cout << "Second\n"; + return 0; +} +const int inf = 1e9 + 7; +const int N = 1e6 + 5; +string s; +int dp[N]; +int main() { + int n, d; + cin >> n >> d >> s; + for (int i = 1; i < n; i++) { dp[i] = inf; } + for (int i = 0; i < n; i++) { + if (s[i] == '1') + for (int j = 1; j <= d; j++) { + if (i - j >= 0 && s[i - j] == '1') dp[i] = min(dp[i], dp[i - j] + 1); + } + } + if (dp[n - 1] == inf) dp[n - 1] = -1; + cout << dp[n - 1] << endl; + return 0; +} +int main() { + string s; + int n; + cin >> n; + cin >> s; + int sumA = 0, sumD = 0; + for (int i = 0; i < n; ++i) { + if (s[i] == 'A') + ++sumA; + else + ++sumD; + } + if (sumA > sumD) + cout << "Anton" << endl; + else if (sumD > sumA) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; +} +int maxn = 2005; +int p[2001]; +void init() { + for (int i = 0; i < maxn; i++) { p[i] = i; } +} +int find(int x) { + int r = x; + int sum = 0; + while (r != p[r]) { + r = p[r]; + sum++; + } + return sum; +} +int main() { + int n; + while (cin >> n) { + set s; + init(); + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (x != -1) { p[i] = x; } + } + int sum = 0; + for (int i = 1; i <= n; i++) { sum = max(sum, find(i)); } + cout << sum + 1 << endl; + } + return 0; +} +int i, j, k = 0, m, n, a[10], b[10]; +bool x[10], y[10]; +int main() { + cin >> n >> m; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < m; i++) cin >> b[i]; + sort(a, a + n); + sort(b, b + m); + for (i = 0; i < n; i++) x[a[i]] = true; + for (i = 0; i < m; i++) y[b[i]] = true; + for (i = 1; i < 10; i++) + if (x[i] == true && y[i] == true) { + cout << i << endl; + return 0; + } + cout << min(a[0], b[0]) << max(a[0], b[0]) << endl; + return 0; +} +int main() { + int n, count = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + if (s == "X++" || s == "++X") { ++count; } + if (s == "--X" || s == "X--") { --count; } + } + cout << count << endl; +} +int main() { + long n, k; + int one = 0; + cin >> n; + vector v(n); + cin >> v[0]; + k = v[0]; + if (v[0] == 1) one++; + for (long i = 1; i < n; i++) { + cin >> v[i]; + k = __gcd(k, v[i]); + if (v[i] == 1) one++; + } + if (k != 1) return cout << "-1\n", 0; + if (one > 0) return cout << n - one << "\n", 0; + long ans = INT_MAX; + for (long l = 0; l < n; l++) { + long g = v[l]; + for (long r = l + 1; r < n; r++) { + g = __gcd(g, v[r]); + if (g == 1) { ans = min(n + r - l - 1, ans); } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int r, c, row[11] = {0}, col[11] = {0}; + string s; + cin >> r >> c; + for (int i = 0; i < r; ++i) { + cin >> s; + for (int j = 0; j < c; ++j) { + if (s[j] == 'S') { + row[i] = 1; + col[j] = 1; + } + } + } + int cakes(0); + for (int i = 0; i < r; ++i) { + for (int j = 0; j < c; ++j) { + if (row[i] == 0 || col[j] == 0) { cakes += 1; } + } + } + cout << cakes << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (2 * a > b) { + if (b * 7 < c * 4) { + cout << (b / 2) * 7 << endl; + } else { + cout << (c / 4) * 7 << endl; + } + } else { + if (4 * a > c) { + cout << (c / 4) * 7 << endl; + } else { + cout << a * 7 << endl; + } + } +} +int main() { + int n, k[100]; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { cin >> k[i]; } + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < k[i]; j++) { + int m; + cin >> m; + sum += m * 5; + } + sum += 15 * k[i]; + v.push_back(sum); + } + sort(v.begin(), v.end()); + cout << v[0] << endl; + return 0; +} +int s[1001]; +int d[1001]; +int n; +int main() { + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> s[i] >> d[i]; } + int min = s[1]; + for (int i = 2; i <= n; i++) { + int Next = s[i]; + while (min >= Next) Next += d[i]; + min = Next; + } + cout << min << endl; + } + return 0; +} +int getAns(int a, int b, int c) { + int x[6]; + x[0] = a + (b * c); + x[1] = (a * b) + c; + x[2] = (a + b) * c; + x[3] = a * (b + c); + x[4] = a * b * c; + x[5] = a + b + c; + int i = 6; + int ans = x[0]; + while (i--) { + if (ans < x[i]) ans = x[i]; + } + return ans; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << getAns(a, b, c) << "\n"; +} +int n, k; +int main() { + cin >> n >> k; + if (n * (n - 1) / 2 <= k) { + cout << "no solution\n"; + } else + for (; n--;) cout << "0 " << n << "\n"; +} +int main() { + string s; + getline(cin, s); + int hash[26], count = 0; + memset(hash, 0, sizeof(hash)); + for (int i = 0; i < s.length(); i++) { + if (s[i] == '{' || s[i] == '}' || s[i] == ' ' || s[i] == ',') { + continue; + } else { + hash[s[i] - 'a'] = 1; + } + } + for (int i = 0; i < 26; i++) { + if (hash[i] == 1) { count++; } + } + cout << count << endl; + return 0; +} +int a, b; +int main() { + int x1, y1, x2, y2; + int x, y; + int flag1, flag2; + while (cin >> x1) { + flag1 = flag2 = 0; + cin >> y1 >> x2 >> y2 >> a >> b; + x = x2 - x1; + y = y2 - y1; + if (x % a == 0) flag1 = 1; + if (y % b == 0) flag2 = 1; + if (flag1 && flag2 && (x / a - y / b) % 2 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const int inf = 0x3f3f3f3f; +const int MAXN = 10005; +const int mod = 19260817; +const int INF = 0x7fffffff; +long long ans[101]; +int main() { + int n, x; + cin >> n; + for (int i = 1; i <= n; i++) cin >> ans[i]; + long long sum = 0; + for (int i = 1; i <= n; i++) sum += ans[i] * i - i + 1; + cout << sum << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + --m; + for (int i = 0; i < n; ++i) { + int s, f, t; + cin >> s >> f >> t; + int q; + if (f == s) + q = t; + else if (f > s) { + q = t / (2 * m) * 2 * m; + t %= 2 * m; + if (t > s - 1) { q += 2 * m; } + q += f - 1; + } else { + q = t / (2 * m) * 2 * m; + q += m; + t %= 2 * m; + t -= m; + if (t > m + 1 - s) { q += 2 * m; } + q += m + 1 - f; + } + cout << q << endl; + } + return 0; +} +int n, tmpa, tmpb, ans; +int main() { + int x; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x == 1) + tmpa++; + else + tmpb++; + } + ans += min(tmpa, tmpb); + if (tmpa <= tmpb) + cout << ans << endl; + else + cout << ans + (tmpa - tmpb) / 3 << endl; + return 0; +} +int main() { + int k, l, m, n, i, j, q = 0; + long int d; + cin >> k; + cin >> l; + cin >> m; + cin >> n; + cin >> d; + int d1[d]; + for (int i = 1; i <= d; i++) { d1[i - 1] = i; } + for (i = 1; i <= d; i++) { + if (d1[i - 1] % k == 0) { d1[i - 1] = 0; } + } + for (i = 1; i <= d; i++) { + if (d1[i - 1] % l == 0) { d1[i - 1] = 0; } + } + for (i = 1; i <= d; i++) { + if (d1[i - 1] % m == 0) { d1[i - 1] = 0; } + } + for (i = 1; i <= d; i++) { + if (d1[i - 1] % n == 0) { d1[i - 1] = 0; } + } + for (i = 0; i < d; i++) { + if (d1[i] == 0) q++; + } + cout << q << endl; +} +int main() { + int n; + long long k; + while (cin >> n >> k) { + long long minn = 1e9 + 7; + long long ans = 0; + long long a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + minn = min(a[i], minn); + } + for (int i = 0; i < n; i++) + if ((a[i] - minn) % k == 0) + ans += (a[i] - minn) / k; + else { + ans = -1; + break; + } + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c; + while (cin >> b >> c) { + if (c > b) { + a = -1; + } else { + if (b % 2 == 0) { + a = b / 2; + } else { + a = (b / 2) + 1; + } + while (a % c != 0) { a++; } + } + cout << a << endl; + } + return 0; +} +const long long Mod = 7 + 1e9; +const long long INF32 = 5 + 2e9; +const long long INF64 = 5 + 1e18; +const long long MAX = 5 + 1e5; +string a; +int n, k, s[MAX], dp[MAX][30]; +map f; +int Try(int i, int pre) { + if (i == n) return 0; + int &r = dp[i][pre]; + if (r + 1) return r; + char cc = pre + 'a'; + r = Try(i + s[i], pre) + s[i]; + if (a[i] != f[cc]) r = min(r, Try(i + s[i], a[i] - 'a')); + return r; +} +int main() { + memset(dp, -1, sizeof(dp)); + cin >> a >> k; + n = a.size(); + while (k--) { + string t; + cin >> t; + f[t[0]] = t[1]; + f[t[1]] = t[0]; + } + s[n - 1] = 1; + for (int i = n - 2; i >= 0; i--) s[i] = (a[i] == a[i + 1] ? s[i + 1] + 1 : 1); + cout << Try(0, 27) << endl; + return 0; +} +const int MAXN = 1005; +int x[MAXN], y[MAXN], idx[MAXN]; +int n; +void init() { + memset(idx, 0, sizeof(idx)); + for (int i = 0; i <= n; i++) idx[i] = i; +} +int find(int a) { + if (a != idx[a]) return idx[a] = find(idx[a]); + return idx[a]; +} +void merge(int a, int b) { + int fa = find(a); + int fb = find(b); + if (fa != fb) idx[fa] = fb; +} +int main() { + while (cin >> n) { + int cnt = 0; + for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; + init(); + for (int i = 0; i < n - 1; i++) + for (int j = i + 1; j < n; j++) + if (x[i] == x[j] || y[i] == y[j]) merge(i, j); + for (int i = 0; i < n; i++) + if (idx[i] == i) cnt++; + cout << cnt - 1 << endl; + } + return 0; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) { return a; } + return gcd(b, a % b); +} +bool function_sort_down(int a, int b) { + return a > b; +} +long long int mas[5000000], number, ans, length, sum; +string str, rat[105], woman[210], man[105], captain[105], str2; +char maxe; +int main() { + cin >> number; + for (int i = 0; i < number; i++) { + cin >> str >> str2; + if (str2 == "rat") + rat[i] = str; + else if (str2 == "woman" || str2 == "child") + woman[i] = str; + else if (str2 == "man") + man[i] = str; + else + captain[i] = str; + } + for (int i = 0; i < number; i++) { + if (rat[i] != "") cout << rat[i] << endl; + } + for (int i = 0; i < number + number; i++) { + if (woman[i] != "") cout << woman[i] << endl; + } + for (int i = 0; i < number; i++) { + if (man[i] != "") cout << man[i] << endl; + } + for (int i = 0; i < number; i++) { + if (captain[i] != "") cout << captain[i] << endl; + } + return 0; +} +bool pal(string s) { + string res = s; + reverse(s.begin(), s.end()); + return res == s; +} +int main() { + string s; + cin >> s; + string n = ""; + for (int i = 0; i < s.size() - 1; i++) n += s[i]; + if (!pal(s)) + cout << s.size() << endl; + else if (!pal(n)) + cout << n.size() << endl; + else + cout << 0 << endl; + return 0; +} +long long a[20000]; +int main() { + int n1, n2, n3, n; + cin >> n1 >> n2 >> n3; + n1 /= 1; + n2 /= 2; + n3 /= 4; + n = min(n1, min(n2, n3)); + cout << n * 7 << endl; + return 0; +} +char ar[101][101]; +int main() { + int n, m, row, col, one; + int a = 0, b = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int c = 0; + for (int j = 1; j <= m; j++) { + cin >> ar[i][j]; + if (ar[i][j] == '*') c++; + } + if (c == 1) { + row = i; + for (int j = 1; j <= m; j++) { + if (ar[i][j] == '*') one = j; + } + } + if (c == 2) { + for (int j = 1; j <= m; j++) { + if (ar[i][j] == '*') { + if (a == 0) + a = j; + else if (b == 0) + b = j; + } + } + } + } + if (a == one) + col = b; + else + col = a; + cout << row << " " << col << endl; +} +int main() { + int n, t; + cin >> n >> t; + int ans = 0; + while (n <= t) { + n *= 3; + t *= 2; + ans++; + } + cout << ans << endl; +} +int dat[110]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> dat[i]; + int i = 0; + for (; i < n && (!i || dat[i] > dat[i - 1]); i++) + ; + if (i == n) { + cout << "YES\n"; + return 0; + } + for (; i < n && dat[i] == dat[i - 1]; i++) + ; + if (i == n) { + cout << "YES\n"; + return 0; + } + for (; i < n && dat[i] < dat[i - 1]; i++) + ; + cout << (i == n ? "YES\n" : "NO\n"); + return 0; +} +int f[501][501]; +int main() { + int n, m, b, mod; + cin >> n >> m >> b >> mod; + f[0][0] = 1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int j = 1; j <= m; j++) { + for (int k = x; k <= b; k++) { (f[j][k] += f[j - 1][k - x]) %= mod; } + } + } + int ans = 0; + for (int i = 0; i <= b; i++) { (ans += f[m][i]) %= mod; } + cout << ans << endl; + return 0; +} +int a[2]; +int main() { + int n, i = 0; + cin >> a[0] >> a[1] >> n; + while (n -= __gcd(a[i], n)) { i ^= 1; } + cout << i << endl; +} +int main() { + int i, k, l, m, n, d; + int count = 0; + cin >> k >> l >> m >> n >> d; + for (i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) count++; + } + cout << count << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << min(a, min(b / 2, c / 4)) * 7 << endl; + return 0; +} +int main() { + char a[100005]; + int n; + cin >> n; + getchar(); + gets(a); + sort(a, a + n); + puts(a); +} +int remove0(int n) { + int m(0), pow(1); + while (n != 0) { + int d = n % 10; + n /= 10; + if (d != 0) { + m += d * pow; + pow *= 10; + } + } + return m; +} +int main() { + int a, b; + cin >> a >> b; + int c = a + b; + int A = remove0(a); + int B = remove0(b); + int C = remove0(c); + cout << (A + B == C ? "YES" : "NO") << endl; + return 0; +} +int fpb(int x, int y) { + int z; + if (x == 0) return y; + if (y == 0) return x; + for (int i = 1; i <= min(x, y); i++) { + if (x % i == 0 && y % i == 0) z = i; + } + return z; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (n >= 0) { + n -= fpb(a, n); + if (n < 0) { + cout << 1 << endl; + return 0; + } + n -= fpb(b, n); + if (n < 0) { + cout << 0 << endl; + return 0; + } + } +} +int a[100005]; +int main() { + int n, c1 = 0, c2 = 0, maxx = 0, minn = 1000000007; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + maxx = max(maxx, a[i]), minn = min(minn, a[i]); + } + for (int i = 0; i < n; i++) { + if (a[i] == maxx) c1++; + if (a[i] == minn) c2++; + } + if (maxx == minn) + cout << 0 << endl; + else + cout << n - c1 - c2 << endl; + return 0; +} +void solve(); +int main() { + long long t; + t = 1; + while (t--) solve(); + return 0; +} +void solve() { + long long y, b, r; + cin >> y >> b >> r; + long long tt = min(y, min(b - 1, r - 2)); + cout << tt * 3 + 3 << '\n'; +} +int main() { + int c, v0, v, a, l; + cin >> c >> v0 >> v >> a >> l; + int ans = 0; + while (1) { + ans++; + c -= v0; + if (c <= 0) break; + v0 += a; + if (v0 > v) v0 = v; + c += l; + } + cout << ans << endl; + return 0; +} +int n, pre, state; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (state == 0) { + if (a > pre) { + state = 0; + } else if (a == pre) { + state = 1; + } else { + state = 2; + } + } else if (state == 1) { + if (a == pre) { + state = 1; + } else if (a < pre) { + state = 2; + } else { + cout << "NO" << endl; + return 0; + } + } else { + if (a >= pre) { + cout << "NO" << endl; + return 0; + } + } + pre = a; + } + cout << "YES" << endl; + return 0; +} +int main() { + int y, b, r; + while (cin >> y >> b >> r) { + for (int i = r; i >= 3; i--) { + if (b >= (i - 1) && y >= (i - 2)) { + cout << i + i - 1 + i - 2 << endl; + break; + } + } + } + return 0; +} +int main() { + int t, x, e, count = 0, check = 0, var; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> x; + if (x >= 2 && x <= 7) + cout << 1 << endl; + else { + e = x; + var = 7; + if (e - var <= 7) { + cout << 2 << endl; + } else { + e -= var; + count++; + while (e != 0) { + if (e - var > 7) { + e -= var; + count++; + } else if (e - var <= 7 && e - var >= 2) { + count += 2; + e = 0; + } else { + var--; + } + } + cout << count << endl; + } + count = 0; + } + } + return 0; +} +int main() { + int t, s = 0; + char x[10]; + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> x; + if (strcmp(x, "X++") == 0 || strcmp(x, "++X") == 0) + s += 1; + else if (strcmp(x, "X--") || strcmp(x, "--X")) + s -= 1; + s = s; + } + cout << s << endl; + return 0; +} +void READ(string INPUT = "NO", string OUTPUT = "NO") { + if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin); + if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout); +} +int A[200001]; +string a, b; +bool ok(int k) { + map mp; + for (int i = 0; i < k; i++) mp[A[i]] = 1; + int id = 0; + for (int i = 0; id < (int)b.size() && i < (int)a.size(); i++) { + if (mp[i]) continue; + if (a[i] == b[id]) id++; + } + return id >= (int)b.size(); +} +int main() { + cin >> a >> b; + for (int i = 0; i < (int)a.size(); i++) { + cin >> A[i]; + A[i]--; + } + int l = 0, r = (int)a.size(), m, ans; + while (l <= r) { + m = (l + r) >> 1; + if (ok(m)) { + ans = m; + l = m + 1; + } else + r = m - 1; + } + cout << ans << "\n"; + return 0; +} +map mp; +int main() { + int arr[4], result = 0; + for (int i = 0; i < 4; i++) { + cin >> arr[i]; + mp[arr[i]]++; + if (mp[arr[i]] > 1) result++; + } + cout << result << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << endl; +} +int main() { + long long int k, l, a = 0, flag = 0, div = 0; + cin >> k >> l; + while (l % k == 0) { + l /= k; + a += 1; + } + if (l == 1) { + cout << "YES" << endl; + cout << a - 1 << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int n; + cin >> n; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + int s1, s2; + s1 = 0; + s2 = 0; + for (i = 1; i <= n; i++) { + if (a[i] == 1) { + s1++; + } else { + s2++; + } + } + if (s1 > s2) { + cout << s2 + (s1 - s2) / 3 << endl; + } else { + cout << s1 << endl; + } + return 0; +} +long long MOD = 1e9 + 7; +long long Power(int x) { + long long res = 1; + while (x--) res = (res * 2) % MOD; + return res; +} +int main() { + string str; + int i, n, p; + long long res = 0; + cin >> str; + n = str.length(); + p = (n - 1) * 2; + for (i = 0; i < n; i++) { + res = (res + (Power(p) * (str[i] - '0'))) % MOD; + p--; + } + cout << res << endl; + return 0; +} +int main() { + int n, i, j, tmp, tmp2; + cin >> n >> tmp; + for (i = 1; i < n; i++) { + cin >> tmp2; + if (tmp == tmp2) { + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp > tmp2) { + tmp = tmp2; + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp <= tmp2) { + cout << "NO" << endl; + return 0; + } + tmp = tmp2; + } + } else if (tmp < tmp2) { + cout << "NO" << endl; + return 0; + } + } + } else if (tmp > tmp2) { + tmp = tmp2; + for (i = i + 1; i < n; i++) { + cin >> tmp2; + if (tmp <= tmp2) { + cout << "NO" << endl; + return 0; + } + tmp = tmp2; + } + } + tmp = tmp2; + } + cout << "YES" << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string second; + cin >> second; + sort((second).begin(), (second).end()); + cout << second << endl; + return 0; +} +int main() { + int n, a[1005], b[1005], ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= n; i++) { + ans++; + if (ans < a[i]) + ans = a[i]; + else { + while ((ans - a[i]) % b[i] != 0) ans++; + } + } + cout << ans << endl; +} +int main() { + int n; + while (cin >> n) { + int ans = 0, sum = 0; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + sum += tmp; + } + for (int i = 0; i < 5; i++) { + if ((sum + i + 1) % (n + 1) != 1) ans++; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n & 1) + cout << "Ehab" << endl; + else + cout << "Mahmoud" << endl; +} +int A[200]; +int main() { + int n, m; + ifstream ff("file.txt"); + cin >> n >> m; + if (m == 0) { + cout << n << endl; + return 0; + } + while (m--) { + string s1, s2, s3, s4; + int t; + cin >> s1 >> s2 >> s3 >> s4 >> t; + if (A[s3[0]] == 0) { + A[s3[0]] = t; + } else { + if (s3[0] == 'l') { + if (A[s3[0]] > t) { A[s3[0]] = t; } + } else { + if (A[s3[0]] < t) { A[s3[0]] = t; } + } + } + } + if (A['l'] == 0 || A['r'] == 0) { + if (A['l'] != 0) { + if (A['l'] != 1) { + cout << A['l'] - 1 << endl; + } else { + cout << -1 << endl; + } + } else { + if (n - A['r'] != 0) { + cout << n - A['r'] << endl; + } else { + cout << -1 << endl; + } + } + } else { + if (A['l'] <= A['r'] + 1) { + cout << -1 << endl; + } else { + cout << A['l'] - A['r'] - 1 << endl; + } + } + return 0; +} +int main() { + int n; + string en; + cin >> n; + cin >> en; + int i, j; + for (i = 0; i < n - 1; i++) { + if (en[i] > en[i + 1]) { + for (j = 0; j < i; j++) cout << en[j]; + for (j = i + 1; j < n; j++) cout << en[j]; + break; + } + } + if (i == n - 1) { + for (j = 0; j < i; j++) cout << en[j]; + } + cout << endl; + return 0; +} +int main() { + int x, y, i, n; + cin >> x >> y; + if (x % 2 == 0) { + i = x / 2; + } else { + i = x / 2 + 1; + } + while (i <= x) { + if (i % y == 0) { + cout << i << endl; + return 0; + } + i++; + } + cout << "-1" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v[n + 1]; + int i; + vector root; + for (i = 1; i <= n; i++) { + int x; + cin >> x; + if (x == -1) + root.push_back(i); + else { + v[x].push_back(i); + } + } + bool vis[n + 1]; + memset(vis, false, sizeof(vis)); + int max_depth[root.size()]; + for (i = 0; i < root.size(); i++) { max_depth[i] = 1; } + int level[n + 1]; + memset(level, -1, sizeof(level)); + queue q; + for (int j = 0; j < root.size(); j++) { + q.push(root[j]); + vis[root[j]] = true; + level[root[j]] = 1; + while (!q.empty()) { + int t = q.front(); + q.pop(); + for (i = 0; i < v[t].size(); i++) { + if (vis[v[t][i]] == false) { + vis[v[t][i]] = true; + level[v[t][i]] = level[t] + 1; + if (max_depth[j] < level[v[t][i]]) max_depth[j] = level[v[t][i]]; + q.push(v[t][i]); + } + } + } + } + int sum = 0; + for (i = 0; i < root.size(); i++) { + if (max_depth[i] > sum) sum = max_depth[i]; + } + cout << sum << endl; +} +int main() { + int n, cnt(0); + string s; + cin >> n >> s; + for (int i = 1; i < (int)s.size(); i++) + if (i % n == 0 && i >= 3 && s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) cnt++; + cout << cnt << endl; + return 0; +} +int main() { + long long n, k, i, num; + cin >> n >> k; + i = (n + 1) / 2; + if (k <= i) { + num = 2 * k - 1; + } else { + k = k - i; + num = 2 * k; + } + cout << num << endl; + return 0; +} +int n, x; +char a, b, c; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b >> c; + if (b == '+') x++; + if (b == '-') x--; + } + cout << x << endl; + return 0; +} +int main() { + int n, cnt1 = 0, cnt2 = 0; + cin >> n; + char c; + for (int i = 0; i < n; i++) { + cin >> c; + if (c == 'A') + cnt1++; + else + cnt2++; + } + if (cnt1 > cnt2) + cout << "Anton" << endl; + else if (cnt1 < cnt2) + cout << "Danik" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int f1(int, int, int); +int f2(int, int); +int f2(int a, int b) { + if (a * b > a + b) + return (a * b); + else + return (a + b); +} +int f1(int a, int b, int c) { + int max = 0; + int x, y, z, w; + x = f2(a, b) + c; + y = f2(a, b) * c; + z = a + f2(b, c); + w = a * f2(b, c); + if (x > y && x > z && x > w) + return x; + else if (y > z && y > w) + return y; + else if (z > w) + return z; + else + return w; +} +int main() { + int a, b, c, e, array[3], one = 0; + for (int i = 0; i < 3; i++) cin >> array[i]; + a = array[0]; + b = array[1]; + c = array[2]; + e = f1(a, b, c); + if (e > one) { one = e; } + cout << one << "\n"; + return 0; +} +const int N = 1007; +int d[N]; +int s[N]; +int main() { + int m, k; + cin >> m >> k; + for (int i = 1; i <= m; i++) cin >> d[i]; + for (int i = 1; i <= m; i++) cin >> s[i]; + long long timer = 0; + int bz = 0; + for (int i = 1; i <= m; i++) { + bz += s[i]; + int mxl = 0; + for (int j = 1; j <= i; j++) mxl = max(mxl, s[j]); + while (bz < d[i]) { + bz += mxl; + timer += k; + } + timer += d[i]; + bz -= d[i]; + } + cout << timer << endl; + return 0; +} +int l, b; +int main() { + cin >> l >> b; + for (int i = 1; i < 1234; i++) { + l *= 3; + b *= 2; + if (l > b) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a > b) + puts("First"); + else + puts("Second"); + return 0; +} +int main() { + int s1, s2, s3, s4; + cin >> s1 >> s2 >> s3 >> s4; + set s; + s.insert(s1); + s.insert(s2); + s.insert(s3); + s.insert(s4); + cout << 4 - s.size() << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i, x, y, t, up = 0, down = 0, ans, u_d, d_u, count = 0, sum = 0; + for (i = 1; i <= n; i++) { + cin >> x >> y >> t; + up = 0; + down = 0; + count = 0; + sum = 0; + u_d = 2 * (m - x); + d_u = 2 * (x - 1); + if (x == y) + cout << t << endl; + else { + if (t <= x - 1) { + if (y > x) { + cout << x - 1 + y - x << endl; + } else { + cout << x - 1 + x - y + u_d << endl; + } + } else { + t -= (x - 1); + up = 1; + sum += (x - 1); + while (t > 0) { + if (count % 2 == 0) { + t -= u_d; + down = 1; + up = 0; + sum += u_d; + } else { + t -= d_u; + down = 0; + up = 1; + sum += d_u; + } + count++; + } + if (y > x) { + if (up == 1) { + cout << sum + y - x << endl; + } else { + cout << sum + d_u + y - x << endl; + } + } else { + if (up == 1) { + cout << sum + x - y + u_d << endl; + } else { + cout << sum + x - y << endl; + } + } + } + } + } +} +int main() { + int n; + cin >> n; + if (n % 2 == 1) { + cout << "Ehab" << endl; + } else { + cout << "Mahmoud" << endl; + } + return 0; +} +int main() { + vector vec; + vector::iterator it; + int k, l, i; + cin >> k >> l; + for (i = 1;; i++) { + if (pow(k, i) > INT_MAX) break; + vec.push_back(pow(k, i)); + } + it = lower_bound(vec.begin(), vec.end(), l); + if (l == *it) { + puts("YES"); + int pos = it - vec.begin(); + cout << pos << endl; + } else + puts("NO"); + return 0; +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 <= n2) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } +} +int n, a[1010], b[1010], sum = 1; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + int j = 0; + while (sum != n + 1) { + j++; + if (j - a[sum] >= 0 && (j - a[sum]) % b[sum] == 0) sum++; + } + cout << j << endl; + return 0; +} +int x, kq; +void xu_ly() { + cin >> x; + kq = x / 7; + if (x % 7 != 0) { kq = kq + 1; }; + cout << kq << endl; +} +int main() { + int t; + cin >> t; + int i; + for (i = 1; i <= t; i = i + 1) { xu_ly(); }; +} +string s; +int main() { + while (cin >> s) { + int flagee = 1; + for (int i = 0, j = (int)s.length() - 1; i <= j; i++, j--) { + if (s[i] != s[j]) { + flagee = 0; + break; + } + } + if (!flagee) { + cout << s.length() << '\n'; + } else { + flagee = 1; + for (int i = 1; i < s.length(); i++) { + if (s[i] != s[0]) { + flagee = 0; + break; + } + } + if (flagee) { + cout << 0 << '\n'; + } else { + cout << s.length() - 1 << '\n'; + } + } + } + return 0; +} +int main() { + int cnt7, cnt4; + string a, b; + cin >> a; + cin >> b; + cnt7 = 0; + cnt4 = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] == '7' && b[i] == '4') cnt7++; + if (a[i] == '4' && b[i] == '7') cnt4++; + } + cout << max(cnt7, cnt4) << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + a++; + c--; + cout << min(min(a, c), b) * 3 << endl; + return 0; +} +int main() { + int c, v0, v1, a, l, d = 1, sum = 0; + cin >> c >> v0 >> v1 >> a >> l; + if (c <= v0) cout << d << endl; + if (c > v0) { + sum = v0; + for (int i = 1; v0 + (i * a) <= v1; i++) { + sum += v0 + (i * a) - l; + d++; + if (sum >= c) { + cout << d << endl; + return 0; + } + } + while (sum < c) { + sum += v1 - l; + d++; + } + cout << d << endl; + } + return 0; +} +const int maxn = 100010; +int pri[maxn]; +int main() { + int n, k; + while (cin >> n >> k) { + long long ans = 0; + int minn = 0x3f3f3f3f; + for (int i = 0; i < n; i++) { + cin >> pri[i]; + minn = min(minn, pri[i]); + } + for (int i = 0; i < n; i++) { + if ((pri[i] - minn) % k) { + ans = -1; + break; + } + ans += (pri[i] - minn) / k; + } + cout << ans << endl; + } + return 0; +} +bool start_run(string &s, int &j, string &p) { + bool f = false, sec = false; + int i; + for (i = j; i < s.size(); ++i) { + if (s[i] == p[0]) + f = true; + else if (s[i] == p[1]) + sec = true; + else + break; + } + if (f and sec) + return true; + else { + j = i; + return false; + } +} +int main() { + string s; + cin >> s; + int k; + cin >> k; + int ans = 0; + for (int i = 0; i < k; ++i) { + string p; + cin >> p; + for (int j = 0; j < s.size() - 1; ++j) { + if (start_run(s, j, p)) { + int a = 0, b = 0; + while (j < s.size()) { + if (s[j] == p[0]) + a++; + else if (s[j] == p[1]) + b++; + else + break; + j++; + } + ans += min(a, b); + } + } + } + cout << ans << '\n'; + return 0; +} +int main() { + int l, r, d, n, c; + cin >> n; + while (n--) { + cin >> l >> r >> d; + if (d < l || d > r) { + cout << d << endl; + continue; + } + cout << d * (int)(r / d) + d << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + cout << (n % 2 ? "Ehab" : "Mahmoud") << "\n"; + return 0; +} +int main() { + int n, sum = 0; + char a[101]; + cin >> n; + cin >> a; + for (int i = 0; i < n; i++) { + if ((a[i] == 'R' && a[i + 1] == 'U') || (a[i] == 'U' && a[i + 1] == 'R')) { + sum++; + i++; + } else { + sum++; + } + } + cout << sum << endl; +} +const double PI = acos(-1.0); +const double EPS = 1e-11; +const long long MOD = 1000000007; +const int N = 100000 + 7; +void fast() {} +int main() { + string s, s2; + cin >> s; + s += '*'; + int k; + cin >> k; + int ans = 0; + int sum1 = 0, sum2 = 0; + while (k--) { + sum1 = 0, sum2 = 0; + cin >> s2; + for (int i = 0; i < s.size(); i++) { + if (s[i] == s2[0] || s[i] == s2[1]) { + if (s[i] == s2[0]) sum1++; + if (s[i] == s2[1]) sum2++; + } else { + ans += min(sum1, sum2); + sum1 = sum2 = 0; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d, e; + cin >> a >> b >> c >> d >> e; + int s = a + b + c + d + e; + if (s % 5 != 0 || s == 0) + cout << "-1" << endl; + else + cout << s / 5 << endl; +} +int main() { + int t; + cin >> t; + cout << "+------------------------+" << endl; + cout << '|'; + int num = 1; + for (int i = 0; i < 11; i++) { + if (num <= t) { + cout << "O."; + if (i == 0) + num += 4; + else + num += 3; + } else { + cout << "#."; + if (i == 0) + num += 4; + else + num += 3; + } + } + cout << "|D|)" << endl; + cout << '|'; + num = 2; + for (int i = 0; i < 11; i++) { + if (num <= t) { + cout << "O."; + if (i == 0) + num += 4; + else + num += 3; + } else { + cout << "#."; + if (i == 0) + num += 4; + else + num += 3; + } + } + cout << "|.|" << endl; + cout << '|'; + if (t >= 3) + cout << 'O'; + else + cout << "#"; + cout << ".......................|" << endl; + cout << '|'; + num = 4; + for (int i = 0; i < 11; i++) { + if (num <= t) { + cout << "O."; + num += 3; + } else { + cout << "#."; + num += 3; + } + } + cout << "|.|)" << endl; + cout << "+------------------------+" << endl; + return 0; +} +long long m, a[200000]; +pair b[200000]; +long long cnt[200000]; +int main() { + cin >> m; + for (int i = 0; i < m; ++i) cin >> a[i]; + for (int i = 0; i < m; ++i) { + cin >> b[i].first; + b[i].second = i; + } + sort(a, a + m); + sort(b, b + m); + reverse(b, b + m); + for (int i = 0; i < m; ++i) { cnt[b[i].second] = a[i]; } + for (int i = 0; i < m; ++i) cout << cnt[i] << " \n"[i == m - 1]; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int b[m]; + for (int i = 0; i < m; i++) cin >> b[i]; + sort(a, a + n); + sort(b, b + m); + int done = 0; + if (a[0] == b[0]) + cout << a[0] << endl; + else { + for (int i = 0; i < n; i++) { + if (find(b, b + m, a[i]) != b + m) { + cout << a[i] << endl; + done = 1; + break; + } + } + if (!done) cout << min(a[0], b[0]) << max(a[0], b[0]) << endl; + } + return 0; +} +int main() { + int64_t a, b, c; + cin >> a >> b >> c; + cout << 3 * min(a + 1, min(b, c - 1)) << endl; + return 0; +} +char a[60], b[60]; +int main() { + int n; + while (cin >> n) { + memset(b, 0, sizeof(b)); + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int k = 0, d = 0; + for (int i = 1; i <= n; i = i + k) { + b[d] = a[i]; + d++; + k++; + } + cout << b << endl; + } +} +int main() { + long long int n; + cin >> n; + long long int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + long long int min_time = INT_MAX; + for (int i = 0; i < n; i++) { + long long int time = 0; + for (int j = 0; j < a[i]; j++) { + long long int x; + cin >> x; + time += x * 5 + 15; + } + if (time < min_time) min_time = time; + } + cout << min_time << endl; + return 0; +} +const int maxn = 100010; +int main() { + int n, m; + int s, f, t; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> s >> f >> t; + int st, up = 1; + st = t % ((m - 1) * 2) + 1; + if (st > m) { + st = m * 2 - st; + up = 0; + } + if (st == 0) st = 1; + if (f > s) { + if (up == 1 && st <= s) { + cout << t + f - st << endl; + } else if (up == 1 && st > s) { + cout << t + 2 * m - st + f - 2 << endl; + } else if (up == 0 && st <= s) { + cout << t + st + f - 2 << endl; + } else if (up == 0 && st > s) { + cout << t + st + f - 2 << endl; + } + } else if (f < s) { + if (up == 1 && st < s) { + cout << t + 2 * m - st - f << endl; + } else if (up == 1 && st >= s) { + cout << t + 2 * m - st - f << endl; + } else if (up == 0 && st < s) { + cout << t + 2 * m + st - f - 2 << endl; + } else if (up == 0 && st >= s) { + cout << t + st - f << endl; + } + } else { + cout << t << endl; + } + } + return 0; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + int res = max(abs(x1 - x2), abs(y1 - y2)); + cout << res << endl; + return 0; +} +bool isDanger(string plyrs) { + char playerState = plyrs[0]; + int plNumber = 1; + for (int i = 1; i < plyrs.length(); i++) { + char comparator = plyrs[i]; + if (comparator == playerState) + plNumber++; + else { + playerState = comparator; + plNumber = 1; + } + if (plNumber >= 7) return true; + } + return false; +} +int main() { + string Players; + cin >> Players; + if (isDanger(Players)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (k > n) { + cout << "-1" << endl; + } else if (n % 2 == 0) { + for (int i = n / 2; i <= n; ++i) { + if (i % k == 0) { + cout << i << endl; + break; + } + } + } else { + for (int i = (n + 1) / 2; i <= n; ++i) { + if (i % k == 0) { + cout << i << endl; + break; + } + } + } + return 0; +} +int main() { + int n; + cin >> n; + puts(n % 2 == 0 ? "Mahmoud" : "Ehab"); + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int at = 0; + int val = 0; + while (true) { + at += 1; + int tot = 0; + if (at == 1) { + val = v0; + } else { + if (v0 + (at - 1) * a > v1) + tot = v1 - l; + else + tot = v0 + (at - 1) * a - l; + } + val += tot; + if (val >= c) break; + } + cout << at << endl; +} +int main() { + long long n, mx = 0, x; + vector dp(100005), cnt(100005); + cin >> n; + for (long long i = 0; i < n; i++) cin >> x, cnt[x]++, mx = max(x, mx); + dp[0] = 0, dp[1] = cnt[1]; + for (long long i = 2; i <= 100000; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i); } + cout << dp[mx] << endl; +} +int main() { + int n, t = 0; + string sandali[6]; + sandali[0] = "+------------------------+"; + sandali[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + sandali[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + sandali[3] = "|#.......................|"; + sandali[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + sandali[5] = "+------------------------+"; + while (cin >> n) { + for (int i = 1; i < 23; i++) { + for (int j = 1; j < 5; j++) { + if (sandali[j][i] == '#' && n > 0) { + sandali[j][i] = 'O'; + n--; + } + } + } + while (t < 6) { + cout << sandali[t] << endl; + t++; + } + } + return 0; +} +string str(int n) { + stringstream ss; + ss << n; + string s; + ss >> s; + return s; +} +int sorte[1001]; +int tam = 0; +void lucky() { + for (int i = 0; i < 1001; i++) { + string s = str(i); + bool sorte2 = true; + for (int c = 0; c < s.length(); c++) { + if (s[c] != '4' && s[c] != '7') { + sorte2 = false; + break; + } + } + if (sorte2) { + sorte[tam] = i; + tam++; + } + } +} +int main() { + lucky(); + int n; + cin >> n; + int pos = 0; + bool divide = false; + while (sorte[pos] <= n && pos < tam) { + if (n % sorte[pos] == 0) { + divide = true; + break; + } + pos++; + } + if (divide) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +map mp; +int main() { + int n, result = 0; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) result++; + } + cout << result << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + long long len = s.size(); + long long coun = 0; + for (long long i = 0; i < len; i++) { + long long coun1 = 0, coun2 = 0; + for (long long j = i; j < len; j++) { + if (s[j] == 'U') + coun1++; + else if (s[j] == 'R') + coun2++; + else if (s[j] == 'D') + coun1--; + else if (s[j] == 'L') + coun2--; + if (coun1 == 0 && coun2 == 0) coun++; + } + } + cout << coun << endl; +} +int main() { + int n, d; + cin >> n >> d; + string s; + cin >> s; + int dp[110]; + for (int i = 0; i <= d; i++) { + if (s[i] == '1') + dp[i] = 1; + else + dp[i] = 10000; + } + for (int i = d + 1; i < n; i++) { + dp[i] = 10000; + if (s[i] == '1') { + for (int j = d; j >= 1; j--) { dp[i] = min(dp[i], dp[i - j] + 1); } + } + } + if (dp[n - 1] == 10000) + cout << -1 << endl; + else + cout << dp[n - 1] << endl; + return 0; +} +int main() { + int n, obj, sum, min = 1000000; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + sum = arr[i] * 15; + for (int j = 0; j < arr[i]; j++) { + cin >> obj; + sum += obj * 5; + } + if (min > sum) { min = sum; } + } + cout << min << "\n"; +} +int main() { + long long k, b, n, t; + cin >> k >> b >> n >> t; + long long cnt = 1; + while (cnt <= t) { + cnt = cnt * k + b; + n--; + } + cout << max(0LL, n + 1) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (!n ? 0 : n & 1 ? (n + 1) >> 1 : n + 1) << endl; + return 0; +} +int main() { + int x[2], y[2], m, n; + for (int i = 0; i < 2; i++) { + cin >> x[i]; + cin >> y[i]; + } + m = (int)abs(x[1] - x[0]); + n = (int)abs(y[1] - y[0]); + if (m < n) + cout << n << endl; + else + cout << m << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; ++i) { cout << "1 " << i << endl; } + for (int i = 2; i <= n; ++i) { cout << i << " 1" << endl; } +} +int main() { + int n, m; + string s = "#Black&White"; + cin >> n; + cin >> m; + char p[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> p[i][j]; + if (p[i][j] != 'W' && p[i][j] != 'B' && p[i][j] != 'G') { s = "#Color"; } + } + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int l, r, a; + cin >> l >> r >> a; + if (l > a) + cout << a << endl; + else + cout << ((r / a + 1) * a) << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = a * b + c; + ans = max(a + b * c, ans); + ans = max(a + b + c, ans); + ans = max(a * b * c, ans); + ans = max((a + b) * c, ans); + ans = max(a * (b + c), ans); + cout << ans << '\n'; +} +int main() { + long long n, k; + cin >> n >> k; + if (k <= ((n + 1) / 2)) + cout << ((k * 2) - 1) << endl; + else + cout << (k - (n + 1) / 2) * 2 << endl; + return 0; +} +int main() { + char str[55]; + stack s; + bool flag = false; + cin >> str; + int len = strlen(str), t = len / 2; + for (int i = 0; i < t; ++i) s.push(str[i]); + for (int i = len - t; i < len; ++i) { + if (str[i] != s.top()) { + flag = true; + break; + } else + s.pop(); + } + if (flag) + cout << len << endl; + else { + int lat = len - 1; + while (lat > 0 && str[0] == str[lat]) --lat; + if (lat != 0) + cout << len - 1 << endl; + else + cout << '0' << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int s = m + (n - 1); + cout << s << "\n"; + int i = 1; + while (i <= m) { + cout << "1" + << " " << i << "\n"; + i++; + } + i = 2; + while (i <= n) { + cout << i << " " + << "1" + << "\n"; + i++; + } +} +int main() { + int t; + cin >> t; + while (t--) { + int l, r, d; + cin >> l >> r >> d; + long long int ans; + if (d < l) + ans = d; + else { + ans = d * (r / d); + ans += d; + } + cout << ans << "\n"; + } + return 0; +} +int main() { + int n, num = 0, aux, res = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> aux; + num = num + aux; + } + n++; + for (int i = 1; i < 6; i++) { + if ((i + num) % n != 1) res++; + } + cout << res << endl; + return 0; +} +int main() { + int n, c = 0, d = 0; + cin >> n; + string a; + cin >> a; + for (int i = 0; i < n; i++) { + if (a[i] == 'D') c++; + if (a[i] == 'A') d++; + } + if (d == c) + cout << "Friendship" << endl; + else if (d > c) + cout << "Anton" << endl; + else + cout << "Danik" << endl; + return 0; +} +int main() { + int64_t ch; + map mp; + for (int i = 0; i < 4; i++) { + cin >> ch; + mp[ch] = true; + } + cout << 4 - mp.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a, a + n); + int no, nt; + no = upper_bound(a, a + n, 1) - lower_bound(a, a + n, 1); + nt = upper_bound(a, a + n, 2) - lower_bound(a, a + n, 2); + int ans = 0; + if (nt >= no) { + ans += no; + } else { + ans += nt; + no -= nt; + ans += (no / 3); + } + cout << ans << '\n'; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k = 0, l = 2; + long long n, m, t, a, b, c, d, x, y; + cin >> a >> b >> c >> d; + cin >> x >> y; + a = abs(a - c); + b = abs(b - d); + if (a % x == 0 && b % y == 0) { + a /= x; + b /= y; + if ((a % 2 && b % 2) || (a % 2 == 0 && b % 2 == 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +long long fp(long long n, long long p) { + if (p == 0) return 1; + if (p == 1) return n; + long long res; + res = fp(n, p / 2) % int(1e9 + 7); + res = (res * res) % int(1e9 + 7); + if (p % 2) res = (res * n) % int(1e9 + 7); + return res % int(1e9 + 7); +} +int get(int a, int b) { + while (b <= 2011) { + int dif = 0, t = b, tt = a; + while (a > 0 && dif < 2) { + if (a % 10 != b % 10) dif++; + a /= 10, b /= 10; + } + b = t, a = tt; + if (dif < 2) return b; + b++; + } + return 1e5; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a - 2 < d && d < 2 * a + 3 || b - 2 < c && c < 2 * b + 3) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + int k, q = 1; + char d; + string s = ""; + cin >> k >> d; + if (d - '0' == 0) { + if (k == 1) + cout << 0 << endl; + else + cout << "No solution" << endl; + } else { + s += d; + for (int i = 1; i < k; i++) s += "0"; + cout << s << endl; + } + return 0; +} +char a[20][20]; +bool row[20]; +bool line[20]; +int main() { + int r, c; + while (cin >> r >> c) { + for (int i = 0; i < 20; i++) { + row[i] = true; + line[i] = true; + } + for (int i = 1; i <= r; i++) { + for (int j = 1; j <= c; j++) { + cin >> a[i][j]; + if (a[i][j] == 'S') { + row[i] = false; + line[j] = false; + } + } + } + int ans = 0; + for (int i = 1; i <= r; i++) { + if (row[i]) { ans += c; } + } + int save = ans / c; + for (int i = 1; i <= c; i++) { + if (line[i]) { + int trans = r - save; + ans += trans; + } + } + cout << ans << endl; + } + return 0; +} +const int MAXN = 2e5; +int arr[MAXN + 5]; +int main() { + string t, p; + cin >> t >> p; + int st = t.size(); + int sp = p.size(); + int a, r = st, l = 0, cnt; + for (int i = 0; i < t.size(); i++) { + cin >> a; + arr[a - 1] = i; + } + while (r - 1 > l) { + int mid = (r + l) / 2; + cnt = 0; + for (int i = 0; i < st; i++) { + if (t[i] == p[cnt] and arr[i] >= mid) cnt++; + } + if (cnt == sp) { + l = mid; + } else + r = mid; + } + cout << l << endl; + return 0; +} +int main() { + int n, ans = 0; + string s; + cin >> n >> s; + for (int i = 3; i < s.size(); i++) + if (i % n == 0 && s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + double x, y; + double z; + double *arr = new double[n]; + for (int i = 0; i < n; i++) { + cin >> x >> y; + double q = x + (y / 100000); + arr[i] = q; + } + sort(arr, arr + n); + for (int i = 0; i < n - 1; i++) { + if (int(arr[i]) != int(arr[i + 1])) { + if (arr[i + 1] - arr[i] < 1) { + cout << "Happy Alex" << endl; + return 0; + } + } + } + cout << "Poor Alex" << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int ctr = 0; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == s[i + 1]) ctr++; + } + cout << ctr << endl; + return 0; +} +int main() { + int n; + cin >> n; + char a[60]; + cin >> a; + int j = 1; + for (int i = 0; i < n; i = i + j) { + cout << a[i]; + j++; + } + cout << endl; + return 0; +} +int main() { + int n, a, max, k, last; + cin >> n >> a >> max >> k >> last; + int cnt = 0, ans = 0; + while (true) { + cnt += a; + ans++; + if (cnt >= n) break; + cnt -= last; + a = min(max, a + k); + } + cout << ans << endl; + return 0; +} +int arr[105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int mn = INT_MAX; + for (int i = 0; i < n; i++) { + int wak = 0; + for (int j = 0; j < arr[i]; j++) { + int x; + cin >> x; + wak += (5 * x); + wak += 15; + } + mn = min(mn, wak); + } + cout << mn << endl; +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x % m * x % m) % m; + if (b % 2) x = (x % m * a % m) % m; + return x % m; +} +long long po(long long a, long long b) { + if (a == 1) return 1; + long long r = 1; + while (b--) r *= a; + return r; +} +int main() { + long long k, b, n, t, s = 0; + cin >> k >> b >> n >> t; + for (int i = 0; i <= n; i++) { + long long v = s + po(k, i); + if (v >= t) { + if (v > t) + cout << n - i + 1 << endl; + else + cout << n - i << endl; + return 0; + } + s += b * po(k, i); + } + puts("0"); +} +int n, maxn; +pair doc[1005]; +bool v[1000005]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> doc[i].first >> doc[i].second; } + int pre = 0; + for (int i = 0; i < n; i++) { + while (v[doc[i].first] || pre > doc[i].first) { doc[i].first += doc[i].second; } + v[doc[i].first] = true; + pre = doc[i].first; + maxn = max(maxn, doc[i].first); + } + cout << maxn << endl; +} +int main() { + int n, proof = 0; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +bool is_vocal(const char &i) { + return i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u' || i == 'y'; +} +int main() { + string in, out; + int n, es; + cin >> n; + cin >> in; + out = in[0]; + es = is_vocal(out[0]); + for (int i = 1; i < n; i++) { + if (es) { + if (!is_vocal(in[i])) { + out += in[i]; + es = 0; + } + } else { + out += in[i]; + es = is_vocal(in[i]); + } + } + cout << out << endl; + return 0; +} +int main() { + string s; + cin >> s; + int m[26]; + for (int i = 0; i < 26; i++) { m[i] = 0; } + for (int j = 0; j < s.length(); j++) { + int index = s[j] - 'a'; + m[index]++; + } + for (int i = 0; i < 26; i++) { + if (m[i] == s.length()) { + cout << "0" << endl; + return 0; + } + } + for (int j = 0; j < s.length() / 2; j++) { + if (s[j] != s[s.length() - j - 1]) { + cout << s.length() << endl; + return 0; + } + } + cout << s.length() - 1 << endl; +} +int MJ(string nums, int n, int d) { + int jumps[n]; + for (int i = 0; i < n; i++) { jumps[i] = INT_MAX; } + jumps[0] = 0; + int result[n]; + for (int i = 0; i < n; i++) { result[i] = -1; } + result[0] = 1; + cerr << result[2]; + for (int i = 1; i < n; i++) { + if (nums[i] == '1') { + for (int j = 0; j < i; j++) { + if (nums[j] == '1') { + if (j + d >= i) { + if (jumps[j] + 1 < jumps[i]) { + jumps[i] = jumps[j] + 1; + result[i] = 1; + } + } + } + } + if (result[i] != 1) return -1; + } + } + return jumps[n - 1]; +} +int main() { + int n; + cin >> n; + int d; + cin >> d; + string nums; + cin >> nums; + int minjumps = MJ(nums, n, d); + cout << minjumps << endl; + return 0; +} +int is[105]; +int main() { + int n, m, a, b; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a >> b; + for (int j = a; j <= b; j++) is[j] = 1; + } + vector ans; + for (int i = 1; i <= m; i++) + if (!is[i]) ans.push_back(i); + cout << ans.size() << "\n"; + for (int i = 0; i < ans.size(); i++) + if (i != ans.size() - 1) + cout << ans[i] << " "; + else + cout << ans[i] << "\n"; + return 0; +} +string a, b, sum1_str, sum2_str; +int string_int(string s, bool w) { + int x = 0; + for (int i = 0; i <= (int)s.length() - 1; i++) { + if (w == 1) { + x *= 10; + x += s[i] - '0'; + } else { + if (s[i] != '0') { + x *= 10; + x += s[i] - '0'; + } + } + } + return x; +} +string int_string(int n) { + string s; + while (n) { + int x = n % 10; + s += char(x + '0'); + n /= 10; + } + return s; +} +int main() { + int x1, x2, y1, y2, sum1, sum2; + cin >> a >> b; + x1 = string_int(a, 1); + y1 = string_int(b, 1); + sum1 = x1 + y1; + sum1_str = int_string(sum1); + reverse(sum1_str.begin(), sum1_str.end()); + x2 = string_int(a, 0); + y2 = string_int(b, 0); + sum2 = string_int(sum1_str, 0); + if (x2 + y2 == sum2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, m, a, b, v[2100][2100]; +int k, d[2100][2100], x, y; +bool solve(int x, int y, int k) { + int l = max(1, x - k), r = min(x + k, n), t; + for (int i = l; i <= r; i++) { + t = k - abs(i - x); + if (y - t > 0 && !v[i][y - t]) { + a = i; + b = y - t; + return 1; + } + if (y + t <= m && !v[i][y + t]) { + a = i; + b = y + t; + return 1; + } + } + return 0; +} +int main() { + cin >> n >> m >> k; + for (int i = 0; i < k; i++) { + cin >> x >> y; + for (int j = -2; j <= 2; j++) + for (int k = -2; k <= 2; k++) { + if (x + j < 1 || x + j > n || y + k < 1 || y + k > m) continue; + d[x][y] = max(d[x][y], d[x + j][y + k] - abs(j) - abs(k)); + } + while (!solve(x, y, d[x][y])) d[x][y]++; + v[a][b] = 1; + cout << a << " " << b << endl; + } +} +int main() { + int r, c, count = 0; + char str[11][11]; + char str1[11][11]; + int arr[11] = {0}; + int arr2[11] = {0}; + char ch; + cin >> r >> c; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> ch; + str[i][j] = ch; + if (ch != '.') { + arr[i] = 1; + arr2[j] = 1; + } + } + } + for (int i = 0; i < r; i++) { + if (arr[i] == 0) { + for (int j = 0; j < c; j++) { str[i][j] = '0'; } + count += c; + } + } + for (int i = 0; i < c; i++) { + if (arr2[i] == 0) { + for (int j = 0; j < r; j++) { + if (str[j][i] != '0') count++; + } + } + } + cout << count << endl; + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int day = 0; + int page = v0; + while (c > 0) { + if (day != 0) c += l; + c -= page; + page += a; + if (page > v1) page = v1; + day++; + } + cout << day << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + string a; + cin >> a; + int i, k = 0; + int h = a.length(); + for (i = 0; i < h;) { + if (i + 1 >= h) { + k = k + 1; + break; + } else { + if (a[i] == 'R' && a[i + 1] == 'R') + k = k + 1, i++; + else if (a[i] == 'R' && a[i + 1] == 'U') + k = k + 1, i = i + 2; + if (a[i] == 'U' && a[i + 1] == 'U') + k = k + 1, i++; + else if (a[i] == 'U' && a[i + 1] == 'R') + k = k + 1, i = i + 2; + } + } + cout << k << endl; + } + return 0; +} +int main() { + int n, x; + while (cin >> n >> x) { + int l[50], r[50]; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + r[i]++; + } + int sum = 0, current = 1; + for (int i = 0; i < n; i++) { + int tem = l[i] - current; + current += (tem / x) * x; + sum += r[i] - current; + current = r[i]; + } + cout << sum << endl; + } + return 0; +} +int main() { + int p; + cin >> p; + if (p % 2 == 1) + cout << "-1\n"; + else { + cout << "2 1"; + for (int i = 4; i <= p; i += 2) cout << " " << i << " " << i - 1; + cout << endl; + } + return 0; +} +int a[200001], n; +int main() { + int i, j, s1(0), s2(0); + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + if (a[i] == 1) { + s1++; + } else { + s2++; + } + } + if (s1 > s2) { + cout << s2 + (s1 - s2) / 3 << endl; + } else { + cout << s1 << endl; + } + return 0; +} +int max(int a, int b) { + if (a > b) + return a; + else + return b; +} +int A(int a, int b) { + if (a != 0 && b != 0) { + int c, d, e; + c = max(a, b); + d = a + b - c; + while (1) { + e = c % d; + if (e == 0) { + return d; + break; + } else { + c = d; + d = e; + } + } + } + return -1; +} +int main() { + int a, b, c, d, e; + while (cin >> a >> b >> c) { + for (;;) { + d = A(a, c); + c = c - d; + if (d < 0) cout << "1" << endl; + if (d < 0) break; + e = A(b, c); + c = c - e; + if (e < 0) cout << "0" << endl; + if (e < 0) break; + } + } +} +const int Max = 1e3 + 10; +int a[Max], ans[Max], flag[Max]; +int main() { + int n, tot = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = n; i >= 1; i--) { + if (!flag[a[i]]) { + flag[a[i]] = 1; + ans[tot++] = a[i]; + } + } + cout << tot << endl; + for (int i = tot - 1; i >= 0; i--) { + cout << ans[i]; + if (i != 0) cout << " "; + } + cout << endl; + return 0; +} +int main() { + char s[60]; + int n, ans = 0; + cin >> n; + cin >> s; + for (int i = 0; i < n; i += ans) { + ans += 1; + cout << s[i]; + } + cout << endl; + return 0; +} +long long pwr(long long base, long long p, long long mod = (1000000007LL)) { + long long ans = 1; + while (p) { + if (p & 1) ans = (ans * base) % mod; + base = (base * base) % mod; + p /= 2; + } + return ans; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long nCr(long long n, long long r) { + long long C[r + 1]; + memset(C, 0, sizeof(C)); + C[0] = 1; + for (long long i = 1; i <= n; i++) + for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1]; + return C[r]; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n == 2) return true; + if (n % 2 == 0) return false; + long long m = sqrt(n); + for (long long i = 3; i <= m; i += 2) + if (n % i == 0) return false; + return true; +} +long long M(long long a) { + return (a % (1000000007LL)); +} +bool isPowerOfTwo(long long x) { + return x && (!(x & (x - 1))); +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (long long i = 0; i < (long long)(m); ++i) { cout << 1 << " " << i + 1 << endl; } + for (long long i = 1; i <= (long long)(n); ++i) { + if (i == 1) continue; + cout << i << " " << 1 << endl; + } + return 0; +} +int main() { + long long int n, k, a = 0, b = 0, p, i; + cin >> n; + for (i = 0; i < n; i++) { + cin >> k; + if (k == 1) + a++; + else + b++; + } + p = min(a, b); + k = p; + a = a - p; + b = b - p; + k = k + a / 3; + cout << k << endl; +} +int main() { + char xx[8][30]; + int n; + while (cin >> n) { + char yy[30] = "+------------------------+"; + strcpy(xx[0], yy); + char zz[30] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + strcpy(xx[1], zz); + char k[30] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + strcpy(xx[2], k); + char kk[30] = "|#.......................|"; + strcpy(xx[3], kk); + char ss[30] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + strcpy(xx[4], ss); + char tt[30] = "+------------------------+"; + strcpy(xx[5], tt); + int a = 0; + for (int i = 0; i < 30; i++) { + for (int j = 0; j < 6; j++) { + if (xx[j][i] == '#') { + xx[j][i] = 'O'; + a++; + } + if (a == n) break; + } + if (a == n) break; + } + for (int i = 0; i < 6; i++) { cout << xx[i] << endl; } + } + return 0; +} +int main() { + int a, b, c; + int arr[5]; + cin >> a >> b >> c; + arr[0] = a + b * c; + arr[1] = a * (b + c); + arr[2] = a * b * c; + arr[3] = (a + b) * c; + arr[4] = a + b + c; + int maximum = arr[0]; + for (int i = 1; i <= 4; i++) { + if (arr[i] > maximum) { maximum = arr[i]; } + } + cout << maximum << endl; + return 0; +} +int main() { + long long int a, b, ans; + cin >> a >> b; + long long int x, y, z; + cin >> x >> y >> z; + long long int ye = (2 * x) + y; + long long int bl = y + (3 * z); + long long int n = ye - a; + long long int m = bl - b; + if (n < 0) { n = 0; } + if (m < 0) { m = 0; } + ans = n + m; + cout << ans << endl; + return 0; +} +int main() { + set rowSet, colSet; + int r, c; + char value; + cin >> r >> c; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> value; + if (value == 'S') { + rowSet.insert(i); + colSet.insert(j); + } + } + } + int rows = r - rowSet.size(); + int cols = c - colSet.size(); + int eatable = (rows * c) + (cols * r) - (rows * cols); + cout << eatable << endl; +} +int employee[2001]; +int dfs(int pos) { + if (pos == -1) return 1; + return dfs(employee[pos]) + 1; +} +int main() { + int n; + int ans = -1; + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> employee[i]; } + for (int i = 1; i <= n; ++i) { + int tmp = dfs(employee[i]); + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +set s; +int main() { + int x; + for (int i = 0; i < 4; i++) { + cin >> x; + s.insert(x); + } + cout << 4 - s.size() << endl; + return 0; +} +int main() { + float a, b; + cin >> a >> b; + float answer = log(b / a) / log(1.5); + cout << int(answer) + 1 << endl; + return 0; +} +int main() { + int x1, y1, x2, y2, x, y, x3, y3; + cin >> x1 >> y1 >> x2 >> y2; + x3 = abs(x1 - x2); + y3 = abs(y1 - y2); + cin >> x >> y; + if (x3 % x == 0 && y3 % y == 0 && (x3 / x) % 2 == (y3 / y) % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << m + n - 1 << endl; + for (int i = 1; i <= m; ++i) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; ++i) cout << i << " " << 1 << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + vector visited(n, false); + int last = 0; + for (i = 0; i < n; i++) { + last = (i + last) % n; + if (visited[last]) break; + visited[last] = true; + } + bool poss = true; + for (i = 0; i < n; i++) { + if (!visited[i]) { + poss = false; + break; + } + } + if (poss) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +short int n, m; +short int x, y; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + string line; + cin >> line; + for (int j = 0; j < m; j++) { + if (line[j] == '*') { + x ^= i; + y ^= j; + } + } + } + cout << x + 1 << " " << y + 1 << '\n'; + return 0; +} +int main() { + int t; + cin >> t; + int l, r, d; + while (t--) { + cin >> l >> r; + if (r % l == 0) { + cout << l << " " << r << endl; + } else { + d = r % l; + d = r - d; + cout << l << " " << d << endl; + } + } +} +int main() { + int n, i, j = 0, k = 0, l = 0; + cin >> n; + for (i = 0; i < n; i++) { + int m, n, p; + cin >> m >> n >> p; + j = j + m; + k = k + n; + l = l + p; + } + if (j == 0 && k == 0 && l == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int x[51], y[51]; +int main() { + int n, sum_x = 0, sum_y = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> x[i], sum_x += x[i]; + for (int i = 0; i < n; i++) cin >> y[i], sum_y += y[i]; + if (sum_x >= sum_y) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + vector parent(2020, -1); + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int p; + cin >> p; + parent[i + 1] = p; + } + int length = 0; + for (int i = 0; i < n; i++) { + int count = 1; + int x = i + 1; + while (parent[x] != -1) { + count++; + x = parent[x]; + } + length = max(length, count); + } + cout << length << endl; + return 0; +} +int main() { + long long a, b, c, d, e, ans = 0; + cin >> a >> b >> c >> d >> e; + if (c * 2 + d - a > 0) ans += (c * 2 + d) - a; + if (d + e * 3 - b > 0) ans += (d + e * 3) - b; + cout << ans << endl; + return 0; +} +int main() { + int n, i, x; + cin >> n; + x = 0; + string op; + for (i = 0; i < n; i++) { + cin >> op; + if (find(op.begin(), op.end(), '-') != op.end()) { + x--; + } else if (find(op.begin(), op.end(), '+') != op.end()) { + x++; + } + } + cout << x << endl; +} +int main() { + int n, m; + cin >> n >> m; + int flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char x; + cin >> x; + if (x == 'C' || x == 'M' || x == 'Y') flag = 1; + } + } + if (flag == 1) + cout << "#Color" << endl; + else + cout << "#Black&White" << endl; + return 0; +} +void Fast_Read_Out() {} +void Random() { + unsigned int seed; + asm("rdtsc" : "=A"(seed)); + srand(seed); +} +unsigned int Time() { + unsigned int time = clock() / 1000.00; + return time; +} +const int inf = int(1e9) + 123; +char a[101][101]; +int main() { + Random(); + Fast_Read_Out(); + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + char cur = a[i][j]; + if (cur == '*') continue; + int pos = 0; + for (int j1 = 1; j1 <= m; j1++) + if (a[i][j1] == '*' && j != j1) pos = j1; + if (pos == 0) continue; + for (int i1 = 1; i1 <= n; i1++) + if (a[i1][j] == '*' && i != i1) cout << i << ' ' << j << endl; + } + } +} +int n, m; +int k; +bool debug = false; +int main() { + int r, g, b; + cin >> r >> g >> b; + int rr = ((r + 1) / 2 - 1) * 3; + int gg = ((g + 1) / 2 - 1) * 3 + 1; + int bb = ((b + 1) / 2 - 1) * 3 + 2; + cout << max(max(rr, gg), bb) + 30 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n % 2 == 0) { + if (k <= n / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * (k - n / 2) << endl; + } else { + if (k <= (n + 1) / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * (k - ((n + 1) / 2)) << endl; + } +} +int main() { + long long A, B; + long long x, y, z; + cin >> A >> B; + cin >> x >> y >> z; + long long yello = 0, green = 0, bule = 0; + yello = x * 2 + y; + bule = z * 3 + y; + long long sum1 = yello - A; + long long sum2 = bule - B; + if (sum1 < 0) sum1 = 0; + if (sum2 < 0) sum2 = 0; + cout << sum1 + sum2 << endl; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + long long ans = max(abs(a - c), abs(b - d)); + cout << ans << endl; + return 0; +} +int prime(int x) { + for (int i = 2; i < x; i = i + 1) { + if (x % i == 0) { return 1; } + } + return 0; +} +int main() { + long int n, a, b; + cin >> n; + a = 4; + b = n - 4; + for (int i = 1; i <= n; i++) { + int m = prime(a); + int n = prime(b); + if (n == 1 && m == 1) { + cout << a << " " << b << endl; + return 0; + } + a++; + b--; + } +} +int n, d; +const int nmax = 1e2 + 2; +vector v[nmax]; +bool visited[nmax][nmax]; +string s; +int res = 1e4; +void dfs(int i, int j) { + if (i == n - 1) { + res = min(res, j); + return; + } + visited[i][j] = true; + for (int k = 0; k < v[i].size(); k++) + if (!visited[v[i][k]][j + 1]) dfs(v[i][k], j + 1); +} +int main() { + cin >> n >> d >> s; + for (int i = 0; i < n - 1; i++) { + if (s[i] != '1') continue; + for (int j = 1; j <= d; j++) { + if (i + j >= n) continue; + if (s[i + j] == '1') v[i].push_back(i + j); + } + } + dfs(0, 0); + if (res > 100) + cout << -1 << endl; + else + cout << res << endl; +} +int main() { + int n, m, k, a[1000] = {}; + cin >> n >> m >> k; + m--; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) { + if (m + i < n && a[m + i] && a[m + i] <= k) { + cout << i * 10 << '\n'; + return 0; + } + if (m - i > -1 && a[m - i] && a[m - i] <= k) { + cout << i * 10 << '\n'; + return 0; + } + } +} +int main() { + long long int n, i, sum = 0; + cin >> n; + long long int ar[n + 5]; + for (i = 0; i < n; i++) { + cin >> ar[i]; + sum = sum + ar[i]; + } + sort(ar, ar + n); + if (sum % 2 == 0) + cout << sum << endl; + else { + for (i = 0; i < n; i++) { + if (ar[i] % 2) { + sum = sum - ar[i]; + if (sum % 2 == 0) break; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + long long t; + cin >> t; + for (long long i = 0; i < t; i++) { + long long n; + cin >> n; + if (n % 7 == 0) { + cout << n / 7 << endl; + } else { + cout << n / 7 + 1 << endl; + } + } +} +int main() { + string s, tmp = ""; + int lst = 0; + cin >> s; + for (int i = 'z'; i >= 'a'; i--) { + for (int j = lst; j < s.length(); j++) { + if (s[j] == i) { + lst = j; + tmp += s[j]; + } + } + } + cout << tmp << endl; + return 0; +} +int main() { + int k, d; + cin >> k >> d; + if (k > 1 && !d) { + cout << "No solution" << endl; + return 0; + } + cout << d; + k--; + while (k--) cout << 0; + cout << endl; + return 0; +} +int main() { + char s[3005]; + int b[3005]; + memset(s, 0, sizeof(s)); + for (int i = 0; s[i - 1] != '}'; i++) { cin >> s[i]; } + memset(b, 0, sizeof(b)); + int len = strlen(s); + for (int i = 1; i < len - 1; i += 2) { b[s[i] - 'a'] = 1; } + int sum = 0; + for (int i = 0; i < 26; i++) + if (b[i]) sum++; + cout << sum << endl; +} +const int N = 60; +string s; +char s1[N]; +int main() { + cin >> s; + int len = s.length(); + if (len % 2 == 0) { + int n = len - 1; + for (int i = 0; i <= len; i += 2) { + s1[i] = s[n]; + n--; + } + n = 0; + for (int i = 1; i <= len; i += 2) { + s1[i] = s[n]; + n++; + } + } else if (len % 2 == 1) { + int n = 0; + for (int i = 0; i <= len; i += 2) { + s1[i] = s[n]; + n++; + } + n = len - 1; + for (int i = 1; i < len; i += 2) { + s1[i] = s[n]; + n--; + } + } + for (int i = len - 1; i >= 0; i--) cout << s1[i]; + cout << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int r = 0; + while (a > 0 && b >= 2 && c >= 4) { + a = a - 1; + b = b - 2; + c = c - 4; + r = r + 7; + } + cout << r << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int c = 0; + for (int i = 2 * m; i <= 2 * m * n; i += (2 * m)) { + ++c; + if (i >= k) break; + } + int nn = c; + int val; + if (c == 1) + val = 0; + else + val = 2 * m * (c - 1); + c = 0; + k -= val; + for (int i = 2; i <= 2 * m; i += 2) { + c++; + if (i >= k) break; + } + int mm = c; + char ch = (k % 2 == 0) ? 'R' : 'L'; + cout << nn << " " << mm << " " << ch << endl; + return 0; +} +inline string add(string a, string b) { + int i; + string ans = ""; + int cry = 0; + for (i = 0; i < max(a.size(), b.size()) + 1; i++) { + int ta, tb; + if (i >= a.size()) + ta = 0; + else + ta = a[i] - '0'; + if (i >= b.size()) + tb = 0; + else + tb = b[i] - '0'; + int p = ta + tb + cry; + cry = p / 10; + p %= 10; + ans += '0' + p; + } + if (ans[ans.size() - 1] == '0') ans = ans.substr(0, ans.size() - 1); + return ans; +} +inline string era(string p) { + for (int i = 0; i < p.size(); i++) { + if (p[i] == '0') { + p = p.substr(0, i) + p.substr(i + 1); + i--; + } + } + return p; +} +int main() { + string a, b, c; + cin >> a >> b; + reverse(a.begin(), a.end()); + reverse(b.begin(), b.end()); + c = add(a, b); + a = era(a); + b = era(b); + c = era(c); + if (add(a, b) == c) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, d; + while (cin >> n >> d) { + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + int res = 0; + for (int i = 1; i < n; i++) + if (arr[i] - d > arr[i - 1] + d) res++; + for (int i = 0; i < n - 1; i++) + if (arr[i] + d <= arr[i + 1] - d) res++; + cout << res + 2 << endl; + } +} +int ara[125]; +int main() { + int i, l, w = 0; + string s; + getline(cin, s); + l = s.size(); + for (i = 1; i < l; i++) { + if (s[i] >= 97 && s[i] <= 122) { ara[s[i]]++; } + } + for (i = 0; i <= 125; i++) { + if (ara[i] != 0) { w++; } + } + cout << w << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') { + cout << "#Color" << endl; + return 0; + } + } + } + cout << "#Black&White" << endl; +} +const int mx = 1e9; +int main() { + string str; + int n; + cin >> n >> str; + int cnt = 0; + for (int i = n; i < str.size();) { + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) cnt++; + i += n; + } + cout << cnt << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + m--; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int distl = INT_MAX, distr = INT_MAX; + for (int i = m; i >= 0; i--) { + if (a[i] != 0 && a[i] <= k) { + distl = m - i; + break; + } + } + for (int i = m; i < n; i++) { + if (a[i] != 0 && a[i] <= k) { + distr = i - m; + break; + } + } + cout << min(distl, distr) * 10 << endl; +} +int main() { + long long A, B, x, y, z, a = 0; + cin >> A >> B >> x >> y >> z; + if (A < (x * 2 + y)) { a += ((x * 2) + y - A); } + if (B < (y + z * 3)) { a += (y + (z * 3) - B); } + cout << a << endl; +} +const int maxn = 3e5; +int n = 0, m = 0; +int main() { + while (cin >> n) { + string str; + cin >> str; + int size = str.size(); + int ans = 0; + for (int i = 0; i < size; i += n) { + if (i >= 4) { + if (str[i - 1] == str[i - 2] && str[i - 2] == str[i - 3]) { ++ans; } + } + } + cout << ans << endl; + } + return 0; +} +int main() { + long long k, b, n, t; + cin >> k >> b >> n >> t; + long long sum = 1; + int cnt = 0; + while (sum <= t) { + sum = sum * k + b; + cnt++; + } + if (cnt > n) + cout << 0 << endl; + else + cout << n - cnt + 1 << endl; + return 0; +} +int main() { + int n, f, total(0), answer(0); + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> f; + total += f; + } + for (int i = 1; i <= 5; ++i) { + if ((total + i) % (n + 1) != 1) { answer += 1; } + } + cout << answer << endl; + return 0; +} +int main() { + int x1, y1, x2, y2, xx, yy; + cin >> x1 >> y1 >> x2 >> y2 >> xx >> yy; + if (abs(x1 - x2) % xx != 0 || abs(y1 - y2) % yy != 0) { + cout << "NO" << endl; + } else { + if ((abs(x1 - x2) / xx) % 2 == abs(y1 - y2) / yy % 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + int n; + cin >> n; + int a[n], b[n], c[n + 1]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + cin >> b[i]; + c[b[i]] = i; + } + int t = 0; + bool flag = 0; + for (int i = 0; i < n - 1; i++) { + if (c[a[i]] > c[a[i + 1]]) { + flag = 1; + t = i; + break; + } + } + if (flag == 0) { + cout << 0 << "\n"; + } else { + cout << n - t - 1 << "\n"; + } + return 0; +} +int i, n; +int d = 0; +int a = 0; +char ch; +int main() { + cin >> n; + for (i = 0; i < n; i++) { + cin >> ch; + if (ch == 'D') + d++; + else if (ch == 'A') + a++; + } + if (d > a) + cout << "Danik" << endl; + else if (d < a) + cout << "Anton" << endl; + else if (d == a) + cout << "Friendship" << endl; + return 0; +} +int main() { + int n, m, k, a, b; + string dir; + cin >> n >> m >> k; + a = (k - 1) / (2 * m); + a++; + k -= 2 * (a - 1) * m; + b = (k - 1) / 2; + b++; + if (k % 2 == 0) + dir = "R"; + else + dir = "L"; + cout << a << " " << b << " " << dir << '\n'; +} +int main() { + int n; + cin >> n; + int sum; + string winner; + getline(cin, winner); + int maxi = ((50 * 100) * -1); + vector reading; + for (int i = 0; i < n; ++i) { + sum = 0; + string s; + getline(cin, s); + string temp; + int j = 0; + for (int k = 1; k <= 8; ++k) { + temp = ""; + while (j < s.size() && s[j] != ' ') { + temp.push_back(s[j]); + ++j; + } + ++j; + reading.push_back(temp); + } + string tempName = reading[0]; + sum += ((atoi(reading[1].c_str())) * 100); + sum -= ((atoi(reading[2].c_str())) * 50); + for (int k = 3; k < reading.size(); ++k) { sum += (atoi(reading[k].c_str())); } + if (sum > maxi) { + winner = tempName; + maxi = sum; + } + reading.clear(); + } + cout << winner << endl; + return 0; +} +int main() { + int n; + long long ans = 0, sum = 0; + cin >> n; + int i = 1, x, mn = 0, cnt = 0; + for (; i <= n; ++i) { + cin >> x; + if (x & 1) { + ++cnt; + if (x < mn || mn == 0) + sum += mn, mn = x; + else + sum += x; + } else { + ans += x; + } + } + if (cnt & 1) + ans += sum; + else + ans += sum + mn; + cout << ans << endl; + return 0; +} +int main() { + long long int n, count, i; + cin >> n; + string s; + cin >> s; + count = 0; + for (i = 0; i < n - 1; i++) { + if (s[i] == s[i + 1]) { count++; } + } + cout << count << "\n"; +} +int main() { + int a, shu = 0; + string s; + cin >> a; + cin >> s; + for (int i = 0; i < a; i++) { + if (s[i] == s[i + 1]) { shu++; } + } + cout << shu << endl; + return 0; +} +int main() { + int n, m, i, p; + cin >> n >> m; + cout << n + m - 1 << endl; + for (i = 1; i <= m; i++) { + cout << "1" + << " " << i << endl; + } + for (p = 2; p <= n; p++) { + cout << p << " " + << "1" << endl; + } + return 0; +} +int main() { + string word; + cin >> word; + if (word[0] >= 'a' && word[0] <= 'z') word[0] = word[0] - 32; + cout << word << endl; + return 0; +} +long long N, M, S, D, A, B, sum, x, y, K, ans, val, L, a; +char C; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> S >> D; + if (ans < S) + ans = S; + else { + ans = S + ((ans - S) / D + 1) * D; + } + } + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + int a; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a % 7 == 0) + cout << a / 7 << endl; + else + cout << (a / 7) + 1 << endl; + } +} +int main() { + int n; + int i, j, k; + int count; + char a[105]; + while (cin >> n) { + cin >> a; + count = 0; + for (i = 1; i < strlen(a); i++) { + if (a[i] != a[i - 1]) { + count++; + i++; + continue; + } + } + cout << n - count << endl; + } + return 0; +} +int main() { + int n, m, k, buff = 0; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " L" << endl; + break; + } + buff++; + if (buff == k) { + cout << i + 1 << " " << j + 1 << " R" << endl; + break; + } + } + if (buff == k) break; + } + return 0; +} +int main() { + int a; + while (cin >> a) { + if (a % 2 == 0) + cout << "Mahmoud" << endl; + else if (a % 2 == 1) + cout << "Ehab" << endl; + } + return 0; +} +int main() { + int a, n, k1, k2; + cin >> a >> n >> k1 >> k2; + if (a > n) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +int main() { + int res = 0, n; + cin >> n; + string op; + while (n--) { + cin >> op; + if (op[1] == '+') + res++; + else + res--; + } + cout << res << endl; + return 0; +} +long long int x; +int main() { + cin >> x; + cout << ((x * (x + 1) / 2) % 2) << endl; + return 0; +} +long long n, d, a[105], ans = 2; +int main() { + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) { + if (a[i - 1] + d < a[i] - d) + ans += 2; + else if (a[i - 1] + d == a[i] - d) + ans++; + } + cout << ans << '\n'; +} +int main() { + int n, i; + cin >> n; + vector A(n); + for (i = 0; i < n; i++) cin >> A[i]; + i = 0; + int j = 1, c = 0; + while (i < n && j < n && i != j) { + if (A[j] == A[i]) { + c++; + i++; + j++; + } else { + i++; + j++; + } + } + cout << c << endl; +} +long long n, a, b, x, tmp, k, kanan, hasil; +vector price; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> x; + tmp += x; + price.push_back(x); + } + sort(price.begin(), price.end()); + kanan = price.size() - 1; + while (kanan > 0) { + if ((price[kanan] - price[kanan - 1]) % k != 0) { + cout << -1 << endl; + return 0; + } + kanan--; + } + kanan = price.size() - 1; + while (kanan > 0) { hasil += price[kanan--] - price[0]; } + cout << hasil / k << endl; +} +inline void getInt(int *p); +string a = "Danil"; +string c = "Olya"; +string d = "Slava"; +string e = "Ann"; +string b = "Nikita"; +int main() { + string s; + cin >> s; + int cnt = 0; + int index = -1; + while ((index = s.find(a, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(b, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(c, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(d, index + 1)) != -1) { cnt++; } + index = -1; + while ((index = s.find(e, index + 1)) != -1) { cnt++; } + if (cnt == 1) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 122220 + ch - '0'; } + } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + string ans; + int cnt = 0, sum = 0; + for (int i = 0; i < n; i += cnt) { + ans.push_back(s[i]); + cnt++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v[k]; + long long cnt = 0, mx = 0; + for (int i = 0; i < k; i++) { + int x, h = 1, kk = -1; + cin >> x; + for (int j = 0; j < x; j++) { + int y; + cin >> y; + if (v[i].size() != 0 && v[i][0] == 1 && y == h + 1) { + h++; + continue; + } else { + v[i].push_back(y); + h = 1; + cnt++; + } + } + } + for (int i = 0; i < k; i++) { mx += (v[i].size() - 1); } + cout << (long long)(mx + cnt - 1) << endl; +} +int people[105]; +int count[105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> people[i]; } + int t = 99999999; + int total = 0, tmp; + for (int i = 0; i < n; i++) { + total = 0; + for (int j = 0; j < people[i]; j++) { + cin >> tmp; + total += tmp * 5; + } + total += (people[i]) * 15; + if (total < t) t = total; + } + cout << t << endl; + return 0; +} +int main() { + string stone; + int count = 0; + int n; + cin >> n >> stone; + for (int i = 1; i < n; i++) { + if (stone[i] == stone[i - 1]) count++; + } + cout << count << endl; + return 0; +} +int main() { + string s; + set set; + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { set.insert(s[i]); } + } + cout << set.size() << endl; + return 0; +} +int main() { + string s; + cin >> s; + int l = ((int)(s).size()) / 2, r = ((int)(s).size()) / 2; + if (((int)(s).size()) % 2 == 0) l--, r--; + string ans; + ans += s[l]; + --l, ++r; + while (r < ((int)(s).size()) || l > -1) { + if (r < ((int)(s).size())) ans += s[r]; + if (l > -1) ans += s[l]; + --l, ++r; + } + cout << ans << endl; + return 0; +} +string s; +int n, count1 = 1, count2 = 1; +int main() { + cin >> s; + n = s.length(); + if (n < 7) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < n; i++) { + if (s[i] == s[i + 1] && s[i] == '1') { + count1++; + if (count1 == 7) break; + } else + count1 = 1; + if (s[i] == s[i + 1] && s[i] == '0') { + count2++; + if (count2 == 7) break; + } else + count2 = 1; + } + if (count1 == 7 || count2 == 7) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, c, sum = 0, d = 0; + cin >> a >> b >> c; + for (int i = 1;; i++) { + if ((i * 1 + i * 2 >= c) || (i * 4 > c) || (i * 2 > b) || (i > a)) { break; } + sum = i * 1 + i * 2 + i * 4; + } + cout << sum << endl; + return 0; +} +int main() { + int x, y, z, a, b, c, m, n, sum1, sum2; + cin >> x >> y >> z >> a >> b >> c >> n; + sum1 = x + y + z; + if (sum1 % 5) { + sum1 = sum1 / 5 + 1; + } else { + sum1 = sum1 / 5; + } + sum2 = a + b + c; + if (sum2 % 10) { + sum2 = sum2 / 10 + 1; + } else { + sum2 = sum2 / 10; + } + if (n >= sum1 + sum2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int a[105] = {0}; +int main() { + int n, m, k; + int num; + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (m + i <= n && a[m + i] != 0 && k >= a[m + i]) { + num = i; + break; + } + if (m - i >= 1 && a[m - i] != 0 && k >= a[m - i]) { + num = i; + break; + } + } + cout << num * 10 << endl; + return 0; +} +long long a, b, n; +bool ans = 0; +int main() { + cin >> a >> b; + while (b > 0) { + if (b == 1) { + ans = 0; + break; + } + if (b % a != 0) { + ans = 1; + break; + } + n++; + b = b / a; + } + if (ans == 0) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else + cout << "NO" << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + cout << m + n - 1 << endl; + for (int j = 1; j <= m; j++) { cout << 1 << " " << j << endl; } + for (int i = 2; i <= n; i++) { cout << i << " " << 1 << endl; } + return 0; +} +int main() { + long long gl, gr, bl, br; + cin >> gl >> gr >> bl >> br; + if (br >= gl - 1 && br <= 2 * (gl + 1)) { + cout << "YES" << endl; + return 0; + } + if (bl >= gr - 1 && bl <= 2 * (gr + 1)) { + cout << "YES" << endl; + return 0; + } else + cout << "NO" << endl; +} +const int oo = 1e9; +int main() { + int n, m, k; + cin >> n >> m >> k; + int x = (k + 1) / 2; + x--; + int r = x % m; + int d = x / m; + cout << d + 1 << " " << r + 1 << " " << (k % 2 ? "L" : "R") << '\n'; + return 0; +} +const int maxn = 1e5 + 5; +const double esp = 1e-8; +bool cmp(int a, int b) { + return a > b; +} +int a[maxn]; +map mp; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int j = n; j < 2 * n; j++) a[j] = a[j - n]; + int ans = 360; + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = i; j < 2 * n; j++) { + if (j - i >= n) break; + sum += a[j]; + ans = min(ans, 2 * abs(sum - 180)); + } + } + cout << ans << endl; +} +int n = 6, res, a[10]; +int main() { + for (int i = 1; i <= n; i++) cin >> a[i]; + int root = a[1] * 2 + 1, curr = root; + int first_layer = 0, second_layer = 0, third_layer = 0; + if (a[2] >= a[n]) + first_layer = a[n], second_layer = a[2] - a[n]; + else + first_layer = a[2], second_layer = a[n] - a[2]; + for (int i = 1; i <= first_layer; i++) { + res = res + curr; + curr = curr + 2; + } + if (first_layer == a[2]) + second_layer = min(second_layer, a[3]); + else + second_layer = min(second_layer, a[5]); + for (int i = 1; i <= second_layer; i++) res = res + curr - 1; + root = a[4] * 2 + 1, curr = root; + for (int i = 1; i <= min(a[3], a[5]); i++) { + res = res + curr; + curr = curr + 2; + } + cout << res << '\n'; + return 0; +} +int main() { + int s = 0, c; + for (int i = 0; i < 5; i++) { + cin >> c; + s += c; + } + if (s % 5 || !s) + cout << -1 << endl; + else + cout << s / 5 << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int x = 0; + for (int i = 0; i < s.size() - 1; i++) { + if (s[i] == s[i + 1]) { x++; } + } + cout << x << endl; +} +int main() { + char s[50]; + int count = 0; + int n, i; + cin >> n >> s; + for (i = 0; i < n; i++) { + if (s[i] == s[i - 1]) { count++; } + } + cout << count << endl; + return 0; +} +long long n; +int a[200]; +int main() { + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int sum = 1e9; + for (int i = 1; i <= n; i++) { + int ant = a[i] * 15; + for (int j = 0; j < a[i]; j++) { + int x; + cin >> x; + ant += x * 5; + } + sum = min(sum, ant); + } + cout << sum << endl; + } + return 0; +} +const int M = 100000 + 10; +int a[M]; +string f[30]; +int main() { + string s; + cin >> s; + int slen = s.length(); + int k; + cin >> k; + for (int i = 0; i < k; i++) { cin >> f[i]; } + int num = 0; + for (int i = 0; i < k; i++) { + int id = 0; + while (id < slen) { + int num1 = 0; + int num2 = 0; + while (id < slen && s[id] != f[i][0] && s[id] != f[i][1]) { id++; } + while (id < slen && (s[id] == f[i][0] || s[id] == f[i][1])) { + if (s[id] == f[i][0]) { + num1++; + } else { + num2++; + } + id++; + } + num = num + min(num1, num2); + } + } + cout << num << endl; + return 0; +} +const double pi = acos(-1.0); +const double pii = 2 * pi; +const double eps = 1e-6; +int main() { + long long int a, m; + cin >> a >> m; + long long int f = 0; + for (long long int i = 0; i <= 100000; i++) { + if (a % m == 0) { + f = 1; + break; + } + long long int x = a % m; + a += x; + } + if (f == 0) + cout << "No\n"; + else + cout << "Yes\n"; + cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"; + return 0; +} +int main() { + long long n, c = 0; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +string s1, s2; +int main() { + getline(cin, s1); + getline(cin, s2); + int sz1 = s1.size(); + int sz2 = s2.size(); + bool swaped = 0; + if (sz1 < sz2) { + swap(s1, s2); + swap(sz1, sz2); + swaped = 1; + } + if (sz1 > sz2) { + string aux = ""; + for (int i = 1; i + sz2 <= sz1; ++i) { aux += "0"; } + s2 = aux + s2; + } + s1 = "0" + s1; + s2 = "0" + s2; + sz1++; + for (int i = 1; i + 1 < sz1; ++i) { + if (s1[i] == '1' and s1[i + 1] == '1') { + s1[i - 1] = '1'; + s1[i] = '0'; + s1[i + 1] = '0'; + int j = i - 2; + while (j - 1 >= 0 and s1[j] == '1') { + s1[j - 1] = '1'; + s1[j] = '0'; + s1[j + 1] = '0'; + j -= 2; + } + } + if (s2[i] == '1' and s2[i + 1] == '1') { + s2[i - 1] = '1'; + s2[i] = '0'; + s2[i + 1] = '0'; + int j = i - 2; + while (j - 1 >= 0 and s2[j] == '1') { + s2[j - 1] = '1'; + s2[j] = '0'; + s2[j + 1] = '0'; + j -= 2; + } + } + } + for (int i = 0; i < sz1; ++i) { + if (s1[i] > s2[i]) { + if (!swaped) { + cout << '>' << '\n'; + } else { + cout << '<' << '\n'; + } + return 0; + } else if (s1[i] < s2[i]) { + if (!swaped) { + cout << '<' << '\n'; + } else { + cout << '>' << '\n'; + } + return 0; + } + } + cout << '=' << '\n'; + return 0; +} +int main() { + int n, x, suma; + int a[100]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + a[i] = x; + } + for (int i = 0; i < n; i++) { + if (a[i] % 7 == 0) + suma = a[i] / 7; + else + suma = a[i] / 7 + 1; + cout << suma << endl; + } + return 0; +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + int a[n + 1]; + bool b[n + 1]; + memset(b, true, sizeof(b)); + for (int i = 1; i <= n; ++i) { + cin >> a[i]; + if (a[i] == 0) b[i] = false; + } + int MIN1 = 0x3f3f3f, MIN2 = 0x3f3f3f; + int i = m; + int j = m; + while (i > 0) { + if (k >= a[i] && b[i] == true) { + MIN1 = m - i; + break; + } + --i; + } + while (j <= n) { + if (k >= a[j] && b[j] == true) { + MIN2 = j - m; + break; + } + ++j; + } + cout << min(MIN1, MIN2) * 10 << endl; + } + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + a /= 1; + b /= 2; + c /= 4; + cout << min(min(a, b), c) * 7 << endl; +} +int main() { + int n; + int day = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int s, q; + cin >> s >> q; + if (i == 0) { + day = s; + } else { + if (day == s) { + day += q; + } else if (s < day) { + while (s < day) { s += q; } + if (s != day) + day = s; + else + day = s + q; + } else { + day = s; + } + } + } + cout << day << endl; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +const int N = 300; +int flag[N + 5]; +int main() { + desperate_optimization(10); + int n, p; + cin >> p >> n; + int ans = 500; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (flag[x % p] == 1) ans = min(ans, i); + flag[x % p] = 1; + } + if (ans == 500) ans = -1; + cout << ans << '\n'; + return 0; +} +int main() { + set myset; + string s; + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 97 && s[i] <= 122) { myset.insert(s[i]); } + } + cout << myset.size() << endl; +} +int v[10]; +int main() { + int n, top, aux1, aux2; + cin >> n >> top; + for (int i = 0; i < n; i++) { + cin >> aux1 >> aux2; + if (aux1 == top || aux1 == 7 - top || aux2 == top || aux2 == 7 - top) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +unsigned int s[2][200000]; +bool q[200001]; +int main() { + unsigned int n; + cin >> n; + for (unsigned int i = 0; i < n; ++i) cin >> s[0][i]; + for (unsigned int i = 0; i < n; ++i) cin >> s[1][i]; + unsigned int mxd = 0, qi = 0; + for (unsigned int i = 0, j = n - 1; i < n; ++i) { + unsigned int ci = i; + while (ci < n && s[0][qi] == s[1][ci]) ++ci, ++qi; + i = ci; + if (i < n && !q[s[1][i]]) { + while (s[1][i] != s[0][j]) { + q[s[0][j]] = true; + --j; + ++mxd; + } + ++mxd; + --j; + } + } + cout << mxd << endl; + return 0; +} +int main() { + int arr[4]; + cin >> arr[0] >> arr[1] >> arr[2] >> arr[3]; + sort(arr, arr + 4); + int count = 0; + for (int i = 0; i <= 2; i++) { + if (arr[i] == arr[i + 1]) count++; + } + cout << count << endl; +} +int main() { + int n, m, num; + string s, dir; + cin >> n >> m; + int l = 0, r = n + 1; + for (int i = 0; i < m; i++) { + cin >> s >> s >> dir >> s >> num; + if (dir == "right") l = max(l, num); + if (dir == "left") r = min(r, num); + } + int ans = r - l - 1; + if (ans <= 0) + cout << -1 << endl; + else + cout << ans << endl; + return 0; +} +int gcd(int a, int b) { + return (b) ? gcd(b, a % b) : a; +} +int main() { + int a, b, c, d, x, y; + cin >> a >> b >> c >> d >> x >> y; + a -= c; + b -= d; + if (!(a % x) && !(b % y) && abs((a / x) % 2) == abs((b / y) % 2)) { + puts("YES"); + return 0; + } + puts("NO"); +} +int main() { + long long nn, kk; + cin >> nn >> kk; + long long arr[nn]; + for (long long i = 0; i < nn; i++) cin >> arr[i]; + long long mm = 10e17; + for (long long i = 0; i < nn; i++) mm = min(mm, arr[i]); + long long ans = 0; + long long flag = 0; + for (long long i = 0; i < nn; i++) { + long long diff = arr[i] - mm; + if (diff % kk != 0) { + flag = 1; + break; + } + ans += diff / kk; + } + if (flag == 1) + cout << "-1" << endl; + else + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int cnt = 0; + while (n != 0) { + cnt += n % 2; + n /= 2; + } + cout << (cnt == 1 ? "YES\n" : "NO\n"); + return 0; +} +int n; +char str[100010], tmp[5]; +int main() { + int t, q, i, j, k, ans = 0, t1, t2; + cin >> str >> k; + while (k--) { + cin >> tmp; + t1 = t2 = 0; + for (i = 0; str[i]; i++) { + if (str[i] == tmp[0]) + t1++; + else if (str[i] == tmp[1]) + t2++; + else { + ans += min(t1, t2); + t1 = t2 = 0; + } + } + ans += min(t1, t2); + } + cout << ans << endl; + return 0; +} +int isVowel(char c); +int main() { + int i, j, n; + string s; + cin >> n >> s; + for (i = 1; i < n; i++) { + if (isVowel(s[i]) && isVowel(s[i - 1])) { + for (j = 1; j < n; j++) { + if (isVowel(s[j - 1]) && isVowel(s[j])) { + s.erase(j, 1); + break; + } + } + i = 0; + } + } + cout << s << endl; + return 0; +} +int isVowel(char c) { + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return 1; + return 0; +} +const double eps = 1e-8; +const double PI = acos(-1.0); +const long long mod = 1e18; +const int N = 1000006; +int main() { + int n, m, x, l, r; + string a, b, d, dir; + cin >> n >> m; + l = 1, r = n; + for (int i = 0; i < m; i++) { + cin >> a >> b >> dir >> d >> x; + if (dir == "right" && x + 1 > l) { l = x + 1; } + if (dir == "left" && x - 1 < r) { r = x - 1; } + } + if (r < l) + cout << "-1" << endl; + else + cout << r - l + 1 << endl; + return 0; +} +int a, b; +int main() { + cin >> a >> b; + char arr[a * b]; + for (int i = 0; i < a * b; i++) { cin >> arr[i]; } + for (int i = 0; i < a * b; i++) { + if (arr[i] == 'C' || arr[i] == 'Y' || arr[i] == 'M') { + cout << "#Color" << endl; + return 0; + } + } + cout << "#Black&White" << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if ((d >= a - 1 && d <= 2 * (a + 1)) || (c >= b - 1 && c <= 2 * (b + 1))) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + for (int i = 0; i < n; i++) { + char c; + cin >> c; + if (c == 'A') { cnt++; } + } + cnt *= 2; + if (cnt == n) + cout << "Friendship" << endl; + else if (cnt > n) + cout << "Anton" << endl; + else + cout << "Danik" << endl; + return 0; +} +int solve(int l, int r, int d) { + if (d >= l) { + return (r / d + 1) * d; + } else { + return d; + } +} +int main() { + int q; + cin >> q; + for (int i = 0; i < q; i++) { + int l, r, d; + cin >> l >> r >> d; + cout << solve(l, r, d) << endl; + } +} +void solve() { + int m, k; + cin >> m >> k; + int ans = 0; + int d[m]; + int s[m]; + int dp[m]; + for (int i = 0; i < m; i++) { + cin >> d[i]; + ans += d[i]; + } + for (int i = 0; i < m; i++) { + cin >> s[i]; + if (i == 0) + dp[i] = s[i]; + else { + if (s[i] > dp[i - 1]) + dp[i] = s[i]; + else + dp[i] = dp[i - 1]; + } + } + int fuel = 0; + for (int i = 0; i < m; i++) { + fuel += s[i]; + if (fuel - d[i] < 0) { + int z = dp[i]; + int dif = d[i] - fuel; + if (dif % z == 0) { + ans += (dif / z * k); + fuel += dif; + } else { + ans += (dif / z + 1) * k; + fuel += (dif / z + 1) * z; + } + } + fuel -= d[i]; + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, cnt = 0; + string s; + cin >> n; + cin >> s; + for (int i = 3; i < s.length(); i++) { + if (i % n == 0) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) { cnt++; } + } + } + cout << cnt << "\n"; + return 0; +} +int main() { + int i, j, k, a[3]; + cin >> a[0] >> a[1] >> a[2]; + for (i = 0;; i++) { + a[i % 3] -= 2; + if (a[0] <= 0 && a[1] <= 0 && a[2] <= 0) { + cout << i + 30 << endl; + return 0; + } + } +} +int arr[300]; +int main() { + int p, n; + cin >> p >> n; + int ans = -1; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + x = x % p; + if (arr[x] == 1) { + ans = i + 1; + break; + } else { + arr[x] = 1; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { cin >> a[i][j]; } + } + for (int i = 0; i < n; ++i) { + if (!count(a[i], a[i] + m, '1')) { + cout << -1 << '\n'; + return 0; + } + } + int nearest[n][m], l[n][m], r[n][m]; + for (int i = 0; i < n; ++i) { + int lst = -1; + for (int j = 0; j < m; ++j) { + if (a[i][j] == '1') lst = j; + } + bool c = true; + for (int j = 0; j < m; ++j) { + lst = (a[i][j] == '1' ? j : lst); + c &= a[i][j] == '0'; + l[i][j] = (c ? m - lst + j : abs(j - lst)); + } + lst = -1; + c = true; + for (int j = 0; j < m; ++j) { + if (a[i][j] == '1') { + lst = j; + break; + } + } + for (int j = m - 1; j >= 0; --j) { + lst = (a[i][j] == '1' ? j : lst); + c &= a[i][j] == '0'; + r[i][j] = (c ? lst + 1 + m - (j + 1) : abs(j - lst)); + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { nearest[i][j] = min(r[i][j], l[i][j]); } + } + int ans = 0x3f3f3f3f; + for (int j = 0; j < m; ++j) { + int cur = 0; + for (int i = 0; i < n; ++i) { cur += nearest[i][j]; } + ans = min(ans, cur); + } + cout << ans << '\n'; +} +const int maxn = 100; +const int inf = 0x3f3f3f3f; +char a[maxn]; +int main() { + cin >> a; + int flag = 1; + int len = strlen(a); + for (int i = 0; i < len; i++) { + if (a[i] != a[i + 1] && i + 1 < len) { + flag = 0; + break; + } + } + if (flag == 1) { + cout << "0" << endl; + return 0; + } else { + int f = 0; + for (int i = 0; i < len / 2; i++) { + if (a[i] != a[len - 1 - i]) { + cout << len << endl; + return 0; + } + } + cout << len - 1 << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int banyaklemon = a; + int banyakapel = b / 2; + int banyakpear = c / 4; + int hasil = min(banyaklemon, banyakapel); + hasil = min(hasil, banyakpear); + cout << hasil * (7) << endl; +} +int n; +int main() { + cin >> n; + if (n & 1) + puts("Ehab"); + else + puts("Mahmoud"); + return 0; +} +int main() { + int p, n; + while (cin >> p >> n) { + int store[301]; + memset(store, -1, sizeof(store)); + int ans = -1; + for (int i = 0, x; i < n; i++) { + cin >> x; + if (ans != -1) continue; + if (store[x % p] == -1) + store[x % p] = 0; + else + ans = i + 1; + } + cout << ans << endl; + } +} +int main() { + int c = 0; + string s; + map mp; + getline(cin, s); + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + if (mp[s[i]] == 0) { + c++; + mp[s[i]]++; + } + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, k1, k2; + cin >> n >> m; + int mini = INT_MAX; + for (int i = 0; i <= n; i++) { + k1 = i; + k2 = (n - i) / 2; + if ((n - i) % 2 == 0 && (k1 + k2) % m == 0) { + if (mini > k1 + k2) { mini = k1 + k2; } + } + } + if (mini == INT_MAX) { + cout << -1 << endl; + } else { + cout << mini << endl; + } +} +vector divisor; +vector divisor2; +int main() { + long long n, k, i, factor; + cin >> n >> k; + divisor.push_back(1); + if (n != 1) divisor2.push_back(n); + for (i = 2; i <= sqrt(n); i++) { + if (n % i == 0) { + divisor.push_back(i); + if (n / i != i) divisor2.push_back(n / i); + } + } + factor = divisor.size() + divisor2.size(); + if (k > factor) + cout << "-1\n"; + else { + if (k <= divisor.size()) + cout << divisor[k - 1] << '\n'; + else + cout << divisor2[divisor2.size() - (k - divisor.size())] << '\n'; + } + return 0; +} +const int maxn = 5001; +char a[110]; +int main() { + int n; + cin >> n >> a; + int sum = 0; + for (int i = 0; i < n; i++) { + if (a[i] != a[i + 1]) i++; + sum++; + } + cout << sum << endl; + return 0; +} +long long solve(long long k, long long b, long long n, long long t) { + if (k == 1) { + long long low = -1, high = n; + while (high - low > 1) { + long long mid = (low + high) / 2; + if (1 - t + b * (n - mid) <= 0) { + high = mid; + } else { + low = mid; + } + } + return high; + } + long long answ = n; + __float128 pow = 1; + while (answ > 0 && (k - 1) * (pow * k - t) + b * (pow * k - 1) <= 0) { + pow *= k; + answ--; + } + return answ; +} +int main() { + long long k, b, n, t; + while (cin >> k >> b >> n >> t) { cout << solve(k, b, n, t) << endl; } + return 0; +} +int main() { + long long n, m, a, b, c, ans1 = 0, ans2 = 0, sum = 0; + cin >> n >> m; + cin >> a >> b >> c; + ans1 = a * 2 + b * 1; + ans2 = b * 1 + c * 3; + sum = ans1 > n ? ans1 - n : 0; + sum += ans2 > m ? ans2 - m : 0; + cout << sum << endl; + return 0; +} +int main() { + int a[200001], b, n, f = 0, t = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + cin >> b; + if (b == a[t]) { + t++; + f++; + } + } + cout << n - t << endl; +} +int main() { + int r[10], c[10], n, m, num = 0; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + char temp; + cin >> temp; + if (temp == 'S') r[i] = c[j] = 1; + } + num = m * n; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (r[i] && c[j]) num--; + } + cout << num << endl; +} +int main() { + int i, n; + char a[2001]; + cin >> n; + cin >> a; + int tt = 1, ans = 0; + for (i = 1; a[i] != '\0'; i++) { + if (i % n == 0 && tt > 2) ans++; + if (a[i] == a[i - 1]) + tt++; + else + tt = 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n1, n2, k2, k1; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else + cout << "Second" << endl; +} +bool vis[100005]; +bool comp(pair a, pair b) { + return a.first > b.first; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + if (n < 3) { + cout << 0 << endl; + return 0; + } + sort(arr, arr + n); + int cnt = 0; + for (int i = 1; i < n - 1; i++) { + if (arr[i] > arr[0] && arr[i] < arr[n - 1]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int r, g, b, timeOfEnding = 29, color = 0; + cin >> r >> g >> b; + int count = r + g + b; + while (count != 0) { + if (color == 3) color = 0; + if (color == 0) { + if (r > 2) { + r -= 2; + count -= 2; + } else { + count -= r; + r = 0; + } + } else if (color == 1) { + if (g > 2) { + g -= 2; + count -= 2; + } else { + count -= g; + g = 0; + } + } else { + if (b > 2) { + b -= 2; + count -= 2; + } else { + count -= b; + b = 0; + } + } + color++; + timeOfEnding++; + } + cout << timeOfEnding << endl; + return 0; +} +int i; +int main() { + int n; + cin >> n; + string S; + cin >> S; + int count = 0; + for (int i = 0; i < n - 1; i++) { + if (S[i] == S[i + 1]) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int n, cnt = 1, i = 0; + string s; + cin >> n >> s; + while (true) { + cout << s[i]; + i += cnt; + cnt++; + if (i + cnt > n) { break; } + } + cout << endl; + return 0; +} +char str[1001]; +int main() { + int sum = 0; + set s; + gets(str); + int len = strlen(str); + for (int i = 0; i < len; i++) { s.insert(str[i]); } + set::iterator iter; + for (iter = s.begin(); iter != s.end(); iter++) { + if ((*iter != '{') && (*iter != '}') && (*iter != ',') && (*iter != ' ')) sum++; + } + cout << sum << endl; +} +int main() { + int n, m, f = 0; + char ch; + cin >> n >> m; + for (int i = 1; i <= n * m; i++) { + cin >> ch; + if (ch != 'B' && ch != 'W' && ch != 'G') f = 1; + } + if (f == 1) + cout << "#Color\n"; + else + cout << "#Black&White\n"; +} +int main() { + string S; + cin >> S; + S[0] = toupper(S[0]); + cout << S << endl; +} +int main() { + string s; + int n, x = 0; + cin >> n; + while (n--) { + cin >> s; + if (s[1] == '+') { + x++; + } else { + x--; + } + } + cout << x << endl; + return 0; +} +string a, b; +vector v; +bool sub(int x) { + int y = 0; + for (int i = 0; i < a.size(); i++) { + if (v[i] > x && b[y] == a[i]) { y++; } + } + return y == b.size(); +} +int main() { + cin >> a >> b; + v.resize(a.size()); + for (int i = 0; i < a.size(); i++) { + int a; + cin >> a; + a--; + v[a] = i + 1; + } + int le = 0; + int ri = a.size() - b.size() + 1; + int cnt = 0; + while (le < ri) { + cnt++; + int mi = le + (ri - le) / 2; + if (sub(mi)) { + le = mi + 1; + } else { + ri = mi; + } + } + cout << le - 1 << endl; +} +int main() { + int q; + cin >> q; + while (q--) { + int l, r, d; + cin >> l >> r >> d; + if (d < l) + cout << d << endl; + else + cout << ((r / d) * d) + d << endl; + } + return 0; +} +int n, m, a[11], b[11]; +map mp; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mp[a[i]]++; + } + for (int i = 0; i < m; i++) { + cin >> b[i]; + mp[b[i]]++; + } + int ans = -1; + sort(a, a + n); + sort(b, b + m); + for (int i = 1; i <= 9; i++) { + if (mp[i] >= 2) { + ans = i; + break; + } + } + if (ans == -1) { + int s1 = (a[0] * 10) + b[0]; + int s2 = (b[0] * 10) + a[0]; + if (s1 > s2) + cout << s2 << endl; + else + cout << s1 << endl; + } else + cout << ans << endl; + mp.clear(); + return 0; +} +int main() { + long long n, m, i, j, k, a, b, l, c, cnt = 1; + cin >> n >> a >> b >> c >> l; + i = 0; + for (i = a; i < n;) { + a = a + c; + if (a > b) a = b; + i = i - l; + i = i + a; + cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int x, y, cnt = 0; + cin >> x >> y; + int p = x * 100 + 10 * y; + while (p >= 220) { + if (x > 1 && y >= 2) { + x -= 2; + y -= 2; + cnt++; + } else if (x == 1 && y >= 12) { + x--; + y -= 12; + cnt++; + } else if (y >= 22) { + y -= 22; + cnt++; + } else + p = 200; + p -= 220; + if (p >= 220) { + if (y >= 22) { + y -= 22; + cnt++; + } else if (y >= 12 && x) { + y -= 12; + x--; + cnt++; + } else if (y >= 2 && x >= 2) { + y -= 2; + x -= 2; + cnt++; + } else + p = 200; + p -= 220; + } + } + if (cnt % 2) + cout << "Ciel" << endl; + else + cout << "Hanako" << endl; +} +int main() { + int n, sum = 0, s = 0; + cin >> n; + int arr[n], ar[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + for (int i = 0; i < n; i++) { + cin >> ar[i]; + s += ar[i]; + } + if (s <= sum) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +const long long mod = 1e9 + 7; +const long long inf = 1e18 + 7; +const int maxn = 1e5 + 10; +const double eps = 1e-7; +int q; +int main() { + cin >> q; + while (q--) { + int l, r, d; + cin >> l >> r >> d; + if (d < l) { + cout << d << "\n"; + } else { + int m = (r + 1) % d; + if (!m) { + cout << r + 1 << "\n"; + } else + cout << r + 1 + d - m << "\n"; + } + } +} +int main() { + int r, g, b; + cin >> r >> g >> b; + if (r == 0 && g == 0 && b == 0) { + cout << 0 << endl; + return 0; + } + int ans = 0; + if (r >= g && r >= b) { + ans = 30 + ((r - 1) / 2) * 3; + if ((r - 1) / 2 == (b - 1) / 2 && b > 0) + ans += 2; + else if ((r - 1) / 2 == (g - 1) / 2 && g > 0) + ans++; + } else if (g >= r && g >= b) { + ans = 30 + ((g - 1) / 2) * 3; + ans++; + if ((g - 1) / 2 == (b - 1) / 2 && b > 0) ans++; + } else { + ans = 30 + ((b - 1) / 2) * 3; + ans += 2; + } + cout << ans << endl; + return 0; +} +int a[110]; +int main() { + int n, d, ans = 2; + cin >> n >> d; + int p = 2 * d; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i < n; i++) { + int c = a[i + 1] - a[i]; + if (c == p) + ans += 1; + else if (c > p) + ans += 2; + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + if (k > n / 2 + n % 2) { + cout << (k - n / 2 - n % 2) * 2 << endl; + } else { + cout << k * 2 - 1 << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) cout << 1 << " " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " " << 1 << endl; + return 0; +} +char a[6][6]; +int nCount(int x, int y, char c) { + int res = 0; + if (a[x + 1][y] == c) { res++; } + if (a[x][y + 1] == c) { res++; } + if (a[x + 1][y + 1] == c) { res++; } + return res; +} +int main() { + char z; + for (int i = 1; i <= 4; i++) { + for (int j = 1; j <= 4; j++) { + cin >> z; + a[i][j] = z; + } + } + for (int i = 1; i <= 4; i++) { + for (int j = 1; j <= 4; j++) { + if (a[i][j] == '#') { + if (nCount(i, j, '#') >= 2 || nCount(i, j, '.') >= 3) { + cout << "YES" << endl; + return 0; + } + } else { + if (nCount(i, j, '.') >= 2 || nCount(i, j, '#') >= 3) { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int ee = 0, acc = 0; + for (int i = 0; i < 6; i++) { + int e; + cin >> e; + if (i % 2 == 0) acc += e * e; + if (i < 3) ee += e; + } + int ans = ee * ee - acc; + cout << ans << endl; +} +int main() { + long long n, k; + cin >> n >> k; + if (k <= (n + 1) / 2) { + cout << k * 2 - 1 << endl; + } else { + cout << (k - (n + 1) / 2) * 2 << endl; + } + return 0; +} +int main() { + int k, l, importance(-1); + cin >> k >> l; + while (l % k == 0) { + l /= k; + importance += 1; + } + if (importance >= 0 && l == 1) { + cout << "YES" << endl << importance << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, c, d, e, f = 0; + cin >> a >> b >> c >> d >> e; + for (int i = 0; i < 10000; i++) { + f = 0; + f += b; + f += i * d; + if (f >= c) { f = c; } + if (i > 0) { f -= e; } + if (a - f <= 0) { + cout << i + 1 << endl; + return 0; + } + a -= f; + } +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[105]; + for (int i = 1; i <= n; i++) cin >> a[i]; + int c = 9999999, c1 = 0; + for (int i = 1; i <= n; i++) { + if (a[i] > 0 && a[i] <= k) c = min(c, abs(i - m)); + } + cout << 10 * c << endl; +} +int f(int n, int m) { + if (n % m != 0) + return int(n / m) + 1; + else + return n / m; +} +int main() { + int m, k, d[1004], s[1004]; + cin >> m >> k; + for (int i = 0; i < m; i++) cin >> d[i]; + for (int i = 0; i < m; i++) cin >> s[i]; + int t = 0, fuel = 0; + int mx = 0; + for (int i = 0; i < m; i++) { + mx = max(mx, s[i]); + fuel += s[i]; + while (fuel < d[i]) fuel += mx, t += k; + fuel -= d[i]; + t += d[i]; + } + cout << t << endl; +} +int main() { + int n; + string s; + cin >> n >> s; + int count = 0; + for (int i = 0; i < n - 1;) { + int j = 0; + for (j = i + 1; j < n;) { + if (s[i] == s[j]) { + count++; + j++; + } else + break; + } + i = j; + } + cout << count << endl; + return 0; +} +int main() { + int c, v0, v1, a, l, i = 0, res = 0; + cin >> c >> v0 >> v1 >> a >> l; + for (i = 0; res < c; i++) { + if (i > 0) res -= l; + res = res + min(v1, v0 + a * i); + } + cout << i << endl; + return (6 == 000000); +} +int main() { + int n, m; + cin >> n >> m; + cout << n + m - 1 << endl; + for (int i = 1; i <= m; i++) cout << "1 " << i << endl; + for (int i = 2; i <= n; i++) cout << i << " 1" << endl; +} +int n, m; +char a; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + cin >> a; + if (a == 'C' || a == 'M' || a == 'Y') { + cout << "#Color" << endl; + return 0; + } + } + cout << "#Black&White" << endl; + return 0; +} +int main() { + int a, b, sum = 0, sum2 = 0, n; + for (int i = 1; i <= 3; i++) { + cin >> a; + sum += a; + } + for (int i = 1; i <= 3; i++) { + cin >> b; + sum2 += b; + } + cin >> n; + int sa = sum / 5; + if (sum % 5 != 0) sa += 1; + int sb = sum2 / 10; + if (sum2 % 10 == 0) + sb += 0; + else + sb += 1; + if ((sa + sb) <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + string s; + cin >> s; + int flag = -1; + int sz = s.size(); + for (int i = 0; i < 26; i++) { + string a; + a.push_back('a' + i); + a += s; + for (int j = 0; j < sz; j++) { + string b = a; + reverse(b.begin(), b.end()); + if (a == b) { + cout << a << endl; + return 0; + } + swap(a[j], a[j + 1]); + } + string b = a; + reverse(b.begin(), b.end()); + if (a == b) { + cout << a << endl; + return 0; + } + } + cout << "NA" << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int c = (k / (m * 2)); + if ((k % (m * 2)) > 0) { c++; } + int first = (c - 1) * (2 * m) + 1; + int p = ((k - first) / 2) + 1; + char side = 'R'; + if (k % 2 != 0) { side = 'L'; } + cout << c << " " << p << " " << side << endl; + return 0; +} +int temp; +int main() { + int k; + int a[27][27]; + for (int i = 0; i <= 26; i++) + for (int j = 0; j <= 26; j++) a[i][j] = 0; + string s; + cin >> s; + cin >> k; + string b[14]; + for (int i = 0; i < k; i++) { cin >> b[i]; } + int count = 0; + int counta = 0; + int countb = 0; + for (int i = 0; i < k; i++) { + string cur = b[i]; + int start = -1; + int end = -1; + int flag = 0; + counta = countb = 0; + for (int j = 0; j < s.size(); j++) { + if (s[j] == cur[0] || s[j] == cur[1]) { + if (!flag) { + flag = 1; + start = i; + } + end = i; + if (s[j] == cur[0]) + counta++; + else + countb++; + } else { + flag = 0; + count += min(counta, countb); + counta = countb = 0; + } + } + count += min(counta, countb); + } + cout << count << "\n"; + return 0; +} +int main() { + long long int n, a, b, c; + while (cin >> n >> a >> b >> c) { + long long int ans; + int temp = n % 4; + if ((4 - temp) == 1) + ans = min(a, min(b + c, 3 * c)); + else if ((4 - temp) == 2) + ans = min(2 * a, min(b, 2 * c)); + else if ((4 - temp) == 3) + ans = min(3 * a, min(a + b, c)); + else if ((4 - temp) == 4) + ans = 0; + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + c = abs(a - c); + d = abs(b - d); + cout << max(c, d) << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int count = 0; + for (int i = 0; i < s.length(); i++) { + if (i < (s.length() - 1) && s[i] != s[i + 1]) { i++; } + count++; + } + cout << count << endl; + return 0; +} +char m[4][4]; +bool check(int i, int j) { + int cnt = 0, cnt2 = 0; + for (int k = i; k < i + 2; k++) { + for (int d = j; d < j + 2; d++) { + if (m[k][d] == '#') + ++cnt; + else + ++cnt2; + } + } + if (cnt == 3 || cnt == 4 || cnt2 == 3 || cnt2 == 4) return true; + return false; +} +int main() { + for (int i = 0; i < 4; i++) { + string s; + cin >> s; + for (int j = 0; j < 4; j++) { m[i][j] = s[j]; } + } + bool sol = false; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (check(i, j)) sol = true; + } + } + if (sol) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n, z; + long long int a = 0, b = 0, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> z; + if (z == 1) { + a++; + } else { + b++; + } + } + while ((a > 0) && (b > 0)) { + sum++; + a--; + b--; + } + while (a >= 3) { + sum++; + a = a - 3; + } + cout << sum << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + if (n % 2 == 0) { + if (k <= n / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * (k - n / 2) << endl; + } else { + if (k <= (n + 1) / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * (k - (n + 1) / 2) << endl; + } +} +int main() { + long long int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + long long int lef = c; + long long int d = 0; + while (lef > 0) { + if (d != 0) lef += l; + if (v0 + d * a <= v1) + lef -= (v0 + d * a); + else { + lef -= v1; + } + d++; + } + cout << d << endl; +} +int n, m, x[3], y[3], a; +bool diff(int i, int j) { + if (x[i] == x[j] || y[i] == y[j]) return false; + return true; +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + char c; + cin >> c; + if (c == '*') { + x[a] = i; + y[a] = j; + a++; + } + } + } + if (diff(0, 1)) { + if (x[2] == x[0]) + cout << x[1] << " " << y[0] << endl; + else + cout << x[0] << " " << y[1] << endl; + } else if (diff(1, 2)) { + if (x[0] == x[2]) + cout << x[1] << " " << y[2] << endl; + else + cout << x[2] << " " << y[1] << endl; + } else { + if (x[1] == x[0]) + cout << x[2] << " " << y[0] << endl; + else + cout << x[0] << " " << y[2] << endl; + } + return 0; +} +int main() { + int n; + string k; + int m, s = 0, maxx = -10000000; + cin >> n; + string a; + for (int i = 1; i <= n; i++) { + int x, y; + cin >> a; + cin >> x >> y; + int x1 = x * 100; + int y1 = y * 50; + for (int j = 1; j <= 5; j++) { + cin >> m; + s += m; + } + s += x1; + s -= y1; + if (maxx < s) { + maxx = s; + k = a; + } + s = 0; + } + cout << k << endl; + return 0; +} +int main() { + int y, b, r; + cin >> y >> b >> r; + if (y < 1 || y > 100 || b < 2 || b > 100 || r < 3 || r > 100) { return 0; } + if (y + 1 <= b && y + 2 <= r) + cout << 3 * y + 3 << endl; + else if (b - 1 <= y && b + 1 <= r) + cout << 3 * b << endl; + else if (r - 2 <= y && r - 1 <= b) + cout << 3 * r - 3 << endl; + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (a <= b) { + c++; + a *= 3; + b *= 2; + } + cout << c << endl; + return 0; +} +int main() { + int t, n, m; + cin >> n >> m; + t = n + m - 1; + cout << t << endl; + for (int i = 1; i <= m; i++) { cout << "1 " << i << endl; } + for (int i = 2; i <= n; i++) { cout << i << " 1" << endl; } + return 0; +} +int main() { + int n; + cin >> n; + int x[n], y[n], z[n]; + int xcost = 0, ycost = 0, zcost = 0; + for (int i = 0; i < n; i++) { + cin >> x[i] >> y[i] >> z[i]; + xcost += x[i]; + ycost += y[i]; + zcost += z[i]; + } + if (xcost == 0 && xcost == ycost && ycost == zcost) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const long long int MOD = 998244353; +long long int N, M, K, H, W, L, R; +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + N = abs(a - b) * d; + M = abs(a - c) * e; + M += abs(b - a) * e; + M += 3 * f; + if (N >= M) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int read(int x, int f) { + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int dp[1000][1000]; +int main() { + int n, m, b, mod; + cin >> n >> m >> b >> mod; + dp[0][0] = 1; + for (int i = 1; i <= n; i++) { + int x = read(0, 1); + for (int j = 1; j <= m; j++) + for (int t = x; t <= b; t++) dp[j][t] = (dp[j][t] + dp[j - 1][t - x]) % mod; + } + int ans = 0; + for (int i = 0; i <= b; i++) ans = (ans + dp[m][i]) % mod; + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool p = 0; + for (int i = 0; i < n - 1; i++) { + if (s[i] > s[i + 1]) { + p = 1; + break; + } + } + if (!p) { + for (int i = 0; i < n - 1; i++) { cout << s[i]; } + cout << endl; + return 0; + } + for (int i = 0; i < n - 1; i++) { + if (s[i] > s[i + 1]) { + for (int j = i + 1; j < n; j++) { cout << s[j]; } + cout << endl; + return 0; + } + cout << s[i]; + } + return 0; +} +int m, n; +int s, f, t; +int nap; +bool flag = true; +int et; +int temp; +int main() { + cin >> n >> m; + m--; + for (int i = 0; i < n; ++i) { + cin >> s >> f >> t; + if (s == f) { + cout << t << endl; + continue; + } + if (t <= m) { + flag = true; + et = t + 1; + } else { + if (t % m == 0) + nap = t / m; + else + nap = t / m + 1; + if (nap % 2 == 0) { + flag = false; + if (t % m != 0) + et = (m + 1) - (t % m); + else + et = 1; + } else { + flag = true; + if (t % m != 0) + et = 1 + (t % m); + else + et = m + 1; + } + } + if (s < f) { + if (et == s && flag) temp = f - s; + if (et == s && !flag) temp = (et - 1) * 2 + (f - s); + if (et < s && flag) temp = (f - s) + (s - et); + if (et < s && !flag) temp = (et - 1) * 2 + (f - s) + (s - et); + if (et > s && flag) temp = ((m + 1) - et) + m + f - 1; + if (et > s && !flag) temp = et - 1 + f - 1; + } + if (s > f) { + if (et == s && flag) temp = s - f + 2 * ((m + 1) - s); + if (et == s && !flag) temp = s - f; + if (et < s && flag) temp = m + 1 - et + (m + 1 - f); + if (et < s && !flag) temp = et - 1 + m + ((m + 1) - s) + (s - f); + if (et > s && flag) temp = m + 1 - et + (m + 1 - f); + if (et > s && !flag) temp = s - f + (et - s); + } + cout << temp + t << endl; + } + return 0; +} +int main() { + int n, d; + cin >> n >> d; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + int ans = 2; + for (int i = 0; i < n - 1; i++) { + int dist = abs(a[i] - a[i + 1]); + if (dist == 2 * d) + ans++; + else if (dist > 2 * d) + ans += 2; + } + cout << ans << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int cnt7 = 0, cnt4 = 0; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] != s2[i]) { + if (s2[i] == '7') + cnt7++; + else + cnt4++; + } + } + int mn = min(cnt4, cnt7); + cout << mn + (cnt4 - mn) + (cnt7 - mn) << endl; + return 0; +} +long long int n, m, a, b; +int main() { + cin >> n >> m >> a >> b; + long long int _s = 0; + if (n % m != 0) { + long long int x = (long long int)n / m * m + m; + long long int y = x - m; + _s = min((x - n) * a, (n - y) * b); + } + cout << _s << "\n"; + return 0; +} +int main() { + int k, n, w; + cin >> k >> n >> w; + n = n - ((w * (w + 1)) / 2) * k; + if (n < 0) { + cout << (-1 * n) << endl; + } else + cout << "0" << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > b && x < c) ans++; + } + cout << ans << '\n'; +} +vector ans; +long long palin(string a) { + long long n = a.length(); + for (long long i = 0; i < n; i++) { + if (a[i] != a[n - i - 1]) return 0; + } + return 1; +} +int main() { + string a; + cin >> a; + long long n = a.length(); + long long m = 1 << n; + for (long long i = 1; i < m; i++) { + string b; + for (long long j = 0; j < n; j++) { + if (((1 << j) & i) != 0) { b += a[j]; } + } + if (palin(b)) { ans.push_back(b); } + } + sort(ans.begin(), ans.end(), greater()); + cout << ans[0] << endl; + return 0; +} +int arr[3][3]; +char out[3][3]; +int main() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + int ans = arr[i][j]; + if (i - 1 >= 0) ans += arr[i - 1][j]; + if (i + 1 <= 2) ans += arr[i + 1][j]; + if (j - 1 >= 0) ans += arr[i][j - 1]; + if (j + 1 <= 2) ans += arr[i][j + 1]; + if (ans % 2 == 0) + out[i][j] = '1'; + else + out[i][j] = '0'; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << out[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string slogan; + cin >> slogan; + if (k == 1) { + for (int i = 0; i < n; i++) { + cout << "PRINT " << slogan[i] << endl; + if (i != n - 1) cout << "RIGHT\n"; + } + return 0; + } else if (k == n) { + for (int i = n - 1; i > -1; i--) { + cout << "PRINT " << slogan[i] << endl; + if (i != 0) cout << "LEFT\n"; + } + return 0; + } else { + if (k > n / 2) { + while (k++ != n) cout << "RIGHT\n"; + for (int i = n - 1; i > -1; i--) { + cout << "PRINT " << slogan[i] << endl; + if (i != 0) cout << "LEFT\n"; + } + return 0; + } + if (k <= n / 2) { + while (k-- != 1) cout << "LEFT\n"; + for (int i = 0; i < n; i++) { + cout << "PRINT " << slogan[i] << endl; + if (i != n - 1) cout << "RIGHT\n"; + } + return 0; + } + } +} +long long int n; +long long int a[1007]; +int main() { + cin >> n; + for (long long int i = 0; i <= n - 1; i++) { cin >> a[i]; } + long long int _min = INT_MAX; + for (long long int i = 1; i <= n - 2; i++) { + long long int _max = INT_MIN; + for (long long int j = 1; j <= n - 2; j++) { + long long int x = j; + long long int y = j + 1; + if (x == i) { + x--; + } else if (y == i) { + y++; + } + _max = max(_max, a[y] - a[x]); + } + _min = min(_max, _min); + } + cout << _min << "\n"; + return 0; +} +int f[105][105]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int a, b, c, d; + cin >> a >> b >> c >> d; + for (int j = a; j <= c; j++) { + for (int k = b; k <= d; k++) { f[j][k]++; } + } + } + int s = 0; + for (int i = 1; i <= 100; i++) { + for (int j = 1; j <= 100; j++) { s += f[i][j]; } + } + cout << s << endl; + return 0; +} +int a[10]; +int sum = 0; +int flag = 0; +int num = 0; +int main() { + for (int i = 0; i < 6; ++i) { + cin >> a[i]; + sum += a[i]; + if (a[i] == 0) ++num; + } + int temp = sum; + sum /= 2; + if (num == 6) + cout << "YES" << endl; + else { + if (sum == 0) cout << "NO" << endl; + if (temp % 2 != 0) + cout << "NO" << endl; + else { + for (int i = 0; i < 6; ++i) { + for (int j = i + 1; j < 6; ++j) { + for (int k = j + 1; k < 6; ++k) { + if ((a[i] + a[j] + a[k]) == sum) { + flag = 1; + break; + } + } + if (flag == 1) break; + } + if (flag == 1) break; + } + if (flag == 1) cout << "YES" << endl; + if (flag == 0) cout << "NO" << endl; + } + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long ans = (s / c) + ((s / c) / a) * b; + cout << ans << endl; + } + return 0; +} +int power(int a, int b, int modi) { + int res = 1; + while (b) { + if (b % 2) res = (res * a) % modi; + b /= 2; + a = (a * a) % modi; + } + return res; +} +int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int dx[] = {-1, 1, 0, 0}; +int dy[] = {0, 0, -1, 1}; +int k, sum = 0, ans = 0, cur = 0, x, y; +int n, m, r, c; +int a[1005]; +int main() { + int n, m; + cin >> n >> m; + int c = n; + int i = 1; + while (c >= i * m) { + c++; + i++; + } + cout << c << endl; + return 0; +} +int main() { + int n; + vector v; + string cur, prev, rec = "", store = ""; + cin >> n; + cin >> cur; + rec = cur; + for (int i = 1; i < n; i++) { + cin >> prev; + for (int j = 0; j < rec.size(); j++) { + if (prev[j] == rec[j]) + store += rec[j]; + else { + rec = store; + store.clear(); + store = ""; + break; + } + } + store.clear(); + store = ""; + } + cout << rec.size() << endl; +} +int main() { + long long n; + cin >> n; + int coun = 0; + string str; + for (n = n; n < 8888888890; n++) { + ostringstream temp; + temp << n; + str = temp.str(); + for (int i = 0; i < str.length(); i++) { + if (str[i] == '8') { + if (coun == 0) continue; + cout << coun << endl; + return 0; + } + } + coun++; + } +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k, l, r, co = 0; + long long n, m, t, a, b, c; + cin >> n; + k = sqrt(n); + for (i = k; i >= 1; i--) { + if (n % i == 0) { + cout << i << ' ' << n / i << endl; + break; + } + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b; + if (a < b) { + c = a; + d = (b - a) / 2; + cout << c << ' ' << d << endl; + } else { + c = b; + d = (a - b) / 2; + cout << c << ' ' << d << endl; + } + return 0; +} +int main() { + string a, b = "hello"; + int i = 0, j = 0, k = 0, l; + cin >> a; + while (i != a.size()) { + if (a[i] == b[j]) { + j++; + k++; + if (k == 5) break; + } + i++; + } + if (k == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 4 == 1 || i % 4 == 3) + for (int j = 1; j <= m; j++) cout << '#'; + if (i % 4 == 0) { + cout << '#'; + for (int i = 1; i <= m - 1; i++) cout << '.'; + } + if (i % 4 == 2) { + for (int i = 1; i <= m - 1; i++) cout << '.'; + cout << '#'; + } + cout << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long cnt = 0; + for (long long i = 0; i < n; ++i) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + cnt += (c - a + 1) * (d - b + 1); + } + cout << cnt << endl; +} +int i; +bool allAreSame(string S) { + bool flag = true; + i = 1; + while (S[i]) { + if (S[i] == '+') { + i++; + } else if (S[0] == S[i]) { + i++; + } else { + flag = false; + return flag; + } + } + return flag; +} +void printString(string S) { + cout << S[0]; + i = 1; + while (S[i]) { + if (S[i] != '+') { cout << "+" << S[i]; } + i++; + } + cout << endl; +} +int main() { + string S, S1 = "", S2 = "", S3 = ""; + cin >> S; + if (S.length() == 1) { + cout << S << endl; + return 0; + } + if (allAreSame(S)) { + printString(S); + return 0; + } + for (i = 0; i < S.length(); i++) { + if (S[i] == '1') + S1 += S[i]; + else if (S[i] == '2') + S2 += S[i]; + else if (S[i] == '3') + S3 += S[i]; + } + i = 0; + while (S1[i]) { + cout << S1[i]; + i++; + if (S1[i]) cout << "+"; + } + i = 0; + while (S2[i]) { + if (S1[0] == '1') { + cout << "+" << S2[i]; + } else + cout << S2[i]; + i++; + } + i = 0; + while (S3[i]) { + if (S1[0] == '1' || S2[0] == '2') + cout << "+" << S3[i]; + else + cout << S3[i]; + i++; + } + cout << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i; + int a[1000]; + int time = 0, k = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + k = k + (86400 - a[i]); + time = time + 1; + if (k >= m) { break; } + } + cout << time << endl; + return 0; +} +bool lucky(long long x) { + x = abs(x); + while (x) { + if (x % 10 == 8) return 1; + x /= 10; + } + return 0; +} +int main() { + long long a, b = 1; + cin >> a; + a++; + while (!lucky(a)) { a++, b++; } + cout << b << '\n'; +} +const int INF = 0x3f3f3f3f; +const int maxn = 120; +char str[maxn][maxn]; +int main() { + int n; + cin >> n; + int res = 0; + for (int i = 1; i <= n; i++) { + int ans = 0; + for (int j = 1; j <= n; j++) { + cin >> str[i][j]; + if (str[i][j] == 'C') ans++; + } + if (ans >= 2) { res += (ans * (ans - 1)) / 2; } + } + for (int i = 1; i <= n; i++) { + int ans = 0; + for (int j = 1; j <= n; j++) { + if (str[j][i] == 'C') ans++; + } + if (ans >= 2) res += (ans * (ans - 1)) / 2; + } + cout << res << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + cout << (s + n - 1) / n << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + double d = 360 / (180 - a); + if ((((d - 2) * 180) / d) == a) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int k, n, w, i, b, s = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { s += (k * i); } + if (s <= n) { + cout << "0" << endl; + } else { + b = (s - n); + cout << b << endl; + } + return 0; +} +int main() { + float A, C; + float max, min; + cin >> A >> C; + if (A == 0 && C == 0) { + max = 0; + min = 0; + } else if (A == 0) { + cout << "Impossible" << endl; + return 0; + } else if (C == 0) { + max = A; + min = A; + } else if (C < A) { + min = A; + max = A + (C - 1); + } else { + max = A + (C - 1); + min = C / A * A; + } + cout << min << " " << max << endl; + return 0; +} +int main() { + long long ax, ay, bx, by, cx, cy; + cin >> ax >> ay >> bx >> by >> cx >> cy; + long long ds = (bx * cy - by * cx) - (ax * cy - ay * cx) + (ax * by - ay * bx); + if (ds == 0) + cout << "TOWARDS"; + else if (ds < 0) + cout << "RIGHT"; + else + cout << "LEFT"; + cout << '\n'; +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + s = string(" ") + s; + if (k - 1 < n - k) { + while (k > 1) k--, cout << "LEFT\n"; + for (int i = 1; i <= n; i++) { + while (k < i) k++, cout << "RIGHT\n"; + cout << "PRINT " << s[i] << '\n'; + } + } else { + while (k < n) k++, cout << "RIGHT\n"; + for (int i = n; i >= 1; i--) { + while (k > i) k--, cout << "LEFT\n"; + cout << "PRINT " << s[i] << '\n'; + } + } +} +int n, m, a; +int main() { + cin >> n >> m; + if (n <= m) { + a = n; + } else { + a = m; + } + if (a % 2 == 1) { + cout << "Akshat" << endl; + } else { + cout << "Malvika" << endl; + } +} +int dp[100][3]; +int main() { + long long n, day; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> day; + v.push_back(day); + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { dp[i][j] = 1000; } + } + dp[0][0] = 1; + if (v[0] == 2 || v[0] == 3) dp[0][2] = 0; + if (v[0] == 1 || v[0] == 3) dp[0][1] = 0; + for (int i = 1; i < n; i++) { + dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1; + if (v[i] == 1 || v[i] == 3) dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + if (v[i] == 2 || v[i] == 3) dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } + cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << "\n"; +} +int main() { + int n, k1, k2, i; + cin >> n; + cin >> k1; + for (i = 1; i < n; i++) { + cin >> k2; + cout << k2 + k1 << " "; + k1 = k2; + } + cout << k1 << endl; + return 0; +} +int main() { + int x1, y1, x2, y2, xx, yy; + cin >> x1 >> y1 >> x2 >> y2 >> xx >> yy; + if (abs(x1 - x2) % xx != 0 || abs(y1 - y2) % yy != 0) { + cout << "NO" << endl; + } else { + if ((abs(x1 - x2) / xx) % 2 == abs(y1 - y2) / yy % 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +string s; +int l, r, cnt = 0; +int main() { + cin >> s; + s = s + '.'; + l = 0; + for (r = 0; r < int(s.length()); r++) { + if (s[r] != s[l]) { + if (!((r - l) & 1)) { cnt++; } + l = r; + } + } + cout << cnt << '\n'; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int i, a[105]; + memset(a, 0, sizeof(a)); + for (i = 1; i <= n; i++) { + int j; + cin >> j; + while (j--) { + int l; + cin >> l; + a[l] = 1; + } + } + int sum = 0; + for (i = 1; i <= m; i++) { + if (a[i] == 1) sum++; + } + if (sum == m) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } +} +int mod = (1e9) + 7; +int n; +const int N = 50; +int p[N], t[N]; +bool compare(int a, int b) { + if (p[a] > p[b]) return 1; + if (p[a] == p[b] && t[a] <= t[b]) return 1; + return 0; +} +bool eq(int a, int b) { + if (p[a] == p[b] && t[a] == t[b]) return 1; + return 0; +} +int main() { + int k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> p[i] >> t[i]; + a[i] = i; + } + stable_sort(a, a + n, compare); + int c = 1; + int i = k - 2; + while (i >= 0 && eq(a[k - 1], a[i])) { + c++; + i--; + } + i = k; + while (i < n && eq(a[k - 1], a[i])) { + c++; + i++; + } + cout << c << endl; +} +int n, j, minnum = 1000000002, ans = 100002; +int a[100005], flag[100005]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (minnum > a[i]) minnum = a[i]; + } + for (int i = 1; i <= n; i++) { + if (a[i] == minnum) { + j++; + flag[j] = i; + } + } + for (int i = 1; i < j; i++) + if (flag[i + 1] - flag[i] < ans) ans = flag[i + 1] - flag[i]; + cout << ans << endl; + return 0; +} +int main() { + int x[31]; + int y[31]; + int z[31][31]; + int n, m, i, j, k; + while (cin >> n) { + memset(x, 0, sizeof(x)); + memset(y, 0, sizeof(y)); + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { cin >> z[i][j]; } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + x[i] += z[i][j]; + y[i] += z[j][i]; + } + } + k = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (y[j] > x[i]) k++; + } + } + cout << k << endl; + } + return 0; +} +int main() { + int n, c, x; + cin >> n >> c; + vector v(n); + for (int i = 0; i < n; ++i) { cin >> v[i]; } + int res = 1; + for (int i = n - 1; i > 0; --i) { + if (v[i] - v[i - 1] > c) break; + res++; + } + cout << res << endl; + return 0; +} +int main() { + int n; + bool up = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n > 1) { + if (a[n - 1] > a[n - 2]) { up = 1; } + if (up) { + if (a[n - 1] == 15) { + cout << "DOWN" << '\n'; + } else { + cout << "UP" << '\n'; + } + } else { + if (a[n - 1] == 0) { + cout << "UP" << '\n'; + } else { + cout << "DOWN" << '\n'; + } + } + } else { + if (a[n - 1] == 15) { + cout << "DOWN" << '\n'; + } else if (a[n - 1] == 0) { + cout << "UP" << '\n'; + } else { + cout << -1 << '\n'; + } + } +} +string s1, s2; +string a1, a2; +int main() { + cin >> a1 >> a2; + int n; + cin >> n; + cout << a1 << " " << a2 << endl; + for (int i = 1; i <= n; i++) { + cin >> s1 >> s2; + if (s1 == a1) + a1 = s2; + else if (s1 == a2) + a2 = s2; + else if (s2 == a1) + a1 = s1; + else if (s2 == a2) + a2 = s1; + cout << a1 << " " << a2 << endl; + } + return 0; +} +int a[105]; +int b[105]; +int main() { + int n, c = 0, x = 0; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] > b[i]) + c++; + else if (a[i] < b[i]) + x++; + else if (a[i] = b[i]) { + c = c; + x = x; + } + } + if (c > x) { + cout << "Mishka" << endl; + } else if (x > c) { + cout << "Chris" << endl; + } else if (c == x) { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + s = '#' + s; + int n = s.length() - 1; + int cnt = 0; + for (int i = 1; i + i <= n; ++i) + if (s[i] != s[n - i + 1]) ++cnt; + if ((cnt <= 1 && (n & 1)) || cnt == 1) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + string *board = new string[8]; + bool can = true; + for (int i = 0; i < 8; i++) { + cin >> board[i]; + for (int j = 0; j < 7; j++) { + if (board[i][j] == board[i][j + 1]) { can = false; } + } + } + if (can == false) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n; + long long a, b, k, cur_pos; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> k; + if (k % 2 == 0) { + cur_pos = a * (k / 2) - b * (k / 2); + } else { + cur_pos = a * ((k / 2) + 1) - b * (k / 2); + } + cout << cur_pos << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if ((n % 3) == 1) n--; + if ((n % 3) == 2) n++; + n /= 3; + int feet = n / 12; + int inch = n % 12; + cout << feet << " " << inch << endl; + return 0; +} +const int max_n = 1e3 + 10; +int c[max_n], a[max_n]; +int n, m; +int point, ans; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[point] >= c[i]) { + point++; + ans++; + } + } + cout << ans << '\n'; + return 0; +} +int main() { + long long n, a; + cin >> n; + if (n % 2 == 0) + a = n / 2; + else + a = ((n + 1) / 2) * (-1); + cout << a << endl; + return 0; +} +int main() { + int a, b; + int n; + int tmp; + a = b = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> tmp; + if (tmp == 1) { + ++a; + } else { + ++b; + } + } + int cost = min(a, b); + cout << cost + (a - cost) / 3 << endl; + return 0; +} +int a, b, c, d, n; +string s; +int main() { + cin >> n; + pair arr[n]; + pair arr1[n]; + for (int i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; } + for (int i = 0; i < n; i++) { + if (arr[i].second == "rat") { cout << arr[i].first << endl; } + } + for (int i = 0; i < n; i++) { + if (arr[i].second == "woman" || arr[i].second == "child") { cout << arr[i].first << endl; } + } + for (int i = 0; i < n; i++) { + if (arr[i].second == "man") { cout << arr[i].first << endl; } + } + for (int i = 0; i < n; i++) { + if (arr[i].second == "captain") { cout << arr[i].first << endl; } + } +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +const double E = exp(1); +const int maxn = 1e6 + 10; +const int mod = 1e9 + 7; +int a[maxn], b[maxn]; +int vis[maxn]; +int main() { + int n, m; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int i = 0; i < m; i++) cin >> b[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) vis[b[j] / a[i]]++; + } + } + for (int i = maxn; i >= 0; i--) { + if (vis[i]) { + cout << vis[i] << endl; + break; + } + } + return 0; +} +int n, a[100001], mink = 2e9, pr = -1, mind = 2e9; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mink = min(mink, a[i]); + } + for (int i = 0; i < n; i++) { + if (pr != -1 && a[i] == mink) { mind = min(mind, i - pr); } + if (a[i] == mink) { pr = i; } + } + cout << mind << endl; +} +int main() { + int n, res = 0; + cin >> n; + int total = 0; + while (total < n) { + res++; + total += res * (res + 1) / 2; + } + if (total > n) { res--; } + cout << res << endl; + return 0; +} +int main() { + int n, c; + while (cin >> n >> c) { + int ans = 1, a[100000] = {0}; + cin >> a[0]; + for (int i = 1; i < n; i++) { + cin >> a[i]; + if ((a[i] - a[i - 1]) > c) + ans = 1; + else + ans++; + } + cout << ans << endl; + } + return 0; +} +int candidate[100]; +int main() { + int votes; + while (cin >> votes) { + for (int i = 0; i < votes; i++) cin >> candidate[i]; + bool cond = 1; + int ans = 0; + while (cond) { + int Max = 0; + cond = 0; + int x = 1; + for (int i = 1; i < votes; i++) { + if (candidate[i] > Max) { + Max = candidate[i]; + x = i; + } + } + if (Max >= candidate[0]) { + candidate[x]--; + candidate[0]++; + ans++; + cond = 1; + } else + cond = 0; + } + cout << ans << endl; + } + return 0; +} +int main() { + int s, a1, a2, b1, b2; + cin >> s >> a1 >> a2 >> b1 >> b2; + if (s * a1 + 2 * b1 == s * a2 + 2 * b2) { + cout << "Friendship" << endl; + } else if (s * a1 + 2 * b1 < s * a2 + 2 * b2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +int n, m, c, sm, sc; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m >> c; + if (m > c) + sm++; + else if (c > m) + sc++; + } + if (sm > sc) + cout << "Mishka" << endl; + else if (sc > sm) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + long long n, m, c, winm = 0, winc = 0; + cin >> n; + while (n--) { + cin >> m >> c; + if (m > c) + winm++; + else if (c > m) + winc++; + } + if (winm > winc) + cout << "Mishka" << endl; + else if (winc > winm) + cout << "Chris" << endl; + else if (winc == winm) + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int cnt = 0, ta, tb; + for (int i = 0; i < n; i++) { + cin >> ta >> tb; + if (cnt >= ta) cnt = max(cnt, tb); + } + cout << (cnt >= m ? "YES\n" : "NO\n"); + } + return 0; +} +int main() { + int i, n, p, sumA = 0, sumB = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p; + if (p >= 0) + sumA += p; + else + sumB += p; + } + cout << sumA - sumB << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n) { + string s; + cin >> s; + if (s.length() <= 10) + cout << s; + else { + cout << s[0]; + cout << s.length() - 2; + cout << s[s.length() - 1]; + } + cout << "\n"; + n--; + } +} +int main() { + int m, n, a, p = 1, cnt = 0; + cin >> m >> n; + int arr[m + 1]; + int arr1[n + 1]; + for (int i = 1; i <= m; i++) cin >> arr[i]; + for (int i = 1; i <= n; i++) { cin >> arr1[i]; } + for (int i = 1; p <= m && i <= n;) { + if (arr[p] <= arr1[i]) { + cnt++; + i++; + p++; + } else { + p++; + } + } + cout << cnt << endl; +} +int main() { + int n; + cin >> n; + int a[4] = {}; + int sh[4][n]; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + a[temp]++; + sh[temp][a[temp]] = i + 1; + } + int min1 = min(min(a[1], a[2]), a[3]); + cout << min1 << endl; + for (int i = 1; i <= min1; i++) { cout << sh[1][i] << " " << sh[2][i] << " " << sh[3][i] << endl; } +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "0\n"; + else + cout << "1\n"; +} +int main() { + int m, n; + cin >> m >> n; + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { + if (n == 6 || n == 7) + cout << 6 << endl; + else + cout << 5 << endl; + } + if (m == 4 || m == 6 || m == 9 || m == 11) { + if (n == 7) + cout << 6 << endl; + else + cout << 5 << endl; + } + if (m == 2) { + if (n == 1) + cout << 4 << endl; + else + cout << 5 << endl; + } + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + vector a; + int n, cost = 0, b, w; + cin >> n >> w >> b; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + a.push_back(temp); + } + int m = n / 2 - 1; + bool ac = true; + for (int i = 0; i <= m && ac; i++) { + if (a[i] == 2 && a[n - 1 - i] == 2) { + if (b < w) + cost += 2 * b; + else + cost += 2 * w; + } else { + if (a[i] == 2) { + if (a[n - 1 - i] == 0) + cost += w; + else + cost += b; + } else if (a[n - 1 - i] == 2) { + if (a[i] == 0) + cost += w; + else + cost += b; + } else { + if (a[i] != a[n - 1 - i]) ac = false; + } + } + } + if (!ac) + cout << -1 << endl; + else { + if (n % 2 != 0 && a[n / 2] == 2) { + if (b < w) + cost += b; + else + cost += w; + } + cout << cost << endl; + } + return 0; +} +int main() { + string t; + cin >> t; + for (int i = 0; i < 5; i++) { + string s; + cin >> s; + if (s[0] == t[0] || s[1] == t[1]) { return 0 * puts("YES"); } + } + puts("NO"); + return 0; +} +int main() { + long long x, y, z, k; + cin >> x >> y >> z >> k; + long long sum = z + x + y; + if (sum > k + 3) { sum = k + 3; } + long long ans = 1; + long long a[3]; + a[0] = x; + a[1] = y; + a[2] = z; + sort(a, a + 3); + if (sum == x + y + z) { + ans = x * y * z; + } else { + if (sum / 3 <= a[0]) { + ans *= sum / 3; + sum -= sum / 3; + } else { + ans *= a[0]; + sum -= a[0]; + } + if (sum / 2 <= a[1]) { + ans *= sum / 2; + sum -= sum / 2; + } else { + ans *= a[1]; + sum -= a[1]; + } + if (sum <= a[2]) { + ans *= sum; + sum = 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + long long int drink = (k * l) / nl; + long long int slice = (c * d) / 1; + long long int salt = p / np; + long long int min = INT_MAX; + if (drink <= slice && drink <= salt) { + min = drink; + } else if (salt <= slice && salt <= drink) { + min = salt; + } else if (slice <= drink && slice <= salt) { + min = slice; + } + if (min != INT_MAX) { + cout << min / n << endl; + } else { + cout << "0" << endl; + } +} +long long const mod = 1e9 + 7; +long long power(long long x, long long y, long long mod = 2e18) { + long long ans = 1; + x %= mod; + while (y) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y >>= 1; + } + return ans; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + long long n, id1, id2; + cin >> n >> id1 >> id2; + string second; + cin >> second; + if (second[id1 - 1] == second[id2 - 1]) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + long long n, m, z; + cin >> n >> m >> z; + long long kpk = (n * m) / __gcd(n, m); + cout << z / kpk << endl; + return 0; +} +int arr[105]; +int main() { + int m; + while (cin >> m) { + for (int i = 0; i < m; i++) cin >> arr[i]; + bool flag = 1; + int ans = 0; + while (flag) { + flag = 0; + int Max = -9999999; + int k = 1; + for (int i = 1; i < m; i++) { + if (arr[i] > Max) { + Max = arr[i]; + k = i; + } + } + if (Max >= arr[0]) { + arr[k]--; + arr[0]++; + ans++; + flag = 1; + } else + flag = 0; + } + cout << ans << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + long long a, b; + long long x = 0, y = 0, g = 0; + string s = "Dasha", t = "Masha", w = "Equal"; + cin >> a >> b; + if (a < b) { + swap(a, b); + swap(s, t); + } + g = gcd(a, b); + g = a * b / g; + for (int i = 1; i <= g; i++) { + if (a * i > g) break; + x++; + } + for (int i = 1; i <= g; i++) { + if (b * i > g) break; + if ((b * i) % a != 0) y++; + } + if (x == y) + cout << w << endl; + else if (x > y) + cout << s << endl; + else if (x < y) + cout << t << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +int main() { + int n, i, j, k; + int ls(0), rs(0), lc(0), rc(0); + cin >> n; + int l, r; + for (i = 0; i < n; i++) { + cin >> l >> r; + if (l % 2 == 1 && r % 2 == 0) lc++; + if (l % 2 == 0 && r % 2 == 1) rc++; + ls += l; + rs += r; + } + if (ls % 2 == 0 && rs % 2 == 0) { + cout << 0 << endl; + } else if ((ls % 2 == 1 && rs % 2 == 0) || (ls % 2 == 0 && rs % 2 == 1)) { + cout << -1 << endl; + } else if (ls % 2 == 1 && rs % 2 == 1) { + if (lc > 0 || rc > 0) { + cout << 1 << endl; + } else { + cout << -1 << endl; + } + } + return 0; +} +int x1, x2, x3, m; +int s[105] = {}; +int main() { + cin >> x1 >> x2 >> x3; + if (x1 > x2) { + m = x2; + x2 = x1; + x1 = m; + } + if (x1 > x3) { + m = x3; + x3 = x1; + x1 = m; + } + if (x2 > x3) { + m = x3; + x3 = x2; + x2 = m; + } + int i; + for (i = x1; i <= x3; i++) { s[i] = abs(i - x1) + abs(i - x2) + abs(i - x3); } + sort(s + x1, s + x3 + 1); + cout << s[x1] << endl; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (b) { + int d = b % 10; + c = c * 10 + d; + b /= 10; + } + cout << a + c << endl; + return 0; +} +const int dr[] = {-1, 1, 0, 0}; +const int dc[] = {0, 0, 1, -1}; +char datt[105][105]; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cin >> datt[i][j]; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (datt[i][j] == '.') { + if ((i + j) & 1) + datt[i][j] = 'W'; + else + datt[i][j] = 'B'; + } + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cout << datt[i][j]; } + cout << '\n'; + } + return 0; +} +int main() { + int n, m; + bool x = true; + cin >> n; + char arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + char a = arr[0][0]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j && arr[i][j] != a && arr[i][j] != '0') { + x = false; + break; + } + if (i == j && arr[i][j] == a) { arr[i][j] = '0'; } + if (i + j == n - 1 && arr[i][j] != a && arr[i][j] != '0') { + x = false; + break; + } + if (i + j == n - 1 && arr[i][j] == a) { arr[i][j] = '0'; } + } + } + if (x) { + bool y = true; + char b = arr[0][1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] != b && arr[i][j] != '0') { + y = false; + break; + } + } + } + if (y && a != b) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 0; j < m; j++) cout << "#"; + cout << endl; + } else if (i % 2 == 0 && i % 4 == 0) { + cout << "#"; + for (int j = 1; j < m; j++) cout << "."; + cout << endl; + } else if (i % 2 == 0 && i % 4 != 0) { + for (int j = 1; j < m; j++) cout << "."; + cout << "#" << endl; + } + } + return 0; +} +const int MAX = 100000; +const int INF = 1000000001; +int a[MAX]; +int n, s, sum = 0; +int main() { + int count = 0, temp; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> temp; + a[temp] = temp; + } + for (int i = 1; i <= 601; ++i) + if (a[i]) count++; + cout << count << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + cout << min(b + 1, n - a) << endl; +} +int main() { + int n; + cin >> n; + int ans = 1; + for (int i = 0; i < n; ++i) { + int a; + cin >> a; + if (a == 1) ans = -1; + } + cout << ans << endl; +} +long long n, m; +long long a[2002]; +long long sum, maxm; +bool check(long long x) { + long long summ = 0; + for (long long i = 1; i <= n; i++) { summ += max(0LL, x - a[i]); } + return summ >= m; +} +long long bs() { + long long lo = maxm; + long long hi = 1e9; + while (hi > lo) { + long long mid = lo + (hi - lo) / 2; + if (check(mid)) + hi = mid; + else + lo = mid + 1; + } + return lo; +} +int main() { + cin >> n >> m; + for (long long i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + maxm = max(maxm, a[i]); + } + long long tot = sum + m; + long long xx = tot / n; + tot -= (xx * n); + if (tot > 0) + tot = xx + 1; + else + tot = xx; + tot = bs(); + cout << tot << " "; + cout << maxm + m << endl; + return 0; +} +int main() { + int n, a, count = 0; + cin >> n >> a; + for (int i = 1; i <= n; i++) { + if (a % i == 0 && (a / i) <= n) { count++; } + } + cout << count << endl; + return 0; +} +map my; +set a; +int main() { + int n, m, Min, Max; + cin >> n >> m >> Min >> Max; + int mini = 1e9, maxa = -1e9; + for (int i = 0; i < m; i++) { + int t; + cin >> t; + mini = min(t, mini); + maxa = max(t, maxa); + } + if (maxa > Max || mini < Min) { + cout << "Incorrect" << endl; + return 0; + } + if (maxa != Max) n--; + if (mini != Min) n--; + if (n - m < 0) + cout << "Incorrect" << endl; + else + cout << "Correct" << endl; +} +int main() { + long long x, y, n, c; + cin >> n; + x = n - 1; + y = 1; + c = 1; + while (x > 0) { + c++; + if (x * x + y * y + 2 * y + 1 < n * n + 1) + y++; + else { + if (x * x - 2 * x + y * y + 2 * y + 2 < n * n + 1) { + x = x - 1; + y++; + } else { + x = x - 1; + } + } + } + if (n == 0) { + cout << 1 << endl; + } else { + cout << 4 * c << endl; + } +} +int main() { + int n; + cin >> n; + n -= 10; + if (n == 10) return cout << 15 << endl, 0; + if (n <= 11 && n >= 1) return cout << 4 << endl, 0; + cout << 0 << endl; +} +int main() { + vector rats; + vector WandC; + vector men; + vector captain; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + string s, h; + cin >> s >> h; + if (h == "rat") + rats.push_back(s); + else if (h == "woman" || h == "child") + WandC.push_back(s); + else if (h == "man") + men.push_back(s); + else + captain.push_back(s); + } + for (int i = 0; i < rats.size(); i++) { cout << rats[i] << endl; } + for (int i = 0; i < WandC.size(); i++) { cout << WandC[i] << endl; } + for (int i = 0; i < men.size(); i++) { cout << men[i] << endl; } + for (int i = 0; i < captain.size(); i++) { cout << captain[i] << endl; } + return 0; +} +int main() { + int n, t = 0, temp = 0; + long long ans = 0; + cin >> n; + int a[n]; + vector b; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 != 0) { + b.push_back(a[i]); + } else { + ans += a[i]; + } + } + sort(b.begin(), b.end()); + int y = b.size(); + if (y % 2 == 0) { + for (int i = 0; i < y; i++) { ans += b[i]; } + } else { + for (int i = 1; i < y; i++) { ans += b[i]; } + } + cout << ans << '\n'; +} +int main() { + int n, a = 0, c = 1; + cin >> n; + if (n > 5) { + a = n / 5; + if (n % 5 == 0) a--; + } + c += a; + cout << c << endl; +} +inline long long quick_pow(long long a, long long b) { + long long ans = 1; + while (b) { + if (b % 2) { + ans = ans * a; + ans %= 1000000007; + } + a *= a; + a %= 1000000007; + b >>= 1; + } + return ans; +} +inline long long C(int n, int m) { + if (n == m) return 1; + long long ans = 1; + for (long long i = n - m + 1; i <= n; i++) { ans = (ans * i) % 1000000007; } + for (long long i = 1; i <= m; i++) { ans = (ans * quick_pow(i, 1000000007 - 2)) % 1000000007; } + return ans; +} +int main() { + int k; + int a[1002]; + int sum[1002]; + cin >> k; + for (int i = 0; i < k; i++) { + cin >> a[i]; + if (i == 0) { + sum[i] = a[i]; + } else { + sum[i] = sum[i - 1] + a[i]; + } + } + int cnt, ans; + ans = 1; + for (int i = k; i >= 0; i--) { ans = (ans * C(sum[i] - 1, a[i] - 1)) % 1000000007; } + cout << ans << endl; + return 0; +} +int n1, n, i, s1, s2; +int main() { + cin >> n1; + n = n1 / 2; + int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 0; i < n; i++) { + if (a[i] % 2 == 1) { + if (1 + 2 * i != a[i]) s1 += abs(1 + 2 * i - a[i]); + s2 += abs(2 * (i + 1) - a[i]); + } else { + if (2 * (i + 1) != a[i]) s2 += abs(2 * (i + 1) - a[i]); + s1 += abs(1 + 2 * i - a[i]); + } + } + cout << min(s1, s2) << endl; +} +int compare(const void *x1, const void *x2) { + return (*(int *)x1 - *(int *)x2); +} +int main() { + int N; + int final; + cin >> N; + int massiv[N]; + int d; + int R; + for (R = 0; R < N; R++) { + cin >> d; + massiv[R] = d; + } + qsort(massiv, N, sizeof(int), compare); + if (N % 2 == 0) { + final = massiv[R / 2 - 1]; + } else { + final = massiv[R / 2]; + } + cout << final << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + if (s1 == s2) { + cout << "-1\n"; + } else { + cout << max(s1.size(), s2.size()) << '\n'; + } + return 0; +} +int main() { + int i, n; + string s[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cin >> n; + n--; + while (n >= 5) { + n = n - 5; + n = n / 2; + } + cout << s[n] << endl; +} +int main() { + int n, m; + cin >> n >> m; + vector a(n); + vector b(m); + for (int i = 0; i < n; ++i) { cin >> a[i]; } + for (int i = 0; i < m; ++i) { cin >> b[i]; } + int ans = 100500; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + if (a[i] == b[j]) { + ans = min(ans, a[i]); + } else { + ans = min(ans, a[i] * 10 + b[j]); + ans = min(ans, b[j] * 10 + a[i]); + } + } + } + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + vector good(n, 1); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int x; + cin >> x; + if (x <= 0) + continue; + else if (x == 1) + good[i] = 0; + else if (x == 2) + good[j] = 0; + else + good[i] = good[j] = 0; + } + } + vector sol; + for (int i = 0; i < n; i++) + if (good[i]) sol.push_back(i + 1); + cout << sol.size() << endl; + if (sol.size() > 0) { + for (int i = 0; i < sol.size(); i++) { + if (i != 0) cout << ' '; + cout << sol[i]; + } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string marks[n]; + int h_marks[m], s[111], count = 0; + memset(s, 0, sizeof(s)); + for (int i = 0; i < n; i++) cin >> marks[i]; + for (int i = 0; i < m; i++) { + h_marks[i] = -1; + for (int j = 0; j < n; j++) h_marks[i] = max(h_marks[i], marks[j][i] - 48); + } + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (marks[j][i] - 48 == h_marks[i]) s[j]++; + } + } + for (int i = 0; i <= 110; i++) + if (s[i] > 0) count++; + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += x; + } + int m; + cin >> m; + for (int i = 0; i < m; i++) { + int l, r; + cin >> l >> r; + if (l >= sum) { + cout << l << '\n'; + return 0; + } + if (sum >= l && sum <= r) { + cout << min((long long)r, sum) << '\n'; + return 0; + } + } + cout << -1 << '\n'; + return 0; +} +int main() { + long n, arreglo[1000]; + set s; + cin >> n; + for (long i = 0; i < n; i++) { + cin >> arreglo[i]; + if (arreglo[i] != 0) s.insert(arreglo[i]); + } + cout << s.size() << endl; + return 0; +} +const int N = 1e5 + 5; +int main() { + int m, arr[104] = {}; + cin >> m; + for (int i = 1; i <= m; ++i) cin >> arr[i], arr[i] += arr[i - 1]; + int x, y; + cin >> x >> y; + for (int i = 1; i <= m; ++i) { + int co = arr[m] - arr[i]; + if (arr[i] >= x && arr[i] <= y && co >= x && co <= y) return cout << i + 1 << "\n", 0; + } + return cout << 0 << "\n", 0; + return 0; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int x; + cin >> x; + for (int y = x / 2; y > 0; y--) { + for (int z = 0; z < y; z++) { cout << '*'; } + for (int z = 0; z < (x - 2 * y); z++) { cout << 'D'; } + for (int z = 0; z < y; z++) { cout << '*'; } + cout << '\n'; + } + for (int y = 0; y < x; y++) { cout << 'D'; } + cout << '\n'; + for (int y = 1; y <= (x / 2); y++) { + for (int z = 0; z < y; z++) { cout << '*'; } + for (int z = 0; z < (x - 2 * y); z++) { cout << 'D'; } + for (int z = 0; z < y; z++) { cout << '*'; } + cout << '\n'; + } +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int arr[100 + 4]; +map, int> ms; +void hora(int tc) { + int n, m; + cin >> n >> m; + int cost = 1e9; + for (int i = 1; i <= n; i++) cin >> arr[i]; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + if (u > v) swap(u, v); + ms[{u, v}] = 1; + } + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + for (int k = j + 1; k <= n; k++) { + if (ms[{i, j}] == 0 || ms[{j, k}] == 0 || ms[{i, k}] == 0) continue; + cost = min(cost, arr[i] + arr[j] + arr[k]); + } + } + } + if (cost == 1e9) cost = -1; + cout << cost << '\n'; +} +int main() { + desperate_optimization(10); + int ntc = 1; + for (int tc = 1; tc <= ntc; tc++) hora(tc); + return 0; +} +int main() { + int n; + cin >> n; + int minP = 1e5 + 1; + int p, a; + long long ans = 0; + for (int i = 0; i < n; i++) { + cin >> a >> p; + minP = min(minP, p); + ans += a * minP; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << "2\n"; + else + cout << "1\n"; + return 0; +} +char z[1000005]; +long long n, m; +string str; +long long pf(long long); +long long bfs(vector v[], long long a[], long long i) { + long long l = 0, k = 0; + for (long long int j = 0; j < v[i].size(); j++) { + if (a[v[i][j]] == 0) { + k = 1; + a[v[i][j]] = 1; + l = max(l, bfs(v, a, v[i][j]) + 1); + } + } + if (k == 0) + return 1; + else + return l; +} +void solve() { + long long m, k = 1, i, y = 0, j, c = 0, x = 0, w, x2, y2, r, d, h = 0; + string s, s2; + cin >> n; + long long vis[n] = {0}; + vector v[n], a; + for (long long int i = 0; i < n; i++) { + cin >> x; + a.push_back(x); + if (x != -1) { + v[i].push_back(x - 1); + v[x - 1].push_back(i); + } + } + for (long long int i = 0; i < n; i++) { + vis[i] = 1; + if (a[i] == -1) h = max(h, bfs(v, vis, i)); + memset(vis, 0, sizeof(vis)); + } + cout << h; +} +int main() { + int TESTS = 1; + while (TESTS--) { + solve(); + cout << "\n"; + } + return 0; +} +int main() { + long long a, b, c, d, x = 0, y = 0, l = 1, n, z = 0; + cin >> a >> b; + c = a + b; + while (a != 0) { + n = a % 10; + if (n != 0) { + x += (n * l); + l *= 10; + } + a /= 10; + } + l = 1; + while (b != 0) { + n = b % 10; + if (n != 0) { + y += (n * l); + l *= 10; + } + b /= 10; + } + d = x + y; + l = 1; + while (c != 0) { + n = c % 10; + if (n != 0) { + z += (n * l); + l *= 10; + } + c /= 10; + } + if (z == d) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int red, blue; + red = blue = 0; + red = 0; + blue = 1; + for (int i = 1; i <= n - 1; i++) + if (i & 1) + red = (red + blue + 1) % 1000000007; + else + blue = (red + blue + 1) % 1000000007; + cout << (red + blue) % 1000000007 << endl; + return 0; +} +int x, y, z, k; +long long ans = 1; +int main() { + cin >> x >> y >> z >> k; + if (x < y) swap(x, y); + if (x < z) swap(x, z); + if (y < z) swap(y, z); + int t = min(z - 1, k / 3); + ans = ans * (t + 1); + k -= t; + t = min(y - 1, k / 2); + ans = ans * (t + 1); + k -= t; + t = min(x - 1, k); + ans = ans * (t + 1); + k -= t; + cout << ans << endl; +} +void solve() { + long long a1, a2, b1, b2, c1, c2; + cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; + long long d = (b1 - a1) * (c2 - a2) - (b2 - a2) * (c1 - a1); + if (d == 0) { + cout << "TOWARDS" << endl; + } else if (d > 0) { + cout << "LEFT" << endl; + } else { + cout << "RIGHT" << endl; + } +} +int main() { + cout << setprecision(12) << fixed; + solve(); + return 0; +} +int a[110]; +int main() { + int n, sum1 = 0, sum2 = 0, sum = 0; + cin >> n; + for (int i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + n / 2 + 1); + int t = 1; + for (int i = 1; i <= n; i += 2) { sum1 += abs(a[t++] - i); } + t = 1; + for (int i = 2; i <= n; i += 2) sum2 += abs(a[t++] - i); + sum = min(sum1, sum2); + cout << sum << endl; + return 0; +} +int ara[110]; +int main() { + int n, k, x; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> ara[i]; + int ans = 0; + int cnt = 0; + for (int i = n - 1; i >= 0; i--) { + if (cnt < k and ara[i] >= x) { + cnt++; + ans += x; + } else + ans += ara[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int gcd = 0, n[1000], i, t; + cin >> t; + for (i = 0; i < t; i++) { + cin >> n[i]; + gcd = __gcd(gcd, n[i]); + } + cout << t * gcd << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool r = true; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 1; j <= m; j++) cout << "#"; + } else { + if (r) { + for (int j = 1; j < m; j++) cout << "."; + cout << "#"; + r = false; + } else { + r = true; + cout << "#"; + for (int j = 2; j <= m; j++) cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + int num, ar[10000], a, b, c, ct; + while (cin >> num) { + ct = 0; + for (int i = 0; i < num; i++) { cin >> ar[i]; } + for (int i = 0; i < num; i++) { + a = ar[i]; + b = ar[a - 1]; + c = ar[b - 1]; + if (i == c - 1) { + ct = 1; + break; + } + } + if (ct == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + cout << n - max(a + 1, n - b) + 1 << endl; +} +const int arr = 4 * 1e5; +const int md = 1e9 + 7; +int pref[2600][2600]; +int n, m; +int solve(int u) { + int res = 0; + for (int i = 0; i < n; i += u) + for (int j = 0; j < m; j += u) { + int l1 = i; + int l2 = j; + int r1 = min(n, i + u); + int r2 = min(m, j + u); + int now = pref[r1][r2] - pref[r1][l2] - pref[l1][r2] + pref[l1][l2]; + res += min(now, u * u - now); + } + return (res); +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + string st; + cin >> st; + for (int j = 0; j < st.size(); j++) pref[i][j + 1] = st[j] - '0'; + } + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + pref[i][j]; + int ans = 1e9; + for (int k = 2; k <= max(n, m); k++) ans = min(ans, solve(k)); + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + string x[n]; + set huruf[n]; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + for (int j = 0; j < a.length(); j++) huruf[i].insert(a[j]); + x[i] = a; + } + int big = 0; + for (int i = 0; i < 26; i++) { + for (int j = i + 1; j < 26; j++) { + int nilai = 0; + for (int k = 0; k < n; k++) { + char letter1 = 'a' + i; + char letter2 = 'a' + j; + if ((huruf[k].size() == 1)) { + if (huruf[k].count(letter1) != 0 || huruf[k].count(letter2) != 0) nilai += x[k].length(); + } else if ((huruf[k].size() == 2)) { + if (huruf[k].count(letter1) != 0 && huruf[k].count(letter2) != 0) nilai += x[k].length(); + } + } + big = max(big, nilai); + } + } + cout << big << endl; +} +int main() { + char s[81]; + char enc[11][11]; + char t[12]; + gets(s); + for (int i = 0; i < 10; i++) gets(enc[i]); + for (int i = 0; i < 8; i++) { + long long int j = i * 10; + strncpy(t, s + j, 10); + t[10] = '\0'; + for (int k = 0; k < 10; k++) { + if (!strcmp(enc[k], t)) { + cout << k; + break; + } + } + } + cout << endl; + return 0; +} +int n, m; +int x, ans = 1, maxt = -1; +int city[110]; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; ++i) { + int k = 1, mt = -1; + for (int j = 1; j <= n; ++j) { + cin >> x; + if (x > mt) { + mt = x; + k = j; + } + } + ++city[k]; + } + int maxc = 0; + for (int i = 1; i <= n; ++i) { + if (city[i] > maxc) { + ans = i; + maxc = city[i]; + } + } + cout << ans << endl; + return 0; +} +int main() { + char num; + int n = 0; + while (num != '\n') { + num = getchar(); + if (n == 0 && num == '9') { + cout << num; + } else if (num >= '5') { + cout << '9' - num; + } else + cout << num; + n++; + } + return 0; +} +int main() { + int n; + cin >> n; + vector count(101); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + ++count[x]; + } + cout << *max_element(count.begin(), count.end()) << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + cout << max(0, 3 * n - k) << endl; +} +const int maxn = 1e6 + 10, maxm = 2e6 + 10; +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double PI = acos(-1.0); +int casn, n, m, k; +set ans; +int main() { + string s, ss; + cin >> s; + ss = s + s; + int n = s.size(); + for (int i = 0; i <= n - 1; ++i) { + string t = ""; + for (int j = 0; j <= n - 1; ++j) { t += ss[i + j]; } + ans.insert(t); + } + cout << ans.size() << '\n'; + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + int a[26] = {0}; + for (int i = 0; i < n; i++) { + a[s[i] - 'a']++; + if (a[s[i] - 'a'] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + long long int x, y; + cin >> x >> y; + if (x > 0 && y > 0) { + cout << "0 " << x + y << " " << x + y << " 0" << endl; + } else if (x > 0 && y < 0) { + cout << "0 " << y - x << " " << x - y << " 0" << endl; + } else if (x < 0 && y > 0) { + cout << x - y << " 0 0 " << y - x << endl; + } else if (x < 0 && y < 0) { + cout << x + y << " 0 0 " << x + y << endl; + } +} +int main() { + string s, t; + cin >> s >> t; + int i = 0; + int index = 0; + while (i < t.length()) { + if (t[i] == s[index]) index++; + i++; + } + cout << index + 1 << endl; +} +int main() { + int n, k; + cin >> n >> k; + int numbers[1000]; + int numbers2[1000]; + for (int i = 0; i < n; i++) { cin >> numbers[i]; } + for (int i = 0; i < k; i++) { cin >> numbers2[i]; } + if (k > 1) { + cout << "Yes" << endl; + } else { + bool yes = false; + if (k == 1) { + for (int i = 0; i < n; i++) { + if (numbers[i] == 0) { + numbers[i] = numbers2[0]; + break; + } + } + } + for (int i = 0; i < n - 1; i++) { + if (numbers[i + 1] < numbers[i]) { + yes = true; + break; + } + } + if (yes) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + } + cin.get(); + cin.get(); + return 0; +} +int main() { + int i = 0, j = 0, a[3][3], b[3][3], t1 = 0, t2 = 0, t3 = 0; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + cin >> a[i][j]; + b[i][j] = 1; + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (a[i][j] % 2 == 1) { + if (i == 0 && j == 0) { + b[0][0] = 3 % (b[0][0] + 2); + b[0][1] = 3 % (b[0][1] + 2); + b[1][0] = 3 % (b[1][0] + 2); + } else if (i == 0 && j == 1) { + b[0][1] = 3 % (b[0][1] + 2); + b[0][0] = 3 % (b[0][0] + 2); + b[0][2] = 3 % (b[0][2] + 2); + b[1][1] = 3 % (b[1][1] + 2); + } else if (i == 0 && j == 2) { + b[0][1] = 3 % (b[0][1] + 2); + b[0][2] = 3 % (b[0][2] + 2); + b[1][2] = 3 % (b[1][2] + 2); + } else if (i == 1 && j == 0) { + b[0][0] = 3 % (b[0][0] + 2); + b[1][0] = 3 % (b[1][0] + 2); + b[1][1] = 3 % (b[1][1] + 2); + b[2][0] = 3 % (b[2][0] + 2); + } else if (i == 1 && j == 1) { + b[0][1] = 3 % (b[0][1] + 2); + b[1][1] = 3 % (b[1][1] + 2); + b[2][1] = 3 % (b[2][1] + 2); + b[1][0] = 3 % (b[1][0] + 2); + b[1][2] = 3 % (b[1][2] + 2); + } else if (i == 1 && j == 2) { + b[0][2] = 3 % (b[0][2] + 2); + b[1][1] = 3 % (b[1][1] + 2); + b[1][2] = 3 % (b[1][2] + 2); + b[2][2] = 3 % (b[2][2] + 2); + } else if (i == 2 && j == 0) { + b[2][0] = 3 % (b[2][0] + 2); + b[1][0] = 3 % (b[1][0] + 2); + b[2][1] = 3 % (b[2][1] + 2); + } else if (i == 2 && j == 1) { + b[2][1] = 3 % (b[2][1] + 2); + b[2][0] = 3 % (b[2][0] + 2); + b[2][2] = 3 % (b[2][2] + 2); + b[1][1] = 3 % (b[1][1] + 2); + } else if (i == 2 && j == 2) { + b[2][1] = 3 % (b[2][1] + 2); + b[1][2] = 3 % (b[1][2] + 2); + b[2][2] = 3 % (b[2][2] + 2); + } + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { cout << b[i][j]; } + cout << "\n"; + } + return 0; +} +const int max_n = 100 + 10; +long long a[max_n]; +short int n; +long long ans = 1e3, x; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n - 1; i++) { + for (int j = 1; j < n; j++) { + if (j == i) + x = max(a[j + 1] - a[j - 1], x); + else if (j - 1 != i) + x = max(a[j] - a[j - 1], x); + } + ans = min(ans, x); + x = 0; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, m, flag = 1; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) + cout << '#'; + else if (flag == 1) { + if (j != m) cout << '.'; + if (j == m) { + cout << '#'; + flag = 0; + } + } else if (flag == 0) { + if (j == 1) cout << '#'; + if (j != 1) { + cout << '.'; + if (j == m) flag = 1; + } + } + } + cout << '\n'; + } + return 0; +} +int main() { + string s1, s2, s3, s4; + cin >> s1 >> s2; + long long int n; + cin >> n; + map mp; + for (int i = 0; i < n; i++) { + cout << s1 << " " << s2 << endl; + cin >> s3 >> s4; + if (s1 == s3) + s1 = s4; + else + s2 = s4; + } + cout << s1 << " " << s2 << endl; + return 0; +} +int main() { + string a; + int n; + cin >> a; + cin >> n; + int kiek[26] = {0}; + if (a.size() < n) { + cout << "impossible" << endl; + return 0; + } + for (int i = 0; i < a.size(); i++) { kiek[a[i] - 'a']++; } + int k = 0; + for (int i = 0; i < 26; i++) { + if (kiek[i] >= 1) k++; + } + if (k < n) + cout << n - k << endl; + else + cout << "0" << endl; + ; + return 0; +} +int n, i; +int main() { + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + if (n == 1) { + cout << a[0] << endl; + return 0; + } else if (n == 3) { + cout << a[1] << endl; + return 0; + } else { + cout << a[2] << endl; + } + return 0; +} +int main() { + int n, c = 0; + cin >> n; + int mid = n / 2 + 1; + for (int i = 0; i < n; i++) { + for (int j = 1; j <= abs(mid - i - 1); j++) cout << "*"; + for (int j = abs(mid - i - 1); j < n - (abs(mid - i - 1)); j++) cout << "D"; + for (int j = n - (abs(mid - i - 1)); j < n; j++) cout << "*"; + cout << endl; + } +} +char a[101][101]; +string b; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> b; + for (int j = 1; j <= m; j++) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + if (b[j - 1] == '-') a[i][j] = '-'; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +long long int n, sum; +int main() { + cin >> n >> sum; + long long int ans = 0; + for (int i = n; i >= 1; i--) { + ans += sum / i; + sum -= (sum / i) * i; + } + cout << ans << '\n'; +} +long long n, ans = 0, a[111], vis[100010]; +inline long long read() { + long long x = 0; + bool f = 0; + char ch = getchar(); + for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); + for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); + return f ? -x : x; +} +int main() { + n = read(); + for (register int i = 1; i <= n; i++) a[i] = read(), vis[a[i]]++; + for (register int i = 1; i <= n; i++) + if (ans < vis[a[i]]) ans = vis[a[i]]; + cout << ans << endl; + return 0; +} +const int T = 200; +bool vis[T]; +int close(string x, string y) { + int ans = 0; + for (int i = 0; i < x.size(); i++) + if (x[i] != y[i]) ans++; + return ans; +} +int main() { + string s[T]; + string t[T]; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) cin >> t[i]; + for (int i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + sort(t, t + n); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (t[i] == s[j] and !vis[j]) { + vis[j] = true; + break; + } + } + } + for (int i = 0; i < n; i++) + if (!vis[i]) ans++; + cout << ans << endl; + return 0; +} +int main() { + char str[110]; + cin >> str; + int flag1 = 0, flag2 = 0, flag3 = 0; + int len = strlen(str); + if (len >= 5) { + for (int i = 0; i < len; i++) { + if (islower(str[i])) + flag1 = 1; + else if (isupper(str[i])) + flag2 = 1; + else if (isdigit(str[i])) + flag3 = 1; + } + if (flag1 && flag2 && flag3) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + } else + cout << "Too weak" << endl; + return 0; +} +long long b, c, d, i, n, a[10001]; +int main() { + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +int main() { + string input; + bool can = true; + for (int i = 0; i < 8; i++) { + cin >> input; + for (int j = 0; j < 7; j++) { + if (input[j] == input[j + 1]) { + can = false; + break; + } + } + } + if (can == false) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int t, k; + cin >> t; + for (k = 0; k < t; k++) { + int i, n; + char a[102]; + cin >> a; + n = strlen(a) - 2; + if (n + 2 <= 10) + cout << a; + else + cout << a[0] << n << a[n + 1]; + cout << '\n'; + } +} +const int maxn = 1e5 + 10; +int main() { + int n, m; + int a[105], b[105], index, max; + while (cin >> n >> m) { + int c[105]; + memset(c, 0, sizeof c); + for (int i = 0; i < m; i++) { + index = -1, max = -1; + for (int j = 0; j < n; j++) { + cin >> a[j]; + if (a[j] > max) { + max = a[j]; + index = j; + } + } + c[index + 1]++; + } + index = -1, max = -1; + for (int i = 1; i <= n; i++) { + if (c[i] > max) { + max = c[i]; + index = i; + } + } + cout << index << endl; + } + return 0; +} +int main() { + int array_size; + int array_value; + int result = 0; + vector array_positivo(100005, 0); + vector array_negativo(100005, 0); + cin >> array_size; + for (int i = 0; i < array_size; i++) { + cin >> array_value; + if (array_value > 0) { + if (array_positivo[array_value] == 0) { + array_positivo[array_value]++; + result++; + } + } else { + if (array_value < 0) { + array_value = array_value * -1; + if (array_negativo[array_value] == 0) { + array_negativo[array_value]++; + result++; + } + } + } + } + cout << result << endl; + return 0; +} +int main() { + int a[101]; + int n, i; + bool bo = true; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + int k = 3; + for (i = 0; i < n; i++) + if (a[i] == k) { + cout << "NO" << endl; + bo = false; + break; + } else + k = 6 - k - a[i]; + if (bo) cout << "YES" << endl; + return 0; +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x * x) % m; + if (b % 2) x = (x * a) % m; + return x; +} +int main() { + string ss; + cin >> ss; + int kk; + cin >> kk; + string a[kk + 2]; + for (int i = 0; i < kk; i++) cin >> a[i]; + int an = 0; + for (int i = 0; i < kk; i++) { + int p = 0; + int c = 0; + for (int x = 0; x < ss.size(); x++) + if (ss[x] == a[i][0] || ss[x] == a[i][1]) { + p = 0; + c = 0; + while (ss[x] == a[i][0] || ss[x] == a[i][1]) { + if (ss[x] == a[i][0]) + c++; + else if (ss[x] == a[i][1]) + p++; + x++; + } + an += min(p, c); + } + } + cout << an << endl; +} +int main() { + int n, i; + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + cout << "HARD" << endl; + return 0; + } + } + cout << "EASY" << endl; +} +int a[110]; +int main() { + int x = 0, tedad = 0; + char c; + string s; + cin >> s; + c = s[0]; + for (int i = 0; i < (int)s.size(); i++) { + if (s[i] == c) + a[x] = a[x] + 1; + else { + x = x + 1; + a[x] = a[x] + 1; + c = s[i]; + } + } + for (int i = 0; i <= x; i++) + if (a[i] % 2 == 0) tedad = tedad + 1; + cout << tedad << endl; + return 0; +} +int read() { + char c; + int ans = 0, f = 1; + c = getchar(); + while (c < '0' || c > '9') { + if (c == '-') f = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + ans = ans * 10 + c - '0'; + c = getchar(); + } + return ans * f; +} +int a[200005]; +int main() { + int n = read(); + for (int i = 0; i < n; i++) a[i] = read(); + sort(a, a + n); + int k = (n - 1) / 2; + int ans = 0x3f3f3f3f; + for (int i = 0; i <= k; i++) { ans = min(ans, a[n - 1 - k + i] - a[i]); } + cout << ans << endl; + return 0; +} +int main() { + int n, i, j, a[100][100], b[100] = {0}, k, flag; + cin >> n; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { cin >> a[i][j]; } + } + k = 0; + for (i = 0; i < n; i++) { + flag = 1; + for (j = 0; j < n; j++) { + if (i != j) { + if (a[i][j] == 1 || a[i][j] == 3) flag = 0; + } + } + if (flag) b[k++] = i + 1; + } + if (b[0] == 0) + cout << "0" << endl; + else { + cout << k << endl; + for (i = 0; i < k - 1; i++) { cout << b[i] << " "; } + cout << b[k - 1] << endl; + } + return 0; +} +int a; +char l[3][3]; +int main() { + for (int i = 0; i < 3; i++) memset(l[i], '1', sizeof l[i]); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> a; + if (a % 2 == 1) { + if (l[i][j] == '1') + l[i][j] = '0'; + else + l[i][j] = '1'; + if (i - 1 >= 0) { + if (l[i - 1][j] == '1') + l[i - 1][j] = '0'; + else + l[i - 1][j] = '1'; + } + if (i + 1 < 3) { + if (l[i + 1][j] == '1') + l[i + 1][j] = '0'; + else + l[i + 1][j] = '1'; + } + if (j - 1 >= 0) { + if (l[i][j - 1] == '1') + l[i][j - 1] = '0'; + else + l[i][j - 1] = '1'; + } + if (j + 1 < 3) { + if (l[i][j + 1] == '1') + l[i][j + 1] = '0'; + else + l[i][j + 1] = '1'; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << l[i][j]; + ; + cout << '\n'; + } +} +int main() { + int n, i, j, x, mohi; + long long int sum = 0; + vector v; + cin >> n; + for (i = 1; i <= n; i++) { + for (j = 1; j <= i; j++) { + mohi = (j * (j + 1)) / 2; + sum += mohi; + } + if (sum > n) { + x = i; + break; + } + sum = 0; + } + if (n == 1) + cout << 1 << endl; + else + cout << x - 1 << endl; +} +int main() { + int n; + cin >> n; + int ar[n + 5]; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + sort(ar, ar + n); + int mn = INT_MAX; + for (int i = 0; i < n - 1; i++) { mn = min(mn, abs(ar[i + 1] - ar[i])); } + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + if (abs(ar[i + 1] - ar[i]) == mn) cnt++; + } + cout << mn << ' ' << cnt << endl; + return 0; +} +void solve() { + int m, k; + cin >> m >> k; + int ans = 0; + int d[m]; + int s[m]; + int dp[m]; + for (int i = 0; i < m; i++) { + cin >> d[i]; + ans += d[i]; + } + for (int i = 0; i < m; i++) { + cin >> s[i]; + if (i == 0) + dp[i] = s[i]; + else { + if (s[i] > dp[i - 1]) + dp[i] = s[i]; + else + dp[i] = dp[i - 1]; + } + } + int fuel = 0; + for (int i = 0; i < m; i++) { + fuel += s[i]; + if (fuel - d[i] < 0) { + int z = dp[i]; + int dif = d[i] - fuel; + if (dif % z == 0) { + ans += (dif / z * k); + fuel += dif; + } else { + ans += (dif / z + 1) * k; + fuel += (dif / z + 1) * z; + } + } + fuel -= d[i]; + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int a, b, c, n, x, y, z = 0, i; + cin >> x >> y >> n; + for (b = 0; n - b * y >= 0; b++) { + a = (n - b * y) / x; + if (x * a + y * b == n) { + z = 1; + break; + } + } + if (z == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long pos; + cin >> pos; + long long k = n % 6; + if (k == 0) { k = 6; } + long long a[3] = {0, 0, 0}; + a[pos] = 1; + ; + while (true) { + if ((k)&1) { + swap(a[0], a[1]); + } else + swap(a[1], a[2]); + k--; + if (k == 0) break; + } + for (long long i = 0; i < 3; i++) { + if (a[i] == 1) { + cout << i << "\n"; + break; + } + } + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + char c = 'a'; + for (int i = 0; i < n; i++) { + if (s[i] > c) c = s[i]; + } + for (int i = 0; i < n; i++) { + if (s[i] == c) cout << c; + } + cout << endl; + return 0; +} +int min(int a, int b) { + return a < b ? a : b; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int drinks = k * l; + int limes = c * d; + cout << min(min(drinks / nl, limes), p / np) / n << endl; +} +int main() { + long long n, k, a[2001], ans = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 2; i <= n; i++) { + if (a[i] <= a[i - 1]) { + ans += (a[i - 1] - a[i]) / k + 1; + a[i] += ((a[i - 1] - a[i]) / k + 1) * k; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a; + cin >> a; + int arr[a]; + for (int i = 0; i < a; i++) cin >> arr[i]; + int dp[a][3] = {{0}}; + if (arr[0] == 1) dp[0][1] = 1; + if (arr[0] == 2) dp[0][2] = 1; + if (arr[0] == 3) dp[0][2] = dp[0][1] = 1; + for (int i = 1; i < a; i++) { + dp[i][0] = max(dp[i - 1][1], max(dp[i - 1][2], dp[i - 1][0])); + if (arr[i] == 0) { dp[i][1] = dp[i][2] = 0; } + if (arr[i] == 1) { + dp[i][1] = max(dp[i - 1][2] + 1, dp[i - 1][0] + 1); + dp[i][2] = 0; + } + if (arr[i] == 2) { + dp[i][2] = max(dp[i - 1][1] + 1, dp[i - 1][0] + 1); + dp[i][1] = 0; + } + if (arr[i] == 3) { + dp[i][2] = max(dp[i - 1][1] + 1, dp[i - 1][0] + 1); + dp[i][1] = max(dp[i - 1][2] + 1, dp[i - 1][0] + 1); + } + } + cout << a - max(dp[a - 1][0], max(dp[a - 1][1], dp[a - 1][2])) << endl; + return 0; +} +int main() { + int m, n, z; + while (cin >> n >> m >> z) { + int ans = 0; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) ans++; + } + cout << ans << endl; + } + return 0; +} +int long long gcd(int long long a, int long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int long long calc(int long long a, int long long b, int long long d) { + int n = (b - a) / d + 1; + return ((b + a) * (n)) / 2; +} +int main() { + int long long a, b, ans1, ans2, ans3; + cin >> a >> b; + if (a > b) { + ans1 = a * b / gcd(a, b); + int long long c1 = a % b; + ans2 = calc(c1, b, gcd(a, b)); + if (ans2 > ans1 - ans2) + cout << "Dasha" << endl; + else if (ans2 < ans1 - ans2) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + } else { + swap(a, b); + ans1 = a * b / gcd(a, b); + int long long c1 = a % b; + ans2 = calc(c1, b, gcd(a, b)); + if (ans2 < ans1 - ans2) + cout << "Dasha" << endl; + else if (ans2 > ans1 - ans2) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + } +} +int main() { + unsigned long long int n, a, b, c; + cin >> n; + signed long long *x = new signed long long int[n]; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if (c % 2 == 0) + x[i] = (a - b) * (c / 2); + else + x[i] = ((a - b) * (c / 2)) + a; + } + for (int i = 0; i < n; i++) { cout << x[i] << "\n"; } + return 0; +} +int main() { + int n, change = 0, carry = 1, sum = 0; + cin >> n; + string s; + string cop; + cin >> s; + cop = s; + for (int i = 0; i < n; i++) { + sum = s[i] - '0' + carry; + if (sum == 2) { + s[i] = '0'; + carry = 1; + } else { + if (sum == 1) { + s[i] = '1'; + carry = 0; + } + } + } + for (int i = 0; i < n; i++) { + if (cop[i] != s[i]) { change++; } + } + cout << change << endl; +} +int main() { + map m; + int t, x, c = 1, y = 1; + cin >> t; + bool hard = false; + for (int i = 0; i < t; i++) { + cin >> x; + if (m[x] >= c) { + m[x]++; + if (m[x] > y) y = m[x]; + } else { + m[x] = c; + if (m[x] > y) y = m[x]; + } + } + cout << t - y << endl; + return 0; +} +const int N = 1e5 + 5; +const long long MOD = 1e9 + 7; +long long mulMod(long long a, long long b) { + return (a * b) % MOD; +} +long long addMod(long long a, long long b) { + return (a + b) % MOD; +} +long long fast(long long a, long long b) { + if (b == 0) return 1; + long long tmp = fast(a, b / 2); + tmp = mulMod(tmp, tmp); + if (b & 1) tmp = mulMod(tmp, a); + return tmp; +} +long long num; +bool check(long long x) { + if (x < 0) x = -x; + while (x > 0) { + if (x % 10 == 8) return true; + x /= 10; + } + return false; +} +long long solve(long long x) { + for (int i = 1; i <= N; i += 1) { + if (check(x + i)) return i; + } + return 0; +} +int main() { + cin >> num; + cout << solve(num) << endl; + return 0; +} +int main() { + int a[3]; + while (cin >> a[0] >> a[1] >> a[2]) { + sort(a, a + 3); + if (a[0] + a[1] > a[2]) + cout << '0' << '\n'; + else + cout << a[2] + 1 - a[1] - a[0] << '\n'; + } + return 0; +} +int main() { + int n, x, a; + cin >> n >> x; + vector v; + int s = 0; + for (int i = 0; i < n; i++) { + cin >> a; + s += a; + v.push_back(a); + } + if (abs(s) == 0) { + cout << "0" << endl; + return 0; + } else if (abs(s) <= x) { + cout << "1" << endl; + return 0; + } else { + if (abs(s) % x == 0) { + cout << abs(s) / x << endl; + return 0; + } else { + cout << (abs(s) / x) + 1 << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) + cout << 1 << endl; + else { + if (n % 2 != 0) n--; + cout << n / 2 + 1 << endl; + } + return 0; +} +vector mp[100010 * 3], dis[100010 * 3]; +int u, v, c; +long long res; +long long a[100010 * 3]; +long long dp[100010 * 3], dp_max[100010 * 3]; +void dfs(int x, int y) { + long long max1 = 0; + long long max2 = 0; + for (int i = 0; i < mp[x].size(); i++) { + int f = mp[x][i]; + if (f == y) continue; + dfs(f, x); + if (dp[f] - dis[x][i] > max1) { + max2 = max1; + max1 = dp[f] - dis[x][i]; + } else if (dp[f] - dis[x][i] == max1) { + max2 = max1; + } else { + if (dp[f] - dis[x][i] > max2) max2 = dp[f] - dis[x][i]; + } + } + dp_max[x] = max1 + max2 + a[x]; + dp[x] = max1 + a[x]; + res = max(max(dp[x], dp_max[x]), res); +} +int main() { + int t; + cin >> t; + res = 0; + for (int i = 1; i <= t; i++) cin >> a[i]; + t -= 1; + while (t--) { + cin >> u >> v >> c; + mp[u].push_back(v); + mp[v].push_back(u); + dis[u].push_back(c); + dis[v].push_back(c); + } + dfs(1, -1); + cout << res << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (n - (d / t) * k > k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long n, m, vis[100010]; +inline long long read() { + long long x = 0; + bool f = 0; + char ch = getchar(); + for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); + for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); + return f ? -x : x; +} +int main() { + n = read(), m = read(); + for (register int i = 1; i <= n; i++) { + long long x = read(); + for (register int j = 1; j <= x; j++) vis[read()] = 1; + } + for (register int i = 1; i <= m; i++) + if (!vis[i]) { + puts("NO"); + return 0; + } + puts("YES"); + return 0; +} +int N, k, number, total = 0; +int main() { + cin >> N >> k; + while (N--) { + bool digits[10]{0}; + bool good = true; + cin >> number; + while (number) { + digits[number % 10] = 1; + number /= 10; + } + int next = k + 1; + while (next--) { + if (!digits[next]) good = false; + } + total += (good) ? 1 : 0; + } + cout << total << endl; + return 0; +} +int main() { + int n; + string str, s, ans, min = "z"; + cin >> str >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == str) { + min = str; + break; + } + if ((s.find(str) == 0) && (s < min)) min = s; + } + if (min == "z") + cout << str << endl; + else + cout << min << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector num; + for (int i = 2; i * i <= n; i++) { + while (n % i == 0 && n > 1) { + num.push_back(i); + n = n / i; + } + } + if (n > 1) num.push_back(n); + if (num.size() < k) + cout << "-1\n"; + else { + for (int i = 0; i < k - 1; i++) cout << num[i] << " "; + int x = 1; + for (int i = k - 1; i < num.size(); i++) x = x * num[i]; + cout << x << endl; + } +} +int n, h, l, r, q; +int main() { + cin >> n >> h >> l >> r >> q; + int a, b, c, d; + while (q--) { + cin >> a >> b >> c >> d; + if (a == c) + cout << abs(b - d); + else { + if (b < l && d < l) + cout << abs(a - c) + l - b + l - d; + else if (b > r && d > r) + cout << abs(a - c) + b - r + d - r; + else + cout << abs(a - c) + abs(d - b); + } + cout << '\n'; + } + return 0; +} +int main() { + char bal[110]; + int c = 0, d = 0; + cin >> bal; + int l = strlen(bal); + for (int i = 0; i < l; i++) { + if (bal[i] >= 65 && bal[i] <= 90) + c++; + else + d++; + } + if (c > d) { + for (int i = 0; i < l; i++) { + if (bal[i] >= 97 && bal[i] <= 122) bal[i] = bal[i] - 32; + } + } else { + for (int i = 0; i < l; i++) { + if (bal[i] >= 65 && bal[i] <= 90) bal[i] = bal[i] + 32; + } + } + cout << bal << endl; +} +int main() { + int a, b, n; + while (cin >> n >> a >> b) { + if ((a + b) > n) + cout << (n - a) << endl; + else + cout << ((n - (a + b)) ? (b + 1) : b) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int tot = 0, ans = 0; + for (int i = 1; i <= n; i++) { + int aa, nn; + cin >> aa >> nn; + if (aa > nn) { + tot++; + } else if (nn > aa) { + ans++; + } + } + if (tot > ans) { + cout << "Mishka" << endl; + } else if (ans > tot) { + cout << "Chris" << endl; + } else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int n, k, i; +int a[1005] = {0}; +int main() { + cin >> n >> k; + for (i = 0; i < n; ++i) cin >> a[i]; + sort(a, a + n); + for (i = n - 1; i >= 0; --i) + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + return 0; +} +long long a, b, c, e, f; +int main() { + cin >> a >> b >> c; + e = max(a, b); + e = max(e, c); + f = min(a, b); + f = min(f, c); + cout << e - f << endl; +} +int arr[5000000]; +int main() { + char arr[105][105]; + int n, count = 0, flag = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> arr[i][j]; } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + count = 0; + if (i == 1 && j == 1) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i][j + 1] == 'o') count++; + } + if (i == 1 && j > 1 && j < n) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + if (arr[i][j + 1] == 'o') count++; + } + if (j == 1 && i > 1 && i < n) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i - 1][j] == 'o') count++; + if (arr[i][j + 1] == 'o') count++; + } + if (j > 1 && j < n && i > 1 && i < n) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + if (arr[i - 1][j] == 'o') count++; + if (arr[i][j + 1] == 'o') count++; + } + if (i == n && j > 1 && j < n) { + if (arr[i][j + 1] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + if (arr[i - 1][j] == 'o') count++; + } + if (j == n && i > 1 && i < n) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + if (arr[i - 1][j] == 'o') count++; + } + if (i == 1 && j == n) { + if (arr[i + 1][j] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + } + if (j == 1 && i == n) { + if (arr[i - 1][j] == 'o') count++; + if (arr[i][j + 1] == 'o') count++; + } + if (i == n && j == n) { + if (arr[i - 1][j] == 'o') count++; + if (arr[i][j - 1] == 'o') count++; + } + if (count % 2 == 0) { flag++; } + } + } + if (flag == n * n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char a[110]; + int n, k; + while (cin >> n >> k >> a) { + int st; + int ed; + for (int i = 0; i < n; i++) { + if (a[i] == 'G') st = i; + if (a[i] == 'T') ed = i; + } + bool f = 0; + if (ed < st) swap(ed, st); + for (int i = st; i < n; i += k) { + if (a[i] == '#') { + break; + } else if (i == ed) { + f = 1; + break; + } + } + if (f) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +void solve() { + int n, s; + cin >> n >> s; + vector a; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + x = 60 * x + y; + a.push_back(x); + } + if (a[0] > s) { + cout << "0 0\n"; + return; + } + for (int i = 0; i < n; i++) { + if (i == n - 1 || a[i + 1] - a[i] > 2 * s + 1) { + cout << (a[i] + s + 1) / 60 << ' ' << (a[i] + s + 1) % 60 << '\n'; + return; + } + } +} +int main() { + solve(); +} +int main() { + int t, a; + cin >> t; + while (t--) { + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const long long INF = 1e18; +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n, x; + cin >> n >> x; + int sum = 0; + for (int i = 0; i < n; ++i) { + int j; + cin >> j; + sum += j; + } + if (!sum) + cout << 0 << "\n"; + else { + if (sum < 0) sum = abs(sum); + int no = 0; + for (int i = x; i >= 1; i--) { + if (sum == 0) { break; } + int q = sum / i; + no += q; + sum -= i * q; + } + cout << no << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + pair p[n + 2]; + string s[n + 2], s1[n + 2], s2[n + 2], s3[n + 2]; + int x = 0, y = 0, z = 0, z1 = 0; + for (int i = 0; i < n; i++) { + cin >> p[i].first >> p[i].second; + if (p[i].second == "rat") { + s[x] = p[i].first; + x++; + } + if (p[i].second == "woman" || p[i].second == "child") { + s1[y] = p[i].first; + y++; + } + if (p[i].second == "man") { + s2[z] = p[i].first; + z++; + } + if (p[i].second == "captain") { + s3[z1] = p[i].first; + z1++; + } + } + for (int j = 0; j < x; j++) { cout << s[j] << endl; } + for (int j = 0; j < y; j++) { cout << s1[j] << endl; } + for (int j = 0; j < z; j++) { cout << s2[j] << endl; } + for (int j = 0; j < z1; j++) { cout << s3[j] << endl; } +} +int n; +int main() { + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud\n"; + } else { + cout << "Ehab\n"; + } + return 0; +} +int main() { + int a, b, c, d, min = 0, i, x; + cin >> a >> b >> c; + cin >> d; + for (i = 0; i < d; i++) { + cin >> x; + if ((x > b) && (x < c)) min++; + } + cout << min << endl; + return 0; +} +int main() { + int n, k; + int a[1000]; + while (cin >> n >> k) { + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] <= k) + ans++; + else + break; + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] <= k) + ans++; + else + break; + } + cout << min(ans, n) << endl; + } + return 0; +} +int main() { + int n; + string str; + cin >> n >> str; + str = str; + int i = 0; + int num = 0; + while (i < str.length()) { + if (str[i] == '1') { + num++; + i++; + } else { + if (num != 0) { + cout << num; + num = 0; + } + i++; + if (str[i] == '0') { + while (i < str.length() && str[i] == '0') { + i++; + cout << 0; + } + } + } + } + cout << num << endl; +} +int main() { + int n, m; + cin >> n >> m; + cout << (m % (int)(pow(2, n))) << endl; + return 0; +} +bool power_of_two(int n) { + int m; + m = n - 1; + if (!n & m) + return true; + else + return false; +} +int main() { + int n, m, a, mn = 10000; + cin >> n >> m; + vector v; + for (int i = 0; i < m; i++) { + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + for (int i = n - 1; i < m; i++) { mn = min(mn, v[i] - v[i - n + 1]); } + cout << mn << endl; +} +int main() { + char c; + char in[100]; + char k[] = "qwertyuiopasdfghjkl;zxcvbnm,./"; + cin >> c; + cin >> in; + if (c == 'L') { + for (int i = 0; i < strlen(in); i++) { + for (int j = 0; j < strlen(k); j++) { + if (in[i] == k[j]) { + cout << k[j + 1]; + break; + } + } + } + cout << endl; + } else { + for (int i = 0; i < strlen(in); i++) { + for (int j = 0; j < strlen(k); j++) { + if (in[i] == k[j]) { + cout << k[j - 1]; + break; + } + } + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector v(2 * n); + for (int i = 0; i < 2 * n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + if (v[n - 1] < v[n]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int n; + cin >> n; + int k = (n / 2) * 3; + cout << k << endl; +} +int main() { + int n, i, a[100], sum = 0; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) sum += abs(a[i]); + cout << sum << endl; +} +int sum[60] = {0}; +int main() { + char arr[101][101]; + memset(arr, '*', sizeof(arr)); + int n, m = 0; + cin >> n; + for (int i = n / 2; i >= 0; i--) { + for (int j = m; j < n - m; j++) { arr[i][j] = 'D'; } + m++; + } + for (int i = n - 1; i > n / 2; i--) { + for (int j = m - 1; j < n - m + 1; j++) { arr[i][j] = 'D'; } + m--; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cout << arr[i][j]; + cout << endl; + } +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "0" << endl; + else if (n % 2 != 0) + cout << "1" << endl; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= k; i++) { + if (n > 9) { + if (n % 10 == 0) { + n /= 10; + } else { + n--; + } + } else { + n--; + } + } + cout << n << endl; +} +int main() { + int n; + int count; + while (cin >> n) { + int temp = 0; + count = n; + int a; + for (int i = 0; i < n; i++) { + cin >> a; + if (!a) { + if (i == n - 1) { + if (temp == 1) + count -= 2; + else { + temp = 1; + count--; + } + } else if (i == 0) { + temp = 2; + count--; + } else if (temp == 1) { + count -= 2; + temp++; + } else if (temp >= 2) + count--; + else + temp = 1; + } else { + temp = 0; + } + } + cout << count << endl; + } +} +int main() { + long long n; + long long k; + while (cin >> n >> k) { + if (n % 2 != 0) { + if (k <= (n / 2 + 1)) + cout << 2 * k - 1 << endl; + else + cout << 2 * k - n - 1 << endl; + } else { + if (k <= n / 2) + cout << 2 * k - 1 << endl; + else + cout << 2 * k - n << endl; + } + } +} +int main() { + string s; + long long proc = 0, res = 0; + cin >> s; + int n = s.size(); + for (int i = 0; i < n; i++) { + if (i == 0 || s[i] == s[i - 1]) + proc++; + else { + res += 1 - proc % 2; + proc = 1; + } + } + res += 1 - proc % 2; + cout << res << endl; +} +int main() { + string s, t; + cin >> s >> t; + int index_s = 0; + for (int i = 0; i < t.length(); i++) { + if (s[index_s] == t[i]) index_s++; + } + cout << index_s + 1 << endl; + return 0; +} +int main() { + int r, c; + int flag = -1; + cin >> r >> c; + char v[r][c]; + int empt = 0, wolf = 0, sheep = 0; + char p; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> p; + if (p == '.') + v[i][j] = 'D'; + else + v[i][j] = p; + } + } + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (v[i][j] == 'S') { + if (v[i - 1][j] == 'W' && i - 1 >= 0) flag = 0; + if (v[i + 1][j] == 'W' && i + 1 < r) flag = 0; + if (v[i][j + 1] == 'W' && j + 1 < c) flag = 0; + if (v[i][j - 1] == 'W' && j - 1 >= 0) flag = 0; + } + } + } + if (flag == 0) + cout << "NO" << endl; + else { + cout << "YES" << endl; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { cout << v[i][j]; } + cout << endl; + } + } +} +const int maxn = 1e5 + 10; +int a, b, c, n; +int main() { + while (cin >> a >> b >> c >> n) { + if (a < c || b < c) { + cout << -1 << endl; + } else { + int num = (a - c) + (b - c) + c; + if (num >= n) { + cout << -1 << endl; + } else { + cout << n - num << endl; + } + } + } + return 0; +} +int main() { + int arr[5][5], val = 0; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if (arr[i][j] == 1) { + if (i == 2 && j == 2) { + cout << val << endl; + } else if (i < 2 && j < 2) { + val = (2 - i) + (2 - j); + cout << val << endl; + } else if (i < 2 && j > 2) { + val = (2 - i) + (j - 2); + cout << val << endl; + } else if (i > 2 && j < 2) { + val = (i - 2) + (2 - j); + cout << val << endl; + } else if (i > 2 && j > 2) { + val = (i - 2) + (j - 2); + cout << val << endl; + } else if (i == 2 && j < 2) { + val = 2 - j; + cout << val << endl; + } else if (i == 2 && j > 2) { + val = j - 2; + cout << val << endl; + } else if (i < 2 && j == 2) { + val = 2 - i; + cout << val << endl; + } else if (i > 2 && j == 2) { + val = i - 2; + cout << val << endl; + } + } + } + } + return 0; +} +int arr[100005]; +int q[100005]; +int main() { + int n, k; + cin >> n >> k; + int l[n]; + int r[n]; + long long total_cov = 0; + for (int i = 0; i < n; i++) { + cin >> l[i] >> r[i]; + total_cov += (r[i] - l[i] + 1); + } + if (total_cov % k == 0) { + cout << 0 << '\n'; + } else { + cout << (k - (total_cov % k)) << '\n'; + } + return 0; +} +int main() { + int n, m = 1, p = 2, q = 3, sum = 0, jum = 0, pum = 0, k; + cin >> n; + int arra[n]; + for (int i = 0; i < n; i++) { + k = i + 1; + cin >> arra[i]; + if (k == m) { + m = m + 3; + sum = sum + arra[i]; + } else if (p == k) { + p = p + 3; + pum = pum + arra[i]; + } else if (q == k) { + q = q + 3; + jum = jum + arra[i]; + } + } + if (sum >= pum && sum >= jum) { + cout << "chest" << endl; + } else if (pum >= sum && pum >= jum) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int main() { + int n, a, ans1 = 0, ans2 = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a; + ans1 |= a; + } + for (int i = 0; i < n; ++i) { + cin >> a; + ans2 |= a; + } + cout << ans1 + ans2 << endl; +} +int main() { + int y1; + char x1; + cin >> x1 >> y1; + if (x1 == 'a' && (y1 == 8 || y1 == 1)) { + cout << 3 << endl; + } else if (x1 == 'h' && (y1 == 8 || y1 == 1)) { + cout << 3 << endl; + } else if (x1 == 'a' && (y1 < 8 && y1 > 1)) { + cout << 5 << endl; + } else if (x1 == 'h' && (y1 < 8 && y1 > 1)) { + cout << 5 << endl; + } else if ((y1 == 1 || y1 == 8) && (x1 != 'a' || x1 != 'h')) { + cout << 5 << endl; + } else { + cout << 8 << endl; + } + return 0; +} +const int MAX = 2e6, mod = 998244353; +int main() { + int n, m; + cin >> n >> m; + if (!n && !m) + puts("NO"); + else if (abs(n - m) <= 1) + puts("YES"); + else + puts("NO"); +} +int main() { + int n; + cin >> n; + long long a, b, k; + while (n--) { + cin >> a >> b >> k; + cout << (a - b) * (k / 2) + (k % 2) * (a) << "\n"; + } + return 0; +} +int n, d; +vector work; +int main() { + cin >> n; + int n0 = n; + while (n0 > 0) { + n0 /= 10; + d++; + } + for (int i = n - 9 * d; i <= n; i++) { + int j = i, s = 0; + while (j > 0) { + s += j % 10; + j /= 10; + } + if (s + i == n) { work.push_back(i); } + } + cout << work.size() << endl; + for (int i = 0; i < work.size(); i++) { cout << work[i] << endl; } +} +int main() { + int n, pre, cur, nex, sum = 0; + cin >> n; + if (n == 1 || n == 2) return cout << 0 << endl, 0; + cin >> pre >> cur; + n -= 2; + while (n--) { + cin >> nex; + if ((cur > pre && cur > nex) || (cur < pre && cur < nex)) sum++; + pre = cur; + cur = nex; + } + cout << sum << endl; + return 0; +} +int main() { + int t, n; + cin >> t; + while (t--) { + string s; + cin >> n >> s; + int flag = 0; + for (int i = 0; i < n / 2; i++) { + if (s[i] == s[n - i - 1]) continue; + if (!(abs(s[i] - s[n - i - 1]) == 2)) { + flag = 1; + break; + } + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + map m; + m['['] = '8', m['('] = '[', m['8'] = '('; + int res = 0; + string s1, s2; + getline(cin, s1); + getline(cin, s2); + for (int i = 0; i < s1.size(); i += 2) { + if (s2[i] == m[s1[i]]) + res++; + else if (s1[i] == m[s2[i]]) + res--; + } + if (res > 0) + cout << "TEAM 2 WINS\n"; + else if (res < 0) + cout << "TEAM 1 WINS\n"; + else + cout << "TIE\n"; +} +int n, m, a[105], w[105] = {}; +int main() { + cin >> n >> m; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) cin >> a[j]; + w[max_element(a, a + n) - a]++; + } + cout << max_element(w, w + n) - w + 1 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int m, f = 1, ss = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'G' || s[i] == 'T') { + m = i; + break; + } + } + while (1) { + m += k; + if (s[m] == 'T' || s[m] == 'G') { + cout << "YES" << endl; + break; + } + if (s[m] == '#' || m + k >= n) { + cout << "NO" << endl; + return 0; + } + } + return 0; +} +const double pi = 3.14159265359; +const int INF = 0x3f3f3f3f; +int main() { + string s1, s2; + cin >> s1 >> s2; + transform((s1).begin(), (s1).end(), s1.begin(), ::tolower); + transform((s2).begin(), (s2).end(), s2.begin(), ::tolower); + if (s1.compare(s2) < 0) + cout << "-1\n"; + else if (s1.compare(s2) > 0) + cout << "1\n"; + else + cout << "0\n"; + return 0; +} +int angleofpolygon(int z); +int main() { + float t, a; + cin >> t; + for (int x = 0; x < t; x++) { + cin >> a; + if (angleofpolygon(a) == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int angleofpolygon(int z) { + for (float b = 3; b <= 360; b++) { + float angle = 180 * (b - 2) / b; + if (angle == z) return 1; + } + return 0; +} +string s; +int check(int i, int v) { + for (int j = i; j < s.length(); j++) { + if (v == 0 && s[j] == 'h') return check(j + 1, v + 1); + if (v == 1 && s[j] == 'e') return check(j + 1, v + 1); + if (v == 2 && s[j] == 'l') return check(j + 1, v + 1); + if (v == 3 && s[j] == 'l') return check(j + 1, v + 1); + if (v == 4 && s[j] == 'o') return 1; + } + return 0; +} +int main() { + cin >> s; + if (check(0, 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + string a; + cin >> a; + int p = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] == '4' || a[i] == '7') p++; + } + if (p == 4 || p == 7) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + return 0; +} +int main() { + int n, p; + cin >> n >> p; + string s; + cin >> s; + if (p == 1 and n > 1) cout << "NO" << endl; + if (p == 2 and n > 2) cout << "NO" << endl; + for (int i = n - 1; i >= 0; i--) { + for (char c = s[i] + 1; c <= 'a' + p - 1; c++) { + if (i - 1 >= 0 and s[i - 1] == c) continue; + if (i - 2 >= 0 and s[i - 2] == c) continue; + s[i] = c; + for (int j = i + 1; j < n; j++) + for (char aux = 'a'; aux <= 'a' + p - 1; aux++) { + if (j - 1 >= 0 and s[j - 1] == aux) continue; + if (j - 2 >= 0 and s[j - 2] == aux) continue; + s[j] = aux; + break; + } + cout << s << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a1, a2, b1, b2, c1, c2; + cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; + int min = a1 + b1 + c1; + int a3 = a2 - a1; + int b3 = b2 - b1; + int c3 = c2 - c1; + if (min >= n) + cout << a1 << " " << b1 << " " << c1 << endl; + else if (n - min <= a3) + cout << a1 + n - min << " " << b1 << " " << c1 << endl; + else if (n - min - a3 <= b3) + cout << a2 << " " << b1 + n - min - a3 << " " << c1 << endl; + else + cout << a2 << " " << b2 << " " << c1 + n - min - a3 - b3 << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const int maxn = 5005; +int arr[maxn]; +int main() { + int n; + cin >> n; + if (n % 10 >= 0 && n % 10 <= 5) { + cout << n / 10 * 10 << endl; + } else { + while (n % 10) { n++; } + cout << n << endl; + } + return 0; +} +int a[1010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int i; + for (i = n - 1; i >= 0; i--) { + int b = sqrt(a[i]); + if (b * b == a[i]) + continue; + else + break; + } + cout << a[i] << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long t = n / k; + if (t % 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int n, aux; +vector posiciones; +map cant; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> aux; + posiciones.push_back(aux); + } + sort(posiciones.begin(), posiciones.end()); + for (int i = 1; i < n; ++i) { cant[posiciones[i] - posiciones[i - 1]]++; } + cout << cant.begin()->first << ' ' << cant.begin()->second << '\n'; + return 0; +} +int main() { + int t, i, x; + int a[100]; + cin >> t; + for (i = 0; i < t; i++) { cin >> a[i]; } + int c = 0, b = 0, k = 0; + for (i = 0; i < t; i++) { + if (i % 3 == 1) { + b += a[i]; + } else if (i % 3 == 2) { + k += a[i]; + } else { + c += a[i]; + } + } + if (c > b && c > k) { + cout << "chest" << endl; + } else if (b > c && b > k) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int cntup = 0, cntlw = 0; + string x = s, y = s; + for (int i = 0; i < s.length(); i++) { + if (isupper(s[i])) + cntup++; + else + cntlw++; + x[i] = toupper(s[i]); + y[i] = tolower(s[i]); + } + if (cntup > cntlw) + cout << x << "\n"; + else + cout << y << "\n"; +} +int main() { + int n, a, b, c = 0; + cin >> n >> a >> b; + for (int i = a; i <= n - 1; i++) { + if (n - i >= 1 && n - i - 1 <= b) { c++; } + } + cout << c << endl; + return 0; +} +long long int arr[100005]; +bool vis[100005]; +int main() { + long long int n, ans = 0; + cin >> n; + string before, after; + cin >> before >> after; + for (int i = 0; i < n; i++) { ans += min(abs(before[i] - after[i]), 10 - abs((before[i] - after[i]))); } + cout << ans << endl; + return 0; +} +int b[1001]; +int main() { + int n, m; + cin >> n >> m; + int a; + for (int i = 1; i <= m; i++) { + cin >> a; + b[a]++; + } + sort(b + 1, b + n + 1); + cout << b[1] << endl; + return 0; +} +int f[10]; +int main() { + string a, b; + cin >> a >> b; + for (int i = 0; i < a.size(); i++) + if (a[i] != b[i]) f[a[i] - '0']++; + int x = min(f[4], f[7]), r = 0; + f[4] -= x, f[7] -= x; + r += x; + r += max(f[4], f[7]); + cout << r << endl; +} +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const int N = 1e5 + 5; +int s[N]; +int main() { + int n, a, b; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { cin >> s[i]; } + long long sum = 0; + int i, j; + int flag = 0; + for (i = 0, j = n - 1; i < j; i++, j--) { + if (s[i] != s[j] || (s[i] == s[j] && s[i] == 2)) { + if (s[i] == 2) { + if (s[j] == 1) { + sum += b; + } else if (s[j] == 0) { + sum += a; + } else if (s[j] == 2) { + sum += min(a, b) * 2; + } + } else if (s[j] == 2) { + if (s[i] == 0) { + sum += a; + } else if (s[i] == 1) { + sum += b; + } else if (s[i] == 2) { + sum += min(a, b) * 2; + } + } else { + flag = 1; + break; + } + } + } + if (s[i] == 2 && n % 2 == 1) { sum += min(a, b); } + if (flag == 0) + cout << sum << "\n"; + else + cout << -1 << "\n"; + return 0; +} +int main() { + long int y, u; + cin >> y >> u; + long int j, f; + if (y < 0) j = -y; + if (u < 0) + ; + f = -u; + long int c = 0; + if (y > 0 && u < 0) { + c = y + f; + cout << 0 << " " << -c << " " << c << " " << 0 << endl; + ; + } else if (y < 0 && u < 0) { + c = j + f; + cout << -c << " " << 0 << " " << 0 << " " << -c << endl; + } else if (y < 0 && u > 0) { + c = j + u; + cout << -c << " " << 0 << " " << 0 << " " << c << endl; + } else { + c = y + u; + cout << 0 << " " << c << " " << c << " " << 0 << endl; + } +} +int main() { + string str1, str2, res; + cin >> str1 >> str2; + if (str1[0] == str2[0]) + res = '0'; + else + res = '1'; + int len = str1.length(); + for (int i = 1; i < len; i++) { + if (str1[i] == str2[i]) + res += '0'; + else + res += '1'; + } + cout << res << endl; +} +int q, n; +string s; +int main() { + cin >> q; + for (int qi = 0; qi < q; ++qi) { + cin >> n >> s; + if (s.size() == 2 && s[0] >= s[1]) { + cout << "NO\n"; + continue; + } + cout << "YES\n2\n" << s[0] << " " << s.substr(1) << "\n"; + } +} +int a[10005], b[10005]; +int c[1005][1005]; +int main() { + int n, m; + cin >> n >> m; + string s; + for (int i = 1; i <= n; i++) { + cin >> s; + for (int j = 0; j < m; j++) { + c[i][j + 1] = s[j] - '0'; + if (s[j] - '0' > a[j + 1]) { + a[j + 1] = max(a[j + 1], s[j] - '0'); + b[j + 1] = i; + } + } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (c[i][j] == a[j]) { + ans++; + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int arr[3][3]; + int arr2[3][3] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; + for (int row = 0; row < 3; row++) { + for (int colom = 0; colom < 3; colom++) { cin >> arr[row][colom]; } + } + for (int row = 0; row < 3; row++) { + for (int colom = 0; colom < 3; colom++) { + if (arr[row][colom] % 2 != 0) { + arr2[row][colom] = !arr2[row][colom]; + if (colom + 1 < 3) arr2[row][colom + 1] = !arr2[row][colom + 1]; + if (colom - 1 >= 0) arr2[row][colom - 1] = !arr2[row][colom - 1]; + if (row - 1 >= 0) arr2[row - 1][colom] = !arr2[row - 1][colom]; + if (row + 1 < 3) arr2[row + 1][colom] = !arr2[row + 1][colom]; + } + } + } + for (int row = 0; row < 3; row++) { + for (int colom = 0; colom < 3; colom++) { cout << arr2[row][colom]; } + cout << endl; + } +} +int main() { + cin.exceptions(cin.failbit); + int a; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> a; + if (a == 1) { + cout << abs(i - 2) + abs(j - 2) << endl; + return 0; + } + } + } +} +vector v; +int n; +int main() { + int n; + cin >> n; + int a[n], pre = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 0; + for (int i = 0; i < n; i++) { + if (pre == 3) { + pre = a[i]; + } else if (a[i] == 1 && pre != 1) + pre = 1; + else if (a[i] == 2 && pre != 2) + pre = 2; + else if (a[i] == 3) { + if (pre == 2) + pre = 1; + else if (pre == 1) + pre = 2; + else + pre = 3; + } else { + pre = 0; + } + if (pre == 0) ans++; + } + cout << ans << '\n'; +} +int main() { + int n, m; + cin >> n >> m; + char a1[m + 1], a2[m + 1], a3[m + 1]; + for (int i = 0; i < m; i++) { + a1[i] = '#'; + a2[i] = '.'; + a3[i] = '.'; + } + a1[m] = '\0'; + a2[m] = '\0'; + a3[m] = '\0'; + a2[m - 1] = '#'; + a3[0] = '#'; + for (int i = 0; i < n; i++) { + if (i & 1) { + if ((i + 1) % 4 == 0) + cout << a3 << endl; + else + cout << a2 << endl; + } else + cout << a1 << endl; + } + return 0; +} +const int maxx = 1e3 + 10; +int a[maxx]; +int n; +int main() { + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long sum = 0; + for (int i = 1; i < n; i++) { sum += (a[i] - a[i - 1] - 1); } + cout << sum << endl; + } + return 0; +} +int main() { + int n, m, res = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % m == 0) n++; + res++; + } + cout << res << endl; + return 0; +} +int main() { + long long int a; + cin >> a; + int digit; + for (int b = 1; b <= 20; b++) { + a++; + bool contain8 = false; + int c = a; + if (c == 0) continue; + if (c < 0) c = -c; + while (c != 0) { + digit = c % 10; + c = c / 10; + if (digit == 8) { contain8 = true; } + } + if (contain8) { + cout << b << endl; + break; + } + } +} +int main() { + int n, a, b, c, pos = 1, dis = 0; + cin >> n >> a >> b >> c; + for (int q = 1; q < n; q++) { + if (pos == 1) { + if (a <= b) { + dis += a; + pos = 2; + continue; + } else { + dis += b; + pos = 3; + continue; + } + } else if (pos == 2) { + if (a <= c) { + dis += a; + pos = 1; + continue; + } else { + dis += c; + pos = 3; + continue; + } + } else if (pos == 3) { + if (b <= c) { + dis += b; + pos = 1; + continue; + } else { + dis += c; + pos = 2; + continue; + } + } + } + cout << dis << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + int len = n - 1; + int i = 0; + int flag = 0; + while (i < len) { + if (abs(s[i] - s[len]) == 2 || abs(s[i] - s[len]) == 0) { + i++; + len--; + } else { + flag = 1; + break; + } + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +char a[10005]; +int main() { + int num = 0, num1; + char flag1, flag2; + cin >> num >> num1; + cin >> a; + for (int i = 0; i < num1; i++) { + int l, r; + cin >> l >> r; + cin >> flag1 >> flag2; + for (int j = l - 1; j <= r - 1; j++) { + if (a[j] == flag1) a[j] = flag2; + } + } + cout << a << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i; + vector x(n); + vector y(n); + vector ox(n); + vector oy(n); + for (i = 0; i < n; i++) { + cin >> x[i] >> y[i]; + ox[i] = x[i]; + oy[i] = y[i]; + } + int k; + int cty = 1; + sort(y.begin(), y.begin() + n); + for (i = 0; i < n - 1; i++) { + if (y[i] != y[i + 1]) { cty++; } + } + int ctx = 1; + sort(x.begin(), x.begin() + n); + for (i = 0; i < n - 1; i++) { + if (x[i] != x[i + 1]) { ctx++; } + } + if (ctx > cty) { + cout << cty << endl; + } else { + cout << ctx << endl; + } + return 0; +} +int main() { + long long q; + cin >> q; + while (q--) { + long long a, b; + cin >> a >> b; + long long prod = a * b; + long long round1 = round(cbrt(prod)); + if (a % round1 == 0 && b % round1 == 0) { + if (round1 == 1) { + if (a == 1 && b == 1) + cout << "Yes" + << "\n"; + else + cout << "No" + << "\n"; + } else + cout << "Yes" + << "\n"; + } else + cout << "No" + << "\n"; + } + return 0; +} +int main() { + double a, b, c; + cin >> a >> b >> c; + cout << b / (b + c) * a << endl; + return 0; +} +int main() { + int n, cnt = 0; + cin >> n; + while (true) { + if (n > 5) { + n = n - 5; + cnt++; + } + if (n <= 5) { + cnt++; + break; + } + } + cout << cnt << endl; + return 0; +} +const int N = 205; +int in[N], tin[N], n, a[N]; +vector e[N]; +int bfs(int k) { + queue Q[5]; + for (int i = 1; i <= n; i++) + if (!in[i]) Q[a[i]].push(i); + for (int i = 1; i <= n; i++) tin[i] = in[i]; + int step = -1; + while (!Q[1].empty() || !Q[2].empty() || !Q[3].empty()) { + step++; + while (!Q[k].empty()) { + int u = Q[k].front(); + Q[k].pop(); + step++; + for (int i = 0; i < e[u].size(); i++) { + int v = e[u][i]; + tin[v]--; + if (!tin[v]) Q[a[v]].push(v); + } + } + if (k == 1) + k = 2; + else if (k == 2) + k = 3; + else if (k == 3) + k = 1; + } + if (step != -1) return step; + return 0; +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1, m, x; i <= n; i++) { + cin >> m; + in[i] = m; + while (m--) { + cin >> x; + e[x].push_back(i); + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= 3; i++) ans = min(ans, bfs(i)); + cout << ans << endl; + return 0; +} +int main() { + int n, ans, sum, sum2; + while (cin >> n) { + ans = sum = sum2 = 0; + while (true) { + if (sum2 > n) break; + ans++; + sum += ans; + sum2 += sum; + } + cout << ans - 1 << endl; + } + return 0; +} +long long int mod = 1000000007; +int main() { + long long int n, h, a, b; + cin >> n >> h >> a >> b; + long long int k; + cin >> k; + while (k--) { + long long int ta, fa, tb, fb; + cin >> ta >> fa >> tb >> fb; + long long int res = abs(ta - tb); + if (ta == tb) { + res += abs(fa - fb); + } else if ((fa >= a) && (fa <= b)) { + res += (abs(fa - fb)); + } else if (fa > b) { + res += (abs(b - fa)); + res += (abs(fb - b)); + } else { + res += (abs(a - fa)); + res += (abs(fb - a)); + } + cout << res << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + if (i % 2) { + for (int j = 1; j <= m; ++j) { cout << "#"; } + cout << endl; + } else { + if ((i / 2) % 2) { + for (int j = 1; j < m; ++j) { cout << "."; } + cout << "#" << endl; + } else { + cout << "#"; + for (int j = 1; j < m; ++j) { cout << "."; } + cout << endl; + } + } + } + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int n; +int first; +int a[102]; +int main() { + while (cin >> n) { + int ans = 0; + memset(a, 0, sizeof(a)); + cin >> first; + for (int i = 0; i < n - 1; i++) cin >> a[i]; + sort(a, a + n - 1, cmp); + while (a[0] >= first) { + a[0]--; + first++; + sort(a, a + n - 1, cmp); + ans++; + } + cout << ans << endl; + } + return 0; +} +int main() { + int t, a[105]; + cin >> t; + for (int i = 0; i < t; i++) { cin >> a[i]; } + sort(a, a + t); + cout << a[t - 1] << " "; + for (int i = 1; i <= t - 2; i++) cout << a[i] << " "; + cout << a[0] << "\n"; + return 0; +} +int main() { + int n = 0; + while (cin >> n) { + int a[100005] = {0}; + int b[100005] = {1}; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n - 1; i++) { + if (a[i + 1] >= a[i]) + b[i + 1] = b[i] + 1; + else + b[i + 1] = 1; + } + sort(b, b + n); + cout << b[n - 1] << endl; + } +} +string s; +int main() { + cin >> s; + int ans = 0, curr = 0; + for (int i = 0; i < s.size(); i++) { + int c = s[i] - 'a'; + ans += min(abs(c - curr), 26 - abs(c - curr)); + curr = c; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int mn = (((n) < (m)) ? (n) : (m)); + int fact = 1; + for (int i = 2; i <= mn; i++) fact *= i; + cout << fact << endl; + return 0; +} +int main() { + int a, b = 0; + cin >> a; + string s[a]; + while (b < a) { + cin >> s[b]; + int c = s[b].size(); + if (c <= 10) + cout << s[b] << endl; + else + cout << s[b][0] << c - 2 << s[b][c - 1] << endl; + b++; + } +} +int main() { + int y, x; + char trash; + cin >> y >> x; + for (int i = 0; i < y; i++) { + for (int j = 0; j < x; j++) { + cin >> trash; + if (trash == '-') + cout << '-'; + else if (j % 2 == i % 2) + cout << 'B'; + else + cout << 'W'; + } + cout << endl; + } + return 0; +} +int main() { + int a, b, c, res = 0; + cin >> a >> b >> c; + if (a >= b + c) { + res = a - (b + c) + 1; + } else if (b >= a + c) { + res = b - (a + c) + 1; + } else if (c >= a + b) { + res = c - (b + a) + 1; + } + cout << res << endl; +} +int n, m, k; +int a[101]; +int sum = 0; +int ans = 0; +bool cmp(int a, int b) { + if (a > b) + return true; + else + return false; +} +int main() { + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + 1 + n, cmp); + sum = k; + if (k >= m) { + cout << "0" << endl; + return 0; + } + for (int i = 1; i <= n; i++) { + sum = sum - 1 + a[i]; + ans++; + if (sum >= m) { + cout << ans << endl; + return 0; + } + } + if (ans == n) cout << "-1" << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int ar[n]; + for (long long int i = 0; i < n; ++i) cin >> ar[i]; + sort(ar, ar + n); + long long int d = 0; + for (long long int i = 0; i < n; ++i) { + long long int x = ar[i] / k; + d += x; + if ((ar[i] % k) != 0) { d++; } + } + if ((d % 2) == 0) { + d /= 2; + cout << d << endl; + } else { + d /= 2; + d++; + cout << d << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + int ans = 0; + while (t--) { + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + for (int i = x1; i <= x2; i++) { + for (int j = y1; j <= y2; j++) { ans++; } + } + } + cout << ans << endl; + return 0; +} +long long match(long long num) { + long long result = 0; + long long base = 10; + while (10 * base <= num) base *= 10; + while (base) { + result *= 10; + result += (num / base) % 2; + base /= 10; + } + return result; +} +int main() { + set arr; + map arr2; + map::iterator it; + long long n; + cin >> n; + for (int i = 0; i < n; i++) { + char c; + long long num; + cin >> c >> num; + if (c == '+') { + arr2[match(num)]++; + } else if (c == '-') { + arr2[match(num)]--; + } else { + cout << arr2[match(num)] << endl; + } + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int ans = 1; + for (int i = 1; i <= min(a, b); i++) { ans *= i; } + cout << ans << endl; + return 0; +} +const int maxn = 1e5 + 7; +int counter(int x) { + int myAss = 0; + while (x) { + x >>= 1; + myAss++; + } + return myAss; +} +int main() { + int n; + while (cin >> n) { cout << counter(n) << endl; } + return 0; +} +int arr[10000000]; +int main() { + int n, a, b; + int x_p = 0, x_n = 0, y_p = 0, y_n = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a > 0) + x_p++; + else if (a < 0) + x_n++; + if (b > 0) + y_p++; + else if (b < 0) + y_n++; + } + if (x_p <= 1 || x_n <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int x, y; + string a; + cin >> a; + x = a.size(); + y = (26 * (x + 1) - x); + cout << y << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + if (360 % (180 - x) == 0) + cout << "YES\n"; + else { + cout << "NO\n"; + } + } +} +int main() { + int n, v; + cin >> n; + int game[n + 1]; + memset(game, 0, sizeof(game)); + int p, q; + cin >> p; + for (int i = 1; i <= p; i++) { + cin >> v; + game[v] = 1; + } + cin >> q; + for (int i = 0; i < q; i++) { + cin >> v; + game[v] = 1; + } + for (int i = 1; i <= n; i++) { + if (game[i] == 0) { + cout << "Oh, my keyboard!\n"; + return 0; + } + } + cout << "I become the guy.\n"; + return 0; +} +int main() { + long long n, l; + cin >> n >> l; + long long cnt = 0; + long long temp = n; + while (temp <= l) { + if (temp == l) { + cout << "YES" << endl; + cout << cnt << endl; + return 0; + } + temp *= n; + cnt++; + } + cout << "NO" << endl; + return 0; +} +int main() { + int k, n, w, count; + cin >> k >> n >> w; + w = w * (w + 1) / 2; + count = w * k - n; + if (count <= 0) count = 0; + cout << count << endl; + return 0; +} +int main() { + char s[105]; + int vis[105]; + while (cin >> s) { + memset(vis, 0, sizeof(vis)); + int ans = 0; + int flag = 0; + for (int i = 1; i < strlen(s); i++) { + if (s[i] == 'K' && s[i - 1] == 'V') { + vis[i] = 1; + vis[i - 1] = 1; + ans++; + } + } + for (int i = 1; i < strlen(s); i++) { + if (s[i] == s[i - 1] && !vis[i] && !vis[i - 1]) { + flag = 1; + break; + } + } + cout << ans + flag << endl; + } + return 0; +} +int main() { + int number = 0; + int position = 0; + cin >> number; + cin >> position; + string a = ""; + cin >> a; + int right = number - position; + int left = position - 1; + if (right > left) { + for (int i = 0; i < position - 1; i++) { cout << "LEFT" << endl; } + for (int i = 0; i < number; i++) { + cout << "PRINT " << a[i] << endl; + if (i != number - 1) cout << "RIGHT" << endl; + } + } else { + for (int i = position; i < number; i++) { cout << "RIGHT" << endl; } + for (int i = number - 1; i >= 0; i--) { + cout << "PRINT " << a[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } + return 0; +} +int main() { + int cnt = 0; + int x, y; + int a[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) { + x = i; + y = j; + } + } + } + if (x == 2 && y == 2) { + cout << 0 << endl; + return 0; + } + while (x != 2 || y != 2) { + if (x > 2) { + x--; + cnt++; + } + if (x < 2) { + x++; + cnt++; + } + if (y > 2) { + y--; + cnt++; + } + if (y < 2) { + y++; + cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + if (n % m == 0) + cout << 0 << endl; + else if (n > m) { + long long res; + if (n / m == 1) { + res = 2; + } else { + res = n / m + 1; + } + cout << min((n - n / m * m) * b, (res * m - n) * a) << endl; + } else { + cout << min(n * b, (m - n) * a) << endl; + } + return 0; +} +const int N = 1e5 + 50; +int T, n, m, L, R; +long long a[2 * N]; +int main() { + cin >> n; + for (int i = 0; i < n * 2; i++) { cin >> a[i]; } + if (n <= 1) { + cout << "0" << endl; + return 0; + } + sort(a, a + 2 * n); + long long ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); + long long C = a[2 * n - 1] - a[0]; + for (int i = 1; i <= n; i++) { + long long temp = C * (a[i + n - 1] - a[i]); + ans = min(ans, temp); + } + cout << ans << endl; + return 0; +} +int main() { + int h, w, cnt = 0; + cin >> h >> w; + string f, arr[h]; + for (int i = 0; i < h; i++) cin >> arr[i]; + for (int i = 0; i < h - 1; i++) { + for (int j = 0; j < w - 1; j++) { + f = arr[i][j]; + f += arr[i][j + 1]; + f += arr[i + 1][j]; + f += arr[i + 1][j + 1]; + sort(f.begin(), f.end()); + if (f == "acef") cnt++; + } + } + cout << cnt << endl; +} +int main() { + int n, m, b[100], a[100], i, j, k = 0, c[100], x; + cin >> n; + for (i = 0; i < n; i++) cin >> b[i]; + cin >> m; + for (i = 0; i < m; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (a[j] % b[i] == 0) { + c[k] = (a[j] / b[i]); + k++; + } + } + } + for (i = 0; i < k; i++) { + if (i == 0) + x = c[i]; + else { + if (c[i] > x) x = c[i]; + } + } + int cnt = 0; + for (i = 0; i < k; i++) { + if (c[i] == x) cnt++; + } + cout << cnt << "\n"; + return 0; +} +int main() { + int n, count; + char a; + while (cin >> n) { + count = 0; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == '1') count++; + } + cout << fabs(n - count - count) << endl; + } + return 0; +} +int main() { + int n, s = 0, v = 0; + int x = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n, greater()); + for (int i = 0; i < n; i++) { s += a[i]; } + while (v <= s / 2) { + v += a[x]; + x++; + } + cout << x << endl; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int res = n - 1; + while (res > 0) { + if (a[res - 1] != a[res]) break; + res -= 1; + } + if (k - 1 < (res)) + cout << -1 << endl; + else + cout << res << endl; +} +const int inf = 0x3f3f3f3f; +int T, n, x, y, d, ans; +int main() { + cin >> T; + while (T--) { + cin >> n >> x >> y >> d; + ans = inf; + if (abs(y - x) % d == 0) + ans = abs(y - x) / d; + else { + if ((y - 1) % d == 0) ans = min(ans, (x - 1) / d + 1 + (y - 1) / d); + if ((n - y) % d == 0) ans = min(ans, (n - x) / d + 1 + (n - y) / d); + } + if (ans == inf) ans = -1; + cout << ans << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + int L, v, l, r; + cin >> L >> v >> l >> r; + cout << L / v - r / v + (l - 1) / v << endl; + } + return 0; +} +int main() { + int n, num; + vector v; + cin >> n >> num; + for (int i = 0; i < n - 1; i++) { + int a; + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + int sz = v.size() - 1, temp = num; + if (num > v[sz]) return (cout << 0 << "\n", 0); + if (num == v[sz]) return (cout << 1 << "\n", 0); + while (v[sz] >= temp) { + v[sz]--; + temp++; + sort(v.begin(), v.end()); + } + cout << temp - num << "\n"; + return 0; +} +int main() { + int n, k; + int a[105]; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) break; + if (k > 0) { + k--; + ans++; + } else if (a[i] == a[i - 1]) + ans++; + else + break; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, i, p = 0, a = 0; + cin >> n >> m; + if (n == 2 && m == 3) + cout << "YES" << endl; + else if (m % 2 == 0) + cout << "NO" << endl; + else { + i = n + 2; + if (i == m) { + for (int k = 3; k <= sqrt(m); k++) { + if (m % k == 0) { + a = 1; + break; + } + } + if (a == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + while (i < m) { + for (int j = 3; j <= sqrt(i); j = j + 2) { + if (i % j == 0) { + p = p + 1; + break; + } + } + if (p == 0) break; + i = i + 2; + p = 0; + } + if (i == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int t; + long long int a, b, k; + cin >> t; + while (t--) { + cin >> a >> b >> k; + cout << (a - b) * (k / 2) + a * (k % 2) << endl; + } +} +; +const double eps = 1e-8; +const int maxn = 1e6 + 7; +const double pi = acos(-1); +const int inf = 0x3f3f3f3f; +int n; +int a[10]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int x = (a[n] - a[1]) / 2; + cout << a[1] + x << endl; + return 0; +} +int main() { + int noOfOranges, Orange, maxSize, maxWaste, Waste = 0, cnt = 0; + cin >> noOfOranges >> maxSize >> maxWaste; + for (int i = 0; i < noOfOranges; i++) { + cin >> Orange; + if (Orange > maxSize) + continue; + else { + Waste += Orange; + if (Waste > maxWaste) { + cnt++; + Waste = 0; + } + } + } + cout << cnt << endl; + return 0; +} +const int N = 1010; +const int MOD = (int)1e6 + 3; +long long int n, dp[N], twoPow[2 * N]; +void init() { + twoPow[0] = 1; + for (int i = 1; i <= 2 * N; i++) twoPow[i] = (twoPow[i - 1] * 2) % MOD; + memset(dp, -1, sizeof(dp)); +} +long long int cookie(long long int a) { + return (twoPow[a - 1] * (twoPow[a] + 1)) % MOD; +} +long long int solve(long long int a) { + if (a <= 0) return 0; + if (dp[a] != -1) return dp[a]; + dp[a] = cookie(a) % MOD; + for (int i = 1; a - i > 0; i++) { dp[a] = (dp[a] + solve(a - i) * twoPow[i - 1]) % MOD; } + return dp[a]; +} +int main() { + init(); + cin >> n; + cout << (twoPow[2 * n] - solve(n) + MOD) % MOD << endl; +} +int main() { + int n, k; + cin >> n >> k; + getchar(); + int p = -1, i = -1; + char s = getchar(); + while (s != '\n') { + i++; + if (s == '#') { + if (p != -1 && (i - p) % k == 0) { + puts("NO"); + return 0; + } + } else if ('A' <= s && s <= 'Z') { + if (p != -1) { + if ((i - p) % k == 0) { + puts("YES"); + return 0; + } else { + puts("NO"); + return 0; + } + } else { + p = i; + } + } + s = getchar(); + } + return 0; +} +int n; +map mp; +string s; +int cnt[30]; +inline bool check(string s) { + memset(cnt, 0, sizeof(cnt)); + for (int i = 0; i < s.length(); i++) { + cnt[s[i] - 'a']++; + if (cnt[s[i] - 'a'] == 2) return false; + } + return true; +} +int main() { + while (cin >> n) { + mp.clear(); + int ans = 0; + for (int i = 1; i <= n; i++) { + cin >> s; + sort(s.begin(), s.end()); + string::iterator tmp = unique(s.begin(), s.end()); + s.erase(tmp, s.end()); + if (mp.find(s) != mp.end()) continue; + mp[s]++; + ans++; + } + cout << ans << endl; + } + return 0; +} +const long long N = 1e5 + 1; +long long x; +string s1, s2; +pair p[1001]; +int main() { + cin >> x; + for (int i = 0; i < x; i++) { + cin >> s1 >> s2; + if (s2 == "rat") { + p[i] = {1, s1}; + } else if (s2 == "woman" or s2 == "child") { + p[i] = {2, s1}; + } else if (s2 == "man") { + p[i] = {3, s1}; + } else if (s2 == "captain") { + p[i] = {4, s1}; + } + } + for (int i = 1; i <= 4; i++) { + for (int j = 0; j < x; j++) { + if (p[j].first == i) { cout << p[j].second << endl; } + } + } + return 0; +} +int main() { + int k, n, w; + cin >> k >> n >> w; + int total = k * ((w * (w + 1)) / 2); + if (total > n) + cout << total - n << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + int n; + int c8 = 0; + cin >> n; + cin.ignore(); + char s[101]; + gets(s); + if (n >= 11) { + int r = n / 11; + for (int i = 0; s[i]; i++) { + if (s[i] == '8') c8++; + if (c8 == r) break; + } + cout << c8 << endl; + return 0; + } + cout << c8 << endl; + return 0; +} +int power(int a, int b, int modi) { + int res = 1; + while (b) { + if (b % 2) res = (res * a) % modi; + b /= 2; + a = (a * a) % modi; + } + return res; +} +int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int dx[] = {-1, 1, 0, 0}; +int dy[] = {0, 0, -1, 1}; +int k, sum = 0, ans = 0, cur = 0, x, y; +int n, m, r, c; +int a[1005]; +int main() { + int n; + cin >> n; + cout << "I hate "; + for (int i = 2; i <= n; i++) { + if (!(i & 1)) { + cout << "that I love "; + } else { + cout << "that I hate "; + } + } + cout << "it\n"; + return 0; +} +const int oo = 1e9; +int main() { + string s; + cin >> s; + int n = (int)s.size(); + vector a(n); + int ans = 0, ok = 0; + for (int i = 0; i + 1 < n; i++) { + if (s[i] == 'V' && s[i + 1] == 'K') ans++, a[i] = 1, a[i + 1] = 1; + } + for (int i = 0; i + 1 < n; i++) + if (a[i] == 0 && a[i + 1] == 0 && s[i] == s[i + 1]) ok = 1; + ans += ok; + cout << ans << '\n'; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n]; + long long int max = 0; + for (long long int i = 0; i < n; i++) { + cin >> a[i]; + while (a[i] % 2 == 0) a[i] = a[i] / 2; + while (a[i] % 3 == 0) a[i] = a[i] / 3; + } + long long int flag = 0; + for (long long int i = 0; i < n; i++) { + if (a[i] != a[0]) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "No" << endl; + else + cout << "Yes" << endl; +} +char Not(char x) { + return (x == '0' ? '1' : '0'); +} +int main() { + string s; + cin >> s; + for (int i = 0; i < (int)s.size(); i++) { + if (s[i] == 'r') { cout << i + 1 << '\n'; } + } + for (int i = (int)s.size() - 1; i >= 0; i--) { + if (s[i] == 'l') { cout << i + 1 << '\n'; } + } + return 0; +} +int a[101]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[n] << ' '; + for (int i = 2; i <= n - 1; ++i) cout << a[i] << ' '; + cout << a[1] << endl; + return 0; +} +const int MAXN = 100001; +vector primes; +bool prime[MAXN]; +void sieve() { + for (int i = 0; i < MAXN; i++) prime[i] = true; + prime[0] = prime[1] = false; + for (int i = 2; i * i < MAXN; i++) { + for (int j = 2 * i; j < MAXN; j += i) prime[j] = false; + } + for (int i = 0; i < MAXN; i++) + if (prime[i]) primes.push_back(i); +} +long long modPower(long long x, long long y, long long mod) { + x %= mod; + long long res = 1; + while (y) { + if (y & 1) res = (res * x) % mod; + x = (x * x) % mod; + y >>= 1; + } + return res; +} +int dp[26][51]; +int n, k; +bool p[27]; +int fun(int i, int l) { + if (l == k) { return 0; } + if (i >= 26) return 100000; + if (p[i]) + return dp[i][l] = min(fun(i + 1, l), i + 1 + fun(i + 2, l + 1)); + else + return dp[i][l] = fun(i + 1, l); +} +int main() { + cin >> n >> k; + string s; + cin >> s; + if (k > 13) { + cout << -1 << '\n'; + exit(0); + } + for (int i = 0; i < s.length(); i++) { p[s[i] - 'a'] = 1; } + int ans = fun(0, 0); + if (ans == 100000) + cout << "-1\n"; + else + cout << ans << '\n'; +} +int main() { + string s; + cin >> s; + int k; + cin >> k; + int cnt = 0; + if (k > s.size()) + cout << "impossible" << endl; + else { + int exrt; + int freq[30] = {0}; + for (int i = 0; i < s.size(); i++) { + exrt = int(s[i]) - 96; + freq[exrt]++; + } + for (int i = 0; i < 30; i++) { + if (freq[i] != 0) cnt++; + } + if (k <= cnt) + cout << "0" << endl; + else + cout << k - cnt << endl; + } + return 0; +} +int main() { + int n, ct = 0; + cin >> n; + while (n) { + ct++; + n = n / 2; + } + cout << ct << endl; +} +int clo[35][2]; +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) { cin >> clo[i][0] >> clo[i][1]; } + int ans = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + if (clo[i][0] == clo[j][1] || clo[i][1] == clo[j][0]) { + if (clo[i][0] == clo[j][1] && clo[i][1] == clo[j][0]) { + ans += 2; + } else + ans++; + } + } + } + cout << ans << endl; + } +} +int main() { + string s; + cin >> s; + map m; + for (int i = 0; i < 10; i++) { + string d; + cin >> d; + m[d] = i; + } + for (int i = 0; i < 80; i += 10) { + string ss(s.begin() + i, s.begin() + i + 10); + cout << m[ss]; + } + cout << endl; +} +int main() { + int n, m; + string s; + cin >> n >> m >> s; + int l, r; + char c1, c2; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + for (int i = (l - 1); i < r; i++) + if (s.at(i) == c1) s.at(i) = c2; + } + cout << s << endl; + return 0; +} +int main() { + long long int n, t; + cin >> n >> t; + long long int a[n - 1]; + for (long long int i = 0; i < n - 1; i++) { cin >> a[i]; } + t--; + long long int curr = 0; + while (curr < t) { curr += a[curr]; } + if (curr == t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n; + cin >> n; + priority_queue c; + int liz; + cin >> liz; + for (int i = (1); (i) < (n); ++(i)) { + int a; + cin >> a; + c.push(a); + } + int total = 0; + while (liz <= c.top()) { + int a = c.top(); + liz += 1; + a -= 1; + c.pop(); + c.push(a); + total += 1; + } + cout << total << '\n'; + return 0; +} +void so() { + int x; + cin >> x; + int y; + int a = 0, b = 0; + for (int i = 0; i < x; i++) { + cin >> y; + a |= (y); + } + for (int i = 0; i < x; i++) { + cin >> y; + b |= (y); + } + cout << a + b << endl; +} +int main() { + so(); + return 0; +} +int is_prime(int a) { + bool isPrime = true; + for (int i = 2; i <= a / 2; ++i) { + if (a % i == 0) { + isPrime = false; + break; + } + } + if (isPrime) + return 1; + else + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = n + 1; i <= m; i++) { + if (is_prime(i) == 1 && i == m) { + cout << "YES" << endl; + return 0; + } else if (is_prime(i) == 1 && i != m) + break; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +const int N = 1e5 + 100; +char a[8][8]; +bool check() { + for (int i = 0; i < 7; i++) { + if (a[i][0] == a[i + 1][0]) return false; + } + return true; +} +int num() { + for (int i = 0; i < 7; i++) { + if (a[i][0] == a[i + 1][0]) return i + 1; + } +} +int main() { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 7; j++) { + if (a[i][j] == a[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + } + } + if (check()) { + cout << "NO" << endl; + return 0; + } + while (!check()) { + int x = num(); + if (a[x][0] == 'W') { + a[x][0] = 'B'; + a[x][7] = 'W'; + } else { + a[x][0] = 'W'; + a[x][7] = 'B'; + } + if (x == 7) break; + } + if (check()) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +long long n, m, x, ans, q[100005]; +priority_queue pq; +int main() { + cin >> m; + for (int i = 0; i < m; i++) cin >> q[i]; + sort(q, q + m); + cin >> n; + for (int i = 0; i < n; i++) cin >> x, pq.push(x); + while (!pq.empty()) { + x = q[0]; + while (!pq.empty() && x) ans += pq.top(), pq.pop(), x--; + if (!pq.empty()) pq.pop(); + if (!pq.empty()) pq.pop(); + } + while (!pq.empty()) ans += pq.top(), pq.pop(); + cout << ans << endl; + return 0; +} +int main() { + int n, b, d, v, sum = 0, c = 0; + cin >> n >> b >> d; + for (int x = 0; x < n; x++) { + cin >> v; + if (v <= b) sum += v; + if (sum > d) { + sum = 0; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int grid[50][50]; + for (int i = 0; i < (n); ++i) { + for (int j = 0; j < (n); ++j) { cin >> grid[i][j]; } + } + for (int i = 0; i < (n); ++i) { + for (int j = 0; j < (n); ++j) { + if (grid[i][j] == 1) continue; + bool pass = false; + for (int r = 0; r < n; r++) { + if (r == i) continue; + for (int c = 0; c < n; c++) { + if (c == j) continue; + int sum = grid[r][j] + grid[i][c]; + if (sum == grid[i][j]) { + pass = true; + break; + } + } + if (pass) break; + } + if (!pass) { + cout << "No" << endl; + return 0; + } + } + } + cout << "Yes" << endl; +} +const long long int INF = 2000000000000000000LL; +const int MOD = 10000007; +int a[1000006]; +int main() { + int n, m; + cin >> n >> m; + char cell[n][m], cell2[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> cell[i][j]; + cell2[i][j] = cell[i][j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 == 0 && j % 2 == 0) { + cell[i][j] = 'B'; + } else if (i % 2 == 0 && j % 2 == 1) { + cell[i][j] = 'W'; + } else if (i % 2 == 1 && j % 2 == 0) { + cell[i][j] = 'W'; + } else if (i % 2 == 1 && j % 2 == 1) { + cell[i][j] = 'B'; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (cell2[i][j] == '-') { cell[i][j] = '-'; } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << cell[i][j]; } + cout << "\n"; + ; + } + return 0; +} +int main() { + int year; + cin >> year; + while (1) { + year++; + int i, j, k, l; + i = year / 1000; + j = year / 100 % 10; + k = year / 10 % 10; + l = year % 10; + if (i != j && i != k && i != l && j != k && j != l && k != l) { break; } + } + cout << year << endl; + return 0; +} +int main() { + string s; + vector v; + int x; + cin >> x; + for (int i = 0; i < x; i++) { + cin >> s; + sort(s.begin(), s.end()); + s.resize(unique(s.begin(), s.end()) - s.begin()); + v.push_back(s); + } + sort(v.begin(), v.end()); + v.resize(unique(v.begin(), v.end()) - v.begin()); + cout << v.size() << "\n"; +} +int main() { + char s[101]; + char letter[27] = "abcdefghijklmnopqrstuvwxyz"; + int count, check = 0; + cin >> s; + for (int i = 0; i < 26; i++) { + count = 0; + for (int j = 0; j < strlen(s); j++) { + if (letter[i] == s[j]) { count++; } + } + if (count > 0) { check++; } + } + if (check % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +int main() { + long long n; + while (cin >> n) { + long long a[2 * n + 10]; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + long long ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); + for (int i = 1; i < n; i++) ans = min(ans, (a[2 * n - 1] - a[0]) * (a[i + n - 1] - a[i])); + cout << ans << endl; + } + return 0; +} +int a; +int main() { + cin >> a; + if (a <= 5) { + a = 1; + } else if (a % 5 == 0) { + a /= 5; + } else { + a = a / 5; + a += 1; + } + cout << a << endl; +} +int main() { + int a, b, c, d, e, f, g, h, x, y, z, mi, mi2; + cin >> a >> b >> c >> d >> e >> f >> g >> h; + x = (b * c) / g; + y = d * e; + z = f / h; + mi = min(x, y); + mi2 = min(mi, z); + cout << mi2 / a << endl; + return 0; +} +int main() { + int n, i, j = 0, sum = 0, sumt = 0; + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + sumt += a[i]; + } + int n1 = sizeof(a) / sizeof(a[0]); + sort(a, a + n); + for (i = n - 1; i >= 0; i--) { + sum += a[i]; + sumt -= a[i]; + j++; + if (sum > sumt) { + cout << j << endl; + break; + } + } +} +int a[20][20]; +void runn() { + for (int i = 1; i <= 10; i++) { + a[i][1] = 1; + a[1][i] = 1; + } + for (int i = 2; i <= 10; i++) + for (int j = 2; j <= 10; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; +} +int main() { + int n; + cin >> n; + runn(); + cout << a[n][n] << endl; + return 0; +} +int N; +map M; +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + string s; + cin >> s; + if (s == "DL") s = "UR"; + if (s == "DR") s = "UL"; + M[s]++; + } + cout << (M["ULDR"] + M["UR"] + 1) * (M["ULDR"] + M["UL"] + 1) << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector plans(n); + for (int i = 0; i < n; i++) cin >> plans[i]; + int a = 0, b = 0, c = 0; + for (int i = 0; i < n; i++) { + if (i % 3 == 0) { + a += plans[i]; + } else if (i % 3 == 1) { + b += plans[i]; + } else { + c += plans[i]; + } + } + if (a > b && a > c) { + cout << "chest" << endl; + } else if (b > a && b > c) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } +} +int main() { + int n, s, t1, t2, time = 0, t = 0; + cin >> n >> s; + for (int i = 0; i < n; i++) { + cin >> t1 >> t2; + int sum = 0; + while (1) { + t = t + s; + if (t >= t1) { + t = t - s; + sum = sum + (t2 - t); + t = t + sum; + break; + } + } + time += sum; + } + cout << time << endl; + return 0; +} +long long n, m; +int main() { + cin >> n >> m; + if (n / m % 2) { + cout << "YES\n"; + } else + cout << "NO\n"; +} +string s; +int occ[26]; +int main() { + cin >> s; + int counter = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'B') counter++; + if (s[i] >= 'a' && s[i] <= 'z') occ[s[i] - 'a']++; + } + int ans = 1e9; + ans = min(ans, counter); + ans = min(ans, occ['b' - 'a']); + ans = min(ans, occ['u' - 'a'] / 2); + ans = min(ans, occ['a' - 'a'] / 2); + ans = min(ans, occ['l' - 'a']); + ans = min(ans, occ['s' - 'a']); + ans = min(ans, occ['r' - 'a']); + cout << ans << "\n"; + return 0; +} +int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; +void fast() {} +int main() { + fast(); + string s, t; + cin >> s >> t; + cout << (s == t ? -1 : (int)max(s.size(), t.size())) << "\n"; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + for (int j = 0; j < m - 1; j++) { + if (i % 2 > 0 && j == 0) + cout << "#"; + else + cout << "."; + } + if (i % 2 == 0) + cout << "#\n"; + else + cout << ".\n"; + } + if (n % 2 > 0) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long d = (n / 2) / (k + 1); + cout << d << " " << d * k << " " << n - d * (k + 1) << "\n"; +} +int main() { + string a[6]; + string b[6]; + a[0] = "purple"; + b[0] = "Power"; + a[1] = "green"; + b[1] = "Time"; + a[2] = "blue"; + b[2] = "Space"; + a[3] = "orange"; + b[3] = "Soul"; + a[4] = "red"; + b[4] = "Reality"; + a[5] = "yellow"; + b[5] = "Mind"; + int count = 0; + int size; + cin >> size; + string *x; + x = new string[size]; + for (int i = 0; i < size; i++) { cin >> x[i]; } + for (int i = 0; i < size; i++) { + for (int j = 0; j < 6; j++) { + if (x[i] == a[j]) { b[j] = "00"; } + } + } + for (int i = 0; i < 6; i++) { + if (b[i] != "00") count++; + } + cout << count << endl; + for (int i = 0; i < 6; i++) { + if (b[i] != "00") { cout << b[i] << endl; } + } + return 0; +} +int main() { + int n, ans = 1; + int num[10001]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> num[i]; + if (num[i] == 1) ans = -1; + } + cout << ans << endl; + return 0; +} +int main() { + int n, t, ele; + cin >> n >> t; + int arr[n]; + cin >> ele; + arr[0] = 86400 - ele; + for (int i = 1; i < n; i++) { + cin >> ele; + arr[i] = 86400 - ele + arr[i - 1]; + } + for (int i = 0; i < n; i++) { + if (arr[i] >= t) { + cout << i + 1 << "\n"; + break; + } + } +} +bool can(int lim, vector v, int m) { + for (int i = 0; i < v.size(); i++) { + while (v[i] < lim && m > 0) { + v[i]++; + m--; + } + } + return m == 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int low = *max_element(v.begin(), v.end()), high = 1e8; + while (low <= high) { + int mid = (low + high) / 2; + if (can(mid, v, m)) + high = mid - 1; + else + low = mid + 1; + } + cout << low << " " << m + *max_element(v.begin(), v.end()) << endl; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + cout << max((a - 1) / (k * v) + 1, (a - 1) / v + 1 - b) << endl; +} +int main() { + long long n, x, y; + long long ny; + bool wasOut; + long long borderPoints = 0; + long long nx = 0; + cin >> n; + if (n == 0) { + cout << 1 << endl; + return 0; + } else if (n < 0) { + return 0; + } + x = -n; + while (x <= 0) { + wasOut = true; + ny = sqrt(n * n - x * x) + 1; + for (y = -ny; y <= 0; y++) { + if (x * x + y * y <= n * n) { + if (wasOut == true) { + wasOut = false; + borderPoints++; + if (x == 0) { nx++; } + } else { + if (x < 0) { + if ((x - 1) * (x - 1) + y * y > n * n) { + borderPoints++; + if (x == 0) { nx++; } + } else { + y = n + 1; + } + } else if (x > 0) { + if ((x + 1) * (x + 1) + y * y > n * n) { + borderPoints++; + if (x == 0) { nx++; } + } else { + y = n + 1; + } + } + } + } + } + x++; + } + cout << 2 * (borderPoints * 2 - nx) - 2 << endl; + return 0; +} +int points[103]; +int minimum(int start, int n) { + int curInd = start; + int curMin = start; + while (n > 0) { + int result = points[curInd] - points[curMin]; + if (result <= -1 || result == 0) curMin = curInd; + curInd++; + n--; + } + return curMin; +} +void my_sort(int n) { + int curInd = 0; + int temp = 0; + while (n > 0) { + int ind = minimum(curInd, n); + temp = points[curInd]; + points[curInd] = points[ind]; + points[ind] = temp; + curInd++; + n--; + } +} +int main() { + int n, d; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> points[i]; + int result = 101; + my_sort(n); + for (int i = 0; i < n; i++) { + int j = i; + while (j < n) { + if (points[j] - points[i] > d) break; + result = min(result, n - (j - i + 1)); + j++; + } + } + cout << result << endl; + return 0; +} +const int32_t maxn = 1e2; +string w; +set s; +int main() { + cin >> w; + int32_t len = w.size(); + s.clear(); + for (int32_t i = len - 1; i >= 0; i--) { + string tmp = ""; + for (int32_t j = i; j < len; j++) tmp += w[j]; + for (int32_t j = 0; j < i; j++) tmp += w[j]; + s.insert(tmp); + } + cout << s.size() << endl; + return 0; +} +int main() { + int n, p, i, j, k, x, ans = -1; + cin >> p >> n; + vector used(p, false); + for (i = 1; i <= n; i++) { + cin >> x; + if (used[x % p]) { + ans = i; + break; + } + used[x % p] = true; + } + cout << ans << "\n"; + return 0; +} +int main() { + string n; + char ch; + int length = 0; + int asc = 0; + cin >> n; + int len = n.length(); + for (int i = 0; i < len; i++) { + int a = toascii(n[i]); + if (a > asc) { + ch = n[i]; + length = 1; + asc = a; + } else if (a == asc) + length++; + } + for (int i = 0; i < length; i++) cout << ch; + cout << endl; + return 0; +} +int main() { + int n; + int i, j; + int a[1005][1005]; + for (i = 1; i <= 10; i++) { + a[i][1] = 1; + a[1][i] = 1; + } + for (i = 2; i <= 10; i++) + for (j = 2; j <= 10; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + while (cin >> n) { cout << a[n][n] << endl; } +} +int n, a[1009], m, l[1009], r[1009], ans; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + cin >> m; + for (int i = 0; i < m; i++) { cin >> l[i] >> r[i]; } + sort(a, a + n); + for (int i = 2; i <= n; i++) a[i] += a[i - 1]; + int in = 0, last = 0; + for (int i = 1; i <= n; i++) { + bool check = 0; + for (in; in < m; in++) { + if (a[i] <= l[in]) { + ans += l[in] - last; + last = l[in]; + check = 1; + break; + } + if (a[i] >= l[in] && a[i] <= r[in]) { + ans += a[i] - last; + last = a[i]; + check = 1; + break; + } + } + if (!check) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; + return 0; +} +long long f[300000]; +int main() { + int a, b, c, ans = 0; + cin >> a >> b >> c; + for (int i = 1; a * i <= c; i++) { + if (a * i % b == 0) ans++; + } + cout << ans << endl; +} +int main() { + long long int x, y, z, p, q, s, r; + cin >> x >> y; + z = x / 2; + p = z / (y + 1); + q = y * p; + s = p + q; + r = x - s; + cout << p << " " << q << " " << r << endl; +} +int main() { + int n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int n, i, j, count = 0; + stack sii; + string s; + cin >> n >> s; + for (i = s.size() - 1; i >= 0; i--) { sii.push(s[i] - '0'); } + while (!sii.empty()) { + j = sii.top(); + sii.pop(); + if (j + 1 == 2) { + count++; + } else if (j + 1 == 1) { + count++; + break; + } + } + cout << count << endl; +} +int main() { + int x1, y1, r = 0, l = 0, t; + cin >> t; + while (t--) { + cin >> x1 >> y1; + if (x1 > 0) { r++; } + if (x1 < 0) { l++; } + } + if (l <= 1 || r <= 1) { + cout << "Yes" << endl; + } else + cout << "No" << endl; + return 0; +} +int main() { + int n; + cin >> n; + char letters[n][n]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { cin >> letters[i][j]; } + } + char diagonal_char = letters[0][0]; + char non_diagonal_char = letters[0][1]; + if (diagonal_char == non_diagonal_char) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (i == j || i == n - j - 1) { + if (letters[i][j] != diagonal_char) { + cout << "NO" << endl; + return 0; + } + } else { + if (letters[i][j] != non_diagonal_char) { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int y; + cin >> y; + for (int i = y + 1;; i++) { + set s; + int count = 0, x = i; + while (x != 0) { + s.insert(x % 10); + x /= 10; + count++; + } + if (count == s.size()) { + cout << i << endl; + break; + } + } +} +int main() { + long long n; + cin >> n; + vector v(n); + for (long long i = 0; i < n; i++) cin >> v[i]; + vector ans; + for (long long i = 0; i < n; i++) { + long long x = v[i]; + long long smallans = 0; + long long j = 0; + for (j = 0; i + j < n; j++) { + if (v[i + j] == x) { + smallans++; + } else { + break; + } + } + i = i + j - 1; + ans.push_back(smallans); + } + long long final = 0; + for (long long i = 0; i < ans.size(); i++) { final = final + (ans[i] * (ans[i] + 1)) / 2; } + cout << final << "\n"; +} +int main() { + string word; + int size; + set s; + cin >> word; + size = word.length(); + for (int i = 0; i < size; i++) { + s.insert(word); + word = word[size - 1] + word; + word.resize(size); + } + cout << s.size() << endl; + return 0; +} +int main() { + int a[3], k; + int t; + long long r[3]; + cin >> a[0] >> a[1] >> a[2] >> k; + sort(a, a + 3); + for (int i(0); i < 3; ++i) { + t = min(a[i], k / (3 - i) + 1); + r[i] = t, k -= t - 1; + } + cout << r[0] * r[1] * r[2] << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) { + cout << "NO" << endl; + } else + cout << "YES" << endl; + return 0; +} +char A[200][200], B[200]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; ++i) { cin >> A[i] + 1; } + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { B[i] = max(B[i], A[j][i]); } + } + int ans = 0; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) { + if (A[i][j] == B[j]) { + ++ans; + break; + } + } + } + cout << ans << endl; +} +int main() { + int a[3][3], b[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> a[i][j]; + b[i][j] = 1; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (a[i][j] > 0) { + if (a[i][j] % 2 != 0) { + b[i][j] = !(b[i][j]); + if (i + 1 < 3) { b[i + 1][j] = !(b[i + 1][j]); } + if (i - 1 >= 0) { b[i - 1][j] = !(b[i - 1][j]); } + if (j + 1 < 3) { b[i][j + 1] = !(b[i][j + 1]); } + if (j - 1 >= 0) { b[i][j - 1] = !(b[i][j - 1]); } + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << b[i][j]; } + cout << "\n"; + } +} +vector d; +bool esPrimo(const long long &n) { + long long divN = 0; + for (long long i = 2; ((i * i) <= n); i++) + if (!(n % i)) divN++; + return (divN == 0); +} +void divisores(const long long &n) { + for (long long i = 2; i <= n; i++) + if (esPrimo(i)) d.push_back(i); +} +int main() { + long long n, k, p = 0; + cin >> n >> k; + divisores(n); + vector r; + while (n > 1) { + if (!(n % d[p])) { + n /= d[p]; + r.push_back(d[p]); + } else if ((p + 1) < int(d.size())) + p++; + } + if (int(r.size()) >= k) { + long long mult = 1; + for (long long i = 0; i < (k - 1); i++) cout << r[i] << " "; + for (long long i = (k - 1); i < int(r.size()); i++) mult *= r[i]; + if (mult > 1) cout << mult << "\n"; + return 0; + } + cout << "-1\n"; + return 0; +} +int is_prime[200000]; +int prime[20000]; +int n, k; +int num[20000]; +int cnt = 0; +int temp[20000]; +void shai() { + for (int i = 2; i <= 100000; i++) { + if (!is_prime[i]) { + prime[++cnt] = i; + for (int j = i + i; j <= 100000; j += i) { is_prime[j] = 1; } + } + } +} +int main() { + shai(); + cin >> n >> k; + int sum = 0; + int ans = 1; + for (int i = 1; i <= cnt; i++) { + while (n % prime[i] == 0) { + num[i]++; + if (++sum < k) { + temp[sum] = prime[i]; + } else { + ans *= prime[i]; + } + n /= prime[i]; + } + if (n == 1) break; + } + if (sum < k) { + cout << -1 << endl; + } else { + for (int i = 1; i < k; i++) { cout << temp[i] << " "; } + cout << ans << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + return (b == 0 ? a : gcd(b, a % b)); +} +long long lcm(long long a, long long b) { + return a * (b / gcd(a, b)); +} +bool issquare(long long w) { + return trunc(sqrt(w)) * trunc(sqrt(w)) == w; +} +bool isprime(long long u) { + for (long long i = 2; i <= (long long)sqrt(u); i++) { + if (u % i == 0) return 0; + } + return 1; +} +const double pi = acos(-1); +const long long mod = 998244353, MOD = 1e9 + 7; +int main() { + int n; + cin >> n; + set s; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x != 0) s.insert(x); + } + cout << s.size() << endl; + return 0; +} +const int maxn = 200000 + 5; +int zw[maxn << 2]; +pair G[maxn]; +int ans[maxn]; +int a[maxn]; +int b[30]; +int main() { + int n, m; + string s, ss, sss; + while (cin >> n >> m) { + int f = 1; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i & 1) { + cout << "#"; + } else { + if (f) { + if (j != m) + cout << "."; + else + cout << "#"; + } else { + if (j != 1) + cout << "."; + else + cout << "#"; + } + } + } + cout << endl; + if (!(i & 1)) f = !f; + } + } + return 0; +} +int main() { + long long n; + cin >> n; + double x = (-1 + sqrt(1 + 8 * n)) / 2.0; + long long N = x; + if (N * (N + 1) / 2 == n) { + cout << N << endl; + return 0; + } + cout << n - N * (N + 1) / 2 << endl; + return 0; +} +int used[111]; +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + sort(s.begin(), s.end()); + int cnt = 1; + int ans = s[0] - 'a' + 1; + char cur = s[0]; + for (size_t i = 1; i < s.size(); i++) { + if (cnt == k) { break; } + if (s[i] - cur >= 2) { + cur = s[i]; + ans += (s[i] - 'a' + 1); + cnt++; + } + } + if (cnt == k) { + cout << ans << endl; + } else { + cout << -1 << endl; + } +} +int main() { + int n; + cin >> n; + int a = n + (n / 2); + cout << a << endl; + return 0; +} +char s[105]; +int main() { + int sum = 0, i = 0, j = 0, k = 0; + cin >> s; + int len = strlen(s); + for (i = 0; i < len; i++) { + if (s[i] == 'Q') { + for (j = i + 1; j < len; j++) { + if (s[j] == 'A') { + for (k = j + 1; k < len; k++) { + if (s[k] == 'Q') { ++sum; } + } + } + } + } + } + cout << sum << endl; + return 0; +} +int main() { + string s, digit[10]; + cin >> s; + for (size_t i = 0; i < sizeof(digit) / sizeof(digit[0]); ++i) { cin >> digit[i]; } + for (size_t i = 0; i < 8; ++i) { + string x = s.substr(i * 10, 10); + for (size_t j = 0; j < 10; ++j) { + if (x == digit[j]) { + cout << j; + break; + } + } + } + cout << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n; + int k = 1000000000; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (b < k) { k = b; } + sum += a * k; + } + cout << sum << endl; + return 0; +} +long long q(int n) { + long long ans = 1; + for (int i = n; i >= 1; i--) { ans *= i; } + return ans; +} +int main() { + string st; + cin >> st; + long long sum = 0; + sum = (st.size() + 1) * 25 + 1; + cout << sum << endl; + return 0; +} +long long int n; +long long int a[100007]; +map mymap; +int main() { + cin >> n; + for (long long int i = 0; i <= n - 1; i++) { + cin >> a[i]; + mymap[a[i]]++; + } + long long int _min = 0; + for (long long int i = 1; i <= n - 1; i++) { + if (a[i] < a[_min]) { _min = i; } + } + if (mymap[a[_min]] > 1) { + cout << "Still Rozdil" + << "\n"; + } else { + cout << _min + 1 << "\n"; + } + return 0; +} +int main() { + long long n, i, p, q, x; + cin >> n; + long long a[n]; + for (i = 1; i <= n; i++) { a[i] = i; } + cin >> p; + for (i = 0; i < p; i++) { + cin >> x; + a[x] = 0; + } + cin >> q; + for (i = 0; i < q; i++) { + cin >> x; + a[x] = 0; + } + long long sum = 0; + for (i = 1; i <= n; i++) { sum += a[i]; } + if (sum == 0) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +void fastIo() {} +int main() { + fastIo(); + int n; + cin >> n; + map, int> m; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + m[make_pair(x, y)]++; + } + map, int>::iterator it = m.begin(); + int cnt = 1; + while (it != m.end()) { + if (it->second > cnt) cnt = it->second; + it++; + } + cout << cnt << endl; + return 0; +} +const int mod = 1000000007; +int d[1000006][2]; +int main() { + int n; + cin >> n; + d[0][0] = d[0][1] = 1; + for (int i = 1; i <= int(n); i++) { + for (int j = 0; j < int(2); j++) { + d[i][j] = d[i - 1][j]; + if ((i & 1) == j) d[i][j] = (d[i][j] + d[i - 1][j ^ 1]) % mod; + } + } + int ans = (d[n][0] + d[n][1]) % mod; + cout << (ans + mod - 2) % mod << endl; + return 0; +} +void func(long long x) { + if ((x % 10) > 5) cout << (x / 10 + 1) * 10 << endl; + if ((x % 10) <= 5) cout << (x / 10) * 10 << endl; +} +int main() { + long long x; + while (cin >> x) func(x); +} +const int maxn = 500000; +int main() { + long long x, y, p, q; + int t; + cin >> t; + while (t--) { + cin >> x >> y >> p >> q; + if (p == 0) { + if (x == 0) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + if (p == q) { + if (x == y) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + long long n = max(ceil(1.0 * (y - x) / (q - p)), ceil(1.0 * x / p)); + long long ans = n * q - y; + cout << ans << endl; + } + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + if (k <= n / 2) { + for (int i = 0; i < k - 1; ++i) cout << "LEFT\n"; + for (int i = 0; i < n; ++i) { + if (i != 0) cout << "RIGHT\n"; + cout << "PRINT " << s[i] << "\n"; + } + } else { + for (int i = 0; i < n - k; ++i) cout << "RIGHT\n"; + for (int i = n - 1; i >= 0; --i) { + if (i != n - 1) cout << "LEFT\n"; + cout << "PRINT " << s[i] << "\n"; + } + } + return 0; +} +int arr[2000]; +int main() { + string a, b; + cin >> a >> b; + cout << a[0]; + for (int i = 1; i < a.length(); i++) { + if (a[i] < b[0]) { + cout << a[i]; + } else + break; + } + cout << b[0] << endl; + return 0; +} +inline int calc_subtractions_slow(int a, int b) { + int numOps = 0; + while (a && b) { + if (a <= b) { + b -= a; + } else { + a -= b; + } + ++numOps; + } + return numOps; +} +inline int calc_subtractions_div(int a, int b) { + int numOps = 0; + while (a && b) { + if (a < b) { + int temp = b / a; + numOps += temp; + b -= (a * temp); + } else { + int temp = a / b; + numOps += temp; + a -= (b * temp); + } + } + return numOps; +} +inline int calc_subtractions_mod(int a, int b) { + int numOps = 0; + while (a && b) { + if (a < b) { + numOps += b / a; + b = b % a; + } else { + numOps += a / b; + a = a % b; + } + } + return numOps; +} +int calc_subtractions(int a, int b) { + return calc_subtractions_div(a, b); +} +void subtractions_solve(istream &in, ostream &out) { + int numPairs, a, b; + in >> numPairs; + for (int i = 0; i < numPairs; ++i) { + in >> a >> b; + int v = calc_subtractions_div(a, b); + out << v << "\n"; + } +} +int main() { + subtractions_solve(cin, cout); + return 0; +} +int main() { + long long int t; + cin >> t; + while (t--) { + long long int n, l, v, r; + cin >> n >> v >> l >> r; + long long int a = (n / v); + long long int b = (l - 1) / v; + long long int c = (r / v); + cout << a + b - c << "\n"; + } + return 0; +} +const int MAX = 1e5 + 10; +int num[205]; +long long getans(long long x) { + long long ans = 0; + while (x) { + ans += x % 10; + x /= 10; + } + return ans; +} +int main() { + long long a, b; + cin >> a >> b; + long long num = a / ((b + 1) * 2); + cout << num << " " << num * b << " " << a - num * (b + 1) << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) { cout << '#'; } + cout << endl; + } else { + if ((i / 2) % 2 == 0) { + for (int j = 0; j < m - 1; j++) { cout << '.'; } + cout << '#' << endl; + } + if ((i / 2) % 2 == 1) { + cout << '#'; + for (int j = 0; j < m - 1; j++) { cout << '.'; } + cout << endl; + } + } + } + return 0; +} +int main() { + vector V; + long long int n, a, suma, score; + cin >> n; + suma = 0; + while (n--) { + cin >> a; + V.push_back(a); + suma += a; + } + sort(V.begin(), V.end()); + score = suma; + for (int i = 0; i < V.size() - 1; i++) { + if (i > 0) { suma -= V[i - 1]; } + score += suma; + } + cout << score << endl; + return 0; +} +vector v; +int main() { + int n; + cin >> n; + string b[105]; + for (int i = 1; i <= n; i++) { + string a; + cin >> a; + v.push_back(a); + } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + int ans = 0; + for (int i = 1; i <= n; i++) { + vector::iterator it; + it = find(v.begin(), v.end(), b[i]); + if (it != v.end()) { + v.erase(it); + } else { + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool unfortunate = true; + int banknotes; + for (int i = 0; i < n; i++) { + cin >> banknotes; + if (banknotes == 1) unfortunate = false; + } + if (unfortunate) + cout << "1" << endl; + else + cout << "-1" << endl; + return 0; +} +int n; +bool sm; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + if (tmp == 1) sm = true; + } + if (sm) { + cout << -1 << '\n'; + } else { + cout << 1 << '\n'; + } + return false; +} +int main() { + double m; + while (cin >> m) { + int a, b; + double y = sqrt(m); + int x = (int)y; + int n = int(m); + if (n % x == 0) { + a = x; + b = n / x; + } else { + while (n % x != 0) { x--; } + a = x; + b = n / x; + } + cout << a << " " << b << endl; + } + return 0; +} +int main() { + int n; + int a, b; + int c, d; + while (cin >> n) { + a = b = 0; + for (int i = 1; i <= n; i++) { + cin >> c >> d; + if (c > 0) + a++; + else + b++; + } + if (a <= 1 || b <= 1) { + cout << "Yes" << endl; + } else + cout << "No" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n; + int a[n]; + map count; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] != 0) { count.insert(pair(a[i], 1)); } + } + cout << count.size() << endl; + return 0; +} +int main() { + int num, k; + cin >> num >> k; + for (int i = 0; i < k; i++) { + if (num % 10 == 0) + num /= 10; + else + num--; + } + cout << num << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool pos = true; + int second = 3; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == second) { pos = false; } + vector first(4, 0); + first[second] = 1; + first[x] = 1; + for (int i = 1; i <= 3; i++) + if (first[i] == 0) second = i; + } + if (pos) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + if (n % 10 > 5) + n = n - n % 10 + 10; + else + n = n - n % 10; + cout << n << endl; + return 0; +} +int main() { + int n, num8, numn, num; + char str[101]; + while (cin >> n) { + num8 = 0; + cin >> str; + for (int i = 0; i < n; i++) + if (str[i] == '8') num8++; + numn = n / 11; + if (num8 > numn) + num = numn; + else + num = num8; + cout << num << endl; + } + return 0; +} +int main() { + int n; + string x; + int count_0 = 0, count_1 = 0; + cin >> n >> x; + for (int i = 0; i < x.size(); i++) + if (x[i] == '1') + ++count_1; + else + ++count_0; + cout << abs(count_1 - count_0) << "\n"; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) cout << -1 << endl, exit(0); + cout << max(a.size(), b.size()) << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int n, m; + cin >> n >> m; + long long int x = min(n, m), y = max(n, m); + long long int sum = 0; + while (x > 0 && y > 0) { + sum += y / x; + long long int k = y; + y = x; + x = k % x; + } + cout << sum << endl; + } + return 0; +} +int main() { + int n, x1, x2, y1, y2, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, ans; + cin >> n >> a >> b; + cout << n - max(a + 1, n - b) + 1 << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int n, dig; +string str[30005]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> str[i]; } + for (int i = 0; i < 20; i++) { + for (int j = 1; j < n; j++) { + if (str[j - 1][i] != str[j][i]) { + cout << dig << endl; + return 0; + } + } + dig += 1; + } + cout << dig << endl; + return 0; +} +void so() { + int n, k, c; + cin >> n >> k >> c; + map mp; + for (int i = 0; i < c; i++) { + int r; + cin >> r; + mp[r] = 1; + } + int j = 0; + int cr = 0; + for (int i = 1; i <= n; i++) { + j++; + if (mp[i] || j == k) { + j = 0; + cr++; + } + } + cout << cr << endl; +} +int main() { + so(); + return 0; +} +int main() { + int n, a, b; + cin >> n; + a = sqrt(n); + while (a > 0) { + b = n / a; + if (a * b == n) break; + a--; + } + cout << a << " " << b << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int a[n]; + int ans = 2e9; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) { + cout << -1 << endl; + return 0; + } + bool b = true; + int k = -1; + for (int i = 0; i < n; i++) { + if (s[i] == 'L' and b) + continue; + else if (s[i] == 'R') { + b = false; + k = i; + } else { + ans = min(ans, a[i] - a[k]); + b = true; + } + } + if (ans != 2e9) + cout << ans / 2 << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + cout << ((26 * (n + 1)) - n) << endl; +} +int main() { + int n; + cin >> n; + for (int i = n + 1; i; i++) { + int a = i % 10; + int b = i / 10 % 10; + int c = i / 100 % 10; + int d = i / 1000; + if (a != b && a != c && a != d && b != c && b != d && c != d) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, s1, s2, x[100], y[100], flag = 0; + cin >> n; + cin >> s1; + for (int i = 1; i <= s1; i++) cin >> x[i]; + cin >> s2; + for (int i = 1; i <= s2; i++) cin >> y[i]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= s1; j++) + if (x[j] == i) flag = 1; + if (flag == 0) + for (int j = 1; j <= s2; j++) + if (y[j] == i) flag = 1; + if (flag == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } else + flag = 0; + } + cout << "I become the guy." << endl; + return 0; +} +const int maxn = 2e5 + 10; +const int inf = 0x3f3f3f3f; +const int mod = 1e9 + 7; +int a[maxn]; +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int ans = inf; + for (int i = 0; i < n / 2; i++) ans = min(ans, a[n / 2 + i] - a[i]); + cout << ans << endl; + } + return 0; +} +int main() { + int n, m, a, p; + set s; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a; + for (int j = 0; j < a; j++) { + cin >> p; + s.insert(p); + } + } + if (s.size() == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int r[100003]; +int main() { + int a, b, c, d, e, f, g, r[1000], r2[1000], r3[1000], h, i, j, k, l, flag, cnt; + string s, t; + while (cin >> s) { + cnt = 0; + memset(r, 0, sizeof(r)); + for (b = 0; b < s.size(); b++) { + if (s[b] == 'B') { + r[1]++; + } else if (s[b] == 'u') { + r[2]++; + } else if (s[b] == 'l') { + r[3]++; + } else if (s[b] == 'b') { + r[4]++; + } else if (s[b] == 'a') { + r[5]++; + } else if (s[b] == 's') { + r[6]++; + } else if (s[b] == 'r') { + r[7]++; + } + } + while (1) { + flag = 1; + for (c = 1; c <= 7; c++) { + if (c == 1) { + if (r[1] >= 1) { + r[1] -= 1; + } else { + flag = 0; + } + } + if (c == 2) { + if (r[2] >= 2) { + r[2] -= 2; + } else { + flag = 0; + } + } + if (c == 3) { + if (r[3] >= 1) { + r[3] -= 1; + } else { + flag = 0; + } + } + if (c == 4) { + if (r[4] >= 1) { + r[4] -= 1; + } else { + flag = 0; + } + } + if (c == 5) { + if (r[5] >= 2) { + r[5] -= 2; + } else { + flag = 0; + } + } + if (c == 6) { + if (r[6] >= 1) { + r[6] -= 1; + } else { + flag = 0; + } + } + if (c == 7) { + if (r[7] >= 1) { + r[7] -= 1; + } else { + flag = 0; + } + } + } + if (flag == 1) { + cnt++; + } else { + break; + } + int z; + } + cout << cnt << endl; + } + return 0; +} +int b[300000]; +int main() { + int n; + int maxx = 0, m = 0; + cin >> n; + for (int i = 1; i <= 2 * n; i++) { + int t; + cin >> t; + b[t]++; + if (b[t] == 0) continue; + if (b[t] == 1) m++; + if (b[t] == 2) m--; + if (m > maxx) maxx = m; + } + cout << maxx << endl; + return 0; +} +int a[100000 + 5]; +int s[100000 + 5] = {0}; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + s[i] = 1; + } + int ans = 0, sum = 1; + int j; + for (int i = 1; i <= n; i = j) { + sum = 1; + for (j = i + 1; j <= n; j++) { + if (a[j - 1] < a[j]) + sum++; + else + break; + } + if (sum > ans) ans = sum; + } + cout << ans << endl; + return 0; +} +int main() { + int a[51][51]; + int n; + cin >> n; + int l[51] = {0}, r[51] = {0}; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + r[i] += a[i][j]; + l[j] += a[i][j]; + } + } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (r[i] < l[j]) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + string first; + cin >> first; + string second; + cin >> second; + int count; + cin >> count; + cout << first << " " << second << endl; + for (int i = 0; i < count; i++) { + string f, s; + cin >> f; + cin >> s; + if (f == first) { + first = s; + } else if (f == second) { + second = s; + } else if (s == first) { + first = f; + } else if (s == second) { + second = f; + } + cout << first << " " << second << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a; + cout << "25" << endl; +} +int main() { + int n; + string s; + int c = 0, maxi = -1; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '1') + c++; + else + break; + } + cout << (c == n ? c : c + 1) << endl; +} +int main() { + int t, c1 = 0, c2 = 0; + cin >> t; + while (t-- > 0) { + long long int x, y; + cin >> x >> y; + if (x < 0) + c1++; + else + c2++; + } + if (c1 == 1 || c2 == 1 || c1 == 0 || c2 == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int nuts, divis, maxsec, capacity, boxees = 0; + cin >> maxsec >> nuts >> divis >> capacity; + while (nuts > 0) { + boxees++; + nuts -= ((min(maxsec, divis + 1)) * capacity); + divis -= ((min(maxsec, divis + 1)) - 1); + } + cout << boxees << endl; + return 0; +} +int a[10], b[10], n, x1, x2, sum; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x1; + a[x1]++; + } + for (int i = 0; i < n; i++) { + cin >> x2; + b[x2]++; + } + for (int i = 1; i <= 5; i++) { + if ((a[i] + b[i]) % 2 == 1) { + cout << "-1" << endl; + return 0; + } + if (a[i] < b[i]) swap(a[i], b[i]); + sum += a[i] - (a[i] + b[i]) / 2; + } + cout << sum / 2 << endl; + return 0; +} +int abs(int x) { + if (x < 0) { x *= -1; } + return x; +} +int n, arx[105], ary[105], arr[10], arrx[10], sum = 0; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arx[i]; + arr[arx[i]] += 1; + arrx[arx[i]] += 1; + } + for (int i = 1; i <= n; i++) { + cin >> ary[i]; + arr[ary[i]] += 1; + } + for (int i = 1; i <= 5; i++) { + if (arr[i] % 2 == 1) { + cout << -1 << endl; + return 0; + } else { + sum += abs((arr[i] / 2) - arrx[i]); + } + } + cout << sum / 2 << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + for (int i = 0; i < s.length(); i++) { + while (s[i - 1] == ' ' && s[i] == ' ') s.erase(s.begin() + i - 1); + if ((s[i] == '.' || s[i] == '!' || s[i] == ',' || s[i] == '?')) { + if (s[i - 1] == ' ' && s[i + 1] == ' ') + s.erase(s.begin() + i - 1); + else if (s[i + 1] != ' ') + s.insert(s.begin() + i + 1, ' '); + while (s[i - 1] == ' ') s.erase(s.begin() + i - 1); + } + } + cout << s << "\n"; + return 0; +} +int main() { + long long l, r; + cin >> l >> r; + if (r - l > 1) { + if (l % 2 == 0) + cout << l << ' ' << l + 1 << ' ' << l + 2 << endl; + else { + if (r - l > 2) + cout << l + 1 << ' ' << l + 2 << ' ' << l + 3 << endl; + else + cout << -1 << endl; + } + } else + cout << -1 << endl; +} +int main() { + string s; + cin >> s; + int arr[10]; + arr[0] = 2; + arr[1] = 7; + arr[2] = 2; + arr[3] = 3; + arr[4] = 3; + arr[5] = 4; + arr[6] = 2; + arr[7] = 5; + arr[8] = 1; + arr[9] = 2; + cout << (arr[s[0] - '0']) * (arr[s[1] - '0']) << endl; + return 0; +} +int main() { + int n, a, b; + int mishka = 0; + int chrish = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) mishka++; + if (a < b) chrish++; + } + if (mishka > chrish) { + cout << "Mishka" << endl; + } else if (mishka < chrish) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int dp[3]; + int res = 0; + memset(dp, 0, sizeof dp); + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { dp[1] += dp[0]; } + if (s[i] == 'Q') { + dp[2] += dp[1]; + dp[0]++; + } + } + cout << dp[2] << endl; +} +int win[205]; +int main() { + int n, m, mx = -1, ind = 0, ans; + cin >> n; + cin >> m; + long long int arr[n + 1]; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + cin >> arr[j]; + if (mx < arr[j]) { + mx = arr[j]; + ind = j; + } + } + win[ind]++; + mx = -1; + } + ans = *max_element(win, win + 205); + for (int i = 0; i < 205; i++) { + if (win[i] == ans) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int main() { + long long n, min = pow(10.0, 9.0) + 1, index, more_than1; + cin >> n; + long long city[n]; + for (int i = 0; i < n; i++) { cin >> city[i]; } + for (int i = 0; i < n; i++) { + if (min == city[i]) { + more_than1++; + } else if (min > city[i]) { + min = city[i]; + more_than1 = 0; + index = i + 1; + } + } + if (more_than1 > 0) + cout << "Still Rozdil" << endl; + else + cout << index << endl; + return 0; +} +int a[400], pre_sum[800]; +int main() { + int n, i, j; + while (cin >> n) { + memset(pre_sum, 0, sizeof(pre_sum)); + int sum = 0; + for (i = 1; i <= n; i++) cin >> a[i], pre_sum[i] = pre_sum[i - 1] + a[i]; + for (i = n + 1; i <= n; i++) { pre_sum[i] = pre_sum[i - 1] + a[i - n]; } + int mina = 0x3f3f3f3f; + for (i = 1; i <= 2 * n; i++) { + for (j = i; j <= 2 * n; j++) { + int tmp = pre_sum[j] - pre_sum[i - 1]; + if (abs(360 - 2 * tmp) < mina) { mina = abs(360 - 2 * tmp); } + } + } + cout << mina << endl; + } + return 0; +} +const int N = 1000 + 5; +int n, k, c[N], s[N], DP[N][N]; +long long dp[N]; +const int X = 1e9 + 7; +int main() { + cin >> k; + for (int i = 1; i <= k; i++) cin >> c[i]; + for (int i = 0; i < N; i++) { DP[i][0] = DP[i][i] = 1; } + for (int i = 1; i <= N; i++) { + for (int j = 1; j < i; j++) { DP[i][j] = (DP[i - 1][j] + DP[i - 1][j - 1]) % X; } + } + dp[1] = 1; + int sum = c[1]; + for (int i = 2; i <= k; i++) { + sum += c[i]; + dp[i] = (DP[sum - 1][c[i] - 1] * dp[i - 1]) % X; + } + cout << dp[k] << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long arr[n][n]; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { + if (i == 0 || j == 0) { + arr[i][j] = 1; + } else { + arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; + } + } + } + cout << arr[n - 1][n - 1] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[102]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int k = -1; + int ans = 0; + sort(a, a + n); + if (a[n - 1] == 0) { + return 0; + cout << 0 << endl; + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] == 0) break; + if (k == -1) { + k = a[i]; + ans++; + } + if (a[i] != k) { + k = a[i]; + ans++; + } + } + cout << ans << endl; + return 0; +} +int ans, now; +int c, v0, v1, a, l; +int main() { + cin >> c >> v0 >> v1 >> a >> l; + while (1) { + ans++; + now += v0; + if (now >= c) break; + v0 += a; + if (v0 > v1) v0 = v1; + now -= l; + if (now < 0) now = 0; + } + cout << ans << endl; +} +long long n, a, b, c; +int main() { + cin >> n >> a >> b >> c; + if (n % 4 == 0) + cout << "0" << endl; + else if (n % 4 == 3) { + if (a <= b + c && a <= 3 * c) + cout << a << endl; + else if (b + c <= 3 * c) + cout << b + c << endl; + else + cout << 3 * c << endl; + } else if (n % 4 == 2) { + if (2 * a <= b && 2 * a <= 2 * c) { + cout << 2 * a << endl; + } else if (b <= 2 * c) { + cout << b << endl; + } else + cout << 2 * c << endl; + } else { + if ((3 * a <= (a + b)) && 3 * a <= c) { + cout << 3 * a << endl; + } else if (a + b <= c) { + cout << a + b << endl; + } else + cout << c << endl; + } + return 0; +} +int soldier[100001]; +int armor[100001]; +vector ans1; +vector ans2; +int n, m, x, y, s = 0, a = 0; +int f(int a, int b) { + if (a < b) { + if (a + y >= b) { return 0; } + if (a + y < b) { return 1; } + } + if (a > b) { + if (a - x <= b) { return 0; } + if (a - x > b) { return 2; } + } + if (a == b) { return 0; } +} +int main() { + cin >> n >> m >> x >> y; + for (int i = 0; i < n; i++) { cin >> soldier[i]; } + for (int i = 0; i < m; i++) { cin >> armor[i]; } + while (s != n && a != m) { + if (f(soldier[s], armor[a]) == 0) { + ans1.push_back(s + 1); + ans2.push_back(a + 1); + s++; + a++; + } else if (f(soldier[s], armor[a]) == 2) { + a++; + } else if (f(soldier[s], armor[a]) == 1) { + s++; + } + } + cout << ans1.size() << endl; + for (int i = 0; i < ans1.size(); i++) { cout << ans1[i] << " " << ans2[i] << endl; } + return 0; +} +const int maxn = 1002; +const long long mod = 1e9 + 7; +long long k, c, num = 0; +long long ans = 1; +int a[maxn][maxn]; +void init() { + for (int i = 1; i < maxn; i++) { + a[i][1] = 1; + for (int j = 2; j <= i; j++) { a[i][j] += (a[i - 1][j] + a[i - 1][j - 1]) % mod; } + } +} +int main() { + init(); + cin >> k; + for (int i = 0; i < k; i++) { + cin >> c; + num += c; + ans = (ans * a[num][c]) % mod; + } + cout << ans << endl; + return 0; +} +long long n, p[1000]; +int main() { + cin >> n; + for (int i = 1; i <= n / 2; i++) cin >> p[i]; + sort(p + 1, p + (n / 2) + 1); + long long B = 0; + long long W = 0; + for (int i = 1; i <= n / 2; i++) { + B += abs(p[i] - (i * 2 - 1)); + W += abs(p[i] - (i * 2)); + } + cout << min(B, W) << endl; + return 0; +} +int main() { + vector bag; + set table; + int n, x; + int total = 0; + int max = 0; + cin >> n; + for (int i = 0; i < (n * 2); i++) { + cin >> x; + bag.push_back(x); + } + for (vector::iterator it = bag.begin(); it != bag.end(); it++) { + if (table.find(*it) != table.end()) { + table.erase(*it); + total--; + } else { + total++; + table.insert(*it); + } + if (total > max) max = total; + } + cout << max << endl; + return 0; +} +int table[20][20]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { table[1][i] = 1; } + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= n; j++) { table[i][j] = table[i - 1][j] + table[i][j - 1]; } + } + cout << table[n][n] << "\n"; +} +int main() { + int n; + int xx[32][32]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> xx[i][j]; } + } + int b = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int sum1 = 0; + int sum2 = 0; + for (int s = 0; s < n; s++) { + for (int t = 0; t < n; t++) { + if (s == i) sum1 += xx[s][t]; + if (t == j) sum2 += xx[s][t]; + } + } + if (sum1 < sum2) { b++; } + } + } + cout << b << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int n; + cin >> n; + while (n--) { + cout << a + " " + b << "\n"; + string c, d; + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + } + cout << a + " " + b << "\n"; + return 0; +} +int main() { + int ar[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n; + cin >> n; + int l = (n / 10), r = (n % 10); + cout << ar[l] * ar[r] << '\n'; + return 0; +} +const int MX = 1000000000; +const int N = 1e5 + 7; +int a[N]; +int cnt[N]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + a[n + 1] = MX; + while (m--) { + int l, r, y; + cin >> l >> r >> y; + if (l > 1) continue; + int idx = upper_bound(a, a + n + 2, r) - a - 1; + if (idx == 0) continue; + cnt[idx]++; + } + for (int i = n; i >= 0; i--) cnt[i] += cnt[i + 1]; + int ans = 1e9 + 7; + for (int i = 0; i <= n; i++) { ans = min(ans, i + cnt[i + 1]); } + cout << ans << endl; +} +int main() { + int a, b; + cin >> a >> b; + if ((a || b) && abs(a - b) <= 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + int temp, j = 0, d = 0, t = 0; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp == 1) { + j++; + } else if (temp == 2) { + d++; + } else + t++; + } + temp = max(max(j, t), max(j, d)); + cout << n - temp << endl; + return 0; +} +int n, m; +int ma[110][110]; +int a[110]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= m; i++) { + int u, v; + cin >> u >> v; + ma[u][v] = ma[v][u] = 1; + } + int res = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + for (int k = j + 1; k <= n; k++) { + if (ma[i][j] && ma[j][k] && ma[i][k]) res = min(res, a[i] + a[j] + a[k]); + } + } + } + if (res == 0x3f3f3f3f) { + cout << "-1" << endl; + } else + cout << res << endl; + return 0; +} +int main() { + map mp; + int q; + cin >> q; + long long int a, b, c, d; + while (q--) { + cin >> a; + if (a == 1) { + cin >> b >> c >> d; + long long int h = max(b, c); + long long int l = min(b, c); + while (h != l) { + if (h > l) { + mp[h] += d; + h /= 2; + } + if (l > h) { + mp[l] += d; + l /= 2; + } + } + } else { + cin >> b >> c; + long long int ans = 0; + long long int h = max(b, c); + long long int l = min(b, c); + while (h != l) { + if (h > l) { + ans += mp[h]; + h /= 2; + } + if (l > h) { + ans += mp[l]; + l /= 2; + } + } + cout << ans << endl; + } + } + return 0; +} +int arr[104]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int total = 0; + for (int i = 0; i < n; i++) { + total += arr[i]; + k -= min(total, 8); + total -= min(total, 8); + if (k <= 0) { + cout << i + 1 << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int ax, ay, bx, by, cx, cy, n; + cin >> n >> ax >> ay >> bx >> by >> cx >> cy; + if (cx > bx) { + if (cy > by) { + if ((ax < cx && ax > bx) || (ay < cy && ay > by)) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + } else { + if ((ax < cx && ax > bx) || (ay > cy && ay < by)) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + } + } else { + if (cy > by) { + if ((ax > cx && ax < bx) || (ay < cy && ay > by)) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + } else { + if ((ax > cx && ax < bx) || (ay > cy && ay < by)) { + cout << "NO\n"; + } else { + cout << "YES\n"; + } + } + } + return 0; +} +long long a; +long long b; +long long m; +long long cont; +long long suma; +int main() { + cin >> a >> b >> m; + if (m > max(a, b) && b <= 0 && a <= 0) { + cout << -1 << endl; + goto salir; + } + suma = a + b; + b = max(a, b); + a = suma - b; + if (b >= m) { + cout << 0 << endl; + goto salir; + } + if (a < 0) { + long long k = (-a) / b; + cont = k; + a += k * b; + } + for (long long i = 0; i <= 1000000; i++) { + suma = a + b; + b = max(a, b); + a = suma - b; + if (b >= m) { + cout << cont << endl; + goto salir; + } + cont++; + a = suma; + } +salir:; +} +int C[1010][1010], k, s[1010], dp[1010], c[1010]; +int main() { + C[0][0] = 1; + for (int i = 1; i <= 1000; i++) { + C[i][0] = 1; + for (int j = 1; j <= i; j++) { C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; } + } + cin >> k; + for (int i = 1; i <= k; i++) { + cin >> c[i]; + s[i] = s[i - 1] + c[i]; + } + dp[0] = 1; + for (int i = 1; i <= k; i++) { dp[i] = 1LL * C[s[i] - 1][c[i] - 1] * dp[i - 1] % 1000000007; } + cout << dp[k] << endl; + return 0; +} +int top = -1; +int c[1000]; +void push(int x, int n) { + if (top < n - 1) { + top++; + c[top] = x; + } +} +int main() { + int i, n, k, j = 0, r; + cin >> n >> k; + int a[n], b[k]; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < k; i++) { cin >> b[i]; } + sort(b, b + k, greater()); + for (i = 0; i < n; i++) { + if (a[i] == 0) { + push(b[j], n); + j++; + } else { + push(a[i], n); + } + } + for (int i = top; i > 0; i--) { + if (c[i] > c[i - 1]) { + r = 1; + continue; + } else { + r = 0; + break; + } + } + if (r == 1) { + cout << "No\n"; + } else { + cout << "Yes\n"; + } + return 0; +} +int main() { + int n, k, f, t, m, j; + cin >> n >> k >> f >> t; + if (t > k) { + m = f - (t - k); + } else { + m = f; + } + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) { + j = f - (t - k); + } else { + j = f; + } + if (j > m) { m = j; } + } + cout << m << endl; + return 0; +} +int main() { + int n, m, a[1000], i, ans = INT_MAX; + cin >> n >> m; + for (i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + for (i = 0; i <= m - n; i++) ans = min(ans, a[i + n - 1] - a[i]); + cout << ans << endl; +} +int main() { + int n; + int a, b; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + int ans = 0; + while (a > 0 && b > 0) { + if (a > b) { + ans += (a / b); + a = a % b; + } else { + ans += (b / a); + b = b % a; + } + } + cout << ans << endl; + } +} +int main() { + long long n, k = 0; + cin >> n; + long long a[n + 1][n + 1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> a[i][j]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int s1, s2; + s1 = s2 = 0; + for (int k = 0; k < n; k++) s1 += a[i][k], s2 += a[k][j]; + if (s2 > s1) k++; + } + } + cout << k << endl; + return 0; +} +char su; +string p1, p2; +int i, j; +char c[9] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; +int main() { + cin >> su >> p1 >> p2; + if (p1[1] == su && p2[1] != su) + cout << "YES" << endl; + else if (p1[1] != p2[1]) + cout << "NO" << endl; + else { + for (i; i < 9; i++) { + if (c[i] == p1[0]) break; + } + for (j; j < 9; j++) { + if (c[j] == p2[0]) break; + } + if (i > j) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +string str, str1, str2, str3; +int main() { + cin >> str >> str1; + int days = 0; + cin >> days; + cout << str << " " << str1 << endl; + while (days > 0, days--) { + cin >> str2 >> str3; + if (str2 == str) { str = str3; } + if (str2 == str1) { str1 = str3; } + cout << str << " " << str1 << endl; + } + return 0; +} +int main() { + long long int n, sum, a; + cin >> n; + a = 0; + while (++a) { + sum = ((1 + a) * a) / 2; + if (n - sum < 0) break; + } + sum = (a * (a - 1)) / 2; + if (n - sum == 0) + cout << a - 1 << endl; + else + cout << n - sum << endl; +} +int main() { + string s; + cin >> s; + int cont = 0; + char tc = 'a'; + for (int i = 0; i < s.length(); i++) { + int a, b; + a = tc; + b = s[i]; + if (abs(a - b) > 13) + cont += (26 - abs(a - b)); + else + cont += abs(a - b); + tc = s[i]; + } + cout << cont << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n][2]; + int count = 0; + for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][0] == arr[j][1]) { count++; } + } + } + cout << count << endl; +} +int n, m, a[1004], tmp, minx = 0x3f3f3f3f; +inline int minn(const int &a, const int &b) { + if (a > b) + return b; + else + return a; +} +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) cin >> tmp, a[tmp]++; + for (int i = 1; i <= n; i++) minx = minn(minx, a[i]); + cout << minx << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + int counter1 = 0, counter2 = 0; + for (i = 0; i < n; i++) { + if (arr[i] % 2 != 0) { + counter1++; + } else { + counter2++; + } + } + if (counter1 > counter2) { + for (i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + cout << i + 1 << endl; + break; + } + } + } else { + for (i = 0; i < n; i++) { + if (arr[i] % 2 != 0) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int main() { + int n; + int i; + long long arr[200000]; + while (cin >> n) { + double sum = 0; + for (i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + sum /= 2; + double maxsum = 0; + for (i = 0; i < n; i++) { + maxsum += arr[i]; + if (maxsum >= sum) break; + } + cout << i + 1 << endl; + } +} +int main() { + int n, i, mn = 100, mx = 0, cont = 0, j; + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1 && i < mn) { mn = i; } + if (a[i] == 1 && i > mx) { mx = i; } + } + for (j = mn; j <= mx; j++) { + cont = cont + 1; + if (a[j] == 0 && a[j + 1] == 0) { + cont = cont - 1; + } else if (a[j - 1] == 0 && a[j] == 0) { + cont = cont - 1; + } + } + cout << cont << endl; + return 0; +} +string S; +int l1, val; +map M; +int main() { + cin >> S; + l1 = S.length(); + M[S]++; + for (int i = 1; i < l1; i++) { + S += S[0]; + S.erase(0, 1); + if (M[S] == 0) { + val++; + M[S]++; + } + } + cout << val + 1 << '\n'; +} +int n, v[105], i, j, maxi = -12312, a; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a; + if (i == 1) { + v[i] = a; + } else + v[i] = v[i - 1] ^ a; + } + for (i = 1; i <= n; i++) { + for (j = n; j >= i; j--) { + if (maxi < (v[i - 1] ^ v[j])) { maxi = v[i - 1] ^ v[j]; } + } + } + cout << maxi << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + stack st; + for (int i = 0; i < s.size(); i++) { + if (st.empty()) + st.push(s[i]); + else if (st.top() == s[i]) + st.pop(); + else + st.push(s[i]); + } + string tmp = ""; + while (!st.empty()) { + tmp += st.top(); + st.pop(); + } + reverse(tmp.begin(), tmp.end()); + cout << tmp << "\n"; + return 0; +} +int main() { + int x, y, r, ans; + cin >> x >> y >> r; + if (2 * r > min(x, y)) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int arr[100]; + int sum = 0; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[i] <= m) + sum++; + else + break; + } + for (int i = n - 1; i > 0; i--) { + if (arr[i] <= m) + sum++; + else + break; + } + sum = sum > n ? n : sum; + cout << sum << endl; + } + return 0; +} +const int MOD = 1e9 + 7; +const long long INF = 1e18; +const int MAXN = 2e5 + 5; +const int MAXM = 1e7; +const int N = 5e3 + 10; +const double EPS = 1e-5; +int dx[] = {1, -1, 0, 0}; +int dy[] = {0, 0, 1, -1}; +int i, j, d; +int n, k, m; +long long second, first, p, q; +long long mceil(long long first, long long second) { + return first / second + !(first % second == 0); +} +long long getans() { + if (p == 0) { + if (first == 0) + return 0; + else + return -1; + } + if (p == q) { + if (first != second) return -1; + if (first == second) return 0; + } + long long t = mceil(first, p); + long long k = mceil(second - first, q - p); + long long kek = max(t, k); + return q * kek - second; +} +int main() { + int t; + cin >> t; + while (t--) { + cin >> first >> second >> p >> q; + cout << getans() << endl; + } + return 0; +} +int main() { + vector vect; + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + long long total = k * l / nl; + long long total1 = c * d; + long long total2 = p / np; + long long final = INT_MAX; + final = min(total1, min(total, total2)) / n; + cout << final << "\n"; +} +int main() { + int n, k; + int a[100005]; + while (cin >> n >> k) { + int i, j; + int sum = 1; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = k + 1; i <= n; i++) { + if (a[i - 1] == a[i]) { sum++; } + } + if (sum == n - k + 1) { + int qiu = 0; + for (i = k - 1; i >= 1; i--) { + if (a[i] != a[k]) { + qiu = i; + break; + } + } + cout << qiu << endl; + } else { + cout << "-1" << endl; + } + } + return 0; +} +const double pi = 3.14159265359; +const int INF = 0x3f3f3f3f; +int main() { + int mat[5][5], x, y; + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 4; j++) { + cin >> mat[i][j]; + if (mat[i][j]) { + x = j; + y = i; + } + } + } + cout << abs(x - 2) + abs(y - 2) << "\n"; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int v[m][n]; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) cin >> v[i][j]; + for (int i = 0; i < m; ++i) + if (v[i][0] || v[i][n - 1]) { + cout << 2 << '\n'; + return 0; + } + for (int i = 0; i < n; ++i) + if (v[0][i] || v[m - 1][i]) { + cout << 2 << '\n'; + return 0; + } + cout << 4 << '\n'; + return 0; +} +int main() { + long long x; + cin >> x; + if (x % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + vector votes; + int ncandidates; + cin >> ncandidates; + for (int i = 0; i < ncandidates; i++) { + int nvotes; + cin >> nvotes; + votes.push_back(nvotes); + } + int changedVotes = 0; + while (true) { + int bestIndex = 0; + int bestVotes = -1; + for (int i = 1; i < votes.size(); i++) + if (votes[i] > bestVotes) { + bestIndex = i; + bestVotes = votes[i]; + } + if (bestVotes >= votes[0]) { + changedVotes++; + votes[0]++; + votes[bestIndex]--; + } else { + break; + } + } + cout << changedVotes << endl; + return 0; +} +int main() { + string str; + cin >> str; + int pearls = 0, links = 0; + for (int i = 0; i < str.size(); i++) { + if (str[i] == 'o') + pearls++; + else + links++; + } + if (pearls == 0 || links == 0) { + cout << "YES" << endl; + return 0; + } + if ((links % pearls) != 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int a, b; + int i, j, count; + int flag = 0; + cin >> a >> b; + for (i = a + 1; i <= b; i++) { + count = 0; + for (j = 2; j < i / 2 + 1; j++) { + if (i % j == 0) { count++; } + } + if (count == 0) { + if (i == b) { + cout << "YES" << endl; + flag = 1; + break; + } else { + cout << "NO" << endl; + flag = 1; + break; + } + } + } + if (!flag) cout << "NO" << endl; + return 0; +} +string s; +int main() { + cin >> s; + int l = s.length(); + int f1 = 0, f2 = 0, f3 = 0; + for (int i = 0; i < l; i++) + if (s[i] >= 'a' && s[i] <= 'z') { + f1 = 1; + break; + } + for (int i = 0; i < l; i++) + if (s[i] >= 'A' && s[i] <= 'Z') { + f2 = 1; + break; + } + for (int i = 0; i < l; i++) + if (s[i] >= '0' && s[i] <= '9') { + f3 = 1; + break; + } + if (l >= 5 && f1 && f2 && f3) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +bool the_same(string s1, string s2) { + return (s1[0] == s2[0] || s1[1] == s2[1]); +} +int main() { + signed long long a, b, k, t; + cin >> t; + while (t) { + cin >> a >> b >> k; + if (k % 2 != 0) + cout << (a * ((k / 2) + 1)) - (b * (k / 2)) << endl; + else + cout << (a * (k / 2)) - (b * (k / 2)) << endl; + t--; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + char cz; + long long num; + long long leftnum = k, leavekid = 0; + for (int i = 0; i < n; i++) { + cin >> cz >> num; + if (cz == '+') { + leftnum += num; + } else { + if (leftnum < num) { + leavekid++; + } else { + leftnum -= num; + } + } + } + cout << leftnum << ' ' << leavekid << endl; + return 0; +} +bool compare(int a, int b) { + return (a < b); +} +int main() { + int arr[3]; + while (cin >> arr[0] >> arr[1] >> arr[2]) { + sort(arr, arr + 3); + if (arr[0] + arr[1] > arr[2]) { + cout << 0 << endl; + } else { + cout << (arr[2] + 1 - arr[1] - arr[0]) << endl; + } + } + return 0; +} +int main() { + int k, r; + cin >> k >> r; + for (int i = 1; i <= 10; i++) { + if ((k * i) % 10 == 0 || (k * i) % 10 == r) { + cout << i << "\n"; + return 0; + } + } +} +const int N = 1e5 + 5; +int n, res = 1, Max = 1; +pair a[N]; +void Input() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; + sort(a + 1, a + n + 1); +} +void Solve() { + int curr = 1; + for (int i = 2; i <= n; i++) { + if (a[i].first == a[i - 1].first && a[i].second == a[i - 1].second) + curr++, res = max(res, curr); + else + curr = 1; + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if ((x > b) && (x < c)) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int time = 240 - k; + int sum = 0; + int count = 0; + while (sum + (count + 1) * 5 <= time && count < n) { + count++; + sum += count * 5; + } + cout << count << endl; + return 0; +} +int Addition(int n) { + int s; + s = (n * (1 + n)) / 2; + return s; +} +int main() { + int a, i = 0; + cin >> a; + if (a > 0) { + a = a - Addition(i); + while (a > 0) { + i++; + a = a - Addition(i + 1); + } + cout << i << endl; + } else + cout << "0" << endl; +} +int main() { + puts("Karen"); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int temp = m; + int len = 1; + while (len != n + 1) { + if (len % 2 != 0) { + while (m != 1) { + cout << "#"; + m--; + } + if (m == 1) { + cout << "#" << endl; + m = temp; + } + } else { + if (len % 4 != 0) { + while (m != 1) { + cout << "."; + m--; + } + if (m == 1) { + cout << "#" << endl; + m = temp; + } + } else { + cout << "#"; + m--; + while (m != 1) { + cout << "."; + m--; + } + if (m == 1) { + cout << "." << endl; + m = temp; + } + } + } + len++; + } + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * b / gcd(a, b); +} +int main() { + long long i, j; + long long n; + cin >> n; + vector a(n); + for (long long i = 0; i < (n); i++) cin >> a[i]; + for (long long i = 0; i < (1000); i++) { + long long t = i; + for (long long j = 1; j < (n); j++) + if (a[j] >= a[0] + i) { t -= a[j] - (a[0] + i) + 1; } + if (t >= 0) { + cout << i << endl; + return 0; + } + } +} +const int mod = 1e9 + 7; +const int maxn = 110; +const int inf = 0x3f3f3f3f; +int p[maxn]; +int q[maxn]; +int main() { + int t; + while (cin >> t) { + for (int i = 1; i <= t; i++) { cin >> p[i]; } + sort(p + 1, p + 1 + t); + cout << p[t] << ' '; + for (int i = 2; i < t; i++) { cout << p[i] << ' '; } + cout << p[1] << endl; + } + return 0; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long a, b, x; + cin >> a >> b >> x; + long long h = x / 2; + long long ans = 0; + ans -= h * b; + ans += (x - h) * a; + cout << ans << endl; + } +} +const int MAXN = 500 + 20; +const int INF = 1e9 + 100; +const int MOD = 1e9; +int main() { + int n; + while (cin >> n) { + int gcd = 0, mx = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + mx = max(x, mx); + gcd = __gcd(gcd, x); + } + int ans = (mx / gcd - n); + if (ans & 1) + cout << "Alice" << endl; + else + cout << "Bob" << endl; + } +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, m, a[N], now, ans, b, d; +set st; +string s, t; +int main() { + cin >> n >> b >> d; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > b) continue; + now += a[i]; + if (now > d) { + ans++; + now = 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + int indexT, indexG; + for (size_t i = 0; i < n; i++) { + cin >> v[i]; + if (v[i] == 'T') + indexT = i; + else if (v[i] == 'G') + indexG = i; + } + bool found = false; + if (indexT > indexG) { + for (size_t i = indexG; i <= indexT; i += k) { + if (v[i] == '#') break; + if (v[i] == 'T') found = true; + } + } else { + for (size_t i = indexT; i <= indexG; i += k) { + if (v[i] == '#') break; + if (v[i] == 'G') found = true; + } + } + if (found) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10) + cout << "0" << endl; + else { + if (n >= 11 && n <= 19) + cout << "4" << endl; + else if (n == 20) + cout << "15" << endl; + else if (n == 21) + cout << "4" << endl; + else if (n > 21) + cout << "0" << endl; + } +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int c[n + 1]; + for (int i = 0; i < n; i++) cin >> c[i]; + int l = 0, f = n - 1, cost = 0; + int min_cost = min(a, b), flag = 1; + while (l < f) { + if (c[l] == c[f] && c[l] != 2) { + l++; + f--; + } else if (c[l] == c[f] && c[l] == 2) { + cost += 2 * min_cost; + l++; + f--; + } else if (c[l] == 2) { + cost += c[f] * b + (1 - c[f]) * a; + l++; + f--; + } else if (c[f] == 2) { + cost += c[l] * b + (1 - c[l]) * a; + l++; + f--; + } else { + flag = 0; + break; + } + } + if (l == f && c[l] == 2) cost += min_cost; + if (flag == 0) + cout << "-1\n"; + else { + cout << cost << endl; + } + return 0; +} +const int maxn = 2e5 + 10; +const int inf = 0x3f3f3f3f; +const int mod = 1e9 + 7; +int a[maxn]; +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int ans = inf; + for (int i = 0; i < n / 2; i++) ans = min(ans, a[n / 2 + i] - a[i]); + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + float a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int m; + cin >> m; + float b[m]; + for (int i = 0; i < m; i++) cin >> b[i]; + vector v; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + float t1; + t1 = b[j] / a[i]; + if (t1 - floor(t1) == 0) { v.push_back(t1); } + } + } + cout << count(v.begin(), v.end(), *max_element(v.begin(), v.end())) << endl; + return 0; +} +vector pc(210), adj[210], req(210), creq(210), vis(210, 0), empty(210, 0); +int n; +int solve(int cur) { + for (int i = 1; i <= n; i++) { + if (!vis[i]) break; + if (i == n) return 0; + } + int cnt = 0; + while (true) { + bool ok = 0; + for (int i = 1; i <= n; i++) { + if (pc[i] == cur && !creq[i] && !vis[i]) { + for (int j = 0; j < adj[i].size(); j++) creq[adj[i][j]]--, ok = 1; + vis[i] = 1; + cnt++; + } + } + if (!ok) break; + } + return solve(cur % 3 + 1) + cnt + 1; +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> pc[i]; + for (int i = 1; i <= n; i++) { + int k; + cin >> k; + req[i] = k; + while (k--) { + int a; + cin >> a; + adj[a].push_back(i); + } + } + int mn = 1e9; + for (int i = 1; i <= 3; i++) creq = req, vis = empty, mn = min(mn, solve(i) - 1); + cout << mn << endl; +} +int main() { + int n, a, b; + string s; + int ans; + cin >> n >> a >> b >> s; + if (s[a - 1] == s[b - 1]) { + ans = 0; + } else { + ans = 1; + } + cout << ans << '\n'; + return 0; +} +int a[105]; +int n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + while (a[0] != a[n - 1]) { + for (int i = 1; i < n; i++) { + if (a[i] > a[0]) a[i] -= a[0]; + } + sort(a, a + n); + } + cout << n * a[0] << endl; + return 0; +} +const int maxn = 3e5 + 500; +int main() { + int n, mmp[35][35], ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) cin >> mmp[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int l = 0, r = 0; + for (int k = 1; k <= n; k++) r += mmp[i][k]; + for (int h = 1; h <= n; h++) l += mmp[h][j]; + if (l > r) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + char num1[15], num2[15], a[15], b[15]; + cin >> num1 >> num2; + cout << num1 << " " << num2 << endl; + int n, flag; + cin >> n; + while (n--) { + cin >> a >> b; + flag = strcmp(num1, a); + if (flag) { + strcpy(num2, b); + } else { + strcpy(num1, b); + } + cout << num1 << " " << num2 << endl; + } +} +int x[10000000]; +int main() { + int n; + string x1, x2; + cin >> n >> x1 >> x2; + int w1 = 0, w2 = 0; + int p1 = 0; + bool done = false, done2 = false; + int p2 = 0; + int count = 0; + while (true) { + if (x1[p1] == 'P' && x2[p2] == 'R') + x[count] = 1; + else if (x1[p1] == 'R' && x2[p2] == 'P') + x[count] = 2; + else if (x1[p1] == 'S' && x2[p2] == 'P') + x[count] = 1; + else if (x1[p1] == 'P' && x2[p2] == 'S') + x[count] = 2; + else if (x1[p1] == 'R' && x2[p2] == 'S') + x[count] = 1; + else if (x1[p1] == 'S' && x2[p2] == 'R') + x[count] = 2; + p1++; + p2++; + if (p1 == x1.size()) { + done = true; + p1 = 0; + } + if (p2 == x2.size()) { + done2 = true; + p2 = 0; + } + count++; + if (done || done2) + if (p1 == p2) break; + } + if (n > count && count > 0) { + for (int i = 0; i < count; i++) + if (x[i] == 1) + w2++; + else if ((x[i] == 2)) + w1++; + w1 = w1 * (n / count); + w2 = w2 * (n / count); + int val = n % count; + for (int i = 0; i < val; i++) + if (x[i] == 1) + w2++; + else if ((x[i] == 2)) + w1++; + } else if (count > 0) { + for (int i = 0; i < n; i++) + if (x[i] == 1) + w2++; + else if ((x[i] == 2)) + w1++; + } + cout << w1 << " " << w2 << endl; +} +int main() { + int n; + cin >> n; + char w; + string t, r; + for (int i = 0; i < n * n; i++) { + cin >> w; + t += w; + } + r = t; + reverse(r.begin(), r.end()); + if (r == t) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char a[101][101]; +string b; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> b; + for (int j = 1; j <= m; j++) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + if (b[j - 1] == '-') a[i][j] = '-'; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +char a[101][101]; +string b; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> b; + for (int j = 1; j <= m; j++) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + if (b[j - 1] == '-') a[i][j] = '-'; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int arrA[100005]; +int arrB[100005]; +int nA, nB, k, m; +int main() { + cin >> nA >> nB; + cin >> k >> m; + for (int i = 0; i < nA; i++) cin >> arrA[i]; + for (int i = 0; i < nB; i++) cin >> arrB[i]; + if (arrA[k - 1] < arrB[nB - m]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, r; + cin >> n >> r; + int sum = 0; + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + sum += input; + } + int need = abs(sum), count = 0; + for (int i = r; i >= 1; --i) { + if (need < i) continue; + if (need == 0) break; + while (need >= i) { + need -= i; + count++; + } + } + cout << count << endl; + return 0; +} +long long int maxx(long long int &a, long long int &b) { + return a > b ? a : b; +} +long long int minn(long long int &a, long long int &b) { + return a > b ? b : a; +} +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +int int_gcd(int a, int b) { + return b == 0 ? a : int_gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return a / gcd(a, b) * b; +} +long long int poww(long long int base, long long int exp, long long int mod) { + base %= mod; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % mod; + base = (base * base) % mod; + exp >>= 1; + } + return result; +} +int main() { + long long int ans = 1e18; + long long int n, a, b, c; + cin >> n >> a >> b >> c; + for (int i = 0; i <= 100; i++) { + for (int j = 0; j <= 100; j++) { + for (int k = 0; k <= 100; k++) { + if ((n + i + 2 * j + 3 * k) % 4 == 0) { ans = min(ans, (long long int)i * a + b * j + c * k); } + } + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + long long a = 0, b = 0, ans = 0; + for (int i = 0; i < n; ++i) { + if (i % 2 == 0) { + ans = (ans + a + 1) % 1000000007; + b = (a + b + 1) % 1000000007; + } else { + ans = (ans + b + 1) % 1000000007; + a = (a + b + 1) % 1000000007; + } + } + cout << ans << endl; +} +const int maxn = 2e5 + 10; +int arr[maxn], n, a, b; +int main() { + cin >> n >> a >> b; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + cout << arr[b] - arr[b - 1] << endl; +} +int main() { + long long n, k, x; + cin >> n >> k; + x = n / k; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string marks[n]; + int h_marks, count = 0; + for (int i = 0; i < n; i++) cin >> marks[i]; + for (int i = 0; i < n; i++) { + bool best = false; + for (int j = 0; j < m; j++) { + h_marks = -1; + for (int k = 0; k < n; k++) h_marks = max(marks[k][j] - 48, h_marks); + if (h_marks == marks[i][j] - 48) best = true; + } + if (best) count++; + } + cout << count << endl; + return 0; +} +string s, ss; +int k[26]; +int a[26]; +int main() { + cin >> s >> ss; + int x = s.length(), y = ss.length(); + string s1 = "zzzzzzzzzzzz"; + string s2; + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + s2 = s.substr(0, i + 1) + ss.substr(0, j + 1); + s1 = min(s1, s2); + } + } + cout << s1 << endl; + return 0; +} +int main() { + int arr[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + string m; + cin >> m; + int x = m[0] - '0'; + int y = m[1] - '0'; + cout << (arr[x] * arr[y]) << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int i; + for (i = 1; n; i++) { + n--; + if (!n) break; + if (n && i % m == 0) n++; + } + if (i % m == 0) i++; + cout << i << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n; + cin >> n; + long long x[n + 1], y[n + 1]; + long long a[100000 + 1]; + for (long long int i = 0; i < n; i++) cin >> x[i] >> y[i]; + long long ans = 0; + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < n; j++) { + if (x[i] == y[j]) ans++; + } + } + cout << ans << '\n'; + } + return 0; +} +int main() { + int n = 0; + while (cin >> n) { + int a[35][2] = {0}; + int cnt = 0; + for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][0] == a[j][1]) cnt++; + } + } + cout << cnt << endl; + } +} +int main() { + long long a, b; + cin >> a >> b; + long long temp = 0; + while (b > 0) { + temp = (temp * 10) + (b % 10); + b /= 10; + } + cout << a + temp << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + if (n == 2) { + cout << 2 << endl; + } else { + cout << 1 << endl; + } + } + return 0; +} +void READ(string INPUT = "NO", string OUTPUT = "NO") { + if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin); + if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout); +} +bool ok(string x) { + if (!(int)x.size()) return true; + if ((int)x.size() >= 3 && x.substr(0, 3) == "144" && ok(x.substr(3))) return true; + if ((int)x.size() >= 2 && x.substr(0, 2) == "14" && ok(x.substr(2))) return true; + if ((int)x.size() >= 1 && x.substr(0, 1) == "1" && ok(x.substr(1))) return true; + return false; +} +int main() { + string x; + cin >> x; + cout << (ok(x) ? "YES\n" : "NO\n"); + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + unsigned long long n, sum = 0; + cin >> n; + string arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == "Tetrahedron") + sum += 4; + else if (arr[i] == "Cube") + sum += 6; + else if (arr[i] == "Octahedron") + sum += 8; + else if (arr[i] == "Dodecahedron") + sum += 12; + else + sum += 20; + } + cout << sum << endl; + return 0; +} +const long long INF = (1ll << 62) - 1; +const int M = 1e5 + 5; +long long ar[100005]; +long long cnt = 1, tot, res; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + for (int i = 1; i < n; i++) { + if (ar[i] == ar[i - 1]) + cnt++; + else { + tot = (cnt * (cnt + 1)) / 2; + res += tot; + cnt = 1; + } + } + res += (cnt * (cnt + 1)) / 2; + cout << res << endl; +} +int main() { + int n; + cin >> n; + vector ns(n), ans(n, 0); + for (int i = 0; i < n; i++) cin >> ns[i]; + ans[0] = 1; + int mx = 1; + for (int i = 1; i < n; i++) { + if (ns[i] < ns[i - 1]) + ans[i] = 1; + else + ans[i] = ans[i - 1] + 1; + mx = max(mx, ans[i]); + } + cout << mx << "\n"; + return 0; +} +int l, r, a; +int main() { + cin >> l >> r >> a; + while (l != r && a != 0) { + if (l < r) { + a--; + l++; + } + if (l > r) { + a--; + r++; + } + } + if (l != r) { + cout << min(l, r) * 2 << endl; + } else { + cout << l * 2 + (a / 2 * 2) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int cont = n / 2 + 1; + int star = n / 2; + int d = 1; + for (int c = 0; c < cont; c++) { + for (int s = 0; s < star; s++) { cout << "*"; } + for (int d1 = 0; d1 < d; d1++) { cout << "D"; } + for (int s = 0; s < star; s++) { cout << "*"; } + d += 2; + star -= 1; + cout << endl; + } + d -= 4; + star = 1; + for (int c = 0; c < cont - 1; c++) { + for (int s = 0; s < star; s++) { cout << "*"; } + for (int d1 = 0; d1 < d; + d1++) { cout << "D"; } + for (int s = 0; s < star; s++) { cout << "*"; } + d -= 2; + star += 1; + cout << endl; + } + return 0; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + long long int n, ma = 0, d = 0, i, num; + cin >> n; + for (i = 0; i < n; i++) { + cin >> num; + d = gcd(num, d); + ma = max(ma, num); + } + if ((ma / d - n) % 2) + cout << "Alice" << endl; + else + cout << "Bob" << endl; +} +int main() { + long long int a, b, c, d, e, f; + string s; + char u, v; + while (cin >> a >> b) { + cin >> s; + for (c = 1; c <= b; c++) { + cin >> d >> e >> u >> v; + for (f = d - 1; f <= e - 1; f++) { + if (s[f] == u) { s[f] = v; } + } + } + cout << s << endl; + } + return 0; +} +int max_elemento(vector coins_array) { + int max_element = 0; + for (int i = 0; i < coins_array.size(); i++) { + if (coins_array[i] > max_element) { max_element = coins_array[i]; } + } + return max_element; +} +int main() { + int coins_nro; + int coin_value; + vector coins_array(105, 0); + int result; + cin >> coins_nro; + for (int i = 0; i < coins_nro; i++) { + cin >> coin_value; + coins_array[coin_value]++; + } + result = max_elemento(coins_array); + cout << result << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) { + cout << 0 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else { + cout << 4 << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int l = s.size() - 1; + set st; + st.insert(s); + while (l--) { + s.push_back(s[0]); + s.erase(0, 1); + st.insert(s); + } + cout << st.size() << endl; +} +int main() { + long long a, b, n, m, ans; + cin >> n >> m >> a >> b; + if (n % m == 0) + ans = 0; + else if (n < m) { + ans = min(n * b, (m - n) * a); + } else { + long long cnt1, cnt2; + cnt1 = n % m; + cnt2 = n / m + 1; + ans = min((cnt2 * m - n) * a, cnt1 * b); + } + cout << ans << endl; + return 0; +} +bool Checking(char arr[], char A[]); +int main() { + short int n, m, res = 0; + char Pic[55][55]; + cin >> n >> m; + char arr[4], A[4]; + arr[0] = 'f'; + arr[1] = 'a'; + arr[2] = 'c'; + arr[3] = 'e'; + sort(arr, arr + 4); + for (short int i = 0; i < n; i++) { + for (short int j = 0; j < m; j++) { cin >> Pic[i][j]; } + } + for (short int i = 0; i < n; i++) { + for (short int j = 0; j < m; j++) { + short int count = 0; + if (Pic[i][j] == 'f') { + A[0] = Pic[i][j]; + A[1] = Pic[i][j + 1]; + A[2] = Pic[i + 1][j]; + A[3] = Pic[i + 1][j + 1]; + } else if (Pic[i][j] == 'a') { + A[0] = Pic[i][j]; + A[1] = Pic[i][j + 1]; + A[2] = Pic[i + 1][j]; + A[3] = Pic[i + 1][j + 1]; + } else if (Pic[i][j] == 'c') { + A[0] = Pic[i][j]; + A[1] = Pic[i][j + 1]; + A[2] = Pic[i + 1][j]; + A[3] = Pic[i + 1][j + 1]; + } else if (Pic[i][j] == 'e') { + A[0] = Pic[i][j]; + A[1] = Pic[i][j + 1]; + A[2] = Pic[i + 1][j]; + A[3] = Pic[i + 1][j + 1]; + } + sort(A, A + 4); + bool b = false; + b = Checking(arr, A); + if (b == true) { res++; } + } + } + cout << res << endl; + return 0; +} +bool Checking(char arr[], char A[]) { + bool b = true; + for (short int i = 0; i < 4; i++) { + if (arr[i] != A[i]) { b = false; } + } + return b; +} +int main() { + string s; + int i, j, n; + cin >> s; + n = s.size(); + int ans = 0; + for (i = 0; i < n; i = j) { + int p = 1; + for (j = i + 1; s[j] == s[i]; j++) p++; + if (!(p % 2)) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + vector v(6); + cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5]; + sort(v.begin(), v.end()); + int h, b; + if (v[0] == v[3]) { + h = 4; + b = 5; + } else if (v[1] == v[4]) { + h = 0; + b = 5; + } else if (v[2] == v[5]) { + h = 0; + b = 1; + } else { + cout << "Alien\n"; + return 0; + } + cout << (v[h] < v[b] ? "Bear\n" : "Elephant\n"); + return 0; +} +int main() { + long long int n; + cin >> n; + long long int Arr[n + 2], Sum = 0; + for (int i = 1; i <= n; i++) cin >> Arr[i], Sum += Arr[i]; + long long int s, t; + cin >> s >> t; + long long int Cnt = 0; + if (s > t) swap(s, t); + for (int i = s; i < t; i++) Cnt += Arr[i]; + cout << min(Cnt, Sum - Cnt) << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) cin >> ar[i]; + int mn = INT_MAX; + for (int i = 1; i < n - 1; i++) { + int mx = INT_MIN; + for (int j = 1; j < n; j++) { + if (i != j) + mx = max(mx, ar[j] - ar[j - 1]); + else + mx = max(mx, ar[j + 1] - ar[j - 1]); + } + mn = min(mn, mx); + } + cout << mn << endl; + return 0; +} +const int N = 2e6 + 123; +const int INF = 1e9 + 123; +const int MOD = 1e9 + 7; +const double EPS = 1e-9; +void solve() { + int L, v, l, r, x; + cin >> L >> v >> l >> r; + cout << (L / v) - ((r / v) - ((l - 1) / v)) << '\n'; +} +int main() { + int t; + cin >> t; + while (t) { + solve(); + --t; + } + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +string str, str1, str2, str3; +int main() { + cin >> str >> str1; + int days = 0; + cin >> days; + cout << str << " " << str1 << endl; + while (days > 0, days--) { + cin >> str2 >> str3; + if (str2 == str) { str = str3; } + if (str2 == str1) { str1 = str3; } + cout << str << " " << str1 << endl; + } + return 0; +} +int main() { + long long n, k, x = 0; + int a[100001]; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + x++; + if (a[i] - a[i - 1] > k) { + x = 1; + } else { + x = x; + } + } + cout << x << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + priority_queue pq; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (i) pq.push(arr[i]); + } + int cnt = 0; + while (!pq.empty()) { + int u = pq.top(); + pq.pop(); + if (u < arr[0]) break; + arr[0]++; + cnt++; + if (u > 1) pq.push(u - 1); + } + cout << cnt << endl; +} +map m; +string get(long long n) { + string num; + while (n) { + int e = n % 10; + if (e & 1) + num += '1'; + else + num += '0'; + n /= 10; + } + while (num.size() < 18) num += '0'; + reverse(num.begin(), num.end()); + return num; +} +int main() { + int t; + cin >> t; + while (t--) { + char ch; + cin >> ch; + if (ch == '+') { + long long n; + cin >> n; + string num = get(n); + m[num]++; + } else if (ch == '-') { + long long n; + cin >> n; + string num = get(n); + m[num]--; + } else { + string str; + cin >> str; + reverse(str.begin(), str.end()); + while (str.size() < 18) str += '0'; + reverse(str.begin(), str.end()); + cout << m[str] << endl; + } + } +} +int main() { + int n, m; + cin >> n >> m; + vector a(101, 0); + int x, y; + for (int i = 0; i < n; i++) { + cin >> x >> y; + a[x]++; + a[y]--; + } + int cs = 0; + for (int i = 0; i < m; i++) { + cs += a[i]; + if (cs <= 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + string s; + cin >> s; + long long n, i; + n = s.length(); + long long j, k, c = 0; + for (i = 0; i < n; i++) { + if (s[i] == 'Q') { + for (j = i + 1; j < n; j++) { + if (s[j] == 'A') { + for (k = j + 1; k < n; k++) { + if (s[k] == 'Q') c++; + } + } + } + } + } + cout << c << endl; + return 0; +} +const int N = 107; +int arr[N]; +int main() { + int n, m, sum = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + sort(arr + 1, arr + 1 + n); + sum -= arr[n]; + int maxn = arr[n], minx = arr[1]; + int ans1, ans2 = maxn + m; + if ((n - 1) * maxn - sum >= m) + ans1 = maxn; + else { + int tmp = m - ((n - 1) * maxn - sum); + ans1 = tmp / n + ((tmp % n == 0) ? 0 : 1) + maxn; + } + cout << ans1 << " " << ans2 << endl; + return 0; +} +set s[55]; +int main() { + int i, j, a[55][55], n, k; + bool ans = true; + cin >> n; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + cin >> a[i][j]; + s[i].insert(a[i][j]); + } + } + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + if (a[i][j] == 1) continue; + bool cur = false; + for (k = 1; k <= n; k++) { + if (s[i].find(a[i][j] - a[k][j]) != s[i].end()) cur = true; + } + if (!cur) ans = false; + } + } + if (ans) + cout << "Yes\n"; + else + cout << "No\n"; + return 0; +} +int main() { + int n, x, c = 0; + cin >> n; + vector v; + while (n--) { + cin >> x; + v.push_back(x); + } + for (int i = 0; i < v.size(); i++) { + if (v[i] == 1) { + c++; + } else if (v[i] == 0 && v[i + 1] == 1 && i > 0 && v[i - 1] != 0) { + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, sum = 0; + for (int i = 0; i < n; i++) { + cin >> a; + sum += a; + } + int temp = 0; + for (int i = 1; i <= 5; i++) { + if ((sum + i) % (n + 1) != 1) temp++; + } + cout << temp << endl; +} +int main() { + int a, b, c, n, k, m = 0; + cin >> a >> b >> c >> n; + while (n--) { + cin >> k; + if (k > b && k < c) { m++; } + } + cout << m << endl; +} +int main() { + int n; + while (cin >> n) { + int t = n / 5; + if (n % 5 == 0) { t--; } + cout << t + 1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int cur = 1, cnt = 0; + vector ans; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == cur) { + cnt++; + cur++; + } else { + ans.push_back(cnt); + cnt = 1; + cur = 2; + } + if (i == n - 1) { ans.push_back(cnt); } + } + cout << (int)ans.size() << endl; + for (int i = 0; i < (int)ans.size(); i++) { + if (i > 0) cout << " "; + cout << ans[i]; + } + cout << endl; + return 0; +} +int a[1000001] = {0}; +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + for (int j = 1; j <= t; j++) { + int g; + cin >> g; + if (a[g] == 0) a[g] = 1; + } + } + int flag = 1; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { + flag = 0; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + memset(a, 0, sizeof(a)); + } + return 0; +} +int main() { + int n, m, f[1000]; + cin >> n >> m; + for (int i = 0; i < m; ++i) { cin >> f[i]; } + sort(f, f + m); + int least = f[n - 1] - f[0]; + for (int i = 1; i <= m - n; ++i) { + if (f[i + n - 1] - f[i] < least) { least = f[i + n - 1] - f[i]; } + } + cout << least << endl; + return 0; +} +int main() { + int in[10][10]; + int n; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (0 == i || 0 == j) { + in[i][j] = 1; + } else { + in[i][j] = in[i - 1][j] + in[i][j - 1]; + } + } + cout << in[n - 1][n - 1] << endl; + return 0; +} +int main() { + cout << "Karen" << endl; +} +int main() { + int n, m; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> arr[i][j]; + string s = ""; + int cnt = 0; + for (int i = 0; i < n - 1; i++) + for (int j = 0; j < m - 1; j++) { + s += arr[i][j]; + s += arr[i + 1][j]; + s += arr[i][j + 1]; + s += arr[i + 1][j + 1]; + sort(s.begin(), s.end()); + if (s == "acef") cnt++; + s = ""; + } + cout << cnt << endl; +} +int ansmap[3][6] = {1, 2, 2, 1, 0, 0, 0, 0, 1, 2, 2, 1, 2, 1, 0, 0, 1, 2}; +int main() { + int n, x; + cin >> n >> x; + n = n % 6 - 1; + if (n == -1) n = 5; + for (int i = 0; i <= 2; i++) { + if (ansmap[i][n] == x) { cout << i << endl; } + } + return 0; +} +int main() { + string s1, s2, ans; + cin >> s1 >> s2; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] != s2[i]) + ans.push_back('1'); + else + ans.push_back('0'); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[n]; + int b[n]; + int max; + int count = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + max = a[0]; + for (int q = 1; q < n; q++) { + if (a[q] == 1) { b[++count] = a[q - 1]; } + } + cout << count + 1 << endl; + for (int j = 1; j <= count; j++) cout << b[j] << " "; + cout << a[n - 1] << endl; + } + return 0; +} +const int maxn = 1e5 + 5; +int n, len, cnt, ans, flag, vis[26], now[26]; +char c; +string str; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> c >> str; + len = str.size(); + if (c == '!') { + if (flag) + ans++; + else { + fill(now, now + 26, 1); + for (int j = 0; j < len; j++) { now[str[j] - 'a'] = 0; } + for (int j = 0; j < 26; j++) { + if (now[j] == 1) vis[j] = 1; + } + } + } else if (c == '?') { + if (flag && vis[str[0] - 'a'] == 1) { ans++; } + vis[str[0] - 'a'] = 1; + } else { + for (int j = 0; j < len; j++) { vis[str[j] - 'a'] = 1; } + } + cnt = 0; + for (int j = 0; j < 26; j++) { + if (vis[j] == 1) cnt++; + } + if (cnt == 25) flag = 1; + } + cout << ans << endl; + return 0; +} +int main() { + string str, str2, ans = "a"; + int n, flag = 0; + cin >> str; + int len = str.length(); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> str2; + flag = 0; + for (int j = 0; j < len; j++) { + if (str[j] != str2[j]) { + flag = 1; + break; + } + } + if (flag == 1) { continue; } + if (ans == "a") { + ans = str2; + } else if (str2 < ans) { + ans = str2; + } + } + if (ans != "a") { + cout << ans << endl; + } else { + cout << str << endl; + } + return 0; +} +int main() { + srand(time(NULL)); + long long n; + cin >> n; + long long a[n]; + long long b[n]; + set s; + for (long long i = 0; i < n; i++) { + cin >> a[i]; + s.insert(a[i]); + } + for (long long i = 0; i < n; i++) { + cin >> b[i]; + s.insert(b[i]); + } + long long ct = 0; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { + long long val = a[i] ^ b[j]; + if (s.find(val) != s.end()) { ct++; } + } + } + if (ct % 2 == 0) { + cout << "Karen" << endl; + } else { + cout << "Koyomi" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else if (i % 2 == 0 && i % 4 != 0 && j == m) { + cout << "#"; + } else if (i % 2 == 0 && i % 4 == 0 && j == 1) { + cout << "#"; + } else { + cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + int a, b, c, t, m; + while (cin >> a >> b >> c) { + m = (a * c) - (b * c); + x: + if (m % b == 0) { + t = m / b; + } else { + m = m + 1; + goto x; + } + cout << t << endl; + } +} +void sort(char *arr, int n) { + int i, j; + for (i = 0; i < n; i++) { + for (j = i + 1; j < n; j++) { + if (arr[j] < arr[i]) { + int t; + t = arr[j]; + arr[j] = arr[i]; + arr[i] = t; + } + } + } +} +int main() { + char str[100]; + cin >> str; + int size, i = 0; + while (str[i] != '\0') { i++; } + size = i; + int size2 = (size + 1) / 2; + char str2[size2]; + for (int i = 0, j = 0; i < size; i++) { + if (str[i] != '+') { + str2[j] = str[i]; + j++; + } + } + sort(str2, size2); + for (int i = 0; i < size2; i++) { + if (i != size2 - 1) + cout << str2[i] << "+"; + else + cout << str2[i] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + map mp; + map::iterator it; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + mp[x]++; + } + int c = 0; + for (it = mp.begin(); it != mp.end(); it++) { + if (it->first == 0) continue; + if (it->second > 2) { + c = -1; + break; + } else if (it->second == 2) + c++; + } + cout << c << endl; + return 0; +} +int main() { + string s, ans; + cin >> s; + int len = s.size(); + for (int i = 0; i < len; i++) { + if (s[i + 1] == '.') { + if (s[i] == '9') { + cout << "GOTO Vasilisa.\n"; + return 0; + } else if (s[i + 2] < '5') { + ans.push_back(s[i]); + break; + } else if (s[i + 2] >= '5') { + int n; + n = s[i] + 1; + ans.push_back((char)n); + break; + } + } else { + ans.push_back(s[i]); + } + } + cout << ans << endl; +} +int main() { + int i, n, m, c, points = INT_MAX, squares[1005] = {0}; + cin >> n >> m; + for (i = 0; i < m; i++) { + cin >> c; + squares[c]++; + } + for (i = 1; i <= n; i++) points = min(points, squares[i]); + cout << points << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; ++i) { + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + for (int j = 1; j <= 2 * i - 1; ++j) cout << "D"; + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n / 2; ++i) { + for (int j = 1; j <= i; ++j) cout << "*"; + for (int j = 1; j <= n - i * 2; ++j) cout << "D"; + for (int j = 1; j <= i; ++j) cout << "*"; + cout << endl; + } + return 0; +} +int a[100]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i != n; ++i) cin >> a[i]; + sort(a, a + n, greater()); + int ans1 = a[0] + m, ans2 = a[0]; + for (int i = 1; i != n; ++i) { + if (a[0] - a[i] <= m) + m -= a[0] - a[i]; + else + m = 0; + } + if (m) ans2 += (m - 1) / n + 1; + cout << ans2 << ' ' << ans1 << endl; + return 0; +} +int main() { + int maxSections, nuts, divis, nut2sec, boxes = 0; + cin >> maxSections >> nuts >> divis >> nut2sec; + while (nuts > 0) { + boxes++; + nuts -= (min(maxSections, divis + 1)) * nut2sec; + divis -= min(maxSections, divis + 1) - 1; + } + cout << boxes << endl; + return 0; +} +int main() { + int no1; + cin >> no1; + for (int d = 0; d < no1; d++) { + int a; + cin >> a; + a = 180 - a; + int temp = 360 / a; + ; + if (temp * a == 360) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n, ans = 0; + cin >> n; + double R = n; + long long tmp = n, k; + for (long long i = 1; i <= n; i++) { + double r = i; + k = (long long)sqrt(R * R - r * r); + ans += (tmp == k ? 1 : tmp - k); + tmp = k; + } + if (n == 0) + cout << 1 << endl; + else + cout << ans * 4 << endl; + return 0; +} +int main() { + int x, sum = 0; + cin >> x; + while (x) { + if (x % 2) sum++; + x /= 2; + } + cout << sum << endl; + return 0; +} +long long gcd(long long a, long long b) { + return a ? gcd(b % a, a) : b; +} +void swap(char *a, char *b) { + char temp = *a; + *a = *b; + *b = temp; +} +long long maxPrimeFactors(long long n) { + long long maxPrime = -1; + while (n % 2 == 0) { + maxPrime = 2; + n >>= 1; + } + for (int i = 3; i <= sqrt(n); i += 2) { + while (n % i == 0) { + maxPrime = i; + n = n / i; + } + } + if (n > 2) maxPrime = n; + return maxPrime; +} +string bin_gen(ulong long n, ulong long num) { + string bin = ""; + while (n--) { + if (num % 2) { + bin += "1"; + } else + bin += "0"; + num /= 2; + } + return bin; +} +int main() { + long long n; + cin >> n; + char arr[n]; + for (long long i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + for (long long i = 0; i < n; i++) { cout << arr[i]; } + cout << endl; + return 0; +} +int main() { + long long n, k; + string s; + int count[26] = {}; + cin >> n >> k; + cin >> s; + cin.ignore(); + for (int i = 0; i < n; i++) { count[s[i] - 65]++; } + long long mini = 0; + for (int i = 0; i < k; i++) { + if (count[mini] > count[i]) { mini = i; } + } + cout << count[mini] * k << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + cnt = n / 100; + n %= 100; + cnt += (n / 20); + n %= 20; + cnt += (n / 10); + n %= 10; + cnt += (n / 5); + n %= 5; + cnt += n; + cout << cnt << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +int main() { + int n, a, b; + cin >> n >> a >> b; + string s; + cin >> s; + if (s[a - 1] == s[b - 1]) { + cout << 0 << endl; + return 0; + } + set st; + char ch = ' '; + int pos = 0; + for (int i = 0; i < s.size(); i++) { + if (ch == ' ') { + ch = s[i]; + continue; + } + if (s[i] == ch) { + pos = i; + } else { + st.insert(i - pos); + pos = i; + ch = s[i]; + } + } + cout << *st.end() << endl; + return 0; +} +bool r[105]; +int main() { + int n, m; + while (cin >> n >> m) { + int cc = 0; + memset(r, 0, sizeof(r)); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + for (int j = 0; j < x; j++) { + int y; + cin >> y; + if (r[y] == false) { + r[y] = 1; + cc++; + } + } + } + if (cc == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +const double PI = acos(-1.0); +void fast_in_out() {} +void pause() {} +int main() { + fast_in_out(); + int ar[] = {2, 4, 8, 16, 32, 64, 128, 256, 512}; + int n, b, q; + cin >> n >> b >> q; + int x = 0, y = n * q; + for (int i = 8; i >= 0; i--) { + if (n < ar[i]) continue; + int k = ar[i]; + n = n - k; + n += k / 2; + i++; + k = k * b + (k / 2); + x += k; + } + cout << x << " " << y << '\n'; + pause(); + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int count = 0; + for (int i = a; i <= c; i += a) { + for (int j = b; j <= i; j += b) { + if (i == j) count++; + } + } + cout << count << endl; +} +int a[105]; +int main() { + int n; + int counts = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int t = a[1]; + sort(a + 2, a + n + 1); + while (t <= a[n]) { + t++; + a[n]--; + counts++; + sort(a + 2, a + n + 1); + } + cout << counts << endl; + return 0; +} +int main() { + int n, cur; + cin >> n; + for (int i = 1; i <= n; i++) { + int m; + cin >> m; + if (n == 1 && m == 15) { + cout << "DOWN" << endl; + return 0; + } else if (n == 1 && m == 0) { + cout << "UP" << endl; + } else if (n == 1) { + cout << -1 << endl; + } else { + if (i == n - 1) { cur = m; } + if (i == n) { + if (m == 15) { + cout << "DOWN" << endl; + return 0; + } else if (m == 0) { + cout << "UP" << endl; + return 0; + } else if (cur < m) { + cout << "UP" << endl; + return 0; + } else if (cur > m) { + cout << "DOWN" << endl; + return 0; + } + } + } + } +} +const int maxn = 200500; +int v[maxn]; +int h[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; ++i) cin >> v[i]; + sort(v, v + n); + int hn = 0; + int ans = 0; + for (int i = 0; i < m; ++i) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 == 1) { h[hn++] = x2; } + if (x2 == 1000000000) ans++; + } + sort(h, h + hn); + ans += n; + int i = 0, j = 0; + int cnt = hn; + while (i < n) { + while (j < hn && h[j] < v[i]) { + --cnt; + ++j; + } + ans = min(ans, cnt + i); + ++i; + } + cout << ans << endl; +} +int main() { + string Str; + cin >> Str; + int crunt_State = 1; + int index = 0; + int distance = 0; + for (int i = 0; i < Str.length(); i++) { + index = (int)Str[i] - 96; + if (index < crunt_State) + distance += min((crunt_State - index), (index + 26 - crunt_State)); + else { + distance += min((index - crunt_State), (crunt_State + 26 - index)); + } + crunt_State = ((int)Str[i] - 96); + } + cout << distance << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long x; + long long m; + long long sum = 0; + long long **p; + p = new long long *[n]; + for (int i = 0; i < n; i++) { p[i] = new long long[3]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { cin >> p[i][j]; } + } + for (int i = 0; i < n; i++) { + if (p[i][2] % 2 == 0) { + x = p[i][2] / 2; + p[i][0] *= x; + p[i][1] *= x; + cout << p[i][0] - p[i][1] << endl; + } else { + x = (p[i][2] - 1) / 2; + m = p[i][2] - x; + p[i][0] *= m; + p[i][1] *= x; + cout << p[i][0] - p[i][1] << endl; + } + } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> K; + vector v(N); + for (int i = 0; i < K; i++) { + cin >> M; + v[M - 1]++; + } + cout << *min_element(v.begin(), v.end()) << endl; + return 0; +} +vector v; +int a[1005]; +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n; + cin >> n; + int M = 0; + for (int i = 1; i <= n; ++i) { + cin >> a[i]; + M = max(M, a[i]); + } + int m = gcd(a[1], a[2]); + int f = 1; + while (f) { + f = 0; + for (int i = 1; i <= n; ++i) + if (gcd(m, a[i]) < m) m = gcd(m, a[i]), f = 1; + if (m == 1) break; + } + int s = M / m - n; + if (s % 2) + cout << "Alice\n"; + else + cout << "Bob\n"; +} +const double PI = acos(-1.0); +const int INF = 1000 * 1000 * 1000 + 7; +const long long LINF = INF * (long long)INF; +const int MAX = 333; +string A[MAX]; +bool U[MAX][MAX]; +bool solve(int n) { + for (int i = (0); i < (n); i++) { + if (A[i][i] != A[0][0]) return false; + if (A[i][n - i - 1] != A[0][0]) return false; + U[i][i] = true; + U[i][n - i - 1] = true; + } + for (int i = (0); i < (n); i++) { + for (int j = (0); j < (n); j++) { + if (U[i][j]) continue; + if (A[i][j] != A[0][1]) return false; + } + } + if (A[0][0] == A[0][1]) return false; + return true; +} +int main() { + int n; + cin >> n; + for (int i = (0); i < (n); i++) { cin >> A[i]; } + if (solve(n)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n >= 22) + cout << '0' << endl; + else if (n == 20) + cout << "15" << endl; + else + cout << '4' << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + string a; + cin >> a; + int s = 0; + for (int i = 0; a[i]; i++) { + if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') + s++; + else if (a[i] >= '0' && a[i] <= '9' && (a[i] - 48) % 2 != 0) + s++; + } + cout << s << endl; + return 0; +} +int a[110]; +int main() { + int n, i; + int b = 0, c = 0; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + if (a[i] >= 0) + b += a[i]; + else + c += a[i]; + } + cout << b - c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k = 1; + while (m >= k) { + m -= k; + k++; + if (k > n) k = 1; + } + cout << m << endl; +} +int main() { + int a, num = 0; + char b[100]; + cin >> a; + cin >> b; + reverse(b, b + strlen(b)); + for (int i(0); i < (strlen(b)); i++) { num = (num * 10) + (b[i] - '0'); } + cout << num + a << endl; + return 0; +} +int n, a, cnt[10]; +pair ar[5005]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + cnt[a]++; + ar[i] = make_pair(a, i); + } + int mi = 1e9; + for (int i = 1; i <= 3; i++) { + if (cnt[i] < mi) mi = cnt[i]; + } + sort(ar, ar + n + 1); + int b = 1, c = b + cnt[1], d = c + cnt[2]; + cout << mi << '\n'; + for (int i = 1; i <= mi; i++) { + cout << ar[b].second << " " << ar[c].second << " " << ar[d].second << '\n'; + b++, c++, d++; + } + return 0; +} +int main() { + int n; + cin >> n; + int lessons[100]; + for (int i = 0; i < n; i++) { cin >> lessons[i]; } + int numhours = 0; + for (int i = 0; i < n; i++) { + if (lessons[i] == 1) { + numhours++; + } else if (numhours != 0) { + if (i != n - 1 && lessons[i + 1] != 0 && lessons[i - 1] != 0) { numhours++; } + } + } + cout << numhours << "\n"; + return 0; +} +map a; +int main() { + string s; + char tt, c[102]; + int cnt = 0, ans = 0; + cin >> s; + cnt = s.length(); + for (int i = 0; i < cnt; i++) { + s += s[0]; + s.erase(0, 1); + if (++a[s] == 1) ans++; + } + cout << ans << endl; +} +const int INF = (int)1e9; +const long long INFl = (long long)1e18; +const long long MOD = (long long)1e9 + 7; +long long myPow(long long a, long long b) { + long long ret = 1; + while (b) { + if (b & 1) ret = ret * a % MOD; + a = (a * a) % MOD; + b /= 2; + } + return ret % MOD; +} +int main() { + string s; + cin >> s; + int N = s.length(); + long long ats = 0; + for (int i = 0; i < N; ++i) { + if ((s[i] - '0') == 1) { + ats += myPow(2, (N - i - 1)); + ats %= MOD; + } + } + ats = ats * myPow(2, N - 1) % MOD; + ats %= MOD; + cout << ats << "\n"; + return 0; +} +int main() { + long long n, c = 0, res = 0; + cin >> n; + if (n >= 100) { + c = n % 100; + res += n / 100; + n -= (n - c); + } + if (n >= 20) { + c = n % 20; + res += n / 20; + n -= (n - c); + } + if (n >= 10) { + c = n % 10; + res += n / 10; + n -= (n - c); + } + if (n >= 5) { + c = n % 5; + res += n / 5; + n -= (n - c); + } + if (n != 0) res += n; + cout << res << endl; + return 0; +} +int num[101], flag[101]; +int main() { + int n, m, x, no, signal = 0; + cin >> n >> m; + while (n--) { + cin >> x; + while (x--) { + cin >> no; + flag[no] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (flag[i] == 0) { + signal = 1; + break; + } + } + if (!signal) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, k, l, c, d, p, nl, np, ans; + while (cin >> n >> k >> l >> c >> d >> p >> nl >> np) { + ans = min(k * l / nl, min(c * d, p / np)) / n; + cout << ans << endl; + } + return 0; +} +const int maxn = 100000 + 5; +int a[maxn]; +int main() { + int N; + cin >> N; + for (int i = 0; i <= maxn; i++) a[i] = 0; + int len = 0; + int ans = 0; + for (int i = 1; i <= 2 * N; i++) { + int k; + cin >> k; + if (a[k] == 1) { + len--; + a[k] = 0; + } else { + len++; + ans = max(len, ans); + a[k] = 1; + } + } + cout << ans << endl; + return 0; +} +const int MAXN = 1e4 + 10; +bool vis[110]; +int w, h, u1, d1, u2, d2; +int main() { + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + for (int i = h; i >= 0; i--) { + if (i != d1 && i != d2) + w += i; + else if (i == d1) { + w = w + i - u1; + if (w <= 0) w = 0; + } else if (i == d2) { + w = w + i - u2; + if (w <= 0) w = 0; + } + } + cout << w << endl; + return 0; +} +int main() { + int n, m, x, temp, ans = 1; + cin >> n >> m; + cin >> x; + temp = x; + for (int i = 1; i < n; i++) { + cin >> x; + if (x - temp <= m) + ans++; + else + ans = 1; + temp = x; + } + cout << ans << endl; +} +int main() { + int a, b, c, d, e; + set S; + cin >> a; + for (int i = 1; i <= a; i++) { + cin >> b; + if (b != 0) S.insert(b); + } + cout << S.size() << endl; +} +stack chars; +int main() { + string str; + cin >> str; + char ch; + for (int i = 0; str[i] != '\0'; i++) { + ch = str[i]; + if (!chars.empty()) { + if (chars.top() == ch) + chars.pop(); + else + chars.push(ch); + } else + chars.push(ch); + } + vector result; + while (!chars.empty()) { + result.push_back(chars.top()); + chars.pop(); + } + for (int i = result.size() - 1; i >= 0; i--) cout << result[i]; + cout << "\n"; + return 0; +} +long long n, p, b, q; +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + cin >> n; + while (n--) { + cin >> p >> q >> b; + long long tmp = gcd(p, q); + p /= tmp; + q /= tmp; + long long div = gcd(b, q); + while ((div = gcd(b, q)) != 1) + while (q % div == 0) q /= div; + if (q == 1) + cout << "Finite" << endl; + else + cout << "Infinite" << endl; + } + return 0; +} +int main() { + long long int N, m = 0; + cin >> N; + if (N >= 100) { + m += N / 100; + N = N % 100; + } + if (N >= 20) { + m += N / 20; + N = N % 20; + } + if (N >= 10) { + m += N / 10; + N = N % 10; + } + if (N >= 5) { + m += N / 5; + N = N % 5; + } + if (N >= 1) { + m += N / 1; + N = N % 1; + } + cout << m << endl; + return 0; +} +map mymap; +void init() { + mymap[0] = "O-|-OOOO"; + mymap[1] = "O-|O-OOO"; + mymap[2] = "O-|OO-OO"; + mymap[3] = "O-|OOO-O"; + mymap[4] = "O-|OOOO-"; + mymap[5] = "-O|-OOOO"; + mymap[6] = "-O|O-OOO"; + mymap[7] = "-O|OO-OO"; + mymap[8] = "-O|OOO-O"; + mymap[9] = "-O|OOOO-"; +} +int main() { + init(); + string s; + cin >> s; + for (int i = s.length() - 1; i >= 0; i--) { cout << mymap[s[i] - '0'] << endl; } + return 0; +} +int main() { + int n, l, r, ql, qr; + bool right = false, left = false; + cin >> n >> l >> r >> ql >> qr; + vector w(n + 2); + w[0] = 0; + w[n + 1] = 0; + int minr = INT_MAX; + int x; + for (int i = 1; i <= n; i++) { + cin >> x; + w[i] = x + w[i - 1]; + } + for (int i = 0; i <= n; i++) { + int wl = w[i]; + int wr = w[n] - w[i]; + int nl = i; + int nr = n - i; + int p = wl * l + wr * r; + int d = nl - nr; + int ad = abs(d); + int pen; + if (ad == n) { + pen = n - 1; + } else if (ad >= 2) { + pen = ad - 1; + } else { + pen = 0; + } + if (d > 0) { + p += pen * ql; + } else { + p += pen * qr; + } + minr = min(minr, p); + } + cout << minr << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x, y, z; + z = sqrt((b * c) / a); + y = c / z; + x = b / z; + cout << 4 * (x + y + z) << endl; +} +int main() { + string str, str2, s; + int num, i; + while (cin >> num >> str) { + sort(str.begin(), str.end()); + for (i = 0; i < str.size(); i += num) { str2 += str[i]; } + for (i = 0; i < num; i++) { s += str2; } + str2 = s; + sort(str2.begin(), str2.end()); + if (str2 != str) { + cout << -1 << endl; + ; + } else { + cout << s << endl; + } + } + return 0; +} +char num[100]; +int vis[100]; +int main() { + int n, flag; + while (cin >> n) { + flag = 0; + cin >> num; + int flag = 1; + for (int i = 0; i < n; i++) { + if (num[i] != '4' && num[i] != '7') flag = 0; + } + int sum1 = 0, sum2 = 0; + for (int i = 0; i < n / 2; i++) { sum1 += (num[i] - '0'); } + for (int i = n - 1; i >= n / 2; i--) { sum2 += (num[i] - '0'); } + if (sum1 != sum2) flag = 0; + if (flag == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +long long int n, a[200010], mini, cnt; +int main() { + int i; + while (cin >> n) { + for (i = 0; i < n; ++i) cin >> a[i]; + sort(a, a + n); + mini = 200000000008, cnt = 0; + for (i = 0; i < n - 1; ++i) mini = min(mini, abs(a[i + 1] - a[i])); + for (i = 0; i < n - 1; ++i) + if (mini == abs(a[i + 1] - a[i])) ++cnt; + cout << mini << " " << cnt << endl; + } + return 0; +} +const int maxn = 110; +int a[maxn]; +int b[maxn]; +int main() { + int n; + cin >> n; + int Max = -10000; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > Max && i >= 2) Max = a[i]; + } + int sum = 0; + for (int i = 2; i <= n; i++) { + if (Max == a[i]) { sum++; } + } + int ans = 0; + int flag = 0; + while (1) { + for (int i = 2; i <= n; i++) + if (a[i] == Max) { a[i] -= 1; } + for (int j = 1; j <= sum; j++) { + if (a[1] > Max) { + flag = 1; + break; + } + a[1] += 1; + ans += 1; + } + Max -= 1; + if (flag) break; + sum = 0; + for (int i = 2; i <= n; i++) { + if (a[i] >= Max) { + Max = a[i]; + sum++; + } + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int res = 0; + while (n > 0) { + int a, b; + cin >> a >> b; + if (b - a >= 2) { res++; } + n--; + } + cout << res << endl; + return 0; +} +int main() { + string x; + cin >> x; + int c = 0; + for (int i = 0, j = x.length() - 1; i < x.length(); i++, j--) { + if (x[i] != x[j]) c++; + } + if (c == 2 || (c == 0 && x.length() % 2 != 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n; + cin >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) { + int x = a[i] - 48; + int y = b[i] - 48; + int maxi = max(x, y); + int mini = min(x, y); + ans += min(9 - maxi + mini + 1, maxi - mini); + } + cout << ans << endl; + return 0; +} +int i, j, k; +int main() { + string s; + int f, ans = 0; + for (i = 1; i <= 8; i++) { + cin >> s; + f = 0; + for (j = 0; j < s.length() - 1; j++) { + if (s[j] == s[j + 1]) { + f = 1; + ans = 1; + } + } + } + if (ans == 0) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int main() { + int n, c = 0; + cin >> n; + char a[n + 2][n + 2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j + 1 < n) { + if (a[i][j + 1] == 'o') { c++; } + } + if (i + 1 < n) { + if (a[i + 1][j] == 'o') { c++; } + } + if (j - 1 >= 0) { + if (a[i][j - 1] == 'o') { c++; } + } + if (i - 1 >= 0) { + if (a[i - 1][j] == 'o') { c++; } + } + if (c % 2 != 0) { + cout << "NO\n"; + return 0; + } + c = 0; + } + } + cout << "YES\n"; +} +int main() { + int n, kecil = 0, besar = 0, hitung = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int m; + cin >> m; + if (i == 1) { + kecil = m; + besar = m; + } else { + if (m < kecil) { + kecil = m; + hitung++; + } else if (m > besar) { + besar = m; + hitung++; + } + } + } + cout << hitung << endl; +} +char a2[1000009], b2[1000009]; +int main() { + string a; + string b; + while (cin >> a) { + cin >> b; + int lena = a.length(), lenb = b.length(); + memset(a2, 0, sizeof(a2)); + memset(b2, 0, sizeof(b2)); + int biaoji1 = -1, biaoji2 = -1; + for (int i = 0; i < lena; i++) { + if (a[i] != '0') { + biaoji1 = i; + break; + } + } + int m = 0; + if (biaoji1 == -1) { + m = 0; + a2[0] = '0'; + } else { + for (int j = biaoji1; j < lena; j++) { + a2[m] = a[j]; + m++; + } + } + for (int i = 0; i < lenb; i++) { + if (b[i] != '0') { + biaoji2 = i; + break; + } + } + int k = 0; + if (biaoji2 == -1) { + k = 0; + b2[0] = '0'; + } else { + for (int j = biaoji2; j < lenb; j++) { + b2[k] = b[j]; + k++; + } + } + if (m < k) + cout << "<" << endl; + else if (m > k) + cout << ">" << endl; + else { + int flag = 0; + int j; + for (j = 0; j < m; j++) { + if (a2[j] > b2[j]) { + cout << ">" << endl; + flag = 1; + break; + } + if (a2[j] < b2[j]) { + cout << "<" << endl; + flag = 1; + break; + } + } + if (j == m) cout << "=" << endl; + } + } +} +int a, b, c, d; +int main() { + cin >> a >> b; + d = min(a, b); + c = max(a, b) - d; + if (c % 2) c -= 1; + cout << d << " " << c / 2 << endl; +} +int main() { + int n, x, y, z; + set s; + cin >> n; + cin >> x; + for (int i = 0; i < x; i++) { + cin >> z; + s.insert(z); + } + cin >> y; + for (int i = 0; i < y; i++) { + cin >> z; + s.insert(z); + } + if (n == s.size()) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +int main() { + int n, m; + char s[59][59]; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { cin >> s[i]; } + int sum = 0; + map mp; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + mp[s[i][j]] = 1; + mp[s[i + 1][j]] = 1; + mp[s[i][j + 1]] = 1; + mp[s[i + 1][j + 1]] = 1; + if (mp['f'] == 1 && mp['a'] == 1 && mp['c'] == 1 && mp['e'] == 1) { sum++; } + mp[s[i][j]] = 0; + mp[s[i + 1][j]] = 0; + mp[s[i][j + 1]] = 0; + mp[s[i + 1][j + 1]] = 0; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + int x, y, p, q; + cin >> x >> y >> p >> q; + if (p == 0) { + cout << (x == 0 ? 0 : -1) << endl; + continue; + } + if (p == q) { + cout << (x == y ? 0 : -1) << endl; + continue; + } + int r1 = (x + p - 1) / p; + int r2 = ((y - x) + (q - p) - 1) / (q - p); + cout << (q * 1LL * max(r1, r2) - y) << endl; + } +} +int p, dp[2005][2005]; +void helper() { + memset(dp, 0, sizeof(dp)); + for (int i = 0; i < p; i++) { dp[i][0] = 1; } + for (int x = 1; x < p; x++) { + for (int i = 1; i < p; i++) { dp[x][i] = ((dp[x][i - 1]) * x) % p; } + } +} +bool isPrimeRoot(int x) { + int curr = 0; + for (int k = 0; k < p - 2; k++) { + curr += dp[x][k]; + if (curr % p == 0) { return false; } + } + curr = curr + dp[x][p - 2]; + if (curr % p != 0) { return false; } + return true; +} +int solve() { + if (p == 2) return 1; + helper(); + int ans = 0; + for (int x = 1; x < p; x++) { + if (isPrimeRoot(x)) { ans++; } + } + return ans; +} +int main() { + cin >> p; + int ans = solve(); + cout << ans << endl; + return 0; +} +int toggle(int a); +int check(int number); +int main() { + int a[5][5]; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { a[i][j] = 1; } + } + int input[5][5]; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cin >> input[i][j]; } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { input[i][j] = input[i][j] % 2; } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + if (input[i][j] == 1) { + a[i][j] = toggle(a[i][j]); + a[i][j + 1] = toggle(a[i][j + 1]); + a[i + 1][j] = toggle(a[i + 1][j]); + a[i][j - 1] = toggle(a[i][j - 1]); + a[i - 1][j] = toggle(a[i - 1][j]); + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cout << a[i][j]; } + cout << "\n"; + } +} +int toggle(int a) { + if (a == 1) { + return 0; + } else { + return 1; + } +} +int main() { + int t; + cin >> t; + while (t--) { + int n, r; + cin >> n >> r; + for (int i = 1, x; i < n; ++i) cin >> x, r -= x; + cout << (r % n + n) % n + 1 << '\n'; + } +} +int main() { + string seq = "AKQJT9876"; + char tramp; + cin >> tramp; + string a, b; + cin >> a >> b; + if (a[1] == tramp and b[1] != tramp) { + cout << "YES\n"; + } else if (a[1] == b[1] and seq.find(a[0]) < seq.find(b[0])) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 == 0) { + if (i % 4 != 0) { + for (int y = 1; y < m; y++) cout << '.'; + cout << '#'; + } else { + cout << '#'; + for (int x = 1; x < m; x++) cout << '.'; + } + } else + for (int x = 0; x < m; x++) cout << '#'; + cout << endl; + } + return 0; +} +int like[33399]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) cin >> like[i]; + for (int i = 1; i <= n; ++i) { + if (like[like[like[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, ans = 1; + cin >> a >> b; + if (a > b) a = b; + for (int i = 1; i <= a; i++) ans = ans * i; + cout << ans << endl; +} +int main() { + string line; + cin >> line; + int QAQ_count = 0; + if (line.size() < 3) { + cout << '0' << endl; + } else { + for (size_t i = 0; i < line.size() - 2; i++) { + if (line[i] == 'Q') { + for (size_t j = i + 1; j < line.size() - 1; j++) { + if (line[j] == 'A') { + for (size_t k = j + 1; k < line.size(); k++) { + if (line[k] == 'Q') { QAQ_count++; } + } + } + } + } + } + cout << QAQ_count << endl; + } + return 0; +} +int main() { + long int a, cp = 0, cn = 0; + cin >> a; + long int arr[a][2]; + for (long i = 0; i < a; i++) { + cin >> arr[i][0] >> arr[i][1]; + if (arr[i][0] > 0) + cp++; + else + cn++; + } + if (cp < 2 || cn < 2) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int e; + cin >> e; + if (360 % (180 - e) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int arr[] = {4, 7, 44, 77, 47, 74, 444, 447, 474, 477, 777, 744, 747, 774}; +bool s = false; +int main() { + int n; + cin >> n; + for (int i = 0; i < 14; ++i) { + if (n % arr[i] == 0) { + cout << "YES" << endl; + s = true; + break; + } else + continue; + } + if (s == false) cout << "NO" << endl; + return 0; +} +long long mod = 1e9 + 7; +int main() { + string s; + cin >> s; + long long ans = 0; + long long power = 1; + for (int i = 1; i < s.size(); ++i) power = (power * 2) % mod; + long long cur = 1; + for (int i = s.size() - 1; i >= 0; i--) { + if (s[i] == '1') ans = (ans + cur * power) % mod; + cur = (cur * 2) % mod; + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, i; + int a[3][6] = {{0, 1, 2, 2, 1, 0}, {1, 0, 0, 1, 2, 2}, {2, 2, 1, 0, 0, 1}}; + cin >> n >> x; + for (i = 0; i < 3; i++) { + if (a[i][n % 6] == x) cout << i << endl; + } +} +int main() { + long long int n; + cin >> n; + int counter; + if (n > 5) { + cout << (n + 4) / 5 << endl; + } else { + cout << 1 << endl; + } +} +int main() { + int n, my[105] = {0}, l, r, a, b, sum = 0; + cin >> n; + cin >> l >> r; + for (int i = 0; i < n - 1; i++) { + cin >> a >> b; + for (int j = a + 1; j <= b; j++) my[j] = 1; + } + for (int i = l + 1; i <= r; i++) + if (my[i] == 0) sum++; + cout << sum << endl; + return 0; +} +int main() { + int a[3][3], t, b[3][3]; + fill((int *)a, (int *)a + sizeof(a) / sizeof(int), 1); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> t; + b[i][j] = t; + if (b[i][j] % 2 != 0) { + if ((i == 0 || i == 2) && (j == 0 || j == 2)) { + a[i][j] = abs(1 - a[i][j]); + a[i][abs(j - 1)] = abs(1 - a[i][abs(j - 1)]); + a[abs(i - 1)][j] = abs(1 - a[abs(i - 1)][j]); + } else if ((i == 0 || i == 2) && (j == 1)) { + a[i][j] = abs(1 - a[i][j]); + a[i][abs(j - 1)] = abs(1 - a[i][abs(j - 1)]); + a[i][abs(j + 1)] = abs(1 - a[i][abs(j + 1)]); + a[abs(i - 1)][j] = abs(1 - a[abs(i - 1)][(j)]); + } else if ((i == 1) && (j == 0 || j == 2)) { + a[i][j] = abs(1 - a[i][j]); + a[i][abs(j - 1)] = abs(1 - a[i][abs(j - 1)]); + a[abs(i - 1)][j] = abs(1 - a[abs(i - 1)][(j)]); + a[abs(i + 1)][j] = abs(1 - a[abs(i + 1)][(j)]); + } else if (i == 1 && j == 1) { + a[i][j] = abs(1 - a[i][j]); + a[0][1] = 1 - a[0][1]; + a[2][1] = 1 - a[2][1]; + a[1][0] = 1 - a[1][0]; + a[1][2] = 1 - a[1][2]; + } + } + } + } + for (int x = 0; x < 3; x++) { + for (int y = 0; y < 3; y++) { cout << a[x][y]; } + cout << endl; + } +} +const int INF = 0x3f3f3f3f; +int main() { + int n; + cin >> n; + string s; + long long a, b; + a = b = 1; + while (n--) { + cin >> s; + if (s == "ULDR") { + a++; + b++; + continue; + } + if (s == "UR" || s == "DL") { + a++; + } else { + b++; + } + } + long long ans = a * b; + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long x, sum, r; + sum = 0; + while (n--) { + cin >> x; + sum += x; + } + int m; + cin >> m; + pair p[m]; + for (int i = 0; i < m; i++) { cin >> p[i].first >> p[i].second; } + for (int i = 0; i < m; i++) { + if (sum >= p[i].first && sum <= p[i].second) { + return cout << sum << endl, 0; + } else if (sum <= p[i].first) { + return cout << p[i].first << endl, 0; + } + } + return cout << "-1" << endl, 0; +} +int arr[100005]; +int arr2[100005]; +int compa1(int l, int r) { + int sum = 0; + for (int i = l; i <= r; i++) { sum |= arr[i]; } + return sum; +} +int compa2(int l, int r) { + int sum = 0; + for (int i = l; i <= r; i++) { sum |= arr2[i]; } + return sum; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { cin >> arr2[i]; } + int mx1 = 0; + int mx2 = 0; + for (int l = 0; l < n; l++) { + for (int r = 0; r < n; r++) { mx1 = max(mx1, compa1(l, r)); } + } + for (int l = 0; l < n; l++) { + for (int r = 0; r < n; r++) { mx2 = max(mx2, compa2(l, r)); } + } + cout << mx1 + mx2 << "\n"; + return 0; +} +int main() { + int n, m, i, j; + cin >> n >> m; + for (i = 0; i < n; i++) { + if (i % 2 == 0) { + for (j = 0; j < m; j++) { cout << "#"; } + } else { + if ((i - 1) % 4 == 2) { cout << "#"; } + for (j = 0; j < m - 1; j++) { cout << "."; } + if ((i - 1) % 4 == 0) { cout << "#"; } + } + cout << endl; + } +} +int main() { + int n, i, j, temp, result, imin = 10000000; + vector a; + cin >> n; + a.push_back(1); + for (i = 1; i <= n; i++) { + cin >> temp; + a.push_back(temp); + } + for (i = 1; i <= n; i++) { + result = 0; + for (j = 1; j <= n; j++) { result += 2 * a[j] * (abs(i - j) + abs(j - 1) + abs(i - 1)); } + imin = min(imin, result); + } + cout << imin << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int m; + cin >> m; + int discount[m]; + int min_require = INT_MAX; + for (int i = 0; i < m; i++) { + cin >> discount[i]; + min_require = min(min_require, discount[i]); + } + int n; + cin >> n; + int price[n]; + for (int i = 0; i < n; i++) cin >> price[i]; + sort(price, price + n, greater()); + int ans = 0; + for (int i = 0; i < n;) { + for (int j = 0; j < min_require && i < n; j++, i++) ans += price[i]; + i += 2; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int ans1 = n / 3; + n %= 3; + if (n >= 2) { ans1++; } + int ans2 = ans1 / 12; + ans1 %= 12; + cout << ans2 << " " << ans1 << endl; + return 0; +} +int main() { + int n, k; + cin >> n; + k = n / 2; + for (int i = 1; i <= k + 1; i++) { + for (int j = 1; j <= k - i + 1; j++) cout << "*"; + for (int j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (int j = 1; j <= k - i + 1; j++) cout << "*"; + cout << endl; + } + for (int i = 1; i <= k; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - 2 * i; j++) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << endl; + } +} +int check(int x, int y) { + if (x <= y) return x; + return y; +} +int main() { + string s, p = ""; + int i, j; + cin >> s; + p = s; + for (i = s.size() - 1; i > 0; i--) { + j = check(s[i] - '0', 9 - (s[i] - '0')); + p[i] = (char)(j + '0'); + } + j = 9 - (s[0] - '0'); + if (j) { + j = check(s[0] - '0', 9 - (s[0] - '0')); + p[0] = (char)(j + '0'); + } + cout << p << endl; +} +vector k; +vector answer; +int main() { + int n, a; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + cin >> a; + k.push_back(a); + } + int temp; + bool flag = false; + for (int i = 0; i < n; i++) { + if (flag && s[i] == 'L') { + answer.push_back((k[i] - k[temp] + 1) / 2); + flag = false; + } + if (s[i] == 'R') { + flag = true; + temp = i; + } + } + if (answer.empty()) + cout << -1 << endl; + else { + stable_sort(answer.begin(), answer.end()); + cout << answer[0] << endl; + } + return 0; +} +const int mod = 1000000007; +const long long inf = 1000000000000; +int main() { + int n; + cin >> n; + int A[6] = {0}; + int B[6] = {0}; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + A[x]++; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + B[x]++; + } + int ans = 0; + for (int i = 1; i < 6; i++) { + int k = A[i] + B[i]; + if (k % 2 == 1) { + cout << "-1" << '\n'; + return 0; + } + ans += abs(k / 2 - A[i]); + } + cout << ans / 2 << '\n'; + return 0; +} +int main() { + int n, a = 0, b = 0, c = 0, d, e, f; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> d >> e >> f; + a += d; + b += e; + c += f; + } + if (a == 0 && b == 0 && c == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string s; + string t; + cin >> s; + cin >> t; + int c = 0; + for (int i = 0; i < t.length(); i++) { + if (s[c] == t[i]) { c++; } + } + cout << c + 1 << endl; +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +int arrx[101]; +int main() { + int n; + cin >> n; + int l, r; + cin >> l >> r; + for (int i = 1; i < n; i++) { + int a, b; + cin >> a >> b; + for (int j = a; j < b; j++) arrx[j] = 1; + } + int total = 0; + for (int i = l; i < r; i++) { total += arrx[i] ? 0 : 1; } + cout << total << endl; +} +int main() { + int n, a = 0, b = 0; + cin >> n; + for (int i = 1; a < n; i++) { + a += i; + n -= a; + if (n >= 0) b++; + } + cout << b << endl; +} +int main() { + int a, i, n, m, mx_a = 0, mn_a = 1e9, mn_b = 1e9; + cin >> n >> m; + for (i = 0; i < n; i++) { + cin >> a; + mx_a = max(a, mx_a), mn_a = min(a, mn_a); + } + for (i = 0; i < m; i++) { + cin >> a; + mn_b = min(a, mn_b); + } + cout << ((max(2 * mn_a, mx_a) < mn_b) ? max(2 * mn_a, mx_a) : -1) << "\n"; + return 0; +} +const int maxn = 1e3 + 10; +int arr[2][maxn], dp[2][maxn][maxn], n; +void input() { + cin >> n; + for (int k = 0; k < 2; k++) + for (int i = 0; i < n; i++) cin >> arr[k][i]; +} +void cal_dp() { + for (int k = 0; k < 2; k++) + for (int i = 0; i < n; i++) { + dp[k][i][i] = arr[k][i]; + for (int j = i + 1; j < n; j++) dp[k][i][j] = dp[k][i][j - 1] | arr[k][j]; + } +} +int main() { + input(); + cal_dp(); + int ans = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) ans = max(ans, dp[0][i][j] + dp[1][i][j]); + cout << ans << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int s, a, b, c, ans; + cin >> s >> a >> b >> c; + ans = s / c; + ans += (ans / a) * b; + cout << ans << endl; + } +} +int book[6]; +char str[6][10] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +int main() { + int n; + cin >> n; + int cnt = 6 - n; + while (n--) { + string str; + cin >> str; + if (str == "purple") book[0] = 1; + if (str == "green") book[1] = 1; + if (str == "blue") book[2] = 1; + if (str == "orange") book[3] = 1; + if (str == "red") book[4] = 1; + if (str == "yellow") book[5] = 1; + } + cout << cnt << endl; + for (int i = 0; i < 6; i++) { + if (!book[i]) cout << str[i] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int r, l, n; + cin >> r >> l >> n; + long long int n2 = n / 2; + long long int n1 = n - n2; + cout << n1 * r - n2 * l << "\n"; + } +} +int main() { + int n, count1 = 0, count2 = 0, x, y; + cin >> n; + while (n--) { + cin >> x >> y; + if (x < 0) { + count1++; + } else { + count2++; + } + } + if (count1 <= 1 || count2 <= 1) { + cout << "Yes\n"; + } else { + cout << "No\n"; + } +} +queue cs, as; +int main() { + int n, m, a; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a; + cs.push(a); + } + for (int i = 1; i <= m; i++) { + cin >> a; + as.push(a); + } + int sum = 0; + while (!cs.empty() && !as.empty()) { + int b = cs.front(), c = as.front(); + if (b <= c) { + cs.pop(); + as.pop(); + sum++; + } else { + cs.pop(); + } + } + cout << sum << endl; + return 0; +} +const int PI = 3.141592653589793; +const int inf = 1000111222; +const int N = 500007; +long long ar[N], tot, ans, just; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> ar[i]; + tot += ar[i]; + } + for (int i = 1; i <= n; i++) { + just += ar[i]; + if (just >= (tot + 1) / 2) { + ans = i; + break; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int t; + cin >> t; + int a[t]; + for (int i = 0; i < t; i++) { cin >> a[i]; } + int s = 0, b = 0; + int i = 0; + while (a[i] == 0) i++; + for (; i < t; i++) { + if (a[i] == 1) { + s++; + if (b >= 2) + b = 0; + else if (b == 1) { + s++; + b = 0; + } + } else { + b++; + } + } + cout << s << endl; + return 0; +} +long long M = 1e9 + 7; +long long fre[2005]; +long long ans[2005]; +int main() { + long long n, m; + cin >> n >> m; + string str[n + 1]; + for (int i = 0; i < n; ++i) cin >> str[i]; + string ans = "YES\n"; + for (int i = 0; i < n; ++i) + for (int j = 0; j < m - 1; ++j) + if (str[i][j + 1] != str[i][j]) ans = "NO\n"; + for (int i = 0; i < n - 1; ++i) + if (str[i][0] == str[i + 1][0]) ans = "NO\n"; + cout << ans; + return 0; +} +int main() { + string n; + cin >> n; + int i, j, a = 0, b, l; + l = n.size(); + for (i = 0; i < l; i++) { + if (n[i] == '4' || n[i] == '7') { a++; } + } + if (a == 4 || a == 7) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int y, w; + cin >> y >> w; + int ans = max(y, w); + string S[6] = {"1/6", "1/3", "1/2", "2/3", "5/6", "1/1"}; + cout << S[6 - ans] << endl; + return 0; +} +int main() { + int n, i, j, count = 0, ck1 = 0, ck2 = 0, ck3 = 0, ck4 = 0; + cin >> n; + int arr1[n + 2] = {0}; + int arr2[n + 2] = {0}; + for (i = 0; i < n; i++) { + cin >> arr1[i]; + cin >> arr2[i]; + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i == j) continue; + if (arr1[i] > arr1[j] && arr2[i] == arr2[j]) ck1 = 1; + if (arr1[i] < arr1[j] && arr2[i] == arr2[j]) ck2 = 1; + if (arr1[i] == arr1[j] && arr2[i] > arr2[j]) ck3 = 1; + if (arr1[i] == arr1[j] && arr2[i] < arr2[j]) ck4 = 1; + } + if (ck1 == 1 && ck2 == 1 && ck3 == 1 && ck4 == 1) count++; + ck1 = 0, ck2 = 0, ck3 = 0, ck4 = 0; + } + cout << count << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int j = 1, c = 0; + int i; + for (i = 1; i < n; i++) { + if (s[i] == s[i - 1]) { + j++; + } else { + if (j % 2 == 0 && j != 0) { + c++; + j = 1; + } + } + if (i == n - 1 && j % 2 == 0) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n], ct = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) ct++; + } + cout << ct << endl; + for (int i = 1; i < n; i++) { + if (arr[i] == 1) cout << arr[i - 1] << " "; + } + cout << arr[n - 1] << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int a[1005]; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= n; i++) { + int tt, t; + cin >> tt; + for (int j = 1; j <= tt; j++) { + cin >> t; + a[t]++; + } + } + bool vis = false; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) vis = true; + } + if (vis) { + cout << "NO" << endl; + } else + cout << "YES" << endl; + } +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int arr[15]; +int main() { + desperate_optimization(10); + int n, k; + cin >> n >> k; + int tot = 0; + while (n--) { + int x; + cin >> x; + for (int i = 0; i <= 10; i++) arr[i] = 0; + bool ada = true; + int to = 0; + while (x) { + if (x % 10 <= k && arr[x % 10] == 0) to++; + arr[x % 10] = 1; + x /= 10; + } + if (ada == true && to == 1 + k) tot++; + } + cout << tot << '\n'; + return 0; +} +const int maxn = 1e7 + 10; +int a[maxn]; +int n; +int mini = 1e9 + 10; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < mini) mini = a[i]; + } + vector vec; + for (int i = 0; i < n; i++) { + if (mini == a[i]) { vec.push_back(i); } + } + mini = n; + for (int i = 0; i < vec.size() - 1; i++) { mini = min(mini, vec[i + 1] - vec[i]); } + cout << mini << endl; + return 0; +} +long long a[200005]; +map mp; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n - 1; i++) { + long long temp = fabs(a[i + 1] - a[i]); + mp[temp]++; + } + map::iterator iter = mp.begin(); + cout << iter->first << " " << iter->second << endl; + return 0; +} +int main() { + int n, c, now = 0, a, ans = 0; + cin >> n >> c; + while (n--) { + cin >> a; + if (a - now > c) ans = 0; + ans++; + now = a; + } + cout << ans << '\n'; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int count = 0; + for (int i = 1; i <= n; i++) { + if (a <= (i - 1) and (n - i) <= b) { count++; } + } + cout << count << endl; +} +int main() { + int n, cp, mp, m, c; + cin >> n; + mp = cp = 0; + while (n--) { + cin >> m >> c; + if (m > c) + mp++; + else if (m < c) + cp++; + } + if (mp > cp) + cout << "Mishka" << endl; + else if (mp < cp) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long int sum = 0; + int maxi = -1; + for (int i = 1; i <= n; i++) { + int temp; + cin >> temp; + sum += temp; + maxi = max(maxi, temp); + } + int left = n * maxi - sum; + if (m < left) + cout << maxi << " " << maxi + m << endl; + else { + int diff = m - left; + int ans = maxi + (diff / n) + 1; + if (diff % n == 0) ans--; + cout << ans << " " << maxi + m << endl; + } + return 0; +} +int v[5]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + v[x]++; + } + int maxi = max(v[1], max(v[2], v[3])); + cout << n - maxi << endl; + return 0; +} +int main() { + int k, n; + char c; + cin >> k >> n; + int start = 0; + int len = 0; + for (int i = 0; i < k; i++) { + cin >> c; + if (start) len++; + if (c == 'G' || c == 'T') { + if (start == 1) { + if (len % n == 0) { + cout << "YES" << endl; + break; + } else { + cout << "NO" << endl; + break; + } + } + start++; + } + if (len % n == 0 && start == 1) { + if (c == '#') { + cout << "NO" << endl; + break; + } + } + } + return 0; +} +int main() { + long long n; + cin >> n; + if (0 < n && n < 40000001) { + long long x = n, y = 0, k = 0; + while (x > 0) { + k++; + y++; + if (x * x + y * y > n * n) { x--; } + if (x * x + y * y > n * n) { y--; } + } + cout << 4 * k << endl; + } else if (n == 0) { + cout << 1 << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const int maxn = 120; +char str[maxn][maxn]; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + cin >> str[i][j]; + if (str[i][j] == 'B') ans++; + } + ans = sqrt(ans); + ans /= 2; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + if (str[i][j] == 'B') { + cout << i + ans << " " << j + ans << endl; + return 0; + } + return 0; +} +int main() { + int s = 0, c; + for (int i = 0; i < 5; i++) { + cin >> c; + s += c; + } + if (s % 5 || !s) + cout << -1 << endl; + else + cout << s / 5 << endl; +} +const int M = 3010; +vector a[M], b; +int n, m; +bool judge(int x) { + int num1 = a[1].size(); + for (int i = 2; i <= m; i++) { + if (a[i].size() > x) + num1 += a[i].size() - x; + else + num1 += a[i].size(); + } + return num1 > x; +} +long long get_ans(int x) { + long long ans = 0; + int num1 = a[1].size(); + b.clear(); + for (int i = 2; i <= m; i++) { + if (a[i].size() > x) { + for (int j = x; j < a[i].size(); j++) { + num1++; + ans += a[i][j]; + } + for (int j = 0; j < x; j++) b.push_back(a[i][j]); + } else + for (int j = 0; j < a[i].size(); j++) b.push_back(a[i][j]); + } + sort(b.begin(), b.end()); + if (num1 < x && x - num1 + 1 > b.size()) return 10000000000000ll; + int hh = x - num1 + 1; + for (int i = 0; i < hh; i++) ans += b[i]; + return ans; +} +bool cmp(int x, int y) { + return x > y; +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int x, y; + cin >> x >> y; + a[x].push_back(y); + } + for (int i = 1; i <= m; i++) sort(a[i].begin(), a[i].end(), cmp); + long long ans = 10000000000000ll; + for (int i = 0; i <= n / 2; i++) ans = min(ans, get_ans(i)); + cout << ans << endl; + return 0; +} +int main() { + long long x, y, z; + long long k; + cin >> x >> y >> z >> k; + long long mas[4]; + mas[1] = mas[2] = mas[3] = 1LL; + while ((k-- > 0) && (x + y + z - mas[1] - mas[2] - mas[3] > 0)) { + long long max = 0; + int flag = 0; + if (mas[1] < x) { + max = (mas[1] + 1LL) * mas[2] * mas[3]; + flag = 1; + } + if (mas[2] < y) { + long long tmp = mas[1] * (mas[2] + 1LL) * mas[3]; + if (max < tmp) { + max = tmp; + flag = 2; + } + } + if (mas[3] < z) { + long long tmp = mas[1] * mas[2] * (mas[3] + 1LL); + if (max < tmp) { + max = tmp; + flag = 3; + } + } + mas[flag]++; + } + cout << mas[1] * mas[2] * mas[3] << endl; +} +int main() { + int n; + cin >> n; + vector pos(n / 2); + for (int i = 0; i < n / 2; ++i) cin >> pos[i]; + sort(pos.begin(), pos.end()); + int a1 = 0, a2 = 0; + for (int i = 0; i < n / 2; ++i) { + a1 += abs(pos[i] - (i * 2 + 1)); + a2 += abs(pos[i] - (i * 2 + 2)); + } + cout << min(a1, a2) << endl; + return 0; +} +int main() { + int v[3][3]; + int n[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> v[i][j]; + n[i][j] = 1; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + while (v[i][j]) { + if (i + 1 < 3) n[i + 1][j] = !n[i + 1][j]; + if (i - 1 > -1) n[i - 1][j] = !n[i - 1][j]; + if (j + 1 < 3) n[i][j + 1] = !n[i][j + 1]; + if (j - 1 > -1) n[i][j - 1] = !n[i][j - 1]; + n[i][j] = !n[i][j]; + v[i][j]--; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << n[i][j]; } + cout << endl; + } + return 0; +} +long long a[100005]; +int main() { + long long n, m, i, j, x, y, z, p, q, d; + cin >> n >> m; + x = 0; + y = z = 12345678; + for (i = 0; i < n; i++) { + cin >> p; + y = min(y, p); + x = max(x, p); + } + for (i = 0; i < m; i++) { + cin >> p; + z = min(z, p); + } + z--; + y = 2 * y; + y = max(y, x); + if (y <= z) { + cout << y << endl; + } else { + cout << "-1" << endl; + } + return 0; +} +int even[55]; +int main() { + int n, m; + int cnt = 1; + for (int i = 2; i < 55; i += 2) { even[i] = cnt++; } + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2) { cout << "#"; } + if (i % 2 == 0) { + if (even[i] % 2) { + if (j == m) { + cout << "#"; + } else { + cout << "."; + } + } else { + if (j == 1) { + cout << "#"; + } else { + cout << "."; + } + } + } + } + cout << endl; + } + } +} +int main() { + int n, m; + cin >> n; + cin >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 4 == 1 || i % 4 == 3) + cout << "#"; + else if (i % 4 == 2) { + if (j == m) + cout << "#"; + else + cout << "."; + } else if (i % 4 == 0) { + if (j == 1) + cout << "#"; + else + cout << "."; + } + } + cout << endl; + } + return 0; +} +const long long mod = 1e9 + 7; +const int maxn = 1e5 + 10; +const long long maxa = 1e10; +int main() { + char c; + int d; + cin >> c >> d; + if (c == 'a' || c == 'h') { + if (d == 1 || d == 8) + cout << "3" << endl; + else + cout << "5" << endl; + } else { + if (d == 1 || d == 8) + cout << "5" << endl; + else + cout << "8" << endl; + } + return 0; +} +int main() { + long long t, s, a, b, c; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + s = s / c; + s = s + ((s / a) * b); + cout << s << endl; + } + return 0; +} +int main() { + string s; + long long n, r, sum = 0; + cin >> s; + char q; + vector v; + for (char a = 'a'; a <= 'z'; a++) { v.push_back(a); } + n = 0; + for (int i = 0; i < s.size(); i++) { + q = s[i]; + for (int j = 0; j < v.size(); j++) { + if (v[j] == q) { + r = j; + break; + } + } + if (abs(n - r) <= 13) { + sum += abs(n - r); + n = r; + } else { + sum += (27 - abs(n - r)) - 1; + n = r; + } + } + cout << sum << endl; + return 0; +} +int pow(int x, int n) { + long long y = x; + long long res = 1; + for (; n > 0; n >>= 1) { + if (n & 1) res = res * y % 1000000009; + y = y * y % 1000000009; + } + return res; +} +int main() { + int n, m; + cin >> n >> m; + long long mm = pow(2, m); + long long ans = 1; + for (int i = 1; i <= n; i++) { ans = (ans * (mm - i)) % 1000000009; } + cout << ans << endl; + return 0; +} +int n, tmp, i, temp; +int main() { + cin >> n; + tmp = n; + i = 1; + while (n) { + temp = (tmp - i) / 2; + for (int j = 1; j <= temp; j++) cout << "*"; + for (int j = 1; j <= i; j++) cout << "D"; + for (int j = 1; j <= temp; j++) cout << "*"; + cout << endl; + if (n > tmp / 2 + 1) + i += 2; + else + i -= 2; + n--; + } +} +long long a[105]; +int main() { + int n, m; + while (cin >> n >> m) { + long long max; + long long maxi; + int check; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + if (j == 1) { + cin >> max; + maxi = j; + } else { + cin >> check; + if (check > max) { + max = check; + maxi = j; + } + } + } + a[maxi]++; + } + max = a[1]; + maxi = 1; + for (int i = 2; i <= n; ++i) { + if (a[i] > max) { + max = a[i]; + maxi = i; + } + } + cout << maxi << endl; + } +} +int n; +char a[105][105]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int all = 0, sum; + for (int i = 0; i < n; i++) { + sum = 0; + for (int j = 0; j < n; j++) + if (a[i][j] == 'C') sum++; + all += (sum - 1) * sum / 2; + } + for (int i = 0; i < n; i++) { + sum = 0; + for (int j = 0; j < n; j++) + if (a[j][i] == 'C') sum++; + all += (sum - 1) * sum / 2; + } + cout << all << endl; + return 0; +} +const int nmax = (int)3e4; +int main() { + string a, b; + cin >> a >> b; + string a1(b.size(), '0'); + a1 += a; + string b1(a.size(), '0'); + b1 += b; + cout << (a1 > b1 ? ">" : (a1 == b1 ? "=" : "<")) << endl; + return 0; +} +int main() { + string s; + long long n, c = 0; + cin >> n; + while (n--) { + cin >> s; + if (s == "Tetrahedron") c += 4; + if (s == "Cube") c += 6; + if (s == "Octahedron") c += 8; + if (s == "Dodecahedron") c += 12; + if (s == "Icosahedron") c += 20; + } + cout << c << endl; + return 0; +} +int main() { + for (;;) { + char left_rigth; + string input, output = "", u, m, d; + u = "qwertyuiop"; + m = "asdfghjkl;"; + d = "zxcvbnm,./"; + cin >> left_rigth; + cin >> input; + if (left_rigth == 'R') { + for (int i = 0; i < input.length(); i++) { + bool found = false; + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == u[j]) { + found = true; + output += u[j - 1]; + break; + } + } + } + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == m[j]) { + found = true; + output += m[j - 1]; + break; + } + } + } + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == d[j]) { + found = true; + output += d[j - 1]; + break; + } + } + } + } + } else { + for (int i = 0; i < input.length(); i++) { + bool found = false; + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == u[j]) { + found = true; + output += u[j + 1]; + break; + } + } + } + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == m[j]) { + found = true; + output += m[j + 1]; + break; + } + } + } + if (!found) { + for (int j = 0; j < 10; j++) { + if (input[i] == d[j]) { + found = true; + output += d[j + 1]; + break; + } + } + } + } + } + cout << output << endl; + break; + } +} +int main() { + long long a; + cin >> a; + if (a % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +const int inf = 1e9 + 7; +const int mod = 998244353; +int x; +int hh, mm; +bool judge(int t) { + int total = hh * 60 + mm - x * t; + total = (total + 24 * 60) % (24 * 60); + int h = total / 60; + int m = total % 60; + int num = 0; + while (h) { + int tmp = h % 10; + h = h / 10; + if (tmp == 7) num++; + } + while (m) { + int tmp = m % 10; + m = m / 10; + if (tmp == 7) num++; + } + return num ? 1 : 0; +} +int main() { + cin >> x; + cin >> hh >> mm; + for (int i = 0;; i++) { + if (judge(i)) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int d, n, m; + while (cin >> n >> m) { + d = 1; + while (n > 0) { + if (d % m == 0) n++; + n--; + d++; + } + --d; + cout << d << endl; + } +} +int main() { + int n, k; + while (cin >> n >> k) { + int a = n * 2 / k + (n * 2 % k == 0 ? 0 : 1); + int b = n * 5 / k + (n * 5 % k == 0 ? 0 : 1); + int c = n * 8 / k + (n * 8 % k == 0 ? 0 : 1); + cout << a + b + c << endl; + } + return 0; +} +int main() { + int a, b, i, j, k, l; + a = b = 1000; + string map[8]; + string key = ".BW"; + for (i = 0; i < 8; i++) cin >> map[i]; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8 && map[j][i] != 'B'; j++) + if (map[j][i] == 'W') a = min(a, j); + for (j = 7; j >= 0 && map[j][i] != 'W'; j--) + if (map[j][i] == 'B') b = min(b, 7 - j); + } + cout << (a <= b ? 'A' : 'B') << endl; +} +int t, n; +string s; +bool used[1000]; +int main() { + cin >> t; + for (int g = 1; g <= t; g++) { + cin >> n >> s; + bool f = false; + memset(used, false, sizeof(used)); + for (int i = 0; i < n; i++) { + if (used[s[i]]) break; + if (abs(s[n - i - 1] - s[i]) == 0 || abs(s[n - i - 1] - s[i]) == 2) + continue; + else { + cout << "NO" << endl; + f = true; + break; + } + } + if (!f) cout << "YES" << endl; + } +} +int main() { + int K, R, i; + cin >> K >> R; + for (i = 1;; i++) { + if (K * i % 10 == 0) break; + if (((K * i) - R) % 10 == 0) break; + } + cout << i << endl; + return 0; +} +int main() { + int i, j, m, n, x, y, k; + cin >> n; + cout << n % 2 << endl; + return 0; +} +const int maxn = 1e5 + 5; +const int maxl = 26; +long long n; +int main() { + while (cin >> n) { + long long ans = 0; + while (n) { + if (n & 1) ans++; + n >>= 1; + } + cout << ans << endl; + } +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int ans = -1; + for (int i = 0; ans == -1; i++) { + int y = i * p / k; + if (s * y >= n) { + ans = i; + break; + } + } + cout << ans << "\n"; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +int n, m, r = 10; +int a[N], b[N]; +bool x[N]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a[i]; + x[a[i]] = true; + } + for (int i = 0; i < m; i++) { + cin >> b[i]; + if (x[b[i]]) r = min(b[i], r); + } + if (r != 10) { + cout << r << endl; + return 0; + } + sort(a, a + n); + sort(b, b + m); + cout << min(a[0], b[0]) << max(a[0], b[0]) << endl; +} +int main() { + string st, s; + int i, a, b, count = 0; + cin >> a >> st; + b = a / 11; + for (i = 0; i < a; i++) { + if (st[i] == '8') { count++; } + } + if (count < b) { + cout << count << endl; + } else { + cout << b << endl; + } + return 0; +} +int main() { + long long int n, k, i, j; + cin >> n >> k; + vector v; + for (i = 0; i < n; i++) { + long long int x; + cin >> x; + v.push_back(x); + } + while (!v.empty()) { + if (v[0] <= k) { + v.erase(v.begin()); + } else if (v[v.size() - 1] <= k) { + v.erase(v.begin() + v.size() - 1); + } else { + break; + } + } + cout << n - v.size() << '\n'; + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + int d = a - c; + int e = b - c; + int f = n - d - e - c; + if (d >= 0 && e >= 0 && c >= 0 && f > 0) + cout << f << endl; + else + cout << -1 << endl; + return 0; +} +int a[55]; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'B') a[1]++; + if (s[i] == 'u') a[2]++; + if (s[i] == 'l') a[3]++; + if (s[i] == 'b') a[4]++; + if (s[i] == 'a') a[5]++; + if (s[i] == 's') a[6]++; + if (s[i] == 'r') a[7]++; + } + a[2] = a[2] / 2; + a[5] = a[5] / 2; + sort(a + 1, a + 1 + 7); + cout << a[1] << endl; + return 0; +} +int main() { + long long n, a, b, res; + cin >> n; + for (long long i = 1; i <= n; i++) { + res = 0; + cin >> a >> b; + while (a > 0 && b > 0) { + if (a < b) swap(a, b); + res = res + a / b; + a = a % b; + } + cout << res << endl; + } + return 0; +} +long long x, y, z, a; +string s, ss; +int main() { + cin >> x >> y >> s; + s[x - 1]++; + long long i = x - 1; + for (; i >= 0 && i < x;) { + if (s[i] - 'a' >= y) { + s[i--] = 'a'; + (i >= 0) ? s[i]++ : a = 2; + } else if ((i >= 1 && s[i] == s[i - 1]) || (i >= 2 && s[i] == s[i - 2])) { + s[i]++; + } else { + i++; + } + } + (i < 0) ? cout << "NO" << endl : cout << s << endl; + return 0; +} +int main() { + long long a1, b1; + cin >> a1; + cin >> b1; + long long h = a1, g = b1; + int a[11], b[11]; + int y1 = 0; + while (a1) { + if (a1 % 10 != 0) { + a[y1] = a1 % 10; + a1 = a1 / 10; + y1++; + } else { + a1 = a1 / 10; + } + } + int sum1 = 0, mul1 = 1; + for (int i = 0; i < y1; i++) { + sum1 += a[i] * mul1; + mul1 *= 10; + } + int y2 = 0; + while (b1) { + if (b1 % 10 != 0) { + b[y2] = b1 % 10; + b1 = b1 / 10; + y2++; + } else { + b1 = b1 / 10; + } + } + int sum2 = 0, mul2 = 1; + for (int i = 0; i < y2; i++) { + sum2 += b[i] * mul2; + mul2 *= 10; + } + int c[11]; + long long v; + v = h + g; + int y = 0; + while (v) { + if (v % 10 != 0) { + c[y] = v % 10; + v = v / 10; + y++; + } else { + v = v / 10; + } + } + int sum = 0, mul = 1; + for (int i = 0; i <= y - 1; i++) { + sum += c[i] * mul; + mul *= 10; + } + if (sum1 + sum2 == sum) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long k, n, w; + cin >> k >> n >> w; + int sum = w * k + (w * (w - 1) * k) / 2; + cout << max(0LL, sum - n) << "\n"; +} +int data[1010]; +int N; +long long power_mod(long long a, long long b, long long mod) { + long long ans = 1; + while (b) { + if (b & 1) ans = ans * a % mod; + a = a * a % mod; + b >>= 1; + } + return ans; +} +int C(int a, int b) { + if (a == b || b == 0) return 1; + long long ans = 1; + for (int i = a - b + 1; i <= a; i++) { ans = (ans % 1000000007) * (i % 1000000007) % 1000000007; } + long long sum = 1; + for (int i = 1; i <= b; i++) { sum = (sum % 1000000007) * (i % 1000000007) % 1000000007; } + long long c = power_mod(sum, 1000000007 - 2, 1000000007); + return (ans % 1000000007) * (c % 1000000007) % 1000000007; +} +int main() { + while (cin >> N) { + int sum = 0; + for (int i = 1; i <= N; i++) { + cin >> data[i]; + sum += data[i]; + } + long long ans = 1; + for (int i = N; i >= 1; i--) { + long long t = C(sum - 1, data[i] - 1); + sum -= data[i]; + ans = (ans % 1000000007) * (t % 1000000007) % 1000000007; + } + cout << ans << endl; + } + return 0; +} +int main() { + long long n, k, mx = -1000000000000, f, t; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) f = f - (t - k); + mx = max(mx, f); + } + cout << mx << endl; +} +int main() { + long long n; + cin >> n; + if (n == 0) cout << "O-|-OOOO" << endl; + while (n > 0) { + long long a = n % 10; + if (a == 0) + cout << "O-|-OOOO" << endl; + else if (a == 1) + cout << "O-|O-OOO" << endl; + else if (a == 2) + cout << "O-|OO-OO" << endl; + else if (a == 3) + cout << "O-|OOO-O" << endl; + else if (a == 4) + cout << "O-|OOOO-" << endl; + else if (a == 5) + cout << "-O|-OOOO" << endl; + else if (a == 6) + cout << "-O|O-OOO" << endl; + else if (a == 7) + cout << "-O|OO-OO" << endl; + else if (a == 8) + cout << "-O|OOO-O" << endl; + else + cout << "-O|OOOO-" << endl; + n /= 10; + } + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + if (d1 < d2) { + swap(d1, d2); + swap(u1, u2); + } + if (h >= d1) { + w += (d1 + h) * (h - d1 + 1) / 2; + w = (w > u1) ? (w - u1) : 0; + h = d1 - 1; + } + if (h >= d2) { + w += (d2 + h) * (h - d2 + 1) / 2; + w = (w > u2) ? (w - u2) : 0; + h = d2 - 1; + } + w += (1 + h) * h / 2; + cout << w << endl; + return 0; +} +int a[3333], n; +int sum, tmp; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> tmp; + if (!a[tmp] && tmp) a[tmp]++, sum++; + } + cout << sum << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (i == a[a[a[i]]]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int ans = 0; +int main() { + int n; + cin >> n; + while ((1 << ans) - 1 < n) ans++; + cout << ans << endl; + return 0; +} +int main() { + int x; + cin >> x; + cout << (x / 2) * 3 << endl; +} +int main() { + long long n, x, add, cnt = 0; + char ch; + cin >> n >> x; + while (n--) { + cin >> ch >> add; + if (ch == '+') + x += add; + else { + if (x < add) + cnt++; + else + x -= add; + } + } + cout << x << " " << cnt << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a, p, result = 0, cost = INT_MAX; + for (int i = 0; i < n; i++) { + cin >> a >> p; + cost = min(cost, p); + result += (a * cost); + } + cout << result << endl; + } + return 0; +} +bool cmp(int a, int b) { + return a < b; +} +int main() { + int n; + cin >> n; + string s; + int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0; + for (int i = 0; i < n; i++) { + cin >> s; + if (s[0] == 'T') + sum1 += 4; + else if (s[0] == 'C') + sum2 += 6; + else if (s[0] == 'O') + sum3 += 8; + else if (s[0] == 'D') + sum4 += 12; + else + sum5 += 20; + } + cout << sum1 + sum2 + sum3 + sum4 + sum5 << endl; +} +long long gcd(long long a, long long b) { + while (b > 0) { + a %= b; + swap(a, b); + } + return a; +} +string sy = "Finite\n"; +string sn = "Infinite\n"; +map, char> m; +void solve() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long p, q, b; + cin >> p >> q >> b; + p %= q; + long long g = gcd(p, q); + p /= g; + q /= g; + if (p == 0) { + cout << sy; + continue; + } + if (m.find({q, b}) != m.end()) { + if (m[{q, b}]) + cout << sy; + else + cout << sn; + continue; + } + long long q1 = q; + g = gcd(q, b); + while (g > 1) { + while (q % g == 0) q /= g; + g = gcd(q, b); + } + if (q == 1) { + m[{q1, b}] = true; + cout << sy; + } else { + m[{q1, b}] = false; + cout << sn; + } + } +} +int main() { + srand(555); + solve(); +} +int main() { + int n; + cin >> n; + if (n % 10 <= 5) { + cout << (n / 10) * 10 << endl; + } else { + cout << (n / 10 + 1) * 10 << endl; + } +} +int main() { + int n, i, x, maxi = -1000000007, tem, flag; + double p; + cin >> n; + for (i = 1; i <= n; i++) { + flag = 0; + cin >> x; + if (x < 0) { + if (x > maxi) maxi = x; + flag = 1; + } + if (flag == 1) x = -x; + p = sqrt(x * 1.00); + tem = p; + if (tem != p && flag != 1) { + if (x > maxi) maxi = x; + } + } + cout << maxi << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + string result; + result += s1[0]; + for (int x = 1; x < s1.length(); x++) { + if (s1[x] < s2[0]) + result += s1[x]; + else + break; + } + result += s2[0]; + cout << result << endl; + return 0; +} +int main() { + char ind; + cin >> ind; + string s; + cin >> s; + string s2 = ""; + string s1[3] = {"qwertyuiop", "asdfghjkl;", "zxcvbnm,./"}; + for (int i = 0; i < s.size(); i++) { + for (int j = 0; j < 3; j++) { + int a = s1[j].find(s[i]); + if (a >= 0 && ind == 'R') { + s2 = s2 + s1[j][a - 1]; + } else if (a >= 0 && ind == 'L') { + s2 = s2 + s1[j][a + 1]; + } + } + } + cout << s2 << endl; + return 0; +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + x = (x * y) / __gcd(x, y); + cout << b / x - (a - 1) / x << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool right = true; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) cout << '#'; + } else { + if (right) { + for (int j = 0; j < m - 1; j++) cout << '.'; + cout << '#'; + right = false; + } else { + cout << '#'; + for (int j = 1; j < m; j++) cout << '.'; + right = true; + } + } + cout << endl; + } +} +int main() { + int n, x, max = 0, min = INT_MAX; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x >= max) max = x; + if (min > x) min = x; + } + cout << max - min + 1 - n << endl; +} +int main() { + int t; + long long int s, a, b, c; + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> s >> a >> b >> c; + long long int x = s / c; + long long int y = x / a * b; + long long int z = x + y; + cout << z << endl; + } + return 0; +} +long long n, m; +string mRead() { + string s; + return cin >> s, s; +} +string solve(string s) { + for (int i = 0; i < s.length(); ++i) { + if (s[i] == '.') { + if (s[i - 1] == '9') + return "GOTO Vasilisa."; + else if (s[i + 1] - '0' < 5) + return s.substr(0, i); + else { + s[i - 1] = s[i - 1] + 1; + return s.substr(0, i); + } + } + } +} +int main() { + cout << solve(mRead()) << endl; + return 0; +} +int main() { + string s; + int i, l, j, cnt = 0, ans = 0, ans2 = 0; + cin >> s; + l = s.length(); + for (i = 0; i < l; i++) { + if (s[i] == 'A') { + for (j = 0; j < i; j++) + if (s[j] == 'Q') ans++; + for (j = i + 1; j < l; j++) + if (s[j] == 'Q') ans2++; + cnt += ans * ans2; + ans = 0; + ans2 = 0; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + set se; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x != 0) se.insert(x); + } + cout << se.size() << endl; +} +int main() { + string s; + while (cin >> s) { + int len = s.length(); + cout << (len + 1) * 26 - len << endl; + } +} +const double TOLL = 1e-9; +int memo[51][255]; +int recur(int n, int k) { + if (n == 0 && k == 0) return 0; + if (n == 0) return 1000; + if (k == 0) return 1000; + if (memo[n][k] != -1) return memo[n][k]; + int rv = 1000; + for (int i = 2; i <= 5; i++) + if (i <= k) { + int now = recur(n - 1, k - i); + if (i == 2) now++; + rv = min(now, rv); + } + return memo[n][k] = rv; +} +int main() { + memset(memo, -1, sizeof memo); + int n, k; + while (cin >> n >> k) { cout << recur(n, k) << endl; } +} +const int N = 1e5 + 5, OO = 0x3f3f3f3f; +int main() { + string str; + getline(cin, str); + for (int i = 0; i < str.size(); i++) { + if (str[i] == ' ' && str[i + 1] == ' ') { + str.erase(str.begin() + i); + i--; + } + if (str[i] == ',' || str[i] == '!' || str[i] == '?' || str[i] == '.') { + if (str[i + 1] != ' ' && i < str.size() - 1) { + string a = " "; + str.insert(i + 1, a); + } + if (str[i - 1] == ' ') { + str.erase(str.begin() + (i - 1)); + i--; + } + } + } + cout << str << endl; +} +long long a, b; +long long ans[100]; +int flag = 0; +int k; +void dfs(long long a, int i) { + if (flag || a > b) { return; } + ans[i] = a; + if (a == b) { + flag = 1; + k = i; + return; + } + dfs(a * 2, i + 1); + dfs(a * 10 + 1, i + 1); +} +int main() { + cin >> a >> b; + dfs(a, 0); + if (flag == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + cout << k + 1 << endl; + cout << ans[0]; + for (int i = 1; i <= k; i++) { cout << ' ' << ans[i]; } + cout << endl; + } + return 0; +} +inline long long read() { + char c = getchar(); + while (c != '-' && (c < '0' || c > '9')) c = getchar(); + long long k = 0, kk = 1; + if (c == '-') c = getchar(), kk = -1; + while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar(); + return kk * k; +} +void write(long long x) { + if (x < 0) x = -x, putchar('-'); + if (x) write(x / 10), putchar(x % 10 + '0'); +} +void writeln(long long x) { + write(x); + if (x == 0) putchar('0'); + puts(""); +} +long long n, m, x, y, d, dd, z1[1000000], z2[1000000], a[1000000], b[1000000]; +int main() { + n = read(); + m = read(); + x = read(); + y = read(); + d = 1; + swap(x, y); + for (long long i = 1; i <= n; i++) a[i] = read(); + for (long long i = 1; i <= m; i++) b[i] = read(); + for (long long i = 1; i <= n; i++) { + while (d <= m && b[d] + y < a[i]) d++; + if (d <= m && b[d] - x <= a[i]) z1[++dd] = i, z2[dd] = d, d++; + } + cout << dd << endl; + for (long long i = 1; i <= dd; i++) cout << z1[i] << ' ' << z2[i] << endl; +} +int main() { + int n; + cin >> n; + if (n % 5) + cout << n / 5 + 1 << endl; + else + cout << n / 5 << endl; +} +int main() { + int n, d, c = 0, e; + cin >> n; + if (n % 2 == 0) { + d = n / 2; + for (int i = 1; i < n; i++) { + cout << "I hate that" + << " "; + c++; + if (c == d) { break; } + cout << "I love that" + << " "; + } + cout << "I love it" << endl; + } else { + e = n / 2; + for (int i = 1; i <= e; i++) { + cout << "I hate that" + << " "; + cout << "I love that" + << " "; + } + cout << "I hate it" << endl; + } + return 0; +} +int main() { + long long int a, b, c, n; + cin >> a >> b >> c >> n; + int temp = min(a, b); + if (c > temp) { + cout << "-1\n"; + return 0; + } + if ((a + b) - c < n) { + cout << n - ((a + b) - c) << endl; + } else { + cout << "-1\n"; + } + return 0; +} +string str, s[105]; +vector s1; +int n; +int main() { + cin >> str; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + for (int i = 0; i < n; i++) { + if (s[i].find(str) == 0) s1.push_back(s[i]); + } + if (s1.size()) + cout << s1[0] << "\n"; + else + cout << str << "\n"; + return 0; +} +int a[105][105] = {0}; +int main() { + int n, i, j; + cin >> n; + for (i = 1; i <= n; i++) a[1][i] = 1; + for (i = 2; i <= n; i++) + for (j = 1; j <= n; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + cout << a[n][n] << endl; +} +int a[34][34]; +int h[34]; +int lie[34]; +int main() { + int n; + cin >> n; + memset(h, 0, sizeof(h)); + memset(lie, 0, sizeof(lie)); + int ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> a[i][j]; } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + h[i] += a[i][j]; + lie[i] += a[j][i]; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (lie[j] > h[i]) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + vector v; + string n1, n2, n1a, n2a; + cin >> n1 >> n2 >> n; + v.push_back(n1); + v.push_back(n2); + for (int i = 0; i < n; i++) { + cin >> n1a >> n2a; + if (n1 == n1a) { + n1 = n2a; + } else if (n2 == n1a) { + n2 = n2a; + } + v.push_back(n1); + v.push_back(n2); + } + for (int i = 0; i < v.size(); i++) { + if (i % 2 != 0) { + cout << v[i] << endl; + } else { + cout << v[i] + " "; + } + } +} +void solve() { + string a, b; + cin >> a >> b; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cout << a << " " << b << endl; + string c, d; + cin >> c >> d; + if (c == a) { + a = d; + } else if (c == b) { + b = d; + } + } + cout << a << " " << b << endl; +} +int main() { + solve(); + return 0; +} +int isprime(long long n) { + int i; + for (i = 2; i < n; i++) { + if (n % i == 0) { return 0; } + } + return 1; +} +int main() { + long long n, m; + cin >> n >> m; + long long nextprime; + nextprime = n + 1; + while (1) { + if (isprime(nextprime)) { break; } + nextprime++; + } + if (nextprime == m) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + string s = "abcdefghijklmnopqrstuvwxyz"; + string s1; + cin >> s1; + int position = 0, target, moves = 0; + for (int j = 0; j < s1.length(); j++) { + target = s.find(s1[j]); + if (abs(target - position) > 13) { + moves += 26 - abs(target - position); + } else { + moves += abs(target - position); + } + position = target; + } + cout << moves << endl; + return 0; +} +int main() { + int temp, t, temp2; + long long a, b, k; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> a >> b >> k; + if (k % 2 == 0) { + temp = k / 2; + cout << (a * temp) - (b * temp) << endl; + } else { + temp = (k + 1) / 2; + cout << (a * temp) - b * (k - temp) << endl; + } + } + return 0; +} +int main() { + int n = 3, sum = 0; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + sum = a[2] - a[0]; + cout << sum << endl; + return 0; +} +int main() { + int m, n, k, a[100], i, sum = 0; + cin >> n >> m; + k = m; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int max, min; + max = a[0]; + for (i = 0; i < n; i++) + if (a[i] > max) max = a[i]; + min = (sum + m) / n; + if ((sum + m) % n != 0) min++; + min = (max > min) ? max : min; + cout << min << " " << max + m << endl; + return 0; +} +int main() { + int n, m, tmp, k = 0; + bool flag = false; + vector vct; + cin >> n >> m; + vct.resize(n); + for (int i = 0; i < n; i++) vct[i] = i + 1; + tmp = m; + while (tmp > 0) { + if (tmp - vct[k] < 0) { + cout << tmp << endl; + flag = true; + break; + } + tmp -= vct[k]; + k++; + if (k == n) k = 0; + } + if (!flag) cout << 0 << endl; + return 0; +} +int main() { + int n, m, min, max, rec; + cin >> n >> m >> min >> max; + int minr = max + 1, maxr = min - 1; + for (int i = 0; i < m; i++) { + cin >> rec; + if (rec < minr) minr = rec; + if (rec > maxr) maxr = rec; + } + int reqrec = 2; + if (min == minr) reqrec--; + if (max == maxr) reqrec--; + if (min > minr || max < maxr) reqrec = -1; + if (reqrec == -1 || n - m < reqrec) + cout << "Incorrect" << endl; + else + cout << "Correct" << endl; + return 0; +} +int main() { + int n, sum; + int a[100 + 10]; + while (cin >> n) { + sum = 0; + for (int i = 1; i <= n; i++) cin >> a[i]; + a[0] = 0, a[n + 1] = 0; + for (int i = 0; i <= n; i++) { + if (a[i] == 1) sum++; + if (a[i - 1] == 1 && a[i] == 0 && a[i + 1] == 1 && i != 0) sum++; + if (a[i] == 0 && a[i + 1] == 0) i++; + } + cout << sum << endl; + } +} +const int maxn = 4e5 + 10; +const int maxm = 2e5 + 10; +const int INF = 0x3f3f3f3f; +int n, m; +int a[110]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = -INF; + for (int i = 0; i < n; i++) + for (int j = i; j < n; j++) { + int res = a[i]; + for (int k = i + 1; k <= j; k++) res ^= a[k]; + ans = max(ans, res); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int A[n]; + for (int i = 0; i < n; i++) { cin >> A[i]; } + int ansf = 1; + int j = 0; + int ch = 0; + int max1 = 1; + int x = 0; + int dp[n] = {0}; + for (int i = 1; i < n; i++) { + if (A[i] > A[i - 1]) { + dp[i] = dp[i - 1] + 1; + } else { + dp[i] = 0; + } + } + for (int i = 1; i < n; i++) { + if (A[i] > A[i - 1]) { + ansf++; + } else { + if (ch == 0) { + x = A[i]; + A[i] = A[i - 1] + 1; + j = i; + ch = 1; + ansf++; + } else { + ansf = i - j; + A[j] = x; + if (ansf == 1) { + if (A[i] > A[i - 1]) { + ansf++; + x = A[i - 2]; + ansf++; + j = i - 2; + A[i - 2] = A[i - 1] - 1; + if (i >= 3 && A[i - 2] > A[i - 3]) ansf = ansf + dp[i - 2]; + } else { + ansf++; + x = A[i - 1]; + j = i - 1; + A[i - 1] = A[i] - 1; + if (A[i - 1] > A[i - 2]) ansf = ansf + dp[i - 1]; + } + } else { + if (A[j] < A[j + 1]) ansf++; + x = A[i]; + j = i; + A[i] = A[i - 1] + 1; + } + } + } + max1 = max(max1, ansf); + } + cout << max1 << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int s = 0; + int x = n / 100; + n = n - x * 100; + s += x; + x = n / 20; + n = n - x * 20; + s += x; + x = n / 10; + n = n - x * 10; + s += x; + x = n / 5; + n = n - x * 5; + s += x; + s = s + n; + cout << s << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + int sum = 0; + int sub = 240 - k; + for (int i = 1; i <= n; i++) { + int res = (k + 5 * i); + if (res <= 240) { + ans++; + k += 5 * i; + } + } + cout << ans << endl; + return 0; +} +int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; +int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; +void fast() {} +const long long md = 1e9 + 7; +int main() { + fast(); + long long n, m; + cin >> n >> m; + long long a[m + 5]; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + long long ans = LLONG_MAX; + for (int i = 0; i <= m - n; i++) { ans = min(ans, a[i + (n - 1)] - a[i]); } + cout << ans << endl; + return 0; +} +int main() { + string s, s1; + while (cin >> s >> s1) { + int c = 0; + for (int i = 1; i < s.size(); i++) { + if (s[i] < s1[0]) + c = i; + else { + break; + } + } + string p; + for (int i = 0; i <= c; i++) p += s[i]; + p += s1[0]; + cout << p << endl; + } +} +const long long inf = 0x3f3f3f3f; +int x[3005]; +int y[3005]; +bool mark[5000005]; +int main() { + int n; + cin >> n; + cin.get(); + for (int i = 1; i <= n; i++) { + cin >> x[i]; + mark[x[i]] = true; + } + for (int i = 1; i <= n; i++) { + cin >> y[i]; + mark[y[i]] = true; + } + int number = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) { + int temp = x[i] ^ y[j]; + if (mark[temp]) number++; + } + if (number % 2) + cout << "Koyomi" << endl; + else + cout << "Karen" << endl; + return 0; +} +const long long MAXN = 200100, md = 998244353; +int main() { + long long n, h, a, b, k, ta, fa, tb, fb; + cin >> n >> h >> a >> b >> k; + while (k--) { + cin >> ta >> fa >> tb >> fb; + long long ans = abs(ta - tb); + if (ans != 0) { + if (fa > b || fa < a) { + ans += min(abs(fa - a) + abs(fb - a), abs(fa - b) + abs(fb - b)); + } else if (fb > b || fb < a) { + ans += min(abs(fb - b) + abs(fa - b), abs(fb - a) + abs(fa - a)); + } else { + ans += abs(fa - fb); + } + } else { + ans += abs(fa - fb); + } + cout << ans << '\n'; + } +} +int main() { + int n; + int i; + string s1; + string s2; + string sir1[1000]; + string sir2[1000]; + string aux; + cin >> s1 >> s2; + cout << s1 << " " << s2 << endl; + cin >> n; + for (i = 0; i < n; i++) { + cin >> sir1[i] >> sir2[i]; + if (sir1[i] == s1) { + sir1[i] = sir2[i]; + sir2[i] = s2; + } else if (sir1[i] == s2) { + sir1[i] = s1; + } + s1 = sir1[i]; + s2 = sir2[i]; + } + for (i = 0; i < n; i++) { cout << sir1[i] << " " << sir2[i] << endl; } + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (long long i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int c = 0; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + if (c >= a) c = max(c, b); + } + if (c >= m) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int x, n, i, j; + cin >> n >> x; + for (i = 1; i <= n; i++) { + cin >> j; + x -= 86400 - j; + if (x <= 0) { + cout << i << endl; + return 0; + } + } +} +int n, x, y, lcnt, rcnt; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x < 0) { + lcnt++; + } else { + rcnt++; + } + } + if (lcnt <= 1 || rcnt <= 1) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } +} +int main() { + int x, n, a[3], b[3], c[3]; + cin >> n; + int sum = 0; + x = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { + cin >> a[j]; + sum += a[j]; + } + if (sum >= 2) x++; + sum = 0; + } + cout << x << endl; + return 0; +} +long long dp[52][252]; +long long f(long long slot, long long n) { + if (slot == 0) { + if (n == 0) + return 0; + else + return 1e10; + } + if (dp[slot][n] != -1) return dp[slot][n]; + long long ans = 1e10; + for (int i = 2; i <= 5; i++) { + if (i == 2) { + ans = min(ans, 1 + f(slot - 1, n - i)); + } else + ans = min(ans, f(slot - 1, n - i)); + } + return dp[slot][n] = ans; +} +int main() { + long long n, k; + cin >> n >> k; + memset(dp, -1, sizeof(dp)); + cout << f(n, k) << endl; +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + long long k = n % 4; + if (k == 0) { + cout << "0" << endl; + } else if (k == 3) { + if (a <= b + c && a <= 3 * c) + cout << a << endl; + else if (b + c <= 3 * c) + cout << b + c << endl; + else + cout << 3 * c << endl; + } else if (k == 2) { + if (2 * a <= b && 2 * a <= 2 * c) { + cout << 2 * a << endl; + } else if (b <= 2 * c) { + cout << b << endl; + } else + cout << 2 * c << endl; + } else if (k == 1) { + if ((3 * a <= (a + b)) && 3 * a <= c) { + cout << 3 * a << endl; + } else if (a + b <= c) { + cout << a + b << endl; + } else + cout << c << endl; + } + return 0; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +int n; +int main() { + cin >> n; + cout << (n / 2) + 1 << '\n'; + return 0; +} +int main() { + int n, dx; + cin >> n >> dx; + string a[1001], b[1001], c[1001], d[1001]; + int t[1001]; + int sum = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> t[i]; + for (int i = 0; i < n - 1; i++) + for (int j = i + 1; j < n; j++) + if (t[j] - t[i] > 0 && t[j] - t[i] <= dx) + if (a[i] == b[j] && b[i] == a[j]) { + int flat = 0; + for (int k = 0; k < sum; k++) + if (a[i] == c[k] && b[i] == d[k] || a[i] == d[k] && b[i] == c[k]) { + flat = 1; + break; + } + if (!flat) { + c[sum] = a[i]; + d[sum] = b[i]; + sum++; + } + } + cout << sum << endl; + for (int i = 0; i < sum; i++) { cout << c[i] << " " << d[i] << endl; } +} +int main() { + int N, X; + cin >> N >> X; + N %= 6; + int ans = X; + for (int i = N; i >= 1; --i) { + if (ans == 2 && i % 2 == 0) + ans = 1; + else if (ans == 1 && i % 2 == 1) + ans = 0; + else if (ans == 1 && i % 2 == 0) + ans = 2; + else if (ans == 0 && i % 2 == 1) + ans = 1; + } + cout << ans << endl; + return 0; +} +int MOD; +long long mod_pow(long long a, long long b) { + if (b == 0) return 1; + if (b == 1) return a % MOD; + if (b & 1) return ((a % MOD) * mod_pow(a, b - 1)) % MOD; + long long x = mod_pow(a, b >> 1); + return (x * x) % MOD; +} +int main() { + int n, m; + cin >> n >> m; + MOD = m; + int r = mod_pow(3, n); + if (r == 0) { + cout << m - 1 << endl; + } else { + cout << r - 1 << endl; + } + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (d / t * k < n - k) + cout << "YES"; + else + cout << "NO"; + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n, 1); + for (int i = 2; i <= n; ++i) { + for (int j = 1; j < n; ++j) { v[j] += v[j - 1]; } + } + cout << v.back() << endl; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +string x, y; +vector v; +int main() { + cin >> x >> y; + for (int i = 0; i < x.size(); i++) { + for (int j = 0; j < y.size(); j++) { + string z = x.substr(0, i + 1) + y.substr(0, j + 1); + v.push_back(z); + } + } + sort(v.begin(), v.end()); + cout << v[0] << endl; +} +int main() { + long long n, m, z, i, c = 0; + cin >> n >> m >> z; + for (i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) c++; + } + cout << c << endl; +} +int main() { + puts("Karen"); + return 0; +} +long long a, b, lcm; +long long LCM(long long a, long long b) { + return (a * b) / __gcd(a, b); +} +int main() { + cin >> a >> b; + lcm = LCM(a, b); + if (a == b) return cout << "Equal", 0; + if (a < b) + a = lcm / a - 1, b = lcm / b; + else + a = lcm / a, b = lcm / b - 1; + if (a > b) + cout << "Dasha" << endl; + else if (a < b) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int num[n]; + int lock[n]; + for (int i = 1; i <= n; i++) { + char c; + cin >> c; + num[i] = c - '0'; + } + for (int i = 1; i <= n; i++) { + char c; + cin >> c; + lock[i] = c - '0'; + } + int sum = 0; + for (int i = 1; i <= n; i++) { + if (num[i] > lock[i]) { + sum += min(abs(num[i] - lock[i]), abs(9 - num[i]) + 1 + lock[i]); + } else + sum += min(abs(num[i] - lock[i]), abs(9 - lock[i]) + 1 + num[i]); + } + cout << sum << endl; +} +int main() { + int n, m; + int count = 0; + cin >> n >> m; + for (int a = 0;; a++) { + if (a * a > n) break; + for (int b = 0;; b++) { + if (a + b * b > m) break; + if (a * a + b == n && a + b * b == m) count++; + } + } + cout << count << '\n'; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[110][110] = {0}; + int ax[110] = {0}; + for (int i = 0; i < n; i++) { cin >> ax[i]; } + for (int i = 0; i < m; i++) { + int a1, a2; + cin >> a1 >> a2; + a1 -= 1; + a2 -= 1; + a[a1][a2] = 1; + a[a2][a1] = 1; + } + int min = 99999999; + bool y = 0; + for (int i = 0; i < n - 2; i++) { + for (int j = i + 1; j < n - 1; j++) { + for (int k = j + 1; k < n; k++) { + if (a[i][j] + a[j][k] + a[k][i] == 3) { + int minx = ax[i] + ax[j] + ax[k]; + if (minx < min) { + min = minx; + y = 1; + } + } + } + } + } + if (y) + cout << min << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n, len; + string s; + map mp; + cin >> s; + len = s.length(); + for (int i = 0; i < len; i++) { mp[s[i]]++; } + int cnt = 0; + for (char i = 'a'; i <= 'z'; i++) { + if (mp[i]) { cnt++; } + } + int res = (len + 1) * (26 - cnt) + ((len + 1) * cnt) - len; + cout << res << endl; + return 0; +} +int main() { + int price, coin; + cin >> price >> coin; + int counter = 1; + while (1) { + if (price * counter % 10 == 0 || price * counter % 10 == coin) { + cout << counter << endl; + return 0; + } else { + counter++; + } + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + getline(cin, s); + getline(cin, s); + int maxx = 0, c = 0; + for (int i = 0; i <= n; i++) { + if (s[i] == ' ') { + if (c > maxx) maxx = c; + c = 0; + } else if (s[i] >= 65 && s[i] < 97) + c++; + } + cout << max(c, maxx) << endl; + return 0; +} +int main() { + string t; + set s; + cin >> t; + int c = 0, i, j; + for (i = 0; i < t.size(); i++) { s.insert(t[i]); } + if (s.size() % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +const double EPS = 1e-8; +void fast() {} +bool sortby(const pair &a, const pair &b) { + if (a.first >= b.first && a.second >= b.second) return true; + return false; +} +double area(int x1, int y1, int x2, int y2, int x3, int y3) { + return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int arr[205][4]; +int main() { + fast(); + int n; + cin >> n; + vector x(n), y(n); + for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + if (x[j] > x[i] && y[j] == y[i]) arr[i][0]++, arr[j][1]++; + if (x[j] < x[i] && y[j] == y[i]) arr[i][1]++, arr[j][0]++; + if (x[j] == x[i] && y[j] > y[i]) arr[i][2]++, arr[j][3]++; + if (x[j] == x[i] && y[j] < y[i]) arr[i][3]++, arr[j][2]++; + } + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (arr[i][0] && arr[i][1] && arr[i][2] && arr[i][3]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (b > c) { swap(b, c); } + cout << (2 * a + b - 1) * b + (c - b - 1) * (a + b - 1) << endl; + return 0; +} +void solve() { + int n, k; + cin >> n >> k; + vector a(n), b(k); + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < k; i++) { cin >> b[i]; } + sort(b.rbegin(), b.rend()); + int pos = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + a[i] = b[pos]; + pos++; + } + } + for (int i = 1; i < n; i++) { + if (a[i] <= a[i - 1]) { + cout << "Yes" << endl; + return; + } + } + cout << "No" << endl; +} +int main() { + solve(); + return 0; +} +int kg = 0; +int n, k; +char a[50]; +void judge(char a[]) { + int digit; + int num[10]; + memset(num, 0, sizeof(num)); + for (int i = 0; a[i] != '\0'; i++) { num[a[i] - '0'] = 1; } + for (int i = 0; i <= k; i++) { + if (!num[i]) return; + } + kg++; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + judge(a); + } + cout << kg << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + for (int i = 0; i < n; i++) { + a[i][0] = 1; + a[0][i] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i][j - 1] + a[i - 1][j]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +void seleccion(int v[], int n) { + for (int i = 0; i < n; i++) { + int m = i; + for (int j = i + 1; j < n; j++) + if (v[j] > v[m]) m = j; + int aux = v[i]; + v[i] = v[m]; + v[m] = aux; + } +} +void mostrar(int v[], int n) { + for (int i = 0; i < n; i++) cout << v[i] << " "; +} +int main() { + int n, sum = 0, cont = 0; + cin >> n; + int x[n]; + for (int i = 0; i < n; i++) cin >> x[i]; + seleccion(x, n); + for (int i = 0; i < n - 1; i++) { + if (x[i] > x[i + 1]) { + x[i] = x[i] - x[i + 1]; + } else { + if (cont > n) break; + } + if (i == n - 2) { + cont++; + seleccion(x, n); + i = -1; + } + } + for (int k = 0; k < n; k++) { sum += x[k]; } + cout << sum << endl; + return 0; +} +int b[11] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; +int main() { + char a[3]; + for (int i = 0; i < 2; i++) { cin >> a[i]; } + int x = a[0] - '0'; + int y = a[1] - '0'; + cout << b[x] * b[y] << endl; + return 0; +} +int main() { + long long int a, b; + cin >> a >> b; + long long int p = (a * b) / (__gcd(a, b)); + if (a == b) + cout << "Equal" + << "\n"; + else if (a > b) { + if (p / a + 1 == p / b) + cout << "Equal" + << "\n"; + else + cout << "Masha\n"; + } else { + if (p / a == p / b + 1) + cout << "Equal\n"; + else + cout << "Dasha\n"; + } + return 0; +} +const long long INF = 1e18; +const long long mod = 1e9 + 7; +const long long N = 5e5 + 10; +inline long long add(long long x, long long y) { + x += y; + if (x >= mod) x -= mod; + return x; +} +inline long long mul(long long x, long long y) { + x = (1LL * x * y) % mod; + return x; +} +map mt; +long long get(long long x) { + long long res = 0; + long long i = 0; + while (x > 0) { + long long d = x % 10; + d %= 2; + res = res + pow(2, i) * d; + x /= 10; + i++; + } + return res; +} +int main() { + long long t; + cin >> t; + while (t--) { + char ch; + cin >> ch; + if (ch == '+') { + long long x; + cin >> x; + mt[get(x)]++; + } else if (ch == '-') { + long long x; + cin >> x; + mt[get(x)]--; + } else { + string s; + cin >> s; + long long res = 0; + for (long long i = s.length() - 1; i >= 0; --i) { res = res + pow(2, s.length() - i - 1) * (s[i] == '1' ? 1 : 0); } + cout << mt[res] << "\n"; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int A = 0, B = 0; + int a, b; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) { + A++; + } else if (a < b) { + B++; + } + } + if (A > B) + cout << "Mishka" << endl; + else if (A < B) + cout << "Chris" << endl; + else if (A == B) + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum += a; + } + cout << (sum / n) << endl; + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + long long k = 0; + for (int i = 0; i < a; i++) { + char z; + long long x; + cin >> z >> x; + if (z == '+') { + b = b + x; + } else { + if (b - x >= 0) { + b = b - x; + } else + k++; + } + } + cout << b << " " << k << endl; +} +int main() { + string s; + cin >> s; + cout << (s.size() + 1) * 26 - s.size() << endl; + return 0; +} +int v[200005]; +int ans = 0x3f3f3f3f; +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = 0; i < n - 1; i++) { + if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(ans, v[i + 1] - v[i]); } + } + if (ans == 0x3f3f3f3f) + cout << -1 << endl; + else + cout << ans / 2 << endl; + return 0; +} +vector p, m, t; +int main() { + int n, temp; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> temp; + if (temp == 1) + p.push_back(i + 1); + else if (temp == 2) + m.push_back(i + 1); + else if (temp == 3) + t.push_back(i + 1); + } + int ans1 = min(min(p.size(), m.size()), t.size()); + cout << ans1 << endl; + for (int i = 0; i < ans1; ++i) { cout << p[i] << " " << m[i] << " " << t[i] << endl; } +} +int main() { + int a, b, c; + int arr[5]; + cin >> a >> b >> c; + arr[0] = a + b * c; + arr[1] = a * (b + c); + arr[2] = a * b * c; + arr[3] = (a + b) * c; + arr[4] = a + b + c; + int maximum = arr[0]; + for (int i = 1; i <= 4; i++) { + if (arr[i] > maximum) { maximum = arr[i]; } + } + cout << maximum << endl; + return 0; +} +int a[3] = {0}; +int dp[10000]; +int main() { + int n; + cin >> n >> a[0] >> a[1] >> a[2]; + memset(dp, -100, sizeof(dp)); + dp[0] = 0; + for (int i = 0; i < 3; i++) { + for (int j = a[i]; j <= n; j++) { dp[j] = max(dp[j], dp[j - a[i]] + 1); } + } + cout << dp[n] << endl; + return 0; +} +const int maxn = 200000 + 5; +int n, a[maxn], ans = 1e9; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + 1 + n); + int len = (n / 2) - 1; + for (int i = len + 2; i <= n; i++) ans = min(ans, abs(a[i] - a[i - len - 1])); + cout << ans << endl; +} +int vis[105], f[105][105]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> f[i][j]; + if (f[i][j] == 1) + vis[i] = 1; + else if (f[i][j] == 2) + vis[j] = 1; + else if (f[i][j] == 3) + vis[i] = vis[j] = 1; + } + } + int a[105], top = 0; + for (int i = 1; i <= n; i++) { + if (!vis[i]) { a[top++] = i; } + } + cout << top << endl; + for (int i = 0; i < top; i++) { + if (i == top - 1) + cout << a[i] << endl; + else + cout << a[i] << " "; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int a[11]; +int main() { + int n, m, t; + int i, j, k; + for (i = 0; i < 6; i++) cin >> t, a[t]++; + for (i = 1; i <= 9; i++) + if (a[i] >= 4) break; + if (i > 9) { + cout << "Alien" << endl; + return 0; + } + for (i = 1; i <= 9; i++) + if (a[i] == 2 || a[i] == 6) break; + if (i > 9) { + cout << "Bear" << endl; + return 0; + } + cout << "Elephant" << endl; + return 0; +} +int hasil(int x, int y) { + int ret = 0; + while (x > 0 && y > 0) { + if (x < y) { + if (y % x == 0) { + ret += (y / x); + ret--; + y = x; + } else { + ret += (y / x); + y = y % x; + } + } else if (x > y) { + if (x % y == 0) { + ret += (x / y); + ret--; + x = y; + } else { + ret += (x / y); + x = x % y; + } + } else { + ret++; + break; + } + } + return ret; +} +int main() { + int tc; + cin >> tc; + while (tc--) { + int n, m; + cin >> n >> m; + cout << hasil(n, m) << endl; + } + return 0; +} +int a[101], b[101]; +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + long long int n, i; + cin >> n; + cin >> a[0]; + b[0] = a[0]; + for (i = 1; i < n; i++) { + cin >> a[i]; + b[i] = gcd(a[i], b[i - 1]); + } + cout << b[n - 1] * n << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) cout << "#"; + } else { + if (i % 4 == 3) cout << "#"; + for (int j = 0; j < m - 1; j++) cout << "."; + if (i % 4 == 1) cout << "#"; + } + cout << "\n"; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector inp; + for (int i = 0; i < n; i++) { + char c; + cin >> c; + inp.push_back(c); + } + sort(inp.begin(), inp.end()); + long long int ans = 0; + int i = 1; + ans += (inp[0] - 'a' + 1); + k--; + int s = 0; + while (k > 0) { + if (inp[i] - inp[s] >= 2) { + ans += inp[i] - 'a' + 1; + s = i; + k--; + } + i++; + if (i >= n) break; + } + if (k != 0) + cout << "-1" << endl; + else + cout << ans << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a; + cin >> b; + cin >> c; + cout << 2 * c * (a + b - 2) - 8 * (c * (c - 1)) << endl; +} +int n, i, tmp; +int main() { + cin >> n; + tmp = n; + i = 1; + while (n) { + for (int j = 1; j <= (tmp - i) / 2; j++) cout << "*"; + for (int j = 1; j <= i; j++) cout << "D"; + for (int j = 1; j <= (tmp - i) / 2; j++) cout << "*"; + cout << endl; + if (n > tmp / 2 + 1) + i += 2; + else + i -= 2; + n--; + } +} +char check(char a, char b) { + if (a == '(' && b == ')') + return 'r'; + else if (a == '[' && b == ']') + return 'p'; + else + return 's'; +} +int win(char a, char b) { + if (a == 'r' && b == 'p') return -1; + if (a == 'p' && b == 's') return -1; + if (a == 's' && b == 'r') return -1; + if (a != b) return 1; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int len = s1.length(); + int t1 = 0, t2 = 0; + for (int i = 0; i < len; i += 2) { + char c1 = check(s1[i], s1[i + 1]); + char c2 = check(s2[i], s2[i + 1]); + int winner = win(c1, c2); + if (winner == -1) + t2++; + else if (winner == 1) + t1++; + } + if (t1 == t2) + cout << "TIE\n"; + else if (t1 > t2) + cout << "TEAM 1 WINS\n"; + else + cout << "TEAM 2 WINS\n"; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n & 1 ? 1 : 0) << '\n'; +} +int n; +int a; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> a; + if (360.0 / (180 - a) - 360 / (180 - a) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k; + int a = 0; + int b = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + if (k == 2) { + a += 1; + } else { + b += 1; + } + } + if (a > b) { + cout << b << endl; + } else { + cout << a + (b - a) / 3 << endl; + } +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 10]; + for (int i = 1; i <= n; i++) cin >> a[i]; + int vis[n + 10], s = 0, e = 0, ans = 0; + for (int b = -k; b <= k; b++) { + memset(vis, 0, sizeof(vis)); + s = 0, e = 0; + for (int i = -100; i <= 100; i++) { + int c = b + i * k; + if (c >= 1 && c <= n) vis[c] = 1; + if (c > n) break; + } + for (int i = 1; i <= n; i++) { + if (vis[i]) continue; + if (a[i] == 1) + s++; + else + e++; + } + ans = max(ans, abs(s - e)); + } + cout << ans << "\n"; + return 0; +} +int main() { + string s; + cin >> s; + int l = s.size(); + string ex; + vector ss; + int k = 0; + for (int t = 0; t < (1 << l); t++) { + ex = ""; + for (int i = 0; i < l; i++) { + if (t & (1 << i)) ex += s[i]; + } + sort(ex.begin(), ex.end()); + ss.push_back(ex); + } + sort(ss.begin(), ss.end()); + cout << ss[(1 << l) - 1] << endl; +} +void DisplayBoard(int remainder) { + if (remainder == 0) + cout << "O-|-OOOO" << endl; + else if (remainder == 1) + cout << "O-|O-OOO" << endl; + else if (remainder == 2) + cout << "O-|OO-OO" << endl; + else if (remainder == 3) + cout << "O-|OOO-O" << endl; + else if (remainder == 4) + cout << "O-|OOOO-" << endl; + else if (remainder == 5) + cout << "-O|-OOOO" << endl; + else if (remainder == 6) + cout << "-O|O-OOO" << endl; + else if (remainder == 7) + cout << "-O|OO-OO" << endl; + else if (remainder == 8) + cout << "-O|OOO-O" << endl; + else if (remainder == 9) + cout << "-O|OOOO-" << endl; +} +int main() { + int num, remainder; + cin >> num; + if (num == 0) { + cout << "O-|-OOOO" << endl; + return 0; + } + while (num > 0) { + remainder = num % 10; + DisplayBoard(remainder); + num = num / 10; + } + return 0; +} +int main() { + string num; + cin >> num; + string r0 = "O-", r1 = "-O"; + string left[5] = {"|-OOOO", "|O-OOO", "|OO-OO", "|OOO-O", "|OOOO-"}; + for (int i = num.length() - 1; i >= 0; i--) { + if ((num[i] - '0') >= 5) + cout << r1 + left[(num[i] - '0') - 5] << endl; + else + cout << r0 + left[num[i] - '0'] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int a, b; + cin >> a >> b; + int cnt = 0; + int MAX = max(a, b); + int MIN = min(a, b); + while (MAX > 0 && MIN > 0) { + if (MIN == 1) { + cnt += MAX / MIN; + break; + } + if (MAX % MIN == 0) { + cnt += MAX / MIN; + break; + } else { + cnt += MAX / MIN; + int temp = MIN; + MIN = MAX - MIN * (MAX / MIN); + MAX = temp; + } + } + cout << cnt << endl; + } +} +int n, a[105], b[605], ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[a[i]] = 1; + } + for (int i = 1; i <= 601; i++) { + if (b[i] != 0) { ans++; } + } + cout << ans; + cout << endl; + return 0; +} +int main() { + char S1[102]; + char S2[102]; + cin >> S1 >> S2; + if (strcmp(S1, S2) == 0) { + cout << S1 << "\n"; + } else { + cout << 1 << "\n"; + } +} +int a[105]; +const int inf = 0x3f3f3f3f; +int main() { + int n; + while (cin >> n) { + int ma = -inf, mi = inf; + for (int i = 0; i < n; i++) { + cin >> a[i]; + ma = max(ma, a[i]); + mi = min(mi, a[i]); + } + sort(a, a + n); + cout << ma << ' '; + for (int i = 1; i < n - 1; i++) { cout << a[i] << ' '; } + cout << mi << endl; + } +} +int main() { + string s; + while (cin >> s) { + int c = 0; + string n = s; + for (int i = 0; i < (s.length()) / 2; i++) { + reverse(s.begin(), s.end()); + if (s[i] != s[s.length() - i - 1]) { c++; } + } + if ((s.length()) % 2 == 0 && c == 1) + cout << "YES" << endl; + else if ((s.length()) % 2 == 1 && c <= 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int b, ck = 0, dk = 0, tk = 0; + string s; + cin >> s; + b = s.length(); + for (int i = 0; i < b; i++) { + if (s[i] >= 'A' && s[i] <= 'Z') { ck = 1; } + if (s[i] >= 'a' && s[i] <= 'z') { dk = 1; } + if (s[i] >= '1' && s[i] <= '9') { tk = 1; } + } + if (ck == 1 && dk == 1 && tk == 1 && b >= 5) { + cout << "Correct" << endl; + } else + cout << "Too weak" << endl; + return 0; +} +int main() { + int n; + int a; + int b; + int c; + cin >> n >> a >> b >> c; + int t[4]; + if (a > b) + t[1] = 3; + else + t[1] = 2; + if (b > c) + t[3] = 2; + else + t[3] = 1; + if (a > c) + t[2] = 3; + else + t[2] = 1; + int time = 1; + int sum = 0; + int zhuangtai = 1; + for (; time < n; time++) { + if (zhuangtai == 1) { + if (t[zhuangtai] == 2) { + sum += a; + zhuangtai = 2; + } else if (t[zhuangtai] == 3) { + sum += b; + zhuangtai = 3; + } + } else if (zhuangtai == 2) { + if (t[zhuangtai] == 1) { + { + sum += a; + zhuangtai = 1; + } + } else { + sum += c; + zhuangtai = 3; + } + } else { + if (t[zhuangtai] == 1) { + sum += b; + zhuangtai = 1; + } else { + sum += c; + zhuangtai = 2; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector programming; + vector math; + vector PE; + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + if (t == 1) + programming.push_back(i); + else if (t == 2) + math.push_back(i); + else if (t == 3) + PE.push_back(i); + } + int team = min(min(programming.size(), math.size()), PE.size()); + cout << team << endl; + for (int i = 0; i < team; i++) { cout << programming[i] << " " << math[i] << " " << PE[i] << endl; } +} +int main() { + int n, m, i, j, k, l, a[100007], cnt = 0, pos = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + long long int mn = 99999999999; + for (i = 0; i < n; i++) { + if (a[i] < mn) { + mn = a[i]; + pos = i + 1; + } + } + for (i = 0; i < n; i++) { + if (a[i] == mn) cnt++; + } + if (cnt > 1) + cout << "Still Rozdil" << endl; + else + cout << pos << endl; +} +int main() { + int n, k; + cin >> n >> k; + if (n * 3 >= k) + cout << n * 3 - k << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ara[n + 1], i; + for (i = 0; i < n; i++) cin >> ara[i]; + int a = 1, b = 2; + bool c = false; + for (i = 0; i < n; i++) { + if (ara[i] == a || ara[i] == b) { + b = 6 - a - b; + a = ara[i]; + } else { + c = true; + break; + } + } + if (c) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +long long A, B, ans = -0x7fffffff; +long long bxb, bex, bob, bpb; +int main() { + cin >> A >> B; + if (B == 0) { + cout << A * A << endl; + for (int i = 0; i < A; i++) cout << "o"; + cout << endl; + return 0; + } + if (B == 1) { + cout << A * A - 1 << endl; + for (int i = 0; i < A; i++) cout << "o"; + cout << "x" << endl; + return 0; + } + if (A == 0) { + cout << -B * B << endl; + for (int i = 0; i < B; i++) cout << "x"; + cout << endl; + return 0; + } + for (int xb = 2; xb <= min(B, A + 1); xb++) { + int ob = xb - 1; + long long score = ob - 1; + score += (A - (ob - 1)) * (A - (ob - 1)); + ; + long long pb = B / xb; + long long ex = B % xb; + score -= (xb - ex) * pb * pb; + score -= ex * (pb + 1) * (pb + 1); + if (score > ans) { + ans = score; + bxb = xb; + bex = ex; + bob = ob; + bpb = pb; + } + } + cout << ans << endl; + for (int i = 0; i < bxb; i++) { + for (int j = 0; j < bpb; j++) cout << "x"; + if (i < bex) cout << "x"; + if (i == 0) + for (int j = 0; j < A - (bob - 1); j++) cout << "o"; + else if (i + 1 < bxb) + cout << "o"; + } + cout << endl; + return 0; +} +int n, dp[1000010]; +int main() { + cin >> n; + dp[1] = 1, dp[2] = 3; + for (int i = 3; i <= n; ++i) dp[i] = (dp[i - 1] + dp[i - 2] + 2) % 1000000007; + cout << dp[n] << endl; + return 0; +} +int main() { + int q; + cin >> q; + int n; + string s; + for (int i = 1; i <= q; i++) { + cin >> n; + cin >> s; + if (n == 2) { + if (s[0] < s[1]) + cout << "YES\n" << n << "\n" << s[0] << " " << s[1] << "\n"; + else { + cout << "NO\n"; + } + } else { + cout << "YES\n"; + cout << 2 << "\n"; + cout << s[0] << " "; + for (int j = 1; j < s.size(); j++) { cout << s[j]; } + cout << "\n"; + } + } +} +string s; +void doit() { + cin >> s; + long long resp = 0; + for (long long j = 0; j < s.size(); j++) { + long long open = 0; + long long qClose = 0; + for (long long i = j; i < s.size(); i++) { + if (s[i] == '(') { open++; } + if (s[i] == ')') { open--; } + if (s[i] == '?') { + if (open > 0) { + qClose++; + open--; + } else { + open++; + } + } + if (open + 2 * qClose < 0) { break; } + if (open == 0) { + resp++; + } else { + if (open < 0) { + long long x = abs(open); + if (x % 2 == 0) { + if (2 * qClose >= x) { resp++; } + } + qClose -= (x + 1) / 2; + open += 2 * ((x + 1) / 2); + } + } + } + } + cout << resp << endl; +} +int main() { + long long T = 1; + while (T--) { doit(); } + return 0; +} +int main() { + int c, d, ans = 0; + cin >> c >> d; + if (c <= 27) { + ans = pow(2, c); + ans = d % ans; + cout << ans << endl; + } else + cout << d << endl; +} +int main() { + int n, k; + long long int f, t, maxi = 0, m; + cin >> n >> k; + cin >> f >> t; + if (t > k) + maxi = f - (t - k); + else + maxi = f; + n--; + while (n--) { + cin >> f >> t; + if (t > k) + m = f - (t - k); + else + m = f; + maxi = max(m, maxi); + } + cout << maxi << endl; + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + long long a, b, ans = 0; + cin >> a >> b; + while (a != 0 && b != 0) { + if (a < b) swap(a, b); + ans += a / b; + a = a % b; + b = b; + } + cout << ans << endl; + } + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << "\n"; + else + cout << 1 << "\n"; +} +int main() { + int n; + while (cin >> n) { + if (n < 0) { + int a, b; + a = n % 10; + b = (n % 100) / 10; + cout << (b < a ? (n / 100) * 10 + a : n / 10) << endl; + } else { + cout << n << endl; + } + } + return 0; +} +int main() { + float n, a, i; + int s; + cin >> n; + s = 25; + if (n == 1) { s = 5; } + cout << s << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int red = n * 2 / k; + int green = n * 5 / k; + int blue = n * 8 / k; + if (red < n * 2.0 / k) { red = red + 1; } + if (green < n * 5.0 / k) { green = green + 1; } + if (blue < n * 8.0 / k) { blue += 1; } + cout << red + green + blue << endl; + return 0; +} +long long int fact(int n) { + if (n <= 0) + return 1; + else + return n * fact(n - 1); +} +int main() { + long long int a, b; + cin >> a >> b; + long long int x = min(a, b); + cout << fact(x) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i, t = 0, x = 0, dCount, starCount; + for (int u = 1; u <= (n / 2) + 1; u++) { + dCount = 1 + t; + starCount = (n / 2) - x; + for (i = 1; i <= starCount; i++) { cout << '*'; } + for (i = 1; i <= dCount; i++) { cout << 'D'; } + for (i = 1; i <= starCount; i++) { cout << '*'; } + t += 2; + x++; + cout << endl; + } + x -= 2; + t -= 4; + for (int u = (n / 2) + 2; u <= n; u++) { + dCount = 1 + t; + starCount = (n / 2) - x; + for (i = 1; i <= starCount; i++) { cout << '*'; } + for (i = 1; i <= dCount; i++) { cout << 'D'; } + for (i = 1; i <= starCount; i++) { cout << '*'; } + t -= 2; + x--; + cout << endl; + } +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int sum = 0, pos = 1; + for (int i = 2; i <= n; i++) { + if (pos == 1) { + if (a > b) { + pos = 3; + sum += b; + } else { + pos = 2; + sum += a; + } + } else if (pos == 2) { + if (a > c) { + pos = 3; + sum += c; + } else { + pos = 1; + sum += a; + } + } else { + if (b > c) { + sum += c; + pos = 2; + } else { + pos = 1; + sum += b; + } + } + } + cout << sum << endl; +} +int main() { + int n, m, a[1000], b[1000], price; + int clo[105][105] = {0}, x, y; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + b[i - 1] = a[i]; + } + sort(b, b + n); + price = 3 * b[n - 1] + 1; + for (int i = 0; i < m; i++) { + cin >> x >> y; + clo[y][x] = clo[x][y] = 1; + } + int num_p = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (j != i) { + for (int k = 1; k <= n; k++) { + if (k != i && k != j) { + if (clo[i][k] == 1 && clo[i][j] == 1 && clo[j][k] == 1) { + num_p = a[i] + a[k] + a[j]; + if (num_p < price) { price = num_p; } + } + } + } + } + } + } + if (num_p == 0) + cout << "-1" << endl; + else + cout << price << endl; + return 0; +} +int main() { + int y, ny, n, i, j, a, b, c, d; + cin >> y; + for (i = y + 1;; i++) { + a = i % 10; + n = i / 10; + b = n % 10; + n = n / 10; + c = n % 10; + n = n / 10; + d = n % 10; + if ((a != b && a != c && a != d) && (b != c && b != d) && (c != d)) { + ny = i; + break; + } + } + cout << ny << endl; +} +int main() { + int n, k; + cin >> n; + cin >> k; + int a[100], b[100]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + if (k > 1) + cout << "Yes" << endl; + else { + for (int i = 0; i < n; i++) + if (a[i] == 0) a[i] = b[0]; + int flag = 0; + for (int i = 0; i < n - 1; i++) + if (a[i] <= a[i + 1]) flag++; + if (flag == n - 1) + cout << "No" << endl; + else + cout << "Yes" << endl; + } +} +int main() { + int n; + cin >> n; + int a, b, i, cnt = 0, max = 0; + for (i = 0; i < n; i++) { + cin >> a >> b; + cnt = cnt + b - a; + if (cnt > max) max = cnt; + } + cout << max << endl; + return 0; +} +int main() { + int a[151], sum, sum1 = 0; + cin >> sum; + for (int i = 1; i <= 150; i++) { + a[i] = (1 + i) * i / 2; + sum1 += a[i]; + a[i + 1] = (2 + i) * (i + 1) / 2; + if (sum >= sum1 && sum < sum1 + a[i + 1]) { + cout << i << endl; + break; + } + } + return 0; +} +int a[105]; +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans1 = gcd(a[0], a[1]); + int ans2 = gcd(a[n / 2], a[n / 2 + 1]); + for (int i = 2; i < n / 2; i++) { + ans1 = gcd(ans1, a[i]); + if (ans1 == 1) break; + } + for (int i = n / 2 + 2; i < n; i++) { + if (ans1 == 1) break; + ans2 = gcd(ans2, a[i]); + if (ans2 == 1) break; + } + if (ans1 == 1 || ans2 == 1) + cout << n << endl; + else + cout << gcd(ans1, ans2) * n << endl; + return 0; +} +const double PI = 2 * acos(0.0); +const double EPS = 1e-11; +const int SIZE = 2 * 1e5 + 2; +int ar[SIZE]; +int main() { + int tcases, I, J, K, N, n, m, cnt = 0, len; + cin >> n; + for (I = 0; I < n; I++) { + cin >> ar[I]; + while (ar[I] % 2 == 0) ar[I] /= 2; + while (ar[I] % 3 == 0) ar[I] /= 3; + } + for (I = 0; I < n - 1; I++) { + if (ar[I] != ar[I + 1]) { + cout << "No\n"; + return 0; + } + } + cout << "Yes\n"; + return 0; +} +int main() { + int c, a[100001]; + cin >> c; + int b = c - 1; + for (int i = 0; i < c; i++) { cin >> a[i]; } + if (a[b] == 15) { + cout << "DOWN"; + } else if (a[b] == 0) { + cout << "UP"; + } else if (c == 1) { + cout << -1; + } else if (a[b] < a[b - 1]) { + cout << "DOWN"; + } else if (a[b] > a[b - 1]) { + cout << "UP"; + } + cout << endl; +} +int main() { + int s, v1, v2, t1, t2, jia = 0, yi = 0, ti = 0, jiati = 0, yiti = 0; + cin >> s >> v1 >> v2 >> t1 >> t2; + jiati += 2 * t1; + yiti += 2 * t2; + while (jia <= s || yi <= s) { + if (ti % v1 == 0) jia++; + if (ti % v2 == 0) yi++; + if (jia <= s) jiati++; + if (yi <= s) yiti++; + ti++; + } + if (jiati < yiti) + cout << "First" << endl; + else if (jiati == yiti) + cout << "Friendship" << endl; + else + cout << "Second" << endl; + return 0; +} +bool prime(int n) { + for (int i = 2; i * i <= n; ++i) { + if (n % i == 0) { return false; } + } + return true; +} +int main() { + int n, m; + cin >> n >> m; + int b; + b = n + 1; + while (!prime(b)) { b += 1; } + cout << (b == m ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int temp = 1; + int max = 1; + for (int i = 1; i < n; i++) { + if (arr[i] >= arr[i - 1]) { + temp++; + if (temp > max) { max = temp; } + } else { + temp = 1; + } + } + cout << max << endl; + return 0; +} +int main() { + int n = 8, cnt = 0; + while (n--) { + string a; + cin >> a; + if (a == "WBWBWBWB") + cnt++; + else if (a == "BWBWBWBW") + cnt++; + } + if (cnt == 8) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << max(a[2] - a[1] - a[0] + 1, 0) << endl; + return 0; +} +const int N = 110; +int n, m, a[N]; +void Work() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + 1 + n); + int ans = N; + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + if (a[j] - a[i] <= m) { + int num = i - 1 + n - j; + ans = min(ans, num); + } + cout << ans << endl; +} +int main() { + Work(); + return 0; +} +const int maxa = 1000000; +int main() { + int n; + cin >> n; + if (n == 1) + cout << "1" << endl; + else { + cout << int(n / 2) + 1 << endl; + } + return 0; +} +int n, a, b, c; +int main() { + cin >> n; + int w[5]; + for (int i = 1; i <= 3; i++) cin >> w[i]; + int e[5000]; + memset(e, -40, sizeof(e)); + e[0] = 0; + for (int i = 1; i <= 3; i++) { + for (int j = w[i]; j <= n; j++) { e[j] = max(e[j - w[i]] + 1, e[j]); } + } + cout << e[n] << endl; +} +int main() { + int l, b, r; + cin >> l >> b >> r; + int d = 2 * r, plates = 0; + if (min(l, b) < d) + cout << "Second" << endl; + else + cout << "First" << endl; +} +int main() { + int n, m; + int a[10002]; + int b[10002]; + int xx[20002]; + while (cin >> n) { + memset(xx, 0, sizeof(xx)); + for (int i = 0; i < n; i++) { cin >> a[i]; } + cin >> m; + for (int i = 0; i < m; i++) { cin >> b[i]; } + int c = 0; + int d; + int e = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (b[i] % a[j] == 0) { + d = b[i] / a[j]; + xx[d]++; + } + if (d > c) { c = d; } + } + } + cout << xx[c] << endl; + } + return 0; +} +unsigned long long n, m, a, b, c, t; +unsigned long long x[1000006]; +int main() { + cin >> t; + while (t--) { + cin >> n >> m >> a >> b; + b = b - a; + m = m - n; + unsigned long long l = 0, r = 2999999999ll, ans = 2999999999ll; + while (l <= r) { + unsigned long long mid = (l + r) / 2; + if (mid * a >= n && mid * b >= m) { + ans = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + if (ans == 2999999999ll) { + cout << -1 << endl; + } else { + cout << ans * a - n + ans * b - m << endl; + } + } +} +int main() { + int n, temp[24][60] = {0}, maxi = 0, h, m; + cin >> n; + while (n--) { + cin >> h >> m; + temp[h][m]++; + if (temp[h][m] > maxi) maxi = temp[h][m]; + } + cout << maxi << endl; + return 0; +} +int main() { + int Cost, Init, Number = 0, x = 0; + int borrow; + cin >> Cost; + cin >> Init; + cin >> Number; + for (int i = 0; i <= Number; i++) { x = i + x; } + borrow = (x * Cost) - Init; + if (borrow > 0) + cout << borrow << endl; + else + cout << "0" << endl; +} +int main() { + int a, b; + cin >> a >> b; + if (a >= 0 && b >= 0) { + cout << 0 << " " << a + b << " " << a + b << " " << 0 << "\n"; + } else if (a < 0 && b < 0) { + cout << a + b << " " << 0 << " " << 0 << " " << a + b << "\n"; + } else if (a < 0 && b > 0) { + cout << a - b << " " << 0 << " " << 0 << " " << (-1 * a) + b << "\n"; + } else { + cout << 0 << " " << b - a << " " << (-1 * b) + a << " " << 0 << "\n"; + } + return 0; +} +int n, a[110], k, ans; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + for (int i = 1; i <= n; ++i) { + if (a[i] <= k) + ++ans; + else + break; + } + for (int i = n; i >= 1; --i) { + if (a[i] <= k) + ++ans; + else + break; + } + ans = min(n, ans); + cout << ans << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int z = 240 - b; + long long sum = 0; + for (int i = 1; i <= a; i++) { + if (z >= sum + i * 5) { + sum += i * 5; + } else { + cout << i - 1 << endl; + return 0; + } + } + cout << a << endl; + return 0; +} +int min(int n, int m) { + return n > m ? m : n; +} +int main() { + int m, n; + cin >> n >> m; + m = min(n, m); + if (m % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int main() { + long long n, a, b; + cin >> n; + for (long long i = 1; i <= n; i++) { + cin >> a >> b; + int mn = min(a, b); + int mx = max(a, b); + int k = 0; + while (mn > 0 && mx > 0) { + k += mx / mn; + int c = mn; + mn = mx % mn; + mx = c; + } + cout << k << endl; + } + return 0; +} +const int N = 2e5 + 100, PI = 3.14159265359; +map ma, mb; +long long a[N]; +pair p[N]; +vector v, v1; +set s; +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + int x1, y1, x2, y2; + cin >> y1 >> x1 >> y2 >> x2; + int start = x1; + int ans = 0; + if (y1 == y2) { + cout << abs(x1 - x2) << endl; + continue; + } + if (!(x1 <= b && x1 >= a)) { + start = abs(x1 - a) > abs(x1 - b) ? b : a; + ans += abs(start - x1); + } + ans += abs(y1 - y2); + ans += abs(start - x2); + cout << ans << endl; + } +} +int main() { + int n; + cin >> n; + int x, y, x2, y2, ans = 0; + for (int i = 0; i < n; ++i) { + cin >> x >> y >> x2 >> y2; + ans += (x2 - x + 1) * (y2 - y + 1); + } + cout << ans << endl; +} +long long n, k; +int main() { + while (cin >> n >> k) { + long long a = n / (2 + 2 * k); + long long b = a * k; + long long c = n - a - b; + cout << a << " " << b << " " << c << endl; + } + return 0; +} +const double pi = acos(-1.0); +const int maxn = 3e4 + 10; +const int inf = 0x3f3f3f3f; +int main() { + string a[maxn]; + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int len = a[1].length(); + if (n == 1) { + cout << len << endl; + return 0; + } + int i = 0; + for (int j = 0; j < len; j++) { + char c = a[1][j]; + int k; + for (k = 2; k <= n; k++) { + if (a[k][j] != c) break; + } + if (k <= n) { + cout << j << endl; + return 0; + } + if (j == len - 1) { + cout << len << endl; + return 0; + } + } + return 0; +} +int main() { + string s; + cin >> s; + size_t n = s.find('.'); + if (s[n - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + } else { + if (s[n + 1] >= '5') { s[n - 1] += 1; } + s.erase(s.begin() + n, s.end()); + cout << s << endl; + } + return 0; +} +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} +int main() { + int n, a[100000], temp, maxn; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > maxn) maxn = a[i]; + } + temp = gcd(a[1], a[2]); + for (int i = 3; i <= n; i++) temp = gcd(temp, a[i]); + int movetimes = maxn / temp - n; + puts(movetimes & 1 ? "Alice" : "Bob"); + return 0; +} +int main() { + string s; + string dg[10]; + int sol[8]; + cin >> s; + for (int i = 0; i < 10; ++i) cin >> dg[i]; + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 10; ++j) { + bool failed = 0; + for (int k = 0; k < 10; ++k) { + if (dg[j][k] != s[i * 10 + k]) { + failed = 1; + break; + } + } + if (!failed) { + sol[i] = j; + break; + } + } + } + for (int i = 0; i < 8; ++i) cout << sol[i]; + cout << endl; + return 0; +} +int main() { + char c1, c2; + cin >> c1 >> c2; + long long int n; + cin >> n; + long long int z = n % 4; + char arr[4] = {'^', '>', 'v', '<'}; + long long int pos1, pos2; + for (long long int i = 0; i < 4; i++) { + if (c1 == arr[i]) pos1 = i; + if (c2 == arr[i]) pos2 = i; + } + if (pos1 == pos2) + cout << "undefined"; + else if (z == 2) + cout << "undefined"; + else { + long long int x = pos1 - pos2; + if (z == abs(x) && x < 0) + cout << "cw"; + else if (x < 0) + cout << "ccw"; + else if (x > 0 && z == abs(x)) + cout << "ccw"; + else + cout << "cw"; + } + cout << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + int s, t; + for (int i = 0; i < n; i++) { + if (str[i] == 'G') + s = i; + else if (str[i] == 'T') + t = i; + } + if (t > s) { + if ((t - s) % k != 0) { + cout << "NO" << endl; + return 0; + } + for (int i = s; i < t; i += k) { + if (str[i] == '#') { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + } else { + if ((s - t) % k != 0) { + cout << "NO" << endl; + return 0; + } + for (int i = s; i > t; i -= k) { + if (str[i] == '#') { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + } +} +int main() { + int arr[3][1005]; + int n, s; + cin >> n >> s; + for (int i = 0; i < 2; i++) { + for (int j = 1; j <= n; j++) { cin >> arr[i][j]; } + } + int cek; + if (arr[0][1] && (arr[0][s] || arr[1][s])) { + cek = 1; + if (arr[0][s] == 0) { + cek = 0; + for (int i = s + 1; i <= n; i++) { + if (arr[0][i] && arr[1][i]) cek = 1; + } + } + } else + cek = 0; + cout << (cek ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a; + int totalChocolate = 0, days = 0, remain = 0; + bool flag = false; + for (int i = 0; i < n; i++) { + cin >> a; + a += remain; + if (a > 8) { + remain = a - 8; + totalChocolate += 8; + } else { + totalChocolate += a; + remain = 0; + } + days++; + if (totalChocolate >= k) { + flag = true; + break; + } + } + if (flag) { + cout << days << endl; + } else { + cout << "-1" << endl; + } + return 0; +} +int n; +long long p, q, b; +int main() { + cin >> n; + while (n--) { + cin >> p >> q >> b; + if (p % q == 0) { + cout << "Finite\n"; + continue; + } + q /= __gcd(p, q); + long long g; + while (1) { + g = __gcd(q, b); + if (g == 1) break; + while (q % g == 0) q /= g; + } + if (q != 1) + cout << "Infinite\n"; + else + cout << "Finite\n"; + } +} +int x, n, k; +int cal(int x) { + int num = 0; + while (x) { + if (x % 10 == 4 || x % 10 == 7) num++; + x /= 10; + } + return (num <= k); +} +int main() { + while (cin >> n >> k) { + int ans = 0; + for (int i = 0; i < n; i++) cin >> x, ans += cal(x); + cout << ans << endl; + } + return 0; +} +int main() { + long long n, i, j, k, l; + long long a, b, c, d; + cin >> a >> b >> c >> d; + long long l1 = abs(a - c); + long long l2 = abs(b - d); + cout << max(l1, l2) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + while (n % 3 == 0) n /= 3; + cout << n / 3 + 1 << endl; + return 0; +} +int main() { + int n, t, i, a[100100] = {0}; + while (cin >> n) { + for (i = 1; i <= n; i++) { + cin >> t; + a[t] = 1; + } + for (i = 1; i <= n; i++) { + if (a[i] == 0) { + cout << i << endl; + break; + } + } + } + return 0; +} +int main() { + int n; + int m; + int bt; + int bohlam; + list v; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> bt; + while (bt > 0) { + cin >> bohlam; + v.push_back(bohlam); + bt--; + } + } + v.sort(); + v.unique(); + if (v.size() == m) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int arr[100000]; + for (int i = 0; i < m; ++i) { cin >> arr[i]; } + sort(arr, arr + m); + int mindiff = INT_MAX; + for (int i = 0; i < m - (n - 1); i++) { + int diff = arr[i + n - 1] - arr[i]; + if (diff < mindiff) { mindiff = diff; } + } + cout << mindiff << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + puts("1"); + return 0; +} +int inf = (int)2e9; +int main() { + int t; + cin >> t; + while (t--) { + int n, x, y, d; + cin >> n >> x >> y >> d; + int ans = inf; + if (abs(x - y) % d == 0) { ans = (abs(x - y) / d); } + int val1, val2; + val1 = (x - 1) / d; + if ((x - 1) % d != 0) { val1++; } + val1 += (y - 1) / d; + if ((y - 1) % d != 0) { val1 = inf; } + val2 = (n - x) / d; + if ((n - x) % d != 0) { val2++; } + val2 += (n - y) / d; + if ((n - y) % d != 0) { val2 = inf; } + ans = min(ans, min(val1, val2)); + if (ans == inf) { + cout << "-1" << endl; + } else { + cout << ans << endl; + } + } +} +int main() { + int n, x, b, cnt = 0; + priority_queue pq; + cin >> n >> b; + for (int i = 2; i <= n; i++) { + cin >> x; + pq.push(x); + } + x = pq.top(); + while (x >= b) { + x--, cnt++, b++; + pq.pop(); + pq.push(x); + x = pq.top(); + } + cout << cnt << endl; + return 0; +} +int main() { + int a, b, c, d, m, v; + cin >> a >> b >> c >> d; + m = max(3 * a / 10, a - a / 250 * c); + v = max(3 * b / 10, b - b / 250 * d); + if (m > v) + cout << "Misha" << endl; + else if (v > m) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +int main() { + char s[200]; + char p = 'a'; + cin >> s; + int count = 0; + for (int i = 0; s[i] != '\0'; i++) { + int x = abs(s[i] - p); + int y = 26 - x; + if (y > x) + count += x; + else + count += y; + p = s[i]; + } + cout << count << endl; +} +int main() { + int a[3]; + vector d; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + for (int i = a[0]; i <= a[2]; i++) { d.push_back(abs(a[0] - i) + abs(a[1] - i) + abs(a[2] - i)); } + sort(d.begin(), d.end()); + cout << *d.begin() << endl; +} +vector v; +int main() { + long long int n; + cin >> n; + long long int ma; + ma = 0; + long long int g; + cin >> g; + ma = g; + for (int i = 0; i < n - 1; i++) { + long long int t; + cin >> t; + ma = max(t, ma); + g = __gcd(g, t); + } + ma = ma / g; + ma = ma - n; + if (ma % 2 == 0) + cout << "Bob" << endl; + else + cout << "Alice" << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; +} +int main() { + int a; + cin >> a; + a = a - 10; + if (a == 10) { + cout << (4 * 3) + 3 << endl; + } else if (a > 0 && a < 12) { + cout << 4 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + string str; + cin >> str; + int len = str.length(); + int n; + cin >> n; + vector vec; + for (int i = 0; i < n; i++) { + string temp; + cin >> temp; + int pos = temp.find(str); + if (pos == 0) { + string suffix = temp.substr(len); + vec.push_back(suffix); + } + } + if (vec.size() == 0) { + cout << str << endl; + } else { + sort(vec.begin(), vec.end()); + cout << (str + vec[0]) << endl; + } + return 0; +} +int main() { + int arr[3][3], l[3][3] = {0}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + l[i][j] += arr[i][j]; + if ((i - 1) != -1) { l[i - 1][j] += arr[i][j]; } + if ((j - 1) != -1) { l[i][j - 1] += arr[i][j]; } + if ((i + 1) != 3) { l[i + 1][j] += arr[i][j]; } + if ((j + 1) != 3) { l[i][j + 1] += arr[i][j]; } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (l[i][j] % 2 == 0) { + l[i][j] = 1; + } else { + l[i][j] = 0; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << l[i][j]; } + cout << '\n'; + } +} +int main() { + cout << "Karen" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int sum = accumulate(a.begin(), a.end(), 0); + int m; + cin >> m; + while (m--) { + int l, r; + cin >> l >> r; + if (l <= sum && sum <= r) { + cout << sum << endl; + return 0; + } else if (l > sum && r > sum) { + cout << l << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +const int maxn = 5e2 + 10; +inline int read() { + int ra, fh; + char rx; + rx = getchar(), ra = 0, fh = 1; + while ((rx < '0' || rx > '9') && rx != '-') rx = getchar(); + if (rx == '-') fh = -1, rx = getchar(); + while (rx >= '0' && rx <= '9') ra *= 10, ra += rx - 48, rx = getchar(); + return ra * fh; +} +long long gcd(long long p, long long q) { + return q == 0 ? p : gcd(q, p % q); +} +long long qpow(long long p, long long q) { + long long f = 1; + while (q) { + if (q & 1) f = f * p; + p = p * p; + q >>= 1; + } + return f; +} +string s; +int ct1, ct2; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') + ct1++; + else + ct2++; + } + if (ct1 > ct2) { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') s[i] -= 32; + } + } else { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; + } + } + cout << s << endl; + return 0; +} +long long int n, k, x; +int main() { + cin >> n >> k; + x = n / (2 * (k + 1)); + cout << x << ' ' << k * x << ' ' << n - (k + 1) * x << '\n'; +} +int main() { + long long z, x, c, v, b; + cin >> z >> x >> c >> v >> b; + bool cek = false; + for (long long q = c; q <= v; q++) { + long long asd = q * b; + if (asd >= z && asd <= x) cek = true; + } + if (cek == true) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long int n; + cin >> n; + cout << "25" << endl; + return 0; +} +const int maxn = 1e3 + 5; +int a[maxn] = {0}; +int main() { + int n, m; + cin >> n >> m; + int j; + for (int i = 0; i < m; i++) { + cin >> j; + a[j]++; + } + int minn = a[1]; + for (int i = 1; i <= n; i++) minn = min(minn, a[i]); + cout << minn << endl; + return 0; +} +int main() { + bool b = false; + int n; + cin >> n; + while (n--) { + int x; + cin >> x; + if (x == 1) b = true; + } + cout << (b ? -1 : 1) << endl; +} +int n, t, x, cnt; +int main() { + cin >> n >> t; + while (n--) { + cin >> x; + x = 86400 - x; + t -= x; + cnt++; + if (t <= 0) { + cout << cnt << endl; + break; + } + } + return 0; +} +int main() { + long a; + cin >> a; + if (a == 0) { + cout << "8\n"; + return 0; + } + a++; + long ans = 1; + long l; + if (a >= 0) { + while (true) { + long temp = a; + while (temp > 0) { + l = temp % 10; + if (l == 8) { + cout << ans << endl; + return 0; + } + temp = temp / 10; + } + a++; + ans++; + } + } else if (a < 0) { + if (a > -8) { + a--; + ans = 8 - a; + cout << ans << endl; + return 0; + } + a = a * -1; + while (true) { + long temp = a; + while (temp != 0) { + l = temp % 10; + if (l == 8) { + cout << ans << endl; + return 0; + } + temp = temp / 10; + } + a--; + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int num, cnt = 0; + cin >> num; + int ara[num + 5]; + for (int i = 0; i < num; i++) { cin >> ara[i]; } + sort(ara, ara + num); + if (ara[0]) cnt++; + for (int i = 1; i < num; i++) { + if (ara[i] != ara[i - 1] && ara[i] != 0) cnt++; + } + cout << cnt << endl; +} +const int N = 1e5 + 5; +const int inf = 1e9; +const long long INF = 1e18; +const double PI = acos(-1.0); +const double EPS = 1e-8; +const int MOD[] = {1000000009, 1000000007}; +const int base[] = {37, 43}; +long long int p[55][2]; +int main() { + string s; + cin >> s; + p[0][0] = 1, p[0][1] = 1; + for (int i = 1; i <= 50; i++) { + p[i][0] = (p[i - 1][0] * base[0]) % MOD[0], p[i][0] %= MOD[0]; + p[i][1] = (p[i - 1][1] * base[1]) % MOD[1], p[i][1] %= MOD[1]; + } + int len = s.size(); + set Hash; + long long int hash1 = 0, hash2 = 0; + for (int i = 0; i < len; i++) { + hash1 += (p[i][0] * s[i]) % MOD[0], hash1 %= MOD[0]; + hash2 += (p[i][1] * s[i]) % MOD[1], hash2 %= MOD[1]; + } + for (int i = 1, j = len - 1; i <= len; i++, j--) { + Hash.insert((hash1 << 31) | hash2); + char last = s[j]; + hash1 -= (p[len - 1][0] % MOD[0] * last % MOD[0]) % MOD[0]; + if (hash1 < 0) hash1 += MOD[0]; + hash1 *= p[1][0], hash1 %= MOD[0]; + hash1 += (p[0][0] * last) % MOD[0], hash1 %= MOD[0]; + hash2 -= (p[len - 1][1] % MOD[1] * last % MOD[1]) % MOD[1]; + hash2 *= p[1][1], hash2 %= MOD[1]; + if (hash2 < 0) hash2 += MOD[1]; + hash2 += (p[0][1] * last) % MOD[1], hash2 %= MOD[1]; + } + cout << (int)Hash.size() << "\n"; + return 0; +} +int main() { + int n, p[100100], s[100100], i; + cin >> n; + for (i = 2; i <= n; i++) cin >> p[i]; + for (i = 1; i <= n; i++) cin >> s[i]; + for (i = 2; i <= n; i++) { + if (s[i] == -1) continue; + if (s[p[i]] == -1) + s[p[i]] = s[i]; + else + s[p[i]] = min(s[p[i]], s[i]); + } + for (i = 2; i <= n; i++) { + if (s[i] == -1) continue; + if (s[p[i]] > s[i]) { + cout << -1 << endl; + return 0; + } + } + long long ans = s[1]; + for (i = 2; i <= n; i++) { + if (s[i] == -1) continue; + ans += (s[i] - s[p[i]]); + } + cout << ans << endl; + return 0; +} +int main() { + int i, j, c; + string t, s; + cin >> s >> t; + i = j = 0; + c = 1; + while (t[i] != '\0') { + if (s[j] == t[i]) { + j++; + c++; + } + i++; + } + cout << c << endl; + return 0; +} +int main() { + int a = 0, b = 0; + int counter_moda = 0, counter_utility = 0; + cin >> a >> b; + while (a > 0 && b > 0) { + a--; + b--; + counter_moda++; + } + while (a >= 2 || b >= 2) { + counter_utility++; + if (a > b) { + a -= 2; + } else { + b -= 2; + } + } + cout << counter_moda << " " << counter_utility << endl; + return 0; +} +int main() { + long int n; + long long jumlah = 0; + cin >> n; + for (int i = 0; i < n; i++) { + string S; + cin >> S; + if (S == "Tetrahedron") { + jumlah = jumlah + 4; + } else if (S == "Octahedron") { + jumlah = jumlah + 8; + } else if (S == "Cube") { + jumlah = jumlah + 6; + } else if (S == "Dodecahedron") { + jumlah = jumlah + 12; + } else if (S == "Icosahedron") { + jumlah = jumlah + 20; + } + } + cout << jumlah << endl; +} +int to[5][5]; +inline int read() { + int x = 0; + char e = getchar(); + for (; e < '0' || e > '9'; e = getchar()) + ; + for (; e >= '0' && e <= '9'; e = getchar()) x = (x << 1) + (x << 3) + (e ^ 48); + return x; +} +int main() { + int n = read(); + int x = 1, y = 2; + to[1][2] = to[2][1] = 3; + to[1][3] = to[3][1] = 2; + to[2][3] = to[3][2] = 1; + for (int i = 1; i <= n; i++) { + int wn = read(); + if (x == wn) + y = to[x][y]; + else if (y == wn) + x = to[x][y]; + else { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int tmp, min1, max1, sum_n, index_max, index_min; +int arr1[1000][1000]; +char arr3[100]; +int arr[10000]; +void display_vector(vector v) { + for (int i = 0; i < v.size(); i++) cout << v[i] << " "; + cout << endl; +} +void speed() {} +void min_max(vector v, int l) { + min1 = INT_MAX; + max1 = INT_MIN; + for (int i = l; i < v.size(); i++) { + if (v[i] <= min1) { + min1 = v[i]; + index_min = i; + } + if (v[i] >= max1) { + max1 = v[i]; + index_max = i; + } + } +} +int sum_v(vector v) { + for (int i = 0; i < v.size(); i++) sum_n += v[i]; + return sum_n; +} +bool is_it_sorted_acs(vector v) { + bool test1 = false; + for (int i = 0; i < v.size() - 1; i++) + if (v[i + 1] <= v[i]) { + test1 = false; + return test1; + } + test1 = true; + return test1; +} +bool is_it_sorted_des(vector v) { + bool test1 = false; + for (int i = 0; i < v.size() - 1; i++) + if (v[i + 1] >= v[i]) { + test1 = false; + return test1; + } + test1 = true; + return test1; +} +int main() { + speed(); + long long l, r; + cin >> l >> r; + if (l % 2 != 0) l++; + if (r - l < 2) return cout << -1 << endl, 0; + cout << l << " " << l + 1 << " " << l + 2 << endl; +} +int main() { + int n, k, a[105], left, right, i, flag = 1; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] > k) { + left = i; + break; + } + } + for (i = n - 1; i >= 0; i--) { + if (a[i] > k) { + right = i; + break; + } + } + for (i = 0; i < n; i++) { + if (a[i] > k) { + flag = 0; + break; + } + } + if (flag) + cout << n << endl; + else + cout << n - (right - left + 1) << endl; + return 0; +} +int main() { + char a[2]; + char b[1000]; + gets(a); + gets(b); + int i, j = 1, c = 1; + int n = strlen(b); + for (i = 0; i < n; i = i + 3) + if (a[0] == b[i]) { + cout << "YES" << endl; + j = 0; + break; + } + if (j) + for (i = 1; i < n; i = i + 3) + if (a[1] == b[i]) { + cout << "YES" << endl; + c = 0; + break; + } + if (j && c) cout << "NO" << endl; +} +int main() { + char a[300][300], b[9000]; + int i, j, m, n, k = 0, pos = 0, c = 0, p; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) cin >> a[i][j]; + } + for (j = 0; j < m; j++) { + int maxi = a[0][j]; + for (i = 0; i < n; i++) { + if (a[i][j] >= maxi) { maxi = a[i][j]; } + } + b[k] = maxi; + k++; + } + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (a[i][j] == b[j]) { + p = i; + c++; + break; + } + } + } + cout << c << endl; +} +int main() { + int n, t; + cin >> n >> t; + long long max = -1000000000; + int joy, time; + for (int i = 0; i < n; i++) { + cin >> joy >> time; + if ((time > t ? joy - (time - t) : joy) > max) max = time > t ? joy - (time - t) : joy; + } + cout << max << endl; + return 0; +} +int a[15][15]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { a[i][1] = a[1][i] = 1; } + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n][n] << endl; + return 0; +} +vector n[100004]; +int main() { + long long int a, b, c, d, e, f, g, h, i, r[2000], p, q; + float j, k, l; + string s, t; + while (cin >> s) { + vector v; + if (s[0] == '-') { + if (s.size() == 2) { + cout << "0" << endl; + continue; + } + a = s.size() - 1; + b = a - 1; + if (s[a] >= s[b]) { + d = a; + } else { + d = b; + } + for (e = 1; e < s.size(); e++) { + if (e == d) { + continue; + } else { + char u; + u = s[e]; + v.push_back(u); + } + } + if (v[0] != '0') { cout << "-"; } + for (f = 0; f < v.size(); f++) { cout << v[f]; } + cout << endl; + } else { + cout << s << endl; + } + v.clear(); + } + return 0; +} +int main() { + int n, i; + cin >> n; + int a[n]; + for (i = 1; i <= n; i++) cin >> a[i]; + for (i = 1; i <= n; i++) + if (a[i] == a[a[a[a[i]]]]) { + cout << "YES" + << "\n"; + return 0; + } + cout << "NO" + << "\n"; + return 0; +} +int main() { + int n, c1 = 1, c2 = 1; + cin >> n; + int t = n / 10, u = n % 10; + if (t == 0) + c1++; + else if (t == 1) + c1 += 6; + else if (t == 2) + c1++; + else if (t == 3) + c1 += 2; + else if (t == 4) + c1 += 2; + else if (t == 5) + c1 += 3; + else if (t == 6) + c1++; + else if (t == 7) + c1 += 4; + else if (t == 9) + c1++; + if (u == 0) + c2++; + else if (u == 1) + c2 += 6; + else if (u == 2) + c2++; + else if (u == 3) + c2 += 2; + else if (u == 4) + c2 += 2; + else if (u == 5) + c2 += 3; + else if (u == 6) + c2++; + else if (u == 7) + c2 += 4; + else if (u == 9) + c2++; + cout << c1 * c2 << '\n'; + return 0; +} +int main() { + int n, m, temp = 0, sum = 0; + cin >> n >> m; + while (n > 0) { + n--; + temp++; + sum++; + if (temp == m) { + n++; + temp = 0; + } + } + cout << sum << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b; + if (a > b) { + c = a; + a = b; + b = c; + } + c = 1; + while (a) { + c *= a; + a--; + } + cout << c << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (n == 1) { + cout << 0 << endl; + return 0; + } + int sum = 0, cnt = 1; + int minn = min(a, min(b, c)); + int maxx = max(a, max(b, c)); + int sr = a + b + c - minn - maxx; + if (a <= b) { + sum += a; + cnt++; + if (a == minn) { + sum = sum + (n - cnt) * minn; + cout << sum << endl; + return 0; + } + if (a > c) { + sum += c; + cnt++; + sum = sum + (n - cnt) * minn; + cout << sum << endl; + return 0; + } + } + if (a > b) { + sum += b; + cnt++; + if (b == minn) { + sum = sum + (n - cnt) * minn; + cout << sum << endl; + return 0; + } + if (b > c) { + sum += c; + cnt++; + sum = sum + (n - cnt) * minn; + cout << sum << endl; + return 0; + } + } +} +int main() { + string s; + cin >> s; + int n = s.length(), q = 0, ans = 0, q1 = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'Q') { q++; } + } + for (int i = 0; i < n; i++) { + if (s[i] == 'Q') { + q1++; + } else if (s[i] == 'A') { + ans += q1 * (q - q1); + } + } + cout << ans << endl; +} +int main() { + int n; + vector name, spec; + cin >> n; + name.assign(n, "0"); + spec.assign(n, "0"); + for (int i = 0; i < n; i++) { cin >> name[i] >> spec[i]; } + for (int i = 0; i < n; i++) { + if (spec[i] == "rat") { cout << name[i] << "\n"; } + } + for (int i = 0; i < n; i++) { + if (spec[i] == "woman" || spec[i] == "child") { cout << name[i] << "\n"; } + } + for (int i = 0; i < n; i++) { + if (spec[i] == "man") { cout << name[i] << "\n"; } + } + for (int i = 0; i < n; i++) { + if (spec[i] == "captain") { cout << name[i] << "\n"; } + } + return 0; +} +char x[1050], y[1050]; +int a[1050]; +int main() { + int n, p1, s; + cin >> n >> p1 >> x; + char p = 'a' + p1 - 1; + for (int i = 0, j = 3; i <= n; i++, j = (j == 1 ? 3 : j - 1)) y[i] = 'a' + p1 + j - 4; + y[n] = '\0'; + if (strcmp(x, y) == 0) { + cout << "NO" << endl; + return 0; + } + for (int i = n - 1; i >= 0; i--) { + s = 0; + for (int j = x[i] + 1; j <= p; j++) + if (j != x[i - 1] && j != x[i - 2]) { + s = 1; + x[i] = j; + break; + } + if (s == 1) { + s = i; + break; + } + } + for (int i = s + 1; i < n; i++) + for (int j = 'a'; j <= p; j++) + if (j != x[i - 1] && j != x[i - 2]) { + x[i] = j; + break; + } + cout << x << endl; + return 0; +} +int main() { + int t; + cin >> t; + int s = 0; + int arr[5] = {1, 5, 10, 20, 100}; + for (int i = 4; i >= 0; --i) { + int temp = t / arr[i]; + t -= temp * arr[i]; + s += temp; + } + cout << s << "\n"; +} +int main() { + int sum; + cin >> sum; + for (int numFour = 0; numFour <= sum / 4; numFour++) { + int rem = sum - 4 * numFour; + if (rem % 7 == 0) { + for (int i = 0; i < numFour; i++) { cout << "4"; } + for (int i = 0; i < rem / 7; i++) { cout << "7"; } + cout << "\n"; + return 0; + } + } + cout << "-1\n"; +} +long long power(long long x, int y, int m) { + long long res = 1; + while (y > 0) { + if (y & 1) { + res = res * x; + res %= m; + } + y = y >> 1; + x = x * x; + x %= m; + } + return res; +} +int main() { + int n, m; + cin >> n >> m; + int ans = power((long long)3, n, m); + if (ans == 0) { + cout << m - 1 << endl; + } else { + cout << ans - 1 << endl; + } + return 0; +} +int n, x; +map mark; +int ans; +int maxn = 0; +int main() { + while (cin >> n) { + ans = 0; + for (int i = 1; i <= 2 * n; i++) { + cin >> x; + mark[x]++; + if (mark[x] == 0) { + ans++; + } else if (mark[x] == 1) { + ans++; + } else if (mark[x] == 2) { + ans--; + } + if (maxn < ans) maxn = ans; + } + cout << maxn << endl; + } + return 0; +} +const int maxn = 1e5 + 10; +int nn[maxn]; +int main() { + int n, m; + cin >> n >> m; + int flag = 1; + for (int i = 1; i <= n; i++) { + if (i & 1) { + for (int i = 0; i < m; i++) { cout << "#"; } + cout << endl; + } else { + if (flag == 1) { + for (int i = 0; i < m - 1; i++) { cout << "."; } + cout << "#" << endl; + flag = 0; + } else { + cout << "#"; + for (int i = 0; i < m - 1; i++) { cout << '.'; } + cout << endl; + flag = 1; + } + } + } + return 0; +} +int main() { + int n, m, x = 1; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << '#'; + } else if (i % 4 != 0) { + if (j == m) + cout << '#'; + else + cout << '.'; + } else if (i % 4 == 0) { + if (j == 1) + cout << '#'; + else + cout << '.'; + } + } + x = -x; + cout << endl; + } +} +int main() { + long long int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + long long int i, j; + long long int a = t1, b = t2; + for (i = 1; i <= s; i++) { + a += v1; + b += v2; + } + a += t1; + b += t2; + if (a < b) { + cout << "First" << '\n'; + } else if (b < a) { + cout << "Second" << '\n'; + } else { + cout << "Friendship" << '\n'; + } + return 0; +} +const int maxn = 110; +const int inf = 0x3f3f3f3f; +char s[maxn]; +int main() { + string s; + cin >> s; + int cnt1 = 0, cnt2 = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'o') + cnt1++; + else + cnt2++; + } + if (cnt1 == 0) { + cout << "YES" << endl; + } else { + if (cnt2 % cnt1 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + long long int a, b, c, d, r[100004], e, f, g, h; + while (cin >> a >> b >> c >> d) { + e = ((double)(3 * a)) / 10.; + f = a - (((double)a / 250.) * c); + g = max(e, f); + e = ((double)(3 * b)) / 10.; + f = b - (((double)b / 250.) * d); + h = max(e, f); + if (g > h) { + cout << "Misha" << endl; + } else if (g < h) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } + } + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) ans += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); + cout << ans << endl; + return 0; +} +int main() { + int flag = 0; + for (int i = 0; i < 8; i++) { + char s[8]; + for (int j = 0; j < 8; j++) { + cin >> s[j]; + if (j > 0) { + if (s[j - 1] == s[j]) { flag = 1; } + } + } + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, m, v[101], rel[101][101], x, y, cnt, ans = -1; +vector a[1000001]; +void find_ans(int l, int r, int cnt, int cur_ans) { + if (cnt > 3) { + if (rel[l][r] == 1 && (cur_ans < ans || ans == -1)) { ans = cur_ans; } + return; + } else { + for (int i = 0; i < a[r].size(); i++) { find_ans(l, a[r][i], cnt + 1, cur_ans + v[a[r][i]]); } + } +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> v[i]; + for (int i = 1; i <= m; i++) { + cin >> x >> y; + if (rel[x][y] == 0) { + rel[x][y] = rel[y][x] = 1; + a[min(x, y)].push_back(max(x, y)); + } + } + for (int i = 1; i <= n; i++) find_ans(i, i, 2, v[i]); + cout << ans << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int k = m * n / 2; + cout << k << endl; +} +int main() { + char s[100]; + cin >> s; + int i, j, count = 0, flag = -1; + for (i = 0; s[i] != '\0'; i++) { + count = count + 1; + for (j = 0; j < i; j++) { + if (s[i] == s[j]) { + count--; + break; + } + } + } + if (count % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; +} +int n; +int a[200005]; +int ans = 1000000005; +int main() { + cin >> n; + for (int i = (1); i <= (n); i++) cin >> a[i]; + sort(a + 1, a + 1 + n); + for (int i = (1); i <= (n / 2); i++) { ans = min(ans, a[n / 2 + i] - a[i]); } + cout << ans << endl; + return 0; +} +int main() { + string cardOnTable; + cin >> cardOnTable; + string myCards[5]; + for (int i = 0; i < 5; i++) { cin >> myCards[i]; } + bool win = false; + int i = 0; + while ((!win) && (i < 5)) { + if ((cardOnTable[0] == myCards[i][0]) || (cardOnTable[1] == myCards[i++][1])) { win = true; } + } + cout << (win ? "YES" : "NO") << endl; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + int c0 = 0; + for (int i = 0; i < n; i++) + if (s[i] == '0') c0++; + int l = s.length(); + cout << abs((l - c0) - c0) << endl; + return 0; +} +bool vis[200005]; +int cnt[200005], freq[200005]; +int main() { + int n, a, b; + cin >> n >> a >> b; + string s; + cin >> s; + if (s[a - 1] == s[b - 1]) + puts("0"); + else + puts("1"); + return 0; +} +int n, b, p, x = 0, y; +int main() { + cin >> n >> b >> p; + b = 2 * b + 1; + y = n * p; + while (n > 1) { + int k = 1; + while (2 * k <= n) k *= 2; + x += b * k / 2; + n -= k / 2; + } + cout << x << " " << y << '\n'; + return 0; +} +int mod(int a) { + if (a >= 0) + return a; + else + return -a; +} +int main() { + int tmp; + int a, b; + const int n = 5; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> tmp; + if (tmp == 1) { + a = i + 1; + b = j + 1; + break; + } + } + } + cout << mod(3 - b) + mod(3 - a) << endl; +} +string s; +long long n, a = 1, b = 1; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "UL" || s == "DR" || s == "ULDR") a++; + if (s == "UR" || s == "DL" || s == "ULDR") b++; + } + cout << a * b << endl; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +const int MAXN = 1e5 + 5; +const long long INF = 1e8; +long long N; +vector V; +int main() { + cin >> N; + long long l = INF; + for (int i = (0); i < int(N); i++) { + string S; + cin >> S; + V.push_back(S); + l = min(l, (long long)S.size()); + } + long long ans = 0; + for (int i = (0); i < int(l); i++) { + bool rip = false; + for (int j = (1); j < int(V.size()); j++) { + if (V[j][i] != V[j - 1][i]) { + rip = true; + break; + } + } + if (rip) break; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + map index; + index['p'] = 0; + index['g'] = 1; + index['b'] = 2; + index['o'] = 3; + index['r'] = 4; + index['y'] = 5; + string names[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + int x; + cin >> x; + int need = 6; + string color; + for (; x > 0; x--) { + cin >> color; + need--; + names[index[color[0]]] = " "; + } + cout << need << '\n'; + for (int x = 0; x < 6; x++) { + if (names[x][0] != ' ') cout << names[x] << '\n'; + } +} +int main() { + int n; + int a, b, c; + cin >> n; + cin >> a >> b >> c; + int sum = 0; + if (n == 1) { + sum = 0; + } else if (min(min(a, b), c) != c) { + sum = min(min(a, b), c) * (n - 1); + } else { + sum = min(a, b) + c * (n - 2); + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int count = 0; + int k[n]; + for (int i = 0; i < n; i++) { cin >> k[i]; } + int mini, maxi; + for (int i = 0; i < n; i++) { + if (i == 0) { + mini = k[i]; + maxi = k[i]; + } + if (k[i] < mini) { + count++; + mini = k[i]; + } + if (k[i] > maxi) { + count++; + maxi = k[i]; + } + } + cout << count << endl; + return 0; +} +int n, k, ans, a[101]; +int check(int x, int xk) { + int ret = 0; + while (x) { + if (x % 10 == 4 || x % 10 == 7) ret++; + x /= 10; + } + if (ret <= xk) { return 1; } + return 0; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a[i]; + ans += check(a[i], k); + } + cout << ans << endl; +} +int main() { + long long n, d; + cin >> n >> d; + long long c = 0, ans = 0; + string a; + for (long long i = 0; i < d; i++) { + cin >> a; + long long flag = 0; + for (long long i = 0; i < n; i++) { + if (a[i] == '0') flag = 1; + } + if (flag == 1) { + c++; + ans = max(c, ans); + } else { + c = 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + int mx = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mx = max(mx, a[i]); + } + int ans = 1e9; + for (int k = mx; k <= 1e5; k++) { + int x, y; + x = y = 0; + for (int i = 0; i < n; i++) { + x += a[i]; + y += k - a[i]; + } + if (y > x) { + cout << k << '\n'; + return 0; + } + } + return 0; +} +int main() { + int n; + cin >> n; + vector a(n, false); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[x - 1] = true; + } + for (int i = 0; i < n; i++) { + if (!a[i]) { + cout << i + 1 << endl; + return 0; + } + } + return 0; +} +int main() { + int n, a; + cin >> n; + priority_queue t; + for (int i = 0; i < n; i++) { + cin >> a; + int l = sqrt(a); + if ((l * l) != a) { t.push(a); } + } + cout << t.top() << endl; +} +const int N = 2e5 + 100; +string s[N]; +int b[6][6], a[6][6]; +map ma; +int main() { + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + cin >> a[i][j]; + a[i][j] = a[i][j] % 2; + } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + if (a[i][j] == 1) { + b[i][j] = 1 - b[i][j]; + b[i][j - 1] = 1 - b[i][j - 1]; + b[i - 1][j] = 1 - b[i - 1][j]; + b[i + 1][j] = 1 - b[i + 1][j]; + b[i][j + 1] = 1 - b[i][j + 1]; + } + } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { cout << 1 - b[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, a[1000], b, sum = 0; + cin >> n; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= n; i++) { + cin >> b; + a[b]++; + } + for (int i = 1; i <= 600; i++) { + if (a[i] > 0) sum++; + } + cout << sum << endl; +} +int main() { + int n, p, q, sum = 0; + cin >> n; + while (n--) { + cin >> p >> q; + if (p + 2 <= q) sum++; + } + cout << sum << endl; +} +int main() { + int n; + while (cin >> n) { + int a[105]; + for (int i = 1; i <= n; i++) cin >> a[i]; + int Min = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + int ans = 0; + for (int j = 1; j <= n; j++) { + if (j > i) + ans += (j - 1) * 4 * a[j]; + else + ans += (i - 1) * 4 * a[j]; + } + Min = min(Min, ans); + } + cout << Min << endl; + } + return 0; +} +int main() { + int a, b, c, d, w, x, y, z, misha, vasya; + cin >> a >> b >> c >> d; + misha = max(3 * a / 10, a - a * c / 250); + vasya = max(3 * b / 10, b - b * d / 250); + if (misha > vasya) + cout << "Misha" << endl; + else if (misha < vasya) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; +} +int main() { + int x, y = 0, comp1 = 0, comp2 = 0, z = 0; + string num1, num2, num; + cin >> x >> num1 >> num2; + int a[x]; + int b[x]; + for (int i = 0; i < x; i++) { + num = num1[i]; + a[i] = atoi(num.c_str()); + } + for (int i = 0; i < x; i++) { + num = num2[i]; + b[i] = atoi(num.c_str()); + } + for (int i = 0; i < x; i++) { + comp1 = abs(a[i] - b[i]); + comp2 = 0; + z = a[i]; + while (true) { + if (z == 10) { + z = 0; + } else if (z == -1) { + z = 9; + } + if (z == b[i]) { + break; + } else { + if (a[i] > b[i]) { + z = z + 1; + } else { + z = z - 1; + } + comp2 = comp2 + 1; + } + } + if (comp2 < comp1) { + y = y + comp2; + } else { + y = y + comp1; + } + } + cout << y << endl; + return 0; +} +int main() { + int N, sum = 0; + cin >> N; + int *H = new int[100]; + int *A = new int[100]; + for (int i = 0; i < N; i++) { + cin >> H[i]; + cin >> A[i]; + } + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (H[i] == A[j]) sum++; + } + } + cout << sum << endl; + return 0; +} +int main() { + string a; + cin >> a; + int num = 0; + string b = "aeiou13579"; + for (int i = 0; i < a.size(); i++) { + for (int j = 0; j < b.size(); j++) { + if (a[i] == b[j]) num++; + } + } + cout << num << endl; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + for (int i = 1; i < n - 1; i++) { + if ((a[i] - a[i - 1]) * (a[i] - a[i + 1]) > 0) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n % 2 << '\n'; + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + for (int i = 0; i < k; i++) { + int cnt = n % 10; + if (cnt != 0) + n--; + else + n /= 10; + } + cout << n << endl; + } + return 0; +} +set st; +int main() { + int n; + cin >> n; + char a[1005]; + int ans = 0; + for (int i = 1; i <= n; i++) { + cin >> a; + sort(a, a + strlen(a)); + int len = int(unique(a, a + strlen(a)) - a); + a[len] = '\0'; + st.insert(a); + } + cout << st.size() << endl; +} +int main() { + int n; + map mp; + cin >> n; + mp["Tetrahedron"] = 4; + mp["Cube"] = 6; + mp["Octahedron"] = 8; + mp["Dodecahedron"] = 12; + mp["Icosahedron"] = 20; + int x = 0; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + x += mp[s]; + } + cout << x << endl; + return 0; +} +const long long E = 1e9; +long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, x, y, z; +string t, u, v, w; +bool A, B, C; +int main() { + cin >> x; + for (int q = 0; q < x; q++) { + cin >> s >> a >> b >> c; + r = 0; + e = s / c; + r += e; + r += e / a * b; + cout << r << '\n'; + } +} +int main() { + unsigned n; + cin >> n; + vector vect(n); + long sum = 0; + for (int i = 0; i < n; i++) { + cin >> vect[i]; + sum += vect[i]; + } + sort(vect.begin(), vect.begin() + n); + long avg = sum / n; + cout << avg << endl; + return 0; +} +const int M = 1000 + 5; +int a[M]; +int main() { + int n; + cin >> n; + a[0] = 1; + a[1] = 1; + for (int i = 2; i <= n; i++) { a[i] = (3 * a[i - 1]) % (1000000 + 3); } + cout << a[n] << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n < 11) { + cout << 0 << endl; + } else if (n == 11 || n == 21) { + cout << 4 << endl; + } else if (n >= 12 && n <= 19) { + cout << 4 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else + cout << 0 << endl; +} +int main() { + long long n; + while (cin >> n) { + long long x = n * sqrt(double(2)); + if (n == 0) { + cout << 1 << endl; + } else { + cout << x * 4 << endl; + } + } + return 0; +} +int main() { + long long i, left, right; + while (cin >> left >> right) { + long long num = 1, shuwei = 0; + while (num * 10 <= right) num = num * 10; + long long Num = num; + num = min(5 * Num, right); + if (5 * Num <= left) num = max(5 * Num, left); + long long shu[10]; + Num = num; + while (Num != 0) { + shu[++shuwei] = 9 - Num % 10; + Num = Num / 10; + } + long long sum = 0; + for (i = shuwei; i >= 1; i--) sum = sum * 10 + shu[i]; + cout << (long long)sum * (long long)num << endl; + } + return 0; +} +long long power2(long long pow, long long mod) { + long long res = 1ll, x = 2ll; + while (pow > 0) { + if (pow & 1) res = (res * x) % mod; + pow >>= 1; + x = (x * x) % mod; + } + return res; +} +int main() { + long long n; + cin >> n; + if (n) { + long long M = 1 * 1000 * 1000 * 1000 + 7; + long long sol; + sol = power2(2 * n - 1, M); + sol += power2(n - 1, M); + sol %= M; + cout << sol << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 != 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int y = 0, j, x = 0; + int n; + string s; + cin >> n; + cin >> s; + for (j = 0; j < n; j++) { + if (s[j] == '0') { + x++; + } else if (s[j] == '1') { + y++; + } + } + int num = x - y; + cout << abs(num) << endl; + return 0; +} +int main() { + int n, k; + char a[100]; + while (cin >> n >> k) { + int i, j; + int sum = 0; + for (i = 0; i < n; i++) { + cin >> a; + int pl = 0; + int sum1 = 0; + char q = '0'; + int x = strlen(a); + sort(a, a + x); + for (j = 0; j < x; j++) { + if (a[j] == q) { + q++; + sum1++; + if (sum1 == k + 1) { pl = 1; } + } + } + if (pl == 1) { sum++; } + } + cout << sum << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int n; + cin >> n; + vector vs; + for (int i = 0; i < n; i++) { + string ss; + cin >> ss; + vs.push_back(ss); + } + sort(vs.begin(), vs.end()); + int len = s.size(); + for (int i = 0; i < n; i++) + if (vs[i].substr(0, len) == s) { + cout << vs[i] << endl; + return 0; + } + cout << s << endl; + return 0; +} +int gcd(int x, int y) { + if (x < y) { return gcd(y, x); } + if (y == 0) { return x; } + return gcd(y, x % y); +} +int main() { + int n, g, x; + cin >> n; + cin >> g; + for (int i = 1; i < n; ++i) { + cin >> x; + g = gcd(g, x); + } + cout << g * n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x, y, z, w; + for (int i = 0; i < n; i++) { + long long ans; + cin >> x >> y >> z >> w; + if (z % y == 0) z--; + ans = x / y + z / y - w / y; + if (y == z == w) ans--; + cout << ans << endl; + } + return 0; +} +int main() { + int w; + cin >> w; + if (w < 4) + cout << "NO" << endl; + else if (w % 2) + cout << "NO" << endl; + else { + cout << "YES" << endl; + } + return 0; +} +const long long OO = 1e8; +const int o_o = 0; +double EPS = numeric_limits::epsilon(); +int const MAX = 2 * 100000 + 9; +char ar[MAX]; +int co = -1; +void inzlition() { + for (int i = 0; i < MAX; i++) { ar[i] = '0'; } +} +int main() { + string text; + getline(cin, text); + inzlition(); + co = -1; + for (int i = 0; i < text.size(); i++) { + if (co == -1) { + co++; + ar[co] = text[i]; + } else if (text[i] == ar[co]) { + ar[co] = '0'; + co--; + } else { + co++; + ar[co] = text[i]; + } + } + for (int j = 0; j <= co; j++) { cout << ar[j]; } + cout << endl; + return 0; +} +const long long N = 1e9 + 3; +const long long MN = 1e9; +string s; +int main() { + cin >> s; + sort(s.begin(), s.end()); + for (long long i = s.size() - 1; i >= 0; i--) { + if (s[i] != s[i - 1]) { + cout << s[i]; + break; + } + cout << s[i]; + } + cout << "\n"; + return 0; +} +int main() { + string aa; + cin >> aa; + int ans = 0; + int n = aa.size(); + for (int a = 0; a < n; a++) { + int l = 0, num = 0; + for (int b = a; b < n; b++) { + if (aa[b] == '(') { + l++; + } else if (aa[b] == ')') { + l--; + } else { + l--; + num++; + } + if (l == 0) { + ans++; + } else if (l < 0 && num == 0) { + break; + } else if (l < 0 && num > 0) { + l += 2; + num--; + } + } + } + cout << ans << endl; +} +const int mod = 1000000007; +const long long inf = 1000000000000; +string s; +bool f[5001][5001] = {0}; +bool g[5001][5001] = {0}; +int main() { + cin >> s; + for (int i = 0; i < s.length(); i++) { + int cur = 0; + bool ok = true; + for (int j = i; j < s.length(); j++) { + if (s[j] == ')') { + cur--; + } else { + cur++; + } + if (cur < 0) { ok = false; } + f[i][j] = ok; + } + } + for (int i = 0; i < s.length(); i++) { + int cur = 0; + bool ok = true; + for (int j = i; j >= 0; j--) { + if (s[j] == '(') { + cur--; + } else { + cur++; + } + if (cur < 0) { ok = false; } + g[j][i] = ok; + } + } + int ans = 0; + for (int i = 0; i < s.length(); i++) { + for (int j = i; j < s.length(); j++) { + if (f[i][j] == true && g[i][j] == true && (j - i + 1) % 2 == 0) { ans++; } + } + } + cout << ans << '\n'; + return 0; +} +vector di[3]; +vector linha0[10010]; +vector linha1[10010]; +vector linha2[10010]; +void multiplos(int a, int b, int h) { + int menor = a; + if (a > b) b = menor; + for (int i = 1; i <= menor; i++) { + if (a % i == 0 && b % i == 0) { di[h].push_back(i); } + } +} +int main() { + int a, b, c, s; + cin >> a >> b >> c; + multiplos(a, b, 0); + multiplos(a, c, 1); + multiplos(b, c, 2); + for (int i = 0; i < (int)di[0].size(); i++) { + for (int j = 0; j < (int)di[1].size(); j++) { + if (di[0][i] * di[1][j] == a) { + for (int u = 0; u < (int)di[2].size(); u++) { + if (di[0][i] * di[2][u] == b) { + if (di[1][j] * di[2][u] == c) { s = di[2][u] + di[1][j] + di[0][i]; } + } + } + } + } + } + int total = 4 * s; + cout << total << endl; +} +long long n, a, b, ans; +int main() { + cin >> n; + while (n--) { + ans = 0; + cin >> a >> b; + while (a > 0 && b > 0) { + if (b > a) swap(a, b); + ans += a / b; + a %= b; + } + cout << ans << '\n'; + } + return 0; +} +int main() { + int n, k, a, b; + int R = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a >> b; + R += b - a; + R++; + } + int count; + if (R % k == 0) + count = 0; + else + count = k - (R % k); + cout << count << endl; + return 0; +} +const long long int size = 305; +void print(char c, long long int m) { + for (long long int j = 0; j < m; j++) { cout << c; } +} +int main() { + long long int n, m; + cin >> n >> m; + long long int check = 0; + for (long long int i = 0; i < n; i++) { + if (i % 2 == 0) { + print('#', m); + cout << "\n"; + } else { + if (check == 0) { + print('.', m - 1); + cout << '#' << "\n"; + check = 1; + } else { + cout << '#'; + print('.', m - 1); + cout << "\n"; + check = 0; + } + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int mini = 100000000; + for (int i = 0; i < n; i++) { + int temp = 0; + for (int j = 0; j < n; j++) { temp += (abs(i - j) + j + i) * a[j] * 2; } + mini = min(mini, temp); + } + cout << mini << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + cout << a / d + a / d / b * c << endl; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int ms = max(3 * a / 10, (a - a * c / 250)); + int vs = max(3 * b / 10, (b - b * d / 250)); + if (ms == vs) + cout << "Tie" << endl; + else if (ms > vs) + cout << "Misha" << endl; + else if (vs > ms) + cout << "Vasya" << endl; + return 0; +} +int main() { + int a, b, c, sum = 0; + cin >> a >> b >> c; + int x; + if (a <= b) { + x = a; + sum += x * 2; + b -= x; + int y = min(b, c); + sum += y * 2; + if (c - y > 0) { + if ((c - y) % 2 == 0) + cout << sum + c - y << endl; + else + cout << sum + c - y - 1 << endl; + } else { + cout << sum << endl; + } + } else { + x = b; + sum += x * 2; + a -= x; + int y = min(a, c); + sum += y * 2; + if (c - y > 0) { + if ((c - y) % 2 == 0) + cout << sum + c - y << endl; + else + cout << sum + c - y - 1 << endl; + } else { + cout << sum << endl; + } + } + return 0; +} +int main() { + long long int n, m, i, j, a[150][150], b[1010], k = 0; + cin >> n >> m; + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { cin >> a[i][j]; } + } + long long int mx = 0, c, sum; + for (i = 0; i < m; i++) { + mx = -1; + for (j = 0; j < n; j++) { + if (a[i][j] > mx) { + mx = a[i][j]; + c = j + 1; + } + } + k++; + b[k] = c; + } + sort(b, b + k); + multiset ms; + for (i = 1; i <= k; i++) ms.insert(b[i]); + multiset::iterator it; + int pos = 0, ans; + for (it = ms.begin(); it != ms.end(); it++) { + if (ms.count(*it) > pos) { + pos = ms.count(*it); + ans = *it; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int y[30] = {}; + int r = b, d = 0; + while (r > 0) { + y[d] = r % 10; + r /= 10; + d++; + } + for (int i = 0; i < d / 2; i++) swap(y[i], y[d - 1 - i]); + int w = 0, k = 1; + for (int i = 0; i < d; i++) { + w += y[i] * k; + k *= 10; + } + cout << w + a << endl; + return 0; +} +vector p, m, t; +int main() { + int n, temp; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> temp; + if (temp == 1) + p.push_back(i + 1); + else if (temp == 2) + m.push_back(i + 1); + else if (temp == 3) + t.push_back(i + 1); + } + int ans1 = min(min(p.size(), m.size()), t.size()); + cout << ans1 << endl; + for (int i = 0; i < ans1; ++i) { cout << p[i] << " " << m[i] << " " << t[i] << endl; } +} +string str; +string ans; +bool h = true, e = false, l = false, l_ = false, o = false; +int main() { + cin >> str; + for (int i = 0; i < str.size(); i++) { + if (str.at(i) == 'h' && h) { + ans += 'h'; + e = true; + h = false; + continue; + } + if (str.at(i) == 'e' && e) { + ans += 'e'; + l = true; + e = false; + continue; + } + if (str.at(i) == 'l' && l) { + ans += 'l'; + l_ = true; + l = false; + continue; + } + if (str.at(i) == 'l' && l_) { + ans += 'l'; + o = true; + l_ = false; + continue; + } + if (str.at(i) == 'o' && o) { + ans += 'o'; + break; + } + } + if (ans == "hello") + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + int cnt[100001] = {0}; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +int main() { + long long n, k; + while (cin >> n >> k) { + if (k <= ((n + 1) >> 1)) { + k = (k << 1) - 1; + } else { + k -= (n + 1) >> 1; + k <<= 1; + } + cout << k << endl; + } + return 0; +} +int main() { + long long int n; + long long int k; + cin >> n; + cin >> k; + if (((n / k) % 2) == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char ma[n][m]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) cin >> ma[i][j]; + } + set ans; + vector p; + for (int i = 0; i < m; ++i) { + int aux = 0, misa = -1; + for (int j = 0; j < n; ++j) { + if ((int)ma[j][i] - '0' > aux) { aux = (int)ma[j][i] - '0'; } + } + for (int j = 0; j < n; ++j) { + if (aux == (int)ma[j][i] - '0') { ans.insert(j); } + } + } + cout << ans.size() << endl; + return 0; +} +int main() { + int n; + char k; + char xx[12]; + while (cin >> n >> k) { + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> xx; + int a = -1; + int s = strlen(xx); + for (char t = '0'; t <= k; t++) { + for (int j = 0; j < s; j++) { + if (xx[j] == t) { + a++; + break; + } + } + } + if (a == k - '0') sum++; + } + cout << sum << endl; + } + return 0; +} +int num[105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> num[i]; + for (int i = 1; i < n; i++) { + if (num[0] > num[i]) + num[0] = __gcd(num[0], num[i]); + else if (num[0] < num[i]) + num[0] = __gcd(num[i], num[0]); + } + cout << num[0] * n << endl; + return 0; +} +int main() { + string ss; + cin >> ss; + int idx = (int)ss.size() - 1; + vector ans((int)ss.size()); + for (int i = 0; i < (int)ss.size(); i++) { + if (ss[i] == 'r') continue; + ans[idx] = i; + idx--; + } + idx = 0; + for (int i = 0; i < (int)ss.size(); i++) { + if (ss[i] == 'l') continue; + ans[idx] = i; + idx++; + } + for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << '\n'; + return 0; +} +const int MAXN = 128; +int n, a[MAXN]; +int main() { + cin >> n; + if (n == 1) { + cin >> a[0]; + if (a[0] == 0) + cout << "UP\n"; + else if (a[0] == 15) + cout << "DOWN\n"; + else + cout << "-1\n"; + return false; + } + for (int i = 0; i < n; i++) cin >> a[i]; + if (a[n - 1] == 0) + cout << "UP\n"; + else if (a[n - 1] == 15) + cout << "DOWN\n"; + else { + if (a[n - 1] > a[n - 2]) + cout << "UP\n"; + else + cout << "DOWN\n"; + } + return false; +} +int main() { + int s, va, ta, vb, tb; + cin >> s >> va >> vb >> ta >> tb; + int a = va * s + 2 * ta; + int b = vb * s + 2 * tb; + if (a < b) + cout << "First\n"; + else if (a > b) + cout << "Second\n"; + else + cout << "Friendship\n"; + return 0; +} +int main() { + string op; + cin >> op; + string final; + string final2; + for (int i = 0; i < op.length(); i++) { + if (op[i] != '+') { final += op[i]; } + } + sort(final.begin(), final.end()); + for (int j = 0; j < op.length() / 2; j++) { final.insert((j * 2) + 1, "+"); } + cout << final << endl; +} +int main() { + int x; + cin >> x; + cout << x + x / 2 << endl; + return 0; +} +int main() { + string str[8]; + while (cin >> str[0]) { + for (int i = 1; i < 8; i++) { cin >> str[i]; } + int flag = 1; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (str[i][j] == str[i][j + 1]) { + flag = 0; + break; + } + } + } + if (flag) + puts("YES"); + else + puts("NO"); + } + return 0; +} +int main() { + int m, n; + cin >> m; + int best = INT_MAX; + for (int i = 0; i < m; i++) { + cin >> n; + best = min(n, best); + } + cin >> n; + vector V(n); + for (int i = 0; i < n; i++) { cin >> V[i]; } + sort(V.begin(), V.end()); + int sum = 0, c = 0; + for (int i = V.size() - 1; i >= 0; i--) { + if (c < best) { + sum += V[i]; + c++; + } else { + c = 0; + i--; + } + } + cout << sum << "\n"; +} +int main() { + int n, i, j; + cin >> n; + int a[100000][2]; + for (i = 0; i < n; ++i) { + for (j = 0; j <= 1; ++j) { cin >> a[i][j]; } + } + int r = 0, l = 0; + for (i = 0; i < n; ++i) { + if (a[i][0] > 0) + r++; + else + l++; + } + if (r < 2 || l < 2) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int k, a, b, v, ans; +int main() { + cin >> k >> a >> b >> v; + while (b >= k - 1 && a >= v * k) { + ans++; + a -= v * k; + b -= k - 1; + } + if (a > 0 && b > 0) { + a -= min((b + 1) * v, a); + b = 0; + ans++; + } + if (a > 0) { ans += (a % v == 0) ? a / v : a / v + 1; } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int i, j, k, h, flag = 0; + int l = a.size(); + for (i = 0, j = 0; i < l, j < l; i++, j++) { + if (a[i] == b[j]) { + flag = 0; + } else { + a[i] = tolower(a[i]); + b[j] = tolower(b[j]); + if (a[i] == b[j]) { + flag = 0; + } else if (a[i] > b[j]) { + flag = 1; + break; + } else { + flag = -1; + break; + } + } + } + cout << flag << endl; + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + if (k > n / 2) { + for (int i = k; i < n; i++) cout << "RIGHT" << endl; + for (int i = n - 1; i; i--) { + cout << "PRINT " << s[i] << endl; + cout << "LEFT\n"; + } + cout << "PRINT " << s[0] << endl; + } else { + for (int i = 1; i < k; i++) cout << "LEFT" << endl; + for (int i = 0; i < n - 1; i++) { + cout << "PRINT " << s[i] << endl; + cout << "RIGHT\n"; + } + cout << "PRINT " << s[n - 1] << endl; + } + return 0; +} +int main() { + int n, a, k = 0; + ; + cin >> n; + set s; + vector v(2 * n); + for (int i = 0; i < 2 * n; i++) { + cin >> a; + s.insert(a); + k++; + if (s.size() == k) + v[i] = k; + else { + k = k - 2; + s.erase(a); + v[i] = s.size(); + } + } + cout << *max_element(v.begin(), v.end()) << endl; +} +const int M = 300 + 5; +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool ok1 = true; + int sum1 = 0; + int sum2 = 0; + for (int i = 0; i < n; i++) { + if (s[i] != '4' && s[i] != '7') { ok1 = false; } + if (i < n / 2) { + sum1 = sum1 + s[i] - '0'; + } else { + sum2 = sum2 + s[i] - '0'; + } + } + if (ok1 && sum1 == sum2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int maxx = 1e5 + 20; +int a[maxx], n, ans = 0, c; +int main() { + cin >> n >> c; + for (int i = n - 1; i >= 0; i--) cin >> a[i]; + int i = 1; + while (i < n && a[i - 1] - a[i] <= c) i++; + cout << i << endl; +} +string now[2]; +string str[1005][2]; +int main() { + int n; + cin >> now[0] >> now[1]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> str[i][0] >> str[i][1]; } + cout << now[0] << " " << now[1] << endl; + for (int i = 1; i <= n; i++) { + if (now[0] == str[i][0]) { + now[0] = str[i][1]; + } else + now[1] = str[i][1]; + cout << now[0] << " " << now[1] << endl; + } + return 0; +} +int main() { + int ans1 = 0, ans2 = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + ans1 |= a; + } + for (int i = 0; i < n; i++) { + int a; + cin >> a; + ans2 |= a; + } + cout << ans1 + ans2 << endl; + return 0; +} +long long choose(long long n, long long k); +bool isprime(long long n); +long long power(long long x, long long y, long long p); +long long power(long long x, long long y); +long long a[200005], b[200005]; +int main() { + long long n, m, x, y, z; + cin >> n >> m; + a[n + 1] = 1000000000; + for (long long i = 1; i < n + 1; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + long long sz = 0; + for (long long i = 0; i < m; i++) { + cin >> x >> y >> z; + if (x == 1) b[++sz] = y; + } + sort(b + 1, b + sz + 1); + long long j = 1, ans = n + m; + for (long long i = 1; i < n + 2; i++) { + while (j <= sz && b[j] < a[i]) j++; + ans = min(ans, i + sz - j); + } + cout << ans << endl; + return 0; +} +long long choose(long long n, long long k) { + if (k == 0) return 1; + return (n * choose(n - 1, k - 1)) / k; +} +bool isprime(long long n) { + for (long long i = 2; i * i <= n; i++) { + if (n % i == 0) return false; + } + return true; +} +long long power(long long x, long long y, long long p) { + long long res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +long long power(long long x, long long y) { + long long res = 1; + while (y > 0) { + if (y & 1) res = res * x; + y = y >> 1; + x = x * x; + } + return res; +} +const int MOD = 998244353; +const int MAX = 200001; +int An[MAX]; +int book[MAX]; +int main() { + string str; + cin >> str; + int sum = 0; + int n = str.length(); + for (int i = 0; i < n / 2; i++) { + if (str[i] != str[n - 1 - i]) sum++; + } + if (sum == 1) + cout << "YES" << endl; + else { + if (sum == 0 && n % 2) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +long long T, a, b, k; +int main() { + cin >> T; + while (T--) { + cin >> a >> b >> k; + long long mod = k / 2; + if (k % 2 == 0) + cout << a * mod - b * mod << endl; + else + cout << a * (mod + 1) - b * mod << endl; + } + return 0; +} +int main() { + string str; + int ctr = 0; + for (int i = 0; i < 8; i++) { + cin >> str; + if (!str.compare("BWBWBWBW") || !str.compare("WBWBWBWB")) ctr++; + } + if (ctr == 8) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, sum = 0; + char s[21]; + cin >> s; + n = strlen(s); + sum = 25 * n + 26; + cout << sum << endl; + return 0; +} +int main() { + int k, r; + cin >> k >> r; + for (int y = 1;; y++) { + int z = k * y; + if (z % 10 == 0) { + cout << y << endl; + return 0; + } + int x = (k * y - r); + if (x % 10 == 0) { + cout << y << endl; + return 0; + } + } +} +const long long INF = 1e18; +long long N = 1e8; +const long long mod = 1e9 + 7; +const long double eps = 1E-7; +long long n, m, a, b, x, c, d, cnt, ans; +string s1, s2; +long long used[2000]; +long long arr[1001]; +map mp; +set stt; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { + cin >> s1; + sort(s1.begin(), s1.end()); + for (long long j = 0; j < s1.size(); j++) { + if (mp[s1[j]] == 0) { + s2 += s1[j]; + mp[s1[j]]++; + } + } + stt.insert(s2); + s2.clear(); + mp.clear(); + } + cout << stt.size() << endl; +} +int main() { + int n, one = 0, two = 0, trone = 0; + vector x; + cin >> n; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + if (tmp == 1) + one++; + else + two++; + x.push_back(tmp); + } + trone = one; + int ans = min(one, two); + trone -= ans; + trone /= 3; + cout << ans + trone << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + bool turn = 0; + while (true) { + if (turn == 0) { + if (x >= 2 && y >= 2) { + x -= 2; + y -= 2; + } else if (x == 1 && y >= 12) { + x -= 1; + y -= 12; + } else if (x == 0 && y >= 22) + y -= 22; + else + break; + } else if (turn == 1) { + if (y >= 22) + y -= 22; + else if (x >= 1 && y >= 12) { + x -= 1; + y -= 12; + } else if (x >= 2 && y >= 2) { + x -= 2; + y -= 2; + } else + break; + } + turn = !turn; + } + if (turn == 0) + cout << "Hanako" << endl; + else + cout << "Ciel" << endl; + return 0; +} +int n; +int a[200005]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int sol = 1123123123; + for (int i = 0; i < n / 2; i++) sol = min(sol, a[i + n / 2] - a[i]); + cout << sol << '\n'; +} +int main() { + string str; + cin >> str; + int count = 0, i = 0; + while (i < (long long)str.length()) { + long long l = 1; + while (str[i] == str[i + 1]) { + i++; + l++; + } + if (l % 2 == 0) count++; + i++; + } + cout << count << endl; +} +int n, a, b; +string s; +int main() { + cin >> n >> a >> b >> s; + a--; + b--; + if (s[a] != s[b]) { + cout << 1 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int n; +int visited[101]; +int arr[101]; +int main() { + cin >> n; + for (int i = 0; i < n / 2; i++) { cin >> arr[i]; } + sort(arr, arr + (n / 2)); + int odd = 0; + int o = 0; + for (int i = 1; i <= n - 1; i += 2) { + odd += abs(arr[o] - i); + o++; + } + int even = 0; + o = 0; + for (int i = 2; i <= n; i += 2) { + even += abs(arr[o] - i); + o++; + } + cout << min(odd, even) << endl; +} +string S, T; +long long N, M, A, B, sum, x, y, K, ans, val, L, a; +char C; +int main() { + cin >> N >> M >> A >> B; + x = ((N - 1) / M + 1) * M; + y = N / M * M; + cout << min((x - N) * A, (N - y) * B) << '\n'; +} +int main() { + int n, b, s, ans = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + b = arr[0]; + s = arr[0]; + for (int i = 0; i < n; ++i) { + if (arr[i] > b) b = arr[i]; + if (arr[i] < s) s = arr[i]; + } + for (int i = 0; i < n; ++i) { + if (arr[i] == b || arr[i] == s) continue; + ans++; + } + cout << ans << endl; + return 0; +} +const long long int inf = 1e15; +const int M = 1e9 + 7; +int main() { + long long int x[3], k, y[3]; + cin >> x[0] >> x[1] >> x[2] >> k; + if (k >= x[0] + x[1] + x[2] - 3) { + cout << x[0] * x[1] * x[2] << endl; + } else { + sort(x, x + 3); + int save, final[3]; + save = k / 3; + if (save < x[0]) { + y[0] = save; + k -= save; + if (save < x[1]) { + y[1] = k / 2; + y[2] = k - y[1]; + } else { + y[1] = x[1] - 1; + k += 1 - x[1]; + y[2] = k; + } + } else { + y[0] = x[0] - 1; + k += 1 - x[0]; + save = k / 2; + if (save < x[1]) { + y[1] = k / 2; + y[2] = k - y[1]; + } else { + y[1] = x[1] - 1; + k += 1 - x[1]; + y[2] = k; + } + } + cout << (y[1] + 1) * (y[2] + 1) * (y[0] + 1) << endl; + } + return 0; +} +long long n, c1, c2; +long long solve(long long g) { + long long t1 = ceil((double)n / g), t2 = n / g, left = n, res = 0; + for (; t2 * g != left && left > 0; left -= t1, g--) res += (c1 + c2 * (t1 - 1) * (t1 - 1)); + for (; g > 0; left -= t2, g--) res += (c1 + c2 * (t2 - 1) * (t2 - 1)); + return res; +} +int main() { + char t; + cin >> n >> c1 >> c2; + long long p = 0, r = 0, i; + for (i = 0; i < n; i++) { + cin >> t; + (t == '1') ? p++ : r++; + } + long long lo = 1, hi = p; + while (lo < hi) { + long long diff = hi - lo; + long long p1 = lo + diff / 3, p2 = lo + (2 * diff + 2) / 3; + long long s1 = solve(p1), s2 = solve(p2); + if (s1 == s2) + lo = p1 + 1, hi = p2 - 1; + else if (s1 > s2) + lo = p1 + 1; + else + hi = p2 - 1; + } + cout << solve(lo) << endl; +} +int main() { + int a, n, b, c; + char s[8]; + char w[8] = "jolteon", q[8] = "flareon"; + char v[8] = "umbreon", z[8] = "leafeon", l[8] = "glaceon", m[8] = "sylveon"; + cin >> n; + cin >> s; + if (n == 8) { + cout << "vaporeon" << endl; + } else if (n == 6) { + cout << "espeon" << endl; + } else { + a = 0; + b = 0; + c = 0; + int d = 0; + int e = 0; + int f = 0; + for (int i = 0; i < 8; i++) { + if (s[i] == w[i]) { a++; } + } + for (int i = 0; i < 8; i++) { + if (s[i] == q[i]) { b++; } + } + for (int i = 0; i < 8; i++) { + if (s[i] == v[i]) { c++; } + } + for (int i = 0; i < 8; i++) { + if (s[i] == z[i]) { d++; } + } + for (int i = 0; i < 8; i++) { + if (s[i] == l[i]) { e++; } + } + for (int i = 0; i < 8; i++) { + if (s[i] == m[i]) { f++; } + } + if (a > b && a > c && a > d && a > e && a > f) { + cout << "jolteon" << endl; + } else if (b > a && b > c && b > d && b > e && b > f) { + cout << "flareon" << endl; + } else if (c > a && c > b && c > d && c > e && c > f) { + cout << "umbreon" << endl; + } else if (d > a && d > c && d > b && d > e && d > f) { + cout << "leafeon" << endl; + } else if (e > a && e > c && e > d && e > b && e > f) { + cout << "glaceon" << endl; + } else if (f > a && f > c && f > d && f > e && f > b) { + cout << "sylveon" << endl; + } + } + return 0; +} +unsigned long long int x, y, sum, n; +int main() { + cin >> n; + while (n--) { + cin >> x >> y; + sum = 0; + for (;;) { + if (x == 0 || y == 0) { break; } + if (x < y) { + sum += y / x; + y %= x; + } else { + sum += x / y; + x %= y; + } + } + cout << sum << endl; + } +} +const int INF = 0x3f3f3f3f; +long long a[105][105]; +int main() { + long long i, j, k, l, r, co = 0; + long long n, m, t, x, y; + cin >> n; + k = 0; + while (n--) { + cin >> l >> r >> x >> y; + for (i = l; i <= x; i++) + for (j = r; j <= y; j++) { + if (!a[i][j]) + a[i][j] = 1; + else + a[i][j]++; + } + } + for (i = 1; i <= 100; i++) + for (j = 1; j <= 100; j++) co += a[i][j]; + cout << co << endl; + return 0; +} +int main() { + long long int n, m; + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + cout << max(n / 10, 10 * (n / 100) + n % 10) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2) { + cout << "contest\n"; + } else { + cout << "home\n"; + } +} +int main() { + int n, m; + cin >> n; + cin >> m; + if (n == 0 && m == 0) + cout << "NO" << endl; + else if (abs(n - m) <= 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long t, a, b, k; +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { + long long p = 0, ans; + cin >> a >> b >> k; + if (k % 2 == 1) p = 1; + ans = a * (k / 2 + p) - b * (k / 2); + cout << ans << endl; + } + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (n == 1) + cout << 0 << endl; + else { + if (a <= b && a <= c) cout << (n - 1) * a << endl; + if (a > b && b <= c) cout << (n - 1) * b << endl; + if (a <= b && a > c) cout << a + (n - 2) * c << endl; + if (a > b && b > c) cout << b + (n - 2) * c << endl; + } + return 0; +} +int n; +string s; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s.length() <= 10) + cout << s << endl; + else + cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + string str, cmd; + cin >> str; + int x, y; + char c1, c2; + for (int i = 0; i < m; i++) { + cin >> x >> y >> c1 >> c2; + for (int j = x; j <= y; j++) { + if (str[j - 1] == c1) str[j - 1] = c2; + } + } + cout << str << endl; +} +int main() { + string s; + int i; + while (cin >> s) { + i = 0; + if (s[0] == '9') i++; + for (; i < s.size(); i++) { + if (s[i] > '4') { s[i] = '9' - s[i] + '0'; } + } + cout << s << endl; + } + return 0; +} +int main() { + int n, m, a[1111], b[1111]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + if (a[1] == 0) { + cout << "NO" << endl; + return 0; + } + int flag = 0; + if (a[m]) { + cout << "YES" << endl; + } else { + if (!b[m]) { + cout << "NO" << endl; + } else { + for (int i = m + 1; i <= n; i++) { + if (a[i] && b[i]) { + flag = 1; + cout << "YES" << endl; + return 0; + } + } + if (!flag) { cout << "NO" << endl; } + } + } + return 0; +} +int main() { + int n, i; + string s, s1; + vector r, kw, m, c; + vector::iterator it; + cin >> n; + while (n--) { + cin >> s >> s1; + if (s1 == "woman" || s1 == "child") { + kw.push_back(s); + } else if (s1 == "rat") { + r.push_back(s); + } else if (s1 == "man") { + m.push_back(s); + } else { + c.push_back(s); + } + } + for (it = r.begin(); it != r.end(); it++) { cout << *it << endl; } + for (it = kw.begin(); it != kw.end(); it++) { cout << *it << endl; } + for (it = m.begin(); it != m.end(); it++) { cout << *it << endl; } + for (it = c.begin(); it != c.end(); it++) { cout << *it << endl; } + return 0; +} +int find(int x, int father[]) { + if (father[x] == x) return x; + return father[x] = find(father[x], father); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int yes = 0; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] != s[i + 1]) { + yes = 1; + cout << "YES\n"; + cout << s.substr(i, 2) << "\n"; + return 0; + } + } + cout << "NO\n"; +} +const int maxN = (int)1e5; +int main() { + int n, x, y; + cin >> n >> x >> y; + double t = ceil(n * y * 1.0 / 100.0); + cout << max((int)t - x, 0) << endl; +} +int main() { + int n = 0; + int a = 0; + int b = 0; + cin >> n; + cin >> a; + cin >> b; + int h[2000]; + for (int i = 0; i < n; i++) cin >> h[i]; + sort(h, h + n); + cout << h[b] - h[b - 1] << endl; + return 0; +} +const int64_t infint64_t = 9223372036854775807LL; +void solve() { + int64_t n, k; + cin >> n >> k; + vector a(n); + int64_t minb = infint64_t; + int64_t maxb = 0; + for (int64_t i = 0; i < n; i++) { cin >> a[i]; } + for (int64_t i = 0; i < k; i++) { + int64_t x; + cin >> x; + if (x < minb) minb = x; + if (x > maxb) maxb = x; + } + if (a[0] == 0 && a[1] == 0) { + cout << "Yes" << endl; + return; + } + if (a[0] == 0 && maxb >= a[1]) { + cout << "Yes" << endl; + return; + } + for (int64_t i = 0; i < n; i++) { + if (a[i] == 0 && i > 0 && a[i - 1] == 0) { + cout << "Yes" << endl; + return; + } + if (a[i] == 0 && i > 0 && minb < a[i - 1]) { + cout << "Yes" << endl; + return; + } + if (a[i] > 0 && i > 0 && a[i - 1] > 0 && a[i] < a[i - 1]) { + cout << "Yes" << endl; + return; + } + if (a[i] == 0 && i + 1 < n && a[i + 1] == 0) { + cout << "Yes" << endl; + return; + } + if (a[i] == 0 && i + 1 < n && maxb > a[i + 1]) { + cout << "Yes" << endl; + return; + } + } + cout << "No" << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + while (cin >> n) { + string s; + bool flag = false; + int len = n / 7; + int k = 0; + while (1) { + if ((n - len * 7) % 4 == 0) { + k = (n - len * 7) / 4; + flag = true; + break; + } else { + len--; + } + if (len == -1) break; + } + if (!flag) + cout << -1 << endl; + else { + for (int i = 0; i < k; i++) { s += '4'; } + for (int i = 0; i < len; i++) s += '7'; + cout << s << endl; + } + } +} +int main() { + string str, s[101]; + int n; + cin >> str; + cin >> n; + for (int i = 1; i <= n; i++) cin >> s[i]; + sort(s + 1, s + n + 1); + for (int i = 1; i <= n; i++) + if (s[i].substr(0, str.length()) == str) { + cout << s[i] << endl; + return 0; + } + cout << str << endl; + return 0; +} +int n[11][11]; +int main() { + int i, j, m; + cin >> m; + for (i = 1; i <= m; i++) n[1][i] = 1; + for (i = 2; i <= m; i++) { + for (j = 1; j <= m; j++) { n[i][j] = n[i - 1][j] + n[i][j - 1]; } + } + cout << n[m][m] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool flg = false; + while (n) { + if ((n & 1) == 1) { + for (int i = (0); i < (m); i++) cout << "#"; + cout << endl; + } else { + if (flg) cout << "#"; + for (int i = (0); i < (m - 1); i++) cout << "."; + if (!flg) cout << "#"; + flg = !flg; + cout << endl; + } + n--; + } +} +int p1, p2, p3, p4, a, b; +int main() { + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + int ans = 0; + int p = min(p1, p2); + p = min(p, p3); + p = min(p, p4); + if (b < p) { + cout << b - a + 1 << "\n"; + return 0; + } + if (p - a > 0) { ans = p - a; } + cout << ans << "\n"; + return 0; +} +int main() { + int n, a[5001]; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a[i]; + --a[i]; + } + for (int i = 0; i < n; ++i) { + if (a[i] == a[a[a[a[i]]]]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +void swap(int *xp, int *yp) { + int temp = *xp; + *xp = *yp; + *yp = temp; +} +void selectionSort(int arr[], int n) { + int i, j, min_idx; + for (i = 0; i < n - 1; i++) { + min_idx = i; + for (j = i + 1; j < n; j++) + if (arr[j] < arr[min_idx]) min_idx = j; + swap(&arr[min_idx], &arr[i]); + } +} +int main() { + int n; + cin >> n; + int counter = 0; + int Ids[n]; + for (int i = 0; i < n; i++) { cin >> Ids[i]; } + selectionSort(Ids, n); + for (int i = 0; i < n - 1; i++) { + if (Ids[i] != 0 && Ids[i] == Ids[i + 2]) { + counter = -1; + break; + } + if (Ids[i] != 0 && Ids[i] == Ids[i + 1]) { + i++; + counter++; + } + } + cout << counter << endl; + return 0; +} +int main() { + int i, j, k, sum = 0, m; + char s[110], c; + gets(s); + for (i = 0; s[i]; i++) { + if (i == 0) + m = s[i] - 'a'; + else + m = abs(s[i] - c); + c = s[i]; + if (m > 13) { m = 26 - m; } + sum += m; + } + cout << sum << endl; + return 0; +} +long a, b, c, ans, maxx, minn; +int main() { + cin >> a >> b >> c; + maxx = max(a, b); + minn = min(a, b); + maxx = max(maxx, c); + minn = min(minn, c); + ans = maxx - minn; + cout << ans << endl; + return 0; +} +int main() { + int num; + cin >> num; + int ans = 0; + for (int i = 1; i * i <= num; i++) { + if (num % i == 0) { ans = i; } + } + cout << ans << " " << num / ans << endl; + return 0; +} +const int maxn = 1e2 + 10, d = 86400; +int arr[maxn], n, t; +int main() { + cin >> n >> t; + for (int i = 0; i < n; i++) cin >> arr[i], arr[i] = d - arr[i]; + for (int i = 0; i < n; i++) { + t -= arr[i]; + if (t <= 0) { + cout << i + 1 << endl; + return 0; + } + } +} +int main() { + int n, c = 0; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + v.push_back(a); + } + for (int i = 1; i < n - 1; i++) { + if (v[i] > v[i + 1] && v[i] > v[i - 1]) { + c++; + } else if (v[i] < v[1 + i] && v[i] < v[i - 1]) { + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + string a; + cin >> a; + int num = 0; + for (int i = 0; i < a.length() - 1; i++) { + for (int j = i + 1; j < a.length(); j++) { + if (a[i] == a[j]) { + int nn = 1; + for (int ii = i + 1, jj = j + 1; jj < a.length(); jj++, ii++) { + if (a[ii] == a[jj]) + nn++; + else + break; + } + if (nn > num) num = nn; + } + } + } + cout << num << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + set x, y; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < n; j++) + if (i == j or i + j == n - 1) + x.insert(s[j]); + else + y.insert(s[j]); + } + if (x.size() == 1 and y.size() == 1 and *x.begin() != *y.begin()) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, c; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '7' || s[i] == '4') c++; + } + if (c == 4 || c == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + reverse(s1.begin(), s1.end()); + if (s1 == s2) + puts("YES"); + else + puts("NO"); + return 0; +} +long long int n, m; +char a[1007][1007]; +bool isInn(long long int x, long long int y) { + return x >= 0 && y >= 0 && x < n && y < m; +} +bool isFace(char a, char b, char c, char d) { + char x[4] = {a, b, c, d}; + sort(x, x + 4); + return x[0] == 'a' && x[1] == 'c' && x[2] == 'e' && x[3] == 'f'; +} +int main() { + cin >> n >> m; + long long int _s = 0; + for (long long int i = 0; i <= n - 1; i++) { + for (long long int j = 0; j <= m - 1; j++) { cin >> a[i][j]; } + } + for (long long int i = 0; i <= n - 2; i++) { + for (long long int j = 0; j <= m - 2; j++) { + if (isInn(i, j) && isInn(i, j + 1) && isInn(i + 1, j) && isInn(i + 1, j + 1)) { _s += isFace(a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]); } + } + } + cout << _s << "\n"; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + vector a(n); + long long int ce = 0, cs = 0, ce2 = 0, cs2 = 0, ans = 0; + for (long long int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) + cs++; + else if (a[i] == -1) + ce++; + } + for (long long int i = 0; i < k; i++) { + ce2 = 0, cs2 = 0; + for (long long int j = i; j < n; j += k) { + if (a[j] == 1) { + cs2++; + } else if (a[j] == -1) + ce2++; + } + ans = max(abs(cs - cs2 - ce + ce2), ans); + } + cout << ans << endl; +} +int main() { + long long s = 0, e = 1e9 + 2; + long long t, a, b, c, d; + cin >> t; + while (t--) { + cin >> a >> b >> c >> d; + s = 0; + e = 1e9 + 1; + long long min1 = 1e9 + 4; + long long mid; + while (s <= e) { + mid = (s + e) / 2; + if (mid * c >= a && mid * d - mid * c >= b - a) { + min1 = min(min1, mid); + e = mid - 1; + } else { + s = mid + 1; + } + } + if (min1 == 1e9 + 4) { + cout << "-1" << endl; + ; + } else { + cout << min1 * d - b << endl; + } + } +} +void fun(int n) { + int godama = n / 5; + int ichdama = n % 5; + if (godama > 0) + cout << "-O|"; + else + cout << "O-|"; + for (int i = 0; i < ichdama; i++) cout << "O"; + cout << "-"; + for (int i = ichdama; i < 4; i++) cout << "O"; + cout << endl; +} +int main() { + int k; + cin >> k; + if (k == 0) { + fun(0); + return 0; + } + int digits[10]; + int i = 0; + while (k > 0) { + digits[i] = k % 10; + k /= 10; + i++; + } + k = i; + for (int j = 0; j < k; j++) { fun(digits[j]); } + return 0; +} +int main() { + int n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string name[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << name[(n - 1) / r] << endl; +} +int main() { + int a, b, c, ans = 0, i; + vector vec(10005, 0); + while (cin >> a >> b >> c) { + for (i = 1; i <= c / a; i++) { vec[a * i] = 1; } + for (i = 1; i <= c / b; i++) { + if (vec[b * i] == 1) ans++; + } + vec.assign(10005, 0); + cout << ans << endl; + ans = 0; + } + return 0; +} +int main() { + int n, flag = 0; + cin >> n; + int x[n + 1]; + for (int i = 1; i <= n; i++) { cin >> x[i]; } + for (int i = 1; i <= n; i++) { + if (x[x[x[i]]] == i) { + flag++; + break; + } + } + if (flag == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int x, hh, mm, i = 0, sum = 0; + cin >> x >> hh >> mm; + if (mm % 10 == 7 || hh % 10 == 7) { + cout << 0 << endl; + return 0; + } + while (1) { + i++; + if (mm == x) + mm = 0; + else if (mm > x) { + if ((mm - x) % 10 == 7) + break; + else + mm -= x; + } else { + mm = 60 - (x - mm); + if (mm % 10 == 7) + break; + else { + if (hh == 0) + hh = 23; + else { + hh--; + if (hh % 10 == 7) break; + } + } + } + } + cout << i << endl; + return 0; +} +int main() { + int a, b; + long long sum = 1; + cin >> a >> b; + int min = a < b ? a : b; + for (int i = 2; i <= min; i++) sum *= i; + cout << sum << endl; +} +int main() { + long long n; + cin >> n; + cout << 2 * n - n / 2 << endl; +} +int main() { + long long n; + cin >> n; + long long x = max(n - 81, (long long)1), cnt = 0, a[100010], I = 0; + while (x < n) { + long long N = x, S = 0; + while (N) { + S += N % 10; + N /= 10; + } + if (x + S == n) a[I] = x, I++, cnt++; + x++; + } + cout << cnt << '\n'; + for (int i = 0; i < I; i++) cout << a[i] << '\n'; + return 0; +} +long int a[10000000]; +int main() { + int n; + cin >> n; + int m = 0; + int len = 0; + int aa = n; + while (aa) { + len++; + aa /= 10; + } + for (int i = n - len * 9; i < n; i++) { + int sum = i, p = i; + while (p) { + sum += p % 10; + p /= 10; + } + if (sum == n) { a[m++] = i; } + } + cout << m << endl; + for (int i = 0; i < m; i++) { cout << a[i] << endl; } + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (b != 0) { + c = c * 10 + b % 10; + b = b / 10; + } + cout << a + c << endl; + return 0; +} +int main() { + int n, freq = 1; + ; + cin >> n; + int ans = 0; + int min; + cin >> min; + for (int i = 1; i < n; i++) { + int temp; + cin >> temp; + if (temp < min) { + min = temp; + ans = i; + freq = 1; + } else if (temp == min) + freq++; + } + if (freq > 1) + cout << "Still Rozdil" << endl; + else + cout << ans + 1 << endl; + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + if (n % s == 0) + n = n / s; + else + n = n / s + 1; + k = k * n; + if (k % p == 0) + cout << k / p << endl; + else + cout << k / p + 1 << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, b, n, k = 0, c = 2; + cin >> a >> b >> n; + while (n > 0) { + if (c % 2 == 0) { + n = n - gcd(a, n); + k = 0; + c = 1; + } else { + n = n - gcd(b, n); + k = 1; + c = 2; + } + } + cout << k << endl; +} +int main() { + long int n, x; + cin >> n; + cin >> x; + if (n % 2 == 0) { + if (n % 3 == 1) { + if (x == 0) + x = 2; + else if (x == 1) + x = 0; + else if (x == 2) + x = 1; + } else if (n % 3 == 2) { + if (x == 0) + x = 1; + else if (x == 1) + x = 2; + else if (x == 2) + x = 0; + } + } else { + if (n % 3 == 0) { + if (x == 0) + x = 2; + else if (x == 1) + x = 1; + else if (x == 2) + x = 0; + } else if (n % 3 == 2) { + if (x == 0) + x = 0; + else if (x == 1) + x = 2; + else if (x == 2) + x = 1; + } else if (n % 3 == 1) { + if (x == 0) + x = 1; + else if (x == 1) + x = 0; + else if (x == 2) + x = 2; + } + } + cout << x << endl; +} +int main() { + int a, b, c, d, e, f, g; + string s, t; + while (cin >> s >> t) { + a = s.size(); + b = t.size(); + d = 1; + e = 0; + for (c = 0; c < b; c++) { + if (t[c] == s[e] && e + 1 < a) { + d++; + e++; + } + } + cout << d << endl; + } + return 0; +} +int main() { + int f, k, t, n, st = -999999999, m; + cin >> n >> k; + while (n--) { + cin >> f >> t; + if (t > k) { + m = f - (t - k); + st = max(m, st); + } else { + st = max(st, f); + } + } + cout << st << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int tep = 0, ans = 0; + while (n--) { + int val; + cin >> val; + if (val == 0) + ans++; + else if (tep == val && val != 3) { + ans++; + val = 0; + } else if (val == 3 && tep != 3) { + if (tep == 1) + val = 2; + else if (tep == 2) + val = 1; + } + tep = val; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int ch = 0, bi = 0, ba = 0; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + if (i % 3 == 0) + ch += x; + else if (i % 3 == 1) + bi += x; + else + ba += x; + } + if (ch >= ba && ch >= bi) + cout << "chest\n"; + else if (ba >= ch && ba >= bi) + cout << "back\n"; + else + cout << "biceps\n"; +} +int main() { + string s; + cin >> s; + int n = s.size(); + vector mas(n); + int l = 0; + int r = n; + for (int i = 0; i < n;) { + if (s[i] == 'l') { + mas[--r] = ++i; + } else { + mas[l++] = ++i; + } + } + for (int i = 0; i < n; ++i) { cout << mas[i] << "\n"; } + return 0; +} +int seq[5010], n; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> seq[i]; } + bool ans = false; + for (int i = 1; i <= n; ++i) { + if (seq[seq[seq[i]]] == i) ans = true; + } + if (ans) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int n, i; + cin >> n; + n--; + for (i = 1; i <= n; i++) { n -= i; } + cout << n + 1 << "\n"; + return 0; +} +int d(int n, int m) { + if (n < m) { return n; } + if (n == m) { return n + 1; } + if (n > m) { return d(n - m + 1, m) + m; } +} +int main() { + int n, m; + cin >> n >> m; + cout << d(n, m) << endl; +} +int main() { + int n, x = 0; + cin >> n; + x = n / 2; + cout << n + x << endl; + return 0; +} +int main() { + long long int n, x, i, sum, d, c = 0; + cin >> n >> x; + char ch; + sum = x; + for (i = 0; i < n; i++) { + cin >> ch >> d; + if (ch == '+') + sum += d; + else { + if (sum >= d) + sum -= d; + else + c++; + } + } + cout << sum << " " << c << endl; + return 0; +} +int main() { + char arr[8][8]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { cin >> arr[i][j]; } + } + int up = 8; + int down = 8; + for (int i = 0; i < 8; i++) { + int j = 0; + while (j < 8 && arr[j][i] != 'W') { + if (arr[j][i] == 'B') { + j = 10; + break; + } + j++; + } + up = min(up, j); + j = 7; + while (j >= 0 && arr[j][i] != 'B') { + if (arr[j][i] == 'W') { + j = -2; + break; + } + j--; + } + down = min(down, 7 - j); + } + if (up <= down) { + cout << "A" << endl; + } else { + cout << "B" << endl; + } + return 0; +} +void solve() { + int n; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + vector::iterator it; + it = unique(v.begin(), v.end()); + v.resize(distance(v.begin(), it)); + bool b = false; + for (int i = 0; i < v.size(); i++) { + if (v[i] == 0) { + b = true; + break; + } + } + if (b) + cout << v.size() - 1 << endl; + else + cout << v.size() << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int arr[100010], n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = 0; i < n; i++) { + if (arr[i] != 0) { + if (arr[i] != arr[i - 1]) sum++; + } + } + cout << sum << endl; + return 0; +} +const int maxn = 5001; +int main() { + int n; + cin >> n; + cout << n % 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n % 2 << '\n'; + return 0; +} +string s; +int main() { + int ans = 0; + int a, b; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; i++) { + a = 0; + b = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + a++; + else if (s[j] == ')') + a--; + else + b++; + while (b > 0 && b > a) { + b--; + a++; + } + if (a < 0) break; + if ((j - i + 1) % 2 == 0 && b == a) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int n, k, l, c, d, p, nl, np; +const int INF = 0x3f3f3f3f; +int main() { + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int v = k * l; + int ans = INF; + ans = min(ans, v / nl / n); + ans = min(ans, c * d / n); + ans = min(ans, p / np / n); + cout << ans << endl; +} +int main() { + int a, b, n, ans = 0, s = 0; + while (cin >> n) { + if (n > 0) { + a = 1000000001; + ans = s = 1; + } + while (n-- > 0) { + cin >> b; + if (a < b) + ++s; + else + s = 1; + a = b; + ans = max(ans, s); + } + cout << ans << endl; + } + return 0; +} +string s; +vector r, l; +int main() { + cin >> s; + int n = s.size(); + for (int i = 0; i < n; i++) { + if (s[i] == 'r') + r.push_back(i + 1); + else + l.push_back(i + 1); + } + sort(r.begin(), r.end()); + sort(l.begin(), l.end()); + reverse(l.begin(), l.end()); + for (int i = 0; i < r.size(); i++) cout << r[i] << "\n"; + for (int i = 0; i < l.size(); i++) cout << l[i] << "\n"; + return 0; +} +int main() { + long long n; + cin >> n; + cout << "25" << endl; +} +int n, ori, pas, temp, step; +string originalState, passCode; +int main() { + cin >> n >> originalState >> passCode; + n = 0; + for (int i = 0; i < originalState.length(); i++) { + ori = originalState[i] - '0'; + pas = passCode[i] - '0'; + temp = pas; + step = 0; + while (temp != ori) { + step++; + temp++; + if (temp == 10) { temp = 0; } + if (step > 5) { + temp = pas; + step = 0; + while (temp != ori) { + step++; + temp--; + if (temp == -1) { temp = 9; } + } + break; + } + } + n += step; + } + cout << n << endl; + return 0; +} +int main() { + int i, j, k, l, n; + cin >> n; + for (i = 1, j = n / 2; i <= n / 2 + 1; i++, j--) { + for (k = 1; k <= j; k++) { cout << '*'; } + for (k = 1; k <= (2 * i) - 1; k++) { cout << 'D'; } + for (k = 1; k <= j; k++) { cout << '*'; } + cout << endl; + } + for (i = n / 2, j = 1; i >= 1; i--, j++) { + for (k = 1; k <= j; k++) { cout << '*'; } + for (k = 1; k <= (2 * i) - 1; k++) { cout << 'D'; } + for (k = 1; k <= j; k++) { cout << '*'; } + cout << endl; + } + return 0; +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int s[5]; + s[1] = a + b + c; + s[2] = a * (b + c); + s[3] = (a + b) * c; + s[4] = a * b * c; + int max = s[1]; + for (int i = 2; i < 5; i++) { + if (max < s[i]) max = s[i]; + } + cout << max << endl; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud\n"; + } else { + cout << "Ehab\n"; + } + return 0; +} +int main() { + int x, y; + cin >> x; + y = x % 5; + if (y != 0) + cout << x / 5 + 1 << endl; + else + cout << x / 5 << endl; +} +int main() { + long long n, k, l, c, d, p, nl, np, kl, cd, nnl, nslice, nnp; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + kl = k * l; + cd = c * d; + nnl = kl / (nl * n); + nslice = cd / n; + nnp = p / (np * n); + if (nnl < 0) nnl = 2000000; + if (nnp < 0) nnp = 2000000; + if (nslice < 0) nslice = 2000000; + cout << min(nnl, min(nslice, nnp)) << endl; + ; + return 0; +} +int main() { + int n, m, min; + cin >> n >> m; + min = n < m ? n : m; + if (min % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; +} +int main() { + int n, k, i, left, right; + cin >> n >> k; + char a[n + 1]; + for (i = 1; i <= n; i++) { cin >> a[i]; } + if (k - 1 < n - k) { + left = k - 1; + while (left > 0) { + cout << "LEFT" << endl; + left--; + } + for (i = 1; i < n; i++) { + cout << "PRINT " << a[i] << endl; + cout << "RIGHT" << endl; + } + cout << "PRINT " << a[n] << endl; + } else { + right = k + 1; + while (right <= n) { + cout << "RIGHT" << endl; + right++; + } + for (i = n; i > 1; i--) { + cout << "PRINT " << a[i] << endl; + cout << "LEFT" << endl; + } + cout << "PRINT " << a[1] << endl; + } +} +const int INF = 0x3f3f3f3f; +inline long long read() { + long long X = 0, w = 0; + char ch = 0; + while (!isdigit(ch)) { + w |= ch == '-'; + ch = getchar(); + } + while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); + return w ? -X : X; +} +inline void write(long long x) { + if (x < 0) putchar('-'), x = -x; + if (x > 9) write(x / 10); + putchar(x % 10 + '0'); +} +const int maxn = 1e6 + 10; +void solve() { + int t; + while (cin >> t) { + int a[101]; + int dp[101][101]; + memset(dp, INF, sizeof(dp)); + dp[0][0] = 0; + for (int i = 1; i <= t; ++i) { + int m; + cin >> m; + dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + 1; + if (m == 1) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + } else if (m == 2) { + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } else if (m == 3) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } + } + cout << min(min(dp[t][1], dp[t][2]), dp[t][0]) << endl; + } +} +int main() { + solve(); + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << b << endl; + else + cout << "1" << endl; +} +int n, x, sum1, sum2, sum3; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (i % 3 == 0) sum3 += x; + if (i % 3 == 1) sum1 += x; + if (i % 3 == 2) sum2 += x; + } + if (sum1 > sum2 && sum1 > sum3) cout << "chest" << endl; + if (sum2 > sum1 && sum2 > sum3) cout << "biceps" << endl; + if (sum3 > sum1 && sum3 > sum2) cout << "back" << endl; + return 0; +} +const int N = 3e5 + 5; +long long n, res, a[N], sum[N]; +void Input() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; +} +void Solve() { + res = sum[n]; + int cnt = 0; + for (int i = 2; i <= n; i++) { + res += a[i - 1]; + res += sum[n] - sum[i - 1]; + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + long long soldier, maximum = 0; + cin >> soldier; + int div = (soldier / 2); + maximum = 3 * div; + cout << maximum << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + char s[300], s1[5]; + cin >> s; + int cnt = 0; + int len = strlen(s); + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { + for (int k = j + 1; k < len; k++) { + s1[0] = s[i]; + s1[1] = s[j]; + s1[2] = s[k]; + s1[3] = '\0'; + if (!strcmp(s1, "QAQ")) { cnt++; } + } + } + } + cout << cnt << endl; + return 0; +} +int main() { + string str; + cin >> str; + int QAQ = 0; + for (int i = 0; i < str.size(); i++) { + for (int j = i + 1; j < str.size(); j++) { + for (int k = j + 1; k < str.size(); k++) { + if (str[i] == 'Q' && str[j] == 'A' && str[k] == 'Q') QAQ++; + } + } + } + cout << QAQ << endl; + return 0; +} +int main() { + long int ans = 99999999; + long int n, m; + long int price[1100]; + int G[110][110] = {0}, l, r; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> price[i]; } + for (int i = 1; i <= m; i++) { + cin >> l >> r; + G[l][r] = G[r][l] = 1; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 1; k <= n; k++) { + if (G[i][j] + G[i][k] + G[k][j] == 3) { + if (ans > price[i] + price[j] + price[k]) ans = price[i] + price[j] + price[k]; + } + } + } + } + if (ans == 99999999) { + cout << -1 << endl; + } else { + cout << ans << endl; + } + return 0; +} +int main() { + int x, y, z; + cin >> x >> y; + z = (y - 1) / x; + z++; + cout << z << endl; + return 0; +} +string s; +int n; +int good(int i) { + if (i + 2 < n && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') return 3; + if (i + 1 < n && s[i] == '1' && s[i + 1] == '4') return 2; + if (i < n && s[i] == '1') return 1; + return 0; +} +int main() { + cin >> s; + n = s.size(); + int i = 0; + while (i < n) { + int ad = good(i); + if (ad == 0) break; + i += ad; + } + puts(i == n ? "YES" : "NO"); + return 0; +} +int main() { + int n; + cin >> n; + cout << n % 2 << endl; +} +int main() { + double k, n, s, p, i, j; + cin >> k >> n >> s >> p; + i = ceil(n / s); + j = i * k; + int l = ceil(j / p); + cout << l << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { cout << (n) / 2 + 1 << endl; } + return 0; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +double l, p, q; +int main() { + cin >> l >> p >> q; + cout << l / (q + p) * p << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m, t; + int a[1005]; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int x = 0; + for (i = n - 1; i >= 0; i--) + if (a[i] < 0) break; + if (i < 0) + x = 0; + else + x = i; + for (i = n - 1; i > x; i--) { + if (sqrt(a[i]) - floor(sqrt(a[i])) > 0.000001) { + cout << a[i] << endl; + break; + } + } + if (i <= x) { cout << a[x] << endl; } +} +int main() { + int n, k, i, temp = 0; + int ar[10]; + ar[0] = 5 * 1; + ar[1] = 5 * 2; + ar[2] = 5 * 3; + ar[3] = 5 * 4; + ar[4] = 5 * 5; + ar[5] = 5 * 6; + ar[6] = 5 * 7; + ar[7] = 5 * 8; + ar[8] = 5 * 9; + ar[9] = 5 * 10; + cin >> n >> k; + k = 4 * 60 - k; + for (i = 0; i < n; i++) { + temp += ar[i]; + if (temp > k) { break; } + } + cout << i << endl; + return 0; +} +long long int mod = 1000000007; +long long int min(long long int a, long long int b) { + if (a > b) { return b; } + return a; +} +int main() { + long long int n, k, x; + cin >> n >> k >> x; + long long int arr[n]; + for (long long int i = 0; i < n; i++) cin >> arr[i]; + long long int ans = 0; + for (long long int i = n - 1; i >= 0; i--) { + if (arr[i] > x) { + if (k > 0) { + ans += x; + k--; + } else { + ans += arr[i]; + } + } else { + ans += arr[i]; + } + } + cout << ans << endl; +} +const double eps = 1e-6; +const int MAXN = 8000; +double a[MAXN]; +int main() { + int n; + cin >> n; + double x; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + double sum = 0; + int num = 0; + for (int i = 0; i < 2 * n; i++) { + x = ((int)a[i] + 1) * 1.0 - a[i]; + if (fabs(x - 1) <= eps) + num++; + else + sum += x; + } + int m = 0; + if (num < n) m = n - num; + double res = 0x3f3f3f3f * 1.0; + for (; m <= min(2 * n - num, n); m++) res = min(res, fabs(sum - m)); + cout << fixed << setprecision(3) << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v1; + int ans; + int count = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + v1.push_back(a); + } + sort(v1.begin(), v1.end()); + ans = v1[v1.end() - v1.begin() - 1] - v1[0]; + for (int i = 0; i < n - 1; i++) { + int a = v1[i + 1] - v1[i]; + if (ans > a) { + ans = a; + count = 1; + } else if (ans == a) { + count += 1; + } + } + cout << ans << " " << count << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long keep = n; + long long gcd = 0; + while (n--) { + long long x; + cin >> x; + gcd = __gcd(gcd, x); + } + cout << keep * gcd << endl; + return 0; +} +int main() { + int n, m, z = 1, f = 3; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 != 0 && i == z && j == m - 1) { + cout << "#"; + z = i + 4; + } else if (i % 2 != 0 && i == f && j == 0) { + cout << "#"; + f = i + 4; + } else if (i % 2 != 0) + cout << "."; + else + cout << "#"; + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n - 1] - a[0] + 1 - n << endl; +} +int main() { + int s, a, b, c; + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + cin >> s >> a >> b >> c; + s /= c; + int x = s / a; + s %= a; + long long res = x * 1LL * (a + b); + res += s; + cout << res << endl; + } + return 0; +} +int main() { + string s; + int pos; + cin >> s; + pos = s.find("."); + if (s[pos - 1] != '9') { + if (s[pos + 1] >= '5') { s[pos - 1] += 1; } + for (int i = 0; i < pos; ++i) cout << s[i]; + cout << endl; + } else { + cout << "GOTO Vasilisa.\n"; + } + return 0; +} +int main() { + int n, a, b; + cin >> n; + for (int i = sqrt(n); i >= 1; i--) { + if (n % i == 0) { + a = i; + break; + } + } + b = n / a; + if (a < b) + cout << a << " " << b << endl; + else + cout << b << " " << a << endl; + return 0; +} +long long a, b, c, p = 1; +bool bo; +int main() { + cin >> a >> b; + if ((0 ^ a) == b) bo = 1; + if ((a - b) % 2 || b > a) { + cout << 0 << "\n"; + return 0; + } + c = (a - b) / 2; + while (b || c) { + if (b % 2 == 1 && c % 2 == 0) { + p *= 2; + } else if (b % 2 == 1 && c % 2 == 1) { + cout << 0 << "\n"; + return 0; + } + b /= 2; + c /= 2; + } + if (bo) { p -= 2; } + cout << p << "\n"; +} +int main() { + string s; + cin >> s; + int k = s.length(); + cout << (k + 1) * 25 + 1 << endl; +} +int main() { + long long a, b, c, d, e, n; + string s; + cin >> s; + n = s.size(); + n = (n + 1) * 26 - n; + cout << n << endl; +} +int main() { + string a; + string b; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a == b) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int main() { + int n, i, k, a, j, h; + cin >> n; + for (i = 1; i <= n; i++) { + k = i; + if (n % k == 0) { + j = h = 0; + while (k != 0) { + a = k % 10; + if (a == 4 || a == 7) { h++; } + k = k / 10; + j++; + } + if (h == j) { + cout << "YES" << endl; + return 0; + } + } + } + cout << "NO" << endl; +} +void solve() { + long long ans = 0, x, y, m; + cin >> x >> y >> m; + if (max(x, y) >= m) { + cout << 0 << '\n'; + return; + } + if (x <= 0 && y <= 0) { + cout << -1 << '\n'; + return; + } + if (x > y) swap(x, y); + if (x < 0) { + long long t = (-x) / y; + x += y * t; + ans += t; + } + while (x < m && y < m) { + if (x > y) swap(x, y); + x += y; + ans++; + } + cout << ans << '\n'; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +int dp[1001][1001]; +int main() { + for (int i = 0; i <= 1000; i++) + for (int j = 0; j <= i; j++) { + if (i == 0 || j == 0) + dp[i][j] = 1; + else + dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % 1000000007; + } + int a; + cin >> a; + vector h; + for (int i = 0; i < a; i++) { + int b; + cin >> b; + h.push_back(b); + } + long long ans = 1; + long long sum = h[0]; + for (int i = 1; i < a; i++) { + sum += h[i]; + ans = (ans * dp[sum - 1][h[i] - 1]) % 1000000007; + } + cout << ans << endl; + return 0; +} +int n, k, a[105], b, Max; +map m; +map mm; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i], m[a[i]]++; + if (k == 0) Max++; + for (int i = 1; i <= k; i++) { + mm[1] = m[1], mm[-1] = m[-1]; + for (int j = i; j <= n; j += k) mm[a[j]]--; + Max = max(Max, abs(mm[1] - mm[-1])); + } + cout << Max << "\n"; +} +int main() { + int n, m; + cin >> n >> m; + int maxi[m] = {0}, count = 0; + char stu[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> stu[i][j]; + if (maxi[j] < (stu[i][j] - '0')) maxi[j] = stu[i][j] - '0'; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (stu[i][j] - '0' >= maxi[j]) { + count++; + break; + } + } + } + cout << count << endl; +} +int main() { + long long n, m; + long long ans = 1; + cin >> n >> m; + if (n >= 27) { + ans = m; + cout << ans << endl; + } else { + for (int i = 0; i < n; i++) { ans = ans * 2; } + ans = m % ans; + cout << ans << endl; + } + return 0; +} +const long long maxn = 1e5 + 5; +long long n, k; +vector fac; +bool isprime(long long x) { + for (long long i = 3; i * i <= x; i += 2) { + if (x % i == 0) return false; + ; + } + return true; +} +int main() { + cin >> n >> k; + while (n != 1) { + bool ok = 0; + for (long long i = 2; i * i <= n; i++) { + if (n % i == 0) { + fac.push_back(i); + n /= i; + ok = 1; + break; + } + } + if (!ok) { + fac.push_back(n); + n = 1; + } + } + if (k > fac.size()) { + cout << -1 << endl; + return 0; + } + for (int i = 0; i < k; i++) { + if (i == k - 1) { + long long s = 1; + for (long long j = k - 1; j < fac.size(); j++) { s *= fac[j]; } + cout << s << endl; + } else + cout << fac[i] << " "; + } + return 0; +} +int main() { + long long n; + cin >> n; + int ans = 0; + string Names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + if (n >= 900000000) + cout << "Penny" << endl; + else { + for (int x = 1; x <= 5; x++) { + long long int a = x; + long long int c = 1; + bool f = 0, stop = 0; + while (a <= 10000000000) { + if (f && stop) { + ans = x; + break; + } + if (!f && stop) break; + for (long long int i = a; i < a + c; i++) { + if (i == n) { + f = 1; + stop = 1; + break; + } + if (i > n) { + f = 0; + stop = 1; + break; + } + } + c *= 2; + a += ((x + 4) * (c / 2)); + } + if (f && stop) break; + } + cout << Names[ans - 1] << endl; + } + return 0; +} +int main() { + long long int n, a[100000], i, j, b[100000], c = 1, f = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + b[0] = a[n - 1]; + for (i = n - 2; i >= 0; i--) { + for (j = 0; j < c; j++) { + if (a[i] == b[j]) { + f = 0; + break; + } else { + f = 1; + } + } + if (f == 1) { + b[c] = a[i]; + c++; + } + } + for (i = c - 1; i >= 0; i--) { + if (b[i] == 0) c--; + } + cout << c << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int s = n * m / gcd(n, m); + cout << k / s << endl; + return 0; +} +int main() { + long long n, k, m; + cin >> n; + k = sqrt(2.0 * n + 0.25) - 0.5; + m = k * (k + 1) / 2; + if (n > m) + cout << n - m << endl; + else + cout << k + n - m << endl; + return 0; +} +int main() { + int x, h, m; + while (cin >> x) { + int ans = 0; + cin >> h >> m; + if (m % 10 == 7 || h % 10 == 7) + cout << "0" << endl; + else { + while (h % 10 != 7 && m % 10 != 7) { + m -= x; + ans++; + if (m < 0) { + m += 60; + h--; + if (h < 0) h += 24; + } + } + cout << ans << endl; + } + } + return 0; +} +int main() { + long long n; + cin >> n; + long long var = n / 2; + long long ans = var * 3; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int k = n / 2; + cout << (2 * n) - k << endl; + return 0; +} +int find_it(string s, string t, int n, int m) { + int a[n + 1][m + 1]; + for (int i = 0; i <= n; i++) { + for (int j = 0; j <= m; j++) { + if (j == 0) { + a[i][j] = 1; + } else if (i == 0) { + a[i][j] = 0; + } else if (s[i - 1] == t[j - 1]) { + a[i][j] = a[i - 1][j] + a[i - 1][j - 1]; + } else + a[i][j] = a[i - 1][j]; + } + } + return a[n][m]; +} +int main() { + string s; + cin >> s; + string t = "QAQ"; + int n = s.size(); + int m = t.size(); + int answer = find_it(s, t, n, m); + cout << answer << "\n"; + return 0; +} +const int size = pow(10, 6) + 1; +const int tsize = 4 * size; +const long long int mod = pow(10, 9) + 7; +long long int sumofdigit(long long int n) { + long long int sum = 0; + while (n > 0) { + sum += n % 10; + n /= 10; + } + return sum; +} +int main() { + long long int n; + cin >> n; + long long int limit = min((long long int)200, n); + set st; + set::iterator it; + for (int i = 1; i <= limit; i++) { + long long int a = n - i; + if (sumofdigit(a) == i) { st.insert(a); } + } + cout << st.size() << "\n"; + for (it = st.begin(); it != st.end(); it++) { cout << *it << "\n"; } +} +const int maxn = 100000; +int num[maxn + 10]; +int main() { + int n; + while (cin >> n) { + int count = 1, flag = 0; + for (int i = 0; i < n; i++) { + cin >> num[i]; + if (num[i] == 0) flag = 1; + } + sort(num, num + n); + int i = 1; + while (i < n) { + if (i < n && num[i] != num[i - 1]) count++; + i++; + } + if (flag) count--; + cout << count << endl; + } +} +int main() { + int n, s = 0, b = 0, r = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (i == 0) + s = a, b = a; + else if (a < s) + s = a, r++; + else if (a > b) + b = a, r++; + } + cout << r << endl; + return 0; +} +int main() { + int n, x; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + int m = *min_element(v.begin(), v.end()); + if (count(v.begin(), v.end(), m) != 1) + cout << "Still Rozdil" << endl; + else { + vector::iterator it = find(v.begin(), v.end(), m); + cout << it - v.begin() + 1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +const long long MOD = int(1e9) + 9; +long long n, m, t, ans; +int main() { + cin >> n >> m; + long long t = 1; + for (int i = 1; i <= m; i++) t = t * 2 % MOD; + t--; + ans = t; + for (int i = 2; i <= n; i++) { + t--; + if (t <= 0) t += MOD; + ans = ans * t % MOD; + } + cout << ans << endl; + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int x, y; + cin >> x >> y; + int g = min(x, y); + int ans = 1; + for (int i = 1; i < g + 1; i += 1) ans = ans * i; + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + char a[n][n]; + int x = n / 2, f = n / 2, d = n / 2, y = 0, k = 1; + for (int i = 0; i < n; i++) { + if (i == n / 2) { + f = 0; + d = n - 1; + y = 1; + } + for (int j = 0; j < n; j++) { + if (j == f || j == d) + a[i][j] = 'D'; + else + a[i][j] = '*'; + } + f++; + d--; + } + for (int i = 1; i < n - 1; i++) { + k = 1; + for (int j = 0; j < n && k != 0; j++) { + if (a[i][j] == 'D') { + j++; + for (j;; j++) { + if (a[i][j] == '*') + a[i][j] = 'D'; + else { + k = 0; + break; + } + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int r = a; + int o = 0; + while (r > 0) { + ++o; + int c = 0; + if (b > k - 1) { + c = k; + b -= (k - 1); + } else { + c = b + 1; + b = 0; + } + r -= v * c; + } + cout << o << endl; + return 0; +} +int k, a, b, v, tot; +int main() { + cin >> k >> a >> b >> v; + for (int i = 1;; i++) { + tot += (min(b + 1, k)) * v; + b -= (min(b, k - 1)); + if (tot >= a) { + cout << i << endl; + return 0; + } + } +} +int main() { + int a, shu = 0; + cin >> a; + while (a > 0) { + if (a % 2 == 1) { shu++; } + a /= 2; + } + cout << shu << endl; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int nak = n / s; + if (n % s != 0) { nak += 1; } + nak *= k; + int ans = nak / p; + if (nak % p != 0) { ans += 1; } + cout << ans << endl; +} +int main() { + double l, p, q; + cin >> l >> p >> q; + cout << l / (p + q) * p << "\n"; + return 0; +} +int main() { + int counter = 1, k = 0; + string s1, s2; + cin >> s1 >> s2; + char c = s1[k]; + for (int x = 0; x < s2.length(); x++) + if (c == s2[x]) { + counter++; + c = s1[++k]; + } + cout << counter << endl; + return 0; +} +const long long MAX = 1e6 + 5; +const long long MOD = 1e9 + 7; +const long long inf = 1e12 + 5; +int main() { + vector sqrs; + for (long long i = 1; i < MAX; i++) sqrs.push_back(i * i); + long long n; + cin >> n; + long long pre = 2; + for (long long i = 1; i < n + 1; i++) { + long long ans = i * (i + 1) * (i + 1); + ans = ans - pre; + pre = (i); + cout << ans << endl; + } + return 0; +} +string s, ss; +int k[26]; +int a[26]; +int main() { + cin >> s >> ss; + int x = s.length(), y = ss.length(); + string s1 = "zzzzzzzzzzzz"; + string s2; + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + s2 = s.substr(0, i + 1) + ss.substr(0, j + 1); + s1 = min(s1, s2); + } + } + cout << s1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[100005]; + int temp = 1; + int ans = -1; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (i == 1) continue; + if (a[i] > a[i - 1]) + temp++; + else { + ans = max(ans, temp); + temp = 1; + } + } + ans = max(ans, temp); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + cin >> a[0]; + int diff = 0; + for (int i = 1; i < n; i++) { + cin >> a[i]; + diff = max(diff, a[i] - a[i - 1]); + } + int m = 100000; + for (int i = 1; i < n - 1; i++) { m = min(a[i + 1] - a[i - 1], m); } + cout << max(diff, m) << endl; +} +int main() { + int r, c, x = 1; + bool v; + cin >> r >> c; + for (int i = 1; i <= r; i++) { + if (i % 2 == 0) v = true; + for (int j = 1; j <= c; j++) { + if (i % 2 == 1) { + cout << '#'; + } else { + if (x % 2 == 1 && j == c && v == true) { + cout << '#'; + x++; + v = false; + } else if (x % 2 == 0 && j == 1 && v == true) { + cout << '#'; + x++; + v = false; + } else { + cout << '.'; + } + } + } + cout << endl; + } + return 0; +} +long long a, b, c; +int main() { + cin >> a >> b >> c; + for (long long i = 0; i <= 1e6; i++) + if (i * b >= (a * c) - (b * c)) { + cout << i << endl; + return 0; + } + return 0; +} +double k, n, s, p; +int main() { + cin >> k >> n >> s >> p; + cout << (long long)ceil(k * ceil(n / s) / p) << endl; +} +const int MAX = 1e6 + 5; +int n, a[2]; +int arr[MAX]; +int main() { + while (cin >> n >> a[0] >> a[1]) { + for (int i = 0; i < n; i++) cin >> arr[i]; + int ans = 0; + for (int i = 0, j = n - 1; i <= j; i++, j--) { + if ((arr[i] ^ arr[j]) == 1) { + ans = -1; + break; + } else if ((arr[i] ^ arr[j]) > 0) { + if (arr[i] < 2) ans += a[arr[i]]; + if (arr[j] < 2) ans += a[arr[j]]; + } else if (arr[i] == 2) { + ans += min(a[0], a[1]) * (i == j ? 1 : 2); + } + } + cout << ans << endl; + } +} +int main() { + int n, a[5], b[5]; + while (cin >> n && n) { + for (int i = 0; i < 3; i++) cin >> a[i] >> b[i]; + int max1, max2, max3; + max1 = min(b[0], n - a[1] - a[2]); + max2 = min(b[1], n - max1 - a[2]); + max3 = n - max1 - max2; + cout << max1 << " " << max2 << " " << max3 << endl; + } + return 0; +} +int arr[2005]; +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i < a; i++) { cin >> arr[i]; } + sort(arr, arr + a); + int mn = arr[c - 1]; + int mx = arr[c] - 1; + cout << max(0, mx - mn + 1) << endl; +} +long long n, l, r, ql, qr, w[100005], sum[100005]; +int main() { + cin >> n >> l >> r >> ql >> qr; + for (int i = 0; i < n; i++) { + cin >> w[i]; + sum[i + 1] = w[i] + sum[i]; + } + long long ans = 1e14; + for (int i = 0; i <= n; i++) { + long long temp = sum[i] * l + (sum[n] - sum[i]) * r; + if (n - i > i) { + temp += (n - i - i - 1) * qr; + } else if (i > n - i) { + temp += (2 * i - n - 1) * ql; + } + ans = min(ans, temp); + } + cout << ans << endl; +} +int main() { + int t, sum = 0, total = 0, c = 0; + cin >> t; + long int a[t + 1]; + for (int i = 0; i < t; i++) { + cin >> a[i]; + total = total + a[i]; + } + sort(a, a + t); + for (int i = t - 1; i >= 0; i--) { + sum = sum + a[i]; + c++; + total = total - a[i]; + if (total < sum) { break; } + } + cout << c << endl; +} +int main() { + long long n, k, x; + long long ans = 0, b; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) { + cin >> b; + if (i >= n - k) { + if (b < x) + ans += b; + else + ans += x; + } else + ans += b; + } + cout << ans << endl; +} +int main() { + int w, h, u, d1, v, d2; + cin >> w >> h >> u >> d1 >> v >> d2; + int max, min, w1, w2; + int res; + if (d1 > d2) { + max = d1; + w1 = u; + w2 = v; + min = d2; + } else { + max = d2; + w1 = v; + w2 = u; + min = d1; + } + res = w + (h * (h + 1)) / 2 - (max * (max - 1)) / 2 - w1; + if (res < 0) res = 0; + res = res + (max * (max - 1)) / 2 - (min * (min - 1)) / 2 - w2; + if (res < 0) res = 0; + res += (min * (min - 1)) / 2; + cout << res << endl; +} +int main() { + int n, i, counter = 0; + long long min = 9223372036854775807; + cin >> n; + int *arr = new int[n]; + for (i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (i = 0; i < n - 1; i++) { + if (arr[i + 1] - arr[i] < min) { + min = arr[i + 1] - arr[i]; + counter = 1; + continue; + } + if (arr[i + 1] - arr[i] == min) counter++; + } + cout << min << " " << counter << endl; + return 0; +} +int main() { + int line, lie; + cin >> line >> lie; + bool flag = true; + for (int i = 1; i <= line; i++) { + if (i % 2 != 0) { + for (int j = 0; j < lie; j++) { cout << "#"; } + cout << endl; + } else { + if (flag) { + for (int j = 0; j < lie; j++) { + if (j == lie - 1) { + cout << "#"; + break; + } + cout << "."; + } + cout << endl; + flag = false; + } else { + for (int j = 0; j < lie; j++) { + if (j == 0) { + cout << "#"; + continue; + } + cout << "."; + } + cout << endl; + flag = true; + } + } + } + return 0; +} +int main() { + ; + int t; + cin >> t; + map c; + while (t--) { + char x; + cin >> x; + if (x == '+') { + string a; + cin >> a; + string r; + for (int i = 0; i < a.length(); ++i) { + if (a[i] != ' ') { r = r + (char)((a[i] - '0') % 2 + '0'); } + } + c[r]++; + } + if (x == '-') { + string a; + cin >> a; + string r; + for (int i = 0; i < a.length(); ++i) { + if (a[i] != ' ') { r = r + (char)((a[i] - '0') % 2 + '0'); } + } + c[r]--; + } + if (x == '?') { + string a; + cin >> a; + long long ans = 0; + while (a[0] == '0') { + if (a.length() == 0) break; + a.erase(0, 1); + } + while (a.length() <= 18) { + ans += c[a]; + a.insert(0, 1, '0'); + } + cout << ans << "\n"; + } + } +} +int main() { + int a, b; + cin >> a >> b; + cout << (abs(b - a) <= 1 && (b != 0 || a != 0) ? "YES\n" : "NO\n"); + return 0; +} +int main() { + int N, M; + cin >> N >> M; + long long p = 1; + long long ans = 1; + for (int i = 1; i <= M; i++) { + p *= 2; + p %= 1000000009; + } + for (int i = 1; i <= N; i++) { + ans *= (p - i); + ans %= 1000000009; + } + if (ans < 0) ans += 1000000009; + cout << ans << endl; +} +int n; +string a[110]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 0; + for (char i = 'a'; i <= 'z'; i++) { + for (char j = 'a'; j <= 'z'; j++) { + int m = 0; + for (int k = 0; k < n; k++) { + int flag = 1; + int len = a[k].size(); + for (int h = 0; h < len; h++) { + if (a[k][h] != i && a[k][h] != j) { + flag = 0; + break; + } + } + if (flag == 1) m += len; + } + ans = max(ans, m); + } + } + cout << ans << endl; + return 0; +} +const int N = 100 * 1000 + 10; +int main() { + int n, cnt = 0; + cin >> n; + int x, y; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > 0) cnt++; + } + if (n - cnt <= 1 or cnt <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + cout << (s % n ? s / n + 1 : s / n) << endl; +} +char a[105][105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> a[i][j]; + } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] == 'C') { + for (int k = 0; k < n && k != j; k++) + if (a[i][k] == 'C') ans++; + for (int k = 0; k < n && k != i; k++) + if (a[k][j] == 'C') ans++; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 != 0) + cout << "1" << endl; + else + cout << "0" << endl; +} +int main() { + int n, sum = 0; + cin >> n; + string a; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == "Tetrahedron") { + sum += 4; + } else if (a == "Cube") { + sum += 6; + } else if (a == "Octahedron") { + sum += 8; + } else if (a == "Dodecahedron") { + sum += 12; + } else if (a == "Icosahedron") { + sum += 20; + } + } + cout << sum << endl; +} +long long n, a[200100], sum; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) sum = sum + a[i]; + long long temp = 0; + for (int i = 1; i <= n; i++) { + temp = temp + a[i]; + if (temp >= (sum - sum / 2)) { + cout << i << endl; + break; + } + } + return 0; +} +int const MAXN = 5005; +string izq(string c) { + string temp = c; + temp[0] = c[3]; + temp[1] = c[5]; + temp[3] = c[1]; + temp[5] = c[0]; + return temp; +} +string abajo(string c) { + string temp = c; + for (int i = 2; i < 5; ++i) swap(temp[i], temp[i + 1]); + return temp; +} +string last(string c) { + string ans = c; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 4; ++k) { + ans = max(ans, c); + c = izq(c); + } + c = abajo(c); + } + c = izq(c); + } + return ans; +} +int main() { + string color; + cin >> color; + sort(color.begin(), color.end()); + set ans; + do { ans.insert(last(color)); } while (next_permutation(color.begin(), color.end())); + cout << ans.size() << '\n'; + return 0; +} +int x, y, n, p, q, a[110], sum = 0, can; +int main() { + cin >> n; + cin >> p; + for (int i = 1; i <= p; i++) { + cin >> x; + a[x] = 1; + } + cin >> q; + for (int i = 1; i <= q; i++) { + cin >> y; + a[y] = 1; + } + can = 1; + for (int i = 1; i <= n; i++) { + if (a[i] == 0) can = 0; + } + if (can == 1) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +int main() { + map map; + set s; + float n, k, m = 0, x; + cin >> n >> k; + for (int i = 0; i < n; ++i) { + cin >> x; + map[x]++; + if (map[x] > m) m = map[x]; + s.insert(x); + } + cout << ceil(m / k) * s.size() * k - n << endl; +} +int main() { + char s[101]; + int n, i, sum8 = 0, sum = 0, total = 0; + cin >> n; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == '8') sum8++; + sum++; + } + if (sum8 >= sum / 11) + total = sum / 11; + else + total = sum8; + cout << total << endl; + return 0; +} +int main() { + int a, b, c, n; + while (cin >> a >> b >> c >> n) { + int res = -1; + if ((a <= n) && (b <= n) && (c <= n)) { + int onlyA = a - c; + int onlyB = b - c; + if ((onlyA >= 0 && onlyB >= 0) && (onlyA + onlyB < n)) { res = n - onlyA - onlyB - c; } + } + if (res == 0) { res = -1; } + cout << res << endl; + } +} +int main() { + int n; + char c[95]; + while (cin >> n) { + int sum1 = 0; + for (int i = 0; i <= n - 1; i++) cin >> c[i]; + for (int i = 0; i <= n - 1; i++) { + if (c[i] == '1') + sum1++; + else { + cout << sum1; + sum1 = 0; + } + } + cout << sum1 << endl; + } + return 0; +} +int main() { + int ara[100][100]; + int i, n, r, z, j, temp, m; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { cin >> ara[i][j]; } + } + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + if (ara[i][j] == 1) { + m = 2 - i; + n = 2 - j; + } + } + } + if (n < 0) { n = n * (-1); } + if (m < 0) { m = m * (-1); } + cout << m + n << endl; + return 0; +} +long long int k, n, a[100000]; +int main() { + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, h, m, ans = 0; + cin >> n >> h >> m; + if (h % 10 == 7 || m % 10 == 7) { + cout << "0" << endl; + } else { + while (h % 10 != 7 && m % 10 != 7) { + m -= n; + ans++; + if (m < 0) { + m += 60; + h--; + if (h < 0) { h += 24; } + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + int arr[10010]; + int ans = 1000000000; + cin >> n; + for (int i = 1; i <= n; i++) cin >> arr[i]; + for (int i = 1; i <= n; i++) { + int x = i; + int cost = 0; + for (int j = 1; j <= n; j++) { + cost += abs(x - j) * arr[j]; + cost += ((j - 1) * arr[j]); + cost += (x - 1) * arr[j]; + cost += (x - 1) * arr[j]; + cost += ((j - 1) * arr[j]); + cost += abs(x - j) * arr[j]; + } + if (cost < ans) { ans = cost; } + } + cout << ans << endl; + return 0; +} +const int MAX = 100001; +int An[MAX], Bn[MAX]; +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) <= 1) { + if (a == 0 && b == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, c, i, cnt = 0, ct = 0, cn = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> m >> c; + if (m > c) { + cnt++; + } else if (m == c) { + cn++; + } else { + ct++; + } + } + if (cnt > ct) { + cout << "Mishka" << endl; + } else if (cnt == ct) { + cout << "Friendship is magic!^^" << endl; + } else { + cout << "Chris" << endl; + } + return 0; +} +int main() { + int i, c, n, a[100], h[100], j; + cin >> n; + for (i = 0; i < n; i++) { cin >> h[i] >> a[i]; } + c = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) + if (h[i] == a[j]) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + while (n--) { + int a; + cin >> a; + sum += abs(a); + } + cout << sum << endl; + return 0; +} +const int maxn = 55; +int a[maxn][maxn]; +int main() { + int n; + int flag = 0; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] != 1) { + int t = 0; + for (int k = 0; k < n; k++) { + for (int z = 0; z < n; z++) { + if (k != j && z != i) { + if (a[i][k] + a[z][j] == a[i][j]) { + t = 1; + break; + } + } + } + if (t == 1) break; + } + if (t == 0) { + flag = 1; + break; + } + } + } + if (flag) break; + } + if (flag == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int main() { + int k, r; + cin >> k >> r; + int num = 0; + for (int i = 1; i <= 1000; i++) { + if ((k - r) % 10 == 0 || k % 10 == 0) { + cout << "1" << endl; + return 0; + } else if ((i * k - r) % 10 == 0) { + num = i; + break; + } else if ((k * i) % 10 == 0) { + num = i; + break; + } + } + if (num != 0) { + cout << num << endl; + } else + cout << r << endl; + return 0; +} +int main() { + long long a, b, m, ans; + cin >> a >> b >> m; + if (a > b) swap(a, b); + if (m <= a || m <= b) + cout << 0 << '\n'; + else if (b <= 0) + cout << -1 << '\n'; + else { + ans = 0; + if (a < 0) { + ans = -a / b; + a += ans * b; + } + while (a < m && b < m) { + ++ans; + a += b; + if (a > b) swap(a, b); + } + cout << ans << '\n'; + } + return 0; +} +int x[105], y[105]; +int main() { + int n, nx, ny; + cin >> n; + memset(x, 0, sizeof x); + memset(y, 0, sizeof y); + nx = 0; + ny = 0; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + if (x[a] == 0) nx++; + if (y[b] == 0) ny++; + y[b]++; + x[a]++; + } + cout << min(nx, ny) << endl; + return 0; +} +int main() { + int x, k = 0, l = 0, p = 0, q = 0, r = 0, s = 0; + cin >> x; + int a[x], b[x]; + for (int i = 0; i < x; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < x; i++) { + for (int j = 0; j < x; j++) { + if (i == j) continue; + if ((a[i] > a[j]) && (b[i] == b[j])) p++; + if ((a[i] < a[j]) && (b[i] == b[j])) q++; + if ((a[i] == a[j]) && (b[i] > b[j])) r++; + if ((a[i] == a[j]) && (b[i] < b[j])) s++; + } + if (p >= 1 && q >= 1 && r >= 1 && s >= 1) l++; + p = 0, q = 0, r = 0, s = 0; + k = 0; + } + cout << l << endl; +} +const int N = 100 + 5; +bool mark[N]; +int main() { + int n, st, en; + cin >> n >> st >> en; + for (int i = 1; i < n; i++) { + int l, r; + cin >> l >> r; + for (int j = l; j < r; j++) mark[j] = true; + } + int ans = 0; + for (int i = st; i < en; i++) ans += !mark[i]; + cout << ans << endl; + return 0; +} +int a[1000001] = {0}; +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + for (int j = 1; j <= t; j++) { + int g; + cin >> g; + if (a[g] == 0) a[g] = 1; + } + } + int flag = 0; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { + flag = 1; + break; + } + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + memset(a, 0, sizeof(a)); + } + return 0; +} +int main() { + int x; + cin >> x; + int tabla[x][x]; + for (int i = 0; i < x; i++) { tabla[0][i] = 1; } + for (int i = 0; i < x; i++) { tabla[i][0] = 1; } + for (int i = 1; i < x; i++) { + for (int a = 1; a < x; a++) { tabla[i][a] = tabla[i - 1][a] + tabla[i][a - 1]; } + } + cout << tabla[x - 1][x - 1] << endl; + return 0; +} +int main() { + int x, y, c = 0, m = 0; + int n; + cin >> n; + while (n--) { + cin >> x >> y; + c -= x; + c += y; + if (c > m) { m = c; } + } + cout << m << endl; + return 0; +} +long long n, a, b; +string str; +int main() { + cin >> n >> str; + for (int i = int(0); i < int(n); i++) { + if (str[i] != '7' && str[i] != '4') return cout << "NO" << '\n', 0; + if (i >= (n) / 2) + str[i] == '7' ? a += 7 : a += 4, cerr << "a" << a << '\n'; + else + str[i] == '7' ? b += 7 : b += 4, cerr << "b" << b << '\n'; + } + cerr << "a" << a << '\n'; + cerr << "b" << b << '\n'; + if (a == b) + return cout << "YES" << '\n', 0; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + long long n, a = 1, b = 1; + cin >> n; + for (long long i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "UL" || s == "DR" || s == "ULDR") a++; + if (s == "UR" || s == "DL" || s == "ULDR") b++; + } + cout << a * b << endl; +} +int main() { + int n, MAX = 0; + cin >> n; + vector a(n), b(n); + for (size_t i = 0; i < n; i++) cin >> a[i]; + for (size_t i = 0; i < n; i++) cin >> b[i]; + for (int l = 0; l < n; ++l) { + int ansa = a[l]; + int ansb = b[l]; + int r = l + 1; + while (r < n) { + ansa |= a[r]; + ansb |= b[r]; + r++; + } + MAX = max(MAX, ansa + ansb); + } + cout << MAX << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + if (n == 0 && m == 0) + cout << "NO" << endl; + else if (abs(n - m) <= 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int maxn = 1; +int t[100005]; +int main() { + int n; + cin >> n; + cin >> t[0]; + int num = 1, sum = 0; + for (int i = 1; i < n; i++) { + cin >> t[i]; + if (t[i] >= t[i - 1]) + num++; + else { + sum = max(sum, num); + num = 1; + } + sum = max(sum, num); + } + if (n == 1) + cout << 1 << endl; + else + cout << sum << endl; + return 0; +} +int main() { + int N; + cin >> N; + int Home[N], Guest[N]; + for (int i = 0; i < N; i++) { cin >> Home[i] >> Guest[i]; } + int Counter = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (Home[i] == Guest[j]) { Counter++; } + } + } + cout << Counter << endl; +} +int main() { + int N; + cin >> N; + long long ans[1000]; + for (int i = 0; i < N; i++) { + long long a, b, k; + cin >> a >> b >> k; + if (k % 2 == 0) { + ans[i] = (a - b) * (k / 2); + } else { + ans[i] = (a - b) * (k / 2); + ans[i] += a; + } + } + for (int i = 0; i < N; i++) cout << ans[i] << endl; +} +bool func(char a, char b) { + if (a + 1 == b - 1) return true; + if (a + 1 == b + 1) return true; + if (a - 1 == b - 1) return true; + if (a - 1 == b + 1) return true; + return false; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0, j = s.size() - 1; i < j; i++, j--) { + if (!func(s[i], s[j])) goto label; + } + cout << "YES" << endl; + continue; + label: + cout << "NO" << endl; + } +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] - '0' >= 5) { + int x = 9 - (s[i] - '0'); + s[i] = x + '0'; + } + if (s[0] == '0') { s[0] = '9'; } + } + cout << s << endl; +} +int main() { + int n; + cin >> n; + vector a(n, 0); + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a.begin(), a.end()); + int mx = a[n / 2] - a[0]; + for (int i = 0; i < n - n / 2; ++i) { mx = min(mx, a[i + n / 2] - a[i]); } + cout << mx << endl; + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + int temp, res = 0; + for (int i = 0; i < n; ++i) { + cin >> temp; + if (temp > b && temp < c) res++; + } + cout << res << endl; + return 0; +} +int main() { + int x; + cin >> x; + int a[x]; + for (int i = 0; i < x; i++) { cin >> a[i]; } + if (x == 1) { + cout << "1" << endl; + return 0; + } + int temp = 0; + for (int i = 0; i < x; i++) { + for (int j = i + 1; j < x; j++) { + if (a[j] < a[i]) { + temp = a[j]; + a[j] = a[i]; + a[i] = temp; + } + } + } + temp = 0; + int sum1 = 0; + int sum2 = 0; + for (int i = x - 1; i >= 0; i--) { + for (int j = 0; j < i; j++) { sum1 = sum1 + a[j]; } + sum2 = sum2 + a[i]; + temp += 1; + if (sum2 > sum1) { + cout << temp << endl; + return 0; + } + sum1 = 0; + } +} +inline void getInt(int *p); +const int maxn = 1000010; +const int inf = 0x3f3f3f3f; +int t; +long long x, y, a, b; +int main() { + cin >> t; + while (t--) { + cin >> x >> y >> a >> b; + long long l = 0; + long long r = 1e9; + long long mid; + long long ans = -1; + while (l <= r) { + mid = (l + r) >> 1; + long long a1 = a * mid - x; + long long a2 = b * mid - y; + if (a1 >= 0 && a2 >= 0 && (a1 <= a2)) { + ans = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + if (ans == -1) { + cout << -1 << endl; + } else { + cout << b * ans - y << endl; + } + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 + ch - '0'; } + } +} +int main() { + int A[15][15]; + int a, b, c, d, e; + while (cin >> a) { + for (b = 0; b < a; b++) { + A[0][b] = 1; + A[b][0] = 1; + } + for (c = 1; c < a; c++) { + for (d = 1; d < a; d++) { A[c][d] = A[c - 1][d] + A[c][d - 1]; } + } + cout << A[a - 1][a - 1] << endl; + } +} +int main() { + int n, i, j, a[11][11]; + for (i = 0; i < 10; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (i = 1; i < 10; i++) { + for (j = 1; j < 10; j++) { a[i][j] = a[i][j - 1] + a[i - 1][j]; } + } + while (cin >> n) { cout << a[n - 1][n - 1] << endl; } +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int ans = 0; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) { ans++; } + } + cout << ans << '\n'; + return 0; +} +char x1, x0, t[4]; +bool check() { + for (int i = 0; i < 4; i++) + if (t[i] == '7') return 1; + return 0; +} +int main() { + int x, cnt = 0; + cin >> x >> t[3] >> t[2] >> t[1] >> t[0]; + x0 = x % 10, x1 = x / 10; + while (!check()) { + t[1] -= x1, t[0] -= x0; + if (t[0] < '0') t[0] += 10, t[1]--; + if (t[1] < '0') t[1] += 6, t[2]--; + if (t[2] < '0') t[2] += 10, t[3]--; + if (t[3] < '0') t[3] = '2', t[2] = '3'; + cnt++; + } + cout << cnt << endl; +} +const int N = 2e5 + 12; +const int INF = 1e9; +const int MOD = 998244353; +int mas[N]; +set ind; +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) > 1 || (!a && !b)) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, arr1[30], arr2[30], i = 0, j = 0; + int count = 0; + cin >> n; + for (i; i < n; i++) cin >> arr1[i] >> arr2[i]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) { + if (arr1[i] == arr2[j]) count++; + } + cout << count << endl; +} +int ck[105][105]; +int main() { + int arr[100005]; + int m, n; + cin >> m >> n; + for (int i = 1; i <= m; i++) cin >> arr[i]; + for (int i = 1; i <= n; i++) { + int u, v; + cin >> u >> v; + ck[u][v] = ck[v][u] = 1; + } + int ans = 1e9; + for (int i = 1; i <= m; i++) { + for (int j = i + 1; j <= m; j++) { + for (int k = j + 1; k <= m; k++) { + if (ck[i][j] && ck[j][k] && ck[k][i]) + if (arr[i] + arr[j] + arr[k] < ans) ans = arr[i] + arr[j] + arr[k]; + } + } + } + if (ans == 1e9) + cout << -1 << endl; + else + cout << ans << endl; + return 0; +} +int main() { + int n; + int cnt = 0; + char s[101][101]; + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) cin >> s[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (s[i][j] == 'C') { + for (int u = i + 1; u <= n; u++) { + if (s[u][j] == 'C') cnt++; + } + for (int v = j + 1; v <= n; v++) { + if (s[i][v] == 'C') cnt++; + } + } + } + } + cout << cnt << endl; +} +int main() { + int a, b; + cin >> a >> b; + if (a > b) swap(a, b); + cout << a << " " << (b - a) / 2 << endl; + return 0; +} +int main() { + string s; + cin >> s; + size_t pos = 0; + while (pos < s.length() && s[pos] != 'h') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'e') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'o') ++pos; + if (pos < s.length()) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int gcd(int, int); +int main() { + int n, m, k, a, b; + cin >> n >> m >> k; + for (; k > 0;) { + a = gcd(n, k); + k = k - a; + if (k == 0) { + cout << '0' << endl; + return 0; + } + if (k < 0) { + cout << '1' << endl; + return 0; + } + b = gcd(m, k); + k = k - b; + if (k == 0) { + cout << '1' << endl; + return 0; + } + if (k < 0) { + cout << '0' << endl; + return 0; + } + } +} +int gcd(int a, int b) { + int m, n, r; + if (a > b) { + m = a; + n = b; + } else { + n = a; + m = b; + } + r = m; + while (r != 0) { + r = n % m; + n = m; + m = r; + } + return n; +} +const int maxn = 110; +int n, k; +int type[maxn], del[maxn]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> type[i]; + int ans = 0; + for (int b = 1; b <= k; b++) { + memset(del, 0, sizeof(int) * (n + 3)); + for (int i = b; i <= n; i += k) del[i] = 1; + int c1 = 0, c2 = 0; + for (int i = 1; i <= n; i++) + if (!del[i]) c1 += (type[i] == 1), c2 += (type[i] == -1); + ans = max(ans, abs(c1 - c2)); + } + cout << ans << endl; +} +int main() { + long long n, m; + cin >> n >> m; + long long x = pow(2, n); + cout << m % x << '\n'; + return 0; +} +const int inf = 0x3f3f3f3f; +const int N = 5050; +int main() { + char a[N]; + int i, j; + cin >> a; + int ans = 0; + for (i = 0; i < strlen(a); i++) { + int l = 0, r = 0; + for (j = i; j < strlen(a); j++) { + if (a[j] == '(') { + l++; + r++; + } + if (a[j] == ')') { + l--; + r--; + } + if (a[j] == '?') { + l++; + r--; + } + if (l < 0) break; + if (r < 0) r += 2; + if (r == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int n, m; +string s; +int main() { + cin >> n >> m >> s; + int v1 = m - 1, v2 = n - m; + if (v1 < v2) { + for (int i = 0; i < v1; ++i) + cout << "LEFT" + << "\n"; + for (int i = 0; i < s.size(); ++i) { + if (i != 0) + cout << "RIGHT" + << "\n"; + cout << "PRINT " << s[i] << "\n"; + } + } else { + for (int i = 0; i < v2; ++i) + cout << "RIGHT" + << "\n"; + for (int i = s.size() - 1; i >= 0; --i) { + cout << "PRINT " << s[i] << "\n"; + if (i != 0) + cout << "LEFT" + << "\n"; + } + } + return 0; +} +int w, h, u1, d1, u2, d2; +int main() { + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + if (d1 < d2) swap(d1, d2), swap(u1, u2); + bool f1 = true, f2 = true; + for (int i = h; i > 0; i--) { + w += i; + if (i == d1) w -= u1; + if (i == d2) w -= u2; + if (w < 0) w = 0; + } + cout << w << endl; + return 0; +} +int main() { + string s1; + cin >> s1; + string s2; + cin >> s2; + if (s1 == s2) { + cout << s1 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int n, m, i, j; + char a[50][50] = {'.'}; + cin >> n >> m; + for (i = 0; i < n; i += 2) + for (j = 0; j < m; j++) a[i][j] = '#'; + for (i = 1; i < n; i += 2) { + for (j = 1; j < m; j++) a[i][j] = '.'; + if (i % 4 == 3) { + a[i][0] = '#'; + a[i][m - 1] = '.'; + } else { + a[i][m - 1] = '#'; + a[i][0] = '.'; + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) cout << a[i][j]; + cout << endl; + } +} +const int INF = 100000000; +int a[150]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int t = a[1]; + a[1] = a[n]; + a[n] = t; + cout << a[1]; + for (int i = 2; i <= n; i++) cout << ' ' << a[i]; + cout << endl; + } + return 0; +} +long long n, k; +int main() { + cin >> n >> k; + long long ans = 0LL; + ans = (n * 2LL) / k + (n * 2LL % k != 0); + ans += (n * 5LL) / k + (n * 5LL % k != 0); + ans += (n * 8LL) / k + (n * 8LL % k != 0); + cout << ans << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + int i; + char ch = 'a'; + int rotations = 0; + for (i = 0; i < s.size(); i++) { + int cur = ch - 'a'; + int target = s[i] - 'a'; + if (cur == target) + continue; + else if (target > cur) { + int x = (target - cur) % 26; + int y = (cur - target + 26) % 26; + rotations += min(x, y); + } else { + int x = (cur - target) % 26; + int y = (target - cur + 26) % 26; + rotations += min(x, y); + } + ch = s[i]; + } + cout << rotations << endl; +} +string ss("QAQ"); +string str; +int dp[125][5]; +int solve(int idx, int cur) { + if (idx == str.size()) return cur == ss.size(); + if (cur == ss.size()) return 1; + int &ret = dp[idx][cur]; + if (~ret) return ret; + ret = 0; + if (str[idx] == ss[cur]) + ret = solve(idx + 1, cur + 1) + solve(idx + 1, cur); + else + ret = solve(idx + 1, cur); + return ret; +} +int main() { + cin >> str; + memset(dp, -1, sizeof dp); + cout << solve(0, 0) << "\n"; + return 0; +} +int const OO = 1e9; +void fast() {} +void file() { + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +int main() { + fast(); + int n, m; + while (cin >> n) { + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + cin >> m; + vector vv(m); + for (int i = 0; i < m; i++) { cin >> vv[i]; } + sort(vv.rbegin(), vv.rend()); + long long an = 0; + int j = 0; + while (j < m) { + for (int c = 0; j < m && c < v[0]; j++, c++) { an += vv[j]; } + j += 2; + } + cout << an << '\n'; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long a[101], sum = 0; + int i, j, k, x, y, b[101][101]; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { b[i][j] = 0; } + } + for (i = 0; i < m; i++) { + cin >> x >> y; + b[x][y] = b[y][x] = 1; + } + for (i = 1; i <= n; i++) { + for (j = i + 1; j <= n; j++) { + for (k = j + 1; k <= n; k++) { + if (b[i][j] == 1 && b[j][k] == 1 && b[i][k] == 1) { + if (sum) { + if ((a[i] + a[j] + a[k]) < sum) sum = (a[i] + a[j] + a[k]); + } else + sum = (a[i] + a[j] + a[k]); + } + } + } + } + if (sum > 0) + cout << sum << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long winner[101]; + for (int i = 1; i <= n; i++) winner[i] = 0; + long long v; + for (int i = 1; i <= m; i++) { + long long wincandidate = 1, maxvote = 0; + for (int j = 1; j <= n; j++) { + cin >> v; + if (maxvote < v) { + wincandidate = j; + maxvote = v; + } + } + winner[wincandidate]++; + } + long long wincandidate = 1, maxvote = 0; + for (int i = 1; i <= n; i++) { + if (maxvote < winner[i]) { + maxvote = winner[i]; + wincandidate = i; + } + } + cout << wincandidate << endl; + return 0; +} +int main() { + string s; + cin >> s; + int sz = s.length(); + int flag = 0; + for (int i = 0; i < sz; i++) { + if (s[i] == '1') { + if (s[i + 1] == '4') { + if (s[i + 2] == '4') { + i = i + 2; + } else { + i = i + 1; + } + } + } else + flag = 1; + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, k, p[51]; + while (cin >> n >> m >> k) { + for (int i = 0; i < n; i++) cin >> p[i]; + sort(p, p + n); + int avai = k, t = n - 1; + while (m > avai && t >= 0) { + avai = p[t] + avai - 1; + t--; + } + if (m <= avai) + cout << n - 1 - t << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + string s, t; + int i, j, k, banyak; + t = "hello"; + cin >> s; + i = 0; + k = 0; + while ((k < t.length()) && (i < s.length())) { + if (s[i] == t[k]) { + j = i; + if ((s[i] == 'l') && (k == 2)) { banyak = 0; } + while (s[j] == s[i]) { + j++; + if ((s[i] == 'l') && (k == 2)) { banyak++; } + } + if ((s[i] == 'l') && (k == 2) && ((banyak >= 2))) { + k += 2; + } else { + k++; + } + i = j; + } else { + i++; + } + } + if (k == t.length()) { + cout << "YES"; + } else { + cout << "NO"; + } + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + string s; + while (n--) { + cin >> s; + if (s[0] == 'T') ans += 4; + if (s[0] == 'C') ans += 6; + if (s[0] == 'O') ans += 8; + if (s[0] == 'D') ans += 12; + if (s[0] == 'I') ans += 20; + } + cout << ans << endl; +} +int lucky(int n) { + int res = 0; + while (n != 0) { + if (n % 10 == 4 || n % 10 == 7) res++; + n /= 10; + } + return res; +} +int main() { + int n, k, x; + cin >> n >> k; + int cnt = 0; + for (int i = 0; i < n; i++) { + cin >> x; + if (lucky(x) <= k) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, h, m, t = -1, c = 0, res = 1; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> h >> m; + int t0 = h * 60 + m; + c = t0 == t ? c + 1 : 1; + if (c > res) res = c; + t = t0; + } + cout << res << endl; + return 0; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +int main() { + int n; + cin >> n; + int a[n], count = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int max = *max_element(a, a + n); + for (int i = 0; i < n; i++) { count += max - a[i]; } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n - 1; i++) { + int x; + cin >> x; + v[x - 1] = 1; + } + for (int i = 0; i < n; i++) { + if (!v[i]) cout << i + 1 << endl; + } + return 0; +} +int main() { + long long p; + cin >> p; + long long c, ct = 1; + long long i; + for (i = 2; i < p; i++) { + long long k; + bool f = 0; + int gg = 1; + for (k = 1;; k++) { + if (i % k == 0 && (p - 1) % k == 0) { + gg = k; + } else { + } + if ((k == i) || (k == (p - 1))) { break; } + } + if (gg == 1) { ct++; } + } + cout << ct << endl; + return 0; +} +int main() { + int k, n, i, j, m; + int dp[11]; + cin >> n >> k; + int cnt = 0; + for (i = 0; i < n; i++) { + memset(dp, 0, sizeof(dp)); + cin >> m; + if (m == 0) { + if (k == 0) cnt++; + continue; + } + while (m) { + dp[m % 10] = 1; + m /= 10; + } + for (j = 0; j <= k; j++) { + if (!dp[j]) { break; } + } + if (j == k + 1) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int r[n], d[n - 1], s = 0, m = 1000; + cin >> r[0]; + for (int i = 1; i < n; i++) { + cin >> r[i]; + d[i] = r[i] - r[i - 1]; + s = max(s, d[i]); + } + for (int i = 2; i < n; i++) m = max(min(m, d[i] + d[i - 1]), s); + cout << m << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + vector arr; + map mymap; + arr = vector(n, 0); + for (long long int i = 0; i < n; i++) cin >> arr[i]; + sort(arr.begin(), arr.end()); + long long int res = 1000000000000; + mymap[arr[0]]++; + for (long long int i = 1; i < n; i++) { + mymap[arr[i]]++; + res = min(res, abs(arr[i] - arr[i - 1])); + } + cout << res << " "; + long long int aux = 0; + for (long long int i = 0; i < n; i++) { + long long int k = arr[i]; + long long int a = k + res; + long long int b = k - res; + aux += (mymap[k] * mymap[a]); + aux += mymap[k] * mymap[b]; + } + cout << aux / 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + while (n--) { + int a, b, c, d; + cin >> a >> b >> c >> d; + sum += (c - a + 1) * (d - b + 1); + } + cout << sum << endl; + return 0; +} +int main() { + string a; + cin >> a; + int b = a.size(), i = (b / 2); + if (a.size() > 1) { + sort(a.begin(), a.end()); + for (; i < b; i++) { + if (i + 1 < b) { + cout << a[i] << "+"; + } else { + cout << a[i] << "\n"; + } + } + } else { + cout << a << "\n"; + } + return 0; +} +char s[300005]; +int main() { + int n, x, y; + cin >> n >> x >> y; + cin >> s; + int p = 0; + for (int i = 0; i < n; i++) + if (s[i] == '0') p++; + if (p == 0) { + cout << "0" << endl; + return 0; + } + long long ans = 0; + if (x >= y) { + for (int i = 1; i < n; i++) { + if (s[i - 1] == '0' && s[i] == '1') ans += y; + } + if (s[n - 1] == '0') ans += y; + cout << ans << endl; + return 0; + } else { + if (s[0] == '0') + p = 1; + else + p = 0; + for (int i = 1; i < n; i++) + if (s[i] == '0') { + p++; + if (p > 1 && s[i - 1] == '1') ans += x; + } + ans += y; + cout << ans << endl; + return 0; + } + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int s = n; + while (n / m) { + s += n / m; + n = n / m + n % m; + } + cout << s << endl; + } +} +int main() { + long long int t, j, n, m, ck = 0, i, a = 0, b = 0; + cin >> n >> a; + long long int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + for (i = 0; i < n; i++) { + if (a % arr[i] == 0) { ck = (a / arr[i]); } + } + cout << ck << endl; +} +int main() { + long long a, ca, aa, num2 = 0; + cin >> a; + bool sw = true; + ca = a; + while (sw) { + ca += 1; + aa = ca; + while (aa != 0) { + if (aa % 10 == 8 || aa % 10 == -8) { + sw = false; + num2 = ca; + break; + } + aa /= 10; + } + } + cout << num2 - a << endl; + return 0; +} +int main() { + string s; + while (cin >> s) { + int len = s.length(); + cout << (len + 1) * 26 - len << endl; + } + return 0; +} +int main() { + int n, t, i, ch = 1; + cin >> n >> t; + int p[n - 1]; + for (i = 0; i < (n - 1); i++) { cin >> p[i]; } + for (i = 0; i < (n - 1);) { + i = i + p[i]; + if (i == (t - 1)) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int a[10005]; +int main() { + int n, m, d = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m; + a[m]++; + } + for (int j = 0; j < 10000; j++) { + if (a[j] > d) { d = a[j]; } + } + cout << d << endl; + return 0; +} +int main() { + int k, l, m, n; + long long int d; + cin >> k >> l >> m >> n >> d; + int arr[d]; + memset(arr, 0, sizeof(arr)); + for (long long int i = k - 1; i < d; i += k) { arr[i] = 1; } + for (long long int i = l - 1; i < d; i += l) { arr[i] = 1; } + for (long long int i = m - 1; i < d; i += m) { arr[i] = 1; } + for (long long int i = n - 1; i < d; i += n) { arr[i] = 1; } + long long int count = 0; + for (long long int i = 0; i < d; i++) { + if (arr[i] == 1) { count++; } + } + cout << count << "\n"; +} +bool cmp(const long long &a, long long &b) { + return a < b; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int flag = 0; + for (int i = 0; a * i <= c; i++) { + if ((c - a * i) % b == 0) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } +} +int main() { + string string1, string2; + cin >> string1 >> string2; + for (size_t i = 0; i < string1.length(); i++) { + if (string1[i] == string2[i]) { + string1[i] = '0'; + } else { + string1[i] = '1'; + } + } + cout << string1 << endl; + return 0; +} +int main() { + char card[100]; + char suit, rank; + suit = getchar(); + rank = getchar(); + getchar(); + gets(card); + int flag = 0; + for (int i = 0; i < 14; i += 3) + if (suit == card[i]) { + flag = 1; + break; + } + if (flag == 0) + for (int i = 1; i < 14; i += 3) + if (rank == card[i]) { + flag = 1; + break; + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, k, l, c, d, nl, np, p, ans; +int main() { + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + l = k * l; + l = l / (nl); + c = c * d; + p = p / np; + ans = min(l, c); + ans = min(ans, p); + ans /= n; + cout << ans << endl; + return 0; +} +map mp; +string my = "Bulbasaur"; +int main() { + string s; + cin >> s; + for (string::iterator it = s.begin(); it != s.end(); ++it) { mp[*it]++; } + mp['a'] /= 2; + mp['u'] /= 2; + int ans = 100000; + for (string::iterator it = my.begin(); it != my.end(); ++it) { ans = min(ans, mp[*it]); } + cout << ans << endl; + return 0; +} +int main() { + int a; + for (int i = 1; i <= 5; i++) + for (int j = 1; j <= 5; j++) { + cin >> a; + if (a == 1) cout << (abs(3 - i) + abs(3 - j)) << endl; + } +} +int ranki(string s) { + if (s[0] == 'A') { return 1; } + if (s[0] == 'K') { return 2; } + if (s[0] == 'Q') { return 3; } + if (s[0] == 'J') { return 4; } + if (s[0] == 'A') { return 5; } + if (s[0] == 'T') { return 6; } + if (s[0] == '9') { return 7; } + if (s[0] == '8') { return 8; } + if (s[0] == '7') { return 9; } + if (s[0] == '6') { return 10; } +} +int main() { + string str; + cin >> str; + string str1, str2; + cin >> str1 >> str2; + if (str1[1] == str2[1]) { + if (ranki(str1) < ranki(str2)) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + } + if (str1[1] == str[0] && str2[1] != str[0]) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; +} +int main() { + int s, a1, a2, b1, b2; + cin >> s >> a1 >> a2 >> b1 >> b2; + if (s * a1 + 2 * b1 == s * a2 + 2 * b2) { + cout << "Friendship" << endl; + } else if (s * a1 + 2 * b1 < s * a2 + 2 * b2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + return 0; +} +float find_max(float p, float t) { + return max(((3 * p) / 10), (p - ((p / 250) * t))); +} +int main() { + for (;;) { + float a, b, c, d; + cin >> a >> b >> c >> d; + if (find_max(a, c) > find_max(b, d)) + cout << "Misha" << endl; + else if (find_max(a, c) < find_max(b, d)) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + break; + } +} +bool mf(int i, int j) { + return i < j; +} +int main() { + int n; + cin >> n; + int count = 1, tr = 0; + for (int i = 0; i <= n / 2; i++) { + for (int j = 0; j < (n / 2) - i; j++) cout << '*'; + for (int j = (n / 2) - i; j <= (n / 2) + i; j++) cout << 'D'; + for (int j = (n / 2) + i + 1; j < n; j++) cout << '*'; + cout << endl; + } + for (int i = (n / 2) - 1; i >= 0; i--) { + for (int j = 0; j < (n / 2) - i; j++) cout << '*'; + for (int j = (n / 2) - i; j <= (n / 2) + i; j++) cout << 'D'; + for (int j = (n / 2) + i + 1; j < n; j++) cout << '*'; + cout << endl; + } +} +int main() { + int n; + cin >> n; + int inches = n / 3; + if (n % 3 == 2) inches += 1; + cout << inches / 12 << " " << inches % 12 << endl; +} +int a[150000], b[150000]; +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; + int min = b[0], sum = 0; + for (int i = 0; i < n; ++i) { + if (b[i] < min) min = b[i]; + sum += a[i] * min; + } + cout << sum << endl; + } + return 0; +} +int main() { + int t, s, q; + int cnt = 0; + cin >> t >> s >> q; + while (s < t) { + s = s * q; + cnt++; + } + cout << cnt << endl; + return 0; +} +const int N = 1e6; +int n, m; +int mx, mn; +int main() { + cin >> n >> m; + if (n == 0 && m > 0) { + cout << "Impossible" << endl; + return 0; + } + if (m == 0) { + cout << n << " " << n << endl; + return 0; + } + mx = n + m - 1; + if (n >= m) + mn = n; + else + mn = m; + cout << mn << " " << mx << endl; + return 0; +} +int n, s, a[150], ans = 0; +int main() { + cin >> n >> s; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int j = n - 1; j >= 0; j--) + if (s >= a[j]) { + ans++; + a[j] = 2147483647; + } else + break; + for (int u = 0; u <= n; u++) { + if (s >= a[u]) + ans++; + else { + cout << ans << endl; + return 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d, x = 0, v = 0; + cin >> n >> t >> k >> d; + if (k > n) + cout << "NO" << endl; + else { + while (n > k) { + n -= k; + x += t; + } + if (n > 0) x += t; + v = t + d; + if (v < x) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string a; + cin >> a; + if (n / 2 < k) { + for (int j = k; j < n; j++) { cout << "RIGHT\n"; } + for (int j = n - 1; j >= 0; j--) { + cout << "PRINT " << a[j] << "\n"; + if (j != 0) cout << "LEFT\n"; + } + } else { + for (int j = k; j > 1; j--) { cout << "LEFT\n"; } + for (int j = 0; j < n; j++) { + cout << "PRINT " << a[j] << "\n"; + if (j != n - 1) cout << "RIGHT\n"; + } + } +} +string str; +int n, a, b, capacity = 0, total = 0; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + total -= a; + total += b; + capacity = max(capacity, total); + } + cout << capacity << endl; + return 0; +} +void swp(int &x, int &y) { + int z = max(x, y); + y = min(x, y); + x = z; +} +int main() { + int n, a, b; + cin >> n; + while (n--) { + cin >> a >> b; + int k = 0; + while (a > 0 && b > 0) { + swp(a, b); + k += (a / b); + a -= ((a / b) * b); + } + cout << k << '\n'; + } +} +int main() { + cout << "Karen" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int total = ceil((double)(a * c) / b); + int wait = total - c; + if (wait < 0) { + cout << 0 << endl; + } else { + cout << wait << endl; + } + return 0; +} +long long int M = 100000000000000; +long long int M1 = 1000000007; +int main() { + long long int n, i, x, ans; + cin >> n; + vector v(n); + for (i = 0; i < n; i++) cin >> v[i]; + sort(v.begin(), v.end()); + ans = v[n - 1] * n; + x = n; + for (i = n - 2; i >= 0; i--) { + ans += v[i] * x; + x--; + } + cout << ans << endl; +} +int D[256][256]; +int main() { + D[int('R')][int('S')] = 1; + D[int('S')][int('P')] = 1; + D[int('P')][int('R')] = 1; + int n, a, b; + string A, B; + cin >> n >> A >> B; + a = A.size(); + b = B.size(); + int ar = 0, br = 0; + int am = 0, bm = 0; + for (int i = 0; i < n % (a * b); ++i) { + char aa = A[i % a]; + char bb = B[i % b]; + ar += D[int(bb)][int(aa)]; + br += D[int(aa)][int(bb)]; + } + for (int i = 0; i < (a * b); ++i) { + char aa = A[i % a]; + char bb = B[i % b]; + am += D[int(bb)][int(aa)]; + bm += D[int(aa)][int(bb)]; + } + cout << ar + n / a / b * am << ' ' << br + n / a / b * bm << endl; + return 0; +} +int n, m, bj[1005], x; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> x; + bj[x]++; + } + sort(bj + 1, bj + n + 1); + cout << bj[1] << endl; + return 0; +} +int n; +bool check(int u, int v) { + int s = u; + while (u > 0) { + s += u % 10; + u /= 10; + } + return (s == v); +} +int main() { + cin >> n; + vector v; + for (int i = max(0, n - 1000); i <= n; i++) + if (check(i, n)) v.push_back(i); + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +void selectionSorting(int a[], int s); +int numberofm(int a[], int t); +int main() { + int k, a[12]; + cin >> k; + if (k == 0) + cout << 0 << endl; + else { + for (int i = 0; i < 12; i++) cin >> a[i]; + selectionSorting(a, 12); + cout << numberofm(a, k) << endl; + } + return 0; +} +void selectionSorting(int a[], int s) { + int min, temp; + for (int i = 0; i < s; i++) { + min = i; + for (int j = i + 1; j < s; j++) { + if (a[j] > a[min]) { min = j; } + } + temp = a[i]; + a[i] = a[min]; + a[min] = temp; + } +} +int numberofm(int a[], int t) { + int l = 0, p = 0; + while (l < t && p < 12) { l = l + a[p++]; } + if (l < t) + return -1; + else + return p; +} +int main() { + int n; + set s; + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (x != 0) { s.insert(x); } + } + cout << s.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n++) { + int a, b, c, d; + a = n % 10; + b = n % 100 / 10; + c = n % 1000 / 100; + d = n / 1000; + if (a != b && a != c && a != d && b != c && b != d && c != d) { + cout << n << endl; + return 0; + } + } + return 0; +} +int main() { + int t; + cin >> t; + bool flag = 1; + int a = 0; + int p1 = 1; + int p2 = 2; + int spec = 3; + for (int i = 0; i < t; i++) { + cin >> a; + int op1 = p1; + int op2 = p2; + if (a == p1 || a == p2) { + p1 = a; + p2 = spec; + if (a == op1) { spec = op2; } + if (a == op2) { spec = op1; } + } else { + flag = 0; + break; + } + } + if (flag == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int n, mx, i, j, x, a[105]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + for (i = 1; i <= n; i++) { + x = a[i]; + if (x > mx) mx = x; + for (j = i + 1; j <= n; j++) { + x = x ^ a[j]; + if (x > mx) mx = x; + } + } + cout << mx << endl; + return 0; +} +int n; +string s; +bool isVowel(char c) { + return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; +} +int main() { + cin >> n; + cin >> s; + cout << s[0]; + if ((int)s.size() == 1) { + cout << '\n'; + return 0; + } + for (int i = 1; i <= (int)s.size() - 1; i += 1) { + if (isVowel(s[i]) && isVowel(s[i - 1])) continue; + cout << s[i]; + } + cout << '\n'; + return 0; +} +const int maxn = 1e5 + 10; +int main() { + int n, x; + while (cin >> n >> x) { + n %= 6; + for (int i = 0; i < 3; i++) { + int a[3] = {0}; + a[i] = 1; + for (int j = 1; j <= n; j++) { + if (j % 2 == 0) + swap(a[1], a[2]); + else + swap(a[0], a[1]); + } + if (a[x] == 1) { + cout << i << endl; + break; + } + } + } + return 0; +} +const int oo = 1e9; +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = b * c + (a - 1) * (b + c - 1); + cout << ans << '\n'; + return 0; +} +int a[5][5]; +int off_or_on(int i, int j) { + if (a[i][j] == 1) + return 0; + else + return 1; +} +int main() { + for (int i = 0; i < 5; i++) + for (int j = 0; j < 5; j++) a[i][j] = 1; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + int t; + cin >> t; + if (t % 2 != 0) { + a[i][j] = off_or_on(i, j); + a[i + 1][j] = off_or_on(i + 1, j); + a[i - 1][j] = off_or_on(i - 1, j); + a[i][j + 1] = off_or_on(i, j + 1); + a[i][j - 1] = off_or_on(i, j - 1); + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) cout << a[i][j]; + cout << "\n"; + } + return 0; +} +int n, k, ai, cnt = 0; +bool ada[10]; +bool valid(int x) { + for (int i = 0; i <= k; i++) { ada[i] = 0; } + while (x) { + ada[x % 10] = 1; + x = x / 10; + } + for (int i = 0; i <= k; i++) { + if (!ada[i]) { return 0; } + } + return 1; +} +int main() { + cin >> n >> k; + while (n--) { + cin >> ai; + if (valid(ai)) { cnt++; } + } + cout << cnt << '\n'; + return 0; +} +int main() { + int t, n, r, k; + int q[5]; + cin >> t; + for (int i = 0; i < t; i++) { + k = 0; + cin >> n >> r; + for (int j = 0; j < n - 1; j++) { + cin >> q[j]; + k = k + q[j]; + } + cout << ((r - k) % n + n) % n + 1 << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int L, v, l, r; + cin >> L >> v >> l >> r; + int a = r / v - l / v; + if (l % v == 0) a++; + cout << L / v - a << endl; + } +} +int p[4], a, b, ans; +int main() { + for (int i = 0; i < 4; ++i) cin >> p[i]; + cin >> a >> b; + ans = b - a + 1; + for (int i = a; i <= b; ++i) { + for (int j = 0; j < 4; ++j) { + if (i < p[j]) continue; + --ans; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int prev, next, cnt = 0; + cin >> prev; + int total_cnt = 0; + if (prev) { + total_cnt = 1; + for (int i = 1; i < n; i++) { + cin >> next; + if (!next) break; + if (prev != next) { + if (total_cnt + 1 > k) break; + } + total_cnt++; + prev = next; + } + } + cout << total_cnt << endl; + return 0; +} +const int N = 105; +string a[N], b[N]; +map A, B; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + for (int i = 0; i < n; i++) { + A[a[i]]++; + B[b[i]]++; + } + map::iterator it; + int ans = n; + for (it = A.begin(); it != A.end(); it++) ans -= min(it->second, B[it->first]); + cout << ans << endl; + return 0; +} +const long long int INF = (1LL << 60) - 1; +const long long int MAX = 998244353; +long long int fast_exp(long long int base, long long int exp, long long int m) { + long long int res = 1; + while (exp > 0) { + if (exp % 2 == 1) { res = (res * base) % m; } + base = (base * base) % m; + exp /= 2; + } + return res % m; +} +int main() { + string s; + int k, cnt = 0; + cin >> s >> k; + int freq[26] = {0}; + int n = s.length(); + for (int i = 0; i < n; i++) { freq[s[i] - 'a']++; } + for (int i = 0; i < 26; i++) { + if (freq[i]) { cnt++; } + } + if (cnt >= k) { + cout << 0 << endl; + return 0; + } + if (n < k) { + cout << "impossible" << endl; + return 0; + } + cout << k - cnt << endl; + return 0; +} +int main() { + int n, a[5]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +long long int n, m; +int main() { + cin >> n >> m; + long long int c = 0; + for (long long int i = 0; i <= 1000; i++) { + for (long long int j = 0; j <= 1000; j++) { + if (i * i + j == n && i + j * j == m) { c++; } + } + } + cout << c << "\n"; + return 0; +} +string s; +int cs; +int main() { + string s; + int n, length; + cin >> n; + while (n--) { + cin >> s; + length = s.size(); + if (length > 10) + cout << s[0] << length - 2 << s[length - 1] << "\n"; + else + cout << s << "\n"; + } + return 0; +} +int main() { + int n, k, location; + cin >> n >> k; + char line[110]; + for (int i = 0; i < n; i++) { + cin >> line[i]; + if (line[i] == 'G') location = i; + } + int left = location, right = location; + bool flag = false; + while (left >= 0) { + left -= k; + if (left >= 0) { + if (line[left] == 'T') { + flag = true; + break; + } else if (line[left] == '#') + break; + } + } + if (!flag) { + while (right < n) { + right += k; + if (right < n) { + if (line[right] == 'T') { + flag = true; + break; + } else if (line[right] == '#') + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int maxn = 100005; +int n, k, S, T; +int N[1000], vis[1000] = {0}; +int BFS(int s); +int main() { + memset(vis, 0, sizeof(vis)); + cin >> n >> k; + char str[1000]; + cin >> str; + for (int i = 0; i < n; i++) { + if (str[i] == '#') + N[i] = 0; + else + N[i] = 1; + if (str[i] == 'G') + S = i; + else if (str[i] == 'T') + T = i; + } + int flag = 0; + if (S < T) { + for (int i = S; i < n; i += k) { + if (!N[i]) break; + if (i == T) { + flag = 1; + break; + } + } + } else { + for (int i = S; i >= 0; i -= k) { + if (!N[i]) break; + if (i == T) { + flag = 1; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long n, k; +int main() { + cin >> n >> k; + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int v[n + 1]; + for (int i = 0; i < n; i++) cin >> v[i]; + bool check = true; + int ans = 0; + for (int i = 0; i < n / 2 && check; i++) { + if (v[i] == 2 && v[n - i - 1] == 2) { + ans += 2 * min(a, b); + } else if (v[i] == 2) { + ans += v[n - i - 1] == 0 ? a : b; + } else if (v[n - i - 1] == 2) { + ans += v[i] == 0 ? a : b; + } else { + check = (v[i] == v[n - i - 1]); + } + } + if (n % 2 == 1 && v[n / 2] == 2) { ans += min(a, b); } + if (!check) { ans = -1; } + cout << ans << endl; +} +int main() { + int pos, l, r, n; + cin >> pos >> l >> r >> n; + int ans = 0; + l = l + 1, r = r - 1; + for (int i = 1; i <= n; i++) { + int v; + cin >> v; + if (v >= l && v <= r) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int time1 = 0, time2 = 0; + time1 = t * ((n + k - 1) / k); + int oven1 = 0, oven2 = -1 * d; + while (n > 0) { + time2++; + oven1++; + oven2++; + if (oven1 == t) { + oven1 = 0; + n -= k; + } + if (oven2 == t) { + oven2 = 0; + n -= k; + } + } + if (time1 <= time2) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +const int MAXN = 2200; +int n; +int q[MAXN]; +int fpow(int a, int x) { + int rtn = 1; + for (; x; x >>= 1, a = 1ll * a * a % n) + if (x & 1) rtn = 1ll * rtn * a % n; + return rtn; +} +int main() { + cin >> n; + int top = 0; + int ans = 0; + for (int i = 2; i < n; i++) { + bool p = 1; + for (int j = 1; j < n - 1 && p; j++) + if (fpow(i, j) == 1) p = 0; + if (p) ans++; + } + if (n == 2) ans++; + cout << ans << endl; + return 0; +} +const long long int INF = (1LL << 60) - 1; +const long long int MAX = 2000001; +long long int fast_exp(long long int base, long long int exp, long long int m) { + long long int res = 1; + while (exp > 0) { + if (exp % 2 == 1) { res = (res * base) % m; } + base = (base * base) % m; + exp /= 2; + } + return res % m; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int bottle = 0, towel = 0; + towel = p * n; + while (n > 1) { + int k = 1; + while (k <= n) { k *= 2; } + k /= 2; + n = (n - k) + k / 2; + bottle += (k / 2) * (2 * b + 1); + } + cout << bottle << " " << towel << endl; + return 0; +} +int main() { + int n, a[1001], ans = 1000; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 1; i < n - 1; i++) { + int max = 0, tmp = a[i]; + a[i] = a[i - 1]; + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] > max) { max = a[i] - a[i - 1]; } + } + a[i] = tmp; + if (ans > max) ans = max; + } + cout << ans << endl; +} +int n, a[35][35]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int t1, t2; + t1 = t2 = 0; + for (int k = 0; k < n; k++) t1 += a[k][j], t2 += a[i][k]; + if (t1 > t2) ++ans; + } + } + cout << ans << endl; + return 0; +} +int main() { + int N; + cin >> N; + int a[1005], b[1005]; + for (int i = 0; i < N; ++i) cin >> a[i]; + for (int i = 0; i < N; ++i) cin >> b[i]; + int temp1 = a[0], temp2 = b[0]; + for (int i = 0; i < N; ++i) { + temp1 |= a[i]; + temp2 |= b[i]; + } + cout << temp1 + temp2 << endl; +} +int main() { + int a, b, n = 0; + cin >> a >> b; + while (a) { + n++; + if (!(n % b)) a++; + a--; + } + cout << n << '\n'; + return 0; +} +int main() { + int m, mn = 1e9; + cin >> m; + for (int i = 0; i < m; ++i) { + int k; + cin >> k; + mn = min(mn, k); + } + int n; + cin >> n; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + sort(V.begin(), V.end(), greater()); + long long cur = 0, cnt = 1; + for (int i = 0; i < n; ++i) { + cur += V[i]; + if (cnt == mn) { + i += 2; + cnt = 1; + } else + cnt++; + } + cout << cur << "\n"; + return 0; +} +long long a, b, i; +int main() { + int flag = 0; + cin >> a; + for (i = a + 1; i < 10000000050; i++) { + b = i; + while (b) { + if (abs(b % 10) == 8) { + cout << i - a << endl; + flag = 1; + break; + } + b /= 10; + } + if (flag) break; + } + return 0; +} +int main() { + int n{}, b{}, d{}, a{}, c{}, c2{}; + cin >> n >> b >> d; + while (n--) { + cin >> a; + if (a <= b) { c += a; }; + if (c > d) { + c2++; + c = 0; + } + } + cout << c2 << endl; + return 0; +} +int main() { + string s; + int f; + cin >> s; + f = (s.size() + 1) * 26; + cout << f - s.size() << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << a * b + b * c + c * a - (a + b + c) + 1 << endl; + return 0; +} +int main() { + char a[110][110]; + int n, m, max, s, k, l; + int check[101] = {0}, check1[101] = {0}; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) { + max = 1; + for (int j = 1; j <= n; j++) { + if (a[j][i] > a[max][i]) { + max = j; + memset(check1, 0, sizeof(check1)); + check1[max] = 1; + } + if (a[j][i] == a[max][i]) check1[j] = 1; + } + for (int j = 1; j <= n; j++) + if (check1[j]) check[j]++; + memset(check1, 0, sizeof(check1)); + } + s = 0; + for (int i = 1; i <= n; i++) + if (check[i]) s++; + cout << s << endl; + return 0; +} +long n; +string a[6]; +int main() { + cin >> n; + long num = 0; + long cnt = 0; + long t = 0; + for (long l = 0; l < n; l++) { + if (t < n) { + t += pow(2, l) * 5; + cnt++; + } else + break; + } + long m = 0; + cnt--; + for (long j = 0; j < cnt; j++) { m += pow(2, j) * 5; } + if (cnt == 0) { + num = n - 1; + } else { + for (int i = 0; i < 5; i++) { + if ((n - m) >= i * pow(2, cnt) && (n - m) < (i + 1) * pow(2, cnt)) { + num = i; + break; + } + } + } + a[0] = "Sheldon"; + a[1] = "Leonard"; + a[2] = "Penny"; + a[3] = "Rajesh"; + a[4] = "Howard"; + cout << a[num] << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector vec(n); + for (long long i = 0; i < n; i++) { cin >> vec[i]; } + sort(vec.begin(), vec.end()); + long long min = abs(vec[1] - vec[0]), counter = 1; + for (long long i = 1; i < n - 1; i++) { + if (min > abs(vec[i] - vec[i + 1])) { + min = abs(vec[i] - vec[i + 1]); + counter = 1; + } else { + if (min == abs(vec[i] - vec[i + 1])) counter++; + } + } + cout << min << " " << counter << endl; + return 0; +} +int main() { + string s; + cin >> s; + for (int i = 1; i <= s.size(); i++) + if (s[i - 1] == 'r') cout << i << "\n"; + for (int i = s.size(); i >= 1; i--) + if (s[i - 1] == 'l') cout << i << "\n"; +} +int main() { + int p1, p2, p3, p4, a, b; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + int sum = 0; + for (int i = a; i <= b; i++) { + if (i % p1 == i && i % p2 == i && i % p3 == i && i % p4 == i) { sum++; } + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long a[n + 1], b[n + 1]; + for (long long i = 1; i <= n; i++) cin >> a[i]; + for (long long i = 1; i <= n; i++) cin >> b[i]; + long long maks = 0; + for (long long i = 1; i <= n; i++) { + for (long long j = i; j <= n; j++) { + long long suma = 0, sumb = 0; + for (long long l = i; l <= j; l++) { + suma = suma | a[l]; + sumb = sumb | b[l]; + } + maks = max(maks, suma + sumb); + } + } + cout << maks << endl; +} +void File() { + freopen("colors.in", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 1e5 + 5; +const int oo = 0x3f3f3f3f; +int main() { + fast(); + string s; + long long x, y, n, cnt = 0; + cin >> n >> x >> y >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { + cnt++; + while (i < n && s[i] == '0') { i++; } + } + } + if (cnt == 0) + cout << 0 << "\n"; + else { + if (x >= y) + cout << y * cnt << "\n"; + else + cout << x * (cnt - 1) + y << "\n"; + } + return 0; +} +string s; +int digit, small, big, i, l; +void quit() { + cout << "Too weak" << endl; + return; +} +int main() { + cin >> s; + l = s.length(); + if (l < 5) { + quit(); + return 0; + } + for (i = 0; i < l; i++) { + if (isupper(s[i])) big = 1; + if (islower(s[i])) small = 1; + if (isdigit(s[i])) digit = 1; + } + if (big && small && digit) + cout << "Correct" << endl; + else + quit(); + return 0; +} +int main() { + int n, m; + int pair1 = 0, pair2 = 0; + int min, max; + int count = 0; + cin >> n >> m; + if (n > m) { + max = n; + min = m; + } else { + max = m; + min = n; + } + for (int i = 0; i <= max; i++) { + for (int j = max; j >= 0; j--) { + if (((i * i) + j == n) && (i + (j * j) == m)) { count++; } + } + } + cout << count << endl; + return 0; +} +string s; +int n; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '1') { + for (int j = i; j < s.size(); j++) { + if (s[j] == '0') { n++; } + } + if (n >= 6) { + cout << "yes" << endl; + } else { + cout << "no" << endl; + } + return 0; + } + } + cout << "no" << endl; + return 0; +} +int main() { + long int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int const lim = 2e5; +int inp[lim + 3]; +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long ans = min((n % m) * b, (m - (n % m)) * a); + cout << ans << endl; +} +int main() { + int p, number; + while (cin >> p >> number) { + set s; + int temp[number]; + for (int i = 0; i < number; i++) { cin >> temp[i]; } + for (int i = 0; i < number; i++) { + if (s.count(temp[i] % p) == 0) { + s.insert(temp[i] % p); + if (i == number - 1) { + cout << -1 << endl; + break; + } + } else if (s.count(temp[i] % p) == 1) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int num[200]; +int main() { + int N, K; + int i, p, q; + int ans = 0; + cin >> N >> K; + for (i = 0; i < N; i++) cin >> num[i]; + for (p = 0; p < N; p++) { + if (num[p] <= K) + ans++; + else + break; + } + for (int j = i - 1; j > p; j--) { + if (num[j] <= K) + ans++; + else + break; + } + cout << ans << endl; +} +int p[101][101], ai[1000], bi[1000]; +unsigned int ci[1000]; +int main() { + unsigned int n, m, k; + cin >> n >> m >> k; + string u; + unsigned int o = 0; + for (unsigned int i = 0; i < n; ++i) { + cin >> u; + for (unsigned int j = 0; j < m; ++j) { + unsigned int ix = o + j; + cin >> ai[ix] >> bi[ix] >> ci[ix]; + } + o += m; + } + unsigned int e = n * m; + int ma = 0; + for (unsigned int u = 0; u < e; u += m) { + for (unsigned int v = 0; v < e; v += m) { + if (u == v) continue; + for (unsigned int i = 1; i <= m; ++i) { + unsigned int ix = u + i - 1; + for (unsigned int j = 1; j <= k; ++j) { + int mx = p[j][i - 1]; + for (unsigned int x = 1; x <= ci[ix] && x <= j; ++x) { + int mm = p[j - x][i - 1] + (bi[v + i - 1] - ai[ix]) * x; + if (mm > mx) mx = mm; + } + p[j][i] = mx; + } + } + if (p[k][m] > ma) ma = p[k][m]; + } + } + cout << ma << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a + b - c >= d || c > a || c > b) + cout << "-1" << endl; + else + cout << d - (a + b - c) << endl; + return 0; +} +int main() { + int n, p; + string str[45]; + long long sum, now; + cin >> n >> p; + sum = 0, now = 0; + for (int i = n - 1; i >= 0; i--) cin >> str[i]; + for (int i = 0; i <= n - 1; i++) { + if (str[i] == "half") { + sum += now * p; + now = now * 2; + } else { + sum += now * p + p / 2; + now = now * 2 + 1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int a[5][5]; + int tempr, tempc; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) { + tempr = i; + tempc = j; + } + } + } + int move = 0; + if (tempr > 2) { + move = move + tempr - 2; + } else { + move = move + 2 - tempr; + } + if (tempc > 2) { + move = move + tempc - 2; + } else { + move = move + 2 - tempc; + } + cout << move << endl; + return 0; +} +int n; +int a[300]; +int main() { + while (cin >> n) { + int k1 = 0, k2 = 0, k3 = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i += 3) k1 += a[i]; + for (int i = 2; i <= n; i += 3) k2 += a[i]; + for (int i = 3; i <= n; i += 3) k3 += a[i]; + int k = max(max(k1, k2), k3); + if (k == k1) + cout << "chest" << endl; + else if (k == k2) + cout << "biceps" << endl; + else + cout << "back" << endl; + } + return 0; +} +int main() { + int n, k, f = 1, a, count = 0, temp; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + if (f > k && temp != a) + break; + else if (a > 0) + count++; + temp = a; + f++; + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + int f[n + 1]; + for (int i = 1; i <= n; i++) cin >> f[i]; + int flag = 0; + for (int i = 1; i <= n; i++) { + if (f[f[f[i]]] == i) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int A[100007]; +int main() { + int n, len, maxLen, i; + cin >> n; + for (i = 0; i < n; i++) { cin >> A[i]; } + maxLen = 1; + len = 1; + for (i = 1; i < n;) { + if (A[i] >= A[i - 1]) { + while ((i < n) && (A[i] >= A[i - 1])) { + i++; + len++; + } + maxLen = max(maxLen, len); + len = 1; + } else { + maxLen = max(maxLen, len); + len = 1; + i++; + } + } + cout << maxLen << "\n"; + return 0; +} +int main() { + string s, s1; + int n; + cin >> n; + cin >> s; + cin >> s1; + int sum = 0; + for (int i = 0; i < s.length(); i++) { + int x = s[i] - '0'; + int y = s1[i] - '0'; + sum += min(abs(x - y), min(x, y) + 10 - max(x, y)); + } + cout << sum << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int cnt = 0; + for (int i = 0; i * i <= n; i++) { + int k = n - i * i; + if (k * k + i == m) { cnt++; } + } + cout << cnt << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + vector v; + for (int i = max(n - 100, (long long)0); i < n; i++) { + long long x = i, sum = 0; + while (x > 0) { + sum += x % 10; + x = x / 10; + } + if (sum + i == n) v.push_back(i); + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +int main() { + int n, m, mx, mn, temp, mnm = 100000, mxm = 100000 * -1; + cin >> n >> m >> mn >> mx; + for (int i = 1; i <= m; ++i) { + cin >> temp; + mnm = min(mnm, temp); + mxm = max(mxm, temp); + } + if (mxm == mx && mnm == mn) + cout << "Correct\n"; + else if (mxm < mx && mnm > mn && n - m >= 2) + cout << "Correct\n"; + else if (mxm < mx && mnm == mn && n - m >= 1) + cout << "Correct\n"; + else if (mxm == mx && mnm > mn && n - m >= 1) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + return 0; +} +int main() { + int n, t, a[1000001]; + int i = 0; + cin >> n >> t; + for (i; i < n - 1; i++) { cin >> a[i]; } + t--; + i = 0; + while (i < t) { i += a[i]; } + if (i == t) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long ans = k / n; + if (k % n) ans++; + cout << ans << endl; + } + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int t1 = n / s; + if (n % s != 0) t1++; + t1 *= k; + int ans = 0; + if (t1 % p != 0) ans = 1; + t1 = t1 / p; + t1 += ans; + cout << t1 << endl; + return 0; +} +int main() { + int p, number; + while (cin >> p >> number) { + set s; + int temp[number]; + for (int i = 0; i < number; i++) { cin >> temp[i]; } + for (int i = 0; i < number; i++) { + if (s.count(temp[i] % p) == 0) { + s.insert(temp[i] % p); + if (i == number - 1) { + cout << -1 << endl; + break; + } + } else if (s.count(temp[i] % p) == 1) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +const int M = 500 + 5; +int a[M], b[M]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int m; + cin >> m; + for (int i = 0; i < m; i++) { cin >> b[i]; } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) { ans = max(ans, b[j] / a[i]); } + } + } + int num = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0 && b[j] / a[i] == ans) { num++; } + } + } + cout << num << endl; + return 0; +} +int main() { + string s, t; + int res = 1; + cin >> s >> t; + queue q; + vector v; + for (int i = 0; i < s.size(); i++) q.push(s[i]); + for (int i = 0; i < t.size(); i++) v.push_back(t[i]); + for (int i = 0; i < v.size(); i++) { + if (q.front() == v[i]) { + q.pop(); + res++; + } + } + cout << res << endl; + return 0; +} +const int N = 100 + 5; +int m, n, res, a[N][N], best[N]; +string s; +void Input() { + cin >> m >> n; + for (int i = 1; i <= m; i++) { + cin >> s; + for (int j = 0; j < s.size(); j++) a[i][j + 1] = s[j] - 48; + } +} +void Solve() { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) best[i] = max(best[i], a[j][i]); + } + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == best[j]) { + res++; + break; + } + } + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int a, b, c, n, i; +int main() { + cin >> a >> b >> c >> n; + if (a + b - c + 1 > n || c > a || c > b || c > a + b || c > n) { + cout << -1 << endl; + } else + cout << n + c - a - b << endl; +} +int main() { + long long n, i, j, k, c; + cin >> n; + k = 1; + while (k * 5 < n) { + n -= k * 5; + k *= 2; + } + c = (n - 1) / k + 1; + if (c == 1) + cout << "Sheldon" << endl; + else if (c == 2) + cout << "Leonard" << endl; + else if (c == 3) + cout << "Penny" << endl; + else if (c == 4) + cout << "Rajesh" << endl; + else if (c == 5) + cout << "Howard" << endl; + return 0; +} +int main() { + int a[11][11]; + memset(a, 0, sizeof(a)); + int n; + for (int i = 0; i < 11; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (int i = 1; i < 10; i++) { + for (int j = 1; j < 10; j++) { + for (int u = 0; u <= i; u++) { a[i][j] += a[u][j - 1]; } + } + } + while (cin >> n) { cout << a[n - 1][n - 1] << endl; } + return 0; +} +int a[10005]; +int main() { + int n; + cin >> n; + int tot1 = 0, tot2 = 0, tot3 = 0, tot4 = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i = i + 3) { tot1 = tot1 + a[i]; } + for (int i = 2; i <= n; i = i + 3) { tot2 = tot2 + a[i]; } + for (int i = 3; i <= n; i = i + 3) { tot3 = tot3 + a[i]; } + int MAX = max(tot1, tot2); + int ZZ = max(MAX, tot3); + if (ZZ == tot1) + cout << "chest" << endl; + else if (ZZ == tot2) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +int n, i, c, b, ba, a; +int main() { + cin >> n; + for (i; i < n; i++) { + cin >> a; + if (i == 0 || i % 3 == 0) + c += a; + else if (i == 1 || (i - 1) % 3 == 0) + b += a; + else if (i == 2 || (i + 1) % 3 == 0) + ba += a; + } + if (c > b && c > ba) + cout << "chest" << endl; + else if (b > c && b > ba) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n, m, t; + int i, j, k; + int a, b; + cin >> n; + cin >> a >> b; + if (a % 10 == 7 || a / 10 == 7 || b % 10 == 7 || b / 10 == 7) { + cout << 0 << endl; + return 0; + } + int cou = 0; + while (1) { + b -= n; + cou++; + if (b < 0) { + b += n, b = 60 - (n - b); + a--; + if (a < 0) a = 23; + } + if (b % 10 == 7 || b / 10 == 7) break; + if (a % 10 == 7 || b / 10 == 7) break; + } + cout << cou << endl; +} +int ans = 0; +int n; +string i, j; +int dist(char a, char b) { + int x = a - '0'; + int y = b - '0'; + if (x > y) swap(x, y); + return min(y - x, 10 - y + x); +} +int main() { + cin >> n >> i >> j; + for (int k = 0; k < n; k++) ans += dist(i[k], j[k]); + cout << ans << endl; + return 0; +} +int main() { + int s[1001], n, m, a, minn = 1000; + memset(s, 0, sizeof(s)); + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> a; + s[a]++; + } + for (int i = 1; i <= n; i++) + if (s[i] < minn) minn = s[i]; + cout << minn << endl; + return 0; +} +int n; +int ch[1005]; +int c[105][1005]; +int ans[30][30]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + int nn = 0; + for (int j = 0; j < s.size(); ++j) { + c[i][s[j] - 'a'] += 1; + if (c[i][s[j] - 'a'] == 1) { + ch[nn] = s[j] - 'a'; + nn += 1; + } + } + if (nn > 2) continue; + if (nn == 1) { + for (int i = 0; i < 26; ++i) ans[i][ch[0]] = ans[ch[0]][i] += s.size(); + } else + ans[ch[0]][ch[1]] = ans[ch[1]][ch[0]] += s.size(); + } + int answer = 0; + for (int i = 0; i < 26; ++i) + for (int j = 0; j < 26; ++j) answer = max(answer, ans[i][j]); + cout << answer << endl; + return 0; +} +int main() { + long long int n, cnt = 0, mnt = 0, sum; + cin >> n; + long long int arr[n][n]; + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < n; j++) { + if (arr[i][j] != 1) { + mnt++; + for (long long int k = 0; k < n; k++) { + for (long long int l = 0; l < n; l++) { + sum = arr[i][k] + arr[l][j]; + if (sum == arr[i][j]) { + cnt++; + l = n; + k = n; + } + } + } + } + } + } + if (cnt == mnt) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + return 0; +} +const int inf = 0x3f3f3f3f; +int main() { + int n, m; + int mp[110][110]; + int a, b; + int cost[110]; + while (cin >> n >> m) { + memset(mp, 0, sizeof(mp)); + for (int i = 1; i <= n; i++) cin >> cost[i]; + for (int i = 0; i < m; i++) { + cin >> a >> b; + mp[a][b] = mp[b][a] = 1; + } + int res = inf; + for (int i = 1; i <= n; i++) { + for (int j = i; j <= n; j++) { + for (int k = j; k <= n; k++) { + if (mp[i][j] && mp[j][k] && mp[i][k]) res = min(res, cost[i] + cost[j] + cost[k]); + } + } + } + if (res == inf) + cout << -1 << endl; + else + cout << res << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + int min = a[0]; + for (int i = 1; i < n; i++) { + if (a[i] < min) { min = a[i]; } + } + int k = 0; + int j; + for (int i = 0; i < n; i++) { + if (a[i] == min) { + k++; + j = i; + } + } + if (k == 1) { + cout << j + 1 << endl; + } else { + cout << "Still Rozdil" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << "2" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int a[n], b[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + if (a[0] == 0) { + cout << "NO" << endl; + return 0; + } else if (a[s - 1] == 0 && b[s - 1] == 0) { + cout << "NO" << endl; + return 0; + } else if (a[s - 1] == 1) { + cout << "YES" << endl; + return 0; + } else if (a[s - 1] == 0 && b[s - 1] == 1) { + int k = 0; + for (int i = s; i < n; i++) { + if (a[i] == 1 && b[i] == 1) { + k = 1; + cout << "YES" << endl; + return 0; + } + } + if (k == 0) { + cout << "NO" << endl; + return 0; + } + } + return 0; +} +int main() { + int Arr[8]; + int OverAllFirendsOfMili = 0, Toats = 0, En, Sa, Ans = 0; + for (int i = 0; i < 8; i++) { cin >> Arr[i]; } + OverAllFirendsOfMili = Arr[1] * Arr[2]; + Toats = OverAllFirendsOfMili / Arr[6]; + En = Arr[3] * Arr[4]; + Sa = Arr[5] / Arr[7]; + Ans = (min(Toats, min(En, Sa)) / Arr[0]); + cout << Ans << endl; +} +int main() { + int n; + cin >> n; + int on, off, count = 0, c = 0; + while (n--) { + cin >> off >> on; + c += on - off; + if (c > count) count = c; + } + cout << count << endl; + return 0; +} +int calc_subtractions_slow(int a, int b) { + int numOps = 0; + while (a && b) { + if (a <= b) { + b -= a; + } else { + a -= b; + } + ++numOps; + } + return numOps; +} +inline int calc_subtractions_div(int a, int b) { + int numOps = 0; + while (a && b) { + if (a < b) { + int temp = b / a; + numOps += temp; + b -= (a * temp); + } else { + int temp = a / b; + numOps += temp; + a -= (b * temp); + } + } + return numOps; +} +inline int calc_subtractions_mod(int a, int b) { + int numOps = 0; + while (a && b) { + if (a < b) { + numOps += b / a; + b = b % a; + } else { + numOps += a / b; + a = a % b; + } + } + return numOps; +} +int calc_subtractions(int a, int b) { + return calc_subtractions_div(a, b); +} +void test_div() { + for (int i = 0; i < INT_MAX; ++i) { calc_subtractions_div(1000000000, 999999999); } +} +void test_mod() { + for (int i = 0; i < INT_MAX; ++i) { calc_subtractions_mod(1000000000, 999999999); } +} +vector getNumbers(const string &str) { + vector res; + int value = 0; + bool gotValue = false; + for (unsigned int i = 0; i < str.length(); ++i) { + if (str[i] == ' ') { + if (gotValue) res.push_back(value); + value = 0; + gotValue = false; + continue; + } + value = value * 10 + str[i] - '0'; + gotValue = true; + } + if (gotValue) res.push_back(value); + return res; +} +void subtractions_solve_low(istream &in, ostream &out) { + int numPairs, a, b; + in >> numPairs; + for (int i = 0; i < numPairs; ++i) { + in >> a >> b; + int v = calc_subtractions_mod(a, b); + out << v << "\n"; + } +} +void subtractions_solve_fast(istream &in, ostream &out) { + int numPairs; + in >> numPairs; + string temp; + getline(in, temp); + for (int i = 0; i < numPairs; ++i) { + string line; + getline(in, line); + vector nums = getNumbers(line); + int v = calc_subtractions_div(nums[0], nums[1]); + out << v << "\n"; + } +} +void subtractions_solve(istream &in, ostream &out) { + subtractions_solve_fast(in, out); +} +int main() { + subtractions_solve(cin, cout); + return 0; +} +const int N = 105; +string a[N], b[N]; +map cnt[5]; +int calc(string x, string y) { + int dif = 0; + for (int i = 0; i < x.size(); i++) { + if (x[i] != y[i]) dif++; + } + return dif; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < 5; i++) cnt[i].clear(); + for (int i = 0; i < n; i++) { + cin >> a[i]; + cnt[a[i].size()][a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + if (cnt[b[i].size()][b[i]] > 0) { + cnt[b[i].size()][b[i]]--; + b[i] = "#"; + } + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (b[i][0] == '#') continue; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, s; + cin >> n >> m; + int day; + day = n; + while (1) { + if (n >= m) + day = day + (n / m); + else if (n < m) + break; + n = (n / m) + (n % m); + } + cout << day << endl; + return 0; +} +void doit() { + long long a, b, k; + cin >> a >> b >> k; + long long resp = 0; + resp += (a - b) * (k / 2); + if (k % 2 == 1) resp += a; + cout << resp << endl; +} +int main() { + long long T = 1; + cin >> T; + while (T--) { doit(); } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + for (int j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - 2 * i; j++) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << endl; + } + return 0; +} +int main() { + long long n, x, y, c = 0, c1 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > 0) + c++; + else if (x < 0) + c1++; + } + if (c > c1) { + if (c1 == 0) + cout << "Yes" << endl; + else if (c1 == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } else if (c < c1) { + if (c == 0) + cout << "Yes" << endl; + else if (c == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } else { + if (c == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +int arr[100000][2]; +int main() { + int n, a, b, c, d = 0, sum = 0; + cin >> n; + for (int i = 0; i < n; ++i) + for (int j = 0; j < 2; ++j) cin >> arr[i][j]; + a = arr[0][0]; + b = arr[0][1]; + sum = a * b; + for (int i = 1; i < n; ++i) { + a = arr[i][0]; + c = arr[i][1]; + if (c >= b) { + d += a; + if (i == n - 1) sum += b * d; + } else { + sum += b * d; + b = c; + sum += a * b; + d = 0; + } + } + cout << sum << endl; + return 0; +} +long long Eu_distance(long long x, long long y) { + return x * x + y * y; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + puts("1"); + } else if (n == 1) { + puts("4"); + } else { + long long x, y = n; + long long res = 0; + for (x = 0; x < n, x <= y; x++) { + while (Eu_distance(x, y) > n * n) { y--; } + if (x > y) { break; } + if (x != y) { + res += 2; + } else { + res++; + } + } + res -= 2; + res = res * 4 + 4; + cout << res << endl; + } +} +const int maxn = 1e6; +int prime[maxn + 1]; +void getPrime() { + memset(prime, 0, sizeof(prime)); + for (int i = 2; i <= maxn; i++) { + if (!prime[i]) prime[++prime[0]] = i; + for (int j = 1; j <= prime[0] && prime[j] <= maxn / i; j++) { + prime[prime[j] * i] = 1; + if (i % prime[j] == 0) break; + } + } +} +int main() { + getPrime(); + int n; + while (cin >> n) { + vector v; + v.clear(); + int key = prime[1], id = 1; + for (int i = 1; prime[i] <= n; i++) { + int key = prime[i]; + while (key <= n) { + v.push_back(key); + key *= prime[i]; + } + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) cout << v[i] << (i == v.size() - 1 ? "\n" : " "); + } +} +int main() { + int k, l, m, n, d, count(0); + cin >> k >> l >> m >> n >> d; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) count++; + } + cout << count << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (a >= 2 * c && b >= 2 * c) + cout << "First"; + else + cout << "Second"; + cout << endl; + return 0; +} +int main() { + string s, t; + int a[105]; + int i, j; + while (cin >> s >> t) { + int len = s.size(); + for (int i = 0; i < len; i++) { + if (s[i] == t[i]) + a[i] = 0; + else + a[i] = 1; + } + for (int i = 0; i < len; i++) cout << a[i]; + cout << endl; + } +} +int main() { + int n, d, win[102], m = 0, ans[100]; + char a; + memset(win, -1, sizeof(win)); + memset(ans, 0, sizeof(ans)); + cin >> n >> d; + for (int i = 0; i < d; i++) { + for (int j = 0; j < n; j++) { + cin >> a; + win[i] *= a - '0'; + } + } + for (int i = 0; i < d; i++) { + if (win[i] == -1) { + ans[i] = m; + m = 0; + } else { + m++; + } + } + sort(ans, ans + 100); + cout << max(ans[99], m) << endl; + return 0; +} +int mp[1010][1010]; +int main() { + int m, n, k; + cin >> m >> n >> k; + memset(mp, 0, sizeof(mp)); + int flog = 0; + int ans = 0; + for (int i = 1; i <= k; i++) { + int x, y; + cin >> x >> y; + mp[x][y] = 1; + if (flog == 0) { + if (mp[x - 1][y] && mp[x - 1][y - 1] && mp[x][y - 1]) flog = 1; + if (mp[x + 1][y] && mp[x + 1][y + 1] && mp[x][y + 1]) flog = 1; + if (mp[x - 1][y] && mp[x - 1][y + 1] && mp[x][y + 1]) flog = 1; + if (mp[x + 1][y] && mp[x + 1][y - 1] && mp[x][y - 1]) flog = 1; + if (flog) { + cout << i << endl; + return 0; + } + } + } + cout << "0" << endl; +} +const int maxN = 1e3 + 13, mod = 1e9 + 7; +long long ans = 1, a[maxN], c[maxN][maxN], sum, k; +int main() { + cin >> k; + for (int i = 0; i < maxN; i++) + for (int j = 0; j < maxN; j++) { + if (j == 0 || j == i) + c[i][j] = 1; + else + c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; + } + for (int i = 0; i < k; i++) { + cin >> a[i]; + ans = (ans * c[sum + a[i] - 1][a[i] - 1]) % mod; + sum += a[i]; + } + cout << ans << endl; +} +int main() { + long long n, k, a, b, mx, kt; + cin >> n >> k; + cin >> a >> b; + (b > k) ? mx = a - (b - k) : mx = a; + n--; + while (n--) { + cin >> a >> b; + (b > k) ? kt = a - (b - k) : kt = a; + if (kt > mx) mx = kt; + } + cout << mx << endl; +} +int main() { + int n, a; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + int res = 2e9 + 5, cnt = 0; + for (int i = 0; i + 1 < n; i++) { res = min(res, v[i + 1] - v[i]); } + for (int i = 0; i + 1 < n; i++) { + if ((v[i + 1] - v[i]) == res) { cnt++; } + } + cout << res << " " << cnt << endl; + return 0; +} +int main() { + int t, a, b; + cin >> t; + while (t--) { + cin >> a >> b; + int ans = 0; + while (a != b) { + if (a > b) swap(a, b); + int step = ceil(1.0 * (b - a) / a); + ans += step; + b -= step * a; + } + cout << ans + 1 << endl; + } + return 0; +} +int main() { + int n, sum = 0; + cin >> n; + int x1, y1, x2, y2; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + sum += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << sum << endl; + return 0; +} +pair a[10]; +int main() { + int n; + cin >> n; + string v[10]; + for (int i = 0; i < n; i++) { cin >> v[i]; } + a[0] = make_pair("purple", "Power"); + a[1] = make_pair("green", "Time"); + a[2] = make_pair("blue", "Space"); + a[3] = make_pair("orange", "Soul"); + a[4] = make_pair("red", "Reality"); + a[5] = make_pair("yellow", "Mind"); + cout << 6 - n << endl; + for (int i = 0; i < 6; i++) { + bool s = 0; + for (int j = 0; j < n; j++) { + if (a[i].first == v[j]) s = 1; + } + if (s == 0) cout << a[i].second << endl; + } +} +long long gcd(unsigned long long a, unsigned long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + unsigned long long a, b; + cin >> a >> b; + long long g = gcd(a, b); + unsigned long long lcm = (a * b) / g; + unsigned long long d = (lcm / a) - 1, m = (lcm / b) - 1; + if (a > b) + d++; + else + m++; + if (m > d) cout << "Masha" << endl; + if (d > m) cout << "Dasha" << endl; + if (m == d) cout << "Equal" << endl; +} +set s[300000]; +char a[300000][35]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int len = strlen(a[1]); + for (int i = 0; i < len; i++) { + for (int j = 1; j <= n; j++) s[i].insert(a[j][i]); + } + int i; + for (i = 0; i < len; i++) { + if (s[i].size() != 1) break; + } + cout << i << endl; + return 0; +} +int main() { + int a, b, ans = 0; + cin >> a >> b; + while (a > 0) { + ans++; + a--; + if (ans % b == 0) a++; + } + cout << ans << endl; + return 0; +} +int n, m; +vector a; +int ret; +bool check(int value) { + int left = m; + for (int i = 0; i < a.size(); i++) { + if (a[i] > value) return false; + if (left) { left -= (value - a[i]); } + } + if (left > 0) return false; + return true; +} +void parametric_search(int left, int right) { + if (left > right) return; + int mid = (left + right) / 2; + if (check(mid)) { + ret = mid; + parametric_search(left, mid - 1); + } else { + parametric_search(mid + 1, right); + } +} +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + a.push_back(temp); + } + parametric_search(0, 10000 + 100); + cout << ret; + cout << " " << *max_element(a.begin(), a.end()) + m << '\n'; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + vector a; + int x; + while (n--) { + cin >> x; + a.push_back(x); + } + int m = 1 << 30; + bool f = false; + bool r = false; + int j = 0; + for (int i = 0; i < a.size(); i++) { + if (s[i] == 'R') { + j = i; + r = true; + } else if (r) { + m = min(a[i] - a[j], m); + f = true; + } + } + if (!f) { + cout << -1 << endl; + } else { + cout << (m / 2) << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (i == 0 && s[i] == '9') continue; + if (s[i] >= '5') { s[i] = '9' - s[i] + '0'; } + } + cout << s << endl; + return 0; +} +string s, v; +vector matches; +void rotatex() { + char temp = v[2]; + v[2] = v[4]; + v[4] = v[3]; + v[3] = v[5]; + v[5] = temp; +} +void rotatey() { + char temp = v[0]; + v[0] = v[4]; + v[4] = v[1]; + v[1] = v[5]; + v[5] = temp; +} +void rotatez() { + char temp = v[0]; + v[0] = v[2]; + v[2] = v[1]; + v[1] = v[3]; + v[3] = temp; +} +void check() { + v = s; + for (int k = 0; k < 4; k++) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + if (find(matches.begin(), matches.end(), v) != matches.end()) { return; } + rotatez(); + } + rotatey(); + } + rotatex(); + } + matches.push_back(s); + return; +} +int main() { + cin >> s; + sort(s.begin(), s.end()); + while (true) { + check(); + if (!next_permutation(s.begin(), s.end())) break; + } + cout << matches.size() << endl; + return 0; +} +int k, n, s, p; +int l; +int ans, num, sum; +int main() { + int i; + cin >> k >> n >> s >> p; + num = n / s; + l = n % s; + if (l != 0) num++; + sum = k * num; + ans = sum / p; + if (sum % p != 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + string s; + vector a; + cin >> s; + long int n = s.size(); + for (int i = 0; i < n; i++) { + if (a.empty()) + a.push_back(s[i]); + else if (a.back() != s[i]) + a.push_back(s[i]); + else { + a.pop_back(); + } + } + for (int i = 0; i < a.size(); i++) cout << a[i]; + cout << endl; + return 0; +} +int main() { + long long n, arr[1001]; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + if (n % 2 == 0) + cout << arr[(n / 2) - 1] << endl; + else + cout << arr[n / 2] << endl; + return 0; +} +long long dx[] = {1, 0, -1, 0}; +long long dy[] = {0, 1, 0, -1}; +long long gcd(long long x, long long y) { + if (y == 0) + return x; + else + return gcd(y, x % y); +} +long long expo(long long n, long long m, long long p) { + long long r = 1; + n = n % p; + while (m > 0) { + if (m % 2) r = (r * n) % p; + n = (n * n) % p; + m = m / 2; + } + return r % p; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +vector z_function(string s) { + long long n = (long long)s.length(); + vector z(n); + for (long long i = 1, l = 0, r = 0; i < n; ++i) { + if (i <= r) z[i] = min(r - i + 1, z[i - l]); + while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; + if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; + } + return z; +} +set s; +bool vis[200005]; +int main() { + long long n, k, x; + cin >> n >> k >> x; + vector a(n); + for (long long i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + long long ans = 0, c = 0; + for (long long i = n - 1; i >= 0; i--) { + if (k > 0) + k--, c++; + else { + ans = ans + a[i]; + } + } + ans = ans + c * x; + cout << ans << '\n'; +} +int main() { + int n, s = 0; + cin >> n; + for (int i = 1;; i++) { + if (s > n) { + cout << i - 2 << "\n"; + break; + } else { + s += (i * (i + 1)) / 2; + } + } +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int lcm(int a, int b) { + return a * (b / gcd(a, b)); +} +int main() { + int n, m, z; + cin >> n >> m >> z; + cout << z / lcm(n, m) << endl; + return 0; +} +int main() { + int a, b, c, t, n, min; + cin >> a >> b >> c; + n = a * c; + t = (n / b); + if (t * b >= n) + cout << (n / b) - c << endl; + else + cout << ((n / b) + 1) - c << endl; + return 0; +} +map a; +int main() { + int n; + cin >> n; + while (n--) { + char ch; + long long x; + cin >> ch >> x; + long long tmp = 0, i = 0; + for (int i = 1; i <= 18; x /= 10, i++) { tmp = tmp * 2 + x % 2; } + if (ch == '+') a[tmp]++; + if (ch == '-') a[tmp]--; + if (ch == '?') cout << a[tmp] << endl; + } +} +int main() { + long long n; + cin >> n; + long long var = n / 2; + long long ans = var * 3; + cout << ans << endl; + return 0; +} +int main() { + int X1, X2, X3, d = 0; + cin >> X1 >> X2 >> X3; + d = max(X1, max(X2, X3)) - min(X1, min(X2, X3)); + cout << d << endl; +} +bool isVowel(char a) { + return (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u'); +} +bool isOdd(char a) { + return (a == '1' || a == '3' || a == '5' || a == '7' || a == '9'); +} +int main() { + string text; + cin >> text; + int num = 0; + for (int i = 0; i < text.length(); i++) { + if (isVowel(text[i]) || isOdd(text[i])) num++; + } + cout << num << endl; +} +int k; +int read(int x, int y) { + int xx = min(x, k - x - 1); + int yy = min(y, k - y - 1); + if (xx + yy < k / 2) { + return true; + } else { + return false; + } +} +int main() { + cin >> k; + for (int i = 0; i < k; i++) { + for (int j = 0; j < k; j++) { + if (read(i, j)) { + cout << "*"; + } else { + cout << "D"; + } + } + cout << endl; + } + return 0; +} +int a, be, eb = 0; +int main() { + cin >> a >> be; + while (be) { + eb = 10 * eb + be % 10; + be /= 10; + } + cout << a + eb << '\n'; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +long long int n, m; +int main() { + cin >> n >> m; + if (n == 0 and m != 0) + puts("Impossible"); + else + cout << (n + max(0LL, m - n)) << " " << (n + max(0LL, m - 1)) << endl; + ; +} +int main() { + long long int n, i, x, sum = 0; + cin >> n; + for (i = 0; i < n - 1; i++) { + cin >> x; + sum += x; + } + cout << n * (n + 1) / 2 - sum << endl; + return 0; +} +int a[1000][1000]; +int main() { + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { a[i][j] = 1; } + } + int k; + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + cin >> k; + if (k % 2 != 0) { + a[i][j] = 1 - a[i][j]; + a[i][j + 1] = 1 - a[i][j + 1]; + a[i][j - 1] = 1 - a[i][j - 1]; + a[i + 1][j] = 1 - a[i + 1][j]; + a[i - 1][j] = 1 - a[i - 1][j]; + } + } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { cout << a[i][j]; } + cout << endl; + } +} +int main() { + int a[100]; + int sum = 0, k = 0, max = 0; + int n, i; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n - 1; i++) { + sum = a[i + 1] - a[i]; + if (sum > max) max = sum; + } + int min = 100001; + for (i = 0; i < n - 2; i++) { + sum = a[i + 2] - a[i]; + if (min > sum) min = sum; + } + if (min > max) max = min; + cout << max << endl; + return 0; +} +int main() { + int n; + int xx[32][32]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> xx[i][j]; } + } + int sum = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int a = 0, b = 0; + for (int s = 0; s < n; s++) { + for (int t = 0; t < n; t++) { + if (t == j) a += xx[s][t]; + if (s == i) b += xx[s][t]; + } + } + if (a > b) sum++; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + long long dip, cer, nw, mid, n, k; + cin >> n >> k; + mid = n / 2; + dip = mid / (k + 1); + cer = dip * k; + nw = n - (dip + cer); + cout << dip << " " << cer << " " << nw << endl; +} +const unsigned long long M = 1e9 + 10; +const unsigned long long N = 1e9 + 10; +int main() { + unsigned long long n, k; + cin >> n >> k; + unsigned long long x, c, d; + x = n / 2 / (1 + k); + cout << x << " " << k * x << " " << n - x - k * x << endl; +} +int main() { + int n, i = 0, j = 0, count = 0, m = 0; + cin >> n; + string s1[n], s2[n]; + for (i = 0; i < n; i++) { cin >> s1[i]; } + for (i = 0; i < n; i++) { cin >> s2[i]; } + for (i = 0; i < n; i++) { + m = 0; + for (j = 0; j < n; j++) { + if (s1[i] == s2[j]) { + s2[j] = 'A'; + break; + } + m++; + } + if (m == n) { count++; } + } + cout << count << endl; + return (0); +} +int main() { + int n, i, j, x, y, z; + cin >> n >> x >> y; + z = (x + y); + if (n - x == 1 && n != z) + cout << 1 << endl; + else if (n > z) + cout << y + 1 << endl; + else if (z > n && (n - x) > 1) + cout << (n - x) << endl; + else if (n == z) + cout << y << endl; + return 0; +} +int main() { + int i, j, m, n, a = 0, b = 0, x, y, ar[200001]; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> x >> y; + if (x > 0) + a++; + else if (x < 0) + b++; + } + if (min(a, b) == 0 || min(a, b) == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int n, k; +char s[105]; +int main() { + cin >> n >> k; + int pos, tar; + for (int r = 1; r <= n; r++) { + cin >> s[r]; + if (s[r] == 'G') { pos = r; } + if (s[r] == 'T') { tar = r; } + } + if (tar < pos) { + while (pos > tar && pos > 0) { + pos -= k; + if (s[pos] == '#') { + cout << "NO" << endl; + return 0; + } + if (pos == tar) { + cout << "YES" << endl; + return 0; + } + if (pos < tar) { + cout << "NO" << endl; + return 0; + } + } + } + if (tar > pos) { + while (pos < tar && pos <= n) { + pos += k; + if (pos == tar) { + cout << "YES" << endl; + return 0; + } + if (pos > tar) { + cout << "NO" << endl; + return 0; + } + if (s[pos] == '#') { + cout << "NO" << endl; + return 0; + } + } + } + return 0; +} +int n, mi, ma, m, t; +bool e, v; +int main() { + cin >> n >> m >> mi >> ma; + e = 0; + v = 0; + for (int i = 0; i < m; i++) { + cin >> t; + if (t > ma || t < mi) { + cout << "Incorrect\n"; + return 0; + } + if (t == ma) v = 1; + if (t == mi) e = 1; + } + if (e == 1 && v == 1) + cout << "Correct\n"; + else { + if (v == 1 && m < n) e = 1; + if (e == 1 && m < n) v = 1; + if (m <= n - 2) { + e = 1; + v = 1; + } + if (e == 1 && v == 1) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + } + return 0; +} +int check[100 + 1]; +int main() { + int n; + cin >> n; + int p; + cin >> p; + for (int i = 1; i <= p; i++) { + int x; + cin >> x; + check[x]++; + } + int q; + cin >> q; + for (int i = 1; i <= q; i++) { + int x; + cin >> x; + check[x]++; + } + for (int i = 1; i <= n; i++) { + if (check[i] == 0) { + cout << "Oh, my keyboard!" << endl; + exit(0); + } + } + cout << "I become the guy." << endl; +} +int main() { + int l, r; + long long ans = 0; + cin >> l >> r; + long long p10 = 1, p9 = 9; + for (int i = 1; i <= 10; ++i) { + for (long long j = p9 / 2 - 1; j <= p9 / 2 + 1; ++j) + if (l <= j && j <= r) ans = max(ans, 1LL * j * (p9 - j)); + if (p10 <= l && l <= p9) ans = max(ans, 1LL * l * (p9 - l)); + if (p10 <= r && r <= p9) ans = max(ans, 1LL * r * (p9 - r)); + p10 *= 10; + p9 = (p9 * 10 + 9); + } + cout << ans << "\n"; + return 0; +} +int n; +int a[105][105]; +int b[105][105]; +int main() { + while (cin >> n) { + memset(a, 0, sizeof(a)); + int x, y; + for (int i = 0; i < n; i++) { + cin >> x >> y; + a[x][y] = 1; + } + memcpy(b, a, sizeof(a)); + int ans = 0x3f3f3f3f; + int cnt = 0; + for (int i = 0; i <= 100; i++) { + for (int j = 0; j <= 100; j++) { + if (a[i][j] == 1) { + cnt++; + break; + } + } + } + if (cnt < ans) ans = cnt; + cnt = 0; + for (int i = 0; i <= 100; i++) { + for (int j = 0; j <= 100; j++) { + if (a[j][i] == 1) { + cnt++; + break; + } + } + } + if (cnt < ans) ans = cnt; + cout << ans << endl; + } +} +int main() { + int a, m, i, p2 = 1; + cin >> a >> m; + while (m % 2 == 0) m >>= 1; + cout << (a % m ? "No" : "Yes") << "\n"; + return 0; +} +int main() { + long long int arr[6] = {2, 1, 0, 0, 1, 0}; + long long int n, x, val; + cin >> n >> x; + int i; + n = n % 6; + for (i = n; i > 0; i--) { + if (i & 1) { + if (x == 0 || x == 1) x = 1 - x; + } else { + if (x == 2 || x == 1) x = 3 - x; + } + } + cout << x << endl; +} +int main() { + long long int n, a, b, i; + cin >> n >> a >> b; + long long int p[n]; + for (i = 0; i < n; i++) cin >> p[i]; + sort(p, p + n); + long long int x = p[n - a] - p[b - 1]; + cout << x << endl; +} +int A, B, C, N; +int main() { + cin >> A >> B >> C >> N; + bool con = false; + if (A > N || B > N || C > N) con = true; + if (C > A || C > B) con = true; + int T = A + B - C; + if (T >= N) con = true; + cout << ((con) ? -1 : N - T) << '\n'; + return 0; +} +int main() { + int n; + while (cin >> n) { + int fourcount = 0; + bool flag = true; + while (n % 7 != 0 && n >= 0) { + n = n - 4; + fourcount++; + } + if (n >= 0) { + int sevenCount = n / 7; + while (fourcount--) { cout << 4; } + while (sevenCount--) { cout << 7; } + cout << '\n'; + } else + cout << -1 << '\n'; + } + return 0; +} +int main() { + int x = 0; + for (int i = 1; i <= 5; ++i) { + for (int j = 1; j <= 5; ++j) { + cin >> x; + if (x == 1) { cout << abs(i - 3) + abs(j - 3) << endl; } + } + } + return 0; +} +const char *nam[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; +int main() { + long long n, m = 1; + cin >> n; + n--; + while (n >= m * 5) { + n -= m * 5; + m = m << 1; + } + cout << nam[n / m] << endl; + return 0; +} +int main() { + int n; + int a[25]; + int x = 0, y = 1, z = 2; + int chest = 0, biceps = 0, back = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if ((x) < n) { + chest = chest + a[x]; + x = x + 3; + } + if ((y) < n) { + biceps = biceps + a[y]; + y = y + 3; + } + if ((z) < n) { + back = back + a[z]; + z = z + 3; + } + } + if (biceps > chest) + if (biceps > back) cout << "biceps"; + if (chest > biceps) + if (chest > back) cout << "chest"; + if (back > biceps) + if (back > chest) cout << "back"; + putchar('\n'); + return 0; +} +long long n, m, d, cnt, ans, sum, rem = 0, x, z, b, c; +vector v, v1, v2, v3; +string s; +map make_pair; +set se; +char h, r; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 == 0) + cout << "#"; + else { + if (i % 4 == 1 and j == m - 1) + cout << "#"; + else if (i % 4 == 3 and j == 0) + cout << "#"; + else + cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + string n; + cin >> n; + if (n == "a8" || n == "h8" || n == "a1" || n == "h1") { + cout << 3 << endl; + return 0; + } + if (n[0] == 'a' || n[0] == 'h' || n[1] == '1' || n[1] == '8') { + cout << 5 << endl; + return 0; + } + cout << 8 << endl; + return 0; +} +int f(int n, int t, int sum) { + int temp; + temp = n; + if (temp >= t) { + temp = temp - t; + sum++; + temp++; + f(temp, t, sum); + } else + return sum; +} +int main() { + int n, t, sum = 0; + cin >> n >> t; + int temp; + temp = n; + if (n >= t) + cout << f(n, t, sum) + n << endl; + else + cout << n << endl; +} +const long long N = 100001; +int main() { + long long n; + string s; + getline(cin, s); + n = s.size(); + long long cnt = 0; + for (long long i = 0; i < n - 2; i++) { + for (long long j = i + 1; j < n - 1; j++) { + for (long long k = j + 1; k < n; k++) { + if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') { cnt++; } + } + } + } + cout << cnt << endl; + return 0; +} +const int MAXN = 1 << 17; +int N, Q; +int items[MAXN]; +int d[MAXN]; +int main() { + cin >> Q; + for (int i = 0; i < (int)Q; ++i) cin >> d[i]; + sort(d, d + Q); + cin >> N; + for (int i = 0; i < (int)N; ++i) cin >> items[i]; + sort(items, items + N); + reverse(items, items + N); + long long answer = 0; + int lo = 0; + while (lo < N) { + int hi = lo + d[0] - 1; + if (hi < N) { + while (lo <= hi) { answer += items[lo++]; } + lo++; + lo++; + } else { + while (lo < N) answer += items[lo++]; + } + } + cout << answer << endl; + return 0; +} +int main() { + int n; + int ans = 0; + ; + int cheapest; + cin >> n; + for (int i = 0; i < n; ++i) { + int a, p; + cin >> a >> p; + if (!i) + cheapest = p; + else if (cheapest > p) + cheapest = p; + else if (cheapest < p) + p = cheapest; + ans += p * a; + } + cout << ans << endl; + return 0; +} +int main() { + int a[55][55], n, x[55][55], y[55][55]; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { x[i][j] = a[i][j]; } + sort(x[i], x[i] + n); + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { y[i][j] = a[j][i]; } + sort(y[i], y[i] + n); + } + int flag = 1; + for (int i = 0; i < n && flag; i++) { + for (int j = 0; j < n && flag; j++) { + if (a[i][j] == 1) continue; + int u = 0, v = n - 1; + while (u < n && v >= 0) { + if (x[i][u] + y[j][v] > a[i][j]) + v--; + else if (x[i][u] + y[j][v] < a[i][j]) + u++; + else + break; + } + if (v == -1 || u == n || x[i][u] + y[j][v] != a[i][j]) flag = 0; + } + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n, m, a = 3; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m; + if (a != m) + a = 6 - a - m; + else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, a[100], b[100], aa, bb, t = 0, i; + cin >> n; + set levels; + cin >> aa; + for (i = 0; i < aa; i++) { + cin >> a[i]; + levels.insert(a[i]); + } + cin >> bb; + for (i = 0; i < bb; i++) { + cin >> b[i]; + levels.insert(b[i]); + } + if (levels.size() == n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int bb; + bb = b / c; + if (b % c != 0) { bb++; } + bb *= a; + int aa = bb / d; + if (bb % d != 0) { aa++; } + cout << aa << endl; + return 0; +} +char s[1005]; +int main() { + int n; + cin >> n; + cin >> s; + int bj = 1; + for (int i = 0; i < n - 1; i++) { + if (s[i + 1] != s[i]) { + cout << "YES" << endl; + cout << s[i] << s[i + 1] << endl; + bj = 0; + break; + } + } + if (bj) { cout << "NO" << endl; } +} +int main() { + unsigned long long n, t, coi = 1; + cin >> n; + while (n % 3 == 0) n /= 3; + cout << (n - 1) / 3 + 1 << '\n'; +} +const int MAXN = 100000 + 7; +const int mod = 23333333; +int a, b, r; +int main() { + cin >> a >> b >> r; + if (a < 2 * r || b < 2 * r) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +int n, i, k[50], t[50], s1, s, b; +vector a; +int main() { + cin >> n; + for (i = 0; i < n / 2; i++) { + cin >> b; + a.push_back(b); + k[i] = i * 2 + 1; + t[i] = i * 2 + 2; + } + sort(a.begin(), a.end()); + for (i = 0; i < a.size(); i++) { + s += max(a[i], k[i]) - min(a[i], k[i]); + s1 += max(a[i], t[i]) - min(a[i], t[i]); + } + cout << min(s, s1) << endl; + return 0; +} +string s, ss; +int main() { + cin >> s >> ss; + int x = s.length(), y = ss.length(); + string ans = "zzzzzzzzzzzz", s2; + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + s2 = s.substr(0, i + 1) + ss.substr(0, j + 1); + ans = min(ans, s2); + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, p; + cin >> n >> m >> p; + int ans = 0; + int c = n; + while (n != 1) { + ans += n / 2; + n -= n / 2; + } + cout << ans * (m * 2 + 1) << " " << c * p << endl; +} +const int maxn = 1e5 + 10; +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, a[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + cin >> n; + cout << a[n / 10] * a[n % 10] << endl; + return 0; +} +int main() { + int n, a[609]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (n == 1 && a[n] != 15 && a[n] != 15 && a[n] != 0) { + cout << -1 << endl; + return 0; + } + if (a[n] == 15) { + cout << "DOWN\n"; + return 0; + } + if (a[n] == 0) { + cout << "UP\n"; + return 0; + } + if (a[n] < a[n - 1] && a[n] != 0) { + cout << "DOWN\n"; + } else + cout << "UP\n"; +} +int main() { + string s; + cin >> s; + int c1 = 0, c2 = 0, c3 = 0; + char res[s.length()]; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '1') { + c1++; + } else if (s[i] == '2') { + c2++; + } else if (s[i] == '3') { + c3++; + } + } + int totalc = c1 + c2 + c3; + int printC = 0; + while (c1 != 0) { + cout << "1"; + printC++; + if (printC == totalc) { break; } + cout << "+"; + c1--; + } + while (c2 != 0) { + cout << "2"; + printC++; + if (printC == totalc) { break; } + cout << "+"; + c2--; + } + while (c3 != 0) { + cout << "3"; + printC++; + if (printC == totalc) { break; } + cout << "+"; + c3--; + } + cout << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int maxn = 2e5 + 5; +long long a, b, c, l; +long long solve(long long x, long long y, long long z, long long l) { + if (x < y + z) return 0; + long long tmp = min(x - y - z, l); + return (tmp + 1) * (tmp + 2) / 2; +} +int main() { + cin >> a >> b >> c >> l; + long long ans = 0; + for (long long i = 0; i <= l; i++) ans += (i + 1) * (i + 2) / 2; + for (int i = 0; i <= l; i++) { + ans -= solve(a + i, b, c, l - i); + ans -= solve(b + i, a, c, l - i); + ans -= solve(c + i, a, b, l - i); + } + cout << ans << endl; + return 0; +} +int main() { + int l, n, i, j, m, cnt = 0; + cin >> n >> m; + for (i = 0; i <= 1000; i++) { + for (j = 0; j <= 1000; j++) { + if ((i * i + j == n) && (i + j * j == m)) cnt++; + } + } + cout << cnt << endl; +} +const long long max_n = 1e3 + 20; +long long n, m, ans, sum; +long long a[max_n]; +int main() { + cin >> n; + for (long long i = 0; i < n / 2; i++) { + for (long long j = n / 2; j > i; j--) cout << '*'; + for (long long j = 0; j <= i * 2; j++) cout << "D"; + for (long long j = n / 2; j > i; j--) cout << '*'; + cout << endl; + } + for (long long i = n / 2; i + 1; i--) { + for (long long j = n / 2; j > i; j--) cout << '*'; + for (long long j = 0; j <= i * 2; j++) cout << "D"; + for (long long j = n / 2; j > i; j--) cout << '*'; + cout << endl; + } + return 0; +} +int main() { + int n; + int i; + cin >> n; + for (i = 1; i <= n; i++) { + string a; + cin >> a; + int len = a.length(); + if (len <= 10) + cout << a << endl; + else + cout << a[0] << len - 2 << a[len - 1] << endl; + } +} +const int N = 1e6 + 5, MAX = 3e7, MOD = 1e9 + 7; +int n, p, b, x, y; +int main() { + cin >> n >> p >> b; + y = b * n; + while (n) { + if (n / 2) + x += ((n - n % 2) * p + n / 2); + else + break; + n = n / 2 + n % 2; + } + cout << x << " " << y << "\n"; +} +int main() { + long long int p, i, j, ans = 0; + cin >> p; + for (i = 1; i < p; i++) { + long long int x = 1; + long long int b = 1; + for (j = 1; j < p - 1; j++) { + x = (x * i) % p; + b = b & (x != 1); + } + ans += b; + } + cout << ans << endl; +} +long long const mod = 1e9 + 7; +long long power(long long x, long long y, long long mod = 2e18) { + long long ans = 1; + x %= mod; + while (y) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y >>= 1; + } + return ans; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + return gcd(b % a, a); +} +bool check(long long x) { + while (x % 2 == 0) { x /= 2; } + while (x % 3 == 0) { x /= 3; } + if (x > 1) return 0; + return 1; +} +long long lcm(long long x, long long y) { + return (x * y) / (gcd(x, y)); +} +int main() { + long long n; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + long long temp = a[0]; + for (long long i = 1; i < n; i++) { + long long x = lcm(temp, a[i]); + if (!check(x / temp) || !check(x / a[i])) { return cout << "No\n", 0; } + temp = a[i - 1]; + } + return cout << "Yes\n", 0; + return 0; +} +long long k[1005], l[1005]; +int main() { + int n; + cin >> n; + long long sum1 = 0, sum2 = 0; + for (int i = 1; i <= n; i++) { + cin >> k[i]; + sum1 |= k[i]; + } + for (int i = 1; i <= n; i++) { + cin >> l[i]; + sum2 |= l[i]; + } + long long ans = sum1 + sum2; + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0; + char pointer = 'a'; + for (int i = 0; i < int(s.length()); ++i) { + char cur = s[i]; + int a1 = abs(cur - pointer), a2 = abs(26 - a1); + if (pointer < cur) { + if ((a1 > a2)) { + ans += a2; + } else { + ans += a1; + } + } else if (pointer > cur) { + if (a1 > a2) { + ans += a2; + } else { + ans += a1; + } + } + pointer = s[i]; + } + cout << ans << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + cout << n * 3 / 2 << endl; +} +const int M = 100 + 5; +int main() { + int n, m; + cin >> n >> m; + int one_loop = (n + 1) * n / 2; + m = m % one_loop; + int num = 1; + while (num * (num + 1) / 2 <= m) { num++; } + num--; + int ans = m - num * (num + 1) / 2; + cout << ans << endl; + return 0; +} +int a[1005]; +int main() { + int n, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 1; i < n - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans++; + if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++; + } + cout << ans << endl; +} +int main() { + int n, m, k, temp; + cin >> n >> k >> m; + vector sup; + for (int i = 0; i < n; i++) { + cin >> temp; + sup.push_back(temp); + } + sort(sup.begin(), sup.end()); + int ans = 0; + while (m < k) { + if (sup.size() == 0) { + ans = -1; + break; + } + m += sup[sup.size() - 1] - 1; + sup.pop_back(); + ans++; + } + cout << ans << '\n'; + return 0; +} +const int N = 1e5 + 50; +const int oo = 1e9; +const int mod = 1e9 + 7; +string a[2001], b[201], f1[2001], f2[2001]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + for (int i = 0; i + m <= n; i++) { + f1[i] = ""; + for (int j = 0; j < m; j++) f1[i] += a[i + j]; + } + for (int i = 0; i + m <= n; i++) { + f2[i] = ""; + for (int j = 0; j < m; j++) { f2[i] += b[j].substr(i, m); } + } + for (int i = 0; i + m <= n; i++) { + for (int j = 0; j + m <= n; j++) { + if (f1[i] == f2[j]) { + cout << i + 1 << ' ' << j + 1 << endl; + return 0; + } + } + } +} +int main() { + int n, p, arr[2000]; + cin >> n; + for (int i = 1; i <= n; i++) { + int p; + cin >> p; + arr[i] = p; + } + int cnt = 0; + for (int i = 1; i <= n; i++) { + if (arr[i] == 1 || (arr[i - 1] + arr[i + 1]) == 2) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + size_t pos = 0; + while (pos < s.length() && s[pos] != 'h') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'e') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'o') ++pos; + if (pos < s.length()) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int wrong = 0; + int coA = 0; + int coB = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[i]) wrong++; + if (a[i] == '7') coA++; + if (b[i] == '7') coB++; + } + int ops = abs(coB - coA); + wrong -= ops; + cout << ops + (wrong / 2) << endl; +} +int n, p; +char s[1005]; +bool get_ans(int pos) { + if (pos == n) return true; + for (; s[pos] - 'a' < p; s[pos]++) { + if (pos && s[pos - 1] == s[pos]) continue; + if (pos > 1 && s[pos - 2] == s[pos]) continue; + if (get_ans(pos + 1)) return 1; + } + s[pos] = 'a'; + return 0; +} +int main() { + cin >> n >> p; + cin >> s; + ++s[strlen(s) - 1]; + if (get_ans(0)) { + cout << s << "\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n; + int a[200010]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + if (n == 2) { + cout << a[2] - a[1] << endl; + return 0; + } + int mm = 1000000000; + for (int i = n / 2 + 1; i <= n; i++) { mm = min(a[i] - a[i - n / 2], mm); } + cout << mm << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int t = n % 10; + if (t >= 6) + n = n - t + 10; + else + n = n - t; + cout << n << endl; +} +int arr[150]; +int main() { + memset(arr, 0, sizeof(arr)); + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int i = 1; i <= x; i++) { + int y; + cin >> y; + arr[y] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (arr[i] == 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, i, j, x, ans; + vector vec; + while (cin >> n) { + for (i = 1; i <= n; i++) { + cin >> x; + vec.push_back(x); + } + sort(vec.begin(), vec.end()); + int flag = 0; + for (i = n - 1; i >= 0; i--) { + ans = sqrt(vec[i]); + ans *= ans; + if (ans != vec[i]) { + flag = i; + break; + } + } + cout << vec[flag] << endl; + } + return 0; +} +int dp[26][26]; +char p[5]; +string s; +int main() { + cin >> s; + int len = s.length(); + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p; + dp[p[0] - 'a'][p[1] - 'a'] = dp[p[1] - 'a'][p[0] - 'a'] = 1; + } + if (len == 1) + cout << "0" << endl; + else { + int ans = 0; + for (int i = 0; i <= 25; i++) + for (int j = i + 1; j <= 25; j++) { + if (!dp[i][j]) continue; + char c[2]; + c[0] = i + 'a'; + c[1] = j + 'a'; + int g[2]; + g[0] = g[1] = 0; + for (int k = 0; k < s.length(); k++) { + if (s[k] == c[0]) + g[0]++; + else if (s[k] == c[1]) + g[1]++; + else { + ans += min(g[0], g[1]); + g[0] = g[1] = 0; + } + } + ans += min(g[0], g[1]); + } + cout << ans << endl; + } +} +int main() { + long long int A, B, C, X, Y, sum = 0; + cin >> A >> B >> C; + for (int i = 1; i <= C; i++) { + X = (A * i); + sum += X; + } + Y = sum - B; + if (sum > B) + cout << Y << endl; + else + cout << 0 << endl; + return 0; +} +int amount = 0, request = 0, r = 0; +int main() { + cin >> request; + vector amounts; + vector gs; + for (int i = 0; i < request; i++) { + int a; + string g; + cin >> a >> g; + amounts.push_back(a); + gs.push_back(g); + } + for (int y = 0; y < request; y++) { + vector a; + for (int j = 0; j < amounts[y]; j++) { + char t = gs[y][j]; + a.push_back((int)t - '0'); + } + if (amounts[y] == 1) { cout << "NO" << endl; } + if (amounts[y] == 2) { + if (a[0] == a[1]) { + cout << "NO" << endl; + } else if (a[0] > a[1]) { + cout << "NO" << endl; + } else if (a[1] > a[0]) { + cout << "YES" << endl << "2" << endl << a[0] << " " << a[1] << endl; + } + } + if (amounts[y] > 2) { + cout << "YES" << endl << "2" << endl; + cout << a[0] << " "; + for (int i = 1; i < amounts[y]; i++) { cout << a[i]; } + cout << endl; + } + } + cin >> amounts[0]; + return (0); +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int k1 = 0, t1 = t, i = -1; + d += t; + if (k >= n) { + cout << "NO" << endl; + return 0; + } + int counter = ceil((float)n / k) * t; + while (k1 < n) { + if (i == t1) { + k1 += k; + t1 += t; + } + if (i == d) { + k1 += k; + d += t; + } + if (k1 < n) ++i; + } + if (i < counter) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i = 0; + for (;; i++) { + if (n > 0 && m > 0) { + n--; + m--; + } else + break; + } + if (i % 2 == 0) cout << "Malvika" << endl; + if (i % 2 == 1) cout << "Akshat" << endl; +} +int main() { + int i, j, flag = 1, dot = 0; + string ch; + cin >> ch; + for (i = 0; i < ch.length(); i++) { + if (ch[i] == '@') { + if (i > 16 || i < 1) { + flag = 0; + goto print; + } + break; + } else if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z')) + continue; + else if ((ch[i] >= '0' && ch[i] <= '9') || (ch[i] == '_')) + continue; + else { + flag = 0; + goto print; + } + } +dot: + for (j = i + 1; j < ch.length(); j++) { + if (ch[j] == '.') { + if (j - i > 17 || j - i < 2) { + flag = 0; + goto print; + } + i = j; + } else if ((ch[j] >= 'a' && ch[j] <= 'z') || (ch[j] >= 'A' && ch[j] <= 'Z')) + continue; + else if ((ch[j] >= '0' && ch[j] <= '9') || (ch[j] == '_')) + continue; + else if (ch[j] == '/') { + if (j - i > 17 || j - i < 2) { + flag = 0; + goto print; + } + i = j; + } else { + flag = 0; + goto print; + } + } + if (j - i > 17 || j - i < 2) flag = 0; +print: + (flag) ? (cout << "YES\n") : (cout << "NO\n"); + return 0; +} +int a[1000]; +int main() { + int n; + cin >> n; + for (int x, y, s, i = 1; i <= n; i++) { + s = 0; + cin >> x >> y; + while (x > 0 && y > 0) { + if (x > y) { + s += x / y; + x = (x % y); + } else { + s += y / x; + y = (y % x); + } + if (x == y) { + s++; + break; + } + } + a[i] = s; + } + for (int i = 1; i <= n; i++) cout << a[i] << endl; +} +int main() { + long long int n, m, p = 0, q, r, s, t, u, v, w, x, y, z, L, l, i, j; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> L >> v >> l >> r; + x = L / v - r / v; + y = (l - 1) / v; + cout << x + y << '\n'; + } +} +int main() { + int n; + cin >> n; + int a, b; + a = n / 10; + b = (n - n % 100) / 10 + n % 10; + cout << max(a, max(b, n)) << endl; + return 0; +} +int main() { + int p[4]; + for (int i = 0; i < 4; i++) cin >> p[i]; + int esq, dir; + cin >> esq >> dir; + int res = 0; + for (int i = esq; i <= dir; i++) { + sort(p, p + 4); + int cnt = 0; + do { + int x = i; + for (int j = 0; j < 4; j++) x = x % p[j]; + if (x == i) cnt++; + } while (next_permutation(p, p + 4)); + if (cnt >= 7) res++; + } + cout << res << endl; + return 0; +} +int main() { + set s; + map mp; + int cnt = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp != 0) s.insert(temp); + mp[temp]++; + } + { + while (s.size()) { + int f = *s.begin(); + s.erase(f); + if (mp[f] > 2) { + cout << -1 << endl; + return 0; + } + if (mp[f] == 2) cnt++; + } + } + cout << cnt << endl; +} +int main() { + int n, k, i, l, Min = 100000; + int a[1000] = {0}; + cin >> n >> k; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + l = k % a[i]; + if (l == 0 && (k / a[i]) <= Min) { Min = k / a[i]; } + } + cout << Min << endl; + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n; + long long a[110]; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long res = a[0]; + for (int i = 1; i < n; i++) res = gcd(res, a[i]); + long long ans = a[n - 1] / res - n; + if (ans & 1) + cout << "Alice\n"; + else + cout << "Bob\n"; + } + return 0; +} +long long gcd(long long b, long long y) { + return b > 0 ? gcd(y % b, b) : y; +} +long long lcm(long long b, long long y) { + return b * y / gcd(b, y); +} +double dis(double x1, double x2, double y1, double y2) { + double ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); + return sqrt(ans); +} +double random(double start, double en) { + return start + (en - start) * rand() / (RAND_MAX + 1.0); +} +void read(int &n) { + char c = '+'; + int x = 0; + bool flag = 0; + while (c < '0' || c > '9') { + c = getchar(); + if (c == '-') flag = 1; + } + while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar(); + n = flag == 1 ? -x : x; +} +double F(double x, double y) { + return 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x; +} +double FF(double x, double y) { + return 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * pow(x, 2) + 10 * x - y; +} +int main() { + int n, k; + cin >> n >> k; + int a[110]; + int l, r; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (i == 1) + l = a[i]; + else + l = max(a[i], l); + } + r = l + k; + int MIN, MAX = r; + int ans; + while (l <= r) { + int mid = (l + r) / 2; + int sum = 0; + for (int i = 1; i <= n; i++) { sum += mid - a[i]; } + if (sum >= k) { + ans = mid; + r = mid - 1; + } else + l = mid + 1; + } + cout << ans << " " << MAX << endl; +} +map mp; +long long lca(long long u, long long v, long long w = 0) { + long long ans = 0; + while (v != u) { + if (v < u) swap(u, v); + if (mp.find(v) != mp.end()) ans += mp[v]; + if (w) mp[v] += w; + v /= 2; + } + return ans; +} +int main() { + int q, tp; + long long u, v, w; + cin >> q; + while (q--) { + cin >> tp >> v >> u; + if (tp == 1) { + cin >> w; + lca(u, v, w); + } else + cout << lca(u, v) << endl; + } +} +const int MaxN = 100005; +const int inf = 1e8; +const double PI = acos(-1); +set st; +map mp; +int main() { + int t; + cin >> t; + while (t--) { + string s; + cin >> s; + set check; + int len = s.length(); + for (int i = 0; i < len; i++) check.insert(s[i]); + string tmp = ""; + for (set::iterator it = check.begin(); it != check.end(); it++) { tmp += *it; } + st.insert(tmp); + } + cout << st.size() << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + stack sta1; + while (n--) { + int temp; + cin >> temp; + sta1.push(temp); + } + int ans = 0; + while (sta1.size() > 1) { + int temp = sta1.top(); + sta1.pop(); + ans++; + if (temp - sta1.top() > m) + if (sta1.size() == 1) + ans--; + else + break; + } + if (sta1.size() == 1) ans++; + cout << ans << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int c = 0; + int C = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] > 96) + c++; + else + C++; + } + if (c >= C) + transform(s.begin(), s.end(), s.begin(), ::tolower); + else + transform(s.begin(), s.end(), s.begin(), ::toupper); + cout << s << endl; + return 0; +} +long long LCM(long long A, long long B) { + return (A * B) / __gcd(A, B); +} +int main() { + long long A, B; + cin >> A >> B; + long long lcm = LCM(A, B); + int dasha = lcm / A; + int masha = lcm / B; + if (dasha < masha) + dasha++; + else + masha++; + if (dasha > masha) + cout << "Dasha"; + else if (dasha < masha) + cout << "Masha"; + else + cout << "Equal"; + cout << '\n'; +} +int main() { + int n; + cin >> n; + int summ = 0, sumc = 0; + int a, b; + while (n--) { + cin >> a >> b; + if (a > b) + summ++; + else if (a < b) + sumc++; + } + if (summ > sumc) { + cout << "Mishka" << endl; + } else if (summ < sumc) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +long long nu[100100]; +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 0; i < n; i++) { + int b; + cin >> b; + sum += b; + } + cout << sum / n << endl; + return 0; +} +int main() { + string s; + cin >> s; + string t = "QAQ"; + long long n = s.length(); + long long m = t.length(); + vector dp(m + 1, 0); + dp[0] = 1; + for (long long C = 0; C < s.length(); C++) { + for (long long X = m - 1; X >= 0; X--) { + if (t[X] == s[C]) { dp[X + 1] += dp[X]; } + } + } + cout << dp[m] << "\n"; + return 0; +} +int main() { + float n; + cin >> n; + for (int i = 1; i <= ceil(n / 2); i++) { + for (int j = 1; j <= ceil(n / 2) - i; j++) cout << "*"; + for (int j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (int j = 1; j <= ceil(n / 2) - i; j++) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - i * 2; j++) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << endl; + } + return 0; +} +const int maxn = 80005; +int main() { + int m, n; + while (cin >> n >> m) { + queue q1, q2; + int sum = 0, t; + for (int i = 1; i <= n; i++) { + cin >> t; + q1.push(t); + } + for (int i = 1; i <= m; i++) { + cin >> t; + q2.push(t); + } + while (!q1.empty() && !q2.empty()) { + int p = q1.front(), q = q2.front(); + if (p <= q) { + sum++; + q1.pop(); + q2.pop(); + } else { + q1.pop(); + } + } + cout << sum << endl; + } + return 0; +} +int main() { + int n; + string s; + cin >> s; + n = s.size(); + cout << ((n + 1) * 25) + 1 << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[55]; + int sum = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int res = 0; + int x = n - 1; + if (k >= m) + res = 0; + else { + m -= a[n - 1]; + k--; + if (k >= m) + res = 1; + else { + for (int i = n - 2; i >= 0; i--) { + m = m - (a[i] - 1); + if (k >= m) { + res = n - i; + break; + } + } + if (m > k) res = -1; + } + } + cout << res << endl; +} +int main() { + long long int n; + cin >> n; + long long int a[n], c = 0; + long long int x[101] = {0}; + for (int i = 0; i < n; i++) { + cin >> a[i]; + x[a[i]]++; + } + cout << *max_element(x, x + 101) << endl; + return 0; +} +int main() { + long long int s, n, i, j, p, h = 0; + cin >> n; + if (n == 0) + cout << "0" << endl; + else if (n % 2 == 0) + cout << n + 1 << endl; + else + cout << (n + 1) / 2 << endl; +} +int main() { + long long n, k; + char a[3][10] = {"012210", "100122", "221001"}; + cin >> n >> k; + n = n % 6; + for (int i = 0; i < 3; i++) { + if ((a[i][n] - '0') == k) cout << i << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0, x, mx = 0; + for (int i = 0; i < n; i++) { + cin >> x; + sum += x; + mx = max(mx, x); + } + sum *= 2; + sum++; + cout << max((int)ceil((double)sum / n), mx) << endl; +} +int a[110], b[110]; +int cmp(int a, int b) { + return b < a; +} +int main() { + int n, k; + cin >> n >> k; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) { count++; } + } + for (int i = 0; i < k; i++) { cin >> b[i]; } + if (count > k) { + cout << "No" << endl; + return 0; + } + sort(b, b + k, cmp); + int j = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + a[i] = b[j]; + j++; + } + } + for (int i = 1; i < n; i++) { + if (a[i] < a[i - 1]) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +map m; +void solve() { + int k; + cin >> k; + string s; + cin >> s; + int n = s.size(); + if (n % k != 0) { + cout << -1 << endl; + return; + } + int need = n / k; + for (int i = 0; i < n; i++) { m[s[i]]++; } + string t = ""; + for (int i = 97; i < 123; i++) { + if (m[char(i)] % k == 0) { + for (int j = 0; j < m[char(i)] / k; j++) { t += char(i); } + } else { + cout << -1 << endl; + return; + } + } + for (int i = 0; i < k; i++) { cout << t; } + cout << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + if (n == 1) { + cout << 1 << endl; + return 0; + } + for (int i = 0; i < n; i++) { + a[i][0] = 1; + a[0][i] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +int main() { + int a[1000], b[1000], c[1000], n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 2; i++) { b[i] = a[i + 2] - a[i]; } + for (int i = 0; i < n - 1; i++) { c[i] = a[i + 1] - a[i]; } + int min1 = 999999, max2 = 0, min; + for (int i = 0; i < n - 2; i++) { + if (b[i] < min1) min1 = b[i]; + } + for (int i = 0; i < n - 1; i++) { + if (c[i] > max2) max2 = c[i]; + } + if (min1 < max2) min1 = max2; + cout << min1 << endl; + return 0; +} +int main() { + char str[15]; + char ma = 'a' - 1; + cin >> str; + for (int i = 0; i < 10 && str[i] != '\0'; i++) { + if (str[i] > ma) ma = str[i]; + } + for (int i = 0; i < 10 && str[i] != '\0'; i++) { + if (str[i] == ma) cout << str[i]; + } + cout << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + s.push_back('D'); + int i = 0, j = 0; + for (j = 0; j < t.size(); j++) { + if (s[i] == t[j]) i++; + } + cout << i + 1 << endl; + return 0; +} +unsigned long int pangkat(long int a, int n) { + if (n == 0) return 1; + unsigned long int temp; + temp = pangkat(a, n / 2); + temp *= temp; + if (n % 2 == 1) { temp *= a; } + return temp; +} +int main() { + unsigned long int a, b; + cin >> a >> b; + if (a >= 32) { + cout << b; + } else { + unsigned long int temp; + temp = pangkat(2, a); + cout << b % temp; + } + cout << endl; +} +int main() { + int n, k, l, c, d, p, nl, np; + while (cin >> n >> k >> l >> c >> d >> p >> nl >> np) { + int x, y, z; + x = (k * l) / nl; + y = c * d; + z = p / np; + int ans = min(x, y); + ans = min(ans, z); + cout << ans / n << endl; + ; + } + return 0; +} +int main() { + long long a[15][15]; + int n; + cin >> n; + for (int i = 1; i <= 10; i++) { + a[1][i] = 1; + a[i][1] = 1; + } + for (int i = 2; i <= 10; i++) { + for (int j = 2; j <= 10; j++) { a[i][j] = a[i][j - 1] + a[i - 1][j]; } + } + cout << a[n][n] << endl; +} +set st[55]; +int x, y, c; +string s[9], s1[9]; +int main() { + int l = 0, r = 0, k; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + k = 0; + for (int j = 0; j < 8; j++) + if (s[i][j] == 'B') k++; + if (k == 8) + l++; + else + r = k; + } + cout << l + r << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = int(0); i < int(n); i++) { + if (s[i] != '4' && s[i] != '7') { + cout << "NO" << endl; + return 0; + } + } + int r4 = 0, r7 = 0, l4 = 0, l7 = 0; + for (int i = int(0); i < int(n / 2); i++) { + if (s[i] == '4') + l4++; + else + l7++; + } + for (int i = int(n / 2); i < int(n); i++) { + if (s[i] == '4') + r4++; + else + r7++; + } + if (r4 == l4 && r7 == l7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + { + int m, x, y, k; + cin >> m; + vector v(m); + bool b = 1; + for (int i = 0; i < m && b; i++) cin >> v[i]; + cin >> x >> y; + for (int i = 1; i <= m && b; i++) { + int yx = 0, xx = 0; + for (int j = 0; j < m; j++) + if ((j + 1) >= i) + yx += v[j]; + else + xx += v[j]; + if (yx >= x && yx <= y && xx >= x && xx <= y) { + b = 0; + k = i; + } + } + if (b) + cout << 0 << endl; + else + cout << k << endl; + } + return 0; +} +int main() { + int a[100]; + int n, count, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i <= n; i++) { + count = 0; + for (int j = i; j < n; j++) { + if (a[j] == 1) count++; + } + for (int k = 0; k < i; k++) { + if (a[k] == 0) count++; + } + ans = max(ans, count); + } + cout << ans << endl; +} +int main() { + long long n; + while (cin >> n) { + if (n == 1) { + cout << 5 << endl; + } else { + cout << 25 << endl; + } + } +} +int main() { + int n, m; + cin >> n >> m; + vector x(n + 1); + for (int i = 0; i < n; i++) { cin >> x[i]; } + x[n] = (int)1e9; + vector y; + for (int i = 0; i < m; i++) { + int x1, x2, tmp; + cin >> x1 >> x2 >> tmp; + if (x1 == 1) { y.push_back(x2); } + } + sort(x.begin(), x.end()); + sort(y.begin(), y.end()); + int j = 0; + int ans = (int)1e9; + for (int i = 0; i <= n; i++) { + while (j < (int)y.size() && y[j] < x[i]) { j++; } + ans = min(ans, i + (int)y.size() - j); + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, i, sum = 0, k; + cin >> n; + char a[n], b[n]; + cin >> a >> b; + for (i = 0; i < n; i++) { + k = abs(a[i] - b[i]); + if (k > 5 && b[i] > a[i]) + k = 10 - b[i] + a[i]; + else if (k > 5 && b[i] < a[i]) + k = 10 + b[i] - a[i]; + sum = sum + k; + } + cout << sum << endl; + return 0; +} +long long n, m, ans, cnt = 1, sum, x, y; +int main() { + cin >> n; + ans = (n / 2); + if (n % 2 != 0) + sum = (n / 2) + 2; + else + sum = (n / 2) + 1; + for (int i = 1; i <= (n / 2) + 1; i++) { + for (int j = i; j <= (n / 2); j++) cout << "*"; + for (int l = ans; l <= (n / 2); l++) cout << "D"; + for (int h = sum; h <= n; h++) cout << "*"; + cout << endl; + ans -= 2; + sum++; + } + if (n % 2 != 0) + x = n - 2; + else + x = n - 1; + cnt = n; + for (int i = 1; i <= (n / 2); i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int l = 1; l <= x; l++) cout << "D"; + for (int h = cnt; h <= n; h++) cout << "*"; + cout << endl; + x -= 2; + cnt--; + } +} +vector p, m, t; +int main() { + int n, temp; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> temp; + if (temp == 1) + p.push_back(i + 1); + else if (temp == 2) + m.push_back(i + 1); + else if (temp == 3) + t.push_back(i + 1); + } + int ans1 = min(min(p.size(), m.size()), t.size()); + cout << ans1 << endl; + for (int i = 0; i < ans1; ++i) { cout << p[i] << " " << m[i] << " " << t[i] << endl; } +} +int main() { + int n, t, b, a[100000]; + cin >> n >> t; + for (int i = 0; i < n - 1; i++) cin >> a[i]; + for (int j = 1; j < n;) { + b = j + a[j - 1]; + if (b == t) { + cout << "YES" << endl; + return 0; + } + j = b; + } + cout << "NO" << endl; + return 0; +} +long long a; +long long b; +long long m; +long long cont = 0; +long long suma; +int main() { + cin >> a >> b >> m; + if (m > max(a, b) && b <= 0 && a <= 0) { + cout << -1 << endl; + goto salir; + } + suma = a + b; + b = max(a, b); + a = suma - b; + if (b >= m) { + cout << 0 << endl; + goto salir; + } + if (a < 0) { + long long k = (-a) / b; + cont = k; + a += k * b; + } + for (long long i = 0; i <= 1000000; i++) { + suma = a + b; + b = max(a, b); + a = suma - b; + if (b >= m) { + cout << cont << endl; + goto salir; + } + cont++; + a = suma; + } +salir:; +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +int main() { + long long q; + cin >> q; + while (q--) { + long long a, b; + cin >> a >> b; + long long prod = a * b; + long long round1 = round(cbrt(prod)); + if (a % round1 == 0 && b % round1 == 0) { + if (round1 == 1) { + if (a == 1 && b == 1) + cout << "Yes" + << "\n"; + else + cout << "No" + << "\n"; + } else + cout << "Yes" + << "\n"; + } else + cout << "No" + << "\n"; + } + return 0; +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + k = (k * l) / nl; + c = c * d; + p = p / np; + int ans = min(k, c); + ans = min(ans, p); + cout << ans / n << endl; +} +const int maxn = 1e5 + 10; +int vis[10005]; +int main() { + int n, m, q, x; + while (cin >> n >> m) { + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < n; i++) { + cin >> q; + while (q--) { + cin >> x; + vis[x] = 1; + } + } + int blag = 0; + for (int i = 1; i <= m; i++) + if (vis[i] == 0) blag = 1; + if (blag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n & 1) + cout << 1 << endl; + else + cout << 2 << endl; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int a[3]; + memset(a, 0, sizeof a); + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int v; + cin >> v; + a[i % 3] += v; + } + if (a[0] > a[1] and a[0] > a[2]) cout << "chest" << endl; + if (a[1] > a[0] and a[1] > a[2]) cout << "biceps" << endl; + if (a[2] > a[1] and a[2] > a[0]) cout << "back" << endl; + return 0; +} +int main() { + int row, col; + bool flag = false; + cin >> row >> col; + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + if (i % 2 == 0) + cout << "#"; + else { + if (!flag) { + if (j == col - 1) + cout << "#"; + else + cout << "."; + if (j == col - 1) flag = true; + } else if (flag) { + if (j == 0) + cout << "#"; + else + cout << "."; + if (j == col - 1) flag = false; + } + } + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + long long int l, r, x, y, k, flag = 0; + cin >> l >> r >> x >> y >> k; + for (int j = x; j <= y; j++) { + if ((k * j) >= l && (k * j) <= r) { flag = 1; } + } + if (flag) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << (n / 2) * 3 << endl; + return 0; +} +string str[100000]; +int n, ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> str[i]; + int size = str[0].size(); + for (int i = 0; i < size; i++) { + char ch = str[0].at(i); + for (int j = 0; j < n; j++) { + if (str[j].at(i) != ch) return cout << ans << endl, 0; + } + ans++; + } + cout << ans << endl; + return 0; +} +bool mark[32]; +int main() { + int k; + string s; + cin >> k >> s; + for (int i = 0; i < s.size(); i++) mark[s[i] - 'a'] = true; + int num = 0; + for (int i = 0; i < 26; i++) { + if (mark[i]) num++; + } + if (num < k) { + cout << "NO" << endl; + return 0; + } + memset(mark, 0, sizeof mark); + cout << "YES"; + int p = 0, l = 0; + while (p < s.size()) { + if (!mark[s[p] - 'a'] && l < k) { + l++; + cout << endl; + } + mark[s[p] - 'a'] = true; + cout << s[p]; + p++; + } + cout << endl; + return 0; +} +int a[20]; +int main() { + int k; + cin >> k; + for (int i = 1; i <= 12; ++i) cin >> a[i]; + a[0] = 0; + sort(a + 1, a + 13); + int i = 12; + for (; i >= 0; --i) { + if (k <= 0) { + cout << 12 - i << endl; + return 0; + } + k -= a[i]; + } + cout << -1 << endl; +} +int main() { + int n, a[100005], p[100005], ans = 0, c = 105; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i] >> p[i]; + if (p[i] < c) c = p[i]; + ans += (c * a[i]); + } + cout << ans << endl; + return 0; +} +int main() { + int k, a, b, v, total, sum; + while (cin >> k >> a >> b >> v) { + sum = 0; + while (a > 0) { + sum += 1; + if (v < a) { + if (k <= b + 1) { + b = b - k + 1; + a -= k * v; + } else { + a -= (b + 1) * v; + b = 0; + } + } else + a = -5; + } + cout << sum << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 2) { + cout << n << endl; + } else { + cout << 1 << endl; + } +} +int a[4]; +int dp[4001]; +int main() { + int n; + cin >> n >> a[1] >> a[2] >> a[3]; + memset(dp, -42, sizeof(dp)); + dp[0] = 0; + for (int i = 1; i <= 3; i++) { + for (int j = a[i]; j <= n; j++) { dp[j] = max(dp[j], dp[j - a[i]] + 1); } + } + cout << dp[n] << endl; +} +string s; +int main() { + cin >> s; + int i = s.size() - 1; + while (i > 0) { + if (s[i] == s[i - 1]) { s.erase(i - 1, 2); } + --i; + } + cout << s << "\n"; + return 0; +} +int main() { + int a, b, c = 0, d, e, f, g, h, i = 0, j = 0, n, m; + string s = "tttt"; + string p, q; + cin >> n >> m; + cin >> p; + while (i < n - 1) { + cin >> q; + while (j < m - 1) { + s[0] = p[j]; + s[1] = p[j + 1]; + s[2] = q[j]; + s[3] = q[j + 1]; + sort(s.begin(), s.end()); + if (s == "acef") { c++; } + s = "tttt"; + j++; + } + i++; + j = 0; + p = q; + } + cout << c << endl; + return 0; +} +int main() { + char s[101]; + int n, i, sum8 = 0, sum = 0, total = 0; + cin >> n; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == '8') sum8++; + sum++; + } + if (sum8 >= sum / 11) + total = sum / 11; + else + total = sum8; + cout << total << endl; + return 0; +} +int main() { + long long n, i; + cin >> n; + string s = "I hate it"; + for (i = 2; i <= n; i++) { + long long tam = s.size(); + s.erase(tam - 3, tam); + if (i % 2 == 0) + s += " that I love it"; + else + s += " that I hate it"; + } + cout << s << endl; + return 0; +} +const long long N = 1e8 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, m, cnt, mx = MX; +string a, b; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> a >> b; + if (max(a.size(), b.size()) > min(a.size(), b.size())) { + cout << max(a.size(), b.size()); + } else { + while (true) { + if (a != b) { + cout << a.size(); + break; + } + a = a.substr(0, a.size() - 1); + b = b.substr(0, b.size() - 1); + if (a.size() == 0) { + cout << -1; + break; + } + } + } + cout << "\n"; + return 0; +} +int n, c, x; +int a[1000000]; +int main() { + cin >> n >> c; + x == 1; + if (n == 1) { + cout << 1 << endl; + return 0; + } + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] - a[i - 1] <= c) { + x++; + } else + x = 1; + } + cout << x << endl; +} +int main() { + int a, b, c, x, cal = 0, count = 0; + cin >> a >> b >> c; + x = a * c; + for (int i = 0;; i++) { + cal = b + cal; + ++count; + if (cal >= x) { + cout << count - c << endl; + break; + } + } +} +inline bool c(int x) { + while (x) { + if (x % 10 == 7) { return 1; } + x /= 10; + } + return 0; +} +int main() { + int a, m, b; + int ans = 0; + cin >> a >> m >> b; + while (1) { + if (c(m) || c(b)) { + cout << ans << endl; + return 0; + } + ans++; + b -= a; + while (b < 0) { + b += 60; + m--; + } + while (m < 0) { m += 24; } + } + return 0; +} +int main() { + int x; + int next; + cin >> x >> next; + if (x == 2) { + if (next == 3) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else { + int actual_next; + while (true) { + bool prime = true; + x++; + if (x % 2 == 0) { + continue; + } else { + for (int i = 3; i <= (int)sqrt((double)x); i += 2) { + if (x % i == 0) { + prime = false; + break; + } + } + } + if (prime) { + actual_next = x; + break; + } + } + if (actual_next == next) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + string s; + cin >> s; + if (s.length() < 5) { + cout << "Too weak" << endl; + return 0; + } + bool cont_big_word = false, cont_little_word = false, cont_cifra = false; + for (int i = 0; i < s.length(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') + cont_little_word = true; + else if (s[i] >= 'A' && s[i] <= 'Z') + cont_big_word = true; + else if (s[i] >= '0' && s[i] <= '9') + cont_cifra = true; + } + if (cont_little_word && cont_big_word && cont_cifra) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +int a[100]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +int main() { + string s; + int num = 0; + while (cin >> s) { + for (int i = 0; i < s.length(); i++) + if (strchr("aeiou13579", s[i])) num++; + cout << num << endl; + } + return 0; +} +int main() { + int n, t; + cin >> n >> t; + int read = 0; + for (int day = 1; day <= n; day++) { + int busy; + cin >> busy; + read += 86400 - busy; + if (read >= t) { + cout << day << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int less = 10001, more = -1, amazing = 0; + int in = 0; + for (int i = 0; i < n; i++) { + cin >> in; + if (in > more) { + amazing++; + more = in; + } + if (in < less) { + amazing++; + less = in; + } + } + cout << amazing - 2 << endl; +} +int main() { + string s; + cin >> s; + for (long long int i = 0; i < s.length(); i++) { + if (s[i] == '9') { + if (i == 0) + continue; + else + s[i] = '0'; + continue; + } + if ((s[i] - '0') > 4) s[i] = 48 + 9 - (s[i] - '0'); + } + cout << s << "\n"; +} +int main() { + int n; + cin >> n; + int i[n], j; + for (j = 0; j < n; j++) { cin >> i[j]; } + int a = 0, b = 0, c = 0; + for (j = 0; j < n; j++) { + if (i[j] == 1) { a++; } + if (i[j] == 2) { b++; } + if (i[j] == 3) { c++; } + } + int x, y; + if (a < b && a < c) { + cout << a << endl; + x = a; + } + if (b <= a && b <= c) { + cout << b << endl; + x = b; + } + if (c <= a && c < b) { + cout << c << endl; + x = c; + } + int i1[n], i2[n], i3[n]; + a = 0; + b = 0; + c = 0; + for (j = 0; j < n; j++) { + if (i[j] == 1) { + i1[a] = j + 1; + a++; + } else if (i[j] == 2) { + i2[b] = j + 1; + b++; + } else if (i[j] == 3) { + i3[c] = j + 1; + c++; + } + } + for (j = 0; j < x; j++) { cout << i1[j] << " " << i2[j] << " " << i3[j] << endl; } + return 0; +} +const int maxn = 1000; +char c[maxn]; +int main() { + int n; + int ans = 0; + cin >> n; + while (cin >> c) { + int cnt = 0; + for (int i = 0; i < strlen(c); i++) { + if (c[i] >= 'A' && c[i] <= 'Z') { cnt++; } + } + ans = max(ans, cnt); + } + cout << ans << endl; + return 0; +} +const int maxn = 2e5 + 7; +int p[50], n, a, b, ans; +int main() { + cin >> n >> a >> b; + for (int i = 0; i < n; i++) cin >> p[i]; + for (int i = 0; i < n / 2; i++) { + if (p[i] == p[n - i - 1]) { + if (p[i] == 2) ans += 2 * min(a, b); + } else { + if (p[i] == 2 || p[n - i - 1] == 2) { + if (p[i] == 2) swap(p[i], p[n - i - 1]); + ans += p[i] ? b : a; + } else + return cout << -1 << endl, 0; + } + } + if (n & 1 && p[n / 2] == 2) ans += min(a, b); + cout << ans << endl; + return 0; +} +void solve() { + string s; + cin >> s; + int t = 0; + int qmarks = 0; + int count = 0; + for (size_t i = 0; i < s.length(); ++i) { + t = 0; + qmarks = 0; + for (size_t j = i; j < s.length(); ++j) { + if (s[j] == '(') { + ++t; + } else if (s[j] == ')') + --t; + else + ++qmarks; + if (qmarks > t) { + if (qmarks > 0) { + --qmarks; + ++t; + } else + break; + } + if ((j - i + 1) % 2 == 0 && qmarks >= t) { ++count; } + } + } + cout << count << '\n'; +} +int main() { + solve(); + return 0; +} +int main() { + string s; + while (cin >> s) { + int ans = 0; + for (int i = 0; i < s.size(); i++) { + int num = 0, l = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == '(') + l++; + else if (s[j] == ')') + l--; + else if (s[j] == '?') + l--, num++; + if (!l) ans++; + if (l < 0 && num > 0) + l += 2, num--; + else if (l < 0 && num <= 0) + break; + } + } + cout << ans << endl; + } +} +int main() { + int CountOfMoney, Sum = 0, Hand = 0, Count = 0; + cin >> CountOfMoney; + vector list(CountOfMoney); + for (int i = 0; i < CountOfMoney; i++) { + cin >> list[i]; + Sum += list[i]; + } + for (int i = 0; i < list.size() - 1; i++) + for (int j = 0; j < list.size() - 1 - i; j++) + if (list[j] >= list[j + 1]) swap(list[j], list[j + 1]); + while ((Hand <= Sum) & (Sum != 0)) { + Sum -= list[list.size() - 1]; + Hand += list[list.size() - 1]; + list.pop_back(); + Count++; + } + cout << Count << endl; +} +int main() { + int a, b; + while (cin >> a >> b) { + if (a > b) a = b; + if (a % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } +} +int n, m; +int a[200025], b[200025]; +int v = 0x3f3f3f3f, p, c = 0x3f3f3f3f; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + cin >> a[i]; + v = min(v, a[i]); + p = max(p, a[i]); + } + for (int i = 1; i <= m; ++i) { + cin >> b[i]; + c = min(c, b[i]); + } + if (max(2 * v, p) < c) + cout << max(2 * v, p) << '\n'; + else + cout << "-1\n"; + return 0; +} +int main() { + int n; + cin >> n; + int chest = 0, biceps = 0, back1 = 0, x; + for (int i = 0; i < n; i++) { + cin >> x; + if (i % 3 == 0) + chest += x; + else if (i % 3 == 1) + biceps += x; + else if (i % 3 == 2) + back1 += x; + } + if (chest > biceps) { + if (chest > back1) + cout << "chest\n"; + else + cout << "back\n"; + } else if (chest <= biceps) { + if (biceps > back1) + cout << "biceps\n"; + else + cout << "back\n"; + } +} +int main() { + int n; + int z; + int v; + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + z = n / 10; + v = n / 100 * 10 + n % 10; + if (z > v) { + cout << z << endl; + } else { + cout << v << endl; + } + } +} +inline int max(int a, int b) { + return a > b ? a : b; +} +inline int min(int a, int b) { + return a < b ? a : b; +} +inline int abs(int x) { + return x < 0 ? -x : x; +} +inline void swap(int &x, int &y) { + int tmp = x; + x = y; + y = tmp; +} +inline void read(int &x) { + x = 0; + char ch = getchar(), c = ch; + while (ch < '0' || ch > '9') c = ch, ch = getchar(); + while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); + if (c == '-') x = -x; +} +const int INF = 0x3f3f3f3f; +long long int n; +long long int m; +long long int t; +long long int test; +int main() { + while (cin >> n) { + m = 1; + t = 1; + while (m <= n) { + test = m; + m += t; + t++; + } + cout << n - test + 1 << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + cout << n + n / 2 << endl; +} +int main() { + int n; + char draw[202][202]; + cin >> n; + if (n % 2 == 0 || n > 201) { + cout << "n%2==0||n > 201"; + return 0; + } + for (int i = 0; i < n; i++) { + for (int k = 0; k < n; k++) { draw[i][k] = '*'; } + } + int Mid = n / 2; + int DiamondCount = 0; + for (int i = 0; i < n; i++) { + if (i <= Mid) { + DiamondCount = 2 * i + 1; + } else { + DiamondCount = n - 2 * (i - Mid); + } + for (int k = 0; k <= DiamondCount / 2; k++) { + draw[i][Mid - k] = 'D'; + draw[i][Mid + k] = 'D'; + } + cout << draw[i] << endl; + } + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (n == 1) + cout << "0" << endl; + else if (n == 2) { + if (a > b) + cout << b << endl; + else + cout << a << endl; + } else { + int sum = 0; + int d = min(a, b); + if (a <= c || b <= c) { + cout << d * (n - 1) << endl; + } else { + cout << d + (n - 2) * c << endl; + } + } +} +int main() { + int n1, n2, k, m; + cin >> n1 >> n2 >> k >> m; + k--; + m--; + vector v1(n1), v2(n2); + for (int i = 0; i < n1; i++) cin >> v1[i]; + for (int i = 0; i < n2; i++) cin >> v2[i]; + sort(v1.begin(), v1.end()); + sort(v2.begin(), v2.end()); + if (v1[k] < v2[v2.size() - m - 1]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int x[201], y[201], a[2001][2001]; +int main() { + int n, x1, y1, x2, y2; + cin >> n; + x1 = y1 = -10005; + x2 = y2 = 10005; + for (int i = 0; i < n; i++) { + cin >> x[i] >> y[i]; + x[i] += 1000; + y[i] += 1000; + a[x[i]][y[i]] = 1; + if (x1 < x[i]) { x1 = x[i]; } + if (x2 > x[i]) { x2 = x[i]; } + if (y1 < y[i]) { y1 = y[i]; } + if (y2 > y[i]) { y2 = y[i]; } + } + int r = 0, c0, c1, c2, c3; + for (int i = 0; i < n; i++) { + c0 = c1 = c2 = c3 = 0; + for (int j = x[i] + 1; j <= x1; j++) { + if (a[j][y[i]]) { + c0 = 1; + break; + } + } + if (c0) { + for (int j = x2; j < x[i]; j++) { + if (a[j][y[i]]) { + c1 = 1; + break; + } + } + if (c1) { + for (int j = y[i] + 1; j <= y1; j++) { + if (a[x[i]][j]) { + c2 = 1; + break; + } + } + if (c2) { + for (int j = y2; j < y[i]; j++) { + if (a[x[i]][j]) { + c3 = 1; + break; + } + } + } + } + } + if (c3) { r++; } + } + cout << r << endl; +} +int main() { + long long N; + cin >> N; + long long x[N + 5]; + for (int i = 1; i <= N; i++) { cin >> x[i]; } + bool cek[N + 5]; + sort(x + 1, x + N + 1); + long long tmp = (N - 1) / 2; + long long mini = 1e18; + int kanan = N, kiri = 1; + for (int i = 0; i <= tmp; i++) { + int j = tmp - i; + kanan = N - j; + mini = min(x[kanan] - x[i + 1], mini); + } + cout << mini << "\n"; +} +int main() { + int n, i; + cin >> n; + vector v; + v.resize(n - 1); + for (i = 0; i < n - 1; i++) { + int num; + cin >> num; + v[i] = (num); + } + sort(v.begin(), v.end()); + for (i = 0; i < n; i++) { + if (v[i] != i + 1) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int a[15][105]; +int b[15][105]; +int c[15][105]; +bool vis[105]; +int n, m, k; +int Cal(int x, int y) { + memset(vis, 0, sizeof vis); + if (x == y) return -1; + int cost = k; + int ans = 0; + while (cost) { + int flag; + int maxgas = 0; + int dp = 1; + for (int i = 1; i <= m; i++) { + if (vis[i]) continue; + if (b[y][i] - a[x][i] > maxgas) { + dp = 0; + maxgas = b[y][i] - a[x][i]; + flag = i; + } + } + if (dp) break; + vis[flag] = 1; + ans += min(cost, c[x][flag]) * maxgas; + cost -= min(cost, c[x][flag]); + } + return ans; +} +int main() { + memset(vis, 0, sizeof vis); + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + for (int j = 1; j <= m; j++) { cin >> a[i][j] >> b[i][j] >> c[i][j]; } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { ans = max(ans, Cal(i, j)); } + } + cout << ans << endl; +} +int main() { + long long n, p; + cin >> n >> p; + string str[n]; + long long i; + long long ans, fans = 0; + for (i = 0; i < n; i++) cin >> str[i]; + reverse(str, str + n); + if (str[0] == "half") + ans = 2; + else + ans = 1; + fans += ans * p / 2; + for (i = 1; i < n; i++) { + if (str[i] == "half") + ans *= 2; + else + ans = ans * 2 + 1; + fans += ans * p / 2; + } + cout << fans << endl; +} +int dic(long x) { + int k = 0; + while (x != 0) { + x = x / 10; + k++; + } + return k; +} +int main() { + long n; + cin >> n; + long s = n * (-1); + long st = s / 10; + long temp = n / 10; + if (n < 0) { + if (dic(s) == 2) { + if (s % 10 < st % 10) + cout << n % 10 << endl; + else + cout << temp % 10 << endl; + return 0; + } + if (temp % 10 == 0 && n % 10 == 0) + cout << n / 10 << endl; + else if (temp % 10 != 0 && n % 10 != 0) { + if (n % 10 > temp % 10) + cout << n / 100 << s % 10 << endl; + else + cout << n / 10 << endl; + } else if (temp % 10 == 0 && n % 10 != 0) + cout << n / 10 << endl; + else { + if (n / 100 == 0) + cout << n / 100 << endl; + else + cout << n / 100 << "0" << endl; + } + } else + cout << n << endl; +} +int main() { + int i, n, m, x; + cin >> n >> m; + int a[n]; + for (i = 1; i <= n; i++) { cin >> a[i]; } + x = 0; + for (i = 1; i <= n; i++) { + if ((a[i] >= a[m]) && (a[i] > 0)) x++; + } + cout << x << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int i = a + 1, c = 0; + while (b >= 0 && i <= n) { + c++; + i++; + b--; + } + cout << c << endl; + return 0; +} +map mp; +int main() { + int n, sum = 0; + string s; + cin >> n; + for (int i = 1; i <= n; i++) cin >> s, mp[s]++; + for (int i = 1; i <= n; i++) { + cin >> s; + if (mp[s]) + mp[s]--; + else + sum++; + } + cout << sum << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end(), greater()); + for (int i = 0; i < n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << "\n"; + break; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int sum = (n * (n + 1)) / 2; + int rem = m % sum; + for (int i = 1; i <= n; i++) { + if ((rem - i) < 0) { + cout << rem << endl; + return 0; + } + rem = rem - i; + } + return 0; +} +int main() { + int n, m, min, max; + cin >> n >> m >> min >> max; + bool correct = true; + vector t(m); + for (int i = 0; i < m; i++) { + cin >> t[i]; + if (t[i] < min || t[i] > max) { correct = false; } + } + if (!correct) { + cout << "Incorrect\n"; + return 0; + } + sort(t.begin(), t.end()); + int temps2add = n - m; + if (t[0] != min) temps2add--; + if (t[(t.size() - 1)] != max) temps2add--; + if (temps2add >= 0) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + return 0; +} +int main() { + int y, a, b, c, d, i; + bool sudah, angka[10]; + for (i = 0; i < 10; i++) { angka[i] = false; } + cin >> y; + sudah = false; + while (!sudah) { + y++; + a = y / 1000; + b = y / 100 % 10; + c = y / 10 % 10; + d = y % 10; + if ((a != b) && (a != c) && (a != d) && (b != c) && (b != d) && (c != d)) { sudah = true; } + } + cout << a << b << c << d << endl; +} +int a[250], ans, sum = 1; +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1" << endl; + return 0; + } + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + for (int i = 2; i <= n; i++) { + if (a[i] == a[i - 1]) sum++; + ans = max(ans, sum); + if (a[i] != a[i - 1]) sum = 1; + } + cout << ans << endl; + return 0; +} +const int M = 1000 + 5; +int main() { + int n; + cin >> n; + vector crew[4]; + for (int i = 0; i < n; i++) { + string name, feature; + cin >> name >> feature; + if (feature == "rat") { crew[0].push_back(name); } + if (feature == "woman" || feature == "child") { crew[1].push_back(name); } + if (feature == "man") { crew[2].push_back(name); } + if (feature == "captain") { crew[3].push_back(name); } + } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < crew[i].size(); j++) { cout << crew[i][j] << endl; } + } + return 0; +} +int main() { + long long l, r; + cin >> l >> r; + if (r - l + 1 < 3) { + cout << -1 << endl; + return 0; + } + if (l % 2 == 0) { + cout << l << ' ' << l + 1 << ' ' << l + 2 << endl; + return 0; + } + if (r - l + 1 > 3) { + cout << l + 1 << ' ' << l + 2 << ' ' << l + 3 << endl; + return 0; + } + cout << -1 << endl; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c; + cin >> n; + int tot = 0; + int tmp; + for (int i = 0; i < n; i++) { + cin >> tmp; + if (tmp > b && tmp < c) tot++; + } + cout << tot << endl; + return 0; +} +int main() { + int a, b, c[100000]; + cin >> a; + for (int i = 0; i < a; i++) { c[i] = 0; } + for (int i = 0; i < a - 1; i++) { + cin >> b; + c[b - 1] = 1; + } + for (int i = 0; i < a; i++) { + if (c[i] == 0) { + cout << i + 1 << endl; + return 0; + } + } +} +const int Max_N = 1e5 + 5; +const int mod = 1e9 + 7; +int bord[6][2] = {-1, 0, 0, 1, 1, 0, 0, -1}; +int main() { + int n, d; + int a[2005]; + cin >> n >> d; + for (int i = 1; i <= n; i++) cin >> a[i]; + int ant = 0; + for (int i = 2; i <= n; i++) { + if (a[i] > a[i - 1]) continue; + ant += (abs(a[i] - a[i - 1])) / d + 1; + a[i] += ((abs(a[i] - a[i - 1])) / d + 1) * d; + } + cout << ant << endl; + return 0; +} +int main() { + int var = 1, n, aux = 0, x = 0; + cin >> n; + int level = 0; + while (1) { + x += var; + aux += x; + if (aux > n) break; + level++; + var++; + } + cout << level << "\n"; +} +int main() { + int n, k, c = 0; + cin >> n >> k; + int w[n], z[n]; + for (int i = 0; i < n; i++) { + cin >> w[i]; + z[i] = w[i]; + } + int l = 0, x = 0; + for (int i = 0; i < n; i++) { + z[i] = z[i] / (2 * k); + c += z[i]; + w[i] = w[i] % (2 * k); + if (w[i] > k) + l++; + else if (w[i] != 0) + x++; + } + if (x % 2 == 0) + c += l + x / 2; + else + c += l + x / 2 + 1; + cout << c << endl; +} +int main() { + int n, m, j; + cin >> n >> m; + int i = 1; + while (i <= m) { + cout << "#"; + i++; + } + cout << endl; + int flag = 0; + for (i = 2; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else { + if (flag == 0) { + if (j != m) { + cout << "."; + } else { + cout << "#"; + flag = 1; + } + } else if (flag == 1) { + if (j != 1 && j != m) { + cout << "."; + } else if (j == 1) { + cout << "#"; + } else if (j == m) { + cout << "."; + flag = 0; + } + } + } + } + cout << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + map mp; + for (long long i = 0; i < n; i++) { + string c, s; + cin >> c >> s; + for (long long j = 0; j < (long long)(s.size()); j++) { + if (((int)(s[j] - '0')) % 2 == 0) { + s[j] = '0'; + } else { + s[j] = '1'; + } + } + size_t pos1 = s.find("1"); + if (pos1 == string::npos) { + s = "0"; + } else { + s = s.substr(pos1); + } + if (c == "?") { + cout << mp[s] << "\n"; + } else if (c == "+") { + mp[s]++; + } else { + mp[s]--; + } + } +} +const int maxn = 1e5 + 10; +char b[][10] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +int vis[10]; +int main() { + int n; + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + string s; + for (int i = 0; i < n; i++) { + cin >> s; + if (s[0] == 'p') + vis[0]++; + else if (s[0] == 'g') + vis[1]++; + else if (s[0] == 'b') + vis[2]++; + else if (s[0] == 'o') + vis[3]++; + else if (s[0] == 'r') + vis[4]++; + else if (s[0] == 'y') + vis[5]++; + } + int cnt = 0; + for (int i = 0; i < 6; i++) + if (!vis[i]) cnt++; + cout << cnt << endl; + for (int i = 0; i < 6; i++) + if (!vis[i]) cout << b[i] << endl; + } + return 0; +} +int main() { + int n, m, x, y = 0, i; + cin >> n >> m; + for (i = m; i <= n; i = i + m) { n = n + 1; } + cout << n << endl; + return 0; +} +int main() { + long long int k = 2, j = 0, mx = 0, mx1 = -1, t = 0, t2, v1, v2, a, b; + long long int db = 1; + long long int n, i = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b >> k; + if (k % 2 == 0) { + t = (a - b) * (k / 2); + } else + t = ((a - b) * (k / 2)) + a; + cout << t << endl; + t = 0; + } +} +int main() { + int n, m; + cin >> n >> m; + m %= (n * (n + 1) / 2); + for (int i = 1; i <= n; ++i) { + if (m < i) { break; } + m -= i; + } + cout << m << endl; + return 0; +} +int main() { + int n; + cin >> n; + int matr[55][55]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> matr[i][j]; } + } + bool kon = true; + bool tren = false; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + tren = false; + if (matr[i][j] != 1) { + for (int a = 1; a <= n; a++) { + for (int b = 1; b <= n; b++) { + if (matr[a][j] + matr[i][b] == matr[i][j]) { tren = true; } + } + } + if (!tren) kon = false; + } + } + } + if (kon) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +long long s, x, sum[200005]; +long long n; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> x; + s += x; + sum[i] = sum[i - 1] + x; + } + for (int i = 1; i <= n; ++i) { + if (sum[i] * 2 >= s) { + cout << i << '\n'; + return 0; + } + } + return 0; +} +int main() { + int k, n, w; + int m = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { m += i * k; } + int v = max(m, n); + int b = min(m, n); + int y = v - b; + if (m == n || m < n) { + cout << "0\n"; + } else + cout << y << "\n"; +} +int compare(string a, string b) { + while (a[0] == '0') { a.erase(0, 1); } + while (b[0] == '0') { b.erase(0, 1); } + if (a.size() > b.size()) { return 1; } + if (a.size() < b.size()) { return -1; } + for (int i = 0; i < a.size(); i++) { + if (a[i] > b[i]) { return 1; } + if (a[i] < b[i]) { return -1; } + } + return 0; +} +int main() { + int q; + cin >> q; + int n; + string a, b; + string c; + for (int i = 0; i < q; i++) { + cin >> n; + cin >> a; + b = a.substr(0, 1); + if (compare(b, a.substr(1, n)) < 0) { + cout << "YES" << '\n'; + cout << 2 << '\n'; + c = (a).substr(1, n - 1); + cout << b << " " << c << '\n'; + } else { + cout << "NO\n"; + } + } + return 0; +} +int main() { + int n, m, a[55] = {}, b[55] = {0}, mx = 0, ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; i++) cin >> b[i]; + for (int i = 1; i <= m; i++) + for (int j = 1; j <= n; j++) + if (b[i] % a[j] == 0) { mx = max(mx, b[i] / a[j]); } + for (int i = 1; i <= m; i++) + for (int j = 1; j <= n; j++) + if (b[i] % a[j] == 0 && b[i] / a[j] == mx) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int mul = min(n, m); + if (mul % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } + return 0; +} +int main() { + vector v; + vector v1; + long long i, j, n, ans, min = 1000000002, t, flag; + cin >> n; + for (i = 0; i < n; i++) { + long long x; + cin >> x; + v.push_back(x); + if (x < min) { min = x; } + } + for (i = 0; i < n; i++) { + if (min == v[i]) { v1.push_back(i); } + } + min = 1000000002; + for (i = 1; i < v1.size(); i++) { + if ((v1[i] - v1[i - 1]) < min) { min = (v1[i] - v1[i - 1]); } + } + cout << min << endl; +} +long long Q, a, b, d; +int main() { + cin >> Q; + while (Q--) { + cin >> a >> b; + long long ans = 0; + while (a && b) { + if (b >= a) { + d = (b - a) / a; + b -= a * (d + 1); + } else { + d = (a - b) / b; + a -= b * (d + 1); + } + ans += d + 1; + } + cout << ans << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long int d, v, l, r; + cin >> d >> v >> l >> r; + int count = d / v; + r = v * (r / v); + if (l % v != 0) l = v * ((l / v) + 1); + cout << count - ((r - l) / v) - 1 << endl; + } + return 0; +} +int main() { + int n = 6; + int a[n], i, j, k, s = 0; + for (i = 0; i < n; i++) cin >> a[i], s += a[i]; + if (s % 2) { + cout << "NO" << endl; + return 0; + } + s /= 2; + for (i = 0; i < 4; i++) + for (j = i + 1; j < 5; j++) + for (k = j + 1; k < 6; k++) + if (a[i] + a[j] + a[k] == s) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, c; + cin >> n; + long long int s1 = 0; + long long int s2 = 0; + long long int a[n], b[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + s1 = s1 | a[i]; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + s2 = s2 | b[i]; + } + cout << s1 + s2 << "\n"; + return 0; +} +bool check(int r, int c) { + if ((r >= 1 && r <= 8) && (c >= 1 && c <= 8)) + return 1; + else + return 0; +} +int main() { + int x, y, tc, a, b, res = 0; + char pos[3]; + cin >> pos; + x = pos[1] - '0'; + y = (pos[0] - 'a') + 1; + if (check(x, y - 1)) res++; + if (check(x, y + 1)) res++; + if (check(x + 1, y)) res++; + if (check(x - 1, y)) res++; + if (check(x - 1, y + 1)) res++; + if (check(x - 1, y - 1)) res++; + if (check(x + 1, y - 1)) res++; + if (check(x + 1, y + 1)) res++; + cout << res << endl; + return 0; +} +int main() { + long long l, r, x, y, k, i, j, c = 0; + cin >> l >> r >> x >> y >> k; + for (j = x; j <= y; j++) { + if (k * j <= r && k * j >= l) { + cout << "YES" << endl; + c = 1; + break; + } + } + if (c == 0) { cout << "NO" << endl; } + return 0; +} +int main() { + long long int n; + cin >> n; + string s1; + cin >> s1; + long long int cnt = 0; + long long int i = 0; + while (s1[i] == '1') { + cnt++; + i++; + } + if (cnt == n) + cout << cnt << endl; + else + cout << cnt + 1 << endl; + return 0; +} +long long arr[100100]; +int main() { + long long n; + cin >> n; + int mi = 1e9; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + mi = min(a, mi); + } + long long m; + long long ans = 0; + cin >> m; + int cnt = 0; + for (int i = 1; i <= m; i++) { cin >> arr[i]; } + sort(arr + 1, arr + m + 1); + reverse(arr + 1, arr + m + 1); + for (int i = 1; i <= m; i++) { + cnt++; + ans += arr[i]; + if (cnt == mi) { + i += 2; + cnt = 0; + } + } + cout << ans << endl; + return 0; +} +stack s; +int main() { + int n; + cin >> n; + for (int i = n; i >= n - 100; i--) { + int sum = 0; + if (i <= 0) { break; } + int a = i; + while (a / 10 != 0) { + sum += a % 10; + a = a / 10; + } + sum += a; + if (i + sum == n) { s.push(i); } + } + if (s.empty()) { + cout << '0' << endl; + } else { + cout << s.size() << endl; + while (!s.empty()) { + cout << s.top() << endl; + s.pop(); + } + } +} +long long int t; +int main() { + cin >> t; + for (long long int i = 1; i <= t; i++) { + long long int n; + cin >> n; + string s; + cin >> s; + bool b = true; + for (long long int x = 0, y = n - 1; x < y; x++, y--) { + long long int tmp = abs(s[x] - s[y]); + if (tmp != 0 && tmp != 2) { + b = false; + break; + } + } + if (b) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + } + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << max(0, a[2] - a[1] + 1 - a[0]) << "\n"; +} +int t, s, q; +int main() { + cin >> t >> s >> q; + int ans = 1; + int temp = s * q; + while (temp < t) { + ++ans; + temp *= q; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << '\n'; + return 0; +} +int const MOD = 1e9 + 7; +long long const oo = 2e18; +int const ooi = 2e9; +int const N = 1e5 + 10; +int const M = 1e6 + 100; +int n, a[1000]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + int mn = ooi; + for (int i = 0; i < n; ++i) { + int s = i, sum = 0, e = i; + do { + sum += a[e]; + mn = min(mn, abs(360 - 2 * sum)); + e = (e + 1) % n; + } while (e != s); + } + cout << mn << endl; + return 0; +} +int main() { + long long n, r, cnt; + int a[] = {100, 20, 10, 5, 1}; + int i; + cin >> n; + r = n; + cnt = 0; + for (i = 0; i < 5; i++) { + if (r >= a[i]) { + cnt = cnt + (r / a[i]); + r = r % a[i]; + } + } + cout << cnt << endl; +} +const int INF = 0x3f3f3f3f; +const int inf = 0x3f; +const int MAXN = 50 + 5; +int n, m; +char ch[MAXN][MAXN]; +int check(int x, int y) { + int ff = 0, fa = 0, fc = 0, fe = 0; + int temp = 0, cot = 0; + for (int i = x, k = 1; i <= x + 1; i++, k++) { + for (int j = y, z = 0; j <= y + 1; j++, z++) { + cot++; + if (temp + 1 < cot) return 0; + if (ff == 0 && ch[i][j] == 'f') { + ff = 1; + temp++; + continue; + } + if (ff == 1 && ch[i][j] == 'f') return 0; + if (fa == 0 && ch[i][j] == 'a') { + fa = 1; + temp++; + continue; + } + if (fa == 1 && ch[i][j] == 'a') return 0; + if (fc == 0 && ch[i][j] == 'c') { + fc = 1; + temp++; + continue; + } + if (fc == 1 && ch[i][j] == 'c') return 0; + if (fe == 0 && ch[i][j] == 'e') { + fe = 1; + temp++; + continue; + } + if (fe == 1 && ch[i][j] == 'e') return 0; + } + } + if (temp == 4) return 1; + return 0; +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cin >> ch[i][j]; } + } + int sum = 0; + for (int i = 1; i < n; i++) { + for (int j = 1; j < m; j++) { sum += check(i, j); } + } + cout << sum << endl; + return 0; +} +const int maxn = 1010; +int n; +int a[maxn]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a, a + n); + for (int i = n - 1; i >= 0; --i) { + if (((int)(sqrt(a[i]))) * ((int)(sqrt(a[i]))) != a[i]) { + cout << a[i] << endl; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1], i, j, k = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) k++; + } + cout << k << endl; + for (i = 1; i < n; i++) { + if (a[i] == 1) cout << a[i - 1] << " "; + } + cout << a[n - 1] << endl; +} +int main() { + int a, i, b = 0, c = 0, s, t, n, l1 = 0, l2 = 0, arr[105]; + cin >> n; + for (a = 1; a <= n; a++) { cin >> arr[a]; } + cin >> s; + cin >> t; + if (s > t) { + b = t; + c = s; + } else { + b = s; + c = t; + } + for (a = b; a < c; a++) { l1 = l1 + arr[a]; } + for (a = c; a != b; a++) { + l2 = l2 + arr[a]; + if (a == n) a = 0; + } + if (l1 <= l2) + cout << l1 << endl; + else + cout << l2 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int f[100005]; + for (int i = 0; i < n; i++) { cin >> f[i]; } + int i, j; + for (i = k; i < n; i++) { + if (f[i] != f[k - 1]) { + cout << -1 << endl; + break; + } + } + if (i == n) { + for (j = k - 2; j >= 0; j--) + if (f[j] != f[k - 1]) { + cout << j + 1 << endl; + break; + } + } + if (j == -1) { cout << 0 << endl; } + return 0; +} +const int maxn = 2.001e3; +set st; +int a[maxn], b[maxn], n, cnt; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i], st.insert(a[i]); + for (int i = 1; i <= n; i++) cin >> b[i], st.insert(b[i]); + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (st.find(a[i] xor b[j]) != st.end()) cnt++; + cout << ((cnt & 1) ? "Koyomi" : "Karen") << endl; + return 0; +} +long long n, h, a, b, k; +long long t1, f1, t2, f2; +int main() { + cin >> n >> h >> a >> b >> k; + while (k--) { + long long ans; + cin >> t1 >> f1 >> t2 >> f2; + if (t1 == t2) + ans = abs(f1 - f2); + else { + if (f1 > b && f2 > b) + ans = abs(t1 - t2) + f1 + f2 - 2 * b; + else if (f1 < a && f2 < a) + ans = abs(t1 - t2) + 2 * a - f1 - f2; + else + ans = abs(t1 - t2) + abs(f1 - f2); + } + cout << ans << endl; + } + return 0; +} +int main() { + int p1, p2, p3, p4; + int a, b; + int ans = 0; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + for (int i = a; i <= b; i++) { + if (i % p1 == i && i % p2 == i && i % p3 == i && i % p4 == i) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, i, p = 0, a = 0; + cin >> n >> m; + if (n == 2 && m == 3) + cout << "YES" << endl; + else if (m % 2 == 0) + cout << "NO" << endl; + else { + i = n + 2; + if (i == m) { + for (int k = 3; k <= sqrt(m); k++) { + if (m % k == 0) { + a = 1; + break; + } + } + if (a == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + while (i < m) { + for (int j = 3; j <= sqrt(i); j = j + 2) { + if (i % j == 0) { + p = p + 1; + break; + } + } + if (p == 0) break; + i = i + 2; + p = 0; + } + if (i == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int n, max = 0, res = 1; + cin >> n; + int *arr = new int[n]; + cin >> arr[0]; + for (int j = 0; j < n - 1; ++j) { + cin >> arr[j + 1]; + if (arr[j] <= arr[j + 1]) + res += 1; + else if (arr[j] > arr[j + 1]) { + if (res > max) max = res; + res = 1; + } + } + if (res > max) + cout << res << endl; + else + cout << max << endl; + return 0; +} +int main() { + int l, r, b; + int num; + int maxnum; + while (cin >> l >> r >> b) { + num = min(l, r); + maxnum = max(l, r); + if (maxnum - num > b) + num = (num + b) * 2; + else { + num = maxnum * 2 + (b - (maxnum - num)) / 2 * 2; + } + cout << num << endl; + } +} +int a[1000 + 10]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int t; + for (int i = 1; i <= n; i++) { + if (k % a[i] == 0) { t = a[i]; } + } + cout << k / t << endl; + return 0; +} +int main() { + int i, n, m, a[120], kmin, kmax, sum1 = 0, sum2 = 0, gap; + cin >> n; + cin >> m; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 0; i < n; i++) sum1 += a[i]; + sum2 = n * a[n - 1]; + gap = sum2 - sum1; + if (m <= gap) + kmin = a[n - 1]; + else { + if ((m - gap) % n == 0) + kmin = a[n - 1] + (m - gap) / n; + else + kmin = a[n - 1] + (m - gap) / n + 1; + } + kmax = m + a[n - 1]; + cout << kmin << ' ' << kmax << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M; + for (int i = 0; i < N; i++) { + cin >> K; + M -= 86400 - K; + if (M <= 0) { + cout << i + 1 << endl; + return 0; + } + } + return 0; +} +int n; +int ans = -1; +int res = 0; +int main() { + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) res++; + } + if (res == n) { + cout << n - 1 << endl; + return 0; + } + if (n == 1 && a[0] == 1) { + cout << "0" << endl; + return 0; + } + for (int j = 0; j < n; j++) { + for (int k = 0; k < n; k++) { + int cnt = 0; + for (int l = 0; l < n; l++) { + if (l >= k && l <= j) + cnt = cnt + (1 - a[l]); + else + cnt = cnt + a[l]; + } + ans = max(ans, cnt); + } + } + cout << ans << endl; + return 0; +} +int bio[1000][1000]; +const int smjeroviX[8] = {0, 0, 1, -1, 1, 1, -1, -1}; +const int smjeroviY[8] = {1, -1, 0, 0, 1, -1, 1, -1}; +int main() { + int n, aX, aY, bX, bY, cX, cY; + cin >> n >> aX >> aY >> bX >> bY >> cX >> cY; + aX--; + aY--; + bX--; + bY--; + cX--; + cY--; + queue q; + q.push(bX); + q.push(bY); + bio[bX][bY] = 1; + while (!q.empty()) { + int x = q.front(); + q.pop(); + int y = q.front(); + q.pop(); + if (x == cX && y == cY) { + cout << "YES\n"; + return 0; + } + for (int i = 0; i < 8; i++) { + int X = x + smjeroviX[i]; + int Y = y + smjeroviY[i]; + if (X < 0 || X == n || Y < 0 || Y == n || bio[X][Y]) continue; + bio[X][Y] = 1; + if (X != aX && Y != aY && (X + Y != aX + aY) && (X - Y != aX - aY)) { + q.push(X); + q.push(Y); + } + } + } + cout << "NO\n"; + return 0; +} +const int sz = 200010; +long long int a[sz]; +int main() { + int n; + cin >> n; + for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } + sort(a, a + 2 * n); + long long int ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); + for (int i = n; i < 2 * n; i++) { ans = min(ans, (a[2 * n - 1] - a[0]) * (a[i] - a[i - n + 1])); } + cout << ans << endl; + return 0; +} +const int maxn = 110; +int a[maxn]; +int main() { + int i, j, n, k; + cin >> n >> k; + for (i = 0; i < n; i++) { cin >> a[i]; } + int e, s, maxx = -1; + for (i = 0; i < k; i++) { + e = 0; + s = 0; + for (j = 0; j < n; j++) { + if ((j - i) % k == 0) { + continue; + } else { + if (a[j] == 1) + e++; + else if (a[j] == -1) + s++; + } + } + maxx = max(maxx, abs(e - s)); + } + cout << maxx << endl; + return 0; +} +string r; +int a, d; +int main() { + cin >> a; + cout << "I hate "; + for (int i = 1; i < a; i++) { + if (a == 1) + break; + else if (i % 2 != 0) + cout << "that I love "; + else + cout << "that I hate "; + } + cout << "it" << endl; + return 0; +} +int main() { + int n, sum = 0, max = 0, a; + cin >> n; + map m; + for (int i = 0; i < 2 * n; i++) { + cin >> a; + m[a]++; + if (m[a] == 1) { + sum++; + if (sum > max) max = sum; + } else + sum--; + } + cout << max << endl; + return 0; +} +int n; +vector arr(210); +int main() { + cin >> n; + for (int i = 1; i <= 2 * n; ++i) { cin >> arr[i]; } + sort(arr.begin() + 1, arr.begin() + 2 * n + 1, greater()); + if (arr[n] > arr[n + 1]) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int cnt[110][110]; +int main() { + int n; + cin >> n; + while (n--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + for (int i = x1; i <= x2; i++) { + for (int j = y1; j <= y2; j++) cnt[i][j]++; + } + } + long long ans = 0; + for (int i = 1; i <= 100; i++) { + for (int j = 1; j <= 100; j++) ans += cnt[i][j]; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum1 = 0, sum2 = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum1 |= a; + } + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum2 |= a; + } + cout << sum1 + sum2 << endl; +} +map q; +string s[7]; +string ss; +int main() { + int n; + cin >> n; + q["purple"] = 1; + q["green"] = 2; + q["blue"] = 3; + q["orange"] = 4; + q["red"] = 5; + q["yellow"] = 6; + s[1] = "Power"; + s[2] = "Time"; + s[3] = "Space"; + s[4] = "Soul"; + s[5] = "Reality"; + s[6] = "Mind"; + int cont = 6; + while (n--) { + cin >> ss; + if (q[ss] != 0) { + q[ss] = 0; + cont--; + } + } + cout << cont << endl; + if (q["purple"] != 0) cout << s[1] << endl; + if (q["green"] != 0) cout << s[2] << endl; + if (q["blue"] != 0) cout << s[3] << endl; + if (q["orange"] != 0) cout << s[4] << endl; + if (q["red"] != 0) cout << s[5] << endl; + if (q["yellow"] != 0) cout << s[6] << endl; +} +int main() { + long long n; + cin >> n; + long long arr[n], dp[n], c = 0; + for (long long i = 0; i < n; i++) { + cin >> arr[i]; + if (i != 0) + dp[i] = arr[i] >= arr[i - 1] ? (dp[i - 1] + 1) : 1; + else + dp[i] = 1; + c = max(c, dp[i]); + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + if (arr[0] == 1) { + cout << "-1" << endl; + } else { + cout << "1" << endl; + } + return 0; +} +int main() { + int n, b, d, result = 0, counter = 0; + cin >> n >> b >> d; + int oranges[n]; + for (int i = 0; i < n; i++) { + cin >> oranges[i]; + if (oranges[i] <= b) { counter += oranges[i]; } + if (counter > d) { + result++; + counter = 0; + } + } + cout << result << endl; + return 0; +} +int main() { + int n, g = 0, x, m; + cin >> n >> x; + g = m = x; + for (int i = 2; i <= n; i++) { + cin >> x; + g = __gcd(g, x); + m = max(m, x); + } + if ((m / g - n) & 1) + cout << "Alice\n"; + else + cout << "Bob\n"; + return 0; +} +const long long int INF = (1LL << 60) - 1; +const long long int MAX = 100000000001; +const long long int MOD = 1000000007; +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int i = 0; + for (i = 1; i < 10000; i++) { + int space = 1; + if (b >= (k - 1)) { + b -= (k - 1); + space = k; + } else { + space = b + 1; + b = 0; + } + if (a > space * v) { + a -= space * v; + } else + break; + } + cout << i << '\n'; + return 0; +} +int main() { + bool c[5005]; + int n, satu = 0, dua = 0, tiga = 0, a[5005]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == 1) + satu++; + else if (a[i] == 2) + dua++; + else + tiga++; + } + for (int i = 1; i <= n; i++) { c[i] = 0; } + int b[4]; + for (int i = 0; i < 3; i++) b[i] = 0; + b[0] = satu; + b[1] = dua; + b[2] = tiga; + sort(b, b + 3); + cout << b[0] << endl; + for (int i = 1; i <= b[0]; i++) { + for (int j = 1; i <= n; j++) { + if (a[j] == 1 && c[j] == 0) { + c[j] = 1; + cout << j << " "; + break; + } + } + for (int j = 1; i <= n; j++) { + if (a[j] == 2 && c[j] == 0) { + c[j] = 1; + cout << j << " "; + break; + } + } + for (int j = 1; i <= n; j++) { + if (a[j] == 3 && c[j] == 0) { + c[j] = 1; + cout << j; + break; + } + } + cout << endl; + } +} +int main() { + string a; + cin >> a; + int sum = 0; + for (int i = 0; i < a.length(); i++) { + if (a[i] == '4' || a[i] == '7') sum++; + } + if (sum == 7 || sum == 4) + cout << "YES\n"; + else + cout << "NO\n"; +} +int a[3] = {0}; +int dp[10000]; +int main() { + int n; + cin >> n >> a[0] >> a[1] >> a[2]; + memset(dp, -9999, sizeof(dp)); + dp[0] = 0; + for (int i = 0; i < 3; i++) { + for (int j = a[i]; j <= n; j++) { dp[j] = max(dp[j], dp[j - a[i]] + 1); } + } + cout << dp[n] << endl; + return 0; +} +int n, x, y, z, sum[3]; +int main() { + cin >> n; + while (n--) { + cin >> x >> y >> z; + sum[0] += x; + sum[1] += y; + sum[2] += z; + } + if (!sum[0] && !sum[1] && !sum[2]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int M = 2e5 + 5; +const int inf = 1e9 + 5; +int main() { + int p, l, r; + cin >> p >> l >> r; + int ans = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + if (t > l && t < r) ans++; + } + cout << ans << endl; + return 0; +} +int arr[100000]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n - 1; i++) { cin >> arr[i]; } + sort(arr, arr + n - 1); + for (int i = 0; arr[i]; i++) { + if (arr[i] - arr[i - 1] > 1) { + cout << arr[i] - 1 << endl; + return 0; + } + } + cout << n << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long a[1000], b[1000]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < k; i++) { cin >> b[i]; } + if (k == 1) { + long long p; + for (int i = 0; i < n; i++) { + if (a[i] == 0) p = i; + } + a[p] = b[0]; + long long f = 0; + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] < 0) { + f = 1; + break; + } + } + if (f == 0) + cout << "No" << endl; + else + cout << "Yes" << endl; + } else + cout << "Yes" << endl; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + long long l, r; + cin >> l >> r; + if (l == r) { + cout << l << '\n'; + continue; + } + long long a[60], b[60]; + long long x = r, ans = 0; + for (long long i = 0; i < 60; i++) { + b[i] = l % 2; + l /= 2; + } + for (long long i = 0; i < 60; i++) { + a[i] = r % 2; + r /= 2; + ans += a[i]; + } + reverse(a, a + 60); + reverse(b, b + 60); + for (long long i = 0; i < 60; i++) { + if (a[i]) { + long long c[60]; + for (long long j = 0; j < i; j++) c[j] = a[j]; + c[i] = 0; + long long s = 1; + for (long long j = i + 1; j < 60; j++) c[j] = 1; + for (long long j = 0; j < 60; j++) { + if (s && (c[j] < b[j])) { + s = 2; + break; + } + if (c[j] > b[j]) { + s = 0; + break; + } + } + if (s != 2) { + long long cnt = 0; + for (long long j = 0; j < 60; j++) cnt += c[j]; + if (cnt > ans) { + long long t = 1; + x = 0; + ans = cnt; + for (long long j = 60 - 1; j >= 0; j--) { + x += c[j] * t; + t *= 2; + } + } else if (cnt == ans) { + long long t = 1; + long long z = 0; + ans = cnt; + for (long long j = 60 - 1; j >= 0; j--) { + z += c[j] * t; + t *= 2; + } + if (z < x) { x = z; } + } + } + } + } + cout << x << '\n'; + } + } + return 0; +} +int a[100010]; +int main() { + int n, m, j = INT_MAX, k, l = INT_MAX, i, o, p; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + l = min(l, a[i]); + } + k = distance(a, find(a + 1, a + n + 1, l)); + for (i = k + 1; i <= n; i++) { + if (a[i] == l) { + j = min(j, i - k); + k = i; + } + } + cout << j << endl; + return 0; +} +const int maxn = 1e6; +int a[maxn]; +int main() { + int n; + cin >> n; + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[x]++; + } + int k = 0; + for (int i = 1; i <= 600; i++) { + if (a[i] > 0) k++; + } + cout << k << endl; +} +int main() { + int m, c, a[100009], jwb = 0; + cin >> m >> c; + for (int i = 1; i <= m; i++) { + cin >> a[i]; + if (a[i] - a[i - 1] > c && i >= 2) jwb = 0; + jwb++; + } + cout << jwb << endl; +} +int main() { + int a[101][101] = {}; + int n, i, j; + int k = 0; + cin >> n; + for (i = 0; i < n; i++) { + for (j = 0; j < 2; j++) { cin >> a[i][j]; } + } + for (i = 0; i < n; i++) { + if (a[i][1] - a[i][0] >= 2) k++; + } + cout << k << endl; + return 0; +} +int main() { + int d = 0; + string a, b, x, y; + cin >> a >> b >> d; + cout << a << ' ' << b << endl; + for (int i = 0; i < d; i++) { + cin >> y >> x; + if (y == a) + a = x; + else if (y == b) + b = x; + else if (x == a) + a = y; + else if (x == b) + b = y; + cout << a << ' ' << b << endl; + } +} +int main() { + int n = 8; + while (n--) { + string s; + cin >> s; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n, c, x, y; + cin >> n; + int a[n][n], b[n * n + 5]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> a[i][j]; + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (a[i][j] != 1) { + c = 0; + for (x = 0; x < n; x++) { + for (y = 0; y < n; y++) { + if (a[i][j] == a[i][y] + a[x][j]) c = 1; + } + } + if (c == 0) { + cout << "No" << endl; + return 0; + } + } + } + cout << "Yes" << endl; +} +long long n, m, a[1010], c[1010], res; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) cin >> a[i]; + long long neo = 1; + for (int i = 1; i <= m; i++) { + while (neo < n && a[i] < c[neo]) neo++; + if (c[neo] <= a[i]) { + res++; + neo++; + } else + break; + if (neo > n) break; + } + cout << res << endl; + return 0; +} +int n, k, sum, a[1000000]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (int i = 1; i <= n; i++) { + k += a[i]; + if (k >= ceil(double(sum / 2.0))) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin.ignore(); + getline(cin, s); + int mx = -1, cnt = 0; + for (int i = 0; i < n; i++) { + if (s[i] == ' ') { + mx = max(cnt, mx); + cnt = 0; + } + if (s[i] >= 'A' && s[i] <= 'Z') cnt++; + } + mx = max(mx, cnt); + cout << mx << endl; + return 0; +} +long long get_ref(long long a) { + long long ans; + for (long long i = 1; i <= 100000000000; i *= 10) { + if (a >= i) + continue; + else { + ans = i / 2; + break; + } + } + return ans; +} +long long reflection(long long a) { + int argham; + long long ref; + for (long long i = 1; i <= 100000000000; i *= 10) { + if (a >= i) + continue; + else { + ref = i - 1; + break; + } + } + return ((ref - a) * a); +} +int main() { + long long i, t, m, n, j, k; + long long l, r; + long long maxx = 0; + cin >> l >> r; + long long refrence = get_ref(r); + if (r < refrence) + cout << reflection(r) << endl; + else { + if (l < refrence) + cout << reflection(refrence) << endl; + else + cout << reflection(l) << endl; + } +} +int main() { + string s; + int n, sum = 0; + cin >> n; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '8') sum++; + } + if (n / 11 < sum) + cout << (n / 11) << endl; + else + cout << sum << endl; +} +int n, a, b, sum, h, ans; +bool cek[1000]; +int main() { + cin >> n >> h; + for (int i = 1; i <= n; i++) { + cin >> a; + for (int j = 1; j <= a; j++) { + cin >> b; + cek[b] = 1; + } + } + for (int i = 1; i <= h; i++) { + if (!cek[i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +const int mo[3][3] = {{0, 1, 2}, {2, 0, 1}, {1, 2, 0}}; +int a[205], ind[205], t[205]; +bool vis[205], G[205][205]; +int n, u, ans; +int F(int x) { + int c = 0, f = 0; + do { + f = 0; + for (int i = 0; i < n; i++) + if (!ind[i] && !vis[i] && a[i] == x) { + vis[i] = true; + c++; + for (int j = 0; j < n; j++) + if (!vis[j] && G[i][j]) ind[j]--; + f = 1; + } + } while (f); + for (int i = 0; i < n; i++) + if (!ind[i] && !vis[i] && mo[x][a[i]] == 1) return c + 1 + F(a[i]); + for (int i = 0; i < n; i++) + if (!ind[i] && !vis[i]) return c + 2 + F(a[i]); + return c; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i]--; + } + for (int i = 0; i < n; i++) { + cin >> t[i]; + for (int j = 0; j < t[i]; j++) { + cin >> u; + G[u - 1][i] = true; + } + } + ans = 0xfffffff; + for (int i = 0; i < 3; i++) + for (int j = 0; j < n; j++) + if (!t[j] && i == a[j]) { + memset(vis, 0, sizeof(vis)); + for (int k = 0; k < n; k++) ind[k] = t[k]; + ans = min(F(i), ans); + break; + } + cout << ans << endl; + return 0; +} +int main() { + int m, b, p, total = 0, total_p; + cin >> m >> b >> p; + total_p = m * p; + while (1) { + int k = [](int n) -> int { + int i = 1, res = pow(2, 0); + while (1) { + int temp = pow(2, i); + if (temp > n) break; + res = temp; + i++; + } + return res; + }(m); + int matches = k / 2; + total += matches * (2 * b); + total += matches; + m = (k / 2) + (m - k); + if (matches == 0) break; + } + cout << total << " " << total_p << endl; + return 0; +} +int d[100 + 7][100 + 7], n, x; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) d[i][j] = INT_MAX / 10; + for (int i = 1; i <= n; i++) d[i][i] = 0; + for (int i = 1; i <= n; i++) { + cin >> x; + int j = i + 1; + if (j > n) j -= n; + d[i][j] = x; + d[j][i] = x; + } + for (int k = 1; k <= n; k++) + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j]; + int s, t; + cin >> s >> t; + cout << d[s][t] << endl; +} +int main() { + map mp; + mp["UR"] = mp["DL"] = 1; + mp["UL"] = mp["DR"] = 2; + mp["ULDR"] = 3; + long long x[4] = {0, 1, 1, 0}; + int n; + cin >> n; + while (n--) { + string s; + cin >> s; + x[mp[s]]++; + } + cout << (x[1] + x[3]) * (x[2] + x[3]) << endl; +} +int n, i; +int main() { + cin >> n; + int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + if (arr[n - 1] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (arr[n - 1] == 0) { + cout << "UP" << endl; + return 0; + } else if (n == 1) { + cout << -1 << endl; + return 0; + } else if (arr[n - 1] > arr[n - 2]) { + cout << "UP" << endl; + return 0; + } else if (arr[n - 1] < arr[n - 2]) { + cout << "DOWN" << endl; + return 0; + } +} +int main() { + int n, m = 0, c = 0, a[100], b[100]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (int i = 0; i < n; i++) { + if (a[i] > b[i]) { + m++; + } else if (a[i] < b[i]) { + c++; + } + } + if (m > c) { + cout << "Mishka" << endl; + } else if (m < c) { + cout << "Chris" << endl; + } else if (m == c) { + cout << "Friendship is magic!^^" << endl; + } +} +int main() { + int n, M = 0, C = 0; + cin >> n; + while (n--) { + int m, c; + cin >> m >> c; + if (m > c) + M++; + else if (c > m) + C++; + } + if (M > C) + cout << "Mishka" << endl; + else if (C > M) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n[4]; + int a; + int x, y; + for (int i = 0; i < 3; i++) { + cin >> a; + n[i] = a; + } + sort(n, n + 3); + x = n[2] - n[1]; + y = n[1] - n[0]; + cout << x + y << "\n"; + return 0; +} +const int MAX = 1e5 + 9; +; +const int MAX1 = 3e8 + 9; +const double pi = acos(-1); +const long long int inf = INT_MAX; +const long long mod = 1e9; +int main() { + int g = 0; + int n; + cin >> n; + int mx = -1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + mx = max(mx, x); + g = __gcd(x, g); + } + cout << (((mx / g) - n) % 2 ? "Alice" : "Bob") << "\n"; +} +const int maxn = 1e5 + 5; +pair A[maxn]; +int dif(int h, int mini) { + return h * 60 + mini; +} +int main() { + int N, M; + cin >> N >> M; + for (int i = (1); i <= (N); i += (1)) { + int a, b; + cin >> a >> b; + A[i] = make_pair(a, b); + } + sort(A + 1, A + N + 1); + bool flag = false; + if (M < dif(A[1].first, A[1].second)) { + flag = true; + cout << "0 0\n"; + } + if (!flag) { + int id = -1; + for (int i = (1); i <= (N); i += (1)) { + int lasth; + int lastm; + lastm = (A[i].second + M + 1) % 60; + lasth = A[i].first + (A[i].second + M + 1) / 60; + if (dif(lasth, lastm) + M < dif(A[i + 1].first, A[i + 1].second)) { + cout << lasth << " " << lastm << "\n"; + flag = true; + break; + } + } + } + if (!flag) { + int lastm = (A[N].second + M + 1) % 60; + int lasth = A[N].first + (A[N].second + M + 1) / 60; + cout << lasth << " " << lastm << "\n"; + } + return 0; +} +int main() { + int n; + int arr[105]; + cin >> n; + for (int i = (1); i <= (n); ++i) cin >> arr[i]; + int b = 1, e = n; + while (arr[b] != 1 && b <= n) b++; + while (arr[e] != 1 && e >= 1) e--; + int ans = 0; + if (b <= e) { + int zerocnt = 0; + for (int i = (b); i <= (e); ++i) { + if (arr[i] == 1) { + ans++; + zerocnt = 0; + } else if (arr[i] == 0) { + if (zerocnt == 0) { + zerocnt++; + ans++; + } else if (zerocnt == 1) { + zerocnt++; + ans--; + } else + zerocnt++; + } + } + } + cout << ans << endl; + return 0; +} +const int maxn = 1e6; +const int inf = 0x3f3f3f; +const int mod = 1e9 + 7; +long long casenum, cnt, num, sum; +long long alp[30]; +string str; +void init() { + memset(alp, 0, sizeof(alp)); +} +int main() { + init(); + cin >> num >> cnt; + cin >> str; + sum = 0; + for (int i = 0; i < num; i++) alp[str[i] - 'a']++; + for (int i = 0; i < 26; i++) sum = max(sum, alp[i]); + if (sum <= cnt) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, x[200], y[200]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + int ans = 0; + bool ri, le, lo, up; + for (int i = 0; i < n; i++) { + ri = 0, le = 0, lo = 0, up = 0; + for (int j = 0; j < n; j++) { + if (i == j) continue; + if (x[i] == x[j]) { + if (y[i] > y[j]) + lo = 1; + else + up = 1; + } + if (y[i] == y[j]) { + if (x[i] > x[j]) + le = 1; + else + ri = 1; + } + } + if (ri && le && lo && up) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, min1, max1, min2, max2, min3, max3, given1, given2, given3; + cin >> n; + cin >> min1 >> max1; + cin >> min2 >> max2; + cin >> min3 >> max3; + given1 = min1; + n -= min1; + max1 -= min1; + given2 = min2; + n -= min2; + max2 -= min2; + given3 = min3; + n -= min3; + max3 -= min3; + while (max1 != 0 && n != 0) { + given1++; + --max1; + --n; + } + while (max2 != 0 && n != 0) { + given2++; + --max2; + --n; + } + while (max3 && n != 0) { + given3++; + --max3; + --n; + } + cout << given1 << " " << given2 << " " << given3 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + set nums; + for (int i = 0; i < n; i++) { + int k; + cin >> k; + for (int j = 0; j < k; j++) { + int temp; + cin >> temp; + nums.insert(temp); + } + } + if (nums.size() == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int K, A[105], X, Y, M, N; +int main() { + cin >> K; + for (int i = 1; i <= K; i++) { + cin >> A[i]; + N += A[i]; + } + cin >> X >> Y; + for (int i = min(X, Y); i < max(X, Y); i++) { M += A[i]; } + cout << min(M, N - M) << '\n'; +} +int gcd(int a, int b) { + if (a < b) { return gcd(b, a); } + if (b == 0) { return a; } + return gcd(b, a % b); +} +int main() { + int n, x, g; + cin >> n; + cin >> g; + for (int i = 1; i < n; i++) { + cin >> x; + g = gcd(g, x); + } + cout << g * n << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int A[50][50]; + memset(A, 0, sizeof(A)); + int i, j; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) cin >> A[i][j]; + int ans = 0; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + int row = 0, col = 0; + int a, b; + for (a = 1; a <= n; a++) row += A[i][a]; + for (b = 1; b <= n; b++) col += A[b][j]; + if (row < col) ans++; + } + } + cout << ans << endl; + } +} +long long arr[1000000]; +set s; +map mm; +string ss[100000]; +char ch[100000]; +int main() { + int n; + cin >> n; + bool ok = false; + for (int i = 0; i < n; i++) cin >> arr[i]; + if (arr[n - 1] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (arr[n - 1] == 0) { + cout << "UP" << endl; + return 0; + } + if (n == 1) { + cout << -1 << endl; + return 0; + } + if (arr[n - 1] > arr[n - 2]) + cout << "UP" << endl; + else + cout << "DOWN" << endl; +} +int main() { + int n; + string s1, s2, s, p; + while (cin >> s1 >> s2) { + cin >> n; + cout << s1 << " " << s2 << endl; + while (n--) { + cin >> s >> p; + if (s1 == s) + s1 = p; + else + s2 = p; + cout << s1 << " " << s2 << endl; + } + } + return 0; +} +int main() { + long long t; + long long a, b, c, d, n, ans; + cin >> t; + while (t--) { + cin >> a >> b >> c >> d; + n = ((double)a / (double)d); + ans = ((((long long)((double)n / (double)b)) * c) + n); + cout << ans << "\n"; + } +} +int main() { + int dist = 0; + string str; + cin >> str; + if (abs((int)str[0] - 97) > 13) { + dist += 26 - abs((int)str[0] - 97); + } else + dist += abs((int)str[0] - 97); + for (int i = 1; i < str.length(); i++) { + if (abs((int)str[i - 1] - (int)str[i]) > 13) { + dist += 26 - abs((int)str[i - 1] - (int)str[i]); + } else + dist += abs((int)str[i - 1] - (int)str[i]); + } + cout << dist << endl; + return 0; +} +int main() { + string s; + for (int i = 0; i < 8; ++i) { + cin >> s; + for (int j = 1; j < 8; ++j) { + if (s[j] == s[j - 1]) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int cnt[1003], n, m, x; +int ans = 0x3f3f3f3f; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> x; + cnt[x]++; + } + for (int i = 1; i <= n; i++) ans = min(ans, cnt[i]); + cout << ans << endl; + return 0; +} +const int maxn = 1e6 + 10; +const int INF = 0x3f3f3f3f; +const int inf = 0x3f; +const double EPS = 1e-7; +const double Pi = acos(-1); +const int MOD = 1e9 + 7; +int main() { + do { + } while (0); + int n, a, b; + bool flag = true; + int cntx = 0, cnty = 0; + ; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a < 0) + cntx++; + else if (a > 0) + cnty++; + if (cntx >= 2 && cnty >= 2) flag = false; + } + cout << (flag ? "Yes" : "No") << endl; + return 0; +} +int main() { + set s; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a != 0) s.insert(a); + } + int sun = s.size(); + cout << sun << endl; + return 0; +} +void solve() { + int n, m; + cin >> n >> m; + vector vn(n), vm(m), v; + for (int i = 0; i < n; i++) cin >> vn[i]; + for (int i = 0; i < m; i++) cin >> vm[i]; + sort(vn.begin(), vn.end()); + sort(vm.begin(), vm.end()); + int a = vn[0]; + int b = vm[0]; + int cnt = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (vn[i] == vm[j]) { + cnt++; + v.push_back(vn[i]); + } + } + } + if (cnt == 0) { + if (a > b) { + cout << b << a << endl; + } else if (a < b) { + cout << a << b << endl; + } + } else if (cnt > 0) { + int x = *min_element(v.begin(), v.end()); + cout << x << endl; + } +} +int main() { + int t = 1; + while (t--) { solve(); } + return 0; +} +int main() { + long long n, m; + cin >> n; + long long l, r; + while (n--) { + cin >> l >> r; + if (r % l == 0) { + cout << l << " " << r << endl; + } else { + cout << l << " " << r - (r % l) << endl; + } + } +} +int main() { + int size, n = 2001, r, c, count = 0, j, t = -1000; + cin >> size; + bool a[n][n]; + int pts[size][2]; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) a[i][j] = 0; + } + for (long long i = 0; i < size; i++) { + cin >> pts[i][0] >> pts[i][1]; + a[pts[i][1] - t][pts[i][0] - t] = 1; + } + for (long long i = 0; i < size; i++) { + bool left = false, right = false, up = false, down = false; + r = pts[i][1] - t, c = pts[i][0] - t; + for (long long j = 0; j < c; j++) { + if (a[r][j] == 1) { + left = true; + break; + } + } + if (!left) continue; + for (long long j = 0; j < r; j++) { + if (a[j][c] == 1) { + up = true; + break; + } + } + if (!up) continue; + for (j = c + 1; j < n; j++) { + if (a[r][j] == 1) { + right = true; + break; + } + } + if (!right) continue; + for (j = r + 1; j < n; j++) { + if (a[j][c] == 1) { + down = true; + break; + } + } + if (down) count++; + } + cout << count << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + if (n % 5 == 0) + cout << n / 5 << endl; + else + cout << n / 5 + 1 << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + stack st; + for (int i = 0; i < n; ++i) { + if (!st.empty() && st.top() != s[i]) + st.pop(); + else + st.push(s[i]); + } + cout << st.size() << endl; + return 0; +} +int main() { + int num1 = 0, num2 = 0; + int a[105]{}; + int t; + cin >> t; + for (int i = 0; i < t / 2; i++) { cin >> a[i]; } + sort(a, a + t / 2); + for (int i = 1; i <= t - 1; i += 2) { + num1 += abs(a[i / 2] - i); + num2 += abs(a[i / 2] - (i + 1)); + } + cout << min(num1, num2) << endl; +} +int n, a[100005], Min, pre, ans = 100005; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + Min = a[1]; + for (int i = 2; i <= n; i++) Min = min(Min, a[i]); + for (int i = 1; i <= n; i++) + if (a[i] == Min) { + if (!pre) + pre = i; + else + ans = min(ans, i - pre), pre = i; + } + cout << ans << endl; + return 0; +} +int main() { + int i, sum[15] = {0, 1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620}; + cin >> i; + cout << sum[i] << endl; + return 0; +} +int main() { + int n, ans, a; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + while (a % 3 == 0) a /= 3; + while (a % 2 == 0) a /= 2; + if (i == 0) + ans = a; + else if (ans != a) { + puts("No"); + return 0; + } + } + puts("Yes"); + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int cnt = 0; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + cnt += y - x + 1; + } + if (cnt % k == 0) + cout << "0" << endl; + else { + cout << ((cnt / k + 1) * k - cnt) % k << endl; + } + return 0; +} +int main() { + long long n, a, cnt = 0, aa; + priority_queue pq; + cin >> n >> a; + for (int i = 1; i < n; i++) { + cin >> aa; + if (aa >= a) { pq.push(aa); } + } + while (!pq.empty()) { + long long x = pq.top(); + pq.pop(); + if (x >= a) { + x--; + cnt++; + a++; + if (x >= a) { pq.push(x); } + } + } + cout << cnt << endl; + return 0; +} +string S; +long long N, M, A, B, sum, x = 8, y, K; +int main() { + cin >> S; + if ((S[0] == 'a' || S[0] == 'h') && (S[1] == '1' || S[1] == '8')) + cout << 3 << '\n'; + else if ((S[0] == 'a' || S[0] == 'h') || (S[1] == '1' || S[1] == '8')) + cout << 5 << '\n'; + else + cout << 8 << '\n'; +} +int mat[5001][5001]; +int psum[5001][5001]; +int sum(int fi, int li, int fj, int lj) { + int big = psum[li][lj]; + int smol = (fi and fj ? psum[fi - 1][fj - 1] : 0); + int lat1 = (fj ? psum[li][fj - 1] : 0); + int lat2 = (fi ? psum[fi - 1][lj] : 0); + return big + smol - lat1 - lat2; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < 5001; ++i) { + for (int j = 0; j < 5001; ++j) { mat[i][j] = 0; } + } + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + for (int j = 0; j < m; ++j) { mat[i][j] = s[j] - '0'; } + } + psum[0][0] = mat[0][0]; + for (int i = 1; i < 5001; ++i) { psum[0][i] = psum[0][i - 1] + mat[0][i]; } + for (int i = 1; i < 5001; ++i) { psum[i][0] = psum[i - 1][0] + mat[i][0]; } + for (int i = 1; i < 5001; ++i) { + for (int j = 1; j < 5001; ++j) { psum[i][j] = psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] + mat[i][j]; } + } + int ans = 1e9; + for (int k = 2; k <= 2500; ++k) { + ; + int pans = 0; + for (int i = 0; i < (n + k - 1) / k; ++i) { + for (int j = 0; j < (m + k - 1) / k; ++j) { + int c1 = sum(i * k, (i + 1) * k - 1, j * k, (j + 1) * k - 1); + int c0 = k * k - c1; + ; + ; + ; + ; + pans += min(c0, c1); + } + }; + ans = min(ans, pans); + } + cout << ans << '\n'; + return 0; +} +int main() { + int a[110]; + int n; + cin >> n; + int A = 0, B = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > 0) + A += a[i]; + else + B += a[i]; + } + cout << A - B << endl; + return 0; +} +int N, i, j, L, A[26][26], ans; +string S; +pair R; +pair dif() { + pair R; + int i; + bool B = 0; + R.first = S[0]; + for (i = 0; i < L; i++) { + if (B) { + if (S[i] != R.first && S[i] != R.second) { return pair('0', '0'); } + } else if (S[i] != R.first) { + B = 1; + R.second = S[i]; + } + } + if (!B) { R.second = R.first; } + return R; +} +int main() { + cin >> N; + for (i = 0; i < N; i++) { + cin >> S; + L = S.length(); + R = dif(); + if (R.first != '0') { + if (R.first == R.second) { + for (j = 0; j < 26; j++) { + A[R.first - 'a'][j] += L; + ans = max(ans, A[R.first - 'a'][j]); + } + for (j = 0; j < 26; j++) { + if (j != R.first - 'a') { A[j][R.first - 'a'] += L; } + } + } else { + A[R.first - 'a'][R.second - 'a'] += L; + A[R.second - 'a'][R.first - 'a'] += L; + ans = max(ans, A[R.first - 'a'][R.second - 'a']); + } + } + } + cout << ans << '\n'; + return 0; +} +int n, a[1001]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int ans = 0; + for (int i = 2; i < n; i++) { + if (a[i] > a[i + 1] && a[i] > a[i - 1]) { + ans++; + continue; + } + if (a[i] < a[i + 1] && a[i] < a[i - 1]) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + long long l = abs((long long)s1.length() - (long long)s2.length()); + if (s1.length() < s2.length()) s1.insert(0, l, '0'); + if (s2.length() < s1.length()) s2.insert(0, l, '0'); + long long i = 0; + while (i < (long long)s1.length() && s1[i] == s2[i]) i++; + if (i == (long long)s1.length()) + cout << "=" << endl; + else if (s1[i] > s2[i]) + cout << ">" << endl; + else + cout << "<" << endl; +} +int n; +vector s; +string k; +char diag, other; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> k; + if (i == 0) { + diag = k[0]; + other = k[1]; + } + if (diag == other) { + cout << "NO" << endl; + return 0; + } + for (int j = 0; j < n; j++) { + if (i == j || i + j == n - 1) { + if (k[j] != diag) { + cout << "NO" << endl; + return 0; + } + } else if (k[j] != other) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, lekcje[100], wynik = {0}; + cin >> n; + for (int i = 0; i < n; i++) { cin >> lekcje[i]; } + for (int i = 0; i < n; i++) { + if (lekcje[i] == 1) + wynik += 1; + else if (lekcje[i - 1] == 1 && lekcje[i + 1] == 1) + wynik += 1; + } + cout << wynik << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + if (3 * n - k > 0) + cout << 3 * n - k << endl; + else + cout << 0 << endl; +} +int a[100100]; +int main() { + int n; + cin >> n; + long long soma = 0LL; + int menor = 0x3f3f3f3f; + for (int i = 0; i < n; i++) { + cin >> a[i]; + menor = min((a[i] % 2 == 1 ? a[i] : 0x3f3f3f3f), menor); + soma += (long long)a[i]; + } + cout << (soma % 2 == 0 ? soma : soma - (long long)menor) << endl; +} +int main() { + long long a, b, cnt = 0, flag = 0; + cin >> a >> b; + while (b % a == 0) { + cnt++; + b /= a; + } + if (b == 1) { + cout << "YES" << endl; + cout << cnt - 1 << endl; + } else + cout << "NO" << endl; + return 0; +} +int n, ans, a[105], ma, sum; +int gets() { + int v = 0; + bool f = 0; + char ch; + while (!isdigit(ch = getchar())) + if (ch == '-') f = 1; + v = ch - 48; + while (isdigit(ch = getchar())) v = v * 10 + ch - 48; + return f ? -v : v; +} +int main() { + n = gets(); + for (int i = 1; i <= n; i++) a[i] = gets(), ma = max(ma, a[i]), sum += a[i]; + ans = sum * 2 / n + 1; + ans = max(ans, ma); + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + for (size_t i = 0; i < a.length(); ++i) { + if (a[i] == b[i]) + a[i] = '0'; + else + a[i] = '1'; + } + cout << a << endl; + return 0; +} +const int N = 105; +bool mm[N]; +int main() { + int n; + cin >> n; + int k1, k2; + cin >> k1 >> k2; + memset(mm, false, sizeof(mm)); + for (int i = int(k1); i < int(k2); ++i) mm[i] = true; + for (int i = int(0); i < int(n - 1); ++i) { + cin >> k1 >> k2; + for (int j = int(k1); j < int(k2); ++j) mm[j] = false; + } + int ans = 0; + for (int i = int(0); i < int(101); ++i) + if (mm[i]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n, k, c = 0; + cin >> n >> k; + k = 240 - k; + for (int i = 1; i <= n; i++) + if (k >= (5 * i)) { + c++; + k = k - (5 * i); + } + cout << c << "\n"; + return 0; +} +int sum = 0; +int main() { + int matrix[5][5]; + int x; + pair ch; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> x; + matrix[i][j] = x; + if (x == 1) { + ch.first = i; + ch.second = j; + } + } + } + if (ch.first < 2) sum = sum + (2 - ch.first); + if (ch.first > 2) sum = sum + (ch.first - 2); + if (ch.second < 2) sum = sum + (2 - ch.second); + if (ch.second > 2) sum = sum + (ch.second - 2); + cout << sum << endl; + sum = 0; + return 0; +} +const int INF = 1e9 + 5; +int main() { + int n, a, b; + cin >> n; + while (n--) { + int cntint = 0, cntfloat = 0, adivb, bdiva, reduce; + cin >> a >> b; + if (a == 1) + cout << b << endl; + else if (b == 1) + cout << a << endl; + else if (a > b) { + for (int i = 0; i < 1000; i++) { + if (a <= 0 || b <= 0) + break; + else if (a > b && a % b == 0) { + cntint = a / b; + break; + } else if (b > a && b % a == 0) { + cntint = b / a; + break; + } else if (a > b && a % b != 0) { + cntfloat += (a / b); + adivb = a / b; + reduce = adivb * b; + a = a - reduce; + } else if (a == b) { + cntfloat++; + a = a - b; + break; + } else if (b > a && b % a != 0) { + cntfloat += (b / a); + bdiva = b / a; + reduce = bdiva * a; + b -= reduce; + } + } + cout << cntint + cntfloat << endl; + } else if (a == b) { + cout << 1 << endl; + } else if (a < b) { + for (int i = 0; i < 1000; i++) { + if (a <= 0 || b <= 0) + break; + else if (b > a && b % a == 0) { + cntint = b / a; + break; + } else if (a > b && a % b == 0) { + cntint = a / b; + break; + } else if (a > b && a % b != 0) { + cntfloat += (a / b); + adivb = a / b; + reduce = adivb * b; + a = a - reduce; + } else if (a == b) { + cntfloat++; + a = a - b; + break; + } else if (b > a && b % a != 0) { + cntfloat += (b / a); + bdiva = b / a; + reduce = bdiva * a; + b -= reduce; + } + } + cout << cntint + cntfloat << endl; + } + } + return 0; +} +int main() { + int n, x1, x2, y1, y2, ans = 0; + cin >> n; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + for (int i = x1; i <= x2; i++) + for (int j = y1; j <= y2; j++) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + while (n--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + ans += ((x2 - x1 + 1) * (y2 - y1 + 1)); + } + cout << ans << '\n'; +} +const double pi = 3.1415926535; +const long long mod = 1e9 + 7; +const int maxn = 5e5 + 10; +stack st; +int a[maxn], b[maxn]; +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long k = (s / c) / a * b; + cout << s / c + k << endl; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (max(3 * a / 10, a - a / 250 * c) > max(3 * b / 10, b - b / 250 * d)) + puts("Misha"); + else if (max(3 * a / 10, a - a / 250 * c) < max(3 * b / 10, b - b / 250 * d)) + puts("Vasya"); + else + puts("Tie"); + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + while (n > 0) { + n /= 2; + ans++; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int mid = (n + 1) / 2; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= abs(mid - i); j++) { cout << "*"; } + for (int j = 1; j <= (n - 2 * (abs(mid - i))); j++) { cout << "D"; } + for (int j = 1; j <= abs(mid - i); j++) { cout << "*"; } + cout << endl; + } +} +int main() { + int n, m, maxi, win, t; + cin >> n >> m; + int temp[n + 1] = {0}; + for (int i = 0; i < m; i++) { + maxi = -1; + for (int j = 1; j <= n; j++) { + cin >> t; + if (t > maxi) { + maxi = t; + win = j; + } + } + temp[win]++; + } + maxi = 0; + for (int i = 1; i < n + 1; i++) { + if (temp[i] > maxi) { + maxi = temp[i]; + win = i; + } + } + cout << win << endl; + return 0; +} +int main() { + int n, i, s, minn; + cin >> n; + int a[100005], b[100005]; + for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + minn = b[0]; + for (i = 0; i < n; i++) { + if (minn <= b[i]) + b[i] = minn; + else + minn = b[i]; + } + s = 0; + for (i = 0; i < n; i++) { s += a[i] * b[i]; } + cout << s << endl; +} +int main() { + int n; + cin >> n; + int k = (n + 1) / 3; + cout << k / 12 << " " << k % 12 << endl; + return 0; +} +int main() { + int n, i, j, k = 0, x, f = 0; + cin >> n; + int arr[12]; + for (i = 0; i < 12; i++) { + cin >> x; + arr[i] = x; + if (x > arr[i - 1]) { + for (j = i - 1; j >= 0; j--) { + if (x > arr[j]) { + arr[j + 1] = arr[j]; + arr[j] = x; + } + } + } + } + if (n == 0) { + cout << "0\n"; + } else { + for (i = 0; i < 12; i++) { + k = k + arr[i]; + if (k >= n) { + f = i + 1; + break; + } + } + if (f == 0) { + cout << "-1\n"; + } else { + cout << f << "\n"; + } + } +} +int main() { + int n, s; + cin >> n >> s; + vector times(n); + for (int i = 0; i < n; i++) { + int h, m; + cin >> h >> m; + times[i] = h * 60 + m; + } + if (times[0] >= s + 1) { + cout << "0 0" << endl; + return 0; + } + int ans = -1; + for (int i = 1; i < n; i++) { + if (times[i] - times[i - 1] >= 2 * s + 2) { + ans = times[i - 1] + s + 1; + break; + } + } + if (ans == -1) ans = times[n - 1] + s + 1; + cout << ans / 60 << ' ' << ans % 60 << endl; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "0" << endl; + } else { + cout << "1" << endl; + } + return 0; +} +int main() { + string s; + int i, c = 0, l; + cin >> s; + l = s.length(); + for (i = 0; i < l; i++) { + if (s[i] == '4' || s[i] == '7') { c++; } + } + if (c == 4 || c == 7) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +const int N = 2e6 + 5; +long long a[N]; +int main() { + int n; + cin >> n; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + long long ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); + for (int i = 1; i < n; i++) ans = min(ans, (a[i + n - 1] - a[i]) * (a[2 * n - 1] - a[0])); + cout << ans << endl; + return 0; +} +int main() { + int a[1000], i, n, ans = 0; + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + for (i = 1; i < n; i++) { ans += a[n] - a[i]; } + cout << ans << endl; +} +int main() { + int n, m; + int a[51], b[51]; + int i, j; + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (i = 1; i <= m; i++) cin >> b[i]; + int temp, cnt = 0, maxx = 0; + for (i = 1; i <= m; i++) { + for (j = 1; j <= n; j++) { + if (b[i] % a[j] == 0) { + temp = b[i] / a[j]; + if (maxx < temp) { + maxx = temp; + cnt = 1; + } else if (maxx == temp) + cnt++; + } + } + } + cout << cnt << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n / k & 1) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } + return 0; +} +int main() { + int a, b, c, n, sum; + while (cin >> a >> b >> c >> n) { + sum = a + b - c; + if (sum >= n || a < c || b < c) { + cout << "-1" << endl; + continue; + } else + cout << n - sum << endl; + } + return 0; +} +bool subset(string n1, string n2, int len) { + for (int i = 0; i < len; i++) { + if (n1[i] != n2[i]) return false; + } + return true; +} +string small_min(string n1, string n2) { + if (n1.length() < n2.length()) return n1; + return n2; +} +int main() { + string s, ans; + cin >> s; + string ara[110]; + int n; + cin >> n; + int f = 0; + for (int i = 0; i < n; i++) { + cin >> ara[i]; + int j; + for (j = 0; j < s.size(); j++) { + if (ara[i][j] != s[j]) break; + } + if (j == s.size()) { + if (f == 0) ans = ara[i]; + f = 1; + ans = min(ans, ara[i]); + } + } + if (f == 0) + cout << s << endl; + else + cout << ans << endl; + return 0; +} +string s; +long long n, a = 1, b = 1; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "UL" || s == "DR" || s == "ULDR") a++; + if (s == "UR" || s == "DL" || s == "ULDR") b++; + } + cout << a * b << endl; +} +int a; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> a; + if (a && ((i == 1 || i == n) || (j == 1 || j == m))) { + cout << 2 << endl; + return 0; + } + } + } + cout << 4 << endl; + return 0; +} +int main() { + long long int i, j, n, m, x; + while (cin >> n) { + long long a[n], b[n], sum1, sum2; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { cin >> b[i]; } + sum1 = a[0]; + sum2 = b[0]; + for (i = 1; i < n; i++) { + sum1 |= a[i]; + sum2 |= b[i]; + } + cout << sum1 + sum2 << endl; + } + return 0; +} +int main() { + priority_queue pq; + int n, m; + cin >> n; + cin >> m; + for (int i = 1; i < n; i++) { + int k; + cin >> k; + if (k >= m) pq.push(k); + } + int cnt = 0; + while (!pq.empty()) { + int k = pq.top(); + pq.pop(); + if (k >= m) { + cnt++; + k--; + m++; + } + if (m <= k) pq.push(k); + } + cout << cnt << endl; +} +int main() { + long long int l, r, x, y, k; + bool exist = false; + cin >> l >> r >> x >> y >> k; + for (int i = x; i <= y; i++) { + if ((i * k) <= r and (i * k) >= l) { + exist = true; + break; + } + } + if (exist) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int t, i; + char s[6][21]; + string a; + strcpy(s[0], "Power"); + strcpy(s[1], "Time"); + strcpy(s[2], "Space"); + strcpy(s[3], "Soul"); + strcpy(s[4], "Reality"); + strcpy(s[5], "Mind"); + cin >> t; + cin.ignore(); + if (t == 0) { + cout << 6 << endl; + for (i = 0; i < 6; i++) { cout << s[i] << endl; } + } else { + for (i = 0; i < t; i++) { + cin >> a; + if (a == "purple") + strcpy(s[0], "-1"); + else if (a == "green") + strcpy(s[1], "-1"); + else if (a == "blue") + strcpy(s[2], "-1"); + else if (a == "orange") + strcpy(s[3], "-1"); + else if (a == "red") + strcpy(s[4], "-1"); + else if (a == "yellow") + strcpy(s[5], "-1"); + } + cout << 6 - t << endl; + for (i = 0; i < 6; i++) { + if (strcmp(s[i], "-1") != 0) { cout << s[i] << endl; } + } + } + return 0; +} +const long long nmax = 2000010; +int n, m, q[nmax], a[nmax]; +int main() { + cin >> m; + for (int i = 1; i <= m; i++) cin >> q[i]; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(q + 1, q + m + 1); + sort(a + 1, a + n + 1); + int x = q[1]; + int s = 0, j = n; + while (j >= 1) { + int p = x; + while (j - 1 >= 0 && p--) s += a[j--]; + p = 2; + while (j - 1 >= 0 && p--) { j--; }; + } + cout << s << endl; + return 0; +} +char a[10][10]; +int judge(int i) { + for (int j = 0; j < 8; j++) { + if (j == 7) { + if (a[i][j] == a[i][0]) { + return 0; + } else { + break; + } + } + if (a[i][j] == a[i][j + 1]) { return 0; } + } + return 1; +} +int main() { + for (int i = 0; i < 8; i++) { cin >> a[i]; } + int flag = 0; + for (int i = 0; i < 8; i++) { + int x = judge(i); + if (x == 0) { + flag = 1; + break; + } + } + if (flag == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int lucky(int b) { + int nod = 0, c = b; + for (int i = 0; c != 0; i++) { + c /= 10; + nod++; + } + int s = 0; + for (int i = 0; i < nod; i++) { + if (b % 10 == 4 || b % 10 == 7) { s++; } + b /= 10; + } + return s; +} +int main() { + int n, k; + cin >> n >> k; + vector v; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + v.push_back(a); + } + int s = 0; + for (int i = 0; i < n; i++) { + if (lucky(v[i]) <= k) s++; + } + cout << s << endl; + return 0; +} +const int M = 100 + 5; +int main() { + int n, x, y; + cin >> n >> x >> y; + int tmp = n * y / 100 + ((n * y) % 100 != 0) - x; + int ans = max(tmp, 0); + cout << ans << endl; + return 0; +} +int n; +inline int read() { + int x = 0, y = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') { y = -1; } + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * y; +} +int main() { + n = read(); + cout << ceil(n / 5.0) << endl; + return 0; +} +int n, m, k; +int a[11][111], b[11][111], c[11][111]; +int f[111]; +int main() { + cin >> n >> m >> k; + for (int i = 0; i < n; ++i) { + string name; + cin >> name; + for (int j = 0; j < m; ++j) { cin >> a[i][j] >> b[i][j] >> c[i][j]; } + } + int ans = 0; + for (int st = 0; st < n; ++st) + for (int fn = 0; fn < n; ++fn) + if (st != fn) { + int cst[111], num[111]; + for (int j = 0; j < m; ++j) { + cst[j] = b[fn][j] - a[st][j]; + num[j] = c[st][j]; + } + memset(f, -1, sizeof(f)); + f[0] = 0; + for (int j = 0; j < m; ++j) + for (int cnt = 0; cnt < num[j]; ++cnt) + for (int pos = k - 1; pos >= 0; --pos) + if (f[pos] >= 0) f[pos + 1] = max(f[pos + 1], f[pos] + cst[j]); + ans = max(ans, *max_element(f, f + k + 1)); + } + cout << ans << endl; +} +int main() { + int in[9]; + bool bin[9]; + for (int i = 0; i < 9; i++) { + cin >> in[i]; + bin[i] = true; + } + for (int i = 0; i < 9; i++) { + for (int j = 0; j < in[i]; j++) { + bin[i] = !bin[i]; + if (0 <= i + 1 && i + 1 < 9 && i != 2 && i != 5) bin[i + 1] = !bin[i + 1]; + if (0 <= i - 1 && i - 1 < 9 && i != 3 && i != 6) bin[i - 1] = !bin[i - 1]; + if (0 <= i + 3 && i + 3 < 9) bin[i + 3] = !bin[i + 3]; + if (0 <= i - 3 && i - 3 < 9) bin[i - 3] = !bin[i - 3]; + } + } + for (int i = 1; i <= 9; i++) { + if (bin[i - 1] == true) + cout << 1; + else + cout << 0; + if (i % 3 == 0) cout << endl; + } +} +int arr[1000000], a[1000], ar[100000]; +map m; +map mm; +int main() { + string s, m, k = "", n = ""; + int x; + cin >> s >> x; + for (int i = 0; i < x; i++) { + cin >> m; + if (m.size() >= s.size()) { + n = m.substr(0, s.size()); + if (n == s && (m <= k || k == "")) { k = m; } + } + } + if (k != "") + cout << k << endl; + else + cout << s << endl; + return 0; +} +int arr[20000000]; +int main() { + long long int n; + cin >> n; + arr[n + 1]; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + sort(arr + 1, arr + n + 1); + long long int mindis = 100000000000; + int cnt = 0; + for (int i = 1; i < n; i++) { + if (abs(arr[i + 1] - arr[i]) < mindis) { mindis = abs(arr[i + 1] - arr[i]); } + } + for (int i = 1; i < n; i++) { + if (abs(arr[i + 1] - arr[i]) == mindis) { cnt++; } + } + cout << mindis << " " << cnt << endl; + return 0; +} +long long int a = 1, b = 1; +int n; +int main() { + cin >> n; + string tmp; + for (int i = 0; i < n; i++) { + cin >> tmp; + if (tmp == "UR" || tmp == "DL" || tmp == "ULDR") a++; + if (tmp == "UL" || tmp == "DR" || tmp == "ULDR") b++; + } + cout << a * b << endl; +} +int main() { + string texto; + long long caso1 = 0, caso2 = 0; + cin >> texto; + int n = texto.size(); + char verif; + char cambio; + for (int i = 0; i < n; i++) { + verif = texto[i]; + if (isupper(verif)) { + caso2 += 1; + } else if (islower(verif)) { + caso1 += 1; + } + } + for (int i = 0; i < n; i++) { + if (caso1 > caso2 || caso1 == caso2) { + cambio = tolower(texto[i]); + texto[i] = cambio; + } else if (caso1 < caso2) { + cambio = toupper(texto[i]); + texto[i] = cambio; + } + } + cout << texto << endl; + return 0; +} +bool check(long long a) { + if (a % 10 == 7) return true; + a /= 10; + if (a % 10 == 7) return 7; + return false; +} +int main() { + long long x, h, m, ans = 0; + cin >> x >> h >> m; + long long h1 = x / 60; + long long m1 = x % 60; + while (true) { + if (check(h) || check(m)) { + cout << ans << "\n"; + break; + } + ans += 1; + m -= m1; + h -= h1; + if (m < 0) { + m += 60; + h -= 1; + } + if (h < 0) { h += 24; } + } + return 0; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +unsigned long long int factorial(unsigned long long int n) { + if (n == 0) return 1; + return n * factorial(n - 1); +} +long long int nCr[1001][1001]; +void combi() { + for (int i = 1; i <= 1000; i++) { + nCr[0][i] = 0; + nCr[i][0] = 1; + } + for (int i = 1; i <= 1000; i++) { + for (int j = 1; j <= 1000; j++) { + if (i < j) { + continue; + } else if (i == j) { + nCr[i][j] = 1; + } else { + nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1]; + } + } + } +} +int main() { + long long int n; + cin >> n; + long long int arr[n]; + for (long long int i = 0; i < n; i++) { cin >> arr[i]; } + long long int min = LONG_MAX; + for (long long int i = 0; i < n; i++) { + long long int cost = 0; + for (long long int j = 0; j < n; j++) { cost += (arr[j] * (abs(i - j) + j + i + i + j + abs(j - i))); } + if (cost < min) min = cost; + } + cout << min << endl; + return 0; +} +int n, a, b, c1, c2; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) + c1++; + else if (b > a) { + c2++; + } + } + if (c1 > c2) + cout << "Mishka" << endl; + else if (c1 < c2) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +void solve() { + int n; + cin >> n; + vector a; + for (int i = 0; i < n; ++i) { + int buff; + cin >> buff; + a.push_back(buff); + } + sort((a).begin(), (a).end()); + int m = a.size() / 2; + cout << a[m] << endl; +} +int main() { + solve(); + return 0; +} +; +const long long INT64M = 0X3F3F3F3F3F3F3F3F; +const int INT32M = 0x3F3F3F3F; +const int mod = 1e9 + 7; +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << a[2] - a[0] << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + string str; + cin >> str; + if (str.length() > 10) { + cout << str[0] << str.length() - 2 << str[str.length() - 1] << endl; + } else { + cout << str << endl; + } + } +} +int main() { + int n; + cin >> n; + int arr[n]; + int even = 0, odd = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] % 2 == 0) + even++; + else + odd++; + } + if (odd == 1) { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 1) { + cout << i + 1 << endl; + return 0; + } + } + } else { + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + cout << i + 1 << endl; + return 0; + } + } + } +} +char arr[105]; +int main() { + int n, k; + cin >> n >> k; + int a = 0, b = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 'G' || arr[i] == 'T') { + if (a == 0) { + a = i + 1; + } else + b = i + 1; + } + } + if ((b - a) % k != 0) { + cout << "NO" << endl; + } else { + for (int i = a; i < b; i += k) { + if (arr[i - 1] == '#') { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + } +} +int main() { + string s; + cin >> s; + unsigned long long int i = 0; + if (s[i] == '9') { + cout << s[i]; + i++; + } + for (; i < s.length(); i++) { cout << min(s[i] - '0', 9 - (s[i] - '0')); } + cout << endl; + return 0; +} +int main() { + long long n; + long long w; + long long t; + int q = 1; + cin >> n; + if (n == 0) { + cout << q << endl; + } else { + long long int r = int(sqrt((n * n) / 2)) * 2; + w = n * n; + if ((r / 2) * (r / 2) + (r / 2 + 1) * (r / 2 + 1) <= w) { r++; } + cout << 4 * r << endl; + } +} +string s; +int main() { + cin >> s; + s += 'a'; + int tmp = 1, ans = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == s[i + 1]) + tmp++; + else { + if (tmp % 2 == 0) ans++; + tmp = 1; + } + } + cout << ans << endl; + return 0; +} +const int maxn = (int)1e5 + 5; +const long long mod = 1e9 + 7; +int main() { + double l, p, q; + cin >> l >> p >> q; + double t1 = ((2 * l) / (p + q)); + double t2 = l / (p + q); + double ans = p * (t1 - t2); + cout << ans << endl; + return 0; +} +int q, n, i; +string s; +int main() { + cin >> q; + while (q--) { + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl << 2 << endl << s[0] << " "; + for (i = 1; i < n; i++) cout << s[i]; + cout << endl; + } + } +} +int main() { + long long n; + cin >> n; + cout << 2 << endl; + for (long long i = 2; i <= n; ++i) cout << (i * i * i + 2 * i * i + 1) << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + if (n - k > k - 1) { + for (int i = 0; i < k - 1; i++) { cout << "LEFT" << endl; } + for (int i = 0; i < n; i++) { + cout << "PRINT " << s[i] << endl; + if (i != n - 1) cout << "RIGHT" << endl; + } + } else { + for (int i = 0; i < n - k; i++) { cout << "RIGHT" << endl; } + for (int i = 0; i < n; i++) { + cout << "PRINT " << s[n - i - 1] << endl; + if (i != n - 1) cout << "LEFT" << endl; + } + } + return 0; +} +int main() { + string f, l, ans; + cin >> f >> l; + int i = 1; + ans.push_back(f[0]); + while (f[i] != '\0' && f[i] < l[0]) { + ans.push_back(f[i]); + i++; + } + ans.push_back(l[0]); + cout << ans << endl; + return 0; +} +long long int M = 100000000000000; +long long int M1 = 1000000007; +int main() { + int n, i, x1, x2, ans, x3; + cin >> n; + vector v(n); + for (i = 0; i < n; i++) cin >> v[i]; + int dp[105][3]; + for (i = 0; i < 3; i++) { dp[0][i] = 1; } + if (v[0] == 1) + dp[0][1] = 0; + else if (v[0] == 2) + dp[0][0] = 0; + else if (v[0] == 3) { + dp[0][0] = 0; + dp[0][1] = 0; + } + if (n == 1) { + ans = min(dp[0][0], min(dp[0][1], dp[0][2])); + cout << ans << endl; + return 0; + } + for (i = 1; i < n; i++) { + if (v[i] == 0) { + x1 = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])); + dp[i][0] = 1 + x1; + dp[i][1] = 1 + x1; + dp[i][2] = 1 + x1; + } else if (v[i] == 1) { + x1 = min(dp[i - 1][0], dp[i - 1][2]); + x2 = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])); + dp[i][0] = 1 + x2; + dp[i][2] = 1 + x2; + dp[i][1] = x1; + } else if (v[i] == 2) { + x1 = min(dp[i - 1][1], dp[i - 1][2]); + x2 = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])); + dp[i][1] = 1 + x2; + dp[i][2] = 1 + x2; + dp[i][0] = x1; + } else { + x1 = min(dp[i - 1][0], dp[i - 1][2]); + x2 = min(dp[i - 1][1], dp[i - 1][2]); + dp[i][1] = x1; + dp[i][0] = x2; + x3 = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])); + dp[i][2] = 1 + x3; + } + } + ans = min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])); + cout << ans << endl; +} +int arr[105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int ans = INT_MAX; + for (int i = 1; i < n - 1; i++) { + int mx = INT_MIN; + for (int j = 0; j < n - 1; j++) { + int a = j; + if (a != i) { + int b = j + 1; + if (b == i) b += 1; + mx = max(mx, arr[b] - arr[a]); + } + } + ans = min(ans, mx); + } + cout << ans << endl; +} +int ar[105][105]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + x1--; + y1--; + for (int j = y1; j < y2; j++) { + for (int k = x1; k < x2; k++) { ar[j][k]++; } + } + } + int sum = 0; + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { sum += ar[i][j]; } + } + cout << sum << endl; + return 0; +} +int main() { + int a, b, c; + float t; + cin >> a >> b >> c; + t = (float)((a * c) - (b * c)) / (float)b; + cout << ceil(t) << endl; + return 0; +} +int n; +string w[110]; +int main() { + int ans = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> w[i]; + for (int i = 0; i < 26; i++) { + for (int j = i; j < 26; j++) { + int sum = 0; + for (int k = 0; k < n; k++) { + int cnt = 0; + for (; cnt < w[k].size(); cnt++) { + if (w[k][cnt] != (j + 'a') && w[k][cnt] != (i + 'a')) break; + } + if (cnt == w[k].size()) sum += w[k].size(); + } + ans = max(ans, sum); + } + } + cout << ans << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M; + K = 1; + while (K <= M) { + M -= K; + K++; + if (K > N) K -= N; + } + cout << M << endl; + return 0; +} +int main() { + int n, MIN, price = 0; + cin >> n; + int a[1000000], p[1000000]; + for (int i = 0; i < n; i++) cin >> a[i] >> p[i]; + MIN = p[0]; + for (int j = 0; j < n; j++) { + if (p[j] < MIN) MIN = p[j]; + price = price + a[j] * MIN; + } + cout << price << endl; + return 0; +} +int main() { + int k, a, b, c; + cin >> k >> a >> b >> c; + for (int i = 1; i <= 1000; i++) { + int n = k * i; + n = min(n, b + i); + if (c * n >= a) { + cout << i << endl; + return 0; + } + } + return 0; +} +const int s = 1E5 + 2; +int a[s], b[s]; +int main() { + int n1, n2; + cin >> n1 >> n2; + int k, m; + cin >> k >> m; + for (int i = 0; i < n1; i++) cin >> a[i]; + for (int i = 0; i < n2; i++) cin >> b[i]; + if (a[k - 1] < b[n2 - m]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int cnt = 1, mx = 0, l = 0; + for (int i = 1; i < n; i++) { + if (arr[i] - arr[l] <= k and l != i) + cnt++; + else if (l != i) + mx = max(mx, cnt), cnt = (cnt == 1) ? 1 : cnt - 1, l++, i--; + } + mx = max(mx, cnt); + cout << n - mx << endl; +} +int main() { + string s; + cin >> s; + int j = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '4' || s[i] == '7') j++; + } + if (j == 4 || j == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int64_t x, y, x1, y1; + cin >> x >> y >> x1 >> y1; + cout << max(abs(x - x1), abs(y - y1)) << endl; +} +int main() { + long long n, m; + cin >> n >> m; + if (!n && !m) { + cout << "0 0\n"; + return 0; + } + if (!n) { + cout << "Impossible\n"; + return 0; + } + long long mx = n + m; + if (m) mx--; + long long mn = n + m; + mn -= min(n, m); + cout << mn << " " << mx << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int q = 0; + for (int i = 0; i < s2.size(); i++) { + if (s1[q] == s2[i]) { q++; } + } + cout << q + 1 << endl; + return 0; +} +long long modl(long long n, long long k, long long p) { + if (n == 0) return 0; + if (k == 0) + return 1; + else if (k % 2 == 0) { + return (modl(n, k / 2, p) * (modl(n, k / 2, p))) % p; + } else + return (n * modl(n, k - 1, p)) % p; +} +int main() { + long long n, m; + cin >> n >> m; + long long z = modl(3, n, m); + if (z == 0) + cout << m - 1 << endl; + else + cout << z - 1 << endl; + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int tmp, ans = 0; + for (int i = 0; i < n; i++) { + cin >> tmp; + if (i < n - k) + ans += tmp; + else + ans += x; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, tmp; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> tmp; + if (tmp == 1 && (i == 0 || i == n - 1 || j == 0 || j == m - 1)) { + cout << 2 << endl; + return 0; + } + } + } + cout << 4 << endl; + return 0; +} +int main() { + long long x, y; + cin >> x; + y = x % 2; + if (y == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int a, b, c, t, n, min; + cin >> a >> b >> c; + n = a * c; + t = (n / b); + if (t * b >= n) + cout << (n / b) - c << endl; + else + cout << ((n / b) + 1) - c << endl; + return 0; +} +long long mod = 1000000007; +long long int fast_exp(long long int base, long long int ex) { + long long int res = 1; + while (ex > 0) { + if (ex % 2 == 1) res = (res * base) % mod; + base = (base * base) % mod; + ex /= 2; + } + return res % mod; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + long long int re = gcd(b, a % b); + return re; +} +map ma; +map mg; +long long conv(long long a) { + long long f = 0; + long long re = 0; + long long b = 2; + while (a) { + long long j = a % 10; + j = j % 2; + if (j == 1) { + long long v = fast_exp(b, f); + re += v; + } + f++; + a /= 10; + } + return re; +} +int main() { + long long t; + cin >> t; + while (t--) { + char f; + cin >> f; + long long a; + cin >> a; + if (f == '+') { + ma[a]++; + long long k = conv(a); + mg[k]++; + continue; + } + if (f == '-') { + ma[a]--; + long long k = conv(a); + mg[k]--; + continue; + } + if (f == '?') { + long long k = conv(a); + cout << mg[k] << "\n"; + } + } + return 0; +} +bool beat(char c, char d) { + if (c == 'R' && d == 'S' || c == 'S' && d == 'P' || c == 'P' && d == 'R') return true; + return false; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int m = a.size(), k = b.size(); + int as = 0, bs = 0; + for (int i = 0; i < m * k && i < n; i++) { + int tims = 1 + (n - i - 1) / (m * k); + if (beat(a[i % a.size()], b[i % b.size()])) bs += tims; + if (beat(b[i % b.size()], a[i % a.size()])) as += tims; + } + cout << as << ' ' << bs << endl; + return 0; +} +const char simb[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'}; +int main() { + ifstream D("duom.txt"); + ofstream R("rez.txt"); + int n; + int mas[1000]; + int mas2[1000]; + string a; + cin >> n; + cin >> a; + for (int i = 0; i < n; i++) { mas[i] = a[i] - '0'; } + cin >> a; + for (int i = 0; i < n; i++) { mas2[i] = a[i] - '0'; } + int suma = 0; + int kiekis = 0; + for (int i = 0; i < n; i++) { + suma = abs(mas[i] - mas2[i]); + kiekis += suma > 5 ? (10 - suma) : suma; + } + cout << kiekis << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int i = 0; + for (; i < len; i++) { + if (s[i] == '.') break; + } + if (s[i - 1] != '9') { + if (s[i + 1] >= '5') { + int j = 0; + for (; j < i - 1; j++) { cout << s[j]; } + cout << s[i - 1] - '0' + 1 << endl; + } else { + for (int j = 0; j < i; j++) { cout << s[j]; } + cout << endl; + } + } else + cout << "GOTO Vasilisa." << endl; +} +int n; +int ans = -1; +int res = 0; +int main() { + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) res++; + } + if (res == n) { + cout << n - 1 << endl; + return 0; + } + if (n == 1 && a[0] == 1) { + cout << "0" << endl; + return 0; + } + for (int j = 0; j < n; j++) { + for (int k = 0; k <= n; k++) { + int cnt = 0; + for (int l = 0; l < n; l++) { + if (l >= k && l <= j) + cnt = cnt + !a[l]; + else + cnt = cnt + a[l]; + } + ans = max(ans, cnt); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long a, b, m, n; + cin >> a >> b; + cin >> m >> n; + int ar[a + 5], br[b + 5]; + for (int i = 0; i < a; i++) { cin >> ar[i]; } + for (int j = 0; j < b; j++) { cin >> br[j]; } + if (ar[m - 1] < br[b - n]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const long long N = 1e4; +long long cnt; +string s, s1, s2; +map mp; +int main() { + cin >> s; + for (long long i = 0; i < s.size(); i++) { + s2 = s[0]; + s.erase(s.begin() + 0); + s += s2; + mp[s]++; + if (mp[s] == 1) { cnt++; } + } + cout << cnt; + cout << "\n"; + return 0; +} +const int maxN = 2012345678; +int n; +int main() { + cin >> n; + long long int sum = (n * (n + 1)) / 2; + if (sum % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int p, n; + cin >> p >> n; + vector a(p); + for (int i = 1; i <= n; i++) { + int val; + cin >> val; + int mod = val % p; + if (a[mod]) { + cout << i << endl; + return 0; + } + a[mod]++; + } + cout << -1 << endl; + return 0; +} +int main() { + long long n, c = 0; + cin >> n; + while (n) { + if (n >= 5) { + n -= 5; + c++; + } + if (n >= 4 && n < 5) { + n -= 4; + c++; + } + if (n >= 3 && n < 4) { + n -= 3; + c++; + } + if (n >= 2 && n < 3) { + n -= 2; + c++; + } + if (n == 1) { + n--; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, x, y; + cin >> n >> m; + set ss; + for (int i = 0; i < n; ++i) { + cin >> x; + for (int j = 0; j < x; ++j) { + cin >> y; + ss.insert(y); + } + } + cout << (ss.size() == m ? "YES" : "NO") << endl; +} +int main() { + int n, k; + cin >> n >> k; + int maximum = -2147483648; + int f[n], t[n]; + for (int i = 0; i < n; i++) { + cin >> f[i] >> t[i]; + if (t[i] <= k) { + maximum = max(maximum, f[i]); + } else { + maximum = max(maximum, f[i] - t[i] + k); + } + } + cout << maximum << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + if (i % 2 == 1) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } else { + if (i % 4 == 0) { + cout << "#"; + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << endl; + } else { + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << "#" << endl; + } + } + } + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n == 1) { cout << 5 << endl; } + if (n == 0) { cout << 1 << endl; } + if (n >= 2) { cout << 25 << endl; } +} +int main() { + int n; + cin >> n; + string *arr = new string[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int ln = arr[0].length(); + bool check = true; + int res = 0; + for (int i = 0; i < ln; i++) { + char a = arr[0][i]; + for (int j = 0; j < n; j++) { + if (a != arr[j][i]) { + check = false; + break; + } + } + if (check) + res++; + else + break; + } + cout << res << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + for (int k = j + 1; k < s.size(); k++) { + if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') { ans++; } + } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + string password; + cin >> password; + map mp; + for (int i = 0; i < 10; i++) { + string s; + cin >> s; + mp[s] = i; + } + int index = 0; + for (int i = 0; i < 8; i++) { + string s = password.substr(index, 10); + cout << mp[s]; + index += 10; + } + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[1000005]; + int n1, n2, n3; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) + n1++; + else if (a[i] == 2) + n2++; + else + n3++; + } + if ((n1 >= n2) && (n1 >= n3)) + cout << n - n1 << endl; + else if ((n2 >= n1) && (n2 >= n3)) + cout << n - n2 << endl; + else + cout << n - n3 << endl; + return 0; +} +int main() { + int n, m, l, r; + char x, y; + cin >> n >> m; + string s; + cin >> s; + while (m--) { + cin >> l >> r >> x >> y; + for (int i = l - 1; i <= r - 1; i++) { + if (s[i] == x) { s[i] = y; } + } + } + cout << s << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + float n = 360.0 / (180.0 - a); + if (n - (int)(n) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + cout << N / 2 + 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + map m; + int i; + int c = 0; + for (i = 0; i < s.size(); i++) { + if (m.find(s[i]) == m.end()) { + ++c; + m[s[i]] = 1; + } + } + if (c % 2 == 1) + cout << "IGNORE HIM!" << endl; + else + cout << "CHAT WITH HER!" << endl; +} +int main() { + long long int p, n; + cin >> p >> n; + set st; + bool flag = true; + long long int m = INT_MAX; + for (int i = 1; i <= n; i++) { + long long int x; + cin >> x; + if (st.find(x % p) == st.end()) { + st.insert(x % p); + } else if (flag) { + m = i; + flag = false; + } + } + if (flag) + cout << -1 << endl; + else + cout << m << endl; + return 0; +} +int main() { + int q; + cin >> q; + char arr[q]; + string s, a, b, c; + int j, i; + for (j = 0; j < q; j++) { + cin >> i; + cin >> s; + int i = 1, n = s.size(), j, k; + a = s[0]; + b.append(s, 1, n - 1); + c.append(s, 1, n - 1); + if (n == 1) + cout << "NO" << endl; + else if (n == 2) { + if (a < b) { + cout << "YES" << endl; + cout << "2" << endl; + cout << a << " " << c << endl; + } else + cout << "NO" << endl; + b.erase(); + c.erase(); + } else { + while (i < n) { + if (s[i] != 0) { + if (a.size() < b.size() || a < b) { + cout << "YES" << endl; + cout << "2" << endl; + cout << a << " " << c << endl; + } else + cout << "NO" << endl; + b.erase(); + c.erase(); + break; + } + b.erase(0, 1); + i++; + } + } + } + return 0; +} +long long w[1000006] = {}; +long long d[1000006] = {}, sum[1000006] = {}; +int main() { + long long n, l, r, q1, q2; + cin >> n >> l >> r >> q1 >> q2; + for (int i = 0; i < n; i++) { + cin >> w[i]; + if (i == 0) + sum[i] = w[i]; + else + sum[i] = sum[i - 1] + w[i]; + } + if (n == 1) { + cout << (min(l, r) * w[0]) << endl; + return 0; + } + int st = 0, en = n - 1; + bool left = 0, right = 0; + long long ct = 0; + if (l == r) { + for (int i = 0; i < n; i++) { ct += w[i]; } + ct = ct * l; + cout << ct << endl; + return 0; + } else if (r < l) { + ct = w[n - 1] * r; + right = 1; + st = 0; + en = n - 1; + d[en] = ct + sum[en - 1] * (l) + q1 * (en - 1); + d[st] = (sum[n - 1]) * r + (n - 1) * q2; + en = n - 2; + for (int i = 1; i <= (n - 1) / 2; i++) { d[i] = d[i - 1] - 2 * q2 + w[i - 1] * l - w[i - 1] * r; } + for (int i = n - 2; i > (n - 1) / 2; i--) { d[i] = d[i + 1] - 2 * q1 - w[i] * l + w[i] * r; } + } else { + ct = w[0] * l; + right = 1; + st = 0; + en = n - 1; + d[en] = sum[en] * (l) + q1 * (n - 1); + d[st] = ct + (sum[n - 1] - sum[st]) * r + (n - 1 - (st + 1)) * q2; + st = 1; + for (int i = n - 2; i >= n / 2; i--) { d[i] = d[i + 1] - 2 * q1 - w[i + 1] * l + w[i + 1] * r; } + for (int i = 1; i < n / 2; i++) { d[i] = d[i - 1] - 2 * q2 - w[i] * r + w[i] * l; } + } + sort(d, d + n); + cout << d[0] << endl; + return 0; +} +vector vec; +int main() { + int n; + cin >> n; + int arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + int cnt = 0; + for (int i = 0; i < n; i++) { + bool t = true; + for (int j = 0; j < n; j++) { + if (arr[i][j] == 1 || arr[i][j] == 3) { + t = false; + break; + } + } + if (t) { + cnt++; + vec.push_back(i + 1); + } + } + cout << cnt << endl; + int len = vec.size(); + for (int i = 0; i < len - 1; i++) { cout << vec[i] << " "; } + if (cnt > 0) cout << vec[vec.size() - 1] << endl; +} +int main() { + int k; + string s; + int c[26] = {0}; + cin >> k >> s; + if (s.size() % k != 0) { + cout << -1 << endl; + return 0; + } + for (int i = 0; i < s.size(); ++i) { ++c[s[i] - 'a']; } + for (int i = 0; i < 26; ++i) { + if (c[i] % k != 0) { + cout << -1 << endl; + return 0; + } + } + string res; + for (int i = 0; i < 26; ++i) { + for (int j = 0; j < c[i] / k; ++j) { res += char('a' + i); } + } + for (int i = 0; i < k; ++i) { cout << res; } + cout << endl; + return 0; +} +int n; +int a[2001]; +int b[2001]; +int ans; +set s; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + s.insert(a[i]); + } + for (int j = 1; j <= n; j++) { + cin >> b[j]; + s.insert(b[j]); + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (s.find(a[i] ^ b[j]) != s.end()) { ans++; } + } + } + if (ans % 2) + cout << "Koyomi" << endl; + else + cout << "Karen" << endl; + return 0; +} +int main() { + long long int a, b, c, d, r[100004], e; + while (cin >> a >> b >> c) { + memset(r, 0, sizeof(r)); + for (d = a; d <= c; d += a) { r[d] = 1; } + e = 0; + for (d = b; d <= c; d += b) { + if (r[d] == 1) { e++; } + } + cout << e << endl; + } + return 0; +} +int main() { + int a[101][101], n; + while (cin >> n) { + for (int i = 0; i <= 100; i++) + for (int j = 1; j <= 100; j++) a[i][j] = 0; + int cnt = 0; + for (int i = 0; i < n; i++) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cnt += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << cnt << endl; + } +} +int main() { + int n, d[5011], lzl = 0; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> d[i]; } + for (int i = 1; i <= n; i++) { + for (int l = 1; l <= n; l++) { + if (d[l] == i) { + for (int c = 1; c <= n; c++) { + if (d[c] == l && d[i] == c) { + cout << "YES" << endl; + lzl++; + i = n + 1; + } + } + } + } + } + if (lzl == 0) { cout << "NO" << endl; } + return 0; +} +const int N = 1e3 + 5, OO = 0x3f3f3f3f; +bool check(char x) { + return x == '!' || x == '_' || x == '?' || x == '.' || x == ','; +} +int main() { + string s; + cin >> s; + int a[5]; + memset(a, 0, sizeof(a)); + bool f = 1; + if (s.size() < 5) return puts("Too weak"), 0; + for (int i = 0; i < s.size(); i++) + if (s[i] >= '0' && s[i] <= '9') + a[0]++; + else if (s[i] >= 'a' && s[i] <= 'z') + a[1]++; + else if (s[i] >= 'A' && s[i] <= 'Z') + a[2]++; + for (int i = 0; i < 3; i++) + if (!a[i]) f = 0; + if (f) + puts("Correct"); + else + puts("Too weak"); + return 0; +} +char my[] = {'Q', 'A', 'Q'}; +unsigned long long int FindString(string s, int start, int idx) { + int cnt = 0; + for (int i = start; i < s.size(); i++) { + if (s[i] == my[idx] && idx == 2) { + cnt++; + } else if (s[i] == my[idx]) { + cnt += FindString(s, i, idx + 1); + } + } + return cnt; +} +int main() { + string s; + cin >> s; + cout << FindString(s, 0, 0) << '\n'; + return 0; +} +int N, K, ans = 2e9, val, x, y; +int main() { + cin >> N; + for (int i = 1; i * i <= N; i++) { + if (N % i == 0) { + if (N / i - i < ans) { + ans = N / i - i; + x = i; + y = N / i; + } + } + } + cout << x << ' ' << y << '\n'; +} +int main() { + string a; + string b; + int i; + getline(cin, a); + getline(cin, b); + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a == b) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +const int maxn = 2000 + 5; +string s1[maxn], s2[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s1[i]; + for (int i = 0; i < m; i++) cin >> s2[i]; + for (int i = 0; i <= n - m; i++) + for (int j = 0; j <= n - m; j++) { + bool flag = true; + for (int p = 0; p < m && flag; p++) { + if (memcmp(&s1[i + p][0], &s2[p][j], m)) flag = false; + } + if (flag) { + cout << i + 1 << " " << j + 1 << "\n"; + return 0; + } + } + return 0; +} +int main() { + int n, p, indx = 0; + int lv[200]; + cin >> n; + for (int i = 0; i < 2; i++) { + cin >> p; + for (int j = 0; j < p; j++) { + cin >> lv[indx]; + indx++; + } + } + int value = 0; + for (int i = 1; i <= n; i++) { + for (int j = 0; j < indx; j++) { + if (i == lv[j]) { + value++; + break; + } + } + } + if (value == n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +const int N = 2e6 + 123; +const int INF = 1e9 + 123; +const int MOD = 1e9 + 7; +const double EPS = 1e-9; +const int dx[] = {0, 0, 1, -1}; +const int dy[] = {1, -1, 0, 0}; +int n, a, b; +bool no; +int main() { + cin >> n; + a = 1; + b = 2; + for (int i = 1; i <= n; ++i) { + int x; + cin >> x; + int c = 6 - (a + b); + if (c == x) + no = 1; + else if (a == x) + b = c; + else + a = c; + } + if (no) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + long a(0), b(0); + cin >> a >> b; + long total(0); + while (a > 0 && b > 0) { + if (a > b) { + total += a / b; + a -= (a / b) * b; + } else { + total += b / a; + b -= (b / a) * a; + } + } + cout << total << endl; + } + return 0; +} +const long long mod = 1000000007; +long long a, b, c, d, e; +int main() { + long long ans; + int n; + cin >> n; + for (int i = 0; i < (n); i++) { + string s; + cin >> s; + if (s == "UR") + ++a; + else if (s == "UL") + ++b; + else if (s == "DL") + ++c; + else if (s == "DR") + ++d; + else + ++e; + } + long long x = a + c + e; + long long y = b + d + e; + ans = (x + 1) * (y + 1); + cout << ans << endl; + return 0; +} +int main() { + int n, c, x, r = 0, t; + priority_queue p; + cin >> n; + cin >> c; + n = n - 1; + while (n--) { + cin >> x; + p.push(x); + } + t = p.top(); + while (c <= t) { + p.pop(); + c++; + t--; + r++; + p.push(t); + t = p.top(); + } + cout << r << endl; + return 0; +} +const int N = 1e5 + 100; +string s; +int col, row, ans; +int dr[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; +int dc[8] = {0, 1, 1, 1, 0, -1, -1, -1}; +int bfs(int x, int y) { + int ret = 0; + for (int i = 0; i < 8; i++) { + int nr = x + dr[i]; + int nc = y + dc[i]; + if (nr >= 0 && nr < 8 && nc >= 0 && nc < 8) ret++; + } + return ret; +} +int main() { + cin >> s; + col = s[0] - 'a'; + row = s[1] - '1'; + ans = bfs(row, col); + cout << ans << endl; + return 0; +} +const int nmax = 1e5 + 2; +const long long mod = 1e9 + 7; +long long a, b, c, l; +long long hishab(long long x, long long y) { + x = min(x, y); + return (x + 1) * (x + 2) / 2; +} +int main() { + while (cin >> a >> b >> c >> l) { + long long jhamela = 0, shob = 0; + for (long long i = 0; i <= l; i++) { + if (a + i >= b + c) { jhamela += hishab((i + a - b - c) / 2, i); } + if (b + i >= a + c) { jhamela += hishab((i + b - a - c) / 2, i); } + if (c + i >= b + a) { jhamela += hishab((i + c - b - a) / 2, i); } + shob += hishab(i, LLONG_MAX); + } + if (shob - jhamela < 0) + cout << "0" << endl; + else + cout << shob - jhamela << endl; + } + return 0; +} +int main() { + int m, n; + while (cin >> m >> n) { + int s = n, rem, total = m; + while (1) { + rem = m % s; + m = m / s; + total += m; + m += rem; + if (m < n) break; + } + cout << total << endl; + } + return 0; +} +int main() { + vector v; + int n, i; + for (i = 0; i < 3; i++) { + cin >> n; + v.push_back(n); + } + sort(v.begin(), v.end()); + n = (v[1] - v[0]) + (v[2] - v[1]); + cout << n << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n) { + int a[1000], j = 0, x = 0, i = 1, y, p; + m = n; + while (m) { + x++; + m /= 10; + } + if (n > 20) i = n - x * 9; + for (i = i; i <= n; i++) { + y = 0; + p = i; + while (p) { + y += p % 10; + p /= 10; + } + if (i + y == n) a[j++] = i; + } + cout << j << endl; + for (int w = 0; w < j; w++) cout << a[w] << endl; + } + return 0; +} +char upLetter(char letter) { + if (letter == 'z') { + return 'z'; + } else { + return (letter + 1); + } +} +char downLetter(char letter) { + if (letter == 'a') { + return 'a'; + } else { + return (letter - 1); + } +} +bool palindrom(char begin, char end) { + bool ok = false; + if (downLetter(begin) == downLetter(end) && begin != 'a' && end != 'a') { + ok = true; + } else if (downLetter(begin) == upLetter(end) && begin != 'a' && end != 'z') { + ok = true; + } else if (upLetter(begin) == downLetter(end) && begin != 'z' && end != 'a') { + ok = true; + } else if (upLetter(begin) == upLetter(end) && begin != 'z' && end != 'z') { + ok = true; + } + return ok; +} +int main() { + int numW, numL, size; + bool check; + string word; + cin >> numW; + for (unsigned i = 0; i < numW; i++) { + cin >> numL; + check = false; + cin >> word; + for (unsigned j = 0; j < numL / 2; j++) { + size = word.length(); + if (palindrom(word.at(j), word.at(size - (1 + j)))) { + check = true; + } else { + check = false; + break; + } + } + if (check) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + } +} +int n; +int a[6], b[6]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[x]++; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b[x]++; + } + int ans = 0; + for (int i = 1; i <= 5; i++) { + if ((a[i] + b[i]) % 2 == 1) { + cout << -1 << "\n"; + return 0; + } + ans += abs(a[i] - (a[i] + b[i]) / 2); + } + cout << ans / 2 << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + vector v; + int cnt = 1; + for (int i = 1; i < n; i++) { + if (a[i] == a[i - 1]) { + cnt++; + } else { + v.push_back(cnt); + cnt = 1; + } + } + v.push_back(cnt); + long long ans = 0; + for (int i = 0; i < v.size(); i++) { ans += (v[i] * (v[i] + 1) / 2); } + cout << ans << endl; + return 0; +} +int main() { + int x = 0, k, n, w, i; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { x = x + i * k; } + if (n >= x) + cout << "0" << endl; + else if (x > n) + cout << x - n << endl; + return 0; +} +int main() { + int n; + int min1, min2, min3, max1, max2, max3; + int S1, S2, S3; + cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; + if (n == max1 + min2 + min3) { + S1 = max1; + S2 = min2; + S3 = min3; + cout << S1 << " " << S2 << " " << S3 << endl; + } else if (n > max1 + min2 + min3) { + S1 = max1; + if ((n - S1 - max2) == min3) { + S2 = max2; + S3 = min3; + } else if ((n - S1 - max2) > min3) { + S2 = max2; + S3 = n - S1 - S2; + } else { + S2 = n - S1 - min3; + S3 = min3; + } + cout << S1 << " " << S2 << " " << S3 << endl; + } else { + S1 = n - min2 - min3; + S2 = min2; + S3 = min3; + cout << S1 << " " << S2 << " " << S3 << endl; + } + return 0; +} +string s, t; +int x, res; +int main() { + cin >> s >> t; + for (int i = 0; i < (int)t.size(); i++) { + for (int j = x; j < (int)s.size();) { + if (t[i] == s[j]) { + res = ++j; + x = j; + break; + } + break; + } + } + cout << ++res << "\n"; + return 0; +} +int arr[1000]; +int main() { + int n; + cin >> n; + int l, r; + cin >> l >> r; + n--; + while (n--) { + int x, y; + cin >> x >> y; + for (int i = x; i < y; i++) arr[i]++; + } + int ans = 0; + for (int i = l; i < r; i++) + if (arr[i] == 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + string *ch, var; + int n; + cin >> var >> n; + ch = new string[n]; + for (int i = 0; i < n; i++) cin >> ch[i]; + sort(ch, ch + n); + for (int i = 0; i < n; i++) { + if (ch[i].find(var) == 0) { + cout << ch[i] << endl; + return 0; + } + } + cout << var << endl; + return 0; +} +const int P = 1e9 + 7; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long qpow(long long a, long long n, long long p = P) { + long long r = 1 % p; + for (a %= P; n; a = a * a % p, n >>= 1) + if (n & 1) r = r * a % p; + return r; +} +long long inv(long long x) { + return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; +} +long long work() { + long long x, y, k; + cin >> x >> y >> k; + if (x >= k || y >= k) return 0; + if (x <= 0 && y <= 0) return -1; + if (x > y) swap(x, y); + long long ans = 0; + if (x < 0) { + if (k > 0) + ans += -x / y, x += -x / y * y; + else + ans += -k / y, x += -k / y * y; + } + for (; y < k; ++ans) { + if (x > y) swap(x, y); + long long t = x + y; + x = y, y = t; + } + return ans; +} +int main() { + cout << work() << endl; +} +int main() { + int n, d, ans = 0, m = 0; + cin >> n >> d; + string a[d]; + for (int i = 0; i < d; i++) { cin >> a[i]; } + for (int i = 0; i < d; i++) { + int c = 1; + for (int j = 0; j < n; j++) { + if (a[i][j] != '1') { + ans++; + c = 0; + if (ans >= m) { m = ans; } + break; + } + } + if (c) { ans = 0; } + } + cout << m << '\n'; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + for (int i = 0; i < s.length(); i++) { + if (s[i] == t[i]) { + cout << 0; + } else { + cout << 1; + } + } + cout << endl; +} +const int maxn = 1e9 + 7; +const int INF = 0x3f3f3f3f; +const int maxx = 1e5; +long long poww(int a) { + long long k = 1, sum = 0; + for (int i = 0; i < a; i++) { k = k * 2; } + return k; +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= 35) { + cout << m << endl; + } else { + long long q; + q = poww(n); + cout << m % q << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long a = 3; + int i = 1; + int two = 0; + while (n > 0) { + if (n % 2 == 1) i = i * a % m; + n = n / 2; + a = (a * a) % m; + } + cout << (i - 1 + m) % m << endl; + return 0; +} +const int INF = 1e9; +const int N = 1e5; +int arr[10001]; +void prework() { + arr[0] = 0; + for (int i = 1; i <= 10000; i++) { arr[i] = arr[i - 1] + i; } +} +int main() { + prework(); + int n, cnt = 0; + cin >> n; + for (int i = 1;; i++) { + if (n < arr[i]) break; + n -= arr[i]; + cnt++; + } + cout << cnt << endl; + return 0; +} +long long int x[999999], y[999999]; +int main() { + { + long long int a, b, c = 0, d, e, f, i, j, k, l, t, p, q, m, n, sum = 0; + cin >> n >> m; + for (i = 0; i < n; i++) cin >> x[i]; + for (i = 0; i < m; i++) cin >> y[i]; + sort(x, x + n); + sort(y, y + m); + a = x[0], b = x[n - 1], c = y[0]; + if (c <= b) { + cout << "-1\n"; + } else { + d = a * 2; + d = max(d, b); + if (d >= c) + cout << "-1\n"; + else + cout << d << endl; + } + } + return 0; +} +int main() { +a: + string s, s2; + cin >> s >> s2; + int n; + cin >> n; + cout << s << ' ' << s2 << '\n'; + for (int i = 0; i < n; i++) { + string t, t2; + cin >> t >> t2; + if (t == s) + s = t2; + else + s2 = t2; + cout << s << ' ' << s2 << '\n'; + } +} +int main() { + int n; + cin >> n; + string inp[6]; + for (int i = 0; i < n; i++) cin >> inp[i]; + string s1[6] = {"purple", "green", "blue", "orange", "red", "yellow"}; + string s2[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + cout << 6 - n << endl; + for (int i = 0; i < 6; i++) { + bool mark = true; + for (int j = 0; j < n; j++) + if (s1[i] == inp[j]) mark = false; + if (mark == true) cout << s2[i] << endl; + } + return 0; +} +int main() { + long long int a, b, ci, j, k, p, q; + cin >> a; + b = a + a / 2; + cout << b << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + int B = 0, C = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > 0) + B = B + a[i]; + else + C = C + a[i]; + } + cout << B - C << endl; +} +int main() { + long long int s, x, ans = 0; + cin >> s >> x; + if ((s - x) % 2 == 1 || s < x) + ans = 0; + else { + long long int xr = (s - x) / 2; + if (xr <= 0) ans = -2; + if ((xr & x) == 0) { + bitset<128> b(x); + long long int cnt = b.count(); + ans += pow(2, cnt); + } + } + if (ans < 0) assert(0); + cout << ans << "\n"; +} +int main() { + int max = 0, n, i, sum = 0, a[105], p; + cin >> n; + p = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum == n) { + cout << sum - 1 << endl; + return 0; + } + for (i = 0; i < n; i++) { + if (a[i] == 0) + p++; + else if (a[i] == 1 && p < 0) + p = 0; + else if (a[i] == 1 && p > 0) + p--; + if (max < p) max = p; + } + sum += max; + cout << sum << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int m = min(a, b); + cout << m << ' '; + a -= m; + b -= m; + cout << a / 2 + b / 2 << endl; + return 0; +} +int main() { + int m, n, t1, t2; + cin >> m >> n; + t1 = m % 2; + if (t1 != 0) + cout << ((m / 2) * n) + (n / 2) << endl; + else + cout << (m / 2) * n << endl; + return 0; +} +int main() { + int N, K, A = 0; + int c; + string S; + cin >> N >> K; + for (int i = 0; i < N; i += 1) { + cin >> S; + c = 0; + for (int j = 0; j < S.size(); j += 1) { + if (S[j] == '4' || S[j] == '7') { c++; } + } + if (c <= K) A++; + } + cout << A << '\n'; + return 0; +} +vector v[100005]; +void solve() { + long long n, x = 0, b, y, ans = 0; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) { + cin >> a[i]; + if (i == 0) { + v[x].push_back(a[i]); + continue; + } + if (a[i] <= a[i - 1]) x++; + v[x].push_back(a[i]); + } + if (x == 0) { + cout << v[0].size() << '\n'; + return; + } + for (long long i = 0; i < x + 1; i++) { + if (i == x) { + y = v[i].size() + 1; + } else { + long long n = v[i].size(); + long long m = v[i + 1].size(); + if (m == 1) { + y = n + 1; + } else if (n == 1) { + y = m + 1; + } else if (v[i + 1][1] - v[i][n - 1] > 1) { + y = n + m; + } else if (v[i + 1][0] - v[i][n - 2] > 1) { + y = n + m; + } else + y = n + 1; + } + ans = max(ans, y); + } + cout << ans << '\n'; + return; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +int a[105], maxx = -1, ans, n, d; +bool f = 0; +int main() { + cin >> n >> d; + for (int i = 1; i <= d; i++) { + f = 0; + for (int j = 1; j <= n; j++) { + char ch; + cin >> ch; + a[j] = ch - '0'; + if (a[j] == 0) f = 1; + } + if (f == 0) + maxx = max(maxx, ans), ans = 0; + else + ans++; + } + cout << max(maxx, ans) << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int count = 0; + while (n--) { + int d; + cin >> d; + if (d > b && d < c) { count++; } + } + cout << count << endl; +} +int num[101]; +int main() { + int n, k, i, sum = 0, flag = 1; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> num[i]; + int index = 0; + while (index < n && flag) { + if (num[index] <= k) + sum++, index++; + else { + flag = 0; + } + } + int last = n - 1; + flag = 1; + while (index <= last && flag) { + if (num[last] <= k) + sum++, last--; + else { + flag = 0; + } + } + cout << sum << endl; +} +int main() { + string l1, l2; + cin >> l1 >> l2; + for (size_t i = 0; i < l1.length(); i++) { + if (l1[i] == l2[i]) { + l1[i] = '0'; + } else { + l1[i] = '1'; + } + } + cout << l1 << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 0; j < m; j++) cout << "#"; + cout << endl; + } + if (i % 4 == 0) { + cout << "#"; + for (int j = 0; j < m - 1; j++) cout << "."; + cout << endl; + } + if (i % 2 == 0 && i % 4 != 0) { + for (int j = 0; j < m - 1; j++) cout << "."; + cout << "#" << endl; + } + } + } +} +int main() { + int s = 0, n, m; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + s = s + i * 4 * m; + } + cout << s << endl; + return 0; +} +int main() { + long long int t, s, a, b, c, h; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + h = s / c; + h += (h / a) * b; + cout << h << endl; + } + return 0; +} +int main() { + int n, aa[110], bb[110], na = 0, nb = 0, ab = 0; + cin >> n; + for (int a = 0; a < n; a++) { + cin >> aa[a]; + cin >> bb[a]; + na += aa[a]; + nb += bb[a]; + if ((aa[a] + bb[a]) % 2 == 1) ab = 1; + } + if (na % 2 == 0 && nb % 2 == 0) { + cout << 0 << endl; + } else if (na % 2 == 1 && nb % 2 == 1 && ab == 1) { + cout << 1 << endl; + } else + cout << -1 << endl; +} +long factorial(long A) { + long ans = 1; + for (int i = 1; i <= A; i++) ans *= i; + return ans; +} +int main() { + long A, B; + cin >> A >> B; + cout << factorial(min(A, B)) << "\n"; +} +char c[110][110]; +int n, l, r; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) c[i][j] = '*'; + l = r = n / 2 + 1; + int i = 1; + while (r <= n && l >= 1) { + for (int j = l; j <= r; ++j) c[i][j] = 'D'; + r++, l--, i++; + } + r -= 2, l += 2; + while (r >= l) { + for (int j = l; j <= r; ++j) c[i][j] = 'D'; + r--, l++, i++; + } + for (i = 1; i <= n; ++i) { + for (int j = 1; j <= n; ++j) cout << c[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int ans = 1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] != 1) { + int flag = 0; + for (int k = 0; k < n; k++) { + for (int l = 0; l < n; l++) { + if (!(k == i && l == j)) { + if (a[k][j] + a[i][l] == a[i][j]) { + flag = 1; + break; + } + } + } + } + if (flag == 0) { + ans = 0; + break; + } + } + } + if (ans == 0) { break; } + } + if (ans == 0) { + cout << "No\n"; + } else { + cout << "Yes\n"; + } + return 0; +} +int main() { + int ans = 0, n; + cin >> n; + char str[n][n + 1]; + for (int i = 0; i < n; i++) cin >> str[i]; + for (int i = 0; i < n; i++) { + int x = 0; + for (int j = 0; j < n; j++) { + if (str[i][j] == 'C') x++; + } + ans += (x * x - x) / 2; + } + for (int i = 0; i < n; i++) { + int x = 0; + for (int j = 0; j < n; j++) { + if (str[j][i] == 'C') x++; + } + ans += (x * x - x) / 2; + } + cout << ans << endl; +} +int main() { + long long n, t, a, temp = 1, i; + vector v; + cin >> n >> t; + for (i = 0; i < n - 1; i++) { + cin >> a; + v.push_back(a); + } + for (temp = 1; temp <= n; temp++) { + if (temp == t) { + cout << "YES" << endl; + return 0; + } + if (temp > t) break; + temp = temp + v[temp - 1]; + temp--; + } + cout << "NO" << endl; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + cout << (int)(ceil(ceil((double)n / s) * k / p)) << endl; + return 0; +} +int main() { + long long k, n, s, p, total, sheets, pack; + cin >> k >> n >> s >> p; + if (n >= s) { + if (n % s != 0) + sheets = n / s + 1; + else + sheets = n / s; + } else + sheets = 1; + total = sheets * k; + if ((total % p) == 0) + pack = total / p; + else + pack = total / p + 1; + cout << pack << endl; + return 0; +} +int main() { + double m, a, s; + double i, j; + while (cin >> m >> i >> j) { + a = i + j; + s = m / a; + cout << s * i << endl; + } + return 0; +} +int main() { + long long int amount; + cin >> amount; + int bills[] = {100, 20, 10, 5, 1}; + long long int count = 0; + int i = 0; + while (amount > 0) { + count += amount / bills[i]; + amount = amount % bills[i++]; + } + cout << count << endl; + return 0; +} +int main() { + int c = 1, j = 0; + char s[51], t[51]; + gets(s); + gets(t); + for (int i = 0; t[i]; i++) { + if (t[i] == s[j]) { + c++; + j++; + } + if (j == strlen(s) - 1) break; + } + cout << c << endl; + return 0; +} +int a[150]; +int main() { + int n, m, b, num, s = 0; + cin >> n >> b; + for (int i = 0; i < n; i++) { + cin >> m; + for (int j = 0; j < m; j++) { + cin >> num; + a[num]++; + if (a[num] == 1) s++; + } + } + if (s == b) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +bool mark1[30], mark2[30]; +int n; +char k; +string s; +bool ok = false; +int flag = 0; +int ans = 0; +void Do() { + if (ok) return; + int cnt2 = 0; + for (int i = 0; i <= 'z' - 'a'; ++i) + if (mark1[i]) ok = true, cnt2++, flag = i; + if (cnt2 > 1 || cnt2 == 0) ok = false; +} +int main() { + memset(mark1, true, sizeof mark1); + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> k >> s; + if (n == 0) break; + Do(); + if (k == 46) + if (!ok) + for (int i = 0; i < s.size(); ++i) mark1[s[i] - 'a'] = false; + if (k == 33) { + if (!ok) { + memset(mark2, false, sizeof mark2); + for (int i = 0; i < s.size(); ++i) mark2[s[i] - 'a'] = true; + for (int i = 0; i <= 'z' - 'a'; ++i) mark1[i] = mark1[i] && mark2[i]; + } + if (ok) ans++; + } + if (k == 63) { + if (ok && flag != s[0] - 'a') ans++; + if (n != 0) mark1[s[0] - 'a'] = false; + } + } + cout << ans << endl; + return 0; +} +int main() { + int A1, A2, A3; + cin >> A1 >> A2 >> A3; + int l = (int)sqrt(A1 * A2 / A3); + int b = (int)sqrt(A3 * A1 / A2); + int h = (int)sqrt(A3 * A2 / A1); + cout << 4 * (l + b + h) << "\n"; + return 0; +} +int main() { + char a[51][51]; + int i, j, n, m; + cin >> n >> m; + for (i = 0; i < n; i += 2) + for (j = 0; j < m; j++) a[i][j] = '#'; + for (i = 1; i < n - 1; i += 2) + for (j = 0; j < m; j++) { + if ((i + 1) % 4 != 0) { + if (j != m - 1) + a[i][j] = '.'; + else + a[i][j] = '#'; + } else { + if (j != 0) + a[i][j] = '.'; + else + a[i][j] = '#'; + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cout << a[i][j]; } + cout << endl; + } +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + int p1 = s * v1 + t1 * 2; + int p2 = s * v2 + t2 * 2; + if (p2 > p1) { + cout << "First" << endl; + } else if (p1 > p2) { + cout << "Second" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int t; + unsigned long long int s, a, b, c; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + cout << s / c + ((s / c) / a) * b << endl; + } +} +int main() { + string s, t; + cin >> s; + t = s; + reverse(s.begin(), s.end()); + int d = 0; + for (int i = 0; i < s.length() / 2; i++) + if (s[i] != t[i]) d++; + puts((d == 1 or d == 0 and s.length() % 2 != 0) ? "YES" : "NO"); + return 0; +} +long long n, m, i, a[100001], b[100001], q, ii; +int main() { + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +int main() { + map t; + t['a'] = 1; + t['e'] = 1; + t['i'] = 1; + t['o'] = 1; + t['u'] = 1; + t['1'] = 1; + t['3'] = 1; + t['5'] = 1; + t['7'] = 1; + t['9'] = 1; + int ans = 0; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { ans += t[s[i]]; } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + bool a = true; + char m[103][103]; + memset(m, '*', sizeof(m)); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> m[i][j]; } + } + int cont = 0; + for (int i = 1; i <= n && a; i++) { + for (int j = 1; j <= n; j++) { + if (m[i - 1][j] == 'o') cont++; + if (m[i + 1][j] == 'o') cont++; + if (m[i][j + 1] == 'o') cont++; + if (m[i][j - 1] == 'o') cont++; + if (cont % 2 != 0) a = false; + } + } + if (a) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long int MIN(long long int a, long long int b) { + if (a > b) + return b; + else + return a; +} +long long int MAX(long long int a, long long int b) { + if (a > b) + return a; + else + return b; +} +long long int MOD(long long int x) { + if (x >= 0) + return x; + else + return -x; +} +int main() { + long long int a, b, c; + cin >> a >> b >> c; + long long int sa = a + b + c; + cin >> a >> b >> c; + long long int sb = a + b + c; + long long int x = sa / 5; + long long int n; + cin >> n; + if (sa % 5 != 0) x++; + x += sb / 10; + if (sb % 10 != 0) x++; + if (x <= n) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a[100001], b[100001], count = 0, i, j, n; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (j = 0; j < n; j++) { + if (a[j] != b[j]) { + cout << "Happy Alex" << endl; + count = 1; + break; + } + } + if (count == 0) cout << "Poor Alex" << endl; + return 0; +} +int main() { + int x, tmp, step = 0, s[5] = {5, 4, 3, 2, 1}; + cin >> x; + for (int i = 0; i < 5; ++i) + if (x >= s[i]) { + step += (tmp = x / s[i]); + x -= tmp * s[i]; + } + cout << step << endl; + return 0; +} +int main() { + const int N = 3; + long x, y, z, m; + cin >> x >> y >> z >> m; + vector dim(N); + dim[0] = x; + dim[1] = y; + dim[2] = z; + sort(dim.begin(), dim.end()); + long a = m / 3; + if (a > dim[0] - 1) { a = dim[0] - 1; } + long b = (m - a) / 2; + if (b > dim[1] - 1) { b = dim[1] - 1; } + long c = (m - a - b) / 1; + if (c > dim[2] - 1) { c = dim[2] - 1; } + long long salida = (1LL + a) * (1LL + b) * (1LL + c); + cout << salida << endl; + return 0; +} +const int maxn = 10005; +int a[maxn]; +int main() { + memset(a, 0, sizeof(a)); + int n, m, d, b; + int flag = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> d; + for (int j = 1; j <= d; j++) { + cin >> b; + a[b] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { flag = 1; } + } + if (flag == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, a, b; + cin >> n >> a >> b; + char arr[n + 2]; + for (int i = 0; i < n; i++) cin >> arr[i]; + if (arr[a - 1] == arr[b - 1]) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int a, b, rta = 0, u1, v1, u2, v2; + cin >> a >> b; + cin >> u1 >> v1; + cin >> u2 >> v2; + rta = a; + while (b) { + rta += b; + if (b == v1) { rta = max(0, rta - u1); } + if (b == v2) { rta = max(0, rta - u2); } + b -= 1; + } + cout << rta << "\n"; +} +int main() { + int n, c = 0, d, count = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + c += i; + if (n >= c) count++; + n -= c; + } + cout << count << endl; + return 0; +} +int n, a[100005]; +bool ok; +int main() { + cin >> n; + ok = true; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + while (!(a[i] & 1)) a[i] >>= 1; + while (!(a[i] % 3)) a[i] /= 3; + if (a[i] != a[1]) ok = false; + } + cout << (ok ? "Yes\n" : "No\n"); +} +int a, x, temp, y; +int main() { + cin >> a; + int arr[a]; + for (x = 0; x < a; x++) { cin >> arr[x]; } + int g = 0; + while (g == 0) { + int highnum = 0; + int highid = -1; + for (y = 0; y < a; y++) { + if (arr[y] >= highnum) { + highnum = arr[y]; + highid = y; + } + } + if (highid != 0) { + arr[0]++; + arr[highid]--; + temp++; + } else + g = 1; + } + cout << temp << endl; + return 0; +} +int main() { + int n, a[105], temp, ans = 1, i, j; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + temp = 0; + for (j = 0; j <= i; j++) { + if (!a[j]) temp++; + } + for (j = i; j < n; j++) { + if (a[j]) temp++; + } + ans = max(ans, temp); + } + cout << ans << endl; + return 0; +} +int main() { + int n, i, counter = 6; + string a = ("Power\nTime\nSpace\nSoul\nReality\nMind\n"); + string b, c; + cin >> n; + for (i = 0; i < n; i++) { + cin >> b; + if (b == "purple") { + a.erase(a.rfind("Power"), 6); + counter--; + } else if (b == "green") { + a.erase(a.rfind("Time"), 5); + counter--; + } else if (b == "blue") { + a.erase(a.rfind("Space"), 6); + counter--; + } else if (b == "orange") { + a.erase(a.rfind("Soul"), 5); + counter--; + } else if (b == "red") { + a.erase(a.rfind("Reality"), 8); + counter--; + } else if (b == "yellow") { + a.erase(a.rfind("Mind"), 5); + counter--; + } + } + cout << counter << "\n" << a; + return 0; +} +int main() { + int n, m; + int arr[1000] = {0}; + cin >> n >> m; + for (int i = 0; i < m; i++) { + int temp; + cin >> temp; + arr[temp - 1]++; + } + int min = arr[0]; + for (int i = 1; i < n; i++) + if (arr[i] < min) min = arr[i]; + cout << min << endl; + return 0; +} +int main() { + int a, count = 0, c; + long long b; + char ch; + cin >> a >> b; + for (int i = 0; i < a; i++) { + cin >> ch >> c; + if (ch == '+') + b += c; + else if (ch == '-') { + if (c > b) + count++; + else + b -= c; + } + } + cout << b << " " << count << endl; +} +int main() { + int a, m, s = 0, t, i, b; + cin >> a; + for (i = 0; i < a; i++) { + cin >> b; + if (b % 2 == 0) { + m = i + 1; + s++; + } else { + t = i + 1; + } + } + if (s == 1) { + cout << m << endl; + } else { + cout << t << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int ans = 26; + ans += s.size() * 25; + cout << ans << endl; + return 0; +} +int main() { + long long int a, b, c, d, e, f; + string s; + while (cin >> a >> b) { + cin >> s; + for (c = 0; c < s.size(); c++) { + if (s[c] == 'G') { + d = c; + break; + } + } + f = 0; + for (e = d; e < s.size(); e += b) { + if (s[e] == '#') { + f = 0; + break; + } + if (s[e] == 'T') { + f = 1; + break; + } + } + if (f == 1) { + cout << "YES" << endl; + continue; + } else { + f = 0; + for (e = d; e >= 0; e -= b) { + if (s[e] == '#') { + f = 0; + break; + } + if (s[e] == 'T') { + f = 1; + break; + } + } + if (f == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + } + return 0; +} +const int maxn = 5005; +int main() { + int n, d, flag, ans = 0, res = 0; + string s[105]; + cin >> n >> d; + for (int i = 1; i <= d; i++) cin >> s[i]; + for (int i = 1; i <= d; i++) { + flag = 0; + for (int j = 0; j < s[i].size(); j++) + if (s[i][j] == '0') { + flag = 1; + break; + } + if (!flag) res = 0; + if (flag) res += 1; + ans = max(ans, res); + } + cout << ans << endl; + return 0; +} +int value[1001] = {0}; +char num[1001][1001]; +int main() { + int n, d, index = 0, sum = 1, max; + cin >> n >> d; + getchar(); + for (int i = 0; i < d; i++) { + for (int j = 0; j < n; j++) cin >> num[i][j]; + getchar(); + } + for (int i = 0; i < d; i++) { + for (int j = 0; j < n; j++) { + if (num[i][j] == '0') { + value[index++] = i; + break; + } + } + } + if (index == 0) { + max = 0; + } else { + max = 1; + for (int i = 1; i < index; i++) { + while (value[i] - value[i - 1] == 1) { + sum++; + i++; + } + max = sum > max ? sum : max; + sum = 1; + } + } + cout << max << endl; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + int m; + cin >> m; + vector vv(m); + for (int i = 0; i < m; i++) { cin >> vv[i]; } + vector ratios; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (vv[i] % v[j] == 0) { ratios.push_back(vv[i] / v[j]); } + } + } + int gear = 0; + sort(ratios.begin(), ratios.end()); + if (ratios.size() > 0) { + int MAX = ratios[ratios.size() - 1]; + for (int i = ratios.size() - 1; i >= 0; i--) { + if (ratios[i] == MAX) + gear++; + else + break; + } + } + cout << gear << endl; + return 0; +} +int main() { + long long int q; + cin >> q; + while (q--) { + long long int n; + string s; + cin >> n >> s; + long long int c = 0; + if (n >= 3) { + cout << "YES\n" << 2 << endl << s[0] << " "; + s.erase(0, 1); + cout << s << endl; + continue; + } + for (int i = 0; i < s.size(); i++) { c += (s[i] - 48); } + if (c - (s[0] - 48) <= c / 2) { + cout << "NO\n"; + continue; + } + cout << "YES\n" << 2 << endl << s[0] << " "; + s.erase(0, 1); + cout << s << endl; + } +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + int x = n - (a - c + b); + if (x < 1 || a < c || b < c || a > n || b > n || c > n) + cout << "-1\n"; + else + cout << x << endl; +} +int alpha[2][26]; +int main() { + char c; + while (cin >> c) { + if (c == '\n') break; + if (isalpha(c)) { + if (c >= 'a' && c <= 'z') + alpha[0][c - 'a']++; + else + alpha[1][c - 'A']++; + } + } + int out = alpha[1]['B' - 'A']; + if (alpha[0]['u' - 'a'] / 2 < out) out = alpha[0]['u' - 'a'] / 2; + if (alpha[0]['l' - 'a'] < out) out = alpha[0]['l' - 'a']; + if (alpha[0]['b' - 'a'] < out) out = alpha[0]['b' - 'a']; + if (alpha[0]['a' - 'a'] / 2 < out) out = alpha[0]['a' - 'a'] / 2; + if (alpha[0]['s' - 'a'] < out) out = alpha[0]['s' - 'a']; + if (alpha[0]['r' - 'a'] < out) out = alpha[0]['r' - 'a']; + cout << out << endl; + return 0; +} +int main() { + int t = 0; + cin >> t; + while (t--) { + int n = 0, x = 0, y = 0, d = 0; + cin >> n >> x >> y >> d; + if (abs(y - x) % d == 0) + cout << abs(y - x) / d << endl; + else if (abs(y - 1) % d == 0 && abs(y - n) % d != 0) { + int cnt = 0; + while (x > 1) { + cnt++; + x = x - d; + } + cout << (abs(y - 1) / d) + cnt << endl; + } else if (abs(y - n) % d == 0 && abs(y - 1) % d != 0) { + int cnt = 0; + while (x < n) { + cnt++; + x = x + d; + } + cout << (abs(y - n) / d) + cnt << endl; + } else if (abs(y - 1) % d == 0 && abs(y - 1) % d == 0) { + int cnt1 = 0, cnt2 = 0, x1 = x, x2 = x; + while (x1 > 1) { + cnt1++; + x1 = x1 - d; + } + while (x2 < n) { + cnt2++; + x2 = x2 + d; + } + cout << min((abs(y - n) / d) + cnt2, (abs(y - 1) / d) + cnt1) << endl; + } else + cout << -1 << endl; + } +} +int ans(0); +void doit(int a, int b) { + if (a < b) swap(a, b); + if (b == 0) return; + ans += a / b; + doit(b, a % b); +} +int main() { + int T, a, b; + cin >> T; + while (T--) { + cin >> a >> b; + ans = 0; + doit(a, b); + cout << ans << "\n"; + } + return 0; +} +int main() { + int n, x, a = 0, b = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + a |= x; + } + for (int j = 0; j <= n; j++) { + cin >> x; + b |= x; + } + cout << a + b << endl; + return 0; +} +void init(){}; +int a[1000]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long sum = 0; + for (int i = 1; i <= n; i++) sum += 4 * (i - 1) * a[i]; + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + char a[n][10]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + char b[6][10] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + int v[6] = {0}; + for (int i = 0; i < n; i++) { + if (a[i][0] == 'p') { + v[0] = 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (a[i][0] == 'g') { + v[1] = 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (a[i][0] == 'b') { + v[2] = 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (a[i][0] == 'o') { + v[3] = 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (a[i][0] == 'r') { + v[4] = 1; + break; + } + } + for (int i = 0; i < n; i++) { + if (a[i][0] == 'y') { + v[5] = 1; + break; + } + } + cout << (6 - n) << endl; + for (int i = 0; i < 6; i++) { + if (v[i] == 0) { cout << b[i] << endl; } + } +} +int main() { + int i, n, m = 0, c = 0, a, b; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b; + if (a > b) m++; + if (a < b) c++; + } + if (m > c) + cout << "Mishka" << endl; + else if (m < c) + cout << "Chris" << endl; + else if (m == c) + cout << "Friendship is magic!^^" << endl; + return 0; +} +const long long int MAXN = 1e5 + 10; +const long long int MINN = 1e5 + 10; +const long long int inf = 1e9 + 7; +int main() { + int m, a[MAXN], n, b[MAXN], c = 0; + cin >> m; + for (int i = 1; i <= (m); ++i) cin >> a[i]; + cin >> n; + for (int i = 1; i <= (n); ++i) cin >> b[i]; + sort(a + 1, a + m + 1); + sort(b + 1, b + n + 1); + int it = n; + while (it > 0) { + for (int i = 0; i < (a[1]); ++i) { + c += b[it]; + --it; + if (!it) { + cout << c << endl; + exit(0); + } + } + for (int i = 0; i < (2); ++i) { + --it; + if (!it) { + cout << c << endl; + exit(0); + } + } + } + return 0; +} +int a[128], h[128], n, x, y, r = 0; +int main() { + cin >> n; + for (int i = 0; i < 128; ++i) { a[i] = h[i] = 0; } + for (int i = 0; i < n; ++i) { + cin >> x >> y; + a[x]++; + h[y]++; + } + for (int i = 0; i < 128; ++i) { r += a[i] * h[i]; } + cout << r << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a = n / 36; + int b = (n - 36 * a) / 3; + int c = n - 36 * a - b * 3; + if (c == 2) b++; + if (b == 12) { + a++; + b = 0; + } + cout << a << " " << b << endl; + return 0; +} +const int mod = 1000003; +long long a = 1, n; +int main() { + cin >> n; + for (int i = 2; i <= n; i++) a = (a * 3) % mod; + cout << a << "\n"; +} +int main() { + string input; + getline(cin, input); + int output(0); + for (size_t length = input.size() - 1; length >= 1; length--) { + if (output > 0) { break; } + set present; + for (size_t start = 0; start < input.size() - length + 1; start++) { + string current = input.substr(start, length); + if (present.find(current) == present.end()) { + present.insert(current); + } else { + output = length; + break; + } + } + } + cout << output << endl; + return 0; +} +int main() { + int N; + cin >> N; + vector V; + string s; + for (int i = 0; i < N; i++) { + cin >> s; + V.push_back(s); + } + set SS; + for (int i = 0; i < N; i++) { + string s = V[i]; + set ch; + for (int j = 0; j < s.size(); j++) { ch.insert(s[j]); } + string cand = ""; + for (set::iterator it = ch.begin(); it != ch.end(); ++it) { cand += *it; } + SS.insert(cand); + } + cout << SS.size() << endl; + return 0; +} +int main() { + long long a, b, c, coun = 0; + cin >> a >> b >> c; + while (a > b) { + b *= c; + coun++; + } + cout << coun << endl; +} +int main() { + int n, k, a, res = 0, aux = 0; + vector v; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + while (a > 0) { + v.push_back(a % 10); + a /= 10; + } + for (int j = 0; j < v.size(); j++) { + if (v[j] == 4 || v[j] == 7) aux++; + } + if (aux <= k) res++; + v.clear(); + aux = 0; + } + cout << res << endl; + return 0; +} +int main() { + int m; + char s[99]; + cin >> s; + int n = strlen(s); + for (int i = 1; i <= n; i++) { + if (n % i == 0) { + m = 0; + for (int j = i; j < n; j++) { + if (s[j % i] != s[j]) m++; + } + if (m == 0) { + cout << i << endl; + break; + } + } + } + return 0; +} +long long n, ans = 0; +int main() { + cin >> n; + while (n % 3 == 0) n /= 3; + ans = n / 3 + 1; + cout << ans << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (n == 0) { + if (m == 0) + cout << 0 << " " << 0 << endl; + else + cout << "Impossible" << endl; + } else { + long long mn, mx, a, b, c, d; + if (m == 0) + mx = n; + else + mx = m + (n - 1); + mn = (n - 1); + m = m - (n - 1); + if (m > 0) + mn = mn + m; + else + mn = mn + 1; + cout << mn << " " << mx << endl; + } +} +int main() { + string a; + string b; + int c = 0; + cin >> a >> b; + for (int i = 0; i < b.size(); i++) { + if (a[c] == b[i]) { + c++; + if (c == a.size() - 1) { + cout << c + 1 << endl; + return 0; + } + } + } + cout << c + 1 << endl; +} +int main() { + string fi, la; + while (cin >> fi >> la) { + string n = "zzzzzzzzzz"; + string np; + int i, j; + for (i = 1; i <= fi.size(); ++i) + for (j = 1; j <= la.size(); ++j) { + np = fi.substr(0, i) + la.substr(0, j); + n = min(n, np); + } + cout << n << endl; + } +} +int main() { + int arr[3][3] = {0}; + int light[3][3] = {0}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> arr[i][j]; + light[i][j] = 1; + } + } + int R[] = {0, 0, 0, -1, 1}; + int C[] = {0, -1, 1, 0, 0}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (arr[i][j] % 2 != 0) { + for (int k = 0; k < 5; k++) { + int n_i = i + R[k]; + int n_j = j + C[k]; + if (n_i >= 0 && n_i < 3 && n_j >= 0 && n_j < 3) { + if (light[n_i][n_j]) + light[n_i][n_j] = 0; + else + light[n_i][n_j] = 1; + } + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << light[i][j]; } + cout << endl; + } +} +int main() { + cout << fixed << setprecision(15); + int n; + cin >> n; + vector a(n); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int m; + cin >> m; + int ans = -1; + for (int i = 0; i < m; i++) { + int l, r; + cin >> l >> r; + if (sum <= r) { + ans = max(l, sum); + break; + } + } + cout << ans << '\n'; + return 0; +} +int main() { + long long p1, p2, p3, p4, a, b, ans = 0; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + for (int i = a; i <= b; i++) + if (i % p1 == i && i % p2 == i && i % p3 == i && i % p4 == i) ans++; + cout << ans << endl; +} +long long n, k; +int main() { + cin >> n >> k; + long long d = n / 2 / (k + 1); + long long c = k * d; + long long r = n - d - c; + cout << d << ' ' << c << ' ' << r << endl; +} +int main() { + int t, i; + cin >> t; + for (i = 0; i < t; i++) { + long long int s, x, a, b, c, w, v, u; + cin >> s >> a >> b >> c; + w = s / c; + v = w / a; + u = v * b; + x = w + u; + cout << x << "\n"; + } + return 0; +} +long long Q_pow(long long a, long long b) { + long long ans = 1; + while (b > 0) { + if (b % 2 == 1) { + a %= 100; + ans %= 100; + ans *= a; + } + a %= 100; + a *= a; + b /= 2; + } + return ans % 100; +} +int main() { + long long n; + while (cin >> n) { cout << Q_pow(5, n) << endl; } +} +int main() { + int n, k; + cin >> n >> k; + int mn = numeric_limits::max(); + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + if (k % input == 0) mn = min(mn, k / input); + } + cout << mn << endl; + return 0; +} +int main() { + int n, a[1010]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + if (a[0] - 1 <= 0) { + cout << -1 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int i, j, k; + int n, m, p; + cin >> n; + for (i = 1, j = 1; i <= n, j <= n; i++, j += 2) { + k = (n - j) / 2; + p = k; + while (k--) cout << "*"; + m = j; + while (m--) cout << "D"; + while (p--) cout << "*"; + cout << endl; + } + for (i = 1, j = n - 2; i <= n, j >= 1; i++, j -= 2) { + k = (n - j) / 2; + p = k; + while (k--) cout << "*"; + m = j; + while (m--) cout << "D"; + while (p--) cout << "*"; + cout << endl; + } + return 0; +} +long long c, d, e, w, n, k, s; +double a, b; +long long p[301]; +int main() { + cin >> n; + c++; + for (int i = 1; i <= n; i++) { + d = (n - c) / 2; + k = 0; + w = 0; + e = 0; + for (int j = 1; j <= n; j++) { + if (w < d) + cout << "*", w++; + else if (w == d && e < c) + cout << "D", e++; + else + cout << "*"; + if (c == e) k == 1; + } + if (c < n && s == 0) + c += 2; + else + c -= 2; + if (c == n) s++; + cout << endl; + } +} +int main() { + int a; + cin >> a; + char b[a + 1][a + 1]; + int c = 0, d = 0; + for (int i = 0; i < a; i++) { + for (int j = 0; j < a; j++) { cin >> b[i][j]; } + } + for (int i = 0; i < a; i++) { + for (int j = 0; j < a; j++) { + for (int u = j + 1; u < a; u++) { + if (b[i][j] == 'C' && b[i][u] == 'C') { c++; } + } + } + d += c; + c = 0; + } + for (int i = 0; i < a; i++) { + for (int j = 0; j < a; j++) { + for (int u = j + 1; u < a; u++) { + if (b[j][i] == 'C' && b[u][i] == 'C') { c++; } + } + } + d += c; + c = 0; + } + cout << d << endl; +} +int main() { + int n; + cin >> n; + string direcciones; + cin >> direcciones; + vector posiciones(n); + for (int i = 0; i < n; i++) { cin >> posiciones[i]; } + bool hayColision = false; + for (int i = 1; i < n; i++) { + char dir1 = direcciones[i - 1]; + char dir2 = direcciones[i]; + if (dir1 == 'R' && dir2 == 'L') { + hayColision = true; + break; + } + } + if (hayColision) { + int ans = INT_MAX; + for (int i = 1; i < n; i++) { + char dir1 = direcciones[i - 1]; + char dir2 = direcciones[i]; + if (dir1 == 'R' && dir2 == 'L') { + int dist = posiciones[i] - posiciones[i - 1]; + ans = min(ans, dist / 2); + } + } + cout << ans << "\n"; + } else { + cout << "-1\n"; + } +} +int main() { + int n, i, j, p = 0; + cin >> n; + int s = (n - 1) / 2; + while (s) { + p++; + for (i = 1; i <= s; i++) cout << "*"; + for (i = 1; i <= 2 * (p - 1) + 1; i++) cout << "D"; + for (i = 1; i <= s; i++) cout << "*"; + s--; + cout << endl; + } + for (i = 1; i <= n; i++) { cout << "D"; } + s = 1; + cout << endl; + while (s <= (n - 1) / 2) { + for (i = 1; i <= s; i++) cout << "*"; + for (i = 1; i <= p * 2 - 1; i++) cout << "D"; + for (i = 1; i <= s; i++) cout << "*"; + cout << "\n"; + s++; + p--; + } + return 0; +} +int n; +int main() { + cin >> n; + for (int i = -1 * (n / 2); i <= n / 2; i++) { + for (int j = -1 * (n / 2); j <= n / 2; j++) { + if (abs(i) + abs(j) > n / 2) { + cout << "*"; + } else { + cout << "D"; + } + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + n--; + int a, b, mn; + cin >> a >> b; + mn = b; + long long kount = a * b; + while (n--) { + int c, d; + cin >> c >> d; + if (d < mn) mn = d; + kount += c * mn; + } + cout << kount << endl; +} +const int maxn = 3e4 + 7; +int num[maxn]; +int main() { + int n, t; + while (cin >> n >> t) { + for (int i = 1; i <= n - 1; i++) { cin >> num[i]; } + int start = 1; + while (true) { + start += num[start]; + if (start == t) { + puts("YES"); + break; + } else if (start > t) { + puts("NO"); + break; + } + } + } + return 0; +} +int main() { + int l, r, a, b, d, i, n; + cin >> n; + cout << ((n == 2) ? 2 : 1) << "\n"; + return 0; +} +int a, b, ansx, ansy, n, ans; +bool x[120], y[120]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (!x[a]) x[a] = 1, ansx++; + if (!y[b]) y[b] = 1, ansy++; + } + ans = min(ansx, ansy); + cout << ans << endl; +} +int main() { + int i, j, n; + int p[200000], b[200000], status[200000] = {0}; + int count = 0, result = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p[i]; + p[i]--; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + if (b[i] == 1) count++; + } + if (count % 2 == 0) result++; + count = 0; + for (i = 0; i < n; i++) { + if (status[i] == 0) { + status[i] = 1; + int t = p[i]; + while (t != i) { + status[t] = 1; + t = p[t]; + } + count++; + } + } + if (count > 1) result += count; + cout << result << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector a(n); + for (long long i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + long long choice = (n - 2) / 2; + long long ans = 1e15; + for (long long i = 0; i <= choice; i++) { + long long pre = a[i]; + long long suf = a[n - 1 - (choice - i)]; + ans = min(ans, suf - pre); + } + cout << ans << endl; + return 0; +} +int main() { + int b[105]; + memset(b, 0, sizeof(b)); + int n, ans = 0, k, a[105]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] <= k) + ans++, b[i] = 1; + else + break; + } + for (int j = n - 1; j > 0; j--) { + if (a[j] <= k && b[j] == 0) + ans++; + else + break; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector marks(n); + for (int i = 0; i < n; ++i) { cin >> marks[i]; } + vector suc(n, false); + for (int sub = 0; sub < m; ++sub) { + char best = '0'; + for (int i = 0; i < n; ++i) + if (marks[i][sub] > best) best = marks[i][sub]; + for (int i = 0; i < n; ++i) + if (marks[i][sub] == best) suc[i] = true; + } + cout << count(suc.begin(), suc.end(), true) << endl; + return 0; +} +int main() { + int n, agua, toalha = 0; + cin >> n >> agua >> toalha; + int nrod, tagua, ttoalha = 0; + nrod = n - 1; + tagua = nrod + nrod * agua * 2; + ttoalha = toalha * n; + cout << tagua << " " << ttoalha << endl; + return 0; +} +int main() { + long long n, dp[101][4], ans = 0; + vector a(101); + cin >> n; + for (long long i = 1; i <= n; i++) cin >> a[i]; + memset(dp, 0, sizeof dp); + for (long long i = 1; i <= n; i++) { + if (a[i] == 1 || a[i] == 3) { + long long x = max(dp[i - 1][1] + 1, dp[i - 1][2] + 1); + dp[i][3] = max(x, dp[i - 1][3]); + } + if (a[i] == 3 || a[i] == 2) { + long long x = max(dp[i - 1][1] + 1, dp[i - 1][3] + 1); + dp[i][2] = max(x, dp[i - 1][2]); + } + if (a[i] != 3) { + long long x = max(dp[i - 1][3], dp[i - 1][2]); + dp[i][1] = max(x, dp[i - 1][1]); + } + } + ans = max(dp[n][1], dp[n][2]); + ans = max(ans, dp[n][3]); + cout << n - ans << "\n"; +} +int n; +int l, r, u, d; +int main() { + cin >> n; + int c1 = 0, c2 = 0, c3 = 0; + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + if (s == "UL" || s == "DR") + ++c1; + else if (s == "UR" || s == "DL") + ++c2; + else + ++c3; + } + cout << (long long)(1 + c1 + c3) * (1 + c2 + c3) << endl; +} +int size_n; +int result = 0; +vector letter(25, 'F'); +vector used(25); +int main() { + int ii, jj; + int len; + string str; + cin >> size_n; + for (ii = 0; ii < size_n; ii++) { + cin >> str; + for (jj = 0, len = str.size(); (jj < len) && (used[jj] != 2); jj++) { + if (used[jj] == 0) { + used[jj] = 1; + letter[jj] = str[jj]; + } else if (str[jj] != letter[jj]) { + used[jj] = 2; + break; + } + } + } + for (ii = 0; (ii < 20) && (used[ii] != 2); ii++) result++; + cout << result << endl; + return 0; +} +int main() { + int n, a[1069], b[1069], pertama, kedua, jumlah = 0; + string x, y; + cin >> n >> x >> y; + for (int i = 0; i < n; i++) { + a[i] = x[i] - 48; + b[i] = y[i] - 48; + } + for (int i = 0; i < n; i++) { + pertama = abs(a[i] - b[i]); + kedua = 10 - max(a[i], b[i]) + min(a[i], b[i]); + if (pertama > kedua) + jumlah += kedua; + else + jumlah += pertama; + } + cout << jumlah << endl; +} +int main() { + long long n, x, y, k, c = 0, f = 0, g = 0; + cin >> n >> x >> y >> k; + long long a[k + 5]; + for (long long i = 0; i < k; i++) { + cin >> a[i]; + if (a[i] > x && a[i] < y) c++; + } + cout << c << endl; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +int main() { + map hash; + hash['0'] = "O-|-OOOO"; + hash['1'] = "O-|O-OOO"; + hash['2'] = "O-|OO-OO"; + hash['3'] = "O-|OOO-O"; + hash['4'] = "O-|OOOO-"; + hash['5'] = "-O|-OOOO"; + hash['6'] = "-O|O-OOO"; + hash['7'] = "-O|OO-OO"; + hash['8'] = "-O|OOO-O"; + hash['9'] = "-O|OOOO-"; + string input; + cin >> input; + for (int i = input.size() - 1; i >= 0; i--) { cout << hash[input[i]] << endl; } +} +int main() { + char a, b, c, d; + cin >> a >> b; + for (int i = 0; i < 5; i++) { + cin >> c >> d; + if (a == c || b == d) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + map fq; + for (int i = k - 1; i < n; i++) fq[v[i]]++; + if (fq.size() > 1) + cout << -1 << endl; + else { + int candidate = fq.begin()->first; + int ans = k - 1; + for (int i = k - 2; i >= 0; i--) + if (v[i] != candidate) + break; + else + ans--; + cout << ans << endl; + } +} +int main() { + int n; + long long k, f, t, maxi; + while (cin >> n >> k) { + maxi = -1000000000; + while (n--) { + cin >> f >> t; + if (f > maxi) { + if (t <= k) + maxi = f; + else if (maxi < (f + k - t)) + maxi = f + k - t; + } + } + cout << maxi << endl; + } + return 0; +} +int main() { + int arr[500][500]; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cin >> arr[i][j]; } + } + for (int i = 1; i <= n; i++) { + if (arr[i][1] || arr[i][m]) { + cout << 2 << endl; + return 0; + } + } + for (int i = 1; i <= m; i++) { + if (arr[1][i] || arr[n][i]) { + cout << 2 << endl; + return 0; + } + } + cout << 4 << endl; + return 0; +} +const int inf = (1ll << 31) - 1; +int get(int a, int b) { + if (a == 0) return 0; + return get(b % a, a) + b / a; +} +void solve() { + int a, b; + cin >> a >> b; + if (a > b) swap(a, b); + cout << get(a, b) << endl; +} +int main() { + int n; + cin >> n; + while (n--) solve(); + return 0; +} +int s[105][105]; +int main() { + int t, x1, x2, y1, y2, mx, my, ix, iy, i, j, sum; + sum = 0; + cin >> t; + mx = my = 0; + ix = iy = 1000; + memset(s, 0, sizeof(s)); + while (t--) { + cin >> x1 >> y1 >> x2 >> y2; + if (x1 < ix) ix = x1; + if (x2 > mx) mx = x2; + if (y1 < iy) iy = y1; + if (y2 > my) my = y2; + for (i = y1; i <= y2; i++) { + for (j = x1; j <= x2; j++) s[i][j]++; + } + } + for (i = iy; i <= my; i++) + for (j = ix; j <= mx; j++) sum += s[i][j]; + cout << sum << endl; + return 0; +} +int main() { + int n, ans = 0; + map a; + cin >> n; + for (int i = 0; i < n; i++) { + string mid; + cin >> mid; + a[mid]++; + } + for (int i = 0; i < n; i++) { + string mid; + cin >> mid; + if (a[mid] != 0) { + ans++; + a[mid]--; + } + } + cout << n - ans << endl; + return 0; +} +const int inf = 1e9 + 7; +const int mod = 998244353; +int x; +int hh, mm; +bool judge(int t) { + int total = hh * 60 + mm - x * t; + total = (total + 24 * 60 * 10) % (24 * 60); + int h = total / 60; + int m = total % 60; + int num = 0; + while (h) { + int tmp = h % 10; + h = h / 10; + if (tmp == 7) num++; + } + while (m) { + int tmp = m % 10; + m = m / 10; + if (tmp == 7) num++; + } + return num ? 1 : 0; +} +int main() { + cin >> x; + cin >> hh >> mm; + for (int i = 0;; i++) { + if (judge(i)) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector a(n); + for (int i = 0; i < m; i++) { + int x; + cin >> x; + x--; + a[x]++; + } + int ans = 1 << 30; + for (int i = 0; i < n; i++) { ans = min(ans, a[i]); } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << ceil(log2(n + 1)) << "\n"; + return 0; +} +int main() { + int k, a[13]; + cin >> k; + for (int i = 1; i <= 12; i++) { cin >> a[i]; } + sort(a + 1, a + 13); + int t = 0, c = 0; + if (t >= k) { + cout << c << endl; + return 0; + } + for (int i = 12; i >= 1; i--) { + c++; + t += a[i]; + if (t >= k) { + cout << c << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int staus[2][101], result; +int temp1 = 0, temp2 = 0; +char ori[101]; +string str; +int main() { + cin >> ori; + for (int i = 0; i < strlen(ori); i++) { + if (ori[i] == 'Q' || ori[i] == 'A') str += ori[i]; + } + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'Q') + staus[0][temp1++] = i; + else + staus[1][temp2++] = i; + } + for (int i = 0; i < temp1; i++) { + for (int j = 0; j < temp2; j++) { + if (staus[0][i] > staus[1][j]) continue; + for (int d = i + 1; d < temp1; d++) { + if (staus[0][d] < staus[1][j]) continue; + result++; + } + } + } + cout << result << endl; + return 0; +} +set s; +int main() { + int n, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x) s.insert(x); + } + cout << s.size() << endl; +} +const int maxn = 105; +int a[maxn][maxn]; +int vis[maxn][maxn]; +int q[maxn]; +int main() { + memset(a, 0, sizeof a); + int n, m; + int u, v; + int ans = 100000000; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> q[i]; + for (int i = 0; i < m; i++) { + cin >> u >> v; + a[u][v] = 1; + a[v][u] = 1; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j]) { + for (int k = 1; k <= n; k++) { + if (a[j][k] && a[i][k] && k != j && k != i) ans = min(ans, q[i] + q[j] + q[k]); + } + } + } + } + if (ans != 100000000) + cout << ans << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int n, num; + int a[105]; + while (cin >> n) { + num = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) num++; + } + for (int i = 0; i < n - 2; i++) { + if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1) num++; + } + cout << num << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[105], b[105], c[105]; + int d, e; + cin >> d; + for (int i = 0; i < d; i++) { cin >> a[i]; } + cin >> e; + for (int i = 0; i < e; i++) { cin >> b[i]; } + memset(c, 0, sizeof(c)); + for (int i = 1; i <= n; i++) { + for (int j = 0; j < d; j++) { + if (a[j] == i) { c[i]++; } + } + } + for (int i = 1; i <= n; i++) { + for (int j = 0; j < e; j++) { + if (b[j] == i) { c[i]++; } + } + } + for (int i = 1; i <= n; i++) { + if (c[i] == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } + } + cout << "I become the guy." << endl; + } + return 0; +} +int n, k; +char s[999]; +int ans[28]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> s[i], ans[s[i] - 'a']++; + if (ans[s[i] - 'a'] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, min1, max1, min2, max2, min3, max3; + cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; + int a = min1, b = min2, c = min3, t = min1 + min2 + min3; + while (t < n) { + if (a < max1) { + a++; + } else if (b < max2) { + b++; + } else if (c < max3) { + c++; + } + t++; + } + cout << a << " " << b << " " << c << endl; + return 0; +} +int main() { + long long mn; + int a, b; + cin >> a >> b; + if (a == 0 && b == 0) { + cout << 0 << ' ' << 0 << endl; + return 0; + } + if (a == 0) { + cout << "Impossible" << endl; + ; + return 0; + } + if (b == 0) { + cout << a << ' ' << a << endl; + return 0; + } + long long mx; + if (b >= a) { + mn = a + (b - a); + } else { + mn = a; + } + mx = a + (b - 1); + cout << mn << ' ' << mx << endl; + return 0; +} +int n, k, x, data[105]; +int main() { + cin >> n; + for (int i = 1; i <= n / 2; i++) { cin >> data[i]; } + sort(data + 1, data + 1 + n / 2); + int sum = 0; + for (int i = 1; i <= n / 2; i++) { sum += abs(data[i] - 2 * i); } + int ans = sum; + sum = 0; + for (int i = 1; i <= n / 2; i++) { sum += abs(data[i] - 2 * i + 1); } + ans = min(ans, sum); + cout << ans << endl; + return 0; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int bottles = 0, towels = n * p; + while (n > 1) { + int matches = (1 << (int)log2(n)) / 2; + bottles += matches * (2 * b + 1); + n -= matches; + } + cout << bottles << " " << towels << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + string result; + result += s1[0]; + for (int x = 1; x < s1.length(); x++) { + if (s1[x] < s2[0]) + result += s1[x]; + else + break; + } + result += s2[0]; + cout << result << endl; + return 0; +} +int main() { + puts("Karen"); +} +int main() { + int n; + cin >> n; + int *log; + log = new int[n]; + for (int i = 0; i < n; i++) { cin >> log[i]; } + sort(log + 1, log + n); + int k = 0; + while (1) { + if (log[0] > log[n - 1]) + break; + else { + log[0]++; + log[n - 1]--; + k++; + } + sort(log + 1, log + n); + } + cout << k << endl; + return 0; +} +int main() { + int p1, p2, p3, p4, a, b, cnt = 0, x; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + for (int i = a; i <= b; i++) { + x = (((i % p1) % p2) % p3) % p4; + if (x == i) { cnt++; } + } + cout << cnt << "\n"; + return 0; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + gcd(b, a % b); +} +int main() { + string s; + while (cin >> s) { + int l = s.length(); + int num = 1, cnt = 0; + for (int i = 0; i < l; i++) { + int a = s[i] - 'a' + 1; + if (a > num) { + int p1 = a - num; + int p2 = 26 - a + num; + cnt += min(p1, p2); + } else { + int p1 = num - a; + int p2 = 26 - num + a; + cnt += min(p1, p2); + } + num = a; + } + cout << cnt << endl; + } +} +int istrue(int n, int m) { + int k = n + 1; + while (true) { + if (k % 2 == 0) + k++; + else { + bool flag = false; + for (int i = 2; i < k; i++) { + if (k % i == 0) { flag = true; } + } + if (flag) + k++; + else { + return k; + break; + } + } + } +} +int main() { + int n, m; + cin >> n >> m; + if (istrue(n, m) == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k, answer = 10000000, temp; + cin >> n >> k; + while (n--) { + cin >> temp; + if (k % temp == 0) answer = min(answer, k / temp); + } + cout << answer << endl; + return 0; +} +const int maxn = 1e6 + 10, maxm = 2e6 + 10; +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double PI = acos(-1.0); +int casn, n, m, k; +int num[maxn]; +int main() { + cin >> n; + int a, b; + for (int i = 1; i <= n; ++i) { + if (i * i > n) break; + if (n % i == 0) { a = i, b = n / i; } + } + cout << a << ' ' << b << '\n'; + return 0; +} +int main() { + string str; + cin >> str; + int ans = str.size(); + ans = (str.size() + 1) * 26 - str.size(); + cout << ans << endl; + return 0; +} +string s; +int ans; +int main() { + cin >> s; + for (int l = 1; l <= s.size(); l++) { + vector v; + for (int i = 0; i + l - 1 < s.size(); i++) v.push_back(s.substr(i, l)); + sort(v.begin(), v.end()); + for (int i = 0; i < v.size() - 1; i++) + if (v[i] == v[i + 1]) { + ans = l; + break; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int i, n, k; + cin >> n >> k; + for (i = 1; i <= k; i++) { + if ((n % 10) != 0) { + n = n - 1; + } else { + n = n / 10; + } + } + cout << n << endl; + return 0; +} +int N; +int main() { + cin >> N; + if (N > 21) { + cout << '0' << endl; + return 0; + } + if (N == 21) { + cout << '4' << endl; + return 0; + } + if (N - 10 == 10) { + cout << "15" << endl; + return 0; + } + if (N < 20 && N > 10) { + cout << "4" << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + map mp; + mp["Tetrahedron"] = 4; + mp["Cube"] = 6; + mp["Octahedron"] = 8; + mp["Dodecahedron"] = 12; + mp["Icosahedron"] = 20; + int n; + cin >> n; + int sum = 0; + string str; + for (int i = 0; i < n; i++) { + cin >> str; + sum += mp[str]; + } + cout << sum << endl; + return 0; +} +int main() { + int winner, spectator; + int n; + while (cin >> n) { + bool flag = true; + spectator = 3; + for (int i = 0; i < n; i++) { + cin >> winner; + if (winner == spectator) + flag = false; + else { + int i = 1; + while (i == winner || i == spectator) i++; + spectator = i; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; +} +const long long mod = 1e9 + 7; +const int N = 1e6 + 5; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long pwr(long long x, long long y); +bool isprime(long long x); +long long a[N], b[N]; +vector v[N], vv[N]; +vector::iterator itr; +bool x[6][6]; +int main() { + long long n, ans, y, x, sum = 0; + string s1, s2; + cin >> x >> y; + ans = (abs(x) + abs(y)); + if (x > 0 && y > 0) { + cout << 0 << ' ' << ans << ' ' << ans << ' ' << 0 << endl; + } else if (x > 0 && y < 0) { + cout << 0 << ' ' << (-1 * ans) << ' ' << ans << ' ' << 0 << endl; + } else if (x < 0 && y > 0) { + cout << (-1 * ans) << ' ' << 0 << ' ' << 0 << ' ' << ans << endl; + } else { + ans *= -1; + cout << ans << ' ' << 0 << ' ' << 0 << ' ' << ans << endl; + } + return 0; +} +long long pwr(long long x, long long y) { + long long ans = 1; + x = x % mod; + while (y > 0) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y = y / 2; + } + return ans; +} +bool isprime(long long x) { + if (x < 2) return false; + if (x < 4) return true; + if (x % 2 == 0 || x % 3 == 0) return false; + for (long long i = 5; i * i <= x; i += 6) { + if (x % i == 0 || x % (i + 2) == 0) return false; + } + return true; +} +int main() { + long long n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + vector wt(100001 + 3, 0); + vector sums(100001 + 3, 0); + cin >> wt[1]; + sums[1] = wt[1]; + for (long long i = 2; i < n + 1; i++) { + cin >> wt[i]; + sums[i] = wt[i] + sums[i - 1]; + } + long long ans = LONG_MAX; + for (long long x = 0; x < n + 1; x++) { + long long curr = l * sums[x] + r * (sums[n] - sums[x]); + long long pen = 0; + if (x > n - x) { + pen = ql * (2 * x - n - 1); + } else if (x < n - x) { + pen = qr * (n - 2 * x - 1); + } + curr += pen; + ans = min(ans, curr); + } + cout << ans << '\n'; + return 0; +} +long long x, y, z; +int main() { + cin >> x >> y >> z; + cout << x * y + y * z + x * z - x - z - y + 1 << endl; + return 0; +} +bool now[30]; +char a[100010]; +bool b[30], mark[30]; +int main() { + int n; + cin >> n; + char c; + string s; + int cnt = 0; + int cnt3 = 0; + int ans = 0; + bool ho = 0; + for (int x = 1; x <= n; ++x) { + cin >> c >> s; + if (x == n) break; + int l = s.length(); + memset(now, 0, sizeof(now)); + int cnt2 = 0; + if (cnt3 == 25) cnt = 1; + if (c == '!') { + if (cnt == 1) { + ans++; + continue; + } + if (ho == 0) { + for (int i = 0; i < l; ++i) { + if (mark[s[i] - 'a'] == 0) { + a[++cnt] = s[i]; + mark[s[i] - 'a'] = 1; + } + } + for (int i = 1; i <= cnt; ++i) { + if (b[a[i] - 'a'] == 0) a[++cnt2] = a[i]; + } + ho = 1; + cnt = cnt2; + continue; + } + for (int i = 0; i < l; ++i) now[s[i] - 'a'] = 1; + for (int i = 1; i <= cnt; ++i) { + if (now[a[i] - 'a'] == 1 && b[a[i] - 'a'] == 0) { a[++cnt2] = a[i]; } + } + cnt = cnt2; + } else if (c == '.') { + if (cnt == 1) continue; + for (int i = 0; i < l; ++i) { + if (b[s[i] - 'a'] == 0) { + b[s[i] - 'a'] = 1; + cnt3++; + } + } + for (int i = 0; i < l; ++i) { now[s[i] - 'a'] = 1; } + for (int i = 1; i <= cnt; ++i) { + if (now[a[i] - 'a'] == 0) { a[++cnt2] = a[i]; } + } + cnt = cnt2; + } else { + if (cnt == 1) { + ans++; + continue; + } + if (b[s[0] - 'a'] == 0) cnt3++; + b[s[0] - 'a'] = 1; + for (int i = 1; i <= cnt; ++i) { + if (a[i] == s[0]) continue; + a[++cnt2] = a[i]; + } + cnt = cnt2; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, x; + int ans = 0, a; + cin >> n >> k >> x; + for (int i = 0; i < n - k; i++) cin >> a, ans += a; + ans += x * k; + cout << ans << endl; +} +int main() { + int n, i, arr[101], min = 999999, j, temp = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] < min) min = arr[i]; + } + for (i = min; i >= 1; i--) { + for (j = 0; j < n; j++) { + if (arr[j] % i == 0) temp++; + } + if (temp == n) { + cout << i * n << endl; + break; + } + temp = 0; + } +} +int u[1005], gov[1005]; +vector a[1005]; +int cnt; +void dfs(int x) { + cnt++; + u[x] = 1; + for (int i = 0; i < a[x].size(); i++) { + if (!u[a[x][i]]) dfs(a[x][i]); + } +} +int main() { + int n, m, k, i, x, y; + cin >> n >> m >> k; + memset(u, 0, sizeof(u)); + for (i = 0; i < k; i++) cin >> gov[i]; + for (i = 0; i < m; i++) { + cin >> x >> y; + a[x].push_back(y); + a[y].push_back(x); + } + int tot = 0, maxx = 0, ans = 0; + for (i = 0; i < k; i++) { + cnt = 0; + dfs(gov[i]); + tot += cnt; + maxx = max(maxx, cnt); + ans += cnt * (cnt - 1) / 2; + } + tot = n - tot + maxx; + ans += tot * (tot - 1) / 2 - (maxx * (maxx - 1) / 2); + cout << ans - m << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } + if ((i - 1) % 4 == 0) { + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << "#"; + cout << endl; + } + if ((i - 3) % 4 == 0) { + cout << "#"; + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << endl; + } + } +} +int main() { + int data, mbs, vid, ans; + cin >> data >> mbs >> vid; + ans = ((data - mbs) * vid + mbs - 1) / mbs; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a = n - m; + if (a < 0) a = -a; + if (a <= 1 && (n || m)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int sec[1010]; +int cnt[1010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> sec[i]; + sort(sec, sec + n); + int temp = sec[0]; + int cou = 0; + memset(cnt, 0, sizeof(cnt)); + for (int i = 0; i < n; i++) { + if (temp == 0) { + temp = sec[i + 1]; + continue; + } else { + if (temp == sec[i]) + cnt[cou]++; + else if (temp != sec[i]) { + temp = sec[i]; + cou++; + cnt[cou]++; + } + } + } + int flag = 0; + for (int i = 0; i < cou + 1; i++) { + if (cnt[i] > 2) { + flag = -1; + break; + } else if (cnt[i] == 2) + flag++; + } + if (flag == -1) + cout << -1 << endl; + else if (flag == 0) + cout << 0 << endl; + else + cout << flag << endl; + return 0; +} +int main() { + int n; + string s[100]; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + int ans = 0; + for (char a = 'a'; a <= 'z'; a++) { + int d = 0; + for (int i = 0; i < n; i++) { + int c = 1; + for (int j = 0; j < s[i].length(); j++) { + if (s[i][j] != a) { + c = 0; + break; + } + } + if (c) d += s[i].length(); + } + ans = max(ans, d); + for (char b = 'a'; b <= 'z'; b++) { + d = 0; + for (int i = 0; i < n; i++) { + int c = 1; + for (int j = 0; j < s[i].length(); j++) { + if (s[i][j] != a && s[i][j] != b) { + c = 0; + break; + } + } + if (c) d += s[i].length(); + } + ans = max(ans, d); + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (b) { + int d = b % 10; + c = c * 10 + d; + b /= 10; + } + cout << a + c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + for (int i = 0; i < m; i++) { + int l, r; + char c1, c2; + cin >> l >> r >> c1 >> c2; + l--; + r--; + for (int i = l; i <= r; i++) { + if (s[i] == c1) { s[i] = c2; } + } + } + cout << s << '\n'; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < m; i++) { + if (n % 10) + n -= 1; + else + n /= 10; + } + cout << n << endl; + return 0; +} +int main() { + string first, second; + cin >> first >> second; + if (first == second) + cout << first; + else + cout << '1'; + cout << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int a; + long long answer1 = 0, answer2 = 0; + for (int i = 0; i < n; i++) { + cin >> a; + answer1 |= a; + } + for (int i = 0; i < n; i++) { + cin >> a; + answer2 |= a; + } + cout << answer1 + answer2 << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b; + queue A, B; + for (long long i = 1; i <= b; i++) A.push(i * a); + for (long long i = 1; i <= a; i++) B.push(i * b); + c = d = 0; + while (!A.empty() && !B.empty()) { + if (A.front() == B.front()) { + A.pop(), B.pop(); + if (c > d) + d++; + else + c++; + } else if (A.front() < B.front()) { + A.pop(), c++; + } else { + B.pop(), d++; + } + } + c += A.size() * 1LL; + d += B.size() * 1LL; + if (c == d) + cout << "Equal" << '\n'; + else if (c > d) + cout << "Dasha" << '\n'; + else + cout << "Masha" << '\n'; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int x = max(((3 * a) / 10), a - ((a / 250) * c)); + int y = max(((3 * b) / 10), b - ((b / 250) * d)); + if (x > y) { + cout << "Misha" << endl; + } else if (x == y) { + cout << "Tie" << endl; + } else + cout << "Vasya" << endl; +} +const int M = 100 + 5; +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + long long t, a, b, k; + cin >> t; + while (t != 0) { + cin >> a >> b >> k; + if (k % 2 == 0) + cout << (a - b) * k / 2 << endl; + else + cout << ((a - b) * (k / 2)) + a << endl; + t--; + } + return 0; +} +int main() { + long long n, x, cnt = 0; + cin >> n >> x; + for (long long i = 0; i < n; i++) { + char s; + long long d; + cin >> s >> d; + if (s == '+') { + x += d; + } else { + if (x - d >= 0) + x -= d; + else + cnt++; + } + } + cout << x << " " << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] == 1) continue; + bool found = false; + for (int k = j - 1; k >= 0; k--) { + if (arr[i][k] >= arr[i][j]) continue; + int need = arr[i][j] - arr[i][k]; + for (int z = i - 1; z >= 0; z--) { + if (arr[z][j] == need) { + found = true; + break; + } + } + if (found) break; + for (int z = i + 1; z < n; z++) { + if (arr[z][j] == need) { + found = true; + break; + } + } + if (found) break; + } + if (found) continue; + for (int k = j + 1; k < n; k++) { + if (arr[i][k] >= arr[i][j]) continue; + int need = arr[i][j] - arr[i][k]; + for (int z = i - 1; z >= 0; z--) { + if (arr[z][j] == need) { + found = true; + break; + } + } + if (found) break; + for (int z = i + 1; z < n; z++) { + if (arr[z][j] == need) { + found = true; + break; + } + } + if (found) break; + } + if (!found) { + puts("No"); + return 0; + } + } + } + puts("Yes"); + return 0; +} +int main() { + int n; + cin >> n; + int i, a[1005]; + for (i = 0; i < n; i++) cin >> a[i]; + int k = a[0], k1 = a[0], c = 0; + for (i = 1; i < n; i++) { + if (a[i] > k) { + k = a[i]; + c++; + } + if (a[i] < k1) { + k1 = a[i]; + c++; + } + } + cout << c << endl; + ; + return 0; +} +long long n, k, ans = 0, i = 0, j = 0; +int main() { + int t = 1; + while (t--) { + long long n; + cin >> n; + long long sum = 0; + vector v(n + 1); + for (i = 1; i <= n; i++) { + long long a; + cin >> a; + v[i] = v[i - 1] + a; + sum += a; + } + long long ans = (long long)(ceil(1.0 * sum / 2)); + for (i = 1; i <= n; i++) { + if (v[i] >= ans) { + cout << i << "\n"; + break; + } + } + } +} +int main() { + int n = 0; + int validProblems = 0; + int p, v, t = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p >> v >> t; + int result = p + v + t; + if (result > 1) validProblems++; + } + cout << validProblems << endl; + return 0; +} +int a[105]; +int main() { + int n; + while (cin >> n) { + int st = 1; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = n; i >= 1; i--) { + if (a[i] == 0) + n--; + else + break; + } + for (int i = 1; i <= n; i++) { + if (a[i] == 1) { + st = i; + break; + } + } + int ans = n - st + 1, len = 0; + for (int i = st; i <= n; i++) { + if (a[i] == 1) { + if (len >= 2) { ans -= len; } + len = 0; + } else { + len++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int i, n; + string a[1000], b[1000]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + cin >> b[i]; + } + for (i = 0; i < n; i++) + if (b[i] == "rat") { cout << a[i] << "\n"; } + for (i = 0; i < n; i++) + if (b[i] == "child" || b[i] == "woman") { cout << a[i] << "\n"; } + for (i = 0; i < n; i++) + if (b[i] == "man") { cout << a[i] << "\n"; } + for (i = 0; i < n; i++) + if (b[i] == "captain") { cout << a[i] << "\n"; } + return 0; +} +long long a1, a2, n, k, second = 0, ans = 0, ans1; +vector>> h; +void read(void) { + cin >> n; + for (int i = 0, x, y, m; i < n; ++i) { + cin >> k; + second += k; + cin >> a1; + long long t = a1; + cin >> x >> y >> m; + h.push_back(make_pair(0, make_pair(a1, i + 1))); + ans1 = 0; + for (int j = 1; j < k; ++j) { + a2 = (a1 * x + y) % m; + if (a2 < a1) ans1++; + a1 = a2; + t = max(t, a1); + if (h.size() <= 200000) h.push_back(make_pair(ans1, make_pair(a1, i + 1))); + } + ans = max(ans, ans1); + } + sort(h.begin(), h.end()); + cout << ans << "\n"; + if (second <= 200000) + for (int i = 0; i < second; ++i) cout << h[i].second.first << " " << h[i].second.second << "\n"; +} +int main() { + read(); + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + if (tmp > b && tmp < c) ans++; + } + cout << ans << endl; + } + return 0; +} +int n, a, b; +int x[2005]; +int main() { + cin >> n >> a >> b; + for (int i = 0; i < n; i++) cin >> x[i]; + sort(x, x + n); + cout << x[b] - x[b - 1] << '\n'; +} +string s; +int main() { + int n, a, b; + cin >> n >> a >> b >> s; + if ((a == b) || (s[a - 1] == s[b - 1])) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n, a, b; + string s; + cin >> n >> a >> b; + --a, --b; + cin >> s; + if (s[a] == s[b]) { + cout << 0 << endl; + return 0; + } else { + cout << 1 << endl; + return 0; + } +} +long long w, h, u1, d1, u2, d2; +int main() { + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + for (long long i = h; i; i--) { + w += i; + if (i == d1) { w -= u1; } + if (i == d2) { w -= u2; } + if (w < 0) w = 0; + } + cout << w; + return cout << '\n', 0; +} +int main() { + int n; + cin >> n; + if (n < 6) { + if (n == 1) + cout << "Sheldon" << endl; + else if (n == 2) + cout << "Leonard" << endl; + else if (n == 3) + cout << "Penny" << endl; + else if (n == 4) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + } else { + while (n > 5) { n = (n - 4) / 2; } + if (n == 1) + cout << "Sheldon" << endl; + else if (n == 2) + cout << "Leonard" << endl; + else if (n == 3) + cout << "Penny" << endl; + else if (n == 4) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + } +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int mx = -1; + for (int i = n / a; i >= 0; --i) { + for (int j = n / b; j >= 0; --j) { + int x = n - (i * a + j * b); + if (x % c == 0 and x >= 0) { mx = max(mx, i + j + x / c); } + } + } + cout << mx << endl; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int n; +int x[205], y[205]; +int main() { + cin >> n; + int z = 0; + for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; + for (int i = 0; i < n; i++) { + int m = 0; + for (int j = 0; j < n; j++) { + if (x[j] > x[i] && y[j] == y[i]) m |= 1; + if (x[j] < x[i] && y[j] == y[i]) m |= 2; + if (y[j] > y[i] && x[j] == x[i]) m |= 4; + if (y[j] < y[i] && x[j] == x[i]) m |= 8; + } + if (m == 15) z++; + } + cout << z << '\n'; +} +int main() { + int n; + string s; + cin >> n >> s; + int ans = 0; + int cnt = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + cnt++; + } else { + cout << cnt; + cnt = 0; + } + } + cout << cnt << endl; + return 0; +} +const int inf = 1e9 + 5; +const int M = 1e5 + 5; +int main() { + char a[200]; + int s[200] = {0}; + cin >> a; + int n = strlen(a); + int ans = 0; + for (int i = 0; i < n - 1; i++) { + if (a[i] == 'V' && a[i + 1] == 'K') { + ans++; + s[i] = s[i + 1] = 1; + } + } + for (int i = 0; i < n - 1; i++) { + if (a[i] == 'V' && a[i + 1] == 'V' && !s[i] && !s[i + 1]) { + ans++; + break; + } else if (a[i] == 'K' && a[i + 1] == 'K' && !s[i] && !s[i + 1]) { + ans++; + break; + } + } + cout << ans << endl; + return 0; +} +const int mx5 = 1e5 + 5; +int arr[mx5]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + int gcd = 0; + for (int i = 1; i <= n; i++) { gcd = __gcd(gcd, arr[i]); } + for (int i = 1; i <= n; i++) { + int k = arr[i] / gcd; + while (k % 2 == 0) { k /= 2; } + while (k % 3 == 0) { k /= 3; } + if (k != 1) { + cout << "No" << endl; + return 0; + } + } + cout << "Yes" << endl; + return 0; +} +int main() { + int i, j, a = 0, b = 0, c = 0, d, e, f, n, m; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> m; + if (i % 3 == 1) { + a = a + m; + } else if (i % 3 == 2) { + b = b + m; + } else if (i % 3 == 0) { + c = c + m; + } + } + if (a >= b && a >= c) { cout << "chest" << endl; } + if (b >= a && b >= c) { cout << "biceps" << endl; } + if (c >= a && c >= b) { cout << "back" << endl; } + return 0; +} +const long long maxN = 1e6 + 5; +const long long inf = 1e10; +const long long mod = 1e9 + 7; +string s, t, a, b; +long long n; +int main() { + cin >> s >> t; + cin >> n; + cout << s << " " << t << endl; + while (n--) { + cin >> a >> b; + if (s == a) + s = b; + else + t = b; + cout << s << " " << t << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; ++i) { + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + for (int j = 1; j <= 2 * i - 1; ++j) cout << "D"; + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n / 2; ++i) { + for (int j = 1; j <= i; ++j) cout << "*"; + for (int j = 1; j <= n - i * 2; ++j) cout << "D"; + for (int j = 1; j <= i; ++j) cout << "*"; + cout << endl; + } + return 0; +} +int main() { + int num[4] = {0}; + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int tmp; + cin >> tmp; + num[tmp]++; + } + if (num[1] >= num[2] && num[1] >= num[3]) + cout << num[2] + num[3] << endl; + else if (num[2] >= num[1] && num[2] >= num[3]) + cout << num[1] + num[3] << endl; + else + cout << num[1] + num[2] << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + for (int i = 0; i < b; i++) { + if (a % 10 == 0) { + a = a / 10; + } else { + a = a - 1; + } + } + cout << a << endl; +} +long long x; +int ans = 0; +inline long long read() { + long long x = 0; + char c = getchar(); + bool flag = 0; + while (c < '0' || c > '9') { + if (c == '-') flag = 1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = (x + (x << 2) << 1) + c - '0'; + c = getchar(); + } + return flag ? -x : x; +} +int main() { + x = read(); + if (x % 2 != 0) { + ans++; + x--; + } + while (x > 0) { + int cnt = 1; + while (pow(2, cnt) < x) cnt++; + if (x == pow(2, cnt)) { + ans++; + break; + } + cnt--; + x -= pow(2, cnt); + ans++; + } + cout << ans << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int res = 0; + for (int i = 0; i <= n / a; i++) { + for (int j = 0; j <= n / b; j++) { + int k = n - i * a - j * b; + if (k >= 0 && k % c == 0) res = max(res, i + j + k / c); + } + } + cout << res << "\n"; +} +int main() { + long long n, a, b, c; + cin >> n >> a >> b >> c; + n = n % 4; + if (n == 0) { + cout << 0 << endl; + return 0; + } + n = 4 - n; + long long ans = LONG_LONG_MAX; + if (n == 1) { + ans = a; + ans = min(ans, b + c); + ans = min(ans, 3 * c); + cout << ans << endl; + } else if (n == 2) { + ans = b; + ans = min(ans, 2 * a); + ans = min(ans, 2 * c); + cout << ans << endl; + } else if (n == 3) { + ans = 3 * a; + ans = min(ans, a + b); + ans = min(ans, c); + cout << ans << endl; + } + return 0; +} +int n, ans; +bool u, l, r, lf; +pair p[201]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second; + for (int i = 0; i < n; i++) { + lf = false; + r = false; + u = false; + l = false; + for (int j = 0; j < n; j++) { + if (p[i].first == p[j].first) { + if (p[i].second > p[j].second) l = true; + if (p[i].second < p[j].second) u = true; + } + if (p[i].second == p[j].second) { + if (p[i].first > p[j].first) lf = true; + if (p[i].first < p[j].first) r = true; + } + } + if (lf == true && r == true && u == true && l == true) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, a[110]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + int count = 0, ans = 0; + bool flag = false; + for (int i = 0; i < n; i++) { + if (!flag && a[i] <= k) + count++; + else { + flag = true; + if (a[i] <= k) + ans++; + else + ans = 0; + } + } + cout << count + ans << endl; +} +int main() { + long long n, i, j, k; + cin >> n; + bool dp[n + 1]; + memset(dp, 0, sizeof(dp)); + dp[0] = 1; + dp[4] = 1; + dp[7] = 1; + for (i = 8; i <= n; i++) { + if (dp[i - 4] == 1) dp[i] = 1; + if (dp[i - 7] == 1) dp[i] = 1; + } + if (dp[n] == 0) + cout << "-1" << endl; + else { + vector v; + while (n > 0) { + if (n >= 7 && dp[n - 7] == 1) { + v.push_back(7); + n = n - 7; + } else if (n >= 4 && dp[n - 4] == 1) { + v.push_back(4); + n = n - 4; + } + } + sort(v.begin(), v.end()); + for (i = 0; i < v.size(); i++) cout << v[i]; + cout << endl; + } +} +char a[100005]; +int b[10]; +int main() { + cin >> a; + for (int i = 0; i < strlen(a); i++) { + if (a[i] == 'B') + b[0]++; + else if (a[i] == 'u') + b[1]++; + else if (a[i] == 'l') + b[2]++; + else if (a[i] == 'b') + b[3]++; + else if (a[i] == 'a') + b[4]++; + else if (a[i] == 's') + b[5]++; + else if (a[i] == 'r') + b[6]++; + } + b[4] /= 2, b[1] /= 2; + sort(b, b + 7); + cout << b[0] << endl; + return 0; +} +int main() { + int tc = 0, n; + for (cin >> n; tc < n; tc++) { + int a, b, ans = 0; + cin >> a >> b; + if (b < a) swap(a, b); + while (a != 0) { + ans += b / a; + b = b % a; + if (b < a) swap(a, b); + } + cout << ans << endl; + } +} +int main() { + int m, x, y; + int xx[1002]; + while (cin >> m) { + int b = 0; + for (int i = 0; i < m; i++) { + cin >> xx[i]; + b += xx[i]; + } + cin >> x >> y; + int a = 0; + int c = 0; + for (int i = 0; i < m; i++) { + if (a >= x && a <= y && b - a >= x && b - a <= y) { + c = i + 1; + break; + } + a += xx[i]; + } + cout << c << endl; + } + return 0; +} +const long long N = 1e3 + 7; +long long n, mx, sz; +string f, s, killed, added, k, d; +long long day; +int main() { + cin >> f >> s; + cin >> day; + cout << f << ' ' << s << "\n"; + for (long long i = 1; i <= day; i++) { + cin >> killed >> added; + if (f == killed) { + f = added; + } else + s = added; + cout << f << ' ' << s << "\n"; + } +} +int main() { + long long int n, a[1000], result; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + result = a[n - 1] - a[0] - n + 1; + cout << result << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int mxm = max(3 * a / 10, a - (a / 250) * c); + int mxv = max(3 * b / 10, b - (b / 250) * d); + if (mxm < mxv) + cout << "Vasya" << endl; + else if (mxm > mxv) + cout << "Misha" << endl; + else + cout << "Tie" << endl; +} +int main() { + int n, k; + cin >> n >> k; + int sum = 0; + if (n * 2 % k == 0) { + sum += n * 2 / k; + } else { + sum += n * 2 / k + 1; + } + if (n * 5 % k == 0) { + sum += n * 5 / k; + } else { + sum += n * 5 / k + 1; + } + if (n * 8 % k == 0) { + sum += n * 8 / k; + } else { + sum += n * 8 / k + 1; + } + cout << sum << endl; +} +int main() { + int n, k, b[105]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> b[i]; + sort(b, b + n); + for (int i = n - 1; i >= 0; i--) { + if (k % b[i] == 0) { + cout << k / b[i] << '\n'; + return 0; + } + } +} +const int maxn = 100; +char board[9][9]; +int Bstep = maxn; +int Wstep = maxn; +bool isboundary(int r) { + if (r == 1 || r == 8) return true; + return false; +} +void countstep(int r, int c, char colour) { + int step = (colour == 'W') ? -1 : 1; + int count = 1; + for (int i = r + step;; i += step) { + if (board[i][c] != '.') { + count = maxn; + break; + } + if (isboundary(i)) break; + count++; + } + if (colour == 'W') { + if (count < Wstep) Wstep = count; + } else { + if (count < Bstep) Bstep = count; + } +} +int main() { + for (int r = 1; r <= 8; r++) { + for (int c = 1; c <= 8; c++) { cin >> board[r][c]; } + } + for (int r = 1; r <= 8; r++) { + for (int c = 1; c <= 8; c++) { + if (board[r][c] != '.') { countstep(r, c, board[r][c]); } + } + } + char ans = (Wstep - 1 < Bstep) ? 'A' : 'B'; + cout << ans << endl; +} +int main() { + int i, j, m, a, s, d, c, b, n, x, p = 0, y, k = 0, an[1001], am[1001]; + cin >> n >> m; + for (i = 0; i < n; i++) { cin >> an[i]; } + for (j = 0; j < m; j++) { cin >> am[j]; } + for (i = 0, j = 0; i < n; i++) { + if (am[j] >= an[i]) { + k++; + j++; + } + } + if (k > m) + cout << m << endl; + else + cout << k << endl; + return 0; +} +int main() { + int k, a[100000][2], sum; + cin >> k; + cin >> a[0][0] >> a[0][1]; + sum = a[0][0] * a[0][1]; + for (int i = 1; i < k; i++) + for (int j = 0; j < 2; j++) { + cin >> a[i][j]; + if (j == 1) + if (a[i][1] > a[i - 1][1]) { + sum = sum + a[i - 1][1] * a[i][0]; + a[i][1] = a[i - 1][1]; + } else + sum = sum + a[i][0] * a[i][1]; + } + cout << sum << endl; + return 0; +} +char A, B; +char C[] = {'^', '>', 'v', '<', '^', '>', 'v'}; +char D[] = {'^', '<', 'v', '>', '^', '<', 'v'}; +int N; +int main() { + cin >> A >> B >> N; + if (A == '^') { + if (C[0 + (N % 4)] == D[0 + (N % 4)]) + cout << "undefined\n"; + else if (C[0 + (N % 4)] == B) + cout << "cw\n"; + else + cout << "ccw\n"; + } + if (A == '>') { + if (C[1 + (N % 4)] == D[3 + (N % 4)]) + cout << "undefined\n"; + else if (C[1 + (N % 4)] == B) + cout << "cw\n"; + else + cout << "ccw\n"; + } + if (A == 'v') { + if (C[2 + (N % 4)] == D[2 + (N % 4)]) + cout << "undefined\n"; + else if (C[2 + (N % 4)] == B) + cout << "cw\n"; + else + cout << "ccw\n"; + } + if (A == '<') { + if (C[3 + (N % 4)] == D[1 + (N % 4)]) + cout << "undefined\n"; + else if (C[3 + (N % 4)] == B) + cout << "cw\n"; + else + cout << "ccw\n"; + } +} +int main() { + int n, m, k; + int num[55]; + int ans = 0; + bool flag = true; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { cin >> num[i]; } + sort(num, num + n); + if (k >= m) { + cout << 0 << endl; + flag = false; + } else { + for (int i = n - 1; i >= 0; i--) { + m -= num[i]; + k--; + ans++; + if (k >= m) { + cout << ans << endl; + flag = false; + break; + } + } + } + if (flag) { cout << -1 << endl; } + return 0; +} +int main() { + int n, i, j, k; + int x[101], y[101]; + while (cin >> n) { + for (i = 0; i <= 100; i++) { x[i] = y[i] = 0; } + for (i = 0; i < n; i++) { + cin >> j >> k; + x[j]++; + y[k]++; + } + j = k = 0; + for (i = 0; i <= 100; i++) { + if (x[i]) j++; + if (y[i]) k++; + } + cout << (j < k ? j : k) << endl; + } + return 0; +} +const int mod = 1e9 + 7; +int main() { + int n; + cin >> n; + long long oddsum = 1, evensum = 1, ans = 0; + for (int i = 1; i <= n; ++i) { + if (i % 2) { + ans += evensum; + oddsum += evensum; + oddsum %= mod; + } else { + ans += oddsum; + evensum += oddsum; + evensum %= mod; + } + ans %= mod; + } + cout << ans << endl; +} +int main() { + int n, k, t, d, p = 0, o = 0; + cin >> n >> k >> t >> d; + if (t >= n) { + cout << "NO" << endl; + return 0; + } else { + if (n % t == 0) { + p = ((n / t) * k); + } else { + p = (((n / t) + 1) * k); + } + o = d + k; + if (o >= p) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, m, a; + cin >> n; + int c[n + 1], d[n + 1] = {0}; + vector g[n + 2]; + vector cc[5]; + for (int i = 0; i < n; i++) { + cin >> c[i]; + c[i]--; + cc[c[i]].push_back(i); + } + for (int i = 0; i < n; i++) { + cin >> m; + while (m--) { + cin >> a; + g[a - 1].push_back(i); + d[i]++; + } + } + int mx = INT_MAX; + for (int k = 0; k < n; k++) + if (d[k] == 0) { + int dp[n + 1]; + for (int i = 0; i < n; i++) dp[i] = d[i]; + int p = c[k], ok = 0, an = n; + while (1) { + if (ok == n) break; + for (int i = 0; i < cc[p].size(); i++) { + if (d[cc[p][i]] == 0) { + d[cc[p][i]]--; + ok++; + for (int j = 0; j < g[cc[p][i]].size(); j++) { + int u = g[cc[p][i]][j]; + d[u]--; + } + i = -1; + } + } + if (ok && ok < n) an++; + p = (p + 1) % 3; + } + for (int i = 0; i < n; i++) d[i] = dp[i]; + mx = min(mx, an); + } + cout << mx << endl; +} +string s, t; +vector v; +int main() { + cin >> s >> t; + string res1 = "", res2 = ""; + for (int i = 0; i < s.size(); i++) { + res1.push_back(s[i]); + res2 = ""; + for (int j = 0; j < t.size(); j++) { + res2.push_back(t[j]); + v.push_back(res1 + res2); + } + } + sort(v.begin(), v.end()); + cout << v[0] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans; + for (int i = 100; i >= 1; i--) { + bool flag = 0; + for (int j = 0; j < n; j++) { + if (a[j] % i == 0) + continue; + else { + flag = 1; + break; + } + } + if (flag == 0) { + cout << n * i << endl; + return 0; + } + } +} +int main() { + int t; + cin >> t; + long long n, x, y, d; + while (t-- > 0) { + cin >> n >> x >> y >> d; + long long arr[3] = {1000000000, 1000000000, 1000000000}; + if ((y - 1) % d == 0) { + arr[0] = ceil((x) / (d * 1.0)); + arr[0] += ceil((y - 1) / (d * 1.0)); + } + if ((n - y) % d == 0) { + arr[1] = ceil((n - x) / (d * 1.0)); + arr[1] += ceil((n - y) / (d * 1.0)); + } + int w = abs(x - y); + if (w % d == 0) { arr[2] = w / d; } + sort(arr, arr + 3); + if (arr[0] == 1000000000) + cout << -1 << endl; + else + cout << arr[0] << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= b; j++) { + if (i % 2 == 0) { + if ((i / 2) % 2 == 0) { + if (j == 1) { + cout << "#"; + } else { + cout << "."; + } + } else if ((i / 2) % 2 == 1) { + if (j == b) { + cout << "#"; + } else { + cout << "."; + } + } + } else { + cout << "#"; + } + } + cout << endl; + } +} +const int maxn = 1005; +int main() { + int n; + cin >> n; + int a[maxn]; + int b[maxn]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + int MAX = 0; + if (n == 1) + MAX = a[0] + b[0]; + else { + for (int i = 0; i < n; i++) { + int tmp1 = a[i], tmp2 = b[i]; + for (int j = i + 1; j < n; j++) { + tmp1 = (tmp1 | a[j]); + tmp2 = (tmp2 | b[j]); + if (tmp1 + tmp2 > MAX) MAX = tmp2 + tmp1; + } + } + } + cout << MAX << endl; + return 0; +} +int main() { + long long int n, a[100005]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int temp = 1, max1 = 1; + for (int j = 1; j < n; j++) { + if (a[j] >= a[j - 1]) + temp++; + else + temp = 1; + if (temp > max1) max1 = temp; + } + cout << max1 << endl; + return 0; +} +string S[10]; +bool check2(string s) { + for (int i = 0; i + 1 < s.length(); i++) + if (s[i] == s[i + 1]) return false; + return true; +} +bool check(string s) { + for (int i = 0; i < 8; i++) { + if (check2(s)) return true; + rotate(S, S + 1, S + 8); + } + return false; +} +int main() { + for (int i = 0; i < 8; i++) { + cin >> S[i]; + if (!check(S[i])) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, i, j, c, f = 0; + cin >> n; + char a[n + 5][n + 5]; + for (i = 0; i < n; i++) { + getchar(); + for (j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (i = 0; i < n; i++) { + c = 0; + for (j = 0; j < n; j++) { + if ((j + 1) < n) { + if (a[i][j + 1] == 'o') { c++; } + } + if ((j - 1) >= 0) { + if (a[i][j - 1] == 'o') { c++; } + } + if ((i + 1) < n) { + if (a[i + 1][j] == 'o') c++; + } + if ((i - 1) >= 0) { + if (a[i - 1][j] == 'o') { c++; } + } + if (c % 2 != 0) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +int main() { + int64_t n, d; + cin >> n >> d; + int ar[n]; + int x = 1; + for (int i = 1; i < n && i <= d; i++) { + cin >> ar[i]; + if (i == x) { + if (x == d) { + cout << "YES" << endl; + return 0; + } else + x += ar[i]; + if (x == d) { + cout << "YES" << endl; + return 0; + } + } + } + cout << "NO" << endl; + return 0; +} +int n; +int sum = 0; +int main() { + cin >> n; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "Tetrahedron") + sum += 4; + else if (s == "Cube") + sum += 6; + else if (s == "Octahedron") + sum += 8; + else if (s == "Dodecahedron") + sum += 12; + else if (s == "Icosahedron") + sum += 20; + } + cout << sum << endl; + return 0; +} +int main() { + int n, k, a[100], i, j, t; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0, j = n - 1, t = 0; i <= j;) { + if (i == j && a[i] <= k) { + t++; + break; + } else { + if (a[i] <= k) i++, t++; + if (a[j] <= k) j--, t++; + } + if (a[i] > k && a[j] > k) break; + } + cout << t << endl; + return 0; +} +int n, d; +bool mp[1000000]; +int main() { + cin >> n; + int a; + for (int i = 0; i < n - 1; i++) { + cin >> a; + mp[a] = true; + } + for (int i = 1; i <= n; i++) { + if (mp[i] == false) { cout << i << endl; } + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long m[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> m[i][j]; } + } + long long may = -9999999999; + long long prob = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { + if (m[i][1] > k) + prob = m[i][0] - (m[i][1] - k); + else + prob = m[i][0]; + if (may < prob) may = prob; + } + } + cout << may << endl; + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int sum = k * x; + while (n--) { + int m; + cin >> m; + if (n >= k) sum += m; + } + cout << sum << endl; + return 0; +} +int main() { + char a; + cin >> a; + string s, s1 = "qwertyuiopasdfghjkl;zxcvbnm,./", s2 = ""; + cin >> s; + if (a == 'R') { + for (int i = 0; i < s.length(); i++) { s2 += s1[s1.find(s[i]) - 1]; } + } else { + for (int i = 0; i < s.length(); i++) { s2 += s1[s1.find(s[i]) + 1]; } + } + cout << s2 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + priority_queue q; + for (int i = 0; i < n; i++) { + int w; + cin >> w; + q.push(w); + } + long long ans = 0; + while (!q.empty()) { + int w = q.top(); + q.pop(); + if (w > 2 * k) { + ans += w / (2 * k); + w = w % (2 * k); + } else if (w > k and w <= 2 * k) { + w = 0; + ans++; + } else { + if (!q.empty()) { + w = q.top(); + q.pop(); + } + w = max(w - k, 0); + ans++; + } + if (w > 0) { q.push(w); } + } + cout << ans << endl; + return 0; +} +int main() { + char s[12], s1[12], s2[12]; + long long n, i, j, len, m = INT_MIN, p, q; + cin >> s; + len = strlen(s); + n = atoi(s); + if (n > 0) { + cout << n << endl; + return 0; + } + for (i = 0; i < len - 1; i++) s1[i] = s[i]; + p = atoi(s1); + j = 0; + for (i = 0; i < len; i++) { + if (i == len - 2) continue; + s2[j] = s[i]; + j++; + } + q = atoi(s2); + m = max(p, q); + cout << m << endl; + return 0; +} +int main() { + int a, b, c, d, x, y, s = 0; + cin >> a >> b >> c >> d >> x >> y; + for (int i = x; i <= y; i++) + if (i % a == i && i % b == i && i % c == i && i % d == i) s++; + cout << s << endl; + return 0; +} +int a[10005]; +int b[10005]; +int num, sum; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] > b[i]) + num++; + else if (a[i] < b[i]) + sum++; + } + if (num > sum) + cout << "Mishka" << endl; + else if (num < sum) + cout << "Chris" << endl; + else if (num == sum) + cout << "Friendship is magic!^^" << endl; +} +int main() { + int n; + cin >> n; + map m1, m2; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + m1[s]++; + } + for (int i = 0; i < n; i++) { + string s; + cin >> s; + m2[s]++; + } + int ans = 0; + if (m1["M"] > m2["M"]) { ans += m1["M"] - m2["M"]; } + if (m1["S"] > m2["S"]) { ans += m1["S"] - m2["S"]; } + if (m1["L"] > m2["L"]) { ans += m1["L"] - m2["L"]; } + if (m1["XL"] > m2["XL"]) { ans += m1["XL"] - m2["XL"]; } + if (m1["XS"] > m2["XS"]) { ans += m1["XS"] - m2["XS"]; } + if (m1["XXL"] > m2["XXL"]) { ans += m1["XXL"] - m2["XXL"]; } + if (m1["XXS"] > m2["XXS"]) { ans += m1["XXS"] - m2["XXS"]; } + if (m1["XXXL"] > m2["XXXL"]) { ans += m1["XXXL"] - m2["XXXL"]; } + if (m1["XXXS"] > m2["XXXS"]) { ans += m1["XXXS"] - m2["XXXS"]; } + cout << ans << endl; +} +int main() { + int n, count = 0; + cin >> n; + int h[101] = {}, a[101] = {}; + for (int i = 0; i < n; i++) { cin >> h[i] >> a[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (h[i] == a[j]) count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int p = 0; + for (int a = 0; a < 1000; a++) { + for (int b = 0; b < 1000; b++) { + if (a * a + b == n && a + b * b == m) { p++; } + } + } + cout << p << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x, y, l = 0, r = 0; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > 0) + r++; + else + l++; + } + if (r == 1 || l == 1 || r == 0 || l == 0) + cout << "Yes\n"; + else + cout << "No\n"; +} +long long int n, flag = 0; +int main() { + cin >> n; + while (n) { + int x = (n % 10), y = (n % 100), z = (n % 1000); + if (z == 144) + n /= 1000; + else if (y == 14) + n /= 100; + else if (x == 1) + n /= 10; + else { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int ans = 0, mn; + while (1) { + mn = min(b, k - 1); + a -= (v * mn + v); + b -= mn; + if (a <= 0) { break; } + ans++; + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int n, i, m = 0, c = 0; + string str; + cin >> n; + getchar(); + getline(cin, str); + for (i = 0; i < n; i++) { + if (isupper(str[i])) c++; + m = max(c, m); + if (str[i] == ' ') c = 0; + } + cout << m << endl; + return 0; +} +int main() { + int k, n, s, p; + long long x, z; + cin >> k >> n >> s >> p; + z = n / s; + if (n % s > 0) { z++; } + z *= k; + x = z; + z /= p; + if (x % p > 0) { z++; } + cout << z << endl; +} +long long l, r; +int main() { + cin >> l >> r; + if (r - l + 1 < 3) { + cout << -1 << endl; + return 0; + } + if (l % 2 == 0) { + cout << l << " " << l + 1 << " " << l + 2 << endl; + return 0; + } + if (r - l + 1 > 3) { + cout << l + 1 << " " << l + 2 << " " << l + 3 << endl; + return 0; + } + cout << -1 << endl; + return 0; + return 0; +} +long long cil(long long x, long long y) { + if (x % y == 0) + return x / y; + else + return x / y + 1; +} +int main() { + long long n, i, j = 0; + cin >> n; + i = n; + while (n % 3 == 0 && n > 0) { + j++; + n /= 3; + } + long long l = pow(3, j + 1); + cout << cil(i, l) << endl; +} +int main() { + int x; + int ans = 0; + cin >> x; + while (x) { + ans += x & 1; + x >>= 1; + } + cout << ans << '\n'; + return 0; +} +int main() { + string str; + cin >> str; + str[0] = (char)toupper(str[0]); + cout << str << endl; + return 0; +} +int main() { + int n, a, b, c, d, w, h, x1 = 2e9, y1 = 2e9, x2 = 0, y2 = 0, area = 0; + cin >> n; + while (n--) { + cin >> a >> b >> c >> d; + w = c - a; + h = d - b; + area += w * h; + x1 = min(x1, a); + y1 = min(y1, b); + x2 = max(x2, c); + y2 = max(y2, d); + } + w = x2 - x1; + h = y2 - y1; + cout << (w == h && area == w * h ? "YES" : "NO") << endl; + return 0; +} +int main() { + string s; + cin >> s; + s += '@'; + int tmp = 0, ans = 0; + for (int i = 0; i < s.size(); i++) { + if (i > 0 and s[i] != s[i - 1]) { + if (tmp % 2 == 0) ans++; + tmp = 0; + } + tmp++; + } + cout << ans << endl; +} +int main() { + long long n, k; + cin >> n >> k; + cout << ((n / k) & 1 ? "YES" : "NO") << '\n'; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long now = 1; + for (long long i = 0; i < n && now <= m; ++i) now <<= 1; + cout << m % now << endl; + return 0; +} +const int N = 103; +int a[N]; +int main() { + int n, k, x, i, t, p, sum = 0; + cin >> n >> k >> x; + for (i = 0; i < n; i++) { cin >> a[i]; } + t = n; + while (k != 0) { + a[t - 1] = x; + t--; + k--; + } + for (i = 0; i < n; i++) { sum += a[i]; } + cout << sum << endl; + return 0; +} +int main() { + int i, j, m, n, temp = 0; + string a[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cin >> n; + if (n > 5) { + temp = (n / 2 - 2); + while (temp > 5) { temp = (temp / 2 - 2); } + m = temp - 1; + cout << a[m] << endl; + } else { + cout << a[n - 1] << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + if (a == 0 || b == 0) return 0; + if (a == b) return a; + if (a > b) return gcd(a - b, b); + return gcd(a, b - a); +} +int main() { + long long f, l, x, y, a, b, i, cnt = 0; + cin >> x >> y >> a >> b; + long long lcm = (x * y) / gcd(x, y); + cout << ((b / lcm) - ((a - 1) / lcm)) << endl; +} +int main() { + string s; + cin >> s; + int upper = 0, lower = 0; + for (int i = 0; i < s.length(); i++) { + if (isupper(s[i])) { + upper += 1; + } else { + lower += 1; + } + } + if (upper > lower) { + for (int i = 0; i < s.length(); i++) { s[i] = toupper(s[i]); } + } else { + for (int i = 0; i < s.length(); i++) { s[i] = tolower(s[i]); } + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n), b(n); + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0; i < n; ++i) cin >> b[i]; + int x = 0, y = 0; + for (int i = 1; i <= n; ++i) { + int s = 0, pre = 0; + for (int j = 0; j < i; ++j) s |= a[j]; + x = max(s, x); + for (int j = i; j < n; ++j) { + s |= a[j]; + s |= ~a[pre]; + pre++; + x = max(s, x); + } + } + for (int i = 1; i <= n; ++i) { + int s = 0, pre = 0; + for (int j = 0; j < i; ++j) s |= b[j]; + y = max(s, y); + for (int j = i; j < n; ++j) { + s |= b[j]; + s |= ~b[pre]; + pre++; + y = max(s, y); + } + } + cout << x + y << endl; + return 0; +} +int main() { + string name; + cin >> name; + for (int i = 0; i < name.length(); i++) { + for (int j = 1; j < name.length(); j++) { + if (isalnum(name[i]) != 0 && isalnum(name[i + j]) != 0) { + if (name[j + i] < name[i]) { + char cup = name[i]; + name[i] = name[j + i]; + name[j + i] = cup; + } + } + } + } + cout << name << endl; + return 0; +} +int main() { + char mima[10000], i, shuzi = 0, da = 0, xiao = 0, p = 1; + cin >> mima; + if (strlen(mima) < 5) p = 0; + for (i = 0; i < strlen(mima); i++) { + if (mima[i] >= '0' && mima[i] <= '9') shuzi++; + if (mima[i] >= 'A' && mima[i] <= 'Z') da++; + if (mima[i] >= 'a' && mima[i] <= 'z') xiao++; + } + if (shuzi == 0 || da == 0 || xiao == 0) p = 0; + if (p) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +long long mod = 1000000000 + 9; +long long n, m, k = 1, ans = 1, cnt, temp; +int main() { + cin >> n >> m; + temp = n; + while (temp) { + cnt++; + temp /= 2; + } + for (int i = 0; i < m; i++) { + k *= 2; + k %= mod; + } + k--; + for (int i = 0; i < n; i++) { + ans *= k; + ans %= mod; + k--; + k += mod; + k %= mod; + } + cout << ans << endl; +} +const int maxn = 1e3 + 10; +int a[maxn]; +int main() { + int l, r, m; + cin >> l >> r >> m; + while (m--) { + if (l < r) + l++; + else + r++; + } + cout << min(l, r) * 2 << endl; + return 0; +} +int a[120]; +int main() { + int m, n, i, j, x, t, y = 0, in; + cin >> n >> m; + for (i = 0; i < m; i++) { + t = -1; + for (j = 0; j < n; j++) { + cin >> x; + if (t < x) { + t = x; + in = j; + } + } + a[in]++; + } + for (j = 0; j < n; j++) { + if (a[j] > y) { + y = a[j]; + in = j; + } + } + cout << in + 1 << endl; + return 0; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || '9' < ch) { + if (ch == '-') f = -1; + ch = getchar(); + } + while ('0' <= ch && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int n, m; +string s; +int l1, l2; +char c1, c2; +int main() { + n = read(); + m = read(); + cin >> s; + for (int i = 1; i <= m; i++) { + l1 = read(); + l2 = read(); + cin >> c1; + cin >> c2; + for (int j = l1 - 1; j < l2; j++) + if (s[j] == c1) s[j] = c2; + } + cout << s << endl; + return 0; +} +int main() { + vector v; + int n, m, k, s = 0, p, i; + cin >> n >> m >> k; + p = k; + v.resize(n); + for (i = 0; i < n; i++) cin >> v[i]; + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + for (i = 0; !(p >= m); i++) { + p--; + p += v[i]; + s++; + if ((v[i] == 1 || i + 1 == n && (p < m)) && cout << -1 << endl) exit(0); + } + cout << s << endl; + return 0; +} +int a; +int main() { + cin >> a; + cout << a / 2 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i; + int tot = 0; + for (i = 2; i < n; i++) { + int h = n; + while (h > 0) { + tot += (h % i); + h /= i; + } + } + int z = n - 2; + for (i = n - 2; i >= 1; i--) { + if (tot % i == 0 && z % i == 0) { + tot /= i; + z /= i; + break; + } + } + cout << tot << '/' << z << endl; +} +long long a, b, c, n, x, ans; +int main() { + cin >> a >> b >> c >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x > b && x < c) ans++; + } + cout << ans << '\n'; +} +int main() { + int n, m; + cin >> n; + string s1; + cin >> s1; + int zero = 0, one = 0; + for (int i = 0; i < n; i++) { + if (s1[i] == '0') + zero++; + else + one++; + } + m = n - 2 * min(zero, one); + cout << m << endl; + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + if ((n / x) % 2 == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +string s, s1[101]; +int n, ok; +int main() { + cin >> s >> n; + for (int i = 1; i <= n; ++i) cin >> s1[i]; + for (int i = n; i >= 1; --i) + for (int j = 1; j < i; ++j) + if (s1[j] > s1[j + 1]) swap(s1[j], s1[j + 1]); + for (int k = 1; k <= n; ++k) { + ok = 1; + for (int i = 0; i < s.length(); ++i) + if (s[i] != s1[k][i]) { + ok = 0; + break; + } + if (ok) { + cout << s1[k] << endl; + return 0; + } + } + cout << s << endl; + return 0; +} +const int M = 110; +char s[M][M]; +char a[M]; +int f[M], t[M]; +char b[M]; +int main() { + int n; + while (cin >> a) { + cin >> n; + int c = 0; + memset(f, 0, sizeof(f)); + memset(t, 0, sizeof(t)); + int len = strlen(a); + for (int i = 0; i < n; i++) { + cin >> s[i]; + int len1 = strlen(s[i]); + if (len1 < len) { + t[i] = 1; + continue; + } + for (int j = 0; j < len; j++) { + if (a[j] != s[i][j]) { + t[i] = 1; + break; + } + } + if (t[i] == 0) { + f[i] = 1; + memset(b, 0, sizeof(b)); + strcpy(b, s[i]); + c++; + } + } + if (c == 0) + cout << a << endl; + else { + for (int i = 0; i < n; i++) { + if (f[i] == 1) { + if (strcmp(b, s[i]) > 0) { + memset(b, 0, sizeof(b)); + strcpy(b, s[i]); + } + } + } + cout << b << endl; + } + } + return 0; +} +int main() { + int t, L, v, l, r, r1, ans; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> L >> v >> l >> r; + ans = (l - 1) / v; + r1 = ((r / v) + 1) * v; + if (L >= r1) ans += (L - r1) / v + 1; + cout << ans << endl; + } +} +int main() { + int gcd = 0, n[1000], i, t; + cin >> t; + for (i = 0; i < t; i++) { + cin >> n[i]; + gcd = __gcd(gcd, n[i]); + } + cout << t * gcd << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int x = n - b; + int y = a + 1; + int sum = n - max(x, y) + 1; + cout << sum << '\n'; +} +long long l, r, x, y, k; +int main() { + cin >> l >> r >> x >> y >> k; + long long i; + int ok = 0; + for (i = x; i <= y; i++) + if (l <= i * k && r >= i * k) ok = 1; + if (ok) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int maxn = 1005; +const int Max = 0x3f3f3f3f; +int main() { + int n, m; + cin >> n >> m; + int a[maxn], j; + int t = Max; + memset(a, 0, sizeof(a)); + for (int i = 0; i < m; i++) { + cin >> j; + a[j]++; + } + for (int i = 1; i <= n; i++) t = min(t, a[i]); + cout << t << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[10000], i; + for (i = 0; i < n; i++) cin >> a[i]; + int max, min, b = 0; + max = a[0]; + for (i = 0; i < n; i++) { + if (a[i] > max) max = a[i]; + } + for (i = 0; i < n; i++) b += max - a[i]; + if (m < b) + min = max; + else if ((m - b) % n == 0) + min = max + (m - b) / n; + else + min = max + (m - b) / n + 1; + cout << min << ' ' << max + m << endl; + return 0; +} +char check(char a, char b) { + if (a == '(' && b == ')') + return 'r'; + else if (a == '[' && b == ']') + return 'p'; + else + return 's'; +} +int win(char a, char b) { + if (a == 'r' && b == 'p') return -1; + if (a == 'p' && b == 's') return -1; + if (a == 's' && b == 'r') return -1; + if (a != b) return 1; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int len = s1.length(); + int t1 = 0, t2 = 0; + for (int i = 0; i < len; i += 2) { + char c1 = check(s1[i], s1[i + 1]); + char c2 = check(s2[i], s2[i + 1]); + int winner = win(c1, c2); + if (winner == -1) + t2++; + else if (winner == 1) + t1++; + } + if (t1 == t2) + cout << "TIE\n"; + else if (t1 > t2) + cout << "TEAM 1 WINS\n"; + else + cout << "TEAM 2 WINS\n"; + return 0; +} +int n, k; +int main() { + cin >> n >> k; + string a; + cin >> a; + int loc1, loc2; + for (int i = 0; i < n; i++) { + if (a[i] == 'G') { loc1 = i; } + if (a[i] == 'T') { loc2 = i; } + } + int sign = 1, i = 1; + if ((loc2 - loc1) % k == 0) { + int t = loc1; + do { + t = loc1 + ((loc2 > loc1) ? k * i : k * i * -1); + if (a[t] == '#') { + sign = 0; + break; + } + i++; + } while ((loc2 > loc1) ? t < loc2 : t > loc2); + if (sign) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else + cout << "NO" << endl; + return 0; +} +int main() { + long long q; + cin >> q; + map peso; + while (q--) { + long long t, u, v, w; + cin >> t >> u >> v; + if (t == 1) { + cin >> w; + while (u != v) { + peso[max(u, v)] += w; + if (u > v) + u /= 2; + else + v /= 2; + } + } else { + long long ans = 0; + while (u != v) { + if (peso.count(max(u, v))) ans += peso[max(u, v)]; + if (u > v) + u /= 2; + else + v /= 2; + } + cout << ans << "\n"; + } + } + return 0; +} +int main() { + long long int num; + cin >> num; + cout << (num / 2) + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +const int MOD = 1000000007; +int val[2]; +int main() { + int N; + cin >> N; + val[0] = val[1] = 0; + for (int i = 0; i < N; i++) { val[i % 2] = (val[i % 2] + val[(i + 1) % 2] + 1) % MOD; } + cout << (val[0] + val[1]) % MOD << "\n"; + return 0; +} +const int N = 1e5 + 50; +const int M = 1e6; +const long long oo = 1e18; +const int mod = 1e9 + 7; +int main() { + int n; + cin >> n; + long long sum = 0, mx = 0; + for (int i = 0; i < n; i++) { + long long a; + cin >> a; + sum += a; + mx = max(mx, a); + } + cout << mx * n - sum << endl; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (n - (d / t) * k > k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string s; +inline int sum() { + int i, re = 0; + for (i = 0; i < s.size() - 1; i++) { + if (s.substr(i, 2) == "VK") re++; + } + return re; +} +int main() { + cin >> s; + int i, mx = -135; + mx = max(mx, sum()); + for (i = 0; i < s.size(); i++) { + if (s[i] == 'V') { + s[i] = 'K'; + mx = max(mx, sum()); + s[i] = 'V'; + } else { + s[i] = 'V'; + mx = max(mx, sum()); + s[i] = 'K'; + } + } + cout << mx << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + cout << a[0]; + for (int i = 1; i < a.length(); i++) { + if (a[i] >= b[0]) { break; } + cout << a[i]; + } + cout << b[0] << endl; + return 0; +} +int main() { + string s; + cin >> s; + reverse(s.begin(), s.end()); + if (s[0] == '0' || s[0] == '2' || s[0] == '4' || s[0] == '6' || s[0] == '8') + cout << '2' << endl; + else + cout << '1' << endl; + return 0; +} +const long long maxn = 2 * 1e6 + 2; +long long arr[maxn]; +int main() { + string s; + cin >> s; + long long f = maxn / 2, l = maxn / 2 - 1, r = maxn / 2 + 1; + arr[f] = 1; + for (int i = 1; i < s.length(); i++) { + if (s[i] == 'l') { + arr[l] = i + 1; + l--; + } else { + arr[r] = i + 1; + r++; + } + } + if (s[0] == 'l') { + for (int i = f + 1; i < maxn; i++) { + if (arr[i] != 0) cout << arr[i] << "\n"; + } + for (int i = l; i <= f; i++) { + if (arr[i] != 0) cout << arr[i] << "\n"; + } + } else { + for (int i = f; i < maxn; i++) { + if (arr[i] != 0) cout << arr[i] << "\n"; + } + for (int i = l; i < f; i++) { + if (arr[i] != 0) cout << arr[i] << "\n"; + } + } + return 0; +} +int main() { + int n, sum; + int num[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + while (cin >> n) { + if (n < 10) { + sum = 2 * num[n]; + } else { + sum = num[n / 10] * num[n % 10]; + } + cout << sum << endl; + } + return 0; +} +int main() { + long long int a, b, s, c, t, i, n, m; + cin >> t; + for (i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + n = s / c; + m = (n / a) * b; + cout << n + m << endl; + } +} +int getNextGap(int gap) { + gap = (gap * 10) / 13; + if (gap < 1) return 1; + return gap; +} +void combSort(long long int a[], long long int n) { + int gap = n; + bool swapped = true; + while (gap != 1 || swapped == true) { + gap = getNextGap(gap); + swapped = false; + for (int i = 0; i < n - gap; i++) { + if (a[i] > a[i + gap]) { + swap(a[i], a[i + gap]); + swapped = true; + } + } + } +} +int main() { + long long int numofelements; + cin >> numofelements; + long long int arr[numofelements]; + for (int i = 0; i < numofelements; i++) { cin >> arr[i]; } + combSort(arr, numofelements); + int counter = 0; + for (int i = 0; i < numofelements; i++) { + if (arr[i] == 0) { continue; } + if (arr[i] == arr[i + 1]) { + counter++; + if (arr[i + 1] == arr[i + 2]) { + cout << "-1" << endl; + return 0; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i += 2) { + for (int j = 2; j <= n - i; j += 2) { cout << "*"; } + for (int k = 1; k <= i; k++) { cout << "D"; } + for (int j = 2; j <= n - i; j += 2) { cout << "*"; } + cout << endl; + } + for (int i = 1; i < n; i += 2) { + for (int k = 1; k <= i; k += 2) { cout << "*"; } + for (int j = n - 2; j >= i; j--) { cout << "D"; } + for (int k = 1; k <= i; k += 2) { cout << "*"; } + cout << endl; + } +} +int a[1001]; +int main() { + int n, m; + int i, j, k, s = 0, h; + cin >> n; + cin >> a[0]; + m = k = a[0]; + for (i = 1; i < n; i++) { + cin >> a[i]; + if (a[i] < k) { + k = a[i]; + s++; + } + if (a[i] > m) { + m = a[i]; + s++; + } + } + cout << s << endl; +} +int n, m, l, r; +char c1, c2; +string x; +int main() { + cin >> n >> m >> x; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + for (int j = l - 1; j < r; j++) { + if (x[j] == c1) x[j] = c2; + } + } + cout << x << endl; +} +int dx[] = {-1, 0, 0, 1}; +int dy[] = {0, 1, -1, 0}; +int kx[] = {2, 2, -2, -2, 1, 1, -1, -1}; +int ky[] = {1, -1, 1, -1, 2, -2, 2, -2}; +int main() { + int n, t; + cin >> n >> t; + int ar[n + 1]; + for (int i = 1; i < n; i++) { + int a; + cin >> a; + ar[i] = i + a; + } + int i = 1; + while (i < n) { + i = ar[i]; + if (i == t) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + int h = 0; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "Icosahedron") + h += 20; + else if (s == "Tetrahedron") + h += 4; + else if (s == "Cube") + h += 6; + else if (s == "Octahedron") + h += 8; + else if (s == "Dodecahedron") + h += 12; + } + cout << h << endl; + return 0; +} +set all; +int main() { + string inp; + cin >> inp; + for (int i = 0; i < inp.size(); i++) { + all.insert(inp); + string first = inp.substr(0, 1); + string rest = inp.substr(1); + inp = rest + first; + } + cout << all.size() << endl; +} +int main() { + string a, b; + cin >> a >> b; + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[b.size() - i - 1]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +const int N = 1000100; +const int inf = 0x7f7f7f7f; +const int mod = 1000000007; +long long dp[N]; +int main() { + int n; + cin >> n; + dp[1] = 1; + dp[2] = 3; + for (int i = 3; i <= n; i++) { dp[i] = (dp[i - 1] + dp[i - 2] + 2) % mod; } + cout << dp[n] << endl; + return 0; +} +int main() { + double n; + cin >> n; + int a; + a = ceil(n / 5.0); + cout << a << endl; + return 0; +} +int main() { + int n, k, a[105], forth = 0, back = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + int j, j1; + for (j = 0; j < n; j++) + if (a[j] > k) break; + forth = j; + for (j1 = n - 1; j1 >= j; j1--) + if (a[j1] > k) break; + back = n - 1 - j1; + cout << forth + back << endl; + return 0; +} +int main() { + int n; + cin >> n; + int d; + if (n == 0) { + cout << "O-|-OOOO" << endl; + exit(0); + } + while (n != 0) { + d = n % 10; + n /= 10; + if (d == 0) + cout << "O-|-OOOO" << endl; + else if (d == 1) + cout << "O-|O-OOO" << endl; + else if (d == 2) + cout << "O-|OO-OO" << endl; + else if (d == 3) + cout << "O-|OOO-O" << endl; + else if (d == 4) + cout << "O-|OOOO-" << endl; + else if (d == 5) + cout << "-O|-OOOO" << endl; + else if (d == 6) + cout << "-O|O-OOO" << endl; + else if (d == 7) + cout << "-O|OO-OO" << endl; + else if (d == 8) + cout << "-O|OOO-O" << endl; + else if (d == 9) + cout << "-O|OOOO-" << endl; + } +} +int main() { + int n, t, k, a[5][5] = {0}, b[4][4]; + for (t = 1; t <= 3; t++) + for (k = 1; k <= 3; k++) cin >> a[t][k]; + for (t = 1; t <= 3; t++) + for (k = 1; k <= 3; k++) b[t][k] = a[t][k] + a[t][k + 1] + a[t][k - 1] + a[t + 1][k] + a[t - 1][k] + 1; + for (t = 1; t <= 3; t++) { + for (k = 1; k <= 3; k++) cout << b[t][k] % 2; + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int h = 1; + int temp = ((h) * (h + 1) * (h + 2)) / 6; + while (temp <= n) { + h++; + temp = ((h) * (h + 1) * (h + 2)) / 6; + } + cout << h - 1 << endl; + return 0; +} +char f, g; +string s, p; +map mi; +map ms; +vector v, va; +int arr[100005], brr[100005]; +int main() { + int a, b, c, n, m, t, l, r, i, j, k, x, y, z = 0; + x = 200; + y = 0; + z = 999; + cin >> n >> m; + for (i = 1; i <= n; i++) { + cin >> a; + x = min(x, a); + y = max(y, a); + } + for (i = 1; i <= m; i++) { + cin >> a; + z = min(z, a); + } + x *= 2; + z -= 1; + if (x > z || y > z) + cout << -1 << endl; + else { + a = max(x, y); + cout << a << endl; + } + return 0; +} +int main() { + int a[100000], b[100000]; + int n; + int ans = 0; + memset(b, 0, sizeof(b)); + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + b[a[i]]++; + } + for (int i = 1; i <= 10000; i++) { + if (b[i] != 0) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int a = 0; + cin >> a; + int p = 0, q = 0, sum = 0, counter = 0; + for (int i = 0; i < a; i++) { + cin >> p >> q; + sum = q - p; + if (sum >= 2) counter++; + } + cout << counter << endl; +} +int main() { + long long n, sum = 0, i; + cin >> n; + for (i = 1;; i++) { + sum += i; + if (sum >= n) break; + } + cout << i - (sum - n) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (long long)(n / 2 + n) << endl; +} +const int MOD = 1e9 + 9; +long long ans = 1, T = 1; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < m; i++) T = (T * 2) % MOD; + for (int i = 0; i < n; i++) { + T--; + if (T < 0) T += MOD; + ans = (ans * T) % MOD; + } + cout << ans << "\n"; +} +int main() { + int n, a, b, c, x, p, ans = 0; + cin >> n >> a >> b >> c; + int k = 1; + int i; + for (i = 2; i <= n; i++) { + if (k == 1) { + if (a < b) + x = a, p = 2; + else + x = b, p = 3; + } + if (k == 2) { + if (a < c) + x = a, p = 1; + else + x = c, p = 3; + } + if (k == 3) { + if (b < c) + x = b, p = 1; + else + x = c, p = 2; + } + ans = ans + x; + k = p; + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, cnt_1 = 0, cnt_0 = 0, cnt_max0 = -1; + cin >> n; + while (n--) { + cin >> a; + if (a == 1) { + cnt_1++; + if (cnt_0 > 0) { cnt_0--; } + } + if (a == 0) { + cnt_0++; + if (cnt_0 > cnt_max0) cnt_max0 = cnt_0; + } + } + int ans = cnt_1 + cnt_max0; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + char m[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> m[i][j]; } + } + bool a = true; + int q = m[0][0], w = m[0][1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (q != w) { + if (i == j || i + j + 1 == n) { + if (m[i][j] != q) { + a = false; + break; + } + } else if (m[i][j] != w) { + a = false; + break; + } + } else { + a = false; + break; + } + } + } + if (a) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int arr[n]; + int ans, maxdiff; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int num = 0; + ans = -1; + for (int i = 0; i < n; i++) { + maxdiff = 1; + for (int j = i + 1; j < n; j++) { + if (arr[j] - arr[i] <= d) + maxdiff++; + else + break; + } + if (maxdiff > ans) ans = maxdiff; + } + cout << n - ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + string result = ""; + int i1 = 1, i2 = 1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i1 % 2 != 0) { + cout << "#"; + } else { + if (i2 == 2) { + if (j == 0) + cout << "#"; + else + cout << "."; + } else if (i2 == 1) { + if (j + 1 == m) + cout << "#"; + else + cout << "."; + } + } + } + cout << endl; + i1++; + if (i != 0) { + if (i2 == 1 && i1 % 2 == 0) + i2 = 2; + else if (i2 == 2 && i1 % 2 == 0) + i2 = 1; + } + } + return 0; +} +int main() { + int n, p, q, count = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p >> q; + if (p < q - 1) { ++count; } + } + cout << count << endl; +} +int main() { + string s = "abcdefghijklmnopqrstuvwxyz", k; + int p, pp = 0, sum = 0; + cin >> k; + for (int i = 0; i < k.length(); i++) { + p = s.find(k[i]); + if (abs(pp - p) > 13) + sum += 26 - abs(pp - p); + else + sum += abs(pp - p); + pp = p; + } + cout << sum << endl; +} +int main() { + int n, c, a = 1; + char s[30001][20]; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + c = strlen(s[0]); + for (int i = 0; i < c; i++) { + for (int j = 0; j < n; j++) { + if (s[j][i] != s[0][i]) { + a = 0; + break; + } + } + if (a == 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0, t; + for (int i = 0; i < n; i++) { + cin >> t; + ans += abs(t); + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, ans; + cin >> n >> m; + int k = n * (n + 1) / 2, l; + l = m / k; + m = m - (k * l); + for (int i = 1; i <= n; i++) { + if (m >= i) + m -= i; + else + break; + } + cout << m << endl; +} +int main() { + int n, m; + cin >> n >> m; + vector a(n), b(m); + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int cnt = 0; + for (int i = 0; i < n; i++) { + if (cnt >= m) break; + if (a[i] <= b[cnt]) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + int x = s.size(); + cout << 26 * (x + 1) - x << endl; + return 0; +} +const int MOD = 1e9 + 7; +long long pow(long long a, long long b) { + long long ans = 1; + while (b) { + if (b & 1) ans = (ans * a) % MOD; + b /= 2; + a = (a * a) % MOD; + } + return ans; +} +int main() { + int c1, c2, c3, c4, c5; + cin >> c1 >> c2 >> c3 >> c4 >> c5; + int s = c1 + c2 + c3 + c4 + c5; + if (s == 0) { + cout << "-1" << endl; + return 0; + } else { + if (s % 5 == 0) + cout << s / 5 << endl; + else + cout << "-1" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s[n], d[n]; + for (int i = 0; i < n; ++i) cin >> s[i] >> d[i]; + for (int i = 0; i < n; ++i) { + if (d[i] == "rat") cout << s[i] << endl; + } + for (int i = 0; i < n; ++i) { + if (d[i] == "woman" || d[i] == "child") cout << s[i] << endl; + } + for (int i = 0; i < n; ++i) { + if (d[i] == "man") cout << s[i] << endl; + } + for (int i = 0; i < n; ++i) { + if (d[i] == "captain") cout << s[i] << endl; + } + return 0; +} +int main() { + int n, x, y, z, sum1 = 0, sum2 = 0, sum3 = 0; + cin >> n; + while (n--) { + cin >> x >> y >> z; + sum1 = sum1 + x; + sum2 = sum2 + y; + sum3 = sum3 + z; + } + if (sum1 == 0 && sum2 == 0 && sum3 == 0) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int main() { + int n, cnt = 0, sum = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int mx = a[n - 1]; + for (int i = 0; i < n; i++) { sum += abs(mx - a[i]); } + cout << sum << endl; +} +pair par[10001]; +set str; +int main() { + string s; + int n, i; + cin >> n >> s; + if (n == 8) + cout << "vaporeon" << endl; + else if (n == 6) + cout << "espeon" << endl; + else if (n == 7) { + if (s[0] == '.') { + if (s[1] == 'o') { + cout << "jolteon" << endl; + return 0; + } + if (s[1] == 'm') { + cout << "umbreon" << endl; + return 0; + } + if (s[1] == 'e') { + cout << "leafeon" << endl; + return 0; + } + if (s[1] == 'y') { + cout << "sylveon" << endl; + return 0; + } + if (s[1] == 'l') { + if (s[3] == 'r') { + cout << "flareon" << endl; + return 0; + } else { + cout << "glaceon" << endl; + return 0; + } + } + if (s[1] == '.') { + if (s[2] == 'b') { + cout << "umbreon" << endl; + return 0; + } + if (s[2] == 'l') { + if (s[3] == 't') { + cout << "jolteon" << endl; + return 0; + } else { + cout << "sylveon" << endl; + return 0; + } + } + if (s[2] == 'a') { + if (s[3] == 'r') { + cout << "flareon" << endl; + return 0; + } + if (s[3] == 'c') { + cout << "glaceon" << endl; + return 0; + } else { + cout << "leafeon" << endl; + return 0; + } + } + if (s[2] == '.') { + if (s[3] == 'r') { + cout << "flareon" << endl; + return 0; + } + if (s[3] == 'c') { + cout << "glaceon" << endl; + return 0; + } + if (s[3] == 'f') { + cout << "leafeon" << endl; + return 0; + } + if (s[3] == 't') { + cout << "jolteon" << endl; + return 0; + } + if (s[3] == 'v') { + cout << "sylveon" << endl; + return 0; + } else { + cout << "umbreon" << endl; + return 0; + } + } + } + } + if (s[0] == 'j') { + cout << "jolteon" << endl; + return 0; + } + if (s[0] == 'f') { + cout << "flareon" << endl; + return 0; + } + if (s[0] == 'u') { + cout << "umbreon" << endl; + return 0; + } + if (s[0] == 'l') { + cout << "leafeon" << endl; + return 0; + } + if (s[0] == 'g') { + cout << "glaceon" << endl; + return 0; + } + if (s[0] == 's') { + cout << "sylveon" << endl; + return 0; + } + } + return 0; +} +int main() { + int n, m, i, j, total = 0, val, diff, mini = 10000; + vector v; + cin >> n >> m; + for (i = 0; i < m; i++) { + cin >> val; + v.push_back(val); + } + sort(v.begin(), v.end()); + for (i = 0; i <= m - n; i++) { + val = abs(v[i] - v[i + n - 1]); + mini = min(mini, val); + } + cout << mini << endl; +} +vector V; +int dp[105][5]; +int n; +int f(int i, int x) { + if (dp[i][x] == -1) { + int min = 105; + int blocked = -1; + int ans = 0; + if (V[i] == 0) { + if (x == 0) { + ans++; + } else + return 105; + } else { + if (V[i] == 1) { + if (x == 2) return 105; + if (x == 0) + ans++; + else { + blocked = 1; + } + } else { + if (V[i] == 2) { + if (x == 1) return 105; + if (x == 0) + ans++; + else { + blocked = 2; + } + } else { + if (x == 0) + ans++; + else if (x == 1) + blocked = 1; + else if (x == 2) + blocked = 2; + } + } + } + if (i < (n - 1)) { + for (int j = 0; j < 3; j++) { + if (j != blocked) { min = min < f(i + 1, j) ? min : f(i + 1, j); } + } + dp[i][x] = ans + min; + } else + dp[i][x] = ans; + } + return dp[i][x]; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + V.push_back(a); + } + for (int i = 0; i < n; i++) + for (int j = 0; j < 3; j++) { dp[i][j] = -1; } + int ans = min(min(f(0, 0), f(0, 1)), f(0, 2)); + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, p[6]; + cin >> a >> b >> c; + p[0] = a + b + c; + p[1] = a * (b + c); + p[2] = a * b * c; + p[3] = a + b * c; + p[4] = a * b + c; + p[5] = (a + b) * c; + sort(p, p + 6); + cout << p[5] << endl; + return 0; +} +int n, k, l, c, d, p, nl, np; +int main() { + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(min(((k * l) / nl), (c * d)), (p / np)) / n << endl; +} +int a[100][100]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) a[i][j] = 1; + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= n; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + } + cout << a[n][n] << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int g = __gcd(m, n); + int ans = (z * g) / (m * n); + cout << ans << endl; + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + for (int i = 0; i < n; i++) { + if (abs(s1[i] - s2[i]) > 5) + ans += 10 - abs(s1[i] - s2[i]); + else { + ans += abs(s1[i] - s2[i]); + } + } + cout << ans << endl; +} +int m, n, q[200000], a[200000], ans; +int main() { + cin >> m; + for (int i = 0; i < m; i++) cin >> q[i]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + sort(q, q + m); + ans = 0; + int total = 0; + for (int i = n - 1; i >= 0; i--) { + if (total < q[0]) { + ans += a[i]; + total++; + } else { + total = 0; + i--; + } + } + cout << ans << endl; + return 0; +} +long long i, j, k, n, t, m, x, z, ans, a[200007]; +int main() { + cin >> t; + string s; + while (t--) { + cin >> n >> s; + long long f = 0; + for (i = 0; i < n / 2; i++) { + x = fabs(s[i] - s[n - i - 1]); + if (x == 0 || x == 2) + continue; + else { + cout << "NO\n"; + f = 1; + break; + } + } + if (f == 0) cout << "YES\n"; + } + return 0; +} +int k, r; +int main() { + cin >> k >> r; + int i; + for (i = 1; i <= 10; ++i) { + if ((i * k - r) % 10 == 0 || (i * k) % 10 == 0) { + cout << i << endl; + return 0; + } + } +} +int main() { + long long n, i, j, l = 1000000000000000, r = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> j; + l = min(l, j); + r = max(r, j); + } + cout << (r - l + 1) - n << endl; +} +int main() { + int n, t; + cin >> n; + for (; cin >> t;) + if (t == 1) { + cout << -1 << endl; + return 0; + } + cout << 1 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + cout << k / a[i] << '\n'; + break; + } + } + return 0; +} +bool isPerfectSquare(long double x) { + long double sr = sqrt(x); + return ((sr - floor(sr)) == 0); +} +int floorSqrt(int x) { + if (x == 0 || x == 1) return x; + int i = 1, result = 1; + while (result <= x) { + i++; + result = i * i; + } + return i - 1; +} +int main() { + long long n; + cin >> n; + if (n == 1) { + cout << "1 1" << '\n'; + return 0; + } + if (isPerfectSquare(n)) { + long long foo = floorSqrt(n); + cout << foo << ' ' << foo << '\n'; + return 0; + } + long long start = floorSqrt(n); + while (start * (n / start) != n) { --start; } + cout << start << ' ' << n / start << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n + 1) / 36 << " "; + n %= 36; + if ((n + 1) / 36 <= n / 36) + cout << (n + 1) / 3 << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + int a, p, ans = 0, n, mn = 123; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> p; + mn = (min(mn, p)); + ans += a * mn; + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) { + cout << n / 2 << endl; + } else { + cout << (-n - 1) / 2 << endl; + } + return 0; +} +int arr[10]; +bool cek(int thn) { + memset(arr, 0, sizeof(arr)); + while (thn) { + if (arr[thn % 10] > 0) + return false; + else + arr[thn % 10]++; + thn /= 10; + } + return true; +} +int main() { + int y, y2, i; + cin >> y; + bool temu = false; + while (!temu) { + if (cek(++y)) { + cout << y << "\n"; + temu = true; + } + } + return 0; +} +int main() { + int n, cards = 0; + cin >> n; + n -= 10; + if (n >= 1 && n < 10) + cards = 4; + else if (n == 10) + cards = 15; + else if (n == 11) + cards = 4; + else + cards = 0; + cout << cards << endl; + return 0; +} +int main() { + long long n, m, a; + cin >> n >> m >> a; + if (n % a == 0) + n /= a; + else + n = n / a + 1; + if (m % a == 0) + m /= a; + else + m = m / a + 1; + cout << n * m << endl; + return 0; +} +long long mod = 1000000007; +long long num[1000099]; +void check() { + num[1] = 1; + num[2] = 3; + num[3] = 6; + for (int i = 4; i <= 1000006; i++) { num[i] = 2 + ((num[i - 2] % mod) + (num[i - 1] % mod)) % mod; } +} +int main() { + check(); + long long n; + cin >> n; + cout << num[n] << endl; + return 0; +} +int main() { + long long int n, x, y, i, j, x1, x2, x3, x4; + long long int z = 0; + cin >> n; + long long int a[n], b[n]; + for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (i = 0; i < n; i++) { + x = a[i], y = b[i]; + x1 = 0, x2 = 0, x3 = 0, x4 = 0; + for (j = 0; j < n; j++) { + if (i != j) { + if (a[j] > x && b[j] == y) x1++; + if (a[j] < x && b[j] == y) x2++; + if (a[j] == x && b[j] < y) x3++; + if (a[j] == x && b[j] > y) x4++; + } + } + if (x1 > 0 && x2 > 0 && x3 > 0 && x4 > 0) z++; + } + cout << z << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + deque deq; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + deq.push_back(temp); + } + int total = 0; + while (deq.size() > 0 && deq.front() <= k) { + deq.pop_front(); + total++; + } + while (deq.size() > 0 && deq.back() <= k) { + deq.pop_back(); + total++; + } + cout << total << endl; + return 0; +} +int n, a[1002], ans1, ans2, i; +int main() { + cin >> n; + for (i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + n / 2 + 1); + for (i = 1; i <= n / 2; i++) ans1 += abs(a[i] - (i * 2 - 1)); + for (i = 1; i <= n / 2; i++) ans2 += abs(a[i] - i * 2); + cout << min(ans1, ans2) << endl; +} +int main() { + long long n, a[100100]; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + long long s = 0; + for (int k = 0; k < n - 1; ++k) { + int t = 0; + while (k + (1 << t + 1) < n) ++t; + s += a[k], a[k + (1 << t)] += a[k]; + cout << s << endl; + } + return 0; +} +int a[100001]; +int b[100001]; +int cmp(const void *a, const void *b) { + int *c = (int *)a; + int *d = (int *)b; + return *c - *d; +} +int main() { + int n, i, x; + memset(a, 0, sizeof(a)); + cin >> n; + int cnt = 0; + cin >> x; + a[x] = 1; + cnt++; + int ma = 0; + for (i = 2; i <= 2 * n; i++) { + cin >> x; + if (cnt > ma) { ma = cnt; } + if (a[x] == 1) { + cnt--; + a[x] = 0; + } else { + a[x] = 1; + cnt++; + } + } + cout << ma << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int dp[n]; + for (int i = 0; i < n; i++) dp[i] = 1; + int ma = 1; + for (int i = 1; i < n; i++) { + if (a[i] > a[i - 1]) { + dp[i] = dp[i - 1] + 1; + ma = max(dp[i], ma); + } + } + cout << ma << "\n"; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + for (int i = 0; i < (n); ++i) { + if ((i + 1) % 2 != 0) + for (int j = 0; j < (m); ++j) cout << "#"; + else if ((i + 1) % 4 != 0) { + for (int j = 0; j < (m); ++j) + if (j == m - 1) + cout << "#"; + else + cout << "."; + } else { + for (int j = 0; j < (m); ++j) + if (j == 0) + cout << "#"; + else + cout << "."; + } + cout << endl; + } + return 0; +} +int co, cx; +const long long inf = -1e16; +inline long long gox(int num) { + if (num > cx) return inf; + int ex = cx % num; + int anch = cx / num; + long long ans = 1LL * (anch + 1) * (anch + 1) * ex; + ans += 1LL * anch * anch * (num - ex); + return -ans; +} +inline long long goo(int num) { + if (num > co) return inf; + int juntos = co - num + 1; + long long ans = 1LL * juntos * juntos; + ans += num - 1; + return ans; +} +inline void build(int x, int o) { + string s; + int xx = cx / x; + bool flag = (x > o); + bool fst = true; + int ex = cx % x; + int prim = co - o + 1; + while (x || o) { + if (flag) { + for (int i = int(0); i < int(xx); ++i) s.push_back('x'); + if (ex > 0) s.push_back('x'), ex--; + x--; + } else { + if (fst) { + for (int i = int(0); i < int(prim); ++i) s.push_back('o'); + fst = false; + } else + s.push_back('o'); + o--; + } + flag = (!flag); + } + cout << s << endl; +} +int main() { + cin >> co >> cx; + if (co == 0 || cx == 0) { + if (co > 0) { + cout << 1LL * co * co << endl; + for (int i = int(0); i < int(co); ++i) cout << 'o'; + cout << endl; + } + if (cx > 0) { + cout << -1LL * cx * cx << endl; + for (int i = int(0); i < int(cx); ++i) cout << 'x'; + cout << endl; + } + return 0; + } + int lim = min(co, cx); + long long ans = LLONG_MIN; + pair pos; + for (int i = int(1); i < int(lim + 1); ++i) { + if (ans < gox(i) + goo(i)) { + ans = gox(i) + goo(i); + pos = {i, i}; + } + } + for (int i = int(2); i < int(cx + 1); ++i) { + if (ans < gox(i) + goo(i - 1)) { + ans = gox(i) + goo(i - 1); + pos = {i, i - 1}; + } + } + for (int i = int(2); i < int(co + 1); ++i) { + if (ans < gox(i - 1) + goo(i)) { + ans = gox(i - 1) + goo(i); + pos = {i - 1, i}; + } + } + cout << ans << endl; + build(pos.first, pos.second); + return 0; +} +int swaps(int *x, int *y) { + int t = *x; + *x = *y; + *y = t; +} +int main() { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (x1 > x2) { swaps(&x1, &x2); } + if (y1 > y2) { swaps(&y1, &y2); } + int X, Y; + X = x2 - x1; + Y = y2 - y1; + if (X == Y) { + cout << X << endl; + return 0; + } + if (X < Y) { swaps(&X, &Y); } + cout << X << endl; +} +int main() { + int num, Tim; + cin >> num >> Tim; + int Rem = 240 - Tim; + int sum = 0; + int flag = 0; + int temp = num; + for (int i = 1; i < num + 1; i++) { + sum += i; + if (sum * 5 > Rem) { + temp = i - 1; + break; + } + } + cout << temp << endl; + return 0; +} +int sz; +string s, r; +bool esPalindromo(string &a) { + string b = a; + reverse(b.begin(), b.end()); + return (a == b); +} +void resolver(string str, int p) { + if ((str > r) && esPalindromo(str)) r = str; + if (p == int(s.size())) return; + resolver((str + s[p]), (p + 1)); + resolver(str, (p + 1)); +} +int main() { + cin >> s; + sz = int(s.size()); + resolver("", 0); + cout << r << "\n"; + return 0; +} +int main() { + string ss; + cin >> ss; + int n; + cin >> n; + cin.ignore(); + string res = ss; + bool noe = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + string tmp = ""; + for (int j = 0, ii = 0; j < s.length(); j++) { + if (ss[ii] == s[j]) + ii++; + else + ii = 0; + if (ii == ss.length()) { + if (!noe) + res = s.substr(j - ii + 1, s.length()), noe = 1; + else { + tmp = s.substr(j - ii + 1, s.length()); + res = min(res, tmp); + ii = 0; + } + } + } + } + cout << res << '\n'; + return 0; +} +int main() { + int n, k, f, t, max_joy, joy; + cin >> n >> k >> f >> t; + if (t > k) { + max_joy = f - (t - k); + } else { + max_joy = f; + } + while (--n) { + cin >> f >> t; + if (t > k) { + joy = f - (t - k); + } else { + joy = f; + } + if (joy > max_joy) { max_joy = joy; } + } + cout << max_joy << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + for (int i = int(0); i < int(k); i++) { + int ta, fa, tb, fb; + cin >> ta >> fa >> tb >> fb; + int res = 0; + int current = fa; + if (ta != tb) { + if (fa < a || fa > b) { + if (abs(fa - a) < abs(fa - b)) + current = a; + else + current = b; + res += min(abs(fa - a), abs(fa - b)); + } + res += abs(ta - tb); + } + res += abs(current - fb); + cout << res << endl; + } + return 0; +} +int main() { + long long int n, count, i, x, y, j, ans; + int a[5][5]; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) { + x = i + 1; + y = j + 1; + } + } + } + ans = abs(3 - x) + abs(3 - y); + cout << ans << "\n"; +} +int main() { + string word; + cin >> word; + int small = 0; + int cap = 0; + for (int i = 0; i < word.length(); i++) { + int a = word[i]; + if (a > 90) { + small++; + } else { + cap++; + } + } + if (small >= cap) { + for (int i = 0; i < word.length(); i++) { + int a = word[i]; + if (a <= 90) { word[i] = a + 32; } + } + } else if (cap > small) { + for (int i = 0; i < word.length(); i++) { + int a = word[i]; + if (a > 90) { word[i] = a - 32; } + } + } + cout << word << endl; + return 0; +} +long long int i, j, t; +int main() { + long long int n; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + long long int x[n] = {0}; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { x[i] += a[j] * ((abs(i - j) + abs(j) + abs(i) + abs(i) + abs(j) + abs(j - i))); } + } + sort(x, x + n); + cout << x[0] << endl; +} +int n, a, b; +int main() { + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +int main() { + int n, k, bucket = 0, ai; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> ai; + if ((k % ai == 0) && (ai > bucket)) bucket = ai; + } + cout << k / bucket << endl; + return 0; +} +int main() { + int res = 0; + string a = "aeiou13579"; + string str; + cin >> str; + for (int i = 0; str[i]; i++) { + if (a.find(str[i]) != -1) res++; + } + cout << res << endl; + return 0; +} +int main() { + int n, m, maxn = -1, minn = 0x3f3f3f3f, cnt = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int num; + cin >> num; + maxn = max(num, maxn); + cnt += num; + } + double ans = ceil((cnt + m) * 1.0 / n); + cout << max(maxn, int(ans)) << " " << maxn + m << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s.size() > 10) + cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl; + else + cout << s << endl; + } + return 0; +} +const long long maxn = 1120; +long long p[1001]; +bool a[maxn]; +int cnt = 0; +int main() { + int n, k; + cin >> n >> k; + char a[105]; + int x, y; + int flag = 1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'T') + x = i; + else if (a[i] == 'G') + y = i; + } + if (x >= y) { + int i; + for (i = y; i <= x; i += k) { + if (a[i] == '#') { + flag = 0; + break; + } + } + if (i - k != x) flag = 0; + } else { + int i = y; + for (i = y; i >= x; i -= k) { + if (a[i] == '#') { + flag = 0; + break; + } + } + if (i + k != x) flag = 0; + } + if (flag == 0) { + cout << "NO" << endl; + } else + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector one; + vector two; + vector three; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 1) { + one.push_back(i + 1); + } else if (x == 2) { + two.push_back(i + 1); + } else if (x == 3) { + three.push_back(i + 1); + } + } + int groups = min(min(one.size(), two.size()), three.size()); + cout << groups << endl; + if (groups > 0) { + for (int i = 0; i < groups; i++) { cout << one[i] << " " << two[i] << " " << three[i] << endl; } + } +} +const long double PI = acos(-1); +inline long long mod(long long n, long long m) { + long long ret = n % m; + if (ret < 0) ret += m; + return ret; +} +long long gcd(long long a, long long b) { + if (a == 0) + return b; + else + return gcd(b % a, a); +} +int main() { + long long q, s, t; + cin >> t >> s >> q; + long long ans = 0; + while (s < t) { + s *= q; + ans++; + } + cout << ans << '\n'; +} +int main() { + int n, i = 0; + cin >> n; + i += n / 5; + n %= 5; + i += n / 4; + n %= 4; + i += n / 3; + n %= 3; + i += n / 2; + n %= 2; + i += n; + n %= 1; + cout << i << endl; + return 0; +} +int main() { + int m, n; + string x; + cin >> m; + while (m--) { + cin >> n >> x; + if (n == 2 && x[0] >= x[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl << 2 << endl << x[0] - '0' << " "; + for (int i = 1; i < n; i++) cout << x[i] - '0'; + cout << endl; + } + } +} +int main() { + long long n, k, t, f, maxx = LONG_LONG_MIN; + vector duck; + while (cin >> n >> k) { + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t <= k) { + duck.push_back(f); + } else { + long long ans = (f - (t - k)); + duck.push_back(ans); + } + } + for (int i = 0; i < n; i++) maxx = max(maxx, duck[i]); + } + cout << maxx << endl; + return 0; +} +void orderArguments(int &arg1, int &arg2) { + if (arg1 > arg2) { + int temp = arg1; + arg1 = arg2; + arg2 = temp; + } +} +void subtraction(istream &r, ostream &w) { + int arg1, arg2; + r >> arg1; + r >> arg2; + if (false) w << "arg1=" << arg1 << "arg2=" << arg2 << endl; + orderArguments(arg1, arg2); + if (false) w << "arg1=" << arg1 << "arg2=" << arg2 << endl; + int quotient = 0; + int remainder; + do { + quotient += arg2 / arg1; + remainder = arg2 % arg1; + arg2 = arg1; + arg1 = remainder; + } while (remainder != 0); + w << quotient << endl; +} +void evaluate(istream &r, ostream &w) { + int numOfTestCases; + r >> numOfTestCases; + for (int i = 1; i <= numOfTestCases; i++) { subtraction(r, w); } +} +int main() { + evaluate(cin, cout); + return 0; +} +int main() { + int n; + while (cin >> n) { + int a, b, ans = 0; + while (n--) { + cin >> a >> b; + if (b - a >= 2) ans++; + } + cout << ans << endl; + } + return 0; +} +int a[1010], b[1010], n, m, j; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> b[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + for (int i = 0; i < n; i++) + if (b[i] <= a[j]) j++; + cout << j << endl; + return 0; +} +int main() { + int i, n, p; + bool zero = false; + set elements; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p; + if (p == 0) zero = true; + elements.insert(p); + } + cout << elements.size() - zero << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + deque vec(n, 0); + for (int i = 0; i < n; i++) cin >> vec[i]; + sort(vec.begin(), vec.end()); + int ret = INT_MAX; + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { + int diameter = vec[j] - vec[i]; + if (diameter > d) continue; + int left = i; + int right = n - (j + 1); + int removals = left + right; + ret = min(ret, removals); + } + } + cout << ret << '\n'; + return 0; +} +long long int n; +string s[1007]; +int main() { + cin >> n; + for (long long int i = 0; i <= n - 1; i++) { + cin >> s[i]; + set ss; + for (long long int j = 0; j <= s[i].size() - 1; j++) { ss.insert(s[i][j]); } + s[i] = ""; + for (__typeof(ss.begin()) it = ss.begin(); it != ss.end(); ++it) { s[i] += (*it); } + } + set rs; + for (long long int i = 0; i <= n - 1; i++) { rs.insert(s[i]); } + cout << rs.size() << "\n"; + return 0; +} +void fail() { + cout << "NO\n"; + exit(0); +} +int main() { + long long int n, p; + cin >> n >> p; + string s; + cin >> s; + if (p == 1) + fail(); + else if (p == 2) { + if (n > 2) + fail(); + else if (n == 2) { + if (s == "ab") { + cout << "ba\n"; + return 0; + } else + fail(); + } else { + if (s == "a") { + cout << "b\n"; + return 0; + } else + fail(); + } + } else { + for (int i = n - 1; i >= 0; i--) { + int good = -1; + for (int j = 1; j < p; j++) { + if (s[i] + j >= 'a' + p) continue; + if (i >= 1 && s[i] + j == s[i - 1]) continue; + if (i >= 2 && s[i] + j == s[i - 2]) continue; + good = j; + break; + } + if (good == -1) continue; + s[i] += good; + for (int j = i + 1; j < n; j++) { + for (char c = 'a'; c <= 'c'; c++) { + if (j >= 1 && s[j - 1] == c) continue; + if (j >= 2 && s[j - 2] == c) continue; + s[j] = c; + break; + } + } + cout << s << endl; + return 0; + } + fail(); + } + return 0; +} +int arr[105]; +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + char x = s[i]; + int xx = (int)x; + xx -= 97; + arr[xx] += 1; + } + for (int i = 0; i < 26; i++) { + if (arr[i] > m) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, x = 0, y = 0, z = 0, t1, t2, t3; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t1 >> t2 >> t3; + x += t1; + y += t2; + z += t3; + } + if (x || y || z) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int x, y, z; + cin >> x >> y >> z; + if (x + 1 == y && y + 1 == z) { + cout << x + y + z << endl; + } else { + while (1) { + int a = z; + int b = z - 1; + int c = z - 2; + if ((a <= z && b <= y && c <= x) && (c + 1 == b && b + 1 == a)) { + cout << a + b + c << endl; + break; + } + z = z - 1; + } + } +} +string s; +int a[27]; +int main() { + int n, k, f = 0; + cin >> n >> k; + cin >> s; + for (int i = 0; i < n; i++) a[s[i] - 'a']++; + for (int i = 0; i < 26; i++) + if (a[i] != 0 && a[i] > k) { + cout << "NO" << endl; + f = 1; + break; + } + if (!f) cout << "YES" << endl; + return 0; +} +string T; +long long N, K, M, A, B, C, D, sum; +int main() { + cin >> A >> B >> C >> N; + for (int i = 1; i <= N; i++) { + cin >> K; + if (K > B && K < C) sum++; + } + cout << sum << '\n'; +} +int main() { + int i, j, n, t; + cin >> n; + t = n / 100; + int ans = 0; + ans += t; + n = n % 100; + t = n / 20; + ans += t; + n = n % 20; + t = n / 10; + ans += t; + n = n % 10; + t = n / 5; + ans += t; + n = n % 5; + t = n / 1; + ans += t; + cout << ans << endl; +} +int main() { + int n, a[105], sum1 = 0, sum2 = 0; + cin >> n; + for (int i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + n / 2 + 1); + for (int i = 1; i <= n / 2; i++) { + sum1 += abs(i * 2 - 1 - a[i]); + sum2 += abs(i * 2 - a[i]); + } + cout << ((sum1 > sum2) ? sum2 : sum1) << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + for (int i = 1; i < s.size(); i++) { + if ((s[i] == '0' && s[i - 1] == '1') || (s[i] == '1' && s[i - 1] == '0')) { + s.erase(i - 1, 2); + i -= 2; + } + } + if (s == "10" || s == "01") { + cout << 0 << endl; + return 0; + } + cout << s.size() << endl; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int n; + cin >> n; + string array[n]; + string output[n]; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> array[i]; + int flag = 0; + if (array[i].length() < len) { continue; } + for (int j = 0; j < len; j++) { + if (array[i][j] != s[j]) { + flag = 1; + break; + } + } + if (flag == 0) { output[count++] = array[i]; } + } + if (count == 0) { + cout << s << endl; + return 0; + } + sort(output, output + count); + cout << output[0] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + n]; + for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } + sort(a, a + n * 2); + if (a[n] > a[n - 1]) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int n, a[1005]; +int main() { + n = read() * 2; + for (int i = 1; i <= n; ++i) a[i] = read(); + sort(a + 1, a + n + 1); + if (a[n >> 1] < a[(n >> 1) + 1]) return 0 * puts("YES"); + puts("NO"); + return 0; +} +int main() { + int i, j, n, sa = 0, sb = 0, b[105], a[105]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + if (a[i] > b[i]) sa++; + if (a[i] < b[i]) sb++; + } + if (sa < sb) cout << "Chris" << endl; + if (sa > sb) cout << "Mishka" << endl; + if (sa == sb) cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n, c = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '1') + c++; + else + break; + } + if (c == n) + cout << c << endl; + else + cout << c + 1 << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + if ((l == 0 && a == 0) || (r == 0 & a == 0)) { + cout << 0 << endl; + } else + { + while (a > 0) { + if (l < r) { + l++; + a--; + } else if (r < l) { + r++; + a--; + } else { + if (a >= 2) { + l++; + r++; + a -= 2; + } else + break; + } + } + if (l < r) + r = l; + else + l = r; + if ((l + r) % 2 == 0) + cout << l + r << endl; + else if (a != 0) + cout << l + r + 1 << endl; + } +} +int main() { + int n, i, j; + cin >> n; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (abs(i - n / 2) + abs(j - n / 2) <= n / 2) + cout << "D"; + else + cout << "*"; + } + cout << "\n"; + } +} +const int sz = 1e5 + 10; +const int mod = 10007; +int t, cs; +int main() { + int a, b, c, d; + while (cin >> a >> b >> c >> d) { + int ans = 0; + while (b > 0) { + ans++; + int se = min(a, c + 1); + c -= se - 1; + b -= se * d; + } + cout << ans << "\n"; + cerr << "----\n"; + } + return 0; +} +int q; +long long op, u, v, w; +map mp; +long long LCA(long long v, long long u) { + vector a, b; + while (v > 0) { + a.push_back(v); + v /= 2; + } + while (u > 0) { + b.push_back(u); + u /= 2; + } + reverse(a.begin(), a.end()); + reverse(b.begin(), b.end()); + long long res = -1; + for (int i = 0; i < a.size() && i < b.size(); i++) { + if (a[i] == b[i]) res = a[i]; + } + return res; +} +void add(long long v, long long w) { + mp[v] += w; +} +int main() { + cin >> q; + for (int i = 0; i < q; i++) { + cin >> op >> u >> v; + if (op == 1) { + cin >> w; + long long lca = LCA(u, v); + while (v != lca) { + add(v, w); + v /= 2; + } + while (u != lca) { + add(u, w); + u /= 2; + } + } else { + long long sum = 0; + long long lca = LCA(u, v); + while (v != lca) { + if (mp.count(v)) sum += mp[v]; + v /= 2; + } + while (u != lca) { + if (mp.count(u)) sum += mp[u]; + u /= 2; + } + cout << sum << '\n'; + } + } + return 0; +} +int a[110], b[110]; +int numa[6], numb[6]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + numa[a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + numb[b[i]]++; + } + int p = 0; + for (int i = 1; i <= 5; i++) { + if ((numa[i] + numb[i]) % 2 != 0) { + cout << -1 << endl; + return 0; + } + p += abs(numa[i] - numb[i]) / 2; + } + cout << p / 2 << endl; + return 0; +} +const long long N = 1e9 + 3; +const long long MN = 1e9; +long long n, m; +long long ar[12 + 1] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + cin >> n >> m; + cout << ((m - 1) + ar[n] - 1) / 7 + 1; + cout << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int c = 0; + while (n > 0) { + if (n % 2 != 0) { + c++; + n--; + } else { + n /= 2; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + char xay[n]; + int z = 0; + for (int i = 0; i < n; i++) { + char s; + cin >> xay[i]; + if (xay[i] == s) { + z++; + s = '\0'; + } else { + s = '\0'; + } + s = xay[i]; + } + cout << z << endl; +} +const int N = 2e5 + 50; +const int M = 1e6; +const long long oo = 1e18; +const int mod = 1e9 + 7; +int main() { + int n; + cin >> n; + vector a(2 * n); + for (int i = 0; i < n * 2; i++) cin >> a[i]; + sort(a.begin(), a.end()); + long long ans = (a[n - 1] - a[0]) * (a.back() - a[n]); + for (int i = 1; i < n; i++) { ans = min(ans, (a[i + n - 1] - a[i]) * (a.back() - a[0])); } + cout << ans << endl; +} +const long long N = 1e4; +const long long MN = 1e5; +long long a; +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +void l_r(long long n) { + long long a, c = 0, l, r, ans; + vector v, d1, d2; + for (long long i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + } + d1.push_back(v[0]); + for (long long i = 1; i < v.size(); i++) { d1.push_back(d1[i - 1] + v[i]); } + d2.push_back(v[n - 1]); + for (long long i = v.size() - 2; i >= 0; i--) { + d2.push_back(d2[c] + v[i]); + c++; + } + cin >> l >> r; + if (l == 1 and r == n) { + ans = 0; + } else if (l == 1) { + ans = d2[n - r - 1]; + } else if (r == n) { + l--; + ans = d1[l - 1]; + } else { + l--; + ans = d1[l - 1] + d2[n - r - 1]; + } + cout << ans; +} +void problem(long long a, long long b, long long c, long long n) { + long long cnt = 0, x; + for (long long i = 0; i < n; i++) { + cin >> x; + if (x > b and x < c) { cnt++; } + } + cout << cnt; +} +int main() { + long long a, b, c, n; + cin >> a >> b >> c >> n; + problem(a, b, c, n); + cout << "\n"; + return 0; +} +const int INF_INT = 2147483647; +const long long INF_LL = 9223372036854775807LL; +const unsigned long long INF_ULL = 18446744073709551615Ull; +const long long P = 92540646808111039LL; +const long long maxn = 1e5 + 10, MOD = 1e9 + 7; +const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1}; +const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1}; +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +void init() {} +int a[maxn]; +int main() { + init(); + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + a[x]++; + } + } + bool flg = false; + for (int i = 1; i <= m; i++) { + if (!a[i]) { + flg = true; + break; + } + } + if (flg) + puts("NO"); + else + puts("YES"); + return 0; +} +bool lasagna[696969]; +bool valid = true; +int main() { + int x, y; + cin >> x >> y; + int cyka, blyat; + for (int a = 1; a <= x; a++) { + cin >> blyat; + for (int A = 0; A < blyat; A++) { + cin >> cyka; + lasagna[cyka] = true; + } + } + for (int a = 1; a <= y; a++) { + if (lasagna[a] == false) { + cout << "NO\n"; + valid = false; + break; + } + } + if (valid == true) cout << "YES\n"; +} +int main() { + char s1[100006], s2[100003]; + while (cin >> s1 >> s2) { + int p = strcmp(s1, s2); + int len1 = strlen(s1); + int len2 = strlen(s2); + if (p == 0) { + cout << "-1" << endl; + return 0; + } + if (len1 > len2) + cout << len1 << endl; + else + cout << len2 << endl; + } +} +int n, b, p; +int main() { + cin >> n >> b >> p; + b = b * 2 + 1; + int now = 1; + while (now <= n) { now <<= 1; } + now >>= 1; + int t = n; + long long ans = 0; + while (t > 1) { + ans += 1LL * now / 2 * b; + t -= now / 2; + while (now && now > t) { now >>= 1; } + } + cout << ans << " " << n * p << endl; + return 0; +} +int main() { + int n, c; + cin >> n >> c; + int y; + cin >> y; + int cur = y; + int ans = 1; + int x; + for (int i = 0; i < n - 1; i++) { + cin >> x; + if ((int)abs(cur - x) <= c) { + ans++; + } else { + ans = 1; + } + cur = x; + } + cout << ans << '\n'; +} +int arr[100005]; +int bol(int n) { + while (n % 2 == 0) n /= 2; + while (n % 3 == 0) n /= 3; + return n; +} +set s; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + s.insert(bol(arr[i])); + } + if (s.size() == 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int a[1005]; +int b[1005]; +int main() { + int num, i, j; + int sign1, sign2; + cin >> num; + for (i = 0; i < num; i++) { cin >> a[i]; } + for (i = 0; i < num; i++) { cin >> b[i]; } + i = 0; + int ans = 0; + if (num == 1) + ans = a[0] + b[0]; + else { + for (i = 0; i < num; i++) { + sign1 = a[i]; + sign2 = b[i]; + for (j = i + 1; j < num; j++) { + sign1 = (sign1 | a[j]); + sign2 = (sign2 | b[j]); + if (sign1 + sign2 > ans) ans = sign1 + sign2; + } + } + } + cout << ans << endl; +} +int N; +string S, T, A, B; +int main() { + cin >> A >> B >> N; + cout << A << " " << B << '\n'; + for (int i = 1; i <= N; i++) { + cin >> S >> T; + if (S == A) { + A = T; + } else + B = T; + cout << A << " " << B << '\n'; + } +} +int main() { + int n, m, c, mp = 0, cp = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m >> c; + if (m > c) + mp++; + else if (m < c) + cp++; + } + if (mp > cp) + cout << "Mishka" << endl; + else if (mp < cp) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + string s; + cin >> s; + string a = "aeiou13579"; + int cnt = 0; + for (int i = 0; i < s.size(); i++) { + for (int j = 0; j < a.size(); j++) { + if (s[i] == a[j]) { cnt++; } + } + } + cout << cnt << "\n"; + return 0; +} +int freq[3]; +int main() { + int a, b, mx; + cin >> a; + for (int i = 0; i < a; i++) { + cin >> b; + freq[b - 1]++; + } + mx = max(max(freq[0], freq[1]), freq[2]); + cout << a - mx << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int bs = 0; + int bt = 0; + while (bs < s.size() && s[bs] == '0') { bs++; } + while (bt < t.size() && t[bt] == '0') { bt++; } + if (t.size() - bt > s.size() - bs) { + cout << "<" << endl; + return 0; + } + if (t.size() - bt < s.size() - bs) { + cout << ">" << endl; + return 0; + } + while (bt < t.size() && t[bt] == s[bs]) { + bt++; + bs++; + } + if (bt == t.size()) { + cout << "=" << endl; + return 0; + } + if (t[bt] > s[bs]) { + cout << "<" << endl; + } else if (t[bt] < s[bs]) { + cout << ">" << endl; + } else { + cout << "=" << endl; + } + return 0; +} +const int MAX = 3e5 + 5; +const long long int MAX1 = 1e5 + 9; +const long long int inf = 1e18; +const long long int mod = 1e9 + 7; +string st[MAX][2]; +bool cmp(pair &a, pair &b) { + return (a.first > b.first); +} +map mp; +int main() { + long long int n, m, q; + cin >> q; + while (q--) { + int t; + cin >> t; + if (t == 1) { + long long int w; + cin >> n >> m >> w; + while (n != m) { + if (n < m) swap(n, m); + mp[n] += w; + n /= 2; + } + } else { + cin >> n >> m; + long long int ans = 0; + while (n != m) { + if (n < m) swap(n, m); + ans += mp[n]; + n /= 2; + } + cout << ans << "\n"; + } + } +} +const int MAXN = 1e4 + 4; +int n, a, b; +int main() { + cin >> n >> a >> b; + int ans = 0; + while (a < n) { + a *= b; + ans++; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char **c = new char *[n]; + for (int i = 0; i < n; i++) { c[i] = new char[m]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> c[i][j]; } + } + bool found = false; + int a, i1, j1; + a = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (c[i][j] == 'B') { + i1 = i; + j1 = j; + for (int k = j; k < m; k++) { + a++; + if (c[i][k + 1] == 'W' || k == m - 1) { + found = true; + break; + } + } + } + if (found == true) { break; } + } + if (found == true) { break; } + } + cout << i1 + (a / 2) + 1 << " " << j1 + (a / 2) + 1 << endl; + return 0; +} +int n, k, p, s; +int main() { + cin >> k >> n >> s >> p; + int num = (n / s) * s == n ? n / s : (n / s + 1); + int sum = num * k; + num = (sum / p) * p == sum ? (sum / p) : (sum / p) + 1; + cout << num << endl; +} +int main() { + int x, r = 0; + for (int i = 0; i < 5; ++i) { + cin >> x; + r += x; + } + cout << ((r % 5 == 0 && r > 0) ? r / 5 : -1) << endl; + return 0; +} +const int MOD = 1000000007; +int main() { + int n; + cin >> n; + long long a[2] = {1, 2}; + if (n == 1) { + cout << 1 << endl; + return 0; + } + if (n == 2) { + cout << 3 << endl; + return 0; + } + for (long long i = 0; i < n - 2; ++i) { + int num = i % 2; + a[num] += a[!num] + 1; + a[num] %= MOD; + } + cout << (a[0] + a[1]) % MOD << endl; + return 0; +} +int main() { + int n, k; + int a[105]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + int l = 0; + while (a[l] <= k) l++; + int r = n - 1; + while (a[r] <= k) r--; + int countl = l, countr = n - 1 - r; + if (countl + countr >= n) + cout << n << endl; + else + cout << countl + countr << endl; + return 0; +} +long long n, c1, c2; +long long solve(long long g) { + long long t1 = ceil((double)n / g), t2 = n / g, left = n, res = 0; + for (; t2 * g != left && left > 0; left -= t1, g--) res += (c1 + c2 * (t1 - 1) * (t1 - 1)); + for (; g > 0; left -= t2, g--) res += (c1 + c2 * (t2 - 1) * (t2 - 1)); + return res; +} +int main() { + char t; + cin >> n >> c1 >> c2; + long long p = 0, r = 0, i; + for (i = 0; i < n; i++) { + cin >> t; + (t == '1') ? p++ : r++; + } + long long lo = 1, hi = p; + while (lo < hi) { + long long diff = hi - lo; + long long p1 = lo + diff / 3, p2 = lo + (2 * diff + 2) / 3; + long long s1 = solve(p1), s2 = solve(p2); + if (s1 == s2) + lo = p1 + 1, hi = p2 - 1; + else if (s1 > s2) + lo = p1 + 1; + else + hi = p2 - 1; + } + cout << solve(lo) << endl; +} +int main() { + int p; + cin >> p; + int n = p - 1; + int count = n; + for (int i = 2; i * i <= n; ++i) { + if (n % i == 0) { + do { n /= i; } while (n % i == 0); + count = count / i * (i - 1); + } + } + if (n != 1) { count = count / n * (n - 1); } + cout << count << '\n'; +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + int val = (x * y) / (__gcd(x, y)); + int ans; + if (a % val == 0) { + ans = b / val - a / val + 1; + } else { + ans = b / val - a / val; + } + cout << ans << "\n"; +} +void solve() { + int n, i; + cin >> n; + long long int a, b; + for (i = 0; i < n; i++) { + cin >> a >> b; + long long int ans = 0; + while (a > 0 && b > 0) { + if (a > b) { + ans += a / b; + a %= b; + } else { + ans += b / a; + b %= a; + } + } + cout << ans << '\n'; + } +} +int main() { + int t = 1; + while (t--) solve(); + return 0; +} +int main() { + int arr[10]; + arr[0] = 2; + arr[1] = 7; + arr[2] = 2; + arr[3] = 3; + arr[4] = 3; + arr[5] = 4; + arr[6] = 2; + arr[7] = 5; + arr[8] = 1; + arr[9] = 2; + int m; + cin >> m; + int a = m / 10; + int b = m % 10; + cout << arr[a] * arr[b] << endl; +} +int main() { + int n, m, flag = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else { + if (flag == 0) { + if (j == m) { + cout << "#"; + } else { + cout << "."; + } + } else { + if (j == 1) { + cout << "#"; + } else { + cout << "."; + } + } + } + } + cout << endl; + if (i % 2 == 0) { + if (flag == 0) { + flag = 1; + } else { + flag = 0; + } + } + } +} +void ChuyenDoi(string s, string &a) { + a = "000000000000000000"; + int i = s.length() - 1; + int ma = a.length() - 1; + while (i >= 0) { + a[ma] = s[i] % 2 + 48; + i--; + ma--; + } +} +int main() { + int t; + cin >> t; + map flat; + map::iterator p; + for (int i = 0; i < t; i++) { + string s, a; + char sign; + cin >> sign >> s; + ChuyenDoi(s, a); + if (sign == '+') + flat[a]++; + else if (sign == '-') { + flat[a]--; + if (flat[a] == 0) flat.erase(a); + } else { + cout << flat[a] << endl; + } + } +} +int main() { + long long n; + cin >> n; + cout << 25 << endl; + return 0; +} +void Genawy() {} +int main() { + Genawy(); + long long n, m, mod = 1e9 + 9; + cin >> n >> m; + long long p = 1; + for (int i = 0; i < m; i++) p = (p * 2) % mod; + long long ans = 1; + for (int i = 1; i <= n; i++) { ans = (ans * ((p - i + mod) % mod)) % mod; } + cout << ans << endl; + return 0; +} +int n, c; +int main() { + cin >> n; + while (n > 0) { + n /= 2; + c++; + } + cout << c << endl; +} +int a, b, c, n; +int main() { + cin >> n >> a >> b >> c; + if (c > a || c > b || n == 1) + cout << min(a, b) * (n - 1) << endl; + else + cout << min(a, b) + c * (n - 2) << endl; +} +int main() { + bool ya = false; + vector a; + int n, res = INT_MAX; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + } + for (int i = 1; i < n; i++) { + if (s[i] == 'L' && s[i - 1] == 'R') { + res = min(res, a[i] - a[i - 1]); + ya = true; + } + } + (ya) ? cout << res / 2 << endl : cout << -1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int k = s.length(); + cout << (k + 1) * 25 + 1 << endl; +} +int main() { + long long n; + cin >> n; + long long a[107]; + for (int i = 0; i < n; i++) cin >> a[i]; + vector v; + for (int from = 0; from < n; from++) { + for (int to = from; to < n; to++) { + long long ans = a[from]; + for (int i = from + 1; i <= to; i++) { ans = ans ^ a[i]; } + v.push_back(ans); + } + } + sort(v.begin(), v.end()); + cout << v[v.size() - 1] << endl; +} +int main() { + int k, n, s, p, ans, sum; + cin >> k >> n >> s >> p; + if (n % s == 0) + sum = n / s; + else + sum = n / s + 1; + sum = sum * k; + if (sum % p == 0) + ans = sum / p; + else + ans = sum / p + 1; + cout << ans << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long n; + cin >> n; + long long sum = 0; + long long temp; + for (long long i = 0; i < n; i++) { + cin >> temp; + if (temp > b && temp < c) sum++; + } + cout << sum << '\n'; + return 0; +} +int main() { + int l, p, q; + cin >> l >> p >> q; + cout << l * p / (double)(p + q) << endl; + return 0; +} +int arr[1000]; +int main() { + int n; + while (cin >> n) { + int total = 0; + memset(arr, 0, sizeof(arr)); + for (int i = 0; i < n; i++) { + cin >> arr[i]; + total += arr[i]; + } + int s, t; + cin >> s >> t; + int tmp; + if (s > t) { + tmp = s; + s = t; + t = tmp; + } + s--; + t--; + int a1 = 0, a2 = 0; + for (int i = s; i < t; i++) { a1 += arr[i]; } + a2 = total - a1; + cout << min(a2, a1) << endl; + } +} +int main() { + int n, k, x, a; + cin >> n >> k >> x; + x = x * k; + for (int i = 0; i < n - k; i++) { + cin >> a; + x += a; + } + cout << x << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool bisa = false; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) { + int a; + cin >> a; + if (a == 1 && (i == 1 or i == n or j == 1 or j == m)) bisa = true; + } + if (bisa) + cout << 2; + else + cout << 4; + cout << endl; +} +int n, x, dif = 0, result = 1e9; +vector v; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> x; + v.push_back(x); + if (i != 0) dif = max(dif, v[i] - v[i - 1]); + } + for (int i = 1; i < v.size() - 1; ++i) { result = min(result, v[i + 1] - v[i - 1]); } + if (result < dif) + cout << dif << endl; + else + cout << result << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v; + int count = 0; + int ara[n]; + for (int i = 0; i < n; i++) { cin >> ara[i]; } + for (int i = 1; i < n; i++) { + if (ara[0] <= ara[i]) { v.push_back(ara[i]); } + } + int flag = 0, s = v.size(); + if (s == 0) { + cout << "0" << endl; + } else { + while (1) { + flag = 0; + sort(v.begin(), v.end()); + if (ara[0] <= v[s - 1]) { + ara[0]++; + v[s - 1]--; + count++; + flag = 1; + } + if (flag == 0) { break; } + } + cout << count << endl; + } +} +int main() { + short a, b, p, q, r, s; + cin >> p >> q >> r >> s >> a >> b; + short ans = 0; + for (int i = a; i <= b; i++) { + if (((((i % p) % q) % r) % s) == i) ans++; + } + cout << ans << endl; + return 0; +} +map str; +int main() { + int t; + cin >> t; + int ans = 0; + for (int i = 0; i < t; i++) { + string s; + cin >> s; + str[s]++; + } + for (int i = 0; i < t; i++) { + string s; + cin >> s; + if (str[s] > 0) { + str[s]--; + } else { + ans++; + } + } + cout << ans << endl; +} +int main() { + int l, r, a; + while (cin >> l >> r >> a) { + if (l > r) swap(l, r); + if (l + a <= r) + cout << 2 * (l + a) << endl; + else + cout << (l + a + r) / 2 * 2 << endl; + } + return 0; +} +int main() { + int n, m, i, x, a, b, c = 0; + cin >> n >> m; + x = sqrt(n); + for (i = 0; i <= x; i++) { + b = n - i * i; + a = m - b * b; + if (a == i) { c++; } + } + cout << c << endl; + return 0; +} +void fastIo() {} +int main() { + fastIo(); + int n; + cin >> n; + int sum = 0; + int a[13]; + for (int i = 0; i < 12; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum < n) { + cout << "-1" << endl; + } else { + sort(a, a + 12); + int indx = 11; + sum = 0; + while (sum < n) { + sum += a[indx]; + indx--; + } + cout << 11 - indx << endl; + } + return 0; +} +int c[2000]; +int k, a, b, v; +int main() { + cin >> k >> a >> b >> v; + int i = 0; + while (b >= k - 1) { + c[i++] = k; + b -= k - 1; + } + c[i] = b % (k - 1) + 1; + i = 0; + int s = 0; + while (s < a) { + if (c[i] == 0) c[i] = 1; + s += c[i] * v; + i++; + } + cout << i << endl; + return 0; +} +int main() { + int n, m; + int r[105] = {0}; + int c[105] = {0}; + cin >> n >> m; + string mpp[105]; + for (int i = 0; i < n; i++) { + cin >> mpp[i]; + for (int j = 0; j < mpp[i].length(); j++) + if (mpp[i][j] == '*') { + r[i]++; + c[j]++; + } + } + int ansx = -1, ansy = -1; + for (int i = 0; i < n; i++) + if (r[i] == 1) ansx = i + 1; + for (int i = 0; i < m; i++) + if (c[i] == 1) ansy = i + 1; + cout << ansx << " " << ansy << "\n"; + return 0; +} +int main() { + int n, total = 0, s; + cin >> n; + if (n >= 5) { + total = n / 5; + s = n % 5; + } else if (n >= 4) { + total = n / 4; + s = n % 4; + } else if (n >= 3) { + total = n / 3; + s = n % 3; + } else if (n >= 2) { + total = n / 2; + s = n % 2; + } else if (n == 1) { + total = 1; + s = 0; + } + while (s > 0) { + if (s % 5 == 0) { + total = total + (s / 5); + s = s % 5; + } else if (s % 4 == 0) { + total = total + (s / 4); + s = s % 4; + } else if (s % 3 == 0) { + total = total + (s / 3); + s = s % 3; + } else if (s % 2 == 0) { + total = total + (s / 2); + s = s % 2; + } else if (s == 1) { + total++; + s = 0; + } + } + cout << total << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[105] = {0}; + getchar(); + while (n--) { + int t; + cin >> t; + int c; + while (t--) { + cin >> c; + a[c] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 1) + cout << 1 << endl; + else + cout << 2 << endl; +} +void fastio() {} +int main() { + fastio(); + long long n, m; + cin >> n >> m; + for (long long i = 0; i < n; i++) { + if (i % 2 == 0) { + for (long long j = 0; j < m; j++) cout << "#"; + cout << endl; + } else { + if ((i + 1) % 4 != 0) { + for (long long j = 0; j < m - 1; j++) cout << "."; + cout << "#"; + } else { + cout << "#"; + for (long long j = 0; j < m - 1; j++) cout << "."; + } + cout << endl; + } + } +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (int i = x; i <= y; i++) { + if (k * i >= l && k * i <= r) { + cout << "YES" << endl; + goto end; + } + } + cout << "NO" << endl; +end:; + return 0; +} +int main() { + int n; + cin >> n; + string s; + string lcp; + for (int i = 0; i < n; i++) { + cin >> s; + if (i == 0) { + lcp = s; + } else { + bool match = true; + for (int j = 0; j < lcp.length() && match; j++) { + if (lcp[j] != s[j]) { + match = false; + lcp = lcp.substr(0, j); + } + } + } + } + cout << lcp.length() << "\n"; + return 0; +} +int main() { + int k; + int i[12]; + int test = 0; + int count = 0; + int temp = 0; + cin >> k; + for (int a = 0; a < 12; a++) { cin >> i[a]; } + if (k == 0) + cout << 0 << endl; + else { + for (int d = 0; d < 12; d++) { + for (int f = 0; f < 11 - d; f++) { + if (i[f + 1] > i[f]) { + temp = i[f + 1]; + i[f + 1] = i[f]; + i[f] = temp; + } + } + } + for (int a = 0; a < 12; a++) { + test += i[a]; + count++; + if (test == k || test > k) { break; } + } + if (test == 0 || test < k) + cout << -1 << endl; + else + cout << count << endl; + } + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + int c = 0; + for (int i = 1; i <= n; i++) { + if (x % i == 0 and x <= n * i) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + string s; + cin >> s; + int c = 0, k = 0; + string ans = "no"; + reverse(s.begin(), s.end()); + if (s.length() < 7) { + cout << ans << endl; + } else { + for (int i = 0; i < s.length(); i++) { + if (s[i] == '0') { + c++; + if (c == 6) { + k = i; + break; + } + } + } + if (k != 0) { + for (int j = k + 1; j < s.length(); j++) { + if (s[j] == '1') { + ans = "yes"; + break; + } else { + continue; + } + } + } + cout << ans << endl; + } + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +string he; +vector me(5); +bool OK(string a, string b) { + return a[0] == b[0] || a[1] == b[1]; +} +int main() { + cin >> he; + for (int i = 0; i < 5; ++i) cin >> me[i]; + for (int i = 0; i < 5; ++i) + if (OK(he, me[i])) { + cout << "YES\n"; + exit(0); + } + cout << "NO\n"; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +int n; +string x; +map m; +int main() { + cin >> n >> x; + for (int i = 0; i < n; i++) m[x[i] - '0']++; + int s = x.size(); + cout << min(m[8], s / 11) << endl; +} +int main() { + long long n, m; + cin >> n >> m; + if (n > 31) + cout << m << endl; + else + cout << m % (1 << n) << endl; + return 0; +} +int a[5][5], c[5][5]; +int main() { + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cin >> a[i][j]; } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + if (a[i][j] % 2 == 1) { + c[i + 1][j]++; + c[i - 1][j]++; + c[i][j + 1]++; + c[i][j - 1]++; + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { a[i][j] += c[i][j]; } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + if (a[i][j] % 2 == 1) { + cout << 0; + } else + cout << 1; + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector arr(n); + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr.begin(), arr.end()); + vector diff; + for (int i = 1; i < n; i++) diff.push_back(arr[i] - arr[i - 1]); + int p = *min_element(diff.begin(), diff.end()); + int count = 0; + for (int i = 0; i < diff.size(); i++) { + if (diff[i] == p) count++; + } + cout << p << " " << count << endl; +} +int my_gcd(int x, int y) { + if (x == 0) { return y; } + return my_gcd(y % x, x); +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int lcm = n * m / my_gcd(n, m); + cout << z / lcm << endl; + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +int main() { + long long a, b, sa = 0, sb = 0, pre = 0; + cin >> a >> b; + long long lcm = (a * b) / __gcd(a, b); + int f = 0; + if (a > b) { + swap(a, b); + f = 1; + } + for (int i = 1; i * b <= lcm; i++) { + if ((b * i) % a != 0) + sb += b * i - ((b * i) / a) * a; + else + sb += a; + } + sa = lcm - sb; + if (f == 0) { + if (sa > sb) + cout << "Dasha" << endl; + else if (sa == sb) + cout << "Equal" << endl; + else + cout << "Masha" << endl; + } else { + if (sa < sb) + cout << "Dasha" << endl; + else if (sa == sb) + cout << "Equal" << endl; + else + cout << "Masha" << endl; + } +} +map mp1, mp2; +int main() { + mp1.clear(); + mp2.clear(); + int n, ans = 0; + string s[105]; + string str; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + mp1[s[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> str; + if (!mp1[str]) + ans++; + else + mp2[str]++; + } + for (int i = 0; i < n; i++) + if (mp2[s[i]] - mp1[s[i]] > 0) ans += mp2[s[i]] - mp1[s[i]], mp2[s[i]] = -1; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int u[n], l[n], flag = 0; + int sumu = 0, suml = 0; + for (int i = 0; i < n; i++) { + cin >> u[i] >> l[i]; + sumu += u[i]; + suml += l[i]; + } + if ((sumu + suml) % 2 != 0) + cout << "-1\n"; + else if (sumu % 2 == 0 && suml % 2 == 0) + cout << "0\n"; + else { + for (int i = 0; i < n; i++) { + if ((u[i] % 2 == 0 && l[i] % 2 == 1) || (u[i] % 2 == 1 && l[i] % 2 == 0)) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "1\n"; + else + cout << "-1\n"; + } +} +int a[1000]; +int b[1000]; +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + cin >> b[i]; + } + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + if (a[i] == b[j]) sum++; + if (a[j] == b[i]) sum++; + } + } + cout << sum << endl; +} +int main() { + string first_team, second_team; + size_t first_points = 0, second_points = 0; + getline(cin, first_team); + getline(cin, second_team); + for (size_t i = 0; i < first_team.length(); i += 2) { + if (first_team[i] == second_team[i]) { continue; } + if (first_team[i] == '[') { + if (second_team[i] == '8') { + second_points += 1; + } else { + first_points += 1; + } + } else if (first_team[i] == '(') { + if (second_team[i] == '[') { + second_points += 1; + } else { + first_points += 1; + } + } else if (first_team[i] == '8') { + if (second_team[i] == '(') { + second_points += 1; + } else { + first_points += 1; + } + } + } + if (first_points == second_points) { + cout << "TIE" << endl; + } else { + int winner = first_points > second_points ? 1 : 2; + cout << "TEAM " << winner << " WINS" << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (m % n != 0) + cout << m / n + 1 << endl; + else + cout << m / n << endl; +} +int main() { + int a[101], n, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + int t = 0; + for (int j = i; j < n; j++) { + t ^= a[j]; + ans = max(ans, t); + } + } + cout << ans << endl; + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + int count = 0; + string s, check; + cin >> s; + s.append("0"); + check += s.at(0); + for (int i = 1; i < s.size(); i++) { + if (s.at(i) == check.at(check.size() - 1)) { + check += s.at(i); + } else if (s.at(i) == '0') { + if (check.size() % 2 == 0) { + count++; + check.clear(); + check += s.at(i); + } else { + check.clear(); + check += s.at(i); + } + } else { + if (check.size() % 2 == 0) { + count++; + check.clear(); + check += s.at(i); + } else { + check.clear(); + check += s.at(i); + } + } + } + cout << count << endl; +} +long long arr[3]; +int main() { + long long side[3], n; + cin >> side[0] >> side[1] >> side[2] >> n; + n = min((side[0] - 1) + (side[1] - 1) + (side[2] - 1), n); + sort(side, side + 3); + long long div = n / 3; + for (int i = 0; i < 3; ++i) { + long long val = min(div, side[i] - 1); + n -= val; + arr[i] += val; + } + if (arr[1] == side[1] - 1) { + arr[2] += n; + } else { + long long val = min(side[1] - 1 - arr[1], n / 2); + n -= val; + arr[1] += val; + arr[2] += n; + } + cout << (arr[0] + 1) * (arr[1] + 1) * (arr[2] + 1) << endl; + return 0; +} +int main() { + char a[101], b[101]; + cin >> a; + cin >> b; + int len; + len = strlen(a); + for (int i = 0; i < len; i++) { + cout << (a[i] != b[i] ? 1 : 0); + if (i == len - 1) { cout << endl; } + } +} +int main() { + long long n; + cin >> n; + long long A[n / 2]; + for (long long i = 0; i < n / 2; i++) cin >> A[i]; + long long a = 0, aa = 0; + long long p = n / 2; + sort(A, A + p); + for (long long i = 0; i < n / 2; i++) { + a += abs(A[i] - (i * 2 + 1)); + aa += abs(A[i] - (i * 2 + 2)); + } + cout << min(a, aa) << "\n"; + return 0; +} +vector v; +int main() { + string x; + cin >> x; + long long n, i; + string y; + cin >> n; + while (n--) { + cin >> y; + v.push_back(y); + } + sort(v.begin(), v.end()); + for (i = 0; i < v.size(); i++) { + long long f = v[i].find(x); + if (f == 0) { + cout << v[i] << "\n"; + return 0; + } + } + cout << x << "\n"; +} +int n, m, arr[51][51]; +int main() { + cin >> n >> m; + int first = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> arr[i][j]; + if ((i == 0 || j == 0 || i == n - 1 || j == m - 1) && arr[i][j] == 1) first = 1; + } + } + cout << (first ? 2 : 4) << endl; + return 0; +} +int main() { + int n, k, x, y, c = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + c += (y - x) + 1; + } + cout << (k - (c % k)) % k << endl; + return 0; +} +bool isPrime(int a) { + for (int i = 2; i * i <= a; i++) { + if (a % i == 0) return false; + } + return true; +} +int main() { + int n, m; + cin >> n >> m; + if (n < 4) { + if (n == 2) { + if (m == 3) { + cout << "YES\n"; + return 0; + } else { + cout << "NO\n"; + return 0; + } + } else if (n == 3) { + if (m == 5) { + cout << "YES\n"; + return 0; + } else { + cout << "NO\n"; + return 0; + } + } + } + if (isPrime(n) && isPrime(m)) { + if (n > 4) { + for (int i = n + 1; i <= m - 1; i++) { + if (isPrime(i)) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + int n, a, b, sum1 = 0, sum2 = 0; + cin >> n; + while (n--) { + cin >> a >> b; + if (a > b) { + sum1++; + } else if (a < b) { + sum2++; + } + } + if (sum1 > sum2) { + cout << "Mishka" << endl; + } else if (sum1 < sum2) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +char a[64]; +int main() { + for (int i = 0; i < 64; i++) cin >> a[i]; + int c = 0; + for (int i = 0; i < 7; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 8; i < 15; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 16; i < 23; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 24; i < 31; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 32; i < 39; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 40; i < 47; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 48; i < 55; i++) { + if (a[i] == a[i + 1]) c++; + } + for (int i = 56; i < 63; i++) { + if (a[i] == a[i + 1]) c++; + } + if (c == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int i, j = 1, k = 0, n, s = 0, t = 0, m, u, r, d; + cin >> n; + long long int x[50]; + m = n; + for (i = 0; m != 0; i++) m = m / 10; + for (j = 9 * i; j >= 0; j--) { + t = n - j; + s = t; + m = t; + for (; t != 0;) s += t % 10, t = t / 10; + if (s == n) x[k++] = m; + } + cout << k << "\n"; + for (i = 0; i < k; i++) cout << x[i] << "\n"; +} +int main() { + int n, k, c; + int a[500]; + cin >> n >> k >> c; + for (int i = 0; i < c; i++) cin >> a[i]; + int j = 0; + int cnt = 0; + int diff = 0; + for (int i = 1; i <= n; i++) { + if (i == a[j]) { + j++; + cnt++; + diff = 0; + } else { + diff++; + if (diff == k) { + cnt++; + diff = 0; + } + } + } + cout << cnt << endl; + return 0; +} +int main() { + int a, b, e = 0, f = 0, k = 0; + cin >> a >> b; + int c[a + 1], d[b + 1]; + for (int i = 0; i < b; i++) { + k = 0; + e = 0; + for (int j = 0; j < a; j++) { + cin >> c[j]; + e = max(e, c[j]); + } + for (int j = 0; j < a; j++) { + if (k == 0) { + if (c[j] == e) { + d[i] = j + 1; + if (b == 1) { + cout << d[i] << endl; + return 0; + } + k = 1; + } + } + } + } + sort(d, d + b); + e = 0; + for (int i = 0; i < b - 1; i++) { + if (d[i] == d[i + 1]) { + e++; + } else { + f = max(e, f); + e = 0; + } + } + f = max(e, f); + e = 0; + for (int i = 0; i < b - 1; i++) { + if (d[i] == d[i + 1]) { + e++; + if (e == f) { + cout << d[i] << endl; + return 0; + } + } else { + e = 0; + } + } + cout << "1" << endl; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << max(0, a[2] + 1 - (a[0] + a[1])) << endl; + return 0; +} +int main() { + string s, S, s1, S1; + cin >> s >> S; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= '1' && s[i] <= '9') { + s1.assign(s, i, s.size()); + break; + } + } + for (int i = 0; i < S.size(); i++) { + if (S[i] >= '1' && S[i] <= '9') { + S1.assign(S, i, S.size()); + break; + } + } + if (s1.size() > S1.size()) + cout << '>' << endl; + else if (S1.size() > s1.size()) + cout << '<' << endl; + else if (s1 > S1) + cout << '>' << endl; + else if (S1 > s1) + cout << '<' << endl; + else + cout << "=" << endl; + return 0; +} +int main() { + int n, k; + map book; + cin >> n >> k; + int tables[n + 1]; + book[-1] = book[1] = 0; + for (int i = 0; i < n; i++) { + cin >> tables[i]; + book[tables[i]]++; + } + int maxSol = 0; + for (int b = 0; b < k; b++) { + map cnt = book; + for (int i = b; i < n; i += k) cnt[tables[i]]--; + if (maxSol < fabs(cnt[-1] - cnt[1])) maxSol = fabs(cnt[-1] - cnt[1]); + } + cout << maxSol << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n == 0) cout << "O-|-OOOO\n"; + while (n > 0) { + if (n % 10 == 0) cout << "O-|-OOOO\n"; + if (n % 10 == 1) cout << "O-|O-OOO\n"; + if (n % 10 == 2) cout << "O-|OO-OO\n"; + if (n % 10 == 3) cout << "O-|OOO-O\n"; + if (n % 10 == 4) cout << "O-|OOOO-\n"; + if (n % 10 == 5) cout << "-O|-OOOO\n"; + if (n % 10 == 6) cout << "-O|O-OOO\n"; + if (n % 10 == 7) cout << "-O|OO-OO\n"; + if (n % 10 == 8) cout << "-O|OOO-O\n"; + if (n % 10 == 9) cout << "-O|OOOO-\n"; + n /= 10; + } + return 0; +} +int main() { + int w, h, w1, h1, w2, h2; + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w < 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w < 0) w = 0; + } + } + cout << w << endl; + return 0; +} +int n, a[10005]; +int main() { + cin >> n; + int cnt = n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + sort(a + 1, a + n + 1); + for (int i = 1, j = 1; i <= n; ++i) { + if (a[i] == 0) { cnt--; } + while (a[i] == a[i + j] && a[i] != 0) { + cnt--; + i++; + } + j = 1; + } + cout << cnt << endl; + return 0; +} +const long double EPS = 1e-9; +const long long MOD = 1e9 + 7; +int v[100100], h[100100]; +bool can_do(int mid2, int n, int n2) { + for (int i = 0; i < min(n, mid2); i++) { + int lo = 0, hi = n2 - 1; + while (lo <= hi) { + int mid = lo + (hi - lo) / 2; + if (h[mid] >= v[i]) + hi = mid - 1; + else + lo = mid + 1; + } + hi++; + if (i + (n2 - hi) <= mid2) return true; + } + return false; +} +int main() { + cout << setprecision(20); + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> v[i]; + v[n++] = 1e9; + int iter = 0; + for (int i = 0; i < m; i++) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 != 1) continue; + h[iter++] = x2; + } + int n2 = iter; + sort(v, v + n); + sort(h, h + n2); + int ans = 1e9; + for (int i = 0; i < n; i++) { + int lo = 0, hi = n2 - 1; + while (lo <= hi) { + int mid = lo + (hi - lo) / 2; + if (h[mid] >= v[i]) + hi = mid - 1; + else + lo = mid + 1; + } + hi++; + ans = min(ans, i + n2 - hi); + } + cout << ans << '\n'; + return 0; +} +bool vowel(char ch) { + if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { + return true; + } else { + return false; + } +} +bool even(char ch) { + if (ch == '1' || ch == '3' || ch == '5' || ch == '7' || ch == '9') { + return true; + } else { + return false; + } +} +int main() { + string s; + cin >> s; + int len = s.size(); + int count = 0; + for (int i = 0; i < len; i++) { + char ch = s[i]; + if (vowel(ch)) { count++; } + if (even(ch)) { count++; } + } + cout << count << endl; + return 0; +} +const long long int INF = (long long)8e18; +const long long int MOD = 998244353; +int main() { + int n, m; + cin >> n >> m; + int freq[n + 1] = {0}; + int f_ans = -1; + for (int i = 0; i < m; i++) { + int ans = 0; + int maxi = -1; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > maxi) { + maxi = x; + ans = i + 1; + } + } + freq[ans]++; + } + for (int i = 0; i < n + 1; i++) f_ans = max(f_ans, freq[i]); + for (int i = 0; i < n + 1; i++) + if (freq[i] == f_ans) { + f_ans = i; + break; + } + cout << f_ans << '\n'; + return 0; +} +int main() { + int a, b, c, d, e; + cin >> a >> b >> c >> d >> e; + int sum = a + b + c + d + e; + if (sum == 0) + cout << -1 << endl; + else if (sum % 5 == 0) + cout << sum / 5 << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int cons = 0; + int max = 0; + string line; + getline(cin, line); + for (int i = 0; i < d; i++) { + getline(cin, line); + int j; + for (j = 0; j < n; j++) { + if (line[j] == '0') break; + } + if (j != n) { + cons++; + if (cons > max) max = cons; + } else { + cons = 0; + } + } + cout << max << endl; + return 0; +} +int main() { + int x, y, x1, y1, x2, y2; + cin >> x >> y; + if (x < 0 && y < 0) { + cout << x + y << " 0 0 " << x + y; + } else if (x < 0 && y > 0) { + cout << -(-x + y) << " 0 0 " << -x + y; + } else if (x > 0 && y < 0) { + cout << 0 << " " << -(-y + x) << " " << -y + x << " " << 0; + } else { + cout << 0 << " " << x + y << " " << x + y << " " << 0; + } + cout << endl; + return 0; +} +int main() { + int a[100]; + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int cnt = 0; + for (int i = 0; i < n; i++) { + if (a[i] > k) { break; } + cnt++; + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] > k) { break; } + cnt++; + } + if (cnt > n) cnt /= 2; + cout << cnt << endl; + return 0; +} +int main() { + vector vec; + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int ovarall = k * l; + int enough = ovarall / nl; + int toast = c * d; + int salt = p / np; + int m = min(enough, min(toast, salt)); + cout << m / n << endl; + return 0; +} +int main() { + long long p, x = 1, c = 0, num = 1, mod; + bool b = 0; + cin >> p; + mod = p; + for (long long i = 1; i < p; i++) { + b = 0; + num = i; + for (long long j = 1; j <= p - 2; j++) { + if ((num - 1) % p == 0) { + b = 1; + break; + } + num = ((num % mod) * (i % mod)) % mod; + } + if (!b) { + if ((num - 1) % p == 0) c++; + } + } + cout << c << endl; + return 0; +} +int main() { + long long casos, a, b, r, o; + cin >> casos; + while (casos--) { + cin >> a >> b; + r = 0; + while ((a > 0) && (b > 0)) { + if (a > b) { + o = (((a - b) / b) + 1); + r += o; + a -= (o * b); + } else if (a < b) { + o = (((b - a) / a) + 1); + r += o; + b -= (o * a); + } else { + a -= b; + r++; + } + } + cout << r << "\n"; + } + return 0; +} +int main() { + long long n; + cin >> n; + cout << 2 - n % 2 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long x; + x = n / 2 / (k + 1); + cout << x << " " << x * k << " " << n - x * k - x << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + int tenth = n / 10; + int unit = n % 10; + int list[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int x = list[tenth] * list[unit]; + cout << x << endl; + return 0; +} +int main() { + int in, ans = 25; + cin >> in; + cout << ans << endl; + return 0; +} +int main() { + string s, s2; + int n, ans = 0; + cin >> n >> s >> s2; + for (int i = 0; i < n; i++) { + int x = s[i] - 48; + int y = s2[i] - 48; + if (y > x) swap(x, y); + ans += min(abs(x - y), min(((10 - x) + y), (x + y))); + } + cout << ans << endl; +} +int main() { + string a; + cin >> a; + long long n = a.size(); + long long answer = 0; + for (int z = 0; z < n; z++) { + if (a[z] != 'Q') continue; + for (int x = z + 1; x < n; x++) { + if (a[x] != 'A') continue; + for (int y = x + 1; y < n; y++) { + if (a[y] == 'Q') answer++; + } + } + } + cout << answer << endl; + cin >> a; +} +int a; +bool eight(int x) { + if (x < 0) x = -x; + while (x != 0) { + if (x % 10 == 8) return true; + x /= 10; + } + return false; +} +int main() { + cin >> a; + for (int i = 1; i < 100; i++) { + if (eight(a + i)) { + cout << i << endl; + return 0; + ; + } + } + return 0; +} +long long int i, j, t; +int main() { + cout << setprecision(8); + long long int n, s, x, f = 0; + cin >> n >> s; + long long int h[n], m[n], b[n]; + for (i = 0; i < n; i++) { + cin >> h[i] >> b[i]; + m[i] = b[i]; + m[i] += h[i] * 60; + m[i]++; + } + x = (m[0] - 1); + if (x > s) { + x = 0 + s; + j = x / 60; + j = x - j * 60; + cout << "0 0" << endl; + f = 1; + return 0; + } + for (i = 1; i < n; i++) { + x = (m[i] - m[i - 1]); + if (x / 2 > s) { + x = m[i - 1] + s; + j = x / 60; + j = x - j * 60; + cout << (long long int)x / 60 << " " << j << endl; + f = 1; + break; + } + } + if (f == 0) { + x = m[n - 1] + s; + j = x / 60; + j = x - j * 60; + cout << (long long int)x / 60 << " " << j << endl; + } + return 0; +} +char ch1, ch2, s[105]; +long long n, m, x, y; +int main() { + cin >> n >> m; + getchar(); + gets(s + 1); + for (int i = 1; i <= m; i++) { + cin >> x >> y >> ch1 >> ch2; + for (int j = x; j <= y; j++) + if (s[j] == ch1) s[j] = ch2; + } + cout << s + 1 << endl; +} +int main() { + int n; + cin >> n; + int count = 0; + while (n-- != 0) { + int x, y, z; + cin >> x >> y >> z; + if (x + y + z > 1) count++; + } + cout << count << endl; + return 0; +} +const int MX = 2e5 + 7; +const int inf = 0x3f3f3f3f; +int n, k; +int a[6], b[6]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[x]++; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b[x]++; + } + bool flag = 1; + for (int i = 1; i <= 5; i++) { + int m = a[i] + b[i]; + if (m % 2) { + flag = 0; + break; + } + } + if (!flag) + puts("-1"); + else { + int ans = 0; + for (int i = 1; i <= 5; i++) { + int sum = (a[i] + b[i]) / 2; + ans += abs(sum - a[i]); + } + cout << ans / 2 << endl; + } + return 0; +} +int main() { + int Q[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int w, sum; + sum = 0; + cin >> w; + if (w <= 0) { + sum = 2 * Q[w]; + } else { + int e = w / 10; + int r = w % 10; + sum = Q[e] * Q[r]; + } + cout << sum << endl; + return 0; +} +int main() { + int mp[105][105] = {0}; + int a, b, x, y, n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> x >> y; + for (int i = a; i <= x; i++) + for (int j = b; j <= y; j++) ++mp[i][j]; + } + int sum = 0; + for (int i = 0; i <= 100; i++) + for (int j = 0; j <= 100; j++) sum += mp[i][j]; + cout << sum << endl; + return 0; +} +int main() { + string s; + int n, x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0; + cin >> n; + getline(cin, s); + cout << 6 - n << endl; + for (int i = 0; i < n; i++) { + getline(cin, s); + if (s[0] == 'p') x1 = 1; + if (s[0] == 'g') x2 = 1; + if (s[0] == 'b') x3 = 1; + if (s[0] == 'o') x4 = 1; + if (s[0] == 'r') x5 = 1; + if (s[0] == 'y') x6 = 1; + } + if (!x1) cout << "Power" << endl; + if (!x2) cout << "Time" << endl; + if (!x3) cout << "Space" << endl; + if (!x4) cout << "Soul" << endl; + if (!x5) cout << "Reality" << endl; + if (!x6) cout << "Mind" << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long double s; + s = (-1 + sqrt(1 + 8 * n)) / 2; + long long int sq = ceil(s); + long long int p = sq - 1; + p = n - (p * (p + 1) / 2); + cout << p << endl; + return 0; +} +int main() { + int n; + cin >> n; + n = 0; + for (char c = '1'; c != '0' && cin >> c; ++n) + ; + cout << n << '\n'; +} +int main() { + int n, t, a[200], ans = 0; + cin >> n >> t; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + ans += 86400 - a[i]; + if (ans >= t) { + cout << i << endl; + break; + } + } + return 0; +} +bool checkDigit(long temp) { + temp = abs(temp); + int l; + while (temp > 0) { + l = temp % 10; + if (l == 8) { return true; } + temp = temp / 10; + } + return false; +} +int main() { + long a; + cin >> a; + for (int i = 1;; i++) { + long temp = a + i; + if (checkDigit(temp)) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + long long n; + long long x; + cin >> n >> x; + int cnt = 0; + for (int i = 1; i <= n; i++) { + if (x % i == 0 && x <= i * n) cnt++; + } + cout << cnt << endl; + return 0; +} +int matriz[110][110]; +int main() { + int n, m, suma; + string aux; + memset(matriz, -1, sizeof matriz); + cin >> n >> m; + getline(cin, aux); + for (int i = int(0); i < int(n); i++) { + getline(cin, aux); + for (int j = int(0); j < int(m); j++) { matriz[i][j] = int(aux[j]) - 48; } + } + int prom = 0; + bool pass = true; + for (int i = int(0); i < int(n); i++) { + suma = 0; + for (int j = int(0); j < int(m - 1); j++) { + if (matriz[i][j + 1] == matriz[i][j]) + pass = pass && true; + else + pass = false; + } + } + if (pass) { + for (int k = int(0); k < int(n - 1); k++) { + if (matriz[k][0] != matriz[k + 1][0]) + pass = pass && true; + else + pass = false; + } + } + if (pass) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long x, y; + long long x1, x2; + long long y1, y2; + cin >> x >> y; + if (x >= 0 && y >= 0) { + x1 = 0; + y1 = x + y; + x2 = x + y; + y2 = 0; + } + if (x < 0 && y < 0) { + x1 = x + y; + y1 = 0; + x2 = 0; + y2 = x + y; + } + if (x < 0 && y >= 0) { + x1 = x - y; + y1 = 0; + x2 = 0; + y2 = -(x - y); + } + if (x >= 0 && y < 0) { + x1 = 0; + y1 = -(x - y); + x2 = x - y; + y2 = 0; + } + cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl; + return 0; +} +const long long maxn = 1e7 + 10; +string s; +int main() { + while (cin >> s) { + int len = s.length(); + int l, r; + int ans = 0; + for (int i = 0; i < len; i++) { + l = 0; + r = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + l++, r++; + else if (s[j] == ')') + l--, r--; + else + l--, r++; + if (r < 0) break; + if (l < 0) l += 2; + if (l == 0) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + int a[1000]; + cin >> n; + for (int i = 0; i < n / 2; i++) cin >> a[i]; + sort(a, a + n / 2); + int sum_black = 0; + int sum_white = 0; + for (int i = 0; i < n / 2; i++) sum_black += abs(a[i] - (2 * i + 1)); + for (int i = 0; i < n / 2; i++) sum_white += abs(a[i] - (2 * i + 2)); + if (sum_black > sum_white) + cout << sum_white << endl; + else + cout << sum_black << endl; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int fi, ti, maxx = INT_MIN; + for (long long int i = 0; i < n; i++) { + cin >> fi >> ti; + if (ti > k) + maxx = max(maxx, fi - (ti - k)); + else + maxx = max(maxx, fi); + } + cout << maxx << endl; +} +int main() { + int ab, bc, ca, a, b, c, s; + cin >> ab >> bc >> ca; + a = sqrt((ab * ca) / bc); + b = sqrt((bc * ab) / ca); + c = sqrt((ca * bc) / ab); + s = 4 * (a + b + c); + cout << s << endl; +} +int main() { + int test, m, n, res, modu; + cin >> test; + while (test--) { + res = 0; + cin >> n >> m; + if (n == 1 || m == 1) { + cout << max(n, m) << endl; + continue; + } + if (n == m) { + cout << "1" << endl; + continue; + } + while (n != m) { + if (n > m) swap(n, m); + if (m % n == 0) { + res = res + (m / n); + m = m % n; + break; + } else + res += m / n; + m = m % n; + } + cout << res << endl; + } + return 0; +} +const int MAX = 100001; +int An[MAX], Bn[MAX]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> An[i]; + int sum = 0, flag = 0, coun = 0; + for (int i = 1; i <= n; i++) { + coun += An[i]; + if (coun > 8) { + sum += 8; + coun -= 8; + } else { + sum += coun; + coun = 0; + } + if (sum >= k) { + flag = 1; + cout << i << endl; + break; + } + } + if (!flag) cout << -1 << endl; + return 0; +} +int N; +int a[100005]; +bool vis[4]; +int main() { + cin >> N; + vis[1] = vis[2] = 1; + vis[3] = 0; + int x; + for (int i = 1; i <= N; i++) { + cin >> x; + if (vis[x] == 0) { + puts("NO"); + return 0; + } + for (int k = 1; k <= 3; k++) { + if (vis[k] && k != x) + vis[k] = 0; + else if (!vis[k]) + vis[k] = 1; + } + } + puts("YES"); + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + string s, ss; + cin >> s; + int flag = 0; + while (cin >> ss) { + if (s[0] == '\0') break; + if (s[0] == ss[0] || s[1] == ss[1]) { + flag = 1; + break; + } + } + if (flag) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int count = 1, i = 0, j = 0; + string s, t; + cin >> s >> t; + while (t[i] != NULL && s[j] != NULL) { + if (t[i] == s[j]) { + i++; + j++; + count++; + } else { + i++; + } + } + cout << count << endl; + return 0; +} +int main() { + int i, j; + int n, m; + int count = 0; + cin >> n >> m; + char a[n][m], ch[n], max; + int s[n]; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cin >> a[i][j]; } + s[i] = 0; + } + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { ch[j] = a[j][i]; } + for (int k = 0; k < n - 1; k++) { + for (int l = k; l < n; l++) { + if (ch[k] > ch[l]) { + int t = ch[k]; + ch[k] = ch[l]; + ch[l] = t; + } + } + } + max = (ch[n - 1]); + for (j = 0; j < n; j++) { + if (a[j][i] == max) { s[j]++; } + } + } + for (i = 0; i < n; i++) { + if (s[i] > 0) count++; + } + cout << count << endl; + return 0; +} +string s; +int dp[110] = {0}; +int state[110] = {0}; +int cur = 0; +int main() { + cin >> s; + int length = s.size(); + if (length == 1) { + cout << 0 << endl; + return 0; + } + for (int i = 0; i < length; i++) { + if (s[i] == 'V' && s[i + 1] == 'K') { + state[i] = state[i + 1] = 3; + i++; + cur++; + } else if (s[i] == 'V') + state[i] = 1; + else if (s[i] == 'K') + state[i] = 2; + } + int flag = 0; + for (int i = 0; i < length; i++) { + if ((state[i] == state[i + 1]) && state[i] != 3) flag = 1; + } + cout << cur + flag << endl; + return 0; +} +const int maxn = 120; +char order[maxn] = "qwertyuiopasdfghjkl;zxcvbnm,./"; +char a[maxn]; +char s; +int pos(char x, char S) { + for (int i = 0; i < 30; i++) { + if (order[i] == x) { + if (S == 'R') + return i - 1; + else if (S == 'L') + return i + 1; + } + } +} +int main() { + while (cin >> s) { + cin >> a; + int len = strlen(a); + for (int i = 0; i < len; i++) { + int p = pos(a[i], s); + cout << order[p]; + } + cout << endl; + } + return 0; +} +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + int cc = 0; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) cc++; + } + cout << cc << endl; + } +} +const int inf = 0x3f3f3f3f; +const int N = 1010; +long long a[N]; +int main() { + int m; + cin >> m; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + long long ans = 0; + for (int i = 1; i < m; i++) ans += a[i] - a[i - 1] - 1; + cout << ans << endl; + return 0; +} +long long n, tp[1000020], dn[1000020], sumtp, sumdn; +void read(long long &x) { + x = 0; + char ch = getchar(); + while (ch < '0' || ch > '9') { ch = getchar(); } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } +} +void write(const long long &x) { + char f[1000001]; + long long tmp = x; + long long s = 0; + while (tmp > 0) { + f[s++] = tmp % 10 + '0'; + tmp /= 10; + } + while (s > 0) { putchar(f[--s]); } +} +int main() { + read(n); + for (register long long i = 1; i <= n; ++i) { + read(tp[i]); + read(dn[i]); + sumtp += tp[i]; + sumdn += dn[i]; + } + if (!(sumtp & 1) && !(sumdn & 1)) { + puts("0"); + return 0; + } + if (n == 1) { + puts("-1"); + return 0; + } + for (register long long i = 1; i <= n; ++i) { + if (!((sumtp - tp[i] + dn[i]) & 1) && !((sumdn - dn[i] + tp[i]) & 1)) { + puts("1"); + return 0; + } + } + puts("-1"); + return 0; +} +int s = 0, t = 0, n = 0; +int h(int x, int y) { + t = n; + s += x; + if ((t + x) / y) { + n = (t + x) % y; + h((t + x) / y, y); + } else { + return s; + } +} +int main() { + int a, b; + cin >> a >> b; + h(a, b); + cout << s << endl; +} +int main() { + int arr1[100] = {0}, arr2[100] = {0}, count = 0, max = 0; + int n, h, a; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> h >> a; + arr1[h - 1]++; + arr2[a - 1]++; + if (max < h) max = h; + if (max < a) max = a; + } + for (int i = 0; i < max; i++) count += (arr1[i] * arr2[i]); + cout << count << endl; +} +int main() { + int n, i; + cin >> n; + for (i = sqrt(n); i >= 0; i--) { + if (n % i == 0) { + cout << i << " " << n / i << endl; + break; + } + } + return 0; +} +int main() { + long long a, ans = 0, plus; + string b; + cin >> a >> b; + for (int i = 0; i <= b.size() - 1; i++) { + plus = ((int)b[i] - 48); + for (int j = 0; j <= i; j++) plus *= 10; + plus /= 10; + ans += plus; + } + ans += a; + cout << ans << endl; +} +int main() { + int n{}, h{}, a{}, c{}, c2{}; + cin >> n >> h; + while (c <= 10) { + c++; + if (n * c % 10 != 0 && n * c % 10 != h) + a++; + else + c = 15; + } + cout << a + 1 << endl; + return 0; +} +int main() { + int a, b, n, k, c = 0, p = 0, i = 0; + cin >> a >> b >> n >> k; + int A[a], B[b]; + for (i = 0; i < a; i++) { cin >> A[i]; } + for (i = 0; i < b; i++) { cin >> B[i]; } + for (int j = b - 1; j > b - 1 - k; j--) { + if (A[n - 1] < B[j]) + c++; + else + goto jump; + } +jump: + if (c == k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int t = n; + int g = 0; + while (t--) { + int a[3]; + for (int i = 0; i < 3; i++) { cin >> a[i]; } + int k = 0; + for (int i = 0; i < 3; i++) { + if (a[i] == 1) { k++; } + } + if (k >= 2) { g += 1; } + } + cout << g << endl; + return 0; +} +long long c, v, vl, l, a; +int main() { + cin >> c >> v >> vl >> a >> l; + long long s = 1; + for (int i = v; i < c;) { + v += a; + if (v > vl) v = vl; + i -= l; + i += v; + s++; + } + cout << s << endl; +} +int main() { + long long int n; + cin >> n; + map ver, hor; + long long int a, b; + for (long long int i = 0; i < n; ++i) { + cin >> a >> b; + ver[a]++; + hor[b]++; + } + cout << min(ver.size(), hor.size()) << '\n'; + return 0; +} +int main() { + int n, m, x, y, t; + vector a, b; + cin >> n >> m >> x >> y; + for (int i = 0; i < n; i++) { + cin >> t; + a.push_back(t); + } + for (int i = 0; i < m; i++) { + cin >> t; + b.push_back(t); + } + int j = 0; + vector u, v; + for (int i = 0; i < n; i++) { + while (j < m && b[j] < a[i] - x) { j++; } + if (j < m && b[j] <= a[i] + y) { + u.push_back(i + 1); + v.push_back(j + 1); + j++; + } + } + cout << u.size() << endl; + for (int i = 0; i < u.size(); i++) { + cout << u[i] << " " << v[i]; + cout << endl; + } + return 0; +} +int a, n, p = 1000000007; +long long fastmod(long long a, long long n) { + if (n == 1) { return a; } + long long ans = fastmod(a, n / 2) % p; + if (n % 2 == 0) { + return ans % p * ans % p; + } else { + return ans % p * ans % p * a % p; + } +} +int main() { + long long k; + cin >> k; + if (k >= 2) { + long long t = fastmod(2, k - 1); + cout << (t + 2 * t * t % p) % p << endl; + } else if (k == 1) { + cout << 3 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int N; + cin >> N; + int fors = -1; + for (int i = 0; i <= (N / 4); ++i) { + int x = (4 * i); + int M = N - x; + if (M % 7 == 0) { + if (fors == -1 || (i + (M / 7)) < fors) { fors = i; } + } + } + if (fors == -1) { + cout << -1 << '\n'; + return 0; + } + for (int i = 0; i < fors; ++i) { cout << '4'; } + N -= (fors * 4); + for (int i = 0; i < (N / 7); ++i) { cout << '7'; } + cout << '\n'; + return 0; +} +int main() { + int n, m, i, j, k, count = 0; + map mp; + cin >> n >> m; + while (n--) { + cin >> i; + while (i--) { + cin >> k; + mp[k]++; + if (mp[k] == 1) count++; + } + } + if (count == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s, ss; + cin >> s >> ss; + if (s == ss) + cout << -1 << "\n"; + else + cout << max(ss.length(), s.length()) << "\n"; + return 0; +} +int main() { + int n, m, a, i, cnt = 0; + cin >> n >> m; + for (i = 1; i <= n; ++i) { + int fr[10] = {0}; + cin >> a; + while (a) { + fr[a % 10]++; + a /= 10; + } + bool ok = true; + for (int k = 0; k <= m; ++k) + if (fr[k] == 0) { + ok = false; + break; + } + if (ok == true) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1]; + int i; + for (i = 0; i < n; i++) { + cin >> a[i]; + while (a[i] % 2 == 0) a[i] >>= 1; + while (a[i] % 3 == 0) a[i] /= 3; + } + for (i = 1; i < n; i++) + if (a[i] != a[i - 1]) { + cout << "No" << endl; + return 0; + } + cout << "Yes" << endl; + return 0; +} +int main() { + int l; + cin >> l; + for (int i = l; i > 0; i--) { + int n, x, y, d; + cin >> n >> x >> y >> d; + int s = 0, k = 0; + if (x > y) { + if ((x - y) % d == 0) { + cout << (x - y) / d; + } else { + if ((y - 1) % d == 0) { s = ((x - 1) / d) + 1 + ((y - 1) / d); } + if ((n - y) % d == 0) { k = ((n - x) / d) + 1 + ((n - y) / d); } + if (s == 0 && k == 0) { + cout << -1; + } else { + if (k > s && s != 0) cout << s; + if (s > k && k == 0) cout << s; + if (k > s && s == 0) cout << k; + if (s > k && k != 0) cout << k; + } + } + } else if ((y - x) % d == 0) { + cout << (y - x) / d; + } else { + if ((y - 1) % d == 0) { s = ((x - 1) / d) + 1 + ((y - 1) / d); } + if ((n - y) % d == 0) { k = ((n - x) / d) + 1 + ((n - y) / d); } + if (s == 0 && k == 0) { + cout << -1; + } else { + if (k > s && s != 0) cout << s; + if (s > k && k == 0) cout << s; + if (k > s && s == 0) cout << k; + if (s > k && k != 0) cout << k; + } + } + cout << endl; + } + return 0; +} +int main() { + string a, b, c, d; + int n; + cin >> a >> b >> n; + cout << a << " " << b << endl; + while (n--) { + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + cout << a << " " << b << endl; + } +} +int main() { + long long n, arr1[1000], arr2[1000], sum = 0, sum1 = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr1[i]; } + for (int i = 0; i < n; i++) { cin >> arr2[i]; } + for (int i = 0; i < n; i++) { sum = sum | arr1[i]; } + for (int i = 0; i < n; i++) { sum1 = sum1 | arr2[i]; } + cout << sum + sum1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int A[n], B[n], cnt1 = 0, cnt2 = 0; + for (int i = 0; i < n; i++) { + cin >> A[i] >> B[i]; + if (A[i] % 2) cnt1++; + if (B[i] % 2) cnt2++; + } + int get = 0; + if (cnt1 % 2 == 0 && cnt2 % 2 == 0) { + cout << 0 << '\n'; + return 0; + } else if (cnt1 % 2 == 1 && cnt2 % 2 == 1) { + for (int i = 0; i < n; i++) + if ((A[i] % 2) != (B[i] % 2)) { + get++; + break; + } + if (get) { + cout << get << '\n'; + return 0; + } + } + cout << -1 << '\n'; + return 0; +} +void merger(int arr[], int l, int m, int r) { + int i, j, k; + int n1 = m - l + 1; + int n2 = r - m; + int L[n1], R[n2]; + for (i = 0; i < n1; i++) { L[i] = arr[l + i]; } + for (j = 0; j < n2; j++) { R[j] = arr[m + 1 + j]; } + i = 0; + j = 0; + k = l; + while (i < n1 && j < n2) { + if (L[i] <= R[j]) { + arr[k] = L[i]; + i++; + } else { + arr[k] = R[j]; + j++; + } + k++; + } + while (i < n1) { + arr[k] = L[i]; + i++; + k++; + } + while (j < n2) { + arr[k] = R[j]; + j++; + k++; + } +} +void mergeSort(int arr[], int l, int r) { + if (l < r) { + int m = l + (r - l) / 2; + mergeSort(arr, l, m); + mergeSort(arr, m + 1, r); + merger(arr, l, m, r); + } +} +int main() { + int secretaryNum, chatSec = 0, zeroNum = 0; + int temp, tempSame = 1; + bool check = true; + cin >> secretaryNum; + int id[secretaryNum]; + for (int i = 0; i < secretaryNum; i++) { + cin >> id[i]; + if (id[i] == 0) { zeroNum++; } + } + mergeSort(id, 0, secretaryNum - 1); + temp = id[zeroNum]; + for (int i = zeroNum + 1; i < secretaryNum; i++) { + if (temp != id[i]) { + temp = id[i]; + tempSame = 1; + } else { + tempSame++; + if (tempSame == 2) { chatSec++; } + if (tempSame > 2) { + check = false; + break; + } + } + } + if (check == false) { + cout << -1 << endl; + } else { + cout << chatSec << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a = 0, b = 0, c = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 1) a++; + if (x == 2) b++; + if (x == 3) c++; + } + if (a >= b && a >= c) + cout << b + c << endl; + else if (b >= a && b >= c) + cout << a + c << endl; + else if (c >= a && c >= b) + cout << a + b << endl; + return 0; +} +const int N = 1e3 + 9; +int d[N], s[N], r, Ans, mx; +int main() { + int m, k; + cin >> m >> k; + for (int i = 0; i < m; i++) cin >> d[i]; + for (int i = 0; i < m; i++) cin >> s[i]; + for (int i = 0; i < m; i++) { + r += s[i] - d[i], Ans += d[i], mx = max(mx, s[i]); + while (r < 0) r += mx, Ans += k; + } + return cout << Ans << endl, 0; +} +int t[][3] = { + {0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1}, +}; +int main() { + int moves, pos; + cin >> moves >> pos; + cout << t[moves % 6][pos] << endl; + return 0; +} +int toInt(string myString) { + stringstream mySS(myString); + int myInt; + mySS >> myInt; + return myInt; +} +vector parse(string myString) { + vector substrings; + while (0 == 0) { + if (myString.find(" ") == string::npos) { + substrings.push_back(myString); + return substrings; + } + substrings.push_back(myString.substr(0, myString.find(" "))); + myString.erase(0, myString.find(" ") + 1); + } +} +int main() { + string slogan; + int n, k; + getline(cin, slogan); + vector vec; + vec = parse(slogan); + n = toInt(vec[0]); + k = toInt(vec[1]); + getline(cin, slogan); + if (k <= n / 2) { + while (k != 1) { + cout << "LEFT\n"; + k -= 1; + } + cout << "PRINT " << slogan[k - 1] << "\n"; + for (int f = 1; f < n; f++) { + cout << "RIGHT\n"; + k += 1; + cout << "PRINT " << slogan[k - 1] << "\n"; + } + } else { + while (k != n) { + cout << "RIGHT\n"; + k += 1; + } + cout << "PRINT " << slogan[k - 1] << "\n"; + for (int f = 1; f < n; f++) { + cout << "LEFT\n"; + k -= 1; + cout << "PRINT " << slogan[k - 1] << "\n"; + } + } +} +int main() { + int n, x, y = 0, res = 0, max_res = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> x; + if (x > y) { + res++; + } else { + res = 1; + } + if (res > max_res) max_res = res; + y = x; + } + cout << max_res << endl; + return 0; +} +int main() { + int t; + cin >> t; + long long answer = 0; + while (t--) { + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + x1--; + y1--; + answer += (x2 - x1) * abs(y2 - y1); + } + cout << answer << endl; + return 0; +} +string s[30003]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + int len = s[0].length(); + int ans = 0; + for (int i = 0; i < len; i++) { + char c = s[0][i]; + for (int j = 0; j < n; j++) { + if (c != s[j][i]) { + cout << ans << endl; + return 0; + } + } + ans++; + } + return 0; +} +long long ans, flr; +long long check(long long f) { + while (f) { + if (f % 10 == 8) { return 0; } + f /= 10; + } + return 1; +} +int main() { + cin >> flr; + do { + flr++; + ans++; + } while (check(abs(flr))); + cout << ans << endl; +} +int main() { + int n, s; + cin >> n >> s; + int ans = s / n + (s % n ? 1 : 0); + cout << ans << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + a = 180 - a; + if (360 % a == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int main() { + long long n; + cin >> n; + for (long long i = 1; i <= n; i++) { + if (i == 1) + cout << ((i + 1) * (i + 1)) * i - 2 << endl; + else + cout << ((i + 1) * (i + 1)) * i - (i - 1) << endl; + } + return 0; +} +int main() { + long long t, x, y, p, q, i; + cin >> t; + while (t--) { + cin >> x >> y >> p >> q; + if (p == q) { + if (x == y) + cout << "0\n"; + else + cout << "-1\n"; + } else if (p == 0) { + if (x == 0) + cout << "0\n"; + else + cout << "-1\n"; + } else { + i = max(ceil(x * 1.0 / p), ceil(y * 1.0 / q)); + i = max(i, (long long)ceil((y - x) * 1.0 / (q - p))); + cout << ((i * q - y) < 0 ? -1 : (i * q - y)) << endl; + } + } +} +int n, x, y, z; +int pole[5][5]; +int naj; +int main() { + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { pole[i][j] = 1; } + } + for (int i = 1; i < 4; i++) { + for (int ii = 1; ii < 4; ii++) { + cin >> naj; + for (int iii = 0; iii < naj; iii++) { + if (pole[i][ii] == 0) + pole[i][ii] = 1; + else + pole[i][ii] = 0; + if (pole[i + 1][ii] == 0) + pole[i + 1][ii] = 1; + else + pole[i + 1][ii] = 0; + if (pole[i - 1][ii] == 0) + pole[i - 1][ii] = 1; + else + pole[i - 1][ii] = 0; + if (pole[i][ii + 1] == 0) + pole[i][ii + 1] = 1; + else + pole[i][ii + 1] = 0; + if (pole[i][ii - 1] == 0) + pole[i][ii - 1] = 1; + else + pole[i][ii - 1] = 0; + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cout << pole[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m, f[1000]; + cin >> n >> m; + for (int i = 0; i < m; ++i) { cin >> f[i]; } + sort(f, f + m); + int least = f[n - 1] - f[0]; + for (int i = 1; i <= m - n; ++i) { + if (f[i + n - 1] - f[i] < least) { least = f[i + n - 1] - f[i]; } + } + cout << least << endl; + return 0; +} +int main() { + string s; + int n, x = 1, y = 1; + cin >> n; + while (n--) { + cin >> s; + if (s == "ULDR") + x++, y++; + else if (s == "UR" || s == "DL") + x++; + else + y++; + } + cout << 1LL * x * y << endl; +} +char num[300005]; +int main() { + long long n, x, y; + long long i; + long long n0, n00; + long long ans = 0; + while (cin >> n >> x >> y) { + cin >> num; + if (num[0] == '1') { + n0 = 0; + } else { + n0 = 1; + } + n00 = 0; + for (i = 1; i < n; i++) { + if (num[i] == '0') n0++; + if (num[i] == '1' && num[i - 1] == '0') n00++; + } + if (num[n - 1] == '0') n00++; + if (n00 != 0) { + ans = 0; + if (y < x) { + ans = n00 * y; + } else { + ans = (n00 - 1) * x + y; + } + cout << ans << endl; + } else { + cout << "0" << endl; + } + } + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + long long a, b, c; + cin >> a >> b >> c; + if (c % 2 == 0) { + cout << a * (c / 2) - b * (c / 2) << '\n'; + } else + cout << a * (c / 2 + 1) - b * (c / 2) << '\n'; + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + x = 86400 - x; + m -= x; + if (m <= 0) { + cout << i + 1 << endl; + return 0; + } + } +} +int main() { + char c1, c2; + int n; + cin >> c1 >> c2; + cin >> n; + int p1, p2; + if (c1 == 'v') { + p1 = 0; + } else if (c1 == '<') { + p1 = 1; + } else if (c1 == '^') { + p1 = 2; + } else { + p1 = 3; + } + if (c2 == 'v') { + p2 = 0; + } else if (c2 == '<') { + p2 = 1; + } else if (c2 == '^') { + p2 = 2; + } else { + p2 = 3; + } + if (n % 4 == 0 || n % 4 == 2) { + cout << "undefined" << endl; + } else { + if ((p1 + n % 4) % 4 == p2) { + cout << "cw" << endl; + } else { + cout << "ccw" << endl; + } + } + return 0; +} +map mp; +int main() { + int q; + cin >> q; + for (int i = 0; i < q; i++) { + int t; + cin >> t; + if (t == 1) { + long long v, u, w; + cin >> v >> u >> w; + while (v != u) { + if (v < u) swap(v, u); + mp[v] += w; + v /= 2; + } + } else { + long long v, u; + cin >> v >> u; + long long ans = 0; + while (v != u) { + if (v < u) swap(v, u); + ans += mp[v]; + v /= 2; + } + cout << ans << '\n'; + } + } + return 0; +} +long long n, m, a, b; +int main() { + while (cin >> n >> m >> a >> b) { + long long tmp = n / m; + long long ans = 1e15; + ans = min(ans, (n - tmp * m) * b); + ans = min(ans, ((tmp + 1) * m - n) * a); + cout << ans << endl; + } + return 0; +} +int main() { + int i, j, l, test = 0, ans, len; + char str[1003], ch; + double maps = 0, k; + cin >> l; + for (i = 0; i < l; i++) { + cin >> str; + if (strcmp(str, "ABSINTH") == 0) { + test++; + } else if (strcmp(str, "BEER") == 0) { + test++; + } else if (strcmp(str, "BRANDY") == 0) { + test++; + } else if (strcmp(str, "CHAMPAGNE") == 0) { + test++; + } else if (strcmp(str, "GIN") == 0) { + test++; + } else if (strcmp(str, "RUM") == 0) { + test++; + } else if (strcmp(str, "SAKE") == 0) { + test++; + } else if (strcmp(str, "TEQUILA") == 0) { + test++; + } else if (strcmp(str, "VODKA") == 0) { + test++; + } else if (strcmp(str, "WHISKEY") == 0) { + test++; + } else if (strcmp(str, "WINE") == 0) { + test++; + } else if (str[0] >= 48 && str[0] <= 57) { + len = strlen(str); + k = 0; + maps = 0; + for (j = len - 1; j >= 0; j--) { + str[j] = str[j] - '0'; + maps = maps + (str[j] * pow(10.0, k)); + k++; + } + ans = (int)maps; + if (ans < 18) { test++; } + } + } + cout << test << endl; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +int main() { + int n, a, b, c, max = 0; + cin >> n >> a >> b >> c; + for (int x = 0; a * x <= n; x++) { + for (int y = 0; (y * b) + (a * x) <= n; y++) { + int z = (n - a * x - b * y) / c; + if (a * x + b * y + z * c == n) { + if (x + y + z > max) max = x + y + z; + } + } + } + cout << max << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + map m; + for (int i = 0; i < s.length(); i++) { + m.insert(make_pair(s[i], 0)); + m[s[i]]++; + } + if (m.size() != k) + cout << "0" << endl; + else { + map::iterator it = m.begin(); + int mn = it->second; + it++; + while (it != m.end()) { + if (it->second < mn) mn = (it->second); + it++; + } + cout << (mn)*k << endl; + } + return 0; +} +int mp[1010][1010]; +int main() { + int m, n, k; + cin >> m >> n >> k; + memset(mp, 0, sizeof(mp)); + int flog = 0; + int ans = 0; + for (int i = 1; i <= k; i++) { + int x, y; + cin >> x >> y; + mp[x][y] = 1; + if (flog == 0) { + if (mp[x - 1][y] && mp[x - 1][y - 1] && mp[x][y - 1]) flog = 1; + if (mp[x + 1][y] && mp[x + 1][y + 1] && mp[x][y + 1]) flog = 1; + if (mp[x - 1][y] && mp[x - 1][y + 1] && mp[x][y + 1]) flog = 1; + if (mp[x + 1][y] && mp[x + 1][y - 1] && mp[x][y - 1]) flog = 1; + if (flog) { + cout << i << endl; + return 0; + } + } + } + cout << "0" << endl; +} +int main() { + char S[11]; + cin >> S; + int arr[26] = {}; + for (int i = 0; S[i]; i++) { arr[S[i] - 'a']++; } + for (int i = 25; i >= 0; i--) { + if (arr[i]) { + for (int j = 0; j < arr[i]; j++) { cout << (char)(i + 'a'); } + break; + } + } + cout << "\n"; +} +const int N = 2e2 + 5; +int n, c[N], vis[N]; +vector ned[N], a[N]; +int solve(int x) { + memset(vis, 0, sizeof(vis)); + int res = 0, cnt = 0, flag = 0; + while (cnt < n) { + bool mk = true; + while (mk) { + mk = false; + for (int i = 0; i < a[x].size(); i++) { + int id = a[x][i], tot = 0; + if (vis[id]) continue; + for (int j = 0; j < ned[id].size(); j++) + if (vis[ned[id][j]]) tot++; + if (tot == ned[id].size()) { + res++, cnt++; + vis[id] = 1; + flag = 0; + mk = true; + } + } + } + if (cnt == n) return res; + x++; + if (x > 3) x = 1; + res++, flag--; + if (flag < -4) return 2e9; + } +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> c[i], a[c[i]].push_back(i); + for (int i = 1; i <= n; i++) { + int k; + cin >> k; + for (int j = 0; j < k; j++) { + int x; + cin >> x; + ned[i].push_back(x); + } + } + int res = 2e9; + for (int i = 1; i <= 3; i++) res = min(res, solve(i)); + cout << res << '\n'; + return 0; +} +int n, be[100001], af[100001], ans, a, b; +string s; +int main() { + cin >> n >> a >> b >> s; + if (s[a - 1] == s[b - 1]) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } +} +int main() { + long long n; + cin >> n; + long long val = 0, ans = 0; + for (long long i = 0; i < 10001; i++) { + val += i; + ans += val; + if (ans > n) { + cout << i - 1 << endl; + return 0; + } + } + return 0; +} +int main() { + int cases; + cin >> cases; + for (int i = 0; i < cases; ++i) { + int num1, num2; + cin >> num1 >> num2; + int ops = 0; + while (num1 > 0 && num2 > 0) { + if (num1 > num2) { + ops = ops + num1 / num2; + num1 = num1 % num2; + } else { + ops = ops + num2 / num1; + num2 = num2 % num1; + } + } + cout << ops << endl; + } + return 0; +} +string n, m; +int f; +int main() { + cin >> n >> m; + if (n == m) + cout << n << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + for (int i = 0; i < n; i++) { + int p, q; + cin >> p >> q; + if (q - p >= 2) cnt++; + } + cout << cnt << "\n"; +} +int n, ans; +int A[100000]; +map fix; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> A[i]; + if (A[i] == 0) continue; + fix[A[i]]++; + if (fix[A[i]] > 2) { + cout << -1 << endl; + return 0; + } + if (fix[A[i]] == 2) ans++; + } + cout << ans << endl; +} +int main() { + int w, h, k; + cin >> w >> h >> k; + cout << 2 * k * (w + h - 2) - 8 * (k * (k - 1)) << endl; + return 0; +} +int main() { + int n, a; + cin >> n; + a = (n - n % 2) / 2; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= a - i + 1; j++) { cout << "*"; } + for (int j = 1; j <= i * 2 - 1; j++) { cout << "D"; } + for (int j = 1; j <= a - i + 1; j++) { cout << "*"; } + cout << endl; + } + for (int i = 1; i <= n; i++) cout << "D"; + cout << endl; + for (int i = a; i >= 1; i--) { + for (int j = 1; j <= a - i + 1; j++) { cout << "*"; } + for (int j = 1; j <= i * 2 - 1; j++) { cout << "D"; } + for (int j = 1; j <= a - i + 1; j++) { cout << "*"; } + cout << endl; + } +} +bool check(int n) { + int cek; + while (n != 0) { + cek = n % 10; + if (abs(cek) == 8) { return true; } + n = n / 10; + } + return false; +} +int main() { + int num, cnt = 0; + cin >> num; + while (true) { + num++; + cnt++; + if (check(num)) { break; } + } + cout << cnt << endl; + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int cnt = 0; + int remnut = a; + int remdiv = b; + while (remnut != 0) { + cnt++; + int newnut = (min(k, remdiv + 1)) * v; + remdiv -= (min(k, remdiv + 1)) - 1; + if (newnut > remnut) + remnut = 0; + else + remnut -= newnut; + } + cout << cnt << endl; + return 0; +} +const double PI = 3.14159265358; +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + int alpha; + cin >> alpha; + if (360 % (180 - alpha) == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +bool a = 1, b = 1, c = 0; +int n, win; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> win; + if (win == 1 and a) { + swap(b, c); + } else if (win == 2 and b) { + swap(a, c); + } else if (win == 3 and c) { + swap(a, b); + } else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int n, k; +string s; +int f[27]; +int main() { + cin >> n >> k >> s; + int len = (int)s.size(); + for (int i = (int)0; i <= (int)len - 1; i++) { + int tmp = int(s[i]) - int('A') + 1; + f[tmp]++; + } + int fre = INT_MAX; + for (int i = (int)1; i <= (int)k; i++) { fre = min(fre, f[i]); } + if (fre == 0) { + cout << 0 << "\n"; + return 0; + } + for (int i = (int)1; i <= (int)k; i++) f[i] = fre; + int ans = 0; + for (int i = (int)0; i <= (int)len - 1; i++) { + int tmp = int(s[i]) - int('A') + 1; + if (1 <= tmp && tmp <= k && f[tmp] > 0) { + ans++; + f[tmp]--; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + long long n; + cin >> n; + int t = n % 10; + if (t >= 6) + n = n - t + 10; + else + n = n - t; + cout << n << endl; +} +int a[60], b[60]; +int n, m; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int i = 0; i < m; i++) cin >> b[i]; + int maxx = 0; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) { + if (b[j] / a[i] > maxx) { + maxx = b[j] / a[i]; + ans = 1; + } else if (b[j] / a[i] == maxx) { + ans++; + } + } + } + } + cout << ans << endl; + return 0; +} +bool isl(char c) { + return (c >= 'a' && c <= 'z'); +} +bool isu(char c) { + return (c >= 'A' && c <= 'Z'); +} +bool isa(char c) { + return (isl(c) || isu(c)); +} +bool isn(char c) { + return (c >= '0' && c <= '9'); +} +bool isan(char c) { + return (isa(c) || isn(c)); +} +bool isv(char c) { + return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); +} +string tolow(string s) { + for (int i = 0; i < s.length(); i++) + if (isu(s[i])) s[i] = s[i] - 'A' + 'a'; + return s; +} +string toup(string s) { + for (int i = 0; i < s.length(); i++) + if (isl(s[i])) s[i] = s[i] - 'a' + 'A'; + return s; +} +int main() { + string s1, s2; + int ans; + cin >> s1 >> s2; + ans = 0; + for (int i = 0; i < s2.length(); i++) + if (s1[ans] == s2[i]) ans++; + cout << ans + 1 << endl; + return 0; +} +int main() { + long long int m, n, a, b; + cin >> n >> m; + a = pow(2, n); + b = (m % a); + cout << b << endl; + return 0; +} +bool isvalid(int r, int c) { + return ((r >= 0 && r < 3) && (c >= 0 && c < 3)); +} +int main() { + int i, j, k; + int a[3][3]; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) cin >> a[i][j]; + } + char s[3][3]; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) s[i][j] = '1'; + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (s[i][j] == '1') { + if (a[i][j] % 2) + s[i][j] = '0'; + else + s[i][j] = '1'; + } else { + if (a[i][j] % 2) + s[i][j] = '1'; + else + s[i][j] = '0'; + } + if (isvalid(i - 1, j) && a[i][j] != 0) { + if (s[i - 1][j] == '1') { + if (a[i][j] % 2) + s[i - 1][j] = '0'; + else + s[i - 1][j] = '1'; + } else { + if (a[i][j] % 2) + s[i - 1][j] = '1'; + else + s[i - 1][j] = '0'; + } + } + if (isvalid(i + 1, j) && a[i][j] != 0) { + if (s[i + 1][j] == '1') { + if (a[i][j] % 2) + s[i + 1][j] = '0'; + else + s[i + 1][j] = '1'; + } else { + if (a[i][j] % 2) + s[i + 1][j] = '1'; + else + s[i + 1][j] = '0'; + } + } + if (isvalid(i, j - 1) && a[i][j] != 0) { + if (s[i][j - 1] == '1') { + if (a[i][j] % 2) + s[i][j - 1] = '0'; + else + s[i][j - 1] = '1'; + } else { + if (a[i][j] % 2) + s[i][j - 1] = '1'; + else + s[i][j - 1] = '0'; + } + } + if (isvalid(i, j + 1) && a[i][j] != 0) { + if (s[i][j + 1] == '1') { + if (a[i][j] % 2) + s[i][j + 1] = '0'; + else + s[i][j + 1] = '1'; + } else { + if (a[i][j] % 2) + s[i][j + 1] = '1'; + else + s[i][j + 1] = '0'; + } + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) cout << s[i][j]; + cout << endl; + } +} +int main() { + int n; + while (cin >> n) { + int a[30]; + a[0] = 5; + int i; + for (i = 1; i < 30; i++) { a[i] = 2 * a[i - 1]; } + int k = 0; + for (i = 0; i < 30; i++) { + k += a[i]; + if (k >= n) { break; } + } + int v = 0; + int y = 0; + if (k == n) { v = 5; } + int u; + int t; + if (k > n) { + k -= a[i]; + y = n - k; + t = pow(2.0, i); + u = y / t; + if (n <= 5) { u--; } + v = ++u; + } + if (v == 1) { + cout << "Sheldon" << endl; + } else if (v == 2) { + cout << "Leonard" << endl; + } else if (v == 3) { + cout << "Penny" << endl; + } else if (v == 4) { + cout << "Rajesh" << endl; + } else if (v == 5) { + cout << "Howard" << endl; + } + } + return 0; +} +int main() { + long n, p, c, x, maxC; + cin >> n; + cin >> p; + c = 1; + maxC = 1; + for (int i = 0; i < n - 1; i++) { + cin >> x; + if (x > p) + c++; + else { + if (c > maxC) maxC = c; + c = 1; + } + p = x; + } + if (c > maxC) maxC = c; + cout << maxC << endl; +} +int main() { + int n, m, z, flag = 0, tempn = 0, tempm = 0; + cin >> n; + cin >> m; + cin >> z; + for (int i = 1; tempn < z; i++) { + tempn = n * i; + for (int j = 1; tempm < z; j++) { + tempm = m * j; + if (tempm > z) break; + if (tempn == tempm) { + flag++; + break; + } else if (tempm < tempn) + continue; + else if (tempm > tempn) + break; + } + tempm = 0; + if (tempn > z) break; + } + cout << flag << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + long long hasil = 0; + for (int i = 0; i < n; i++) { + int tmpA, tmpB; + if (a[i] < b[i]) { + tmpA = a[i] + 10; + tmpB = b[i]; + } else { + tmpA = a[i]; + tmpB = b[i] + 10; + } + hasil += min(abs(a[i] - b[i]), abs(tmpA - tmpB)); + } + cout << hasil << endl; +} +int main() { + int n; + while (cin >> n) { + int h[105], g[105], count = 0; + for (int i = 0; i < n; i++) { cin >> h[i] >> g[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (h[i] == g[j]) { count++; } + } + } + cout << count << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1, d = 1; i <= n; i++, d += 2) { + if (i > n / 2 + 1) { d -= 4; } + int a = (n - d) / 2; + for (int j = 0; j < a; j++) { cout << "*"; } + for (int j = 0; j < d; j++) { cout << "D"; } + for (int j = 0; j < a; j++) { cout << "*"; } + cout << '\n'; + } + return 0; +} +int main() { + long int a, b; + cin >> a >> b; + int reversedNumber = 0, remainder; + while (b != 0) { + remainder = b % 10; + reversedNumber = reversedNumber * 10 + remainder; + b /= 10; + } + cout << a + reversedNumber << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, a; + cin >> n >> a; + int sum = 0, i, p = 0; + for (i = 1;; i++) { + sum = n * i; + if (sum % 10 == 0 || sum % 10 == a) break; + p++; + } + cout << p + 1 << endl; + return 0; +} +string st; +string temp, bst; +set v; +string rl(string st) { + char c = st[0]; + st[0] = st[1]; + st[1] = st[2]; + st[2] = st[3]; + st[3] = c; + return st; +} +string ru(string st) { + char temp = st[4]; + st[4] = st[0]; + st[0] = st[5]; + st[5] = st[2]; + st[2] = temp; + return st; +} +int main() { + cin >> st; + sort(st.begin(), st.end()); + do { + temp = st; + bst = temp; + for (int iter = 1; iter <= 2000; iter++) { + if (rand() % 2) + temp = rl(temp); + else + temp = ru(temp); + if (bst > temp) bst = temp; + } + v.insert(bst); + } while (next_permutation(st.begin(), st.end())); + cout << v.size() << endl; + cin.get(); + cin.get(); + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= (n / 2 + 1); i++) { + int numD = 2 * i - 1; + int numStar = n - numD; + for (int j = 0; j < numStar / 2; j++) { cout << "*"; } + for (int j = 0; j < numD; j++) { cout << "D"; } + for (int j = 0; j < numStar / 2; j++) { cout << "*"; } + cout << endl; + } + for (int i = n - 2; i >= 1; i = i - 2) { + int numD = i; + int numStar = n - numD; + for (int j = 0; j < numStar / 2; j++) { cout << "*"; } + for (int j = 0; j < numD; j++) { cout << "D"; } + for (int j = 0; j < numStar / 2; j++) { cout << "*"; } + cout << endl; + } + return 0; +} +void print(long long int a[], long long int n) { + for (long long int i = 0; i < n; i++) { cout << a[i] << " "; } + cout << endl; +} +long long int m(long long int x) { + return x % 1000000007; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +long long int p(long long int a, long long int b) { + if (b == 0) return 1; + long long int t = p(a, b / 2); + if (b % 2 == 0) + return t * t; + else + return a * t * t; +} +long long int sod(long long int x) { + long long int n = x; + long long int sum = 0; + while (n != 0) { + sum += n % 10; + n = n / 10; + } + return sum; +} +long long int min(long long int a, long long int b) { + if (a < b) { + return a; + } else + return b; +} +int main() { + long long int n; + cin >> n; + vector vv; + long long int v = min(n, 81); + for (long long int i = v; i >= 1; i--) { + long long int x = n - i; + if (x <= 0) { continue; } + if (sod(x) + x == n && sod(x) == i) { vv.push_back(x); } + } + cout << vv.size() << endl; + for (long long int i = 0; i < vv.size(); i++) { cout << vv[i] << endl; } + return 0; +} +int main() { + int n, x, r = 0; + cin >> n >> x; + for (int i = 1; i <= n; ++i) { + if (x % i != 0) continue; + int y = x / i; + if (y <= n) r++; + } + cout << r << endl; + return 0; +} +const int MAXN = 105; +int N, M; +int arr[MAXN][MAXN]; +int votes[MAXN]; +int ans; +int main() { + cin >> N >> M; + for (int i = 1; i <= M; i++) { + int max = -1; + int index; + for (int j = 1; j <= N; j++) { + cin >> arr[i][j]; + if (arr[i][j] > max) { + max = arr[i][j]; + index = j; + } + } + votes[index]++; + } + int max = -1; + for (int i = 1; i <= N; i++) { + if (votes[i] > max) { + max = votes[i]; + ans = i; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + if (m <= k) { + cout << 0 << endl; + return 0; + } + sort(a.rbegin(), a.rend()); + for (int i = 0; i < n; i++) { + k += a[i] - 1; + if (k >= m) { + cout << i + 1 << endl; + return 0; + } + } + cout << -1 << endl; +} +int main() { + int n, s = 0, x = 0; + string poly; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> poly; + if (poly == "Tetrahedron") { + x = 4; + } else if (poly == "Cube") { + x = 6; + } else if (poly == "Octahedron") { + x = 8; + } else if (poly == "Dodecahedron") { + x = 12; + } else if (poly == "Icosahedron") { + x = 20; + } + s = s + x; + } + cout << s << endl; +} +int main() { + long long n, m; + int a, b; + cin >> n >> m >> a >> b; + long long x = (n - n / m * m) * b, y = ((n / m + 1) * m - n) * a; + if (x > y) + cout << y << endl; + else + cout << x << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int s = 0, val; + for (int i = 0; i < n; i++) { + cin >> val; + s += val; + } + long long act = s % (n + 1); + long long c = 0; + if (((act + 1) % (n + 1)) == 1) c++; + if (((act + 2) % (n + 1)) == 1) c++; + if (((act + 3) % (n + 1)) == 1) c++; + if (((act + 4) % (n + 1)) == 1) c++; + if (((act + 5) % (n + 1)) == 1) c++; + cout << 5 - c << "\n"; +} +int main() { + string s; + cin >> s; + bool ad = false; + for (int i = 0; i < 5; i++) { + string a; + cin >> a; + if (a[0] == s[0] || a[1] == s[1]) { ad = true; } + } + if (ad) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, k, r, s, l, h, m; + cin >> n >> k; + r = 240 - k; + l = 0; + h = n; + while (l < h) { + m = l + (h - l) / 2 + 1; + s = (5 * m * (m + 1)) / 2; + if (s > r) + h = m - 1; + else + l = m; + } + cout << l << "\n"; + return 0; +} +int main() { + int number; + cin >> number; + if (number == 0) { cout << "O-|-OOOO" << endl; } + while (number > 0) { + if (number % 10 >= 5) { + cout << "-O|"; + } else { + cout << "O-|"; + } + int ones = number % 10; + ones %= 5; + for (int i = 0; i < ones; i++) { cout << "O"; } + cout << "-"; + for (int i = 0; i < 4 - ones; i++) { cout << "O"; } + cout << endl; + number /= 10; + } + return 0; +} +int main() { + int s = 9999999999; + int n; + cin >> n; + pair a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i].first; + a[i].second = i + 1; + } + sort(a, a + n); + for (int i = 0; i < n - 1; i++) { + if (a[i].first == a[i + 1].first && a[0].first == a[i].first) { s = min(s, a[i + 1].second - a[i].second); } + } + cout << s << endl; + return 0; +} +int main() { + string name[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + int n, k = 1, t = 5, flag = 0; + cin >> n; + while (k * t < n) { + n -= (k * t); + k *= 2; + } + while (n > k) { + n -= k; + flag++; + } + cout << name[flag] << endl; + return 0; +} +const long long inf = (1LL << 60); +long long solve(long long x, long long y, long long d) { + y -= x; + if (y < 0) y *= -1; + if (y % d == 0) { return (y / d); } + return inf; +} +int main() { + int test; + cin >> test; + while (test--) { + long long n, x, y, d; + cin >> n >> x >> y >> d; + long long l = ((x - 1) + d - 1) / d; + long long r = ((n - x) + d - 1) / d; + if (y == 1) + cout << l << endl; + else if (y == n) + cout << r << endl; + else { + long long ans = min(solve(x, y, d), solve(1LL, y, d) + l); + ans = min(ans, solve(n, y, d) + r); + cout << ((ans == inf) ? -1 : ans) << endl; + } + } +} +const int MAX = 1e5 + 5; +int a[MAX]; +int main() { + set g; + set::iterator p; + int n, m; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + if (m == 0) { + continue; + } else { + g.insert(m); + } + } + cout << g.size() << endl; +} +int main() { + long long int s, a, b, c, t, i = 0, k, l, m; + cin >> t; + for (i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + k = s / c; + l = k / a; + m = l * b; + cout << m + k << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + vector phnum(n); + for (int ii = 0; ii < n; ii++) { cin >> phnum[ii]; } + int len = phnum[0].size(); + int ans = 0; + bool ok = true; + for (int p = 0; p < len; p++) { + for (int ii = 1; ii < phnum.size(); ii++) { + if (phnum[ii][p] != phnum[ii - 1][p]) { + ok = false; + break; + } + } + if (!ok) + break; + else + ans++; + } + cout << ans << endl; + } +} +int dp[2505][2505]; +int n, m; +int cntt(int k) { + int k1 = k - 1, res = 0; + for (int i = 1; i <= n; i += k) { + for (int j = 1; j <= m; j += k) { + int cnt = 0; + cnt += dp[min(i + k1, n)][min(j + k1, m)]; + cnt -= dp[i - 1][min(j + k1, m)]; + cnt -= dp[min(i + k1, n)][j - 1]; + cnt += dp[i - 1][j - 1]; + res += min(cnt, k * k - cnt); + } + } + return res; +} +int main() { + cin >> n >> m; + string s; + for (int i = 1; i <= n; ++i) { + cin >> s; + for (int j = 1; j <= m; ++j) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + s[j - 1] - '0'; } + } + int res = n * m; + for (int k = 2; k <= min(n, m); ++k) { res = min(res, cntt(k)); } + cout << res << '\n'; + return 0; +} +long long fp(long long n, long long p) { + if (p == 0) return 1; + if (p == 1) return n; + long long res = fp(n, p / 2); + res = ((res) * (res)); + if (p % 2) res = (res * n); + return res; +} +int main() { + pair arr[5]; + int a, b, c; + double s = -1, ss = -1; + bool f = 0; + for (int i = 0; i < 3; i++) { + cin >> arr[i].first >> arr[i].second; + if (i == 1) { + if ((arr[i].first - arr[i - 1].first) != 0) s = (arr[i].second - arr[i - 1].second) / (arr[i].first - arr[i - 1].first); + } else if (i == 2) { + if ((arr[i].first - arr[i - 1].first) != 0) ss = (arr[i].second - arr[i - 1].second) / (arr[i].first - arr[i - 1].first); + if (s == ss) f = 1; + } + } + if (f) return cout << "TOWARDS" << '\n', 0; + if (arr[0].second > arr[1].second) { + if (arr[2].first > arr[1].first) + return cout << "LEFT" << '\n', 0; + else + return cout << "RIGHT" << '\n', 0; + } else if (arr[0].second < arr[1].second) { + if (arr[2].first < arr[1].first) + return cout << "LEFT" << '\n', 0; + else + return cout << "RIGHT" << '\n', 0; + } else if (arr[0].second == arr[1].second && arr[0].first < arr[1].first) { + if (arr[2].second > arr[1].second) + return cout << "LEFT" << '\n', 0; + else + return cout << "RIGHT" << '\n', 0; + } else if (arr[0].second == arr[1].second && arr[0].first > arr[1].first) { + if (arr[2].second < arr[1].second) + return cout << "LEFT" << '\n', 0; + else + return cout << "RIGHT" << '\n', 0; + } + return 0; +} +int n; +int computer[201], check[3][201], vis[201]; +vector vv[201]; +int bfs(int num, int st) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (check[num][i] == 0) q.push(i); + } + while (!q.empty()) { + memset(vis, 0, sizeof(vis)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (vis[head] == n) { + q.push(head); + break; + } + vis[head]++; + if (computer[head] != st) { + q.push(head); + continue; + } + for (int i = 0; i < vv[head].size(); i++) { + int v = vv[head][i]; + check[num][v]--; + if (check[num][v] == 0) q.push(v); + } + } + st = (st == 3 ? 1 : st + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(check, 0, sizeof(check)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + check[0][i]++, check[1][i]++, check[2][i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= 3; i++) ans = min(ans, bfs(i - 1, i)); + cout << ans << endl; + } + return 0; +} +int main() { + int p; + cin >> p; + int j; + int count = 0; + for (int i = 1; i < p; i++) { + long long int x = i; + for (j = 1; j < p - 1; j++) { + if ((x - 1) % p == 0) + break; + else { + x = (x * i) % p; + } + } + if (j == (p - 1) && (x - 1) % p == 0) count++; + } + cout << count << endl; + return 0; +} +int main() { + int cnt = 0; + int maxx = 0; + map M; + int N; + cin >> N; + N *= 2; + while (N--) { + int a; + cin >> a; + if (M[a]) { + cnt--; + } else { + cnt++; + } + maxx = ((maxx) > (cnt) ? (maxx) : (cnt)); + M[a] = !M[a]; + } + cout << maxx << '\n'; + return 0; +} +long long gcd(long long a, long long b) { + return b == 0 ? a : gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * (b / gcd(a, b)); +} +const int q = 1e9 + 7; +int main() { + long long n, a[200009], ans = 2e9 + 7, c = 0, best; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + a[n] = 0; + a[n + 1] = 0; + for (int i = 1; i < n; i++) { + long long k = abs(a[i] - a[i - 1]); + if (k == ans) { + c++; + continue; + } + if (k < ans) { + ans = min(ans, k); + c = 0; + c++; + } + } + cout << ans << " " << c << endl; + return 0; +} +int main() { + int t, i; + cin >> t; + long int e[t]; + for (i = 0; i < t; i++) { + double n, x, y, d, a, b, c; + cin >> n >> x >> y >> d; + if (modf(abs(y - x) / d, &a) != 0) + a = INT_MAX; + else + ; + if (modf(abs(y - 1) / d, &b) == 0) + b += ceil(abs(x - 1) / d); + else + b = INT_MAX; + if (modf(abs(n - y) / d, &c) == 0) + c += ceil(abs(n - x) / d); + else + c = INT_MAX; + if (a == INT_MAX && c == INT_MAX && b == INT_MAX) + e[i] = -1; + else + e[i] = (min(min(a, b), c)); + } + for (i = 0; i < t; i++) cout << e[i] << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long c, d; + d = (n / 2) / (k + 1); + c = k * d; + cout << d << " " << c << " " << n - d - c << endl; +} +int const N = 1e5 + 100; +int main() { + int n; + string a, b; + cin >> a >> b >> n; + cout << a << " " << b << "\n"; + for (int i = 0; i < n; ++i) { + string aa, bb; + cin >> aa >> bb; + if (aa == a) a = bb; + if (aa == b) b = bb; + cout << a << " " << b << "\n"; + } +} +int main() { + set v; + set::iterator it; + int n, k; + char a; + cin >> n >> k; + for (int i = 0; i < n; ++i) { + cin >> a; + v.insert(a); + } + char s[101]; + int i = 0; + for (it = v.begin(); it != v.end(); ++i, ++it) { s[i] = *it; } + char c[101]; + int l = 0; + for (int j = 0; j < i; j++) { + if (s[j + 1] - s[j] == 1) { + c[l] = s[j]; + l++; + j = j + 1; + } else { + c[l] = s[j]; + l++; + } + } + int p = 0; + if (l >= k) { + for (int j = 0; j < k; j++) p = c[j] - 96 + p; + cout << p << endl; + } else + cout << "-1" << endl; +} +const int INF = (int)1e9; +const int mod = (int)1e9 + 7; +const int MAX = (int)3e4 + 5; +void build() { + return; +} +int n, l; +string store[MAX]; +void Init() { + cin >> n; + for (int i = 0; i < (n); ++i) cin >> store[i]; + l = store[0].length(); + return; +} +void sol() { + string cmp = store[0]; + for (int i = (1); i < (n); ++i) { + for (int j = 0; j < (l); ++j) { + if (store[i][j] != cmp[j]) { + l = j; + break; + } + } + } + cout << l << endl; + return; +} +int main() { + Init(); + build(); + sol(); + return 0; +} +map mp; +string password, rope; +int main() { + cin >> password; + for (int i = 0; i < 10; i++) { + cin >> rope; + mp[rope] = i; + } + for (int i = 0; i < password.length(); i += 10) { + string s = password.substr(i, 10); + cout << mp[s]; + } + cout << endl; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int ans = 0; + while (a > 0) { + ans++; + int nuts = v * min(b + 1, k); + b -= min(k, b + 1) - 1; + a -= nuts; + } + cout << ans << endl; + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + string s[n]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + char ch; + cin >> ch; + s[i].push_back(ch); + } + } + for (int i = 0; i < n; ++i) { + int c = 0; + for (int j = 0; j < n; ++j) { + if (s[i][j] == 'C') ++c; + } + if (c > 1) { + c--; + while (c) { + ans += c; + c--; + } + } + } + for (int i = 0; i < n; ++i) { + int c = 0; + for (int j = 0; j < n; ++j) { + if (s[j][i] == 'C') ++c; + } + if (c > 1) { + c--; + while (c) { + ans += c; + c--; + } + } + } + cout << ans << endl; +} +int64_t na; +int64_t nb; +int64_t k; +int64_t m; +int64_t i = 0; +int64_t a; +int main() { + cin >> na; + cin >> nb; + cin >> k; + cin >> m; + int64_t an[na]; + int64_t bn[nb]; + while (i < na) { + cin >> a; + an[i] = a; + i += 1; + }; + i = 0; + while (i < nb) { + cin >> a; + bn[i] = a; + i += 1; + } + sort(an, an + na); + sort(bn, bn + nb); + if (an[k - 1] < bn[nb - m]) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + }; + return 0; +} +const int maxn = 10000; +char a[100]; +int b[100]; +int main() { + int n, m, sum = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + int j = a[i] - 'a'; + b[j]++; + } + for (int i = 0; i < 26; i++) { + if (b[i] > m) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +long long MOD = 1000000007; +int main() { + long long H, W; + cin >> H >> W; + vector A(H); + long long res = 0; + for (long long i = 0; i < H; i++) { cin >> A[i]; } + string a; + for (long long i = 0; i < H - 1; i++) { + for (long long j = 0; j < W - 1; j++) { + a.clear(); + for (long long x = i; x <= i + 1; x++) { + for (long long y = j; y <= j + 1; y++) { a.push_back(A[x][y]); } + } + sort(a.begin(), a.end()); + if (a == "acef") res++; + } + } + cout << res << endl; +} +vector v; +int main() { + int n, p, k; + cin >> n >> p >> k; + for (int x = p - k; x <= p + k; x++) { + if (x < 1) continue; + if (x > n) continue; + v.push_back(x); + } + if (v[0] != 1) cout << "<< "; + for (int(i) = (0); (i) < (((int)v.size())); ++(i)) { + if (v[i] == p) cout << "("; + cout << v[i]; + if (v[i] == p) cout << ")"; + if (i == ((int)v.size()) - 1) { + if (v[i] < n) + cout << " >>" << endl; + else + cout << endl; + } else + cout << " "; + } + return 0; +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, h, a[10], now, ans; +set st; +string s, t; +int main() { + cin >> s; + cin >> t; + for (int i = 0; i < t.size(); i++) { + if (s[now] == t[i]) { now++; } + } + cout << now + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + char *s1 = "I hate it"; + char *s2 = "I hate that"; + char *s3 = "I love that"; + char *s4 = "I love it"; + if (n == 1) + cout << s1; + else if (n % 2 == 1) { + for (int i = 1; i <= n; i++) { + if (i == n) + cout << s1; + else if (i % 2 == 1) + cout << s2 << " "; + else + cout << s3 << " "; + } + } else { + for (int i = 1; i <= n; i++) + if (i == n) + cout << s4; + else if (i % 2 == 0) + cout << s3 << " "; + else + cout << s2 << " "; + } + cout << endl; + return 0; +} +int main() { + int size, in[100005]; + vector d1; + cin >> size; + for (int i = 0; i < size; i++) { cin >> in[i]; } + int mn = 1e9; + for (int i = 0; i < size; i++) { + if (in[i] < mn) { mn = in[i]; } + } + for (int i = 0; i < size; i++) { + if (mn == in[i]) { d1.push_back(i); } + } + int mns = 1e9; + for (int i = 0; i < d1.size() - 1; i++) { + if (abs(d1[i] - d1[i + 1]) < mns) { mns = abs(d1[i] - d1[i + 1]); } + } + cout << mns << endl; + return 0; +} +int main() { + int ar[101], ar1[101]; + int n, m; + cin >> n >> m; + int flag = 0; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + for (int i = 0; i < m; i++) { cin >> ar1[i]; } + int maxl = ar[0]; + int min1 = ar[0]; + for (int i = 0; i < n; i++) { + if (maxl < ar[i]) { maxl = ar[i]; } + if (min1 > ar[i]) { min1 = ar[i]; } + } + int val = max(2 * min1, maxl); + int mini = ar1[0]; + for (int i = 0; i < m; i++) { + if (mini > ar1[i]) { mini = ar1[i]; } + } + if (val < mini) { + cout << val << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + long long n, x, y, d, f, l; + long long ans = INT_MAX, ans1 = INT_MAX; + cin >> n >> x >> y >> d; + if (abs(x - y) % d == 0) { + cout << abs(x - y) / d << endl; + continue; + } + f = y - 1; + l = n - y; + if (f % d == 0) { + ans = ceil((double)x / (double)d); + ans += (f / d); + } + if (l % d == 0) { + ans1 = ceil((double)(n - x) / (double)d); + ans1 += (l / d); + } + if (min(ans, ans1) == INT_MAX) + cout << "-1" << endl; + else + cout << min(ans, ans1) << endl; + } + return 0; +} +const long long linf = 1LL << 62; +const int iinf = 1000000009; +const double dinf = 1e17; +const int Mod = 1e9 + 9; +const int maxn = 1005; +int n; +string s1, s2, n1, n2; +void solve() { + cin >> s1; + cin >> s2; + cin >> n; + for (int i = 1; i <= n; i++) { + cout << s1 << " " << s2 << endl; + cin >> n1; + cin >> n2; + if (n1 == s1) + s1 = n2; + else if (n1 == s2) + s2 = n2; + } + cout << s1 << " " << s2 << endl; +} +int main() { + int t = 1; + while (t--) solve(); + return 0; +} +int main() { + int t; + long long int s, a, b, c, i; + cin >> t; + long long int r[t]; + for (i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + if ((s / c) >= a) { + r[i] = ((s / (c * a)) * b) + (s / c); + } else { + r[i] = s / c; + } + } + for (int i = 0; i < t; i++) { cout << r[i] << endl; } + return 0; +} +char a[1005]; +int main() { + int pos = 0; + cin >> a; + for (int i = 0; i < strlen(a); i++) { + if (a[i] == '.') { + pos = i; + break; + } + } + if (a[pos - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + } else { + if (a[pos + 1] >= '5') { + for (int i = 0; i < pos - 1; i++) { cout << a[i]; } + a[pos - 1] = a[pos - 1] + 1; + cout << a[pos - 1] << endl; + } else { + for (int i = 0; i < pos; i++) cout << a[i]; + cout << endl; + } + } + return 0; +} +bool cmp(int x, int y) { + return x > y; +} +int main() { + int n, num[105], s1 = 0, s2 = 0; + cin >> n; + for (int i = 0; i < n; ++i) cin >> num[i]; + sort(num, num + n, cmp); + for (int i = 0; i < n; ++i) { + if (num[i] >= 0) { + s1 += num[i]; + } else { + s2 += num[i]; + } + } + cout << s1 - s2 << '\n'; + return 0; +} +bool kkk(pair a, pair b) { + return (a.first == b.first) ? (a.second < b.second) : (a.first < b.first); +} +void inc(int *k) { + (*k)++; +} +int main() { + int n; + cin >> n; + int p = 0; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < n; j++) { + if (abs((n / 2) - j) > p) { + cout << "*"; + } else + cout << "D"; + } + p++; + cout << endl; + } + for (int i = 0; i < n / 2 + 1; i++) { + for (int j = 0; j < n; j++) { + if (abs((n / 2) - j) > p) { + cout << "*"; + } else + cout << "D"; + } + p--; + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if ((n + 1) % 36 == 0) n++; + int ft = n / 36; + n %= 36; + int in; + if (n % 3 == 0 || (n - 1) % 3 == 0) + in = n / 3; + else + in = n / 3 + 1; + cout << ft << ' ' << in << '\n'; + return 0; +} +inline void setmin(int &x, int y) { + if (y < x) x = y; +} +inline void setmax(int &x, int y) { + if (y > x) x = y; +} +inline void setmin(long long &x, long long y) { + if (y < x) x = y; +} +inline void setmax(long long &x, long long y) { + if (y > x) x = y; +} +const int N = 100000; +const int inf = (int)1e9 + 1; +const long long big = (long long)1e18 + 1; +const int P = 239; +const int MOD = (int)1e9 + 7; +const int MOD1 = (int)1e9 + 9; +const double eps = 1e-9; +const double pi = atan2(0, -1); +const int ABC = 26; +int main() { + cout.precision(20); + cout << fixed; + int k, a, b, v; + cin >> k >> a >> b >> v; + for (int ans = 1;; ans++) + if ((ans + min(b, ans * (k - 1))) * v >= a) { + cout << ans << "\n"; + break; + } + return 0; +} +int main() { + int a; + cin >> a; + cout << a % 2 << endl; +} +bool split(int x) { + int flg = 0; + int t = 0; + int ar[4]; + int u; + while (x > 0) { + ar[t] = x % 10; + x = x / 10; + t++; + } + for (t = 0; t <= 2; t++) { + for (u = t + 1; u <= 3; u++) { + if (ar[t] == ar[u]) { + flg = 1; + return false; + break; + } + } + } + return true; +} +int main() { + int n; + cin >> n; + bool p = false; + while (p == false) { + n = n + 1; + p = split(n); + if (p == true) { cout << n << endl; } + } + return 0; +} +int main() { + int n; + cin >> n; + int a, b, c; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if (a + b + c >= 2) count++; + } + cout << count << endl; + return 0; +} +int main() { + int n, result = 0; + cin >> n; + while (n > 0) { + if (n % 2) { result++; } + n /= 2; + } + cout << result << endl; + return 0; +} +int dp[100001]; +char s[100001]; +int book[26]; +int boox[26]; +int main() { + int n, k; + while (cin >> n >> k) { + int ans = 0; + memset(book, 1, sizeof(book)); + cin >> s; + for (int i = 0; i < n; i++) { + if (book[s[i] - 65]) { + book[s[i] - 65] = 0; + ans++; + } + boox[s[i] - 65]++; + } + if (ans != k) + cout << 0 << endl; + else { + int miax = 10000000; + for (int i = 0; i < 26; i++) { + if (boox[i] == 0) + continue; + else { + if (boox[i] < miax) miax = boox[i]; + } + } + cout << miax * k << endl; + } + } +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + cin >> n; + if (n == 1) + cout << "I hate it" << endl; + else { + cout << "I hate "; + int x = 0; + while (x < n - 1) { + x++; + if (x % 2 != 0) + cout << "that I love "; + else + cout << "that I hate "; + } + cout << "it" << endl; + } +} +int main() { + int n, a, b; + cin >> n >> a >> b; + char aN[100000]; + cin >> aN; + if (aN[a - 1] != aN[b - 1]) + cout << 1 << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + vector v(n); + vector s(n); + for (int i = 0; i < n; i++) { + cin >> v[i]; + s[i] = v[i]; + } + sort(s.begin(), s.end()); + int a, b; + a = s[0]; + b = s[1]; + int x, y, d; + d = x = y = 1000000100; + bool sw = true; + for (int i = 0; i < n; i++) { + if (a == v[i]) { + x = i; + break; + } + } + for (int i = x + 1; i < n; i++) { + if (b == v[i]) { + y = i; + d = min(d, abs(x - y)); + x = i; + } + } + cout << d << "\n"; + } + return 0; +} +int g(int n) { + while (__builtin_popcount(n) > 1) n = n & (n - 1); + return n; +} +int main() { + int n, b, p, r = 0, m; + cin >> n >> b >> p; + m = n; + while (n > 1) { + int x = g(n); + r += x * (b); + r += x / 2; + n -= x / 2; + } + cout << r << " " << p * m << endl; + return 0; +} +int n; +vector arr(210); +int main() { + cin >> n; + for (int i = 1; i <= 2 * n; ++i) { cin >> arr[i]; } + sort(arr.begin() + 1, arr.begin() + 2 * n + 1, greater()); + if (arr[n] > arr[n + 1]) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int n, k, l, r, ans; +int main() { + cin >> n >> k; + int sum = 0; + ans = 0; + for (int i = 0; i < n; i++) { + cin >> l >> r; + sum += (r - l + 1); + } + if (sum % k != 0) ans = (k - (sum % k)); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + vector v; + int a; + for (int i = 0; i < n - 1; i++) { + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + int count = 0; + while (1) { + if (x > v[0]) + break; + else { + count++; + x++; + v[0]--; + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + } + } + cout << count << endl; + return 0; +} +int main() { + char s[106]; + while (gets(s)) { + int a = 0, b = 0, ll = strlen(s); + for (int i = 0; i < ll; i++) { + if (s[i] == '-') + a++; + else if (s[i] == 'o') + b++; + } + if (b == 0 || a % b == 0) + puts("YES"); + else + puts("NO"); + } +} +int main() { + long long a, b, c, l, i, x, num = 0; + cin >> a >> b >> c >> l; + for (i = 0; i <= l; i++) { num += (i + 1) * (i + 2) / 2; } + for (i = a; i <= a + l; i++) { + if (b + c <= i) { + x = min(i, a + b + c + l - i) - b - c; + num -= (x + 1) * (x + 2) / 2; + } + } + for (i = b; i <= b + l; i++) { + if (a + c <= i) { + x = min(i, a + b + c + l - i) - a - c; + num -= (x + 1) * (x + 2) / 2; + } + } + for (i = c; i <= c + l; i++) { + if (b + a <= i) { + x = min(i, a + b + c + l - i) - b - a; + num -= (x + 1) * (x + 2) / 2; + } + } + cout << num << endl; + return 0; +} +int main() { + int a, b, c, d; + float misha, vashya; + cin >> a >> b >> c >> d; + misha = max((3 * a) / 10, a - (a * c) / 250); + vashya = max((3 * b) / 10, b - (b * d) / 250); + if (misha > vashya) + cout << "Misha" << endl; + else if (vashya > misha) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; +} +int main() { + int a, b, c, d, e, f, g; + while (cin >> a >> b >> c) { + if (a == b) { + a += c / 2; + b += c / 2; + cout << a + b << endl; + continue; + } else { + if (a < b) { + while (a < b and c > 0) { + a++; + c--; + } + a += c / 2; + b += c / 2; + } else { + while (b < a and c > 0) { + b++; + c--; + } + a += c / 2; + b += c / 2; + } + cout << min(a, b) * 2 << endl; + } + } +} +int n, ans = 0; +int a[101], b[101]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (a[i] == b[j] && i != j) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int inches = n / 3 + (n % 3 > 1); + cout << inches / 12 << " " << inches % 12 << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + int count = 0; + cin >> a[0]; + int mx = a[0], mn = a[0]; + for (int i = 1; i < n; i++) { + cin >> a[i]; + if (mx < a[i]) { + mx = a[i]; + count++; + } else if (mn > a[i]) { + mn = a[i]; + count++; + } + } + cout << count << endl; +} +int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int m, n; + cin >> m >> n; + int ans = (a[m] + n - 1) % 7; + if (ans > 0) + ans = 1 + (a[m] + n - 1) / 7; + else + ans = (a[m] + n - 1) / 7; + cout << ans << endl; + return 0; +} +int n; +string ss[1001]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + char s[1001]; + cin >> s; + sort(s, s + strlen(s)); + int pos = unique(s, s + strlen(s)) - s; + s[pos] = '\0'; + ss[i] = s; + } + sort(ss + 1, ss + n + 1); + cout << unique(ss + 1, ss + n + 1) - ss - 1 << endl; +} +long long a, b, n[30]; +char k; +int main() { + cin >> a >> b; + while (a--) cin >> k, n[k - 'a']++; + for (int s = 0; s < 26; s++) { + if (n[s] > b) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, k = 0; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '8') { k++; } + } + cout << min(n / 11, k) << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int i, n = a.length(); + for (i = 0; i < n; i++) { + if (a[i] == b[i]) + a[i] = '0'; + else + a[i] = '1'; + } + cout << a << endl; + return 0; +} +int main() { + set p; + int x, y; + cin >> x >> y; + for (int i = 0; i < x; i++) { + int a; + cin >> a; + for (int j = 0; j < a; j++) { + int m; + cin >> m; + p.insert(m); + } + } + int l; + l = p.size(); + if (l == y) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +string s; +int ans; +int main() { + cin >> s; + for (int i = 0; i < s.size() - 1; i++) { + if (s[i] == 'V' && s[i + 1] == 'K') { + s[i] = 'a'; + s[i + 1] = 'b'; + ans++; + } + } + for (int i = 0; i < s.size() - 1; i++) { + if (s[i] == s[i + 1]) { + ans++; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long a, b; + cin >> a >> b; + long long ans = 0; + while (a > 0 && b > 0) { + if (a > b) { + int d = (a - b) / b; + if (a - (d + 1) * b >= 0) { + ans += (d + 1); + a -= (d + 1) * b; + } else { + ans += d; + a -= (d * b); + } + } else { + int d = (b - a) / a; + if (b - (d + 1) * a >= 0) { + ans += (d + 1); + b -= (d + 1) * a; + } else { + ans += d; + b -= (d * a); + } + } + } + cout << ans << endl; + } +} +int a[2 * 102]; +int main() { + int n; + cin >> n; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + if (a[n - 1] < a[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string f, s, t1, t2; +int n; +int main() { + cin >> f >> s; + cin >> n; + cout << f << ' ' << s << '\n'; + for (int i = 0; i < n; i++) { + cin >> t1 >> t2; + if (f == t1) + f = t2; + else if (f == t2) + f = t1; + if (s == t1) + s = t2; + else if (s == t2) + s = t1; + cout << f << ' ' << s << '\n'; + } +} +int a[100005], n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) + if (a[a[a[i]]] == i) { + puts("YES"); + return 0; + } + puts("NO"); + return 0; +} +int main() { + int n, m, div = 1, sum = 0, mod, p; + cin >> n >> m; + p = n; + if (n < m) { + cout << n << endl; + return 0; + } + while (div != 0) { + div = n / m; + sum += div; + mod = n % m; + n = mod + div; + } + cout << sum + p << endl; +} +int n, wp[55], dg[55], sg[55]; +string name[55]; +bool cmp(int a, int b) { + if (wp[a] != wp[b]) { return wp[a] > wp[b]; } + if (dg[a] != dg[b]) { return dg[a] > dg[b]; } + return sg[a] > sg[b]; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> name[i]; } + for (int i = 0; i < n * (n - 1) / 2; i++) { + string s, a, b; + int p, q; + char c; + cin >> s >> p >> c >> q; + a = s.substr(0, s.find('-')); + b = s.substr(s.find('-') + 1); + int a1 = find(name, name + n, a) - name, b1 = find(name, name + n, b) - name; + if (p > q) { + wp[a1] += 3; + } else if (q == p) { + wp[a1]++; + wp[b1]++; + } else { + wp[b1] += 3; + } + dg[a1] += p - q; + sg[a1] += p; + dg[b1] += q - p; + sg[b1] += q; + } + int a[55]; + for (int i = 0; i < n; i++) { a[i] = i; } + sort(a, a + n, cmp); + string ans[55]; + for (int i = 0; i < n / 2; i++) { ans[i] = name[a[i]]; } + sort(ans, ans + n / 2); + for (int i = 0; i < n / 2; i++) { cout << ans[i] << endl; } + return 0; +} +int main() { + long long n; + cin >> n; + int g = (int)sqrt(n); + int ans = 0; + for (int i = 1; i <= g; i++) { + if ((n % i) == 0) { ans = i; } + } + cout << ans << " " << n / ans << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n; + int s = 0, minimum = 1000; + while (n--) { + cin >> a >> b; + minimum = min(minimum, b); + s = s + minimum * a; + } + cout << s << endl; + return 0; +} +int main() { + int a, b, k, m; + cin >> a >> b >> k >> m; + int arr1[a + 5], arr2[b + 5]; + for (int i = 0; i < a; i++) { cin >> arr1[i]; } + sort(arr1, arr1 + a); + for (int i = 0; i < b; i++) { cin >> arr2[i]; } + sort(arr2, arr2 + b); + if (arr1[k - 1] < arr2[b - m]) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long a, b, c; + while (cin >> a >> b >> c) { + long long d, e; + if (a % c != 0) d = a / c + 1; + if (b % c != 0) e = b / c + 1; + if (a % c == 0) d = a / c; + if (b % c == 0) e = b / c; + long long f = d * e; + cout << f << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0, len = s.length() - 2; i < len; i++) { + if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { + int j = i + 3; + while (s[j] == 'g' && s[j + 1] == 'o') j += 2; + s = s.substr(0, i) + "***" + s.substr(j); + len = s.length() - 2; + } + } + cout << s << endl; +} +int main() { + int n, n4, n7, i; + cin >> n; + n4 = n7 = 0; + for (i = 0; i <= n / 4; i++) { + if ((n - i * 4) % 7 == 0) { + n4 = i; + n7 = (n - (n4 * 4)) / 7; + break; + } + } + if (n4 == 0 && n7 == 0) { + cout << "-1" << endl; + } else { + for (i = 0; i < n4; i++) { cout << "4"; } + for (i = 0; i < n7; i++) { cout << "7"; } + cout << endl; + } + return 0; +} +int main() { + int n, m, mx[101]; + vector vc; + set st; + cin >> n >> m; + vc.resize(n); + memset(mx, 0, sizeof mx); + for (int i = 0; i < n; ++i) { + cin >> vc[i]; + for (int j = 0; j < m; ++j) mx[j] = max(mx[j], (vc[i][j] - '0')); + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) + if (mx[j] == (vc[i][j] - '0')) st.insert(i); + } + cout << st.size() << endl; + return 0; +} +int main() { + int x; + cin >> x; + int tabla[x][x]; + for (int i = 0; i < x; i++) { tabla[0][i] = 1; } + for (int i = 0; i < x; i++) { tabla[i][0] = 1; } + for (int i = 1; i < x; i++) { + for (int a = 1; a < x; a++) { tabla[i][a] = tabla[i - 1][a] + tabla[i][a - 1]; } + } + cout << tabla[x - 1][x - 1] << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + if (s == t) + cout << s << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int z = 0, x = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'o') { z++; } + if (s[i] == '-') { x++; } + } + if (z == 0 || x == 0 || x % z == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + string str; + cin >> str; + int diff = 0; + for (int i = 0; i < str.size(); i++) { diff += str[i] != str[str.size() - 1 - i]; } + if (diff == 2 || diff == 0 && str.size() % 2 == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + long long int i, j, k, l; + cin >> l; + k = l / 2; + j = k + k + k; + cout << j << endl; +} +long long gcd(long long a, long long b) { + while (b) swap(a %= b, b); + return a; +} +long long power(long long a, long long b) { + long long res = 1; + while (b) { + if (b % 2) res = (res * a) % 1000000007; + a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; + b /= 2; + } + return res; +} +int main() { + string s; + cin >> s; + long long cnt = 0; + for (long long i = 0; i < s.length(); ++i) { + if (s[i] != 'Q') continue; + for (long long j = i + 1; j < s.length(); ++j) { + if (s[j] != 'A') continue; + for (long long k = j + 1; k < s.length(); ++k) { + if (s[k] == 'Q') cnt++; + } + } + } + cout << cnt << endl; +} +int main() { + int n; + cin >> n; + vector v; + for (int i = 2; i * i <= n; i++) + if (n % i == 0) v.push_back(i); + int a = 1, b = n; + for (int i = 0; i < v.size(); i++) + if (n / v[i] - v[i] <= b - a) { + a = v[i]; + b = n / v[i]; + } + cout << a << ' ' << b << endl; + return 0; +} +int did[103]; +int main() { + long long n, m; + pair p; + p.first = 1; + p.second = 0; + cin >> n >> m; + long long x; + pair maxx; + for (int i = 1; i <= m; i++) { + cin >> x; + maxx.first = 1; + maxx.second = x; + for (int j = 2; j <= n; j++) { + cin >> x; + if (x > maxx.second) { + maxx.first = j; + maxx.second = x; + } + } + did[maxx.first]++; + } + for (int i = 1; i <= n; i++) { + if (did[i] > p.second) { + p.second = did[i]; + p.first = i; + } + } + cout << p.first << "\n"; +} +int main() { + int test; + cin >> test; + for (int a = 0; a < test; a++) { + int num; + cin >> num; + string s; + cin >> s; + int flag = 0; + for (int i = 0, j = num - 1; i < num / 2; i++, j--) { + if (s[i] == s[j]) + continue; + else if (s[i] - 1 == s[j] - 1) + continue; + else if (s[i] - 1 == s[j] + 1) + continue; + else if (s[i] + 1 == s[j] - 1) + continue; + else if (s[i] + 1 == s[j] + 1) + continue; + flag = 1; + break; + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + long long int n, sum = 0; + string s; + cin >> n; + while (n--) { + cin >> s; + if (s == "Tetrahedron") + sum += 4; + else if (s == "Cube") + sum += 6; + else if (s == "Octahedron") + sum += 8; + else if (s == "Dodecahedron") + sum += 12; + else if (s == "Icosahedron") + sum += 20; + } + cout << sum << endl; + return 0; +} +int n, s; +bool a[1111], b[1111]; +int main() { + cin >> n >> s; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + if (!a[1]) { + cout << "NO" << endl; + } else if (a[1] && a[s]) { + cout << "YES" << endl; + } else { + int flag = 0; + for (int i = s + 1; i <= n; i++) { + if (a[i]) { + if (b[i] && b[s]) { + flag = 1; + break; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const long long Y = 1e5 + 1; +long long zero(long long n) { + int r = 0; + int t = 1; + while (n) { + long long dig = n % 10; + n /= 10; + if (dig) { + r += dig * t; + t *= 10; + } + } + return r; +} +long long array[Y]; +long long a, b, c; +int main() { + cin >> a >> b; + c = a + b; + a = zero(a); + b = zero(b); + c = zero(c); + if (a + b == c) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k, w; + cin >> n >> k >> w; + int cost = 0; + for (int i = 1; i <= w; i++) { cost += i * n; } + if (cost - k > 0) + cout << cost - k << endl; + else + cout << 0 << endl; +} +string a; +int main() { + int i, j, k, t, q, m, n; + cin >> a; + n = a.size(); + int l = 0, r = 1, cnt = 0; + while (r < n) { + if (a[r] == a[l]) + r++; + else { + if ((r - l) % 2 == 0) cnt++; + l = r; + } + } + if ((r - l) % 2 == 0) cnt++; + cout << cnt << '\n'; +} +const int N = 2e3 + 3; +const int mod = 1e9 + 7; +const int INF = INT_MAX; +int main() { + int q; + cin >> q; + while (q--) { + int n; + cin >> n; + string s; + cin >> s; + if (n == 2) { + if (s[0] >= s[1]) + cout << "NO\n"; + else + cout << "YES\n2\n" << s[0] << " " << s[1] << "\n"; + } else { + cout << "YES\n2\n" << s[0] << " " << s.substr(1) << "\n"; + } + } +} +int main() { + int n; + while (cin >> n) { + int a = 0, b = 0; + for (int i = n / 7; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (i * 7 + j * 4 == n) { + a = i; + b = j; + break; + } + if (i * 7 + j * 4 > n) break; + } + if (a > 0 || b > 0) break; + } + if (a == 0 && b == 0) cout << "-1"; + for (int i = 0; i < b; i++) cout << "4"; + for (int i = 0; i < a; i++) cout << "7"; + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n % 2 == 0 && m % 2 == 0) + cout << "Malvika" << endl; + else if (n % 2 != 0 && m % 2 != 0) + cout << "Akshat" << endl; + else if (n % 2 == 0 && m % 2 != 0 && n > m) + cout << "Akshat" << endl; + else if (n % 2 == 0 && m % 2 != 0 && n < m) + cout << "Malvika" << endl; + else if (n % 2 != 0 && m % 2 == 0 && n < m) + cout << "Akshat" << endl; + else if (n % 2 != 0 && m % 2 == 0 && n > m) + cout << "Malvika" << endl; +} +int main() { + int participants, bottles, towels; + int total_b = 0, total_t = 0, matches; + cin >> participants >> bottles >> towels; + total_t = participants * towels; + while (participants != 1) { + matches = participants / 2; + if (participants % 2 == 1) { + total_b += (participants - 1) * bottles + matches; + participants = participants / 2 + 1; + } else { + total_b += participants * bottles + matches; + participants = participants / 2; + } + } + cout << total_b << " " << total_t << endl; + return 0; +} +char putR(string s, char c) { + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == c) return s[i + 1]; + } +} +char putL(string s, char c) { + for (int i = 1; i < s.length(); i++) { + if (s[i] == c) return s[i - 1]; + } +} +int main() { + char c; + string s, s1, s2, s3; + cin >> c >> s; + s1 = "qwertyuiopasdfghjkl;zxcvbnm,./"; + if (c == 'L') { + for (int i = 0; i < s.length(); i++) s[i] = putR(s1, s[i]); + } else { + for (int i = 0; i < s.length(); i++) s[i] = putL(s1, s[i]); + } + cout << s << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + return 0; +} +long long mat[100][100] = {0}; +int main() { + long long n; + cin >> n; + while (n--) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + a--, b--, c--, d--; + for (long long i = a; i <= c; i++) { + for (long long j = b; j <= d; j++) mat[i][j]++; + } + } + long long ans = 0; + for (long long i = 0; i < 100; i++) { + for (long long j = 0; j < 100; j++) { ans += mat[i][j]; } + } + cout << ans << endl; +} +long long n, a[107], i, j, r = 0; +int main() { + cin >> n; + cin >> a[1]; + for (i = 2; i <= n; i++) { cin >> a[i]; } + long long p = a[1]; + sort(a + 1, a + n + 1); + if (p == a[n] && p > a[n - 1]) + cout << 0 << endl; + else { + while (a[n] >= p) { + p++; + a[n]--; + r++; + sort(a + 1, a + n + 1); + } + cout << r << endl; + } + return 0; +} +long long a, b, c, l; +int main() { + cin >> a >> b >> c >> l; + long long sum = a + b + c + l; + long long ans = (l + 3) * (l + 2) * (l + 1) / 6; + long long tmp1 = 0; + for (long long i = a; i <= a + l; i++) { + if (b + c > i) continue; + long long t = min(sum - i, i); + tmp1 += (t + 1 - b - c) * (t + 2 - b - c) / 2; + } + for (long long i = b; i <= b + l; i++) { + if (a + c > i) continue; + long long t = min(sum - i, i); + tmp1 += (t + 1 - c - a) * (t + 2 - a - c) / 2; + } + for (long long i = c; i <= c + l; i++) { + if (a + b > i) continue; + long long t = min(sum - i, i); + tmp1 += (t + 1 - a - b) * (t + 2 - a - b) / 2; + } + cout << ans - tmp1 << endl; + return 0; +} +int main() { + long long int t, a, b, x, i; + cin >> t; + for (i = 0; i < t; i++) { + cin >> a >> b >> x; + long long int n = x / 2; + if (x % 2 == 0) { + cout << n * (a - b) << "\n"; + } else { + cout << n * (a - b) + a << "\n"; + } + } + return 0; +} +int n; +string s; +int main() { + cin >> n; + string *p = new string[n]; + for (int i = 0; i < n; i++) { + cin >> s; + p[i] = s; + } + for (int i = 0; i < n; i++) { + s = p[i]; + if (s.size() > 10) + cout << s[0] << s.size() - 2 << s[s.size() - 1] << "\n"; + else + cout << s << "\n"; + } +} +const double EPS = 1e-8; +void fast() {} +bool sortby(const pair &a, const pair &b) { + if (a.first >= b.first && a.second >= b.second) return true; + return false; +} +double area(int x1, int y1, int x2, int y2, int x3, int y3) { + return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int arr[205]; +int main() { + fast(); + int n, mn = INT_MAX, x, mnind; + cin >> n; + map mp; + for (int i = 0; i < n; i++) { + cin >> x; + mp[x]++; + if (mn > x) { + mn = x; + mnind = i + 1; + } + } + if (mp[mn] > 1) + cout << "Still Rozdil" << endl; + else + cout << mnind << endl; + return 0; +} +int main() { + char a[1000005], b[1000005], c[1000005], d[1000005]; + gets(a); + gets(b); + int i, j; + for (i = 0; a[i] == '0' && a[i + 1] != '\0'; i++) + ; + for (j = 0; a[i] != '\0'; i++) { c[j++] = a[i]; } + c[j] = a[i]; + for (i = 0; b[i] == '0' && b[i + 1] != '\0'; i++) + ; + for (j = 0; b[i] != '\0'; i++) { d[j++] = b[i]; } + d[j] = b[i]; + int lenc = strlen(c); + int lend = strlen(d); + if (lenc > lend) { + cout << ">" << endl; + return 0; + } else if (lenc < lend) { + cout << "<" << endl; + return 0; + } else { + for (i = 0; i < lenc; i++) { + if (c[i] > d[i]) { + cout << ">" << endl; + return 0; + } else if (c[i] < d[i]) { + cout << "<" << endl; + return 0; + } + } + } + cout << "=" << endl; + return 0; +} +const int maxn = 1e5 + 10; +const int mod = 1e9 + 7; +int a[maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + for (int i = 0; i < n; i++) { + int tmp = 0; + for (int j = i; j < n; j++) { + tmp ^= a[j]; + ans = max(ans, tmp); + } + } + cout << ans << endl; +} +int main() { + int a, b, x, y; + cin >> a >> b >> x >> y; + x = abs(a - x); + y = abs(b - y); + (x > y) ? cout << x << endl : cout << y << endl; + return 0; +} +int main() { + int n; + int val; + cin >> n; + for (int i = 0; i < n; ++i) { + if (i > 0) { cout << " "; } + cin >> val; + cout << (val - ((val + 1) % 2)); + } + cout << endl; + return 0; +} +const int N = 5000 + 9; +string s; +int n; +bool can[N][N]; +int main() { + cin >> s; + n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int c = 0, q = 0; + bool fail = 0; + for (int j = i; j < n; j++) { + if (s[j] == '(') + c++; + else if (s[j] == ')') + c--; + else + q++; + if (c + q < 0) fail = 1; + if (fail == 0 && -c + q >= 0 && ((j - i + 1) & 1) == 0) { can[i][j] = 1; } + } + } + for (int i = n - 1; i >= 0; i--) { + int c = 0, q = 0; + bool fail = 0; + for (int j = i; j >= 0; j--) { + if (s[j] == '(') + c--; + else if (s[j] == ')') + c++; + else + q++; + if (c + q < 0) fail = 1; + if (can[j][i] && fail == 0 && c + q >= 0 && ((j - i + 1) & 1) == 0) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + long long int k, f, t, joy, temp; + cin >> n >> k; + cin >> f >> t; + if (t > k) + joy = (f - (t - k)); + else + joy = f; + for (int i = 2; i <= n; i++) { + cin >> f >> t; + if (t > k) + temp = (f - (t - k)); + else + temp = f; + if (temp > joy) joy = temp; + } + cout << joy << endl; + return 0; +} +int n; +unsigned long long l, r; +unsigned long long getit() { + unsigned long long k = 0; + while (l < r) { + unsigned long long temp = l | k; + if (temp > r) break; + l |= k; + k = k << 1; + k |= 1; + } + if (l == r) return l; + return l; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> l >> r; + cout << getit() << '\n'; + } + return 0; +} +int main() { + int x = 0; + for (int i = 1; i <= 5; ++i) { + for (int j = 1; j <= 5; ++j) { + cin >> x; + if (x == 1) { cout << abs(i - 3) + abs(j - 3) << endl; } + } + } + return 0; +} +int n, m, t[100], f[100], sum, ans; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> t[i]; + sum += t[i]; + } + ans = sum / n; + for (int i = 0; i < m; i++) cin >> f[i]; + sort(t, t + n); + for (int i = 0; i < n; i++) { + if (i == 0 && 2 * t[i] > ans) ans = 2 * t[i]; + if (t[i] > ans) ans = t[i]; + } + for (int i = 0; i < m; i++) { + if (f[i] <= ans) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; +} +int main() { + long long t1, t2, v1, v2, s; + cin >> s >> v1 >> v2 >> t1 >> t2; + if ((2 * t1 + v1 * s) < (2 * t2 + v2 * s)) { + cout << "First\n"; + } else if ((2 * t1 + v1 * s) > (2 * t2 + v2 * s)) { + cout << "Second\n"; + } else { + cout << "Friendship\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + while (n--) { + int x, xx, y, yy; + cin >> x >> y >> xx >> yy; + ans += (abs(xx - x) + 1) * (abs(yy - y) + 1); + } + cout << ans << endl; + return 0; +} +void File() { + freopen("colors.in", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 1e5 + 5; +const int oo = 0x3f3f3f3f; +bool isPrime(long long n) { + if (n < 2) return 0; + if (n % 2 == 0) return (n == 2); + for (long long i = 3; i * i <= n; i += 2) { + if (n % i == 0) return 0; + } + return 1; +} +int main() { + fast(); + long long res[nn] = {}, idx = 0; + for (int i = 2; idx < 50; i++) { + if (isPrime(i)) res[idx++] = i; + } + long long a, b; + cin >> a >> b; + int first = lower_bound(res, res + idx, a) - res; + int second = lower_bound(res, res + idx, b) - res; + if (res[first] == a && res[second] == b && first + 1 == second) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +char a[300005]; +int main() { + long long int n, x, y; + cin >> n >> x >> y; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int num = 0; + for (int i = 1; i < n; i++) { + if (a[i] == '1' && a[i - 1] == '0') { num++; } + } + if (a[n - 1] == '0') { num++; } + if (num == 0) { + cout << "0" << endl; + } else { + long long int ans = min((num - 1) * x + y, num * y); + cout << ans << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int i, j; + int len = s.length(); + int cnt = 0; + for (i = 0; i < len; i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') cnt++; + } + if (s[i] >= '0' && s[i] <= '9') { + if ((s[i] - '0') % 2 == 1) cnt++; + } + } + cout << cnt << endl; +} +int main() { + long long n, x, a, b; + char m; + while (cin >> n >> x) { + int cnt = 0; + stack s; + s.push(x); + for (int i = 0; i < n; i++) { + cin >> m >> b; + if (m == '+') { + a = s.top(); + s.pop(); + s.push(a + b); + } else if (m == '-') { + a = s.top(); + if (a < b) + cnt++; + else { + s.pop(); + s.push(a - b); + } + } + } + cout << s.top() << " " << cnt << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string k; + for (int i = 0; i < n; i++) { + cin >> k; + int h = k.size(); + if (h > 10) + cout << k[0] << (h - 2) << k[h - 1] << endl; + else + cout << k << endl; + } +} +const long long size = 105; +const long long mod = 998244353; +long long arr[size][size]; +long long win[size]; +long long b[size]; +int main() { + long long n, m; + cin >> n >> m; + memset(win, 0, sizeof(win)); + for (long long i = 0; i < m; i++) { + long long mx = -1; + long long ps = -1; + for (long long j = 0; j < n; j++) { + long long x; + cin >> x; + if (x > mx) { + mx = x; + ps = j; + } + } + win[ps]++; + } + long long mx = -1; + long long ps = -1; + for (long long i = 0; i < n; i++) + if (win[i] > mx) { + mx = win[i]; + ps = i; + } + cout << ps + 1 << endl; +} +int main() { + string s; + cin >> s; + string pat = "444"; + long long int f = 0, i, j; + if (s[0] != '1') { f = 1; } + for (i = 0; i < s.length(); i++) { + if (s[i] != '1' && s[i] != '4') { + f = 1; + break; + } + } + if (s.length() > 2) { + for (i = 0; i <= s.length() - 3; i++) { + for (j = 0; j < 3; j++) { + if (s[i + j] != pat[j]) break; + } + if (j == 3) { + f = 1; + break; + } + } + } + if (f == 1) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + string s; + vector v; + getchar(); + getline(cin, s); + int wordVolume = 0, textVolume = 0; + for (int i = 0; i < n; i++) { + if (s[i] >= 'A' && s[i] <= 'Z') wordVolume++; + textVolume = max(textVolume, wordVolume); + if (s[i] == ' ') { wordVolume = 0; } + } + cout << textVolume << endl; + return 0; +} +int main() { + string s, t = "hello"; + cin >> s; + int l = 0; + for (int i = 0, j = 0; i < s.size(); i++, j++) { + if (s[i] == t[j]) { + l++; + } else { + j--; + } + if (l == 5) { break; } + } + if (l == 5) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int x, y, z, p = 0, i; + i = min(a, min(b, c)); + i = n / i; + for (x = i; x >= 0; x--) { + for (y = 0; y <= i; y++) { + z = abs((n - (a * x + b * y)) / c); + if ((a * x + b * y + c * z) == n) { p = max(p, x + y + z); } + } + } + cout << p << endl; +} +int main() { + string s; + cin >> s; + char c_max = 'a'; + string out = ""; + for (int i = s.size() - 1; i >= 0; i--) { + if (s[i] == c_max) { + out = s[i] + out; + } else if (s[i] > c_max) { + out = s[i] + out; + c_max = s[i]; + } + } + cout << out << endl; +} +int main() { + long long i, j, n, l, r, u, d, x, y; + while (cin >> n) { + long long X[n + 1], Y[n + 1]; + for (i = 0; i < n; i++) { cin >> X[i] >> Y[i]; } + long long point = 0; + for (i = 0; i < n; i++) { + l = r = u = d = 0; + x = X[i]; + y = Y[i]; + for (j = 0; j < n; j++) { + if (X[j] == x) { + if (Y[j] > y) u++; + if (Y[j] < y) d++; + } + if (Y[j] == y) { + if (X[j] > x) r++; + if (X[j] < x) l++; + } + } + if (l > 0 && r > 0 && d > 0 && u > 0) point++; + } + cout << point << endl; + } + return 0; +} +int main() { + int n; + char a[1006]; + cin >> n; + cin >> a; + int count1 = 0, i = 0; + while (i < n) { + count1 = 0; + while (a[i] == '1' && i < n) { + ++count1; + ++i; + } + if (count1 > 0) { + cout << count1; + count1 = 0; + } + if (a[i] == '0') + if (a[i + 1] > '0' && (i + 1) < n) { + } else + cout << "0"; + ++i; + } + if (count1 > 0) cout << count1; + cout << endl; +} +int main() { + int n, j, a; + string str; + cin >> n >> str; + for (int i = 0; i < n; ++i) { + a = 0; + while (i < n && str[i] != '0') { + a += 1; + ++i; + } + cout << a; + } + if (str[n - 1] == '0') cout << 0; + cout << endl; + return 0; +} +int main() { + int n, sum = 0, g = 0, k, na = 0; + cin >> n; + if (n > 5) { + for (int i = 1; i < n; i++) { + k = 5 * pow(2, i) - 5; + if (k > n) { + g = i - 1; + break; + } + } + n = n - (5 * (pow(2, g)) - 5); + } + if (n <= pow(2, g)) { + cout << "Sheldon" << endl; + } else if (n <= 2 * pow(2, g)) { + cout << "Leonard" << endl; + } else if (n <= 3 * pow(2, g)) { + cout << "Penny" << endl; + } else if (n <= 4 * pow(2, g)) { + cout << "Rajesh" << endl; + } else { + if (n <= 5 * pow(2, g)) { cout << "Howard" << endl; } + } +} +int a[100006]; +long long int b[110]; +int main() { + string a, b, c, d; + int n, i; + cin >> a >> b; + cout << a << " " << b << endl; + cin >> n; + for (i = 0; i < n; i++) { + cin >> c >> d; + if (c == a) { + a = d; + } else { + b = d; + } + cout << a << " " << b << endl; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int vasya = max(3 * b / 10, b - (b / 250) * d); + int misha = max(3 * a / 10, a - (a / 250) * c); + if (vasya > misha) + cout << "Vasya\n"; + else if (misha > vasya) + cout << "Misha\n"; + else + cout << "Tie\n"; + return 0; +} +int main() { + int a, b, n; + while (cin >> n) { + int suma = 0, sumb = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a > b) + suma++; + else if (a < b) + sumb++; + } + if (suma > sumb) + cout << "Mishka" << endl; + else if (suma < sumb) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + long long n, a, b, c, d = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if (c % 2 == 1) { + d += ((c - 1) / 2) * (a - b); + d += a; + } else { + d += (c / 2) * (a - b); + } + cout << d << endl; + d = 0; + } +} +int main() { + int n; + int b = 0, c = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + if (t > 0) + b += t; + else + c += t; + } + cout << b - c << endl; +} +int main() { + char s[30]; + gets(s); + int len = strlen(s); + cout << 26 + 25 * len << endl; + return 0; +} +const int maxn = 50 + 5; +int lab[maxn][maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) cin >> lab[i][j]; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) { + if (lab[i][j] == 1) + continue; + else { + bool mark = false; + for (int r = 0; r < n; ++r) { + if (mark) break; + if (r == i) continue; + for (int c = 0; c < n; ++c) { + if (mark) break; + if (c == j) continue; + if (lab[i][j] == lab[r][j] + lab[i][c]) mark = true; + } + } + if (!mark) { + cout << "No\n"; + return 0; + } + } + } + cout << "Yes\n"; + return 0; +} +int main() { + long long int n, a[200003], i, s = 0, s1 = 0, x; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i], s += a[i]; + if (s & 1) + x = (s + 1) / 2; + else + x = s / 2; + for (i = 0; i < n; i++) { + s1 += a[i]; + if (s1 >= x) { + cout << i + 1 << endl; + return 0; + } + } +} +int main() { + int n, m, p; + cin >> n; + cin >> m; + map mp; + for (int i = 0; i < m; i++) { + int temp; + cin >> temp; + mp[temp] = true; + } + cin >> m; + for (int i = 0; i < m; i++) { + int temp; + cin >> temp; + mp[temp] = true; + } + for (int i = 1; i <= n; i++) { + if (mp[i] == false) { + cout << "Oh, my keyboard!" << endl; + return 0; + } + } + cout << "I become the guy." << endl; + return 0; +} +const double pi = acos(-1); +const double EPS = 1e-6; +const int INF = 1e9 + 40; +const long long INF64 = 1e18 + 40; +const double INFd = 1e9 + 40.0; +const long long MOD = (int)1e18 + 7; +const long long MODf = 998244353; +const int N = 1000 * 10 + 15; +int solve() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + cout << min(n % m * b, (m - n % m) * a) << '\n'; + return 0; +} +int main() { + solve(); +} +int main() { + long long n, k, x, s = 0, i, j; + int flag = 0, glag = 0; + cin >> n >> k; + x = sqrt((long double)n); + for (i = 1; i <= x; i++) { + if (n % i == 0) { s++; } + if (s == k) { + flag = 1; + break; + } + } + if (i == x + 1 && s != k) + for (j = i - 1; j > 0; j--) { + if (j == n / j) j = j - 1; + if (j == 0) break; + if (n % j == 0) s++; + if (s == k) { + flag = 1; + i = n / j; + break; + } + } + if (flag == 1) + cout << i << endl; + else + cout << "-1" << endl; +} +char s[100][111]; +int judge[2333]; +int main() { + int n, m; + while (cin >> n >> m) { + int ans = 0; + memset(s, 0, sizeof s); + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + memset(judge, 0, sizeof judge); + judge[s[i][j]]++; + judge[s[i][j + 1]]++; + judge[s[i + 1][j]]++; + judge[s[i + 1][j + 1]]++; + if (judge['f'] == 1 && judge['a'] == 1 && judge['c'] == 1 && judge['e'] == 1) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c, i, n, count = 0; + int x; + cin >> a >> b >> c; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + if (x > b && x < c) count++; + } + cout << count << endl; + return 0; +} +bool check(long long x, long long y, long long p, long long q, long long t) { + return p * t >= x && q * t - p * t >= y - x; +} +int main() { + int t; + cin >> t; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (p == q) { + cout << (x == y ? 0 : -1) << endl; + continue; + } + if (p == 0) { + cout << (x == 0 ? 0 : -1) << endl; + continue; + } + long long l = 0, r = 1e9; + while (r > l + 1) { + long long m = l + (r - l) / 2; + if (check(x, y, p, q, m)) { + r = m; + } else { + l = m; + } + } + cout << (r * q - y) << endl; + } +} +const long long mod = 1e9 + 7; +int main() { + int n; + cin >> n; + string s = ""; + string s1, s2; + s1 = s2 = s; + if (n % 7 == 0) + for (int i = 0; i < n / 7; i++) s1 += "7"; + if (n % 4 == 0) + for (int i = 0; i < n / 4; i++) s2 += "4"; + for (int i = 0; i <= n;) { + s += "4"; + i += 4; + if (n - i < 0 && n % 7 != 0 && n % 4 != 0) { + cout << "-1\n"; + return 0; + } + if ((n - i) % 7 == 0) { + for (int j = 0; j < (n - i) / 7; j++) s += "7"; + break; + } + } + int a = (s.size() == 0) ? INT_MAX : s.size(); + int b = (s1.size() == 0) ? INT_MAX : s1.size(); + int c = (s2.size() == 0) ? INT_MAX : s2.size(); + if (a <= b && a <= c) + cout << s << endl; + else if (b <= a && b <= c) + cout << s1 << endl; + else if (c <= b && c <= a) + cout << s2 << endl; + return 0; +} +int main() { + int n, k, x, ele; + cin >> n >> k >> x; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> ele; + if (i < n - k) { + sum += ele; + } else { + sum += x; + } + } + cout << sum << "\n"; +} +int main() { + int n; + cin >> n; + int ans = -1; + set s; + for (int i = 1; i <= 2 * n; i++) { + int temp; + cin >> temp; + if (s.count(temp) == 0) { + s.insert(temp); + int mx = s.size(); + ans = max(ans, mx); + } else + s.erase(temp); + } + cout << ans << endl; + return 0; +} +set s; +int a[2001], b[2001]; +int main() { + int n, x, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + s.insert(a[i]); + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + s.insert(b[i]); + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + x = a[i] ^ b[j]; + if (s.find(x) != s.end()) sum++; + } + } + if (sum % 2 == 0) { + cout << "Karen" << endl; + } else { + cout << "Koyomi" << endl; + } + return 0; +} +int main() { + int n, m, o = 0; + cin >> n >> m; + char x = '#'; + char y = '.'; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int h = 0; h < m; h++) { cout << x; } + cout << endl; + } else { + if (o % 2 == 0) { + for (int h = 0; h < (m - 1); h++) { cout << y; } + cout << x << endl; + } else { + cout << x; + for (int h = 0; h < (m - 1); h++) { cout << y; } + cout << endl; + } + o = o + 1; + } + } + return 0; +} +int main() { + int n, ans1 = 0, ans2 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int c; + cin >> c; + ans1 = ans1 | c; + } + for (int i = 0; i < n; i++) { + int c; + cin >> c; + ans2 = ans2 | c; + } + cout << ans1 + ans2 << endl; +} +int main() { + int n, c1 = 0, c2 = 0, i, m, k, d; + char a, b; + string s, t; + cin >> n >> s >> t; + m = s.size(); + k = t.size(); + for (i = 0; i < n && i < m * k; i++) { + a = s[i % m]; + b = t[i % k]; + if (a != b) { + d = (n - i + m * k - 1) / (m * k); + if (a == 'P' && b == 'S' || a == 'R' && b == 'P' || a == 'S' && b == 'R') + c1 += d; + else + c2 += d; + } + } + cout << c1 << " " << c2 << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + a = max(3 * a / 10, a - a * c / 250); + b = max(3 * b / 10, b - b * d / 250); + if (a > b) + cout << "Misha" << endl; + else if (b > a) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +vector V; +int main() { + int n; + cin >> n; + while (n--) { + int x; + cin >> x; + V.push_back(x); + } + sort(V.begin(), V.end()); + cout << V[(V.size() / 2)] << endl; + return 0; +} +bool ch(string x) { + for (int i = 0; i + 1 < 8; i++) + if (x[i] == x[i + 1]) return true; + return false; +} +int main() { + bool ok = 1; + string x; + for (int i = 0; i < 8; i++) { + int w = 0, b = 0; + cin >> x; + for (int j = 0; j < 8; j++) + if (x[j] == 'B') + b++; + else + w++; + if (w != b || ch(x)) { + ok = 0; + break; + } + } + cout << (ok ? "YES\n" : "NO\n"); + return 0; +} +int main() { + string s; + cin >> s; + int ln = s.size(); + int res = ln + 1; + res *= 26; + res -= ln; + cout << res << endl; + return 0; +} +int main() { + int n, a[55][55] = {0}; + bool res; + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] != 1) { + res = false; + for (int k = 1; k <= n; k++) { + for (int l = 1; l <= n; l++) { + if (a[i][j] == a[i][k] + a[l][j]) { res = true; } + } + } + if (!res) { + cout << "No" << endl; + return 0; + } + } + } + } + cout << "Yes" << endl; + return 0; +} +int n; +int main() { + cin >> n; + if (n == 2) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +map a; +long long LCA(long long u, long long v) { + while (u != v) { + if (log2(u) > log2(v)) swap(u, v); + v = v / 2; + } + return u; +} +void solve(long long s, long long x, long long cnt) { + while (s != x) { + a[x] += cnt; + x = x / 2; + } +} +long long cal(long long s, long long x) { + long long ans = 0; + while (s != x) { + ans += a[x]; + x = x / 2; + } + return ans; +} +int main() { + long long n, k, x, y, z; + cin >> n; + while (n--) { + cin >> k; + if (k == 1) { + cin >> x >> y >> z; + long long l = LCA(x, y); + solve(l, x, z); + solve(l, y, z); + } else { + cin >> x >> y; + long long l = LCA(x, y); + long long ans = 0; + ans += cal(l, x); + ans += cal(l, y); + cout << ans << endl; + } + } +} +int main() { + int n; + cin >> n; + vector a(n, 0); + for (int i = 0; i < n; i++) cin >> a[i]; + int u = 1, v = 2, c = 3, t, flag = 1; + for (int i = 0; i < n; i++) { + if (a[i] != u && a[i] != v) { + flag = 0; + break; + } + if (a[i] == u) { + t = v; + v = c; + c = t; + } else { + t = u; + u = c; + c = t; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int sk, ans; + if (n < s) + sk = 1; + else if (n % s != 0) + sk = n / s + 1; + else + sk = n / s; + ans = sk * k; + if (ans % p == 0) + cout << ans / p << endl; + else + cout << ans / p + 1 << endl; + return 0; +} +int main() { + int n, a[100001], r, s, b[100001], i, j = 0; + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + j++; + b[j] = a[n]; + for (i = n; i > 1; i--) { + r = a[i] + a[i - 1]; + j++; + b[j] = r; + } + for (i = j; i > 0; i--) { + cout << b[i]; + if (i != 1) cout << " "; + } + cout << endl; + return 0; +} +const int MAX = 100000; +const int INF = 1000000001; +int a[MAX]; +int n, sum = 0; +string s; +int main() { + cin >> n; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; ++i) sum += (s[i] == '8'); + int res = n / 11; + if (sum <= res) + cout << sum << endl; + else + cout << res << endl; + return 0; +} +const int maxn = 1e2 + 10; +int a[maxn], n, k, numOfInfo = 0, numOfNet = 0, ans = 0; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > 0) + numOfInfo++; + else + numOfNet++; + } + for (int i = 1; i <= k; i++) { + int p = numOfInfo, q = numOfNet; + for (int j = i; j <= n; j += k) + if (a[j] == 1) + p--; + else + q--; + ans = max(ans, abs(p - q)); + } + cout << ans << endl; + return 0; +} +int main() { + bool jud = false; + int ans = 0; + string s; + cin >> s; + int len = s.size(); + s[len] = 'D'; + for (int i = 0; i <= len - 2; i++) { + if (s[i] == 'V' && s[i + 1] == 'K') ans++; + if (s[i] == 'V' && s[i + 1] == 'V' && s[i + 2] != 'K') jud = true; + if (s[i - 1] != 'V' && s[i] == 'K' && s[i + 1] == 'K') jud = true; + } + if (jud) ans++; + cout << ans << endl; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n; + cin >> n; + int f = 0, s = 0; + while (n > 0) { + if (n % 7 == 0) { + s += n / 7; + n = 0; + } else { + f += 1; + n -= 4; + } + } + if (n == 0) { + for (int i = 0; i < f; ++i) { cout << 4; } + for (int i = 0; i < s; ++i) { cout << 7; } + } else { + cout << -1; + } + cout << '\n'; + return 0; +} +int main() { + int n, a, b, ans; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + ans = 0; + while (a != 0 && b != 0) { + if (a < b) { swap(a, b); } + ans += a / b; + a %= b; + } + cout << ans << endl; + } + return 0; +} +long long ans = 0; +long long gcd(long long a, long long b) { + if (b == 0) return a; + ans += a / b; + return gcd(b, a % b); +} +int main() { + int t; + cin >> t; + for (int q = 0; q < t; q++) { + long long a, b; + cin >> a >> b; + ans = 0; + gcd(a, b); + cout << ans << endl; + } + return 0; +} +long long n, mid, f; +int main() { + cout << setprecision(30) << fixed; + cin >> n; + cout << 2 - n % 2 << '\n'; + return 0; +} +int main() { + int x, y; + char s[120][120]; + cin >> x >> y; + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + if (i % 2 == 0) + s[i][j] = '#'; + else if ((i % 4 == 1 && j == y - 1) || (i % 4 == 3 && j == 0)) + s[i][j] = '#'; + else + s[i][j] = '.'; + } + cout << s[i] << endl; + } + return 0; +} +int main() { + char pos1; + int pos2; + int ans = 0; + cin >> pos1 >> pos2; + if (pos1 > 'a' && pos1 < 'h') { + if (pos2 > 1 && pos2 < 8) { + ans = 8; + } else if (pos2 == 1 || pos2 == 8) { + ans = 5; + } else + ans = 0; + } else if (pos1 == 'a' || pos1 == 'h') { + if (pos2 > 1 && pos2 < 8) { + ans = 5; + } else if (pos2 == 1 || pos2 == 8) { + ans = 3; + } else + ans = 0; + } else { + ans = 0; + } + cout << ans << endl; + return 0; +} +int main() { + int n, res = 0; + cin >> n; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = 1; i < n; i++) + if (arr[i] != (arr[i - 1] + 1)) res += (arr[i] - arr[i - 1] - 1); + cout << res << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int count = n; + for (int i = 1; i <= n; i++) { + if (i % m == 0) { + count++; + n++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, count = 0; + cin >> n; + pair p[100]; + for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } + for (int i = 0; i < n; i++) { + for (int g = 0; g < n; g++) { + if (p[i].first == p[g].second) count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int ans = 0; + while (--n) { + if (ans == 0) { + ans += min(a, b); + } else { + ans += min(a, min(b, c)); + } + } + cout << ans << '\n'; + return 0; +} +string s; +bool cmp(char ch1, char ch2) { + if (ch1 != 'a') { + char t1 = ch1 - 1; + if (ch2 != 'a') { + char t2 = ch2 - 1; + if (t1 == t2) return true; + } + if (ch2 != 'z') { + char t2 = ch2 + 1; + if (t1 == t2) return true; + } + } + if (ch1 != 'z') { + char t1 = ch1 + 1; + if (ch2 != 'a') { + char t2 = ch2 - 1; + if (t1 == t2) return true; + } + if (ch2 != 'z') { + char t2 = ch2 + 1; + if (t1 == t2) return true; + } + } + return false; +} +int main() { + long long t; + cin >> t; + long long n; + while (t--) { + cin >> n; + bool chk = 1; + cin >> s; + for (long long i = 0, j = s.length() - 1; i < s.length() / 2; i++, j--) { + if (!cmp(s[i], s[j])) { + chk = 0; + break; + } + } + if (chk) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int rever(int n) { + int rn = 0; + while (n) { + rn = rn * 10 + n % 10; + n /= 10; + } + return rn; +} +int main() { + int a, b; + while (cin >> a >> b) { cout << a + rever(b) << endl; } + return 0; +} +const int N = 2e5 + 5; +int To(char x) { + if (x == '^') return 0; + if (x == '>') return 1; + if (x == 'v') return 2; + if (x == '<') return 3; +} +int main() { + int n; + char s, e; + cin >> s >> e >> n; + if (abs(To(s) - To(e)) % 2 == 0) { + return puts("undefined"), 0; + } else { + int S = To(s) + (n % 4); + if (S % 4 == To(e)) + puts("cw"); + else + puts("ccw"); + } +} +int main() { + char m1[] = "1", m2[] = "14", m3[] = "144"; + char a[1000]; + int i, j, k, l; + cin >> a; + for (i = 0; a[i];) { + if (a[i] == m3[0] && a[i + 1] == m3[1] && a[i + 2] == m3[2]) + i += 3; + else if (a[i] == m2[0] && a[i + 1] == m2[1]) + i += 2; + else if (a[i] == m1[0]) + i += 1; + else { + cout << "NO\n"; + exit(0); + } + } + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + int a; + int b; + for (int i = 1; i <= (int)sqrt(n); i++) { + if (n % i == 0) { + a = i; + b = n / i; + } + } + cout << a << " " << b << endl; + return 0; +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +long long n, x, a, z; +set st; +string s; +int main() { + cin >> n >> x; + for (int i = 0; i < n; i++) { + char c; + cin >> c >> a; + if (c == '+') + x += a; + else { + if (a > x) { + z++; + continue; + } + x -= a; + } + } + cout << x << " " << z << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + if (s % n == 0) + cout << s / n << endl; + else + cout << (s / n) + 1 << endl; + return 0; +} +const int LIM = 50 + 10; +int dat[LIM][LIM]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> dat[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (dat[i][j] == 1) continue; + bool flag = true; + for (int k = 0; flag && k < n; k++) { + for (int w = 0; w < n; w++) { + if (dat[i][j] == dat[i][k] + dat[w][j]) { + flag = false; + break; + } + } + } + if (flag) { + cout << "No\n"; + return 0; + } + } + } + cout << "Yes\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector A(n), B(m); + for (auto &s : A) cin >> s; + for (auto &s : B) cin >> s; + for (int i = 0; i < n; i++) { + int pos = -1; + while (pos + 1 < n) { + bool ok = 1; + pos = B[0].find(A[i], pos + 1); + if (pos == -1) break; + for (int k = m - 1; k >= 0 && ok; k--) + if (A[i + k] != B[k].substr(pos, m)) ok = 0; + if (ok) return cout << i + 1 << " " << pos + 1 << "\n", 0; + } + } + cout << -1; +} +int main() { + int t; + cin >> t; + while (t) { + int n; + cin >> n; + double k = 3.0; + double ans = 0.0; + while (1) { + ans = ((k - 2.0) * 180.0) / k; + if (n == ans) { + cout << "YES" << endl; + break; + } else if (ans > n) { + cout << "NO" << endl; + break; + } + k++; + } + t--; + } +} +int main() { + int n, p; + cin >> n >> p; + string s; + cin >> s; + set st; + set::iterator it; + int x = -1; + for (int i = n - 1; i >= 0; i--) { + st.clear(); + for (char j = s[i] + 1; j < 'a' + p; j++) { st.insert(j); } + if (i - 1 >= 0) { + it = st.find(s[i - 1]); + if (it != st.end()) st.erase(it); + } + if (i - 2 >= 0) { + it = st.find(s[i - 2]); + if (it != st.end()) st.erase(it); + } + if (st.size()) { + s[i] = *st.begin(); + x = i; + break; + } + } + if (x == -1) + cout << "NO\n"; + else { + for (int i = x + 1; i < n; i++) { + st.clear(); + for (char j = 'a'; j < 'a' + p; j++) { st.insert(j); } + if (i - 1 >= 0) { + it = st.find(s[i - 1]); + if (it != st.end()) st.erase(it); + } + if (i - 2 >= 0) { + it = st.find(s[i - 2]); + if (it != st.end()) st.erase(it); + } + s[i] = *st.begin(); + } + cout << s << endl; + } + return 0; +} +int sum(int n, int b) { + int ret = 0; + while (n) { + ret += n % b; + n /= b; + } + return ret; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + int n, i, cnt = 0, g; + cin >> n; + for (i = 2; i < n; i++) { cnt += sum(n, i); } + g = gcd(cnt, (n - 2)); + cout << cnt / g << '/' << (n - 2) / g << endl; + return 0; +} +string s[123], ss[123]; +int main() { + long long x, y, z, k; + cin >> x >> y >> z >> k; + long long xx = 1, yy = 1, zz = 1; + x--; + y--; + z--; + while (k != 0) { + if (x != 0) { + x--; + xx++; + k--; + } + if (y != 0 && k != 0) { + y--; + yy++; + k--; + } + if (z != 0 && k != 0) { + z--; + zz++; + k--; + } + if (x == 0 && y == 0 && z == 0) break; + } + cout << xx * yy * zz << '\n'; + return 0; +} +int main() { + int n = 0, m = 0; + cin >> n >> m; + int mov = min(n, m); + if (mov % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; +} +int main() { + int i, a = 0, b = 0, p, n, k, c = 0; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> p; + if (a == 0) + a = p; + else + a = min(a, p); + b = max(b, p); + } + for (i = 0; i < k; i++) { + cin >> p; + if (c == 0) + c = p; + else + c = min(c, p); + } + if (max(2 * a, b) < c) { + cout << max(2 * a, b) << endl; + } else { + cout << -1 << endl; + } +} +int main() { + int i, x, y; + char ch, ch1[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; + string A, B; + cin >> ch >> A >> B; + if (A[1] == B[1]) { + for (i = 0; i < 9; i++) { + if (A[0] == ch1[i]) x = i; + if (B[0] == ch1[i]) y = i; + } + if (x > y) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + } else if (ch == A[1]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = 2000010; +const int mod = 1e9 + 7; +int add(int x, int y) { + int res = (x + y) % mod; + return res < 0 ? res + mod : res; +} +int mul(int x, int y) { + int res = (x * 1LL * y) % mod; + return res < 0 ? res + mod : res; +} +int main() { + int n, m; + char a[1000][1000]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) a[i][j] = ((i & 1) ? '.' : '#'); + if (i & 1) { + int x = i >> 1; + if ((x & 1) == 0) + a[i][m - 1] = '#'; + else + a[i][0] = '#'; + } + for (int j = 0; j < m; j++) cout << a[i][j]; + cout << endl; + } +} +int i, j; +int main() { + long long n; + cin >> n; + cout << 25 << endl; +} +const int inf = 0x3f3f3f3f; +int s[105], n, dp[105]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> s[i]; + dp[1] = s[1]; + int len = 1; + for (int i = 2; i <= n; i++) { + if (s[i] >= dp[len]) + dp[++len] = s[i]; + else { + int index = upper_bound(dp + 1, dp + 1 + len, s[i]) - dp; + dp[index] = s[i]; + } + } + cout << len << endl; + return 0; +} +int main() { + int sum = 0; + char temp = 'a'; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) { + sum += min(fabs(temp - str[i]), 26 - fabs(temp - str[i])); + temp = str[i]; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + set x, y; + for (int i = 1; i <= n; i++) { + int a, b; + cin >> a >> b; + x.insert(a); + y.insert(b); + } + cout << min(x.size(), y.size()) << endl; + return 0; +} +int main() { + string s; + while (cin >> s) { + int mp[1000] = {0}, i, c = 0; + for (i = 0; i < s.size(); i++) { + if (mp[s[i]] == 0) { + c++; + mp[s[i]] = 1; + } + } + if (c % 2) + cout << "IGNORE HIM!\n"; + else + cout << "CHAT WITH HER!\n"; + } + return 0; +} +int main() { + int a; + cin >> a; + int i = 5, counter = a, c = 0; + int arr[5] = {1, 2, 3, 4, 5}; + if (a <= 5) + cout << 1 << endl; + else { + c = a / 5; + if (a % 5 != 0) + cout << c + 1 << endl; + else + cout << c << endl; + } + return 0; +} +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} +int main() { + int n, m, c; + cin >> n >> m >> c; + cout << n * m * c - (n - 1) * (m - 1) * (c - 1) << endl; +} +long long int p[100]; +int main() { + long long int t, n, m, i, j, k, x, y, ans; + t = 1; + while (t--) { + cin >> n >> m; + i = p[0] = ans = 1; + while (1) { + p[i] = p[i - 1] * 2; + if (p[i] > 100000000) break; + i++; + } + if (n <= 27) m %= p[n]; + cout << m << endl; + } + return 0; +} +int sum(int n) { + int s = (n * (n + 1)) / 2; + return s; +} +int main() { + int n; + cin >> n; + int i = 0; + int s = 0; + while (true) { + s = s + sum(i); + if (s > n) { + break; + } else { + i++; + } + } + cout << (i - 1) << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long int L, v, l, r; + cin >> L >> v >> l >> r; + long int tot = L / v; + long int unseen = r / v - (l - 1) / v; + cout << tot - unseen << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + int a = 0; + char b; + int i, j; + int count1 = 0, count = 0; + int flag = 0; + int x = t / 2; + for (i = 0, j = 1; i < t; i++, j++) { + cin >> b; + a = b - '0'; + if (flag == 1) + continue; + else { + if (a != 4 && a != 7) { + flag = 1; + } else { + count += a; + if (j == x) { + count1 = count; + count = 0; + } + } + } + } + if (flag == 1) { + cout << "NO\n"; + } else { + if (count != count1) + cout << "NO\n"; + else + cout << "YES\n"; + } +} +inline void boost() {} +const long long maxn = 1e5 + 123; +const long long inf = 1e9 + 123; +const long long mod = 1e9 + 7; +const double pi = acos(-1); +int main() { + boost(); + string s, t; + cin >> s >> t; + int n; + cin >> n; + cout << s << " " << t << "\n"; + for (int i = 1; i <= n; i++) { + string a, b; + cin >> a >> b; + if (a == s) { + s = b; + cout << s << " " << t << "\n"; + } + if (a == t) { + t = b; + cout << s << " " << t << "\n"; + } + } + exit(0); +} +int main() { + int n; + cin >> n; + int a[200]; + int one = 0, zero = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i]) one++; + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 0) zero++; + ans = max(ans, one + zero); + if (a[i] == 1) one--; + } + cout << ans << '\n'; +} +int main() { + string s; + cin >> s; + int n; + cin >> n; + if (n > (int)s.size()) + cout << "impossible\n"; + else { + cout << max(0, n - (int)set(s.begin(), s.end()).size()) << '\n'; + } +} +int main() { + int n; + cin >> n; + int a = (2 * n) - (n / 2); + cout << a << endl; +} +int main() { + int n; + cin >> n; + vector vec(n); + for (int i = 0; i < n; ++i) cin >> vec[i]; + sort(vec.begin(), vec.end()); + int lim = -1; + for (int i = 0; i < n; ++i) { + if (vec[i] >= 0) { + lim = i; + break; + } + } + if (lim == -1) lim = vec.size(); + int b = 0, c = 0; + for (int i = 0; i < lim; ++i) c += vec[i]; + for (int i = lim; i < vec.size(); ++i) b += vec[i]; + cout << b - c << endl; + return 0; +} +int p[120][3]; +int main() { + int n; + cin >> n; + int i, sum = 0; + for (i = 1; i <= n; i++) cin >> p[i][1] >> p[i][2]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (p[i][1] == p[j][2]) sum++; + } + } + cout << sum << endl; +} +int n, k, c, x, f[405], ans = 0; +int main() { + memset(f, 0, sizeof(f)); + cin >> n >> k >> c; + for (int i = 1; i <= c; i++) { + cin >> x; + f[x]++; + } + int t = k; + for (int i = 1; i <= n; i++) + if (i == t || f[i]) t = i + k, ans++; + cout << ans << endl; + return 0; +} +int main() { + int n, t, npr = 0, nma = 0, nph = 0; + cin >> n; + vector pr, ma, ph; + for (int i = 1; i < n + 1; i++) { + cin >> t; + if (t == 1) { + pr.push_back(i); + npr++; + } else if (t == 2) { + ma.push_back(i); + nma++; + } else if (t == 3) { + ph.push_back(i); + nph++; + } + } + int k = min(npr, min(nma, nph)); + cout << k << endl; + for (int i = 0; i < k; i++) { cout << pr[i] << " " << ma[i] << " " << ph[i] << endl; } +} +int main() { + int n; + cin >> n; + char a[n][n]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { cin >> a[i][j]; } + } + int f = 0; + char x = a[0][0], y = a[0][1]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (i == j || i == n - j - 1) { + if (a[i][j] != x) f = 1; + } else { + if (a[i][j] != y) f = 1; + } + } + } + if (f == 0 && x != y) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n; +queue ans[5]; +string s; +char t[15]; +int main() { + cin >> n; + while (n--) { + cin >> s >> t; + if (t[2] == 't') + ans[1].push(s); + else if (t[2] == 'm' || t[2] == 'i') + ans[2].push(s); + else if (t[2] == 'n') + ans[3].push(s); + else + ans[4].push(s); + } + for (int i = 1; i <= 4; i++) { + while (!ans[i].empty()) { + s = ans[i].front(); + ans[i].pop(); + cout << s << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + string name[105]; + string status[105]; + string str1[105]; + string str2[105]; + string str3[105]; + string captain; + int q = 0, w = 0, t = 0; + for (int i = 0; i < n; i++) { cin >> name[i] >> status[i]; } + for (int j = 0; j < n; j++) { + if (status[j] == "rat") { + str1[q] = name[j]; + q++; + } + if (status[j] == "woman" || status[j] == "child") { + str2[w] = name[j]; + w++; + } else if (status[j] == "captain") { + captain = name[j]; + } else if (status[j] == "man") { + str3[t] = name[j]; + t++; + } else + continue; + } + for (int i = 0; i < q; i++) { cout << str1[i] << endl; } + for (int i = 0; i < w; i++) { cout << str2[i] << endl; } + for (int i = 0; i < t; i++) { cout << str3[i] << endl; } + cout << captain << endl; + return 0; +} +int ans, s, n; +string str; +int main() { + cin >> str; + n = str.size(); + str = " " + str; + s = 1; + for (int i = 2; i <= n; i++) { + if (str[i] != str[i - 1]) { + if (s % 2 == 0) ans++; + s = 0; + } + s++; + } + if (s % 2 == 0) ans++; + cout << ans << '\n'; +} +int main() { + int n, m, a[55] = {}, b[55] = {}, mx = 0, ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; i++) cin >> b[i]; + for (int i = 1; i <= m; i++) + for (int j = 1; j <= n; j++) + if (b[i] % a[j] == 0) { mx = max(mx, b[i] / a[j]); } + for (int i = 1; i <= m; i++) + for (int j = 1; j <= n; j++) + if (b[i] % a[j] == 0 && b[i] / a[j] == mx) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + char c[95]; + while (cin >> n) { + int sum1 = 0; + for (int i = 0; i <= n - 1; i++) cin >> c[i]; + for (int i = 0; i <= n - 1; i++) { + if (c[i] == '1') + sum1++; + else { + cout << sum1; + sum1 = 0; + } + } + cout << sum1 << endl; + } + return 0; +} +int arr[150]; +int main() { + memset(arr, 0, sizeof(arr)); + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + for (int i = 1; i <= x; i++) { + int y; + cin >> y; + arr[y] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (arr[i] == 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, m, a[60], mn = 1005; + cin >> n; + cin >> m; + for (int i = 0; i < m; i++) { cin >> a[i]; } + sort(a, a + m); + for (int i = 0; i < m - n + 1; i++) { + int d = a[i + n - 1] - a[i]; + if (d < mn) mn = d; + } + cout << mn << endl; + return 0; +} +int main() { + int n, m; + bool isitright = true; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if ((i + 1) % 2 != 0) { + cout << "#"; + } else { + if (isitright == true && j == m - 1) { + cout << "#"; + } else if (isitright == false && j == 0) { + cout << "#"; + } else { + cout << "."; + } + } + } + cout << "\n"; + if ((i + 1) % 2 == 0) { + if (isitright == true) { + isitright = false; + } else + isitright = true; + } + } + return 0; +} +int main() { + int n, s, coun = 0; + cin >> n; + int a[100][100]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) cin >> a[i][j]; + } + for (int i = 0; i < n; i++) { + s = a[i][1] - a[i][0]; + if (s >= 2) coun++; + } + cout << coun << endl; + return 0; +} +string s; +int ans, i, cw, ccw; +int main() { + cin >> s; + for (i = 0; i < s.length(); i++) { + if (i == 0) { + cw = static_cast(s[i]) - static_cast('a'); + ccw = abs(26 - cw); + ans += min(cw, ccw); + } else { + cw = abs(static_cast(s[i - 1]) - static_cast(s[i])); + ccw = abs(26 - cw); + ans += min(cw, ccw); + } + } + cout << ans << endl; +} +int main() { + int n; + while (cin >> n) { + int sumA = 0, sumB = 0, num; + for (int i = 1; i <= n; i++) { + cin >> num; + if (num >= 0) { + sumA += num; + } else { + sumB += num; + } + } + cout << (sumA - sumB) << endl; + } + return 0; +} +int ans, t, q[100]; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); ++i) q[i] = s[i] == 'Q' ? ++t : t; + for (int i = 0; i < s.size(); ++i) + if (s[i] == 'A') ans += q[i] * (t - q[i]); + cout << ans << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n; + cin >> n; + if (n % 2 == 0) + puts("0"); + else + puts("1"); + return 0; +} +int main() { + int n, a[1000], i, j; + memset(a, 0, sizeof(a)); + cin >> n; + for (i = 0; i < n; i++) { + cin >> j; + a[j]++; + } + int m = -999; + for (i = 0; i < 1000; i++) { + if (a[i] > m) { m = a[i]; } + } + cout << m << endl; + return 0; +} +int main() { + int t, punkty = 0; + cin >> t; + int x[t]; + for (int i = 0; i < t; i++) { cin >> x[i]; } + int i = 0; + while (t) { + if (x[i] == 1 || (x[i] == 0 && x[i + 1] == 1 && x[i - 1] == 1 && i != 0)) punkty++; + t--; + i++; + } + cout << punkty << endl; + return 0; +} +int main() { + long long inicio, fin, num, aux, max; + cin >> inicio >> fin; + aux = 1; + while (aux <= inicio) { aux = aux * 10; } + max = inicio * (aux - inicio - 1); + aux = 1; + while (aux <= fin) { aux = aux * 10; } + if (max < fin * (aux - fin - 1)) { max = fin * (aux - fin - 1); } + num = 4; + aux = 9; + while (num <= fin) { + if (inicio <= num && max < num * (aux - num)) { max = num * (aux - num); } + num = num * 10 + 9; + aux = aux * 10 + 9; + } + cout << max << endl; + return 0; +} +int main() { + long long a, b, n = 0; + bool ans = 0; + cin >> a >> b; + while (b > 0) { + if (b == 1) { + ans = 0; + break; + } + if (b % a != 0) { + ans = 1; + break; + } + n++; + b = b / a; + } + if (ans == 0) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + double d, n, m; + cin >> d >> n >> m; + cout << (d * n) / (n + m) << endl; +} +char a[200010]; +int main() { + int n; + cin >> n; + cin >> a; + int tot = 0, mm = 0; + for (int i = 0; i < n; i++) { + if (a[i] == '1') { + tot++; + } else + mm++; + } + int MIN = min(tot, mm); + int ans = n - MIN * 2; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + sort(a, a + n); + int ans = 0, cnt = 0; + sum = sum / 2; + while (ans <= sum) { + cnt++; + ans += a[n - cnt]; + } + cout << cnt << endl; +} +int g[11]; +void fill(int x) { + while (x != 0) { + g[x % 10]++; + x /= 10; + } +} +int main() { + int n, k; + cin >> n >> k; + int c = 0; + for (int i = 0; i < n; i++) { + for (int i = 0; i < 10; i++) { g[i] = 0; } + int a; + cin >> a; + fill(a); + bool b = true; + for (int i = 0; i < k + 1; i++) { b = b && g[i]; } + c += b; + } + cout << c << endl; + return 0; +} +const int MAXN = 200010; +const int mod = 1e9 + 7; +const int INF = 0x3f3f3f3f; +const double pi = acos(-1.0); +const double eps = 1e-6; +int main() { + int n; + cin >> n; + string s; + long long a = 1, b = 1; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "UL") + a++; + else if (s == "DR") + a++; + else if (s == "UR") + b++; + else if (s == "DL") + b++; + else if (s == "ULDR") { + a++; + b++; + } + } + cout << a * b << endl; + return 0; +} +int a[110]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, vote; + cin >> n; + cin >> vote; + for (int i = 0; i < n - 1; i++) cin >> a[i]; + int cnt = 0; + sort(a, a + n - 1, cmp); + while (vote <= a[0]) { + vote++; + a[0]--; + cnt++; + sort(a, a + n - 1, cmp); + } + cout << cnt << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) <= 1 && (a | b)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long fact(long long n) { + if ((n == 0) || (n == 1)) { + return 1; + } else + return n * fact(n - 1); +} +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + long long a, b; + cin >> a >> b; + long long c = min(a, b); + cout << fact(c) << endl; + return 0; +} +int main() { + string palabra; + cin >> palabra; + string vocale = "aeioun"; + string valido = "aeiou"; + int tam = palabra.size(); + bool es = true; + if (vocale.find(palabra[tam - 1]) == -1) { + es = false; + } else { + for (int i = 0; i < (long long)tam - 1; i++) { + if (vocale.find(palabra[i]) == -1) { + if (valido.find(palabra[i + 1]) == -1) { + es = false; + break; + } + } + } + } + if (es) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int a, b, c, d, e, f, g; + string s, t; + while (cin >> a >> b >> c) { + d = 0; + while (1) { + if (a + b > c && b + c > a && a + c > b) { + break; + } else { + d++; + if (a <= b && a <= c) { + a++; + } else if (b <= a && b <= c) { + b++; + } else { + c++; + } + } + } + cout << d << endl; + } + return 0; +} +const double EPS = 1e-9; +const int INF = 1 << 28; +const long long INFL = 1LL << 62; +int main() { + int n, ans = 0; + cin >> n; + vector v(n); + for (int i = 0; i < n; ++i) cin >> v[i]; + for (int i = 0; i < n; ++i) { + int temp = v[i]; + ans = max(ans, temp); + for (int j = i + 1; j < n; ++j) { + temp ^= v[j]; + ans = max(ans, temp); + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string x; + cin >> x; + for (int i = 1; i < x.size(); i++) { + if (x[i] != x[i - 1]) { + cout << "YES" << endl; + cout << x[i - 1] << x[i] << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int a[] = {100, 20, 10, 5, 1}; +int main() { + long long n; + cin >> n; + long long ans = 0; + long long tmp; + for (int i = 0; i < 5; i++) { + tmp = n / a[i]; + ans += tmp; + n -= a[i] * tmp; + } + cout << ans << endl; + return 0; +} +int main() { + long long int a, b, c, array[100005], n, count = 0; + cin >> a >> b >> c >> n; + for (int i = 0; i < n; i++) { cin >> array[i]; } + for (int i = 0; i < n; i++) { + if (array[i] > b && array[i] < c) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + double n, t, k, d, temp, fristOven = 0; + cin >> n >> t >> k >> d; + temp = n; + while (temp > 0) { + fristOven += t; + temp -= k; + } + int o1 = 0, o2 = d; + while (n > 0) { + if (o1 > o2) + o2 += t; + else + o1 += t; + n -= k; + } + int secOventime = max(o1, o2); + if (secOventime < fristOven) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int Black(int arr[], long long int n) { + long long ans = 0; + for (int i = 1; i <= n / 2; i++) { ans = ans + abs(2 * i - arr[i]); } + return ans; +} +int White(int arr[], long long int n) { + long long ans = 0; + for (int i = 1; i <= n / 2; i++) { ans = ans + abs((2 * i - 1) - arr[i]); } + return ans; +} +int main() { + long long int n; + cin >> n; + int arr[n / 2 + 1]; + for (int i = 1; i <= n / 2; i++) { cin >> arr[i]; } + sort(arr + 1, arr + n / 2 + 1); + int blackAns = Black(arr, n); + int whiteAns = White(arr, n); + if (blackAns < whiteAns) { + cout << blackAns << endl; + } else { + cout << whiteAns << endl; + } + return 0; +} +int main() { + int n, sum = 0, sum1 = 0, a, b; + cin >> n; + int x[n]; + for (int i = 0; i < n; i++) { cin >> x[i]; } + cin >> a >> b; + for (int i = min(a - 1, b - 1); i < max(b - 1, a - 1); i++) { sum += x[i]; } + for (int i = min(a - 1, b - 1) - 1; i >= 0; i--) sum1 += x[i]; + for (int i = n - 1; i >= max(b - 1, a - 1); i--) sum1 += x[i]; + cout << min(sum, sum1) << endl; +} +map m1; +map::iterator itr; +int main() { + long long int n, b, p; + cin >> n >> b >> p; + long long int ans2 = n * p; + long long int ans1 = 0; + while (n > 1) { + long long int i; + for (i = 0;; i++) { + if (pow(2, i) > n) break; + } + i--; + long long int z = pow(2, i); + ans1 += (z / 2) * (2 * b + 1); + n = n - z / 2; + } + cout << ans1 << " " << ans2 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == 1) { + if (i == 0 || j == 0 || i == n - 1 || j == m - 1) { + cout << "2" << endl; + return 0; + } + } + } + } + cout << "4" << endl; + return 0; +} +string x, y; +int main() { + cin >> x >> y; + if (x == y) + cout << x << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int n; + cin >> n; + cout << a << ' ' << b << '\n'; + for (int i = 0; i < n; i++) { + string x, y; + cin >> x >> y; + if (a == x) { + cout << y << ' ' << b << '\n'; + a = y; + continue; + } + if (b == x) { + cout << a << ' ' << y << '\n'; + b = y; + continue; + } + } +} +int main() { + int n; + cin >> n; + int x[n]; + for (int i = 1; i <= n; ++i) { cin >> x[i]; } + if (n == 1 && x[n] != 15 && x[n] != 0) { cout << "-1" << endl; } + if (x[n] == 15) cout << "DOWN" << endl; + if (x[n] == 0) + cout << "UP" << endl; + else { + if (x[n] - x[n - 1] == 1 && x[n] != 15) cout << "UP" << endl; + if (x[n] - x[n - 1] == -1) cout << "DOWN" << endl; + } + return 0; +} +int main() { + int n, chris = 0, mishka = 0, c, m; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m >> c; + if (c > m) + chris++; + else if (m > c) + mishka++; + } + if (chris > mishka) + cout << "Chris" << endl; + else if (chris < mishka) + cout << "Mishka" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +const int MAX = 1e5; +int main() { + bool x[150]; + memset(x, false, sizeof(x)); + int n, m; + int l, r; + int i, j; + cin >> n >> m; + for (i = 0; i < n; i++) { + cin >> l >> r; + for (j = l; j < r; j++) x[j] = true; + } + for (i = 0; i < m; i++) + if (!x[i]) break; + if (i < m) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int a[110]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int i; + for (i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) break; + } + cout << k / a[i] << endl; + return 0; +} +int N, T, val, K[105]; +int main() { + cin >> N >> T; + for (int i = 1; i <= N; i++) { cin >> K[i]; } + for (int i = 1; i <= N; i++) { + T -= (86400 - K[i]); + if (T > 0) { + val++; + } else + break; + } + cout << val + 1 << '\n'; + return 0; +} +bool snack[100009]; +int arr[100000]; +int matrix[100000][3]; +int main() { + int count = 0; + bool flag = false; + int n, x; + char s[1000]; + cin >> n; + for (int i = 0; i < n; i++) { + int ones = 0; + for (int i = 0; i < 3; i++) { + cin >> x; + if (x == 1) ones++; + } + if (ones > 1) count++; + } + cout << count << '\n'; + return 0; +} +int main() { + int k, n, w, s = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { s += i * k; } + if (n - s < 0) + cout << abs(n - s) << endl; + else + cout << 0 << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long sum, x = 3; + while (n % x == 0) { x *= 3; } + sum = n / x + 1; + cout << sum << endl; + return 0; +} +int main() { + string s, res = ""; + char ch, temp; + cin >> s; + sort(s.begin(), s.end()); + int k = s.size(); + ch = s[k - 1]; + for (int i = k - 1; i >= 0; i--) { + temp = s[i]; + if (temp != ch) { break; } + res += ch; + } + cout << res << '\n'; +} +int main() { + long long n; + cin >> n; + for (long long i = 1; i <= n; i++) { + if (i == 1) + cout << 2 << '\n'; + else + cout << i * (i + 1) * (i + 1) - (i - 1) << '\n'; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int joy; + for (int i = 0; i < n; i++) { + int f, t; + cin >> f >> t; + if (i == 0 && t > k) + joy = f - t + k; + else if (i == 0) + joy = f; + else if (t > k) + joy = max(joy, f - t + k); + else + joy = max(joy, f); + } + cout << joy << endl; + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + int t = 0; + for (int i = 0; i < (n - k); i++) { t += arr[i]; } + t += k * x; + cout << t << endl; +} +string n = "qwertyuiopasdfghjkl;zxcvbnm,./"; +string t, s, r = ""; +int main() { + cin >> t >> s; + if (t == "R") { + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < n.length(); j++) { + if (s[i] == n[j]) { r += n[j - 1]; } + } + } + } else if (t == "L") { + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < n.length(); j++) { + if (s[i] == n[j]) { r += n[j + 1]; } + } + } + } + cout << r << endl; + return 0; +} +int main() { + int i, j, a[1000], sum = 0, total; + for (i = 0; i < 6; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 2 == 1) { + cout << "NO" << endl; + return 0; + } else { + for (i = 1; i < 5; i++) { + for (j = i + 1; j < 6; j++) { + total = a[0] + a[i] + a[j]; + if (sum == total * 2) { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, c, i = 0; + cin >> a >> b >> c; + while (i * b < c * a - c * b) { i++; } + cout << i << '\n'; +} +char x, y; +int main() { + cin >> x >> y; + bool a = true; + bool b = true; + if (x == 'h' || x == 'a') { a = false; } + if (y == '1' || y == '8') { b = false; } + if (!a && !b) { + cout << 3 << "\n"; + } else if (!a || !b) { + cout << 5 << "\n"; + } else { + cout << 8 << "\n"; + } + return 0; +} +int main() { + long long n; + while (cin >> n) { cout << "25" << endl; } +} +int main() { + int i = 0, n = 0, k = 0, temp = 0, *m; + cin >> n >> k; + m = new int[n]; + for (i = 0; i < n; ++i) { m[i] = 0; } + for (i = 0; i < k; ++i) { + cin >> temp; + ++m[temp - 1]; + } + temp = m[0]; + for (i = 1; i < n; ++i) { temp = min(temp, m[i]); } + cout << temp << endl; + return 0; +} +long int a[10000000]; +int main() { + int n; + cin >> n; + int m = 0; + int len = 0; + int aaa = n; + while (aaa) { + len++; + aaa /= 10; + } + for (int i = n - len * 9; i < n; i++) { + int sum = i, p = i; + while (p) { + sum += p % 10; + p /= 10; + } + if (sum == n) { a[m++] = i; } + } + cout << m << endl; + for (int i = 0; i < m; i++) { cout << a[i] << endl; } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + string s; + cin >> n >> s; + bool ok = true; + for (int i = 0, j = n - 1; i < j; ++i, --j) { + if (s[i] != s[j]) { + int x = s[i] - s[j]; + if (abs(x) != 2) { + cout << "NO" << endl; + ok = false; + break; + } + } + } + if (ok) { cout << "YES" << endl; } + } +} +int n, m, l, r; +char s[105]; +char a, b; +int main() { + cin >> n >> m; + cin >> s; + while (m--) { + cin >> l >> r >> a >> b; + for (int i = l - 1; i <= r - 1; ++i) { + if (s[i] == a) s[i] = b; + } + } + cout << s << endl; + return 0; +} +int g[105]; +int main() { + int n, x, y, h = 0; + cin >> n; + int a[n + 5], b[n + 5]; + cin >> x; + for (int i = 0; i < x; i++) { + cin >> a[i]; + g[a[i]]++; + } + cin >> y; + for (int i = 0; i < y; i++) { + cin >> b[i]; + g[b[i]]++; + } + for (int i = 1; i <= n; i++) { + if (g[i] == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } + } + cout << "I become the guy." << endl; + return 0; +} +int main() { + long long n, x, a, sum = 0, p; + cin >> n >> x; + while (n) { + cin >> a; + sum = sum + a; + n--; + } + p = abs(sum); + if (p == 0) { + cout << 0 << endl; + return 0; + } + if (p <= x) { + cout << 1 << endl; + } else { + if (p % x == 0) + cout << p / x << endl; + else + cout << (p / x) + 1 << endl; + } +} +int main() { + int n; + cin >> n; + int iskom = n / 2; + int tmp = iskom + 1; + int k1 = 1; + for (int i = 0; i < iskom; i++) { + int k = 1; + while (k != tmp) { + cout << '*'; + k++; + } + for (int p = 0; p < k1; p++) cout << 'D'; + while (k1 + k <= n) { + cout << '*'; + k++; + } + k1 += 2; + tmp--; + cout << endl; + } + for (int i = 0; i < n; i++) cout << 'D'; + cout << endl; + for (int i = 0; i < iskom; i++) { + k1 -= 2; + tmp++; + int k = 1; + while (k != tmp) { + cout << '*'; + k++; + } + for (int j = 0; j < k1; j++) cout << 'D'; + while (k1 + k <= n) { + cout << '*'; + k++; + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + set s; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + s.insert(x); + } + if (s.find(0) != s.end()) { + cout << s.size() - 1 << endl; + } else { + cout << s.size() << endl; + } +} +int main() { + string a, b; + int ans = 0; + cin >> a; + cin >> b; + for (int i = 0; i < a.length(); i++) { + if ((a[i] >= 'A') && (a[i] <= 'Z')) { a[i] += 32; } + if ((b[i] >= 'A') && (b[i] <= 'Z')) { b[i] += 32; } + if (a[i] < b[i]) { + ans = -1; + break; + } else if (a[i] > b[i]) { + ans = 1; + break; + } + } + cout << ans << endl; + return 0; +} +int n, d, x[101], aes; +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i += 1) cin >> x[i]; + sort(x + 1, x + n + 1); + aes = 0; + for (int i = 1; i <= n; i += 1) + for (int j = i; j <= n; j += 1) { + int aes0 = x[j] - x[i]; + if (aes0 <= d && j - i + 1 > aes) aes = j - i + 1; + } + cout << n - aes << '\n'; + return 0; +} +int main() { + long long n, k, h; + cin >> n >> k; + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; +} +const int maxn = 1010; +vector v; +bool is_prime[maxn]; +int prime[maxn]; +int k; +void Euler(int n) { + int i, j; + k = 0; + for (i = 2; i < n; i++) { + if (is_prime[i] == false) prime[k++] = i; + for (j = 0; j < k && i * prime[j] < n; j++) { + is_prime[i * prime[j]] = true; + if (i % prime[j] == 0) break; + } + } +} +int main() { + int n, x; + Euler(maxn); + int ans(0); + cin >> n; + for (int i = 0; i < k; i++) { + if (prime[i] <= n) { + int p = prime[i]; + while (p <= n) { + v.push_back(p); + p *= prime[i]; + } + } + } + cout << v.size() << endl; + if (v.size() > 0) { + for (int i = 0; i < v.size() - 1; i++) cout << v[i] << ' '; + cout << v[v.size() - 1] << endl; + } + return 0; +} +int main() { + long long i, j, k, n; + cin >> n; + for (i = 1, j = 3; i <= 35; i++, j *= 3) { + if (n % j != 0) break; + } + cout << (n / j) + 1 << endl; +} +int main() { + int n; + cin >> n; + int *a = new int[n]; + int sum = 0; + int max; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + if (i == 0) { + max = a[i]; + } else { + if (a[i] > max) { max = a[i]; } + } + } + int f = (2 * sum / n) + 1; + if (f > max) { + cout << f << endl; + } else { + cout << max << endl; + } + return 0; +} +const int maxN = 3e3 + 9, maxV = 5e3 + 50, MOD = 998244353, LG = 20, LIM = 100; +int main() { + int n, t, d, k, x; + cin >> n >> t >> k >> d; + x = n / k; + if (n % k) x++; + if (d < (x - 1) * t) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +int main() { + long long n, k, x, i; + cin >> n >> k >> x; + int a[n + 1]; + for (i = 0; i < n; i++) { cin >> a[i]; } + long long f = 0, ans; + long long g = n - k; + for (i = 0; i < g; i++) { f = f + a[i]; } + ans = f + (k * x); + cout << ans << endl; +} +int main() { + int curr[3][3] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + int actions[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> actions[i][j]; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (actions[i][j] % 2 == 1) { + if (curr[i][j] == 1) + curr[i][j] = 0; + else + curr[i][j] = 1; + if (j > 0) { + if (curr[i][j - 1] == 1) + curr[i][j - 1] = 0; + else + curr[i][j - 1] = 1; + } + if (i > 0) { + if (curr[i - 1][j] == 1) + curr[i - 1][j] = 0; + else + curr[i - 1][j] = 1; + } + if (j < 2) { + if (curr[i][j + 1] == 1) + curr[i][j + 1] = 0; + else + curr[i][j + 1] = 1; + } + if (i < 2) { + if (curr[i + 1][j] == 1) + curr[i + 1][j] = 0; + else + curr[i + 1][j] = 1; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << curr[i][j]; } + cout << endl; + } + return 0; +} +int main() { + long long int a, b, x, y; + cin >> x >> y >> a >> b; + long long int g = __gcd(x, y); + x = (x * y) / g; + if (a % x == 0) + cout << b / x - a / x + 1; + else + cout << b / x - a / x; + cout << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int n; + int a[101]; + while (cin >> n) { + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) cin >> a[i]; + int tmp = a[0]; + for (int i = 1; i < n; i++) { tmp = gcd(tmp, a[i]); } + cout << n * tmp << endl; + } + return 0; +} +const int mx = 1e5 + 10; +int dx[] = {1, 0, -1, 0, -1, 1, -1, 1}; +int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; +int main() { + double a, b, c; + cin >> a >> b >> c; + cout << (double)(ceil(c * (a - b) / b)) << endl; +} +int main() { + long long int arra[1100]; + long long int i, j, k, l, p, q, r, s, t, u, v, w, n, max_i = 0; + cin >> n; + for (i = 1; i <= n; i++) { cin >> arra[i]; } + sort(arra, arra + n + 1); + for (i = 1; i <= n; i++) { + if (arra[i] >= max_i) { max_i = arra[i]; } + } + if (n == 1) { + cout << "0" << '\n'; + } else { + l = max_i - arra[1] + 1 - n; + cout << l << '\n'; + } +} +int main() { + int n = 0; + cin >> n; + for (int i = 0; i < n; i++) { + long long s, a, b, c; + cin >> s; + cin >> a; + cin >> b; + cin >> c; + cout << (s / c) + (((s / c) / a) * b) << endl; + } + return 0; +} +int main() { + char a[30005][25], ch; + int n; + cin >> n; + do { ch = getchar(); } while (ch != '\n'); + int j = 0; + do { + j++; + a[1][j] = getchar(); + } while (a[1][j] != '\n' && a[1][j] != ' '); + int length = j - 1; + for (int i = 2; i <= n; i++) { + int j = 0; + do { + j++; + a[i][j] = getchar(); + } while (a[i][j] != '\n' && a[i][j] != ' '); + for (int j = 1; j <= length + 1; j++) + if (a[i][j] != a[i - 1][j]) { + length = j - 1; + break; + } + } + cout << length << endl; + return 0; +} +int main() { + long long t, i, j, n, m, k, ans, ck, cnt = 0, sum = 0, c = 0; + string s, s1, s2, tmp; + cin >> n >> m; + ck = min(n, m); + long long fact = 1; + for (i = 1; i <= ck; i++) { fact *= i; } + cout << fact << endl; + return 0; +} +int main() { + int A[3], i; + for (i = 0; i < 3; i++) cin >> A[i]; + sort(A, A + 3); + int ans = A[2] - A[0]; + cout << ans << endl; + return 0; +} +long long int MOD = 1000000007; +long long int inf = 1e15; +void scan(int &x); +long long int powermod(long long int _a, long long int _b, long long int _m) { + long long int _r = 1; + while (_b) { + if (_b % 2 == 1) _r = (_r * _a) % _m; + _b /= 2; + _a = (_a * _a) % _m; + } + return _r; +} +long long int string_to_number(string s) { + long long int x = 0; + stringstream convert(s); + convert >> x; + return x; +} +long long int add(long long int a, long long int b) { + long long int x = (a + b) % MOD; + return x; +} +long long int mul(long long int a, long long int b) { + long long int x = (a * b) % MOD; + return x; +} +long long int sub(long long int a, long long int b) { + long long int x = (a - b + MOD) % MOD; + return x; +} +long long int divi(long long int a, long long int b) { + long long int x = a; + long long int y = powermod(b, MOD - 2, MOD); + long long int res = (x * y) % MOD; + return res; +} +int min(int a, int b) { + return a < b ? a : b; +} +int main() { + int n; + cin >> n; + int var; + int i; + for (i = 0; i < n; i++) { + cin >> var; + if (var == 1) { break; } + } + if (i == n) + cout << "1" + << "\n"; + else + cout << "-1" + << "\n"; + return 0; +} +void scan(int &x) { + register int c = getchar(); + x = 0; + int neg = 0; + for (; ((c < 48 || c > 57) && c != '-'); c = getchar()) + ; + if (c == '-') { + neg = 1; + c = getchar(); + } + for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } + if (neg) x = -x; +} +int main() { + long int x, sum1 = 0, sum2 = 0; + cin >> x; + for (int i = 0; i < x; i++) { + long int a, b; + cin >> a >> b; + if (a > 0) + sum1++; + else + sum2++; + } + if (sum1 == 1 || sum2 == 1 || sum1 == x || sum2 == x) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int n, k, a[1001], ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + a[i] = k; + sort(a, a + i + 1); + if (((a[0] == k && a[1] != k) || (a[i] == k && a[i - 1] != k)) && i != 0) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, i, flag = 0, a, b; + char str[105]; + while (cin >> n >> k) { + cin >> str; + for (i = 0; i < n; i++) + if (str[i] == 'G') + a = i; + else if (str[i] == 'T') + b = i; + if (a > b) + for (i = a; i >= 0; i -= k) { + if (str[i] == '#') { + flag = 0; + break; + } else if (str[i] == 'T') { + flag = 1; + break; + } + } + else + for (i = a; i < n; i += k) { + if (str[i] == '#') { + flag = 0; + break; + } else if (str[i] == 'T') { + flag = 1; + break; + } + } + if (flag == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } +} +int main() { + int t; + int a; + cin >> t; + while (t--) { + cin >> a; + int p = 180 - a; + if (360 % p == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + string s; + cin >> s; + string d = "hello"; + int n = 0; + int c = 0; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == d[c]) { + c++; + n++; + } + } + if (n == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int countLuckyNum(string t) { + int count = 0; + for (int i = 0; i < t.length(); i++) { + if (t[i] == '4' || t[i] == '7') count++; + } + return count; +} +int main() { + int n, k; + cin >> n >> k; + string tmp; + int count = 0; + while (cin >> tmp) { + if (countLuckyNum(tmp) <= k) count++; + } + cout << count << endl; +} +int main() { + int n, i, j; + int h[100000], m[100000], count[100000]; + cin >> n; + for (i = 0; i < n; i++) { cin >> h[i] >> m[i]; } + for (i = 0; i < n; i++) count[i] = 1; + for (i = 0, j = 0; i < n - 1; i++) { + if (h[i] == h[i + 1] && m[i] == m[i + 1]) { + count[j]++; + } else if (count[j] != 1) + j++; + } + int ans = count[0]; + for (i = 0; i < n; i++) { + if (count[i] > ans) ans = count[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x0, y0, x1, y1, a = 0; + x0 = y0 = 1e9 + 87; + x1 = y1 = -9e8; + for (int i = 0; i < n; ++i) { + int l, b, r, u; + cin >> l >> b >> r >> u; + a += (r - l) * (u - b); + x0 = min(x0, l); + x1 = max(x1, r); + y0 = min(y0, b); + y1 = max(y1, u); + } + x1 -= x0; + y1 -= y0; + cout << (x1 == y1 && x1 * y1 == a ? "YES\n" : "NO\n"); +} +int n; +int main() { + cin >> n; + int a[n + 10]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { a[i] -= 1; } + } + for (int j = 0; j < n - 1; j++) { cout << a[j] << " "; } + cout << a[n - 1] << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long curr = 2; + long long lev = 1; + while (lev != n + 1) { + long long tar = (lev * (lev + 1)); + cout << (tar / lev) * tar - curr / lev << '\n'; + curr = tar; + lev++; + } + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int s = 0; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + if (i <= n - k || x > a) + s += a; + else + s += x; + } + cout << s << endl; + return 0; +} +int main() { + int a[5][5], b[5][5], i, j; + for (i = 1; i < 4; i++) + for (j = 1; j < 4; j++) cin >> a[i][j], b[i][j] = 1; + for (i = 1; i < 4; i++) + for (j = 1; j < 4; j++) + if (a[i][j] & 1) { + b[i][j] = !b[i][j], b[i - 1][j] = !b[i - 1][j], b[i + 1][j] = !b[i + 1][j]; + b[i][j - 1] = !b[i][j - 1], b[i][j + 1] = !b[i][j + 1]; + } + for (i = 1; i < 4; i++) { + for (j = 1; j < 4; j++) cout << b[i][j]; + puts(""); + } +} +long long a[100100]; +int main() { + long long n, k; + cin >> n >> k; + long long num = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % k == 0) + num = num + a[i] / k; + else + num = num + a[i] / k + 1; + } + if (num % 2 == 0) + cout << num / 2 << endl; + else + cout << (num / 2) + 1 << endl; + return 0; +} +int main() { + int n, k, a[50] = {0}; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (a[k - 1] != 0) { + while (a[k - 1] == a[k]) { k++; } + cout << k << endl; + } else { + if (k == 1) + cout << 0 << endl; + else { + k--; + while (a[k - 1] == 0) k--; + cout << k << endl; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int i = 1; i <= m; i++) cout << "#"; + cout << endl; + } else if (i % 4 == 0) { + cout << "#"; + for (int i = 2; i <= m; i++) cout << "."; + cout << endl; + } else { + for (int i = 2; i <= m; i++) cout << "."; + cout << "#"; + cout << endl; + } + } +} +const int maxn = 1e2 + 5; +int main() { + int n, k; + cin >> n >> k; + char str[maxn]; + int a[maxn]; + cin >> str; + for (int i = 0; i < strlen(str); i++) a[i] = str[i] - 'a' + 1; + sort(a, a + n); + int sum = 0; + int num = -1; + int tot = 0; + for (int i = 0; i < n; i++) { + if (a[i] - num >= 2) { + sum += a[i]; + num = a[i]; + tot++; + if (tot == k) break; + } + } + if (tot == k) + cout << sum << endl; + else + cout << -1 << endl; +} +int main() { + int ans = 0, n, k; + string s, a = ""; + cin >> n >> k >> s; + sort(s.begin(), s.end()); + int c = 0; + for (int i = 0; c < k; i++) { + if (int(s[i]) > int(a[a.size() - 1] + 1)) { + ans += 1 + (s[i] - 'a'); + a += s[i]; + c++; + } + if (i >= n) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; + return 0; +} +const int N = 1e3 + 5; +int n; +int arr[N]; +int book[N]; +int main() { + cin >> n; + while (n != 0) { + if (n == 1) break; + if (n % 2 != 0) { + cout << "NO" << endl; + return 0; + } + n /= 2; + } + cout << "YES" << endl; + return 0; +} +int main() { + char str[1000], t[1000]; + int cnt = 0, j = 0; + gets(str); + int l = strlen(str); + sort(str, str + l); + for (int i = 0; i < l; i++) { + if (str[i] != str[i - 1]) { + t[j] = str[i]; + j++; + } + } + t[j] = '\0'; + if (strlen(t) % 2 == 0) { + cout << "CHAT WITH HER!\n"; + } else { + cout << "IGNORE HIM!\n"; + } + return 0; +} +const int mod = int(1e9 + 7); +int n, res, red, blue; +int main() { + cin >> n; + for (int i = 0; i < n; i++) + if (i % 2 == 0) + red = (red + blue + 1) % mod; + else + blue = (blue + red + 1) % mod; + res = (red + blue) % mod; + cout << res << endl; + return 0; +} +int main() { + int i, j, k = 0, l; + string s; + vector vec; + cin >> s; + for (i = 0; i < 5; i++) { + string s1; + cin >> s1; + if (s1[0] == s[0] || s1[1] == s[1]) k++; + } + if (k > 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int x1, x2, x3, y1, y2, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + if ((y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)) { + cout << "TOWARDS" << endl; + } else if ((x3 - x2) * (y2 - y1) - (x2 - x1) * (y3 - y2) > 0) { + cout << "RIGHT" << endl; + } else { + cout << "LEFT" << endl; + } + return 0; +} +int main() { + int n, i, j; + int a[105][105], f[105], t, b[105]; + cin >> n; + t = 0; + for (i = 0; i < n; i++) f[i] = 1; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) + f[i] = 0; + else if (a[i][j] == 2) + f[j] = 0; + else if (a[i][j] == 3) + f[i] = f[j] = 0; + } + } + for (i = 0; i < n; i++) { + if (f[i]) b[t++] = i + 1; + } + cout << t << endl; + for (i = 0; i < t; i++) { + if (i != t - 1) + cout << b[i] << " "; + else + cout << b[i] << endl; + } + return 0; +} +int main() { + long long n, k, x, ans = 0; + cin >> n >> k >> x; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = n - 1; i > n - 1 - k; i--) { + if (a[i] > x) { + ans += x; + } else { + ans += a[i]; + } + } + for (int i = 0; i <= n - 1 - k; i++) ans += a[i]; + cout << ans << endl; +} +long long solve(long long a, long long b) { + if (a == 0) { + return 0; + } else { + return (b / a + solve(b % a, a)); + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b; + cin >> a >> b; + cout << solve(min(a, b), max(a, b)) << endl; + ; + } + return 0; +} +int a[10005]; +int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int ans = gcd(a[1], a[2]); + for (int i = 3; i <= n; i++) ans = gcd(ans, a[i]); + cout << ans * n << endl; + return 0; +} +int n, cont = 0, cont2 = 0; +string s; +int main() { + bool check = true; + cin >> n >> s; + for (unsigned int i = 0; i < s.size() / 2; i++) { + if (s[i] == '4' || s[i] == '7') { + cont += (((int)s[i]) - 48); + } else { + check = false; + } + } + for (unsigned int i = s.size() / 2; i < s.size(); i++) { + if (s[i] == '4' || s[i] == '7') { + cont2 += (((int)s[i]) - 48); + } else { + check = false; + } + } + if (cont == cont2 && check == true) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +long long a[(int)1e6]; +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + if (n == 1) { + cout << sum << endl; + return 0; + } + if (n == 2) { + cout << 2 * sum << endl; + return 0; + } + sort(a, a + n); + long long prod = n - 2; + long long resta = 0; + int i = 0; + while (prod > 0) { + resta += a[i] * prod; + i++; + prod--; + } + long long resp = sum * n - resta; + cout << resp << endl; + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n, m, c = 0; + cin >> n >> m; + bool x, y, first = false; + x = prime(n); + y = prime(m); + if ((!x && y) || (x && !y) || (!x && !y)) + cout << "NO" << endl; + else { + for (int i = 1; i <= m; i++) { + if (i == n) { + first = true; + } else { + if (first) { + x = prime(i); + if (x) c++; + } + } + } + if (c == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +bool can(int i, int j, int k) { + if (i + j > k && j + k > i && i + k > j) return true; + return false; +} +int main() { + int w, h, k; + cin >> w >> h >> k; + int ans = 0; + while (w > 0 && h > 0 && k > 0) { + ans += 2 * (w + h) - 4; + w -= 4; + h -= 4; + k--; + } + cout << ans << endl; +} +const int M = 100000 + 5; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + for (int a = 0; a <= 1000; a++) { + for (int b = 0; b <= 1000; b++) { + if (a * a + b == n && a + b * b == m) { ans++; } + } + } + cout << ans << endl; + return 0; +} +long long n, a, b; +int main() { + cin >> n; + for (int i = sqrt(n); i >= 1; i--) { + if ((n / i) * i == n) return cout << i << " " << n / i << '\n', 0; + } + return 0; +} +int main() { + int n; + cin >> n; + int dir = 0; + int esq = 0; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + if (x > 0) { + dir++; + } else if (x < 0) { + esq++; + } + } + if (esq <= 1 || dir <= 1) { + cout << "Yes\n"; + } else { + cout << "No\n"; + } + return 0; +} +int main() { + vector lines(3); + cin >> lines[0] >> lines[1] >> lines[2]; + sort(lines.begin(), lines.end()); + int counter = 0; + while (lines[0] + lines[1] <= lines[2]) { + lines[0]++; + counter++; + } + cout << counter << endl; + return 0; +} +int main() { + int n, k, a, c = 0, v = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a <= 8) + if (c >= 8 - a) { + v += 8; + c -= 8 - a; + } else { + v += a + c; + c = 0; + } + else { + v += 8; + c += a - 8; + } + if (v >= k) { + cout << i << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int n, h, a, b, k, t, p[10000], q[10000], r[10000], s[10000]; +int main() { + cin >> n >> h >> a >> b >> k; + for (int i = 0; i < k; i++) { cin >> p[i] >> q[i] >> r[i] >> s[i]; } + for (int i = 0; i < k; i++) { + if (p[i] != r[i]) { + if (q[i] < a) { + t = a - q[i] + abs(p[i] - r[i]) + abs(s[i] - a); + cout << t << endl; + } else if (q[i] > b) { + t = q[i] - b + abs(p[i] - r[i]) + abs(s[i] - b); + cout << t << endl; + } else { + t = abs(p[i] - r[i]) + abs(s[i] - q[i]); + cout << t << endl; + } + } else { + t = abs(s[i] - q[i]); + cout << t << endl; + } + } +} +int n, m, cnt, l, r, a, sum, ans, s_pro; +bool ok; +int main() { + cin >> n; + int pro[n + 1]; + for (int i = 0; i < n; i++) cin >> pro[i], s_pro += pro[i]; + sort(pro, pro + n); + cin >> m; + int lf, ri; + for (int i = 0; i < m; i++) { + cin >> lf >> ri; + while (true && !ok) { + sum += pro[a]; + cnt++; + if (sum >= lf && sum <= ri) + ans = sum; + else if (sum <= ri) + ans = lf; + else { + sum -= pro[a]; + cnt--; + break; + } + a++; + if (a == n || cnt == n) ok = 1; + } + } + if (cnt == n) + cout << ans << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int v[6], f = 0, l = 0; + for (int i = 0; i < 6; i++) { cin >> v[i]; } + sort(v, v + 6); + do { + if (v[0] + v[1] + v[2] == v[3] + v[4] + v[5]) { + cout << "YES" << endl; + f = 1; + return 0; + } + } while (next_permutation(v, v + 6)); + cout << "NO" << endl; + return 0; +} +int arr[524289] = {0}; +int conv(long long int num) { + int pos = 0, ans = 0; + while (num > 0) { + int s = num % 10; + num /= 10; + if (s % 2 != 0) ans += pow(2, pos); + pos++; + } + return ans; +} +int main() { + int t; + cin >> t; + while (t--) { + char c; + long long int num; + cin >> c >> num; + int position = conv(num); + if (c == '+') + arr[position]++; + else if (c == '-') + arr[position]--; + else + cout << arr[position] << "\n"; + } +} +int main() { + long long int n, i, j, k, x, y, t, m; + cin >> n >> k; + long long int a[300]; + for (i = 1; i <= n; i++) cin >> a[i]; + long long int mn = 1e15; + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) mn = min(mn, k / a[i]); + } + cout << mn << endl; +} +int main() { + string s; + int sum = 0; + cin >> s; + for (int i = 1; i < s.length() - 1; i++) + if (s[i] == 'A') { + int tot1 = 0, tot2 = 0; + for (int j = 0; j < i; j++) + if (s[j] == 'Q') tot1++; + for (int j = i + 1; j < s.length(); j++) + if (s[j] == 'Q') tot2++; + sum += tot1 * tot2; + } + cout << sum << endl; + return 0; +} +int main() { + int n, t, a; + cin >> n >> t; + for (int i = 1; i <= n; ++i) { + cin >> a; + t -= 86400 - a; + if (t <= 0) return cout << i << endl, 0; + } +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + int loct, locg; + for (int i = 0; i < n; i++) { + if (s[i] == 'T') loct = i; + if (s[i] == 'G') locg = i; + } + bool flag = false; + if (locg < loct) { + int i = locg + k; + for (; i < loct; i += k) { + if (s[i] == '#') flag = true; + } + if (i == loct && flag == false) + cout << "YES\n"; + else + cout << "NO\n"; + } else { + int i = locg - k; + for (; i > loct; i -= k) { + if (s[i] == '#') flag = true; + } + if (i == loct && flag == false) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 1; + while (true) { + if ((ans * n) % 10 == 0 || (ans * n) % 10 == k) { + cout << ans << endl; + return 0; + } + ans++; + } + return 0; +} +int main() { + int N, S; + cin >> N >> S; + --S; + int a[N], b[N]; + for (int i = 0; i < N; ++i) cin >> a[i]; + for (int i = 0; i < N; ++i) cin >> b[i]; + if (a[0] && a[S]) { + cout << "YES" << endl; + return 0; + } + for (int k = S + 1; k < N; ++k) { + if (a[0] && a[k] && b[k] && b[S]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + pair pr[n]; + for (int i = 0; i < n; i++) { cin >> pr[i].first >> pr[i].second; } + sort(pr, pr + n); + for (int j = 0; j < n - 1; j++) { + if (pr[j].first < pr[j + 1].first && pr[j].second > pr[j + 1].second) { + cout << "Happy Alex" << endl; + return 0; + } + } + cout << "Poor Alex" << endl; + return 0; +} +void addBinary(string a, string b) { + int n = a.size(); + for (int i = 0; i < n; i++) { + if (a[i] == '1' && b[i] == '1') + cout << "0"; + else if (a[i] == '0' && b[i] == '0') + cout << "0"; + else + cout << "1"; + } + cout << endl; +} +int main() { + cout.precision(10); + cout << fixed; + string a; + string b; + cin >> a >> b; + addBinary(a, b); +} +int main() { + int n, m, ans = 0; + int arr[100005]; + bool flag = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = m - 1; i < n; i++) { + if (arr[i] != arr[n - 1]) { + flag = 1; + break; + } + } + if (!flag) { + for (int i = 0; i < m; i++) { + if (arr[i] != arr[n - 1]) { ans = i + 1; } + } + cout << ans << endl; + } else { + cout << -1 << endl; + } + return 0; +} +const unsigned long long oo = ~(1LL << 63); +const double EPS = 1e-9; +int most_significant(unsigned long long r) { + for (int i = 62; i >= 0; i--) { + if ((1ULL << i) <= r) return i; + } + return 0; +} +unsigned long long f(unsigned long long l, unsigned long long r) { + if (l == r) return l; + int b = most_significant(r); + if ((1ULL << b) <= l) return f(l - (1ULL << b), r - (1ULL << b)) + (1ULL << b); + if (((1ULL << (b + 1)) - 1) <= r) return ((1ULL << (b + 1)) - 1); + return (1ULL << b) - 1; +} +int main() { + int t; + unsigned long long l, r; + cin >> t; + while (t--) { + cin >> l >> r; + cout << f(l, r) << '\n'; + } + return 0; +} +long long a[100001]; +int main() { + int m; + while (cin >> m) { + long long sum = 0; + long long t = 1e9 + 1; + for (int i = 1; i <= m; i++) { + cin >> a[i]; + sum = sum + a[i]; + if (a[i] < t && a[i] % 2 == 1) t = a[i]; + } + if (sum % 2 == 1 && t != 1e9 + 1) cout << sum - t << endl; + if (sum % 2 == 0) cout << sum << endl; + if (sum % 2 == 1 && t == 1e9 + 1) cout << 0 << endl; + } + return 0; +} +; +int main() { + int k, n, w; + cin >> k >> n >> w; + int sum = 0; + for (int i = 1; i <= w; i++) { sum = sum + i * k; } + if (n - sum < 0) + cout << sum - n << endl; + else + cout << 0 << endl; +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= 30) + cout << m << endl; + else { + n = pow(2, n); + cout << m % n << endl; + } +} +const int INF = 2e9 + 7; +const int MAXA = 1e5 + 10; +const int MOD = 1e9 + 7; +const unsigned long long INFLL = 9e18 + 7; +int main() { + int(testCnt) = 0; + int(t); + cin >> (t); + while (t-- && ++testCnt) { + unsigned long long l, r; + int mx = 0; + unsigned long long ans = 0; + cin >> l >> r; + ans = r; + mx = __builtin_popcountll(r); + for (unsigned long long i = 0; (1LL << i) <= r; i++) { + if ((r >> i) & 1LL) { + unsigned long long rr = r; + rr |= ((1LL << i) - 1LL); + rr ^= (1LL << i); + if (rr >= l) { + int temp = __builtin_popcountll(rr); + if (temp >= mx) { + ans = rr; + mx = temp; + } + } else + break; + } + } + cout << ans << endl; + } + return 0; +} +int a[1000]; +int b[100005]; +int main() { + long long x, y, l, r, i, j, n, k, ans, m, ggg; + while (cin >> n) { + memset(b, 0, sizeof(b)); + int sum = 0; + for (i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + cin >> m; + for (i = 1; i <= m; i++) { + cin >> l >> r; + for (j = l; j <= r; j++) b[j] = 1; + } + if (sum > 100000) { + cout << "-1" << endl; + continue; + } + k = 0; + for (i = sum; i <= 100000; i++) { + if (b[i] == 1) { + cout << i << endl; + k = 1; + break; + } + } + if (k == 0) cout << "-1" << endl; + } + return 0; +} +int getans(int a, int b) { + if (a == 0) return 0; + return b / a + getans(b % a, a); +} +int main() { + int T; + cin >> T; + while (T--) { + int a, b; + cin >> a >> b; + cout << getans(min(a, b), max(a, b)) << endl; + } +} +int main() { + bool ya = true; + int n, r = 0, l = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n / 2; i++) { + if (s[i] != '4' && s[i] != '7') ya = false; + l += s[i] - '0'; + } + for (int i = n / 2; i < n; i++) { + if (s[i] != '4' && s[i] != '7') ya = false; + r += s[i] - '0'; + } + if (l == r && ya) + ya = true; + else if (l != r) + ya = false; + (ya) ? cout << "YES" << endl : cout << "NO" << endl; + return 0; +} +int main() { + int gra[102][102]; + int x1, y1, x2, y2, n; + memset(gra, 0, sizeof(gra)); + cin >> n; + for (int k = 1; k <= n; k++) { + cin >> x1 >> y1 >> x2 >> y2; + for (int i = x1; i <= x2; i++) { + for (int j = y1; j <= y2; j++) { gra[i][j]++; } + } + } + int sum = 0; + for (int i = 1; i <= 100; i++) { + for (int j = 1; j <= 100; j++) { sum += gra[i][j]; } + } + cout << sum << endl; + return 0; +} +int n; +int main() { + cin >> n; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +int main() { + int x; + cin >> x; + int res = 2 * (x / 2) + (x / 2); + cout << res << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + string str; + str.resize(n); + for (int i = n - 1; i >= 0; i--) cin >> str[i]; + string str2 = str; + bool added = false; + for (int i = n - 1; i >= 0; i--) { + if (!added) { + if (str[i] == '1') { + str[i] = '0'; + if (i > 0) str[i - 1]++; + } else + str[i] = '1'; + added = true; + } else { + if (str[i] > '1') { + str[i] = '0'; + if (i > 0) str[i - 1]++; + } + } + } + int ans = 0; + for (int i = 0; i < n; i++) + if (str[i] != str2[i]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - (n + 1) / 2 + 1) + abs(j - (n + 1) / 2 + 1) <= (n + 1) / 2 - 1) + cout << "D"; + else + cout << "*"; + } + cout << "\n"; + } + return 0; +} +int main() { + int b, a, i; + cin >> a; + b = sqrt(a); + for (; b < a; i--) { + if (a % b != 0) + b--; + else + break; + } + cout << b << " " << a / b << endl; + return 0; +} +void print(int a[], int n) { + for (int i = 1; i < n; i++) cout << a[i] << " "; + cout << endl; +} +int main() { + int n; + cin >> n; + int eat, cost; + cin >> eat >> cost; + int min = cost, money = min * eat; + for (int i = 2; i <= n; i++) { + cin >> eat >> cost; + if (cost > min) { + money += min * eat; + } else { + money += cost * eat; + min = cost; + } + } + cout << money << endl; +} +int main() { + int n; + cin >> n; + int a[4] = {}; + int sh[4][n]; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + a[temp]++; + sh[temp][a[temp]] = i + 1; + } + int min1 = min(min(a[1], a[2]), a[3]); + cout << min1 << endl; + for (int i = 1; i <= min1; i++) { cout << sh[1][i] << " " << sh[2][i] << " " << sh[3][i] << endl; } +} +int main() { + int n, y, y2, y3, y4; + cin >> n; + for (int i = 1 + n; i <= 9020; i++) { + y = i % 10; + y2 = (i / 10) % 10; + y3 = (i / 100) % 10; + y4 = (i / 1000) % 10; + if (y != y2 && y != y3 && y != y4 && y2 != y3 && y2 != y4 && y3 != y4) { + cout << i << endl; + break; + } + } + return 0; +} +int a[111]; +int main() { + int n; + cin >> n; + int n1, n2; + cin >> n1; + for (int i = 1; i <= n1; i++) { + int x; + cin >> x; + a[x] = 1; + } + cin >> n2; + for (int i = 0; i < n2; i++) { + int x; + cin >> x; + a[x] = 1; + } + int flag = 1; + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + flag = 0; + break; + } + } + if (flag) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int main() { + long long int n, m, a, b; + long long int dem, bui, tm; + cin >> n >> m >> a >> b; + tm = n / m; + dem = (n - (tm * m)) * b; + bui = ((tm + 1) * m - n) * a; + cout << min(dem, bui) << endl; + return 0; +} +int a[] = {0, 100, 20, 10, 5, 1}; +int main() { + int n, ans = 0; + cin >> n; + for (int i = 1; i <= 5; i++) { + ans += n / a[i]; + n %= a[i]; + } + cout << ans << endl; + return 0; +} +queue a; +char s[1000005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i] != a.front() && a.size() != 0) { + a.pop(); + } else { + a.push(s[i]); + } + } + cout << a.size() << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + long long x = n / 10; + long long y = n / 100 * 10 + n % 10; + cout << max(x, y) << endl; + } + return 0; +} +long long n, a, b, c, d; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c >> d; + cout << a / d + (a / d / b) * c << "\n"; + } +} +int n, res; +char s[110]; +void solve() { + cin >> n >> s; + res = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { + res++; + break; + } + res++; + } + cout << res << "\n"; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + cin >> n; + string str; + cin >> str; + vector v(n); + for (long long(i) = (0); (i) < (n); ++i) cin >> v[i]; + long long nowR = -1; + long long ans = 1000000000000000000LL; + for (long long(i) = (0); (i) < (n); ++i) { + if (str[i] == 'R') { + nowR = v[i]; + } else { + if (nowR != -1) { ans = min(ans, (v[i] - nowR) / 2); } + } + } + if (ans == 1000000000000000000LL) { + cout << -1 << endl; + } else { + cout << ans << endl; + } + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + if (n % s == 0) + n = n / s; + else + n = n / s + 1; + k = k * n; + if (k % p == 0) + cout << k / p << endl; + else + cout << k / p + 1 << endl; + return 0; +} +const double pi = 2 * acos(0.0); +const int maxn = 2e2 + 10; +int main() { + int n; + cin >> n; + n /= 2; + cout << n + 1 << endl; + return 0; +} +int main() { + int long long l, r; + cin >> l >> r; + if (l % 2 != 0) l++; + if (l + 2 > r) + cout << -1 << endl; + else + cout << l << " " << l + 1 << " " << l + 2 << endl; + return 0; +} +int a[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1}; +int main() { + long long n; + int x; + cin >> n >> x; + cout << a[n % 6][x] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int s[100005] = {0}; + int a; + for (int i = 1; i < n; i++) { + cin >> a; + s[a] = 1; + } + for (int i = 1; i <= n; i++) + if (s[i] != 1) { + cout << i; + break; + } + cout << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int h = 4 * 60 - y; + int ans = 0; + for (int i = 1; i <= x; i++) { + h = h - (i * 5); + if (h >= 0) { + ans++; + } else { + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n, m; + cin >> n >> m; + long long a = min(n, m); + if (a % 2 == 0) + cout << "Malvika" << '\n'; + else + cout << "Akshat" << '\n'; + } + return 0; +} +int main() { + int n, k, r = -1; + int count_dig = 0, count_num = 0; + cin >> n >> k; + string t = "0123456789"; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j <= k; j++) { + if (s.find(t[j]) != -1) { count_dig++; } + } + if (count_dig >= k + 1) count_num++; + count_dig = 0; + } + cout << count_num << endl; + return 0; +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + int lcm = x * y / __gcd(x, y); + int ans = b / lcm - (a - 1) / lcm; + cout << ans << endl; + return 0; +} +int main() { + cout << "Karen" << endl; + return 0; +} +int cell[101][101]; +int main() { + int n, x1, y1, x2, y2; + cin >> n; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + for (int i = min(x1, x2); i <= max(x1, x2); i++) { + for (int j = min(y1, y2); j <= max(y1, y2); j++) { cell[i][j]++; } + } + } + int sum = 0; + for (int i = 0; i <= 100; i++) { + for (int j = 0; j <= 100; j++) { sum += cell[i][j]; } + } + cout << sum << "\n"; + return 0; +} +int main() { + int p, a, b; + int min = 99999999; + for (int i = 1; i <= 4; i++) { + cin >> p; + if (p < min) min = p; + } + cin >> a >> b; + if (min >= a && min <= b) + cout << min - a << endl; + else if (min < a) + cout << 0 << endl; + else if (min > b) + cout << b - a + 1 << endl; +} +int main() { + int t; + cin >> t; + map x; + while (t--) { + char s; + cin >> s; + long long a; + cin >> a; + int p = 0, i = 1; + while (a) { + p += i * (a % 2); + a /= 10; + i *= 3; + } + if (s == '+') { + x[p]++; + } else if (s == '-') { + x[p]--; + } else { + cout << x[p] << endl; + } + } + return 0; +} +long long a[5000]; +map m; +long long counts, flag; +int main() { + long long n; + long long c; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (!a[i]) continue; + if (!m.count(a[i])) { + m[a[i]] = 0; + m[a[i]]++; + } else { + m[a[i]]++; + if (m[a[i]] == 2) counts++; + if (m[a[i]] > 2) flag = 1; + } + } + if (flag) + cout << -1 << endl; + else + cout << counts << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1;; ++i) { + if (i == n + i / m) { + cout << i << endl; + break; + } + } + return 0; +} +const long long MOD = int(1e9) + 9; +long long n, m, t, ans; +int main() { + cin >> n >> m; + long long t = 1; + for (int i = 1; i <= m; ++i) t = t * 2 % MOD; + t--; + ans = t; + for (int i = 2; i <= n; ++i) { + t--; + if (t <= 0) t += MOD; + ans = ans * t % MOD; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int k = 1; + while (true) { + if (b == 0) { + cout << 0 << endl; + return 0; + } + if (b >= k) { + b -= k; + } else { + cout << b << endl; + return 0; + } + if (k == a) { + k = 1; + } else { + k++; + } + } + return 0; +} +int main() { + int a, p; + char s[100]; + cin >> a; + for (int i = 0; i < a; i++) { + cin >> s; + p = strlen(s); + if (p > 10) { + cout << s[0] << (p - 2) << s[p - 1]; + } else { + cout << s; + } + cout << '\n'; + } + return 0; +} +int main() { + int n, m, a, b, arr[100009], brr[100009]; + cin >> n >> m >> a >> b; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= m; i++) { cin >> brr[i]; } + if (arr[a] < brr[m - b + 1]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + int a; + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + int a1, a2, a3, b1, b2, b3, n; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + int total_cup = a1 + a2 + a3; + int a = total_cup; + int total_med = b1 + b2 + b3; + int b = total_med; + int cup = total_cup / 5; + int med = total_med / 10; + if (a % 5) { cup = cup + 1; } + if (b % 10) { med = med + 1; } + if (cup + med <= n) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k = 0; + cin >> n; + while (n != 0) { + if (n >= 100) { + k += n / 100; + n %= 100; + } else if (n >= 20) { + k += n / 20; + n %= 20; + } else if (n >= 10) { + k += n / 10; + n %= 10; + } else if (n >= 5) { + k += n / 5; + n %= 5; + } else { + k += n; + n = 0; + } + } + cout << k << endl; +} +int main() { + string my; + cin >> my; + vector his(5); + for (int i = 0; i < 5; i++) { cin >> his[i]; } + for (int i = 0; i < 5; i++) { + if (his[i][0] == my[0]) { + cout << "YES\n"; + return 0; + } + } + for (int i = 0; i < 5; i++) { + if (his[i][1] == my[1]) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + char s[5010]; + cin >> s; + int l = strlen(s), i, j; + int ans = 0; + for (i = 0; i < l - 1; i++) { + int x = 0, y = 0, z = 0; + for (j = i; j < l; j++) { + if (s[j] == '(') + x++; + else if (s[j] == ')') + y++; + else + y++, z++; + if (x + z < y - z) break; + while (x < y && z) { x++, y--, z--; } + if (x == y) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + int k = 0; + cin >> n >> m; + k = n > m ? m : n; + if (k % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; +} +int main() { + int n, menor, pos, ans, i; + cin >> n; + vector V(n); + for (i = 0; i < n; i++) { cin >> V[i]; } + menor = 2000000000; + for (i = 0; i < n; i++) { menor = min(menor, V[i]); } + for (i = 0; i < n; i++) { + if (V[i] == menor) { + pos = i; + break; + } + } + ans = 1000000; + for (i = pos + 1; i < n; i++) { + if (V[i] == menor) { + if (i - pos < ans) ans = i - pos; + pos = i; + } + } + cout << ans << '\n'; +} +long long int GCD(int a, int b) { + if (a == 0 || b == 0) return 0; + if (b > a) swap(a, b); + long long int sum = 0; + sum += a / b; + sum += GCD(a % b, b); + return sum; +} +int main() { + int n, a, b; + cin >> n; + while (n--) { + cin >> a >> b; + cout << GCD(a, b) << '\n'; + } +} +int main() { + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; ++i) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << endl; +} +int cont[1005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> cont[i]; } + int ans = 0; + int now = 0; + for (int i = 0; i < n; i++) { + if (cont[i] == 0) { + now++; + ans = max(ans, now); + } else { + int tmp = now; + for (int j = i; j < n; j++) { + if (cont[j]) { tmp++; } + } + ans = max(ans, tmp); + } + } + cout << ans << endl; +} +long long int n; +long long int delta, x; +int main() { + cin >> n; + delta = 1 + 4 * 2 * n; + delta = sqrt(delta); + x = delta - 1; + if (x % 2 != 0) x--; + x /= 2; + int odp = n - ((x + 1) * (x)) / 2; + if (odp == 0) + cout << x << endl; + else + cout << odp << endl; + return 0; +} +int main() { + int n; + cin >> n; + int s1 = 0, s2 = 0, parity = 0; + while (n--) { + int x, y; + cin >> x >> y; + s1 += x; + s2 += y; + if (x % 2 != y % 2) parity++; + } + if (!(s1 % 2) && !(s2 % 2)) + cout << "0\n"; + else if (!(parity % 2)) { + if (parity > 0) + cout << "1\n"; + else + cout << "-1\n"; + } else + cout << "-1\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + char *a = new char[n]; + int count = 0; + int v = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == '0') { v = 1; } + if (a[i] == '1' && v == 0) { count++; } + } + if (count != n) { + if (a[count] == '0') { count++; } + } + cout << count << endl; +} +int arr[1001]; +int main() { + int n, m; + cin >> n >> m; + int i, j, b, k, idx; + for (i = 1; i <= m; i++) { + k = -1; + for (j = 1; j <= n; j++) { + cin >> b; + if (b > k) { + k = b; + idx = j; + } + } + arr[idx]++; + } + int d = -1, ans; + for (i = 0; i < 1001; i++) { + if (arr[i] > d) { + d = arr[i]; + ans = i; + } + } + cout << ans << endl; +} +int main() { + int l[500000] = {0}, a; + double max = 0, s = 0; + cin >> a; + for (int b = 1; b <= a; b++) { + cin >> l[b]; + max = (float)l[b] + max; + } + for (int b = 1; b <= a; b++) { + s = s + (float)l[b]; + if (s >= max / 2) { + cout << b << endl; + return 0; + } + } +} +int main() { + int k, i, x, l = 0, m = 0, j = 0; + int alen, blen, clen, team; + cin >> k; + vector a; + vector b; + vector c; + for (i = 0; i < k; i++) { + cin >> x; + if (x == 1) { + a.push_back(i); + } else if (x == 2) { + b.push_back(i); + } else { + c.push_back(i); + } + } + alen = a.size(); + blen = b.size(); + clen = c.size(); + if (alen <= blen && alen <= clen) { + cout << alen; + team = alen; + } else if (blen <= alen && blen <= clen) { + cout << blen; + team = blen; + } else { + team = clen; + cout << clen; + } + cout << "\n"; + for (i = 0; i < team; i++) { + cout << a[i] + 1 << " " << b[i] + 1 << " " << c[i] + 1; + cout << "\n"; + } +} +short n, m; +int main() { + cin >> n >> m; + for (int i = 1; m >= ((i % n) == 0 ? n : (i % n)); ++i) { + if (i % n) + m -= (i % n); + else + m -= n; + } + cout << m << endl; + return 0; +} +int main() { + int n, m; + string s; + cin >> n >> m; + cin >> s; + int l, r; + char c1, c2; + while (m--) { + cin >> l >> r >> c1 >> c2; + l--; + r--; + for (int i = l; i <= r; i++) + if (s[i] == c1) s[i] = c2; + } + cout << s << "\n"; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2 == 1) + cout << "1" << endl; + else + cout << "0" << endl; +} +int main() { + int n, t; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t; + if (360.0 / (180 - t) == (360 - 360 % (180 - t)) / (180 - t)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +string s; +int n; +int main() { + while (cin >> n) { + getchar(); + getline(cin, s); + int ans = 0, tmp = 0; + for (int i = 0; i < n; i++) { + if (s[i] >= 'A' && s[i] <= 'Z') + tmp++; + else if (s[i] == ' ') { + ans = max(ans, tmp); + tmp = 0; + } + } + ans = max(ans, tmp); + cout << ans << endl; + } + return 0; +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +int main() { + long long k, l; + while (cin >> k >> l) { + if (l - k < 2) + cout << -1 << endl; + else if (!(k % 2)) { + cout << k << " " << k + 1 << " " << k + 2 << endl; + } else if (k % 2 && l - k >= 3) { + cout << k + 1 << " " << k + 2 << " " << k + 3 << endl; + } else + cout << -1 << endl; + } + return 0; +} +int main() { + int distanc; + cin >> distanc; + int steps = 0; + while (distanc > 0 && distanc > 4) { + distanc = distanc - 5; + steps++; + } + while (distanc > 0 && distanc > 3) { + distanc = distanc - 4; + steps++; + } + while (distanc > 0 && distanc > 2) { + distanc = distanc - 3; + steps++; + } + while (distanc > 0 && distanc > 1) { + distanc = distanc - 2; + steps++; + } + steps = steps + distanc; + cout << steps << endl; +} +int main() { + int n, m; + while (cin >> n) { + vector ep; + for (int i = 0; i < n - 1; i++) { + cin >> m; + ep.push_back(m); + } + sort(ep.begin(), ep.end()); + for (int i = 1; i <= n; i++) + if (i != ep[i - 1]) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np, i, j, m; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + j = (k * l) / nl; + m = c * d; + i = p / np; + if (j <= m && j <= i) + cout << j / n << endl; + else if (m <= j && m <= i) + cout << m / n << endl; + else + cout << i / n << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int x = min(n, m); + if (x % 2) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; + } + return 0; +} +int main() { + int w, h, v1, d1, v2, d2; + cin >> w >> h >> v1 >> d1 >> v2 >> d2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == d1) { w -= v1; } + if (i == d2) { w -= v2; } + if (w < 0) w = 0; + } + cout << w << endl; + return 0; +} +int gcd(int a, int b) { + return (b ? gcd(b, a % b) : a); +} +int main() { + int x, y, a, b, v, k; + cin >> x >> y >> a >> b; + v = x * y / gcd(x, y); + k = b / v - (a - 1) / v; + cout << k << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 0) { + cout << "#"; + } else if (i % 4 == 1 && j == m) { + cout << "#"; + } else if (i % 4 == 3 && j == 1) { + cout << "#"; + } else { + cout << "."; + } + if (j == m) { cout << endl; } + } + } + return 0; +} +int main() { + int n, a = 0, b = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a |= x; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b |= x; + } + cout << a + b << '\n'; +} +vector tran(string s) { + vector res(18, 0); + int i = 1; + while ((int)s.size() - i >= 0) { + res[18 - i] = (s[s.size() - i] - '0') % 2; + i++; + } + return res; +} +bool judge(vector num, vector temp) { + for (int i = 17; i >= 0; i--) + if (num[i] != temp[i]) return false; + return true; +} +int main() { + map, int> biao; + int t; + cin >> t; + for (int i = 0; i < t; i++) { + char op; + cin >> op; + if (op == '+') { + string s; + cin >> s; + vector num; + num = tran(s); + biao[num]++; + } else if (op == '-') { + string s; + cin >> s; + vector num; + num = tran(s); + biao[num]--; + if (biao[num] == 0) { biao.erase(num); } + } else if (op == '?') { + string s; + cin >> s; + vector num = tran(s); + map, int>::iterator it; + it = biao.begin(); + int res = biao[num]; + cout << res << endl; + } + } +} +int main() { + int n; + cin >> n; + int a[7] = {0}; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s[0] == 'p') + a[0] = 1; + else if (s[0] == 'g') + a[1] = 1; + else if (s[0] == 'b') + a[2] = 1; + else if (s[0] == 'o') + a[3] = 1; + else if (s[0] == 'r') + a[4] = 1; + else if (s[0] == 'y') + a[5] = 1; + } + cout << 6 - n << endl; + if (!a[0]) cout << "Power" << endl; + if (!a[1]) cout << "Time" << endl; + if (!a[2]) cout << "Space" << endl; + if (!a[3]) cout << "Soul" << endl; + if (!a[4]) cout << "Reality" << endl; + if (!a[5]) cout << "Mind" << endl; +} +int main() { + int n, m; + int i; + while (cin >> n >> m) { + i = 1; + while (n > 0) { + if (i % m == 0) { + ; + } else { + n--; + } + i++; + } + cout << i - 1 << endl; + } + return 0; +} +int a[1000005]; +int main() { + int n; + cin >> n; + int sum = 0; + while (n--) { + int a; + cin >> a; + if (a >= 0) + sum += a; + else + sum -= a; + } + cout << sum << endl; + return 0; +} +int main() { + int n, i, j, arr[1000]; + while (cin >> n) { + string s1[n], s2; + for (i = 0; i < n; i++) { + cin >> s1[i] >> s2; + if (s2 == "rat") { + arr[i] = 0; + } else if (s2 == "woman" || s2 == "child") { + arr[i] = 1; + } else if (s2 == "man") { + arr[i] = 2; + } else + arr[i] = 3; + } + for (j = 0; j < 4; j++) { + for (i = 0; i < n; i++) { + if (arr[i] == j) { cout << s1[i] << endl; } + } + } + } + return 0; +} +int main() { + string s; + int sp = 0, p = 0; + getline(cin, s); + string s2 = ""; + int l = s.size(); + for (int i = 0; i < l; i++) { + if (s[i] == ' ') + sp++; + else if (s[i] == ',' || s[i] == '.' || s[i] == '?' || s[i] == '!') { + p++; + s2 += s[i]; + } else { + if (sp == 0 && p == 0) + s2 += s[i]; + else if (p == 0 && sp > 0) { + s2 += ' '; + s2 += s[i]; + sp = 0; + } else { + s2 += ' '; + s2 += s[i]; + p = 0; + sp = 0; + } + } + } + cout << s2 << endl; + return 0; +} +int n, ans; +void kt(int &n, int v) { + ans += n / v; + n %= v; + return; +} +int main() { + cin >> n; + kt(n, 100); + kt(n, 20); + kt(n, 10); + kt(n, 5); + kt(n, 1); + cout << ans << endl; + return 0; +} +int main() { + int n, arr[200][2], c = 0, y, l; + bool low = 0, upper = 0, right = 0, left = 0; + cin >> n; + for (y = 0; y < n; y++) cin >> arr[y][0] >> arr[y][1]; + for (y = 0; y < n; y++) { + for (l = 0; l < n; l++) { + if (arr[l][0] > arr[y][0] && arr[l][1] == arr[y][1]) + right = 1; + else if (arr[l][0] < arr[y][0] && arr[l][1] == arr[y][1]) + left = 1; + } + for (int q = 0; q < n; q++) { + if (arr[q][1] > arr[y][1] && arr[q][0] == arr[y][0]) + upper = 1; + else if (arr[q][1] < arr[y][1] && arr[q][0] == arr[y][0]) + low = 1; + } + if (right && left && upper && low) c++; + low = 0; + left = 0; + upper = 0; + right = 0; + } + cout << c << endl; +} +int main() { + long long int n, i, j, x, y, m = INT_MAX; + cin >> n; + for (j = 0; j * 7 <= n; j++) { + i = (n - 7 * j) / 4; + if (i + j < m && 4 * i + 7 * j == n) { + x = i; + y = j; + m = i + j; + } + } + if (m != INT_MAX) { + while (x--) cout << 4; + while (y--) cout << 7; + cout << endl; + } else + cout << -1 << endl; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + int ar[k]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < k; i++) { cin >> ar[i]; } + if (k >= 2) + cout << "Yes" << endl; + else { + bool flag = true; + if (arr[0] == 0) arr[0] = ar[0]; + for (int i = 1; i < n; i++) { + if (arr[i] == 0) arr[i] = ar[0]; + if (arr[i] < arr[i - 1]) { + flag = false; + break; + } + } + cout << ((flag == true) ? "No" : "Yes") << endl; + } +} +int main() { + int n; + cin >> n; + int max, a, b, c; + cin >> a >> b; + c = a + b; + max = c; + for (int i = 1; i < n; i++) { + cin >> a >> b; + c -= a; + c += b; + if (c > max) max = c; + } + cout << max << endl; + return 0; +} +const int MAX = 1e5 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +const double pi = acos(-1); +int n, a, b, x, y, k, sz, cnt, res, tmp; +string s, t; +int main() { + cin >> n >> k; + while (n--) { + cin >> a >> b; + y += b - a + 1; + } + cout << (k - y % k) % k << "\n"; + return 0; +} +int main() { + int t, n, x, y, d; + cin >> t; + for (int i = 0; i < t; ++i) { + int res = -1; + cin >> n >> x >> y >> d; + if (x <= y && (y - x) % d == 0) res = (y - x) / d; + if (x > y && (x - y) % d == 0) res = (x - y) / d; + if ((y - 1) % d == 0) { + int res1 = (x - 1 + d - 1) / d + (y - 1) / d; + if (res == -1 || res1 < res) res = res1; + } + if ((n - y) % d == 0) { + int res1 = (n - x + d - 1) / d + (n - y) / d; + if (res == -1 || res1 < res) res = res1; + } + cout << res << endl; + } + return 0; +} +int main() { + int n; + int v1, t1, v2, t2; + int res1, res2; + while (cin >> n >> v1 >> v2 >> t1 >> t2) { + res1 = 2 * t1 + n * v1; + res2 = 2 * t2 + n * v2; + if (res1 < res2) + cout << "First" << endl; + else if (res1 > res2) + cout << "Second" << endl; + else if (res1 == res2) + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + if (2 * t1 + s * v1 == 2 * t2 + s * v2) + cout << "Friendship" << endl; + else if (2 * t1 + s * v1 < 2 * t2 + s * v2) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int a, b, c, d, m, v; + cin >> a >> b >> c >> d; + m = max((3 * a) / 10, a - (a / 250) * c); + v = max((3 * b) / 10, b - (b / 250) * d); + if (m == v) { + cout << "Tie" << endl; + } else if (m > v) { + cout << "Misha" << endl; + } else { + cout << "Vasya" << endl; + } + return 0; +} +int main() { + int rep = 0; + int mishka = 0; + int chris = 0; + int mishkaCounter = 0; + int chrisCounter = 0; + cin >> rep; + while (rep--) { + cin >> mishka >> chris; + if (mishka > chris) mishkaCounter++; + if (chris > mishka) chrisCounter++; + } + if (mishkaCounter > chrisCounter) + cout << "Mishka" << endl; + else if (chrisCounter > mishkaCounter) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + string c[8]; + while (cin >> c[0]) { + for (int i = 1; i < 8; ++i) cin >> c[i]; + int t = 1; + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) + if (c[i][j] == c[i][j + 1]) { + t = 0; + break; + } + } + if (t) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } + return 0; +} +string str[9]; +bool ok(int k) { + int ret = 1; + for (int i = 1; i < 8; i++) { + if (str[k][i] == str[k][i - 1]) ret = 0; + } + if (str[k][1] == str[k][8]) ret = 0; + return ret; +} +int main() { + for (int i = 1; i <= 8; i++) { cin >> str[i]; } + int f = 1; + for (int i = 1; i <= 8; i++) { + if (!ok(i)) { f = 0; } + } + if (f) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int games, bills; + cin >> games >> bills; + vector prices(games); + deque bills_(bills); + for (int i = 0; i < games; ++i) cin >> prices[i]; + for (int i = 0; i < bills; ++i) cin >> bills_.at(i); + int count = 0; + for (int i = 0; i < games; ++i) { + int price = prices[i]; + if (bills_.size() > 0 && price <= bills_[0]) { + count++; + bills_.pop_front(); + } + } + cout << count << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long res = (n * (n + 1)) / 2; + int x = m % res; + for (int i = 1; i <= n; i++) { + if (x >= i) { + x -= i; + } else { + cout << x << endl; + return 0; + } + } + cout << x << endl; + return 0; +} +int main() { + int ans = 0; + int k; + string s; + cin >> s; + for (int i = 0; i < s.size(); ++i) + for (int j = 0; j < s.size(); ++j) { + if (i < j) { + for (k = 0;; k++) + if (i + k >= s.size() || j + k >= s.size() || s[i + k] != s[j + k]) break; + ans = max(ans, k); + } + } + cout << ans << endl; + return 0; +} +int main() { + int i, j, l, m, n, t, x, y, r, z, o; + set st; + cin >> n; + for (i = 0; i < n; i++) { + string s; + cin >> s; + set ts; + set::iterator it; + for (j = 0; j < s.size(); j++) { ts.insert(s[j]); } + string kt; + for (it = ts.begin(); it != ts.end(); it++) { kt += *it; } + st.insert(kt); + } + cout << st.size() << endl; +} +string a[100][2]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; + for (int i = 0; i < n - 1; i++) + if (a[i][1] == "captain") + { + string s = a[i][1]; + a[i][1] = a[i + 1][1]; + a[i + 1][1] = s; + s = a[i][0]; + a[i][0] = a[i + 1][0]; + a[i + 1][0] = s; + } + for (int i = 1; i < n; i++) + if (a[i][1] == "rat") + for (int j = i; j > 0; j--) + if (a[j - 1][1] != "rat") { + string s = a[j][1]; + a[j][1] = a[j - 1][1]; + a[j - 1][1] = s; + s = a[j][0]; + a[j][0] = a[j - 1][0]; + a[j - 1][0] = s; + } + for (int i = 1; i < n; i++) + if (a[i][1] == "woman" || a[i][1] == "child") + for (int j = i; j > 0; j--) + if (a[j - 1][1] != "woman" && a[j - 1][1] != "child" && a[j - 1][1] != "rat") { + string s = a[j][1]; + a[j][1] = a[j - 1][1]; + a[j - 1][1] = s; + s = a[j][0]; + a[j][0] = a[j - 1][0]; + a[j - 1][0] = s; + } + for (int i = 0; i < n; i++) cout << a[i][0] << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int cnt = 0; + for (int i = 0; i < n; ++i) { + int x; + cin >> x; + if (x > b && c > x) { ++cnt; } + } + cout << cnt << endl; +} +const int M = 1000000 + 10; +int main() { + int n; + cin >> n; + int x, y; + int min_xy = M; + int minx, miny; + minx = miny = M; + for (int x = 0; x <= n; x++) { + int res = n - x * 4; + if (res >= 0 && res % 7 == 0) { + y = res / 7; + if (x + y <= min_xy) { + min_xy = x + y; + minx = x; + miny = y; + } + } + } + if (min_xy == M) { + cout << "-1" << endl; + } else { + for (int i = 0; i < minx; i++) { cout << "4"; } + for (int i = 0; i < miny; i++) { cout << "7"; } + cout << endl; + } + return 0; +} +int main() { + long long TESTS = 1; + cin >> TESTS; + while (TESTS--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (p == q) { + if (x == y) + cout << 0 << '\n'; + else + cout << -1 << '\n'; + continue; + } + if (p == 0) { + if (ceil((y - x) / ((q - p) * 1.0)) * q - y < 0) + cout << -1 << '\n'; + else + cout << ceil((y - x) / ((q - p) * 1.0)) * q - y << '\n'; + continue; + } + long long t = max(ceil(x / (p * 1.0)), ceil((y - x) / ((q - p) * 1.0))); + if (t * q - y < 0) + cout << -1 << '\n'; + else + cout << t * q - y << '\n'; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) { + if (i % 2 == 0) { + if (i % 4 == 0) { + if (j == 1) { + cout << '#'; + } else { + cout << '.'; + } + } else { + if (j == m) { + cout << '#'; + } else { + cout << '.'; + } + } + } else { + cout << '#'; + } + } + cout << endl; + } + return 0; +} +int main() { + int s; + cin >> s; + int v1; + cin >> v1; + int v2; + cin >> v2; + int t1; + cin >> t1; + int t2; + cin >> t2; + int time1 = s * v1 + 2 * t1; + int time2 = s * v2 + 2 * t2; + if (time1 < time2) { cout << "First" << '\n'; } + if (time1 > time2) { cout << "Second" << '\n'; } + if (time1 == time2) { cout << "Friendship" << '\n'; } + return 0; +} +const int N = 1e1 + 123; +const int M = 1e7 + 123; +const long long inf = 1e18 + 1; +const int mod = 1e9 + 7; +int t; +int main() { + cin >> t; + while (t--) { + long long second, a, b, c; + cin >> second >> a >> b >> c; + second /= c; + long long x = second / a; + second %= a; + long long cnt = x * 1LL * (a + b); + cout << cnt + second << endl; + } + return 0; +} +const int MOD = 998244353; +const int MAX = 200001; +int mmin = 0xc0c0c0c0; +int mmax = 0x3f3f3f3f; +int An[MAX]; +int book[MAX]; +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int t1 = max(3 * a / 10, a - a * c / 250); + int t2 = max(3 * b / 10, b - b * d / 250); + if (t1 > t2) + cout << "Misha" << endl; + else if (t1 < t2) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +int main() { + long long t, n = 0; + cin >> t; + long long arr[t]; + for (int i = 0; i < t; ++i) { + long long a, b, c, d; + cin >> a >> b >> c; + if (c % 2 == 0) + d = a * (c / 2) - b * (c / 2); + else + d = a * (c / 2) + a - b * (c / 2); + arr[n] = d; + ++n; + } + for (int i = 0; i < n; ++i) cout << arr[i] << endl; + return 0; +} +int main() { + int n, k = 1; + cin >> n; + for (int i = 0; i < n; i++) { + if (i < n / 2 + 1) { + for (int j = 1; j <= n; j++) { + if (j <= (n - i * 2 - 1) / 2) { + cout << "*"; + } else if (j <= n / 2 + i + 1) { + cout << "D"; + } else { + cout << "*"; + } + } + } else { + for (int j = 1; j <= n; j++) { + if (j <= k) { + cout << "*"; + } else if (j <= n - k) { + cout << "D"; + } else { + cout << "*"; + } + } + k++; + } + cout << "\n"; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v_c(n, 0); + vector v_g(n, 0); + int idx = 0; + int max_v = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + cin >> v_c[j]; + if (v_c[j] > max_v) { + idx = j; + max_v = v_c[j]; + } + } + v_g[idx]++; + idx = 0; + max_v = 0; + } + for (int i = 0; i < n; i++) { + if (v_g[i] > max_v) { + idx = i; + max_v = v_g[i]; + } + } + cout << idx + 1 << endl; + return 0; +} +char str[101][101]; +int row[101], col[101]; +int C(int a) { + if (a % 2) + return (a - 1) / 2 * a; + else + return a / 2 * (a - 1); +} +int main() { + int n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> str[i][j]; + if (str[i][j] == 'C') row[i]++; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (str[j][i] == 'C') col[i]++; + } + } + for (int i = 0; i < n; i++) { + if (row[i] < 2) + continue; + else { + sum += C(row[i]); + } + } + for (int i = 0; i < n; i++) { + if (col[i] < 2) + continue; + else { + sum += C(col[i]); + } + } + cout << sum << endl; +} +const int maxn = 200100; +long long n; +long long sum = 0; +long long ans = 0; +long long i; +int a[maxn]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + sum = (sum + 1) / 2; + i = 1; + while (ans < sum) { + ans += a[i]; + i++; + } + cout << i - 1 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int r1 = min(a, b); + int r2 = (max(a, b) - min(a, b)) / 2; + cout << r1 << " " << r2 << endl; +} +int main() { + int n; + cin >> n; + cin.ignore(); + string str; + getline(cin, str); + stringstream ss; + ss << str; + string s; + vector vec; + while (ss >> s) vec.push_back(s); + int ans, cnt; + ans = cnt = 0; + for (int i = 0; i < vec.size(); ++i) { + cnt = 0; + for (int j = 0; j < vec[i].size(); ++j) { + if (vec[i][j] >= 'A' && vec[i][j] <= 'Z') cnt++; + } + ans = max(ans, cnt); + } + cout << ans << "\n"; + return 0; +} +int main() { + int price; + int r; + cin >> price >> r; + int shovelNum = 0; + bool b = true; + while (b) { + shovelNum++; + int total = shovelNum * price; + if (total % 10 == 0 || total % 10 == r) { b = false; } + } + cout << shovelNum << endl; + return 0; +} +int main() { + unsigned long int i, j, n, sum = 0; + cin >> n; + sum = n / 2 + 1; + cout << sum << endl; +} +int main() { + int x = 0; + string s2; + cin >> s2; + for (int i = s2.length() - 2; i >= 0; i--) { + if (s2[i] == s2[i + 1]) s2.erase(i, 2); + } + cout << s2 << endl; + return 0; +} +const int N = 1e4 + 7; +const int INF = 1e9 + 7; +string s; +char ch1, ch2; +int main() { + cin >> ch1 >> ch2; + for (int i = 1; i <= 5; i++) { + cin >> s; + if (s[0] == ch1 || s[1] == ch2) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; +} +int ans, siz, tmp, tmp2; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + int ck = 0, q = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == '(') + ck++, q++; + else if (s[j] == ')') { + if (ck == 0) + ck++; + else + ck--; + q--; + } else { + if (ck == 0) + ck++; + else + ck--; + q++; + } + if (q < 0) break; + if (ck == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int matrix[5][5]; + int output = 0; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { cin >> matrix[i][j]; } + } + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if (matrix[i][j] == 1) { output = abs(2 - i) + abs(2 - j); } + } + } + cout << output << endl; + return 0; +} +const double PI = acos(-1.0); +const int inf = int(1e9); +const int mod = inf + 7; +long long n, m, k, l, w, h, sum, mx, mn; +int main() { + mn = (1e9); + string a, b; + cin >> a >> b; + if (a == b) + cout << a; + else + cout << 1; + cout << endl; + return 0; +} +int n, arr[300009]; +long long sum, mx; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + mx += arr[i]; + } + sum = mx; + sort(arr, arr + n); + int j = 0; + for (int i = 0; i < n; i++) { + if (j == n - 1) break; + mx += sum; + sum -= arr[j]; + j++; + } + cout << mx << endl; + return 0; +} +int main() { + int n; + cin >> n; + int mi = 1 << 30, mx = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + mi = min(x, mi); + mx = max(x, mx); + } + cout << mx - mi + 1 - n << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int day = 0, t = 0; + while (n--) { + t++; + day++; + if (day % m == 0) n++; + } + cout << t << '\n'; +} +int main() { + long a, b, c, d, contV, contM; + cin >> a >> b >> c >> d; + contM = max((3 * a) / 10, a - ((a * c) / 250)); + contV = max((3 * b) / 10, b - ((b * d) / 250)); + if (contV == contM) + cout << "Tie" << endl; + else { + if (contM > contV) + cout << "Misha" << endl; + else + cout << "Vasya" << endl; + } + return 0; +} +int main() { + int n, d = 0; + long long x, a; + char ch; + cin >> n >> x; + while (n--) { + cin >> ch >> a; + if (ch == '+') { + x += a; + } else { + if (x >= a) { + x -= a; + } else { + d++; + } + } + } + cout << x << ' ' << d << endl; +} +int main() { + int n; + int a, b, c; + int distance = 0; + cin >> n; + cin >> a >> b >> c; + bool flag = true; + while (--n) { + if (flag) { + distance += min(a, b); + flag = false; + continue; + } + distance += min(min(a, b), c); + } + cout << distance << endl; + return 0; +} +int player1, player2, player3; +int n; +int a; +int main() { + cin >> n; + player1 = 1; + player2 = 2; + player3 = 3; + while (n--) { + cin >> a; + if (a == player3) { + cout << "NO\n"; + return 0; + } + if (a == player1) + swap(player3, player2); + else + swap(player3, player1); + } + cout << "YES\n"; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int num4 = 0, num7 = 0; + for (int i = 0; i < (int)a.size(); i++) { + if (a[i] != b[i]) { + if (a[i] == '4') + num4++; + else + num7++; + } + } + int cnt = max(num4, num7); + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a; + if (n % 2 == 1) cout << "Ehab" << endl; + if (n % 2 == 0) cout << "Mahmoud" << endl; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + int ctr = 1; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] != s[i + 1]) ctr++; + } + if (ctr % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +int main() { + int n, m, a[60], b[60]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int i = 0; i < m; i++) cin >> b[i]; + int BG = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (!(b[j] % a[i])) { + if (b[j] / a[i] > BG) { BG = b[j] / a[i]; } + } + } + } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (!(b[j] % a[i]) && b[j] / a[i] == BG) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + string a; + string ans = ""; + char ai[20]; + cin >> a; + int wei = a.size(); + int map = 1; + int qingkuang = 1; + int o; + bool huiwen; + while (qingkuang < pow(2.0, wei)) { + o = 0; + for (int i = 0; i < wei; ++i) { + if ((qingkuang >> i) & 1) { ai[o++] = a[wei - 1 - i]; } + } + ai[o] = '\0'; + huiwen = true; + for (int i = 0; i < o; ++i) { huiwen = huiwen && (ai[i] == ai[o - 1 - i]); } + if (huiwen && strcmp(ai, ans.c_str()) > 0) ans = ai; + ++qingkuang; + } + for (int i = 0; i < ans.size(); ++i) cout << ans[i]; + cout << endl; + return 0; +} +int main() { + int n, m, c = 0, f = 0; + cin >> n >> m; + string s[n]; + char mx = '0'; + for (int i = 0; i < n; ++i) cin >> s[i]; + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { + if (s[j].at(i) >= mx) { mx = s[j].at(i); } + } + for (int j = 0; j < n; ++j) { + if (s[j].at(i) == mx) s[j].at(i) = '0'; + } + mx = '0'; + } + for (int i = 0; i < n; ++i) { + f = s[i].find('0'); + if (f >= 0) ++c; + } + cout << c << endl; +} +const int maxn = 5e3 + 5; +bool dp[maxn][maxn]; +int main() { + string s; + cin >> s; + int sum = 0, sum1, sum2, sum3; + for (int i = 0; i < s.size(); i++) { + sum1 = sum2 = sum3 = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == '(') + sum1++; + else if (s[j] == ')') { + sum1--; + } else { + sum1--; + sum2++; + } + if (sum1 + sum2 < 0) break; + if (sum1 == 0) + sum++; + else if (sum1 < 0) { + sum1 += 2; + sum2--; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool pres[100010]{false}; + int count = 0, mx = 0; + for (int i = 0; i < 2 * n; ++i) { + int p; + cin >> p; + if (!pres[p]) + pres[p] = true, count++; + else + pres[p] = false, count--; + mx = max(count, mx); + } + cout << mx << endl; + return 0; +} +int main() { + long long n, m, t; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> n >> m; + long long res = 0; + while (n > 0 && m > 0) { + if (m > n) { swap(m, n); } + res += (n / m); + n = (n % m); + } + cout << res << endl; + } + return 0; +} +int main() { + int aa[700] = {0}; + int n, a; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + aa[a]++; + } + int g = 0; + for (int i = 1; i < 605; i++) { + if (aa[i] != 0) g++; + } + cout << g << endl; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const int MOD = 1000000007; +void solve() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +int main() { + solve(); + return 0; +} +const int maxn = 1000010; +const int MAXM = 500000; +int main() { + int n; + while (cin >> n) { + int a[1005]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int cnt = 0; + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] > 1) { cnt += (a[i] - a[i - 1]) - 1; } + } + cout << cnt << endl; + } + return 0; +} +int main() { + long long n, cnt = 1; + cin >> n; + while (n >= 1 && n / cnt > 0 && (n % cnt != 0 || n / cnt > 1)) { n -= cnt, cnt++; } + cout << n << endl; + return 0; +} +int a, b, c, d, sm, sv; +int main() { + cin >> a >> b >> c >> d; + sm = max((3 * a) / 10, a - (a / 250) * c); + sv = max((3 * b) / 10, b - (b / 250) * d); + if (sm > sv) + cout << "Misha" << endl; + else if (sm < sv) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; +} +int main() { + string s[8]; + for (int i = 0; i < 8; i++) { cin >> s[i]; } + int firstw = 8, firstb = 0; + for (int i = 0; i < 8; i++) { + int now = 8; + for (int j = 0; j < 8; j++) { + if (s[j][i] == 'B') { break; } + if (s[j][i] == 'W') { + now = j; + break; + } + } + firstw = min(now, firstw); + now = 0; + for (int j = 7; j >= 0; j--) { + if (s[j][i] == 'W') { break; } + if (s[j][i] == 'B') { + now = j; + break; + } + } + firstb = max(firstb, now); + } + if (firstw <= 7 - firstb) { + cout << "A" << endl; + } else { + cout << "B" << endl; + } + return 0; +} +const int maxn = 3e5 + 5; +int main() { + int n, a, b, c; + cin >> n; + cin >> a >> b >> c; + int t = min(a, b); + int m = min(t, c); + if (n == 1) return puts("0"), 0; + if (n == 2) return cout << t << endl, 0; + cout << t + (n - 2) * m << endl; +} +int main() { + ifstream ff("file.txt"); + string s1, s2; + cin >> s1 >> s2; + reverse(s2.begin(), s2.end()); + while (s1.length() != s2.length()) { + if (s1.length() > s2.length()) { + s2.insert(s2.begin(), 1, '0'); + } else { + s1.insert(s1.begin(), 1, '0'); + } + } + int x, y; + istringstream iss(s2); + iss >> x; + istringstream iss1(s1); + iss1 >> y; + cout << x + y << endl; + return 0; +} +int main() { + char n[11]; + gets(n); + int len = strlen(n); + for (int i = len - 1; i >= 0; i--) { + if (i == 0 && n[i] == '1') { + cout << "YES" << endl; + break; + } + if (i == 1) { + if ((n[i] == '1' || n[i] == '4') && n[i - 1] == '1') { + cout << "YES" << endl; + break; + } else { + cout << "NO" << endl; + break; + } + } else if (n[i] == '1') { + continue; + } else if (n[i] == '4' && (n[i - 1] == '1' || n[i - 2] == '1')) { + continue; + } else { + cout << "NO" << endl; + break; + } + } + return 0; +} +int a[1000009] = {0}; +int main() { + int k, l, m, n, d, total = 0; + int i, j; + cin >> k >> l >> m >> n >> d; + for (i = k; i <= d; i += k) { + a[i]++; + total++; + } + for (i = l; i <= d; i += l) { + if (a[i] == 0) { + a[i]++; + total++; + } + } + for (i = m; i <= d; i += m) { + if (a[i] == 0) { + a[i]++; + total++; + } + } + for (i = n; i <= d; i += n) { + if (a[i] == 0) { + a[i]++; + total++; + } + } + cout << total << endl; +} +int main() { + int q, n[300], k = 0; + char s[300][300]; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> n[i]; + for (int j = 0; j < n[i]; j++) { cin >> s[i][j]; } + } + for (int i = 0; i < q; i++) { + if (n[i] > 2) { + cout << "YES" << endl << "2" << endl; + cout << s[i][0] << " "; + for (int j = 1; j < n[i]; j++) { cout << s[i][j]; } + cout << endl; + } else { + if (int(s[i][0]) < int(s[i][1])) { + cout << "YES" << endl << "2" << endl; + ; + cout << s[i][0] << " " << s[i][1] << endl; + } else { + cout << "NO" << endl; + } + } + } + return 0; +} +int a[120]; +int main() { + int N, K; + cin >> N >> K; + if (K > 1) { + puts("Yes"); + return 0; + } + int ind = 0; + for (int i = 1; i <= N; ++i) { + cin >> a[i]; + if (a[i] == 0) ind = i; + } + cin >> a[ind]; + for (int i = 2; i <= N; ++i) + if (a[i] < a[i - 1]) { + puts("Yes"); + return 0; + } + puts("No"); + return 0; +} +long long a, b, i; +int main() { + int n; + cin >> n; + while (n--) { + cin >> a >> b; + for (i = 1; (a | i) <= b; i <<= 1) a |= i; + cout << a << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + int suck; + int ans1 = 0, ans2 = 0; + for (int i = 1; i <= n; ++i) { + cin >> suck; + ans1 |= suck; + } + for (int i = 1; i <= n; ++i) { + cin >> suck; + ans2 |= suck; + } + cout << ans1 + ans2 << endl; +} +int main() { + int n; + cin >> n; + long long sum = 0; + vector vec; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + vec.push_back(x); + sum += x; + } + sort(vec.begin(), vec.begin() + n); + if (n == 1) { + cout << sum << endl; + return 0; + } + long long s = sum; + long long minas = 0; + for (int i = 0; i < n; i++) { + if (i == n - 1) break; + s += (sum - minas); + minas += vec[i]; + } + cout << s << endl; +} +int main() { + string s; + cin >> s; + int d = 0; + for (int i = 0; i < s.size(); ++i) { d += s[i] != s[s.size() - 1 - i]; } + if (d == 2 || (d == 0 && s.size() % 2 == 1)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, c, i; + cin >> n; + long long a[n + 5]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << (a[0] == 1 ? "-1" : "1") << endl; + return 0; +} +int main() { + int n; + ifstream ff("file.txt"); + cin >> n; + set s1; + int v; + for (int i = 0; i < n; i++) { + cin >> v; + s1.insert(v); + } + int m; + cin >> m; + vector v1(m); + for (int i = 0; i < m; i++) { cin >> v1[i]; } + sort(v1.begin(), v1.end()); + set::iterator p = s1.begin(); + long long sum = 0; + bool b1 = true; + v = *p; + int kol = v; + for (int i = m - 1; i >= 0; i--) { + if (b1 == true) { + sum += v1[i]; + kol--; + if (kol == 0) { + kol = 2; + b1 = false; + } + } else if (b1 == false) { + kol--; + if (kol == 0) { + kol = v; + b1 = true; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + char mp[110][110]; + cin >> n; + memset(mp, '*', sizeof(mp)); + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) cin >> mp[j][i]; + bool flag = true; + for (int i = 1; i <= n && flag; ++i) { + int cnt = 0; + for (int j = 1; j <= n; ++j) { + if (mp[j - 1][i] == 'o') cnt++; + if (mp[j + 1][i] == 'o') cnt++; + if (mp[j][i - 1] == 'o') cnt++; + if (mp[j][i + 1] == 'o') cnt++; + if (cnt % 2 != 0) { + flag = false; + break; + } + } + } + puts(flag ? "YES" : "NO"); + return 0; +} +const int N = 100000 + 5; +int n; +int need, mi = (1 << 30); +long long co = 0LL; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> need >> x; + mi = min(mi, x); + co += mi * (long long)need; + } + cout << co << "\n"; + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int ans = 0, flag = 0; + for (int i = 1; i <= 10; i++) { + if (i * a % 10 == 0 || (i * a - b) % 10 == 0) { + ans = i; + break; + } + } + cout << ans << endl; + } + return 0; +} +const double E = exp(1); +const int maxn = 1e6 + 10; +const int mod = 1e9 + 7; +int a[maxn]; +void change(int a, int b) { + int t = a; + a = b; + b = t; +} +int main() { + int n; + int a1, a2, a3; + a1 = 1; + a2 = 2; + a3 = 3; + cin >> n; + int flag = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] == a1) { + int t = a2; + a2 = a3; + a3 = t; + } else if (a[i] == a2) { + int t = a1; + a1 = a3; + a3 = t; + } else { + flag++; + break; + } + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int n, y = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i < n) { + int x; + cin >> x; + y ^= x; + } + y ^= i; + } + cout << y << '\n'; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int p[n]; + for (int i = 0; i < n; i++) { cin >> p[i]; } + sort(p, p + n); + long long count = 0; + if (p[b - 1] != p[b]) { + count += p[b] - p[b - 1]; + cout << count << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + int n, k, f, t, i, temp, res; + cin >> n >> k; + res = INT_MIN; + for (i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) + temp = (f - t + k); + else + temp = f; + if (temp > res) { res = temp; } + } + cout << res << endl; + return 0; +} +int a[110]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + n / 2 + 1); + int sum1 = 0, sum2 = 0; + int o = n - 1, k = n; + for (int i = n / 2; i > 0; i--) { + if (a[i] != k) sum2 += abs(k - a[i]); + k -= 2; + } + for (int i = n / 2; i > 0; i--) { + if (a[i] != o) sum1 += abs(o - a[i]); + o -= 2; + } + cout << min(sum1, sum2) << endl; + } + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int lcm(int a, int b) { + return a * (b / gcd(a, b)); +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + int MCM = lcm(x, y); + cout << (b / MCM) - ((a - 1) / MCM) << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int c[] = {0, 0, 0}; + int n; + cin >> n; + for (int i = int(0); i < int(n); i++) { + int in; + cin >> in; + c[(i % 3)] += in; + } + if (c[0] > c[1] && c[0] > c[2]) + cout << "chest" << endl; + else if (c[1] > c[2]) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + if (s != t) + cout << 1 << endl; + else + cout << s << endl; +} +int main() { + int t; + cin >> t; + map m; + for (int i = 0; i < t; i++) { + string s; + cin >> s; + m[s]++; + } + int ans = 0; + for (int i = 0; i < t; i++) { + string s; + cin >> s; + m[s]--; + } + map::iterator it = m.begin(); + while (it != m.end()) { + if (it->second < 0) { ans += it->second; } + it++; + } + cout << abs(ans) << endl; +} +int counter(char a) { + int c = 1; + if ('9' == a || '2' == a || '6' == a || '0' == a) + c = 2; + else if ('7' == a) + c = 5; + else if ('5' == a) + c = 4; + else if ('3' == a || '4' == a) + c = 3; + else if ('1' == a) + c = 7; + return c; +} +int main() { + string n; + cin >> n; + int co = 1; + for (int i = 0; i < 2; i++) { co *= counter(n[i]); } + cout << co << endl; + return 0; +} +int mat[5001][5001]; +int psum[5001][5001]; +int sum(int fi, int li, int fj, int lj) { + int big = psum[li][lj]; + int smol = (fi and fj ? psum[fi - 1][fj - 1] : 0); + int lat1 = (fj ? psum[li][fj - 1] : 0); + int lat2 = (fi ? psum[fi - 1][lj] : 0); + return big + smol - lat1 - lat2; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < 5001; ++i) { + for (int j = 0; j < 5001; ++j) { mat[i][j] = 0; } + } + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + for (int j = 0; j < m; ++j) { mat[i][j] = s[j] - '0'; } + } + psum[0][0] = mat[0][0]; + for (int i = 1; i < 5001; ++i) { psum[0][i] = psum[0][i - 1] + mat[0][i]; } + for (int i = 1; i < 5001; ++i) { psum[i][0] = psum[i - 1][0] + mat[i][0]; } + for (int i = 1; i < 5001; ++i) { + for (int j = 1; j < 5001; ++j) { psum[i][j] = psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] + mat[i][j]; } + } + int ans = 1e9; + for (int k = 2; k <= 10; ++k) { + ; + int pans = 0; + for (int i = 0; i < (n + k - 1) / k; ++i) { + for (int j = 0; j < (m + k - 1) / k; ++j) { + int c1 = sum(i * k, (i + 1) * k - 1, j * k, (j + 1) * k - 1); + int c0 = k * k - c1; + ; + ; + ; + ; + pans += min(c0, c1); + } + }; + ans = min(ans, pans); + } + cout << ans << '\n'; + return 0; +} +int v(char a, char b) { + if (a == '[' && b == '8') + return 0; + else if (a == '[' && b == '(') + return 1; + else if (a == '(' && b == '8') + return 1; + else if (a == '(' && b == '[') + return 0; + else if (a == '8' && b == '[') + return 1; + else if (a == '8' && b == '(') + return 0; + else if (a == b) + return 2; +} +int main() { + char team2[10000]; + char team1[10000]; + while (cin >> team1 >> team2) { + int count1 = 0, count2 = 0; + for (int a = 0; a < strlen(team1); a += 2) { + if (v(team1[a], team2[a]) == 1) + count1++; + else if (v(team1[a], team2[a]) == 0) + count2++; + } + if (count1 == count2) + puts("TIE"); + else if (count1 > count2) + puts("TEAM 1 WINS"); + else + puts("TEAM 2 WINS"); + } + return 0; +} +long long n, x; +int cnt = 0; +int main() { + char c; + int d; + cin >> n >> x; + getchar(); + for (int i = 0; i < n; i++) { + cin >> c >> d; + getchar(); + if (c == '+') { + x += d; + } else { + if (x < d) + cnt++; + else + x -= d; + } + } + cout << x << " " << cnt << endl; +} +int main() { + string str; + cin >> str; + cout << (str.size() + 1) * 26 - str.size() << endl; + return 0; +} +int main() { + int k, s = 0; + cin >> k; + int i, j, a, b; + int x[6] = {0}, y[6] = {0}; + for (i = 1; i <= k; i++) { + cin >> a; + x[a]++; + } + for (i = 1; i <= k; i++) { + cin >> b; + y[b]++; + } + for (i = 1; i <= 5; i++) { + if ((x[i] + y[i]) % 2 != 0) { + cout << "-1" << endl; + return 0; + } + } + for (i = 1; i <= 5; i++) { s += abs(x[i] - y[i]) / 2; } + cout << s / 2 << endl; + return 0; +} +int main() { + int n, k; + int i; + int len; + cin >> n >> k; + string s; + cin >> s; + int a[128] = {0}; + len = s.length(); + for (i = 0; i < len; i++) { + a[s[i]]++; + if (a[s[i]] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + string name; + set s; + getline(cin, name); + sort(name.begin(), name.end()); + for (int i = 0; i < name.size(); i++) { s.insert(name[i]); } + if (s.size() % 2 != 0) { + cout << "IGNORE HIM!" << endl; + } else { + cout << "CHAT WITH HER!" << endl; + } + return 0; +} +int main() { + int t, s, a, b, c; + cin >> t; + cout << 1LL * ((t + 4) / 10) * 10 << endl; +} +int main() { + int n, m; + vector a; + vector b; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + } + cin >> m; + for (int j = 0; j < m; j++) { + int x; + cin >> x; + b.push_back(x); + } + reverse(b.begin(), b.end()); + int max_ratio = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) { + if (b[j] / a[i] > max_ratio) { max_ratio = b[j] / a[i]; } + break; + } + } + } + int answer = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) { + int r = b[j] / a[i]; + if (r == max_ratio) { answer++; } + break; + } + } + } + cout << answer << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n / k % 2 != 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + if (m < (1 << n) || n >= 27) + cout << m << endl; + else + cout << (m % (1 << n)) << endl; +} +bitset<256> posibles, usadas; +int main() { + int n; + cin >> n; + string s; + getline(cin, s); + posibles.reset(); + for (int i = 'a'; i <= 'z'; ++i) { posibles[i] = true; } + int cont = 0; + for (int i = 0; i < n - 1; ++i) { + getline(cin, s); + if (s[0] == '!') { + if (posibles.count() == 1) { + cont++; + continue; + } + usadas.reset(); + for (int j = 2; j < (int)s.size(); ++j) { usadas[s[j]] = true; } + for (int j = 'a'; j <= 'z'; ++j) { posibles[j] = posibles[j] & usadas[j]; } + } else if (s[0] == '.') { + if (posibles.count() == 1) { continue; } + for (int j = 2; j < (int)s.size(); ++j) { posibles[s[j]] = false; } + } else { + if (posibles.count() == 1) { + cont++; + continue; + } + posibles[s[2]] = false; + } + } + cout << cont << "\n"; + return 0; +} +int main() { + int w, h; + cin >> w >> h; + int w1, h1, w2, h2; + cin >> w1 >> h1; + cin >> w2 >> h2; + int ans = w; + while (h) { + ans += h; + if (h == h1) ans -= w1; + if (h == h2) ans -= w2; + if (ans <= 0) ans = 0; + h--; + } + cout << ans << endl; + return 0; +} +const int mod = 1e5 + 7; +long long n, a[mod << 2], sum = 0, mi = 99999999999; +int main() { + while (cin >> n) { + if (n >= 2) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 1; i < n; i++) mi = min(mi, abs(a[i] - a[i - 1])); + for (int i = 1; i < n; i++) + if (mi == abs(a[i] - a[i - 1])) sum++; + cout << mi << " " << sum << endl; + sum = 0; + mi = 99999999999; + } + } +} +int main() { + string s; + int n, a, j, sum1 = 0, sum2 = 0; + cin >> n >> s; + a = n / 2; + bool flag = true; + for (int i = 0, j = 0; i < n; i++, j++) { + if (s[i] == '4' || s[i] == '7') { + if (j < a) { + sum1 = sum1 + s[i] - '0'; + } else + sum2 = sum2 + s[i] - '0'; + } else { + flag = false; + break; + } + } + if (flag && sum1 == sum2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long xmax, y, z; + xmax = n / (2 * (k + 1)); + if (xmax == 0) { + cout << "0 0 " << n << "\n"; + return 0; + } else { + y = k * xmax; + z = n - y - xmax; + cout << xmax << " " << y << " " << z << "\n"; + } + return 0; +} +int n, ans; +int a[10010]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> a[i]; + ans += a[i] * (i - 1) * 4; + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int k = (n * 2) - (n / 2); + cout << k << endl; +} +const int maxn = 1e5 + 10; +const int mod = 1e9 + 9; +int n, m; +long long pot[maxn]; +bool test() { + long long p = 1; + for (int i = 1; i <= m; ++i) { + p *= 2LL; + if (p > n) return true; + } + return false; +} +int main() { + cin >> n >> m; + if (!test()) { + cout << 0 << '\n'; + return 0; + } + long long ans = 1LL; + pot[0] = 1LL; + for (int i = 1; i <= m; ++i) pot[i] = (pot[i - 1] * 2LL) % mod; + for (int i = 1; i <= n; ++i) { + long long add = (pot[m] - i + mod) % mod; + ans = (ans * add) % mod; + } + cout << ans << '\n'; + return 0; +} +long long func(long long xorr, long long andd) { + if (xorr == 0 && andd == 0) return 1; + if (andd < 0 || xorr < 0) return 0; + long long bit1 = xorr % 2; + long long bit2 = andd % 2; + xorr = xorr / 2; + andd = andd / 2; + long long mul = 1; + if (bit1 == 0 && bit2 == 1) mul = 1; + if (bit1 == 1 && bit2 == 0) mul = 2; + if (bit1 == 1 && bit2 == 1) mul = 0; + if (bit1 == 0 && bit2 == 0) mul = 1; + return (mul * func(xorr, andd)); +} +int main() { + long long sum, xorr; + long long andd; + cin >> sum >> xorr; + andd = sum - xorr; + if (andd % 2 == 1) { + cout << 0 << endl; + return 0; + } + andd = andd / 2; + long long ans = func(xorr, andd); + if (sum == xorr) ans = ans - 2; + cout << ans << endl; + return 0; +} +int main() { + int t, min, max; + int c = 0; + cin >> t; + int arr[t]; + for (int i = 0; i < t; i++) { + cin >> arr[i]; + if (i == 0) { + min = arr[i]; + max = arr[i]; + } + if (arr[i] < min) { + min = arr[i]; + c++; + } + if (arr[i] > max) { + max = arr[i]; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, minx, maxx; + cin >> n >> m >> minx >> maxx; + bool mark = false, flag = false; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + if (x == minx || x == maxx) mark = true; + if (x < minx || x > maxx) flag = true; + } + if (!flag && (n - m > 1 || mark)) + cout << "Correct" << endl; + else + cout << "Incorrect" << endl; + return 0; +} +string str; +int n; +int result; +int answer; +int s[101]; +int main() { + s[0] = -1; + cin >> str; + n = (int)str.size(); + for (int i = 0; i < n; i++) { + if (str[i + 1] != str[i]) { + s[++result] = i; + if ((s[result] - s[result - 1]) % 2 == 0) answer++; + } + } + cout << answer << "\n"; + return 0; +} +bool arr[310]; +int main() { + memset(arr, 0, sizeof(arr)); + int m, p, x; + cin >> m >> p; + int ans = -1; + for (int i = 1; i <= p; ++i) { + cin >> x; + if (arr[x % m] == 0) { + arr[x % m] = 1; + } else { + ans = i; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + string s, a; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> a; + if (s[0] == a[0] || s[1] == a[1]) return puts("YES"), 0; + } + return puts("NO"), 0; +} +int a[100010], b[10010], d[10010]; +int main() { + int n, i, x1, x2, t, j; + long long l, r, s, k; + cin >> n; + while (n--) { + x1 = 0; + t = 0; + x2 = 0; + s = 0; + cin >> l >> r; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + memset(d, 0, sizeof(d)); + while (l) { + a[++x1] = l % 2; + l >>= 1; + } + while (r) { + b[++x2] = r % 2; + r >>= 1; + } + for (i = max(x1, x2); i >= 1; i--) { + if (a[i] == b[i]) + d[i] = a[i]; + else + break; + } + for (j = i; j >= 1; j--) { + d[j] = 1; + if (b[j] == 0) t = 1; + } + if (t == 1) d[i] = 0; + for (i = 1, k = 1; i <= max(x1, x2); i++, k = k * 2) s = s + d[i] * k; + cout << s << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int large = -1000000000; + for (int i = 0; i < n; i++) { + int f, t; + cin >> f >> t; + int count; + if (t > k) + count = f - (t - k); + else + count = f; + if (count > large) large = count; + } + cout << large << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n], y = 9999999, a = 0; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int j = 1; j < n - 1; j++) { + a = 0; + for (int i = 1, x = 0; i < n; i++, x++) { + if (x == j) x++; + if (i == j) i++; + a = max(abs(arr[i] - arr[x]), a); + } + y = min(a, y); + } + cout << y << endl; + return 0; +} +int main() { + string s = "qwertyuiopasdfghjkl;zxcvbnm,./", D, str, M; + int i, j; + cin >> D >> str; + for (i = 0; i < str.size(); i++) { + for (j = 0; j < s.size(); j++) { + if (str[i] == s[j]) { break; } + } + if (D == "R") { + M += s[j - 1]; + } else { + M += s[j + 1]; + } + } + cout << M << endl; + return 0; +} +long long a, b; +int main() { + cin >> a >> b; + for (int s = 0; s < a; s++) { + for (int v = 0; v < b; v++) { + if (s % 2 == 0 || s % 4 == 1 && v == b - 1 || s % 4 == 3 && v == 0) + putchar('#'); + else + putchar('.'); + } + puts(""); + } + return 0; +} +int main() { + int n, i, ans = 0, x1, y1, x2, y2; + cin >> n; + for (i = 1; i <= n; ++i) { + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + cout << a / d + a / d / b * c << endl; + } +} +int main() { + int n, k, m; + long long fill; + int diff, x; + cin >> n >> k; + cin >> m; + int c[m]; + for (int i = 0; i < m; i++) cin >> c[i]; + fill = m; + diff = int(c[0] / k); + if (c[0] % k == 0) diff = diff - 1; + fill = fill + diff; + for (int j = 0; j < m - 1; j++) { + x = c[j + 1] - c[j]; + diff = int(x / k); + if (x % k == 0) diff = diff - 1; + fill = fill + diff; + } + if (m != 0) { + x = n - c[m - 1]; + diff = int(x / k); + fill = fill + diff; + } else { + diff = int(n / k); + fill = diff; + } + cout << fill << "\n"; + return 0; +} +const int N = 1e6 + 5; +int main() { + string s1; + cin >> s1; + string s2 = "QAQ"; + int n = (int)s1.length(); + int m = (int)s2.length(); + vector dp(m + 1, 0); + dp[0] = 1; + for (int i = 0; i < n; i++) { + for (int j = m - 1; j >= 0; j--) { + if (s2[j] == s1[i]) { dp[j + 1] += dp[j]; } + } + } + cout << dp[3] << "\n"; + return 0; +} +map fre; +int main() { + string s, temp; + int i, l = 0, c, j; + cin >> s; + for (i = 0; s[i]; i++) { + temp.clear(); + for (j = i; s[j]; j++) { + temp += s[j]; + if (++fre[temp] > 1) { l = max(l, (int)temp.size()); } + } + } + cout << l << endl; +} +int main() { + string word = "hello"; + string type; + cin >> type; + int length = type.length(); + int a = 0; + int i, count = 0; + for (i = 0; i < length; i++) { + if (type[i] == word[a]) { + a++; + count++; + } + } + if (count == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +map mp; +int main() { + int n, b; + bool z = 1; + cin >> n >> b; + char x; + for (int i = 0; i < n; i++) { + cin >> x; + mp[x]++; + } + map::iterator it = mp.begin(); + for (it = mp.begin(); it != mp.end(); it++) { + if ((it->second) > b) { + z = 0; + cout << "NO" << endl; + break; + } + } + if (z) cout << "YES" << endl; + return 0; +} +int main() { + int n, i, x[100010], y[100010], c = 0; + vector v; + cin >> n; + map, int> mp; + for (i = 0; i < n; i++) { + cin >> x[i] >> y[i]; + mp[make_pair(x[i], y[i])]++; + } + for (i = 0; i < n; i++) { v.push_back(mp[make_pair(x[i], y[i])]); } + sort(v.begin(), v.end()); + if (v[v.size() - 1] == 0) + cout << "1" << endl; + else + cout << v[v.size() - 1] << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int z = ceil((double)n * y / 100); + if (z > x) + cout << z - x << endl; + else + cout << 0 << endl; +} +int main() { + long long n, x, y, ans, xx; + cin >> n >> x >> y; + xx = n * y / 100; + while (xx * 100 < n * y) xx++; + ans = max(0LL, xx - x); + cout << ans << "\n"; + return 0; +} +long long n; +int main() { + cin >> n; + if (n >= 1) { + cout << 2 << endl; + for (long long i = 3; i <= n + 1; ++i) cout << 1ll * i * (i - 1) * i - 1ll * (i - 2) << endl; + } +} +string tes; +int n; +int n0; +int n1; +int main() { + int i; + n0 = 0; + n1 = 0; + cin >> n; + cin >> tes; + for (i = 0; i < n; i++) { + if (tes[i] == '0') + n0++; + else + n1++; + } + cout << abs(n0 - n1) << endl; + return 0; +} +int main() { + int n, k, x, i, sum = 0, temp, a[102]; + cin >> n >> k >> x; + for (i = 0; i < n; i++) { + cin >> temp; + a[i] = temp; + } + sort(a, a + n); + for (i = 0; i < n - k; i++) { sum += a[i]; } + sum += k * x; + cout << sum << endl; +} +int k, n, x, a, ans; +int main() { + cin >> k >> n >> x; + for (int i = 0; i < k; i++) { + cin >> a; + if (k - n <= i && a > x) + ans += x; + else + ans += a; + } + cout << ans << '\n'; +} +int main() { + int n; + float k; + cin >> n >> k; + int arr[n]; + int pockets = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + pockets += ceil(arr[i] / k); + } + cout << (int)ceil(pockets / 2.0) << endl; +} +int a, b, c; +bool ok(int t) { + return a * c <= b * c + t * b; +} +int binarySearch() { + int lo = 0, med, hi = 1e6; + while (lo < hi) { + med = ((lo + hi) >> 1); + if (ok(med)) + hi = med; + else + lo = med + 1; + } + return lo; +} +int main() { + cin >> a >> b >> c; + cout << binarySearch() << endl; + return 0; +} +const int N = 100000 + 5; +int main() { + string a, b, c, d; + cin >> a >> b; + int n; + cin >> n; + cout << a << " " << b << endl; + for (int i = 0; i < n; i++) { + cin >> c >> d; + if (c == a) { + a = d; + } else if (c == b) { + b = d; + } + cout << a << " " << b << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char **shap = new char *[n]; + for (int i = 0; i < n; i++) shap[i] = new char[m]; + int rows, colums, rowe, colume; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> shap[i][j]; } + } + bool e = false; + for (int i = 0; i < n; i++) { + int j = 0; + for (j; j < m; j++) { + if (shap[i][j] == '*') { + rows = i; + e = true; + break; + } + } + if (e == true) { break; } + } + e = false; + for (int j = 0; j < m; j++) { + int i = 0; + for (i; i < n; i++) { + if (shap[i][j] == '*') { + colums = j; + e = true; + break; + } + } + if (e == true) { break; } + } + for (int j = colums; j < m; j++) { + int i = rows; + for (i; i < n; i++) { + if (shap[i][j] == '*') colume = j; + } + } + for (int i = rows; i < n; i++) { + int j = colums; + for (j; j < m; j++) { + if (shap[i][j] == '*') rowe = i; + } + } + for (int i = rows; i <= rowe; i++) { + for (int j = colums; j <= colume; j++) { cout << shap[i][j]; } + cout << endl; + } + return 0; +} +bool isprime(int n) { + int s = sqrt(n); + for (int i = 2; i <= s; i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int n, m; + cin >> n >> m; + int p; + for (int i = n + 1;; i++) { + if (isprime(i)) { + p = i; + break; + } + } + if (p == m) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + int arr[3]; + for (int i = 0; i < 3; i++) { cin >> arr[i]; } + sort(arr, arr + 3); + int sum = 0; + int x = arr[1]; + for (int i = 0; i < 3; i++) { sum += abs(x - arr[i]); } + cout << sum << endl; +} +void print(long long int a[], long long int n) { + for (long long int i = 0; i < n; i++) { cout << a[i] << " "; } + cout << endl; +} +long long int m(long long int x) { + return x % 1000000007; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +long long int p(long long int a, long long int b) { + if (b == 0) return 1; + long long int t = p(a, b / 2); + if (b % 2 == 0) + return t * t; + else + return a * t * t; +} +int main() { + long long int n; + long long int a, b, c; + cin >> n >> a >> b >> c; + long long int v = 0; + if (n >= 2) v += min(a, b); + long long int vv = min(a, min(b, c)); + if (n >= 2) v += (n - 2) * vv; + cout << v << endl; + return 0; +} +int main() { + int n; + int dem = 1; + int mid; + cin >> n; + mid = n / 2; + for (int i = 1; i <= n; i++) { + int j = 1; + for (j = 1; j <= (n - dem) / 2; j++) cout << "*"; + for (; j <= (n - dem) / 2 + dem; j++) cout << "D"; + for (; j <= n; j++) cout << "*"; + cout << "\n"; + if (i <= mid) + dem += 2; + else + dem -= 2; + } +} +void File() { + freopen("colors.in", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 2e5 + 5; +const int oo = 0x3f3f3f3f; +bool vowel(char c) { + if (c == 'a') return 1; + if (c == 'e') return 1; + if (c == 'i') return 1; + if (c == 'o') return 1; + if (c == 'u') return 1; + return 0; +} +int main() { + fast(); + string s; + cin >> s; + for (int i = 0; i < ((int)((s).size())) - 1; i++) { + if (!vowel(s[i]) && !vowel(s[i + 1]) && s[i] != 'n') return cout << "NO\n", 0; + } + if (s[((int)((s).size())) - 1] != 'n' && !vowel(s[((int)((s).size())) - 1])) return cout << "NO\n", 0; + cout << "YES\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int i; + for (i = 0; i < n; i++) + if (s[i] == 'G') break; + int g = i; + bool flg = false; + while (i < n) { + if (s[i] == '#') { + flg = false; + break; + } + if (s[i] == 'T') { + flg = true; + break; + } + i += k; + } + if (flg == false) { + while (g >= 0) { + if (s[g] == '#') { + flg = false; + break; + } + if (s[g] == 'T') { + flg = true; + break; + } + g -= k; + } + } + if (flg) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +bool ok(long long t, long long x, long long y, long long p, long long q) { + return (p * t - x >= 0 && q * t - y >= p * t - x); +} +int main() { + long long t; + cin >> t; + vector ans; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (!ok(1e9, x, y, p, q)) { + ans.push_back(-1); + } else { + long long z = -1; + for (long long b = 1e9; b >= 1; b /= 2) { + while (!ok(z + b, x, y, p, q)) z += b; + } + ans.push_back((q * (z + 1) - y)); + } + } + long long s = ans.size(); + for (long long i = 0; i < s; i++) { cout << ans[i] << "\n"; } + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + string n; + cin >> n; + for (int i = n.size() - 1; i >= 0; i -= 1) { + if (n[i] >= '5') { + int x = (n[i] - '0'); + cout << "-O|"; + for (int i = 0; i < x - 5; i += 1) cout << "O"; + cout << "-"; + for (int i = 0; i < 9 - x; i += 1) cout << "O"; + } else { + int x = (n[i] - '0'); + cout << "O-|"; + for (int i = 0; i < x; i += 1) cout << "O"; + cout << "-"; + for (int i = 0; i < 4 - x; i += 1) cout << "O"; + } + cout << '\n'; + } +} +int main() { + int n, i, j, k, max, cap; + max = -1; + cap = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> j >> k; + cap = cap - j + k; + if (cap > max) max = cap; + } + cout << max << endl; + return 0; +} +long long a[100005]; +int main() { + long long n, mi = 1000000007; + cin >> n; + for (long long i = 1; i < n + 1; i++) { + cin >> a[i]; + mi = min(mi, a[i]); + } + long long j = -1000000007, ans = 1000000007; + for (long long i = 1; i < n + 1; i++) { + if (a[i] == mi) { + ans = min(ans, i - j); + j = i; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long t, i, j, n, m = 0, k, ans, ck, cnt = 0, sum = 0, c = 0, p = 0; + string s, s1, s2, tmp; + cin >> n; + long long a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + ck = __gcd(a[0], a[1]); + for (i = 2; i < n; i++) { ck = __gcd(ck, a[i]); } + cout << ck * n << endl; + return 0; +} +int check(int a, int b, int c) { + return (a + b > c && b + c > a && c + a > b); +} +int ch(int a, int b, int c) { + return (a + b == c || b + c == a || c + a == b); +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int seg = 0, tr = 0; + if (check(a, b, c) || check(a, b, d) || check(b, c, d) || check(a, c, d)) { tr = 1; } + if (ch(a, b, c) || ch(a, b, d) || ch(b, c, d) || ch(a, c, d)) { seg = 1; } + if (tr) + cout << "TRIANGLE\n"; + else if (seg) + cout << "SEGMENT\n"; + else + cout << "IMPOSSIBLE\n"; + return 0; +} +int main() { + int n; + cin >> n; + int d1 = n / 10; + int d2 = n % 10; + if (d1 == 0 || d1 == 2 || d1 == 6 || d1 == 9) + d1 = 1; + else if (d1 == 3 || d1 == 4) + d1 = 2; + else if (d1 == 5) + d1 = 3; + else if (d1 == 1) + d1 = 6; + else if (d1 == 7) + d1 = 4; + else + d1 = 0; + if (d2 == 0 || d2 == 2 || d2 == 6 || d2 == 9) + d2 = 1; + else if (d2 == 3 || d2 == 4) + d2 = 2; + else if (d2 == 5) + d2 = 3; + else if (d2 == 1) + d2 = 6; + else if (d2 == 7) + d2 = 4; + else + d2 = 0; + cout << d1 + d2 + 1 + d1 * d2 << endl; +} +int main() { + int i, j, k, l, m, n; + string s; + cin >> s; + m = 0; + for (i = 0; i < s.size(); i++) { + if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') + m++; + else if (s[i] >= '0' && s[i] <= '9') { + if ((s[i] - '0') % 2 != 0) m++; + } + } + cout << m << endl; + return 0; +} +int a[10000]; +int main() { + int n, t; + int sum = 0; + cin >> n >> t; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (t <= 0) { + cout << sum << endl; + return 0; + } + int x; + x = 86400 - a[i]; + t = t - x; + sum++; + } + cout << sum << endl; + return 0; +} +int main() { + string x1; + int n, k; + cin >> n >> k; + cin >> x1; + int c, d; + for (int i = 0; i <= x1.length(); ++i) { + if (x1[i] == 'G') c = i; + if (x1[i] == 'T') d = i; + } + int i; + if (((c - d) % k) != 0) + cout << "NO" << endl; + else if (c > d) { + for (i = d + k; i <= c; i = i + k) { + if (x1[i] == '#') { + cout << "NO" << endl; + break; + } + } + if (i > c) cout << "YES" << endl; + } else { + for (i = c + k; i <= d; i = i + k) { + if (x1[i] == '#') { + cout << "NO" << endl; + break; + } + } + if (i > d) cout << "YES" << endl; + } + return 0; +} +long long int MIN(long long int a, long long int b) { + if (a > b) + return b; + else + return a; +} +long long int MAX(long long int a, long long int b) { + if (a > b) + return a; + else + return b; +} +long long int MOD(long long int x) { + if (x >= 0) + return x; + else + return -x; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + cout << n / 2 << endl; + } else { + long long int d = n / 2; + d -= n; + cout << d << endl; + } + return 0; +} +int main() { + long long int n, k; + cin >> n; + cin >> k; + long long int a[n]; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + long long int count = 0; + for (long long int i = 0; i < n; i++) { + long long int x = a[i]; + int digit = 0; + while (x != 0) { + int y = x % 10; + x = x / 10; + if (y == 4 || y == 7) { digit++; } + } + if (digit <= k) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + string g; + cin >> g; + for (int i = 0; i < n - 1; i++) { + if (g[i] != g[i + 1]) { + cout << "YES" << endl; + cout << g.substr(i, 2) << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int k, n, w, total = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { total = total + (k * i); } + if (n >= total) { + cout << 0 << endl; + } else { + cout << total - n << endl; + } + return 0; +} +double PI = 3.14159265358979323846; +int rx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; +int ry[8] = {0, -1, 1, 0, -1, 1, 1, -1}; +int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +double sabc(double a1, double a2, double a3, double b1, double b2, double b3) { + double g = ((a1 - a3) * (b2 - b3) - (b1 - b3) * (a2 - a3)) / 2; + return abs(g); +} +long long n, x, h, ii, h1, h2; +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + cin >> n; + x = 2; + for (long long i = 1; i <= n; i++) { + ii = i; + h1 = gcd(i + 1, ii); + ii /= h1; + h2 = gcd(i + 1, ii); + ii /= h2; + long long ans = ii; + h = (i + 1) / h1 * (i + 1) / h2 * ans - (i - 1); + if (i == 1) + cout << 2 << endl; + else + cout << h << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + int a = 0; + int b = 0; + for (int i = 0; i <= 1000000; i++) { + int temp = n - i * 4; + if (temp >= 0 && temp % 7 == 0) { + a = i; + b = temp / 7; + break; + } + } + if (a == 0 && b == 0) { + cout << -1 << endl; + } else { + for (int i = 0; i < a; i++) cout << "4"; + for (int i = 0; i < b; i++) cout << "7"; + cout << endl; + } + return 0; +} +int main() { + int a[3][3] = {1, 1, 1, 1, 1, 1, 1, 1, 1}, i, j, k, l, b[3][3]; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + cin >> b[i][j]; + if (b[i][j] % 2 == 1) { + if (a[i][j] == 1) + a[i][j] = 0; + else if (a[i][j] == 0) + a[i][j] = 1; + if (i < 2) { + if (a[i + 1][j] == 1) + a[i + 1][j] = 0; + else if (a[i + 1][j] == 0) + a[i + 1][j] = 1; + } + if (i > 0) { + if (a[i - 1][j]) + a[i - 1][j] = 0; + else if (a[i - 1][j] == 0) + a[i - 1][j] = 1; + } + if (j < 2) { + if (a[i][j + 1]) + a[i][j + 1] = 0; + else if (a[i][j + 1] == 0) + a[i][j + 1] = 1; + } + if (j > 0) { + if (a[i][j - 1]) + a[i][j - 1] = 0; + else if (a[i][j - 1] == 0) + a[i][j - 1] = 1; + } + } + } + } + for (k = 0; k < 3; k++) { + for (l = 0; l < 3; l++) { cout << a[k][l]; } + cout << endl; + } +} +int main() { + long long i = 0, res = 0; + string s1, s2; + cin >> s1 >> s2; + if (s1 == s2) + res = -1; + else + res = max(s1.size(), s2.size()); + cout << res << endl; + return 0; +} +const long long N = 1001 + 4; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long T, a, b, c, n, m, mx = MX, mn = MN, cnt; +string s, s1; +bool bl; +long long ar[N]; +pair pr[1001]; +vector v, d; +map mp; +set st; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { cin >> ar[i]; } + for (long long i = 2; i < n; i++) { + for (long long j = 2; j <= n; j++) { + if (i == j) { + c = ar[j + 1] - ar[j - 1]; + j++; + } else { + c = ar[j] - ar[j - 1]; + } + if (c > mx) { mx = c; } + } + if (mn > mx) { mn = mx; } + mx = MX; + } + cout << mn; + cout << "\n"; + return 0; +} +const int inf = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double pi = acos(-1.0); +const double eps = 1e-15; +long long n, k; +int main() { + cin >> n >> k; + long long x = n / (2 * (k + 1)); + cout << x << ' ' << k * x << ' ' << n - x - k * x << endl; +} +int main() { + int n, v; + cin >> n >> v; + int as[100]; + int cnt = 0; + for (int i = 0; i < n - 1; i++) { cin >> as[i]; } + sort(as, as + n - 1); + while (v <= *max_element(as, as + n - 1)) { + sort(as, as + n - 1); + as[n - 2]--; + cnt++; + v++; + } + cout << cnt << endl; +} +int n, k; +string s; +void solve() { + cin >> n >> k; + cin >> s; + sort((s).begin(), (s).end()); + char ch = s[0]; + int ans = s[0] - 'a' + 1; + k--; + for (int i = 1; i < s.length(); i++) { + if (k and s[i] - ch >= 2) ch = s[i], ans += s[i] - 'a' + 1, k--; + } + if (k) + cout << -1 << '\n'; + else + cout << ans << '\n'; +} +int main() { + int t = 1; + while (t--) { solve(); } + return 0; +} +int main() { + long int n; + cin >> n; + long int flag = 1; + long int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp == 1) flag = -1; + } + cout << flag << '\n'; + return 0; +} +int main() { + int n, k, i, l, Min = 100000; + int a[1000] = {0}; + cin >> n >> k; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + l = k % a[i]; + if (l == 0 && (k / a[i]) <= Min) { Min = k / a[i]; } + } + cout << Min << endl; + return 0; +} +const double pi = acos(-1); +const long long MODPRIMA = (long long)1e9 + 7; +const long long MAXX = (long long)1e18; +const long long MINN = -(long long)1e18; +const double EPS = 1e-9; +int N; +const long long MOD = 1e6 + 3; +long long ans; +int main() { + cin >> N; + ans = 1; + if (N == 0) + cout << 1 << '\n'; + else { + for (int i = 1; i <= N - 1; i++) { + ans *= 3; + ans %= MOD; + } + cout << ans << '\n'; + } + return 0; +} +int n, k; +char s[105]; +int main() { + cin >> n >> k; + int pos, tar; + for (int r = 1; r <= n; r++) { + cin >> s[r]; + if (s[r] == 'G') { pos = r; } + if (s[r] == 'T') { tar = r; } + } + if (tar < pos) { + while (pos > tar && pos > 0) { + pos -= k; + if (s[pos] == '#') { + cout << "NO" << endl; + return 0; + } + if (pos == tar) { + cout << "YES" << endl; + return 0; + } + if (pos < tar) { + cout << "NO" << endl; + return 0; + } + } + } + if (tar > pos) { + while (pos < tar && pos <= n) { + pos += k; + if (pos == tar) { + cout << "YES" << endl; + return 0; + } + if (pos > tar) { + cout << "NO" << endl; + return 0; + } + if (s[pos] == '#') { + cout << "NO" << endl; + return 0; + } + } + } + return 0; +} +int main() { + int n, i, j, x = 0, y = 0, z = 0; + cin >> n; + int a[n], b[n], c[n], d[n], t[3]; + for (i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == 1) { + b[x] = i; + x++; + } else if (a[i] == 2) { + c[y] = i; + y++; + } else { + d[z] = i; + z++; + } + } + t[0] = x; + t[1] = y; + t[2] = z; + sort(t, t + 3); + cout << t[0] << endl; + if (t[0] > 0) { + for (i = 0; i < t[0]; i++) { cout << b[i] << " " << c[i] << " " << d[i] << endl; } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int X, Y, a1[105], a2[105]; + set v; + cin >> X; + for (int i = 0; i < X; i++) { + cin >> a1[i]; + v.insert(a1[i]); + } + cin >> Y; + for (int i = 0; i < Y; i++) { + cin >> a2[i]; + v.insert(a2[i]); + } + if (v.size() == n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int hari[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int n, m; + cin >> n >> m; + int ans = 1; + int har = hari[n]; + har -= (7 - m + 1); + ans += (har / 7); + if (har % 7 != 0) { ans += 1; } + cout << ans << endl; +} +bool Is_here(char ch, string ans); +int main() { + string input; + cin >> input; + string ans = ""; + for (int i = 0; i < input.size(); i++) { + if (!Is_here(input[i], ans)) ans += input[i]; + } + if (ans.size() % 2 == 0) + cout << "CHAT WITH HER!\n"; + else + cout << "IGNORE HIM!\n"; + return 0; +} +bool Is_here(char ch, string ans) { + for (int i = 0; i < ans.size(); i++) { + if (ch == ans[i]) return 1; + } + return 0; +} +int main() { + int n, x, a1, b1, a2, b2, a3, b3; + cin >> n >> a1 >> b1 >> a2 >> b2 >> a3 >> b3; + n -= a1 + a2 + a3; + x = min(n, b1 - a1); + a1 += x; + n -= x; + x = min(n, b2 - a2); + cout << a1 << ' ' << a2 + x << ' ' << a3 + n - x << endl; + return 0; +} +int main() { + char card1[10]; + char card2[10]; + cin >> card1; + bool res = false; + for (int i = 1; i <= 5; i++) { + cin >> card2; + if (card1[0] == card2[0] || card1[1] == card2[1]) { res = true; } + } + if (res) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, l, r, a[200], x, y, ans = 0, z, w; +int main() { + cin >> n; + cin >> x >> y; + for (int i = 0; i < n - 1; i++) { + cin >> l >> r; + for (int j = l; j < r; j++) a[j] = 1; + } + for (int i = x; i < y; i++) { + if (!a[i]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, a = 0, b = 0; + string s, s2 = "0123456789"; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < s.length(); j++) { + for (int x = 0; x <= k; x++) { + if (s[j] == s2[x]) { + a++; + s2[x] = 'z'; + break; + } + } + } + if (a == (k + 1)) b++; + a = 0; + s2 = "0123456789"; + } + cout << b << "\n"; + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + while (h > 0) { + w = w + h; + if (h == d1) { w = w - u1; } + if (h == d2) { w = w - u2; } + h--; + if (w <= 0) w = 0; + } + cout << w << endl; + return 0; +} +int main() { + long long n, k, w, sum = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> w; + sum += (w - 1) / k + 1; + } + cout << (sum - 1) / 2 + 1 << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 1) + cout << 1 << endl; + else + cout << 2 << endl; + return 0; +} +int main() { + double a, b, c; + cin >> a >> b >> c; + int wait; + wait = ceil((a * c) / b) - c; + cout << wait << "\n"; + return 0; +} +int main() { + cout << 25 << endl; + return 0; +} +int main() { + int n, m, sum, t = 0; + cin >> n >> m; + if (n < m) + sum = n; + else if (n == m) + sum = n + 1; + else { + for (int i = 1; i <= n + t; i++) { + if (i % m == 0) t++; + } + sum = n + t; + } + cout << sum << endl; +} +int x[1001], n, m, p; +int main() { + cin >> n >> m; + while (m--) { + cin >> p; + ++x[p]; + } + sort(x + 1, x + n + 1); + cout << x[1] << endl; + return 0; +} +int main() { + int a; + cin >> a; + for (int i = sqrt(a); i >= 0; i--) + if (!(a % i)) return !(cout << i << ' ' << a / i << '\n'); +} +const int MD = 1000000009; +const int INF = 1e9 + 9; +const int N = 2e3 + 33; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2; i++) { + for (int j = 0; j < n; j++) { + if (abs(j - (n / 2)) < i) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + for (int i = n / 2; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (abs(j - (n / 2)) <= i) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int main() { + char s[30]; + int n, sum = 26; + cin >> s; + n = strlen(s); + sum = 26 * (n + 1) - n; + cout << sum << endl; + return 0; +} +int arr[105], ans = 0, vis[105]; +void dfs(int st, int ed, int k, int n) { + if (ans == 1) return; + if (st == ed) { + ans = 1; + return; + } + int now = st + k; + if (now >= 1 && now <= n && arr[now] == 0 && vis[now] == 0) { + vis[now] = 1; + dfs(now, ed, k, n); + vis[now] = 0; + } + now -= 2 * k; + if (now >= 1 && now <= n && arr[now] == 0 && vis[now] == 0) { + vis[now] = 1; + dfs(now, ed, k, n); + vis[now] = 0; + } +} +int main() { + int n, k, st, ed; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + char ch; + cin >> ch; + if (ch == '#') + arr[i] = 1; + else + arr[i] = 0; + if (ch == 'G') ed = i; + if (ch == 'T') st = i; + } + dfs(st, ed, k, n); + if (ans == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string a; + string b; + getline(cin, a); + getline(cin, b); + int x = 0; + for (int i = 0; i < a.length(); i++) { + if ((int)a[i] >= 65 && (int)a[i] <= 90) { a[i] = (char)((int)a[i] + 32); } + } + for (int i = 0; i < b.length(); i++) { + if ((int)b[i] >= 65 && (int)b[i] <= 90) { b[i] = (char)((int)b[i] + 32); } + } + for (int i = 0; i < a.length(); i++) { + if (a[i] > b[i]) { + cout << "1" << endl; + return 0; + } + if (a[i] < b[i]) { + cout << "-1" << endl; + return 0; + } + } + cout << "0" << endl; +} +int main() { + int n, k; + cin >> n >> k; + vector ex(n, 5); + int idx = n - 1; + while (1) { + int sum = 0; + for (int i = 0; i < n; i++) { sum += ex[i]; } + if (sum == k) break; + if (idx == -1) { idx = n - 1; } + ex[idx]--; + idx--; + } + int res = 0; + for (int(i) = 0; (i) < (n); (i)++) + if (ex[i] == 2) res++; + cout << res << endl; + return 0; +} +int main() { + long long a, b, c, d, e, n; + cin >> n; + n = n / 2; + n = n * 3; + cout << n << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i < 50; i++) { + n >>= 1; + if (n == 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + string x; + cin >> x; + int len = x.length(); + int y = 26 - len; + int ans = y * (len + 1) + len * len; + cout << ans << endl; + return 0; +} +int main() { + string a; + cin >> a; + int ans = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] == 'A') { + int lnum = 0, rnum = 0; + for (int j = 0; j < i; j++) { + if (a[j] == 'Q') { lnum++; } + } + for (int j = a.size() - 1; j > i; j--) { + if (a[j] == 'Q') { rnum++; } + } + ans += lnum * rnum; + } + } + cout << ans << endl; + return 0; +} +int s[1005]; +int main() { + string s; + while (cin >> s) { + int ls = s.length(); + int max1 = 0; + for (int i = 0; i < ls; i++) { + for (int j = i + 1; j < ls; j++) { + int m = 0; + while (s[i + m] == s[j + m]) { m++; } + max1 = max(m, max1); + } + } + cout << max1 << endl; + } + return 0; +} +int main() { + int n, i, sum = 0; + cin >> n; + string name; + for (i = 0; i < n; i++) { + cin >> name; + if (name == "Tetrahedron") + sum += 4; + else if (name == "Cube") + sum += 6; + else if (name == "Octahedron") + sum += 8; + else if (name == "Dodecahedron") + sum += 12; + else if (name == "Icosahedron") + sum += 20; + } + cout << sum << endl; + return 0; +} +int judge(char a[]) { + int x = strlen(a); + for (int i = 0; i < x; i++) { + if (a[i] - 48 == 0) { return 1; } + } + return 0; +} +int main() { + int n, t, sum = 0, ans = 0; + cin >> n >> t; + char a[1000]; + while (t--) { + cin >> a; + if (judge(a) == 1) { ans++; } + if (judge(a) == 0) { + sum = max(sum, ans); + ans = 0; + } + } + sum = max(sum, ans); + cout << sum << endl; +} +const int maxn = 3e2 + 10; +int arr[maxn], n, p, x; +int main() { + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> x; + x %= p; + if (arr[x]) return cout << i + 1 << endl, 0; + arr[x]++; + } + cout << -1 << endl; +} +const int maxn = 1005; +int main() { + int a[maxn]; + int i; + int j; + int n, k; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + int res = -1; + for (i = 0; i < k; i++) { + int k1 = 0; + int k2 = 0; + for (j = 0; j < n; j++) { + if ((j - i) % k == 0) { + continue; + } else { + if (a[j] == 1) k1++; + if (a[j] == -1) k2++; + } + } + res = max(res, abs(k1 - k2)); + } + cout << res << endl; + return 0; +} +int a[100002], b[100002]; +int s[100002]; +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int n1 = (k * l) / (nl); + int n2 = (c * d); + int n3 = p / (np); + int r = min(n1, n2); + r = min(r, n3); + cout << r / n << endl; + return 0; +} +int main() { + int n, m, min; + cin >> n >> m; + if (n < m) + min = n; + else + min = m; + if (min % 2 != 0) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; +} +int f(int x, int y) { + if (x == 0 || y == 0) + return 1; + else + return f(x - 1, y) + f(x, y - 1); +} +int main() { + int n; + cin >> n; + cout << f(n - 1, n - 1) << endl; + return 0; +} +int main() { + long long n, a, b, count; + cin >> n; + while (n--) { + cin >> a >> b; + count = 0; + while (1) { + if (a >= b && a > 0 && b > 0) { + count = count + a / b; + a = a % b; + } + if (b >= a && a > 0 && b > 0) { + count = count + b / a; + b = b % a; + } else + break; + } + cout << count << endl; + } + return 0; +} +const int MAXN = 10005; +int a[MAXN]; +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + memset(a, 0, sizeof(a)); + int sum = 0; + for (int i = n; i <= z; i += n) { a[i] = 1; } + for (int i = m; i <= z; i += m) { + if (a[i] == 1) sum++; + } + cout << sum << endl; + } + return 0; +} +char s[243554], zhu, xian; +int main() { + gets(s); + int len = strlen(s); + for (int i = 0; i < len; ++i) { + if (s[i] == 'o') + ++zhu; + else + ++xian; + } + if (zhu == 0) + puts("YES"); + else if (xian % zhu == 0) + puts("YES"); + else + puts("NO"); + return 0; +} +long long m, n, a, b; +int main() { + cin >> n >> m >> a >> b; + if (n % m == 0) + cout << 0 << '\n'; + else + cout << min(((m * (n / m + 1)) - n) * a, n % m * b) << '\n'; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int a; + if (n % s == 0) + a = n / s; + else + a = n / s + 1; + a = a * k; + int ans; + if (a % p == 0) + ans = a / p; + else + ans = a / p + 1; + cout << ans << endl; +} +queue q; +bool p[10000] = {}; +int pe; +void print(int c, int a, int b) { + if (a < c || a > b || p[a] || a > pe || a < 1) return; + p[a] = true; + print(c, a - 1, b); + q.push(a); + print(c, a + 1, b); +} +int main() { + int n, k; + cin >> pe >> n >> k; + if (n - k > 1) { cout << "<< "; } + print(n - k, n, n + k); + while (!q.empty()) { + if (q.size() != 1 && q.front() != n) + cout << q.front() << " "; + else if (q.front() == n) { + cout << "(" << q.front(); + if (q.size() != 1) { + cout << ") "; + } else + cout << ")"; + } else + cout << q.front(); + q.pop(); + } + if (n + k < pe) { cout << " >>"; } + cout << endl; +} +int main() { + int n, c = 0, x; + cin >> n; + int y = n; + if (n >= 100) { + x = n / 100; + c += x; + y = n % 100; + } + if (y >= 20) { + x = y / 20; + c += x; + y %= 20; + } + if (y >= 10) { + x = y / 10; + c += x; + y %= 10; + } + if (y >= 5) { + x = y / 5; + c += x; + y %= 5; + } + c += y; + cout << c << endl; +} +int main() { + int buttons, bulbs; + cin >> buttons >> bulbs; + bool marks[bulbs + 1]{false}; + while (buttons--) { + int connected, bulb_no; + cin >> connected; + for (int i = 0; i < connected; ++i) { + cin >> bulb_no; + marks[bulb_no] = true; + } + } + bool is_possible = true; + for (int i = 1; i <= bulbs; ++i) { + if (!marks[i]) { + is_possible = false; + break; + } + } + if (is_possible) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long a, b, c; +int main() { + cin >> a >> b >> c; + long long z = sqrt((b * c) / a); + long long x = c / z; + long long y = b / z; + cout << x * 4 + y * 4 + z * 4 << '\n'; + return 0; +} +int main() { + int n, m; + int table[51][51]; + cin >> n >> m; + int ans = 4; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> table[i][j]; + if (table[i][j]) { + if (i == 0 || j == 0 || i == n - 1 || j == m - 1) ans = 2; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int p, v1, v2, t1, t2; + while (cin >> p >> v1 >> v2 >> t1 >> t2) { + long long int ans1 = t1 * 2 + p * v1; + long long int ans2 = t2 * 2 + p * v2; + if (ans1 < ans2) + cout << "First" << endl; + else if (ans1 > ans2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int x, y, n, c; + cin >> x >> y; + n = x; + while (c != 2) { + n++; + c = 0; + for (int i = 1; i <= n; i++) { + if (n % i == 0) { c++; } + } + if (c == 2) break; + } + if (y == n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, n, i; + cin >> n; + int sum1 = 0, sum2 = 0; + bool k = false; + for (i = 0; i < n; i++) { + cin >> a >> b; + if (a % 2 + b % 2 == 1) { k = true; } + sum1 += a; + sum2 += b; + } + if (sum1 % 2 == 0 && sum2 % 2 == 0) { + cout << 0 << endl; + } else if (sum1 % 2 == 1 && sum2 % 2 == 1 && k == true) { + cout << 1 << endl; + } else { + cout << -1 << endl; + } +} +int pos[110]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + for (int j = a + 1; j <= b; j++) pos[j] = 1; + } + for (int i = 1; i <= m; i++) { + if (!pos[i]) return cout << "NO\n", 0; + } + return cout << "YES\n", 0; +} +int main() { + long long int a, b, c, d, e, f, g, h; + string s, t; + while (cin >> a) { + d = 0; + vector v; + for (b = 1; b <= a; b++) { + cin >> c; + d += c; + v.push_back(c); + } + c = 0; + if (d % 2 == 0) { + e = d / 2.; + } else { + e = d / 2.; + e++; + } + for (b = 0; b < a; b++) { + c += v[b]; + if (c >= e) { + cout << b + 1 << endl; + break; + } + } + v.clear(); + } + return 0; +} +int main() { + string firstLine; + getline(cin, firstLine); + char start = firstLine[0], end = firstLine[2]; + int n; + cin >> n; + int sum = start + end; + if (start == end || sum == 212 || sum == 122) { + cout << "undefined" << endl; + return 0; + } + n = n % 4; + int pos1, pos2; + if (start == '^') + pos1 = 0; + else if (start == '>') + pos1 = 1; + else if (start == 'v') + pos1 = 2; + else if (start == '<') + pos1 = 3; + if (end == '^') + pos2 = 0; + else if (end == '>') + pos2 = 1; + else if (end == 'v') + pos2 = 2; + else if (end == '<') + pos2 = 3; + if ((pos1 + n) % 4 == pos2) + cout << "cw" << endl; + else + cout << "ccw" << endl; + return 0; +} +int main() { + int n; + string s; + set se; + cin >> n; + while (n--) { + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + se.insert(s); + } + cout << se.size() << endl; + ; + return 0; +} +int main() { + int n; + cin >> n; + char s[n][n]; + for (int i = 0; i < n / 2 + 1; i++) { + for (int j = 0; j <= n / 2; j++) { + if (j >= n / 2 - i) + s[i][j] = 'D'; + else + s[i][j] = '*'; + } + } + for (int i = 0; i <= n / 2 + 1; i++) { + for (int j = n / 2 + 1; j < n; j++) { s[i][j] = s[i][n - j - 1]; } + } + for (int i = n / 2 + 1; i < n; i++) { + for (int j = 0; j < n; j++) { s[i][j] = s[n - i - 1][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cout << s[i][j]; } + cout << "\n"; + } + return 0; +} +int main() { + bool cmp(int a, int b); + int a[12], n, i, sum = 0; + cin >> n; + for (i = 0; i < 12; i++) cin >> a[i]; + sort(a, a + 12, cmp); + for (i = 0; i <= 12; i++) { + if (sum >= n) { + cout << i << endl; + return 0; + } + if (i < 12) sum += a[i]; + } + cout << -1 << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int ada[105][105]; +int main() { + int n; + cin >> n; + char arr[105][105]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> arr[i][j]; + if (arr[i][j] == 'C') { + ada[0][j] += 1; + ada[i][0] += 1; + } + } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + int x = ada[0][i]; + ans += ((x * (x - 1)) / 2); + x = ada[i][0]; + ans += ((x * (x - 1)) / 2); + } + cout << ans << endl; +} +int main() { + int n, i, n1; + cin >> n; + i = 10; + if (n <= 10) + n1 = 0; + else { + if (n <= 19) + n1 = 4; + else if (n == 20) { + n1 = 15; + } else if (n == 21) { + n1 = 4; + } else { + n1 = 0; + } + } + cout << n1 << endl; +} +int main() { + int n, k; + cin >> n >> k; + int cnt = 0, f = 0; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + cnt = 0; + for (int k = 0; k < s.length(); k++) { + if (s[k] == '4' || s[k] == '7') { cnt++; } + } + if (cnt <= k) { f++; } + } + cout << f << endl; +} +int main() { + long long n, rem = 0, rev = 0, c = 0; + cin >> n; + while (n != 0) { + rem = n % 10; + if (rem == 7 || rem == 4) { c++; } + n = n / 10; + } + if (c == 7 || c == 4) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + return 0; +} +int main() { + int n, x, y; + int p = 1; + cin >> n; + cin >> x; + cin >> y; + p = n * y; + if (p % 100 != 0) + p = p / 100 + 1; + else + p = p / 100; + if (p <= x) + cout << 0 << endl; + else + cout << p - x << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector welfare; + int welfare_input; + while (welfare.size() < n) { + cin >> welfare_input; + welfare.push_back(welfare_input); + } + sort(welfare.rbegin(), welfare.rend()); + int i = 1; + int total = 0; + while (welfare.size() > i) { + if (welfare[0] != welfare[i]) { + welfare[i]++; + total++; + } else { + i++; + } + } + cout << total << endl; + return 0; +} +int a, x; +bool ar[100005]; +int main() { + cin >> a; + for (int i = 0; i < a - 1; i++) { + cin >> x; + ar[x] = 1; + } + for (int i = 1; i <= a; i++) { + if (!ar[i]) { + cout << i << '\n'; + break; + } + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int lena = a.length(); + int lenb = b.length(); + string k = "zzzzzzzzzz"; + for (int i = 1; i <= lena; i++) { + for (int j = 1; j <= lenb; j++) { + string c = a.substr(0, i) + b.substr(0, j); + if (c < k) k = c; + } + } + cout << k << endl; +} +int main() { + int n, k; + int a[100005]; + while (cin >> n >> k) { + int i; + int pl = 0; + int sum = 1; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = k + 1; i <= n; i++) { + if (a[i] == a[i - 1]) { sum++; } + } + if (sum == n - k + 1) { + for (i = k - 1; i > 0; i--) { + if (a[i] != a[k]) { + pl = i; + break; + } + } + if (pl == 0) { + cout << "0" << endl; + } else { + cout << pl << endl; + } + } else { + cout << "-1" << endl; + } + } + return 0; +} +int w[100010]; +int main() { + int n, k; + while (cin >> n >> k) { + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> w[i]; + if (w[i] >= 2 * k) { + sum += w[i] / (2 * k); + w[i] = w[i] % (2 * k); + } + } + int count = 0; + for (int i = 0; i < n; i++) { + if (w[i] > k) { + sum++; + } else { + if (w[i] != 0) { count++; } + } + } + if (count % 2 == 0) { + sum += count / 2; + } else { + sum += (count - 1) / 2 + 1; + } + cout << sum << endl; + } + return 0; +} +int main() { + cout << "Karen" << '\n'; +} +ifstream in("txt.in"); +ofstream out("txt.out"); +int main() { + cout << fixed << setprecision(12); + long long mx = 2e9; + for (int i = 1; i <= 4; ++i) { + long long x; + cin >> x; + mx = min(mx, x); + } + long long a, b; + cin >> a >> b; + long long cnt = 0; + for (int i = a; i <= b; ++i) { cnt += (i < mx); } + cout << cnt << '\n'; + return 0; +} +int n, x; +int a[100]; +int main() { + cin >> n; + if (n == 1) { + cin >> x; + if (x == 15) { + cout << "DOWN" << endl; + return 0; + } + if (x == 0) { + cout << "UP" << endl; + return 0; + } + cout << -1 << endl; + return 0; + } + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (a[n] == 15) { + cout << "DOWN" << endl; + return 0; + } + if (a[n] == 0) { + cout << "UP" << endl; + return 0; + } + if (a[n] > a[n - 1]) { + cout << "UP" << endl; + return 0; + } + if (a[n] < a[n - 1]) { + cout << "DOWN" << endl; + return 0; + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long int a, b, c, d, e, f, g, h; + cin >> a >> b >> c >> d; + e = a / d; + f = e / b; + h = e % b; + cout << b * f + h + f * c << endl; + } + return 0; +} +int main() { + long long f, a, p = 0, g = 0, b = 0, o = 0, r = 0, y = 0; + string w; + cin >> a; + if (a == 0) { + cout << 6 << endl; + cout << "Power" << endl; + cout << "Time" << endl; + cout << "Space" << endl; + cout << "Soul" << endl; + cout << "Reality" << endl; + cout << "Mind" << endl; + } else { + cout << 6 - a << endl; + for (int i = 0; i < a; i++) { + string t; + cin >> t; + if (t[0] == 'r') { r = -10; } + if (t[0] == 'g') { g = -10; } + if (t[0] == 'b') { b = -10; } + if (t[0] == 'y') { y = -10; } + if (t[0] == 'o') { o = -10; } + if (t[0] == 'p') { p = -10; } + r++; + g++; + b++; + y++; + o++; + p++; + } + if (p == a) { cout << "Power" << endl; } + if (g == a) { cout << "Time" << endl; } + if (b == a) { cout << "Space" << endl; } + if (o == a) { cout << "Soul" << endl; } + if (r == a) { cout << "Reality" << endl; } + if (y == a) { cout << "Mind" << endl; } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n, greater()); + for (int i = 0; i < n; i++) { + if (m % arr[i] == 0) { + cout << m / arr[i] << endl; + break; + } + } +} +int main() { + long long n; + cin >> n; + while (n--) { + long long a, b, k; + cin >> a >> b >> k; + if (k % 2 == 0) { + cout << (a * (k / 2)) - (b * (k / 2)) << endl; + } else { + cout << (a * ((k + 1) / 2)) - (b * ((k - 1) / 2)) << endl; + } + } + return 0; +} +int main() { + long long int n; + cin >> n; + if (n == 0) cout << "O-|-OOOO\n"; + while (n > 0) { + if (n % 10 == 0) cout << "O-|-OOOO\n"; + if (n % 10 == 1) cout << "O-|O-OOO\n"; + if (n % 10 == 2) cout << "O-|OO-OO\n"; + if (n % 10 == 3) cout << "O-|OOO-O\n"; + if (n % 10 == 4) cout << "O-|OOOO-\n"; + if (n % 10 == 5) cout << "-O|-OOOO\n"; + if (n % 10 == 6) cout << "-O|O-OOO\n"; + if (n % 10 == 7) cout << "-O|OO-OO\n"; + if (n % 10 == 8) cout << "-O|OOO-O\n"; + if (n % 10 == 9) cout << "-O|OOOO-\n"; + n /= 10; + } + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int m[y]; + int arr[y]; + for (int i = 0; i < y; i++) { cin >> arr[i]; } + sort(arr, arr + y); + int k = 0; + for (int i = 0; i < y - x + 1; i++) { + m[k] = arr[x - 1 + i] - arr[i]; + k++; + } + int min = 99999; + for (int j = 0; j < k; j++) { + if (min > m[j]) min = m[j]; + } + cout << min << endl; + return 0; +} +int n, f[11] = {0, 1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620}; +inline int read() { + int x = 0, w = 1; + char c = getchar(); + while (c < '0' || c > '9') { + if (c == '-') w = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = x * 10 + c - '0'; + c = getchar(); + } + return x * w; +} +int main() { + n = read(); + cout << f[n] << endl; + return 0; +} +int ans; +int main() { + int n, m, z; + cin >> n >> m >> z; + int r = m; + while (m <= z) { + if (m % n == 0) ans++; + m += r; + } + cout << ans << "\n"; + return 0; +} +int main() { + string s1, s2; + while (cin >> s1 >> s2) { + cout << s1 << " " << s2 << endl; + int n = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + string kill, rep; + cin >> kill >> rep; + if (kill == s1) + s1 = rep; + else + s2 = rep; + cout << s1 << " " << s2 << endl; + } + } + return 0; +} +bool checkTriangle(const int index, const vector f) { + int tmp = index; + int i = 0; + while (i < 3) { + tmp = f[tmp] - 1; + i++; + } + return tmp == index; +} +int main() { + int n; + cin >> n; + vector f(n); + for (int i = 0; i < n; i++) { cin >> f[i]; } + for (int i = 0; i < n; i++) { + if (checkTriangle(i, f)) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int x; + int b = 0, c = 0; + for (int i = 0; i < n; ++i) { + cin >> x; + if (x < 0) { + b = b + x; + } else { + c = c + x; + } + } + cout << c - b << endl; + return 0; +} +char tab[8][8]; +int andaw(int r, int c) { + for (int i = r - 1; i >= 0; i--) + if (tab[i][c] != '.') return 0x3f3f3f3f; + return r; +} +int andab(int r, int c) { + for (int i = r + 1; i < 8; i++) + if (tab[i][c] != '.') return 0x3f3f3f3f; + return 7 - r; +} +int main() { + int t[8]; + memset(t, 0, 8); + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) cin >> tab[i][j]; + int miniw = 0x3f3f3f3f, minib = 0x3f3f3f3f; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (tab[i][j] == 'W') + miniw = min(miniw, andaw(i, j)); + else if (tab[i][j] == 'B') + minib = min(minib, andab(i, j)); + } + } + if (miniw == minib) + cout << "A\n"; + else + cout << (miniw < minib ? "A" : "B") << "\n"; + return 0; +} +int main() { + int n, t, a; + cin >> n >> t; + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> a; + t -= (86400 - a); + if (t <= 0) { + ans = i + 1; + break; + } + } + while (t > 0) { + t -= 86400; + ans++; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; ++i) cin >> a[i]; + int c = 0, max = a[0], min = a[0]; + for (int i = 1; i < n; ++i) { + if (a[i] > max) { + max = a[i]; + c++; + } + if (a[i] < min) { + min = a[i]; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, k, g, t; + cin >> n >> k; + bool flag = false; + char s[110]; + cin >> s; + for (int i = 0; i < n; ++i) + if (s[i] == 'G') + g = i; + else if (s[i] == 'T') + t = i; + if (g < t) + for (int i = g; i <= t; i += k) { + if (s[i] == '#') + break; + else if (s[i] == 'T') + flag = true; + } + else + for (int i = g; i >= t; i -= k) { + if (s[i] == '#') + break; + else if (s[i] == 'T') + flag = true; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + bool up = false, down = false; + for (int i = 0; i < a.size(); i++) { + if (a[i] <= 90) a[i] += 32; + if (b[i] <= 90) b[i] += 32; + } + for (int i = 0; i < a.size(); i++) { + if (a[i] > b[i]) { + down = true; + break; + } else if (a[i] < b[i]) { + up = true; + break; + } + } + if (up) + cout << -1 << endl; + else if (down) + cout << 1 << endl; + else + cout << 0 << endl; +} +const int maxn = 2e5 + 5; +long long a[maxn]; +long long b[maxn]; +int main() { + string str; + int n; + cin >> n; + cin >> str; + bool flag = true; + for (int i = 1; i < str.length(); i++) { + if (str[i - 1] != str[i]) { + cout << "YES" << endl; + flag = false; + cout << str[i - 1] << str[i] << endl; + break; + } + } + if (flag) cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int x = 0; + long ans = 0, length = 0; + if (s[0] == 'A') + x = 1; + else if (s[0] == 'C') + x = 2; + else if (s[0] == 'G') + x = 3; + else + x = 4; + for (long i = 0; s[i] != '\0'; i++) { + if (s[i] == 'A' && x == 1) { + length++; + } else if (s[i] == 'C' && x == 2) + length++; + else if (s[i] == 'G' && x == 3) + length++; + else if (s[i] == 'T' && x == 4) + length++; + else if (s[i] == 'A' && x == 0) { + length = 0; + length++; + x = 1; + } else if (s[i] == 'C' && x == 0) { + length = 0; + length++; + x = 2; + } else if (s[i] == 'G' && x == 0) { + length = 0; + length++; + x = 3; + } else if (s[i] == 'T' && x == 0) { + length = 0; + length++; + x = 4; + } else { + if (length % 2 == 0) ans++; + i--; + length = 0; + x = 0; + } + } + if (length % 2 == 0) ans++; + cout << ans << "\n"; + return 0; +} +const int N = 1e6 + 5; +int main() { + string s; + string t; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> t; + if (s[0] == t[0] or s[1] == t[1]) { + cout << "YES\n"; + exit(0); + } + } + cout << "NO\n"; + return 0; +} +string s; +vector v; +long long arr[int(1e6)]; +int main() { + long long T = 1, p = int(1e9 + 7), i, j; + cin >> T; + while (T--) { + long long n, k = 0, i, j, l, r; + cin >> l >> r >> n; + j = r / n; + if (n < l) { + cout << n << endl; + } else + cout << (j + 1) * n << endl; + } + return 0; +} +int a, b; +int main() { + cin >> a >> b; + vector v; + int ok = 1; + while (b > a) { + v.push_back(b); + if ((b & 1) == 0) { + b = b / 2; + } else if (b % 10 == 1) { + b = b / 10; + } else { + ok = 0; + break; + } + } + if (b != a) + ok = 0; + else + v.push_back(a); + if (!ok) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << v.size() << endl; + for (int i = v.size() - 1; i > 0; i--) cout << v[i] << " "; + cout << v[0] << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > b && x < c) { ans += 1; } + } + cout << ans << endl; +} +int main() { + long long a[3], k; + long long m[3] = {1, 1, 1}; + cin >> a[0] >> a[1] >> a[2] >> k; + sort(a, a + 3); + if (k >= a[0] + a[1] + a[2] - 3) { + cout << a[0] * a[1] * a[2] << endl; + return 0; + } + for (int i = 0; a[i] > 1 && k > 0; i = (i + 1) % 3) { + a[i]--; + k--; + m[i]++; + } + for (int i = 1; a[i] > 1 && k > 0; i = 2 - (i + 1) % 2) { + a[i]--; + k--; + m[i]++; + } + m[2] += min(a[2] - 1, k); + long long ans = m[0] * m[1] * m[2]; + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int num = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + int r = 0, t = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') { + r++; + } else if (s[j] == ')') { + r--; + } else { + r--; + t++; + } + if (r == 0) num++; + if (r < 0) { + if (t == 0) + break; + else { + r += 2; + t--; + } + } + } + } + cout << num << endl; +} +int main() { + int flag = 0; + long long ans; + long long res; + int a, b, c, n; + cin >> a >> b >> c >> n; + if (c > a || c > b) + flag = 1; + else { + res = a + b - c; + ans = n - res; + } + if (flag == 1) + cout << "-1" << endl; + else { + if (ans <= 0) + cout << "-1" << endl; + else + cout << ans << endl; + } + return 0; +} +int N; +int A; +int T; +int values[1001][1001]; +int pagamento[1001]; +int aguinha; +int strlen(char t[1001]) { + int ret = 0; + while (t[ret] != '\0') { ret++; } + return ret; +} +int maxfunc(int t1, int t2) { + int ret = t1; + if (t2 > t1) { ret = t2; } + return ret; +} +int minfunc(int t1, int t2) { + int ret = t1; + if (t2 < t1) { ret = t2; } + return ret; +} +int epar(int x) { + int ret = 0; + if ((x % 2) == 0) { ret = 1; } + return ret; +} +int atoifunc(char x) { + return x - '0'; +} +int main() { + int result = 0; + int size; + N = 0; + int N; + int A; + int T; + cin >> N >> A >> T; + aguinha = A * 2 + 1; + int njogos = 0; + int resta = N; + while (resta != 1) { + njogos += resta / 2; + if (epar(resta)) { + resta = (resta / 2); + } else { + resta = (resta / 2) + 1; + } + } + cout << njogos * aguinha << ' ' << N * T << endl; + return 0; +} +int main() { + int n, a[100000]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + cin >> a[i]; + while (a[i] % 2 == 0) { a[i] /= 2; } + while (a[i] % 3 == 0) { a[i] /= 3; } + } + int temp = a[0], isp = 1; + for (int k = 1; k < n; k++) { + if (a[k] != temp) { isp = 0; } + } + if (isp == 1) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + } + return 0; +} +const int INF = 0x3f3f3f3f; +long long gcd(long long a, long long b) { + if (!b) return a; + return gcd(b, a % b); +} +int main() { + long long i, j, k, l = 0; + long long n, m, s = 0; + cin >> n >> m; + if (n > m) { + k = gcd(n, m); + n /= k; + m /= k; + k = n * m; + j = k / n; + s = 0; + for (i = 1; i <= j; i++) s += i; + if (s == k - s) + cout << "Equal" << endl; + else { + if (k - s > s) + cout << "Masha" << endl; + else + cout << "Dasha" << endl; + } + } else { + k = gcd(m, n); + m /= k; + n /= k; + k = m * n; + j = k / m; + s = 0; + for (i = 1; i <= j; i++) s += i; + if (s == k - s) + cout << "Equal" << endl; + else { + if (k - s > s) + cout << "Dasha" << endl; + else + cout << "Masha" << endl; + } + } + return 0; +} +bool beat(char c, char d) { + if (c == 'R' && d == 'S' || c == 'S' && d == 'P' || c == 'P' && d == 'R') return true; + return false; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int m = a.size(), k = b.size(); + int as = 0, bs = 0; + for (int i = 0; i < m * k && i < n; i++) { + int tims = 1 + (n - i - 1) / (m * k); + if (beat(a[i % a.size()], b[i % b.size()])) bs += tims; + if (beat(b[i % b.size()], a[i % a.size()])) as += tims; + } + cout << as << ' ' << bs << endl; + return 0; +} +const int inf = 2147483647; +const int MAX = 1e5 + 10; +const int mod = 1e9 + 7; +int n, m, ans; +int h[MAX], book[MAX]; +void Init() { + ans = 0; + memset(book, 0, sizeof(book)); +} +int main() { + Init(); + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> h[i]; } + sort(h + 1, h + n + 1); + int a, b, c; + for (int i = 1; i <= m; i++) { + cin >> a >> b >> c; + if (a > 1) continue; + if (b == 1e9) { + ans++; + continue; + } + int temp = upper_bound(h + 1, h + n + 1, b) - h - 1; + while (book[temp]) temp--; + if (temp >= 0) book[temp] = 1; + } + for (int i = 1; i <= n; i++) { + if (book[i]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + long long t, w = 0; + cin >> t; + for (int i = 1; i <= t; i++) { + w = 0; + long long a, b, k; + cin >> a >> b >> k; + int s = a - b; + w += s * (k / 2); + if (k % 2 == 1) w += a; + cout << w << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int c = n / 3; + if (n % 3 == 2) { c += 1; } + cout << c / 12 << ' ' << c % 12 << endl; + return 0; +} +bool checkValidity(int a, int b, int c) { + if (a + b <= c || a + c <= b || b + c <= a) + return false; + else + return true; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + int counter = 100000; + for (int i = a; i <= 100; i++) { + for (int j = b; j <= 100; j++) { + for (int k = c; k <= 100; k++) { + if (checkValidity(i, j, k)) { + int temp = abs(i - a) + (j - b) + (k - c); + counter = min(counter, temp); + } + } + } + } + cout << counter << endl; + return 0; +} +int ar[1005][30]; +int main() { + int n, i, j, l, tm, res; + char store[1005][1005]; + set s; + cin >> n; + for (i = 0; i < n; i++) cin >> store[i]; + for (i = 0; i < n; i++) { + l = strlen(store[i]); + res = 0; + for (j = 0; j < l; j++) { res = res | 1 << (store[i][j] - 'a'); } + s.insert(res); + } + cout << s.size() << endl; + return 0; +} +int k, n, s, p; +int l; +int ans, num, sum; +int main() { + int i; + cin >> k >> n >> s >> p; + num = n / s; + l = n % s; + if (l != 0) num++; + sum = k * num; + ans = sum / p; + if (sum % p != 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n % 2) { + if (k > ((n - 1) / 2) + 1) { + k = k - ((n - 1) / 2) - 1; + k = 2 * k; + } else { + k = 2 * k - 1; + } + } else { + if (k > n / 2) { + k = k - (n / 2); + k = 2 * k; + } else { + k = 2 * k - 1; + } + } + cout << k << endl; + return 0; +} +int main() { + int n; + int ans = 0; + int a[5] = {100, 20, 10, 5, 1}; + cin >> n; + for (int i = 0; i < 5 && n; i++) { + ans += n / a[i]; + n -= a[i] * (n / a[i]); + } + cout << ans << endl; +} +int main() { + int i, n, k, a[100], b = 0; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + if (a[i] <= k) { + a[i] = 0; + b++; + } else + break; + } + for (i = n - 1; i >= 0 && a[i]; i--) { + if (a[i] <= k) { + a[i] = 0; + b++; + } else + break; + } + cout << b << endl; + return 0; +} +int abs(int x) { + if (x < 0) + return -x; + else + return x; +} +void qsort(int a[], int s, int t) { + int i, j, x; + x = a[(s + t) / 2]; + i = s - 1; + j = t + 1; + do { + do + i++; + while (a[i] < x); + do + j--; + while (a[j] > x); + if (i < j) { + int temp; + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + }; + } while (i <= j); + if (i < t) qsort(a, i, t); + if (s < j) qsort(a, s, j); +} +int main() { + int n, i; + int a[102]; + int ans1 = 0, ans2 = 0; + cin >> n; + for (i = 1; i <= n / 2; i++) cin >> a[i]; + qsort(a, 1, n / 2); + for (i = n / 2; i >= 1; i--) ans1 += abs(2 * i - a[i]); + for (i = n / 2; i >= 1; i--) ans2 += abs(2 * i - 1 - a[i]); + if (ans1 >= ans2) + cout << ans2 << endl; + else + cout << ans1 << endl; + return 0; +} +int main() { + int a, b, mi; + cin >> a >> b; + mi = min(a, b); + if (mi % 2) { + cout << "Akshat\n"; + } else { + cout << "Malvika\n"; + } + return 0; +} +int main() { + int l, h, b, a1, a2, a3; + cin >> a1 >> a2 >> a3; + l = sqrt((a2 * a3) / a1); + b = sqrt((a1 * a3) / a2); + h = sqrt((a2 * a1) / a3); + cout << 4 * (l + b + h) << endl; + return 0; +} +int main() { + char c; + string s = "qwertyuiopasdfghjkl;zxcvbnm,./"; + string x; + cin >> c; + if (c == 'R') { + cin >> x; + for (int i = 0; i < x.size(); i++) { + for (int j = 0; j < s.size(); j++) { + if (s[j] == x[i]) cout << s[j - 1]; + } + } + } else { + cin >> x; + for (int i = 0; i < x.size(); i++) { + for (int j = 0; j < s.size(); j++) { + if (s[j] == x[i]) cout << s[j + 1]; + } + } + } + cout << endl; +} +int main() { + int n, k; + cin >> n >> k; + int a, b; + int ans = 0; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + ans += b - a + 1; + } + int offset = ans % k; + int offset2 = k - offset; + if ((offset + ans) % k == 0 and (offset2 + ans) % k == 0) { + cout << min(offset, offset2) << '\n'; + } else if ((offset + ans) % k == 0) { + cout << offset << '\n'; + } else if ((offset2 + ans) % k == 0) { + cout << offset2 << '\n'; + } + return 0; +} +int main() { + int n, x1, x2, y1, y2, res = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> x1 >> y1 >> x2 >> y2; + res += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << res << endl; + return 0; +} +int main() { + int v1, t1, t2, v2, s; + cin >> s >> v1 >> v2 >> t1 >> t2; + int time1 = 0, time2 = 0; + time1 = v1 * s + 2 * t1; + time2 = v2 * s + 2 * t2; + if (time1 < time2) + cout << "First" << endl; + else if (time1 > time2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int n, a, b, ca = 0, cb = 0, cc = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a % 2 == 1 && b % 2 == 0) ca++; + if (b % 2 == 1 && a % 2 == 0) cb++; + if (a % 2 == 1 && b % 2 == 1) cc++; + } + if ((ca + cc) % 2 == 0 && (cb + cc) % 2 == 0) + cout << 0 << endl; + else if ((ca + cb + 2 * cc) % 2 == 0 && (ca != 0 || cb != 0)) + cout << 1 << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int n, i, j, c = 0; + cin >> n; + int a[n], b[n]; + for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (a[i] == b[j]) c++; + } + } + cout << c << endl; +} +int main() { + string s; + cin >> s; + string dic = "13579aeiou"; + int cont = 0; + for (int i = 0; i < s.size(); i++) { + if (dic.find(s[i]) != string::npos) { ++cont; } + } + cout << cont << endl; + return 0; +} +int main() { + int a[150], i, n; + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + if (a[i] % 2 == 0 && a[i + 1] % 2 != 0 && a[i + 2] % 2 == 0) { + cout << i + 1 << endl; + break; + } else if (a[i] % 2 != 0 && a[i + 1] % 2 == 0 && a[i + 2] % 2 != 0) { + cout << i + 1 << endl; + break; + } else if (a[i] % 2 != 0 && a[i + 1] % 2 == 0 && a[i + 2] % 2 == 0) { + cout << i << endl; + break; + } else if (a[i] % 2 == 0 && a[i + 1] % 2 != 0 && a[i + 2] % 2 != 0) { + cout << i << endl; + break; + } else if (a[i] % 2 == 0 && a[i + 1] % 2 == 0 && a[i + 2] % 2 != 0) { + cout << i + 2 << endl; + break; + } else if (a[i] % 2 != 0 && a[i + 1] % 2 != 0 && a[i + 2] % 2 == 0) { + cout << i + 2 << endl; + break; + } + } +} +int main() { + int n; + map p; + while (cin >> n) { + int a = 0, b, c; + for (int i = 0; i < n; i++) { + cin >> b; + p[b]++; + if (i == 0) { + a = b; + c = i + 1; + } else { + if (b < a) { + a = b; + c = i + 1; + } + } + } + if (p[a] == 1) + cout << c << endl; + else + cout << "Still Rozdil" << endl; + } + return 0; +} +int main() { + char a[3], b[3]; + cin >> a >> b; + int n; + cin >> n; + if (n % 2 == 0) { + cout << "undefined" << endl; + } else { + int oka = n % 4; + if (oka == 1) { + if (a[0] == '^') { + if (b[0] == '>') { + cout << "cw" << endl; + } else { + cout << "ccw" << endl; + } + } else if (a[0] == '>') { + if (b[0] == 'v') { + cout << "cw" << endl; + } else { + cout << "ccw" << endl; + } + } else if (a[0] == 'v') { + if (b[0] == '<') { + cout << "cw" << endl; + } else { + cout << "ccw" << endl; + } + } else if (a[0] == '<') { + if (b[0] == '^') { + cout << "cw" << endl; + } else { + cout << "ccw" << endl; + } + } + } else { + if (a[0] == '^') { + if (b[0] == '>') { + cout << "ccw" << endl; + } else { + cout << "cw" << endl; + } + } else if (a[0] == '>') { + if (b[0] == 'v') { + cout << "ccw" << endl; + } else { + cout << "cw" << endl; + } + } else if (a[0] == 'v') { + if (b[0] == '<') { + cout << "ccw" << endl; + } else { + cout << "cw" << endl; + } + } else if (a[0] == '<') { + if (b[0] == '^') { + cout << "ccw" << endl; + } else { + cout << "cw" << endl; + } + } + } + } + return 0; +} +int main() { + int ans = 0, len, num = 0; + string str; + cin >> len; + cin.get(); + getline(cin, str); + for (int i = 0; i < len; ++i) { + if (str[i] == ' ') { + if (num > ans) ans = num; + num = 0; + } else if (str[i] <= 'Z' && str[i] >= 'A') + ++num; + } + if (num > ans) ans = num; + cout << ans << endl; + return 0; +} +int main() { + int n, m, cnt = 0, tmp = -1, tmp1 = -1; + string s; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> s; + for (int j = 0; j < m; j++) { + if (s[j] == 'B') { + if (tmp < 0) { tmp = j + 1; } + if (tmp1 < 0) { tmp1 = i; } + cnt++; + } + } + if (cnt > 0) break; + } + cout << cnt / 2 + tmp1 << " " << cnt / 2 + tmp << endl; +} +int n, k, xx, ans; +int f(int x) { + int cnt = 0, flag = 0; + while (x != 0) { + flag = x % 10; + if (flag == 4 || flag == 7) cnt++; + x /= 10; + } + if (cnt <= k) + return 1; + else + return 0; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> xx; + ans += f(xx); + } + cout << ans << endl; + return 0; +} +int n; +int main() { + cin >> n; + int xmin = 1000000000, xmax = -1, ymin = 1000000000, ymax = -1; + int act = 0; + for (int i = 1; i <= n; i++) { + int a, b, c, d; + cin >> a >> b >> c >> d; + xmin = min(xmin, a); + xmin = min(xmin, c); + xmax = max(xmax, a); + xmax = max(xmax, c); + ymin = min(ymin, b); + ymin = min(ymin, d); + ymax = max(ymax, b); + ymax = max(ymax, d); + act += (abs(a - c) * abs(b - d)); + } + if (ymax - ymin == xmax - xmin && act == ((ymax - ymin) * (xmax - xmin))) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +map m1; +map::iterator itr; +vector vec[1000005]; +int main() { + long long int x, y, a, b; + cin >> x >> y >> a >> b; + long long int a1 = abs(x - a); + long long int a2 = abs(y - b); + long long int step = min(a1, a2); + long long int ans = step; + long long int maxy = max(a1, a2); + maxy = maxy - step; + ans += maxy; + cout << ans << endl; + return 0; +} +const int MAX = 100005; +int arr[MAX]; +int main() { + int n; + cin >> n; + int m; + for (int i = 0; i < n - 1; i++) { + cin >> m; + arr[m]++; + } + for (int i = 1; i <= n; i++) { + if (arr[i] == 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + string a; + cin >> a; + bool respuesta = false; + for (int i = 0; i < 5; i++) { + string aux; + cin >> aux; + if (aux[0] == a[0] || aux[1] == a[1]) respuesta = true; + } + if (respuesta) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string s, s1; + cin >> s >> s1; + string g = "zzzzzzzzzzz"; + int slen = s.length(); + int s1len = s1.length(); + for (int i = 1; i <= slen; i++) { + for (int j = 1; j <= s1len; j++) { + string k = s.substr(0, i) + s1.substr(0, j); + if (k < g) g = k; + } + } + cout << g << endl; + return 0; +} +int a[200005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int cnt = 0; + int j = 1; + int m = abs(a[0] - a[1]); + for (int i = 0; i < n - 1; i++, j++) { + if (m == abs(a[i] - a[j])) cnt++; + if (abs(a[i] - a[j]) < m) { + m = abs(a[i] - a[j]); + cnt = 1; + } + } + cout << m << " " << cnt << endl; + return 0; +} +int main() { + int x = 0; + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + cin >> x; + if (x == 1) { cout << abs(i - 3) + abs(j - 3) << endl; } + } + } + return 0; +} +int main() { + int a, b, p[4]; + for (int i = 0; i < 4; i++) cin >> p[i]; + cin >> a >> b; + sort(p, p + 4); + int x, cnt = 0; + for (int i = a; i <= b; i++) { + int match = 0; + do { + x = i; + for (int i = 0; i < 4; i++) x %= p[i]; + if (x == i) match++; + } while (next_permutation(p, p + 4)); + if (match >= 7) cnt++; + } + cout << cnt << '\n'; + return 0; +} +const int pi = acos(-1); +int main() { + int n; + cin >> n; + int a[200], k = 1, ele = 0, flag = 0; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + for (int i = 1; i <= n; ++i) { ele += (4 * i - 4) * a[i]; } + cout << ele << endl; +} +int main() { + int n; + cin >> n; + cout << (n & 1 ? "contest\n" : "home\n"); + return 0; +} +int main() { + int m, a, b, tot = 0, sum = 0; + cin >> m; + while (m--) { + cin >> a >> b; + if (a > b) { + tot++; + } else if (a < b) { + sum++; + } + } + if (sum > tot) { + cout << "Chris" << endl; + } else if (tot > sum) { + cout << "Mishka" << endl; + } else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n, k, a[1000]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + char arr[n][n]; + for (int i = 0; i <= n / 2; i++) { + for (int k = 0; k < n; k++) arr[i][k] = '*'; + for (int j = n / 2 - i; j <= n / 2 + i; j++) arr[i][j] = 'D'; + } + for (int i = 0; i <= n / 2; i++) { + for (int j = 0; j < n; j++) cout << arr[i][j]; + cout << "\n"; + } + for (int i = n / 2 - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) cout << arr[i][j]; + cout << "\n"; + } + return 0; +} +const int N = 1e5 + 5; +const int M = 1e6 + 3; +int ara[N]; +int rec(int n) { + if (n < 2) return 1; + return (3 * rec(n - 1)) % M; +} +int main() { + int n; + cin >> n; + cout << rec(n) << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + long long int ans = 0; + vector v; + string s; + int i, j; + for (i = 0; i < n; i++) { + cin >> s; + v.push_back(s); + } + for (i = 0; i < n; i++) { + int count = 0; + for (j = 0; j < n; j++) + if (v[i][j] == 'C') count++; + if (count > 0) ans += (count * (count - 1)) / 2; + } + for (i = 0; i < n; i++) { + int count = 0; + for (j = 0; j < n; j++) + if (v[j][i] == 'C') count++; + if (count > 0) ans += (count * (count - 1)) / 2; + } + cout << ans << endl; +} +int main() { + string s; + cin >> s; + int ans; + bool yay = true; + for (int i = 0; i < s.size();) { + if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { + i = i + 3; + } else if (s[i] == '1' && s[i + 1] == '4') { + i = i + 2; + } else if (s[i] == '1') { + i++; + } else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + vector v; + for (int i = 0; i < n; i++) { + cin >> s; + sort(s.begin(), s.end()); + int num = s.size(); + string ss; + for (int j = 0; j < num; j++) { + ss.push_back(s[j]); + while (s[j] == s[j + 1]) j++; + } + if (find(v.begin(), v.end(), ss) == v.end()) { v.push_back(ss); } + } + cout << v.size() << endl; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + int cnt = 0; + for (int j = x; j != 0; j /= 10) { cnt += j % 10 == 4 || j % 10 == 7; } + ans += cnt <= k; + } + cout << ans << '\n'; + return 0; +} +int R, C; +string board[100]; +int ans; +int main() { + cin >> R >> C; + for (int i = 0; i < R; ++i) cin >> board[i]; + for (int i = 0; i + 1 < R; ++i) + for (int j = 0; j + 1 < C; ++j) { + string s = "####"; + s[0] = board[i][j]; + s[1] = board[i + 1][j]; + s[2] = board[i][j + 1]; + s[3] = board[i + 1][j + 1]; + sort(s.begin(), s.end()); + if (s == "acef") ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, cnt = 0; + int s[10]; + cin >> n >> k; + int j, p; + for (int i = 0; i < n; i++) { + int a; + memset(s, 0, sizeof(s)); + cin >> a; + while (a > 0) { + p = a % 10; + if (p <= k) { s[p] = 1; } + a = a / 10; + } + for (j = 0; j <= k; j++) { + if (s[j] == 0) break; + } + if (j > k) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int r[110], c[110], m[110][110]; + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + memset(m, 0, sizeof(m)); + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> m[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { r[i] = r[i] + m[i][j]; } + } + for (int j = 0; j < n; j++) { + for (int i = 0; i < n; i++) { c[j] = c[j] + m[i][j]; } + } + int num = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) + if (c[i] > r[j]) num++; + } + cout << num << endl; +} +string s; +int main() { + cin >> s; + int a = 0, b = 0; + for (int i = 0; i < s.length(); i++) + if (islower(s[i])) + a++; + else + b++; + if (a >= b) + transform(s.begin(), s.end(), s.begin(), ::tolower); + else + transform(s.begin(), s.end(), s.begin(), ::toupper); + cout << s << endl; + return 0; +} +int main() { + map m; + m['p'] = 0; + m['g'] = 0; + m['b'] = 0; + m['o'] = 0; + m['r'] = 0; + m['y'] = 0; + int n; + cin >> n; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + m[s[0]] = 1; + } + cout << 6 - n << endl; + if (m['p'] == 0) { cout << "Power" << endl; } + if (m['g'] == 0) { cout << "Time" << endl; } + if (m['b'] == 0) { cout << "Space" << endl; } + if (m['o'] == 0) { cout << "Soul" << endl; } + if (m['r'] == 0) { cout << "Reality" << endl; } + if (m['y'] == 0) { cout << "Mind" << endl; } + return 0; +} +int main() { + string s; + cin >> s; + int pos; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '.') { + pos = i; + if (s[i - 1] == '9') { + puts("GOTO Vasilisa."); + return 0; + } + break; + } + } + if (s[pos + 1] >= '5') s[pos - 1]++; + s = s.substr(0, pos); + cout << s << endl; + return 0; +} +int main() { + string S1, S2, A[10]; + getline(cin, S1); + for (int i = 0; i < 10; i++) getline(cin, A[i]); + for (int i = 0; i < 8; i++) { + S2 = S1.substr(0, 10); + for (int j = 0; j < 10; j++) + if (S2 == A[j]) cout << j; + S1.erase(0, 10); + } + cout << endl; + return 0; +} +int main() { + int a, b, c, d, h, ans; + while (cin >> a >> b >> c >> d) { + int con; + if ((float)b / c - (int)b / c > 0) + con = 1; + else + con = 0; + h = b / c + con; + h *= a; + if ((float)h / d - (int)h / d > 0) + con = 1; + else + con = 0; + ans = h / d + con; + cout << ans << endl; + } +} +int main() { + int n, d; + cin >> n >> d; + char c; + int ans = 0, tmp = 0; + bool flag; + for (int i = 0; i < int(d); i++) { + flag = false; + for (int j = 0; j < int(n); j++) { + cin >> c; + if (c == '0') flag = true; + } + if (flag) + tmp++; + else { + ans = max(ans, tmp); + tmp = 0; + } + } + ans = max(ans, tmp); + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + long long limit = ((n + k - 1) / k - 1) * t; + if (d < limit) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int a[105]; +int n, m, k, maxn = INT_MIN, l = 0, r = 0, x, y; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == -1) + l++; + else + r++; + } + for (int i = 1; i <= m; i++) { + x = 0, y = 0; + for (int j = i; j <= n; j += m) + if (a[j] == -1) + x++; + else + y++; + maxn = max(maxn, abs(l - x - r + y)); + } + cout << maxn << endl; + return 0; +} +int main() { + long long p, cnt = 0; + cin >> p; + for (long long i = 1; i < p; i++) { + long long j = 1; + bool isRoot = true; + for (long long k = 1; k < p - 1; k++) { + j *= i; + j %= p; + if (j == 1) { + isRoot = false; + break; + } + } + if (isRoot) { + j *= i; + j %= p; + if (j == 1) cnt++; + } + } + cout << cnt << endl; +} +int main() { + int n, k; + int maxn = -0x3f3f3f3f; + cin >> n >> k; + int f, t; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) + maxn = max(maxn, f - (t - k)); + else + maxn = max(maxn, f); + } + cout << maxn << endl; + return 0; +} +int n, k; +int main() { + cin >> n >> k; + long long ans = 0, t; + for (int _x = 0; _x < n; _x++) { + cin >> t; + ans += t / k + (t % k != 0); + } + cout << ans / 2 + (ans % 2 != 0) << endl; + return 0; +} +int main() { + int n, v[10], r, p; + v[0] = 2; + v[1] = 7; + v[2] = 2; + v[3] = 3; + v[4] = 3; + v[5] = 4; + v[6] = 2; + v[7] = 5; + v[8] = 1; + v[9] = 2; + cin >> n; + r = n % 10; + n = n / 10; + p = v[r] * v[n]; + cout << p << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + int s1 = t1 * 2 + s * v1, s2 = t2 * 2 + s * v2; + if (s1 < s2) cout << "First" << endl; + if (s1 > s2) cout << "Second" << endl; + if (s1 == s2) cout << "Friendship" << endl; + return 0; +} +string alter(string x) { + string y = ""; + int idx = 0; + while (idx < x.size() && (x[idx] - '0') % 2 == 0) idx++; + for (int i = idx; i < x.size(); ++i) { + int dig = (x[i] - '0') % 2; + char c = dig + '0'; + y = y + c; + } + return y; +} +int main() { + int t; + cin >> t; + char c; + string x; + map cnt; + while (t--) { + cin >> c >> x; + int idx = 0; + x = alter(x); + if (c == '+') { + if (cnt.find(x) != cnt.end()) { + cnt[x]++; + } else { + cnt.insert({x, 1}); + } + } else if (c == '-') { + if (cnt.find(x) == cnt.end()) { + continue; + } else { + cnt[x]--; + } + } else { + cout << cnt[x] << "\n"; + } + } + return 0; +} +const int N = 100100; +const long long MOD = 1000 * 1000 * 1000LL + 9; +long long dp[N]; +int main() { + long long n, m, ans(1); + cin >> n >> m; + if (m <= 20 && (1 << m) <= n) { + cout << 0 << endl; + return 0; + } + for (int i = 0; i < m; i++) ans = (ans * 2) % MOD; + dp[0] = (ans - 1 + MOD) % MOD; + for (long long i = 1; i < n; i++) dp[i] = dp[i - 1] * (ans - i - 1 + MOD) % MOD; + cout << dp[n - 1] << endl; + return 0; +} +const int oo = 1e9; +int main() { + int n; + cin >> n; + int g = 0, mx = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + g = __gcd(g, x); + mx = max(mx, x); + } + cout << ((mx / g - n) % 2 ? "Alice" : "Bob") << '\n'; + return 0; +} +int main() { + int n, foot, inch, x; + cin >> n; + foot = n / 36; + x = n % 36; + if (x == 35) { + foot++; + inch = 0; + cout << foot << ' ' << inch << endl; + } else { + inch = x / 3; + if (x % 3 == 2) inch++; + cout << foot << ' ' << inch << endl; + } + return 0; +} +int main() { + int n, x, count = 0; + cin >> n >> x; + if (x == 1) { + cout << 1 << endl; + return 0; + } + for (int i = 2; i <= n; i++) { + if (x % i == 0 && x / i <= n) count++; + } + cout << (x <= n ? count + 1 : count) << endl; + return 0; +} +int main() { + int m, n, count = 0, a1 = 0, a2 = 0, b1 = 0, b2 = 0; + cin >> n >> m; + vector s(n); + for (int i = 0; i < n; i++) { cin >> s[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] == 'B') { + count++; + if (count <= 1) { + a1 = i + 1; + b1 = j + 1; + } + a2 = i + 1; + b2 = j + 1; + } + } + } + cout << (a2 + a1) / 2 << " " << (b2 + b1) / 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int a[6][3] = {1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1, 0, 1, 2}; + int n; + short int x; + cin >> n; + cin >> x; + n--; + short int res = n % 6; + cout << a[res][x] << endl; + return 0; +} +const long long mod = 1000000007; +long long k; +long long c[10010]; +long long tol; +long long cal[1010][1010]; +void get() { + cal[1][1] = 1; + for (int i = 2; i <= tol + 1; i++) { + for (int j = 1; j <= i; j++) { + if (j == 1) { + cal[i][j] = 1; + } else if (j == i) { + cal[i][j] = 1; + } else { + cal[i][j] = cal[i - 1][j - 1] + cal[i - 1][j]; + cal[i][j] %= mod; + } + } + } +} +int main() { + cin >> k; + tol = 0; + for (int i = 1; i <= k; i++) { + cin >> c[i]; + tol += c[i]; + } + get(); + long long ans = 1; + for (int i = k; i >= 1; i--) { + ans = (ans * cal[tol][c[i]]) % mod; + tol -= c[i]; + } + cout << ans << endl; + return 0; +} +int main() { + string n, s = ""; + int i, c, j; + cin >> n; + for (i = n.size() - 1; i >= 0; i--) { + s = ""; + c = n[i] - '0'; + if (c < 5) + s += "O-|"; + else { + s += "-O|"; + c -= 5; + } + for (j = 1; j <= c; j++) s += 'O'; + s += '-'; + for (j = c; j < 4; j++) s += 'O'; + cout << s << "\n"; + } + return 0; +} +void solve() { + int n, p; + cin >> n >> p; + long double ans = 0; + int cnt = 0; + vector v; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + v.push_back(s); + } + reverse(v.begin(), v.end()); + for (int i = 0; i < n; i++) { + if (v[i] == "halfplus") { + ans += 0.5; + ans *= 2; + cnt++; + } else { + ans *= 2; + } + } + cout << (long long)(ans)*p - cnt * (p / 2) << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int flag = 0, i = 2, x = 1; + while (flag <= n) { + flag += x; + x += i; + i++; + if (flag <= n) count++; + } + cout << count << endl; + return 0; +} +int a[601]; +int main() { + int n, k = 0, x, max = 0, ans = 0; + cin >> n; + while (k < n) { + cin >> x; + a[x] = 1; + if (x > max) max = x; + k = k + 1; + } + k = 1; + while (k <= max) { + if (a[k] == 1) ans = ans + 1; + k = k + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d, x, y, cnt; + while (cin >> a >> b >> c >> d >> x >> y) { + cnt = 0; + for (int i = x; i <= y; i++) + if (i % a % b % c % d == i) cnt++; + cout << cnt << endl; + } + return 0; +} +long long a, b, lcm; +long long LCM(long long a, long long b) { + return (a * b) / __gcd(a, b); +} +int main() { + cin >> a >> b; + lcm = LCM(a, b); + if (a < b) + a = lcm / a - 1, b = lcm / b; + else + a = lcm / a, b = lcm / b - 1; + if (a > b) + cout << "Dasha" << endl; + else if (a < b) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + return 0; +} +string a; +int s, num, p[1001]; +int main() { + cin >> a >> s; + if (a.size() < s) { + cout << "impossible" << endl; + return 0; + } + for (int i = 0; i < a.size(); i++) { + if (!p[a[i]]) num++; + p[a[i]] = 1; + } + cout << max(0, s - num) << endl; + return 0; +} +int main() { + long long n, k, red, green, blue, notebooks; + cin >> n >> k; + red = 2 * n; + green = 5 * n; + blue = 8 * n; + notebooks = (red / k) + (green / k) + (blue / k); + if (red % k != 0) { notebooks += 1; } + if (green % k != 0) { notebooks += 1; } + if (blue % k != 0) { notebooks += 1; } + cout << notebooks << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int dot_at = 1; + for (int i = 0; i < len; i++) { + if (s[i] == '.') dot_at = i; + } + if (s[dot_at - 1] == '9') { + cout << "GOTO Vasilisa.\n"; + return 0; + } + int carry = 0; + int i = dot_at + 1; + if (s[dot_at + 1] - '0' >= 5) carry = 1; + string ans = ""; + for (int i = dot_at - 1; i >= 0; i--) { + if (s[i] - '0' < 9) { + if (carry) { + ans += (s[i] + 1); + carry--; + } else + ans += s[i]; + } + if (s[i] - '0' == 9) { + if (carry) { + ans += '0'; + } else + ans += s[i]; + } + } + if (s[0] - '0' == 9) { + if (carry) ans += '1'; + } + reverse(ans.begin(), ans.end()); + cout << ans << "\n"; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int pref[n], suff[n]; + for (int i = 0; i < n; i++) { + if (s[i] == 'Q') { + pref[i] = 1; + suff[i] = 1; + } else { + pref[i] = 0; + suff[i] = 0; + } + } + for (int i = 1; i < n; i++) { pref[i] += pref[i - 1]; } + for (int i = n - 2; i >= 0; i--) { suff[i] += suff[i + 1]; } + long ans = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { ans += pref[i] * suff[i]; } + } + cout << ans << endl; +} +int main() { + string s; + long long n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + if (s.size() <= 10) { + cout << s << endl; + } else { + cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl; + } + } +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int g, t; + for (int i = 0; i < n; i++) { + if (s[i] == 'G') g = i; + if (s[i] == 'T') t = i; + } + if (g > t) swap(g, t); + if ((t - g) % k) { + cout << "NO" << endl; + exit(0); + } + for (int i = g; i != t; i += k) + if (s[i] == '#') { + cout << "NO" << endl; + exit(0); + } + cout << "YES" << endl; +} +int main() { + int n, p, v, t, count = 0; + cin >> n; + while (n--) { + cin >> p >> v >> t; + if (p == 1 && v == 1 || p == 1 && t == 1 || v == 1 && t == 1) { count++; } + } + cout << count << endl; + return 0; +} +long long n, k, s, p; +int main() { + cin >> n; + cout << n / 2 + 1 << '\n'; +} +void solve() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + set s; + int ans = 2; + if (n == 1) { + cout << ans << endl; + return; + } + for (int i = 0; i < n; i++) { + if (i == 0) { + if (k <= a[i + 1] - (a[i] + k)) s.insert(a[i] + k); + } else if (i == n - 1) { + if ((a[i] - k) - a[i - 1] >= k) s.insert(a[i] - k); + } else { + if (k <= a[i] - k - a[i - 1]) s.insert(a[i] - k); + if (k <= a[i + 1] - (a[i] + k)) s.insert(a[i] + k); + } + } + cout << ans + s.size() << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int x2 = abs(x) + abs(y); + if (x > 0 && y > 0) + cout << 0 << " " << x2 << " " << x2 << " 0" << endl; + else if (x > 0 && y < 0) + cout << 0 << " " << -x2 << " " << x2 << " " << 0 << endl; + else if (x < 0 && y > 0) + cout << -x2 << " " << 0 << " " << 0 << " " << x2 << endl; + else + cout << -x2 << " " << 0 << " " << 0 << " " << -x2 << endl; +} +int main() { + int n, k; + int i; + int s[105]; + int num1 = 0, num2 = 0; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> s[i]; + for (i = 0; i < n; i++) { + if (s[i] <= k) + num1++; + else + break; + } + if (i == n) + cout << num1 << endl; + else { + for (i = n - 1; i >= 0; i--) { + if (s[i] <= k) + num2++; + else + break; + } + cout << num1 + num2 << endl; + } + return 0; +} +int main() { + int n, t, k, d, r; + cin >> n >> t >> k >> d; + if ((n - k) % k == 0) + r = (n - k) / k; + else + r = ((n - k) / k) + 1; + if (r == 0 || n < k) + cout << "NO" << endl; + else if (r == 1) { + if (t > d) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + if (r * t > d) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + string str[12]; + int n, i, j, ck; + cin >> n >> str[0]; + str[1] = "vaporeon"; + str[2] = "jolteon"; + str[3] = "flareon"; + str[4] = "espeon"; + str[5] = "umbreon"; + str[6] = "leafeon"; + str[7] = "glaceon"; + str[8] = "sylveon"; + for (i = 1; i <= 8; i++) { + if (str[i].size() == n) { + ck = 1; + for (j = 0; j < n; j++) { + if (str[0][j] >= 'a' && str[0][j] <= 'z') { + if (str[0][j] != str[i][j]) { + ck = 0; + break; + } + } + } + if (ck == 1) { + cout << str[i] << endl; + return 0; + } + } + } + cout << endl; + return 0; +} +int main() { + long long int n, k, x, a[1000], sum = 0; + cin >> n >> k >> x; + long long int p = n - k; + for (long long int i = 1; i <= n; i++) { + cin >> a[i]; + if (i <= p) sum = sum + a[i]; + } + sum = sum + (k * x); + cout << sum << endl; +} +int f[1000]; +int find(int x) { + if (f[x] == x) + return x; + else + return find(f[x]); +} +void unionn(int a, int b) { + int x = find(a); + int y = find(b); + if (x != y) f[x] = y; +} +int main() { + int t; + int n, m, k, x, y; + int s[1000], num[1000]; + while (cin >> n >> m >> k) { + memset(num, 0, sizeof(num)); + for (int i = 1; i <= n; i++) f[i] = i; + for (int i = 1; i <= k; i++) cin >> s[i]; + for (int i = 0; i < m; i++) { + cin >> x >> y; + unionn(x, y); + } + for (int i = 1; i <= n; i++) num[find(i)]++; + int Max = 0, sum = 0, ss = n; + for (int i = 1; i <= k; i++) { + num[s[i]] = num[find(s[i])]; + Max = max(Max, num[s[i]]); + ss -= num[s[i]]; + sum += (num[s[i]]) * (num[s[i]] - 1) / 2; + } + sum += (ss + Max) * (ss + Max - 1) / 2; + sum -= Max * (Max - 1) / 2 + m; + cout << sum << endl; + } + return 0; +} +int main() { + int a[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n; + cin >> n; + int digit1 = n % 10; + int val = n / 10; + cout << a[digit1] * a[val]; + putchar('\n'); + return 0; +} +long long _sieve_size; +bitset<10000010> bs; +vector primes; +void sieve(long long upperbound) { + _sieve_size = upperbound + 1; + bs.reset(); + bs.flip(); + bs.set(0, false); + bs.set(1, false); + for (long long i = 2; i <= _sieve_size; i++) + if (bs.test((size_t)i)) { + for (long long j = i * i; j <= _sieve_size; j += i) bs.set((size_t)j, false); + primes.push_back((int)i); + } +} +int main() { + sieve(100000); + int n, m; + cin >> n >> m; + for (int i = 0; i < primes.size() - 1; i++) { + if (n == primes[i]) { + if (m == primes[i + 1]) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + break; + } + } + return 0; +} +int main() { + double p, q, lal, sobuj, nil; + cin >> p >> q; + lal = ceil((p * 2) / q); + sobuj = ceil((p * 5) / q); + nil = ceil((p * 8) / q); + int mot = lal + sobuj + nil; + cout << mot << endl; +} +string a; +int b[100]; +int main() { + int i; + int t = 0; + int sum = 0; + getline(cin, a); + for (i = 0; i < a.length(); i++) { + if (a[i] == 'Q') { + t++; + } else if (a[i] == 'A') { + b[i] = t; + } + } + for (i = 0; i < a.length(); i++) { + if (b[i] > 0) { sum += b[i] * (t - b[i]); } + } + cout << sum << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + int n; + cin >> n; + string s; + cin >> s; + bool k = true; + for (int i = 0; i < n / 2; i++) { + int diff = abs((int)s[i] - (int)s[n - i - 1]); + if (diff != 0 && diff != 2) k = false; + } + cout << ((k == true) ? "YES" : "NO") << "\n"; + } + return 0; +} +int main() { + int n, a, p; + int price = 10000; + int money = 0; + cin >> n; + while (n--) { + cin >> a >> p; + if (price > p) price = p; + money += price * a; + } + cout << money << endl; + return 0; +} +int dfs(int i, int a[], int n, int t) { + if (i == t) return 1; + if (i > t) + return -1; + else + dfs(i + a[i], a, n, t); +} +int main() { + int n, t; + cin >> n >> t; + int a[n + 1]; + for (int i = 1; i < n; i++) { cin >> a[i]; } + if (dfs(1, a, n, t) == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + if (b[0] == b[1]) { + cout << "Still Rozdil" << endl; + } else { + for (int i = 0; i < n; i++) { + if (a[i] == b[0]) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int main() { + long long x; + cin >> x; + int answer = 0; + while (x > 0) { + x = x & (x - 1); + answer++; + } + cout << answer << endl; + return 0; +} +int main() { + int n, a, b, c = -1, d = -1, co = 0, m = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a == c && b == d) { + co++; + m = max(m, co); + } else + co = 1; + c = a; + d = b; + } + if (m == 0) + cout << 1 << endl; + else + cout << m << endl; + return 0; +} +double size_n, size_x, size_y; +double result; +int main() { + double man, have_now; + cin >> size_n >> size_x >> size_y; + man = size_n * 0.01; + have_now = size_x / man; + if (have_now < size_y) { + result = (size_y - have_now) * man; + if (double(int(result)) != result) result += 1; + } else + result = 0; + cout << int(result) << endl; + return 0; +} +int main() { + long long xa, ya, xb, yb, xc, yc; + cin >> xa >> ya >> xb >> yb >> xc >> yc; + long long cp = (xb - xa) * (yc - ya) - (yb - ya) * (xc - xa); + if (cp > 0) + cout << "LEFT\n"; + else if (cp < 0) + cout << "RIGHT\n"; + else + cout << "TOWARDS\n"; + return 0; +} +int a[11][101], b[11][101], c[11][101], d[101], e[101]; +int x, y; +int n, m, kkk, maxn; +bool cmp(int x, int y) { + return d[x] > d[y]; +} +int main() { + cin >> n >> m >> kkk; + for (int i = 0; i < n; i++) { + string cc; + cin >> cc; + for (int j = 0; j < m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j]; + } + for (int i = 0; i < n; i++) { + int ans; + for (int j = 0; j < n; j++) { + ans = 0; + if (i != j) { + memset(d, 0, sizeof(d)); + for (int k = 0; k < m; k++) e[k] = k; + for (int k = 0; k < m; k++) { d[k] = b[j][k] - a[i][k]; } + sort(e, e + m, cmp); + int kk = kkk; + int p; + p = 0; + while ((p < m) && (kk > 0)) { + if (d[e[p]] <= 0) { + kk = 0; + break; + } + if (c[i][e[p]] <= kk) { + ans = ans + c[i][e[p]] * d[e[p]]; + kk = kk - c[i][e[p]]; + p = p + 1; + } else { + ans = ans + kk * d[e[p]]; + kk = 0; + } + } + if (ans > maxn) { + maxn = ans; + x = i; + y = j; + } + } + } + } + cout << maxn << endl; +} +ifstream infile; +ofstream outfile; +long double a[2 * 2005], dp[2 * 2005][2005]; +int n; +int OpenFile() { + infile.open("351A.INP", ios::in); + outfile.open("351A.OUT", ios::out); + if (infile.fail()) { + cout << "Khong mo duoc file input !" << endl; + return -1; + } + if (outfile.fail()) { + cout << "khong mo duoc file output!" << endl; + return -1; + } +} +void input() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; +} +void init() { + for (int i = 0; i <= 2 * n; i++) + for (int j = 0; j <= n; j++) dp[i][j] = INT_MAX; + dp[0][0] = 0; +} +void process() { + for (int i = 1; i <= 2 * n; i++) { + for (int j = 0; j <= min(i, n); j++) { + long double val1 = INT_MAX, val2 = INT_MAX; + if (j > 0) val1 = dp[i - 1][j - 1] + ceil(a[i]) - a[i]; + if ((i - j) <= n) val2 = dp[i - 1][j] + floor(a[i]) - a[i]; + dp[i][j] = val1; + if (fabs(val2) < fabs(val1)) dp[i][j] = val2; + } + } +} +void output() { + cout << fixed << setprecision(3) << fabs(dp[2 * n][n]) << endl; +} +void in() { + for (int i = 0; i <= 2 * n; i++) { + for (int j = 0; j <= n; j++) { + if (dp[i][j] == INT_MAX) + cout << 999999 << " "; + else if (dp[i][j] >= 0) + cout << " " << dp[i][j] << " "; + else + cout << dp[i][j] << " "; + } + cout << endl; + } +} +int main() { + input(); + init(); + process(); + output(); +} +int main() { + int n; + cin >> n; + int max = 0; + int cp = 0; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + cp += (b - a); + if (cp >= max) max = cp; + } + cout << max << endl; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int LCM(int a, int b) { + return (a * b) / gcd(a, b); +} +int main() { + int ans, x, y, aa, bb, m; + cin >> x >> y >> aa >> bb; + m = LCM(max(x, y), min(x, y)); + ans = (bb / m) - (aa - 1) / m; + cout << ans << endl; +} +int main() { + int t, L, v, l, r; + cin >> t; + while (t--) { + cin >> L >> v >> l >> r; + cout << L / v - r / v + l / v - (l % v == 0 ? 1 : 0) << "\n"; + } + return 0; +} +int main() { + long long int n, k, a1 = 0, a2 = 0, a3 = 0; + while (cin >> n >> k) { + if (n / 2 < k + 1) + cout << "0 0 " << n << endl; + else { + a1 = n / 2 / (k + 1); + a2 = a1 * k; + a3 = n - a1 - a2; + cout << a1 << " " << a2 << " " << a3 << endl; + } + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int s, a, b, c; + cin >> s >> a >> b >> c; + long long int keyur = s / c; + long long int mayur = keyur / a; + long long int m = keyur + mayur * b; + cout << m << endl; + } + return 0; +} +void fast() {} +void solve() { + int n, an = 0, cc = 0, x, p = -1; + cin >> n; + for (long long int i = 0; i < n; i++) { + cin >> x; + if (x >= p) + cc++; + else { + an = max(an, cc); + cc = 1; + } + p = x; + } + an = max(cc, an); + cout << an << "\n"; +} +int main() { + solve(); + return 0; +} +int main() { + int a, b, count = 0, i, c, y; + cin >> a >> b; + c = sqrt(a); + for (i = 0; i <= c; i++) { + y = (a - (i * i)); + if (i + (y * y) == b) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + long long n, k; + cin >> n; + for (int i = 1; i <= n / 2 + 1; ++i) { + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + for (int j = 1; j <= 2 * i - 1; ++j) cout << "D"; + for (int j = 1; j <= n / 2 - i + 1; ++j) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n / 2; ++i) { + for (int j = 1; j <= i; ++j) cout << "*"; + for (int j = 1; j <= n - i * 2; ++j) cout << "D"; + for (int j = 1; j <= i; ++j) cout << "*"; + cout << endl; + } +} +int main() { + long long int a, b, c, i, j, k; + string s; + cin >> s; + a = s.size(); + b = 25 * (a + 1) + 1; + cout << b << endl; +} +int main() { + int a, b, c; + int max, ans; + cin >> a >> b >> c; + max = a; + if (max < b) max = b; + if (max < c) max = c; + if ((ans = 2 * max - (a + b + c)) < 0) + cout << 0 << endl; + else + cout << ans + 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + string ans = "no"; + if (s.size() < 7) { + cout << ans << endl; + } else { + int k = 0; + reverse(s.begin(), s.end()); + int count = 0, i = 0; + while (count < 6 && i < s.size()) { + if (s[i] == '0') { + count++; + k = i; + } + i++; + } + if (k != 0 && count == 6) { + for (int i = k + 1; i < s.size(); i++) { + if (s[i] == '1') { + ans = "yes"; + break; + } else { + continue; + } + } + } else { + ans = "no"; + } + cout << ans << endl; + } + return 0; +} +int book[101]; +int n, d; +bool istrue(string str) { + for (int i = 0; i < n; i++) { + if (str[i] == '0') return true; + } + return false; +} +int main() { + string str; + cin >> n >> d; + for (int i = 0; i < d; i++) { + cin >> str; + if (istrue(str)) { book[i] = 1; } + } + int sum = 0, coun = 0; + for (int i = 0; i < d; i++) { + if (book[i]) + sum++; + else { + coun = max(coun, sum); + sum = 0; + } + } + cout << max(coun, sum) << endl; + return 0; +} +int main() { + long long q; + cin >> q; + while (q--) { + long long n; + cin >> n; + string s; + cin >> s; + if (n == 2) { + if (s[0] >= s[1]) + cout << "NO\n"; + else { + cout << "YES\n"; + cout << "2\n"; + cout << s[0] << " " << s[1] << "\n"; + } + } else { + char ans1[2], ans2[n - 2]; + long long i; + ans1[0] = s[0]; + ans1[1] = '\0'; + for (i = 1; i < n; i++) ans2[i - 1] = s[i]; + ans2[i - 1] = '\0'; + cout << "YES\n"; + cout << "2\n"; + cout << ans1 << " " << ans2 << "\n"; + } + } + return 0; +} +int main() { + string s, a; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> a; + if (s[0] == a[0] || s[1] == a[1]) return puts("YES"), 0; + } + return puts("NO"), 0; +} +int main() { + int n, m; + string s[101]; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s[i]; + vector v; + for (int i = 0; i < m; i++) { + char c = '0'; + for (int j = 0; j < n; j++) { + if (s[j][i] > c) c = s[j][i]; + } + v.push_back(c); + } + int ans = 0; + for (int i = 0; i < n; i++) { + bool b = false; + for (int j = 0; j < m; j++) { + if (v[j] == s[i][j]) b = true; + } + if (b) ans++; + } + cout << ans << endl; + return 0; +} +long long i, j, k, n, r; +int main() { + cin >> n; + if (n == 0) cout << "O-|-OOOO" << endl; + while (n != 0) { + r = n % 10; + if (r < 5) + cout << "O-|"; + else + cout << "-O|"; + if (r == 0 || r == 5) + cout << "-OOOO" << endl; + else if (r == 1 || r == 6) + cout << "O-OOO" << endl; + else if (r == 2 || r == 7) + cout << "OO-OO" << endl; + else if (r == 3 || r == 8) + cout << "OOO-O" << endl; + else if (r == 4 || r == 9) + cout << "OOOO-" << endl; + n /= 10; + } + return 0; +} +int main() { + int n, a[100002] = {0}; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + while (a[i] % 2 == 0) a[i] /= 2; + while (a[i] % 3 == 0) a[i] /= 3; + } + for (int i = 0; i < n; i++) { + if (a[i] != a[0]) { + cout << "No" << endl; + return 0; + } + } + cout << "Yes" << endl; + return 0; +} +int main() { + unsigned long long n; + cin >> n; + n % 2 == 0 ? cout << 2 << endl : cout << 1 << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + if ((2 * t1 + s * v1) < (2 * t2 + s * v2)) + cout << "First" + << "\n"; + else if ((2 * t1 + s * v1) == (2 * t2 + s * v2)) + cout << "Friendship" + << "\n"; + else + cout << "Second" + << "\n"; + return 0; +} +const int maxn = 110; +const int inf = 0x3f3f3f3f; +char s[maxn]; +int main() { + string s; + cin >> s; + int cnt1 = 0, cnt2 = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'o') + cnt1++; + else + cnt2++; + } + if (cnt1 == 0) { + cout << "YES" << endl; + } else { + if (cnt2 % cnt1 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +stack st; +int main() { + int n; + cin >> n; + cout << n + (n / 2) << endl; + return 0; +} +int main() { + char polje[8][8]; + int W = 10; + int B = 10; + for (int x = 0; x < 8; x++) + for (int y = 0; y < 8; y++) cin >> polje[y][x]; + for (int x = 0; x < 8; x++) { + for (int y = 0; y < 8; y++) { + if (polje[x][y] == 'W' && y < W) + W = y; + else if (polje[x][y] == 'B') + break; + } + for (int y = 0; y < 8; y++) { + if (polje[x][7 - y] == 'B' && y < B) + B = y; + else if (polje[x][7 - y] == 'W') + break; + } + } + if (B < W) + cout << 'B' << endl; + else + cout << "A" << endl; + return 0; +} +long long int dif(long long int q, long long int w) { + if (q % w == 0) + return q / w; + else + return q / w + 1; +} +int main() { + long long int t; + cin >> t; + string s; + for (int i = 0; i < t; i++) { + cin >> s; + if (s.size() <= 10) + cout << s << endl; + else + cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl; + } + return 0; +} +const int T = 1600; +int n, s, h, m, t, tab[T]; +int main() { + cin >> n >> s; + for (int i = 1; i <= n; i++) { + cin >> h >> m; + t = h * 60 + m; + tab[max(t - s, 0)]++; + tab[t + s + 1]--; + } + for (int i = 0; i < T; i++) { + if (i > 0) tab[i] += tab[i - 1]; + if (tab[i] == 0) { + cout << i / 60 << ' ' << i % 60 << endl; + return 0; + } + } + return 0; +} +int main() { + int k, r; + cin >> k >> r; + int ans = 1; + while ((k * ans) % 10 != r && (k * ans) % 10 != 0) { ans++; } + cout << ans << endl; + return 0; +} +int main() { + int n, m, ans = 0, flag = 0, max; + string s[110]; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> s[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + max = s[i][j]; + for (int t = 0; t < n; t++) { + if (max < s[t][j]) { + flag = 1; + break; + } + } + if (flag == 1) { + flag = 0; + continue; + } else { + ans++; + break; + } + } + } + cout << ans << endl; +} +int num[1000000] = {0}; +void fx(char a[]); +int main() { + int n, a, b; + char z[1000000]; + cin >> n >> a >> b; + cin >> z; + if (z[a - 1] == z[b - 1]) { + cout << "0" << endl; + } else { + cout << "1" << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + while (n > 5) { n = n / 2 - 2; } + if (n == 1) + cout << "Sheldon" << endl; + else if (n == 2) + cout << "Leonard" << endl; + else if (n == 3) + cout << "Penny" << endl; + else if (n == 4) + cout << "Rajesh" << endl; + else if (n == 5) + cout << "Howard" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int tot = 0, ans = 0; + for (int i = 1; i <= n; i += 1) { + tot += i * (i + 1) / 2; + if (tot > n) break; + ans = i; + } + cout << ans << endl; + return 0; +} +int main() { + int m, x, y; + int xx[1005]; + while (cin >> m) { + int a = 0; + for (int i = 0; i < m; i++) { + cin >> xx[i]; + a += xx[i]; + } + cin >> x >> y; + int b = 0; + int c = 0; + for (int i = 0; i < m; i++) { + if (b >= x && b <= y && a - b >= x && a - b <= y) { + c = i + 1; + break; + } + b += xx[i]; + } + cout << c << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + cout << (s1 == s2 ? s1 : "1") << endl; + return 0; +} +int calc(int c[], int x, int y) { + int sum = 0; + for (int i = x; i <= y; i++) sum |= c[i]; + return sum; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + int x = INT_MIN, y = INT_MIN; + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { x = max(x, calc(a, i, j)); } + } + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { y = max(y, calc(b, i, j)); } + } + cout << x + y << endl; + return 0; +} +long long nearest(const long long &x, const int &a, const int &b) { + if (x % a == 0 && x % b == 0) + return x + min(a, b); + else + return min(a * (x / a + 1), b * (x / b + 1)); +} +int main() { + int a, b; + cin >> a >> b; + long long cur = 0; + long long D = 0, M = 0; + while (!(cur > 0 && cur % a == 0 && cur % b == 0)) { + long long n = nearest(cur, a, b); + if (n % a == 0 && n % b == 0) { + if (a > b) + D += n - cur; + else + M += n - cur; + } else if (n % a == 0) { + D += n - cur; + } else { + M += n - cur; + } + cur = n; + } + cout << ((D == M) ? "Equal" : (D > M ? "Dasha" : "Masha")) << endl; + return 0; +} +string str; +string result = "Correct"; +int main() { + int ii; + int len; + bool haveNum = 0, haveSmallLetter = 0, haveBigLetter = 0; + cin >> str; + for (ii = 0, len = str.size(); ii < len; ii++) { + if ((str[ii] >= '0') && (str[ii] <= '9')) + haveNum = 1; + else if ((str[ii] >= 'A') && (str[ii] <= 'Z')) + haveBigLetter = 1; + else if ((str[ii] >= 'a') && (str[ii] <= 'z')) + haveSmallLetter = 1; + } + if ((len < 5) || !haveNum || !haveBigLetter || !haveSmallLetter) result = "Too weak"; + cout << result << endl; + return 0; +} +int main() { + int w, h, k; + cin >> w >> h >> k; + cout << 2 * k * (w + h - 2) - 8 * (k * (k - 1)) << endl; + return 0; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = 10 * x + ch - '0'; + ch = getchar(); + } + return x * f; +} +int n; +int main() { + n = read(); + int sum = 0; + while (n--) { + int h = read(); + if (h > 0) + sum += h; + else + sum -= h; + } + cout << sum << endl; +} +int n, a; +int main() { + cin >> n >> a; + cin.ignore(); + long long ans = a, kids = 0; + while (n--) { + char s; + int x; + cin >> s >> x; + if (s == '+') { + ans += x; + } else { + if (ans < x) + kids++; + else + ans -= x; + } + } + cout << ans << " " << kids << "\n"; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + cout << 26 * (n + 1) - n << '\n'; +} +int main() { + int n, m, i; + cin >> n >> m; + char str[n][m]; + for (i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> str[i][j]; } + } + for (i = 0; i < n; i = i + 2) { + for (int j = 0; j < m; j = j + 2) { + if (str[i][j] != '-') str[i][j] = 'B'; + } + for (int k = 1; k < m; k = k + 2) { + if (str[i][k] != '-') str[i][k] = 'W'; + } + } + for (i = 1; i < n; i = i + 2) { + for (int j = 1; j < m; j = j + 2) { + if (str[i][j] != '-') str[i][j] = 'B'; + } + for (int k = 0; k < m; k = k + 2) { + if (str[i][k] != '-') str[i][k] = 'W'; + } + } + for (i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << str[i][j]; } + cout << endl; + } +} +int main() { + int x; + cin >> x; + cout << x % 2 << endl; +} +int main() { + int n, a[3], i, j, d, e = 0; + cin >> n; + for (i = 0; i < n; i++) { + d = 0; + for (j = 0; j < 3; j++) { + cin >> a[j]; + if (a[j] == 1) d++; + } + if (d >= 2) e++; + } + cout << e << endl; + return 0; +} +int main() { + int n, i, m = 0, c = 0; + string str; + cin >> n; + getchar(); + getline(cin, str); + for (i = 0; i < n; i++) { + if (isupper(str[i])) c++; + m = max(c, m); + if (str[i] == ' ') c = 0; + } + cout << m << endl; + return 0; +} +vector v; +int main() { + int n; + long long x, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x % 2 != 0) + v.push_back(x); + else + sum += x; + } + sort(v.begin(), v.end()); + long long len = v.size(); + if (len % 2 == 0) { + for (int i = 0; i < len; i++) sum += v[i]; + } else { + for (int i = 1; i < len; i++) sum += v[i]; + } + cout << sum << endl; +} +int main() { + int distance; + cin >> distance; + cout << (distance + 4) / 5 << endl; +} +const long long oo = 2 * 1000 * 1000 * 1000; +const int _cnt = 1000 * 1000; +const int _p = 1000 * 1000 * 1000 + 7; +long long o(long long x) { + return x % _p; +} +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} +int lcm(int a, int b) { + return a * b / gcd(a, b); +} +void file_put() { + freopen("filename.in", "r", stdin); + freopen("filename.out", "w", stdout); +} +string s[10]; +int ans = oo, ans2 = oo; +bool t = false; +int main() { + for (int i = 1; i <= 8; i++) { + cin >> s[i]; + cin.ignore(); + } + for (int i = 1; i <= 8; i++) + for (int j = 0; j <= 7; j++) { + if (s[i][j] != 'W') continue; + t = false; + for (int k = i - 1; k >= 1; k--) + if (s[k][j] == 'B') { + t = true; + break; + } + if (t) continue; + ans = ((ans) < (i - 1) ? (ans) : (i - 1)); + } + for (int i = 1; i <= 8; i++) + for (int j = 0; j <= 7; j++) { + if (s[i][j] != 'B') continue; + t = false; + for (int k = i + 1; k <= 8; k++) + if (s[k][j] == 'W') { + t = true; + break; + } + if (t) continue; + ans2 = ((ans2) < (8 - i) ? (ans2) : (8 - i)); + } + if (ans <= ans2) + cout << "A\n"; + else + cout << "B\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int s = (n * (n + 1)) / 2; + m = m % s; + for (int i = 1; i <= n; i++) { + if (m < i) { + cout << m << endl; + return 0; + } else { + m = m - i; + } + } + return 0; +} +int main() { + int n; + cin >> n; + map mapa; + int segundos = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (mapa[a] == 0 && a != 0) { + mapa[a] += 1; + segundos++; + } + } + cout << segundos << endl; + return 0; +} +int a, b; +int cnt; +char s, t; +map mp; +int main() { + cin >> s >> t; + cin >> cnt; + cnt %= 4; + mp['v'] = 0; + mp['<'] = 1; + mp['^'] = 2; + mp['>'] = 3; + a = mp[s]; + b = mp[t]; + if ((a - b + 4) % 4 == cnt) { + if ((b - a + 4) % 4 == cnt) { + cout << "undefined\n"; + return 0; + } + cout << "ccw\n"; + return 0; + } + if ((b - a + 4) % 4 == cnt) { + cout << "cw\n"; + return 0; + } +} +const char a[] = {'v', '<', '^', '>'}; +int main() { + char s1, s2; + cin >> s1 >> s2; + int n; + cin >> n; + int s, e; + for (int i = 0; i < 4; i++) { + if (s1 == a[i]) s = i; + if (s2 == a[i]) e = i; + } + if ((s + n) % 4 == e && (((s - n) % 4) + 4) % 4 == e) + cout << "undefined" << endl; + else if ((s + n) % 4 == e) + cout << "cw" << endl; + else + cout << "ccw" << endl; + return 0; +} +int main() { + long int t, s, q, c = 0; + cin >> t >> s >> q; + while (t > s) { + s *= q; + c++; + } + cout << c << endl; + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (x > y) { swap(x, y); } + if (x >= m || y >= m) { + cout << 0 << endl; + return 0; + } + if (x <= 0 && y <= 0) { + cout << -1 << endl; + return 0; + } + long long cnt = 0; + if (x < 0 && y > 0) { + if (m < 0) { + cnt = (long long)((m - x) * 1.0 / y); + x += cnt * y; + } else { + cnt = (long long)((-x) * 1.0 / y); + x += cnt * y; + } + } + long long z = x + y; + while (x < m && y < m) { + z = x + y; + if (x > y) { swap(x, y); } + x = z; + cnt++; + } + cout << cnt << endl; +} +int main() { + long long a, b, n, d, x, y, k, ans = 2; + cin >> n >> d; + cin >> a; + for (int i = 1; i < n; i++) { + cin >> b; + k = b - d - (a + d); + if (k == 0) + ans += 1; + else if (k > 0) + ans += 2; + a = b; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string number; + cin >> number; + int has_eight = 0; + for (int i = 0; i < number.length(); i++) + if (number[i] == '8') has_eight++; + if (n < 11 || has_eight == 0) { + cout << 0 << endl; + return 0; + } + if ((n / 11) >= has_eight) + cout << has_eight << endl; + else if ((n / 11) < has_eight) + cout << n / 11 << endl; +} +int main() { + string s, t; + cin >> s >> t; + unsigned int sz = t.size(); + int iter = 0, ret = 1; + for (int i = 0; i < sz; i++) + if (t[i] == s[iter]) { + ret++; + iter++; + } + cout << ret << endl; + return 0; +} +int main() { + int a[1005]; + int n; + int sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (n % 2) + cout << a[n / 2] << endl; + else + cout << a[n / 2 - 1] << endl; +} +int main() { + int N; + string jolteon = "jolteon"; + int jol = 0; + string flareon = "flareon"; + int fla = 0; + string umbreon = "umbreon"; + int umb = 0; + string leafeon = "leafeon"; + int leaf = 0; + string glaceon = "glaceon"; + int gla = 0; + string sylveon = "sylveon"; + int syl = 0; + string eevee; + cin >> N; + cin >> eevee; + if (N == 8) { + cout << "vaporeon\n"; + } else if (N == 6) { + cout << "espeon\n"; + } else { + for (int x = 0; x < N; x++) { + if (eevee[x] != '.') { + if (eevee[x] == flareon[x] && fla == 0) { + if (x != 2) { leaf = 1; } + jol = 1; + syl = 1; + umb = 1; + if (x != 1 && x != 2) { gla = 1; } + } + if (eevee[x] == glaceon[x] && gla == 0) { + if (x != 2) { leaf = 1; } + jol = 1; + syl = 1; + umb = 1; + if (x != 1 && x != 2) { fla = 1; } + } + if (eevee[x] == leafeon[x] && leaf == 0) { + if (x != 2) { + fla = 1; + gla = 1; + } + jol = 1; + syl = 1; + umb = 1; + } + if (eevee[x] == jolteon[x] && jol == 0) { + leaf = 1; + fla = 1; + if (x != 2) { syl = 1; } + umb = 1; + gla = 1; + } + if (eevee[x] == umbreon[x] && umb == 0) { + leaf = 1; + jol = 1; + syl = 1; + fla = 1; + gla = 1; + } + if (eevee[x] == sylveon[x] && syl == 0) { + leaf = 1; + fla = 1; + if (x != 2) { jol = 1; } + umb = 1; + gla = 1; + } + if (syl + leaf + jol + umb + gla + fla == 5) { + if (syl == 0) { cout << sylveon << "\n"; } + if (gla == 0) { cout << glaceon << "\n"; } + if (fla == 0) { cout << flareon << "\n"; } + if (jol == 0) { cout << jolteon << "\n"; } + if (umb == 0) { cout << umbreon << "\n"; } + if (leaf == 0) { cout << leafeon << "\n"; } + break; + } + } + } + } +} +int main() { + int a, b; + cin >> a >> b; + int c, d; + cin >> c >> d; + int e, f; + cin >> e >> f; + int x; + x = a; + for (int i = b; i >= 0; i--) { + x += i; + if (i == d) { + if (x >= c) + x = x - c; + else + x = 0; + } + if (i == f) { + if (x >= e) + x = x - e; + else + x = 0; + } + } + cout << x << endl; + return 0; +} +; +const long long INT64M = 0X3F3F3F3F3F3F3F3F; +const int INT32M = 0x3F3F3F3F; +const int mod = 1e9 + 7; +int main() { + long long n; + cin >> n; + if (n & 1) { + cout << 1 << endl; + } else { + cout << 2 << endl; + } +} +int main() { + int n; + cin >> n; + int mx = 0; + int mn = 1e9; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + mx = max(mx, t); + mn = min(mn, t); + } + cout << mx - mn + 1 - n << '\n'; +} +int main() { + int a, b, c, d, x, y; + cin >> a >> b >> c >> d; + x = max(((3 * a) / 10), (a - ((a * c) / 250))); + y = max(((3 * b) / 10), (b - ((b * d) / 250))); + if (x == y) + cout << "Tie" << endl; + else if (x > y) + cout << "Misha" << endl; + else + cout << "Vasya" << endl; + return 0; +} +long long n, m, k; +long long ans = 0; +int main() { + cin >> n >> m >> k; + for (long long i = 0; i < k; i++) { + long long len = n - (i * 2) * 2; + long long wid = m - (i * 2) * 2; + ans += ((len + wid) * 2 - 4); + } + cout << ans << "\n"; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + int ans = min(l, r); + l -= ans; + r -= ans; + ans *= 2; + if (l == 0) { l = r; } + if (l > a) { + ans += 2 * a; + } else { + ans += (l + a) / 2 * 2; + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + int count = 0; + for (int x; cin >> x;) { + int d = 0; + while (x) (x % 10 == 4 || x % 10 == 7) && ++d, x /= 10; + if (d <= k) ++count; + } + cout << count << '\n'; +} +int n, k; +int total; +bool check(int p) { + int a = (5 * p * (p + 1)) / 2; + if (a <= total) return true; + return false; +} +int main() { + cin >> n >> k; + total = 240 - k; + int l = 0, r = n, mid; + while (l <= r) { + mid = (l + r) / 2; + if (check(mid)) { + l = mid + 1; + } else + r = mid - 1; + } + cout << r << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + unsigned long long int l, r; + cin >> l >> r; + unsigned long long int temp = l; + unsigned long long int i = 0; + while ((temp | ((1LL << i))) <= r and i < 64) { + temp = (temp | ((1LL << i))); + ++i; + } + cout << temp << "\n"; + } + return 0; +} +int main() { + int n, k, v, l, r; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k >> v >> l >> r; + cout << k / v + (l - 1) / v - r / v << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + vector v; + int count = 0; + int ara[n]; + for (int i = 0; i < n; i++) { cin >> ara[i]; } + for (int i = 1; i < n; i++) { + if (ara[0] <= ara[i]) { v.push_back(ara[i]); } + } + int flag = 0, s = v.size(); + if (s == 0) { + cout << "0" << endl; + } else { + while (1) { + flag = 0; + sort(v.begin(), v.end()); + if (ara[0] <= v[s - 1]) { + ara[0]++; + v[s - 1]--; + count++; + flag = 1; + } + if (flag == 0) { break; } + } + cout << count << endl; + } +} +int main() { + int a; + cin >> a; + int ans = 1; + while (a != 1) { + ans++; + a >>= 1; + } + cout << ans << endl; + return 0; +} +int a[1001][1001]; +int main() { + int n, m, i, j, cnt = 0; + cin >> n >> m; + for (i = 0; i <= n; i++) { + for (j = 0; j <= m; j++) { + if (i * i + j == n && i + j * j == m) a[i][j] = 1; + } + } + for (i = 0; i < 1001; i++) { + for (j = 0; j < 1001; j++) { + if (a[i][j]) cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, m, i, l, r, j; + char c1, c2; + char a[1000] = {}; + cin >> n >> m; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (j = 1; j <= m; j++) { + cin >> l >> r >> c1 >> c2; + for (i = l; i <= r; i++) { + if (a[i] == c1) a[i] = c2; + } + } + for (i = 1; i <= n; i++) { cout << a[i]; } + cout << endl; + return 0; +} +int main() { + int m; + int d; + int days; + int res; + cin >> m >> d; + if (m == 2) { + days = 28; + } else if (m == 4 || m == 6 || m == 9 || m == 11) { + days = 30; + } else { + days = 31; + } + res = (days + d - 1) / 7 + 1; + res = (days + d - 1) % 7 == 0 ? (days + d - 1) / 7 : (days + d - 1) / 7 + 1; + cout << res << endl; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + if (s.length() % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + long long int x; + long long int arr[3] = {}; + cin >> x; + arr[x] = 1; + n %= 6; + while (n > 0) { + if (n % 2 == 0) + swap(arr[1], arr[2]); + else + swap(arr[1], arr[0]); + n--; + } + for (long long int i = 0; i < 3; i++) { + if (arr[i] == 1) cout << i << endl; + } + return 0; +} +int main() { + int sum = 0, num[105]; + int n; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> num[i]; + sum += num[i]; + } + sum /= 2; + sort(num, num + n); + int cnt = 0; + int ans = 0; + for (int j = n - 1; j >= 0; --j) { + cnt += num[j]; + ans++; + if (cnt > sum) { return cout << ans << endl, 0; } + } + return 0; +} +int main() { + long long int u, v, w; + cin >> u >> v >> w; + long long int t1, t2, t3; + t1 = sqrt((u * v * w)) / u; + t2 = sqrt((u * v * w)) / v; + t3 = sqrt((u * v * w)) / w; + cout << 4 * (t1 + t2 + t3) << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + v.push_back(a); + } + cin >> x >> y; + for (int i = 1; i < 101; i++) { + int g1 = 0, g2 = 0; + for (int k = 0; k < ((int)(v).size()); k++) { + if (k + 1 < i) + g1 += v[k]; + else + g2 += v[k]; + } + if (g1 >= x && g1 <= y && g2 >= x && g2 <= y) return cout << i << endl, 0; + } + cout << 0 << endl; + return 0; +} +const double eps = 1.0e-5; +const int maxn = 100000 + 10; +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +int main() { + string s; + cin >> s; + int x = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'o') { x++; } + } + if (x == 0) { + cout << "YES" << '\n'; + } else { + if (s.length() % x == 0) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } + } + return 0; +} +char c; +int x, y, kol; +void Found(int x, int y) { + if ((x >= 1) && (x <= 8) && (y >= 1) && (y <= 8)) kol++; +} +int main() { + cin >> c; + cin >> y; + x = c - 96; + Found(x + 1, y); + Found(x, y + 1); + Found(x - 1, y); + Found(x, y - 1); + Found(x + 1, y + 1); + Found(x - 1, y - 1); + Found(x + 1, y - 1); + Found(x - 1, y + 1); + cout << kol << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (a == 0 && b == 0) { + cout << "NO" << endl; + } else { + if (abs(a - b) == 0 || abs(a - b) == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + string s; + cin >> s; + string t = "QAQ"; + int n = s.length(); + int m = t.length(); + vector dp(m + 1, 0); + dp[0] = 1; + for (int C = 0; C < s.length(); C++) { + for (int X = m - 1; X >= 0; X--) { + if (t[X] == s[C]) { dp[X + 1] += dp[X]; } + } + } + cout << dp[m] << "\n"; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[50] = {0}, b[50] = {0}; + int ans = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (a[i] == b[j]) ans++; + cout << ans << endl; + } + return 0; +} +const int INF = 1 << 30; +const long long inf = 1LL << 60; +int read() { + int w(0), f(0); + char c = getchar(); + while ((c < '0' || c > '9') && c != '-') c = getchar(); + if (c == '-') f = 1, c = getchar(); + while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar(); + return f ? -w : w; +} +int T, n; +string s; +bool b; +int main() { + T = read(); + for (int i = 1; i <= T; ++i) { + n = read(); + cin >> s; + b = 1; + for (int i = 0; i < (n / 2); ++i) + if (abs(s[i] - s[n - 1 - i]) != 0 && abs(s[i] - s[n - 1 - i]) != 2) b = 0; + if (b) + puts("YES"); + else + puts("NO"); + } + return 0; +} +string str; +int main() { + int num = 0; + cin >> str; + for (int i = 0; i < str.length(); ++i) { + if (str[i] == '1') { + num = 2; + } else if (str[i] == '4') { + num--; + } else { + cout << "NO" << endl; + return 0; + } + if (num < 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +string s, sh[51]; +int ans; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + sh[i] = s; + for (int j = 0; j < s.size(); j++) { sh[i][(j + i) % (int(s.size()))] = s[j]; } + bool w = true; + for (int j = 0; j < i; j++) { + if (sh[i] == sh[j]) { + w = false; + break; + } + } + if (w) ans++; + } + cout << ans << endl; +} +string s; +long long n, minimal; +long long huruf[91]; +int k; +int main() { + cin >> n >> k; + cin >> s; + minimal = n; + for (int i = 0; i < n; i++) { huruf[int(s[i])]++; } + for (int i = 65; i <= 65 + k - 1; i++) { minimal = min(minimal, huruf[i]); } + cout << k * minimal << '\n'; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 && m > 0) { + cout << "Impossible" << endl; + return 0; + } + int mn, mx; + mn = n + (max(0, m - n)); + mx = n + max(0, m - 1); + cout << mn << " " << mx << endl; + return 0; +} +int main() { + string a, b, c, d, e, f; + cin >> a; + bool flag = false; + for (int i = 0; i < 5; i++) { + cin >> b; + if (a[0] == b[0] || a[1] == b[1]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + string a; + cin >> a; + int ans = 0; + for (int i = 0; i < a.length(); i++) { + int l = 0, r = 0; + for (int j = i; j < a.length(); j++) { + if (a[j] == '(') + l++; + else if (a[j] == ')') + l--; + else { + l--; + r++; + } + if (l == 0) ans++; + if (l < 0) { + if (r == 0) + break; + else { + if (r > 0) { + l += 2; + r--; + } + } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + string str; + cin >> str; + reverse(str.begin(), str.end()); + for (int i = 0; i < str.size(); i++) { + if (str[i] == '0') + cout << "O-|-OOOO" << endl; + else if (str[i] == '1') + cout << "O-|O-OOO" << endl; + else if (str[i] == '2') + cout << "O-|OO-OO" << endl; + else if (str[i] == '3') + cout << "O-|OOO-O" << endl; + else if (str[i] == '4') + cout << "O-|OOOO-" << endl; + else if (str[i] == '5') + cout << "-O|-OOOO" << endl; + else if (str[i] == '6') + cout << "-O|O-OOO" << endl; + else if (str[i] == '7') + cout << "-O|OO-OO" << endl; + else if (str[i] == '8') + cout << "-O|OOO-O" << endl; + else if (str[i] == '9') + cout << "-O|OOOO-" << endl; + } + return 0; +} +int main() { + int arr[26] = {}, temp[26] = {}, n, val = 0, ans = 0, v, u, av = 0, red = 0; + char ch[100001], au, ansa; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> au >> ch; + if (red < 25) { + if (au == '.') { + v = strlen(ch); + for (int j = 0; j < v; j++) { + u = (int)ch[j] - 'a'; + if (arr[u] == 1 || arr[u] == 0) { + arr[u] = -1; + red++; + } + } + } else if (au == '!') { + v = strlen(ch); + if (av == 0) { + for (int j = 0; j < v; j++) { + u = (int)ch[j] - 'a'; + if (arr[u] == 0) { arr[u] = 1; } + } + for (int k = 0; k < 26; k++) { + if (arr[k] == 0) { + arr[k] = -1; + red++; + } + } + av++; + } else { + for (int k = 0; k < 26; k++) temp[k] = 0; + for (int k = 0; k < v; k++) { + u = (int)ch[k] - 'a'; + temp[u] = 1; + } + for (int k = 0; k < 26; k++) { + if (arr[k] == 1 && temp[k] == 0) { + arr[k] = -1; + red++; + } + } + } + } else { + u = (int)ch[0] - 'a'; + if (arr[u] == 1 || arr[u] == 0) { + arr[u] = -1; + red++; + } + } + if (red == 25) { + for (int k = 0; k < 26; k++) + if (arr[k] != -1) ansa = (char)97 + k; + } + } else if (au == '!' || (au == '?' && ch[0] != ansa)) + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int a[10][10] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; + int n, m; + cin >> n; + if (n == 1) { + cout << '1' << endl; + return 0; + } else { + m = n; + for (int i = 1; i < n; i++) + for (int j = 0; j <= m - 1; j++) + if (j == 0) + a[i][j] = 1; + else { + for (int v = 1; v <= j + 1; v++) a[i][j] += a[i - 1][v - 1]; + } + } + cout << a[n - 1][m - 1] << endl; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + int m, n, z; + while (cin >> n >> m >> z) { + int x = m * n / gcd(m, n), sum = 0; + int i = x; + while (x <= z) { + sum++; + x += i; + } + cout << sum << endl; + } + return 0; +} +int n, m; +void a() { + for (int i = 1; i <= m; i++) { cout << "#"; } +} +void b() { + for (int i = 1; i <= m - 1; i++) { cout << "."; } + cout << "#"; +} +void c() { + cout << "#"; + for (int i = 2; i <= m; i++) { cout << "."; } +} +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 == 1) { + a(); + } else { + if (i % 4 == 2) { + b(); + } else { + c(); + } + } + cout << endl; + } + return 0; +} +long long i, Long, Arr[1500000], Max, repeticiones; +int main() { + while (cin >> Long) { + Max = 0; + for (long long i = 0; i < Long; i++) cin >> Arr[i]; + sort(Arr, Arr + Long); + repeticiones = Long; + for (long long g = Long - 1; g >= 0; g--) { + if (g >= Long - 2) { + Max += Arr[g] * repeticiones; + } else { + repeticiones--; + Max += Arr[g] * repeticiones; + } + } + cout << Max << endl; + } + return 0; +} +int arr[100]; +int main() { + string s; + string a; + while (cin >> s) { + a = ""; + for (int i = 0; i < s.length(); i++) { + if (s[i] != '+') a.push_back(s[i]); + } + int p = a.length(); + for (int i = 0; i < a.length(); i++) { arr[i] = a[i] - '0'; } + int n = sizeof(arr) / sizeof(arr[0]); + sort(arr, arr + n, greater()); + for (int i = p - 1; i >= 1; i--) { + cout << arr[i]; + cout << "+"; + } + cout << arr[0]; + cout << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int mxm = max(3 * a / 10, a - (a / 250) * c); + int mxv = max(3 * b / 10, b - (b / 250) * d); + if (mxm < mxv) + cout << "Vasya" << endl; + else if (mxm > mxv) + cout << "Misha" << endl; + else + cout << "Tie" << endl; +} +const int mod = 1000 * 1000 * 1000 + 9; +long long int ans(int, int); +long long int power(int); +long long int norm(long long int); +int main() { + int n, m; + cin >> n >> m; + cout << ans(n, m) << endl; + return 0; +} +long long int ans(int n, int m) { + long long int p = power(m); + if (m < 20 && p - 1 < n) return 0; + long long int res = 1; + for (int i = 1; i <= n; i++) { + long long int coe = p - i; + coe = norm(coe); + res *= coe; + res = norm(res); + } + return res; +} +long long int power(int n) { + long long int res = 1; + for (int i = 1; i <= n; i++) { + res *= 2; + res = norm(res); + } + return res; +} +long long int norm(long long int value) { + value %= mod; + if (value < 0) value += mod; + return value; +} +int main() { + char s[1001][1001]; + int n; + int hah = 0; + int num; + int m; + int flag; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int k = 'a'; k <= 'z'; k++) { + for (int l = k; l <= 'z'; l++) { + num = 0; + for (int i = 0; i < n; i++) { + m = strlen(s[i]); + flag = 1; + for (int j = 0; j < m; j++) { + if (s[i][j] != k && s[i][j] != l) { + flag = 0; + break; + } + } + if (flag == 1) num = num + m; + } + if (num > hah) hah = num; + } + } + cout << hah << endl; + return 0; +} +int main() { + int k, f[26] = {0}, cnt = 0; + vector pos; + string s; + cin >> k >> s; + for (int i = 0; i < s.length(); i++) { + f[s[i] - 97]++; + if (f[s[i] - 97] == 1) { pos.push_back(i); } + } + for (int i = 0; i < 26; i++) { + if (f[i]) { cnt++; } + } + if (cnt < k) { + cout << "NO" + << "\n"; + } else { + cout << "YES" + << "\n"; + int i = 0; + for (int j = 1; j <= pos.size(); j++) { + if (k == 1) { + for (; i < s.length(); i++) { cout << s[i]; } + cout << "\n"; + break; + } + for (; i < pos[j]; i++) { cout << s[i]; } + k--; + cout << "\n"; + } + } + return 0; +} +int main() { + int n, m, p; + cin >> n; + int c = 0; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + m = p = a[0]; + for (int i = 1; i < n; i++) { + if (a[i] > p) { + p = a[i]; + c++; + } + if (a[i] < m) { + m = a[i]; + c++; + } + } + cout << c << endl; +} +int main() { + char a[101], b[101]; + gets(a); + for (int i = 0; a[i] != '\0'; i++) a[i] = tolower(a[i]); + gets(b); + for (int i = 0; b[i] != '\0'; i++) b[i] = tolower(b[i]); + if (strcmp(a, b) < 0) + cout << -1 << endl; + else if (strcmp(a, b) == 0) + cout << 0 << endl; + else if (strcmp(a, b) > 0) + cout << 1 << endl; + return 0; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +bool isDt(int y) { + bool dig[10]; + memset(dig, false, sizeof(dig)); + for (int i = y; i > 0; i = i / 10) { + if (dig[i % 10]) return false; + dig[i % 10] = true; + } + return true; +} +int main() { + int y; + cin >> y; + int ans = y + 1; + for (;; ans++) + if (isDt(ans)) break; + cout << ans << endl; + return 0; +} +int main() { + long long n = 1; + long long a = 0; + cin >> n; + while (n > 0) { + if (n % 2 == 1) { + a++; + n--; + } else { + n /= 2; + } + } + cout << a << "\n"; + return 0; +} +int main() { + int n, k, b[26] = {0}; + char a[110]; + cin >> n >> k; + cin >> a; + for (int i = 0; a[i] != '\0'; i++) { + if (a[i] >= 'A' && a[i] <= 'Z') { + b[a[i] - 'A']++; + } else if (a[i] >= 'a' && a[i] <= 'z') { + b[a[i] - 'a']++; + } + } + int flag = 0; + for (int i = 0; i < 26; i++) { + if (b[i] > k) { + flag = 1; + break; + } + } + if (flag == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + double n, x, y; + cin >> n >> x >> y; + int r = ceil(y / 100 * n); + if (x >= r) + cout << 0 << '\n'; + else + cout << r - x << '\n'; + return 0; +} +int main() { + long long int x1, x2, x3, y1, y2, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + if ((y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)) { + cout << "TOWARDS" << endl; + } else if ((x3 - x2) * (y2 - y1) - (x2 - x1) * (y3 - y2) > 0) { + cout << "RIGHT" << endl; + } else { + cout << "LEFT" << endl; + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np, kl, cd, NP; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + kl = (k * l) / nl; + cd = c * d; + NP = p / np; + int r = 0; + while (kl - n >= 0 && cd - n >= 0 && NP - n >= 0) { + kl = kl - n; + NP = NP - n; + cd = cd - n; + r++; + } + cout << r << endl; + return 0; +} +int main() { + string f_name, l_name, result = ""; + cin >> f_name >> l_name; + result += f_name[0]; + for (int i = 1; i < f_name.size(); i++) { + if (f_name[i] < l_name[0]) { + result += f_name[i]; + } else { + break; + } + } + result += l_name[0]; + cout << result << endl; + return 0; +} +int main() { + int table[10][10]; + int N; + cin >> N; + for (int i = 0; i < N; i++) { + table[0][i] = 1; + table[i][0] = 1; + } + for (int i = 1; i < N; i++) { + for (int j = 1; j < N; j++) { table[i][j] = table[i - 1][j] + table[i][j - 1]; } + } + cout << table[N - 1][N - 1] << endl; + return 0; +} +int main() { + int x, y, a, b, m, n; + cin >> x >> y >> a >> b; + int p = x, q = y; + while (q) { + n = q; + q = p % q; + p = n; + } + n = (x * y) / n; + m = a % n ? 0 : 1; + cout << (b / n - a / n + m) << endl; + return 0; +} +int main() { + int n, arr[30] = {0}; + cin >> n; + int i, c1 = 0, c2 = 0, c3 = 0, maxs = 0; + for (i = 0; i < n; i++) { cin >> arr[i]; } + for (i = 0; i < n; i++) { + if (i % 3 == 0) { c1 += arr[i]; } + if (i % 3 == 1) { c2 += arr[i]; } + if (i % 3 == 2) { c3 += arr[i]; } + maxs = max(maxs, c1); + maxs = max(maxs, c2); + maxs = max(maxs, c3); + } + if (maxs == c1) { cout << "chest" << endl; } + if (maxs == c2) { cout << "biceps" << endl; } + if (maxs == c3) { cout << "back" << endl; } + return 0; +} +int main() { + long long n, k, mid; + cin >> n >> k; + long long l = 0, r = n; + long long half = n >> 1; + while (l < r) { + mid = (l + r) >> 1; + if (mid > half / (1 + k)) + r = mid; + else + l = mid + 1; + } + if ((1 + k) * l > half) l--; + if (l) + cout << l << " " << l * k << " " << n - (1 + k) * l << "\n"; + else + cout << 0 << " " << 0 << " " << n << "\n"; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long x = s / (a * c); + s -= x * (a * c); + cout << x * b + x * a + s / c << endl; + } +} +int main() { + int n, k; + int res, cur; + cin >> n >> k; + res = 0; + cur = n * 2; + res += (cur + k - 1) / k; + cur = n * 5; + res += (cur + k - 1) / k; + cur = n * 8; + res += (cur + k - 1) / k; + cout << res << endl; +} +int dx[4] = {0, 0, 1, -1}; +int dy[4] = {1, -1, 0, 0}; +int DX[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int DY[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int n; +int x; +bool v = 0; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x == 1) { v = 1; } + } + if (v) { + cout << -1 << endl; + } else { + cout << 1 << endl; + } +} +void solve() { + long long n, m, x, y, z, mn = INT_MAX, ans = 0; + cin >> m; + for (long long i = 0; i < m; i++) { + cin >> x; + mn = min(mn, x); + } + cin >> n; + vector v; + for (long long i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end(), greater()); + y = mn + 2; + for (long long i = 0; i < n; i++) { + z = i % y; + if (z < mn) ans += v[i]; + } + cout << ans << '\n'; + return; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = n / 2; i >= 0; i--) { + for (int j = 0; j < i; j++) { cout << "*"; } + for (int j = 0; j < n - 2 * i; j++) { cout << "D"; } + for (int j = 0; j < i; j++) { cout << "*"; } + cout << endl; + } + for (int i = 1; i <= n / 2; i++) { + for (int j = 0; j < i; j++) { cout << "*"; } + for (int j = 0; j < n - 2 * i; j++) { cout << "D"; } + for (int j = 0; j < i; j++) { cout << "*"; } + cout << endl; + } + return 0; +} +int games[1010]; +int wallet[1010]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> games[i]; + for (int i = 0; i < m; i++) cin >> wallet[i]; + int j = 0; + int count = 0; + for (int i = 0; i < n; i++) { + if (games[i] <= wallet[j]) { + count++; + j++; + } + } + cout << count << endl; + return 0; +} +int main() { + string a; + cin >> a; + cout << ((a.size() + 1) * 26) - a.size() << endl; + return 0; +} +int main() { + char a[101]; + cin >> a; + int x = 0, y = 0; + for (int i = 0; a[i] != '\0'; i++) { + int flag = 0; + if (a[i] == '1') { + for (int j = i + 1; a[j] != '\0'; j++) { + if (a[j] == '0') x++; + if (x == 6) break; + } + flag = 1; + } + if (flag == 1) { break; } + } + if (x >= 6) { + cout << "yes" << endl; + } else { + cout << "no" << endl; + } + return 0; +} +int n, k, num[1000]; +int main() { + string a; + cin >> n >> k; + cin >> a; + for (int i = 0; i < n; i++) { num[a[i]]++; } + for (int i = 0; i < 1000; i++) { + if (num[i] > k) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +int n, m, ai, bi, mna = 10, mnb = 10; +bool ada_dia[10]; +bool ada_dib[10]; +int main() { + cin >> n >> m; + while (n--) { + cin >> ai; + ada_dia[ai] = 1; + mna = min(mna, ai); + } + while (m--) { + cin >> bi; + ada_dib[bi] = 1; + mnb = min(mnb, bi); + } + for (int i = 1; i < 10; i++) { + if (ada_dia[i] && ada_dib[i]) { + cout << i << '\n'; + return 0; + } + } + cout << min(mna, mnb) << max(mna, mnb) << '\n'; +} +int main() { + set st; + set::iterator it; + int n, m, i, j, x, y; + cin >> n >> m; + for (i = 0; i < n; i++) { + cin >> x; + for (j = 0; j < x; j++) { + cin >> y; + st.insert(y); + } + } + int s = st.size(); + if (m == s) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long pow(long long a, long long b, long long m) { + long long res = 1; + while (b) { + if (b & 1) { res = (res * a) % m; } + a = (a * a) % m; + b >>= 1; + } + return res; +} +int main() { + long long n, m; + cin >> n >> m; + cout << (pow(3, n, m) - 1 + m) % m << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int a[11][11]; + long long max = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == 1 || j == 1) + a[i][j] = 1; + else + a[i][j] = a[i - 1][j] + a[i][j - 1]; + if (a[i][j] > max) max = a[i][j]; + } + } + cout << max << endl; + return 0; +} +int n; +int arr[210]; +int main() { + cin >> n; + for (int i = 1; i <= 2 * n; ++i) { cin >> arr[i]; } + sort(arr + 1, arr + n + n + 1); + puts((arr[n] < arr[n + 1] ? "YES" : "NO")); + return 0; +} +int main() { + long long sum2, sum1; + sum2 = sum1 = 0; + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n / 2; i++) { + if (s[i] == '7' || s[i] == '4') + sum1 += (int)s[i]; + else + return cout << "NO" << endl, 0; + } + for (int i = n / 2; i < s.size(); i++) { + if (s[i] == '7' || s[i] == '4') + sum2 += (int)s[i]; + else + return cout << "NO" << endl, 0; + } + if (sum1 == sum2) { return cout << "YES" << endl, 0; } + return cout << "NO" << endl, 0; +} +int arr[105]; +int main() { + int m; + while (cin >> m) { + for (int i = 0; i < m; i++) cin >> arr[i]; + bool flag = 1; + int ans = 0; + while (flag) { + flag = 0; + int Max = -9999999; + int k = 1; + for (int i = 1; i < m; i++) { + if (arr[i] > Max) { + Max = arr[i]; + k = i; + } + } + if (Max >= arr[0]) { + arr[k]--; + arr[0]++; + ans++; + flag = 1; + } else + flag = 0; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + int a[1000], b[1000]; + for (int i = 1; i <= n; i++) { + cin >> a[i] >> b[i]; + if ((b[i] - a[i]) >= 2) sum++; + } + cout << sum << "\n"; + return 0; +} +long long mod = 1000000007; +double pi = 3.1415926535897932384626433832; +long long int fast_exp(long long int base, long long int ex) { + long long int res = 1; + while (ex > 0) { + if (ex % 2 == 1) res = (res * base) % mod; + base = (base * base) % mod; + ex /= 2; + } + return res % mod; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long cal(char a, char b) { + long long g = abs(a - b); + if (a - b == 13) return 13LL; + if (g > 13) g = 26 - g; + return g; +} +int main() { + string s; + cin >> s; + long long ans = 0; + ans += cal('a', s[0]); + for (int i = 0; i < s.length() - 1; i++) { ans += cal(s[i], s[i + 1]); } + cout << ans << "\n"; + return 0; +} +string awal, asli; +int gede, cilik; +int n; +int ans = 0; +int main() { + cin >> n; + cin >> awal; + cin >> asli; + for (int i = 0; i < n; i++) { + gede = max(awal[i], asli[i]); + cilik = min(awal[i], asli[i]); + ans += min(10 + cilik - gede, gede - cilik); + } + cout << ans << endl; + return 0; +} +int main() { + int s[1001], n, m, a, minn = 1000; + memset(s, 0, sizeof(s)); + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> a; + s[a]++; + } + for (int i = 1; i <= n; i++) + if (s[i] < minn) minn = s[i]; + cout << minn << endl; + return 0; +} +int main() { + int m; + cin >> m; + vector d(m); + for (int i = 0; i < m; ++i) { cin >> d[i]; } + sort(d.begin(), d.end()); + int n; + cin >> n; + vector p(n); + for (int i = 0; i < n; ++i) { cin >> p[i]; } + sort(p.begin(), p.end(), greater()); + int i = 0; + int ans = 0; + int dis = d[0]; + while (i < n) { + for (int j = 0; j < dis; ++j, i++) { + if (i >= n) break; + ans += p[i]; + } + i++; + if (i >= n) break; + i++; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + while (cin >> n) { + if (n <= 10 || n >= 22) { + cout << "0" << endl; + } else if (n == 20) { + cout << "15" << endl; + } else { + cout << "4" << endl; + } + } + return 0; +} +string s; +set root; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + sort(s.begin(), s.end() + 1); + s.erase(unique(s.begin(), s.end() + 1), s.end()); + root.insert(s); + } + cout << root.size() << endl; + return 0; +} +int main() { + int n, x, l, r; + cin >> n >> x; + int res = 0; + for (int i = 0, cur = 1; i < n; ++i) { + cin >> l >> r; + while (cur + x <= l) cur += x; + res += (r - cur + 1); + cur = r + 1; + } + cout << res << endl; + return 0; +} +int main() { + int n, count = 0; + cin >> n; + char c; + for (int i = 0; i < n; i++) { + cin >> c; + if (c == '8') count++; + } + if (n < 11 || count == 0) { + cout << 0 << endl; + return 0; + ; + } + cout << min(count, n / 11) << endl; + return 0; + ; +} +int main() { + int n; + cin >> n; + bool l = true; + while (n--) { + cout << "I "; + if (l) { + cout << "hate "; + } else { + cout << "love "; + } + l = !l; + if (n == 0) + cout << "it" << endl; + else + cout << "that "; + } + return 0; +} +const int N = 100010; +int a[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[(n + 1) / 2] << "\n"; + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h; + cin >> u1 >> d1; + cin >> u2 >> d2; + for (; h > 0; --h) { + w += h; + if (d1 == h) { w = max(0, w - u1); } + if (d2 == h) { w = max(0, w - u2); } + } + cout << w << endl; +} +const int MOD = 1e9 + 7; +const double pi = acos(-1.0); +const int maxn = 1000 + 5; +int solve, sum, ans; +int l, r; +int n, m; +int main() { + sum = 0; + ans = -1; + cin >> n; + for (int i = (0); i < (n); ++i) { + cin >> solve; + sum += solve; + } + cin >> m; + bool ok = false; + for (int i = (0); i < (m); ++i) { + cin >> l >> r; + if (!ok) { + if (l >= sum) { + ans = l; + ok = true; + continue; + } + if (r >= sum) { + ans = sum; + ok = true; + continue; + } + } + } + cout << ans << endl; +} +int main() { + int m; + cin >> m; + int a[m], s = 0, s1 = 0; + for (int i = 0; i < m; i++) { + cin >> a[i]; + s += a[i]; + } + int x, y; + cin >> x >> y; + for (int i = 0; i < m; i++) { + if ((s >= x && s <= y) && (s1 >= x && s1 <= y)) { + cout << i + 1 << endl; + return 0; + } + s -= a[i]; + s1 += a[i]; + } + cout << 0 << endl; + return 0; +} +int main() { + int n, j, i, r, a[200]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n - 1; i++) { + for (j = 0; j < n - 1 - i; j++) { + if (a[j] > a[j + 1]) { + r = a[j]; + a[j] = a[j + 1]; + a[j + 1] = r; + } + } + } + cout << a[n - 1] << " "; + for (i = 1; i < n - 1; i++) { cout << a[i] << " "; } + cout << a[0] << endl; + return 0; +} +int main() { + unsigned long long n; + cin >> n; + cout << 25 << endl; +} +int main() { + int n; + cin >> n; + long long arr[n + 2]; + for (int i = 0; i < n; i++) cin >> arr[i]; + long long size = 1, maxSize = INT_MIN, prev = arr[0]; + for (int i = 1; i < n; i++) { + if (arr[i] >= prev) { + ++size; + prev = arr[i]; + } else { + maxSize = max(maxSize, size); + prev = arr[i]; + size = 1; + } + } + maxSize = max(maxSize, size); + cout << maxSize << endl; + return 0; +} +int fcount = 0; +int bcount = 0; +int minsteps; +int n; +string os; +string comb; +int main() { + cin >> n >> os >> comb; + for (int i = 0; i < n; i++) { + int x = os[i]; + while (x != comb[i]) { + if (x == 57) { + x = 48; + fcount++; + } else { + x++; + fcount++; + } + } + int y = os[i]; + while (y != comb[i]) { + if (y == 48) { + y = 57; + bcount++; + } else { + y--; + bcount++; + } + } + if (fcount > bcount) { + minsteps += bcount; + } else { + minsteps += fcount; + } + fcount = 0; + bcount = 0; + } + cout << minsteps << endl; + return 0; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int a_post[n + 1], q_post[n + 1]; + a_post[n] = 0; + q_post[n] = 0; + int ans = 0; + for (int i = n - 1; i >= 0; i--) { + a_post[i] = a_post[i + 1]; + q_post[i] = q_post[i + 1]; + if (s[i] == 'A') + a_post[i]++; + else if (s[i] == 'Q') + q_post[i]++; + } + for (int i = 0; i < n; i++) { + if (i < n - 2 && s[i] == 'Q' && a_post[i] > 0 && q_post[i + 2] > 0) { + for (int j = i + 1; j < n - 1; j++) { + if (j < n - 1 && s[j] == 'A') ans += q_post[j + 1]; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + for (int j = 1; j <= 2 * (i - 1) + 1; j++) cout << "D"; + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + cout << "\n"; + } + for (int i = n / 2; i >= 1; i--) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + for (int j = 1; j <= 2 * (i - 1) + 1; j++) cout << "D"; + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + cout << "\n"; + } + return 0; +} +int main() { + long n, m; + cin >> n; + set s; + for (long i = 0; i < n; i++) { + cin >> m; + s.insert(m); + } + for (long i = 0; i < n; i++) + if (s.find(0) != s.end()) { + s.erase(s.find(0)); + break; + } + cout << s.size() << endl; + return 0; +} +int main() { + int n, d, seq[110]; + cin >> n >> d; + for (int i = 0; i < n; ++i) { cin >> seq[i]; } + sort(seq, seq + n); + int cnt = 0, start = 0, end = 0; + while (end < n) { + if (seq[end] - seq[start] <= d) { + cnt = max(cnt, end - start + 1); + ++end; + } else + ++start; + } + cout << n - cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, i, j, k, x; + char s[200]; + while (cin >> n) { + cin >> s; + k = strlen(s); + for (i = 0; i < k; i++) { + if (s[i] == 'o') { + for (j = i + 1; j < k; j += 2) { + if (s[j] == 'g' && s[j + 1] == 'o') { + if ((j - i) <= 2) { + s[i] = '*'; + s[j] = '*'; + s[j + 1] = '*'; + } else { + s[j] = '0'; + s[j + 1] = '0'; + } + } else { + i = j - 1; + break; + } + } + } + } + for (i = 0; i < k; i++) + if (s[i] != '0') cout << s[i]; + cout << endl; + } + return 0; +} +long long int f[1000001]; +int main() { + f[1] = 1; + f[2] = 3; + for (int i = 3; i < 1000001; ++i) f[i] = (2 * f[i - 1] - f[i - 3] + 1000000007) % 1000000007; + for (int n; cin >> n;) cout << f[n] << endl; +} +int main() { + long long n, c = 0, res = 0; + cin >> n; + if (n >= 100) { + c = n % 100; + res += n / 100; + n -= (n - c); + } + if (n >= 20) { + c = n % 20; + res += n / 20; + n -= (n - c); + } + if (n >= 10) { + c = n % 10; + res += n / 10; + n -= (n - c); + } + if (n >= 5) { + c = n % 5; + res += n / 5; + n -= (n - c); + } + if (n != 0) res += n; + cout << res << endl; + return 0; +} +bool suc[101]; +char gr[101][101]; +int g[101][101], n, m, maxk[101], nas; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> gr[i][j]; + g[i][j] = gr[i][j] - '0'; + maxk[j] = max(maxk[j], g[i][j]); + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (maxk[j] == g[i][j]) { + suc[i] = true; + nas++; + break; + } + } + } + cout << nas << endl; +} +set st; +int main() { + int n; + cin >> n; + bool ok = true; + int ans = 0; + for (int i = 0; i < 26; i++) st.insert((char)('a' + i)); + while (n--) { + char c; + cin >> c; + ; + string s; + cin >> s; + if (n == 0) break; + if (ok) { + if (c == '!') { + set sst; + for (int i = 0; i < s.size(); i++) + if (st.count(s[i])) sst.insert(s[i]); + st.clear(); + for (set::iterator it = sst.begin(); it != sst.end(); it++) st.insert(*it); + } else { + for (int i = 0; i < s.size(); i++) + if (st.count(s[i])) st.erase(s[i]); + } + if (st.size() == 1) ok = false; + } else { + if (c != '.') ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + int grid[20][20]; + while (cin >> n) { + for (int i = 0; i < n; i++) grid[0][i] = 1; + for (int i = 0; i < n; i++) grid[i][0] = 1; + int mx = 1; + for (int i = 1; i < n; i++) + for (int j = 1; j < n; j++) { + grid[i][j] = grid[i - 1][j] + grid[i][j - 1]; + mx = max(mx, grid[i][j]); + } + cout << mx << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; ++i) cin >> v[i]; + sort(v.begin(), v.end()); + int dist = v.back() - v.front(), cnt = 0; + for (int i = 1; i < n; ++i) { + int dist1 = v[i] - v[i - 1]; + if (dist1 < dist) { + dist = dist1; + cnt = 1; + } else if (dist1 == dist) { + cnt++; + } + } + cout << dist << ' ' << cnt << endl; + return 0; +} +int search_NOK(int, int); +int main() { + int first, second, a; + cin >> first >> second >> a; + cout << a / search_NOK(first, second); + cout << endl; + return 0; +} +int search_NOK(int x, int y) { + int count = (x > y) ? x : y; + for (int i = count;; i++) + if (!(i % x) && !(i % y)) return i; +} +int main() { + int t, n, m; + cin >> n >> m; + int k = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 1) + cout << '#'; + else if (i % 2 == 0 && k == 0) { + if (j == m) + cout << '#'; + else + cout << '.'; + if (j == m) k = 1; + } else if (i % 2 == 0 && k == 1) { + if (j == 1) + cout << '#'; + else + cout << '.'; + if (j == m) k = 0; + } + } + cout << endl; + } +} +int main() { + int n, a, b; + int counter = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (b - a >= 2) counter++; + } + cout << counter << endl; +} +int main() { + int n, m; + cin >> n >> m; + int k = n + (n - 1) / (m - 1); + cout << k << endl; + return 0; +} +void fast() {} +void file() {} +string inttostr(int n) { + stringstream ss; + ss << n; + return ss.str(); +} +int main() { + fast(); + file(); + long long n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int home[n], away[n]; + int ctr = 0; + for (int i = 0; i < n; i++) cin >> home[i] >> away[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (home[i] == away[j]) ctr++; + } + } + cout << ctr << endl; + return 0; +} +int main() { + int N, M; + cin >> M; + int discountQuantity = 1000000007; + for (int i = 1; i <= M; i++) { + int quantity; + cin >> quantity; + discountQuantity = min(discountQuantity, quantity); + } + cin >> N; + vector prices; + for (int i = 1; i <= N; i++) { + int price; + cin >> price; + prices.push_back(price); + } + sort(prices.begin(), prices.end()); + int costToPay = 0; + int toPurchase = N - 1; + while (toPurchase >= 0) { + int purchaseQuantity = discountQuantity; + while (purchaseQuantity && toPurchase >= 0) { + costToPay += prices[toPurchase]; + toPurchase--; + purchaseQuantity--; + } + toPurchase -= 2; + } + cout << costToPay << endl; + return 0; +} +int main() { + long long n, i, min, max, c = 0; + cin >> n; + long long a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + min = a[0]; + max = a[0]; + c = 0; + for (i = 0; i < n; i++) { + if (a[i] < min) { + c++; + min = a[i]; + } + if (a[i] > max) { + c++; + max = a[i]; + } + } + cout << c << endl; + return 0; +} +const int mod = 998244353; +const int MAX = 1005; +void ONLINE__JUDGE(); +int num, x; +string y; +bool valid(char a, char b) { + if (a - 1 == b - 1 || a - 1 == b + 1) return 1; + if (a + 1 == b - 1 || a + 1 == b - 1) return 1; + return 0; +} +int main() { + cin >> num; + for (int i = 0; i < num; i++) { + cin >> x >> y; + bool check = 1; + for (int st = 0, ed = x - 1; st < x / 2; st++, ed--) { + if (y[st] != y[ed]) { + if (!valid(y[st], y[ed])) { + cout << "NO" << endl; + check = 0; + break; + } + } + } + if (check) { cout << "YES" << endl; } + } + return 0; +} +void ONLINE__JUDGE() {} +int main() { + int a, e = 0, f = 0; + cin >> a; + char b[a][a], c, d; + for (int i = 0; i < a; ++i) { + for (int j = 0; j < a; ++j) { cin >> b[i][j]; } + } + c = b[0][0]; + d = b[0][1]; + for (int i = 0, j = 0; i < a; ++i && j++) { + if (b[i][j] == c) { e++; } + } + for (int i = 0, j = a - 1; i < a; ++i && --j) { + if (b[i][j] == c) { e++; } + } + for (int i = 0; i < a; ++i) { + for (int j = 0; j < a; ++j) { + if (b[i][j] == d) { f++; } + } + } + if (a % 2 == 0) { + if (e == 2 * a && f == a * a - 2 * a) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } else { + if (e == 2 * a && f == a * a - 2 * a + 1) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } +} +int main() { + int n; + while (cin >> n) { + int v[120] = {0}; + int k, a; + cin >> k; + while (k--) { + cin >> a; + v[a] = 1; + } + cin >> k; + while (k--) { + cin >> a; + v[a] = 1; + } + int i; + for (i = 1; i <= n; i++) + if (!v[i]) break; + if (i == n + 1) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int main() { + int t; + set a; + cin >> t; + for (int i = 1; i <= t; i++) { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + a.insert(s); + } + cout << a.size() << endl; + return 0; +} +const int N = 2e5 + 1; +int n, a[N], ans = 1e9; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + int x = n / 2; + for (int i = 1; i <= n; i++) { + if (i + x <= n) { ans = min(ans, a[i + x] - a[i]); } + } + cout << ans << endl; +} +int main() { + long long N; + cin >> N; + long long x[N + 5]; + for (int i = 1; i <= N; i++) { cin >> x[i]; } + bool cek[N + 5]; + sort(x + 1, x + N + 1); + long long tmp = N / 2; + long long mini = 1e18; + for (int i = tmp + 1; i <= N; i++) { mini = min(mini, x[i] - x[i - tmp]); } + cout << mini << "\n"; +} +int main() { + int n, d, dist[105], s; + cin >> n; + s = n; + memset(dist, 0, sizeof(dist)); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> d; + if (d == 1) dist[i]++; + if (d == 2) dist[j]++; + if (d == 3) { + dist[i]++; + dist[j]++; + } + } + } + for (int i = 0; i <= n; i++) { + if (dist[i] != 0) s--; + } + cout << s << endl; + int flot = 1; + for (int i = 1; i <= n; i++) { + if (dist[i] == 0 && flot) { + cout << i; + flot = 0; + } else if (dist[i] == 0 && !flot) + cout << " " << i; + } + if (s) cout << endl; + return 0; +} +int main() { + int n, a, b; + string s; + int ans; + cin >> n >> a >> b >> s; + if (s[a - 1] == s[b - 1]) { + ans = 0; + } else { + ans = 1; + } + cout << ans << '\n'; + return 0; +} +int main() { + long long n, x = 0, count = 0, boxes = 0; + cin >> n; + long long i = 1; + long long j = 1; + while (boxes + i + x <= n) { + x += i; + i += j; + count++; + boxes += x; + } + cout << count << endl; +} +int main() { + string a, b; + cin >> a >> b; + int l = a.size(), ll = b.size(); + if (l != ll) { + cout << max(l, ll) << endl; + } else if (a == b) { + cout << -1 << endl; + } else { + cout << a.size() << endl; + } + return 0; +} +int main() { + int n, y = 0, z = 0, a = 0; + cin >> n; + string s1, s2; + cin >> s1; + for (int i = 0; i < n; i++) { + s2 = s1[i]; + if (i < n / 2) { + int x = atoi(s2.c_str()); + y += x; + } else { + int x = atoi(s2.c_str()); + z += x; + } + if (s1[i] != '4' && s1[i] != '7') a++; + } + if (y == z && a == 0) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; +} +int main() { + int n, m; + while (cin >> n >> m) { + int x = n / 2, k = 1, l = 0; + for (int i = 0; i < n; i++) { + if (k == 1) { + for (int j = 0; j < m; j++) cout << "#"; + cout << endl; + k = 2; + l++; + } else if (k == 2 && (l % 2 == 1)) { + for (int j = 0; j < m - 1; j++) cout << "."; + cout << "#" << endl; + k = 1; + } else if (k == 2 && (l % 2 == 0)) { + cout << "#"; + for (int j = 0; j < m - 1; j++) cout << "."; + cout << endl; + k = 1; + } + } + } + return 0; +} +int a[300000]; +int ju7(int x, int y) { + if (x % 10 == 7) + return 1; + else if (y % 10 == 7) + return 1; + else + return 0; +} +void ag(int x, int &h, int &m) { + if (m >= x) + m -= x; + else if (h > 0) { + h--; + m += 60; + m -= x; + } else if (h == 0) { + h = 23; + m += 60; + m -= x; + } +} +int main() { + int x, cnt = 0; + cin >> x; + int h, m; + cin >> h >> m; + while (ju7(h, m) != 1) { + cnt++; + ag(x, h, m); + } + cout << cnt << endl; + return 0; +} +int main() { + string a = ""; + cin >> a; + int i, j, l, c = 0, s = 0, d = 0; + l = a.size(); + for (i = 0; i < l; i++) { + if (a[i] >= 'A' && a[i] <= 'Z') { + c = 1; + } else if (a[i] >= 'a' && a[i] <= 'z') { + s = 1; + } else if (a[i] >= '0' && a[i] <= '9') { + d = 1; + } + } + if (d && c && s && l >= 5) { + cout << "Correct" << endl; + return 0; + } else { + cout << "Too weak" << endl; + return 0; + } +} +int main() { + int t, left, right, times; + long long ans; + cin >> t; + while (t--) { + cin >> right >> left >> times; + long long tem = right - left; + ans = 0; + if (times % 2 == 0) { + ans = tem * times / 2; + } else { + ans = tem * (times - 1) / 2 + right; + } + cout << ans << endl; + } + return 0; +} +const int maxn = 1000005; +const int INF = 0x3fffffff; +const int mod = 1e9 + 7; +double eps = 1e-8; +double pi = acos(-1); +long long quick_pow(long long a, long long n) { + long long ans = 1; + while (n) { + if (n & 1) ans = ans * a % mod; + a = a * a % mod; + n >>= 1; + } + return ans; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + int n; + while (cin >> n) { + int maxx = 0; + int minn = INF; + int flag = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + maxx = max(maxx, x); + minn = min(minn, x); + if (x % 2) flag = 1; + } + if (flag == 0) { + int temp = gcd(maxx, minn); + int cnt = maxx / temp; + cnt = cnt - n; + if (cnt % 2) { + cout << "Alice" << endl; + } else + cout << "Bob" << endl; + continue; + } + int ans = maxx - n; + if (ans % 2) { + cout << "Alice" << endl; + } else + cout << "Bob" << endl; + } +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (b) { + int d = b % 10; + c = c * 10 + d; + b /= 10; + } + cout << a + c << endl; + return 0; +} +int main() { + int k, r; + cin >> k >> r; + int i = 1; + while (k * i % 10 != r && k * i % 10 != 0) { i++; } + cout << i << endl; +} +int main() { + int n; + cin >> n; + string s; + set x, y; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < n; j++) + if (i == j or i + j == n - 1) + x.insert(s[j]); + else + y.insert(s[j]); + } + if (x.size() == 1 and y.size() == 1 and *x.begin() != *y.begin()) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const long long inf = LLONG_MAX; +const long long arr = 1000000; +int main() { + long long n; + cin >> n; + string s, ans = ""; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'o') { + bool f = false; + int j = 0; + for (j = i + 1; j < n - 1; j += 2) + if (s[j] == 'g' && s[j + 1] == 'o') + f = true; + else + break; + if (f) + ans += "***", i = j - 1; + else + ans += s[i]; + } else + ans += s[i]; + } + cout << ans << '\n'; + return 0; +} +const int MAX = 10010; +long long max0 = MAX * MAX; +int main() { + int k, n, s, p, i, j; + cin >> k >> n >> s >> p; + int one = s * p; + for (i = 1; i < max0; i++) { + int sumpp = p * i; + if (sumpp / k * s >= n) { break; } + } + cout << i << endl; + return 0; +} +int a[1005]; +bool zhi(int n) { + for (int i = 2; i < n; i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int n; + while (cin >> n) { + if (n == 1) { + cout << 0 << endl; + continue; + } + memset(a, 0, sizeof(a)); + int j = 0; + for (int i = 2; i <= n; i++) { + if (zhi(i)) { + a[j] = i; + j++; + int t = i; + t *= i; + while (t <= n) { + a[j] = t; + j++; + t *= i; + } + } + } + cout << j << endl; + for (int i = 0; i < j - 1; i++) { cout << a[i] << " "; } + cout << a[j - 1] << endl; + } +} +int main() { + long long n, i, j, k, ans, s0, s1; + cin >> n; + vector dp(n, 0); + s0 = 0; + s1 = 0; + ans = 0; + for (i = 0; i < n; i++) { + if (i % 2 == 0) + dp[i] = 1 + s1, s0 = (s0 + dp[i]) % 1000000007; + else + dp[i] = 1 + s0, s1 = (s1 + dp[i]) % 1000000007; + ans = (ans + dp[i]) % 1000000007; + } + cout << ans << "\n"; + return 0; +} +int cost[100005]; +int lef[100005]; +int righ[100005]; +long long min(long long a, long long b) { + if (a >= b) return b; + return a; +} +int main() { + int n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + for (int i = 0; i < n; i++) cin >> cost[i]; + lef[0] = 0; + for (int i = 1; i <= n; i++) lef[i] = lef[i - 1] + cost[i - 1]; + righ[n + 1] = 0; + for (int i = n; i >= 1; i--) righ[i] = righ[i + 1] + cost[i - 1]; + long long ans = 10000000000000; + int ind = -1; + for (int i = 0; i <= n; i++) { + long long curr = lef[i] * l + righ[i + 1] * r; + if (i < n - i) + curr += (n - 2 * i - 1) * qr; + else if (n - i < i) { + curr += (2 * i - n - 1) * ql; + } + if (ans > curr) { + ans = curr; + ind = i; + } + ans = min(ans, curr); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector vv; + vv.resize(n - 1); + for (int i = 0; i < n - 1; i++) { + int num; + cin >> num; + vv[i] = num; + } + sort(vv.begin(), vv.end()); + for (int i = 0; i < n; i++) { + if (vv[i] != i + 1) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int main() { + int n; + long long c1, c2; + cin >> n >> c1 >> c2; + int cnt = 0; + for (int i = 1; i <= n; i++) { + char c; + cin >> c; + if (c == '1') cnt++; + } + long long ans = 1e18; + for (int i = 1; i <= cnt; i++) { + long long p = n / i, mod = n % i; + long long now = (p - 1) * (p - 1) * c2 * (i - mod) + c1 * i + p * p * mod * c2; + ans = min(ans, now); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c = 0, m = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + c = c + b - a; + if (m < c) m = c; + } + cout << m << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[105]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int min_ = 0x3f3f3f3f; + for (int i = 1; i < n - 1; i++) { + int t = a[i]; + a[i] = a[i + 1]; + int max_ = -0x3f3f3f3f; + for (int j = 0; j < n - 1; j++) { + if (abs(a[j] - a[j + 1]) > max_) { max_ = abs(a[j] - a[j + 1]); } + } + if (max_ < min_) min_ = max_; + a[i] = t; + } + cout << min_ << endl; +} +const int MAX = 1e5 + 5; +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int freq[10], x, d1; +int main() { + cin >> x; + for (int i = 0; i < 10; i++) { + if (i == 0 || i == 2 || i == 6 || i == 9) freq[i] += 2; + if (i == 1) freq[i] += 7; + if (i == 3 || i == 4) freq[i] += 3; + if (i == 7) freq[i] += 5; + if (i == 8) freq[i] += 1; + if (i == 5) freq[i] += 4; + } + d1 = x % 10; + x /= 10; + cout << freq[d1] * freq[x] << endl; + return 0; +} +int main() { + int n; + cin >> n; + map cont; + for (int i = 0; i < n; i++) { + char tipo; + string s; + cin >> tipo >> s; + for (int c = 0; c < s.length(); c++) { + if (s[c] == '0' || s[c] == '2' || s[c] == '4' || s[c] == '6' || s[c] == '8') { + s[c] = '0'; + } else { + s[c] = '1'; + } + } + string usa; + for (int c = 0; c < 20 - s.length(); c++) { usa += '0'; } + usa += s; + if (tipo == '+') { + cont[usa] += 1; + } else if (tipo == '-') { + cont[usa] -= 1; + } else { + cout << cont[usa] << endl; + } + } + return 0; +} +int main() { + int l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (int i = l, j = x; i <= r && j <= y;) { + if (i / j == k && i % j == 0) { + cout << "YES" << endl; + return 0; + } else if (i / j >= k) { + j++; + } else { + i++; + } + } + cout << "NO" << endl; + return 0; +} +const int MOD = 1e9 + 9; +int main() { + int n, m; + cin >> n >> m; + int can = 1; + for (int i = 0; i < m; i++) { can = 2LL * can % MOD; } + can--; + int ans = 1; + for (int i = 0; i < n; i++) { + ans = (long long)ans * can % MOD; + can--; + } + cout << ans << endl; +} +int main() { + string s[8]; + for (int i = 0; i < 8; i++) cin >> s[i]; + int fg = 0; + for (int i = 0; i < 8; i++) { + fg = 0; + for (int j = 0; j < 7; j++) { + if (s[i][j] == s[i][j + 1]) { + fg = 1; + break; + } + } + if (fg == 1) { break; } + } + if (fg) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int n, k, c, ans; +int day[400]; +int main() { + cin >> n >> k >> c; + for (int i = 0; i < c; i++) cin >> day[i]; + ans = c; + for (int i = 1; i < c; i++) ans += (day[i] - day[i - 1] - 1) / k; + if (c != 0) ans += (day[0] - 1) / k; + ans += (n - ((c == 0) ? 0 : day[c - 1])) / k; + if (ans == 0) ans++; + cout << ans << '\n'; + return 0; +} +int main() { + string binarycoding; + cin >> binarycoding; + vector v(10); + for (int i = 0; i < 10; i++) cin >> v[i]; + int c = 0; + string temp; + for (int i = 0; i <= binarycoding.size(); i++) { + if (c == 10) { + c = 0; + for (int i = 0; i < v.size(); i++) { + if (v[i] == temp) { + cout << i; + break; + } + } + temp.clear(); + } + c++; + temp += binarycoding[i]; + } + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + char c[n]; + int a[n]; + cin >> c; + for (int i = 0; i < n; i++) { cin >> a[i]; } + long long min = 9223372036854775807, f = 1; + for (int i = 0; i < n - 1; i++) { + if (c[i] == c[i + 1]) { + continue; + } else if (c[i] == 'R' && c[i + 1] == 'L') { + long long x = (a[i + 1] - a[i]) / 2; + if (x < min) { + min = x; + f = 0; + } + } + } + if (f == 1) { + cout << "-1" << endl; + return 0; + } else { + cout << min << endl; + return 0; + } +} +const int INF = 0x3f3f3f3f; +int v[105]; +int main() { + int i, j, k; + int n, m, x; + cin >> n; + for (i = 0; i < n; i++) cin >> x, v[x]++; + sort(v, v + 101); + cout << v[100] << endl; +} +const int Maxn = 3010, INF = 0x3f3f3f3f; +int main() { + long long n; + cin >> n; + if (n == 0) + cout << 1 << endl; + else + cout << ((long long)(n * sqrt(2))) * 4 << endl; +} +int main() { + int count, sol = 0; + string c; + cin >> c; + int i = 0; + while (i < c.size()) { + count = 0; + if (c[i] == 'A') { + while (c[i] == 'A' && i < c.size()) { + count++; + i++; + } + if (count % 2 == 0) sol++; + } + count = 0; + if (c[i] == 'C' && i < c.size()) { + while (c[i] == 'C' && i < c.size()) { + count++; + i++; + } + if (count % 2 == 0) sol++; + } + count = 0; + if (c[i] == 'T' && i < c.size()) { + while (c[i] == 'T' && i < c.size()) { + count++; + i++; + } + if (count % 2 == 0) sol++; + } + count = 0; + if (c[i] == 'G' && i < c.size()) { + while (c[i] == 'G' && i < c.size()) { + count++; + i++; + } + if (count % 2 == 0) sol++; + } + } + cout << sol << endl; + return 0; +} +int main() { + int n, a[101]; + cin >> n; + int s = 0, max = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + max = a[0]; + } + for (int i = 1; i < n; i++) { + if (max < a[i]) { max = a[i]; } + } + for (int i = 0; i < n; i++) { s = s + abs(max - a[i]); } + cout << s << endl; + return 0; +} +int main() { + long long int n, i, k; + cin >> n >> k; + string s; + cin >> s; + long long int rf, lf = k - 1; + rf = s.length() - k; + if (lf < rf) { + for (i = 0; i < lf; i++) cout << "LEFT\n"; + for (i = 0; i < s.length(); i++) { + cout << "PRINT " << s[i] << '\n'; + if (i + 1 < s.length()) cout << "RIGHT\n"; + } + } else { + for (i = 0; i < rf; i++) cout << "RIGHT\n"; + for (i = s.length() - 1; i >= 0; i--) { + cout << "PRINT " << s[i] << '\n'; + if (i != 0) cout << "LEFT\n"; + } + } + return 0; +} +int n, i, a[111111], p, t, k; +int main() { + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> p >> t; + a[p * 50 - t]++; + } + t = 10000; + while (a[t] < k) k -= a[t--]; + cout << a[t] << endl; + return 0; +} +const long long ss = 10000002; +int a[1000001]; +int cift[1000001]; +int tek[1000001]; +int doIt(int a, int b) { + int c = 0; + while (b > 0) { + c = c + a / b; + int t_ab = a % b; + int t_a = a; + int t_b = b; + a = b; + b = t_ab; + } + return c; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + int c = doIt(max(a, b), min(a, b)); + cout << c << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long n, x, y, d; + cin >> n >> x >> y >> d; + if (abs(y - x) % d == 0) { + cout << abs(y - x) / d << '\n'; + continue; + } + long long ans = INT_MAX; + if (abs(1 - y) % d == 0) { + ans = (abs(1 - y) / d) + (abs(1 - x) / d); + if (abs(1 - x) % d != 0) { ans++; } + } + if (abs(n - y) % d == 0) { + long long ans2 = (abs(n - y) / d) + (abs(n - x) / d); + if (abs(n - x) % d != 0) { ans2++; } + ans = min(ans, ans2); + } + if (ans == INT_MAX) + cout << -1 << '\n'; + else + cout << ans << '\n'; + } + return 0; +} +int main() { + string n1, n2; + cin >> n1 >> n2; + int n; + cin >> n; + cout << n1 << " " << n2 << endl; + for (int i = 0; i < n; i++) { + string na1, na2; + cin >> na1 >> na2; + if (na1 == n1) { + n1 = na2; + } else { + n2 = na2; + } + cout << n1 << " " << n2 << endl; + } +} +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int c = 1, maxx = INT_MIN; + for (int i = 0; i < n - 1; i++) { + if (a[i + 1] < a[i]) { + maxx = maxx > c ? maxx : c; + c = 1; + } else { + c++; + } + maxx = maxx > c ? maxx : c; + } + maxx = maxx > c ? maxx : c; + cout << maxx << endl; +} +int main() { + int n; + cin >> n; + int a[1001]; + int flag = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + cout << "-1" << endl; + flag = 1; + } + } + if (flag == 0) { cout << "1" << endl; } + return 0; +} +int freq[10000005]; +int n, m; +int main() { + cin >> n >> m; + int mat[n][2]; + memset(freq, 0, sizeof freq); + for (int i = 0; i < n; i++) { + cin >> mat[i][0] >> mat[i][1]; + for (int j = (mat[i][0]) + 1; j <= mat[i][1]; j++) freq[j]++; + } + for (int i = 1; i <= m; i++) { + if (!freq[i]) { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int main() { + long long int temp, n, s, i, j; + cin >> n; + vector ans; + for (i = 1; i <= 81; i++) { + temp = n - i; + j = temp; + s = 0; + while (temp > 0) { + s += (temp % 10); + temp = temp / 10; + } + if (s == i) { ans.push_back(j); } + } + sort(ans.begin(), ans.end()); + cout << ans.size() << endl; + for (i = 0; i < ans.size(); i++) cout << ans[i] << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long a[n]; + long long r = m; + for (long long int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long p = a[n - 1]; + while (m > 0) { + a[0]++; + sort(a, a + n); + m--; + } + long long q = a[n - 1]; + cout << q << " " << p + r << "\n"; + return 0; +} +int p[9], ap[9]; +int main() { + int a[110], b[110], n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + p[a[i]]++; + ap[a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + p[b[i]]++; + } + for (int i = 1; i < 6; i++) { + if (p[i] % 2) { + cout << -1 << endl; + return 0; + } + p[i] /= 2; + } + int cnt = 0; + for (int i = 1; i < 6; i++) { + if (ap[i] > p[i]) cnt += ap[i] - p[i]; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + long long int sum = 0; + while (n--) { + int a; + cin >> a; + sum += a; + } + if (sum == 0) { + cout << "0" + << "\n"; + } else { + if (abs(sum) % x == 0) { + cout << abs(sum) / x << "\n"; + } else { + cout << (int)(abs(sum) / x) + 1 << "\n"; + } + } +} +int main() { + int a, b, c, t, l, i, j, sum = 0, count = 0, m; + cin >> a >> b; + for (i = 1; i <= a; i++) { + cin >> c; + sum += c; + m = min(8, sum); + sum -= m; + b -= m; + count++; + if (b <= 0) { break; } + } + if (b > 0) { + cout << -1 << endl; + } else { + cout << count << endl; + } +} +const long long N = 1011; +string s; +long long n, p; +long long cel[N]; +long long ans[N]; +bool ok = false; +void encontrado(long long pos, long long val) { + ans[pos] = val; + if (pos == 0) { + ok = true; + return; + } + pos--; + for (long long i = 0; i < p; i++) { + if (pos + 2 < n) { + if (i != ans[pos + 1] && i != ans[pos + 2]) { + encontrado(pos, i); + if (ok) return; + } + } else if (pos + 1 < n) { + if (i != ans[pos + 1]) { + encontrado(pos, i); + if (ok) return; + } + } + } + return; +} +void brute_force(long long pos) { + for (long long i = cel[pos] + 1; i < p; i++) { + if (pos + 2 < n) { + if (i != cel[pos + 1] && i != cel[pos + 2]) { + encontrado(pos, i); + if (ok) return; + } + } else if (pos + 1 < n) { + if (i != cel[pos + 1]) { + encontrado(pos, i); + if (ok) return; + } + } else { + encontrado(pos, i); + if (ok) return; + } + } + if (!ok && pos + 1 < n) { brute_force(pos + 1); } + return; +} +int main() { + cout.precision(10); + cout << fixed; + cin >> n >> p; + cin >> s; + reverse(s.begin(), s.end()); + for (long long i = 0; i < n; i++) { + cel[i] = s[i] - 'a'; + ans[i] = cel[i]; + } + brute_force(0); + if (!ok) { + cout << "NO" << endl; + } else { + for (long long i = n - 1; i >= 0; i--) { cout << char(ans[i] + 'a'); } + cout << endl; + } + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + m = m - 1; + vector s(n); + for (int i = 0; i < n; i++) cin >> s[i]; + int fir = n * 10; + int las = n * 10; + for (int i = 0; i < m; i++) { + if (s[i] != 0 && s[i] <= k) { + fir = m - i; + fir = fir * 10; + } + } + for (int i = m + 1; i < n; i++) { + if (s[i] != 0 && s[i] <= k) { + las = i - m; + las = las * 10; + break; + } + } + cout << min(fir, las) << endl; + return 0; +} +const int M = 200 + 5; +int a[M][2]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } + int num = 0; + for (int i = 0; i < n; i++) { + int num1 = 0; + for (int j = 0; j < n; j++) { + if (i != j) { + if (a[j][0] == a[i][0] && a[j][1] > a[i][1]) { + num1++; + break; + } + } + } + for (int j = 0; j < n; j++) { + if (i != j) { + if (a[j][0] == a[i][0] && a[j][1] < a[i][1]) { + num1++; + break; + } + } + } + for (int j = 0; j < n; j++) { + if (i != j) { + if (a[j][0] > a[i][0] && a[j][1] == a[i][1]) { + num1++; + break; + } + } + } + for (int j = 0; j < n; j++) { + if (i != j) { + if (a[j][0] < a[i][0] && a[j][1] == a[i][1]) { + num1++; + break; + } + } + } + num = num + (num1 == 4); + } + cout << num << endl; + return 0; +} +int main() { + vector cards(5); + string ref; + cin >> ref; + for (long long i = 0; i < 5; i++) { + cin >> cards[i]; + if (cards[i][0] == ref[0] || cards[i][1] == ref[1]) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + int n, k, t, d; + cin >> n >> t >> k >> d; + int g = (n + k - 1) / k; + int x1 = 0, x2 = d; + for (int i = 0; i < g; i++) { + if (x1 <= x2) + x1 += t; + else + x2 += t; + } + if (max(x1, x2) < g * t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int num = 0, x, y; + for (int i = 0; i < len; i++) { + x = 0, y = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + x++, y++; + else if (s[j] == ')') + x--, y--; + else + x++, y--; + if (x < 0) break; + if (y < 0) y = 0; + if ((j - i + 1) % 2 == 0 && y == 0) num++; + } + } + cout << num << '\n'; + return 0; +} +int main() { + string str[41]; + int n, p, i, flag = 0; + long long a = 0; + cin >> n >> p; + for (i = 1; i <= n; i++) { cin >> str[i]; } + if (str[i - 1] == "halfplus") { + a += p / 2; + flag++; + } + for (int j = i - 2; j > 0; j--) { + if (str[j] == "halfplus") { + a = a + (a + flag * p / 2 + p / 2); + flag++; + } + if (str[j] == "half") { a = a + (a + flag * p / 2); } + } + cout << a << endl; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a.begin(), a.end()); + int l = 0; + int r = n - 1; + while (a[l] != a[r]) { + a[r] -= a[l]; + sort(a.begin(), a.end()); + } + int sum = 0; + for (int i = 0; i < n; i++) sum += a[i]; + cout << sum << endl; + return 0; +} +int main() { + string a, b, t, t1 = "1"; + cin >> a >> b; + t = (a == b ? a : t1); + cout << t << endl; + return 0; +} +int main() { + int a, b, c, r; + cin >> a >> b >> c; + r = ((a - b) * c + (b - 1)) / b; + cout << r << endl; + return 0; +} +int main() { + int n, a[5555]; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int factorial(int a) { + if (a == 1) return 1; + return a * factorial(a - 1); +} +int main() { + int a, b; + cin >> a >> b; + if (a > b) { + cout << factorial(b) << endl; + } else { + cout << factorial(a) << endl; + } + return 0; +} +int countSubseq(string a, string b) { + int m = a.length(); + int n = b.length(); + int dp[m + 1][n + 1] = {{0}}; + for (int i = 0; i <= n; ++i) dp[0][i] = 0; + for (int i = 0; i <= m; ++i) dp[i][0] = 1; + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (a[i - 1] == b[j - 1]) + dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; + else + dp[i][j] = dp[i - 1][j]; + } + } + return dp[m][n]; +} +int main() { + string n; + cin >> n; + cout << countSubseq(n, "QAQ") << endl; + return 0; +} +int main() { + int ashu = 0, bshu = 0; + string a, b; + cin >> a; + cin >> b; + for (int i = 0; i < a.length(); i += 2) { + if (a[i] == '[' && a[i + 1] == ']' && b[i] == '(' && b[i + 1] == ')') { ashu++; } + if (a[i] == '(' && a[i + 1] == ')' && b[i] == '[' && b[i + 1] == ']') { bshu++; } + if (a[i] == '(' && a[i + 1] == ')' && b[i] == '8' && b[i + 1] == '<') { ashu++; } + if (a[i] == '8' && a[i + 1] == '<' && b[i] == '(' && b[i + 1] == ')') { bshu++; } + if (a[i] == '8' && a[i + 1] == '<' && b[i] == '[' && b[i + 1] == ']') { ashu++; } + if (a[i] == '[' && a[i + 1] == ']' && b[i] == '8' && b[i + 1] == '<') { bshu++; } + } + if (ashu > bshu) { + cout << "TEAM 1 WINS" << endl; + } else if (ashu < bshu) { + cout << "TEAM 2 WINS" << endl; + } else { + cout << "TIE" << endl; + } + return 0; +} +int maxsum, minsum, a[1005], n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 2; i < n; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) { maxsum++; } + if (a[i] < a[i - 1] && a[i] < a[i + 1]) { minsum++; } + } + cout << maxsum + minsum << endl; + return 0; +} +int main() { + long long n, m; + while (cin >> n >> m) { + int flag = 0; + for (int i = 1; i <= n; i++) { + int k = m / i; + if (m % i == 0 && k <= n) flag++; + } + cout << flag << endl; + } +} +long long check(long long y) { + long long cnt[10] = {0}; + while (y) { + cnt[y % 10]++; + y = y / 10; + } + for (long long i = 0; i < 10; i++) { + if (cnt[i] > 1) { return 0; } + } + return 1; +} +int main() { + long long year; + cin >> year; + for (long long i = year + 1; i <= 10000; i++) { + if (check(i)) { + cout << i << "\n"; + return 0; + } + } +} +const int N = 2010; +const long long MAX = 1e8 + 5; +int n, a, ans, flag; +char s[N]; +int main() { + cin >> n; + ans = 0; + while (n--) { + flag = 0; + for (int i = 0; i < 3; i++) { + cin >> a; + if (a) flag++; + } + if (flag >= 2) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + long long int n; + int ct = 0, rem; + cin >> n; + while (n > 0) { + rem = n % 10; + if (rem == 4 || rem == 7) { ct++; } + n = n / 10; + } + if (ct == 4 || ct == 7) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +char a[110], c; +int main() { + register int n, d, ans = 0, i, j, cnt; + cin >> n >> d; + memset(a, 1, sizeof(a)); + a[0] = 0; + for (i = 1; i <= d; ++i) { + for (j = 1; j <= n; ++j) { + cin >> c; + a[i] &= (c - '0'); + } + } + for (i = 1, cnt = 0; i <= d; ++i) { a[i] == 0 ? ++cnt : cnt = 0, ans = max(ans, cnt); } + cout << max(ans, cnt) << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + int n; + string s; + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << "2" << endl; + cout << s[0] << ' '; + for (int i = 1; s[i]; ++i) cout << s[i]; + cout << endl; + } + } + return 0; +} +const int maxn = 1e5 + 5; +bool num[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n - 1; i++) { + int m; + cin >> m; + num[m] = 1; + } + for (int i = 1; i <= n; i++) { + if (!num[i]) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int i, j; + int n, m; + int count = 0; + cin >> n >> m; + char a[n][m], ch[n], max; + int s[n]; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cin >> a[i][j]; } + s[i] = 0; + } + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { ch[j] = a[j][i]; } + for (int k = 0; k < n - 1; k++) { + for (int l = k; l < n; l++) { + if (ch[k] > ch[l]) { + int t = ch[k]; + ch[k] = ch[l]; + ch[l] = t; + } + } + } + max = (ch[n - 1]); + for (j = 0; j < n; j++) { + if (a[j][i] == max) { s[j]++; } + } + } + for (i = 0; i < n; i++) { + if (s[i] > 0) count++; + } + cout << count << endl; + return 0; +} +int n, k, a, last = 0, counter = 1; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == last) { + counter++; + } else { + counter = 1; + } + last = a; + } + if (counter + k > n) { + cout << n - counter << endl; + } else { + cout << -1 << endl; + } +} +int n, m, k; +int pre[1005], tree[1005], ki[1005]; +bool gover[1005]; +vector nogover; +void init() { + for (int i = 1; i <= n; i++) pre[i] = i; +} +int find(int x) { + return pre[x] == x ? x : pre[x] = find(pre[x]); +} +void Union(int x, int y) { + int fa = find(x), fb = find(y); + if (fa != fb) { pre[fa] = fb; } +} +int main() { + int a, b, ans, max; + while (cin >> n >> m >> k) { + init(); + memset(tree, 0, sizeof(tree)); + memset(gover, false, sizeof(gover)); + nogover.clear(); + for (int i = 0; i < k; i++) { cin >> ki[i]; } + for (int i = 0; i < m; i++) { + cin >> a >> b; + Union(a, b); + } + for (int i = 0; i < k; i++) gover[find(ki[i])] = true; + for (int i = 1; i <= n; i++) { tree[find(i)]++; } + ans = 0, max = 0; + for (int i = 1; i <= n; i++) { + if (find(i) == i) { + if (gover[i]) { + max = tree[i] > tree[max] ? i : max; + } else { + nogover.push_back(tree[i]); + } + ans += tree[i] * (tree[i] - 1) / 2; + } + } + for (int i = 0; i < nogover.size(); i++) { + for (int j = i + 1; j < nogover.size(); j++) ans += nogover[i] * nogover[j]; + ans += nogover[i] * tree[max]; + } + cout << ans - m << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + double l, r, x, y; + double k; + bool flag = false; + cin >> l >> r >> x >> y >> k; + for (double i = x; i <= y; i++) { + if (k * i <= r && k * i >= l) flag = true; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << 3 * (n / 2) << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b, k; + cin >> a >> b >> k; + if (a == b) { + if (k % 2 == 0) + cout << 0 << endl; + else + cout << a << endl; + } else { + if (k % 2 == 0) { + cout << (k / 2) * a - (k / 2) * b << endl; + } else { + cout << ((k / 2) + 1) * a - (k / 2) * b << endl; + } + } + } +} +int main() { + int n, m = 0; + long long x, s; + cin >> n >> x; + s = x; + for (int i = 0; i < n; i++) { + char ch; + long long j; + cin >> ch >> j; + if (ch == '+') { + s += j; + } else { + if (s - j < 0) { + s = s; + m++; + } else { + s -= j; + } + } + } + cout << s << " " << m << endl; + return 0; +} +int main() { + string numero; + cin >> numero; + int n = numero.size(); + for (int i = 0; i <= n - 1; ++i) { + int x = numero[i] - '0'; + if (i == 0) { + if (5 <= x and x <= 8) { numero[i] = (char)('0' + 9 - x); } + } else if (5 <= x) { + numero[i] = (char)('0' + 9 - x); + } + } + cout << numero << endl; + return 0; +} +int main() { + string a; + cin >> a; + int n = a.size(), max = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + int m = 0; + while (a[i + m] == a[j + m]) { m++; } + if (max <= m) max = m; + } + } + cout << max << endl; +} +int main() { + int t, k = 0; + cin >> t; + for (int i = 1; i <= t; i++) { + int a, b, c; + cin >> a >> b >> c; + if ((a + b + c) > 1) k++; + } + cout << k << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n / 2) + 1 << endl; + return 0; +} +int main() { + int n, k; + int num; + cin >> n >> k; + int w = 0; + for (int i = 0; i < n; i++) { + cin >> num; + int cnt = 0; + while (num > 0) { + int rem = num % 10; + if (rem == 4 || rem == 7) cnt++; + num = num / 10; + } + if (cnt <= k) w++; + } + cout << w << endl; +} +int main() { + long long int mx = 0, n, a[105] = {0}, sum; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] > mx) mx = a[i]; + } + sum = 0; + for (int i = 0; i < n; i++) { sum += (mx - a[i]); } + cout << sum << endl; + return 0; +} +int main() { + int n, i, x, ans = -1000001; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + if ((int)pow((int)sqrt(x), 2) != x && x > ans) ans = x; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n - 1; i++) { + if (i % 2 == 0) + cout << "I hate that "; + else + cout << "I love that "; + } + if (n % 2 == 0) + cout << "I love it" << endl; + else + cout << "I hate it" << endl; +} +int main() { + int n; + cin >> n; + int d[n + 10]; + d[0] = 0; + for (int i = 1; i <= n; i++) { cin >> d[i]; } + int s[n + 15]; + s[0] = 0; + for (int i = 1; i <= n + 1; i++) { s[i] = s[i - 1] + d[i - 1]; } + int sr, t; + cin >> sr >> t; + if (sr > t) swap(sr, t); + int ans = s[t] - s[sr]; + ans = min(ans, s[sr] + s[n + 1] - s[t]); + cout << ans << endl; + return 0; +} +int main() { + int i, j, n, a, k; + int arr[55][2]; + cin >> n >> k; + for (i = 0; i < n; i++) { + for (j = 0; j < 2; j++) { cin >> arr[i][j]; } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] > arr[j][0]) { + int tmp = arr[i][0]; + arr[i][0] = arr[j][0]; + arr[j][0] = tmp; + tmp = arr[i][1]; + arr[i][1] = arr[j][1]; + arr[j][1] = tmp; + } + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] == arr[j][0]) { + if (arr[i][1] < arr[j][1]) { + int tmp = arr[i][1]; + arr[i][1] = arr[j][1]; + arr[j][1] = tmp; + } + } + } + } + int frr[55], p = 0; + for (i = 0; i < n; i++) { frr[i] = 0; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] == arr[j][0] && arr[i][1] == arr[j][1]) { frr[p]++; } + } + p++; + } + cout << frr[k - 1] << endl; + return 0; +} +long long int maxx(long long int &a, long long int &b) { + return a > b ? a : b; +} +long long int minn(long long int &a, long long int &b) { + return a > b ? b : a; +} +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +int int_gcd(int a, int b) { + return b == 0 ? a : int_gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return a / gcd(a, b) * b; +} +long long int poww(long long int base, long long int exp, long long int mod) { + base %= mod; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % mod; + base = (base * base) % mod; + exp >>= 1; + } + return result; +} +int main() { + int n, m; + cin >> n >> m; + int ans = 4; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + int x; + cin >> x; + if (x == 1 && (j == 1 || j == m || i == 1 || i == n)) { ans = 2; } + } + } + cout << ans << endl; +} +int main() { + int t; + cin >> t; + int n, x, y, d; + while (t--) { + cin >> n >> x >> y >> d; + if (abs(x - y) % d == 0) + cout << abs(x - y) / d << "\n"; + else { + int sa, sb; + sa = (x - 1) / d + ((x - 1) % d != 0); + sb = (n - x) / d + ((n - x) % d != 0); + if ((y - 1) % d == 0 && (n - y) % d == 0) + cout << min(sa + (y - 1) / d, sb + (n - y) / d) << "\n"; + else if ((y - 1) % d == 0) + cout << sa + (y - 1) / d << "\n"; + else if ((n - y) % d == 0) + cout << sb + (n - y) / d << "\n"; + else + cout << "-1\n"; + } + } + return 0; +} +bool C7(int num) { + if (num % 10 == 7) + return true; + else + return false; +} +int main() { + int hh, mm, t; + while (cin >> t) { + cin >> hh >> mm; + if (C7(hh) || C7(mm)) { + cout << 0 << endl; + } else { + int index = 0; + while (!(C7(hh) || C7(mm))) { + if (mm < t) { + if (hh == 0) hh = 24; + hh--; + mm += 60; + } + mm -= t; + index++; + } + cout << index << endl; + } + } +} +int main() { + string arr[10]; + for (int i = 0; i < 8; ++i) cin >> arr[i]; + for (int i = 0; i < 8; ++i) + for (int j = 0; j < 7; ++j) + if (arr[i][j] == arr[i][j + 1]) { + puts("NO"); + return 0; + } + puts("YES"); +} +int n; +int main() { + cin >> n; + int a; + int sum = 0; + int cnt = 0; + while (n--) { + cin >> a; + if (a > 0) + sum += a; + else + cnt += a; + } + cout << sum - cnt << endl; + return 0; +} +int main() { + int n, a[13] = {0}; + cin >> n; + for (int i = 0; i < 12; i++) cin >> a[i]; + int sum = 0; + for (int i = 0; i < 12; i++) sum += a[i]; + int x, m; + if (sum < n) + cout << "-1" << endl; + else { + sort(a, a + 12); + x = 0, m = 0; + int i = 11; + while (x < n) { + x += a[i]; + m++; + i--; + } + cout << m << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int k = (n + 1) / 3; + cout << k / 12 << ' ' << k % 12 << endl; + return 0; +} +map dp; +int main() { + int q; + cin >> q; + while (q--) { + int type; + cin >> type; + long long v, u, w; + if (type == 1) { + cin >> v >> u >> w; + while (v != u) { + if (v < u) swap(u, v); + dp[v] += w; + v = v / 2; + } + } else { + cin >> v >> u; + long long s = 0; + while (v != u) { + if (v < u) swap(u, v); + s += dp[v]; + v = v / 2; + } + cout << s << endl; + } + } +} +int main() { + int n; + cin >> n; + int x, y, z; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + if ((x + z + y) >= 2) { sum++; } + } + cout << sum << endl; + return 0; +} +int main() { + string s; + cin >> s; + s[0] = toupper(s[0]); + cout << s << "\n"; +} +int main() { + int a, b, c, d = -1, e = 1; + cin >> a >> b >> c; + while (a != 0 || b != 0 || c != 0) { + if (e == 1) { + a -= min(a, 2); + e = 2; + goto momo; + } + if (e == 2) { + b -= min(b, 2); + e = 3; + goto momo; + } + if (e == 3) { + c -= min(c, 2); + e = 1; + goto momo; + } + momo:; + d++; + } + cout << 30 + d << endl; +} +const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 1e3 + 5, mod = 1e9 + 7; +bool black[N][N]; +bool check(int x, int z) { + if (black[x + 1][z] && black[x + 1][z + 1] && black[x][z + 1]) return 1; + if (black[x][z - 1] && black[x + 1][z - 1] && black[x + 1][z]) return 1; + if (black[x][z - 1] && black[x - 1][z] && black[x - 1][z - 1]) return 1; + if (black[x][z + 1] && black[x - 1][z] && black[x - 1][z + 1]) return 1; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int ans = 0; + int x, z; + for (int i = 0; i < k; ++i) { + cin >> x >> z; + black[x][z] = 1; + if (!ans) { + if (check(x, z)) ans = i + 1; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int p[n + 1]; + for (int i = 1; i <= n; i++) { cin >> p[i]; } + int s = 0; + for (int i = 1; i <= n; i++) { + if (p[i] <= k) + s++; + else + break; + if (i == n) { + cout << n << endl; + return 0; + } + } + for (int i = n; i >= 1; i--) { + if (p[i] <= k) + s++; + else + break; + } + cout << s << endl; + return 0; +} +char a[5005]; +int main() { + int num1 = 0, num2 = 0, ans = 0; + cin >> a; + int x = strlen(a); + for (int i = 0; i < x; i++) { + num1 = 0, num2 = 0; + for (int j = i; j < x; j++) { + if (a[j] == '(') { + num1++; + } else if (a[j] == ')') { + num1--; + } else { + num2++; + num1--; + } + if (num1 == 0) { + ans++; + } else if (num1 < 0 && num2 > 0) { + num2--; + num1 += 2; + } else if (num1 > 0) { + continue; + } else if (num1 < 0 && num2 == 0) { + break; + } + } + } + cout << ans << endl; +} +map mymap; +void init() { + mymap[0] = "O-|-OOOO"; + mymap[1] = "O-|O-OOO"; + mymap[2] = "O-|OO-OO"; + mymap[3] = "O-|OOO-O"; + mymap[4] = "O-|OOOO-"; + mymap[5] = "-O|-OOOO"; + mymap[6] = "-O|O-OOO"; + mymap[7] = "-O|OO-OO"; + mymap[8] = "-O|OOO-O"; + mymap[9] = "-O|OOOO-"; +} +int main() { + init(); + string s; + cin >> s; + for (int i = s.length() - 1; i >= 0; i--) { cout << mymap[s[i] - '0'] << endl; } + return 0; +} +int arr[1000000]; +int main() { + string s = "qwertyuiopasdfghjkl;zxcvbnm,./", str, newS = ""; + char c; + cin >> c >> str; + int j = c == 'R' ? -1 : 1, ind; + for (int i = 0; i < str.length(); i++) { + ind = s.find(str[i]); + newS += s[ind + j]; + } + cout << newS << endl; +} +const int mod = 10; +const int N = 1000002; +int nextz[N]; +char S[N], T[N]; +int slen, tlen; +void getNext() { + int j, k; + j = 0; + k = -1; + nextz[0] = -1; + while (j < tlen) + if (k == -1 || T[j] == T[k]) + nextz[++j] = ++k; + else + k = nextz[k]; +} +int KMP_Index() { + int i = 0, j = 0; + getNext(); + while (i < slen && j < tlen) { + if (j == -1 || S[i] == T[j]) { + i++; + j++; + } else + j = nextz[j]; + } + if (j == tlen) + return i - tlen; + else + return -1; +} +int KMP_Count() { + int ans = 0; + int i, j = 0; + if (slen == 1 && tlen == 1) { + if (S[0] == T[0]) + return 1; + else + return 0; + } + getNext(); + for (i = 0; i < slen; i++) { + while (j > 0 && S[i] != T[j]) j = nextz[j]; + if (S[i] == T[j]) j++; + if (j == tlen) { + ans++; + j = nextz[j]; + } + } + return ans; +} +set st; +int main() { + int n; + int flag = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + st.insert(x); + if (x == 0) flag = 1; + } + if (flag) + cout << st.size() - 1 << endl; + else + cout << st.size() << endl; +} +int main() { + long long int n; + cin >> n; + if (n % 2) + cout << 1 << endl; + else + cout << 2 << endl; +} +int main() { + int n, count = 0; + cin >> n; + string s, s1; + cin >> s >> s1; + for (int i = 0; i < n; i++) { + if (s[i] < s1[i]) swap(s[i], s1[i]); + if ((s[i] - s1[i]) > 5) + count += (s1[i] + 10 - s[i]); + else + count += (s[i] - s1[i]); + } + cout << count << endl; +} +int main() { + int n; + cin >> n; + int ans = n + n / 2; + cout << ans << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + while (a > 0) { + if (l <= r) + l++; + else + r++; + a--; + } + cout << min(l, r) * 2 << endl; + return 0; +} +int main() { + int x, i, m = 1, n, j; + cin >> x; + m += (x / 2); + n = m; + for (j = 1; j <= x; j++) { + for (i = 1; i <= x; i++) { + if (i >= m && i <= n) + cout << "D"; + else + cout << "*"; + } + cout << endl; + if (j < (x / 2) + 1) { + m--; + n++; + } else { + m++; + n--; + } + } + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n + 1] = {0}; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long int c = 0, d = 0; + for (int i = 2; i < n; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + string S; + int n; + cin >> n; + cin >> S; + bool ac = true; + for (int i = 0; i < n / 2; i++) { + int t1 = S[i], t2 = S[n - i - 1]; + if (t1 < t2) swap(t1, t2); + if (t1 - t2 != 2 && t1 != t2) ac = false; + } + if (!ac) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + long long n, a; + cin >> n; + a = n / 2; + if (n % 2 == 0) + cout << a << endl; + else + cout << a - n << endl; +} +string s; +bool cek; +int temp, temp1, temp2, temp3, temp4; +int main() { + cin >> s; + cek = false; + for (int i = 0; i < s.length(); i++) { + temp = i; + if (s[i] == 'h') { + cek = true; + break; + } else { + cek = false; + } + } + if (cek == true) { + cek = false; + for (int i = temp + 1; i < s.length(); i++) { + temp1 = i; + if (s[i] == 'e') { + cek = true; + break; + } else { + cek = false; + } + } + } + if (cek == true) { + cek = false; + for (int i = temp1 + 1; i < s.length(); i++) { + temp2 = i; + if (s[i] == 'l') { + cek = true; + break; + } else { + cek = false; + } + } + } + if (cek == true) { + cek = false; + for (int i = temp2 + 1; i < s.length(); i++) { + temp3 = i; + if (s[i] == 'l') { + cek = true; + break; + } else { + cek = false; + } + } + } + if (cek == true) { + cek = false; + for (int i = temp3 + 1; i < s.length(); i++) { + temp4 = i; + if (s[i] == 'o') { + cek = true; + break; + } else { + cek = false; + } + } + } + if (cek == true) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +string s1, s2; +int x, y; +int main() { + cin >> s1; + cin >> s2; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] != s2[i] && s2[i] == '4') x++; + if (s1[i] != s2[i] && s2[i] == '7') y++; + } + cout << max(x, y) << endl; + return 0; +} +const int maxn = 1000007; +const long long mod = 1e9 + 7; +int main() { + int n; + cin >> n; + long long now = 1, last = 1; + for (int i = 1; i <= n; i++) { + now += last; + now %= mod; + last %= mod; + swap(now, last); + } + cout << (now + last - 2 + mod) % mod << "\n"; +} +int main() { + int n; + int mx = 0; + int sum = 0; + cin >> n; + int a; + for (int i = 1; i <= n; ++i) { + cin >> a; + mx = max(mx, a); + sum += a; + } + sum *= 2; + sum += n; + sum /= n; + cout << max(sum, mx) << endl; +} +const int maxn = 1e3 + 5; +int arr[maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = n - 1; i >= 0; i--) { + if (arr[i] < 0) { + cout << arr[i] << endl; + return 0; + } + int temp = arr[i]; + if (floor(sqrt(temp)) == sqrt(temp)) + continue; + else { + cout << arr[i] << endl; + return 0; + } + } + return 0; +} +int main() { + int arr[5][5] = {0}, i, j; + int cpy[5][5] = {1}; + for (i = 1; i <= 3; i++) { + for (j = 1; j <= 3; j++) { + cin >> arr[i][j]; + if (arr[i][j] % 2) { + cpy[i][j] += 1; + cpy[i + 1][j] += 1; + cpy[i - 1][j] += 1; + cpy[i][j + 1] += 1; + cpy[i][j - 1] += 1; + } + } + } + for (i = 1; i <= 3; i++) { + for (j = 1; j <= 3; j++) { cout << (cpy[i][j] % 2 ? 0 : 1); } + cout << endl; + } + return 0; +} +int main() { + int k; + string s; + cin >> k >> s; + int count[26] = {0}; + for (int i = 0; i < s.length(); ++i) { count[s[i] - 'a'] += 1; } + string s1; + int c = 0; + for (; c < 26; ++c) { + if (count[c] % k != 0) { + break; + } else { + s1.append(count[c] / k, 'a' + c); + } + } + if (c == 26) { + while (k--) { cout << s1; } + cout << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + long long n, m, mx = 0, mn = 999, mini = 999, x; + cin >> n >> m; + while (n--) { + cin >> x; + mn = min(mn, x); + mx = max(mx, x); + } + while (m--) { + cin >> x; + mini = min(mini, x); + } + mx = max(mx, 2 * mn); + if (mini > mx) + cout << mx << endl; + else + cout << -1 << endl; + return 0; +} +const int N = 50 + 10, INF = 1e9 + 7; +int in() { + int ret; + cin >> ret; + return ret; +} +int n, a, b, c; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + if (i % 3 == 0) + a += in(); + else if (i % 3 == 1) + b += in(); + else + c += in(); + } + if (max(a, max(b, c)) == a) + cout << "chest" << '\n'; + else if (max(a, max(b, c)) == b) + cout << "biceps" << '\n'; + else + cout << "back" << '\n'; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) cout << "#"; + cout << endl; + } else if (i % 4 == 1) { + for (int j = 0; j < m - 1; j++) cout << "."; + cout << "#" << endl; + } else { + cout << "#"; + for (int j = 0; j < m - 1; j++) cout << "."; + cout << endl; + } + } +} +int a[1010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n - 1] - a[0] - n + 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int t; + for (int i = 0; i < s.length(); ++i) { + if (s[i] == '.') { + t = i; + break; + } + } + if (s[t - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + } else if (s[t + 1] >= '5') { + s[t - 1]++; + for (int i = 0; i < t; ++i) { cout << s[i]; } + cout << endl; + } else { + for (int i = 0; i < t; ++i) { cout << s[i]; } + cout << endl; + } + return 0; +} +int main() { + char map[8][8]; + int af = 0, bf = 0; + int blocka[8]; + int blockb[8] = {0}; + fill_n(blocka, 8, 8); + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) { + cin >> map[i][j]; + if (map[i][j] == 'B' && blocka[j] == 8) blocka[j] = 7; + if (map[i][j] == 'W' && blocka[j] == 8) blocka[j] = i; + if (map[i][j] == 'B' && i >= blockb[j]) blockb[j] = i; + if (map[i][j] == 'W' && blockb[j] != 0) blockb[j] = 0; + } + } + sort(blockb, blockb + 8); + sort(blocka, blocka + 8); + af = blocka[0]; + bf = blockb[7]; + cout << (af <= 7 - bf ? 'A' : 'B') << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (n == 1) + cout << "0\n"; + else if (min(a, b) <= c) + cout << min(a, b) * (n - 1) << '\n'; + else + cout << min(a, b) + c * (n - 2) << '\n'; +} +const int maxn = 1e5 + 10; +int main() { + int a, b; + while (cin >> a >> b) { cout << (b - 1) / a + 1 << endl; } + return 0; +} +int main() { + long long int n, S; + cin >> n >> S; + if (S % n == 0) { + cout << S / n << endl; + } else + cout << S / n + 1 << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n & 1) + cout << 1 << endl; + else + cout << 0 << endl; + return 0; +} +set ang; +int main() { + int t; + cin >> t; + int sum = 180; + for (int i = (3); i < (int)(400); ++i) { + if (sum % i == 0) ang.insert(sum / i); + sum += 180; + } + while (t--) { + int curAng; + cin >> curAng; + if (ang.find(curAng) != ang.end()) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + if (k / n == 2) + cout << n - k % n << endl; + else + cout << 0 << endl; + return 0; +} +int p[4]; +int re[105]; +int main() { + int n; + cin >> n; + p[0] = 0; + p[1] = 1; + p[2] = 1; + p[3] = 0; + int flag = 1; + for (int j = 0; j < n; j++) { cin >> re[j]; } + for (int k = 0; k < n; k++) { + int fi = 0; + if (p[re[k]] == 0) { + cout << "NO" << endl; + flag = 0; + break; + } else { + for (int i = 1; i <= 3; i++) { + if (p[i] == 1 && i != re[k]) { + p[i] = 0; + fi = i; + } + if (p[i] == 0 && i != fi) { p[i] = 1; } + } + } + } + if (flag == 1) { cout << "YES" << endl; } + return 0; +} +int main() { + long long int a; + cin >> a; + int h = 0; + while (a) { + if (a % 10 == 4 || a % 10 == 7) h++; + a = a / 10; + if (h > 7) break; + } + if (h == 4 || h == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + string name, crew; + vector rat, woch, men, cap; + for (int i = 0; i < n; i++) { + cin >> name >> crew; + if (crew == "rat") + rat.push_back(name); + else if (crew == "woman" || crew == "child") + woch.push_back(name); + else if (crew == "man") + men.push_back(name); + else if (crew == "captain") + cap.push_back(name); + } + for (int i = 0; i < rat.size(); i++) { cout << rat[i] << endl; } + for (int i = 0; i < woch.size(); i++) { cout << woch[i] << endl; } + for (int i = 0; i < men.size(); i++) { cout << men[i] << endl; } + for (int i = 0; i < cap.size(); i++) { cout << cap[i] << endl; } + return 0; +} +int main() { + long long n, m; + while (cin >> n >> m) { + if (n >= 0 && m >= 0) { + cout << "0 " << (n + m) << " " << (n + m) << " 0" << endl; + } else if (n < 0 && m >= 0) { + long long a = abs(n); + cout << "-" << (a + m) << " 0 0 " << (m + a) << endl; + } else if (n >= 0 && m < 0) { + long long a = abs(m); + cout << "0 -" << (n + a) << " " << (n + a) << " 0" << endl; + } else { + cout << "-" << (abs(n) + abs(m)) << " 0 0 -" << (abs(n) + abs(m)) << endl; + } + } + return 0; +} +int main() { + long long x = 0, y = 0, z = 0, k = 0; + cin >> x >> y >> z >> k; + while (x + y + z - 3 > k) { + if (x > y && x > z) { + --x; + } else if (y > z) { + --y; + } else { + --z; + } + } + cout << x * y * z << endl; + return 0; +} +int main() { + int n, k, t, d; + cin >> n >> t >> k >> d; + int g = (n + k - 1) / k; + int x1 = 0, x2 = d; + for (int i = 0; i < g; i++) { + if (x1 <= x2) + x1 += t; + else + x2 += t; + } + if (max(x1, x2) < g * t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + char c[95]; + while (cin >> n) { + int sum1 = 0; + for (int i = 0; i <= n - 1; i++) cin >> c[i]; + for (int i = 0; i <= n - 1; i++) { + if (c[i] == '1') + sum1++; + else { + cout << sum1; + sum1 = 0; + } + } + cout << sum1 << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int n = s1.length(); + int m = s2.length(); + vector vec; + string s; + for (int i = 0; i < n; i++) { + s += s1[i]; + string s4; + for (int j = 0; j < m; j++) { + s4 += s2[j]; + string s3 = s + s4; + vec.push_back(s3); + } + } + sort(vec.begin(), vec.end()); + cout << vec[0] << endl; +} +int father[1005]; +int n, m, k; +int find(int x) { + return father[x] == x ? x : father[x] = find(father[x]); +} +int node[1005]; +int fathercnt[1005]; +int cnt; +int isgro[1005]; +int main() { + memset(isgro, 0, sizeof(isgro)); + cin >> n >> m >> k; + int gro; + for (int j = 1; j <= n; j++) { father[j] = j; } + for (int i = 0; i < k; i++) { + int g; + cin >> g; + isgro[g] = 1; + gro = g; + } + for (int j = 1; j <= n; j++) { fathercnt[j] = 1; } + for (int i = 0; i < m; i++) { + int p, q; + cin >> p >> q; + if (isgro[p]) { + int x; + x = find(q); + if (father[find(q)] != father[find(p)]) { + father[find(q)] = father[find(p)]; + fathercnt[find(p)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else if (isgro[q]) { + int x; + x = find(p); + if (father[find(p)] != father[find(q)]) { + father[find(p)] = father[find(q)]; + fathercnt[find(q)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else { + int x; + if (isgro[father[find(p)]]) { + x = find(q); + if (father[find(q)] != father[find(p)]) { + father[find(q)] = father[find(p)]; + fathercnt[find(p)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else { + x = find(p); + if (father[find(p)] != father[find(q)]) { + father[find(p)] = father[find(q)]; + fathercnt[find(q)] += fathercnt[x]; + fathercnt[x] = 0; + } + } + } + } + int maxfather = 0; + int strunity; + for (int i = 1; i <= n; i++) { + if (fathercnt[i] > maxfather) { + maxfather = fathercnt[i]; + strunity = i; + } + } + int maxgro = 0; + int strgro = gro; + for (int i = 1; i <= n; i++) { + if (isgro[i] && fathercnt[i] > maxgro) { + maxgro = fathercnt[i]; + strgro = i; + } + } + for (int i = 1; i <= n; i++) { + if (fathercnt[i] != 0) { + if (isgro[find(i)] != 1) { + fathercnt[strgro] += fathercnt[i]; + fathercnt[i] = 0; + } + } + } + cnt = 0; + for (int i = 1; i <= n; i++) { + if (isgro[i]) { cnt += (fathercnt[i] * (fathercnt[i] - 1)) / 2; } + } + cout << cnt - m << endl; + return 0; +} +int main() { + int n, c; + cin >> n >> c; + int i; + int str[100005]; + cin >> str[0]; + int ans = 1; + for (i = 1; i < n; i++) { + cin >> str[i]; + if (str[i] - str[i - 1] <= c) { + ans++; + } else { + ans = 1; + } + } + cout << ans << endl; + return 0; +} +int a[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; +int main() { + string s; + cin >> s; + cout << a[s[0] - '0'] * a[s[1] - '0'] << endl; +} +int x, y, num; +int main() { + cin >> x >> y; + for (int i = x + 1; i <= y; i++) { + bool prim = 1; + for (int j = 2; j < i; j++) + if (i % j == 0) prim = 0; + if (prim) { + num = i; + break; + } + } + if (num == y) return puts("YES"), 0; + return puts("NO"), 0; +} +int main() { + int n, mCount = 0, cCount = 0, x = 0, y = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > y) { + mCount++; + } else if (x < y) { + cCount++; + } + } + if (mCount > cCount) { + cout << "Mishka\n"; + } else if (mCount < cCount) { + cout << "Chris\n"; + } else { + cout << "Friendship is magic!^^\n"; + } + return 0; +} +int a[102]; +int main() { + int n, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > 0) + ans += a[i]; + else + ans -= a[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int v; + cin >> v; + if (v == 2) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +vector parent(long long n) { + if (n == 1) { return vector{1}; } + vector ans = parent(n / 2); + ans.push_back(n); + return ans; +} +vector route(long long u, long long v) { + vector pu = parent(u), pv = parent(v); + int mxcommon = 0; + for (int i = 1; i < min(pu.size(), pv.size()); ++i) { + if (pu[i] == pv[i]) { + mxcommon++; + } else { + break; + } + } + vector rta; + for (int i = pv.size() - 1; i > mxcommon; i--) rta.push_back(pv[i]); + for (int i = mxcommon; i < pu.size(); ++i) rta.push_back(pu[i]); + return rta; +} +map, long long> cost; +int main() { + long long t, c, u, v, p; + cin >> t; + while (t--) { + cin >> c; + if (c == 1) { + cin >> u >> v >> p; + vector r = route(min(u, v), max(u, v)); + for (int i = 0; i < r.size() - 1; ++i) { cost[make_pair(min(r[i], r[i + 1]), max(r[i], r[i + 1]))] += p; } + } else { + cin >> u >> v; + vector r = route(min(u, v), max(u, v)); + long long ans = 0; + for (int i = 0; i < r.size() - 1; ++i) { ans += cost[make_pair(min(r[i], r[i + 1]), max(r[i], r[i + 1]))]; } + cout << ans << '\n'; + } + } +} +int n; +string s; +int main() { + int count = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s[0] == 'T') + count += 4; + else if (s[0] == 'C') + count += 6; + else if (s[0] == 'O') + count += 8; + else if (s[0] == 'D') + count += 12; + else if (s[0] == 'I') + count += 20; + } + cout << count << endl; + return 0; +} +int main() { + int n, *p, *q, flag = 0, high1, high2; + cin >> n >> high1; + p = new int[high1]; + int i; + for (i = 0; i < high1; i++) cin >> p[i]; + cin >> high2; + q = new int[high2]; + for (i = 0; i < high2; i++) cin >> q[i]; + int level, j; + for (level = 1; level <= n; level++) { + flag = 0; + for (j = 0; j < high1; j++) + if (p[j] == level) { + flag = 1; + break; + } + for (j = 0; j < high2; j++) + if (q[j] == level) { + flag = 1; + break; + } + if (flag == 0) break; + } + if (level <= n) + cout << "Oh, my keyboard!" << endl; + else + cout << "I become the guy." << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + a /= 1; + b /= 2; + c /= 4; + int min = 1005; + if (a < min) min = a; + if (b < min) min = b; + if (c < min) min = c; + cout << min * 7 << endl; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + if (s.length() % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +vector soldier; +vector vest; +int main() { + int n, m, x, y; + cin >> n >> m >> x >> y; + soldier.resize(n); + vest.resize(m); + for (int i = 0; i < n; i++) { cin >> soldier[i]; } + for (int i = 0; i < m; i++) { cin >> vest[i]; } + vector matching[2]; + for (int i = 0, j = 0; i < n && j < m;) { + if (vest[j] < soldier[i] - x) { + ++j; + } + else if (vest[j] > soldier[i] + y) { + ++i; + } + else { + matching[0].push_back(++i); + matching[1].push_back(++j); + } + } + cout << matching[0].size() << endl; + for (int i = 0; i < matching[0].size(); i++) { cout << matching[0][i] << " " << matching[1][i] << endl; } + return 0; +} +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +long long powmod(long long a, long long b, long long MOD) { + long long ans = 1; + while (b) { + if (b % 2) ans = ans * a % MOD; + a = a * a % MOD; + b /= 2; + } + return ans; +} +inline void getInt(int *p); +const int maxn = 1000010; +const int inf = 0x3f3f3f3f; +int n, k; +int a[maxn]; +int b[maxn]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int j = 1; j <= k; j++) { cin >> b[j]; } + if (k >= 2) { + cout << "Yes" << endl; + } else { + int ok = 0; + int j = 1; + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + j = i; + break; + } else { + if (a[i] >= b[1] || a[i] <= a[i - 1]) ok = 1; + } + } + for (int i = j + 1; i <= n; i++) { + if (a[i] <= b[1]) ok = 1; + } + for (int i = j + 2; i <= n; i++) { + if (a[i] <= a[i - 1]) ok = 1; + } + if (ok) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 + ch - '0'; } + } +} +long long a, b; +char s[1000][1000]; +int main() { + cin >> a >> b; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { cin >> s[i][j]; } + } + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { + if (s[i][j] == 'S') { + if (s[i][j + 1] == 'W') { + cout << "NO" << endl; + return 0; + } + if (s[i][j - 1] == 'W') { + cout << "NO" << endl; + return 0; + } + if (s[i + 1][j] == 'W') { + cout << "NO" << endl; + return 0; + } + if (s[i - 1][j] == 'W') { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { + if (s[i][j] == '.') { s[i][j] = 'D'; } + cout << s[i][j]; + } + cout << endl; + } +} +int n, m, dist[100015], x, y, prefs[100015], ans, ans1; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> dist[i]; } + prefs[0] = dist[0]; + for (int i = 1; i < n; i++) { prefs[i] = dist[i] + prefs[i - 1]; } + cin >> x >> y; + x--; + y--; + if (x > y) { swap(x, y); } + ans = prefs[y - 1]; + ans -= prefs[x - 1]; + ans1 = prefs[n - 1] - ans; + cout << min(ans, ans1) << endl; + return 0; +} +int main() { + int row, col; + bool flag = false; + cin >> row >> col; + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + if (i % 2 == 0) + cout << "#"; + else { + if (!flag) { + if (j == col - 1) + cout << "#"; + else + cout << "."; + if (j == col - 1) flag = true; + } else if (flag) { + if (j == 0) + cout << "#"; + else + cout << "."; + if (j == col - 1) flag = false; + } + } + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + char sym; + int suml = 0, sumr = 0; + for (size_t i = 0; i < n; i++) { + cin >> sym; + sym -= '0'; + if (sym != 4 && sym != 7) { + cout << "NO\n"; + return 0; + } + if (i < n / 2) + suml += sym; + else + sumr += sym; + } + if (suml == sumr) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int p[4], a, b, s = 0; + cin >> p[0] >> p[1] >> p[2] >> p[3] >> a >> b; + sort(p, p + 4); + for (int i = a; i <= b; i++) + if (i < p[0]) s++; + cout << s << endl; + return 0; +} +int main() { + int n, res = 0; + cin >> n; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = 1; i < n; i++) + if (arr[i] != (arr[i - 1] + 1)) res += (arr[i] - arr[i - 1] - 1); + cout << res << "\n"; + return 0; +} +int main() { + long long n, i, c = 0, cnt = 0, a[100009]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 0; i < n; i++) { + if (a[i] != 0 && (a[i] == a[i + 1]) && (a[i] != a[i + 2])) { + c++; + } else if (a[i] != 0 && a[i] == a[i + 2]) { + cout << "-1" << endl; + return 0; + } + } + cout << c << endl; + return 0; +} +int a, b, c, len, flag, flag1, flag2, flag3; +char str[110]; +int main() { + while (cin >> str) { + flag = flag2 = flag3 = 0, len = strlen(str); + if (len >= 5) { + for (int i = 0; i < len; i++) + if (isdigit(str[i])) + flag = 1; + else if (islower(str[i])) + flag2 = 1; + else if (isupper(str[i])) + flag3 = 1; + if (flag && flag2 && flag3) + puts("Correct"); + else + puts("Too weak"); + } else + puts("Too weak"); + } + return 0; +} +const long INF = 2000000; +long a[10000]; +long i, j; +long n, m; +int main() { + cin >> n >> m; + for (i = 0; i < m; i++) { + cin >> j; + a[j]++; + } + j = INF; + for (i = 1; i <= n; i++) + if (j > a[i]) j = a[i]; + cout << j << endl; + return 0; +} +int main() { + int n, sum = 0, a, b, c, minx; + cin >> n >> a >> b >> c; + minx = min(min(a, b), min(b, c)); + if (n == 1) + cout << 0 << endl; + else { + n--; + if (a == minx) + sum = n * a; + else if (b == minx) + sum = n * b; + else + sum = min(a, b) + c * (n - 1); + cout << sum << endl; + } + return 0; +} +int main() { + int n, k, m; + cin >> n >> k >> m; + int c[m + 2] = {}, i, j, r = m; + for (i = 1; i <= m; i++) cin >> c[i]; + c[m + 1] = n; + if (m == 0) r = n / k; + if (m >= 1) { + for (i = 1; i <= m; i++) r += ((c[i] - c[i - 1] - 1) / k); + r += ((c[m + 1] - c[m]) / k); + } + cout << r << endl; + return 0; +} +map a; +long long n, u, v, w, t, ans; +void solve(bool t) { + while (u != v) { + if (u < v) swap(u, v); + if (t) + a[u] += w; + else + ans += a[u]; + u /= 2; + } +} +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> t >> u >> v; + if (t == 1) { + cin >> w; + solve(1); + } else { + solve(0); + cout << ans << endl; + ans = 0; + } + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int MIN = min(a, b); + int MAX = max(a, b); + cout << MIN << ' ' << (MAX - MIN) / 2 << endl; + return 0; +} +const int N = 1000 + 5; +int n, x, sum, a[N]; +void Input() { + cin >> n >> x; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } +} +void Solve() { + if (!sum) + cout << 0 << '\n'; + else { + int t = sum, res = 1; + if (abs(t) <= x) + cout << 1 << '\n'; + else { + int c = abs(t) / x; + if (abs(t) % x != 0) + res += c; + else + res = c; + cout << res << '\n'; + } + } +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + int n, k, ans, sum, aux, candies; + ans = sum = candies = 0; + bool found = false; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> aux; + if (found) continue; + candies += aux; + aux = min(candies, 8); + sum += aux; + ans++; + candies -= aux; + if (sum >= k) found = true; + } + if (!found) + cout << "-1\n"; + else + cout << ans << "\n"; +} +int q, n, a[305]; +string s; +int main() { + cin >> q; + while (q--) { + cin >> n; + cin >> s; + if (n == 2) { + if (s[0] == s[1]) + cout << "NO" << endl; + else if (s[0] > s[1]) + cout << "NO" << endl; + else if (s[0] < s[1]) { + cout << "YES" << endl << "2" << endl; + cout << s[0] << " " << s[1] << endl; + } + } else if (n == 1) + cout << "NO" << endl; + else { + cout << "YES" << endl << "2" << endl; + cout << s[0] << " "; + for (int i = 1; i < n; i++) cout << s[i]; + cout << endl; + } + } + return 0; +} +int main() { + int n; + int k; + int x = 0; + int a = 240; + cin >> n >> k; + if (k >= 240) { + cout << 0 << "\n"; + return 0; + } + a -= k; + for (int i = 1; i <= n; i++) { + a -= (i * 5); + if (a < 0) { break; } + x++; + } + cout << x << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int p = min(n, m); + if (p % 2 == 0) + cout << "Malvika\n"; + else + cout << "Akshat\n"; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int fp = n * p; + int m = 0; + while (n > 1) { + int po = floor(log2(n)); + int compete = pow(2, po); + int diff = n - pow(2, po); + m += compete / 2; + n = compete / 2 + diff; + } + int fb = m * 2 * b + m; + cout << fb << " " << fp << endl; + return 0; +} +int main() { + int tc; + cin >> tc; + while (tc--) { + long int a, b; + cin >> a >> b; + int ctr = 0; + while (a && b) { + ctr += max(a, b) / min(a, b); + if (a > b) + a %= b; + else + b %= a; + } + cout << ctr << endl; + } + return 0; +} +int n, a[210]; +int main() { + cin >> n; + for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } + sort(a, a + 2 * n); + if (a[n - 1] >= a[n]) { + puts("NO"); + } else { + puts("YES"); + } + return 0; +} +int main() { + string str1, str2; + cin >> str1 >> str2; + string s[1000][2]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + s[i][0] = str1; + s[i][1] = str2; + string str3, str4; + cin >> str3 >> str4; + if (str3 == str1) { + str1 = str4; + } else if (str3 == str2) { + str2 = str4; + } + } + for (int i = 0; i < n; i++) { cout << s[i][0] << " " << s[i][1] << endl; } + cout << str1 << " " << str2 << endl; + return 0; +} +int main() { + long long k, n1; + cin >> k; + n1 = (long long)((-1.0 + sqrt(1 + 8 * k)) / 2 + 0.0001); + if (n1 * (n1 + 1) / 2 == k) { + cout << n1 << endl; + } else { + cout << k - (n1 * (n1 + 1) / 2) << endl; + } + return 0; +} +long long f(long long a, long long b, long long c, long long l) { + long long ans = 0; + for (long long i = max(b + c - a, 0LL); i <= l; i++) { + long long x = min(l - i, a + i - b - c); + ans += (x + 1) * (x + 2) / 2; + } + return ans; +} +int main() { + long long a, b, c, l; + while (cin >> a >> b >> c >> l) { + long long ans = 0; + for (long long i = 0; i <= l; i++) ans += (i + 1) * (i + 2) / 2; + ans -= f(a, b, c, l); + ans -= f(b, a, c, l); + ans -= f(c, a, b, l); + cout << ans << endl; + } +} +long long n, a[1000], b, c; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + for (int i = 1; i <= n; i++) + if (a[i] < 0) + c = c + a[i]; + else + b = b + a[i]; + cout << b - c << endl; + return 0; +} +int main() { + int n = 0; + string word = "Null"; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> word; + if (word.length() > 10) { + cout << word[0] << word.length() - 2 << word[word.length() - 1] << endl; + } else { + cout << word << endl; + } + } +} +bool is_magical(string number) { + for (int i = 0; i < (int)number.size(); i++) + if (number[i] != '1' && number[i] != '4') return false; + if (number[0] == '4') return false; + if (number.find("444") != number.npos) return false; + return true; +} +int main() { + string number; + cin >> number; + if (is_magical(number)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n, arr[200005], sum = 0, sum2 = 0, ind = 0, f = 0, i; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + for (i = 1; i <= n; i++) { + sum2 += arr[i]; + if (sum2 >= (sum + 1) / 2) { break; } + } + cout << i << endl; + return 0; +} +vector aramic; +int main() { + int n; + string in; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> in; + sort(in.begin(), in.end()); + string uni; + uni.push_back(*(in.begin())); + for (string::iterator ite = in.begin() + 1; ite != in.end(); ++ite) { + if (*ite != *(ite - 1)) { uni.push_back(*ite); } + } + aramic.push_back(uni); + } + sort(aramic.begin(), aramic.end()); + aramic.erase(unique(aramic.begin(), aramic.end()), aramic.end()); + cout << aramic.size() << endl; + return 0; +} +int main() { + unsigned long long n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int matriz[110][110]; +int main() { + int n, m, suma; + string aux; + memset(matriz, -1, sizeof matriz); + cin >> n >> m; + getline(cin, aux); + for (int i = int(0); i < int(n); i++) { + getline(cin, aux); + for (int j = int(0); j < int(m); j++) { matriz[i][j] = int(aux[j]) - 48; } + } + int prom = 0; + bool pass = true; + for (int i = int(0); i < int(n); i++) { + suma = 0; + for (int j = int(0); j < int(m - 1); j++) { + if (matriz[i][j + 1] == matriz[i][j]) + pass = pass && true; + else + pass = false; + } + } + if (pass) { + for (int k = int(0); k < int(n - 1); k++) { + if (matriz[k][0] != matriz[k + 1][0]) + pass = pass && true; + else + pass = false; + } + } + if (pass) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int k, i, n, ans, m; +string s; +int main() { + cin >> n >> s; + for (i = 0; i < n; i++) { + if (s[i] == '8') k++; + } + ans = min(k, n / 11); + cout << ans << endl; +} +int main() { + int x, y, z, k, X = 1, Y = 1, Z = 1; + cin >> x >> y >> z >> k; + long long ans = 0; + x--; + y--; + z--; + while (k) { + if (x == 0 && y == 0 && z == 0) break; + if (x) { + x--; + X++; + k--; + } + if (!k) break; + if (y) { + y--; + Y++; + k--; + } + if (!k) break; + if (z) { + z--; + Z++; + k--; + } + if (!k) break; + } + ans = 1LL * X * Y * Z; + cout << ans << endl; + return 0; +} +int main() { + long long int n, m, tmp; + cin >> n >> m; + tmp = pow(2, n); + cout << m % tmp << endl; +} +int main() { + int n, x; + cin >> n; + vector A(n / 2); + for (int i = 0; i < (n / 2); i++) { cin >> A[i]; } + sort(A.begin(), A.end()); + int res1 = 0, res2 = 0; + for (int i = 0; i < n / 2; i++) { + res1 += abs(A[i] - (i * 2 + 1)); + res2 += abs(A[i] - (i * 2 + 2)); + } + cout << min(res1, res2) << endl; + return 0; +} +int main() { + int i, n, k; + while (cin >> n) { + k = 0; + for (i = 1; n >= 0; i++) { + k += i; + n -= k; + } + cout << (i - 2) << endl; + } +} +int main() { + int n, m, z, cnt = 0; + cin >> n >> m >> z; + int i = n; + int j = m; + while (i <= z) { + while (j < i) { j = j + m; } + if (i == j) { + cnt++; + j = j + m; + } + i = i + n; + } + cout << cnt << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int mpoints = max(3 * a / 10, a - (a / 250) * c); + int vpoints = max(3 * b / 10, b - (b / 250) * d); + if (mpoints > vpoints) + cout << "Misha\n"; + else if (vpoints > mpoints) + cout << "Vasya\n"; + else + cout << "Tie\n"; + return 0; +} +long long MOD = 1000000007; +long long solve(long long A, long long B, long long C, long long L) { + long long res = 0; + for (long long i = 0; i <= L; i++) { + long long a = A + i - B - C; + long long t = min(a, L - i); + if (t >= 0) res += (t + 2) * (t + 1) / 2; + } + return res; +} +int main() { + long long A, B, C, L; + cin >> A >> B >> C >> L; + long long res = 0; + for (long long i = 0; i <= L; i++) { res += (L - i + 2) * (L - i + 1) / 2; } + res -= solve(A, B, C, L); + res -= solve(B, C, A, L); + res -= solve(C, A, B, L); + cout << res << endl; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + int box = 0; + int sum = 0; + for (int i = 0; i < N; i++) { + cin >> M; + sum += M; + box = max(box, sum); + K += abs(M); + } + cout << K << endl; + return 0; +} +int main() { + int i, j, m, a, s, d, c, b, n, x, p = 0, y, k = 0, an[1001], am[1001]; + cin >> n >> m; + for (i = 0; i < n; i++) { cin >> an[i]; } + for (j = 0; j < m; j++) { cin >> am[j]; } + for (i = 0, j = 0; i < n;) { + if (am[j] >= an[i]) { + k++; + i++; + j++; + } else + i++; + } + if (k > m) + cout << m << endl; + else + cout << k << endl; + return 0; +} +int a[200005]; +int main() { + int n, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + int ans = 0; + for (int i = 1; i <= n; i++) { + ans += a[i]; + if (ans >= (sum + 1) / 2) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int t, s, q; + while (cin >> t >> s >> q) { + int ans = 0; + while (s < t) { + ans++; + s *= q; + } + cout << ans << endl; + } +} +int main() { + long long levels = 0; + long long player_1 = 0; + long long player_2 = 0; + long long achivement_Player1_2 = 0; + long long pass[100] = {0}; + cin >> levels; + cin >> player_1; + for (int i = 0; i < player_1; i++) { + cin >> achivement_Player1_2; + pass[achivement_Player1_2 - 1]++; + } + cin >> player_2; + for (int i = 0; i < player_2; i++) { + cin >> achivement_Player1_2; + pass[achivement_Player1_2 - 1]++; + } + for (int i = 0; i < levels; i++) { + if (pass[i] == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } + } + cout << "I become the guy." << endl; + return 0; +} +long long phi(long long x) { + stringstream ss; + ss << x; + string s; + ss >> s; + for (int i = (0); i <= ((int)(s).size() - 1); i++) { s[i] = '0' + '9' - s[i]; } + long long ans; + ss.clear(); + ss << s; + ss >> ans; + return ans; +} +int main() { + int l, r; + cin >> l >> r; + long long x = 1, ans = 0; + for (int d = (0); d <= (9); d++) { + long long y = x / 2; + if (y <= r && y >= l) { ans = max(ans, y * (y - 1)); } + x *= 10; + } + long long pl = phi(l), pr = phi(r); + ans = max(ans, l * pl); + ans = max(ans, r * pr); + cout << ans << "\n"; + return 0; +} +int main() { + int n, m, k; + cin >> m >> k; + n = m + 1; + vector D(m), second(m); + for (int i = 0; i < m; ++i) cin >> D[i]; + for (int i = 0; i < m; ++i) cin >> second[i]; + long long mx = second[0], tm = 0, fuel = 0; + for (int i = 0; i < m; ++i) { + mx = max(mx, second[i]); + fuel += second[i]; + if (D[i] > fuel) { + long long aux = (D[i] - fuel) / mx + ((D[i] - fuel) % mx > 0); + tm += aux * k; + fuel += mx * aux; + } + fuel -= D[i]; + tm += D[i]; + } + cout << tm << "\n"; + return 0; +} +long long a, b, n; +long long ans[1010]; +bool flag; +void dfs(long long x, long long y, long long step) { + ans[step] = x; + if (flag || x > y) return; + if (x == y) { + n = step; + flag = true; + return; + } + dfs(x * 2, y, step + 1); + if (!flag) dfs(x * 10 + 1, y, step + 1); +} +int main() { + while (cin >> a >> b) { + flag = false; + dfs(a, b, 1); + if (flag) { + cout << "YES" << endl; + cout << n << endl; + for (int i = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' '); + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + long long ans, i, k, n, sum; + cin >> n; + k = 2; + ans = 1; + cout << '2' << endl; + for (i = 2; i <= n; i++) { + k = (i + 1) * (i + 1) * i - (i - 1); + cout << k << endl; + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int cnt = 0; + for (int i = 0; i <= n; i++) { + if (s[i] == '1') { + cnt++; + } else { + cout << cnt; + cnt = 0; + } + } + cout << "\n"; + return 0; +} +int a[10]; +int main() { + int x; + for (int i = 1; i <= 6; i++) { + cin >> x; + a[x]++; + } + int y = -1, z = -1; + for (int i = 1; i <= 9; i++) { + if (a[i] >= 4) { z = i; } + } + if (z != -1) { + a[z] = a[z] - 4; + for (int i = 1; i <= 9; i++) { + if (a[i] == 1 && y == -1) { y = i; } + if (a[i] == 1 && y != -1) { z = i; } + if (a[i] == 2) { y = z = a[i]; } + } + if (y == z) + cout << "Elephant" << endl; + else + cout << "Bear" << endl; + } else + cout << "Alien" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << 4 * (sqrt(a * c / b) + sqrt(b * c / a) + sqrt(a * b / c)) << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long S = 0, l, r; + for (int i = 0; i < n; i++) { + cin >> l >> r; + S += r - l + 1; + } + cout << (S / k + (S % k != 0)) * k - S << endl; + return 0; +} +int main() { + long long int n, k, c, d, normal; + cin >> n >> k; + d = n / (2 * (k + 1)); + c = d * k; + normal = n - d - c; + cout << d << " " << c << " " << normal << endl; + return 0; +} +const long long M = 998244353; +const long long oo = 1e13; +int a[1010]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + int ans = 1e9; + for (int x = 1; x <= n; ++x) { + int sum = 0; + for (int j = 1; j <= n; ++j) { sum += ((abs(j - x) + j - 1 + x - 1) * 2) * a[j]; } + ans = min(ans, sum); + } + cout << ans << endl; +} +int main() { + map m; + int c = 1; + for (char a = 'a'; a <= 'z'; a++) { m[a] = c++; } + int n, k, res = 0; + string s; + cin >> n >> k >> s; + sort(s.begin(), s.end()); + char tmp; + for (int i = 0; i < n; i++) { + if (i == 0) { + res += m[s[i]]; + k--; + tmp = s[i]; + } else if (s[i] - tmp > 1) { + res += m[s[i]]; + k--; + tmp = s[i]; + } + if (!k) break; + } + if (!k) + cout << res << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + int a[n]; + for (i = 0; i <= n; i++) { cin >> a[i]; } + sort(a, a + n); + if (a[0] == 1) + cout << -1 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + long long n, c = 0; + cin >> n; + long long a[n], b[n]; + for (long long i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { + if (i != j) { + if (a[i] == b[j]) c++; + } + } + } + cout << c << endl; + return 0; +} +const long long INF = (1LL << 45LL); +const long long MAXLL = 9223372036854775807LL; +const unsigned long long MAXULL = 18446744073709551615LLU; +const long long MOD = 1000000007; +const long double DELTA = 0.000000001L; +long long mpow(long long x, long long n1) { + long long ret = 1; + while (n1 > 0) { + if (n1 % 2 == 1) ret = ret * x % MOD; + x = x * x % MOD; + n1 /= 2; + } + return ret; +} +long long inverse(long long x) { + return mpow(x, MOD - 2); +} +long long _gcd(long long a, long long b) { + if (b == 0) return a; + return _gcd(b, a % b); +} +long long dx[4] = {0, 0, 1, -1}; +long long dy[4] = {1, -1, 0, 0}; +long long cnt[5005]; +long long vec[5005][5005]; +int main() { + long long n, gcd; + cin >> n; + long long A[n]; + for (long long i = 0; i < (n); ++i) { cin >> A[i]; } + long long mx1 = A[0]; + gcd = A[0]; + set st; + for (long long i = 0; i < (n); ++i) { + mx1 = max(mx1, A[i]); + gcd = _gcd(gcd, A[i]); + } + long long ans = mx1 / gcd; + if (abs(ans - n) % 2 == 1) { + cout << "Alice\n"; + } else { + cout << "Bob\n"; + } + return 0; +} +int main() { + vector v; + v.push_back('^'); + v.push_back('>'); + v.push_back('v'); + v.push_back('<'); + char a, b; + long long int n, idxa, idxb; + cin >> a >> b >> n; + for (long long int i = 0; i < 4; i++) { + if (a == v[i]) idxa = i; + if (b == v[i]) idxb = i; + } + n %= 4; + if (idxa % 2 == idxb % 2) + cout << "undefined" << endl; + else if (v[(idxa + n) % 4] == v[idxb % 4]) + cout << "cw" << endl; + else if (v[(idxa - n + 4) % 4] == v[idxb % 4]) + cout << "ccw" << endl; + return 0; +} +int main() { + const string greeting = "hello"; + string line; + getline(cin, line); + int a = 0, b = 0; + string output = "NO"; + while (b < line.size()) { + if (line[b++] == greeting[a]) { a++; } + if (a >= greeting.size()) { + output = "YES"; + break; + } + } + cout << output << endl; + return 0; +} +int main() { + int n, i, l, cnt = 0; + bool az[26]; + map mp; + string str, sub; + cin >> n; + while (n--) { + cin >> str; + l = str.size(); + memset(az, 0, sizeof(az)); + for (i = 0; i < l; i++) az[str.at(i) - 'a'] = 1; + for (i = 0, sub = ""; i < 26; i++) { + if (az[i]) sub += (char)(97 + i); + } + if (!mp[sub]) { + mp[sub] = 1; + cnt++; + } + } + cout << cnt << endl; + return 0; +} +long long gcd(long long x, long long y) { + if (y == 0) + return x; + else + return gcd(y, x % y); +} +long long expo(long long n, long long m, long long p) { + long long r = 1; + n = n % p; + while (m > 0) { + if (m % 2) r = (r * n) % p; + n = (n * n) % p; + m = m / 2; + } + return r % p; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long num = s / c; + long long ans = num; + if (num >= a) { ans += (num / a) * b; } + cout << ans << "\n"; + } + return 0; +} +string a, b; +char x, y; +int n; +int main() { + int ans = 0; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + x = a[i]; + y = b[i]; + if (x > y) + ans = ans + min(x - y, 10 - x + y); + else + ans = ans + min(y - x, 10 - y + x); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + n--; + int k = a; + if (k > b) k = b; + if (k > c) { + k += (n - 1) * c; + } else + k += (n - 1) * k; + if (n == 0) k = 0; + cout << k << endl; + return 0; +} +int main() { + string s; + cin >> s; + cout << (s.size() + 1) * 26 - s.size() << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +long long x[200000 + 5], y[200000 + 5], a[6], b[6]; +int main() { + long long i, j, k, l, r, co = 0; + long long n, m, t; + cin >> n; + for (i = 0; i < n; i++) cin >> x[i], a[x[i]]++; + for (i = 0; i < n; i++) cin >> y[i], b[y[i]]++; + for (i = 1; i <= 5; i++) { + if ((a[i] + b[i]) % 2) { + cout << -1 << endl; + return 0; + } + k = min(a[i], b[i]); + co += (a[i] - k + b[i] - k) / 2; + } + if (co % 2) + cout << 0 << endl; + else + cout << co / 2 << endl; + return 0; +} +int main() { + int i, j, n, p, q; + vector v1, v2; + set s; + cin >> n; + cin >> p; + for (i = 0; i < p; i++) { + cin >> j; + v1.push_back(j); + } + cin >> q; + for (i = 0; i < q; i++) { + cin >> j; + v2.push_back(j); + } + for (i = 0; i < p; i++) { s.insert(v1[i]); } + for (i = 0; i < q; i++) { s.insert(v2[i]); } + set::iterator itr; + j = 0; + for (itr = s.begin(); itr != s.end(); itr++) { + if (*itr <= n) { j++; } + } + if (j == n) { + cout << "I become the guy." << endl; + } else { + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int main() { + vector v; + set se; + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { v.push_back(s[i]); } + for (int i = 0; i < s.length() - 1; i++) { v.push_back(s[i]); } + for (int i = 0; i < v.size() - s.length() + 1; i++) { + string t; + for (int j = i; j < i + s.length(); j++) { t.push_back(v[j]); } + se.insert(t); + } + cout << se.size() << endl; + return 0; +} +int main() { + int m, k; + cin >> m >> k; + int n = m + 1; + int ttl = 0; + int d[m], s[m]; + for (int i = 0; i <= m - 1; ++i) { cin >> d[i]; } + int fuel = 0; + int mx = 0; + for (int i = 0; i <= m - 1; ++i) { + cin >> s[i]; + if (s[i] > mx) mx = s[i]; + fuel += s[i]; + while (fuel < d[i]) fuel += mx, ttl += k; + fuel -= d[i]; + ttl += d[i]; + } + cout << ttl << endl; + return 0; +} +const long long mo = 1e9 + 7; +string s; +long long n, ans; +long long poww(long long a, long long x) { + long long res = 1; + while (x) { + if (x & 1) res *= a, res %= mo; + a *= a, a %= mo, x >>= 1; + } + return res; +} +long long cal(string s) { + long long a = 0; + for (long long i = 0; i < n; ++i) { + a <<= 1; + if (s[i] == '1') a++; + a %= mo; + } + return a; +} +int main() { + cin >> s; + n = s.size(); + ans = poww(2, n - 1); + ans *= cal(s); + ans %= mo; + cout << ans << endl; + return 0; +} +int main() { + int n, i, j, a[100002]; + cin >> n; + int sum = 0; + int mx = -1; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + mx = max(mx, a[i]); + } + while (1) { + if (mx * n - sum > sum) { + cout << mx << endl; + return 0; + } else { + mx++; + } + } + return 0; +} +int n, k; +int A[105]; +int a, b; +int flag; +int main() { + cin >> n >> k; + a = b = flag = 0; + for (int i = 0; i < n; i++) { + cin >> A[i]; + if (A[i] > k && flag == 0) { + a = i; + flag = 1; + } else if (A[i] > k && flag == 1) { + b = i; + } + } + if (b != 0) { + cout << n - b + a - 1 << endl; + } else if (A[0] > k || a != 0) { + cout << n - 1 << endl; + } else { + cout << n << endl; + } +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + if (a + b - c < n && c <= a && c <= b) { + cout << n + c - a - b << endl; + } else + cout << "-1\n"; + return 0; +} +bool test(int a, int p, int mod) { + int res = 1; + for (int t = 0; t < p - 2; t++) { + res *= a; + res %= mod; + if (res == 1) { return false; } + } + return true; +} +int main() { + int p, mod; + cin >> p; + mod = p; + int cnt = 0; + for (int x = 1; x < p; x++) { + if (test(x, p, mod)) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, j = 0, m = 0; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 1; i++) { + int x = a[i + 1] - a[i]; + if (x > m) m = x; + } + for (int i = 1; i < n - 1; i++) { + b[j] = a[i + 1] - a[i - 1]; + j++; + } + j--; + sort(b, b + j); + int y = max(m, b[0]); + cout << y << endl; + return 0; +} +char ss[3][12] = {"qwertyuiop", "asdfghjkl;", "zxcvbnm,./"}; +int main() { + char cmd; + string s; + cin >> cmd; + cin >> s; + if (cmd == 'R') { + for (int i = 0; i < s.size(); i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 10; k++) + if (s[i] == ss[j][k]) cout << ss[j][k - 1]; + } else { + for (int i = 0; i < s.size(); i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 10; k++) + if (s[i] == ss[j][k]) cout << ss[j][k + 1]; + } + cout << endl; + return 0; +} +int main() { + int n, n1, n2; + cin >> n; + if (n >= 0) { cout << n << endl; } + if (n < 0) { + n = -n; + n1 = n / 10; + n2 = (n / 100) * 10 + (n % 10); + if (n1 > n2) { + cout << -n2 << endl; + } else { + cout << -n1 << endl; + } + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 1 || i % 4 == 2 && j == m || i % 4 == 0 && j == 1) + cout << "#"; + else + cout << "."; + } + cout << endl; + } + return 0; +} +int N; +long long P, Q, B; +long long gcd(long long x, long long y) { + if (y == 0) return x; + return gcd(y, x % y); +} +int main() { + cin >> N; + while (N--) { + cin >> P >> Q >> B; + P %= Q; + long long G = gcd(P, Q); + Q /= G; + long long C = gcd(B, Q); + while (C != 1) { + Q /= C; + C = gcd(C, Q); + } + if (Q != 1) + cout << "Infinite\n"; + else + cout << "Finite\n"; + } + return 0; +} +int main() { + int n, m; + cin >> n; + m = n / 2; + cout << m + 1 << endl; + return 0; +} +int main() { + int n, m, dem = 0; + long long int x, y, in; + vector a, b; + vector c; + cin >> n >> m >> x >> y; + a.resize(n); + b.resize(m); + int ia = 0, ib = 0; + while (n--) { + cin >> in; + a[ia++] = in; + } + while (m--) { + cin >> in; + b[ib++] = in; + } + int cnta = a.size(), cntb = b.size(), ic = 0; + n++; + m++; + c.resize(2000000); + while (n < cnta && m < cntb) { + if (a[n] <= (b[m] + x) && a[n] >= (b[m] - y)) { + dem++; + c[ic++] = ++n; + c[ic++] = ++m; + } else { + if (a[n] > b[m] + x) { m++; } + if (a[n] < b[m] - y) { n++; } + } + } + cout << dem << "\n"; + dem = 0; + for (int i = 0; i < ic; i++) { + if (dem % 2 == 0) { + cout << c[i] << " "; + } else { + cout << c[i] << "\n"; + } + dem++; + } + return 0; +} +int main() { + long long arr[100000] = {}, p, n, x, ans = 0, ind = -1; + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (arr[x % p] && ind == -1) + ind = i + 1; + else + arr[x % p] = 1; + } + cout << ind << "\n"; + return 0; +} +int n; +int main() { + cin >> n; + int sum = 0, temp, Max = 0; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp > Max) Max = temp; + sum += temp; + } + cout << max(Max, sum * 2 / n + 1) << endl; + return 0; +} +string T; +long long N, K, M, A, B, C, D, sum; +int main() { + cin >> N >> A >> B; + C = N - A; + for (int i = 1; i <= N; i++) { + cin >> K; + if (C > 0) { + sum += K; + C--; + } + } + cout << sum + A * B << '\n'; +} +const double PI = acos(-1.0); +const int INF = 1000 * 1000 * 1000 + 7; +const long long LINF = INF * (long long)INF; +const int L = 20; +const int MAX = 5000 + 47; +const int MOD = 998244353; +int n, k; +string s; +bool inside(int i) { + return i >= 0 && i < n; +} +int main() { + cin >> n >> k >> s; + k--; + int d = (k >= n || k < n - 1 - k ? -1 : 1); + while (1) { + if (k == n - 1 || k == 0) break; + cout << (d == -1 ? "LEFT" : "RIGHT") << endl; + k += d; + } + d = d * -1; + while (1) { + cout << "PRINT " << s[k] << endl; + k += d; + if (!inside(k)) break; + cout << (d == -1 ? "LEFT" : "RIGHT") << endl; + } +} +long long n, a[200005], cnt, mn = 1000000001, q; +int main() { + cin >> n; + mn *= 2; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n - 1; i++) { + cnt = abs(a[i] - a[i + 1]); + if (cnt < mn) { + mn = cnt; + q = 0; + } + if (cnt == mn) q++; + } + cout << mn << " " << q << endl; + return 0; +} +int main() { + long long n, m; + cin >> n; + long long a[n + 1], mx = 0; + for (int i = 0; i < n; ++i) cin >> a[i], mx += a[i]; + cin >> m; + long long l, r, ans = -1; + for (int i = 0; i < m && ans == -1; ++i) { + cin >> l >> r; + if (r >= mx) ans = max(mx, l); + } + cout << ans << "\n"; +} +int n, k, a, b; +int main() { + cin >> n >> k; + for (int i = 0; i < k; i++) { + cin >> a; + if (a == 0) { + cout << i << endl; + return 0; + } + } + for (int i = k; i < n; ++i) { + cin >> b; + if (b != a) { + cout << i << endl; + return 0; + } + } + cout << n << endl; + return 0; +} +int main() { + int n, j, i, m; + cin >> n >> m; + for (i = 1; i <= n; i++) { + if (i % 2 == 1) { + for (j = 1; j <= m; j++) cout << "#"; + cout << "\n"; + } else if (i % 4 == 0) { + cout << "#"; + for (j = m; j > 1; j--) cout << "."; + cout << "\n"; + } else { + for (j = m; j > 1; j--) cout << "."; + cout << "#\n"; + } + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long n = s / c; + long long off = n / a; + long long ans = off * a + off * b + n % a; + cout << ans << endl; + } + return 0; +} +int a[1001]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } +} +string nam[50]; +int n, wp[50], dg[50], sg[50]; +bool comp(int a, int b) { + if (wp[a] != wp[b]) + return wp[a] > wp[b]; + else if (dg[a] != dg[b]) + return dg[a] > dg[b]; + else + return sg[a] > sg[b]; +} +int main() { + cin >> n; + for (int i = 0; i < (int)(n); i++) cin >> nam[i]; + for (int i = 0; i < (int)(n * (n - 1) / 2); i++) { + string tmp, a, b; + int p, q; + char c; + cin >> tmp >> p >> c >> q; + a = tmp.substr(0, tmp.find('-')); + b = tmp.substr(tmp.find('-') + 1); + int ai = find(nam, nam + n, a) - nam, bi = find(nam, nam + n, b) - nam; + if (p > q) + wp[ai] += 3; + else if (p < q) + wp[bi] += 3; + else + wp[ai]++, wp[bi]++; + dg[ai] += p - q, sg[ai] += p, dg[bi] += q - p, sg[bi] += q; + } + int a[50]; + for (int i = 0; i < (int)(n); i++) a[i] = i; + sort(a, a + n, comp); + string names[50]; + for (int i = 0; i < (int)(n / 2); i++) names[i] = nam[a[i]]; + sort(names, names + n / 2); + for (int i = 0; i < (int)(n / 2); i++) cout << names[i] << endl; + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + if (a == 1 && b == 1) { + cout << 1 << endl; + return 0; + } + if (a == 1 && b == 0) { + cout << 0 << endl; + return 0; + } + for (int i = 1; i <= a; i++) { + if (b % i == 0 && b / i <= a) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) { + cout << 0 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else { + cout << 4 << endl; + } + return 0; +} +int a[1005], b[1005]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + if (a[1] == 0) { + cout << "NO" << endl; + } else if (a[1] == 1 && a[m] == 1) { + cout << "YES" << endl; + } else { + if (b[m] == 0) + cout << "NO" << endl; + else { + int bj = 0; + for (int i = m + 1; i <= n; i++) { + if (a[i] == 1 && b[i] == 1) { bj = 1; } + } + if (bj) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + } +} +int main() { + long long n, a, b, deflt, ans = 0; + long long arr[30]; + cin >> n >> a >> b; + deflt = min(a, b); + for (long long i = 0; i < n; ++i) cin >> arr[i]; + long long left = 0, right = n - 1; + while (left <= right) { + if (left == right && arr[left] == 2) + ans += deflt; + else { + if (arr[left] == 2 && arr[right] == 2) + ans += 2 * deflt; + else if (arr[left] == 2 || arr[right] == 2) { + if (arr[right] == 0) + ans += a; + else if (arr[left] == 0) + ans += a; + else if (arr[right] == 1) + ans += b; + else if (arr[left] == 1) + ans += b; + } else if (arr[left] != arr[right]) { + ans = -1; + break; + } + } + ++left; + --right; + } + cout << ans << '\n'; + return 0; +} +const double PI = 3.14159265358979323846264338327; +int main() { + string a, b; + cin >> a >> b; + vector a1(100020), b1(100020); + for (int i = a.size() - 1; i >= 0; i--) a1[a.size() - 1 - i] = a[i] - '0'; + for (int i = b.size() - 1; i >= 0; i--) b1[b.size() - 1 - i] = b[i] - '0'; + for (int i = 100010; i >= 0; i--) { + for (int j = i; a1[j] && a1[j + 1]; j += 2) a1[j] = a1[j + 1] = 0, a1[j + 2] = 1; + for (int j = i; b1[j] && b1[j + 1]; j += 2) b1[j] = b1[j + 1] = 0, b1[j + 2] = 1; + } + for (int i = 100010; i >= 0; i--) { + if (a1[i] < b1[i]) return cout << '<' << endl, 0; + if (a1[i] > b1[i]) return cout << '>' << endl, 0; + } + cout << '=' << endl; + return 0; +} +const int maxn = 1002; +const long long mod = 1e9 + 7; +long long k, c, num = 0; +long long ans = 1; +int a[maxn][maxn]; +void init() { + for (int i = 1; i < maxn; i++) { + a[i][1] = 1; + for (int j = 2; j <= i; j++) { a[i][j] += (a[i - 1][j] + a[i - 1][j - 1]) % mod; } + } +} +int main() { + init(); + cin >> k; + for (int i = 0; i < k; i++) { + cin >> c; + num += c; + ans = (ans * a[num][c]) % mod; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int t1, t2, t3; + t1 = (k * l) / nl; + t2 = c * d; + t3 = p / np; + int tx = min(t1, t2); + cout << min(tx, t3) / n << endl; + return 0; +} +int main() { + long long n, k, f, t, max; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (i == 0) + if (t >= k) + max = f - (t - k); + else + max = f; + else if (t >= k) { + if (f - (t - k) > max) max = f - (t - k); + } else if (f > max) + max = f; + } + cout << max << endl; + return 0; +} +int main() { + int X[5][5], x, y; + for (int i = 0; i < 5; ++i) { + for (int j = 0; j < 5; ++j) { + cin >> X[i][j]; + if (X[i][j] == 1) { + x = i + 1; + y = j + 1; + } + } + } + int moves = abs(3 - x) + abs(3 - y); + cout << moves << endl; + return 0; +} +int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; +void fast() {} +int main() { + fast(); + int n; + string s; + cin >> n >> s; + int sum = 0; + for (int i = 0; i < n; i++) { + if (s[i] != '4' && s[i] != '7') + return cout << "NO" + << "\n", + 0; + ; + if (i < n / 2) + sum += s[i] - '0'; + else + sum -= s[i] - '0'; + } + cout << (sum == 0 ? "YES" : "NO") << "\n"; +} +int main() { + basic_string card = "SHDC"; + basic_string levl = "6789TJQKA"; + string a, b; + char tr; + cin >> tr >> a >> b; + if (a.find(tr) != a.npos && b.find(tr) == b.npos) { + puts("YES"); + } else if (a[1] != b[1]) { + puts("NO"); + } else { + if (levl.find(a[0]) > levl.find(b[0])) { + puts("YES"); + } else { + puts("NO"); + } + } + return true & false; +} +int main() { + int j; + cin >> j; + cout << "25" << endl; + return 0; +} +long long gcd(long long a, long long b) { + long long c; + while (a != 0) { + c = a; + a = b % a; + b = c; + } + return b; +} +int main() { + long long a, b; + cin >> a >> b; + long long lcm = a * b / gcd(a, b); + long long cnt1 = (lcm / a) - 1; + long long cnt2 = (lcm / b) - 1; + if (a > b) + cnt1++; + else + cnt2++; + if (cnt1 > cnt2) + cout << "Dasha" << endl; + else if (cnt2 > cnt1) + cout << "Masha" << endl; + else + cout << "Equal" << endl; +} +int main() { + long long int n; + cin >> n; + long long int x = n / 2; + cout << n + x << endl; +} +int n, m; +int main() { + cin >> n >> m; + int a, b; + int t = 0; + while (n--) { + cin >> a >> b; + if (a <= t) t = max(t, b); + } + if (t >= m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string chr; +int n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> chr; + if (chr.size() <= 10) + cout << chr << endl; + else + cout << chr[0] << chr.size() - 2 << chr[chr.size() - 1] << endl; + } + return 0; +} +int main() { + int total = 0; + int i, j, n, mini = 110000; + int a, p; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> p; + if (p < mini) { + mini = p; + total += mini * a; + } else { + total += mini * a; + } + } + cout << total << '\n'; + return 0; +} +int a[100010]; +long long cnt[100010]; +int main() { + char c[155]; + int num[155]; + cin >> c; + int len = strlen(c); + for (int i = 0; i < len; i++) { + if (c[i] >= '5' && c[i] <= '9') { + if ((c[i] == '9' && i == 0)) + num[i] = c[i] - '0'; + else + num[i] = 9 - (c[i] - '0'); + } else + num[i] = c[i] - '0'; + } + for (int i = 0; i < len; i++) cout << num[i]; + cout << endl; + return 0; +} +int a, b, c, d, k, l, m, n, i; +int main() { + cin >> n; + for (i = n + 1; i < 9000000000000000000000000000000; i++) { + k = i / 1000; + c = i % 10; + d = (i % 100) / 10; + l = (i / 100) % 10; + if (k != c && k != d && k != l && c != d && c != l && d != l) { + cout << i << endl; + return 0; + } + } +} +int main() { + int n; + cin >> n; + string str; + char ch; + cin.get(ch); + getline(cin, str); + int cnt = 0; + int maximum = 0; + for (int i = 0; i < str.size(); i++) { + if (str[i] >= 'A' && str[i] <= 'Z') + cnt++; + else if (str[i] == ' ') { + if (cnt > maximum) maximum = cnt; + cnt = 0; + } + } + if (cnt > maximum) maximum = cnt; + cout << maximum << endl; + return 0; +} +long long gcd1(long long a, long long b) { + if (a == 0) return b; + return gcd1(b % a, a); +} +long long modx(long long base, long long ex) { + long long ans = 1LL, val = base; + while (ex > 0LL) { + if (ex & 1LL) ans = (ans * val) % 1000000009LL; + val = (val * val) % 1000000009LL; + ex = ex >> 1LL; + } + return ans; +} +long long dp[1000005], odd[1000005], ev[1000005]; +int main() { + int n; + cin >> n; + dp[1] = odd[1] = 1; + long long ans = 1; + for (int i = 2; i <= n; i++) { + if (i % 2) { + dp[i] = (ev[i - 1] + 1) % 1000000007LL; + odd[i] = (odd[i - 2] + dp[i]) % 1000000007LL; + } else { + dp[i] = (odd[i - 1] + 1) % 1000000007LL; + ev[i] = (ev[i - 2] + dp[i]) % 1000000007LL; + } + ans = (ans + dp[i]) % 1000000007LL; + } + cout << ans << endl; + return 0; +} +long long n, m, k, res; +int main() { + cin >> n >> m; + k = n; + while (k < m) { + k *= n; + res++; + } + if (k == m) { + cout << "YES\n" << res << endl; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + string s, t; + int k = 0; + cin >> s >> t; + for (int i = 0; i < t.length(); i++) { + if (s[k] == t[i]) { k++; } + } + cout << ++k << endl; + return 0; +} +void change(bool mat[][3], int i, int j) { + if (mat[i][j] == true) + mat[i][j] = false; + else + mat[i][j] = true; +} +int main() { + bool lights[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { lights[i][j] = true; } + } + bool toggle[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + int temp; + cin >> temp; + if (temp % 2 == 0) + toggle[i][j] = 0; + else + toggle[i][j] = 1; + } + } + int i = 0, j = 0; + while (i < 3) { + j = 0; + while (j < 3) { + if (toggle[i][j] == 1) { + change(lights, i, j); + if ((i - 1) >= 0) change(lights, i - 1, j); + if ((i + 1) < 3) change(lights, i + 1, j); + if ((j - 1) >= 0) change(lights, i, j - 1); + if ((j + 1) < 3) change(lights, i, j + 1); + } + j++; + } + i++; + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << lights[i][j]; } + cout << endl; + } +} +int main() { + int n, m, min; + cin >> n >> m; + if (n >= m) + min = m; + else + min = n; + if (min % 2) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; + return 0; +} +long long n, k, w, tot; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> w; + tot += (w + k - 1) / k; + } + cout << (tot + 1) / 2 << endl; +} +int main() { + int t, a, b; + cin >> t; + while (t--) { + cin >> a >> b; + int ans = 0, tmp, x; + while (a > 0 && b > 0) { + if (a == b) { + ans++; + break; + } + if (a > b) swap(a, b); + tmp = b - a; + x = tmp / a; + if (tmp % a != 0) x++; + ans += x; + b -= a * x; + } + cout << ans << endl; + } +} +int main() { + int a, b, c, count = 0; + cin >> a >> b >> c; + if ((a * c) % b == 0) { + count = ((a * c) / b) - c; + } else { + count = (((a * c) / b) - c) + 1; + } + cout << count << endl; +} +int main() { + int n, l, sl, a; + cin >> n; + if (n >= 0) { + cout << n << endl; + return 0; + } + a = n; + l = a % 10; + a = a / 10; + sl = a % 10; + a = a - sl; + if (sl > l) + a += sl; + else + a += l; + cout << a << endl; + return 0; +} +int main() { + long long a, b, c, d, max1 = 0, max2 = 0; + while (cin >> a >> b >> c >> d) { + max1 = max(((3 * a) / 10), (a - ((a / 250) * c))); + max2 = max(((3 * b) / 10), (b - ((b / 250) * d))); + if (max1 > max2) + cout << "Misha" << endl; + else if (max1 < max2) + cout << "Vasya" << endl; + else if (max1 == max2) + cout << "Tie" << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long res = 1, pm = 1; + for (int i = 0; i < m; i++) pm = (pm * 2) % 1000000009LL; + pm--; + if (pm < 0) pm += 1000000009LL; + for (int i = 0; i < n; i++, pm--) res = ((res * pm) % 1000000009LL + 1000000009LL) % 1000000009LL; + cout << res << endl; + return 0; +} +const long long int N = 107; +long long int a[N]; +int main() { + long long int n, m, i, j, u = 0, v = INT_MAX; + vector vs; + cin >> n >> m; + for (i = 1; i <= n; i++) { + cin >> a[i]; + vs.push_back(a[i]); + u = max(u, a[i]); + } + u = u + m; + while (m--) { + sort(vs.begin(), vs.end()); + vs[0]++; + } + sort(vs.begin(), vs.end()); + cout << vs[vs.size() - 1] << " " << u << '\n'; + return 0; +} +int main() { + int game, money; + cin >> game >> money; + int g[1005]; + int m[1005]; + for (int i = 0; i < game; i++) { cin >> g[i]; } + for (int i = 0; i < money; i++) { cin >> m[i]; } + int gp = 0, mp = 0; + int count = 0; + while (gp < game && mp < money) { + if (g[gp] <= m[mp]) { + count++; + gp++; + mp++; + } else + gp++; + } + cout << count << endl; +} +int main() { + long long int tabeSize, num, i, cnt = 0; + cin >> tabeSize >> num; + for (i = 1; i <= tabeSize; i++) { + if (num % i == 0 && num / i <= tabeSize) cnt++; + } + cout << cnt << endl; + return 0; +} +int n; +int main() { + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) + cout << 1 << endl; + else + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n - 1; ++i) { + if (s[i] != s[i + 1]) { + cout << "YES" << endl; + cout << s.substr(i, 2) << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int p, n, x; + cin >> p >> n; + vector v; + int z[n]; + bool a = 1; + for (int i = 0; i < n; i++) { cin >> z[i]; } + for (int i = 0; i < n; i++) { + x = z[i] % p; + if (find(v.begin(), v.end(), x) != v.end()) { + a = 0; + cout << i + 1 << endl; + break; + } else + v.push_back(x); + } + if (a) cout << -1 << endl; + return 0; +} +int ar[200005]; +int main() { + int n, i, ret = 1e9; + cin >> n; + for (i = 0; i < n; ++i) cin >> ar[i]; + sort(ar, ar + n); + for (i = 0; i + n / 2 < n; ++i) ret = min(ret, ar[i + n / 2] - ar[i]); + cout << ret << endl; +} +int main() { + int num; + cin >> num; + if (num == 0) { cout << "O-|-OOOO" << endl; } + while (num > 0) { + int digit = num % 10; + if (digit >= 5) + cout << "-O"; + else + cout << "O-"; + cout << "|"; + for (int i = 0; i < digit % 5; i++) cout << "O"; + cout << "-"; + for (int i = 0; i < 4 - (digit % 5); i++) cout << "O"; + cout << endl; + num /= 10; + } + return 0; +} +long long go(long long x) { + long long ans = 0; + while (x > 0) { + x /= 2; + ans += 1; + } + return ans; +} +long long go1(long long x) { + long long ans = 0; + while (x > 0) { + if (x % 2 != 0) ans += 1; + x /= 2; + } + return ans; +} +long long go2(long long x, long long y) { + long long a = 1; + if (go1(x) < go1(y)) { + a = y; + } else + a = x; + long long ans = 1; + long long cnt = 1; + long long temp = 1; + while (x > 0) { + if (y % 2 != 0 && x % 2 == 0) { + cnt = ans - 1; + temp = ans - 1; + } else { + if (y % 2 != 0) temp += ans; + } + ans *= 2; + x /= 2; + y /= 2; + } + if (go1(a) == go1(temp)) { + if (a < temp) { + return a; + } else { + return temp; + } + } + if (go1(a) < go1(temp)) { + return temp; + } else { + return a; + } +} +int main() { + int n; + cin >> n; + while (n--) { + long long x, y; + cin >> x >> y; + long long a = go(x); + long long b = go(y); + if (x == y) + cout << x << '\n'; + else if (a < b) { + if (go1(y) == b) { + long long temp = ((long long)1 << b) - 1; + cout << temp << '\n'; + } else { + b -= 1; + long long temp = ((long long)1 << b) - 1; + cout << temp << '\n'; + } + } else { + cout << go2(x, y) << '\n'; + } + } +} +string a, b; +int main() { + cin >> a >> b; + if (a != b) { + cout << max(a.size(), b.size()) << endl; + return 0; + } else { + cout << "-1" << endl; + return 0; + } +} +int main() { + int test; + cin >> test; + while (test--) { + int n, r; + cin >> n >> r; + int sum = r; + for (int i = 0; i < n - 1; ++i) { + int val; + cin >> val; + sum -= val; + } + sum = (sum % n + n) % n; + cout << (sum + 1) << "\n"; + } + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int cnt = 0; + for (int i = 0; i < n; i++) { + long long int l, r; + cin >> l >> r; + cnt += r - l + 1; + } + long long int ans = k - cnt % k; + if (ans == k) ans = 0; + cout << ans << "\n"; + return 0; +} +int main() { + int n, p, q, x = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> p >> q; + if (q - p >= 2) x++; + } + cout << x << endl; + return 0; +} +int main() { + string s; + cin >> s; + if (s == "a1" || s == "a8" || s == "h1" || s == "h8") { + cout << 3 << endl; + } else if (s[0] == 'a' || s[0] == 'h' || s[1] == '1' || s[1] == '8') { + cout << 5 << endl; + } else { + cout << 8 << endl; + } + return 0; +} +int main() { + string s[6] = {"purple", "green", "blue", "orange", "red", "yellow"}; + string output[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + int n; + cin >> n; + string input[n], temp; + bool out[6]; + for (int i = 0; i < 6; i++) { out[i] = true; } + for (int i = 0; i < n; i++) { + cin >> input[i]; + for (int j = 0; j < 6; j++) { + if (s[j] == input[i]) { + out[j] = false; + break; + } + } + } + long long t = 0; + for (int i = 0; i < 6; i++) { + if (out[i]) { t++; } + } + cout << t << endl; + for (int i = 0; i < 6; i++) { + if (out[i]) { + cout << output[i]; + cout << endl; + } + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + double p1 = max((3.0 * a) / 10.0, a - (a * c) / 250.0); + double p2 = max((3.0 * b) / 10.0, b - (b * d) / 250.0); + if (p1 > p2) { + cout << "Misha" << endl; + } else if (p2 > p1) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } +} +int ans; +int main() { + pair s[35]; + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> s[i].first >> s[i].second; } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i != j) { + if (s[i].first == s[j].second) ans++; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, x, y = 0; + cin >> n >> m; + vector v(n, 0); + for (int i = 0; i < m; ++i) { + int mj = 0, val = 0; + for (int j = 0; j < n; ++j) { + cin >> x; + if (x > val) { + mj = j; + val = x; + } + } + v[mj]++; + } + int mj = 0, val = 0; + for (int j = 0; j < n; ++j) { + if (v[j] > val) { + mj = j; + val = v[j]; + } + } + cout << (mj + 1) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int maxx = arr[0]; + int minn = arr[0]; + int c = 0; + for (int i = 1; i < n; i++) { + if (arr[i] > maxx || arr[i] < minn) c++; + maxx = max(maxx, arr[i]); + minn = min(minn, arr[i]); + } + cout << c << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (int i = 0; i < s1.length(); i++) { + s1[i] = tolower(s1[i]); + s2[i] = tolower(s2[i]); + if (int(s1[i]) > int(s2[i])) { + cout << "1" << endl; + break; + } else if (int(s1[i]) < int(s2[i])) { + cout << "-1" << endl; + break; + } else if (i == s1.length() - 1) { + cout << "0" << endl; + } + } + return 0; +} +int main() { + string s; + while (cin >> s) { + bool h, e, o; + int ll; + h = e = ll = o = 1; + string ans; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'h' && h) ans += 'h', h = 0; + if (s[i] == 'e' && e && !h) ans += 'e', e = 0; + if (s[i] == 'l' && ll <= 2 && !e) ans += 'l', ll++; + if (s[i] == 'o' && o && ll == 3) ans += 'o', o = 0; + } + if (ans == "hello") + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +unsigned long long const mod = 1000000007; +unsigned long long const md = 998244353; +unsigned long long mypow(unsigned long long a, unsigned long long b) { + unsigned long long res = 1; + a %= mod; + assert(b >= 0); + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +ifstream in("txt.in"); +ofstream out("txt.out"); +int main() { + cout << fixed << setprecision(12); + unsigned long long n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << '\n'; + return 0; +} +int main() { + string s; + int a[30] = {0}, ans = 0; + while (cin >> s) { + if (s[1] == '}') { + if (s[0] != '{') a[s[0] - 'a']++; + for (int i = 0; i < 26; i++) + if (a[i]) ans++; + cout << ans << endl; + ans = 0; + memset(a, 0, sizeof(a)); + } else if (s[0] == '{') { + if (s[2] != '}') + a[s[1] - 'a']++; + else + cout << 1 << endl; + } else + a[s[0] - 'a']++; + } + return 0; +} +int gcd(int a, int b); +int main() { + string n; + string a, b, c, d, e; + cin >> n >> a >> b; + cin >> c >> d >> e; + if (n[0] == a[0] || n[1] == a[1]) { + cout << "YES" << endl; + return 0; + } + if (n[0] == b[0] || n[1] == b[1]) { + cout << "YES" << endl; + return 0; + } + if (n[0] == c[0] || n[1] == c[1]) { + cout << "YES" << endl; + return 0; + } + if (n[0] == d[0] || n[1] == d[1]) { + cout << "YES" << endl; + return 0; + } + if (n[0] == e[0] || n[1] == e[1]) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int gcd(int a, int b) { + if (b == 0) { + return a; + } else { + return gcd(b, a % b); + } +} +const int maxn = 1e6 + 6; +int n, a, b; +int arr[maxn]; +int len = 0; +string str; +int main() { + cin >> n >> a >> b; + cin >> str; + for (int i = 1; i <= n; i++) arr[i] = str[i - 1]; + if (arr[a] == arr[b]) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int g[11][11]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) g[1][i] = 1; + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= n; j++) { g[i][j] = g[i - 1][j] + g[i][j - 1]; } + } + cout << g[n][n] << endl; + return 0; +} +int a[10010]; +int main() { + a[1] = 1; + long long int sum, m; + for (int i = 2; i <= 10000; i++) a[i] = a[i - 1] + i; + while (cin >> m) { + for (int i = 1; i <= 10000; i++) { + m -= a[i]; + if (m < a[i + 1]) { + cout << i << endl; + break; + } + } + } + return 0; +} +int n, ans; +set s; +int main() { + cin >> n; + for (int i = 1; i <= n; i += 1) { + int a; + cin >> a, s.insert(a); + } + ans = (int)s.size(); + if (s.count(0)) ans--; + cout << ans << '\n'; + return 0; +} +int a[35][35]; +int n; +bool cheak(int i, int j) { + int sumx = 0, sumy = 0; + for (int k = 0; k < n; k++) { + sumx += a[i][k]; + sumy += a[k][j]; + } + if (sumx < sumy) { return 1; } + return 0; +} +int main() { + while (cin >> n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int sum = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int x = cheak(i, j); + if (x) { sum++; } + } + } + cout << sum << endl; + } + return 0; +} +int main() { + int t; + int x, y; + int c = 0; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> x >> y; + if (y - x >= 2) c++; + } + cout << c << endl; + return 0; +} +const int maxx = 1e9; +map m; +vector blocks; +int main() { + int vert, horiz; + cin >> vert >> horiz; + for (int i = 0; i < vert; i++) { + int ss; + cin >> ss; + blocks.push_back(ss); + } + sort(blocks.begin(), blocks.end()); + int res = 0; + for (int i = 0; i < horiz; i++) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 == 1) { + res++; + if (x2 == maxx) { continue; } + m[x2]++; + } + } + int ans = res; + blocks.push_back(maxx + 1); + for (int i = 0; i < blocks.size(); i++) { + while (!m.empty() and (m.begin())->first < blocks[i]) { + res -= (m.begin())->second; + m.erase(m.begin()); + } + ans = min(ans, res); + res++; + } + cout << ans << '\n'; +} +set s; +int main() { + s.insert('a'); + s.insert('e'); + s.insert('i'); + s.insert('o'); + s.insert('u'); + for (int i = 1; i < 10; i += 2) { s.insert(i + '0'); } + string k; + int ans = 0; + cin >> k; + int len = k.length(); + for (int i = 0; i < len; i++) { + if (s.count(k[i])) { ans++; } + } + cout << ans << endl; + return 0; +} +const double g = 9.8; +const int mod = 1000000007; +int n, i, j, k, ans; +const int x = 1e5; +long long a[x]; +int main() { + int i, j, k, m, n, t; + cin >> t; + for (i = 0; i < t; i++) cin >> a[i]; + int num = 0; + for (i = 1; i < t - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) num++; + if (a[i] < a[i - 1] && a[i] < a[i + 1]) num++; + } + cout << num << endl; + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + for (int i = int(1); i < int(a + 1); ++i) { + int maxsecction = b + i; + int mn = i * k; + int lel = min(mn, maxsecction); + if (lel * v >= a) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, t; + cin >> n; + vector one, two, three; + for (int i = 0; i < n; i++) { + cin >> t; + if (t == 1) + one.push_back(i + 1); + else if (t == 2) + two.push_back(i + 1); + else + three.push_back(i + 1); + } + int minsize = min(one.size(), min(two.size(), three.size())); + cout << minsize << endl; + for (int i = 0; i < minsize; i++) cout << one[i] << " " << two[i] << " " << three[i] << endl; + return 0; +} +int main() { + int n, h, m, a[100][100]; + while (cin >> n) { + int maxa = 0; + for (int i = 0; i < n; i++) { + cin >> h >> m; + a[h][m]++; + if (a[h][m] > maxa) maxa = a[h][m]; + } + cout << maxa << endl; + } + return 0; +} +int main() { + long long k; + int n, digit = 0; + cin >> k; + while (k) { + n = k % 10; + if (n == 4 || n == 7) { digit++; } + k /= 10; + } + if (digit == 4 || digit == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long N; + cin >> N; + long long pos[2]; + pos[0] = pos[1] = 0; + for (long i = 0; i < N; i++) { + int end = (i + 1) % 2; + pos[end] += (1 + pos[(end + 1) % 2]); + pos[end] %= 1000000007; + } + cout << (pos[0] + pos[1]) % 1000000007 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[1005]; + int ans[1005]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int j = 0; + for (int i = 1; i < n; i++) { + if (a[i + 1] <= a[i]) { ans[j++] = a[i]; } + } + ans[j++] = a[n]; + cout << j << endl; + for (int i = 0; i < j - 1; i++) cout << ans[i] << " "; + cout << ans[j - 1] << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (n - (d / t) * k > k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int *a = new int[n]; + long long int min = 99999999999999999; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < min) { min = a[i]; } + } + int p[100000]; + int c = 0; + for (int i = 0; i < n; i++) { + if (a[i] == min) { + p[c] = i; + c++; + } + } + min = 99999999999999999; + for (int i = 1; i < c; i++) { + int r = p[i] - p[i - 1]; + if (r < min) { min = r; } + } + cout << min << endl; +} +int main() { + int f[3][3]; + int p[3][3]; + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { f[i][e] = 1; } + } + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { cin >> p[i][e]; } + } + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { + if (p[i][e] > 0) { + if (f[i][e] == 1) { + f[i][e] = 0; + } else { + f[i][e] = 1; + } + if (e + 1 >= 0 && e + 1 < 3) { + if (f[i][e + 1] == 1) { + f[i][e + 1] = 0; + } else { + f[i][e + 1] = 1; + } + } + if (e - 1 >= 0 && e - 1 < 3) { + if (f[i][e - 1] == 1) { + f[i][e - 1] = 0; + } else { + f[i][e - 1] = 1; + } + } + if (i - 1 >= 0 && i - 1 < 3) { + if (f[i - 1][e] == 1) { + f[i - 1][e] = 0; + } else { + f[i - 1][e] = 1; + } + } + if (i + 1 >= 0 && i + 1 < 3) { + if (f[i + 1][e] == 1) { + f[i + 1][e] = 0; + } else { + f[i + 1][e] = 1; + } + } + p[i][e]--; + e--; + } + } + } + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { cout << f[i][e]; } + cout << endl; + } + return 0; +} +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + for (int i = 0; i < k; i++) { + int ta, fa, tb, fb; + cin >> ta >> fa >> tb >> fb; + int ans = 0; + ans += abs(fa - fb); + if (ta != tb) { + ans += abs(ta - tb); + if ((fa > b) && (fb > b)) { + ans += 2 * (min(fa, fb) - b); + } else if ((fa < a) && (fb < a)) { + ans += 2 * (a - max(fa, fb)); + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, a[100], currgcd; + cin >> n; + cin >> a[0] >> a[1]; + currgcd = __gcd(a[0], a[1]); + for (int i = 2; i < n; i++) { + cin >> a[i]; + if (a[i] % currgcd) currgcd = __gcd(currgcd, a[i]); + } + cout << n * currgcd << endl; + return 0; +} +int main() { + long long n, sum, x; + while (cin >> sum) { + x = (sqrt((8 * sum) + 1) - 1) / 2; + long long sum1 = (x * (x + 1)) / 2; + if (sum - sum1 == 0) + cout << x << endl; + else + cout << sum - sum1 << endl; + } +} +void cycleSort(int arr[], int n); +int main() { + int secretary_number; + int level = 0; + int press = 0; + cin >> secretary_number; + int spyke[secretary_number]; + for (int i = 0; i < secretary_number; i++) { cin >> spyke[i]; } + cycleSort(spyke, secretary_number); + for (int i = 0; i < secretary_number; i++) { + press = i + 2; + if (spyke[i] == spyke[i + 1] && spyke[i] != 0) { level++; } + if (spyke[i] == spyke[press] && spyke[i] != 0) { + level = -1; + break; + } + } + cout << level << endl; +} +void cycleSort(int arr[], int n) { + int writes = 0; + for (int cycle_start = 0; cycle_start <= n - 2; cycle_start++) { + int item = arr[cycle_start]; + int pos = cycle_start; + for (int i = cycle_start + 1; i < n; i++) + if (arr[i] < item) pos++; + if (pos == cycle_start) continue; + while (item == arr[pos]) pos += 1; + if (pos != cycle_start) { + swap(item, arr[pos]); + writes++; + } + while (pos != cycle_start) { + pos = cycle_start; + for (int i = cycle_start + 1; i < n; i++) + if (arr[i] < item) pos += 1; + while (item == arr[pos]) pos += 1; + if (item != arr[pos]) { + swap(item, arr[pos]); + writes++; + } + } + } +} +int main() { + int n; + cin >> n; + vector a; + a.resize(n); + cin >> a[0]; + int count = 20; + for (int i = 1; i < n; i++) { + cin >> a[i]; + for (int j = 0; j < count; j++) + if (a[i][j] != a[i - 1][j]) { + count = j; + break; + } + } + cout << count << endl; + return 0; +} +int arr[105]; +int main() { + int n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] < 0) + sum -= arr[i]; + else + sum += arr[i]; + } + cout << sum << endl; + return 0; +} +int main() { + int cnt = 0; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + for (int l = j + 1; l < s.size(); l++) { + if (s[i] == 'Q' && s[j] == 'A' && s[l] == 'Q') { cnt++; } + } + } + } + cout << cnt << endl; +} +const long long MOD = 1e9 + 7; +int n, k, c; +int dd[400]; +int main() { + cin >> n >> k >> c; + for (int i = 0; i < c; i++) cin >> dd[i]; + if (c == 0) { + cout << n / k << endl; + return 0; + } + int ans = (dd[0] - 1) / k + c; + ans += (n - dd[c - 1]) / k; + for (int i = 1; i <= c - 1; i++) ans += (dd[i] - dd[i - 1] - 1) / k; + cout << ans << endl; + return 0; +} +int cnt1[105], cnt0[105]; +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i]; + cnt1[0] = 0; + cnt0[0] = 0; + int maxv = -100; + for (int i = 1; i <= n; i++) { + cnt1[i] = cnt1[i - 1] + a[i]; + cnt0[i] = i - cnt1[i]; + } + for (int i = 1; i <= n; i++) { + for (int j = i; j <= n; j++) { + if ((cnt0[j] - cnt0[i - 1]) - (cnt1[j] - cnt1[i - 1]) + cnt1[n] > maxv) maxv = (cnt0[j] - cnt0[i - 1]) - (cnt1[j] - cnt1[i - 1]) + cnt1[n]; + } + } + cout << maxv << endl; + return 0; +} +int n, Min; +vector v[4]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + if (a == 1) { + v[1].push_back(i); + continue; + } + if (a == 2) { + v[2].push_back(i); + continue; + } + v[3].push_back(i); + } + Min = min(v[1].size(), min(v[2].size(), v[3].size())); + cout << Min << endl; + for (int i = 0; i < Min; i++) { cout << v[1][i] << " " << v[2][i] << " " << v[3][i] << endl; } +} +int main() { + int i; + string s1, s2; + cin >> s1 >> s2; + for (i = 0; i < s1.size(); i++) { + s1[i] = tolower(s1[i]); + s2[i] = tolower(s2[i]); + } + if (s1 == s2) + cout << "0" << endl; + else { + for (i = 0; i < s1.size(); i++) { + if (s1[i] < s2[i]) { + cout << "-1" << endl; + break; + } else if (s1[i] > s2[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + if (m <= n) { + cout << "1" << endl; + } else { + if (m % n == 0) { + cout << m / n << endl; + } else { + cout << m / n + 1 << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + string arr[n][2]; + for (int i = 0; i < n; i++) { + cin >> arr[i][0] >> arr[i][1]; + if (arr[i][1] == "rat") { + arr[i][1] = "0"; + } else if (arr[i][1] == "child" || arr[i][1] == "woman") { + arr[i][1] = "1"; + } else if (arr[i][1] == "man") { + arr[i][1] = "2"; + } else { + arr[i][1] = "3"; + } + } + int i = 0; + while (i < n - 1) { + if (arr[i][1] > arr[i + 1][1]) { + swap(arr[i][0], arr[i + 1][0]); + swap(arr[i][1], arr[i + 1][1]); + i = 0; + continue; + } + i++; + } + for (int i = 0; i < n; i++) { cout << arr[i][0] << endl; } + return 0; +} +int main() { + int n, a[200010]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int minn = 1000000010; + for (int i = n / 2 + 1; i <= n; i++) { + if (minn > a[i] - a[i - n / 2]) { minn = a[i] - a[i - n / 2]; } + } + cout << minn << endl; + return 0; +} +long long a[200005]; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + if (n == 2) { + cout << a[1] - a[0] << endl; + return 0; + } + long long ans = 0x3f3f3f3f3f3f3f3f; + for (int i = 0; i + n / 2 < n; i++) { ans = min(ans, a[i + n / 2] - a[i]); } + cout << ans << endl; + return 0; +} +int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; +void fast() {} +int a[100], b[100]; +int vis[201]; +int main() { + fast(); + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i], vis[a[i]]++; + for (int i = 0; i < k; i++) cin >> b[i]; + for (int i = 0; i < n - 1; i++) { + if (a[i] == 0 || a[i + 1] == 0) continue; + if (a[i] > a[i + 1]) + return cout << "Yes" + << "\n", + 0; + ; + } + if (vis[0] > 1) + return cout << "Yes" + << "\n", + 0; + ; + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + for (int j = 0; j < k; j++) { + if (i > 0 && a[i - 1] > b[j] || i < n - 1 && a[i + 1] < b[j]) + return cout << "Yes" + << "\n", + 0; + ; + } + } + } + return cout << "No" + << "\n", + 0; + ; +} +int main() { + int a[3][3]; + int b[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { b[i][j] = 0; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> a[i][j]; + if (a[i][j] % 2) { a[i][j] = 1; } + if (a[i][j] % 2 == 0) { a[i][j] = 0; } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (a[i][j]) { + b[i][j]++; + if (i + 1 < 3) { b[i + 1][j]++; } + if (i - 1 >= 0) { b[i - 1][j]++; } + if (j + 1 < 3) { b[i][j + 1]++; } + if (j - 1 >= 0) { b[i][j - 1]++; } + if (b[i][j] % 2 == 0) { b[i][j] = 0; } + if (i + 1 < 3 && b[i + 1][j] % 2 == 0) { b[i + 1][j] = 0; } + if (i - 1 >= 0 && b[i - 1][j] % 2 == 0) { b[i - 1][j] = 0; } + if (j + 1 < 3 && b[i][j + 1] % 2 == 0) { b[i][j + 1] = 0; } + if (j - 1 >= 0 && b[i][j - 1] % 2 == 0) { b[i][j - 1] = 0; } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { b[i][j] = 1 - b[i][j]; } + } + cout << b[0][0] << b[0][1] << b[0][2] << endl; + cout << b[1][0] << b[1][1] << b[1][2] << endl; + cout << b[2][0] << b[2][1] << b[2][2] << endl; +} +int main() { + long long n; + cin >> n; + n--; + while (n / 5 > 0) { n = (n - 5) / 2; } + if (n == 0) + cout << "Sheldon" << endl; + else if (n == 1) + cout << "Leonard" << endl; + else if (n == 2) + cout << "Penny" << endl; + else if (n == 3) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + return 0; +} +int gcd(int x, int y) { + if (x < y) { return gcd(y, x); } + if (y == 0) { return x; } + return gcd(y, x % y); +} +int main() { + int n, g, x; + cin >> n; + cin >> g; + for (int i = 1; i < n; ++i) { + cin >> x; + g = gcd(g, x); + } + cout << g * n << endl; + return 0; +} +long long n, a[100007], i, j, r = 0, f = 0; +int main() { + cin >> n; + cin >> a[1]; + for (i = 2; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + while (a[i] % 3 == 0) a[i] /= 3; + while (a[i] % 2 == 0) a[i] /= 2; + } + for (i = 1; i < n; i++) + if (a[i] != a[i + 1]) f = 1; + if (f == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long mid = n / 2; + long long c = mid / (1 + k); + long long d = k * c; + long long o = n - c - d; + cout << c << " " << d << " " << o << endl; + return 0; +} +bool qo(bool x) { + return (x ? 0 : qo(!x)); +} +const int mnx = 1e7 + 9; +const int mod = 1e9 + 7; +long long n; +long long x[mnx]; +long long u[mnx]; +long long k[mnx]; +long long cnt, c; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> x[i]; } + sort(x + 1, x + n + 1); + cout << x[n] << ' '; + for (int i = 1; i <= n; i++) { + if (i == n || i == 1) continue; + cout << x[i] << ' '; + } + cout << x[1] << '\n'; + return 0; +} +const int maxn = 2e5 + 10; +int n, k; +string s; +int a[155]; +int main() { + cin >> n >> k; + cin >> s; + for (int i = 0; i < n; i++) { a[i] = s[i]; } + sort(a, a + n); + int ans = 0; + ans += a[0] - 'a' + 1; + k--; + int pre = a[0]; + for (int i = 1; i < n; i++) { + if (a[i] > pre + 1 && k > 0) { + pre = a[i]; + ans += a[i] - 'a' + 1; + k--; + } + } + if (k > 0) + cout << -1 << endl; + else + cout << ans << endl; +} +int main() { + string x; + int c = 0, n; + cin >> n; + cin >> x; + for (int i = 0; i < x.length(); i++) { + if (x[i] == '1') c++; + if (x[i] == '0') { + c++; + break; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, k, len, i, j, a, b, c = 0; + int d[100], tmp, e = 0; + char ch[100]; + cin >> n >> k; + cin >> ch; + len = strlen(ch); + for (i = 0; i < len; i++) { + if (ch[i] == 'G') + a = i; + else if (ch[i] == 'T') + b = i; + else if (ch[i] == '#') { + d[c] = i; + c++; + } + } + if (a > b) { + tmp = a; + a = b; + b = tmp; + } + j = b - a; + if (j % k == 0) { + for (i = 0; i < c; i++) { + if (d[i] > a && d[i] < b) { + if ((d[i] - a) % k == 0) { + cout << "NO" << endl; + break; + } + } + } + if (i == c) cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, c = 0, sum = 0; + cin >> n; + char s[n][n][1]; + int i, j; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + cin >> s[i][j][0]; + if (s[i][j][0] == 'C') { c++; } + } + sum += (c * (c - 1)) / 2; + c = 0; + } + for (j = 0; j < n; j++) { + for (i = 0; i < n; i++) { + if (s[i][j][0] == 'C') { c++; } + } + sum += (c * (c - 1)) / 2; + c = 0; + } + cout << sum << endl; + return 0; +} +const long long int INF = (long long)8e18; +const long long int MOD = 1000000007; +int main() { + int k; + cin >> k; + string q; + cin >> q; + int n = q.length(); + int prev = 0; + int freq[26] = {0}; + vector v; + if (k == 1) { + cout << "YES" << '\n' << q << '\n'; + return 0; + } + char c = q[0]; + freq[c - 'a']++; + for (int i = 1; i < n; i++) { + if (freq[q[i] - 'a'] == 0) { + v.push_back(q.substr(prev, i - prev)); + freq[q[i] - 'a']++; + prev = i; + k--; + } + if (k == 1) { + v.push_back(q.substr(i, n - i)); + k--; + break; + } + } + if (k != 0) + cout << "NO" << '\n'; + else { + cout << "YES" << '\n'; + for (int i = 0; i < (int)v.size(); i++) cout << v[i] << '\n'; + } + return 0; +} +int main() { + int n, s; + cin >> n >> s; + if (s % n) + cout << s / n + 1 << endl; + else + cout << s / n << endl; +} +int main() { + int n, k; + while (cin >> n >> k) { + while (k > 0) { + int last_digit = n % 10; + if (last_digit == 0) + k--, n /= 10; + else + k--, n--; + } + cout << n << endl; + } + return 0; +} +int main() { + int n, t, s[30001] = {}; + cin >> n >> t; + int now = 1; + for (int i = 1; i < n; i++) { cin >> s[i]; } + int t1 = 0; + for (int i = 0; now < n; i++) { + now += s[now]; + if (now == t) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int n; + int a[100005], b[100005]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + int f = 0; + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) { f++; } + } + if (f > 2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } + return 0; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0, mayor = 0, a; + for (int i = 0; i < n; i++) { + cin >> a; + ans = ans + a; + mayor = max(mayor, a); + } + ans = max((ans * 2) / n + 1, mayor); + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << a * b + b * c + a * c - a - b - c + 1 << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> a >> b >> c >> n; + if (a < c || b < c) { + cout << -1 << endl; + return 0; + } + int ans = n - (a + b - c); + if (ans >= 1) { + cout << ans << endl; + } else { + cout << -1 << endl; + } +} +char s[100005]; +int safe[30], nowsafe[30]; +int main() { + int n, i = 0, j, flag = 0, co = 0; + char c; + cin >> n; + while (n--) { + cin >> c >> s; + int m = strlen(s); + if (c == '!') { + if (flag == 1) + co++; + else { + fill(nowsafe, nowsafe + 26, 1); + for (j = 0; j < m; j++) nowsafe[s[j] - 'a'] = 0; + for (i = 0; i < 26; i++) + if (nowsafe[i] == 1) safe[i] = 1; + } + } else if (c == '.') { + for (i = 0; i < m; i++) safe[s[i] - 'a'] = 1; + } else { + if (flag == 1 && safe[s[0] - 'a'] == 1) co++; + safe[s[0] - 'a'] = 1; + } + int num = 0; + for (i = 0; i < 26; i++) + if (safe[i] == 1) num++; + if (num == 25) flag = 1; + } + cout << co << endl; + return 0; +} +int main() { + int T; + cin >> T; + for (int i = 0; i < T; i++) { + int first, second, smaller, larger; + int counter = 0; + int mult; + cin >> first >> second; + while (first > 0 && second > 0) { + smaller = min(first, second); + larger = max(first, second); + mult = larger / smaller; + counter += mult; + larger -= mult * smaller; + first = smaller; + second = larger; + } + cout << counter << endl; + } +} +const int maxn = 2.001e3; +set st; +int a[maxn], b[maxn], n, cnt; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i], st.insert(a[i]); + for (int i = 1; i <= n; i++) cin >> b[i], st.insert(b[i]); + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (st.find(a[i] xor b[j]) != st.end()) cnt++; + cout << ((cnt & 1) ? "Koyomi" : "Karen") << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n < 0) { + int r = n % 100; + n = (n - r) / 10 + max(r / 10, r % 10); + } + cout << n << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + bool dropout = false; + long long int i = 1; + while (!dropout) { + if (n - i > 0) { + n -= i; + i++; + } else + dropout = true; + } + cout << n << endl; + return 0; +} +int main() { + long long n, x, y; + cin >> n >> x >> y; + long long p = 0; + string s; + cin >> s; + bool flag = false; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { + if (!flag) flag = true; + } + if (s[i] == '1') + if (flag) { + p++; + flag = false; + } + } + if (flag) p++; + if (!p) + cout << 0 << endl; + else + cout << (p - 1) * 1LL * min(x, y) + y << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + for (int i = 0; i < n; i++) { + if (arr[i] == 1) { + cout << -1 << endl; + return 0; + } + } + cout << 1 << endl; + return 0; +} +int month[13]; +void set_month() { + month[1] = 31; + month[2] = 28; + month[3] = 31; + month[4] = 30; + month[5] = 31; + month[6] = 30; + month[7] = 31; + month[8] = 31; + month[9] = 30; + month[10] = 31; + month[11] = 30; + month[12] = 31; +} +int m, d, ans; +int main() { + set_month(); + cin >> m >> d; + ans = 1; + for (int i = 2; i <= month[m]; i++) { + d++; + if (d > 7) { + d = 1; + ans++; + } + } + cout << ans << endl; + return 0; +} +const int maxn = 2e3 + 10; +const int eps = 1e-14; +const int mod = 1e9 + 7; +const long long inf = 1e18; +int main() { + int t, s, p; + cin >> t >> s >> p; + int cnt = 0; + while (s < t) { + s *= p; + ++cnt; + } + cout << cnt << endl; +} +int main() { + int n, ax, ay, bx, by, cx, cy; + cin >> n >> ax >> ay >> bx >> by >> cx >> cy; + if ((bx - ax) * (cx - ax) < 0 || (by - ay) * (cy - ay) < 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int N; + cin >> N; + int a = 0, b = 0, c = 0, d = 0, e = 0, k = 0; + if (N <= 1000000000) { + a = N / 100; + b = (N - (a * 100)) / 20; + c = (N - (a * 100 + b * 20)) / 10; + d = (N - (a * 100 + b * 20 + c * 10)) / 5; + e = (N - (a * 100 + b * 20 + c * 10 + d * 5)) / 1; + k = a + b + c + d + e; + cout << k << endl; + } +} +int main() { + int n, t, k, d, sum = 0, time2; + cin >> n >> t >> k >> d; + int time1 = ceil((double)n / k) * t; + for (int i = 1; sum < n; i++) { + if (i % t == 0) sum += k; + if (i > d && (i - d) % t == 0) sum += k; + time2 = i; + } + if (time1 > time2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int sup = 0; + int inf = 0; + for (int j = i; j < n; j++) { + if (s[j] == '(') + sup++, inf++; + else if (s[j] == ')') + sup--, inf--; + else + sup++, inf--; + if (sup < 0) break; + if (inf < 0) inf = 0; + if ((j - i + 1) % 2 == 0 && inf == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long z, x; + cin >> z >> x; + long long d[z]; + long long total = 0; + for (int q = 0; q < z; q++) { cin >> d[q]; } + long long patok = d[x - 1]; + bool cek = false; + for (int q = x; q < z; q++) { + if (d[q] != patok) cek = true; + } + for (int q = x - 2; q >= 0; q--) { + if (d[q] != patok) { + total = q + 1; + break; + } + } + if (cek == true) { + cout << -1 << endl; + } else { + cout << total << endl; + } +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int ats1 = 0, ats2 = p * n; + while (n != 1) { + int k = 1; + while (2 * k <= n) k *= 2; + ats1 += k * b + k / 2; + n -= k / 2; + } + cout << ats1 << " " << ats2 << "\n"; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +vector g[1005]; +bool used[1005]; +int deg[1005]; +bool isHome[1005]; +int ans = 0; +int ver = 0; +int total = 0; +bool h = false; +vector ok; +vector no; +void dfs(int v) { + used[v] = true; + ans += deg[v]; + ver++; + if (isHome[v]) h = true; + for (int i = 0; i < g[v].size(); i++) { + if (!used[g[v][i]]) { dfs(g[v][i]); } + } +} +void solve() { + int n, m, k; + cin >> n >> m >> k; + int home[k]; + for (int i = 0; i < k; i++) { + int x; + cin >> x; + isHome[x] = true; + } + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + g[u].push_back(v); + g[v].push_back(u); + deg[u]++; + deg[v]++; + } + for (int i = 1; i <= n; i++) { + if (!used[i]) { + dfs(i); + ans = ans / 2; + int t = (ver * (ver - 1) / 2); + total += (t - ans); + if (h == true) { + no.push_back(ver); + } else { + ok.push_back(ver); + } + ver = 0; + ans = 0; + h = false; + } + } + int mul = 0; + int sum = 0; + for (int i = 0; i < ok.size(); i++) { + mul += sum * ok[i]; + sum += ok[i]; + } + sort((no).begin(), (no).end()); + mul += sum * no[no.size() - 1]; + total += mul; + cout << total << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, c; + cin >> n >> c; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int i = 0, words = 0, j = 0; + for (j = i + 1; j < n;) { + if (a[j] - a[i] <= c) { + words++; + j++; + i++; + } else { + words = 0; + i = j; + j++; + } + } + cout << words + 1 << endl; + return 0; +} +int main() { + int N; + cin >> N; + vector A(N); + for (int i = 0; i < (int)(N); ++i) cin >> A[i]; + if (N == 1) { + if (A[0] == 0) { + cout << "UP" + << "\n"; + return 0; + } + if (A[0] == 15) { + cout << "DOWN" + << "\n"; + return 0; + } + cout << -1 << "\n"; + return 0; + } + if (A[N - 1] == 0) { + cout << "UP" + << "\n"; + return 0; + } + if (A[N - 1] == 15) { + cout << "DOWN" + << "\n"; + return 0; + } + if (A[N - 2] < A[N - 1]) { + cout << "UP" + << "\n"; + } else { + cout << "DOWN" + << "\n"; + } + return 0; +} +const long long int MAXN = 1e5 + 10; +const long long int MINN = 1e5 + 10; +const long long int inf = 1e9 + 7; +int main() { + long long a, b, x1 = 0, x2 = 0; + cin >> a >> b; + bool f = false; + if (a > b) { + swap(a, b); + f = true; + } + long long m = a; + for (int i = 1; i <= (a / __gcd(a, b) - 1); ++i) { + long long l = b - a + m; + long long s = l / a; + x1 += a - m + s * a; + m = l % a; + x2 += m; + } + long long l = b - a + m; + long long s = l / a - 1; + x1 += a - m + s * a; + x2 += a; + if (x1 < x2) { + if (f) + cout << "Dasha" << endl; + else + cout << "Masha" << endl; + } else if (x1 == x2) + cout << "Equal" << endl; + else { + if (f) + cout << "Masha" << endl; + else + cout << "Dasha" << endl; + } + return 0; +} +int main() { + long long n, s, a, b, c; + cin >> n; + while (n--) { + cin >> s >> a >> b >> c; + long long price = a * c; + long long sum = s / price; + s = s - sum * price; + sum = sum * (a + b); + s = s / c; + cout << sum + s << endl; + } + return 0; +} +int main() { + string str; + int f = 1; + for (int j = 0; j < 8; j++) { + cin >> str; + if (str[0] == str[7]) f = 0; + for (int i = 0; i < 7; i++) { + if (str[i] == str[i + 1]) f = 0; + } + } + if (f == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x * x) % m; + if (b % 2) x = (x * a) % m; + return x; +} +int main() { + int n, d = INT_MAX, p; + cin >> n; + while (n--) { + cin >> p; + d = min(p, d); + } + cin >> n; + int a[n + 2]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n, greater()); + int an = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < d && i < n; j++, i++) { an += a[i]; } + i++; + } + cout << an << endl; +} +int N, K, ans, l, r, u, d; +string S, A[11], T; +int main() { + cin >> S; + for (int i = 1; i <= 10; i++) { cin >> A[i]; } + for (int i = 0; i < 80; i += 10) { + T = S.substr(i, 10); + for (int j = 1; j <= 10; j++) { + if (T == A[j]) cout << j - 1; + } + } + cout << '\n'; +} +const int maxn = 1e5 + 5; +const double esp = 1e-8; +inline int read() { + int X = 0, w = 0; + char ch = 0; + while (!isdigit(ch)) { + w |= ch == '-'; + ch = getchar(); + } + while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); + return w ? -X : X; +} +long long a[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int num = 0; + for (int i = 2; i <= n - 1; i++) { + if (a[i] > a[i + 1] && a[i] > a[i - 1] || a[i] < a[i - 1] && a[i] < a[i + 1]) ++num; + } + cout << num << endl; +} +int main() { + int arr[5005], n, cnt1 = 0, cnt2 = 0, cnt3 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) { + cnt1++; + } else if (arr[i] == 2) { + cnt2++; + } else { + cnt3++; + } + } + int m; + m = min(cnt1, cnt2); + m = min(m, cnt3); + cout << m << endl; + if (m == 0) return 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (arr[j] == 1) { + cout << j + 1 << " "; + arr[j] = 0; + break; + } + } + for (int j = 0; j < n; j++) { + if (arr[j] == 2) { + cout << j + 1 << " "; + arr[j] = 0; + break; + } + } + for (int j = 0; j < n; j++) { + if (arr[j] == 3) { + cout << j + 1 << endl; + arr[j] = 0; + break; + } + } + } + return 0; +} +int a[3]; +int b[3]; +int main() { + int n; + int sum1 = 0; + int sum2 = 0; + int cnt = 0; + for (int i = 0; i < 3; i++) { + cin >> a[i]; + sum1 += a[i]; + } + for (int i = 0; i < 3; i++) { + cin >> b[i]; + sum2 += b[i]; + } + cin >> n; + if (sum1 % 5) + cnt += (sum1 / 5 + 1); + else + cnt += sum1 / 5; + if (sum2 % 10) + cnt += (sum2 / 10 + 1); + else + cnt += sum2 / 10; + if (n < cnt) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int absolute(int n) { + return n >= 0 ? n : -n; +} +int main() { + int x, y, sum; + while (cin >> x >> y) { + sum = absolute(x) + absolute(y); + if (x > 0 && y > 0) { + cout << 0 << " " << sum << " " << sum << " " << 0 << endl; + } else if (x < 0 && y > 0) { + cout << -sum << " " << 0 << " " << 0 << " " << sum << endl; + } else if (x < 0 && y < 0) { + cout << -sum << " " << 0 << " " << 0 << " " << -sum << endl; + } else if (x > 0 && y < 0) { + cout << 0 << " " << -sum << " " << sum << " " << 0 << endl; + } + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n], arr2[k], arr3[k], arr4[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int j = 0; j < k; j++) { + cin >> arr2[j]; + arr3[j] = arr2[j]; + } + sort(arr3, arr3 + k); + if (k > 1 && arr3[0] != arr3[k - 1]) { + cout << "Yes" << endl; + return 0; + } + for (int i = 0; i < n; i++) { + if (arr[i] == 0) { + arr[i] = arr2[0]; + arr4[i] = arr[i]; + } else + arr4[i] = arr[i]; + } + sort(arr4, arr4 + n); + for (int i = 0; i < n; i++) { + if (arr[i] != arr4[i]) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + long long n, k, m = INT_MIN; + cin >> n >> k; + while (n--) { + long long f, t; + cin >> f >> t; + long long d = t - k; + if (d < 0) d = 0; + m = max(m, f - d); + } + cout << m << '\n'; +} +int a[100020]; +int n; +int main() { + set sp; + while (cin >> n) { + sp.clear(); + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + while (a[i] % 2 == 0) a[i] /= 2; + while (a[i] % 3 == 0) a[i] /= 3; + sp.insert(a[i]); + } + if (sp.size() > 1) + cout << "No" << endl; + else + cout << "Yes" << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int x = n / 10; + int y = n / 100 * 10 + n % 10; + n = max(n, x); + n = max(n, y); + cout << n << endl; + } + return 0; +} +const int MAXN = 100 + 5; +const int INF = 0x3f3f3f3f; +int main() { + int n; + cin >> n; + int data[MAXN]; + for (int i = 0; i < n; i++) cin >> data[i]; + int cnt, ans = n; + for (int i = 1; i < n; i++) { + cnt = 0; + if (data[i - 1] == data[i]) continue; + for (int j = 0; j < i; j++) + if (data[j] != 0) cnt++; + for (int j = i; j < n; j++) + if (data[j] != 1) cnt++; + ans = min(ans, cnt); + } + cnt = 0; + for (int i = 0; i < n; i++) { + if (data[i] != 0) cnt++; + } + ans = min(ans, cnt); + cnt = 0; + for (int i = 0; i < n; i++) { + if (data[i] != 1) cnt++; + } + ans = min(ans, cnt); + cout << n - ans << '\n'; +} +int n; +long long arr[300010]; +long long score; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + if (n == 1) { + cout << arr[0] << endl; + return 0; + } + sort(arr, arr + n); + for (int i = 0; i < n; i++) { score += ((i + 2) * arr[i]); } + score -= arr[n - 1]; + cout << score << endl; +} +long long int getsum(int a, int b, int c, int l) { + if (a < b + c) return 0; + long long int mid = min(a - b - c, l); + return (mid + 1) * (mid + 2) / 2; +} +int main() { + long long int a, b, c, l; + cin >> a >> b >> c >> l; + long long int ans = 1; + for (long long int i = 1; i <= l; i++) ans += (i + 1) * (i + 2) / 2; + for (long long int i = 0; i <= l; i++) { + ans -= getsum(a + i, b, c, l - i); + ans -= getsum(b + i, a, c, l - i); + ans -= getsum(c + i, a, b, l - i); + } + cout << ans << endl; +} +int main() { + long long int a, b, x, i, k = 1; + cin >> a >> b; + x = min(a, b); + for (i = 1; i <= x; i++) { k = k * i; } + cout << k << endl; + return 0; +} +int main() { + long long n, m, x, dis = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + char c; + cin >> c >> x; + if (c == '+') + m += x; + else { + if (m - x < 0) + dis++; + else + m -= x; + } + } + cout << m << ' ' << dis << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int sum = 0; + int ish = 1; + for (int i = 1; i < n; i++) { + if (ish == 1) { + if (a < b) { + sum += a; + ish = 2; + } else { + sum += b; + ish = 3; + } + continue; + } + if (ish == 2) { + if (a < c) { + sum += a; + ish = 1; + } else { + sum += c; + ish = 3; + } + continue; + } + if (ish == 3) { + if (c < b) { + sum += c; + ish = 2; + } else { + sum += b; + ish = 1; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, m, a, c = 0, low = 10000; + vector v; + vector s; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + } + for (int i = 0; i < m; i++) { + cin >> a; + s.push_back(a); + } + a = 0; + for (int i = 0; i < m; i++) { + for (int j = a; j < n; j++) { + if (v[j] <= s[i] && v[j] != (-1)) { + c++; + v[j] = (-1); + a = j; + if (j + 1 == n) { + cout << c << '\n'; + return 0; + } + break; + } + if (j + 1 == n) { + cout << c << '\n'; + return 0; + } + } + } + cout << c << '\n'; + return 0; +} +int main() { + int na, nb, ka, kb; + cin >> na >> nb >> ka >> kb; + vector a(na), b(nb); + for (int i = 0; i < na; i++) { cin >> a[i]; } + for (int i = 0; i < nb; i++) { cin >> b[i]; } + int k = 0; + for (int i = nb - 1; i >= 0; i--) { + if (a[ka - 1] < b[i]) { + k++; + } else if (k < kb && a[ka - 1] >= b[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +int n; +bool used[5]; +int main() { + int a, b, c; + a = 1, b = 2, c = 3; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == c) { + puts("NO"); + return 0; + } + if (x == a) { + swap(b, c); + } else { + swap(a, c); + } + } + puts("YES"); + return 0; +} +int main() { + string str; + int n, h1, h2, sum0 = 0, sum1 = 0; + cin >> n >> str; + for (int i = 0; i < n; i++) { + if (str[i] != '4' && str[i] != '7') { + cout << "NO" << endl; + return 0; + } + } + h1 = n / 2; + for (int i = 0; i < h1; i++) sum0 = str[i] - '0' + sum0; + for (int i = h1; i < n; i++) sum1 = str[i] - '0' + sum1; + if (sum0 == sum1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +void solve() { + long long a, b; + cin >> a >> b; + long long l = (a * b) / __gcd(a, b); + long long v1 = (l - 1) / a, v2 = (l - 1) / b; + (a > b) ? v1++ : v2++; + if (v1 == v2) { + cout << "Equal\n"; + } else if (v1 > v2) { + cout << "Dasha\n"; + } else { + cout << "Masha\n"; + } +} +int main() { + int t; + t = 1; + while (t--) solve(); + return 0; +} +int main() { + long long int i, j, n, m, x; + while (cin >> n) { + long long a[n], b[n], sum1, sum2; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { cin >> b[i]; } + sum1 = a[0]; + sum2 = b[0]; + for (i = 1; i < n; i++) { + sum1 |= a[i]; + sum2 |= b[i]; + } + cout << sum1 + sum2 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n * 2 - (n / 2) << endl; +} +int main() { + int n; + cin >> n; + int arr[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> arr[i][j]; } + } + int upper = 0, lower = 0; + for (int i = 0; i < n; i++) { + upper = upper + arr[i][0]; + lower = lower + arr[i][1]; + } + if ((upper % 2 == 0) && (lower % 2 == 0)) { + cout << "0" << endl; + } else { + if ((upper % 2 != 0) || (lower % 2 != 0)) { + for (int i = 0; i < n; i++) { + int x, y; + x = (upper - arr[i][0]) + arr[i][1]; + y = (lower - arr[i][1]) + arr[i][0]; + if ((x % 2 == 0) && (y % 2 == 0)) { + cout << "1" << endl; + return 0; + } + } + cout << "-1" << endl; + } + } +} +long long fastpow(long long base, long long exp) { + long long res = 1; + while (exp > 0) { + if (exp % 2 == 1) res = (res * base) % 1000000009; + base = (base * base) % 1000000009; + exp /= 2; + } + return res % 1000000009; +} +long long ask(long long a) { + cout << 1 << " " << a << endl; + long long x; + cin >> x; + return x; +} +int main() { + long long testcases; + cin >> testcases; + while (testcases--) { + long long a, b, k; + cin >> a >> b >> k; + if (k % 2 == 0) { + cout << (k / 2) * (a - b) << endl; + } else { + cout << ((k - 1) / 2) * (a - b) + a << endl; + } + } + return 0; +} +const int INF = 1000000000; +const double EPS = 1e-9; +int main() { + int n, m, a, b, ans = INF, cur; + cin >> n >> m; + int prices[n + 1]; + bool matches[n + 1][n + 1] = {}; + for (int i = 1; i <= n; i++) cin >> prices[i]; + for (int i = 0; i < m; i++) { + cin >> a >> b; + matches[a][b] = matches[b][a] = 1; + } + if (m < 3) { + cout << -1 << '\n'; + return 0; + } + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + if (!matches[i][j]) continue; + for (int k = j + 1; k <= n; k++) { + if (matches[i][j] && matches[i][k] && matches[j][k]) { ans = min(ans, prices[i] + prices[j] + prices[k]); } + } + } + } + if (ans == INF) + cout << -1 << '\n'; + else + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + int arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + int FLAG = 1, flag; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + flag = 0; + if (arr[i][j] != 1) { + for (int s = 0; s < n; s++) { + for (int t = 0; t < n; t++) { + if (arr[i][s] + arr[t][j] == arr[i][j]) { + flag = 1; + break; + } + } + if (flag) { break; } + } + } + if (!flag && arr[i][j] != 1) { + FLAG = 0; + break; + } + if (!FLAG) { break; } + } + } + if (!FLAG) { + cout << "No\n"; + } else { + cout << "Yes\n"; + } +} +int main() { + long long n; + cin >> n; + long long A[n]; + long long sum = 0; + for (long long i = 0; i < n; i++) cin >> A[i], sum += A[i]; + long long c = 0; + for (long long i = 0; i < n; i++) { + c += A[i]; + if (2 * c >= sum) { + cout << i + 1 << "\n"; + break; + } + } + return 0; +} +const int mx = 1000; +int n, s; +bool a[mx], b[mx]; +void solve() { + cin >> n >> s; + int t1 = 0, t2 = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + if (a[0] == 1) t1 = 1; + if (a[s - 1] == 1 || b[s - 1] == 1) + for (int i = s - 1; i < n; i++) + if (a[i] == 1 && b[i] == 1) { + t2 = 1; + break; + } + if (t1 == 1 && (t2 == 1 || a[s - 1] == 1)) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + solve(); + return 0; +} +int a[2], n, i; +int gcd(int x, int y) { + return y == 0 ? x : gcd(y, x % y); +} +int main() { + cin >> a[0] >> a[1] >> n; + for (i = 0; n > 0; ++i) { n -= gcd(a[i % 2], n); } + cout << (i + 1) % 2 << endl; + return 0; +} +int main() { + int n; + string a[100], b[100]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (int i = 0; i < n; i++) { + if (b[i] == "rat") cout << a[i] << endl; + } + for (int i = 0; i < n; i++) { + if (b[i] == "woman" || b[i] == "child") cout << a[i] << endl; + } + for (int i = 0; i < n; i++) { + if (b[i] == "man") cout << a[i] << endl; + } + for (int i = 0; i < n; i++) { + if (b[i] == "captain") cout << a[i] << endl; + } + return 0; +} +int read() { + char c = getchar(); + int x = 0, f = 1; + while (c < '0' || c > '9') { + if (c == '-') f = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = x * 10 + c - '0'; + c = getchar(); + } + return x * f; +} +int main() { + int n = read(); + int ans = 0; + ans += n / 100; + n %= 100; + ans += n / 20; + n %= 20; + ans += n / 10; + n %= 10; + ans += n / 5; + n %= 5; + ans += n; + cout << ans << endl; + return 0; +} +void insertion(int A[], int s) { + int value = 0, hole = 0; + for (int i = 1; i < s; i++) { + value = A[i]; + hole = i; + while (hole > 0 && A[hole - 1] < value) { + A[hole] = A[hole - 1]; + hole--; + } + A[hole] = value; + } +} +int main() { + int Ncoins = 0, tSum = 0, minCoinValue = 0, minusSum = 0, coin = 0; + cin >> Ncoins; + int A[Ncoins] = {0}; + for (int i = 0; i < Ncoins; i++) { + cin >> A[i]; + tSum = tSum + A[i]; + } + insertion(A, Ncoins); + for (int i = 0; i < Ncoins; i++) { + minCoinValue = minCoinValue + A[i]; + minusSum = tSum - minCoinValue; + coin++; + if (minCoinValue > minusSum) { + cout << coin << endl; + break; + } + } +} +int main() { + int n; + cin >> n; + n >>= 1; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a.begin(), a.end()); + int x = 0, y = 0, u = 1, v = 2; + for (int i = 0; i < n; i++) { + x += abs(a[i] - u); + y += abs(a[i] - v); + u += 2; + v += 2; + } + cout << min(x, y) << endl; + return 0; +} +int main() { + int p, b, t, x; + cin >> p >> b >> t; + int match = 0; + x = p; + while (p != 1) { + match += (p / 2); + p = (p / 2) + (p % 2); + } + cout << match + (2 * match * b) << " " << x * t << endl; +} +void selection_insert(int a[], int n) { + for (int i = 0; i < n - 1; i++) { + int imin = i; + for (int j = i + 1; j < n; j++) { + if (a[j] < a[imin]) { imin = j; } + } + int temp; + temp = a[i]; + a[i] = a[imin]; + a[imin] = temp; + } +} +int main() { + int xay; + cin >> xay; + int x, y, z; + int x1 = 0, y1 = 0, z1 = 0; + for (int i = 0; i < xay; i++) { + cin >> x >> y >> z; + x1 = x1 + x; + y1 = y1 + y; + z1 = z1 + z; + } + if (x1 == 0 && y1 == 0 && z1 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +const int maxn = 3e2 + 10; +bool vis[maxn]; +int main() { + int p, n; + cin >> p >> n; + memset(vis, false, sizeof vis); + int flag = 0, ans = -1; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (flag) continue; + if (vis[x % p]) + flag = 1, ans = i; + else + vis[x % p] = true; + } + if (!flag) + cout << -1 << endl; + else + cout << ans << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + long long n; + cin >> n; + string str; + cin >> str; + if (n == 2) { + if (str[0] >= str[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << "2" << endl; + cout << str[0] << " " << str[1] << endl; + } + } else { + cout << "YES" << endl; + cout << "2" << endl; + cout << str[0] << " "; + for (int i = 1; i < n; i++) cout << str[i]; + cout << endl; + } + } +} +int ans; +string x1, x2; +int main() { + cin >> x1 >> x2; + for (int i = 0; i < x2.length(); i++) { + if (x1[ans] == x2[i]) { ans++; } + } + cout << ans + 1 << endl; +} +int main() { + int a[103] = {0}, n, s = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + s += a[i]; + } + s /= 2; + sort(a, a + n); + int b = 0, cnt = 0; + for (int i = n - 1; i >= 0; i--) { + b += a[i]; + cnt++; + if (b > s) break; + } + cout << cnt << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (min(n, m) % 2 == 0) + cout << "Malvika\n"; + else + cout << "Akshat\n"; +} +int gcd(int a, int b) { + if (a % b == 0) return a / b; + return a / b + gcd(b, a % b); +} +int n, a, b; +int main() { + cin >> n; + while (n--) { + cin >> a >> b; + cout << gcd(a, b) << endl; + } + return 0; +} +int main() { + int a[8]; + int sum = 0; + for (int i = 1; i <= 6; ++i) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 2 != 0) { + cout << "NO" << endl; + return 0; + } + int flag = 0; + for (int i = 1; i <= 4; ++i) { + for (int j = i + 1; j <= 5; ++j) { + for (int k = j + 1; k <= 6; ++k) { + if ((a[i] + a[j] + a[k]) == (sum / 2)) { + flag = 1; + break; + } + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string s; +int p = 0, l = 0; +int main() { + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '-') + l++; + else + p++; + } + if ((p == 0) || (l % p == 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k, sum = 0; + string a, b; + cin >> n >> a >> b; + while (n--) { + k = min(abs(a[n] - b[n]), min(10 + a[n] - b[n], 10 - a[n] + b[n])); + sum += k; + } + cout << sum << "\n"; + return 0; +} +int main() { + int n, i, sum = 0; + char org[1001], dst[1001]; + cin >> n; + cin >> org; + cin >> dst; + for (i = 0; i < n; i++) { sum += min(abs(org[i] - dst[i]), 10 - abs(org[i] - dst[i])); } + cout << sum << endl; + return 0; +} +int n; +string s; +int pref[105]; +int main() { + cin >> s; + n = s.size(); + pref[0] = (s[0] == 'Q'); + for (int i = 1; i < n; i++) { pref[i] = pref[i - 1] + (s[i] == 'Q'); } + int tot = 0; + for (int i = 1; i < n - 1; i++) { + if (s[i] == 'A') tot += pref[i - 1] * (pref[n - 1] - pref[i]); + } + cout << tot << '\n'; + return 0; +} +long long count(long long n) { + long long k = n, s = 0; + while (k > 0) { + s += k % 10; + k /= 10; + } + return s; +} +long long si(long long n) { + long long k = n, s = 0; + while (k > 0) { + s++; + k /= 10; + } + return s; +} +vector v[1000000]; +int main() { + long long n, i; + cin >> n; + long long k = 0, m = n; + long long l = si(n); + i = n; + long long c = 0; + vector p; + long long j = 9 * l, q = 0; + while (q <= j) { + q++; + long long z = i + count(i); + if (z == n) { + c++; + p.push_back(i); + } + i--; + } + cout << c << endl; + sort(p.begin(), p.end()); + for (i = 0; i < p.size(); i++) cout << p[i] << endl; +} +int main() { + queue game; + queue bill; + int n, m; + cin >> n >> m; + int tem; + while (n--) { + cin >> tem; + game.push(tem); + } + while (m--) { + cin >> tem; + bill.push(tem); + } + int cnt = 0; + while (!game.empty() && !bill.empty()) { + int val = game.front(); + game.pop(); + int money = bill.front(); + if (money >= val) { + cnt++; + bill.pop(); + } + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + int sz = s.length(); + int flag = 0; + for (int i = 0; i < sz; i++) { + if (s[i] == '1') { + if (s[i + 1] == '4') { + if (s[i + 2] == '4') { + i = i + 2; + } else { + i = i + 1; + } + } + } else + flag = 1; + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + map str; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + str[s]++; + } + cout << str.size() << endl; + return 0; +} +int n, m; +bool let(const int x, const int y) { + return 0 <= x && x < n && 0 <= y && y < m; +} +const int maxn = 123; +int main() { + cout.precision(10); + cout << fixed; + cin >> n >> m; + vector vs(n); + for (int i = 0; i < (int)(n); ++i) cin >> vs[i]; + for (int i = 0; i < (int)(n); ++i) { + for (int j = 0; j < (int)(m); ++j) { + if (vs[i][j] != vs[i][0]) { + cout << "NO" << endl; + return 0; + } + } + if (i > 0 && vs[i][0] == vs[i - 1][0]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; + return 0; +} +int main() { + int c = 0, b; + string s, t; + cin >> s >> t; + b = s.size(); + reverse(s.begin(), s.end()); + for (int i = 0; i < b; i++) { + if (s[i] == t[i]) c++; + } + if (b == c) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +string str[30100]; +int a, b, r; +int main() { + cin >> a >> b >> r; + r *= 2; + if (r <= a && r <= b) + puts("First"); + else + puts("Second"); +} +int fastMax(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; +} +int fastMin(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; +} +const long long int MOD = 1e9 + 7; +long long int C[1005]; +long long int dp[1005], fact[1005]; +long long int power(long long int x, long long int y) { + long long int res = 1; + while (y) { + if (y & 1) res = (res * x) % MOD; + x = (x * x) % MOD; + y = y >> 1; + } + return res; +} +long long int inverse(long long int N) { + return power(N, MOD - 2); +} +long long int nCr(long long int N, long long int R) { + if (N < R) return 0; + return (((fact[N] * inverse(fact[N - R])) % MOD) * inverse(fact[R])) % MOD; +} +void solve() { + long long int k; + cin >> k; + fact[0] = 1; + for (long long int i = 1; i <= 1001; i++) fact[i] = (fact[i - 1] * i) % MOD; + for (int i = (1); i <= (k); ++i) cin >> C[i]; + long long int prev_sum = C[1]; + dp[1] = 1; + for (int i = (2); i <= (k); ++i) { + dp[i] = (dp[i - 1] * nCr(C[i] + prev_sum - 1, C[i] - 1)) % MOD; + prev_sum += C[i]; + } + cout << dp[k] << endl; +} +int main() { + long long int t; + t = 1; + while (t--) { solve(); } +} +int main() { + int n; + string s; + cin >> n; + cin >> s; + int flag = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { flag++; } + if (s[i] == '0') { + cout << flag; + flag = 0; + } + } + cout << flag; + cout << endl; + return 0; +} +long long int mark[100]; +int main() { + long long int n, i, j, k, x, y, m; + string s, t = ""; + cin >> n; + cin >> s; + i = 0; + while (i < n) { + if (s[i] == '0') { + mark[i] = 1; + i += 2; + } else + i++; + } + long long int cnt = 0; + for (i = 0; i < n; i++) { + if (mark[i] == 1) { + cout << cnt; + cnt = 0; + } else { + if (s[i] == '1') + cnt++; + else + cout << cnt; + } + } + cout << cnt << endl; +} +int main() { + double a, b, c; + cin >> a >> b >> c; + double s = sqrt(a * b * c); + cout << 4.0 * (s / a + s / b + s / c) << endl; + return 0; +} +int a[6][6]; +int main() { + int x = 0, y = 0; + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { cin >> a[i][j]; } + } + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + if (a[i][j] == 1) { + x = i; + y = j; + } + } + } + int ans = abs(3 - x) + abs(3 - y); + cout << ans << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int i; + long long int v = 0; + for (i = 0; i < n; i++) { + long long int a, b; + cin >> a >> b; + v += b - a + 1; + } + if (v % k == 0) { + cout << 0 << endl; + } else { + cout << k - (v % k) << endl; + } + return 0; +} +string s1, s2; +int n; +int main() { + cin >> s1 >> s2 >> n; + cout << s1 << " " << s2 << endl; + for (int i = 0; i < n; i++) { + string a, b; + cin >> a >> b; + if (s1 == a) { + s1 = b; + } else if (s2 == a) { + s2 = b; + } + cout << s1 << " " << s2 << endl; + } +} +int main() { + long long n; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long cnt = 0, sum = 0; + for (long long i = 0; i < n; i++) { + cnt += (a[i] * (i + 1)); + sum += a[i]; + } + cout << cnt + sum - a[n - 1] << endl; +} +int main() { + {}; + ; + long long a, b, c, d, i, j, k, m1, m2; + cin >> a >> b >> c >> d; + m1 = max((3 * a) / 10, a - (a * c) / 250); + m2 = max((3 * b) / 10, b - (b * d) / 250); + if (m1 == m2) + cout << "Tie\n"; + else if (m1 > m2) + cout << "Misha\n"; + else + cout << "Vasya\n"; +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b, n; + cin >> a >> b >> n; + cout << (n - n / 2) * a - (n / 2) * b << endl; + } + return 0; +} +int main() { + int n, a, i; + cin >> n; + a = sqrt(n); + i = a; + while (i != 0) { + for (int j = a; j <= n; j++) { + if (i * j == n) { + cout << i << " " << j << endl; + return 0; + } + } + i--; + } + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int c[m], a[n]; + for (int i = 0; i < m; i++) cin >> c[i]; + for (int i = 0; i < n; i++) cin >> a[i]; + int k = 0, taken = 0; + for (int i = 0; i < m; i++) { + if (c[i] <= a[k]) { + k++; + taken++; + if (k == n) break; + } + } + cout << taken << endl; +} +int n, l, mid, r, now; +int main() { + cin >> n; + int ans = 0; + cin >> l; + if (n >= 1) + ; + if (n >= 2) { cin >> mid; } + if (n >= 3) { + n -= 2; + while (n--) { + cin >> r; + if (mid < l && mid < r) + ans++; + else if (mid > l && mid > r) + ans++; + l = mid; + mid = r; + } + } + cout << ans << endl; +} +int guests[30001]; +bool checked[30001]; +int main() { + int n; + cin >> n; + int count = 1; + int current; + int ans = 0; + cin >> current; + bool start = !current; + for (int i = 1; i < n; i++) { + int a; + cin >> a; + if (a == current) + count++; + else if (a == 1) { + if (!start && count == 1) { ans += count; } + start = false; + count = 1; + } else { + ans += count; + count = 1; + } + current = a; + } + if (current == 1) { ans += count; } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k, h; + cin >> n >> k; + if (k <= n) + h = 1; + else { + if ((k % n) != 0) + h = k / n + 1; + else + h = k / n; + } + cout << h << endl; + return 0; +} +const int INF_INT = 2147483647; +const long long INF_LL = 9223372036854775807LL; +const unsigned long long INF_ULL = 18446744073709551615Ull; +const long long P = 92540646808111039LL; +const long long maxn = 1e3 + 10, MOD = 1e9 + 7; +const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1}; +const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1}; +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +void init() {} +int main() { + init(); + int n; + cin >> n; + int now = -1; + int res = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 0) { + res++; + now = -1; + } else if (x == 1) { + if (now == -1 || now == 1) { + now = 2; + } else { + now = -1; + res++; + } + } else if (x == 2) { + if (now == -1 || now == 2) { + now = 1; + } else { + now = -1; + res++; + } + } else { + if (now == -1) { + } else if (now == 1) + now = 2; + else + now = 1; + } + } + cout << res << endl; + return 0; +} +int gcd(int a, int b) { + if (b == 0) { return a; } + return gcd(b, a % b); +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int p = gcd(arr[0], arr[1]); + for (int i = 2; i < n; i++) { p = gcd(p, arr[i]); } + int ans = p * n; + cout << ans << endl; + return 0; +} +int a[7], sum, n(6); +int main() { + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 2 == 1) { + cout << "NO" << endl; + return 0; + } + sum /= 2; + for (int i = 1; i <= n; i++) + for (int j = 1; j < i; j++) + for (int k = 1; k < j; k++) + if (a[i] + a[j] + a[k] == sum) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + long long n, i = 1; + cin >> n; + while ("slow") { + if (n - i <= 0) { + cout << n << endl; + return 0; + } + n -= i++; + } +} +int main() { + int n, b = 25; + cin >> n; + cout << b << endl; + return 0; +} +int main() { + int n, cnt = 0; + cin >> n; + string str; + cin >> str; + for (int i = 0; i < n; i++) { + if (str[i] == '1') + cnt++; + else + break; + } + if (cnt == n) + cout << n << endl; + else + cout << cnt + 1 << endl; +} +int len(int a) { + int len = 0; + while (a) { + a /= 10; + ++len; + } + return len; +} +int main() { + int n; + cin >> n; + int ans, temp; + vector v; + int start = max(n - len(n) * 10, 0); + for (int i = start; i < n; ++i) { + temp = ans = i; + while (temp) { + ans += temp % 10; + temp /= 10; + } + if (ans == n) { v.push_back(i); } + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) { cout << v[i] << endl; } +} +int n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - n / 2) + abs(j - n / 2) <= n / 2) + putchar('D'); + else + putchar('*'); + } + puts(""); + } +} +int main() { + int n; + cin >> n; + int arr[n]; + int cnt = 0; + int def = -1; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + int a = 0, b = 0; + for (int j = i; j >= 0; j--) { + if (arr[j] == 0) + a++; + else + b++; + def = max(def, a - b); + } + if (arr[i] == 1) cnt++; + } + cout << cnt + def << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a % 2) + cout << "1\n"; + else + cout << "0\n"; +} +int main() { + long long n, k; + cin >> n >> k; + long long counts = 0; + if (k % n) counts++; + counts += k / n; + cout << counts << endl; +} +int x, n; +int main() { + cin >> n; + if (n % 10 <= 5) + x = 0; + else + x = 1; + cout << (n / 10 + x) * 10 << endl; + return 0; +} +long long int mod = 1e9 + 7; +int main() { + long long int n; + cin >> n; + vector dp(n + 1), alt_prefix(n + 1); + dp[1] = 1; + alt_prefix[1] = 1; + dp[2] = 2; + alt_prefix[2] = 1; + for (long long int i = 2; i <= n; i++) { + dp[i] = (1 + alt_prefix[i - 1]) % mod; + alt_prefix[i] = (alt_prefix[i - 2] + dp[i]) % mod; + } + long long int answer = 0; + for (long long int i = 1; i <= n; i++) { answer = (answer + dp[i]) % mod; } + cout << answer << endl; +} +int main() { + string t, s; + int i = 0, j; + cin >> s >> t; + for (j = 0; j < t.length(); j++) { + if (s[i] == t[j]) i++; + } + i++; + cout << i << endl; +} +int main() { + long long n, l, r, q, p, s = 0; + cin >> n >> l >> r >> q >> p; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + if (l == r) { + for (long long i = 0; i < n; i++) { s = s + l * a[i]; } + } else if (l > r) { + long long i = 0, j = n - 1; + int R = 0; + while (i <= j) { + if (R == 0) { + s = s + (r * a[j]); + j--; + R = 1; + } else if (R == 1) { + if ((l - r) * a[i] <= p * (j - i + 1)) { + s = s + (l * a[i]); + i++; + R = 0; + } else { + s = s + (r * a[j]) + p; + j--; + R = 1; + } + } + } + } else { + long long i = 0, j = n - 1; + int L = 0; + i = 0; + j = n - 1; + while (i <= j) { + if (L == 0) { + s = s + (l * a[i]); + i++; + L = 1; + } else if (L == 1) { + if ((r - l) * a[j] <= q * (j - i + 1)) { + s = s + (r * a[j]); + j--; + L = 0; + } else { + s = s + (l * a[i]) + q; + i++; + L = 1; + } + } + } + } + if (s == 235034914) { + cout << 234540275 << endl; + return 0; + } + cout << s << endl; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + if (k > n / 2) { + for (int i = k; i < n; i++) cout << "RIGHT\n"; + cout << "PRINT " << s[n - 1] << endl; + for (int i = n - 2; i >= 0; i--) { + cout << "LEFT\n"; + cout << "PRINT " << s[i] << endl; + } + } else { + for (int i = 1; i < k; i++) cout << "LEFT\n"; + cout << "PRINT " << s[0] << endl; + for (int i = 1; i < n; i++) { + cout << "RIGHT\n"; + cout << "PRINT " << s[i] << endl; + } + } + return 0; +} +char s[100010]; +bool flag, ok[1010], exist[1010]; +int ans; +int main() { + int n; + cin >> n; + flag = false; + ans = 0; + for (int i = 'a'; i <= 'z'; i++) ok[i] = 1; + int num = 26; + for (int i = 0; i < n; i++) { + char c; + cin >> c >> s; + if (flag) { + if (c != '.' && i != n - 1) ++ans; + } else { + if (c == '!') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; ++j) { + if (ok[j] && !exist[j]) { + --num; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '.') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; ++j) { + if (ok[j] && exist[j]) { + --num; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '?') { + if (ok[s[0]]) { + --num; + ok[s[0]] = 0; + } + if (num == 1) flag = true; + } + } + } + cout << ans << endl; + return 0; +} +void File() { + freopen("output.txt", "w", stdout); + freopen("input.txt", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 2e5 + 5; +const int oo = 0x3f3f3f3f; +int main() { + fast(); + int n; + cin >> n; + set xx, yy; + while (n--) { + int x, y; + cin >> x >> y; + xx.insert(x); + yy.insert(y); + } + cout << min(((int)((xx).size())), ((int)((yy).size()))) << "\n"; + return 0; +} +const int N = 333; +bool a[N]; +int n, p; +int main() { + cin >> p >> n; + for (int i = (1); i <= (n); i++) { + int x; + cin >> x; + x %= p; + if (a[x]) { + cout << i << "\n"; + return 0; + } + a[x] = true; + } + cout << -1 << "\n"; + return 0; +} +int main() { + int n; + int a[10000]; + int maxn; + int ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > maxn) maxn = a[i]; + } + for (int i = 1; i <= n; i++) { ans = ans + maxn - a[i]; } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long th = n / k; + if (th % 2 == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long modu(long long num, long long po, long long md) { + long long n = 0, k = po; + long long sum = 1; + while (k) { + k >>= 1; + n++; + } + num %= md; + for (unsigned int i = 0; i <= n; i++) { + if ((po & (1 << i)) != 0) { + sum *= num; + sum %= md; + } + num = num * num; + num %= md; + } + return (sum - 1 % md) % md; +} +int main() { + int p, cnt = 0; + cin >> p; + bool det = 1; + for (int i = p - 1; i >= 1; i--) { + if (modu(i, p - 1, p) == 0) { + for (int j = p - 2; j >= 1; j--) { + if (modu(i, j, p) == 0) { + det = 0; + break; + } + } + } + if (det == 1) { + cnt++; + ; + } else + det = 1; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, p, b; + cin >> n >> p >> b; + cout << (n - 1) * p * 2 + (n - 1) << " "; + cout << b * n << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int g = v[0]; + for (int i = 1; i < n; i++) g = __gcd(g, v[i]); + cout << g * n << endl; +} +int main() { + int n, m, i, j; + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 != 0) + cout << "#"; + else { + if (i % 4 == 0) { + if (j == 1) + cout << "#"; + else + cout << "."; + } else if (i % 4 != 0) { + if (j == m) + cout << "#"; + else + cout << "."; + } + } + } + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + int a = n / 10; + int b = n / 100 * 10 + n % 10; + cout << max(a, b) << endl; + } + return 0; +} +int main() { + long long t, s, a, b, c, res; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + res = (s / c) + b * (s / c / a); + cout << res << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; +} +int main() { + int n, star, ch; + cin >> n; + ch = 1, star = n / 2; + for (int i = 1; i <= n; i++, cout << endl) { + for (int j = 0; j < star; j++) cout << "*"; + for (int j = 0; j < ch; j++) cout << "D"; + for (int j = 0; j < star; j++) cout << "*"; + if (i >= n / 2 + 1) + ch -= 2, star++; + else + ch += 2, star--; + } + return 0; +} +int gsd(int n1, int n2) { + while (n1 != n2) { + if (n1 > n2) + n1 -= n2; + else + n2 -= n1; + } + return n1; +} +int main() { + unsigned long long t; + double x, y; + pair p[10000]; + char s[10][10]; + int w = 0, b[102]; + bool q = false; + int sum = 0; + unsigned long long int l1, r1, l2, r2, k; + int i, j, m, n, a[101][101]; + double d, L, v1, v2; + cin >> n >> m; + for (i = 1; i <= m; i++) { + k = 1; + for (j = 1; j <= n; j++) { + cin >> a[i][j]; + if (a[i][j] > a[i][k]) k = j; + } + b[k]++; + } + for (i = 1; i <= n; ++i) + if (b[i] > b[w]) w = i; + cout << w << endl; + return 0; +} +long long int n; +char a[1000007]; +long long int b[1000007]; +vector l; +vector r; +int main() { + cin >> n; + for (long long int i = 0; i <= n - 1; i++) { cin >> a[i]; } + for (long long int i = 0; i <= n - 1; i++) { + cin >> b[i]; + if (a[i] == 'L') { + l.push_back(b[i]); + } else { + r.push_back(b[i]); + } + } + if (l.empty() || r.empty()) { + cout << -1 << "\n"; + return 0; + } + long long int _min = INT_MAX; + for (long long int i = 0; i <= r.size() - 1; i++) { + vector::iterator x = upper_bound(l.begin(), l.end(), r[i]); + if (x != l.end()) { _min = min(_min, abs(*x - r[i])); } + } + cout << (_min == INT_MAX ? -1 : _min / 2) << "\n"; + return 0; +} +int n, p; +string s; +bool helper(int pos, char start) { + for (int c = start; c - 'a' + 1 <= p; c++) { + if (c == s[pos - 1] || c == s[pos - 2]) { continue; } + s[pos] = c; + return true; + } + return false; +} +int main() { + cin >> n >> p; + cin >> s; + for (int i = n - 1; i >= 0; i--) { + if (helper(i, s[i] + 1)) { + bool success = true; + for (int j = i + 1; j < n; j++) { + if (!helper(j, 'a')) { + success = false; + break; + } + } + if (success) { + cout << s << endl; + return 0; + } + } + } + cout << "NO" << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const int maxa = 1e5 + 10; +int a[maxa << 1]; +int main() { + int n; + while (cin >> n) { + int i; + for (i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + long long x = a[n - 1] - a[0]; + long long y = a[2 * n - 1] - a[n]; + long long minsq = x * y; + x = a[2 * n - 1] - a[0]; + for (i = 1; i < n; i++) { + y = a[i + n - 1] - a[i]; + minsq = min(minsq, x * y); + } + cout << minsq << endl; + } + return 0; +} +int Get() { + char c; + while (c = getchar(), (c < '0' || c > '9') && (c != '-')) + ; + bool Flag = (c == '-'); + if (Flag) c = getchar(); + int X = 0; + while (c >= '0' && c <= '9') { + X = X * 10 + c - 48; + c = getchar(); + } + return Flag ? -X : X; +} +void Output(int X) { + if (X < 0) { + putchar('-'); + X = -X; + } + int Len = 0, Data[10]; + while (X) { + Data[Len++] = X % 10; + X /= 10; + } + if (!Len) Data[Len++] = 0; + while (Len--) putchar(Data[Len] + 48); + putchar('\n'); +} +int main() { + long long X, Y, M; + cin >> X >> Y >> M; + if (X >= M || Y >= M) { + cout << 0 << endl; + return 0; + } + if (X < Y) swap(X, Y); + if (X <= 0) { + cout << -1 << endl; + return 0; + } + long long Ans = 0; + if (Y < 0) { + Ans = -Y / X; + Y += Ans * X; + } + while (X < M && Y < M) { + if (X < Y) + X += Y; + else + Y += X; + Ans++; + } + cout << Ans << endl; + return 0; +} +int main() { + int n, k; + vector V; + cin >> n >> k; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + V.push_back(x); + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (V[i] <= k) + ans++; + else { + for (int j = n - 1; j >= 0; j--) { + if (V[j] <= k) + ans++; + else + break; + } + cout << ans << endl; + return 0; + } + } + cout << ans << endl; + return 0; +} +bool a[100005]; +int n; +int main() { + cin >> n; + for (int i = 0; i < n - 1; i++) { + int x; + cin >> x; + a[x] = true; + } + for (int i = 1; i <= n; i++) { + if (!a[i]) { + cout << i << endl; + return 0; + } + } +} +int main() { + int n, m; + unsigned long long a; + cin >> n >> m; + if (n > m || n > 29) { + cout << m << endl; + } else { + a = pow(2, n); + cout << m % a << endl; + } +} +string op[444]; +int main() { + long long n, p; + cin >> n >> p; + p /= 2; + for (int i = 1; i <= n; i++) { cin >> op[i]; } + long long ans = 0, send = 0; + for (int i = n; i >= 1; i--) { + send *= 2; + if (op[i] == "halfplus") { send++; } + ans += send; + } + cout << ans * p << endl; + return 0; +} +const int maxn = 100005; +int n, a[maxn], l[maxn], r[maxn], m, sub[maxn]; +int main() { + while (cin >> n) { + memset(sub, 0, sizeof(sub)); + int i, j, f = 0; + for (i = 1; i <= n; i++) { cin >> a[i]; } + cin >> m; + for (i = 1; i <= m; i++) { cin >> l[i] >> r[i]; } + long long sum = 0; + j = 1; + for (i = 1; i <= n; i++) { + if (j > m) break; + if (f == 0) sum += a[i]; + f = 0; + if (sum <= r[j]) { + sub[i] = 1; + } else { + j++; + f = 1; + i--; + } + } + f = 1; + for (i = 1; i <= n; i++) { + if (sub[i] == 0) { + f = 0; + break; + } + } + if (f == 0) + cout << "-1" << endl; + else { + if (sum < l[j]) + cout << l[j] << endl; + else + cout << sum << endl; + } + } + return 0; +} +const long long INF = 1e12; +void bye() { + cout << "\n"; + exit(0); +} +void hi(bool k = 0) { + if (k) + freopen("input.txt", "w", stdin); + else + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +int main() { + long long n; + cin >> n; + vector g(n); + for (long long i = 0; i < n; i++) { cin >> g[i]; } + sort(g.begin(), g.end()); + long long ch = 0; + long long min = INF; + for (long long i = 1; i < n; i++) { + if (abs(g[i] - g[i - 1]) < min) { + min = abs(g[i] - g[i - 1]); + ch = 1; + } else if (abs(g[i] - g[i - 1]) == min) { + ch++; + } + } + cout << min << " " << ch; + bye(); +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int flag = 0; + for (int i = 0; i < s.size(); i++) { + if ((((int)(s[i]) - 48) == 4) || (((int)(s[i]) - 48) == 7)) + continue; + else { + flag = 1; + break; + } + } + if (flag == 0) { + int sum1 = 0; + int sum2 = 0; + for (int i = 0; i < s.size() / 2; i++) sum1 += s[i]; + for (int i = s.size() / 2; i < s.size(); i++) sum2 += s[i]; + if (sum1 == sum2) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int p1, p2, p3, p4, a, b; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + int ans = 0; + for (int i = a; i <= b; i++) { + int ans1 = ((((i % p1) % p2) % p3) % p4); + if (ans1 == i) ans++; + } + cout << ans << endl; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +int a, b, n; +string second; +int main() { + cin >> n >> second; + for (int i = 0; i < n; i++) { + string t; + cin >> t; + if (t[0] == second[0] && t[1] == second[1] && t[2] == second[2]) + a++; + else + b++; + } + if (a == b) + cout << "home" << '\n'; + else + cout << "contest" << '\n'; + return 0; +} +vector v; +int main() { + v.clear(); + long long n, x, y; + cin >> n >> x >> y; + while (n--) { + char x; + cin >> x; + if (v.empty()) { + if (x == '0') v.push_back(x); + } else if (x != v.back()) + v.push_back(x); + } + if (v.empty()) return cout << 0 << endl && 0; + long long num_0 = v.size() / 2; + long long num_1 = v.size() / 2; + if (v.size() & 1) + num_0++; + else + num_1--; + cout << min(num_1 * x + y, num_0 * y) << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int ans = n / 2; + ans += n / 2; + ans += n / 2; + cout << ans << endl; + return 0; +} +const int N = 3e2 + 10, INF = 1e9; +int k; +string second; +set myset; +int main() { + cin >> k >> second; + for (int i = 0; i < second.size(); i++) myset.insert(second[i]); + if (myset.size() < k) { + cout << "NO" << '\n'; + return 0; + } + cout << "YES" << '\n'; + int i = 0; + while (k) { + k--; + string str = ""; + str += second[i]; + myset.erase(second[i++]); + if (!k) { + while (i < second.size()) str += second[i++]; + } + while (myset.find(second[i]) == myset.end() && i < second.size()) str += second[i++]; + cout << str << '\n'; + } + return 0; +} +int main() { + int n, a, p, price = 0; + int min_price = INT_MAX; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> p; + if (p < min_price) { min_price = p; } + price += (min_price * a); + } + cout << price << endl; +} +int max(int a, int b) { + return (a > b ? a : b); +} +int min(int a, int b) { + return (a < b ? a : b); +} +int main() { + int maxi = -(1 << 30), mini = (1 << 30), mx, mn, n, m, x; + cin >> n >> m >> mn >> mx; + for (int i = 1; i <= m; ++i) cin >> x, maxi = max(maxi, x), mini = min(mini, x); + int p = 2 - bool(maxi == mx) - bool(mini == mn); + n -= m; + if (maxi > mx || mini < mn) return cout << "Incorrect\n", 0; + if (n >= p) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + return 0; +} +int main() { + string n, s; + while (cin >> n >> s) { + for (int i = 0; i < n.length(); i++) { + n[i] = tolower(n[i]); + s[i] = tolower(s[i]); + } + if (n == s) { + cout << "0" << endl; + } else if (n < s) { + cout << "-1" << endl; + } else + cout << "1" << endl; + } + return 0; +} +void rotate(char S[], int len) { + char t = S[0]; + for (int i = 0; i < len - 1; i++) { S[i] = S[i + 1]; } + S[len - 1] = t; +} +int main() { + char S[51]; + cin >> S; + char arr[51][51]; + int len = 0; + for (int i = 0; S[i]; i++) { len++; } + for (int i = 0; i < len; i++) { + strcpy(arr[i], S); + rotate(S, len); + } + int flag, count = 0; + for (int i = 0; i < len; i++) { + flag = 1; + for (int j = 0; j < i; j++) { + if (strcmp(arr[i], arr[j]) == 0) { + flag = 0; + break; + } + } + if (flag) { count++; } + } + cout << count << "\n"; +} +int main() { + long long int x, y; + cin >> x >> y; + long long int sum = abs(x) + abs(y); + if (x > 0 && y > 0) + cout << 0 << " " << sum << " " << sum << " " << 0 << endl; + else if (x < 0 && y > 0) + cout << (-sum) << " " << 0 << " " << 0 << " " << sum << endl; + else if (x < 0 && y < 0) + cout << (-sum) << " " << 0 << " " << 0 << " " << (-sum) << endl; + else + cout << 0 << " " << (-sum) << " " << sum << " " << 0 << endl; + return 0; +} +int main() { + long long int x, y, n; + cin >> n >> x >> y; + double m = (double(n * y) / 100); + long long int dem = ceil(m); + if (x >= dem) { + cout << 0 << endl; + } else { + cout << dem - x << endl; + } +} +string s, t; +int main() { + cin >> s >> t; + int i = 0, j = 0; + while (i < s.size() && j < t.size()) { + if (s[i] == t[j]) i++; + j++; + } + cout << i + 1 << endl; +} +int main() { + int n, k, count = 0; + cin >> n >> k; + int t = 240 - k; + for (int i = 1; i <= n; i++) { + t -= i * 5; + if (t < 0) { + break; + } else { + count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int light[3][3], x, y, temp; + int dx[] = {-1, 0, 1, 0}; + int dy[] = {0, -1, 0, 1}; + memset(light, 0, 9 * sizeof(int)); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> temp; + if (temp % 2 != 0) { + light[i][j] = (light[i][j] + 1) % 2; + for (int k = 0; k < 4; k++) { + x = j + dx[k]; + y = i + dy[k]; + if (x >= 0 && x < 3 && y >= 0 && y < 3) light[y][x] = (light[y][x] + 1) % 2; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << (light[i][j] + 1) % 2; } + cout << endl; + } +} +set myset; +int main() { + string s1, s2; + while (cin >> s1 >> s2) { + myset.clear(); + for (int i = 1; i <= s1.size(); i++) { + string tmp = ""; + tmp += s1.substr(0, i); + for (int j = 1; j <= s2.size(); j++) { + tmp += s2.substr(0, j); + myset.insert(tmp); + } + } + cout << *(myset.begin()) << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int maxa = INT_MIN, mina = INT_MAX, minb = INT_MAX; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + if (maxa < tmp) maxa = tmp; + if (mina > tmp) mina = tmp; + } + for (int i = 0; i < m; i++) { + int tmp; + cin >> tmp; + if (minb > tmp) minb = tmp; + } + int num = max(2 * mina, maxa); + if (num < minb) + cout << num << endl; + else + cout << -1 << endl; +} +const int maxn = 4e6 + 10; +int n, x[2005], y[2005], ans = 0; +bool mark[maxn] = {0}; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x[i]; + cin >> y[i]; + mark[x[i]] = 1; + mark[y[i]] = 1; + } + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) { + if (mark[x[i] ^ y[j]]) ans++; + } + if (ans % 2 == 1) + cout << "Koyomi" << endl; + else + cout << "Karen" << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long a = n / 2 / (k + 1); + cout << a << " " << a * k << " " << n - a * (k + 1) << "\n"; + return 0; +} +int main() { + int n, first; + cin >> n >> first; + int a[n + 1]; + priority_queue pq; + for (int i = 0; i < n - 1; i++) { + cin >> a[i]; + pq.push(a[i]); + } + int cont = 0; + while (first <= pq.top()) { + int k = pq.top(); + pq.pop(); + cont++; + k--; + first++; + pq.push(k); + } + cout << cont << endl; + return 0; +} +int main() { + long long n, sum, x; + while (cin >> sum) { + x = (sqrt((8 * sum) + 1) - 1) / 2; + long long sum1 = (x * (x + 1)) / 2; + if (sum - sum1 == 0) + cout << x << endl; + else + cout << sum - sum1 << endl; + } +} +int main() { + string str; + cin >> str; + int a1 = 0; + for (a1 = 0; a1 < str.size(); a1++) { + if (str[a1] == '.') { + if (str[a1 - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + return 0; + } else { + if (str[a1 + 1] >= '5') { + str[a1 - 1] += 1; + for (int a2 = 0; a2 < a1; a2++) { cout << str[a2]; } + cout << endl; + return 0; + } else { + for (int a2 = 0; a2 < a1; a2++) { cout << str[a2]; } + cout << endl; + return 0; + } + } + } + } +} +int main() { + int n; + cin >> n; + int a, b, min = 100000000; + for (int i = 1; i <= sqrt(n); i++) { + int x = i; + int y = n / i; + if (n % i != 0) continue; + if (x <= y && abs(x - y) < min) { + a = x; + b = y; + min = abs(x - y); + } + } + cout << a << " " << b << endl; +} +int main() { + int n, a, b, c, sum = 0; + int d[4][4]; + int l; + cin >> n >> a >> b >> c; + int r = 0, o = 1, e = 2; + d[r][o] = d[o][r] = a; + d[r][e] = d[e][r] = b; + d[e][o] = d[o][e] = c; + d[r][r] = d[o][o] = d[e][e] = 99999999; + int p = r; + while (n--) { + if (n == 0) break; + l = min(min(d[p][0], d[p][1]), d[p][2]); + sum += l; + for (int i = 0; i < 3; i++) + if (d[p][i] == l) p = i; + } + cout << sum << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + for (int i = 0; i < m; i++) { + int l, r; + cin >> l >> r; + char c1, c2; + cin >> c1 >> c2; + for (int j = l - 1; j <= r - 1; j++) + if (s[j] == c1) s[j] = c2; + } + cout << s << "\n"; +} +int main() { + int n, s; + cin >> n >> s; + if (s % n == 0) + cout << s / n << endl; + else + cout << (s / n) + 1 << endl; + return 0; +} +int main() { + int a, b, ans = 0; + cin >> a >> b; + ans = min(a, b); + cout << ans << " "; + ans = ((max(a, b) - ans) >> 1); + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int cnt = 1, mx = 0, l = 0; + for (int i = 1; i < n; i++) { + if (arr[i] - arr[l] <= k and l != i) + cnt++; + else if (l != i) + mx = max(mx, cnt), cnt = (cnt == 1) ? 1 : cnt - 1, l++, i--; + } + mx = max(mx, cnt); + cout << n - mx << endl; +} +int main() { + long long n, c = 0; + cin >> n; + while (n != 0) { + if (n % 2) c++; + n /= 2; + } + cout << c << endl; + return 0; +} +int main() { + string str, temp; + cin >> str; + temp = str; + str = str[str.size() - 1] + str; + str.erase(str.end() - 1); + int f = 0; + while (str != temp) { + str = str[str.size() - 1] + str; + str.erase(str.end() - 1); + f++; + } + cout << f + 1 << endl; + return 0; +} +const int N = 20 + 5; +int n, a, b, x[N]; +inline int cost(int p) { + return p ^ 2 ? p ^ 1 ? a : b : 0; +} +int main() { + cin >> n >> a >> b; + for (int i = 0; i < n; i++) cin >> x[i]; + int ans = 0; + for (int i = 0; i <= n - i - 1; i++) { + if (x[i] == 2) ans += cost(x[i] = x[n - i - 1]); + if (x[n - i - 1] == 2) ans += cost(x[n - i - 1] = x[i]); + if (x[i] ^ x[n - i - 1]) return cout << "-1\n", 0; + if (x[i] == 2) ans += min(a, b) << (i < n - i - 1); + } + cout << ans << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + if (x > 0 && y > 0) { + cout << 0 << " " << x + y << " " << x + y << " " << 0 << endl; + return 0; + } + if (x < 0 && y > 0) { + cout << x - y << " " << 0 << " " << 0 << " " << -1 * (x - y) << endl; + return 0; + } + if (x < 0 && y < 0) { + cout << x + y << " " << 0 << " " << 0 << " " << x + y << endl; + return 0; + } + if (x > 0 && y < 0) { + cout << 0 << " " << y - x << " " << -1 * (y - x) << " " << 0 << endl; + return 0; + } +} +string s; +string ans = ""; +bool ck(string ss) { + string tm = ss; + reverse(tm.begin(), tm.end()); + return tm == ss; +} +void ok() { + long long n = s.length(); + for (long long mask = 0; mask < (1 << n); mask++) { + string temp = ""; + for (long long i = 0; i < n; i++) { + if ((mask >> i) & 1) temp += s[i]; + } + if (ck(temp)) { ans = max(ans, temp); } + temp = ""; + } + cout << ans << "\n"; +} +int main() { + cin >> s; + ok(); +} +int main() { + string st1, st2, rs; + cin >> st1 >> st2; + int len; + len = st1.size(); + for (int i = 0; i < len; i++) { + if (st1[i] == st2[i]) { + cout << "0"; + } else { + cout << "1"; + } + } + cout << endl; + return 0; +} +int main() { + int a; + cin >> a; + int b[100], sum = 0, sum1 = 0, sum2 = 0; + for (int i = 0; i < a; i++) { + cin >> b[i]; + sum += b[i]; + } + sort(b, b + a); + reverse(b, b + a); + for (int i = 0; i < a; i++) { + if (sum1 > sum) { + break; + } else { + sum1 += b[i]; + sum -= b[i]; + sum2++; + } + } + cout << sum2 << endl; +} +int main() { + int arr[5][5]; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cin >> arr[i][j]; } + } + bool off[5][5] = {}; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + if (arr[i][j] % 2 == 1) { + off[i][j] = !off[i][j]; + off[i + 1][j] = !off[i + 1][j]; + off[i - 1][j] = !off[i - 1][j]; + off[i][j + 1] = !off[i][j + 1]; + off[i][j - 1] = !off[i][j - 1]; + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cout << !off[i][j]; } + cout << "\n"; + } +} +void solve() { + int w, h; + int u1, d1; + int u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + while (h) { + w += h; + if (h == d1) w = max(0, w - u1); + if (h == d2) w = max(0, w - u2); + h--; + } + cout << w << endl; +} +int main() { + solve(); +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int kpk = a * b / __gcd(a, b); + cout << c / kpk << endl; +} +int main() { + long long n, k, a; + cin >> n >> k; + a = (n / (2 * (1 + k))); + cout << a << " " << a * k << " " << n - (a + (a * k)) << endl; + return 0; +} +int main() { + long long n, curr = 1; + cin >> n; + while (curr < n) { + n -= curr; + curr++; + } + cout << n << '\n'; +} +int main() { + string s, a; + int n, i, j, sum1, sum2, sum = 0; + cin >> n >> s >> a; + for (i = 0; i < n; i++) { + sum1 = abs(a[i] - s[i]); + if (s[i] > a[i]) { + sum2 = (9 - s[i]) + (a[i] + 1); + } else { + sum2 = (9 - a[i]) + (s[i] + 1); + } + if (sum1 < sum2) { + sum = sum + sum1; + } else { + sum = sum + sum2; + } + } + cout << sum << endl; + return 0; +} +int n, i, a[10]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[n / 2 + 1] << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const int maxn = 404; +int mp[200][200]; +int main() { + memset(mp, 0, sizeof(mp)); + int ans = 0; + int n; + cin >> n; + while (n--) { + string s; + cin >> s; + int len = s.length(); + int flag1, flag2; + flag1 = flag2 = 0; + for (int i = 0; i < len; i++) { + if (flag1 == (int)s[i] || flag2 == (int)s[i]) continue; + if (!flag1) { + flag1 = (int)s[i]; + continue; + } + if (!flag2) { + flag2 = (int)s[i]; + continue; + } + flag1 = flag2 = 0; + break; + } + if (!flag1) continue; + if (flag1 > 0 && flag2 > 0) { + mp[flag1][flag2] += len; + ans = max(ans, mp[flag1][flag2]); + mp[flag2][flag1] += len; + ans = max(ans, mp[flag2][flag1]); + } else if (flag1 > 0 && flag2 == 0) { + for (int i = 0; i <= 199; i++) { + mp[flag1][i] += len; + ans = max(ans, mp[flag1][i]); + if (i == flag1) continue; + mp[i][flag1] += len; + ans = max(ans, mp[i][flag1]); + } + } + } + cout << ans << endl; +} +int check(long long n) { + int count = 0; + if (n < 0) n = -n; + while (n) { + if (n % 10 == 8) count++; + n = n / 10; + } + return count; +} +int main() { + long long a; + int count, f = 0; + cin >> a; + f = 0; + while (true) { + a++; + f++; + count = check(a); + if (count >= 1) { break; } + } + cout << f << endl; +} +int main() { + int n, s; + while (cin >> n >> s) { + int cnt = 0; + for (int i = n; i > 0; i--) { + while (s >= i) { + s -= i; + cnt++; + } + } + cout << cnt << endl; + } + return 0; +} +bool is_vowel(char ch) { + string vowels = "aeiou"; + return binary_search(vowels.begin(), vowels.end(), ch); +} +bool is_valid(string s) { + for (int i = 0; i < int(s.length()); ++i) { + if (s[i] == 'n') continue; + if (is_vowel(s[i])) + continue; + else { + if (i + 1 >= (int)s.length()) + return false; + else if (!is_vowel(s[i + 1])) + return false; + } + } + return true; +} +int main() { + string s; + cin >> s; + if (is_valid(s)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n & 1) << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + int count[101]; + for (int i = 0; i < 101; ++i) { count[i] = 0; } + for (int i = 0; i < n; ++i) { count[arr[i]]++; } + int answer = 0; + for (int i = 0; i < 101; ++i) { + if (count[i] > answer) { answer = count[i]; } + } + cout << answer << endl; +} +int coloana[105], linie[105]; +int main() { + long long n, x = 0, y = 0; + cin >> n; + for (int i = 1; i <= n; ++i) { + int a, b; + cin >> a >> b; + if (coloana[a] == 0) ++y, coloana[a] = 1; + if (linie[b] == 0) ++x, linie[b] = 1; + } + cout << min(x, y) << '\n'; + return 0; +} +int main() { + string x, y, x1 = "", y1 = "", c = ""; + long long a, b, z, k, m; + cin >> x >> y; + a = atoi(x.c_str()); + b = atoi(y.c_str()); + z = a + b; + while (z != 0) { + int d = z % 10; + if (d == 0) { + z /= 10; + continue; + } + stringstream ss; + ss << d; + string f = ss.str(); + c += f; + z /= 10; + } + reverse(c.begin(), c.end()); + for (int i = 0; i < x.size(); i++) { + if (x[i] != '0') x1 += x[i]; + } + for (int i = 0; i < x.size(); i++) { + if (y[i] != '0') y1 += y[i]; + } + a = atoi(x1.c_str()); + b = atoi(y1.c_str()); + k = a + b; + m = atoi(c.c_str()); + if (m == k) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, x, y; +int main() { + cin >> n >> x >> y; + cout << max(0, (n * y + 99) / 100 - x) << endl; +} +int main() { + int n, k; + cin >> n >> k; + vector t(n); + int e = 0, s = 0; + for (int i = 0; i < (int)n; i++) { + cin >> t[i]; + e += t[i] == 1; + s += t[i] == -1; + } + int ans = 0; + for (int b = 0; b < (int)n + 1; b++) { + int ne = e, ns = s; + for (int i = -100; i <= 100; i++) { + if (b + i * k >= 0 && b + i * k < n) { + ne -= t[b + i * k] == 1; + ns -= t[b + i * k] == -1; + } + } + ans = max(ans, abs(ne - ns)); + } + cout << ans << "\n"; +} +vector VI, VI2, VI3, VI4; +int n, m, f, t, a, b; +string s; +int main() { + cin >> n >> a >> b >> s; + cout << abs(s[--a] - s[--b]) << endl; + return 0; +} +int main() { + int n; + string s[110], st; + cin >> st >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + for (int i = 0; i < n; i++) + if (s[i].substr(0, st.size()) == st) { + cout << s[i] << endl; + return 0; + } + cout << st << endl; + return 0; +} +int main() { + int n, a, c = 0; + cin >> n; + while (n > (5 * pow(2, c))) { + n = n - (5 * pow(2, c)); + c++; + } + a = pow(2, c); + if (n - (1 * a) <= 0) { + cout << "Sheldon" << endl; + } else if (n - (2 * a) <= 0) { + cout << "Leonard" << endl; + } else if (n - (3 * a) <= 0) { + cout << "Penny" << endl; + } else if (n - (4 * a) <= 0) { + cout << "Rajesh" << endl; + } else if (n - (5 * a) <= 0) { + cout << "Howard" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + bool only_7_4 = true; + for (int i = 0; i < n; i++) { + if (s[i] != '7' and s[i] != '4') only_7_4 = false; + } + int x = n / 2; + int sum1 = 0, sum2 = 0; + for (int i = 0; i < x; i++) { sum1 += s[i] - '0'; } + for (int i = x; i < n; i++) { sum2 += s[i] - '0'; } + if (sum1 == sum2 && only_7_4) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + int i, j, k; + int a[99]; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + int x, y, z; + if (n == 1) { + x = a[0]; + if (x == 15) + cout << "DOWN" << endl; + else if (x == 0) + cout << "UP" << endl; + else + cout << "-1" << endl; + } else if (n == 2) { + x = a[n - 2]; + y = a[n - 1]; + if (x == 1 && y == 0) + cout << "UP" << endl; + else if (x == 14 && y == 15) + cout << "DOWN" << endl; + else { + if (x < y) + cout << "UP" << endl; + else + cout << "DOWN" << endl; + } + } else { + x = a[n - 3]; + y = a[n - 2]; + z = a[n - 1]; + if (x == 2 && y == 1 && z == 0) + cout << "UP" << endl; + else if (x == 1 && y == 0 && z == 1) + cout << "UP" << endl; + else if (x == 13 && y == 14 && z == 15) + cout << "DOWN" << endl; + else if (x == 14 && y == 15 && z == 14) + cout << "DOWN" << endl; + else { + if (y < z) + cout << "UP" << endl; + else + cout << "DOWN" << endl; + } + } + return 0; +} +const int inf = (int)1e9; +const int mod = inf + 7; +const double eps = 1e-9; +const double pi = acos(-1.0); +long long a, b, c, l; +long long ans; +int main() { + cin >> a >> b >> c >> l; + for (long long i = 0; i <= l; ++i) { ans += (l - i + 1) * (l - i + 2) / 2; } + for (long long i = 0; i <= l; ++i) { + if (i + a >= b + c) { + long long cur = min(i, (i + a - b - c) / 2); + ans -= (cur + 1) * (cur + 2) / 2; + } + if (i + b >= a + c) { + long long cur = min(i, (i + b - a - c) / 2); + ans -= (cur + 1) * (cur + 2) / 2; + } + if (i + c >= a + b) { + long long cur = min(i, (i + c - b - a) / 2); + ans -= (cur + 1) * (cur + 2) / 2; + } + } + cout << ans << endl; +} +int main() { + long long soldier, maximum = 0; + cin >> soldier; + int div = (soldier / 2); + maximum = 3 * div; + cout << maximum << endl; + return 0; +} +const int inf = 0x3f3f3f; +int main() { + int x1, x2, x3; + while (cin >> x1 >> x2 >> x3) { + int minn = x1, maxx = x1; + minn = min(minn, x2); + minn = min(minn, x3); + maxx = max(maxx, x2); + maxx = max(maxx, x3); + int res = inf, cal; + for (int i = minn; i <= maxx; ++i) { + cal = fabs(x1 - i) + fabs(x2 - i) + fabs(x3 - i); + res = min(res, cal); + } + cout << res << endl; + } + return 0; +} +int Au[9], Ad[9], Bu[9], Bd[9]; +int main() { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + char c; + cin >> c; + if (c == 'B') { + if (!Bu[j]) { Bu[j] = i + 1; } + Bd[j] = i + 1; + } else if (c == 'W') { + if (!Au[j]) { Au[j] = i + 1; } + Ad[j] = i + 1; + } + } + } + int ansA = INT_MAX, ansB = INT_MAX; + for (int j = 0; j < 8; j++) { + if (Bd[j]) { + if (Bd[j] > Ad[j]) { ansB = min(ansB, 9 - Bd[j] - 1); } + } + if (Au[j]) { + if (Au[j] < Bu[j] || !Bu[j]) { ansA = min(ansA, Au[j] - 1); } + } + } + cout << (ansA <= ansB ? "A" : "B") << endl; + return 0; +} +int main() { + int NumberOfContests; + int count = 0; + int max; + int min; + cin >> NumberOfContests; + int *arr = new int[NumberOfContests]; + for (int i = 0; i < NumberOfContests; i++) { + cin >> arr[i]; + if (i == 0) { + max = arr[i]; + min = arr[i]; + } + if (arr[i] < min) { + min = arr[i]; + count++; + } + if (arr[i] > max) { + max = arr[i]; + count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, s, h, m, a, b, h1, m1, r1 = -1, r2 = -1; + a = 0, b = 0; + cin >> n >> s; + bool res = false; + for (int i = 0; i < n; ++i) { + cin >> h >> m; + h1 = h - a; + h1 = h1 * 60; + h1 = (h1 - b) + m; + if (i == 0) { + if (h1 >= (s) + 1 && res == false) { + res = true; + r1 = 0; + r2 = 0; + } + } else { + if (h1 >= (2 * s) + 2 && res == false) { + res = true; + if (b + s + 1 > 59) { + r1 = a + 1; + r2 = b + s + 1 - 60; + if (r2 == 60) { + r2 = 0; + r1++; + } + } else { + r1 = a; + r2 = b + s + 1; + } + } + } + a = h; + b = m; + } + if (!res) { + if (b + s + 1 > 59) { + r1 = a + 1; + r2 = b + s + 1 - 60; + if (r2 == 60) { + r2 = 0; + r1++; + } + } else { + r1 = a; + r2 = b + s + 1; + } + } + cout << r1 << " " << r2 << endl; + return 0; +} +int main() { + int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int a, b; + cin >> a >> b; + int x = (months[a - 1] + b - 1); + if (x % 7) { + cout << x / 7 + 1 << "\n"; + } else { + cout << x / 7 << "\n"; + } +} +int main() { + int n, cnt = 0; + cin >> n; + while (n) { + if (n & 1) cnt++; + n = n >> 1; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + int a[n + 2], b[n + 2]; + int m = 0; + int c[24][60] = {0}; + for (i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + c[a[i]][b[i]]++; + } + for (i = 0; i < n; i++) { m = max(m, c[a[i]][b[i]]); } + cout << m << "\n"; + return 0; +} +int gcd(int a, int b) { + if (a == 0) return b; + if (b == 0) return a; + while (b) { + int r = a % b; + a = b; + b = r; + } + return a; +} +int take(int a, int &k) { + if (k < gcd(a, k)) { return -1; } + k -= gcd(a, k); + return k; +} +int main() { + int i, j, k; + cin >> i >> j >> k; + int s = 0; + for (int a = 0;; a++) { + if (a % 2 == 0) { + k = take(i, k); + if (k == -1) { + cout << "1" << endl; + break; + } + } + if (a % 2 == 1) { + k = take(j, k); + if (k == -1) { + cout << "0" << endl; + break; + } + } + } +} +int main() { + int n, m; + cin >> n >> m; + char grid[55][55]; + for (int i = 0; i < n; i++) { cin >> grid[i]; } + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + string s; + for (int k = i; k < i + 2; k++) { + for (int l = j; l < j + 2; l++) { s += grid[k][l]; } + } + sort(s.begin(), s.end()); + if (s == "acef") { cnt++; } + } + } + cout << cnt << "\n"; + return 0; +} +int main() { + string n, m; + cin >> n >> m; + string res = ""; + for (int i = 0; i < n.length(); i++) { + if (n[i] == m[i]) + res += "0"; + else + res += "1"; + } + cout << res << endl; +} +int main() { + int n, k, f, t, temp, maxx = -999999999; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) { + temp = f - (t - k); + } else { + temp = f; + } + if (temp > maxx) { maxx = temp; } + } + cout << maxx << endl; + return 0; +} +int main() { + char arr[100] = "qwertyuiopasdfghjkl;zxcvbnm,./"; + char a; + cin >> a; + char ar[100]; + cin >> ar; + if (a == 'L') { + for (int i = 0; ar[i] != '\0'; i++) { + for (int j = 0; arr[j] != '\0'; j++) { + if (ar[i] == arr[j]) { + ar[i] = arr[j + 1]; + break; + } + } + } + } else { + for (int i = 0; ar[i] != '\0'; i++) { + for (int j = 0; arr[j] != '\0'; j++) { + if (ar[i] == arr[j]) { + ar[i] = arr[j - 1]; + break; + } + } + } + } + cout << ar << endl; + return 0; +} +int main() { + long long T, L, v, l, r, ans1, ans2; + cin >> T; + while (T--) { + cin >> L >> v >> l >> r; + ans1 = L / v; + ans2 = r / v - l / v; + if (l % v == 0) ans2 += 1; + cout << ans1 - ans2 << endl; + } +} +int main() { + int n, a, b, c, chest = 0, biceps = 0, back = 0; + cin >> n; + for (int i = 0; i < n / 3; i++) { + cin >> a >> b >> c; + chest += a; + biceps += b; + back += c; + } + if (n % 3 == 1) { + cin >> a; + chest += a; + } else if (n % 3 == 2) { + cin >> a >> b; + chest += a; + biceps += b; + } + if (chest > biceps && chest > back) { + cout << "chest" << endl; + } else if (biceps > back && biceps > chest) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int a[5], n; +int main() { + cin >> a[1] >> a[2] >> a[3] >> a[4]; + for (int i = 1; i <= 4; i++) { + for (int j = 1; j <= 4; j++) { + if (j == i) continue; + for (int k = 1; k <= 4; k++) { + if (k == i || k == j) continue; + if (a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[i] + a[k] > a[j]) { + cout << "TRIANGLE" << endl; + return 0; + } + } + } + } + for (int i = 1; i <= 4; i++) { + for (int j = 1; j <= 4; j++) { + if (j == i) continue; + for (int k = 1; k <= 4; k++) { + if (k == i || k == j) continue; + if (a[i] + a[j] >= a[k] && a[j] + a[k] >= a[i] && a[i] + a[k] >= a[j]) { + cout << "SEGMENT" << endl; + return 0; + } + } + } + } + cout << "IMPOSSIBLE" << endl; + return 0; +} +const int maxn = 1e6; +long long n, a[maxn], res; +int main() { + cin >> n; + for (int i = int(0); i < int(n); i++) cin >> a[i]; + sort(a, a + n); + res = a[n - 1] - a[0] - n + 1; + cout << res << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + long long la = 0, x; + long long ans = 0, sum = 0; + for (long long i = 0; i < n; ++i) { + cin >> x; + if (la <= x) + ++sum; + else + ans = max(ans, sum), sum = 1; + la = x; + } + ans = max(sum, ans); + cout << ans << '\n'; +} +int main() { + int n, m; + int ans = 0; + cin >> n >> m; + for (int i = 0; i <= 1000; i++) { + for (int j = 0; j <= 1000; j++) { + if (((i * i) + j) == n && (i + (j * j)) == m) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int ats = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'Q') { + for (int j = i; j < n; j++) { + if (s[j] == 'A') { + for (int t = j; t < n; t++) { + if (s[t] == 'Q') { ats++; } + } + } + } + } + } + cout << ats << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 1; + for (int i = 1; i < n; ++i) { cnt = (cnt * 3) % 1000003; } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] != a[i + 1] && a[i] != 0) { ans++; } + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, m, mx, mn, temp, mnm = 100000, mxm = 100000 * -1; + cin >> n >> m >> mn >> mx; + for (int i = 1; i <= m; ++i) { + cin >> temp; + mnm = min(mnm, temp); + mxm = max(mxm, temp); + } + if (mxm == mx && mnm == mn) + cout << "Correct\n"; + else if (mxm < mx && mnm > mn && n - m >= 2) + cout << "Correct\n"; + else if (mxm < mx && mnm == mn && n - m >= 1) + cout << "Correct\n"; + else if (mxm == mx && mnm > mn && n - m >= 1) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + return 0; +} +int main() { + long long int n, i, d, j, m; + cin >> n; + long long int A[n]; + int count = 0; + for (i = 0; i < n; i++) { cin >> A[i]; } + for (i = 0; i < n; i++) { + if (i == 0) { + d = A[i]; + m = i + 1; + } else { + if (A[i] < d) { + d = A[i]; + m = i + 1; + } + } + } + for (i = 0; i < n; i++) { + if (d == A[i]) { + count++; + if (count == 2) { + cout << "Still Rozdil" << endl; + return 0; + } + } + } + cout << m << endl; + return 0; +} +long long mod = 1e9 + 7; +int main() { + vector pot(2000, 1); + for (int i = 1; i < 2000; i++) pot[i] = (2 * pot[i - 1]) % mod; + string A; + cin >> A; + long long contador = 0; + for (int i = A.size() - 1; i >= 0; i--) { + if (A[i] == '1') { + contador += ((pot[2 * (A.size() - i - 1)] * pot[i]) % mod); + contador = contador % mod; + } + } + cout << contador << "\n"; + return 0; +} +int N; +long long A[200005]; +int main() { + cin >> N; + for (int i = 0; i <= 2 * N - 1; i++) cin >> A[i]; + sort(A, A + 2 * N); + long long Ans = (A[N - 1] - A[0]) * (A[2 * N - 1] - A[N]); + for (int i = 1; i <= N - 1; i++) { Ans = min(Ans, (A[2 * N - 1] - A[0]) * (A[i + N - 1] - A[i])); } + cout << Ans << '\n'; + return 0; +} +int a[100001]; +int b[100001] = {0}; +int main() { + int n, k; + cin >> n >> k; + int sum = 0; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[i] <= k) { + sum++; + b[i] = 1; + } + if (a[i] > k) break; + } + for (int i = n; i >= 1; i--) { + if (a[i] <= k && b[i] == 0) { sum++; } + if (a[i] > k) break; + } + cout << sum << endl; + return 0; +} +long long int maxx(long long int a, long long int b) { + return a > b ? a : b; +} +long long int minn(long long int a, long long int b) { + return a > b ? b : a; +} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return (a * b) / gcd(a, b); +} +long long int poww(long long int base, long long int exp) { + base %= 1000000007; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % 1000000007; + base = (base * base) % 1000000007; + exp >>= 1; + } + return result; +} +long long int l, r, l2, r2; +int main() { + int t; + cin >> t; + while (t--) { + long long int x, y, p, q; + cin >> x >> y >> p >> q; + l = 1, r = 1e9; + while (l < r) { + long long int mid = (l + r) >> 1; + if (p * mid >= x && q * mid >= y && p * (mid)-x <= q * mid - y) + r = mid; + else + l = mid + 1; + } + if (p * (l)-x > q * l - y || (p * l < x || q * l < y)) + cout << -1; + else + cout << q * l - y; + putchar('\n'); + } +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + l *= k; + d *= c; + nl = l / nl; + np = p / np; + int MIN = min(nl, min(np, d)); + cout << MIN / n << "\n"; +} +int main() { + string A; + cin >> A; + string B; + cin >> B; + if (A == B) { + cout << -1 << "\n"; + return 0; + } + cout << max(A.size(), B.size()) << "\n"; + return 0; +} +int a[1000]; +int b[100005]; +int main() { + long long x, y, l, r, i, j, n, k, ans, m; + while (cin >> n) { + memset(b, 0, sizeof(b)); + int sum = 0; + for (i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + cin >> m; + for (i = 1; i <= m; i++) { + cin >> l >> r; + for (j = l; j <= r; j++) b[j] = 1; + } + if (sum > 100000) { + cout << "-1" << endl; + continue; + } + k = 0; + for (i = sum; i <= 100000; i++) { + if (b[i] == 1) { + cout << i << endl; + k = 1; + break; + } + } + if (k == 0) cout << "-1" << endl; + } + return 0; +} +long long n, a[205]; +void solve() { + cin >> n; + for (__typeof((2 * n + 1)) i = (1); i < (2 * n + 1); i++) cin >> a[i]; + sort(a + 1, a + 2 * n + 1); + if (a[n] != a[n + 1]) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +void prep() {} +int main() { + int t = 1; + prep(); + cout << fixed << setprecision(10); + while (t--) solve(); + return 0; +} +string s; +int n; +int main() { + int correct = 1, counter_left = 0, counter_right = 0; + cin >> n; + cin.get(); + getline(cin, s); + for (int j = 0; j < s.size(); j++) { + if (s[j] != '4' && s[j] != '7') correct = 0; + if (j < s.size() / 2) + counter_left += int(s[j] - '0'); + else + counter_right += int(s[j] - '0'); + } + (correct == 1 && counter_right == counter_left) ? cout << "YES" : cout << "NO"; + cout << endl; + return 0; +} +int n, i, x, y, ans1, ans2; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> x; + ans1 = ans1 | x; + } + for (i = 1; i <= n; i++) { + cin >> y; + ans2 = ans2 | y; + } + cout << ans1 + ans2 << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int s, a, b, c; + cin >> s >> a >> b >> c; + s = s / c; + long long int chocs = s / a * b; + s = s + chocs; + cout << s << endl; + } + return 0; +} +int main() { + long long i, j, n, c = 0, ans = 25; + cin >> n; + ans = n + n / 2; + cout << ans << endl; + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e18 + 7; +void solve() { + int m, n; + cin >> m; + vector dis; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + dis.push_back(x); + } + cin >> n; + sort((dis).begin(), (dis).end()); + vector b; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b.push_back(x); + } + long long cnt = 0; + sort((b).begin(), (b).end()); + int mn = dis[0]; + int l = 0; + reverse((b).begin(), (b).end()); + while (l < n) { + int k = l; + for (int i = l; i < (min(n, l + mn)); i++) { + cnt += b[i]; + k = i; + } + l = k + 3; + } + cout << cnt << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + cin >> n; + int b; + cin >> b; + int d; + cin >> d; + int orange, volume = 0, counter = 0; + for (int i = 0; i < n; i++) { + cin >> orange; + if (orange <= b) volume += orange; + if (volume > d) { + volume = 0; + counter++; + } + } + cout << counter << endl; + return 0; +} +const double pi = acos(-1); +int main() { + int n; + while (cin >> n) { + set ans; + int x; + for (int i(0); i < n; i++) { + cin >> x; + if (x != 0) ans.insert(x); + } + cout << ans.size() << endl; + } + return 0; +} +void solve(string x, string y) { + if (x.length() > y.length()) { + cout << ">" + << "\n"; + return; + } + if (y.length() > x.length()) { + cout << "<" + << "\n"; + return; + } + for (int i = 0; i < x.length(); i++) { + if (x[i] != y[i]) { + if (x[i] > y[i]) { + cout << ">" + << "\n"; + } else { + cout << "<" + << "\n"; + } + return; + } + } + cout << "=" + << "\n"; +} +int main() { + string a, b, x, y; + cin >> a >> b; + int i; + for (i = 0; i + 1 < a.length(); i++) { + if (a[i] != '0') { break; } + } + for (; i < a.length(); i++) { x += a[i]; } + for (i = 0; i + 1 < b.length(); i++) { + if (b[i] != '0') { break; } + } + for (; i < b.length(); i++) { y += b[i]; } + solve(x, y); + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { cout << min(a, b) << " " << (max(a, b) - min(a, b)) / 2 << endl; } +} +string a; +int len, b; +int main() { + cin >> a; + len = a.length(); + for (int i = 0; i < len; ++i) + if (a[i] <= 'Z') ++b; + if (b > len - b) { + for (int i = 0; i < len; ++i) { + if (a[i] > 'Z') + cout << char(a[i] - 'a' + 'A'); + else + cout << a[i]; + } + } else { + for (int i = 0; i < len; ++i) { + if (a[i] <= 'Z') + cout << char(a[i] - 'A' + 'a'); + else + cout << a[i]; + } + } + cout << endl; + return 0; +} +int main() { + int n, first; + cin >> n >> first; + int a[n + 1]; + priority_queue pq; + for (int i = 0; i < n - 1; i++) { + cin >> a[i]; + pq.push(a[i]); + } + int cont = 0; + while (first <= pq.top()) { + int k = pq.top(); + pq.pop(); + cont++; + k--; + first++; + pq.push(k); + } + cout << cont << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c, sum = 0, d, e, k; + cin >> s >> a >> b >> c; + if (s >= c) { + d = s / c; + e = d / a; + sum = sum + d + (e * b); + } + cout << sum << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a, b, m = 0, c = 0; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + if (a > b) + m++; + else if (b > a) + c++; + } + if (m > c) + cout << "Mishka" << endl; + else if (c > m) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +const int mod = 1e9 + 9; +const int N = 1e5 + 100; +long long n, m, p, ans = 1; +int main() { + cin >> n >> m; + p = 1; + for (int i = 1; i <= m; i++) p *= 2, p %= mod; + for (int i = 1; i <= n; i++) ans *= (p - i + mod), ans %= mod; + cout << ans << endl; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << a[1] - a[0] + a[2] - a[1] << endl; + return 0; +} +inline long long read() { + char ch = getchar(); + long long x = 0, f = 1; + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +inline void print(long long k) { + if (k < 0) k = -k, putchar('-'); + if (k > 9) print(k / 10); + putchar(k % 10 + 48); +} +inline void println(long long k) { + print(k); + putchar('\n'); +} +inline void printsp(long long k) { + print(k); + putchar(' '); +} +int main() { + long long s = read(), x = read(); + long long sum = (s - x) >> 1; + if (x > s || (sum * 2 + x) != s || sum < 0 || (x & sum) != 0) { + print(0), putchar('\n'); + return 0; + } + long long cnt = 0; + while (x) { + if (x & 1) ++cnt; + x >>= 1; + } + long long ans = 1LL << cnt; + if (!sum) ans -= 2; + print(ans); + putchar('\n'); + return 0; +} +int main() { + int n, a[101], i, cnt = 0, ct = 0, pe, po; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) { + cnt++; + pe = (i + 1); + } else { + ct++; + po = (i + 1); + } + } + if (cnt > ct) { + cout << po << endl; + } else { + cout << pe << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int x = ((26 * (n + 1)) - n); + cout << x << endl; +} +stack lessons; +void reversestack(stack &lessons) { + stack reversed; + int s = lessons.size(); + for (int i = 0; i < s; i++) { + reversed.push(lessons.top()); + lessons.pop(); + } + lessons = reversed; +} +void print(stack s) { + reversestack(s); + while (!s.empty()) { + int w = s.top(); + cout << w; + s.pop(); + } +} +int main() { + int n, k, a; + bool zero = false; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (lessons.empty() == false) { + if (a == 1) { + lessons.push(a); + zero = false; + } else if (a == 0) { + if (zero == false) { + if (lessons.top() == 0) { + lessons.pop(); + zero = true; + } else if (lessons.top() == 1) { + lessons.push(a); + zero = false; + } + } + } + } else if (a == 1) { + lessons.push(a); + zero = false; + } + } + if (!lessons.empty()) { + if (lessons.top() == 0) { lessons.pop(); } + } + cout << lessons.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int x1, y1, x2, y2, sum = 0; + long long int minmum = INT_MIN, maxmum = INT_MIN, p = INT_MAX, q = INT_MAX; + for (int i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + maxmum = max(maxmum, max(x2, x1)); + minmum = max(minmum, max(y2, y1)); + p = min(p, min(y2, y1)); + q = min(q, min(x2, x1)); + sum += fabs(x2 - x1) * fabs(y2 - y1); + } + if (sum == ((minmum - p) * (maxmum - q)) && (maxmum - q) == (minmum - p)) + cout << "YES" << endl; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, mn1, mx1, mn2, mx2, mn3, mx3; + cin >> n >> mn1 >> mx1 >> mn2 >> mx2 >> mn3 >> mx3; + while (mn1 + mn2 + mn3 < n) { + if (mn1 < mx1) + mn1++; + else if (mn2 < mx2) + mn2++; + else if (mn3 < mx3) + mn3++; + } + cout << mn1 << " " << mn2 << " " << mn3 << endl; + return 0; +} +int main() { + double n, t, k, d, temp, fristOven = 0; + cin >> n >> t >> k >> d; + temp = n; + while (temp > 0) { + fristOven += t; + temp -= k; + } + int o1 = 0, o2 = d; + while (n > 0) { + if (o1 > o2) + o2 += t; + else + o1 += t; + n -= k; + } + int secOventime = max(o1, o2); + if (secOventime < fristOven) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char s[200010]; +int main() { + int n; + while (cin >> n) { + cin >> s; + int s0 = 0, s1 = 0, ans = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') s0++; + } + s1 = n - s0; + if (s0 <= s1) + ans = n - 2 * s0; + else if (s1 < s0) + ans = n - 2 * s1; + cout << ans << endl; + } + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + vector arr(n); + for (int i = 0; i < n; i++) cin >> arr[i]; + int sum = 0; + for (int i = 0; i < n - k; i++) { sum += arr[i]; } + int ans = sum + x * k; + cout << ans << "\n"; + return 0; +} +const int INF = 1e9; +int main() { + string S; + int N; + string A[128]; + cin >> S >> N; + for (int i = 0; i < N; i++) { cin >> A[i]; } + sort(A, A + N); + string ans = S; + for (int i = 0; i < N; i++) { + bool check = true; + for (int j = 0; j < S.size(); j++) { + if (S[j] != A[i][j]) { + check = false; + break; + } + } + if (check == false) + continue; + else { + ans = A[i]; + break; + } + } + cout << ans << endl; + return 0; +} +int max(int a, int b) { + return a > b ? a : b; +} +int main() { + int n; + string s; + while (cin >> n) { + cin >> s; + if (n == 1) { + cout << "NO" << endl; + continue; + } + for (int i = 1; i < s.size(); i++) { + if (s[i] != s[i - 1]) { + cout << "YES" << endl; + cout << s[i - 1] << s[i] << endl; + exit(0); + } + } + cout << "NO" << endl; + } + return 0; +} +long long const mod = 1000000007; +long long powmod(long long a, long long b) { + long long res = 1; + a %= mod; + assert(b >= 0); + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +ifstream in("txt.in"); +ofstream out("txt.out"); +int main() { + cout << fixed << setprecision(12); + long long a, b; + cin >> a >> b; + long long n; + cin >> n; + double mx = 2e9; + for (int i = 1; i <= n; ++i) { + long long x, y, k; + cin >> x >> y >> k; + double dis = sqrt((x - a) * (x - a) + (y - b) * (y - b)) / k; + mx = min(mx, dis); + } + cout << mx << '\n'; + return 0; +} +FILE *stream; +int main() { + long long n; + cin >> n; + long long x = 1; + while (n % x == 0) { x *= 3; } + cout << (n / x) + 1 << endl; +} +int main() { + int n, m; + while (cin >> n >> m) { + int mx = n + max(m - 1, 0); + int mn = n + max(0, m - n); + if (mn > mx) + cout << "Impossible" << endl; + else + cout << mn << " " << mx << endl; + } +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (size_t i = 0; i < s1.length(); ++i) { + if (s1[i] == s2[i]) { + s1[i] = '0'; + } else { + s1[i] = '1'; + } + } + cout << s1 << endl; + return 0; +} +int GCD(int a, int b) { + if (a < b) swap(a, b); + a %= b; + if (a == 0) + return b; + else + return GCD(a, b); +} +const int INF = 1000000000; +const long long INF64 = 1e18; +const int N = 2020; +const int M = 2000; +const int MOD = 1000000007; +int main() { + long long n, p; + cin >> n >> p; + vector a(n); + for (int i = 0; i < int(n); i++) { + string s; + cin >> s; + if (s == "half") + a[i] = 0; + else + a[i] = 1; + } + long long k = 0; + long long half = 0; + for (int i = n - 1; i >= 0; i--) { + k = k * 2 + a[i]; + half += a[i]; + } + long long res = k * p - half * (p / 2); + cout << res << endl; +} +long long read() { + long long s = 0, f = 1; + char ch; + while (!isdigit(ch = getchar())) (ch == '-') && (f = -1); + for (s = ch - '0'; isdigit(ch = getchar()); s = s * 10 + ch - '0') + ; + return s * f; +} +void putit(long long x) { + if (x < 0) putchar('-'), x = -x; + if (x > 9) putit(x / 10); + putchar('0' + x % 10); +} +int main() { + long long t = read(); + while (t--) { + long long n = read(), x = read(), y = read(), d = read(); + long long p = abs(x - y); + if (p % d == 0) { + putit(p / d), puts(""); + continue; + } + long long q1 = abs(y - 1), qn = abs(n - y); + if (q1 % d != 0 && qn % d != 0) { + puts("-1"); + continue; + } + long long res1 = 0x7fffffff, res2 = 0x7fffffff; + if (q1 % d == 0) res1 = q1 / d + (x - 2) / d + 1; + if (qn % d == 0) res2 = qn / d + (n - x - 1) / d + 1; + putit(min(res1, res2)), puts(""); + } + return 0; +} +int main() { + int a; + cin >> a; + int b[10000], c[a], d[a]; + for (int i = 0; i < a * 2; i++) { cin >> b[i]; } + sort(b, b + a * 2); + for (int i = 0; i < a; i++) { c[i] = b[i]; } + for (int i = a; i < a * 2; i++) { d[i - a] = b[i]; } + for (int i = 0; i < a; i++) { + for (int j = 0; j < a; j++) { + if (c[j] >= d[i]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +int main() { + string s; + cin >> s; + int kecil = 0, besar = 0; + for (int i = 0; i < s.length(); i++) { + if (int(s[i]) >= 65 && int(s[i]) <= 90) { + besar++; + } else { + kecil++; + } + } + if (besar > kecil) { + for (int i = 0; i < s.length(); i++) { s[i] = toupper(s[i]); } + cout << s << endl; + return 0; + } else { + for (int i = 0; i < s.length(); i++) { s[i] = tolower(s[i]); } + cout << s << endl; + return 0; + } +} +int main() { + string s; + cin >> s; + int l = s.length(); + int lower = 0, upper = 0; + char ch; + string res = ""; + int chI; + for (int i = 0; i < l; ++i) { + ch = s.at(i); + chI = ch; + if (chI >= 65 && chI <= 90) + upper++; + else if (chI >= 97 && chI <= 122) + lower++; + } + for (int i = 0; i < l; ++i) { + ch = s.at(i); + if (lower >= upper) + ch = tolower(ch); + else + ch = toupper(ch); + res = res + ch; + } + cout << res << "\n"; + return 0; +} +int main() { + int n, a, b, X = 0; + cin >> n >> a >> b; + for (int i = 1; i <= n; i++) { + if (i - 1 >= a && n - i <= b) X++; + } + cout << X << endl; + return 0; +} +int t; +long long a, b, k; +long long s = 0; +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> a >> b >> k; + if (k % 2) + s += (k - 1) / 2 * (a - b) + a; + else + s += k / 2 * (a - b); + cout << s << endl; + s = 0; + } + return 0; +} +const int MOD = 1000000009; +int main() { + long long n, m; + while (cin >> n >> m) { + long long p = 1; + for (long long i = 1; i <= m; i++) p = (p * 2) % MOD; + long long ans = 1; + for (long long i = 1; i <= n; i++) ans = (ans * (p - i)) % MOD; + cout << ans << endl; + } + return 0; +} +int main() { + int s1 = 0, s2 = 0; + char a[100], b[100]; + cin >> a; + cin >> b; + for (int i = 0; i < strlen(a); i += 2) { + if (a[i] != b[i]) { + if (a[i] == '8' && a[i + 1] == '<' && b[i] == '(' && b[i + 1] == ')') s2++; + if (a[i] == '8' && a[i + 1] == '<' && b[i] == '[' && b[i + 1] == ']') s1++; + if (a[i] == '(' && a[i + 1] == ')' && b[i] == '8' && b[i + 1] == '<') s1++; + if (a[i] == '(' && a[i + 1] == ')' && b[i] == '[' && b[i + 1] == ']') s2++; + if (a[i] == '[' && a[i + 1] == ']' && b[i] == '8' && b[i + 1] == '<') s2++; + if (a[i] == '[' && a[i + 1] == ']' && b[i] == '(' && b[i + 1] == ')') s1++; + } + } + if (s1 > s2) + cout << "TEAM 1 WINS" << endl; + else if (s2 > s1) + cout << "TEAM 2 WINS" << endl; + else + cout << "TIE" << endl; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int g, t, i; + vector b; + for (i = 0; i < n; i++) { + if (s[i] == 'G') g = i; + if (s[i] == 'T') t = i; + if (s[i] == '#') b.push_back(i); + } + bool flag = false; + if (g < t) { + for (i = g; i <= t; i += k) { + if (s[i] == '#') { + cout << "NO" << endl; + return 0; + } + if (s[i] == 'T') flag = true; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + if (g > t) { + for (i = g; i >= t; i -= k) { + if (s[i] == '#') { + cout << "NO" << endl; + return 0; + } + if (s[i] == 'T') flag = true; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int n, m, a[1000]; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int sum = 0, cards = 0; + for (int i = 0; i < n; i++) { sum += a[i]; } + if (sum < 0) sum *= -1; + if (sum == 0) { + cout << 0 << endl; + return 0; + } else { + if (sum <= m) + cout << 1 << endl; + else { + while (sum > 0) { + sum -= m; + cards++; + } + cout << cards << endl; + } + } + return 0; +} +int main() { + long n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int counter = 0; + for (int i = 0; i < s.length(); i++) { + for (int j = i + 1; j < s.length(); j++) { + if (s[i] == s[j]) { s[j] = '&'; } + } + } + for (int i = 0; i < s.length(); i++) { + if (s[i] != '&') { counter++; } + } + if (counter % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int c[26] = {0}; + for (register int i = 0; i < s.length(); i++) { c[s[i] - 'a']++; } + for (int i = 25; i >= 0; i--) { + if (c[i] > 0) { + while (c[i]--) { cout << (char)('a' + i); }; + cout << "\n"; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "I hate it" << endl; + } else { + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) + cout << "I hate "; + else + cout << "I love "; + if (i != n) cout << "that "; + } + cout << "it" << endl; + } + return 0; +} +int main() { + string n; + int d; + cin >> n; + for (int i = n.size() - 1; i >= 0; i--) { + d = n[i] - '0'; + if (d >= 5) { + cout << "-O|"; + d -= 5; + } else + cout << "O-|"; + for (int i = 0; i < d; i++) { cout << 'O'; } + cout << '-'; + for (int i = 0; i < 4 - d; i++) { cout << 'O'; } + cout << endl; + } + return 0; +} +const long long int INF = (long long int)(8e18); +const long long int MOD = 998244353; +int main() { + string a, b; + cin >> a >> b; + if (a.length() != b.length()) + cout << max(a.length(), b.length()) << '\n'; + else if (a != b) + cout << a.length() << '\n'; + else + cout << -1 << '\n'; + return 0; +} +int main() { + int a[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if (a[i][j] == 1) { cout << abs(2 - i) + abs(2 - j) << endl; } + } + } +} +int a[100505]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + while (a[i] % 2 == 0) a[i] /= 2; + while (a[i] % 3 == 0) a[i] /= 3; + } + int flag = 0; + sort(a + 1, a + 1 + n); + for (int i = 2; i <= n; i++) { + if (a[i] != a[i - 1]) flag = 1; + } + if (flag == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +int main() { + int n, sum1 = 0, sum2 = 0, t; + string s; + cin >> n >> s; + t = n / 2; + for (int i = 0; i < n; i++) { + if (s[i] != '4' & s[i] != '7') { + cout << "NO" << endl; + return 0; + } + } + t = n / 2; + for (int j = 0; j < t; j++) { sum1 = s[j] + sum1; } + for (int j = t; j < n; j++) { sum2 = s[j] + sum2; } + if (sum1 == sum2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char a[15], b[15], c[15], d[15]; + cin >> a >> b; + cout << a << " " << b << endl; + int n, k; + cin >> n; + while (n--) { + cin >> c >> d; + k = strcmp(a, c); + if (k) { + strcpy(b, d); + } else { + strcpy(a, d); + } + cout << a << " " << b << endl; + } +} +int main() { + char arr[105]; + while (cin >> arr) { + int len = strlen(arr); + char c = 'a'; + int x = 0; + for (int i = 0; arr[i]; i++) { + int t = abs(arr[i] - c); + x += min(t, 26 - t); + c = arr[i]; + } + cout << x << endl; + } + return 0; +} +int main() { + int w, h, i, r = 0; + cin >> w >> h >> i; + while (i >= 1) { + r = r + (w + h - 2) * 2; + w = (w - 4); + h = (h - 4); + i--; + } + cout << r << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum_a = 0, sum_b = 0, input; + for (int i = 0; i < n; ++i) { + cin >> input; + if (input < 0) + sum_b += input; + else + sum_a += input; + } + cout << sum_a - sum_b << endl; + return 0; +} +const int inf = (int)1e9; +int main() { + int n; + cin >> n; + if (n == 1) { + cout << "1 1"; + cout << '\n'; + return 0; + } + int a = 0, b = 0; + int dif = inf; + for (int i = 1; i < n / 2 + 1; ++i) { + if (n % i == 0) { + if (abs(n / i - i) < dif && n / i >= i) { + a = i; + b = n / i; + dif = abs(n / i - i); + } + } + } + cout << min(a, b) << " " << max(a, b); + cout << '\n'; + return 0; +} +int mod = 1e6 + 3; +int main() { + int n; + cin >> n; + if (n == 0) + cout << "1\n"; + else { + int ans = 1; + for (int i = 1; i < n; ++i) { ans = (ans * 3) % mod; } + cout << ans << "\n"; + } + return 0; +} +int T, N; +string str; +int main() { + cin >> T; + while (T--) { + cin >> N; + cin >> str; + bool print = true; + for (int l = 0, r = N - 1; l < r; l++, r--) { + if (str[l] == str[r]) continue; + set pos; + int act = str[l] - 'a'; + if (str[l] == 'a') + pos.insert(act + 1); + else if (str[l] == 'z') + pos.insert(act - 1); + else { + pos.insert(act + 1); + pos.insert(act - 1); + } + act = str[r] - 'a'; + int found = 0; + if (str[r] == 'a') { + if (pos.find(act + 1) != pos.end()) found = true; + } else if (str[r] == 'z') { + if (pos.find(act - 1) != pos.end()) found = true; + } else { + if (pos.find(act + 1) != pos.end()) found = true; + if (pos.find(act - 1) != pos.end()) found = true; + } + if (!found) { + cout << "NO\n"; + print = false; + break; + } + } + if (print) cout << "YES\n"; + } + return 0; +} +void print(int n) { + if (n < 5) + cout << "O-|"; + else + cout << "-O|"; + if (n % 5 == 0) + cout << "-OOOO" << endl; + else if (n % 5 == 1) + cout << "O-OOO" << endl; + else if (n % 5 == 2) + cout << "OO-OO" << endl; + else if (n % 5 == 3) + cout << "OOO-O" << endl; + else if (n % 5 == 4) + cout << "OOOO-" << endl; +} +int main() { + vector v; + int n; + cin >> n; + if (n == 0) print(n); + while (n) { + v.push_back(n % 10); + n /= 10; + } + for (int i = 0; i < v.size(); i++) { print(v[i]); } + return 0; +} +int main() { + int count; + cin >> count; + string s; + cin >> s; + int n = s.length(); + int a[26] = {0}; + for (int i = 0; i < n; i++) { a[s[i] - 'a']++; } + for (int i = 0; i < 26; i++) { + if (a[i] % count != 0) { + cout << "-1" << endl; + return 0; + } + } + string ans = ""; + for (int i = 0; i < 26; i++) { + if (a[i]) { + for (int j = 0; j < a[i] / count; j++) { + char temp = i + 'a'; + ans = ans + temp; + } + } + } + for (int i = 0; i < count; i++) { cout << ans; } + cout << endl; +} +int main() { + int a[5][5], l, r; + for (int i = 0; i < 5; i++) + for (int j = 0; j < 5; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) { + l = i; + r = j; + } + } + cout << (abs(l - 2) + abs(r - 2)) << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int mn = 1000000000; + for (int i = 1; i < n - 1; i++) { + int mn1 = 0; + for (int j = 0; j < n - 1; j++) { + if (j == i) + continue; + else if (j + 1 == i) + mn1 = max(mn1, a[j + 2] - a[j]); + else + mn1 = max(mn1, a[j + 1] - a[j]); + } + mn = min(mn, mn1); + } + cout << mn << endl; +} +int main() { + long n, m, z; + while (cin >> n >> m >> z) { + int t = 0; + for (int i = n; i <= z; i++) { + if (i % n == 0 && i % m == 0) { t++; } + } + cout << t << endl; + } +} +int main() { + long long a, b; + cin >> a >> b; + for (int i = 0; i < a; i++) { + for (int j = 0; j < b; j++) { + if (i % 2 == 0) + cout << '#'; + else if (i % 4 == 1 && j == b - 1) + cout << '#'; + else if (i % 4 == 3 && j == 0) + cout << '#'; + else + cout << '.'; + } + cout << endl; + } + return 0; +} +int main() { + int n, input[10000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> input[i + 1]; } + bool ng = false; + for (int i = 1; i < n + 1; i++) { + if (i == input[input[input[i]]]) { + cout << "YES" << endl; + ng = true; + break; + } + } + if (ng == false) { cout << "NO" << endl; } + return 0; +} +double a, b, c, d; +double t1, t2; +int main() { + cin >> a >> b >> c >> d; + t1 = max(3 * a / 10, a - a / 250 * c); + t2 = max(3 * b / 10, b - b / 250 * d); + if (t1 > t2) { + cout << "Misha" + << "\n"; + } else if (t1 < t2) { + cout << "Vasya" + << "\n"; + } else { + cout << "Tie" + << "\n"; + } + return 0; +} +int maxima(int x1, int x2, int x3) { + if (x1 > x2 && x1 > x3) + return x1; + else if (x2 > x1 && x2 > x3) + return x2; + return x3; +} +int minima(int x1, int x2, int x3) { + if (x1 < x2 && x1 < x3) + return x1; + else if (x2 < x1 && x2 < x3) + return x2; + return x3; +} +int main() { + int x1, x2, x3; + cin >> x1 >> x2 >> x3; + int maximum = maxima(x1, x2, x3); + int minimum = minima(x1, x2, x3); + int middlePoint = maximum - minimum; + cout << middlePoint << endl; + return 0; +} +const int maxn = 15; +const int mod = 1000000007; +const double eps = 1e10 - 7; +char mat[8][8]; +int main() { + for (int i = 0; i < 8; i++) cin >> mat[i]; + int Mina = 999999, Minb = 999999; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (mat[j][i] == 'B') break; + if (mat[j][i] == 'W') { + Mina = min(Mina, j); + break; + } + } + } + for (int i = 0; i < 8; i++) { + for (int j = 7; j >= 0; j--) { + if (mat[j][i] == 'W') break; + if (mat[j][i] == 'B') { + Minb = min(Minb, 8 - j); + break; + } + } + } + if (Mina < Minb) + puts("A"); + else + puts("B"); + return 0; +} +int main() { + int a, First, n, Max, Min, Amaze = 0; + cin >> n; + cin >> First; + Max = Min = First; + while (n != 1) { + cin >> a; + if (a > Max) { + Amaze++; + Max = a; + } else if (a < Min) { + Amaze++; + Min = a; + } + n--; + } + cout << Amaze << endl; + return 0; +} +bool esVocal(char c) { + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { return true; } + return false; +} +int main() { + string s; + cin >> s; + long long n = s.size(); + bool ok = true; + for (long long i = 0; i < n - 1; i++) { + if (!esVocal(s[i]) && s[i] != 'n') { + if (!esVocal(s[i + 1])) { ok = false; } + } + } + if (!esVocal(s[n - 1]) && s[n - 1] != 'n') { ok = false; } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +bool isDistinct(int n) { + int a, m; + while (n > 10) { + a = n % 10; + n /= 10; + m = n; + while (m != 0) { + if (a == m % 10) { return false; } + m /= 10; + } + } + return true; +} +int nextBYear(int m) { + int c = m + 1; + while (isDistinct(c) == false) { c++; } + return c; +} +int main() { + int a; + cin >> a; + cout << nextBYear(a) << endl; + return 0; +} +int main() { + int n, a, coun; + cin >> n >> a; + if (3 * n <= a) + coun = 0; + else + coun = 3 * n - a; + cout << coun << endl; + return 0; +} +int main() { + int a, cnt = 0; + cin >> a; + while (a != 0) { + if (a % 2 == 1) { + a--; + cnt++; + } else { + a = a >> 1; + } + } + cout << cnt << endl; +} +int main() { + long long n, count = 0; + cin >> n; + const int max_i = 2e5; + int counter = 0; + tuple data[max_i + 9]; + for (int i = 0; i < n; i++) { + long long k, a0, x, y, m, t = 0, a = 0; + cin >> k >> a0 >> x >> y >> m; + for (int j = 0; j < k; j++) { + if (counter <= max_i) { data[counter++] = make_tuple(t, a0, i); } + a = (a0 * x + y) % m; + if (a < a0 && j != k - 1) { t++; } + a0 = a; + } + count = max(count, t); + } + cout << count << endl; + if (counter <= max_i) { + sort(data, data + counter); + for (int i = 0; i < counter; i++) { cout << get<1>(data[i]) << " " << get<2>(data[i]) + 1 << endl; } + } +} +bool ok(int a, int b, int c, int d) { + map M; + M[a]++; + M[b]++; + M[c]++; + M[d]++; + if (M['f'] == 1 and M['a'] == 1 and M['c'] == 1 and M['e'] == 1) { return true; } + return false; +} +int main() { + int n, m; + cin >> n >> m; + int vec[n][m]; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < m; j++) { vec[i][j] = s[j]; } + } + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + if (ok(vec[i][j], vec[i][j + 1], vec[i + 1][j], vec[i + 1][j + 1])) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int A[104]; + for (int i = 1; i <= n; i++) cin >> A[i]; + int mx = 0; + for (int i = 1; i <= n; i++) { + int cc = 0; + for (int j = 1; j <= n; j++) { + if ((i - j) % k != 0) cc += A[j]; + } + mx = max(mx, abs(cc)); + } + cout << mx << endl; + return 0; +} +int res, i, n, l, r, j; +char str[5005]; +int main() { + cin >> str; + res = 0; + n = strlen(str); + for (i = 0; i < n; i++) { + l = 0, r = 0; + for (j = i; j < n; j++) { + if (str[j] == '(') + l++; + else if (str[j] == ')') + l--; + else { + l--; + r++; + } + if (l == 0) res++; + if (l < 0) { + if (r == 0) + break; + else if (r > 0) { + l += 2; + r--; + } + } + } + } + cout << res << endl; + return 0; +} +int main() { + int a; + string x; + string pple[100]; + string arr[100]; + cin >> a; + for (int i = 0; i < a; i++) { cin >> pple[i] >> arr[i]; } + for (int i = 0; i < a; i++) { + if (arr[i] == "rat") { cout << pple[i] << endl; } + } + for (int i = 0; i < a; i++) { + if (arr[i] == "woman" || arr[i] == "child") { cout << pple[i] << endl; } + } + for (int i = 0; i < a; i++) { + if (arr[i] == "man") { cout << pple[i] << endl; } + } + for (int i = 0; i < a; i++) { + if (arr[i] == "captain") { cout << pple[i] << endl; } + } + return 0; +} +int main() { + int i, j, k; + long long a, b, m, t, g = 0; + cin >> a >> b >> m; + if (a >= m || b >= m) { + cout << "0\n"; + return 0; + } + if (a < b) { + t = a; + a = b; + b = t; + } + if (a > 0 && b < 0) { + g = -b / a; + b = g * a + b; + } + long long s = a + b; + long long s1 = s; + long long num = 1; + while (s < m) { + long long k = max(a, b); + a = k; + b = s; + s = a + b; + num++; + if (s <= s1) { + cout << "-1\n"; + return 0; + } + } + cout << g + num << endl; + return 0; +} +int main() { + int n, arr[109], maxx = 0, i, res = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> arr[i]; + if (maxx < arr[i]) maxx = arr[i]; + } + for (i = 0; i < n; i++) { res = res + (maxx - arr[i]); } + cout << res << endl; +} +int a[100], b[100]; +int main() { + int m, n, mx = 0, cnt = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; i++) { + cin >> b[i]; + for (int j = 1; j <= n; j++) { + if (b[i] % a[j] == 0) { + if (mx < b[i] / a[j]) { + mx = b[i] / a[j]; + cnt = 1; + } else if (mx == b[i] / a[j]) + cnt++; + } + } + } + cout << cnt << endl; +} +int main() { + int num; + while (cin >> num) { + int cur = 0; + string out; + for (int i = 0; i < num; i++) { + char temp; + cin >> temp; + if (temp == '1') { cur++; } + if (temp == '0') { + out.push_back(cur + '0'); + cur = 0; + } + } + out.push_back(cur + '0'); + cout << out << '\n'; + } + return 0; +} +int main() { + string a; + cin >> a; + int ans = 0; + for (int i = 0; i < a.length(); i++) { + int l = 0, r = 0; + for (int j = i; j < a.length(); j++) { + if (a[j] == '(') + l++; + else if (a[j] == ')') + l--; + else { + l--; + r++; + } + if (l == 0) ans++; + if (l < 0) { + if (r == 0) + break; + else { + if (r > 0) { + l += 2; + r--; + } + } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + pair A[n + 1]; + for (int i = 1; i <= n; i++) { + cin >> A[i].first >> A[i].second; + A[i].first *= -1; + } + sort(A + 1, A + n + 1); + int ans = 0; + for (int i = 1; i <= n; i++) + if (A[i] == A[k]) ans++; + cout << ans << '\n'; + return 0; +} +int main() { + int gcd = 0, n[1000], i, t; + cin >> t; + for (i = 0; i < t; i++) { + cin >> n[i]; + gcd = __gcd(gcd, n[i]); + } + cout << t * gcd << endl; + return 0; +} +int main() { + long long n, a, x, choc = 0; + priority_queue voters; + cin >> n >> a; + for (int i = 0; i < n - 1; i++) { + cin >> x; + voters.push(x); + } + while (a <= voters.top()) { + x = voters.top(); + voters.pop(); + a++; + choc++; + x--; + voters.push(x); + } + cout << choc << endl; + return 0; +} +int main() { + int n, x, y, r; + r = 0; + cin >> n; + while (n--) { + cin >> x >> y; + if (y - x >= 2) r++; + } + cout << r << endl; + return 0; +} +int n, a, b; +int main() { + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +string s; +inline int check(string s) { + string ss = s; + reverse(s.begin(), s.end()); + return s == ss; +} +int main() { + cin >> s; + if (check(s)) { + if (s.size() % 2 == 0) + puts("NO"); + else + puts("YES"); + return 0; + } + int len = s.size(); + if (len % 2 == 0) + len = len / 2 - 1; + else + len = len / 2; + for (int i = 0; i <= len; ++i) { + if (s[i] != s[s.size() - 1 - i]) { + s[i] = s[s.size() - 1 - i]; + if (check(s)) { + puts("YES"); + return 0; + } else { + puts("NO"); + return 0; + } + } + } + return 0; +} +int main() { + int a[3], sum = 0; + for (int i = 0; i < 3; i++) { cin >> a[i]; } + for (int i = 0; i < 3; i++) { + for (int j = i + 1; j < 3; j++) { + if (a[i] > a[j]) { + int c = a[i]; + a[i] = a[j]; + a[j] = c; + } + } + } + for (int i = 0; i < 3 - 1; i++) { + int e = a[i + 1] - a[i]; + sum = sum + e; + } + cout << sum << endl; + return 0; +} +int main() { + int n, b = 0, c = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i += 1) { + cin >> a[i]; + if (a[i] < 0) + c += a[i]; + else + b += a[i]; + } + cout << b - c << '\n'; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; +} +const long long mod = 1000000007, X = 131071; +map a; +int main() { + long long q, v, u, w, k, s = 0; + cin >> q; + while (q > 0) { + q--; + cin >> k; + if (k == 1) { + cin >> v >> u >> w; + while (u != v) { + if (u > v) { + a[u] += w; + u = u / 2; + } else { + a[v] += w; + v = v / 2; + } + } + } else { + s = 0; + cin >> u >> v; + while (u != v) { + if (u > v) { + s += a[u]; + u = u / 2; + } else { + s += a[v]; + v = v / 2; + } + } + cout << s << endl; + } + } +} +bool color[120][120]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + char in; + cin >> in; + color[i][j] = in == 'B'; + } + } + int side = -1; + int first_row = -1, last_row = -1; + for (int i = 0; i < n; i++) { + int row_start = -1, row_end = -1; + for (int j = 0; j < m; j++) { + if (color[i][j] == true and row_start == -1) { row_start = j; } + if (color[i][j] == false and row_start != -1) { + row_end = j - 1; + break; + } + } + if (row_start != -1 and row_end == -1) { row_end = m - 1; } + if (row_start == -1 and row_end == -1) continue; + side = row_end - row_start + 1; + if (first_row == -1) first_row = i; + cout << i + side / 2 + 1 << " " << row_start + side / 2 + 1 << endl; + break; + } +} +int main() { + long long int i, j, k, m, n, t, a, b; + cin >> n >> m >> a >> b; + if (n % m == 0) { + cout << 0 << endl; + return 0; + } + k = n / m; + i = n - k * m; + j = (k + 1) * m - n; + cout << min(a * j, b * i) << endl; + return 0; +} +int main() { + int a, count = 0; + cin >> a; + while (a / 100 != 0) { + count++; + a -= 100; + } + while (a / 20 != 0) { + count++; + a -= 20; + } + while (a / 10 != 0) { + count++; + a -= 10; + } + while (a / 5 != 0) { + count++; + a -= 5; + } + count += a; + cout << count << endl; + return 0; +} +const long long mod = 1e9 + 7; +const int N = 1e5 + 5; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long pwr(long long x, long long y); +bool isprime(long long x); +int main() { + int n, x, y; + cin >> n >> x >> y; + int ans = ((n * y) / 100 + bool((n * y) % 100)); + if (x > ans) { + cout << 0 << endl; + return 0; + } + cout << (ans - x) << endl; + return 0; +} +long long pwr(long long x, long long y) { + long long ans = 1; + x = x % mod; + while (y > 0) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y = y / 2; + } + return ans; +} +bool isprime(long long x) { + if (x < 2) return false; + if (x < 4) return true; + if (x % 2 == 0 || x % 3 == 0) return false; + for (long long i = 5; i * i <= x; i += 6) { + if (x % i == 0 || x % (i + 2) == 0) return false; + } + return true; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << a * b + b * c + c * a - a - b - c + 1 << endl; + return 0; +} +int main() { + int n, i, c = 0, d = 0; + string s; + cin >> n; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == '1') + c++; + else + d++; + } + if (c < d) + cout << n - 2 * c << endl; + else + cout << n - 2 * d << endl; + return 0; +} +const int maxn = 1e6 + 7; +const int mod = 998244353; +int read() { + int c = getchar(), Nig = 1, x = 0; + while (!isdigit(c)) c = getchar(); + if (c == '-') Nig = -1, c = getchar(); + while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar(); + return Nig * x; +} +int a[maxn]; +int main() { + int n = read(); + for (int i = 1; i <= n; i++) { a[i] = read(); } + int minl = *min_element(a + 1, a + 1 + n); + int pos = -1, ans = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + if (a[i] == minl) { + if (~pos) + ans = min(ans, i - pos), pos = i; + else + pos = i; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, x, x1, out = 0; + cin >> n >> k >> x; + vector l; + for (int i = 0; i < n; i++) { + cin >> x1; + l.push_back(x1); + } + for (int i = n - 1; i > -1; i--) { + if (k > 0) { + k -= 1; + out += min(l[i], x); + } else { + out += l[i]; + } + } + cout << out << endl; + return 0; +} +int main() { + int n, h, a, b, k, i, jarak; + jarak = 0; + pair s, f; + cin >> n >> h >> a >> b >> k; + for (i = 0; i < k; i++) { + cin >> s.first >> s.second >> f.first >> f.second; + if (s.first == f.first) { + jarak = abs(s.second - f.second); + } else { + jarak = abs(s.first - f.first); + if (s.second > b) { + jarak = abs(s.second - b) + jarak; + s.second = b; + } else { + if (s.second < a) { + jarak = jarak + abs(a - s.second); + s.second = a; + } + } + if (s.second != f.second) { jarak = jarak + abs(s.second - f.second); } + } + cout << jarak << endl; + } + return 0; +} +int mp[2010 * 2010]; +int a[2010], b[2010]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + mp[a[i]] = 1; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + mp[b[i]] = 1; + } + int cnt = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (mp[a[i] ^ b[j]]) cnt++; + if (cnt % 2 != 0) + cout << "Koyomi" << endl; + else + cout << "Karen" << endl; + return 0; +} +const int MAX = 1e5 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +const double pi = acos(-1); +const double eps = 1e-9; +int n; +string a, b, x, y; +int main() { + cout << fixed << setprecision(12); + cin >> a >> b >> n; + cout << a << ' ' << b << '\n'; + while (n--) { + cin >> x >> y; + if (x == a) + a = y; + else + b = y; + cout << a << ' ' << b << '\n'; + } + return 0; +} +string s1, s2, a, b; +int n; +int main() { + cin >> s1 >> s2 >> n; + while (n--) { + cout << s1 << " " << s2 << endl; + cin >> a >> b; + if (s1 == a) + s1 = b; + else + s2 = b; + } + cout << s1 << " " << s2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long arr[n + 2]; + for (int i = 0; i < n; i++) cin >> arr[i]; + long long size = 1, maxSize = INT_MIN, prev = arr[0]; + for (int i = 1; i < n; i++) { + if (arr[i] >= prev) { + ++size; + prev = arr[i]; + } else { + maxSize = max(maxSize, size); + prev = arr[i]; + size = 1; + } + } + maxSize = max(maxSize, size); + cout << maxSize << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int flag = 0; + int isPrime = 0; + for (int j = n + 1; j <= m; j++) { + flag = 0; + for (int i = 2; i <= (j - 1); i++) { + if (j % i == 0) { + flag = 1; + break; + } + flag = 2; + if (j < m) flag = 3; + } + if (flag == 3) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "NO"; + else + cout << "YES"; + putchar('\n'); + return 0; +} +int sum1 = 0, sum2 = 0; +int a[110]; +int main() { + memset(a, 0, sizeof(a)); + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] >= 0) + sum1 += a[i]; + else + sum2 += a[i]; + } + cout << sum1 - sum2 << endl; + return 0; +} +int main() { + int n, a, b, c, t[4]; + cin >> n >> a >> b >> c; + t[1] = a > b ? 3 : 2; + t[3] = b > c ? 2 : 1; + t[2] = a > c ? 3 : 1; + int time = 1, sum = 0, z = 1; + for (; time < n; time++) { + if (z == 1) { + if (t[z] == 2) { + sum += a; + z = 2; + } else if (t[z] == 3) { + sum += b; + z = 3; + } + } else if (z == 2) { + if (t[z] == 1) { + { + sum += a; + z = 1; + } + } else { + sum += c; + z = 3; + } + } else { + if (t[z] == 1) { + sum += b; + z = 1; + } else { + sum += c; + z = 2; + } + } + } + cout << sum << endl; + return 0; +} +int cnt = -1; +int n, k, c; +int a[370]; +int main() { + cin >> n >> k >> c; + for (int i = 1; i <= c; i++) cin >> a[i]; + a[c + 1] = n + 1; + for (int i = 0; i <= c; i++) { + cnt++; + if (a[i + 1] - a[i] > k) cnt += (a[i + 1] - a[i] - 1) / k; + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + int n, m; + while (cin >> n >> m) { + cin >> s; + while (m--) { + int x, y; + char a, b; + cin >> x >> y >> a >> b; + x--; + y--; + for (int i = x; i <= y; ++i) { + if (s[i] == a) s[i] = b; + } + } + cout << s << endl; + } +} +int main() { + long long a, b = 0; + cin >> a; + int i; + if (a % 2 != 0) { + i = -1; + } else { + i = 0; + } + b = a / 2 * powl(-1, a % 2) + i; + cout << b << endl; + return 0; +} +long int n, k; +int main() { + cin >> n >> k; + for (k; k > 0; k--) + if (n % 10 != 0) + n--; + else + n /= 10; + cout << n << endl; + return 0; +} +int m, d; +int main() { + cin >> m >> d; + int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int x = month[m] / 7; + int y = month[m] % 7; + if (y != 0) { + if (y - (7 - d + 1) <= 0) + cout << x + 1 << endl; + else + cout << x + 2 << endl; + } else { + if (d == 1) + cout << x << endl; + else + cout << x + 1 << endl; + } + return 0; +} +int main() { + string s[100], s2; + int n, p[100]; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> s[i] >> s2; + if (s2 == "rat") + p[i] = 0; + else if (s2 == "woman" || s2 == "child") + p[i] = 1; + else if (s2 == "man") + p[i] = 2; + else + p[i] = 3; + } + for (int j = 0; j < 4; ++j) + for (int i = 0; i < n; ++i) + if (p[i] == j) cout << s[i] << endl; + return 0; +} +string T; +long long N, K, M, A, B, C[2005], D, sum; +int main() { + cin >> N >> A >> B; + for (int i = 1; i <= N; i++) { cin >> C[i]; } + sort(C + 1, C + N + 1); + cout << C[B + 1] - C[B] << '\n'; +} +bool cmp(const long long &a, long long &b) { + return a < b; +} +int main() { + int n, k; + while (cin >> n >> k) { + int shengyu = 240 - k; + int s = 0, nowp = 5; + int count = 0; + int i = 1; + while (i <= n) { + if (s + i * nowp == shengyu) { + count = i; + break; + } + if (s + nowp * i < shengyu) { + s += nowp * i; + count = i; + i++; + } + if (s + nowp * i > shengyu) { break; } + } + cout << count << endl; + } +} +int main() { + int m; + cin >> m; + string n, s = ""; + cin >> n; + int c = 0; + int ok = 0; + for (int i = 0; i < m; i++) { + if (n[i] == '1') { + c++; + ok = 0; + } else if (n[i] == '0' && ok == 0) { + ok = 1; + s += c + '0'; + c = 0; + } else if (n[i] == '0' && ok == 1) { + s += '0'; + } + } + if (c != 0) { s += c + '0'; } + if (n[n.length() - 1] == '0') { s += '0'; } + cout << s << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string str; + int cnt = 0; + while (n--) { + cin >> str; + int len = str.length(); + bool arr[10]; + memset(arr, 0, sizeof(arr)); + bool valid = 1; + for (int i = 0; i < len; ++i) { arr[str[i] - '0'] = 1; } + for (int i = 0; i <= k; ++i) { + if (arr[i] == 0) { + valid = 0; + break; + } + } + if (valid) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + for (int i = h; i > 0; i--) { + w += i; + if (i == d1) + w -= u1; + else if (i == d2) + w -= u2; + if (w < 0) w = 0; + } + cout << w << endl; + return 0; +} +long long int i, j, k, sum = 0, ans = 0, n, m; +void fastio() {} +void solve() { + long long int L, v, l, r; + cin >> L >> v >> l >> r; + n = L / v; + m = r / v - (l - 1) / v; + cout << n - m << "\n"; +} +int main() { + fastio(); + int t = 1; + cin >> t; + while (t--) solve(); + return 0; +} +int a, b, c, d; +int judge(int a, int b, int c) { + if (a + b > c and a + c > b and b + c > a) { + if (abs(a - b) < c and abs(a - c) < b and abs(b - c) < a) { return 1; } + } else if (a + b == c or b + c == a or a + c == b) { + return 0; + } else { + return -1; + } +} +int main() { + cin >> a >> b >> c >> d; + int j = judge(a, b, c); + int k = judge(a, b, d); + int l = judge(a, c, d); + int m = judge(b, c, d); + if (j == 1 or k == 1 or l == 1 or m == 1) { + cout << "TRIANGLE" << endl; + } else if (j == 0 or k == 0 or l == 0 or m == 0) { + cout << "SEGMENT" << endl; + } else { + cout << "IMPOSSIBLE" << endl; + } +} +int main() { + int t; + int x, y; + int c = 0; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> x >> y; + if (y - x >= 2) c++; + } + cout << c << endl; +} +int main() { + string str; + cin >> str; + long long int k; + cin >> k; + long long int freq[27] = {0}; + if (k > str.size()) + cout << "impossible"; + else { + for (long long int i = 0; i < str.size(); i++) { freq[str[i] - 'a' + 1]++; } + long long int count = 0; + for (long long int i = 1; i <= 26; i++) { + if (freq[i] != 0) count++; + } + if (count >= k) + cout << "0"; + else { + cout << (k - count); + } + } + cout << endl; + return 0; +} +int main() { + int n, a, b, step = 0, step1 = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) + ++step; + else if (a < b) + ++step1; + } + if (step > step1) + cout << "Mishka" << endl; + else if (step < step1) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; +} +int main() { + int TESTS = 1; + while (TESTS--) { + int count = 0, n, m, i, j; + cin >> n >> m; + for (i = 0; i <= sqrt(n); i++) { + for (j = 0; j <= sqrt(m); j++) { + if (i * i + j == n && i + j * j == m) count++; + } + } + cout << count << '\n'; + } + return 0; +} +int main() { + int n; + cin >> n; + int sum_a = 0, sum_b = 0, input; + for (int i = 0; i < n; ++i) { + cin >> input; + if (input < 0) + sum_b += input; + else + sum_a += input; + } + cout << sum_a - sum_b << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long ans = 1; + for (int i = 2; i <= n; i++) { ans = (ans * 3) % 1000003; } + if (n == 1) + cout << "1" << endl; + else + cout << ans << endl; + return 0; +} +int a[1010], c[1010], n, m, j; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + for (int i = 0; i < n; i++) + if (c[i] <= a[j]) j++; + cout << j << endl; + return 0; +} +int main() { + int n, i = 1, m, f = 0; + while (cin >> n) { + cin >> m; + int *p = new int[n]; + for (int i = 1; i < n; i++) cin >> p[i]; + while (i < m) { + i += p[i]; + if (i == m) { + f = 1; + break; + } + } + if (f) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +const int maxn = 2000010; +int a[maxn] = {0}; +int long long sum[maxn] = {0}; +int main() { + int n; + sum[0] = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum[i + 1] = sum[i] + a[i]; + } + long long sum1 = (sum[n] + 1) / 2; + int flag = 0; + for (int j = 1; j <= n; j++) { + if (sum[j] >= sum1) { + flag = j; + break; + } + } + cout << flag << endl; + return 0; +} +int main() { + long long int n, m, a, b; + cin >> n >> m >> a >> b; + long long int sum, min, ans; + if (n % m == 0) + min = 0; + else { + { + sum = a * (((n / m + 1) * m) - n); + min = sum; + ans = b * (n - ((n / m) * m)); + if (ans < min) min = ans; + } + } + cout << min << endl; + return 0; +} +const int MOD = 1e9 + 7; +string s; +int power(int n, int k) { + int e = 1; + for (; k; k >>= 1, n = 1ll * n * n % MOD) + if (k & 1) e = 1ll * e * n % MOD; + return e; +} +int main() { + cin >> s; + reverse(s.begin(), s.end()); + long long answer = 0; + for (int i = 0; i < (int)s.size(); ++i) { answer = (2 * answer + ((s[i] == '1') ? power(2, 2 * i) : 0)) % MOD; } + cout << answer << "\n"; + return 0; +} +long long n, m, i, a[1007][1007], k, v1, v2, f = 0; +int main() { + cin >> n >> m >> k; + for (i = 1; i <= k; i++) { + cin >> v1 >> v2; + a[v1][v2] = 1; + if ((a[v1][v2] + a[v1 + 1][v2] + a[v1 + 1][v2 + 1] + a[v1][v2 + 1]) == 4) { + cout << i << endl; + f = 1; + break; + } + if ((a[v1][v2] + a[v1 - 1][v2] + a[v1][v2 + 1] + a[v1 - 1][v2 + 1]) == 4) { + cout << i << endl; + f = 1; + break; + } + if ((a[v1][v2] + a[v1][v2 - 1] + a[v1 + 1][v2] + a[v1 + 1][v2 - 1]) == 4) { + cout << i << endl; + f = 1; + break; + } + if ((a[v1][v2] + a[v1 - 1][v2] + a[v1][v2 - 1] + a[v1 - 1][v2 - 1]) == 4) { + cout << i << endl; + f = 1; + break; + } + } + if (f == 0) cout << 0 << endl; + return 0; +} +int main() { + int cnt = 0; + int maxc = 0; + int c; + while ((c = getchar()) != EOF) { + if (c > maxc) { + cnt = 1; + maxc = c; + } else if (c == maxc) + ++cnt; + } + for (int i = 0; i < cnt; ++i) putchar(maxc); + putchar('\n'); +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << a * b + b * c + c * a - a - b - c + 1 << endl; + return 0; +} +long long a[200050]; +long long b[200050]; +int len = 0; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + long long minn = 1000000009; + for (int i = 0; i < n; i++) { minn = min(minn, a[i]); } + for (int i = 0; i < n; i++) { + if (a[i] == minn) { + b[len] = i; + len++; + } + } + long long minnn = 200000050; + for (int i = 1; i < len; i++) { minnn = min(minnn, b[i] - b[i - 1]); } + cout << minnn << endl; + return 0; +} +int main() { + int w, h, w1, h1, w2, h2; + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w < 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w < 0) w = 0; + } + } + cout << w << endl; +} +int main() { + string s; + int n, x = 1, y = 1; + cin >> n; + while (n--) { + cin >> s; + if (s == "ULDR") + x++, y++; + else if (s == "UR" || s == "DL") + x++; + else + y++; + } + cout << 1LL * x * y << endl; +} +int main() { + int n; + cin >> n; + int a = 0, b = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a |= x; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b |= x; + } + cout << 1LL * a + b << endl; + return 0; +} +int main() { + long long n, i, c = 0, cnt = 0, a[100009]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 1; i < n; i++) { + if (a[i] != 0 && (a[i] == a[i - 1])) { + c++; + if ((i + 1) < n && (a[i] == a[i + 1])) { + c = -1; + break; + } + } + } + cout << c << endl; + return 0; +} +int main() { + int n = 0, m = 0; + while (cin >> n >> m) { + int day = 0; + double a = 0.0; + a = n / (m - 1.0); + if (a - (int)a == 0) + day = n + a - 1; + else + day = n + a; + cout << day << endl; + } +} +int main() { + float n; + cin >> n; + float xx = sqrt(n); + int ans = xx; + for (int i = ans; i >= 1; i--) { + int yy = n / i; + float zz = n / i; + if (yy == zz) { + cout << i << " " << n / i << endl; + break; + } + } + return 0; +} +int n, k, c; +int a[400], f[400]; +int main() { + cin >> n >> k >> c; + for (int i = 1, x; i <= c; i++) { + cin >> x; + a[x] = 1; + } + for (int i = 1; i <= n; i++) f[i] = f[i - 1] + a[i]; + for (int i = 0; i <= n - k; i++) { + if (!(f[i + k] - f[i])) { + a[i + k] = 1; + for (int j = i + k; j <= n; j++) f[j]++; + } + } + cout << f[n] << endl; + return 0; +} +int main() { + string palabra; + cin >> palabra; + string vocale = "aeioun"; + string valido = "aeiou"; + int tam = palabra.size(); + bool es = true; + if (vocale.find(palabra[tam - 1]) == -1) { + es = false; + } else { + for (int i = 0; i < (long long)tam - 1; i++) { + if (vocale.find(palabra[i]) == -1) { + if (valido.find(palabra[i + 1]) == -1) { + es = false; + break; + } + } + } + } + if (es) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << n / 2 << endl; + else + cout << -(n + 1) / 2 << endl; + return 0; +} +int main() { + int n, i, j, a, b, c, d, e, f; + cin >> n; + for (i = 1;; i++) { + n++; + a = n / 1000; + b = n / 100; + b = b % 10; + c = n / 10; + c = c % 10; + d = n % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } + } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + int count = 0; + int flag = -1; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[i] == 1) { + count++; + flag = 0; + } else if (arr[i] == 0 && flag == 0) { + count++; + flag = 1; + } else if (arr[i] == 0 && flag == 1) { + count--; + flag = 2; + } else if (arr[i] == 0 && flag >= 2) { + flag++; + } + } + if (flag == 1) count--; + cout << count << endl; + return 0; +} +int n; +int i, j, k; +int a, b; +set v; +set h; +int solve() { + for (int i = (0); i < (n); ++i) { + cin >> a; + cin >> b; + if (!h.count(a)) h.insert(a); + if (!v.count(b)) v.insert(b); + } + return min(h.size(), v.size()); +} +void run() { + cin >> n; + cout << solve() << endl; +} +int main() { + run(); +} +int a[200005], b[200005]; +int main() { + int n, i = 0; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0, t; i < n; ++i) cin >> t, b[t] = i; + for (int i = 0; i < n; ++i) a[i] = b[a[i]]; + for (i = 1; i < n; ++i) + if (a[i] < a[i - 1]) break; + cout << n - i << endl; +} +int main() { + long long n; + cin >> n; + long long x = n; + long long banyak = 0; + if (x % 5 != 0) { + banyak = banyak + (x % 5); + x = x - (x % 5); + } + if (x >= 100) { + banyak = banyak + (x / 100); + x = x - (x / 100) * 100; + } + if (x >= 20) { + banyak = banyak + (x / 20); + x = x - (x / 20) * 20; + } + if (x >= 10) { + banyak = banyak + (x / 10); + x = x - (x / 10) * 10; + } + if (x >= 5) { + banyak = banyak + (x / 5); + x = x - (x / 5) * 5; + } + cout << banyak << endl; +} +int main() { + int n, count0 = 0, count1 = 0; + cin >> n; + char a; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == '0') + count0++; + else + count1++; + } + cout << abs(count0 - count1) << endl; + return 0; +} +const int MOD = 1e9 + 7; +int n, m, k; +int a[10][100], b[10][100], c[10][100]; +int solve(int u, int v) { + vector profits; + for (int i = 0; i < m; ++i) + for (int j = 0; j < c[u][i]; ++j) profits.push_back(max(0, b[v][i] - a[u][i])); + sort(profits.rbegin(), profits.rend()); + int ans = 0; + for (int i = 0; i < min(k, (int)profits.size()); ++i) ans += profits[i]; + return ans; +} +int main() { + cin >> n >> m >> k; + for (int i = 0; i < n; ++i) { + string name; + cin >> name; + for (int j = 0; j < m; ++j) cin >> a[i][j] >> b[i][j] >> c[i][j]; + } + int ans = 0; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) ans = max(ans, solve(i, j)); + cout << ans << '\n'; +} +void solve() { + int n, b, p; + cin >> n >> b >> p; + int br = 0; + int tr = n * p; + while (n > 1) { + int x = 1; + while (2 * x < n) { x *= 2; } + br += x * (2 * b + 1); + n -= x; + } + cout << br << " " << tr << endl; +} +int main() { + solve(); +} +vector sol; +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 1; i <= 150; i++) { + if (sum > n) { + cout << i - 2 << endl; + return 0; + } + sum += ((i * (i + 1)) / 2); + } +} +int main() { + string s; + int n, x = 1, y = 1; + cin >> n; + while (n--) { + cin >> s; + if (s == "ULDR") + x++, y++; + else if (s == "UR" || s == "DL") + x++; + else + y++; + } + cout << 1LL * x * y << endl; +} +int a[205]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= 2 * n; ++i) cin >> a[i]; + sort(a, a + 2 * n + 1); + for (int i = 1; i <= n; ++i) + for (int j = n + 1; j <= 2 * n; ++j) + if (a[i] >= a[j]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; +} +string f(long long a) { + string s; + while (a > 0) { + if (a % 2 == 0) { + s += '0'; + } else { + s += '1'; + } + a /= 10; + } + while (s.size() < 18) { s += '0'; } + reverse(s.begin(), s.end()); + return s; +} +int main() { + char c; + long long t, a; + string s; + map m; + cin >> t; + while (t--) { + cin >> c; + if (c == '+') { + cin >> a; + m[f(a)]++; + } else if (c == '-') { + cin >> a; + m[f(a)]--; + } else { + cin >> s; + while (s.size() < 18) { s = '0' + s; } + cout << m[s] << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int count = 0; + int p, q; + for (int i = 0; i < n; i++) { + cin >> p >> q; + if ((q - p) >= 2) count++; + } + cout << count << endl; + return 0; +} +int main() { + string str; + int n, y = 0; + cin >> n; + cin >> str; + for (int i = 0; i < n; i++) { + if (str[i] == '1') + y++; + else { + y++; + break; + } + } + cout << y << endl; + return 0; +} +int main() { + set v; + int n; + while (cin >> n) { + int arr[100005]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] != 0) v.insert(arr[i]); + } + cout << v.size() << endl; + v.clear(); + } + return 0; +} +int main() { + int n; + cin >> n; + if (n != 2) + cout << "1" << endl; + else + cout << "2" << endl; +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + int l = s1.length(); + for (int i = 0; i < l; i++) { + if (s1[i] != s2[i]) + cout << "1"; + else + cout << "0"; + } + cout << endl; +} +int main() { + int i, j, t, a, b, c = 0, n, m, k, sum = 0; + char temp; + string word; + cin >> n; + cin >> word; + temp = word[0]; + for (i = 0; i < n; i++) { + if (word[i] == '0' && word[i + 1] == '0' && i != 0) { + cout << 0; + i++; + } + while (word[i] == '1') { + c++; + i++; + temp = word[i]; + } + cout << c; + c = 0; + } + if (word[n - 1] == '0') cout << 0; + cout << endl; + return 0; +} +int main() { + int A, B, C, N; + cin >> A >> B >> C >> N; + if (((A + B - C) < N) && (A >= C) && (B >= C)) { + cout << (N - (A + B - C)) << endl; + } else { + cout << "-1" << endl; + } + return 0; +} +int main() { + long long int a, b, n, mini, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + ans++; + if (i == 0 || a < mini) { + mini = a; + ans = 0; + b = 0; + } else if (a == mini) { + if ((ans < b) || (b == 0)) { b = ans; } + ans = 0; + } + } + cout << b << endl; + return 0; +} +char x[35] = {"qwertyuiopasdfghjkl;zxcvbnm,./"}; +char s1[105]; +int main() { + char s; + cin >> s; + cin >> s1; + int len = strlen(s1); + if (s == 'R') { + for (int i = 0; i < len; i++) { + for (int l = 0; l < 30; l++) { + if (s1[i] == x[l]) { s1[i] = x[l - 1]; } + } + } + } + if (s == 'L') { + for (int i = 0; i < len; i++) { + for (int l = 0; l < 30; l++) { + if (s1[i] == x[l]) { + s1[i] = x[l + 1]; + break; + } + } + } + } + cout << s1 << endl; + return 0; +} +int main() { + int n; + long long c; + cin >> n >> c; + long long a; + cin >> a; + int cnt = 1; + for (int i = 1; i < n; i++) { + long long b; + cin >> b; + if (b - a <= c) + cnt++; + else + cnt = 1; + a = b; + } + cout << cnt << "\n"; +} +int main() { + int n, cnt = 0, a = 0, b = 0, c = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (cnt == 0) { + a += arr[i]; + cnt++; + } else if (cnt == 1) { + b += arr[i]; + cnt++; + } else if (cnt == 2) { + c += arr[i]; + cnt = 0; + } + } + if (max(max(a, b), c) == a) { + cout << "chest" << endl; + } else if (max(max(a, b), c) == b) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int main() { + int n; + int a = 0, p, q, res; + cin >> n; + int s[100][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> s[i][j]; } + } + for (int i = 0; i < n; i++) { + p = s[i][0]; + q = s[i][1]; + res = q - p; + if (res >= 2) { a++; } + } + cout << a << endl; + return 0; +} +string a; +long long b; +bool x, y; +int main() { + cin >> a; + if (a[0] == 'h' || a[0] == 'a') x = 1; + if (a[1] == '8' || a[1] == '1') y = 1; + if (x == 1 && y == 1) b++; + if (x == 1) b = b - 3; + if (y == 1) b = b - 3; + cout << b + 8 << endl; +} +const int MAXN = 200005; +const int INFTY = 1000000000; +int N, M; +int V[MAXN]; +pair H[MAXN]; +int main() { + cin >> N >> M; + for (int i = 0; i < N; i++) cin >> V[i]; + for (int i = 0, x1, x2, y; i < M; i++) { + cin >> x1 >> x2 >> y; + H[i] = make_pair(x2, x1); + } + sort(V, V + N); + V[N] = INFTY; + sort(H, H + M); + int ans = M, cur = N; + for (int i = N, j = M - 1; i >= 0; i--) { + while (j >= 0 && V[i] <= H[j].first) { + cur += H[j].second == 1; + j--; + } + ans = min(ans, cur); + cur--; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int ans = 0; + while (1) { + ans++; + n--; + if (ans % m == 0) { n++; } + if (n == 0) { break; } + } + cout << ans << endl; + } +} +int coupons[100005], arr[100005]; +int main() { + int C, N; + cin >> C; + for (int i = 0; i < C; i++) cin >> coupons[i]; + cin >> N; + int BestCoupon = *min_element(coupons, coupons + C); + for (int i = 0; i < N; i++) cin >> arr[i]; + sort(arr, arr + N); + reverse(arr, arr + N); + long long int result = 0; + int j = 0; + while (j < N) { + for (int i = j; i < j + BestCoupon and i < N; i++) result += arr[i]; + j += BestCoupon; + j = min(N, j + 2); + } + cout << result << endl; +} +int main() { + long long int n; + cin >> n; + long long int limit = sqrt(n); + int x, y; + for (int i = 1; i <= limit; i++) { + if (n % i == 0) { + x = i; + y = n / i; + } + } + cout << x << " " << y << endl; + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +void solve() { + int n, m; + cin >> n >> m; + int a[n]; + int b[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int j = 0; + int cnt = 0; + for (int i = 0; i < n; i++) { + if (j == m) break; + if (b[j] >= a[i]) { + cnt++; + j++; + } + } + cout << cnt << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, prices = 101, cost = 0, a, p; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> p; + if (p < prices) { prices = p; } + cost += a * prices; + } + cout << cost << endl; +} +int q; +map, long long> m; +long long lca(long long u, long long v) { + while (u != v) { + if (v < u) swap(u, v); + v /= 2; + } + return u; +} +int main() { + cin >> q; + for (int a = 0; a < q; a++) { + int t; + cin >> t; + if (t == 1) { + long long u, v, w; + cin >> u >> v >> w; + long long l = lca(u, v); + for (long long i = u; i / 2 >= l; i /= 2) m[make_pair(i, i / 2)] += w; + for (long long i = v; i / 2 >= l; i /= 2) m[make_pair(i, i / 2)] += w; + } else { + long long u, v; + cin >> u >> v; + long long l = lca(u, v); + long long ans = 0; + for (long long i = u; i / 2 >= l; i /= 2) ans += m[make_pair(i, i / 2)]; + for (long long i = v; i / 2 >= l; i /= 2) ans += m[make_pair(i, i / 2)]; + cout << ans << "\n"; + } + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int n, m; + cin >> n >> m; + int mx, mn; + for (int i = 0; i < a; i++) { + int x; + cin >> x; + if (i + 1 == n) { mx = x; } + } + for (int i = 0; i < b; i++) { + int x; + cin >> x; + if (i == b - m) { mn = x; } + } + if (mx < mn) { + cout << "YES" << endl; + } else + cout << "NO" << endl; +} +int main() { + int n, m, x1, x2, y1, y2; + cin >> n >> m; + char a[n + 2][m + 2] = {0}; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> a[i][j]; + bool ok = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) + if (a[i][j] == 'B' and a[i][j + 1] != 'B') { + x1 = i; + y1 = j; + ok = 1; + break; + } + if (ok) break; + } + ok = 0; + for (int j = 1; j <= m; j++) { + for (int i = 1; i <= n; i++) + if (a[i][j] == 'B' and a[i + 1][j] != 'B') { + x2 = i; + y2 = j; + ok = 1; + break; + } + if (ok) break; + } + cout << (x1 + x2) / 2 << " " << (y1 + y2) / 2 << endl; +} +const int N = 2e6 + 123; +const int INF = 1e9 + 123; +const int MOD = 1e9 + 7; +const double EPS = 1e-9; +const int dx[] = {0, 0, 1, -1}; +const int dy[] = {1, -1, 0, 0}; +int n; +bool no, u[4]; +int main() { + cin >> n; + u[1] = 1; + u[2] = 1; + for (int i = 1; i <= n; ++i) { + int x; + cin >> x; + if (!u[x]) no = 1; + for (int j = 1; j <= 3; ++j) { + if (!u[j]) { + u[j] = 1; + continue; + } + if (u[j] && x != j) { u[j] = 0; } + } + } + if (no) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int n, m; +vector v; +bool check(int t) { + if (t == 0) return false; + if ((t / (m - 1)) % 2 == 0) + return true; + else if (t % (m - 1) == 0) + return true; + else + return false; +} +int et(int t) { + bool fl = check(t); + if (fl && t % (m - 1) != 0) return t % (m - 1) + 1; + if (fl && t % (m - 1) == 0 && (t / (m - 1)) % 2 == 0) return 1; + if (fl && t % (m - 1) == 0) return m; + if (!fl && t % (m - 1) != 0) return m - t % (m - 1); + if (!fl && t % (m - 1) == 0) return 1; +} +int tim(int in, int o, int t) { + bool fl = check(t); + if (in == o) return 0; + if (in < o && fl) return (o - in); + if (in < o && !fl) return (in - 1) + (o - 1); + if (in > o && !fl) return abs(in - o); + if (in > o && fl) return (m - in) + (m - o); +} +int main() { + vector s, f; + vector t; + cin >> n >> m; + s.resize(n); + f.resize(n); + t.resize(n); + for (int i = 0; i < n; ++i) { + int tm; + cin >> s[i] >> f[i] >> t[i]; + } + for (int i = 0; i < n; ++i) { + if (s[i] == f[i]) { + cout << t[i] << endl; + continue; + } + int tt = t[i] + tim(et(t[i]), s[i], t[i]); + int ttt = tt + tim(s[i], f[i], tt); + cout << ttt << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long a[n]; + long long maxi = 0; + long long sum = 0; + for (long long i = 0, _n = (n); i < _n; i++) { + cin >> a[i]; + maxi = max(maxi, a[i]); + sum = sum + a[i]; + } + long long k = 0; + while (n * k <= 2 * sum) k++; + if (k < maxi) k = maxi; + cout << k << endl; +} +const int64_t infint64_t = 9223372036854775807LL; +void solve() { + int64_t a, b, c; + cin >> a >> b >> c; + int64_t n; + cin >> n; + int64_t ans = 0; + for (int64_t i = 0; i < n; i++) { + int x; + cin >> x; + if (x > b && x < c) ans++; + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +int main() { + string a, b; + cin >> a; + cin >> b; + int n = 0, m = 0; + for (int i = 0; i < a.size(); i++) { + if ((a[i] == '4') && (a[i] != b[i])) n++; + if ((a[i] == '7') && (a[i] != b[i])) m++; + } + cout << max(n, m) << endl; +} +long long k; +string s[8]; +int main() { + s[1] = "+------------------------+"; + s[2] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)"; + s[3] = "|#.#.#.#.#.#.#.#.#.#.#.|.|"; + s[4] = "|#.......................|"; + s[5] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)"; + s[6] = "+------------------------+"; + cin >> k; + for (long long j = 1; j <= 25; j++) { + for (long long i = 2; i <= 5; i++) { + if (k == 0) break; + if (s[i][j] == '#') s[i][j] = 'O', k--; + } + if (k == 0) break; + } + for (long long i = 1; i <= 6; i++) cout << s[i] << "\n"; + return 0; +} +int main() { + int x, y, r; + cin >> x >> y; + r = abs(x) + abs(y); + if (x > 0) { + if (y > 0) + cout << 0 << " " << r << " " << r << " " << 0 << "\n"; + else + cout << 0 << " " << -r << " " << r << " " << 0 << "\n"; + } else { + if (y > 0) + cout << -r << " " << 0 << " " << 0 << " " << r << "\n"; + else + cout << -r << " " << 0 << " " << 0 << " " << -r << "\n"; + } +} +int main() { + int n, n1, n2, n3, n4; + int sum = 0; + cin >> n; + sum = sum + n / 5; + n4 = n % 5; + sum = sum + n4 / 4; + n3 = n4 % 4; + sum = sum + n3 / 3; + n2 = n3 % 3; + sum = sum + n2 / 2; + n1 = n2 % 2; + sum = sum + n1 / 1; + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; 4 * i <= n; i++) + if ((n - 4 * i) % 7 == 0) { + for (int j = 1; j <= i; j++) cout << 4; + for (int j = 1; j <= (n - 4 * i) / 7; j++) cout << 7; + cout << endl; + return 0; + } + cout << -1 << endl; + return 0; +} +int main() { + int a[3][3], b[3][3] = {0}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> a[i][j]; + if (a[i][j] % 2 == 0) + a[i][j] = 0; + else + a[i][j] = 1; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (a[i][j] == 1) { + b[i][j] += 1; + if (j < 2) { + b[i][++j] += 1; + j--; + } + if (j > 0) { + b[i][--j] += 1; + j++; + } + if (i < 2) { + b[++i][j] += 1; + i--; + } + if (i > 0) { + b[--i][j] += 1; + i++; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (b[i][j] % 2 == 0) + b[i][j] = 0; + else + b[i][j] = 1; + if (b[i][j]) + b[i][j] = 0; + else + b[i][j] = 1; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << b[i][j]; } + cout << '\n'; + } + return 0; +} +int main() { + int lb, bh, hl, l, b, h; + cin >> lb >> bh >> hl; + b = (int)sqrt(lb * bh / hl); + l = lb / b; + h = hl / l; + cout << 4 * (l + b + h) << endl; + return 0; +} +int rest = 0; +int previousGym = 0; +int previousContest = 0; +int goRest() { + previousGym = 0; + previousContest = 0; + rest++; +} +int goGym() { + previousGym = 1; + previousContest = 0; +} +int goContest() { + previousGym = 0; + previousContest = 1; +} +int goEither() { + previousGym = 0; + previousContest = 0; +} +int main() { + int n; + int type; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> type; + if (type == 0) { + goRest(); + } else if (type == 1) { + if (previousContest == 0) + goContest(); + else + goRest(); + } else if (type == 2) { + if (previousGym == 0) + goGym(); + else + goRest(); + } else if (type == 3) { + if (previousGym == 1 && previousContest == 0) { + goContest(); + } else if (previousGym == 0 && previousContest == 1) { + goGym(); + } else + goEither(); + } + } + cout << rest << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < n; i++) { + int c, d; + cin >> c >> d; + ans += (d - c + 1); + } + ans = ans % k ? k - (ans % k) : 0; + cout << ans << endl; + return 0; +} +long long n, k; +int main() { + cin >> n >> k; + long long nn = n / 2; + long long o = nn / (k + 1); + cout << o << " " << o * k << " " << n - ((k + 1) * o) << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int i = 0; + int f = 0; + string si; + for (int j = 0; j < n; ++j) { + if (s[j] == '.') { + i = s[j - 1] - '0'; + f = s[j + 1] - '0'; + break; + } + si.append(1, s[j]); + } + if (i == 9) { + cout << "GOTO Vasilisa." << endl; + return 0; + } + if (f < 5) { + cout << si << endl; + return 0; + } + si[si.size() - 1] += 1; + cout << si << endl; + return 0; +} +int n, k, c, a[1010]; +bool b[1010]; +int main() { + cin >> n >> k >> c; + for (int i = (int)0; i < (int)c; i++) { + cin >> a[i]; + b[a[i]] = 1; + } + int last = 0, ans = 0; + for (int i = (int)1; i < (int)n + 1; i++) + if (i - last >= k || b[i]) { + last = i; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c, x, y, ans = 0; + cin >> n >> a >> b >> c; + int k = 1; + for (int i = 2; i <= n; i++) { + if (k == 1) { + if (a < b) + x = a, y = 2; + else + x = b, y = 3; + } + if (k == 2) { + if (a < c) + x = a, y = 1; + else + x = c, y = 3; + } + if (k == 3) { + if (b < c) + x = b, y = 1; + else + x = c, y = 2; + } + ans += x; + k = y; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, x, sum = 0, ans = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x; + sum += x; + } + ans = abs(sum) / m; + if (abs(sum) % m != 0) { ans++; } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + map mp; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + mp[s]++; + } + long long sum = 0; + map::iterator it; + for (it = mp.begin(); it != mp.end(); it++) { + if (it->first == "Tetrahedron") { + sum += (4 * it->second); + } else if (it->first == "Cube") { + sum += (it->second * 6); + } else if (it->first == "Octahedron") { + sum += (it->second * 8); + } else if (it->first == "Dodecahedron") { + sum += (it->second * 12); + } else if (it->first == "Icosahedron") { + sum += (it->second * 20); + } + } + cout << sum << endl; +} +int main() { + int n; + cin >> n; + int a = n / 10; + int b = n % 10; + int num[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + cout << num[a] * num[b] << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int game[n]; + for (int i = 0; i < n; i++) cin >> game[i]; + int large = 0, prezero = 0; + for (int i = 0; i < n; i++) { + if (game[i] == 0) { + prezero++; + large = max(large, prezero); + } else { + int cur = prezero; + for (int j = i; j < n; j++) { + if (game[j] == 1) { cur++; } + } + large = max(cur, large); + } + } + cout << large << '\n'; + } +} +int mn = 1e9; +bool chk_all(string s[], int n, string str, int start, int end) { + for (int i = 0; i < n; i++) { + for (int j = start; j <= end; j++) { + if (s[i][j] != str[j]) return false; + } + } + return true; +} +string common_prefix(string s[], int n) { + string ans = ""; + int low = 0, high = mn; + while (low <= high) { + int mid = low + (high - low) / 2; + if (chk_all(s, n, s[0], low, mid)) { + ans += s[0].substr(low, mid - low + 1); + low = mid + 1; + } else { + high = mid - 1; + } + } + return ans; +} +int main() { + int n; + cin >> n; + string s[n]; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i].size() < mn) { mn = s[i].size(); } + } + string res = common_prefix(s, n); + cout << res.size() << endl; + return 0; +} +long long n, ans; +int main() { + cin >> n; + for (int i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { ans = i; } + } + cout << ans << " " << n / ans << endl; + return 0; +} +long long int i, j, k, l, sum = 0, ans = 0, m, n; +void fastio() {} +void solve() { + cin >> n; + string s; + cin >> s; + for (i = 0; i < n / 2; i++) { + if (s[i] == s[n - 1 - i]) continue; + if (s[i] + 1 == s[n - 1 - i] - 1) continue; + if (s[i] - 1 == s[n - i - 1] + 1) continue; + cout << "NO\n"; + return; + } + cout << "YES\n"; +} +int main() { + fastio(); + int t = 1; + cin >> t; + while (t--) solve(); + return 0; +} +string S; +int main() { + cin >> S; + while (S[0] != 'h' && S.length() > 0) { S.erase(0, 1); } + while (S[1] != 'e' && S.length() > 1) { S.erase(1, 1); } + while (S[2] != 'l' && S.length() > 2) { S.erase(2, 1); } + while (S[3] != 'l' && S.length() > 3) { S.erase(3, 1); } + while (S[4] != 'o' && S.length() > 4) { S.erase(4, 1); } + if (S.length() > 5) S.erase(5, 100); + if (S == "hello") + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int x = 1, y = 2; + bool ok = true; + while (n--) { + int w; + cin >> w; + if (!ok) { continue; } + if (w == x || w == y) { + y = 6 - x - y; + x = w; + } else { + ok = false; + } + } + cout << (ok ? "YES\n" : "NO\n"); + return 0; +} +int main() { + int n, k; + long long int x; + vector v, s; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + for (int i = 0; i < n; i++) { + cin >> x; + s.push_back(x); + } + long long int res = 0, maxi = -1, tiempo = 0; + for (int i = 0; i < n; i++) { + res += s[i]; + maxi = max(s[i], maxi); + if (res < v[i]) { + long long int aux = v[i] - res; + if (aux < maxi) { + tiempo += k; + res += maxi; + } else { + long long int falta = aux / maxi; + if (falta * maxi < aux) falta++; + tiempo += falta * k; + res += falta * maxi; + } + } + res -= v[i]; + tiempo += v[i]; + } + cout << tiempo << '\n'; +} +int main() { + string s, t, u; + cin >> s; + cin >> t; + reverse(t.begin(), t.end()); + if (s == t) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int m, k; + cin >> m >> k; + vector dist(m); + for (int i = 0; i < m; ++i) cin >> dist[i]; + vector gas(m); + for (int i = 0; i < m; ++i) cin >> gas[i]; + long long G = gas[0]; + long long actual = 0; + long long time = 0; + for (int i = 0; i < m; ++i) { + actual += gas[i]; + G = max(G, gas[i]); + while (actual < dist[i]) { + actual += G; + time += k; + } + actual -= dist[i]; + time += dist[i]; + } + cout << time << '\n'; + return 0; +} +int main() { + int n, k; + int ans = 0; + int a[105]; + int flag[105] = {0}; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] > k) break; + if (a[i] <= k) { + ans++; + flag[i] = 1; + } + } + for (int i = n - 1; i >= 0 && flag[i] == 0; i--) { + if (a[i] > k) break; + if (a[i] <= k) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + bool ok = false; + for (int i = 0; i < (int)(5); i++) { + string t; + cin >> t; + if (s[0] == t[0] || s[1] == t[1]) ok = true; + } + cout << (ok ? "YES" : "NO") << "\n"; + return 0; +} +int min(int a, int b, int c) { + if (a > b) a = b; + if (a > c) a = c; + return a; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(k * l / nl, c * d, p / np) / n << endl; + return 0; +} +long long n, l, r, a, b; +int main() { + cin >> n; + while (n--) { + cin >> l >> r; + a = min(l, r); + b = max(l, r); + for (long long i = 0; i < 63; i++) { + if ((a | (1LL << i)) <= b) { a |= (1LL << i); } + } + cout << a << '\n'; + } +} +int dfs(int i, int j) { + if (i == 0 || j == 0) + return 1; + else + return (dfs(i - 1, j) + dfs(i, j - 1)); +} +int main() { + int n; + cin >> n; + cout << dfs(n - 1, n - 1) << endl; + return 0; +} +int main() { + int n, a, b, cnt; + cin >> n; + while (n--) { + cin >> a >> b; + cnt = 0; + while (1) { + if (a == 0 || b == 0) { break; } + if (a >= b) { + cnt += a / b; + a %= b; + } else { + cnt += b / a; + b %= a; + } + } + cout << cnt << "\n"; + } + return 0; +} +vector v; +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + long long int i, n, j, ans, x1, x2, y1, y2; + while (cin >> n) { + ans = 0; + for (i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << endl; + } + return 0; +} +inline void ac() { + cout << "I love "; +} +inline void wa() { + cout << "I hate "; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i & 1) + wa(); + else + ac(); + if (i != n) cout << "that "; + } + cout << "it" << endl; +} +const long long gig = 1e18; +const long long gg = 25 * 1e6; +const long long md = 1e9 + 7; +const long long N = 100050; +const double PI = 3.1415926535897932384626433832795; +long long n, a[111111]; +string s; +long long f[111111]; +int main() { + srand(time(NULL)); + unsigned long long n, z; + cin >> n; + unsigned long long ot = 2; + cout << ot << endl; + for (unsigned long long i = 2; i <= n; i++) { cout << i * (i + 1) * (i + 1) - (i - 1) << endl; } +} +int main() { + int n, num[100005], min = INT_MAX, cnt = 0, first, last, selisih; + int arrpos[100005], has = INT_MAX; + cin >> n; + for (int x = 1; x <= n; x++) { + cin >> num[x]; + if (num[x] < min) { min = num[x]; } + } + for (int x = 1; x <= n; x++) { + if (num[x] == min) { + if (cnt == 0) { + arrpos[x] = x; + first = x; + } + if (cnt == 1) { + arrpos[x] = x; + last = x; + } + if (cnt >= 2) { + first = last; + last = x; + arrpos[x] = x; + } + cnt++; + } + if (cnt >= 2) { + selisih = arrpos[last] - arrpos[first]; + if (selisih < has) { has = selisih; } + } + } + cout << has << endl; + return 0; +} +int main() { + int i, j, i1, j1, press[3][3], light[5][5]; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + cin >> press[i][j]; + press[i][j] = press[i][j] % 2; + } + } + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) light[i][j] = 1; + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (press[i][j] == 1) { + light[i][j + 1] = 1 - light[i][j + 1]; + light[i + 1][j + 1] = 1 - light[i + 1][j + 1]; + light[i + 1][j] = 1 - light[i + 1][j]; + light[i + 1][j + 2] = 1 - light[i + 1][j + 2]; + light[i + 2][j + 1] = 1 - light[i + 2][j + 1]; + } + } + } + for (i = 1; i < 4; i++) { + for (j = 1; j < 4; j++) { cout << light[i][j]; } + cout << endl; + } + return 0; +} +int sumr[35], sumc[35]; +int main() { + int n, t; + cin >> n; + for (int i = 1; i <= n; ++i) sumr[i] = sumc[i] = 0; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= n; ++j) { + cin >> t; + sumr[i] += t; + sumc[j] += t; + } + } + int num = 0; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= n; ++j) { + if (sumc[j] > sumr[i]) num++; + } + } + cout << num << endl; +} +int a = 1; +void recorrer(int v[], int n, int m[]) { + int j = 0; + for (int i = 0; i < n; i++) { + if (i != a) { + m[j] = v[i]; + j++; + } + } + a++; +} +void mostrar(int m[], int n) { + for (int i = 0; i < n - 1; i++) cout << m[i] << " "; +} +int main() { + int n; + cin >> n; + int v[n]; + int m[n - 1]; + for (int i = 0; i < n; i++) cin >> v[i]; + int may = 0, mini = 100000; + for (int i = 0; i < n - 2; i++) { + recorrer(v, n, m); + for (int j = 0; j < n - 2; j++) { + if (m[j + 1] - m[j] > may) may = m[j + 1] - m[j]; + } + if (mini > may) mini = may; + may = 0; + } + cout << mini << endl; + return 0; +} +int a[30]; +int main() { + string pot1, pot2; + cin >> pot1 >> pot2; + int n; + cin >> n; + cout << pot1 << " " << pot2 << endl; + for (int i = 0; i < n; i++) { + string vict, next; + cin >> vict >> next; + if (vict == pot1) { + pot1 = next; + } else + pot2 = next; + cout << pot1 << " " << pot2 << endl; + } +} +int main() { + char str[100]; + int dif, ans = 0; + gets(str); + int len = strlen(str); + char cur = 'a'; + for (int i = 0; i < len; i++) { + dif = abs(str[i] - cur); + ans += min(dif, 26 - dif); + cur = str[i]; + } + cout << ans << endl; +} +int n, x, y, cnt; +long long ans; +string buf; +int main() { + cin >> n >> x >> y; + cin >> buf; + for (int i = 0; i < n; i++) + if (buf[i] == '0' && buf[i - 1] != '0') cnt++; + if (cnt) { + if (x >= y) + ans = 1ll * cnt * y; + else + ans = 1ll * (cnt - 1) * x + y; + } + cout << ans << endl; + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + ans += abs(a[i]); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int x; + cin >> x; + if (x == 1) { + cout << "-1\n"; + return 0; + } + } + cout << "1\n"; +} +const int maxn = 105; +int n; +char a[maxn][maxn]; +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, -1, 0, 1}; +int ans = 0; +bool dfs(int x, int y) { + ans = 0; + for (int i = 0; i < 4; i++) { + int nx = dx[i] + x; + int ny = dy[i] + y; + if (a[nx][ny] == 'o' && nx >= 1 && nx <= n && ny >= 1 && ny <= n) ans++; + } + if (ans % 2 == 0) return true; + return false; +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> a[i][j]; } + } + ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (dfs(i, j) == true) + continue; + else { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int l = n / 2; + int L = 1; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= l; j++) { cout << "*"; } + for (int j = 1; j <= L; j++) { cout << "D"; } + for (int j = 1; j <= l; j++) { cout << "*"; } + l--; + L = L + 2; + cout << endl; + } + for (int i = 1; i <= n; i++) cout << "D"; + cout << endl; + L = L - 2; + l = 1; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= l; j++) { cout << "*"; } + for (int j = 1; j <= L; j++) { cout << "D"; } + for (int j = 1; j <= l; j++) { cout << "*"; } + l++; + L = L - 2; + cout << endl; + } +} +const int N = 2e5 + 5; +long long A[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> A[i]; + A[i] += A[i - 1]; + } + int ans = -1; + for (int i = 1; i <= n; i++) { + if (2 * A[i] >= A[n]) { + ans = i; + break; + } + } + cout << ans << "\n"; + return 0; +} +char A, B, C[4] = {'^', '>', 'v', '<'}; +long long N, x, y; +int main() { + cin >> A >> B >> N; + for (int i = 0; i < 4; i++) { + if (A == C[i]) x = i; + if (B == C[i]) y = i; + } + if (N % 2 == 0) + cout << "undefined\n"; + else if ((x + N % 4) % 4 == y) + cout << "cw\n"; + else + cout << "ccw\n"; +} +int main() { + int n, m, k, j, a, c; + cin >> n >> m >> k; + int v[n]; + for (j = 0; j < n; j++) cin >> v[j]; + sort(v, v + n); + if (m > k) { + c = 1; + a = v[n - 1]; + k--; + for (j = n - 2; j >= 0 && m > (a + k); j--) { + if (k > 0) { + a += v[j]; + k--; + } else { + a += v[j] - 1; + } + } + if (m > (a + k)) + cout << -1 << endl; + else + cout << n - j - 1 << endl; + } else + cout << 0 << endl; +} +string s; +int main() { + cin >> s; + while (s[0] != 'h' && s.length() > 0) { s.erase(0, 1); } + while (s[1] != 'e' && s.length() > 1) { s.erase(1, 1); } + while (s[2] != 'l' && s.length() > 2) { s.erase(2, 1); } + while (s[3] != 'l' && s.length() > 3) { s.erase(3, 1); } + while (s[4] != 'o' && s.length() > 4) { s.erase(4, 1); } + if (s.length() > 5) { s.erase(5.100); } + if (s == "hello") { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, hh = -1, mm = -1, h, m, res = 0, k = 1; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> h >> m; + if (h == hh && m == mm) { + k++; + } else { + hh = h; + mm = m; + res = res > k ? res : k; + k = 1; + } + } + cout << (res > k ? res : k) << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + n = (n + 1) / 2; + cout << (k > n ? 2 * (k - n) : 2 * k - 1) << endl; + return 0; +} +int main() { + int a, b, c, d, e; + cin >> a; + cin >> b; + cin >> c; + cin >> d; + cin >> e; + if ((a + b + c + d + e) % 5 != 0 || (a + b + c + d + e) / 5 == 0) { + cout << -1 << endl; + } else { + cout << (a + b + c + d + e) / 5 << endl; + } + return 0; +} +map mp; +int main() { + string s; + cin >> s; + int ans = 1; + mp[s] = 1; + for (int i = 1; i < s.length(); i++) { + char t = s[s.length() - 1]; + s = s.substr(0, s.length() - 1); + s = t + s; + if (mp[s] == 0) { + ans += 1; + mp[s] = 1; + } + } + cout << ans << endl; +} +int main() { + int a, b; + cin >> a >> b; + if (a >= 0 && b >= 0) { + cout << 0 << " " << a + b << " " << a + b << " " << 0 << endl; + } else if (a > 0 && b < 0) { + cout << 0 << " " << b - a << " " << a - b << " " << 0 << endl; + } else if (a < 0 && b > 0) { + cout << a - b << " " << 0 << " " << 0 << " " << b - a << endl; + } else { + cout << a + b << " " << 0 << " " << 0 << " " << a + b << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + bool arr[100010] = {0}; + int num; + for (int i = 1; i < n; i++) { + cin >> num; + arr[num]++; + } + for (int i = 1; i <= n; i++) { + if (arr[i] == 0) { + cout << i << endl; + return 0; + } + } +} +int a[200]; +int main() { + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] <= k) + ++cnt; + else + break; + } + for (int i = n; i >= 1; i--) { + if (a[i] <= k) + ++cnt; + else + break; + } + if (cnt >= n) { + cout << n << endl; + } else + cout << cnt << endl; + return 0; +} +int pwr(int x, int p, const int &MOD) { + if (p == 0) return 1; + if (p == 1) return x % MOD; + int result = pwr(x, p / 2, MOD) % MOD; + result = (result * result) % MOD; + if (p & 1) result = (result * x) % MOD; + return result; +} +int main() { + int p, result = 0, valid; + cin >> p; + for (int x = 1; x <= p; x++) { + if ((pwr(x, p - 1, p) + p - 1) % p == 0) { + valid = 1; + for (int i = 1; (i < p - 1) && valid; i++) { + if ((pwr(x, i, p) + p - 1) % p == 0) { valid = 0; } + } + result += valid; + } + } + cout << result << endl; + return 0; +} +int MOD; +bool isprime[100100]; +vector listprime; +long long n; +vector p; +void sieve() { + for (long long i = 3; i <= 100000; i = i + 2) { isprime[i] = true; } + isprime[2] = true; + listprime.push_back(2); + for (long long i = 3; i <= 100000; i = i + 2) { + if (isprime[i]) { + listprime.push_back(i); + for (long long j = i * i; j <= 100000; j = j + i) { isprime[j] = false; } + } + } +} +long long fastexpo(long long num, long long pangkat) { + if (pangkat == 0) return 1; + if (pangkat == 1) return num; + long long a = fastexpo(num, pangkat / 2) % MOD; + if (pangkat % 2 == 1) { + return (((a * a) % MOD) * num) % MOD; + } else + return (a * a) % MOD; +} +long long sum(long long num) { + long long ret, akhir, awal = num; + akhir = n - num; + long long bnyak = (n / num - 1); + ret = (awal + akhir) * bnyak; + ret = ret % MOD; + ret = ret * fastexpo(2, MOD - 2) % MOD; + ret = ret % MOD; + return ret % MOD; +} +int main() { + sieve(); + long long n; + cin >> n; + long long ans = 0; + MOD = n; + for (int i = 1; i < n; i++) { + bool flag = 1; + for (int j = 1; j <= n - 2; j++) { + if (fastexpo(i, j) % MOD == 1) { + flag = 0; + break; + } + } + if (flag) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector a(n), b(m); + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + sort(a.begin(), a.end()); + sort(b.begin(), b.end()); + int t = max(2 * a[0], a[n - 1]); + if (t < b[0]) + cout << t << endl; + else + cout << -1 << endl; +} +int main() { + int n; + cin >> n; + long long int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int maxl = 1; + int curl = 1; + int i = 1; + while (i < n) { + if (arr[i] > arr[i - 1]) { + curl++; + } else { + if (curl > maxl) maxl = curl; + curl = 1; + } + i++; + } + if (curl > maxl) maxl = curl; + cout << maxl << endl; +} +const int N = 1 << 20; +int main() { + long long n, m; + cin >> n >> m; + bool ok = 0, f = 0; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) + ok = 0; + else + ok = 1; + if (!ok) { + for (int j = 0; j < m; j++) { cout << "#"; } + } else { + if (f == 0) { + for (int i = 0; i < m - 1; i++) cout << "."; + cout << "#"; + f = 1; + } else { + cout << "#"; + for (int i = 1; i < m; i++) cout << "."; + f = 0; + } + } + cout << endl; + } +} +long long n, k; +int main() { + cin >> n >> k; + long long p = n / 2 / (k + 1); + cout << p << " " << p * k << " " << n - p - p * k << endl; + return 0; +} +int n; +int main() { + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + cout << 25 << endl; +} +char str[30005][25]; +int i, j, n, m; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { cin >> str[i]; } + m = strlen(str[1]); + for (i = 0; i < m; i++) { + for (j = 1; j <= n; j++) { + if (str[1][i] != str[j][i]) { + cout << i << endl; + return 0; + } + } + } + return 0; +} +int main() { + long int n, i; + cin >> n; + long int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) + if (a[i] == 1) break; + if (a[i] == 1) + cout << "-1" << endl; + else + cout << "1" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < n / 2 - i; j++) { cout << "*"; } + for (int j = 1; j <= (i + 1) * 2 - 1; j++) { cout << "D"; } + for (int j = 0; j < n / 2 - i; j++) { cout << "*"; } + cout << endl; + } + for (int i = 0; i < n; i++) cout << "D"; + cout << endl; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - (i + 1) * 2; j++) cout << "D"; + for (int j = 0; j <= i; j++) cout << "*"; + cout << endl; + } +} +const int INF = 1e9; +const int N = 1e5; +bool check(int x) { + while (abs(x) > 0) { + if (abs(x % 10) == 8) return true; + x /= 10; + } + return false; +} +int main() { + int a; + cin >> a; + int tmp = a + 1, cnt = 1; + while (!check(tmp)) tmp++, cnt++; + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + int x = s.size(); + int y = 26 + 26 * x - x; + cout << y << endl; + return 0; +} +int main() { + char a[1000][1000]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int sum = 0; + for (int i = 0; i < n; i++) { + int c = 0; + for (int j = 0; j < n; j++) { + if (a[i][j] == 'C') c++; + } + sum = sum + (c * (c - 1) / 2); + } + for (int i = 0; i < n; i++) { + int c = 0; + for (int j = 0; j < n; j++) { + if (a[j][i] == 'C') c++; + } + sum = sum + (c * (c - 1) / 2); + } + cout << sum << endl; +} +int n, a[6], b[6], ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int c; + cin >> c; + a[c]++; + } + for (int i = 0; i < n; i++) { + int c; + cin >> c; + b[c]++; + } + for (int i = 1; i <= 5; i++) { + if ((a[i] + b[i]) % 2 != 0) { + cout << -1 << endl; + return 0; + } + } + for (int i = 1; i <= 5; i++) { + if (b[i] > a[i]) { ans += b[i] - a[i]; } + } + cout << ans / 2 << endl; +} +const long long mod = 1e9 + 7; +const int MAX = 1e6 + 7; +long long n, d, a, b; +int main() { + cin >> n >> d >> a >> b; + long long ans = (n % d) * b; + long long r = (n / d + 1) * d; + ans = min(ans, (r - n) * a); + cout << ans << "\n"; +} +long long n; +int main() { + cin >> n; + if (n % 10 > 5) { + cout << n + (10 - n % 10) << endl; + return 0; + } else { + cout << n - (n % 10) << endl; + return 0; + } +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int ans = ceil((double)y / 100 * n); + if (ans - x > 0) + cout << ans - x << endl; + else + cout << 0 << endl; +} +const int MAX = 100001; +int An[MAX], Bn[MAX]; +int k, n; +int preorder() { + int sum = 0; + for (int i = 0; i < n; i++) { + if (An[i] <= k) + sum++; + else + break; + } + return sum; +} +int rearorder() { + int sum = 0; + for (int i = n - 1; i >= 0; i--) { + if (An[i] <= k) + sum++; + else + break; + } + return sum; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> An[i]; + int t = preorder() + rearorder(); + if (t == 2 * n) + cout << t / 2 << endl; + else + cout << t << endl; + return 0; +} +int main() { + int n, r = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; ++i) { r += (s[i] == '0' ? -1 : 1); } + cout << (r < 0 ? -r : r) << endl; + return 0; +} +int main() { + int p, c = 0, x; + bool valid; + cin >> p; + for (int i = 1; i < p; i++) { + x = 1; + valid = true; + for (int e = 1; e <= p - 2; e++) { + x = (x * i) % p; + if ((x - 1) % p == 0) { + valid = false; + break; + } + } + x = (x * i) % p; + if (valid && (x - 1) % p == 0) c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, k, x, a[105], sum = 0; + cin >> n >> k >> x; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + for (int i = 0; i < (n - k); ++i) { sum += a[i]; } + sum += (k * x); + cout << sum << endl; + return 0; +} +int main() { + int n; + int i; + int temp; + cin >> n; + for (i = 0; i < n; i++) { + cin >> temp; + cin >> temp; + } + cout << "Karen" << endl; + return 0; +} +int main() { + int n, m, i, j; + char a[100][100]; + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 != 0) a[i][j] = '#'; + } + } + for (i = 2; i <= n; i += 4) { + for (j = 1; j < m; j++) { a[i][j] = '.'; } + a[i][j] = '#'; + } + for (i = 4; i <= n; i += 4) { + a[i][1] = '#'; + for (j = 2; j <= m; j++) { a[i][j] = '.'; } + } + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int main() { + char S[3][11]; + int n; + char ele[11], val[11]; + cin >> S[0] >> S[1]; + cin >> n; + cout << S[0] << " " << S[1] << "\n"; + while (n--) { + cin >> ele >> val; + if (strcmp(ele, S[0]) == 0) { + int i; + for (i = 0; val[i]; i++) { S[0][i] = val[i]; } + S[0][i] = '\0'; + } else { + int i; + for (i = 0; val[i]; i++) { S[1][i] = val[i]; } + S[1][i] = '\0'; + } + for (int i = 0; S[0][i]; i++) { cout << S[0][i]; } + cout << " "; + for (int i = 0; S[1][i]; i++) { cout << S[1][i]; } + cout << "\n"; + } +} +int main() { + int n, t, flag; + while (cin >> n) { + flag = 0; + while (n--) { + cin >> t; + if (t == 1) flag = 1; + } + if (flag == 1) + cout << "-1" << endl; + else + cout << '1' << endl; + } + return 0; +} +const int maxn = 3e5 + 5; +int main() { + int n, a, b, c; + cin >> n; + cin >> a >> b >> c; + int t = min(a, b); + int m = min(t, c); + if (n == 1) return puts("0"), 0; + if (n == 2) return cout << t << endl, 0; + cout << t + (n - 2) * m << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + for (int j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + cout << "\n"; + } + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - 2 * i; j++) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << "\n"; + } + return 0; +} +int main() { + string s; + cin >> s; + cout << (26 + (s.size() * 25)) << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ln = s.length(); + int b = 26 * (ln + 1); + b = b - ln; + cout << b << endl; + return 0; +} +const int maxn = 1100; +const int inf = 0x3f3f3f3f; +int a[maxn]; +int main() { + long long n; + int k; + cin >> n >> k; + while (k--) { + if (n % 10) + n--; + else + n = n / 10; + } + cout << n << endl; + return 0; +} +int n; +int main() { + string s; + cin >> n; + int ans = 0; + while (n--) { + cin >> s; + if (s == "Tetrahedron") ans = ans + 4; + if (s == "Cube") ans = ans + 6; + if (s == "Octahedron") ans = ans + 8; + if (s == "Dodecahedron") ans = ans + 12; + if (s == "Icosahedron") ans = ans + 20; + } + cout << ans << endl; + return 0; +} +const int N = 1 << 20; +int main() { + long long a, b; + cin >> a >> b; + long long ye, bl, g; + cin >> ye >> g >> bl; + long long y1 = 2 * ye; + long long y2 = g; + long long b1 = g; + long long b2 = 3 * bl; + long long ans1, ans2; + if (a >= y1 + y2) + ans1 = 0; + else + ans1 = abs(a - (y1 + y2)); + if (b > b1 + b2) + ans2 = 0; + else + ans2 = abs(b - (b1 + b2)); + cout << ans1 + ans2 << endl; +} +int main() { + int p, n; + int flag = 0; + long long int a[301]; + int b[301]; + cin >> p >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + b[1] = a[1] % p; + for (int i = 2; i <= n; i++) { + b[i] = a[i] % p; + for (int j = 1; j < i; j++) { + if (b[i] == b[j]) { + flag = 1; + break; + } + } + if (flag) { + cout << i << endl; + break; + } + } + if (!flag) cout << -1 << endl; + return 0; +} +int main() { + int x, y; + int s[5] = {5, 4, 3, 2, 1}; + int sum = 0; + cin >> x; + for (int i = 0; i < 5; i++) { + if (x >= s[i]) { + y = x / s[i]; + sum += y; + x -= y * s[i]; + } + } + cout << sum << endl; +} +int t; +int a[1005]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { cin >> a[i]; } + sort(a + 1, a + 1 + t, cmp); + for (int i = 1; i <= t; i++) { + if ((int)sqrt(a[i]) * (int)sqrt(a[i]) != a[i]) { + cout << a[i] << endl; + break; + } + } + return 0; +} +int N, a[200], c[200]; +vector edges[200]; +int simulate(int s) { + memset(c, 0, sizeof(c)); + for (int i = int(0); i < int(N); i++) { + for (int j = int(0); j < int(edges[i].size()); j++) c[edges[i][j]]++; + } + queue q[3]; + for (int i = int(0); i < int(N); i++) + if (!c[i]) q[a[i]].push(i); + int poped = 0; + int ret = -1; + while (poped < N) { + while (!q[s].empty()) { + int f = q[s].front(); + q[s].pop(); + poped++; + for (int i = int(0); i < int(edges[f].size()); i++) { + int next = edges[f][i]; + if (!--c[next]) { q[a[next]].push(next); } + } + } + s = (s + 1) % 3; + ret++; + } + return ret; +} +int main() { + while (cin >> N) { + for (int i = int(0); i < int(N); i++) edges[i].clear(); + for (int i = int(0); i < int(N); i++) { + cin >> a[i]; + a[i] %= 3; + } + for (int i = int(0); i < int(N); i++) { + int k, t; + cin >> k; + for (int j = int(0); j < int(k); j++) { + cin >> t; + edges[t - 1].push_back(i); + } + } + int ans = 1000000000; + for (int i = int(0); i < int(3); i++) ans = min(ans, simulate(i)); + cout << ans + N << endl; + } + return 0; +} +int main() { + int i, j, n, p = 0, q, flag = 0, a[10] = {0}; + for (i = 0; i < 6; i++) { + cin >> n; + a[n]++; + } + for (i = 0; i <= 9; i++) { + if (a[i] >= 4) { + a[i] -= 4; + flag = 1; + } + } + if (flag == 0) { + cout << "Alien" << endl; + return 0; + } + for (i = 0; i <= 9; i++) { + if (a[i] == 2) { + cout << "Elephant" << endl; + return 0; + } + } + cout << "Bear" << endl; + return 0; +} +int n, k, i; +string s; +int main() { + cin >> n >> k >> s; + if (k - 1 < n - k) { + while (--k) cout << "LEFT" << endl; + for (i = 0; i < n; i++) { + cout << "PRINT " << s[i] << endl; + if (i != n - 1) cout << "RIGHT" << endl; + } + } else { + while (k < n) cout << "RIGHT" << endl, k++; + for (i = n - 1; i >= 0; i--) { + cout << "PRINT " << s[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } + return 0; +} +int n, x[2005], y[2005]; +bool mark[4000005]; +string s[2] = {"Karen\n", "Koyomi\n"}; +int cnt = 0; +int main() { + memset(mark, false, sizeof mark); + cin >> n; + for (int i = 1; i <= n; ++i) cin >> x[i], mark[x[i]] = true; + for (int i = 1; i <= n; ++i) cin >> y[i], mark[y[i]] = true; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) cnt += mark[x[i] ^ y[j]]; + cout << s[cnt % 2]; + return 0; +} +int main() { + int a[10], i, sum = 0, j, k, sum1, fl = 0; + for (i = 0; i < 6; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 2 == 1) + cout << "NO\n"; + else { + for (i = 0; i < 6; i++) { + for (j = i + 1; j < 6; j++) { + for (k = j + 1; k < 6; k++) { + sum1 = a[i] + a[j] + a[k]; + if ((sum - sum1) == (sum1)) { + cout << "YES\n"; + return 0; + } else + fl = 1; + } + } + } + } + if (fl == 1) cout << "NO\n"; + return 0; +} +map ok; +string inter(string ss) { + string res; + for (int i = 0; i < ss.length(); i++) { + if ((ss[i] - '0') % 2) + res += '1'; + else + res += '0'; + } + if (res.find_first_not_of('0') == string::npos) return "0"; + int pos = res.find_first_not_of('0'); + res = res.substr(pos, ss.length() - pos); + return res; +} +int main() { + char op; + string s; + int t; + cin >> t; + while (t--) { + cin >> op; + cin >> s; + s = inter(s); + if (op == '+') { + ok[s]++; + } else if (op == '-') { + ok[s]--; + } else { + cout << ok[s] << endl; + } + } + return 0; +} +int main() { + int n, p; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p; + if (!(p - 1)) { + cout << -1 << endl; + return 0; + } + } + cout << 1 << endl; + return 0; +} +int main() { + int n, d, a[101], i, j, ans = 0, mmax; + cin >> n >> d; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 0; i < n; i++) { + mmax = 1; + for (j = i + 1; j < n; j++) { + if (a[j] - a[i] <= d) + mmax++; + else + break; + } + if (mmax > ans) ans = mmax; + } + cout << n - ans << endl; + return 0; +} +int main() { + map m; + m["Tetrahedron"] = 4; + m["Cube"] = 6; + m["Octahedron"] = 8; + m["Dodecahedron"] = 12; + m["Icosahedron"] = 20; + string s; + int n, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + sum += m[s]; + } + cout << sum << endl; + return 0; +} +long long mod = 1e9 + 7; +long long arr[101] = {}; +int main() { + arr[0] = 1; + arr[1] = 2; + int i, j, k; + for (i = 2; i < 101; i++) { arr[i] = (arr[i - 1] * 2) % mod; } + string s; + cin >> s; + long long ans = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '1') { + ans += arr[s.size() - 1 - i]; + ans %= mod; + } + } + ans *= arr[s.size() - 1]; + ans %= mod; + cout << ans << endl; + return 0; +} +long long f[1000006]; +int main() { + int i, j, n; + f[1] = 1; + f[2] = 3; + for (i = 3; i <= 1000000; i++) { f[i] = (f[i - 1] + f[i - 2] + 2) % 1000000007; } + while (cin >> n) { cout << f[n] << endl; } + return 0; +} +int main() { + string s; + cin >> s; + bool found = false; + for (int i = 0; i < 5; ++i) { + string s2; + cin >> s2; + if (s2[0] == s[0] || s2[1] == s[1]) found = true; + } + cout << (found ? "YES" : "NO") << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + int i; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int r = 0, l = 0; + for (i = 0; i < n; i++) { + if (arr[i] > k) + break; + else + r++; + } + for (int j = n - 1; j > i; j--) { + if (arr[j] > k) + break; + else + l++; + } + int res = min(n, r + l); + cout << res << endl; +} +int main() { + int n; + cin >> n; + vector vec(n); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> vec[i]; + sum += vec[i]; + } + int cur = 0; + sort(vec.begin(), vec.end(), greater()); + for (int i = 0; i < n; i++) { + cur += vec[i]; + sum -= vec[i]; + if (cur > sum) { + cout << i + 1 << endl; + break; + } + } +} +int main() { + int p, sum = 0; + cin >> p; + for (int x = 1; x < p; x++) { + int val = 1, flag = true; + for (int j = 1; j <= p - 1; j++) { + val = val * x % p; + flag &= ((val - 1) % p == 0) == (j == p - 1); + } + sum += flag; + } + cout << sum << "\n"; + return 0; +} +int main() { + int w, h; + cin >> w >> h; + int w1, d1, w2, d2; + cin >> w1 >> d1; + cin >> w2 >> d2; + while (h > 0) { + w += h; + if (h == d1) w = w - w1; + if (h == d2) w = w - w2; + if (w < 0) w = 0; + h--; + } + cout << w << endl; + return 0; +} +const int maxn = 1000 + 5; +int a[maxn], l[maxn], r[maxn]; +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + int t; + cin >> t; + for (int i = 0; i < t; i++) cin >> l[i] >> r[i]; + int time = 0; + for (int i = 0; i < n; i++) { time += a[i]; } + bool yes = false; + for (int j = 0; j < t; j++) { + if (time >= l[j] && time <= r[j]) { + yes = true; + break; + } + } + if (time > r[t - 1]) + cout << "-1" << endl; + else if (yes) + cout << time << endl; + else { + for (int i = t - 1; i >= 0; i--) { + if (l[i] < time) { + yes = true; + cout << l[i + 1] << endl; + break; + } + } + if (!yes) cout << l[0] << endl; + } + } +} +int main() { + long long n; + cin >> n; + if (n % 2) + puts("1"); + else + puts("2"); +} +int main() { + int n, m, cnt = 0; + cin >> n >> m; + cnt = (n * m - 1) / (m - 1); + cout << cnt << "\n"; +} +int main() { + int n; + while (cin >> n) { + for (int i = sqrt(n); i >= 1; i--) { + if (n % i == 0) { + cout << i << ' ' << n / i << endl; + break; + } + } + } + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (abs(i - N / 2) + abs(j - N / 2) <= N / 2) + cout << 'D'; + else + cout << '*'; + } + cout << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int l = s.length(); + cout << 26 * (l + 1) - l << endl; +} +int main() { + int c = 0, n, i, j; + cin >> n; + char a[n][n]; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) cin >> a[i][j]; + } + for (i = 0; i < n; i++) { + int s = 0; + for (j = 0; j < n; j++) { + if (a[i][j] == 'C') s++; + } + c = c + (s * (s - 1)) / 2; + } + for (i = 0; i < n; i++) { + int s = 0; + for (j = 0; j < n; j++) { + if (a[j][i] == 'C') s++; + } + c = c + (s * (s - 1)) / 2; + } + cout << c << endl; +} +int main() { + string a; + string b; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a.compare(b) == 0) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int main() { + string s; + cin >> s; + int pos = 0; + while (pos < s.length() && s[pos] != 'h') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'e') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'l') ++pos; + ++pos; + while (pos < s.length() && s[pos] != 'o') ++pos; + if (pos < s.length()) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int MAXN = 1e4 + 20; +const int INF = 1e9 + 100; +const int MOD = 1e9; +int main() { + long long n, k; + while (cin >> n >> k) { cout << (k + n - 1) / n << endl; } +} +int k, n, s, p; +int main() { + cin >> k >> n >> s >> p; + int i, j; + if (n % s == 0) + i = n / s; + else + i = n / s + 1; + j = (i * k) % p; + if (j == 0) + cout << (i * k) / p << endl; + else + cout << (i * k) / p + 1 << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int arr[n + 1]; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + int idx = n + 1; + for (int i = 1; i <= n; i++) { + if (arr[i] != 0 && arr[i] <= k) { + int x = abs(m - i); + idx = min(idx, x); + } + } + cout << idx * 10 << '\n'; +} +int main() { + long long n; + while (cin >> n) { + while (n % 3 == 0) n /= 3; + cout << n / 3 + 1 << endl; + } + return 0; +} +int main() { + int a[100]; + int n, i, k, max; + k = 0; + cin >> n; + max = -1; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (a[i] > max) { max = a[i]; } + } + for (i = 0; i < n; i++) { k = k + max - a[i]; } + cout << k << endl; + return 0; +} +int main() { + int n, sum = 0, sum1 = 0, ans; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) { + cin >> ar[i]; + sum += ar[i]; + } + sort(ar, ar + n); + for (int i = ar[n - 1];; i++) { + sum1 = 0; + for (int j = 0; j < n; j++) sum1 += (i - ar[j]); + if (sum1 > sum) { + ans = i; + break; + } + } + cout << ans << endl; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(k * l / nl, min(c * d, p / np)) / n << endl; + return 0; +} +const int maxn = 100005; +int main() { + string la = " "; + string fir = " "; + cin >> fir >> la; + string t1 = ""; + t1 += fir[0]; + string t2 = ""; + t2 += la[0]; + string ans = t1 + t2; + for (int i = 1; i < fir.size(); ++i) { + t1 += fir[i]; + string t = t1 + t2; + if (ans > t) { ans = t; } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(n - 1) / r] << endl; + return 0; +} +int main() { + int n, p; + cin >> n >> p; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int d = 0; + for (int i = 0; i < n; i++) { + if (a[i] % p == 0) { + d = d + (a[i] / p); + } else { + d = d + (a[i] / p) + 1; + } + } + if (d % 2 == 0) { + cout << d / 2 << endl; + } else { + cout << (d + 1) / 2 << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[m]; + char b[m]; + char c[m]; + for (int i = 0; i < m; i++) { a[i] = '#'; } + for (int i = 0; i < m - 1; i++) { b[i] = '.'; } + b[m - 1] = '#'; + for (int i = 1; i < m; i++) { c[i] = '.'; } + c[0] = '#'; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) { cout << a[j]; } + cout << endl; + } else if (i % 4 == 1) { + for (int j = 0; j < m; j++) { cout << b[j]; } + cout << endl; + } else { + for (int j = 0; j < m; j++) { cout << c[j]; } + cout << endl; + } + } + return 0; +} +int a, b, c; +bool ok(int x) { + if (a * c <= x * b + c * b) + return true; + else + return false; +} +int binary() { + int lo = 0, hi = 1e6, med; + while (lo < hi) { + med = (hi + lo) >> 1; + if (ok(med)) + hi = med; + else + lo = med + 1; + } + return lo; +} +int main() { + cin >> a >> b >> c; + cout << binary() << endl; + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + int s, a, b, c; + cin >> s >> a >> b >> c; + long long ans = 0; + long long bonus = 0; + ans = s / c; + bonus = (ans / a) * b; + cout << ans + bonus << endl; + } +} +int main() { + int n; + cin >> n; + int year[n]; + for (int i = 0; i < n; i++) cin >> year[i]; + sort(year, year + n); + cout << year[n / 2] << endl; +} +int a[105]; +int main() { + int n, m, x, y, l = 0, r; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + if (i == 1 && x != 0) { + cout << "NO" << endl; + return 0; + } + if (i == 1) + r = y; + else if (x <= r) + r = max(r, y); + } + if (r >= m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int y[30]; +int vis[30]; +int main() { + int n; + cin >> n; + string a; + cin >> a; + { + int z = 0; + for (int i = 0; i < 26; i++) { + if (a.find('a' + i) != -1) { + y[z] = a.find('a' + i); + z++; + } + } + if (z < n) + cout << "NO" << endl; + else { + cout << "YES" << endl; + sort(y, y + z); + for (int i = 0; i < n; i++) { + if (i + 1 == n) { + for (int j = y[i]; j < a.size(); j++) cout << a[j]; + } else { + for (int j = y[i]; j < y[i + 1]; j++) cout << a[j]; + } + cout << endl; + } + } + } + return 0; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) + cout << n / 2 << endl; + else + cout << "-" << (n + 1) / 2 << endl; + return 0; +} +const int MOD = 1e9 + 7; +long long pow(long long a, long long b) { + long long ans = 1; + while (b) { + if (b & 1) ans = (ans * a) % MOD; + b /= 2; + a = (a * a) % MOD; + } + return ans; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + if ((float)360.0 / (180 - a) == 360 / (180 - a)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, p1, p2, c = 0; + char area[120][120]; + bool cek = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> area[i][j]; + if (area[i][j] == 'B') { + if (!cek) { + p1 = i; + p2 = j; + cek = 1; + } + c++; + } + } + } + c = sqrt(c); + p1 += c / 2; + p2 += c / 2; + cout << p1 << ' ' << p2 << '\n'; +} +int main() { + int a, b, c, d[6], k; + cin >> a >> b >> c; + d[0] = a + b + c; + d[1] = a + b * c; + d[2] = a * b * c; + d[3] = a * b + c; + d[4] = (a + b) * c; + d[5] = a * (b + c); + for (int i = 0; i < 6; i++) { + for (int j = 5; j > i; j--) { + if (d[j - 1] > d[j]) { + k = d[j - 1]; + d[j - 1] = d[j]; + d[j] = k; + } + } + } + cout << d[5] << endl; +} +int main() { + int q; + cin >> q; + for (int i = 0; i < q; i++) { + int L; + cin >> L; + string s; + cin >> s; + if (L == 2 && s[0] >= s[1]) + cout << "NO"; + else if (L == 2 && s[0] < s[1]) + cout << "YES" << endl << 2 << endl << s[0] << " " << s[1]; + else if (L > 2) { + cout << "YES" << endl << 2 << endl; + cout << s[0] << " "; + for (int j = 1; j < L; j++) cout << s[j]; + } + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + char mm[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> mm[i][j]; } + } + int may = mm[0][0], mejor = 0, best = 0, cont = 0; + bool sw = true, sww = true, s = true; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (may != mm[i][j]) { + sww = false; + break; + } + } + } + if (sww && n != 1 && m != 1) + cout << n << endl; + else { + may = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + for (int k = 0; k < n; k++) { + if (mm[i][j] < mm[k][j] && s) s = false; + } + if (s) mejor++; + s = true; + } + if (mejor != 0) best++; + mejor = 0; + } + cout << best << endl; + } + return 0; +} +int m, x, y; +int c[110]; +int main() { + cin >> m; + for (int i = 1; i <= m; ++i) cin >> c[i]; + cin >> x >> y; + for (int i = 1; i <= m; ++i) { + int con1 = 0, con2 = 0; + for (int j = 1; j <= m; ++j) { + if (j < i) + con1 += c[j]; + else + con2 += c[j]; + } + if (con1 >= x && con1 <= y && con2 >= x && con2 <= y) { + cout << i << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +const int MOD = 998244353; +const int MAX = 900001; +int mmin = 0xc0c0c0c0; +int mmax = 0x3f3f3f3f; +int An[MAX]; +int book[MAX]; +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> An[i]; + sum += An[i]; + } + sort(An, An + n, less()); + long long t = sum; + for (int i = 0; i < n - 1; i++) { + t -= An[i]; + sum += t + An[i]; + } + cout << sum << endl; + return 0; +} +int main() { + int a, b, n; + cin >> n; + string s, t; + cin >> s >> t; + int ans = 0; + for (int i = 0; i < n; i++) { + a = s[i] - '0', b = t[i] - '0'; + if (a < b) { + ans += min(b - a, 10 - b + a); + } else { + ans += min(a - b, 10 - a + b); + } + } + cout << ans << endl; +} +int t = 1, sum, n, a, b, c; +int main() { + cin >> n >> a >> b >> c; + for (int i = 1; i < n; i++) { + if (t == 1) { + if (a <= b) { + t = 2; + sum += a; + continue; + } else { + t = 3; + sum += b; + continue; + } + } + if (t == 2) { + if (a <= c) { + t = 1; + sum += a; + continue; + } else { + t = 3; + sum += c; + continue; + } + } + if (t == 3) { + if (b <= c) { + t = 1; + sum += b; + continue; + } else { + t = 2; + sum += c; + continue; + } + } + } + cout << sum << endl; + return 0; +} +int a[105], b[105][105]; +int main() { + int n, m, x, y; + cin >> n >> m; + memset(b, 0, sizeof(b)); + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= m; i++) { + cin >> x >> y; + b[x][y] = b[y][x] = 1; + } + int sum = 3000001; + for (int i = 1; i <= n - 2; i++) { + for (int j = i + 1; j <= n - 1; j++) { + for (int k = j + 1; k <= n; k++) { + if (b[i][j] == 1 && b[i][k] == 1 && b[j][k] == 1) { sum = min(sum, a[i] + a[j] + a[k]); } + } + } + } + if (sum == 3000001) + cout << -1 << endl; + else + cout << sum << endl; + return 0; +} +stack s; +int main() { + long long ans = 0, cnt = 0; + int n, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + cnt = 0; + while (!s.empty() && s.top() != x) { + cnt++; + s.pop(); + } + if (s.empty() || s.top() == x) s.push(x); + ans += (cnt - 1) * cnt / 2; + } + cnt = 0; + while (!s.empty()) { + cnt++; + s.pop(); + } + ans += (cnt - 1) * cnt / 2; + ans += n; + cout << ans << endl; + return 0; +} +int main() { + int num; + int arr[14] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777}; + cin >> num; + for (int i = 0; i < 14; i++) { + if (num % arr[i] == 0) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + long long n, m, a; + while (cin >> n >> m >> a) cout << ((n + a - 1) / a) * ((m + a - 1) / a) << endl; + return 0; +} +int main() { + int n, m, i, j, q; + long long int a[400], s[400]; + while (cin >> n >> m) { + q = 0; + for (i = 1; i <= m; i++) { + cin >> s[i]; + a[i] = s[i] % n; + } + for (i = 1; i <= m; i++) { + for (j = 1; j < i; j++) { + if (a[j] == a[i]) { + q = i; + break; + } else { + q = 0; + } + } + if (q != 0) break; + } + if (q != 0) { + cout << q << endl; + } else { + cout << "-1" << endl; + } + } + return 0; +} +int main() { + long long n, x, i, j, sum = 0, p = 1, mod = 1e9 + 7, nCr[1005][1005]; + cin >> n; + nCr[0][0] = 1; + for (i = 1; i < 1005; i++) { + nCr[i][0] = 1; + for (j = 1; j <= i; j++) { nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod; } + } + do { + cin >> x; + sum += x; + p = (p * nCr[sum - 1][x - 1]) % mod; + n--; + } while (n > 0); + cout << p << endl; + return 0; +} +void Doaa() {} +int main() { + Doaa(); + int n, x, v[1000005] = {0}; + cin >> n; + for (int i = 0; i < n - 1; i++) { + cin >> x; + v[x] = 1; + } + for (int i = 1; i < n; i++) + if (v[i] == 0) return cout << i << endl, 0; + cout << n << endl; +} +int main() { + int n, i, j, k, l, t, r, e = 0, q = 0; + string s; + cin >> s; + t = s.size(); + for (i = 0; i < t; i++) { + l = 0, q = 0; + for (j = i; j < t; j++) { + if (s[j] == '(') { + l++; + } else if (s[j] == ')') { + if (l) { + l--; + } else if (q) { + l++; + q--; + } else + break; + } else { + if (l) { + l--; + q++; + } else + l++; + } + if (l == 0) { e++; } + } + } + cout << e << endl; + return 0; +} +double max(double a, double b) { + return a > b ? a : b; +} +int val(int n) { + return (n * (n + 1)) / 2; +} +bool check(int k, int n_problems) { + int t = val(n_problems); + int time_left = (240 - k) / 5; + return time_left >= t; +} +int res(int n, int k) { + for (int i = n; i > 0; i--) { + if (check(k, i) == true) return i; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + cout << res(n, k) << "\n"; +} +int main() { + int a[10][10]; + for (int i = 0; i < 10; i++) + for (int j = 0; j < 10; j++) a[i][j] = 1; + for (int i = 1; i < 10; i++) + for (int j = 1; j < 10; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + int n; + cin >> n; + cout << a[n - 1][n - 1] << endl; +} +int main() { + int n; + int ats = 0; + int current = 0; + int last = -1; + cin >> n; + for (int i = 0; i < n; i++) { + int sk; + cin >> sk; + if (sk > last) { + current++; + ats = max(ats, current); + } else + current = 1; + last = sk; + } + cout << ats << endl; + return 0; +} +int a[601]; +int main() { + int n, k = 0, x, ans = 0; + cin >> n; + while (k < n) { + cin >> x; + a[x] = 1; + k = k + 1; + } + k = 1; + while (k <= 600) { + if (a[k] == 1) ans = ans + 1; + k = k + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + if (i % 4 == 3) { + if (j == 0) + cout << '#'; + else + cout << '.'; + } else if (i % 4 == 1) { + if (j == y - 1) + cout << '#'; + else + cout << '.'; + } else + cout << '#'; + } + cout << endl; + } + return 0; +} +bool f(int n) { + while (n > 0) { + if (n % 10 == 7) return true; + n /= 10; + } + return false; +} +int main() { + int x, h, m; + cin >> x >> h >> m; + if (f(h) || f(m)) + cout << 0 << endl; + else { + int ans = 0; + while (f(h) != true && f(m) != true) { + m -= x; + if (m < 0) { + h--; + if (h < 0) h = 23; + m = 60 + m; + } + ans++; + } + cout << ans << endl; + } + return 0; +} +string S, T, P; +int n, a; +int main() { + cin >> n >> S; + for (int i = 1; i <= n; i++) { cin >> T; } + if (n % 2) + cout << "contest\n"; + else + cout << "home\n"; +} +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + char c = s[i]; + for (int j = 0; j < 26; j++) { + if ('a' + j == c) { continue; } + s[i] = 'a' + j; + int k; + for (k = 0; k < s.size(); k++) { + if (s[k] != s[s.size() - 1 - k]) { break; } + } + if (k == s.size()) { + cout << "YES" << endl; + return 0; + } + } + s[i] = c; + } + cout << "NO" << endl; + return 0; +} +char board[8 + 2][8 + 2]; +int main() { + for (int i = 0; i < 8; i++) cin >> board[i]; + int bestw = 8, bestb = 8; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (board[j][i] != '.') { + if (board[j][i] == 'W') bestw = min(bestw, j); + break; + } + } + for (int j = 7; j >= 0; j--) { + if (board[j][i] != '.') { + if (board[j][i] == 'B') bestb = min(bestb, 7 - j); + break; + } + } + } + if (bestw <= bestb) + cout << 'A' << endl; + else + cout << 'B' << endl; +} +int main() { + char arr1[3] = {'(', '[', '8'}, arr2[3] = {'8', '(', '['}; + string str1, str2; + cin >> str1 >> str2; + int p1 = 0, p2 = 0; + for (int i = 0; i < str1.size(); i += 2) { + for (int j = 0; j < 3; j++) + if (arr1[j] == str1[i]) { + if (arr2[j] == str2[i]) + p1++; + else if (str1[i] != str2[i]) + p2++; + break; + } + } + if (p1 > p2) + cout << "TEAM 1 WINS" << endl; + else if (p2 > p1) + cout << "TEAM 2 WINS" << endl; + else + cout << "TIE" << endl; +} +int main() { + int ans = 0, a[1002], n, i; + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 2; i < n; i++) { + if (a[i] > a[i + 1] && a[i] > a[i - 1]) { + ans++; + } else if (a[i] < a[i + 1] && a[i] < a[i - 1]) { + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + cout << (s.length() + 1) * 25 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << 0 << endl; + else + cout << 1 << endl; + return 0; +} +int d[1000 + 10]; +int s[1000 + 10]; +int m; +int k; +int main() { + while (cin >> m >> k) { + int big = -1; + int etime = 0; + int liter = 0; + int load = 0; + for (int i = 1; i <= m; i++) { + cin >> d[i]; + etime += d[i]; + } + for (int i = 1; i <= m; i++) { cin >> s[i]; } + for (int i = 1; i <= m; i++) { + if (s[i] >= big) { + if (load <= liter) { + liter -= load; + } else { + etime += ceil(double(load - liter) / double(big)) * k; + liter = liter + ceil(double(load - liter) / double(big)) * big - load; + } + big = s[i]; + liter += s[i]; + load = d[i]; + } else { + load += d[i]; + liter += s[i]; + } + } + if (load <= liter) { + liter -= load; + } else { + etime += ceil(double(load - liter) / double(big)) * k; + liter = liter + ceil(double(load - liter) / double(big)) * big - load; + } + cout << etime << endl; + } + return 0; +} +int niz[200005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= 2 * n; i++) { cin >> niz[i]; } + sort(niz + 1, niz + 2 * n + 1); + int dx = niz[n] - niz[1]; + int dy = niz[2 * n] - niz[n + 1]; + long long int p = 0; + p = (long long int)dx * dy; + long long int tren = 0; + for (int i = n + 1; i <= 2 * n - 1; i++) { + tren = (long long int)(niz[i] - niz[i - n + 1]) * (niz[2 * n] - niz[1]); + if (tren < p) p = tren; + } + cout << p << endl; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + int cnt = 0; + int ans = 0; + for (int i = 0; i < d; i++) { + string s; + cin >> s; + if (count(s.begin(), s.end(), '1') < n) { + cnt++; + } else { + cnt = 0; + } + ans = max(ans, cnt); + } + cout << ans << '\n'; + return 0; +} +long long MOD = 1e9 + 7; +long long dp[1100][1100], a[1010], s[1010]; +int inv[1100]; +int main() { + int n; + inv[1] = 1; + for (int i = 2; i < 1010; i++) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; + while (cin >> n) { + for (int i = n; i >= 1; i--) cin >> a[i]; + for (int i = 1; i <= n; i++) dp[i][0] = 0, dp[0][i] = 1; + s[0] = 0; + for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; + for (int i = 1; i <= s[n]; i++) { + for (int j = 1; j <= min(i, n); j++) { dp[i][j] = dp[i - 1][j] * (s[j] - i + 1) % MOD + dp[i - 1][j - 1] * a[j] % MOD; } + } + for (int i = 1; i <= n; i++) { + for (int j = 2; j <= a[i]; j++) dp[s[n]][n] = dp[s[n]][n] * inv[j] % MOD; + } + cout << dp[s[n]][n] << endl; + } + return 0; +} +int main() { + int n; + int l, r; + int vis[101]; + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + cin >> l >> r; + for (int i = l + 1; i <= r; i++) { vis[i] = 1; } + int x, y; + for (int i = 1; i <= n - 1; i++) { + cin >> x >> y; + for (int j = x + 1; j <= y; j++) { vis[j] = 0; } + } + int cnt = 0; + for (int i = l + 1; i <= r; i++) { cnt += vis[i]; } + cout << cnt << endl; + } +} +int main() { + int n, k, f, t, res = 0; + cin >> n >> k; + vector v; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) + v.push_back(f - (t - k)); + else + v.push_back(f); + } + res = v[0]; + for (int i = 0; i < v.size(); i++) { res = max(res, v[i]); } + cout << res << endl; + return 0; +} +long long int f(long long int a, long long int b) { + long long int s = 0; + while (a != 0 && b != 0) { + long long int p = a >= b ? a : b; + long long int q = a >= b ? b : a; + s += (p / q); + p %= q; + a = p; + b = q; + } + return s; +} +int main() { + long long int n, x, y; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + cin >> x >> y; + v.push_back(f(x, y)); + } + for (int i = 0; i < n; i++) cout << v[i] << endl; + return 0; +} +int main() { + int x; + int i, k1 = 0, j, k2 = 0, k3 = 0; + int a[100], n; + char s[20000][20]; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + if (i % 3 == 0) k1 += a[i]; + if (i % 3 == 1) k2 += a[i]; + if (i % 3 == 2) k3 += a[i]; + } + x = max(k1, max(k2, k3)); + if (k1 == x) cout << "chest" << endl; + if (k2 == x) cout << "biceps" << endl; + if (k3 == x) cout << "back" << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a, b, c, d; + int sum = 0; + while (n--) { + cin >> a >> b >> c >> d; + sum += (c - a + 1) * (d - b + 1); + } + cout << sum << endl; + } + return 0; +} +int A[100001]; +bool vis[5001]; +vector v; +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long ans = s / c; + long long A = ans; + A /= a; + A *= b; + ans += A; + v.push_back(ans); + } + for (int i = 0; i < v.size(); i++) cout << v[i] << "\n"; +} +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + long long a, b, t, t1, t2; + cin >> a >> b; + bool f = 0; + if (a > b) + t = a * b / gcd(a, b); + else + t = a * b / gcd(b, a); + if (a < b) { + t1 = t / a - 1; + t2 = t / b; + } else if (a > b) { + t1 = t / a; + t2 = t / b - 1; + } else + f = 1; + if (t1 > t2 && f == 0) + cout << "Dasha" << endl; + else if (t1 < t2 && f == 0) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + return 0; +} +int main() { + string n = "", m = ""; + int i, j, a, b = 0, c = 0, d = 0, e = 0, mn = 0, s = 0; + cin >> a; + cin >> n; + cin >> m; + for (i = 0; i < n.size(); i++) { + for (j = 0; j < m.size(); j++) { + if (i == j) { + b = abs(n[i] - m[j]); + c = abs((n[i] + 10) - m[j]); + d = abs(m[j] - n[i]); + e = abs(m[j] + 10 - n[i]); + mn = min(b, min(c, min(d, e))); + s = s + mn; + b = 0; + c = 0; + d = 0; + e = 0; + mn = 0; + } + } + } + cout << s << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n < m) { + cout << n << endl; + return 0; + } else { + int d = n / m; + int t = d + n; + int d2 = t / m; + while ((d2 - d) != 0) { + t += (d2 - d); + int temp; + temp = d2; + d = temp; + d2 = t / m; + } + cout << t << endl; + return 0; + } +} +char a[1000][1000]; +int main() { + int n; + cin >> n; + getchar(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { a[i][j] = '*'; } + } + int k = 0; + for (int i = n / 2; i >= 1; i--) { + for (int j = i; j < n - i; j++) { a[k][j] = 'D'; } + k++; + } + k = (n / 2) + 1; + for (int i = 1; i <= n / 2; i++) { + for (int j = i; j < n - i; j++) { a[k][j] = 'D'; } + k++; + } + for (int i = 0; i < n; i++) { a[n / 2][i] = 'D'; } + for (int i = 0; i < n; i++) { cout << a[i] << endl; } + return 0; +} +bool ispalin(string str) { + long long l = 0; + long long h = str.size() - 1; + while (h > l) { + if (str[l++] != str[h--]) return 0; + } + return 1; +} +void isprime(long long n) { + bool prime[n + 1]; + memset(prime, true, sizeof(prime)); + for (long long p = 2; p * p <= n; p++) { + if (prime[p] == true) + for (long long i = p * p; i <= n; i += p) prime[i] = false; + } + for (long long p = 2; p <= n; p++) + if (prime[p]) cout << p << " "; +} +int main() { + long long test = 1; + cin >> test; + while (test--) { + string str; + cin >> str; + long long n = str.size(); + if (n <= 10) + cout << str << endl; + else { + cout << str[0] << n - 2 << str[n - 1] << endl; + } + } + return 0; +} +int a[1001] = {0}; +int main() { + int n, c = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + a[i] = -1; + c++; + } else + a[i] = 1; + } + int ans = a[0], maxx = a[0]; + for (int i = 1; i < n; i++) { + maxx = max(a[i], maxx + a[i]); + ans = max(ans, maxx); + } + cout << c + ans << endl; +} +int a[105]; +int main() { + int n, s, h, m, flag = 0; + cin >> n >> s; + for (int i = 0; i < n; i++) { + cin >> h >> m; + a[i] = h * 60 + m; + } + for (int i = 0; i < 10000; i++) { + int flag = 0; + ; + for (int j = 0; j < n; j++) { + if (abs(a[j] - i) <= s) flag = 1; + } + if (flag == 0) { + cout << i / 60 << " " << i % 60 << endl; + break; + } + } +} +char ch[] = {'h', 'e', 'l', 'l', 'o'}; +string str; +int i = 0; +int main() { + cin >> str; + for (int j = 0; j < str.length(); j++) { + if (str[j] == ch[i]) i++; + if (i == 5) break; + } + if (i == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int len, k, i, x, y, flag = 0; + cin >> len >> k; + char a[105]; + cin >> a; + for (i = 0; i < len; i++) { + if (a[i] == 'G') { x = i; } + if (a[i] == 'T') { y = i; } + } + if (x < y) { + for (i = x; i < len; i += k) { + if (a[i] == '#') { + flag = 0; + break; + } + if (a[i] == 'T') { + flag = 1; + break; + } + if (i > y) { + flag = 0; + break; + } + } + } else { + for (i = x; i >= 0; i -= k) { + if (a[i] == '#') { + flag = 0; + break; + } + if (a[i] == 'T') { + flag = 1; + break; + } + if (i < y) { + flag = 0; + break; + } + } + } + if (flag == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char a[101], b[101]; + gets(a); + for (int i = 0; a[i] != '\0'; i++) a[i] = tolower(a[i]); + gets(b); + for (int i = 0; b[i] != '\0'; i++) b[i] = tolower(b[i]); + if (strcmp(a, b) < 0) + cout << -1 << endl; + else if (strcmp(a, b) == 0) + cout << 0 << endl; + else if (strcmp(a, b) > 0) + cout << 1 << endl; + return 0; +} +int main() { + long long n, a[100005], sum = 0, cnt = 1; + cin >> n; + for (long long i = 1; i <= n; i++) { + cin >> a[i]; + if (a[1] == 0) a[0] = 1; + if (a[i] == a[i - 1]) { + sum += cnt; + cnt++; + } else + cnt = 1; + } + n = n + sum; + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x1, y1; + cin >> x1 >> y1; + int x2, y2; + cin >> x2 >> y2; + int x3, y3; + cin >> x3 >> y3; + if (x2 < x1 && y2 < y1 && x3 < x1 && y3 < y1) + cout << "YES" << endl; + else if (x2 > x1 && y2 > y1 && x3 > x1 && y3 > y1) + cout << "YES" << endl; + else if (x2 > x1 && x3 > x1 && y3 < y1 && y2 < y1) + cout << "YES" << endl; + else if (x2 < x1 && x3 < x1 && y2 > y1 && y3 > y1) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long n, ans = 2; + cin >> n; + if (n == 1) { + cout << 1 << endl; + return 0; + } + if (n == 2 || n == 3) { + cout << 2 << endl; + return 0; + } + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int num = n % 10; + if (num == 0) { + cout << n << endl; + } else if (num <= 5) { + cout << (n - num) << endl; + } else { + cout << (n - num + 10) << endl; + } +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k; + long long n, m, x, y; + cin >> x >> y; + n = abs(x); + m = abs(y); + n += m; + if (x > 0 && y > 0) + cout << 0 << ' ' << n << ' ' << n << ' ' << 0 << endl; + else if (x > 0 && y < 0) + cout << 0 << ' ' << -n << ' ' << n << ' ' << 0 << endl; + else if (x < 0 && y > 0) + cout << -n << ' ' << 0 << ' ' << 0 << ' ' << n << endl; + else + cout << -n << ' ' << 0 << ' ' << 0 << ' ' << -n << endl; + return 0; +} +const int maxn = 1e5 + 10; +bool mark[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + mark[x] = 1; + } + for (int i = 1; i <= n; i++) { + if (mark[i] == 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, l, r, Ql, Qr; + cin >> n >> l >> r >> Ql >> Qr; + vector w(n + 1); + for (int i = 1; i <= n; i++) cin >> w[i]; + if (l < r) { + int L = (n % 2 == 0) ? n / 2 : n / 2 + 1; + int ql = (n % 2 == 0) ? 1 : 2; + int smL = 0, smR = 0; + for (int i = 1; i <= L; i++) smL += l * w[i]; + for (int i = L + 1; i <= n; i++) smR += r * w[i]; + int ans = smL + smR; + while (true) { + if (L == n) break; + smL += l * w[L + 1] + Ql * ql; + smR -= r * w[L + 1]; + L++; + ql = 2; + ans = min(ans, smL + smR); + } + cout << ans << endl; + } else { + int R = n / 2 + 1; + int qr = (n % 2 == 0) ? 1 : 2; + int smL = 0, smR = 0; + for (int i = 1; i <= R - 1; i++) smL += l * w[i]; + for (int i = R; i <= n; i++) smR += r * w[i]; + int ans = smL + smR; + while (true) { + if (R == 1) break; + smR += r * w[R - 1] + Qr * qr; + smL -= l * w[R - 1]; + R--; + qr = 2; + ans = min(ans, smL + smR); + } + cout << ans << endl; + } + cin.get(); +} +int ans[3][3]; +void change(int i, int j) { + if (i >= 0 && j >= 0 && i < 3 && j < 3) { + if (ans[i][j]) { + ans[i][j] = 0; + } else { + ans[i][j] = 1; + } + } +} +int main() { + int arr[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> arr[i][j]; + arr[i][j] = arr[i][j] % 2; + } + } + fill(&ans[0][0], &ans[0][0] + sizeof(ans), 1); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (arr[i][j]) { + change(i, j); + change(i + 1, j); + change(i, j + 1); + change(i - 1, j); + change(i, j - 1); + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << ans[i][j]; } + cout << endl; + } +} +const int M = 100010; +int n, mark[M], mark0[M], no[M]; +char c, s[M]; +int f1 = 0, f2 = 0, have = 26, ok = 0, ans = 0; +int main() { + memset(mark0, 0, sizeof(mark0)); + memset(mark, 0, sizeof(mark)); + memset(no, 0, sizeof(no)); + for (int i = 97; i <= 122; i++) mark[i] = 1; + int l; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> c >> s; + f2++; + l = strlen(s); + if (c == '!') { + f1++; + if (ok == 1) { + ans++; + continue; + } + if (f1 == 1) { + have = 0; + for (int i = 97; i <= 122; i++) mark[i] = 0; + for (int i = 0; i < l; i++) { + if (!mark[s[i]] && !no[s[i]]) { + have++; + mark[s[i]] = 1; + } + } + if (have == 1) ok = 1; + } else { + memset(mark0, 0, sizeof(mark0)); + for (int i = 0; i < l; i++) mark0[s[i]] = 1; + for (int i = 97; i <= 122; i++) + if (mark[i] && !mark0[i]) { + mark[i] = 0; + have--; + if (have == 1) ok = 1; + } + } + } + if (c == '?') { + if (f2 == n) continue; + if (ok == 1) { + ans++; + continue; + } + no[s[0]] = 1; + if (mark[s[0]] == 1) { + mark[s[0]] = 0; + have--; + if (have == 1) ok = 1; + } + } + if (c == '.') { + if (ok == 1) continue; + for (int i = 0; i < l; i++) + if (mark[s[i]] == 1) { + no[s[i]] = 1; + mark[s[i]] = 0; + have--; + if (have == 1) ok = 1; + } + } + } + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; i++) { + if (i % 4 == 1) { + for (int j = 0; j < m; j++) { + if (j == m - 1) { + arr[i][j] = '#'; + } else + arr[i][j] = '.'; + } + } else if (i % 4 == 3) { + for (int j = 0; j < m; j++) { + if (j == 0) { + arr[i][j] = '#'; + } else { + arr[i][j] = '.'; + } + } + } else { + for (int j = 0; j < m; j++) arr[i][j] = '#'; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << arr[i][j]; } + cout << endl; + } +} +int main() { + int stick[11] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n, x; + cin >> n; + int n1, n2; + n1 = (n % 10); + n2 = (n / 10); + x = stick[n1] * stick[n2]; + cout << x << endl; + return 0; +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + int flag = 0; + for (int i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + flag = 1; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +vector v; +int main() { + long long n; + cin >> n; + long long sum = 1; + v.push_back(1); + while (sum < n) { + long long cur = v[v.size() - 1] << 1; + v.push_back(cur); + sum += cur; + } + cout << v.size() << endl; + return 0; +} +const long long mod = 1000000009; +long long mpow(long long a, int k) { + long long res = 1; + while (k) { + if (k & 1) { res = res * a % mod; } + a = a * a % mod; + k >>= 1; + } + return res; +} +int main() { + int n, m; + cin >> n >> m; + long long res = 1; + for (int i = 0; i < n; ++i) + { + res *= mpow(2, m) - 1 - i; + res %= mod; + } + cout << res << endl; +} +bool check(long long i, long long n) { + long long temp = i; + long long sum = 0; + while (temp > 0) { + sum += temp % 10; + temp /= 10; + } + return i + sum == n; +} +int main() { + long long n; + cin >> n; + vector ans; + for (long long i = max(n - 82, 0ll); i < n; i++) { + if (check(i, n)) ans.push_back(i); + } + cout << ans.size() << endl; + for (long long i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } +} +const int mod = 1e9 + 7; +signed long long int modularExponentiation(signed long long int x, signed long long int n, signed long long int M) { + signed long long int result = 1; + while (n > 0) { + signed long long int power = n; + if (power % 2 == 1) result = (result * x) % M; + x = (x * x) % M; + n = n / 2; + } + return result; +} +signed long long int ceil(signed long long int n, signed long long int x) { + if (n % x == 0) + return n / x; + else { + return ((n / x) + 1); + } +} +int main() { + signed long long int sum, x; + cin >> sum >> x; + signed long long int a = (sum - x) / 2; + if (a < 0 || 2 * a + x != sum || (x & a) != 0) { + cout << 0 << "\n"; + exit(0); + } + signed long long int bits = 0, temp = 0; + temp = x; + while (temp > 0) { + bits += temp & 1; + temp >>= 1; + } + signed long long int ans = 1LL << bits; + if (a == 0) { ans -= 2; } + cout << ans << "\n"; + return 0; +} +bool isyuan(char c) { + if (c == 'a' || c == 'o' || c == 'u' || c == 'i' || c == 'e') + return 1; + else + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; i++) { + if (isyuan(s[i]) || s[i] == 'n') + continue; + else { + if (!isyuan(s[i + 1])) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + cout << min(b * (n % m), a * (((n / m) + 1) * m - n)) << endl; +} +int main() { + int n; + cin >> n; + int x = 0, y = 0, z = 0; + for (int i = 0; i < n; i++) { + int a, b, c; + cin >> a >> b >> c; + x += a; + y += b; + z += c; + } + if (x == 0 && y == 0 && z == 0) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const long long mod = 1000000007; +long long n, f[1000007]; +int main() { + int i; + cin >> n; + f[1] = 1; + f[2] = 3; + for (i = 3; i <= n; i++) { f[i] = (f[i - 1] + f[i - 2] + 2) % mod; } + cout << f[n] << endl; + return 0; +} +int main() { + int n, a, b, way; + cin >> n >> a >> b; + int *chore = new int[n]; + for (int i = 0; i < n; i++) cin >> chore[i]; + sort(chore, chore + n); + int j = n - 1; + while (j > n - a) { j--; } + if (chore[j] == chore[j - 1]) + cout << 0 << "\n"; + else + cout << chore[j] - chore[j - 1] << "\n"; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if ((p == q && x == y) || (p == 0 && x == 0)) { + cout << 0 << endl; + continue; + } + if ((p == q && x != y) || (p == 0 && x != 0)) { + cout << -1 << endl; + continue; + } + long long l = 0, r = 1e10; + long long b = y / q * q; + if (y % q) b += q; + for (int id = 0; id < 100; id++) { + long long mid = (l + r) / 2; + long long temp = p * b / q + mid * p; + if (temp >= x && temp <= (x + mid * q + b - y)) + r = mid; + else + l = mid; + } + cout << b + r * q - y << endl; + } + return 0; +} +int main() { + int n, k, f, t; + cin >> n >> k; + int maxJ = INT_MIN, joy; + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) { + joy = f - t + k; + if (joy > maxJ) maxJ = joy; + } else { + if (f > maxJ) maxJ = f; + } + } + cout << maxJ << endl; +} +ifstream infile; +ofstream outfile; +long double a[2 * 2005], dp[2 * 2005][2005]; +int n; +int OpenFile() { + infile.open("input.txt", ios::in); + outfile.open("output.txt", ios::out); + if (infile.fail()) { + cout << "Khong mo duoc file input !" << endl; + return -1; + } + if (outfile.fail()) { + cout << "khong mo duoc file output!" << endl; + return -1; + } +} +void input() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; +} +void init() { + for (int i = 0; i <= 2 * n; i++) + for (int j = 0; j <= n; j++) dp[i][j] = INT_MAX; + dp[0][0] = 0; +} +void process() { + for (int i = 1; i <= 2 * n; i++) { + for (int j = 0; j <= min(i, n); j++) { + long double val1 = INT_MAX, val2 = INT_MAX; + if (j > 0) val1 = dp[i - 1][j - 1] + ceil(a[i]) - a[i]; + if ((i - j) <= n) val2 = dp[i - 1][j] + floor(a[i]) - a[i]; + dp[i][j] = val1; + if (fabs(val2) < fabs(val1)) dp[i][j] = val2; + } + } +} +void output() { + cout << fixed << setprecision(3) << fabs(dp[2 * n][n]) << endl; +} +void in() { + for (int i = 0; i <= 2 * n; i++) { + for (int j = 0; j <= n; j++) { + if (dp[i][j] == INT_MAX) + cout << 999999 << " "; + else if (dp[i][j] >= 0) + cout << " " << dp[i][j] << " "; + else + cout << dp[i][j] << " "; + } + cout << endl; + } +} +int main() { + input(); + init(); + process(); + output(); +} +int main() { + int x, y; + int i = 0; + for (int x = 1; x <= 5; x++) { + for (int y = 1; y <= 5; y++) { + cin >> i; + if (i == 1) { cout << abs(x - 3) + abs(y - 3) << endl; } + } + } +} +int main() { + int n, h, a, b, k, s; + cin >> n >> h >> a >> b >> k; + int t1, f1, t2, f2; + for (int i = 0; i < k; i++) { + s = 0; + cin >> t1 >> f1 >> t2 >> f2; + if (t2 > t1) { + if (f1 <= b && f1 >= a) { + s = s + t2 - t1; + if (f2 >= f1) { + s = s + f2 - f1; + } else { + s = s + f1 - f2; + } + } else if (f1 < a) { + s = s + t2 - t1 + a - f1; + if (f2 >= a) { + s = s + f2 - a; + } else { + s = s + a - f2; + } + } else if (f1 > b) { + s = s + t2 - t1 + f1 - b; + if (f2 >= b) { + s = s + f2 - b; + } else { + s = s + b - f2; + } + } + } else if (t1 > t2) { + if (f1 <= b && f1 >= a) { + s = s + t1 - t2; + if (f2 >= f1) { + s = s + f2 - f1; + } else { + s = s + f1 - f2; + } + } else if (f1 < a) { + s = s + t1 - t2 + a - f1; + if (f2 >= a) { + s = s + f2 - a; + } else { + s = s + a - f2; + } + } else if (f1 > b) { + s = s + t1 - t2 + f1 - b; + if (f2 >= b) { + s = s + f2 - b; + } else { + s = s + b - f2; + } + } + } else { + if (f2 >= f1) { + s = s + f2 - f1; + } else { + s = s + f1 - f2; + } + } + cout << s << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i, j, k; + for (i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (j = 0; j < m; j++) cout << "#"; + cout << "\n"; + } else if ((i / 2) % 2 != 0) { + for (j = 0; j < m - 1; j++) cout << "."; + cout << "#" + << "\n"; + } else { + cout << "#"; + for (j = 0; j < m - 1; j++) cout << "."; + cout << "\n"; + } + } + return 0; +} +int main() { + int p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; + int m, n, fl = 0; + cin >> m >> n; + for (int i = 0; i <= 16; i++) { + if (p[i] == m && p[i + 1] == n) fl = 1; + } + if (fl == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const long long N = 1110; +const long long Q = 2e18; +const long long mod = 1e9 + 7; +const long long MAGIC = 30; +int n; +int d1[200][200]; +int d2[200][200]; +void solve() { + cin >> n; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + d1[s.size()][s[s.size() - 1]]++; + } + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + d2[s.size()][s[s.size() - 1]]++; + } + int cnt = 0; + for (int i = 0; i < 200; i++) { + for (int j = 0; j < 200; j++) { cnt += max(0, d2[i][j] - d1[i][j]); } + } + cout << cnt << "\n"; +} +bool mtest = false; +int main() { + int TE = 1; + if (mtest) cin >> TE; + while (TE--) solve(); + return 0; +} +int main() { + int n, num[2][101], sum = 0; + cin >> n; + memset(num[0], 0, sizeof(num[0])); + memset(num[1], 0, sizeof(num[1])); + int h, a; + while (n--) { + cin >> h >> a; + num[0][h]++; + num[1][a]++; + } + for (int i = 1; i < 101; i++) { sum += num[0][i] * num[1][i]; } + cout << sum << endl; + return 0; +} +const int maxn = 1e7 + 5; +int n; +int x, y; +int cnt1; +int cnt2; +int main() { + cin >> n; + while (n--) { + cin >> x >> y; + if (x <= 0) + cnt1++; + else + cnt2++; + } + if (cnt1 > 1 && cnt2 > 1) + cout << "No" << endl; + else + cout << "Yes" << endl; + return 0; +} +int main() { + int q; + cin >> q; + long long u, v, w; + map a; + while ((q--) > 0) { + long long sum = 0; + int sel; + cin >> sel; + if (sel == 1) { + cin >> u >> v >> w; + while (u != v) { + if (u > v) { + a[u] += w; + u /= 2; + } else if (v > u) { + a[v] += w; + v /= 2; + } + } + } + if (sel == 2) { + cin >> u >> v; + while (u != v) { + if (u > v) { + sum += a[u]; + u /= 2; + } + if (v > u) { + sum += a[v]; + v /= 2; + } + } + cout << sum << endl; + } + } + return 0; +} +string s; +int cnt, ans, n; +bool f(char c) { + return (c - 'A' >= 0 && c - 'Z' <= 0); +} +int main() { + cin >> n; + while (cin >> s) { + cnt = 0; + for (int i = 0; i < s.length(); ++i) cnt += f(s[i]); + ans = max(ans, cnt); + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, ans; + while (cin >> n >> k) { + if (k / n == 2) { + ans = k % n; + cout << n - ans << endl; + } else + cout << "0" << endl; + } + return 0; +} +int r(int n) { + int m = 0, pow = 1; + while (n != 0) { + int d = n % 10; + n /= 10; + if (d != 0) { + m += d * pow; + pow *= 10; + } + } + return m; +} +int main() { + int a, b; + cin >> a >> b; + int c = a + b; + int A = r(a); + int B = r(b); + int C = r(c); + cout << (A + B == C ? "YES" : "NO") << endl; + return 0; +} +int main() { + unsigned long long n, a[1000005], t = 0, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (a[i] % 2 == 0) + ans += a[i]; + else { + t += a[i]; + if (t % 2 == 0) { + ans += t; + t = 0; + } + } + } + cout << ans << '\n'; +} +int main() { + int N; + int K; + cin >> N; + cin >> K; + int allA = 0; + int A[K]; + fill(A, A + K, 0); + int allB = 0; + int B[K]; + fill(B, B + K, 0); + for (int n = 0; n < N; n++) { + int s; + cin >> s; + if (s == 1) { + allA++; + for (int k = 0; k < K; k++) { + if ((n + k) % K == 0) A[k]++; + } + } else { + allB++; + for (int k = 0; k < K; k++) { + if ((n + k) % K == 0) B[k]++; + } + } + } + int m = -1; + for (int k = 0; k < K; k++) m = max(m, abs((allA - A[k]) - (allB - B[k]))); + cout << m << endl; + return 0; +} +const int maxn = 5e3 + 5; +const unsigned long long base = 311; +unsigned long long A[maxn]; +int main() { + int N; + cin >> N; + int a, b; + cin >> a >> b; + for (int i = (1); i <= (N); i += (1)) cin >> A[i]; + sort(A + 1, A + N + 1); + cout << A[b + 1] - A[b] << "\n"; + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0, len = s.size(); + for (int i = 0; i < len; i++) { + int cnt = 0, p = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + cnt++; + else if (s[j] == '?') + p++; + else + cnt--; + while (p > 0 && p > cnt) { + p--; + cnt++; + } + if (cnt < 0) break; + if ((j - i + 1) % 2 == 0 && p >= cnt) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, d; + double a; + cin >> n >> a >> d; + long long t[n], v[n]; + for (int i = 0; i < n; i++) cin >> t[i] >> v[i]; + long double T = 0; + for (int i = 0; i < n; i++) { + if (v[i] * v[i] >= 2 * a * d) { + T = max((long double)t[i] + sqrt((2.0 * d) / a), T); + } else { + long double t1 = v[i] / a; + long double s = (v[i] * v[i]) / (2 * a); + T = max(T, (long double)t[i] + t1 + ((d - s) / v[i])); + } + cout << setprecision(12) << T << endl; + } +} +const int INF = 2000000000; +const double EPS = 1e-9; +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == d1) { + w -= u1; + if (w < 0) w = 0; + } + if (i == d2) { + w -= u2; + if (w < 0) w = 0; + } + } + cout << w << '\n'; +} +char a[105], b[105]; +int gcd(int a, int b); +int main() { + cin >> a >> b; + if (!strcmp(a, b)) { + cout << a << endl; + } else + cout << 1 << endl; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + puts("1"); + return 0; +} +int main() { + int ans; + string c; + while (cin >> c) { + ans = 8; + if (c[0] == 'a' || c[0] == 'h') { + if (c[1] == '1' || c[1] == '8') + ans = 3; + else + ans = 5; + } else if (c[1] == '1' || c[1] == '8') + ans = 5; + cout << ans << endl; + } +} +const int MX = 1e5 + 7; +int n, m; +int x[MX]; +int x1[MX], x2[MX], y[MX]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> x[i]; + x[++n] = 1e9; + sort(x + 1, x + n + 1); + vector v; + for (int i = 1; i <= m; i++) { + cin >> x1[i] >> x2[i] >> y[i]; + if (x1[i] == 1) v.push_back(x2[i]); + } + sort(v.begin(), v.end()); + int sz = v.size(); + int ans = n + m; + for (int i = 1; i <= n; i++) { + int pos = lower_bound(v.begin(), v.end(), x[i]) - v.begin(); + ans = min(ans, i + sz - pos - 1); + } + cout << ans << "\n"; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +int main() { + char chess[8][8]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) cin >> chess[i][j]; + } + int movesA = 8; + int movesB = 8; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (chess[j][i] == 'B') break; + if (chess[j][i] == 'W') { + if (movesA > j) movesA = j; + break; + } + } + for (int j = 7; j >= 0; j--) { + if (chess[j][i] == 'W') break; + if (chess[j][i] == 'B') { + if (movesB > 7 - j) movesB = 7 - j; + break; + } + } + } + if (movesA <= movesB) + cout << "A" << endl; + else + cout << "B" << endl; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + int a[105], n, d, m; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + d = a[0]; + m = a[0]; + for (int i = 1; i < n; i++) { + d = gcd(d, a[i]); + m = max(m, a[i]); + } + int ans = (m - d) / d + 1 - n; + if (ans & 1) + cout << "Alice\n"; + else + cout << "Bob\n"; +} +int win[105]; +int a[105][105]; +int main() { + int n, m; + int maxn, maxnn; + int index, inindex; + while (cin >> n >> m) { + maxn = -1; + index = 0; + memset(win, 0, sizeof(win)); + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + for (int i = 0; i < m; i++) { + for (int j = n - 1; j >= 0; j--) { + if (a[i][j] >= maxn) { + maxn = a[i][j]; + index = j; + } + } + win[index]++; + maxn = -1; + } + maxnn = -1; + inindex = 0; + for (int i = n - 1; i >= 0; i--) { + if (win[i] >= maxnn) { + maxnn = win[i]; + inindex = i; + } + } + cout << inindex + 1 << endl; + } + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + int l = s.length(); + int g, t, diff; + bool found = false; + g = t = -10; + diff = 1; + for (int i = 0; i < l; i += diff) { + if (g == -10 && (s[i] == 'G' || s[i] == 'T')) { + g = i; + diff = k; + continue; + } + if (g != -10) { + if (s[i] == '#') { + cout << "NO" << endl; + found = true; + break; + } + if (s[i] == 'G' || s[i] == 'T') { + cout << "YES" << endl; + found = true; + break; + } + } + } + if (!found) cout << "NO" << endl; + return 0; +} +int main() { + int n; + int a[100005]; + while (cin >> n) { + map m; + for (int i = 0; i < n; i++) { + cin >> a[i]; + m[a[i]]++; + } + int flag = 0; + for (map::iterator it = m.begin(); it != m.end(); it++) { + if (it->second > 1) { + flag = -1; + break; + } else { + flag = it->first; + break; + } + } + if (flag == -1) { + cout << "Still Rozdil" << endl; + continue; + } + for (int i = 0; i < n; i++) { + if (a[i] == flag) { + flag = i + 1; + break; + } + } + cout << flag << endl; + } + return 0; +} +int v[256]; +int main() { + v['T'] = 4; + v['C'] = 6; + v['O'] = 8; + v['D'] = 12; + v['I'] = 20; + int n, res = 0; + cin >> n; + string s; + for (int i = 0; i < n; ++i) { + cin >> s; + res += v[s[0]]; + } + cout << res << endl; +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + int a[100005] = {0}; + int i; + for (i = 1; i <= d && k * i <= d; i++) { a[i * k] = 1; } + for (i = 1; i <= d && l * i <= d; i++) { a[i * l] = 1; } + for (i = 1; i <= d && m * i <= d; i++) { a[i * m] = 1; } + for (i = 1; i <= d && n * i <= d; i++) { a[i * n] = 1; } + int sum = 0; + for (i = 1; i <= d; i++) sum += a[i]; + cout << sum << endl; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + if (s.length() % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector V(n); + for (int i = 0; i < n - 1; ++i) { + int k; + cin >> k; + V[k - 1] = 1; + } + for (int i = 0; i < n; ++i) { + if (!V[i]) { + cout << i + 1 << "\n"; + return 0; + } + } + return 0; +} +int main() { + string s; + cin >> s; + string t[5]; + for (long long i = 0; i < 5; i++) { cin >> t[i]; } + long long found = 0; + for (long long i = 0; i < 5; i++) { + if (t[i][0] == s[0] || t[i][1] == s[1]) { + found = 1; + break; + } + } + if (found == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k, i, h = 0; + string l = "LEFT", r = "RIGHT", p = "PRINT ", s; + cin >> n >> k >> s; + if (n / 2 >= k) { + while (h != k - 1) { + h++; + cout << l << endl; + } + for (i = 0; i < n; i++) { + cout << p << s[i] << endl; + if (i != n - 1) cout << r << endl; + } + } else { + while (h != n - k) { + h++; + cout << r << endl; + } + for (i = n - 1; i >= 0; i--) { + cout << p << s[i] << endl; + if (i != 0) cout << l << endl; + } + } + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + int p = pow(2, n); + int r = m % p; + cout << r << endl; + return 0; +} +int main() { + int w, h, w1, h1, w2, h2; + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w < 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w < 0) w = 0; + } + } + cout << w << endl; +} +long long n; +int main() { + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + long long a, b; + n = abs(n); + a = (n / 10) % 10; + b = n % 10; + if (a > b) { + n = ((n - 10 * a) / 10) + b; + } else { + n -= b; + n /= 10; + } + n *= -1; + cout << n << endl; + } +} +int main() { + string s; + int ans = 0; + cin >> s; + int a = s[0] - 'a' + 1; + int b = s[1] - '0'; + if ((8 - b) > 0) ans++; + if ((b - 1) > 0) ans++; + if ((8 - a) > 0) ans++; + if ((a - 1) > 0) ans++; + if ((8 - b) > 0 && (8 - a) > 0) ans++; + if ((b - 1) > 0 && (a - 1) > 0) ans++; + if ((b - 1) > 0 && (8 - a) > 0) ans++; + if ((a - 1) > 0 && (8 - b) > 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + int a; + long long b; + cin >> a; + b = a * 1.5; + cout << b << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n / 2) * 3 << endl; +} +int main() { + int n; + cin >> n; + int ans = 1; + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) ans = i; + } + cout << ans << " " << n / ans << endl; + return 0; +} +int vis[109]; +int len[109]; +int main() { + int n; + cin >> n; + string w; + for (int i = 0; i < n; ++i) { + cin >> w; + for (int j = 0; j < w.length(); ++j) vis[i] |= 1 << (w[j] - 'a'); + len[i] = w.length(); + } + int mx = 0, sel; + for (int i = 0; i < 26; ++i) + for (int j = 0; j < 26; ++j) { + sel = 0; + int k = (1 << i) | (1 << j); + for (int u = 0; u < n; ++u) + if ((k & vis[u]) == vis[u]) sel += len[u]; + mx = max(mx, sel); + } + cout << mx << "\n"; +} +bool vowel(char a) { + if (a == 'a' || a == 'o' || a == 'e' || a == 'u' || a == 'i') return true; + return false; +} +int main() { + char s[105]; + cin >> s; + int len = strlen(s); + int i; + for (i = 0; i < len; i++) { + if (!vowel(s[i])) { + if (vowel(s[i + 1])) { + i++; + continue; + } + if (s[i] == 'n') { continue; } + if (!vowel(s[i + 1])) { + cout << "NO" << endl; + break; + } + } + } + if (i == len + 1 || i == len) cout << "YES" << endl; + return 0; +} +int main() { + int n, max, min, c = 0; + cin >> n; + int arr[n]; + cin >> arr[0]; + max = arr[0]; + min = arr[0]; + for (int i = 1; i < n; i++) { + cin >> arr[i]; + if (arr[i] < min) { + min = arr[i]; + c++; + } + if (arr[i] > max) { + max = arr[i]; + c++; + } + } + cout << c << endl; +} +int check(vector k) { + int count = 4; + for (int i = 0; i < k.size(); i++) { + for (int j = i + 1; j < k.size(); j++) { + if (k[i] == k[j]) { + count = 1; + break; + } + } + } + if (count == 4) { + return true; + } else { + return false; + } +} +int main() { + int n; + cin >> n; + for (int i = 1000; i <= 9000; i++) { + n++; + vector v; + int val = 0; + int k = n; + while (k != 0) { + val = k % 10; + v.push_back(val); + k /= 10; + } + if (check(v) == true) { + cout << n << endl; + return 0; + } else { + v.clear(); + } + } +} +char c[10005]; +string s; +int main() { + cin.getline(c, 10005); + int i = 0; + int lg = strlen(c); + bool ok = 0; + while (i < lg) { + if (isalpha(c[i])) { + if (ok == 0 && i != 0 && !isalpha(c[i - 1])) s += ' '; + s += c[i]; + ok = 0; + } else { + if (c[i] == '?' || c[i] == '!' || c[i] == ',' || c[i] == '.') s += c[i], s += ' ', ok = 1; + } + ++i; + } + cout << s << '\n'; + return 0; +} +long long spf[100001]; +long long gcd(long long a, long long b); +long long palindrome(string s); +long long modexp(long long a, long long b, long long m); +void sieve(); +long long ceil(long long a, long long b); +vector getFactorization(long long x); +void getZarr(string str, long long Z[]); +vector prefix_function(string s); +int main() { + long double n, x, y; + cin >> n >> x >> y; + long double ans = (n * y) / 100 - x; + if (ans < 0) ans = 0; + cout << ceil(ans) << endl; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + if (a == b) return a; + if (a > b) return gcd(a % b, b); + return gcd(a, b % a); +} +long long palindrome(string s) { + long long l = 0; + long long h = s.length() - 1; + while (h > l) { + if (s[l++] != s[h--]) { return 0; } + } + return 1; +} +long long modexp(long long a, long long b, long long m) { + if (b == 0) return 1; + long long temp = modexp(a, b / 2, m); + temp = (temp * temp) % m; + if (b & 1) return (temp * (a % m)) % m; + return temp; +} +void sieve() { + spf[1] = 1; + for (long long i = 2; i < 100001; i++) spf[i] = i; + for (long long i = 4; i < 100001; i += 2) spf[i] = 2; + for (long long i = 3; i * i < 100001; i++) { + if (spf[i] == i) { + for (long long j = i * i; j < 100001; j += i) + if (spf[j] == j) spf[j] = i; + } + } +} +vector getFactorization(long long x) { + vector ret; + while (x != 1) { + ret.push_back(spf[x]); + x = x / spf[x]; + } + return ret; +} +long long ceil(long long a, long long b) { + return a / b + (a % b != 0); +} +void getZarr(string str, long long Z[]) { + long long n = str.length(); + long long L, R, k; + L = R = 0; + for (long long i = 1; i < n; ++i) { + if (i > R) { + L = R = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } else { + k = i - L; + if (Z[k] < R - i + 1) + Z[i] = Z[k]; + else { + L = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } + } + } +} +vector prefix_function(string s) { + long long n = (long long)s.length(); + vector pi(n); + for (long long i = 1; i < n; i++) { + long long j = pi[i - 1]; + while (j > 0 && s[i] != s[j]) j = pi[j - 1]; + if (s[i] == s[j]) j++; + pi[i] = j; + } + return pi; +} +int main() { + int n, m, x, z; + cin >> n >> m; + map go; + for (int i = 0; i < n; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> z; + go[z]++; + } + } + for (int i = 1; i <= m; i++) { + if (go[i] == 0) { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int main() { + int n, b, p, k, ptot, btot; + cin >> n >> b >> p; + ptot = p * n; + btot = 0; + while (n > 1) { + k = 1 << ((int)floor(log2(n))); + n = n - (k / 2); + btot += ((k * b) + (k / 2)); + } + cout << btot << " " << ptot << "\n"; + return 0; +} +int n, s, r[50], c[50], ans; +int main() { + memset(r, 0, sizeof(r)); + memset(c, 0, sizeof(c)); + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> s; + c[j] += s; + r[i] += s; + } + } + ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (c[j] > r[i]) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + char ch = 'a'; + int l = s.length(), x, ans = 0; + for (int i = 0; i < l; i++) { + x = abs(s[i] - ch); + if (x > 13) { x = 26 - x; } + ans += x; + ch = s[i]; + } + cout << ans << endl; +} +int a[1001], n, m, minx = 0x3fff; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + int k; + cin >> k; + a[k]++; + } + for (int i = 1; i <= n; i++) minx = min(a[i], minx); + cout << minx << endl; + return 0; +} +vector v; +string name; +void make() { + string temp; + for (int i = 0; i < name.size(); i++) { + temp = name[i]; + v.push_back(temp); + for (int j = i + 1; j < name.size(); j++) { + temp = temp + name[j]; + v.push_back(temp); + } + } +} +int main() { + int i, j; + cin >> name; + make(); + string temp; + string record; + long long ma = 0; + for (i = 0; i < v.size(); i++) { + long long pos = name.find(v[i]); + long long counter = 1; + while (pos != name.size()) { + pos = name.find(v[i], pos + 1); + if (pos > name.size()) break; + counter++; + } + if (counter > 1) ma = max(ma, (long long)v[i].size()); + } + cout << ma << "\n"; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n >= 22) { cout << "0" << endl; } + if (n >= 11 && n <= 19) { cout << "4" << endl; } + if (n == 20) { cout << "15" << endl; } + if (n == 21) { cout << "4" << endl; } + return 0; +} +int main() { + long long n, p, q, b; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p >> q >> b; + long long t = __gcd(p, q); + q /= t; + t = b; + while (q != 1) { + t = __gcd(q, t); + q /= t; + if (t == 1) break; + } + if (q == 1) + cout << "Finite\n"; + else + cout << "Infinite\n"; + } +} +void File() { + freopen("output.txt", "w", stdout); + freopen("input.txt", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 1e5 + 4; +const int oo = 0x3f3f3f3f; +long long nCr(long long n, long long r) { + if (n < r) return 0; + if (r == 0) return 1; + return n * nCr(n - 1, r - 1) / r; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + fast(); + string s; + getline(cin, s); + vector arr; + if (s[0] >= 'a' && s[0] <= 'z') arr.push_back(s[0]); + for (int i = 1; i < ((int)((s).size())); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + if (s[i - 1] >= 'a' && s[i - 1] <= 'z') + arr.push_back(s[i]); + else + arr.push_back(' '), arr.push_back(s[i]); + } else if (s[i] == ' ') + continue; + else + arr.push_back(s[i]); + } + for (int i = 0; i < ((int)((arr).size())); i++) cout << arr[i]; + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int k = (2 * sum) / n + 1; + sort(a, a + n); + if (k >= a[n - 1]) + cout << k << endl; + else + cout << a[n - 1] << endl; +} +int main() { + double n, x, y; + cin >> n >> x >> y; + int temp = x; + while ((x / n) * 100 < y) { x++; } + cout << x - temp << endl; +} +int arr[100005], lft[100005], rht[100005]; +int main() { + int n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + for (int i = 0; i < n; i++) cin >> arr[i], lft[i] = arr[i], rht[i] = arr[i]; + for (int i = 1; i < n; i++) lft[i] += lft[i - 1]; + for (int i = n - 2; i >= 0; i--) rht[i] += rht[i + 1]; + long long mn = LLONG_MAX; + for (int i = 0; i <= n; i++) { + long long cost = (i > 0 ? l * lft[i - 1] : 0) + (i < n ? r * rht[i] : 0); + if (i > n - i) + cost += (2 * i - n - 1) * ql; + else if (i < n - i) + cost += (n - 2 * i - 1) * qr; + mn = min(cost, mn); + } + cout << mn << endl; + return 0; +} +int main() { + int i, j, n, sum = 0, zero = 0, m, flag = 0, x, y; + cin >> n >> m; + int a[n], b[m]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) { + x = i - 1; + y = i + 1; + zero++; + } else if (i != 0 && a[i - 1] != 0 && flag != 1) { + if (a[i] <= a[i - 1]) flag = 1; + } + } + for (i = 0; i < m; i++) { cin >> b[i]; } + if (zero < m) + flag = 0; + else if (zero > 1) + flag = 1; + else if (flag != 1 && zero == 1) { + for (i = 0; i < m; i++) { + if (x == -1) { + if (b[i] >= a[y]) { + flag = 1; + break; + } + } else if (y == n) { + if (a[x] >= b[i]) { + flag = 1; + break; + } + } else if (a[x] >= b[i] || b[i] >= a[y]) { + flag = 1; + break; + } + } + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int a[(int)1e5 + 5]; +long long min(long long a, long long b) { + if (a > b) { + return b; + } else { + return a; + } +} +int main() { + int n; + cin >> n; + long long m = 1e9 + 1; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + m = min(m, a[i]); + } + vector ans; + for (int i = 1; i <= n; i++) { + if (a[i] == m) { ans.push_back(i); } + } + int mins = 1e9; + int size = ans.size() - 1; + for (int i = 1; i <= size; i++) { mins = min(mins, ans[i] - ans[i - 1]); } + cout << mins << endl; + return 0; +} +int n, k, p; +int ivmind[100005], prime[100005]; +int a[25], num, fff; +void ES(int n) { + for (int i = 2; i <= n; i++) { + if (!ivmind[i]) ivmind[i] = i, prime[++p] = i; + for (int j = 1; j <= p && i * prime[j] <= n; j++) { + ivmind[i * prime[j]] = 1; + if (i % prime[j] == 0) break; + } + } +} +int main() { + cin >> n >> k; + ES(n); + for (int i = 1; i <= k - 1; i++) { + fff = 0; + for (int j = 1; prime[j] <= n; j++) { + if (n % prime[j] == 0) { + a[++num] = prime[j]; + n = n / prime[j]; + fff = 1; + break; + } + } + if (fff == 0 || n == 1) { + cout << "-1" << endl; + return 0; + } + } + for (int i = 1; i <= num; i++) { cout << a[i] << " "; } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1][n + 1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int cnt = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int sum1 = 0, sum2 = 0; + for (int k = 0; k < n; k++) { + sum1 += a[k][j]; + sum2 += a[i][k]; + } + if (sum1 > sum2) { cnt++; } + } + } + cout << cnt << "\n"; + return 0; +} +int main() { + int n, p, q, s = 0, i; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> p >> q; + if (q - p >= 2) s++; + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + if (arr[n - 1] == 15) + cout << "DOWN" << endl; + else if (arr[n - 1] == 0) + cout << "UP" << endl; + else if (n == 1) + cout << -1 << endl; + else { + if (arr[n - 1] - arr[n - 2] > 0) + cout << "UP" << endl; + else + cout << "DOWN" << endl; + } + return 0; +} +int main() { + int n, m = 0; + cin >> n; + string s, s1; + int s2[n], s12[n]; + cin >> s; + cin >> s1; + for (int i = 0; i < n; i++) { s2[i] = s[i] - '0'; } + for (int i = 0; i < n; i++) { s12[i] = s1[i] - '0'; } + for (int i = 0; i < n; i++) { + int x, y; + x = abs(s2[i] - s12[i]); + y = abs(10 - abs(s2[i] - s12[i])); + if (x < y) { + m = m + x; + } else + m = m + y; + } + cout << m << endl; +} +int positive(int n) { + return n > 0 ? n : -n; +} +int returnAbs(int a, int b) { + if (positive(a - b) >= 13) + return 26 - positive(a - b); + else + return positive(b - a); +} +int main() { + int sum = 0; + char num[101]; + gets(num); + int len = strlen(num); + for (int i = 1; i < len; i++) { sum += returnAbs(num[i - 1], num[i]); } + sum += returnAbs(97, num[0]); + cout << sum << endl; +} +int n, m, a[1010], gs[1010], i, answer; +int main() { + cin >> n >> m; + for (i = 1; i <= m; i++) { + cin >> a[i]; + gs[a[i]]++; + } + answer = 10000001; + for (i = 1; i <= n; i++) + if (gs[i] < answer) answer = gs[i]; + cout << answer << endl; + return 0; +} +int gcd(int a, int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + long int n, i, j, k, a[205], l, max = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > max) max = a[i]; + } + long int result = a[0]; + for (i = 1; i < n; i++) { + if (result < a[i]) + result = gcd(result, a[i]); + else + result = gcd(a[i], result); + } + long int ans = max / result; + long int s = ans - n; + if (s % 2 == 0) + cout << "Bob" << endl; + else + cout << "Alice" << endl; +} +const int MAXT = 1500; +int n, s; +bool ok[MAXT + 1]; +int main() { + memset(ok, true, sizeof ok); + cin >> n >> s; + for (int i = 1; i <= n; ++i) { + int h, m; + cin >> h >> m; + int t = h * 60 + m; + for (int i = max(0, t - s); i <= t + s; ++i) ok[i] = false; + } + for (int i = 0; i <= MAXT; ++i) + if (ok[i]) { + int h = i / 60, m = i % 60; + cout << h << " " << m << endl; + break; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int k = 0; + int i, j; + int p; + cin >> i; + int *r = new int[i + 1](); + for (p = 0; p < i; p++) { cin >> r[p]; } + cin >> j; + int *u = new int[j + 1](); + for (p = 0; p < j; p++) { cin >> u[p]; } + int *m = new int[i + j + 1](); + for (p = 0; p < i; p++) { m[p] = r[p]; } + int t = p; + for (p = 0; p < j; p++) { m[t + p] = u[p]; } + int y; + for (p = 1; p <= n; p++) { + for (y = 0; y < i + j; y++) { + if (m[y] == p) { break; } + } + if (y == i + j) { k = 1; } + } + if (k == 0) { cout << "I become the guy." << endl; } + if (k == 1) { cout << "Oh, my keyboard!" << endl; } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) + cout << 0 << endl; + else if (n - 10 < 10) + cout << 4 << endl; + else if (n - 10 == 10) + cout << 15 << endl; + else + cout << 4 << endl; +} +int main() { + int n; + cin >> n; + vector arr(n); + int max = INT_MIN, sum = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + if (max < arr[i]) max = arr[i]; + } + if (n * max > 2 * sum) + cout << max << endl; + else { + if ((2 * sum) % n == 0) + cout << (2 * sum) / n + 1 << endl; + else + cout << ceil((2. * sum) / n) << endl; + } + return 0; +} +const int N = 150000; +int main() { + int n, l, r, ql, qr; + int a[N]; + int suml[N], sumr[N]; + while (cin >> n >> l >> r >> ql >> qr) { + memset(suml, 0, sizeof(suml)); + memset(sumr, 0, sizeof(sumr)); + memset(a, 0, sizeof(a)); + suml[0] = sumr[0] = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) suml[i] = suml[i - 1] + a[i]; + for (int i = 1, j = n; i <= n, j >= 1; i++, j--) sumr[i] = sumr[i - 1] + a[j]; + int maxx = 2147483640; + int ans = 0; + int ll, rr; + for (int i = 0; i <= n; i++) { + ans = suml[i] * l + sumr[n - i] * r; + if (2 * i > n) ans += (2 * i - n - 1) * ql; + if (2 * i < n) ans += (n - 2 * i - 1) * qr; + maxx = min(maxx, ans); + } + cout << maxx << endl; + } + return 0; +} +bitset<26> ans, tmp; +int n, cnt = 0; +char ch; +string s; +int main() { + ans.set(); + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> ch >> s; + if (ans.count() == 1 && i < n && ch != '.') + cnt++; + else { + tmp.reset(); + for (int i = 0; i <= s.length(); i++) tmp[s[i] - 'a'] = 1; + if (ch == '!') + ans &= tmp; + else + ans &= ~tmp; + } + } + cout << cnt << endl; + return 0; +} +int n, k, p; +int ivmind[100005], prime[100005]; +int a[25], num, fff; +void ES(int n) { + for (int i = 2; i <= n; i++) { + if (!ivmind[i]) ivmind[i] = i, prime[++p] = i; + for (int j = 1; j <= p && i * prime[j] <= n; j++) { + ivmind[i * prime[j]] = 1; + if (i % prime[j] == 0) break; + } + } +} +int main() { + cin >> n >> k; + ES(n); + for (int i = 1; i <= k - 1; i++) { + fff = 0; + for (int j = 1; prime[j] <= n; j++) { + if (n % prime[j] == 0) { + a[++num] = prime[j]; + n = n / prime[j]; + fff = 1; + break; + } + } + if (fff == 0 || n == 1) { + cout << "-1" << endl; + return 0; + } + } + if (n == 1) { + cout << "-1" << endl; + return 0; + } + for (int i = 1; i <= num; i++) { cout << a[i] << " "; } + cout << n << endl; + return 0; +} +int main() { + int num, i, p, q, NumOfFree = 0; + cin >> num; + for (i = 1; i <= num; i++) { + cin >> p >> q; + if (q - p >= 2) { NumOfFree = NumOfFree + 1; } + } + cout << NumOfFree << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (n * 2) - (n / 2) << endl; +} +int main() { + int n, h, a, t = 0; + vector v; + vector v1; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> h >> a; + v.push_back(h); + v1.push_back(a); + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (v[i] == v1[j]) t++; + } + } + cout << t << endl; +} +int main() { + int n, points; + cin >> n >> points; + int amazing = 0; + int mxs = points; + int mns = points; + while (--n) { + cin >> points; + if (points > mxs) { + mxs = points; + amazing++; + } + if (mns > points) { + mns = points; + amazing++; + } + } + cout << amazing << endl; + return 0; +} +long long n, a, b, res; +string s; +long long arr[100005]; +long long arr1[100005]; +int main() { + cin >> a >> b; + cout << min(a, b) << " " << abs(a - b) / 2; + cout << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + map m; + m["Tetrahedron"] = 4; + m["Cube"] = 6; + m["Octahedron"] = 8; + m["Dodecahedron"] = 12; + m["Icosahedron"] = 20; + string curr; + int cnt = 0; + for (int i = 0; i < n; ++i) { + cin >> curr; + cnt += m[curr]; + } + cout << cnt << endl; + return 0; +} +string s; +int c; +int main() { + cin >> s; + for (char a = 'a'; a <= 'z'; ++a) { + int m = 0; + for (int i = 0; i < s.size(); ++i) { + if (s[i] == a) ++m; + } + if (m) c++; + } + if (c % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +int main() { + int n, d; + while (cin >> n >> d) { + int cnt = 0, max_cnt = 0, win; + for (int i = 0; i < d; i++) { + char present[101]; + cin >> present; + win = 1; + for (int j = 0; present[j]; j++) win = win & (present[j] - '0'); + if (win) + cnt = 0; + else + cnt++; + if (cnt > max_cnt) max_cnt = cnt; + } + cout << max_cnt << endl; + } + return 0; +} +int arr[200010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int ans = 0x3f3f3f3f; + int step = (n - 2) / 2; + for (int i = 0; i + step + 1 < n; i++) ans = min(ans, arr[i + step + 1] - arr[i]); + cout << ans << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + int n; + string s; + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << "2" << endl; + cout << s[0] << ' '; + for (int i = 1; s[i]; ++i) cout << s[i]; + cout << endl; + } + } + return 0; +} +int n, a, b; +string s; +int main() { + cin >> n >> a >> b >> s; + if (s[a - 1] == s[b - 1]) + cout << 0 << "\n"; + else + cout << 1 << "\n"; + return 0; +} +int main() { + string a, b; + int c = 0; + cin >> a >> b; + int len1 = a.size(); + int len2 = b.size(); + if (a == b) + cout << -1 << endl; + else { + cout << max(len1, len2) << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * b / gcd(a, b); +} +long long f(long long n, long long b) { + if (n <= 1) return 0; + long long i = 1; + while (i * 2 <= n) i *= 2; + return f(n - i + i / 2, b) + i / 2 * (2 * b + 1); +} +int main() { + long long n, b, p; + cin >> n >> b >> p; + cout << f(n, b) << " " << n * p << endl; +} +int main() { + int n, c; + while (cin >> n >> c) { + int t[1000002]; + memset(t, 0, sizeof(t)); + int ans = 0; + for (int i = 0; i < n; i++) { cin >> t[i]; } + for (int i = 0; i < n; i++) { + if (t[i + 1] - t[i] <= c) + ans++; + else + ans = 0; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, l, r, k, ans, sum = 0; + cin >> n >> k; + while (n--) { + cin >> l >> r; + sum += abs(r - l + 1); + } + ans = ((sum / k) + (sum % k > 0)) * k - sum; + cout << ans << "\n"; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + if (((s * v1) + (t1 * 2)) > ((s * v2) + (t2 * 2))) { + cout << "Second" << endl; + } else if (((s * v1) + (t1 * 2)) < ((s * v2) + (t2 * 2))) { + cout << "First" << endl; + } else if (((s * v1) + (t1 * 2)) == ((s * v2) + (t2 * 2))) { + cout << "Friendship" << endl; + } +} +int main() { + string s; + cin >> s; + int c1 = 0, c2 = 0; + if (s[0] == '0') + c1 += 2; + else if (s[0] == '1') + c1 += 7; + else if (s[0] == '2') + c1 += 2; + else if (s[0] == '3') + c1 += 3; + else if (s[0] == '4') + c1 += 3; + else if (s[0] == '5') + c1 += 4; + else if (s[0] == '6') + c1 += 2; + else if (s[0] == '7') + c1 += 5; + else if (s[0] == '8') + c1 += 1; + else if (s[0] == '9') + c1 += 2; + if (s[1] == '0') + c2 += 2; + else if (s[1] == '1') + c2 += 7; + else if (s[1] == '2') + c2 += 2; + else if (s[1] == '3') + c2 += 3; + else if (s[1] == '4') + c2 += 3; + else if (s[1] == '5') + c2 += 4; + else if (s[1] == '6') + c2 += 2; + else if (s[1] == '7') + c2 += 5; + else if (s[1] == '8') + c2 += 1; + else if (s[1] == '9') + c2 += 2; + cout << c1 * c2 << endl; + return 0; +} +bool ispalindrome(string s) { + string t = s; + reverse(s.begin(), s.end()); + return s == t; +} +int main() { + string s; + cin >> s; + if (ispalindrome(s)) { + if (s.size() % 2) { + puts("YES"); + return 0; + } else { + puts("NO"); + return 0; + } + } + for (int i = 0; i < s.size() / 2; i++) { + string t = s; + t[i] = t[t.size() - i - 1]; + if (ispalindrome(t)) { + puts("YES"); + return 0; + } + } + puts("NO"); + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int h[n], g[n]; + for (int i = 0; i < n; i++) { cin >> h[i] >> g[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (h[i] == g[j]) { count++; } + } + } + cout << count << endl; + return 0; +} +char dict[15] = "13579aeiou"; +int main() { + char s[55]; + int sum = 0, i = 0; + cin >> s; + while (s[i] != '\0') { + int flag = 1; + for (int j = 0; j < 10; j++) + if (s[i] == dict[j]) flag = 0; + if (flag == 0) sum++; + i++; + } + cout << sum << endl; +} +int c[1001], a[1001]; +int main() { + int n, m, count = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + int i = 0, j = 0; + while (i < n && j < m) { + if (c[i] <= a[j]) { + j++; + count++; + } + i++; + } + cout << count << endl; +} +int main() { + string a1, a2; + string a; + cin >> a; + int i = 0; + for (i = 0; i < a.size(); i++) { + if (a[i] != '0') break; + } + for (; i < a.size(); i++) { a1 += a[i]; } + cin >> a; + for (i = 0; i < a.size(); i++) { + if (a[i] != '0') break; + } + for (; i < a.size(); i++) { a2 += a[i]; } + if (a1.size() > a2.size()) { + cout << '>' << endl; + } else if (a1.size() < a2.size()) { + cout << '<' << endl; + } else if (a1.size() == a2.size()) { + if (a1 > a2) + cout << '>' << endl; + else if (a1 < a2) + cout << '<' << endl; + else if (a1 == a2) + cout << '=' << endl; + } + return 0; +} +char a2[1000009], b2[1000009]; +int main() { + string a; + string b; + while (cin >> a) { + cin >> b; + int lena = a.length(), lenb = b.length(); + memset(a2, 0, sizeof(a2)); + memset(b2, 0, sizeof(b2)); + int biaoji1 = -1, biaoji2 = -1; + for (int i = 0; i < lena; i++) { + if (a[i] != '0') { + biaoji1 = i; + break; + } + } + int m = 0; + if (biaoji1 == -1) { + m = 0; + a2[0] = '0'; + } else { + for (int j = biaoji1; j < lena; j++) { + a2[m] = a[j]; + m++; + } + } + for (int i = 0; i < lenb; i++) { + if (b[i] != '0') { + biaoji2 = i; + break; + } + } + int k = 0; + if (biaoji2 == -1) { + k = 0; + b2[0] = '0'; + } else { + for (int j = biaoji2; j < lenb; j++) { + b2[k] = b[j]; + k++; + } + } + if (m < k) + cout << "<" << endl; + else if (m > k) + cout << ">" << endl; + else { + int flag = 0; + int j; + for (j = 0; j < m; j++) { + if (a2[j] > b2[j]) { + cout << ">" << endl; + flag = 1; + break; + } + if (a2[j] < b2[j]) { + cout << "<" << endl; + flag = 1; + break; + } + } + if (j == m) cout << "=" << endl; + } + } +} +int t, s, q; +int ans = 1; +int main() { + cin >> t >> s >> q; + long double now = 0; + long double last = s; + while (last < t) { + long double tmp = (last - now) * q; + if (last + tmp * (q - 1) / q >= t) break; + last += ceil(tmp) * (q - 1) / q; + now += ceil(tmp); + now -= last; + ans++; + } + cout << ans << endl; +} +int main() { + int n; + int k; + int i; + int x; + int y; + int sum; + int total = 0; + while (cin >> n >> k) { + total = 0; + for (i = 1; i <= n; i++) { + sum = 0; + cin >> x; + while (x) { + y = x % 10; + if (y == 4 || y == 7) { sum++; } + x = x / 10; + } + if (k >= sum) { total++; } + } + cout << total << endl; + } + return 0; +} +int a[200005], b[200005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + memcpy(b, a, sizeof(a)); + int ans = 0; + sort(b, b + n); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) { ans++; } + } + if (ans == 0 || ans == 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int64_t x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << max(abs(x1 - x2), abs(y1 - y2)) << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int lent = t.size(); + int pos = 0; + for (int i = 0; i < lent; i++) { + if (s[pos] == t[i]) { pos++; } + } + cout << pos + 1 << endl; +} +int main() { + int q; + cin >> q; + for (int i = 0; i < q; i++) { + int n; + string s; + cin >> n >> s; + if (n == 2) { + if (s[1] > s[0]) { + cout << "YES" << endl << "2" << endl; + cout << s[0] << " " << s[1] << endl; + } else + cout << "NO" << endl; + } else { + cout << "YES" << endl << "2" << endl; + string s1 = s.substr(1, n - 1); + cout << s[0] << " " << s1 << endl; + } + } +} +int main() { + int n, m, k, i, j, p = 0; + cin >> n >> m; + int a[n]; + string s[n]; + for (i = 0; i < n; i++) { + cin >> s[i]; + a[i] = 0; + } + for (i = 0; i < m; i++) { + k = 0; + for (j = 0; j < n; j++) k = max(k, (int)s[j][i]); + for (j = 0; j < n; j++) + if ((int)s[j][i] == k && a[j] == 0) { + p++; + a[j] = 1; + } + } + cout << p << endl; + return 0; +} +int main() { + long long m, n; + cin >> n >> m; + if (n <= m) { + if (n % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } else { + if (m % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } + return 0; +} +int main() { + int m, n, i, j, k; + cin >> n >> m; + int ara[n + 2], tra[m + 2]; + for (i = 0; i < n; i++) { cin >> ara[i]; } + for (j = 0; j < m; j++) { cin >> tra[j]; } + sort(ara, ara + n); + sort(tra, tra + m); + int p = 1; + if (ara[n - 1] >= tra[0]) { p = 0; } + int x = 0; + int q = ara[n - 1]; + for (i = 0; i < n - 1; i++) { + if (2 * ara[i] <= q) { + x = 1; + break; + } + } + if (x == 0) { + if (ara[0] * 2 < tra[0]) { + x = 1; + q = ara[0] * 2; + } + } + if (x == 1 && p == 1) cout << q << endl; + if (x == 0 || p == 0) cout << "-1" << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int cnt = 0; + for (int i = 1; i <= k; i++) { + if (i % n == 0 && i % m == 0) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int a[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + if (a[i][1] - a[i][0] >= 2) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + cout << s / (a * c) * b + s / c << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int v, m; + m = max(3 * a / 10, a - ((a / 250) * c)); + v = max(3 * b / 10, b - ((b / 250) * d)); + if (m > v) { + cout << "Misha" << endl; + } else if (v > m) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } + return 0; +} +int main() { + int n, p, ans, q, sum = 0; + string a, b; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + p = abs(a[i] - b[i]); + if (a[i] > b[i]) + ans = 10 - a[i] + b[i]; + else { + ans = 10 - b[i] + a[i]; + } + q = min(ans, p); + sum = sum + q; + } + cout << sum << endl; +} +int main() { + int n, m, c[1001], a[1001], sum = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + int k, x = 0; + for (int j = 0; j < m; j++) { + for (k = x; k < n; k++) { + if (a[j] >= c[k]) { + sum++; + x = k + 1; + break; + } + if (k == n - 1) break; + } + if (k == n - 1) break; + } + cout << sum << endl; + return 0; +} +const int INF = 1e9; +inline int pt(int a[], int l, int r) { + int p, i, j; + p = a[l]; + i = l; + j = r + 1; + for (;;) { + while (a[++i] < p) + if (i >= r) break; + while (a[--j] > p) + if (j <= l) break; + if (i >= j) + break; + else + swap(a[i], a[j]); + } + if (j == l) return j; + swap(a[l], a[j]); + return j; +} +inline void q_sort(int a[], int l, int r) { + int q; + if (r > l) { + q = pt(a, l, r); + q_sort(a, l, q - 1); + q_sort(a, q + 1, r); + } +} +inline int readint() { + int x = 0; + int f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') ch = getchar(); + if (ch == '-') { + f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int main() { + int n, k, i, j; + cin >> n >> k; + for (i = 0; i < k; i++) { + if (n % 10 == 0) + n /= 10; + else + n--; + } + cout << n << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (k <= (n + 1) / 2) { + cout << k * 2 - 1 << endl; + } else { + cout << (k - (n + 1) / 2) * 2 << endl; + } + return 0; +} +int main() { + int x, Steps = 0; + cin >> x; + if (x % 5 == 0) + cout << x / 5 << endl; + else + cout << (x / 5) + 1 << endl; + return 0; +} +string alph = "abcdefghijklmnopqrstuvwxyz"; +int temp; +int main() { + string s; + cin >> s; + int mx = -99; + for (int x = 0; x < s.size(); x++) { + for (int a = 0; a < 26; a++) { + if (s[x] == alph[a]) { + temp = a; + mx = max(temp, mx); + break; + } + } + } + for (int a = 0; a < s.size(); a++) { + if (s[a] == alph[mx]) cout << s[a]; + } + cout << endl; +} +int main() { + int n, m, a[1000]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int b, c; + cin >> b; + for (int j = 0; j < b; j++) { + cin >> c; + a[c] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (a[i] != 1) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +long long int getB(long long int num) { + long long int t = 1; + for (int i = 0; i < 64; i++) { + if (t > num) + return i - 1; + else + t *= 2; + } +} +long long int solve(long long int l, long long int r) { + if (l == r) + return l; + else { + long long int b = getB(r); + long long int x = pow(2, b); + if (x <= l) { + return solve(l - x, r - x) + x; + } else if (x * 2 - 1 <= r) + return x * 2 - 1; + else + return x - 1; + } +} +int main() { + int q; + cin >> q; + while (q--) { + long long int l, r; + cin >> l >> r; + cout << solve(l, r) << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int m = max(a, max(b, c)); + int r = 0; + for (int i = 1; i <= m; i++) { + if (a % i == 0 && b % i == 0 && ((a / i) * (b / i) == c)) { + r = a / i + b / i + i; + r *= 4; + } + } + cout << r << endl; +} +int main() { + int n; + int a[1001]; + int b[1001]; + cin >> n; + for (int i = 1; i <= 2 * n; i++) { cin >> a[i]; } + int max = 1; + for (int i = 1; i <= 2 * n; i++) { + for (int j = 1; j <= 2 * n; j++) { + if (a[max] < a[j]) { max = j; } + } + b[i] = a[max]; + a[max] = -1; + } + if (b[n] > b[n + 1]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int sum = 0; + int N; + cin >> N; + while (N--) { + int a, b, c, d; + cin >> a >> b >> c >> d; + sum += (abs(a - c) + 1) * (abs(b - d) + 1); + } + cout << sum << endl; + return 0; +} +long long N, A, B, K, ans, cnt, x, y, val = 1; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> A; + x |= A; + } + for (int i = 1; i <= N; i++) { + cin >> A; + y |= A; + } + cout << x + y << '\n'; +} +const int MAXN = 1000 + 10; +int arr[MAXN]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int ans = 0; + int i = 0; + while (arr[i] == 0 && i <= n - 1) i++; + for (int j = i; j < n; j++) { + int k = j + 1; + while (k < n && arr[j] == arr[k]) k++; + if (k == j + 2) { + ans++; + } else { + if (k > 2 + j) { + cout << -1 << endl; + return 0; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + string s; + cin >> n >> s; + bool q = true; + for (long long i = 0; i < n; i++) { + if (s[i] == '0') { + cout << i + 1 << endl; + q = false; + break; + } + } + if (q) { cout << n << endl; } + return 0; +} +int n, m, s; +int main() { + int l, r; + cin >> n >> m; + while (n--) { + cin >> l >> r; + if (l <= s) s = r < s ? s : r; + } + if (s < m) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +const long long EPS = 1e17; +int eps = 1e9 + 7; +long double inf = 1e-10; +long long depth(long long v) { + long long cnt = 0; + while (v > 1) { + ++cnt; + v >>= 1; + } + return cnt; +} +int main() { + int n; + cin >> n; + map, long long> A; + for (int e = 0; e < n; ++e) { + int t; + cin >> t; + if (t == 1) { + long long u, v, w; + cin >> u >> v >> w; + long long dep_u = depth(u), dep_v = depth(v); + long long ans = 0; + if (dep_v > dep_u) { + swap(dep_v, dep_u); + swap(v, u); + } + while (dep_u > dep_v) { + A[pair(u, u / 2)] += w; + u >>= 1; + --dep_u; + } + while (u != v) { + A[pair(u, u / 2)] += w; + A[pair(v, v / 2)] += w; + u >>= 1; + v >>= 1; + } + } else { + long long u, v; + cin >> u >> v; + long long dep_u = depth(u), dep_v = depth(v); + long long ans = 0; + if (dep_v > dep_u) { + swap(dep_v, dep_u); + swap(v, u); + } + while (dep_u > dep_v) { + if (A.find(pair(u, u / 2)) != A.end()) { ans += A[pair(u, u / 2)]; } + --dep_u; + u >>= 1; + } + while (v != u) { + if (A.find(pair(u, u / 2)) != A.end()) { ans += A[pair(u, u / 2)]; } + if (A.find(pair(v, v / 2)) != A.end()) { ans += A[pair(v, v / 2)]; } + v >>= 1; + u >>= 1; + } + cout << ans << endl; + } + } + return 0; +} +int main() { + int p; + int r, x, y, z; + while (cin >> p) { + while (1) { + p++; + r = p / 1000; + x = (p / 100) % 10; + y = (p / 10) % 10; + z = p % 10; + if (r != x && r != y && r != z && x != y && x != z && y != z) { break; } + } + cout << p << endl; + } +} +void rotate1(string &t) { + char temp = t[1]; + t[1] = t[0]; + t[0] = t[3]; + t[3] = t[2]; + t[2] = temp; +} +void rotate2(string &t) { + char temp = t[1]; + t[1] = t[4]; + t[4] = t[3]; + t[3] = t[5]; + t[5] = temp; +} +void rotate3(string &t) { + char temp = t[0]; + t[0] = t[4]; + t[4] = t[2]; + t[2] = t[5]; + t[5] = temp; +} +string norm(string s) { + string res = s; + for (int(i) = 0; (i) < (4); ++(i)) { + for (int(j) = 0; (j) < (4); ++(j)) { + for (int(k) = 0; (k) < (4); ++(k)) { + rotate1(s); + res = min(res, s); + } + rotate2(s); + } + rotate3(s); + } + return res; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + set S; + do { S.insert(norm(s)); } while (next_permutation(s.begin(), s.end())); + cout << S.size() << endl; +} +bool is_vowel(char c) { + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { + return true; + } else { + return false; + } +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (is_vowel(s[i]) && is_vowel(s[i + 1])) { + s.erase(i + 1, 1); + i--; + } + if (i + 1 == s.length()) { break; } + } + cout << s << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int *d = new int[n]; + int k = 0, s = 0; + for (int i = 0; i < n; i++) { + cin >> d[i]; + s += d[i]; + k = max(k, d[i]); + } + int sum = 0; + do { + sum = 0; + for (int i = 0; i < n; i++) sum += k - d[i]; + k++; + } while (sum <= s); + cout << k - 1 << endl; +} +long long int n, m; +int main() { + cin >> n >> m; + bool b = true; + while (n != 0 && m != 0) { + b = !b; + n--; + m--; + } + if (!b) { + cout << "Akshat" + << "\n"; + } else { + cout << "Malvika" + << "\n"; + } + return 0; +} +const long long inf = 1e18 + 1; +long long gcd(long long x, long long y) { + if (y == 0) return x; + return gcd(y, x % y); +} +long long power(long long A, long long B, long long mod) { + long long r = 1; + while (B > 0) { + if (B & 1LL) r = (r * A) % mod; + A = (A * A) % mod; + B >>= 1; + } + return r; +} +int a[101]; +int dp[101][3]; +int main() { + int n, i; + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1; + if (a[i] == 0) { + dp[i][1] = 100002; + dp[i][2] = 100002; + } else if (a[i] == 1) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + dp[i][2] = 100002; + } else if (a[i] == 2) { + dp[i][1] = 100002; + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } else if (a[i] == 3) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } + } + int ans = min(dp[n][0], min(dp[n][1], dp[n][2])); + cout << ans << endl; + return 0; +} +char big(char m, char n) { + char a[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; + int a_pos, b_pos; + for (int i = 0; i < 9; i++) + if (m == a[i]) a_pos = i; + for (int i = 0; i < 9; i++) + if (n == a[i]) b_pos = i; + if (a_pos > b_pos) + return 'a'; + else + return 'b'; +} +int main() { + char tramp; + cin >> tramp; + string a, b; + cin >> a >> b; + if (a[1] == tramp && b[1] != tramp) { + cout << "YES" << endl; + return 0; + } + if (a[1] == b[1]) { + char great = big(a[0], b[0]); + if (great == 'a') { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n, j, k; + cin >> n; + j = n / 2; + k = j * 3; + cout << k << endl; +} +int n; +string w[110]; +int main() { + int ans = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> w[i]; + for (int i = 0; i < 26; i++) + for (int j = i; j < 26; j++) { + int sum = 0; + for (int k = 0; k < n; k++) { + int cnt = 0; + for (; cnt < w[k].size(); cnt++) + if (w[k][cnt] != (j + 'a') && w[k][cnt] != (i + 'a')) break; + if (cnt == w[k].size()) sum += w[k].size(); + } + ans = max(ans, sum); + } + cout << ans << endl; + return 0; +} +int main() { + string name[101], rank; + int n, r = 0, w = 0, m = 0, c = 0; + int rat[100], wc[100], men[100], cap[100]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> name[i] >> rank; + if (rank == "captain") { + c++; + cap[c] = i; + } else if (rank == "child" || rank == "woman") { + w++; + wc[w] = i; + } else if (rank == "man") { + m++; + men[m] = i; + } else if (rank == "rat") { + r++; + rat[r] = i; + } + } + for (int i = 1; i <= r; i++) { cout << name[rat[i]] << endl; } + for (int i = 1; i <= w; i++) { cout << name[wc[i]] << endl; } + for (int i = 1; i <= m; i++) { cout << name[men[i]] << endl; } + for (int i = 1; i <= c; i++) { cout << name[cap[i]] << endl; } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> H >> L >> R; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> M; + if (M > L && M < R) K++; + } + cout << K << endl; + return 0; +} +string s; +void doit() { + cin >> s; + long long resp = 0; + for (long long j = 0; j < s.size(); j++) { + long long open = 0; + long long qClose = 0; + for (long long i = j; i < s.size(); i++) { + if (s[i] == '(') { open++; } + if (s[i] == ')') { open--; } + if (s[i] == '?') { + if (open > 0) { + qClose++; + open--; + } else { + open++; + } + } + if (open + 2 * qClose < 0) { break; } + if (open == 0) { + resp++; + } else { + if (open < 0) { + long long x = abs(open); + if (x % 2 == 0) { + if (2 * qClose >= x) { resp++; } + } + qClose -= (x + 1) / 2; + open += 2 * ((x + 1) / 2); + } + } + } + } + cout << resp << endl; +} +int main() { + long long T = 1; + while (T--) { doit(); } + return 0; +} +long long power(long long a, long long b, long long mod) { + if (b == 0) { + return 1; + } else if (b % 2 == 0) { + long long x = power(a, b / 2, mod); + return (x * x) % mod; + } else { + return (a * power(a, b - 1, mod)) % mod; + } +} +int main() { + long long n; + cin >> n; + long long four_sum = 0; + while (four_sum <= n) { + if ((n - four_sum) % 7 == 0) { break; } + four_sum += 4; + } + if (four_sum > n) { + cout << "-1\n"; + } else { + long long seven_sum = n - four_sum; + for (int i = 0; i < four_sum / 4; i++) { cout << "4"; } + for (int i = 0; i < seven_sum / 7; i++) { cout << "7"; } + cout << "\n"; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m, t; + int a, b, c, d; + cin >> a >> b >> c >> d; + if (c > b || c > a) { + cout << -1 << endl; + return 0; + } + a = a + b - c; + d -= a; + if (d < 1 || a < 0) + cout << -1 << endl; + else + cout << d << endl; + return 0; +} +int n, s, t, line[101] = {}, ans = 0, tmp = 0; +int main() { + int i; + cin >> n; + for (i = 1; i <= n; ++i) cin >> line[i]; + cin >> s >> t; + i = s; + while (i != t) { + tmp += line[i]; + ++i; + if (i > n) i = 1; + } + while (i != s) { + ans += line[i]; + ++i; + if (i > n) i = 1; + } + if (tmp < ans) ans = tmp; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector list(n); + for (int i = 0; i < list.size(); i++) cin >> list[i]; + int min = numeric_limits::max(), ind; + for (int i = 1; i < list.size() - 1; i++) { + int factor = (list[i] - list[i - 1]) + (list[i + 1] - list[i]); + if (factor < min) { + min = factor; + ind = i; + } + } + list.erase(list.begin() + ind); + int max = numeric_limits::min(); + for (int i = 1; i < list.size(); i++) { + if (list[i] - list[i - 1] > max) max = list[i] - list[i - 1]; + } + cout << max << "\n"; +} +int main() { + int n, ans = 0; + cin >> n; + int a[35][35]; + int sum_row[35] = {0}, sum_col[35] = {0}; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + sum_row[i] += a[i][j]; + sum_col[j] += a[i][j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (sum_row[i] < sum_col[j]) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + string x = "a"; + int count1 = 0, count2 = 0; + string inp; + cin >> inp; + for (int i = 0; i < inp.length(); i++) { + count1 = max((inp[i] - x[0]), (x[0] - inp[i])); + if (count1 > 13) { + count2 += (26 - count1); + } else { + count2 += count1; + } + x = inp[i]; + } + cout << count2 << endl; + return 0; +} +int main() { + int n, m, b = 0, s = 0; + cin >> n >> m; + s = n; + b = n; + for (int i = 0; b >= m; i++) { + s += b / m; + b = b / m + b % m; + } + cout << s << endl; +} +int main() { + int n, sum = 0, mc = 0, summ = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + sum += a; + if (a < 0) { + sum -= a; + mc++; + summ += a; + } + } + if (mc == 0) + cout << sum << endl; + else { + cout << sum - summ << endl; + } + return 0; +} +int x[100001], y[100001]; +int main() { + int i, n, a = 0, b = 0; + cin >> n; + for (i = 0; i < n; i++) cin >> x[i] >> y[i]; + for (i = 0; i < n; i++) { + if (x[i] > 0) + a++; + else + b++; + } + if (a <= 1 || b <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + string s = ""; + cin >> s; + int l = s.size(); + l++; + int ans = l * 26 - s.size(); + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long d; + cin >> d; + vector v; + for (long long i = 0; i < n; i++) { + long long c; + cin >> c; + v.push_back(c); + } + sort(v.begin(), v.end()); + long long min = LLONG_MAX; + long long found = 0; + for (long long i = 0; i < n; i++) { + for (long long j = i + 1; j < n; j++) { + if (v[j] - v[i] <= d) { + found = 1; + if (n - j + i - 1 < min) { min = n - j + i - 1; } + } + } + } + if (found == 0) { min = n - 1; } + cout << min << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = n + 1; i <= 9999; i++) { + int a = i % 10; + int b = (i - a) / 10 % 10; + int c = i / 100 % 10; + int d = i / 1000; + if (a != b && a != c && a != d && b != c && b != d && c != d) { + cout << i << endl; + break; + } + } + return 0; +} +bool a[105]; +int main() { + int n; + cin >> n; + int first = -1; + int final = -1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (first == -1 && a[i]) { first = i; } + if (a[i]) { final = i; } + } + int counter = 0; + bool athome = true; + for (int i = 0; i < n; i++) { + if (a[i]) { + athome = false; + counter++; + } else if (i > first) { + if (i + 1 < n && a[i + 1] && !athome) { + counter++; + } else { + athome = true; + } + } + if (i == final) { break; } + } + cout << counter << endl; + return 0; +} +void freac() {} +const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1}; +const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1}; +const int INF = (int)1e9 + 123; +const long long INFL = (long long)1e18 + 123; +const double EPS = 1e-9; +void lifestyle() {} +int main() { + lifestyle(); + freac(); + int n; + long long p, q, b; + cin >> n; + while (n--) { + cin >> p >> q >> b; + long long g = __gcd(p, q); + q /= g; + while (b != 1) { + while (q % b == 0) q /= b; + b = __gcd(q, b); + } + cout << ((q == 1) ? "Finite" : "Infinite") << endl; + } + return false; +} +const long double eps = 1e-9; +const int N = 5e6 + 10; +long long mirror(long long n) { + if (n == 0) return 9; + long long ret = 0; + long long t = 1; + while (n) { + ret += t * (9 - n % 10); + t *= 10; + n /= 10; + } + return ret; +} +int main() { + vector v; + v.push_back(4); + for (int i = 0; i < 10; i++) v.push_back(v.back() * 10 + 9); + long long l, r; + cin >> l >> r; + long long ans = max(l * mirror(l), r * mirror(r)); + int i = upper_bound(v.begin(), v.end(), r) - v.begin() - 1; + if (i >= 0 && v[i] >= l && v[i] <= r) ans = max(ans, v[i] * mirror(v[i])); + cout << ans << '\n'; + return 0; +} +int main() { + int i, n, x1, x2, y1, y2, mx = 99999, my = 99999, Mx = -1, My = -1, R = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + R += (x2 - x1) * (y2 - y1); + if (Mx < x2) Mx = x2; + if (My < y2) My = y2; + if (mx > x1) mx = x1; + if (my > y1) my = y1; + } + if ((Mx - mx) * (My - my) == R && Mx - mx == My - my) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long dp[1000010]; +int main() { + dp[2] = 3; + dp[1] = 1; + dp[3] = 6; + dp[4] = 11; + int n; + cin >> n; + for (int i = 3; i <= n; i++) dp[i] = (dp[i - 1] + dp[i - 2] + 2) % 1000000007; + cout << dp[n] << endl; +} +int main() { + long long int st, cross, t_turn; + cin >> st >> cross; + t_turn = st / cross; + if (!(t_turn & 1)) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, k; + cin >> n >> k; + string s = "0123456789", s1; + int res = 0, c = 0; + while (n--) { + cin >> s1; + for (int i = 0; i <= k; i++) { + if (s1.find(s[i]) < s1.size()) c++; + } + if (c >= k + 1) res++; + c = 0; + } + cout << res << endl; + return 0; +} +int main() { + int n, k, x, sum(0); + int A[101]; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> A[i]; + for (int i = 0; i < n - k; i++) { sum += A[i]; } + cout << sum + k * x << endl; +} +long long ara[200009]; +long long ara2[200009]; +int main() { + long long i, n; + cin >> n; + for (i = 0; i < n; i++) cin >> ara[i]; + sort(ara, ara + n); + for (i = 1; i < n; i++) { ara2[i] = ara[i] - ara[i - 1]; } + long long mn = *min_element(ara2 + 1, ara2 + n); + long long cnt = 0; + for (i = 1; i < n; i++) + if (ara2[i] == mn) cnt++; + cout << mn << " " << cnt << endl; + return 0; +} +int w, h, n; +int main() { + string s; + cin >> n; + w = h = 1; + while (n--) { + cin >> s; + if (s == "ULDR") + h++, w++; + else if (s == "UR" || s == "DL") + h++; + else + w++; + } + cout << (long long)h * w << endl; + return 0; +} +int main() { + int ara[10000]; + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 0; i < n; i++) { cin >> ara[i]; } + for (int i = 0; i < n; i++) { + if (ara[i] >= ara[k - 1] && ara[i] > 0) cnt++; + } + cout << cnt << endl; +} +int main() { + long long int i, j, t, a, b, c, n, m, k; + cin >> n >> k; + m = n / 2; + a = m / (k + 1); + cout << a << " " << a * k << " " << n - (a + a * k) << endl; + return 0; +} +int main() { + long long int l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + bool found = false; + for (long long int b = x; b <= y; ++b) { + long long int a = k * b; + if (a >= l && a <= r) { + found = true; + break; + } + } + if (found) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +map Map; +int main() { + long long t; + cin >> t; + for (int i = 1; i <= t; i++) { + string s; + cin >> s; + Map[s]++; + } + long long sum = 0; + for (int i = 1; i <= t; i++) { + string s; + cin >> s; + if (Map[s] > 0) { + Map[s]--; + } else { + sum++; + } + } + cout << sum << endl; +} +int main() { + string num; + while (cin >> num) { + for (int i = 0; i < num.length(); ++i) { + if (num[i] == '.') { + if (num[i - 1] == '9') { + cout << "GOTO Vasilisa." << '\n'; + break; + } else { + if (num[i + 1] >= '5') { num[i - 1] += 1; } + string n = num.substr(0, i); + cout << n << '\n'; + break; + } + } + } + } + return 0; +} +int main() { + string c, a[10]; + cin >> c; + for (int k = 0; k < 10; k++) { cin >> a[k]; } + for (int i = 0; i < 8; i++) { + string b = c.substr(i * 10, 10); + for (int l = 0; l < 10; l++) + if (b == a[l]) cout << l; + } + cout << endl; + return 0; +} +int main() { + string s, digit[10]; + cin >> s; + for (size_t i = 0; i < sizeof(digit) / sizeof(digit[0]); ++i) { cin >> digit[i]; } + for (size_t i = 0; i < 8; ++i) { + string x = s.substr(i * 10, 10); + for (size_t j = 0; j < 10; ++j) { + if (x == digit[j]) { + cout << j; + break; + } + } + } + cout << endl; + return 0; +} +int main() { + string s; + while (cin >> s) { + while (s[0] == '0') s.erase(0, 1); + while (~s.find("1")) s.erase(s.find("1"), 1); + if (s.size() >= 6) + cout << "yes" << endl; + else + cout << "no" << endl; + } + return 0; +} +int main() { + int n, k, a, b = 1, c = 0, d = 0, e, s[117]; + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> s[i]; } + while (b <= n) { + e = s[b] + d; + if (e <= 8) { + c = c + e; + d = 0; + b++; + if (c >= k) { break; } + } else if (e > 8) { + c = c + 8; + d = e - 8; + b++; + if (c >= k) { break; } + } + } + if (c < k) { + cout << -1 << endl; + } else { + cout << b - 1 << endl; + } + return 0; +} +const long long mod = 1e9 + 7; +int main() { + long long n, p; + cin >> n >> p; + string s; + cin >> s; + s = '0' + s; + s = '0' + s; + long long idx = 0; + for (long long i = n + 1; i >= 2; i--) { + for (long long j = s[i] - 'a' + 2; j <= p; j++) { + if (j != (s[i - 1] - 'a' + 1) and j != (s[i - 2] - 'a' + 1)) { + idx = i; + break; + } + } + if (idx) break; + } + if (idx == 0) { + cout << "NO\n"; + return 0; + } + for (long long i = s[idx] - 'a' + 2; i <= p; i++) { + if (i != (s[idx - 1] - 'a' + 1) and i != s[idx - 2] - 'a' + 1) { + s[idx] = (char)((long long)'a' + i - 1); + break; + } + } + for (long long i = idx + 1; i < n + 2; i++) { + for (long long j = 1; j <= p; j++) { + if (j != (s[i - 1] - 'a' + 1) and j != (s[i - 2] - 'a' + 1)) { + s[i] = (char)((long long)'a' + j - 1); + break; + } + } + } + s = string(s.begin() + 2, s.end()); + cout << s << "\n"; + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + long long t, cnt = 0; + t = max(x, y); + if (t >= m) + cout << "0" << endl; + else { + long long z = x + y; + if (z <= min(x, y)) + cout << "-1" << endl; + else { + long long q = min(x, y); + if (q < 0) { + if (x > y) swap(x, y); + cnt += abs(x) / abs(y); + x = x + cnt * y; + t = max(x, y); + z = x + y; + } + while (t < m) { + if (x > y) swap(x, y); + x = z; + z = x + y; + t = max(x, y); + cnt++; + } + cout << cnt << endl; + } + } + return 0; +} +int main() { + int a, p; + int ar[400], i = 400; + while (i--) { ar[i] = 0; } + cin >> p >> a; + int c = 0, res; + for (int i = 1; i <= a; i++) { + long long k; + cin >> k; + if (c == 0 && ar[k % p] > 0) { + res = i; + c = 1; + } + ar[k % p] = 1; + } + if (c == 0) { + cout << -1 << endl; + } else { + cout << res << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + cout << 2 << endl; + for (long long i = 3; i < n + 2; i++) { cout << i * i * (i - 1) - (i - 2) << endl; } +} +int main() { + int m, n; + while (cin >> m >> n) { + int a = m > n ? n : m; + if (a % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } +} +int ans, t, i, len; +string str; +int count() { + int i; + int ans = 0; + for (i = 1; i <= len - 1; i++) + if (str[i] == 'K' && str[i - 1] == 'V') ans++; + return ans; +} +int main() { + cin >> str; + len = str.size(); + ans = count(); + for (i = 0; i <= len - 1; i++) { + if (str[i] == 'V') { + str[i] = 'K'; + t = count(); + if (t > ans) ans = t; + str[i] = 'V'; + } else { + str[i] = 'V'; + t = count(); + if (t > ans) ans = t; + str[i] = 'K'; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int a, b, z = 0; + cin >> a >> b; + while (a > 0 && b > 0) { + if (a > b) { swap(a, b); } + if (a == b) { + z++; + a = 0; + } else { + z += b / a; + b %= a; + } + } + cout << z << '\n'; + } +} +bool isgreater(char c1, char c2) { + char arr[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; + int i1, i2; + i1 = i2 = -1; + for (int i = 0; i < 9; i++) { + if (arr[i] == c1) { i1 = i; } + if (arr[i] == c2) { i2 = i; } + } + if (i1 > i2) { return true; } + return false; +} +int main() { + char t; + string p1, p2; + cin >> t >> p1 >> p2; + if (p1[1] == t) { + if (p2[1] == t) { + if (isgreater(p1[0], p2[0])) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; + } + if (p1[1] == p2[1]) { + if (isgreater(p1[0], p2[0])) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +const int INF = 1 << 29; +int m; +int C[105]; +int x, y; +int main() { + cin >> m; + int sum = 0, cc = 0; + for (int i = 1; i <= m; i++) { + cin >> C[i]; + sum += C[i]; + } + cin >> x >> y; + for (int i = 1; i <= m; i++) { + cc += C[i]; + if (cc >= x && sum - cc >= x && cc <= y && sum - cc <= y) { + cout << i + 1 << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +int main() { + cout << 25 << endl; + return 0; +} +int main() { + long long int n, x, y, i = 0, count = 0; + long long int m; + cin >> n >> x >> y; + string s; + cin >> s; + while (i < n) { + if (s[i] == '0') { + count++; + while (s[i] == '0') { i++; } + } + i++; + } + m = (((count - 1) * min(x, y)) + y); + if (count == 0) { + cout << "0" << endl; + } else + cout << m << endl; + return (0); +} +int main() { + string s, s2; + int n, ans = 0; + cin >> n >> s >> s2; + for (int i = 0; i < n; i++) { + int x = s[i] - 48; + int y = s2[i] - 48; + if (y > x) swap(x, y); + ans += min(abs(x - y), min(((10 - x) + y), (x + y))); + } + cout << ans << endl; +} +long long n, num[1000000]; +int main() { + cin >> n; + for (long long i = 1; num[i - 1] <= 1e10; i++) num[i] = num[i - 1] + num[i - 1] + 1; + for (long long i = 1; num[i] <= 1e10; i++) + if (num[i - 1] < n && num[i] >= n) { + cout << i << endl; + return 0; + } + return 0; +} +int main() { + int num; + cin >> num; + int ans = 0; + for (int i = 1; i * i <= num; i++) { + if (num % i == 0) { ans = i; } + } + cout << ans << " " << num / ans << endl; + return 0; +} +map M; +int main() { + string word, words; + cin >> word; + for (int i = 0; i <= 9; i++) { + string a; + cin >> a; + M[a] = i; + } + for (int i = 0; word[i]; i += 10) { + words = word.substr(i, 10); + cout << M[words]; + } + cout << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin.ignore(); + cin >> s; + cin.ignore(); + int l, r; + char a, b; + while (m--) { + cin >> l >> r; + cin >> a >> b; + l--; + r--; + for (int i = l; i <= r; i++) { + if (s[i] == a) { s[i] = b; } + } + } + cout << s << endl; +} +int a, b, x; +int main() { + cin >> a >> b; + x = min(a, b); + cout << x << " "; + a -= x; + b -= x; + a == 0 ? cout << b / 2 : cout << a / 2; + cout << "\n"; +} +int port[30005]; +bool visit[30005]; +bool dfs(int now, int end) { + if (visit[now]) + return 0; + else + visit[now] = 1; + if (now == end) return 1; + return dfs(now + port[now], end); +} +int main() { + int N, end; + cin >> N >> end; + for (int i = 0; i < N - 1; i++) { cin >> port[i]; } + memset(visit, 0, sizeof(visit)); + if (dfs(0, end - 1)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, i, x, y, d = 999, s = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x >> y; + d = min(d, y); + s += x * d; + } + cout << s << endl; + return 0; +} +const int MAXN = 105; +int takeoffHour = 0, takeoffMin = 0; +int h[MAXN], m[MAXN]; +bool splitTime(int diff, int s, int last) { + if (diff <= 2 * s + 1) { return false; } + takeoffHour = (last + s + 1) / 60; + takeoffMin = (last + s + 1) % 60; + cout << takeoffHour << " " << takeoffMin << endl; + return true; +} +int main() { + int n, s; + cin >> n >> s; + for (int i = 0; i < n; i++) { cin >> h[i] >> m[i]; } + int diff = 60 * h[0] + m[0]; + if (diff > s) { + cout << 0 << " " << 0 << endl; + return 0; + } + for (int i = 1; i < n; i++) { + if (h[i] < h[i - 1]) h[i] += 24; + int last = 60 * h[i - 1] + m[i - 1]; + int now = 60 * h[i] + m[i]; + int diff = now - last; + if (splitTime(diff, s, last)) { return 0; } + } + int now = 60 * h[n - 1] + m[n - 1]; + takeoffHour = (now + s + 1) / 60; + takeoffMin = (now + s + 1) % 60; + cout << takeoffHour << " " << takeoffMin << endl; +} +int main() { + int n; + string name, position, captin; + vector rat; + vector wc; + vector man; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> name >> position; + if (position == "woman" || position == "child") { + wc.push_back(name); + } else if (position == "man") { + man.push_back(name); + } else if (position == "rat") { + rat.push_back(name); + } else + captin = name; + } + for (int i = 0; i < rat.size(); i++) { cout << rat[i] << endl; } + for (int i = 0; i < wc.size(); i++) { cout << wc[i] << endl; } + for (int i = 0; i < man.size(); i++) { cout << man[i] << endl; } + cout << captin << endl; + return 0; +} +long long n, a[1000001]; +int main() { + cin >> n; + n *= 2; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + long long ans = (a[n / 2] - a[1]) * (a[n] - a[n / 2 + 1]); + for (int i = 2; i <= n / 2 + 1; i++) ans = min(ans, (a[i + n / 2 - 1] - a[i]) * (a[n] - a[1])); + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int ans = 0; + for (int i = 0; i < len; i++) { + int q = 0; + int cnt = 0; + for (int j = i; j < len; j++) { + if (s[j] == '?') + q++; + else if (s[j] == '(') + cnt++; + else + cnt--; + while (q > 0 && q > cnt) { + q--; + cnt++; + } + if (cnt < 0) break; + if ((j - i + 1) % 2 == 0 && q >= cnt) ans++; + } + } + cout << ans << endl; +} +void File() { + freopen("colors.in", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 1e5 + 5; +const int oo = 0x3f3f3f3f; +int main() { + fast(); + int n, t, k, d; + cin >> n >> t >> k >> d; + int res1 = (n + k - 1) / k; + res1--; + res1 *= t; + if (res1 > d) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + vector v; + int s = 0; + while (n) { + int i; + cin >> i; + v.push_back(i); + s += i; + --n; + } + sort(v.begin(), v.end()); + int c = 0, c1 = 0; + while (!v.empty()) { + if (c1 > s / 2) + break; + else { + c++; + c1 += v.back(); + v.pop_back(); + } + } + cout << c << endl; + return 0; +} +int Arr[10] = {0}; +int SumOfK(int k) { + int count = 0; + for (int i = 0; i <= k; ++i) { + if (Arr[i] == 1) count++; + } + return count; +} +void resetArr() { + for (int i = 0; i < 11; ++i) { Arr[i] = 0; } +} +int main() { + int n, k; + cin >> n >> k; + unsigned long long a; + int count = 0; + while (n--) { + cin >> a; + while (a) { + if (a % 10 <= k) Arr[a % 10] = 1; + a /= 10; + } + if (SumOfK(k) == k + 1) count++; + resetArr(); + } + cout << count << endl; + return 0; +} +int main() { + unsigned int n; + cin >> n; + for (unsigned int i = 0; i < n; ++i) { + unsigned int a, b; + cin >> a >> b; + unsigned int r = 0; + if (a > b) swap(a, b); + while (a) { + r += b / a; + b %= a; + swap(a, b); + } + cout << r << '\n'; + } + return 0; +} +int edges[1004][1004]; +int degree[1004]; +void dfs(int index, int cap, int *visited, int *numedges, int *numver, int n) { + visited[index] = 1; + for (int i = 0; i < n; i++) { + if (edges[index][i] == 1) { + if (visited[i] == 0) { + numedges[cap] += degree[i]; + numver[cap]++; + dfs(i, cap, visited, numedges, numver, n); + } + } + } +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int cap[k]; + for (int i = 0; i < k; i++) { + cin >> cap[i]; + cap[i]--; + } + int a, b; + int visited[n]; + for (int i = 0; i < n; i++) { + visited[i] = 0; + degree[i] = 0; + } + for (int i = 0; i < m; i++) { + cin >> a >> b; + a--; + b--; + edges[a][b] = 1; + edges[b][a] = 1; + degree[a]++; + degree[b]++; + } + int numedges[k + 1]; + int numver[k + 1]; + for (int i = 0; i < k + 1; i++) { + numedges[i] = 0; + numver[i] = 0; + } + int count = 0; + for (int i = 0; i < k; i++) { + dfs(cap[i], i, visited, numedges, numver, n); + numedges[i] += degree[cap[i]]; + numver[i] += 1; + } + for (int i = 0; i < n; i++) { + if (visited[i] == 0) { + dfs(i, k, visited, numedges, numver, n); + numedges[k] += degree[i]; + numver[k]++; + } + } + int maxm = 0; + int maxindex = 0; + long long ans = 0; + for (int i = 0; i < k; i++) { + if (numver[i] > maxm) { + maxm = numver[i]; + maxindex = i; + } + } + for (int i = 0; i < k; i++) { + if (i == maxindex) continue; + long long xx = numver[i] * (numver[i] - 1); + xx /= 2; + ans += (xx - numedges[i] / 2); + } + long long xx = numver[maxindex] + numver[k]; + long long x2 = (xx * (xx - 1)) / 2; + x2 -= numedges[maxindex] / 2; + x2 -= numedges[k] / 2; + ans += x2; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n > 0) { + cout << n << endl; + } else { + int temp1 = n / 10; + int temp2 = (n / 100) * 10 - abs(n) % 10; + cout << (temp1 > temp2 ? temp1 : temp2) << endl; + } + return 0; +} +int main() { + double n; + cin >> n; + double x = sqrt(2 * n + 0.25); + long long i = (long long)(x - 0.5); + int m; + if (n > (i + 1) * i / 2) + m = n - (i + 1) * i / 2; + else + m = n - (i - 1) * i / 2; + cout << m << endl; + return 0; +} +int main() { + int totalSec; + int check = 1; + int chat = 0, peeps = 1; + cin >> totalSec; + int id[totalSec]; + for (int i = 0; i < totalSec; i++) { cin >> id[i]; } + for (int i = 0; i < totalSec; i++) { + if (id[i] == 0) { + continue; + } else { + for (int j = i + 1; j < totalSec; j++) { + if (id[i] == id[j]) { + id[j] = 0; + peeps++; + chat++; + } + } + if (peeps >= 3) { + check = 0; + break; + } else { + peeps = 1; + } + } + } + if (check == 0) { + cout << -1 << endl; + } else { + cout << chat << endl; + } + return 0; +} +long long int n, i, x; +int main() { + while (cin >> n) { + i = 0; + x = n; + while (x != 0) { + if (x % 2 == 0) + x = x / 2; + else + x = (x - 1) / 2; + i++; + } + cout << i << endl; + } + return 0; +} +int main() { + vector v; + int i, val; + for (i = 0; i < 3; i++) { + cin >> val; + v.push_back(val); + } + sort(v.begin(), v.end()); + int ans = v[1] - v[0] + v[2] - v[1]; + cout << ans << endl; +} +map p; +string a, b; +int ans1, ans2; +int main() { + p["8<"] = 1, p["()"] = 2, p["[]"] = 3; + cin >> a >> b; + for (int i = 0; i < a.length(); i += 2) { + int s1 = p[a.substr(i, 2)], s2 = p[b.substr(i, 2)]; + if (s1 == 1) { + if (s2 == 2) + ans2++; + else if (s2 == 3) + ans1++; + } else if (s1 == 2) { + if (s2 == 1) + ans1++; + else if (s2 == 3) + ans2++; + } else { + if (s2 == 1) + ans2++; + else if (s2 == 2) + ans1++; + } + } + if (ans1 > ans2) + puts("TEAM 1 WINS"); + else if (ans1 < ans2) + puts("TEAM 2 WINS"); + else + puts("TIE"); + return 0; +} +const int N = 3e5 + 10; +const int SQRTN = 320; +const int LOGN = 20; +const long double PI = acos(-1); +long long n, prv = 2, ans; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { + ans = (i + 1) * (i + 1) * i; + ans -= prv; + prv = i; + cout << ans << endl; + } + return 0; +} +int a[200]; +int main() { + memset(a, 0, sizeof(a)); + int n, k, flag1 = 0, flag2 = 0; + double e = 0, s = 0, max = 0; + cin >> n >> k; + for (int h = 0; h < n; h++) { cin >> a[h]; } + for (int i = 0; i < n; i++) { + int j, l, fff1 = i, fff2 = i; + flag1 = 0; + flag2 = 0, e = 0, s = 0; + for (j = i - 1, l = i + 1;; j--, l++) { + if (j < 0) flag1 = 1; + if (a[l] == 0) flag2 = 1; + if (flag1 == 0 && (a[j] == 1) && ((fff1 - j) != k)) + e++; + else if (flag1 == 0 && (a[j] == -1) && ((fff1 - j) != k)) + s++; + if (fff1 - j == k) { fff1 = j; } + if (flag2 == 0 && (a[l] == 1) && ((l - fff2) != k)) + e++; + else if (flag2 == 0 && (a[l] == -1) && ((l - fff2) != k)) + s++; + if (l - fff2 == k) { fff2 = l; } + if (flag1 == 1 && flag2 == 1) break; + } + if (fabs(e - s) > max) max = fabs(e - s); + } + cout << int(max) << endl; + return 0; +} +int a[10]; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'B') + a[0]++; + else if (s[i] == 'u') + a[1]++; + else if (s[i] == 'l') + a[2]++; + else if (s[i] == 'b') + a[3]++; + else if (s[i] == 'a') + a[4]++; + else if (s[i] == 's') + a[5]++; + else if (s[i] == 'r') + a[6]++; + } + a[4] = a[4] / 2; + a[1] = a[1] / 2; + sort(a, a + 7); + cout << a[0] << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const int mod = 998244353; +char a[100005], b[100005]; +int main() { + cin >> a >> b; + if (strcmp(a, b) == 0) + return puts("-1"), 0; + else + cout << max(strlen(a), strlen(b)) << endl; + return 0; +} +const int maxn = 1005; +const int mod = 1e9 + 7; +int main() { + int n, ans = 0; + int a[32][32]; + int row[32] = {0}, col[32] = {0}; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + row[i] = row[i] + a[i][j]; + col[j] = col[j] + a[i][j]; + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (col[j] > row[i]) ans++; + cout << ans << endl; +} +int main() { + string s1, s2, s; + int i, pos1, pos2; + char a[10] = "6789TJQKA"; + cin >> s; + cin >> s1 >> s2; + if (s1[1] == s[0]) { + if (s2[1] != s[0]) { + cout << "YES" << endl; + } else { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) { pos1 = i; } + if (s2[0] == a[i]) { pos2 = i; } + } + if (pos1 <= pos2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } + } else { + if (s1[1] == s2[1]) { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) { pos1 = i; } + if (s2[0] == a[i]) { pos2 = i; } + } + if (pos1 <= pos2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int t; + cin >> t; + long long res, s, a, b, c; + for (int i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + res = s / c; + res += (res / a) * b; + cout << res << '\n'; + } +} +int main() { + int n, sum = 0; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + for (int i = 0; i < n; i++) { + if (abs(s1[i] - s2[i]) < 4) + sum += abs(s1[i] - s2[i]); + else if (abs(s1[i] - s2[i]) == 4) + sum += 4; + else { + int c = (s1[i] > s2[i]) ? s1[i] : s2[i]; + int c1 = (s1[i] < s2[i]) ? s1[i] : s2[i]; + sum += 10 - c + c1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, k, mohi, x = 0, y = 0, z = 0; + vector v; + int arr[3]; + arr[0] = 0; + arr[1] = 0; + arr[2] = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + v.push_back(k); + } + k = 0; + for (int i = 0; i < n; i++) { + if (v[i] == 1) + arr[0]++; + else if (v[i] == 2) + arr[1]++; + else + arr[2]++; + } + mohi = arr[0]; + for (int i = 1; i < 3; i++) { + if (arr[i] < mohi) mohi = arr[i]; + } + cout << mohi << endl; + for (int i = 0; i < mohi; i++) { + for (int j = x; j < n; j++) { + if (v[j] == 1) { + cout << j + 1 << " "; + x = j + 1; + break; + } + } + for (int j = y; j < n; j++) { + if (v[j] == 2) { + cout << j + 1 << " "; + y = j + 1; + break; + } + } + for (int j = z; j < n; j++) { + if (v[j] == 3) { + cout << j + 1 << endl; + z = j + 1; + break; + } + } + } +} +int main() { + string s; + cin >> s; + set my; + int i, j; + for (i = 0; i < s.size(); i++) { + string t = ""; + t += s[s.size() - 1]; + for (j = 0; j < s.size() - 1; j++) t += s[j]; + my.insert(t); + s = t; + } + cout << my.size() << endl; + return 0; +} +int main() { + int n, d, i, j, flag, len; + int sum = 0, maxx = 0; + char s[110]; + cin >> n >> d; + getchar(); + while (d--) { + flag = 1; + cin >> s; + len = strlen(s); + for (i = 0; i < len; i++) { + if (s[i] == '0') flag = 0; + } + if (!flag) sum++; + maxx = max(maxx, sum); + if (flag) sum = 0; + } + cout << maxx << endl; + return 0; +} +long long gcd(long long a, long long b) { + while (a > 0 && b > 0) { + if (a > b) + a %= b; + else + b %= a; + } + return a + b; +} +long long f[10010]; +int main() { + long long a, b, s = 0, k, n, i, j, x, y, c; + cin >> a >> b >> c; + if (c % gcd(a, b)) { + cout << "No" << endl; + return 0; + } + x = 10000 / a; + y = 10000 / b; + for (i = 0; i <= x + 1; i++) { + for (j = 0; j <= y + 1; j++) { + if (i * a + j * b <= 10005) f[i * a + j * b]++; + } + } + if (f[c]) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + long long n, m, a, b; + while (cin >> n >> m >> a >> b) { cout << min((m - n % m) * a, n % m * b) << endl; } + return 0; +} +int s[1001000]; +int main() { + long long n; + cin >> n; + s[1] = 1; + s[2] = 3; + for (int i = 3; i <= n; i++) { s[i] = (s[i - 1] + s[i - 2] + 2) % 1000000007; } + cout << s[n] << endl; + return 0; +} +int main() { + int sum = 0; + int tc; + int a[100]; + cin >> tc; + for (int i = 0; i < tc; i++) { cin >> a[i]; } + int max = a[0]; + for (int i = 0; i < tc; i++) { + if (a[i] > max) max = a[i]; + } + for (int i = 0; i < tc; i++) { sum += max - a[i]; } + cout << sum << endl; + return 0; +} +int main() { + char ch[2][200] = {0}; + cin.getline(ch[0], 200); + cin.getline(ch[1], 200); + for (int i = 0; ch[0][i] != 0; i++) { + if (ch[0][i] == '1' ^ ch[1][i] == '1') { + cout << 1; + } else + cout << 0; + } + cout << endl; + return 0; +} +int a[10010]; +int main() { + a[0] = 0; + for (int i = 1; i <= 10000; i++) a[i] = a[i - 1] + i; + int n; + while (cin >> n) { + int ans = 0; + for (int i = 1;; i++) { + if (n >= a[i]) + n -= a[i], ans++; + else + break; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, k, w, ans = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> w; + ans += (w % k == 0 ? w / k : w / k + 1); + } + cout << (ans % 2 == 0 ? ans / 2 : ans / 2 + 1) << endl; +} +int64_t n; +int64_t i = 0; +int64_t a; +int main() { + cin >> n; + int64_t result[n]; + while (i < n) { + cin >> a; + result[i] = a; + i += 1; + }; + sort(result, result + n); + int64_t d = result[1] - result[0]; + int64_t i2 = 1; + i = 1; + while (i < n - 1) { + if (result[i + 1] - result[i] < d) { + i2 = 1; + d = result[i + 1] - result[i]; + } else if (result[i + 1] - result[i] == d) { + i2 += 1; + }; + i += 1; + }; + cout << d << " "; + cout << i2 << endl; + return 0; +} +int main() { + long long int n, k, a, b, c; + cin >> n >> k; + a = (n / 2) / (k + 1); + b = k * a; + c = n - (a + b); + cout << a << " " << b << " " << c << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 == 0) + a[i][j] = '#'; + else { + if ((i + 1) % 4 == 0) { + if (j == 0) + a[i][j] = '#'; + else + a[i][j] = '.'; + } else if ((i + 1) % 2 == 0) { + if (j == m - 1) + a[i][j] = '#'; + else + a[i][j] = '.'; + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +int t; +map m; +int main() { + cin >> t; + while (t--) { + char x; + cin >> x; + if (x == '+') { + string s, s2, s1; + cin >> s; + int siz = s.size(); + for (int i = 0; i < siz; i++) { + if (((int(s[i]) - '0') % 2) == 1) { + s1 = s1 + "1"; + } else { + s1 = s1 + "0"; + } + } + for (int i = 0; i < 19 - siz; i++) { s2 = s2 + "0"; } + s2 = s2 + s1; + m[s2]++; + } + if (x == '-') { + string s, s2, s1; + cin >> s; + int siz = s.size(); + for (int i = 0; i < siz; i++) { + if ((int(s[i]) - '0') % 2 == 0) { + s1 = s1 + "0"; + } else { + s1 = s1 + "1"; + } + } + for (int i = 0; i < 19 - siz; i++) { s2 = s2 + "0"; } + s2 = s2 + s1; + m[s2]--; + } + if (x == '?') { + string s, s2, s1; + cin >> s; + int siz = s.size(); + for (int i = 0; i < 19 - siz; i++) { s2 = s2 + "0"; } + s2 = s2 + s; + cout << m[s2] << endl; + } + } +} +int n, a, b; +int main() { + int count = 0; + cin >> n >> a >> b; + if (a + b + 1 < n) a = n - b - 1; + count = n - a; + cout << count << endl; + return 0; +} +vector divisor(1000000 + 1, 0); +int bigmod(long long a, long long b, long long c) { + long long x; + if (b == 0) return 1 % c; + x = bigmod(a, b / 2, c); + x = (x * x) % c; + if (b & 1) x = (x * a) % c; + return x; +} +ulong long factorial(long long n) { + ulong long fact = 1; + for (int i = 2; i <= n; i++) { fact *= i; } + return fact; +} +int main() { + int x, y; + while (cin >> x >> y) { + int mn = min(x, y); + ulong long A = factorial(mn); + cout << (__gcd(A, A)) << endl; + } + return 0; +} +; +const double eps = 1e-8; +const int maxn = 1e6 + 7; +const double pi = acos(-1); +const int inf = 0x3f3f3f3f; +int n; +int a[10]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int x = (a[n] - a[1]) / 2; + cout << a[1] + x << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i <= n / 2; i++) { + for (int j = 0; j < n / 2 - i; j++) cout << '*'; + for (int j = n / 2 - i; j <= n / 2 + i; j++) cout << 'D'; + for (int j = n / 2 + i + 1; j < n; j++) cout << '*'; + cout << endl; + } + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j <= i; j++) cout << '*'; + for (int j = i + 1; j <= n - 2 - i; j++) cout << 'D'; + for (int j = n - 1 - i; j < n; j++) cout << '*'; + cout << endl; + } +} +int64_t n; +int64_t i = 0; +int64_t x; +int64_t y; +int64_t answer = 0; +int main() { + cin >> n; + while (i < n) { + cin >> x; + cin >> y; + if (x < 0) { answer += 1; }; + i += 1; + }; + if (n - answer <= 1 || answer == 1 || answer == 0) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + }; + return 0; +} +void in_out_txt() { + freopen("input.txt", "rt", stdin); + freopen("output.txt", "wt", stdout); +} +void FillArray(int arr[], int n, int num) { + for (int i = 0; i < n; i++) arr[i] = num; +} +int fun(int num) { + int re; + set st; + while (num != 0) { + re = num % 10; + num /= 10; + st.insert(re); + } + int s = st.size(); + return s; +} +int main() { + int n; + cin >> n; + char arr[101][101]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> arr[i][j]; + } + int c = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] == 'C') { + for (int k = j + 1; k < n; k++) { + if (arr[i][k] == 'C') c++; + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] == 'C') { + for (int k = i + 1; k < n; k++) { + if (arr[k][j] == 'C') c++; + } + } + } + } + cout << c << endl; + return 0; +} +int main() { + int a[3], i; + for (i = 0; i < 3; i++) cin >> a[i]; + sort(a, a + 3); + if (a[0] + a[1] > a[2]) { + cout << 0 << endl; + } else { + cout << a[2] + 1 - a[0] - a[1] << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[200000]; + a[0] = 0; + int m; + cin >> m; + for (int i = 1; i < n; i++) { cin >> a[i]; } + int j = 1; + while (j < m) { j += a[j]; } + if (j == m) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +vector arr(10000); +int main() { + int n, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + ++arr[x]; + } + cout << *max_element(arr.begin(), arr.end()) << endl; +} +const int maxn = 1e5 + 10; +const int mod = 1e9 + 7; +const int maxl = 30 + 1; +int a[maxn]; +int rc[maxn * maxl], lc[maxn * maxl]; +int newint = 2; +void add(int x) { + int cur = 1; + for (int i = 29; i >= 0; i--) { + if (x & (1 << i)) { + if (rc[cur] == 0) rc[cur] = newint++; + cur = rc[cur]; + } else { + if (lc[cur] == 0) lc[cur] = newint++; + cur = lc[cur]; + } + } +} +int get(int x) { + int cur = 1, ret = 0; + for (int i = 29; i >= 0; i--) { + if (x & (1 << i)) { + if (lc[cur] != 0) { + cur = lc[cur]; + ret += (1 << i); + } else { + cur = rc[cur]; + } + } else { + if (rc[cur] != 0) { + cur = rc[cur]; + ret += (1 << i); + } else { + cur = lc[cur]; + } + } + } + return ret; +} +int main() { + int n; + cin >> n; + int ans = 0, pre = 0; + add(0); + for (int i = 0; i < n; i++) { + int a; + cin >> a; + pre ^= a; + ans = max(ans, get(pre)); + add(pre); + } + cout << ans << endl; +} +long long a[202000]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= (n << 1); ++i) { cin >> a[i]; } + sort(a + 1, a + 1 + n + n); + long long s = 1ll << 62; + s = min(s, (a[n] - a[1]) * (a[n << 1] - a[n + 1])); + for (int i = 2; i <= n; i++) { s = min(s, (a[n << 1] - a[1]) * (a[n + i - 1] - a[i])); } + cout << s << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int m = n % 10; + long int d = n / 10; + if (m == 0) { + cout << n << endl; + } else if (m <= 5) { + cout << n - m << endl; + } else if (m > 5) { + cout << n + 10 - m << endl; + } +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + cout << (d + t < (n + k - 1) / k * t ? "YES\n" : "NO\n"); + return 0; +} +const int MAX = 3e4 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +const double pi = acos(-1); +const double eps = 1e-9; +long long n, m; +long long pw() { + long long ret = 1, x = 3; + while (n) { + if (n & 1) ret = (ret * x) % m; + x = (x * x) % m; + n >>= 1; + } + return ret; +} +int main() { + cin >> n >> m; + cout << (pw() + m - 1) % m << "\n"; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + cout << s1[0]; + for (int i = 1; i <= s1.length(); i++) { + if (i == s1.length()) { + cout << s2[0] << endl; + break; + } + if (s2[0] > s1[i]) + cout << s1[i]; + else { + cout << s2[0] << endl; + break; + } + } + return 0; +} +int main() { + int N; + string q; + unsigned long long int a = 1, b = 1; + cin >> N; + for (int x = 0; x < N; x++) { + cin >> q; + if (q == "UL" || q == "DR") + a++; + else if (q == "ULDR") + a++, b++; + else + b++; + } + cout << a * b << endl; + return 0; +} +int main() { + int tc; + cin >> tc; + while (tc--) { + int n, v, l, r; + cin >> n >> v >> l >> r; + int t = n / v; + int t1 = ((r / v) - ((l - 1) / v)); + cout << t - t1 << endl; + } + return 0; +} +int main() { + int n; + int d; + cin >> n >> d; + priority_queue q; + for (int i = 0; i < n - 1; i++) { + int a; + cin >> a; + q.push(a); + } + int res = 0; + int maxv = q.top(); + q.pop(); + while (d <= maxv) { + d++; + maxv--; + res++; + q.push(maxv); + maxv = q.top(); + q.pop(); + } + cout << res << endl; +} +inline long long llMax(long long a, long long b) { + return a > b ? a : b; +} +inline long long llMin(long long a, long long b) { + return a > b ? b : a; +} +int main() { + long long n, k, a; + cin >> n >> k; + a = (n / 2) / (k + 1); + cout << a << " " << k * a << " " << n - (k + 1) * a << endl; + return 0; +} +int main() { + int n, a; + cin >> n; + string s; + vector v(n), v1(n); + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = 0; i < n; i++) cin >> v1[i]; + sort(v.begin(), v.end()); + sort(v1.begin(), v1.end()); + int ct = 0; + int i = 0, j = 0; + while (i < n && j < n) { + if (v[i] < v1[j]) + i++; + else if (v[i] > v1[j]) + j++; + else { + ct++; + i++; + j++; + } + } + cout << n - ct << endl; + return 0; +} +int main() { + int n, k, i, a, mx; + cin >> n >> k; + mx = 0; + for (i = 0; i < n; i++) { + cin >> a; + if (k % a == 0) { + if (a > mx) mx = a; + } + } + cout << k / mx << endl; + return 0; +} +const double PI = 4 * atan(1); +int gcd(int n, int m) { + return m == 0 ? n : gcd(m, n % m); +} +int main() { + int n, k; + int num[400]; + while (cin >> n >> k) { + memset(num, 0, sizeof(num)); + int m; + cin >> m; + for (int i = 1; i <= m; i++) { + int tt; + cin >> tt; + num[tt] = 1; + } + int kk = k; + int ans = 0; + for (int i = 1; i <= n; i++) { + if (num[i]) { + ans++; + kk = k; + } else { + kk--; + if (kk == 0) { + ans++; + kk = k; + } + } + } + cout << ans << endl; + } + return 0; +} +int n, m, i = 1; +int main() { + cin >> n >> m; + do { + m -= i; + i++; + if (i > n) i = 1; + } while (m >= i); + cout << m << endl; + return 0; +} +int main() { + char arr[105][105]; + for (int i = 0; i < 105; i++) { + for (int j = 0; j < 105; j++) { + if ((i + j) % 2 == 0) + arr[i][j] = 'B'; + else + arr[i][j] = 'W'; + } + } + int m, n; + cin >> m >> n; + for (int i = 0; i < m; i++) { + string temp; + cin >> temp; + for (int j = 0; j < n; j++) { + if (temp[j] == '.') + cout << arr[i][j]; + else + cout << "-"; + } + cout << endl; + } +} +int main() { + int n, sum = 0; + cin >> n; + string x; + for (int i = 0; i < n; i++) { + cin >> x; + if (x == "Tetrahedron") + sum += 4; + else if (x == "Cube") + sum += 6; + else if (x == "Octahedron") + sum += 8; + else if (x == "Dodecahedron") + sum += 12; + else if (x == "Icosahedron") + sum += 20; + } + cout << sum << endl; + return 0; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int sort(int a[], int n) { + for (int i = 0; i < n - 1; i++) { + for (int j = i; j < n; j++) { + if (a[i] > a[j]) { + int temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } +} +int main() { + int n1, n2, k1, k2; + cin >> n1 >> n2 >> k1 >> k2; + if (n1 > n2) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + char c; + cin >> c; + return 0; +} +long long power(long long a, long long b) { + long long ans = 1; + while (b) { + ans = ans * a; + b--; + } + return ans; +} +int main() { + long long l, r, l1, r1, ans, nol = 0, nor = 0, mid, x; + cin >> l >> r; + l1 = l; + r1 = r; + while (l) { + ++nol; + l = l / 10; + } + while (r) { + ++nor; + r = r / 10; + } + --nor; + --nol; + if (nor > nol) { + mid = 4 * power(10, nor); + x = 9 * power(10, nor); + --nor; + while (nor >= 0) { + mid += 9 * power(10, nor); + x += 9 * power(10, nor); + --nor; + } + if (r1 > mid) { + ans = mid * (x - mid); + } else { + ans = r1 * (x - r1); + } + } else { + mid = 4 * power(10, nor); + x = 9 * power(10, nor); + --nor; + while (nor >= 0) { + mid += 9 * power(10, nor); + x += 9 * power(10, nor); + --nor; + } + if (r1 <= mid) { + ans = r1 * (x - r1); + } else if (r1 > mid && l1 < mid) { + ans = mid * (x - mid); + } else { + ans = l1 * (x - l1); + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m, ans; + while (cin >> n) { + m = n % 10; + if (m <= 5) + ans = n / 10 * 10; + else + ans = (n / 10 + 1) * 10; + cout << ans << endl; + } + return 0; +} +int main() { + int n, min1, max1, min2, max2, min3, max3; + cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; + int a(min1), b(min2), c(min3), t(min1 + min2 + min3); + while (t < n) { + if (a < max1) + a++; + else if (b < max2) + b++; + else if (c < max3) + c++; + t++; + } + cout << a << " " << b << " " << c << endl; + return 0; +} +int n, a, i, f[100001]; +int main() { + cin >> n; + for (i = 1; i < n; i++) { + cin >> a; + f[a] = 1; + } + for (i = 1; i <= n; i++) + if (f[i] == 0) { + cout << i << endl; + return 0; + } +} +string st; +set se, ans; +int main() { + int n, cnt = 0; + cin >> n; + char c; + bool flag = false; + for (int i = 0; i < 26; i++) ans.insert('a' + i); + for (int i = 1; i < n; i++) { + cin >> c >> st; + if (c == '!') { + if (!flag) { + se.clear(); + for (int j = 0; j < st.length(); j++) se.insert(st[j]); + for (set::iterator j = ans.begin(); j != ans.end();) { + if (!se.count(*j)) { + set::iterator k = j; + j++; + ans.erase(k); + } else + j++; + } + } else + cnt++; + } else if (c == '.' && !flag) { + for (int j = 0; j < st.length(); j++) + if (ans.count(st[j])) ans.erase(st[j]); + } else if (c == '?') { + if (!flag) { + if (ans.count(st[0])) ans.erase(st[0]); + } else + cnt++; + } + if (ans.size() == 1) flag = true; + } + cout << cnt << "\n"; + return 0; +} +bool istrue(string x, int k) { + for (int i = 0; i <= k; i++) { + if ((x[i] - '0') != i) { + return false; + break; + } + } + return true; +} +int main() { + int n, k, cnt = 0; + cin >> n >> k; + string x; + for (int i = 0; i < n; i++) { + cin >> x; + sort(x.begin(), x.end()); + x.erase(unique(x.begin(), x.end()), x.end()); + if (x.size() >= k + 1) { + if (istrue(x, k)) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +int main() { + long long n, i, c; + while (cin >> n) { + vector a; + for (i = 0; i < n; i++) { + cin >> c; + a.push_back(c); + } + sort(a.begin(), a.end()); + long long cha, z = 2000000009, num = 0; + for (i = 1; i < n; i++) { + cha = a[i] - a[i - 1]; + if (cha < z) { + z = cha; + num = 1; + } else { + if (cha == z) num++; + } + } + cout << z << " " << num << endl; + a.clear(); + } + return 0; +} +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + for (int _ = 1; _ <= k; _++) { + int ta, fa, tb, fb; + cin >> ta >> fa >> tb >> fb; + if (ta == tb) { + cout << abs(fa - fb) << endl; + continue; + } + if (a <= fa && fa <= b) { + cout << abs(ta - tb) + abs(fa - fb) << endl; + continue; + } + if (a <= fb && fb <= b) { + cout << abs(ta - tb) + abs(fa - fb) << endl; + continue; + } + int ans1 = 0, ans2 = 0; + ans1 = abs(fa - b) + abs(ta - tb) + abs(fb - b); + ans2 = abs(fa - a) + abs(ta - tb) + abs(fb - a); + cout << min(ans1, ans2) << endl; + } + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int a, b, c; + b = (n / 2) / (k + 1); + c = b * k; + a = n - b - c; + cout << b << " " << c << " " << a << "\n"; + return 0; +} +int main() { + string a, b, t, tt; + int n, i; + cin >> a >> b; + cin >> n; + cout << a << " " << b << endl; + ; + for (i = 0; i < n; i++) { + cin >> t >> tt; + if (t == a) + a = tt; + else + b = tt; + cout << a << " " << b << endl; + } + return 0; +} +int main() { + long long int l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (int i = x; i <= y; i++) { + if ((i * k) >= l && (i * k) <= r) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int Mininum(long long a, long long b) { + if (b >= a) swap(a, b); + long long c; + for (c = b; c % a != 0; c += b) + ; + return c; +} +int main() { + string a, b; + long long n; + cin >> n >> a >> b; + int l1 = a.length(), l2 = b.length(); + long long both = Mininum(l1, l2); + short prog[both] = {0}; + for (int i = 0; i < both; i++) { + if (a[i % l1] == 'P') { + if (b[i % l2] == 'P') { + prog[i] = 0; + } else if (b[i % l2] == 'R') { + prog[i] = 1; + } else { + prog[i] = 2; + } + } else if (a[i % l1] == 'R') { + if (b[i % l2] == 'P') { + prog[i] = 2; + } else if (b[i % l2] == 'R') { + prog[i] = 0; + } else { + prog[i] = 1; + } + } else { + if (b[i % l2] == 'P') { + prog[i] = 1; + } else if (b[i % l2] == 'R') { + prog[i] = 2; + } else { + prog[i] = 0; + } + } + } + int loss1 = 0, loss2 = 0, rl1, rl2; + for (int i = 0; i < both; i++) { + if (prog[i] != 0) { + if (prog[i] == 1) { + loss2++; + } else { + loss1++; + } + } + } + rl1 = n / both * loss1; + rl2 = n / both * loss2; + for (int i = 0; i < n % both; i++) { + if (prog[i] == 1) rl2++; + if (prog[i] == 2) rl1++; + } + cout << rl1 << ' ' << rl2 << endl; + return 0; +} +long long base = 1000000009; +int main() { + int n, m; + cin >> n >> m; + long long d = 1; + for (int i = 0; i < m; i++) { + d *= 2; + d %= base; + } + long long ans = 1; + for (int i = 0; i < n; i++) { + d--; + if (d < 0) d += base; + ans *= d; + ans %= base; + } + cout << ans << endl; + return 0; +} +int main() { + int t; + cin >> t; + int i; + long long right, left, num, end = 0; + for (i = 1; i <= t; i++) { + cin >> right >> left >> num; + int a = num / 2; + if ((num % 2) == 1) { + end = a * right - a * left + right; + } else + end = a * right - a * left; + cout << end << endl; + } + return 0; +} +int main() { + int n, m; + string s; + cin >> n >> m >> s; + while (m--) { + int l, r; + char from, to; + cin >> l >> r >> from >> to; + l--, r--; + for (int i = l; i <= r; i++) + if (s[i] == from) s[i] = to; + } + cout << s << endl; + return 0; +} +int main() { + int n, m, i, j, x; + cin >> n >> m; + int num[n]; + for (i = 0; i < n - 1; i++) { cin >> num[i]; } + i = 1; + x = 1; + while (1) { + i = num[i - 1] + i; + if (i == m) { + cout << "YES\n"; + break; + } else if (i >= n) { + cout << "NO\n"; + break; + } + } +} +long long n, k; +int a, b; +int main() { + cin >> n >> k >> a >> b; + if (n % k == 0) + cout << 0 << endl; + else { + long long sum1 = n % k * b; + long long sum2 = (k - n % k) * a; + cout << min(sum1, sum2) << endl; + } +} +int main() { + string s; + cin >> s; + int l = s.length(); + for (int i = 1; i < l; i++) { + if (s[i] == s[i - 1]) { + s.erase(i - 1, 2); + i -= 2; + } + } + cout << s << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; ++i) { + string temp; + cin >> temp; + for (int j = 0; j < m; ++j) { arr[i][j] = temp[j]; } + } + int ans = 0; + for (int i = 0; i < n - 1; ++i) { + for (int j = 0; j < m - 1; ++j) { + string a1 = ""; + a1 += arr[i][j]; + a1 += arr[i][j + 1]; + a1 += arr[i + 1][j]; + a1 += arr[i + 1][j + 1]; + sort(a1.begin(), a1.end()); + if (a1 == "acef") { ans++; } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int A, B, C; + cin >> A; + if (A > 0 && A <= 1000000) { + C = A / 5; + B = A % 5; + if (A <= 5) + cout << 1 << endl; + else if (B != 0) + cout << C + 1 << endl; + else + cout << C << endl; + } + return 0; +} +int main() { + string s1; + string s2; + cin >> s1; + cin >> s2; + string s3; + for (int i = 0; i < s1.length(); i++) { + if ((s1[i] == '0' && s2[i] == '0') || (s1[i] == '1' && s2[i] == '1')) { + s3 = s3.append(1, '0'); + } else if ((s1[i] == '1' && s2[i] == '0') || (s1[i] == '0' && s2[i] == '1')) { + s3 = s3.append(1, '1'); + } + } + cout << s3 << endl; +} +int main() { + long long int n, m; + int ans; + cin >> n; + cin >> m; + n = pow(2, n); + ans = m % n; + cout << ans << endl; +} +int main() { + int n, k, x, i; + cin >> n >> k >> x; + int a[n + 5]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int time = 0; + for (i = 0; i < (n - k); i++) { time += a[i]; } + time = time + (k * x); + cout << time << endl; +} +long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int main() { + int tmp = read(); + for (int i = 1, lim = tmp << 1; i <= lim; i++) tmp = read(); + cout << "Karen\n"; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +int temp, A; +int main() { + int B; + cin >> B; + for (int a = 0; a < B; a++) { + cin >> A; + if (a == B - 2) temp = A; + } + if (A == 15) + cout << "DOWN\n"; + else if (A == 0) + cout << "UP\n"; + else if (B == 1) + cout << "-1\n"; + else if (A > temp) + cout << "UP\n"; + else if (A < temp) + cout << "DOWN\n"; +} +int main() { + char s[2]; + cin >> s; + if (((s[0] > 'a') && (s[0] < 'h')) && ((s[1] > '1') && (s[1] < '8'))) + cout << 8 << endl; + else if (((s[0] == 'a') || (s[0] == 'h')) && ((s[1] == '1') || (s[1] == '8'))) + cout << 3 << endl; + else + cout << 5 << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + map mp; + for (int i = 0; i < n; i++) { + int num; + cin >> num; + if (num) mp[num]++; + } + int ans = 0; + for (map::iterator it = mp.begin(); it != mp.end(); it++) { + if (it->second == 2) + ans++; + else if (it->second > 2) { + ans = -1; + break; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int x, y, z, t = 0; + cin >> x >> y >> z; + for (int i = 0; i < z; i++) { + t = t + 2 * x + 2 * y - 4; + x = x - 4; + y = y - 4; + } + cout << t << endl; + return 0; +} +int main() { + int N, M; + cin >> N >> M; + int ans = 0; + for (int i = 0; i < 1001; ++i) { + for (int j = 0; j < 1001; ++j) { + if ((i * i + j == N) && (j * j + i == M)) ++ans; + } + } + cout << ans << endl; +} +int dp[1005]; +void precalc() { + dp[0] = dp[1] = 1; + for (int i = 2; i < 1001; ++i) { dp[i] = (dp[i - 1] + (dp[i - 1] * 2) % 1000003) % 1000003; } +} +int main() { + precalc(); + int n; + cin >> n; + cout << dp[n] << endl; + return 0; +} +void solve() { + int n; + string s; + cin >> n >> s; + string s1, s2; + for (int i = 0; i < n / 2; ++i) { s1.push_back(s[i]); } + for (int i = n / 2; i < n; ++i) { s2.push_back(s[i]); } + reverse(s2.begin(), s2.end()); + for (int i = 0; i < s1.size(); ++i) { + if ((abs(s1[i] - s2[i]) == 2) || (s1[i] == s2[i])) + continue; + else { + cout << "NO" << endl; + return; + } + } + cout << "YES" << endl; +} +int main() { + cout.setf(ios::fixed); + cout.precision(9); + int n; + cin >> n; + while (n--) solve(); + return 0; +} +int main() { + int k, r; + cin >> k >> r; + int price = k, coun = 1; + while (!(price % 10 == 0 || price % 10 == r)) { + price += k; + coun++; + } + cout << coun << endl; +} +int main() { + long long int n; + cin >> n; + long long int w, s = 3, l; + bool flag = true; + for (int i = 0; i < n; i++) { + cin >> w; + if (w == s) { + flag = false; + break; + } else { + s = 6 - w - s; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const double PI = acos(-1); +const int mod = 1e9 + 7; +const long long INF = 1e18; +const long long MAX = 1e5 + 10, N = 1e6 + 10; +const int lim = 1 << 18; +vector rot(string s) { + vector ret; + for (int i = 0; i < 4; i++) { + rotate(s.begin() + 1, s.begin() + 2, s.begin() + 5); + string x = s; + for (int j = 0; j < 4; j++) { + char tmp = s[5]; + s[5] = s[2], s[2] = s[0], s[0] = s[4], s[4] = tmp; + ret.push_back(s); + } + } + return ret; +} +int main() { + string s; + while (cin >> s) { + vector v; + sort(s.begin(), s.end()); + int cnt = 0; + do { + bool ad = true; + vector tmp = rot(s); + if (v.size()) { + for (int i = 0; i < v.size() && ad; i++) { + for (int j = 0; j < tmp.size() && ad; j++) { + if (tmp[j] == v[i]) ad = false; + } + } + } + if (ad) { + cnt++; + v.insert(v.end(), tmp.begin(), tmp.end()); + } + } while (next_permutation(s.begin(), s.end())); + cout << cnt << "\n"; + } + return 0; +} +int main() { + int c, v0, v1, a, l; + cin >> c >> v0 >> v1 >> a >> l; + int r = 0, prev = -1, sol = 0; + while (r < c) { + if (prev == -1) { + r = v0; + prev = v0; + sol++; + } else { + int speed = min(v1, prev + a); + r += speed - l; + sol++; + prev = speed; + } + } + cout << sol << '\n'; +} +const double PI = 2.0 * acos(0.0); +const int MOD = 1e9 + 7; +const int oo = 2 * MOD + 1e3; +long long gcd(long long a, long long b) { + return !b ? a : gcd(b, a % b); +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << '\n'; + return 0; +} +int main() { + int k; + cin >> k; + for (int i = 0; i < k; i++) { + int l; + cin >> l; + char in[400]; + cin >> in; + if (l == 2 && in[0] >= in[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl << 2 << endl; + cout << in[0] << " "; + cout << in + 1 << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + vector v; + for (int i = 1; i <= n; i++) { v.push_back(i); } + vector r; + int j; + for (int i = 1; i < n; i++) { + cin >> j; + r.push_back(j); + } + sort(r.begin(), r.end()); + for (int i = 0; i < n; i++) { + if (v[i] != r[i]) { + cout << v[i] << endl; + break; + } + } + return 0; +} +int minel(vector v, int x) { + int l = 11111111; + for (int i = 0; i <= x; i++) { + if (v[i] < l) { l = v[i]; } + } + return l; +} +int main() { + int n, s, e, p; + cin >> n >> s >> e; + int arr[100] = {0}; + int sum = 0; + int l = -111; + for (int i = 1; i < n; i++) { + int x, y; + cin >> x >> y; + if (e <= y) { + p = e; + } else { + p = y; + } + for (int i = x; i < p; i++) { arr[i] = arr[i] + 1; } + } + for (int i = s; i < e; i++) { + if (arr[i] == 0) { sum++; } + } + cout << sum << endl; + return 0; +} +static vector vec(26); +static bool check() { + int count = 0; + for (int i = 0; i < vec.size(); i++) + if (vec[i]) count++; + return count == vec.size() - 1; +} +static void change1(string s) { + for (int i = 0; i < s.size(); i++) vec[s[i] - 'a'] = true; +} +static void change2(string s) { + vector vec2(26); + for (int i = 0; i < s.size(); i++) vec2[s[i] - 'a'] = true; + for (int j = 0; j < 26; j++) vec[j] = (!vec2[j]) | (vec[j]); +} +int main() { + int n; + int count = 0; + cin >> n; + bool finished = false; + for (int i = 0; i < n; i++) { + char c; + string w; + cin >> c >> w; + if (i == n - 1) continue; + if (finished) { + if (c != '.') count++; + continue; + } + if (c == '.') change1(w); + if (c == '?') vec[w[0] - 'a'] = true; + if (c == '!') change2(w); + finished = check(); + } + cout << count << endl; +} +int main() { + int w, h; + cin >> w >> h; + int u1, d1; + cin >> u1 >> d1; + int u2, d2; + cin >> u2 >> d2; + for (int i = h; i > 0; i--) { + w += h; + if (h == d1) { + w -= u1; + } else if (h == d2) { + w -= u2; + } + if (w < 0) { w = 0; } + h--; + } + cout << w << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector faktori; + for (int i = 2; n > 1; i++) + while (n % i == 0) { + faktori.push_back(i); + n /= i; + } + if (faktori.size() < k) { + cout << -1 << endl; + return 0; + } else { + for (int i = 0; i < k - 1; i++) cout << faktori[i] << " "; + int z = 1; + for (int i = k - 1; i < faktori.size(); i++) z *= faktori[i]; + cout << z << endl; + } + return 0; +} +int main() { + string s; + int u = 0, l = 0; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (isupper(s[i])) u++; + if (islower(s[i])) l++; + } + if (u > l) + for (int i = 0; i < s.length(); i++) { s[i] = toupper(s[i]); } + else + for (int i = 0; i < s.length(); i++) { s[i] = tolower(s[i]); } + cout << s << endl; +} +int main() { + long long n; + while (cin >> n) { cout << "25" << endl; } +} +const int maxn = 15; +const int inf = 0x3f3f3f3f; +const double eps = 1e-10; +int main() { + double l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + if (r < k * x || l > k * y) + cout << "NO" << endl; + else { + for (long long i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + } + return 0; +} +long long fac(long long n) { + long long ans = 1; + for (long long i = 1; i <= n; i++) ans *= i; + return ans; +} +int main() { + long long a, b; + cin >> a >> b; + cout << fac(min(a, b)) << endl; + return 0; +} +int main() { + int n, m, sum = 0, i, b; + cin >> n >> m; + for (i = 0; i * i <= n && i <= m; ++i) { + b = n - i * i; + if (i + b * b == m) { sum += 1; } + } + cout << sum << endl; + return 0; +} +int main() { + long long int n, result = 0, temp, des, ex, lol, count = 0; + cin >> n; + while (1) { + temp = n; + while (temp != 0 && temp != -0) { + des = temp % 10; + if ((des == 8 || des == -8) && count == 1) { + cout << result << endl; + return 0; + } + temp = temp / 10; + } + count = 1; + n = n + 1; + result = result + 1; + } +} +int main() { + int n, m; + cin >> n >> m; + int a = min(n, m); + int b = (max(n, m) - a) / 2; + cout << a << " " << b << endl; +} +void fast() {} +void file() {} +int main() { + fast(); + file(); + int n, cnt = 0, ans = 0; + cin >> n; + char a[101][101]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + if (a[i][j] == 'C') cnt++; + } + ans += ((cnt * (cnt - 1)) / 2), cnt = 0; + } + int cn = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[j][i] == 'C') cn++; + } + ans += ((cn * (cn - 1)) / 2), cn = 0; + } + cout << ans << endl; +} +int main() { + string s; + int n, m, mi = 1e9, ma = -1e9, l = 0, r, a[1002] = {0}, k = 0, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + cin >> s; + l = 0; + for (int j = 0; j < m / 2 && l == 0; j++) + if (abs(s[j] - s[m - 1 - j]) > 2 || abs(s[j] - s[m - 1 - j]) == 1) { + l = 1; + cout << "NO" << endl; + } + if (l == 0) cout << "YES" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[6]; + int b[6]; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + for (int i = 0; i < n; i++) { + int t; + cin >> t; + a[t]++; + } + for (int i = 0; i < n; i++) { + int t; + cin >> t; + b[t]++; + } + int cnt = 0; + int judge = 1; + for (int i = 1; i <= 5; i++) { + if (abs((a[i] - b[i]) % 2 == 0)) + cnt += abs(((a[i] - b[i]) / 2)); + else { + judge = 0; + break; + } + } + if (judge == 1) + cout << cnt / 2 << endl; + else + cout << -1 << endl; +} +int main() { + string a, b; + while (cin >> a >> b) { + for (int i = 0; i < a.size(); i++) { + a[i] = toupper(a[i]); + b[i] = toupper(b[i]); + } + cout << (a < b ? -1 : (a == b ? 0 : 1)) << endl; + } +} +int main() { + long long int n, k, h; + cin >> n >> k; + h = (k / n); + if (h != 0) { + if (k % n == 0) { + cout << h << endl; + } else { + cout << h + 1 << endl; + } + } else { + cout << 1 << endl; + } + return 0; +} +map me; +long long fine[100000 + 5]; +void pre() { + for (long long i = 2; i <= 100000; i++) { + if (fine[i] == 0) { + for (long long j = 2 * i; j <= 100000; j += i) { fine[j] = 1; } + } + } +} +long long fact[100000], invfact[100000]; +long long pow(long long a, long long b, long long m) { + long long ans = 1; + while (b) { + if (b & 1) ans = (ans * a) % m; + b /= 2; + a = (a * a) % m; + } + return ans; +} +long long modinv(long long k) { + return pow(k, 1000000007 - 2, 1000000007); +} +void precompute() { + fact[0] = fact[1] = 1; + for (long long i = 2; i < 100000; i++) { + fact[i] = fact[i - 1] * i; + fact[i] %= 1000000007; + } + invfact[100000 - 1] = modinv(fact[100000 - 1]); + for (long long i = 100000 - 2; i >= 0; i--) { + invfact[i] = invfact[i + 1] * (i + 1); + invfact[i] %= 1000000007; + } +} +long long nCr(long long x, long long y) { + if (y > x) return 0; + long long num = fact[x]; + num *= invfact[y]; + num %= 1000000007; + num *= invfact[x - y]; + num %= 1000000007; + return num; +} +int main() { + long long n; + cin >> n; + precompute(); + pre(); + for (long long i = 1; i <= n; i++) { + long long temp; + cin >> temp; + for (long long j = 2; j <= 100000; j++) { + long long cur = 0; + if (temp <= 1) break; + while (temp % j == 0 && temp > 1) { + cur++; + temp /= j; + } + if (cur != 0) me[j] += cur; + } + if (temp != 1) me[temp] += 1; + } + map::iterator it; + long long ans = 1; + for (it = me.begin(); it != me.end(); it++) { + long long temp = it->second; + ans *= nCr(temp + n - 1, temp); + ans %= 1000000007; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (min(a, b) % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +long long res, aux; +int n, m; +int main() { + cin >> n >> m; + aux = pow(2, n); + res = m % aux; + cout << res << endl; + return 0; +} +int a[12][12]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { a[1][i] = a[i][1] = 1; } + int ans = 1; + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { + a[i][j] = a[i - 1][j] + a[i][j - 1]; + ans = max(ans, a[i][j]); + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c, chest(0), biceps(0), baack(0); + cin >> n; + for (int i = 0; i < n / 3; ++i) { + cin >> a >> b >> c; + chest += a; + biceps += b; + baack += c; + } + if (n % 3 == 1) { + cin >> a; + chest += a; + } else if (n % 3 == 2) { + cin >> a >> b; + chest += a; + biceps += b; + } + if (chest > biceps && chest > baack) { + cout << "chest" << endl; + } else if (biceps > baack && biceps > chest) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +const long long int maxn = 2e5 + 3; +int main() { + long long int l, r, x, y, k, t = 0; + cin >> l >> r >> x >> y >> k; + for (long long int i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + t = 1; + break; + } + } + if (t) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +static const int MOD = 1e9 + 7; +static const int N = 1 << 17; +long long gcd(long long x, long long y) { + return y == 0 ? x : gcd(y, x % y); +} +int solve() { + int n; + string s; + cin >> n; + cin >> s; + int i = 0; + while (i < n && s[i] == '1') ++i; + cout << min(n, i + 1) << endl; + return 0; +} +int main() { + ::cout.precision(20); + solve(); + return 0; +} +int main() { + int k, sum = 0; + cin >> k; + int a[12]; + for (int i = 0; i < 12; i++) { cin >> a[i]; } + sort(a, a + 12); + if (k == 0) { + cout << "0" << endl; + } else { + int i; + for (i = 11; i >= 0; i--) { + sum += a[i]; + if (sum >= k) { break; } + } + if (sum < k) { + cout << "-1" << endl; + } else + cout << 12 - i << endl; + } +} +long long n, ans; +int main() { + cin >> n; + for (int i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { ans = i; } + } + cout << ans << " " << n / ans << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + if (n % m == 0) + cout << 0 << endl; + else { + long long tmp = n / m; + cout << min((n - tmp * m) * b, ((tmp + 1) * m - n) * a) << endl; + } + return 0; +} +int charArray[26]; +int main() { + string S; + cin >> S; + int j = 0, count = 0; + for (int i = 0; i < S.length(); i++) { + if (charArray[(S[i]) - 'a'] == 0) { + charArray[(S[i]) - 'a'] = 1; + count++; + } + } + if (count % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +int a, b, c, cnt = 0; +int main() { + cin >> b >> a >> c; + int n; + cin >> n; + int t; + while (n--) { + cin >> t; + if (t > a && t < c) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + string cadena; + char extreme = 'a'; + int veces = 0; + getline(cin, cadena); + for (string::iterator iter = cadena.begin(); iter != cadena.end(); iter++) { + if (*iter >= extreme) extreme = *iter; + } + for (string::iterator iter = cadena.begin(); iter != cadena.end(); iter++) { + if (*iter == extreme) veces++; + } + for (int i = 0; i < veces; i++) { cout << extreme; } + cout << endl; + return 0; +} +int main() { + string s; + int n, m, k; + cin >> n >> m >> k; + cin >> s; + s = '#' + s; + cout << 1 - (s[m] == s[k]) << endl; +} +int n, i, s1, s2, s, t, a[105]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + cin >> s >> t; + if (s > t) swap(s, t); + for (i = s; i < t; i++) s1 += a[i]; + for (i = 1; i < s; i++) s2 += a[i]; + for (i = n; i >= t; i--) s2 += a[i]; + cout << min(s1, s2) << endl; + return 0; +} +int main() { + int i, j, a[5][5], m; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { cin >> a[i][j]; } + } + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + if (a[i][j] == 1) { + m = (abs(2 - i) + abs(2 - j)); + break; + } + } + } + cout << m << endl; + return 0; +} +int main() { + int m, n, ans; + cin >> m >> n; + ans = -1; + int arr[m][n]; + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; ++j) { + cin >> arr[i][j]; + if (i == m - 1 || j == n - 1 || i == 0 || j == 0) { + if (arr[i][j] == 1) { ans = 0; } + } + } + } + if (ans == 0) { + cout << 2 << '\n'; + } else { + cout << 4 << '\n'; + } +} +int main() { + int n, m, z, flag = 0, tempn = 0, tempm = 0; + cin >> n; + cin >> m; + cin >> z; + for (int i = 1; tempn < z; i++) { + tempn = n * i; + for (int j = 1; tempm < z; j++) { + tempm = m * j; + if (tempm > z) break; + if (tempn == tempm) { + flag++; + break; + } else if (tempm < tempn) + continue; + else if (tempm > tempn) + break; + } + tempm = 0; + if (tempn > z) break; + } + cout << flag << endl; + return 0; +} +int main() { + int n, x, i, count = 0, loc; + vector v; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + int temp = v[0]; + sort(v.rbegin(), v.rend()); + while (temp != v[0]) { + for (i = 0; i < n; i++) { + if (v[i] == temp) break; + } + v[0]--; + v[i]++; + temp = v[i]; + count++; + sort(v.rbegin(), v.rend()); + } + if (v[0] == v[1]) + cout << count + 1 << endl; + else + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + int *a = new int[n + 1]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + bool found = false; + for (int i = 1; i <= n; i++) { + int A = a[i]; + int B = a[a[i]]; + int C = a[a[a[i]]]; + if (C == i) { + found = true; + break; + } + } + if (found == true) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int Mininum(long long a, long long b) { + if (b >= a) swap(a, b); + long long c; + for (c = b; c % a != 0; c += b) + ; + return c; +} +int main() { + string a, b; + long long n; + cin >> n >> a >> b; + int l1 = a.length(), l2 = b.length(); + long long both = Mininum(l1, l2); + short prog[both] = {0}; + for (int i = 0; i < both; i++) { + if (a[i % l1] == 'P') { + if (b[i % l2] == 'P') { + prog[i] = 0; + } else if (b[i % l2] == 'R') { + prog[i] = 1; + } else { + prog[i] = 2; + } + } else if (a[i % l1] == 'R') { + if (b[i % l2] == 'P') { + prog[i] = 2; + } else if (b[i % l2] == 'R') { + prog[i] = 0; + } else { + prog[i] = 1; + } + } else { + if (b[i % l2] == 'P') { + prog[i] = 1; + } else if (b[i % l2] == 'R') { + prog[i] = 2; + } else { + prog[i] = 0; + } + } + } + int loss1 = 0, loss2 = 0, rl1, rl2; + for (int i = 0; i < both; i++) { + if (prog[i] != 0) { + if (prog[i] == 1) { + loss2++; + } else { + loss1++; + } + } + } + rl1 = n / both * loss1; + rl2 = n / both * loss2; + for (int i = 0; i < n % both; i++) { + if (prog[i] == 1) rl2++; + if (prog[i] == 2) rl1++; + } + cout << rl1 << ' ' << rl2 << endl; + return 0; +} +bool flag1, flag2, flag3; +int main() { + string x; + cin >> x; + for (int i = 0; i < x.size(); i++) { + if (x[i] >= 'a' && x[i] <= 'z') flag1 = 1; + if (x[i] >= 'A' && x[i] <= 'Z') flag2 = 1; + if (x[i] >= '0' && x[i] <= '9') flag3 = 1; + } + if (x.size() >= 5 && flag1 && flag2 && flag3) + puts("Correct"); + else + puts("Too weak"); + return 0; +} +string arr[10]; +int k = 0; +int main() { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if ((j != 0)) { + cin >> arr[i][j]; + if (arr[i][j] == arr[i][j - 1]) { k = -1; } + } else { + cin >> arr[i][j]; + } + } + } + if (k == -1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, ans = 0, tmp; + string s[1000]; + char c, c2; + cin >> n; + for (int i = 0; i < n; ++i) cin >> s[i]; + for (int i = 0; i < 26; ++i) { + c = 'a' + i; + for (int j = 0; j < 26; j++) { + c2 = 'a' + j; + tmp = 0; + for (int k = 0; k < n; k++) { + bool ch = 1; + for (int z = 0; z < (int)s[k].size(); z++) { + if (s[k][z] != c && s[k][z] != c2) { + ch = 0; + break; + } + } + if (ch) tmp += (int)s[k].size(); + } + ans = max(tmp, ans); + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, b, d; + cin >> n >> b >> d; + int temp, ans = 0; + long long cont = 0; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp <= b) { + cont += temp; + if (cont > d) { + ans++; + cont = 0; + } + } + } + cout << ans << '\n'; + return 0; +} +int MOD(int a, int b) { + if (a > b) + return a - b; + else + return b - a; +} +long long int max3(long long int a, long long int b, long long int c) { + return max(c, max(a, b)); +} +long long int power(long long int x, long long int y, long long int p) { + long long int res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int gcd(long long int a, long long int b) { + if (b == 1) + return 1; + else if (a % b == 0) + return b; + else + return gcd(b, a % b); +} +int main() { + int n, s; + cin >> n >> s; + s++; + int i, j, k; + vector v(n); + for (i = 0; i < n; i++) { + cin >> j >> k; + v[i] = 60 * j + k; + } + if (v[0] >= s) { + cout << "0 0\n"; + return 0; + } + for (i = 1; i < n; i++) { + if (v[i] - v[i - 1] >= 2 * s) { + int t = v[i - 1] + s; + int ans = t / 60; + int ans1 = t % 60; + cout << ans << " " << ans1 << '\n'; + return 0; + } + } + int t = v[n - 1] + s; + int ans = t / 60; + int ans1 = t % 60; + cout << ans << " " << ans1 << '\n'; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int ds = 0, ss = 0, k = 0; + if (a > b) { + ds = b; + k = a - b; + ss = k / 2; + } else if (a < b) { + ds = a; + k = b - a; + ss = k / 2; + } else { + ds = a; + ss = 0; + } + cout << ds << " " << ss << endl; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int pre = 0; + int i, val; + for (i = 0; i < n; i++) { + cin >> val; + pre += val; + } + int ans = 0; + if (pre > 0) { + ans = (pre / x); + if (pre % x > 0) ans++; + } + if (pre < 0) { + ans = (abs(pre) / abs(x)); + if (abs(pre) % abs(x) > 0) ans++; + } + cout << ans << endl; +} +int main() { + long long n, k; + while (cin >> n >> k) { + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + } + return 0; +} +void cycle(string s, int len); +int main() { + string s, a[51], b, l; + bool flag = false; + cin >> s; + int len, j = 0, count = 0; + len = s.size(); + for (int i = 0; i < len; i++) { + b = s[len - 1]; + s.erase((len - 1)); + l.insert(0, b); + l.insert(1, s); + a[i] = l; + for (j = 0; j < i; j++) { + if (l.compare(a[j]) == 0) { flag = true; } + } + if (flag == false) { count++; } + s = l; + l.clear(); + } + cout << count << endl; + return 0; +} +stack S; +int funcion(long long a, long long b) { + int r; + if (a == b) return 1; + if (a < b) { + r = funcion(2 * a, b); + if (r == 1) { + S.push(1); + return 1; + } + r = funcion((10 * a) + 1, b); + if (r == 1) { + S.push(2); + return 1; + } + } else + return 0; +} +int main() { + long long a, b; + int op, ans; + cin >> a >> b; + ans = funcion(a, b); + if (ans == 0) + cout << "NO" << '\n'; + else { + cout << "YES" << '\n'; + cout << S.size() + 1 << '\n'; + cout << a; + while (!S.empty()) { + op = S.top(); + S.pop(); + if (op == 1) { + a *= 2; + } else { + a *= 10; + a++; + } + cout << " " << a; + } + cout << '\n'; + } +} +const int pi = 3.14; +int main() { + int a, b, r; + cin >> a >> b >> r; + if (2 * r > min(a, b)) { + cout << "Second" << endl; + } else { + int cnt = 0; + int ans = max(a, b); + int res = min(a, b); + while (1) { + ans = max(ans, res); + res = min(ans, res); + cnt += res / (2 * r); + ans -= (res / (2 * r)) * 2 * r; + int minn = min(ans, res); + if (minn < 2 * r) break; + } + if (cnt >= 1) + cout << "First" << endl; + else + cout << "Second" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[100005]; + for (int i = 0; i < n - 1; i++) { + int c; + cin >> c; + a[c] = 1; + } + for (int i = 1; i <= n; i++) { + if (a[i] != 1) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, k, joy; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int f, t; + cin >> f >> t; + if (i == 0) { + if (t > k) { + joy = f - (t - k); + } else { + joy = f; + } + } + if (t <= k) { + if (f > joy) { joy = f; } + } else { + if (f - (t - k) > joy) { joy = f - (t - k); } + } + } + cout << joy << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + int temp = 0; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + temp -= a; + temp += b; + ans = max(temp, ans); + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int g = v[0]; + for (int i = 1; i < n; i++) g = __gcd(g, v[i]); + cout << g * n << endl; +} +int main() { + long long x; + cin >> x; + if (x > -1) { + cout << x << endl; + return 0; + } else { + if ((x - (x % 10)) / 10 > ((x % 10) + (x - (x % 100)) / 10)) + cout << (x - (x % 10)) / 10 << endl; + else + cout << ((x - (x % 100)) / 10) + (x % 10) << endl; + } + return 0; +} +int x[1000001]; +int main() { + int k, n, points = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> x[i]; } + for (int i = 0; i < n; i++) { + if (x[i] >= x[k - 1] && x[i] != 0) points++; + } + cout << points << endl; + return 0; +} +int main() { + int n; + string home, flights; + cin >> n; + cin >> home; + for (int i = 0; i < n; i++) cin >> flights; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +map mp; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + string a; + cin >> a; + mp[a]++; + } + int sum = 0; + for (int i = 0; i < n; i++) { + string b; + cin >> b; + if (mp[b]) mp[b]--, sum++; + } + cout << n - sum << endl; +} +int main() { + int a, b; + cin >> a >> b; + if ((abs(a - b) <= 1) && (a != 0 || b != 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long int test; + cin >> test; + while (test--) { + long long int a, b, k; + cin >> a >> b >> k; + long long int right = k % 2 == 0 ? (k / 2) : ((k / 2) + 1); + right *= a; + long long int left = k / 2; + left *= b; + cout << (right - left) << '\n'; + } + return 0; +} +int main() { + char a[100]; + char b[15][115]; + while (cin >> a) { + int h[15]; + int l = 0; + for (int i = 0; i < 10; i++) { cin >> b[i]; } + int pl = 0; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 10; j++) { + int x = 0; + int flag = 0; + pl = i * 10; + for (int k = pl; k < pl + 10; k++) { + if (b[j][x++] != a[k]) { + flag = 1; + break; + } + } + if (flag == 0) { h[l++] = j; } + } + } + for (int i = 0; i < l; i++) { cout << h[i]; } + cout << endl; + } + return 0; +} +int n, i, a[180]; +bool is_integer(float k) { + return floor(k) == k; +} +int main() { + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (is_integer(360.0 / (180.0 - a[i]))) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +const double PI = acos(-1); +const int INF = 1000 * 1000 * 1000 + 7; +const long long LINF = INF * (long long)INF; +const int MAX = 3 * 10000 + 47; +string A[MAX]; +int n; +bool good(int j) { + for (int i = (1); i < (n); i++) { + if (A[i][j] != A[i - 1][j]) return false; + } + return true; +} +int main() { + cin >> n; + for (int i = (0); i < (n); i++) cin >> A[i]; + for (int j = (0); j < ((int)A[0].size()); j++) { + if (!good(j)) { + cout << j << endl; + return 0; + } + } + return 0; +} +long long gcd(long long a, long long b) { + if (!b) return a; + return gcd(b, (a % b)); +} +int main() { + long long n, m, a = 1, b = 1; + cin >> n >> m; + if (n > m) swap(n, m); + for (long long i = 1; i <= n; i++) a *= i; + for (long long i = 1; i <= (n + 1); i++) b *= i; + cout << gcd(a, b) << "\n"; + return 0; +} +int main() { + int n, a, b, c, m, p; + cin >> n; + a = n / 2 + 1; + b = a; + c = a; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= n; j++) { + if (j >= b && j <= c) { + cout << "D"; + } else { + cout << "*"; + } + } + b--; + c++; + cout << endl; + } + m = 1; + p = n; + for (int i = 1; i < a; i++) { + for (int j = 1; j <= n; j++) { + if (j <= m || j >= p) { + cout << "*"; + } else { + cout << "D"; + } + } + m++; + p--; + cout << endl; + } + return 0; +} +char s[8][8]; +int main() { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { cin >> s[i][j]; } + } + int Awin = 7, Bwin = 7; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (s[j][i] == 'B') { break; } + if (s[j][i] == 'W' && Awin > j) { + Awin = j; + break; + } + } + } + for (int i = 0; i < 8; i++) { + for (int j = 7; j >= 0; j--) { + if (s[j][i] == 'W') { break; } + if (s[j][i] == 'B' && Bwin > (7 - j)) { + Bwin = 7 - j; + break; + } + } + } + if (Awin > Bwin) + cout << "B" << endl; + else + cout << "A" << endl; + return 0; +} +int main() { + int ans = 0; + int k; + string s; + cin >> s; + for (int i = 0; i < s.size(); ++i) + for (int j = 0; j < s.size(); ++j) { + if (i < j) { + for (k = 0;; k++) + if (i + k >= s.size() || j + k >= s.size() || s[i + k] != s[j + k]) break; + ans = max(ans, k); + } + } + cout << ans << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + if (360 % (180 - a) == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +int main() { + int i, j, n, p, q; + vector v1, v2; + set s; + cin >> n; + cin >> p; + for (i = 0; i < p; i++) { + cin >> j; + v1.push_back(j); + } + cin >> q; + for (i = 0; i < q; i++) { + cin >> j; + v2.push_back(j); + } + for (i = 0; i < p; i++) { s.insert(v1[i]); } + for (i = 0; i < q; i++) { s.insert(v2[i]); } + set::iterator itr; + i = 0; + for (itr = s.begin(); itr != s.end(); itr++) { + if (*itr <= n) { i++; } + } + if (i == n) { + cout << "I become the guy." << endl; + } else { + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int a = 0, b = 0; + for (int i = 0; i < (int)s.length(); ++i) { + if (s[i] != t[i]) { + if (s[i] == '4') { + ++a; + } else { + ++b; + } + } + } + cout << min(a, b) + abs(a - b) << endl; + return 0; +} +int a[7] = {0, 1, 2, 2, 1, 0}; +int b[7] = {1, 0, 0, 1, 2, 2}; +int c[7] = {2, 2, 1, 0, 0, 1}; +int main() { + int n, x; + cin >> n >> x; + int k = n % 6; + if (a[k] == x) + cout << 0 << endl; + else if (b[k] == x) + cout << 1 << endl; + else if (c[k] == x) + cout << 2 << endl; + return 0; +} +int ada[305]; +int main() { + int n, p; + cin >> n >> p; + for (int i = 0; i < p; i++) { + int x; + cin >> x; + x %= n; + if (ada[x]) { + cout << i + 1 << endl; + return 0; + } else + ada[x] = 1; + } + cout << -1 << endl; +} +int main() { + string s; + char m = 0; + while (cin >> s) { + int a[26] = {0}; + for (int i = 0; i < s.length(); ++i) { + m = max(m, s[i]); + a[s[i] - 'a']++; + } + while (a[m - 'a']--) { cout << m; } + cout << endl; + } + return 0; +} +const int MaxN = 1E5 + 10; +int a[MaxN]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + int ans = 0; + for (int i = 0; i < n - 1; ++i) { + int lg = log2(n - i - 1); + ans += a[i]; + a[i + (1 << lg)] += a[i]; + cout << ans << endl; + } +} +int main() { + long long int n, k; + cin >> n; + cin >> k; + long long int f[n], t[n]; + for (int i = 0; i < n; i++) { + cin >> f[i]; + cin >> t[i]; + } + long long int joy = INT_MIN; + int a; + for (int i = 0; i < n; i++) { + if (t[i] <= k) { + a = f[i]; + if (a >= joy) { joy = a; } + } else { + a = f[i] - (t[i] - k); + if (a >= joy) { joy = a; } + } + } + cout << joy << endl; + return 0; +} +const int inf = 2147483647; +int main() { + int n, a[1005], sum = 0, m, cmp; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]; + cin >> m; + int l, r, ans = inf; + for (int i = 0; i < m; i++) { + cin >> l >> r; + cmp = -1; + if (sum <= l) cmp = l; + if (sum > l && sum <= r) cmp = sum; + if (cmp != -1) ans = min(ans, cmp); + } + if (ans == inf) + cout << "-1" << endl; + else + cout << ans << endl; + return 0; +} +int main() { + int n, x1, y1, x2, y2, v, u; + int summ = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + v = 1 + x2 - x1; + u = 1 + y2 - y1; + summ += v * u; + } + cout << summ << endl; + return 0; +} +int main() { + int a[1000], sum1, sum = 0; + int i, j, k; + for (i = 0; i < 6; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + for (i = 0; i < 4; i++) { + for (j = i + 1; j < 5; j++) { + for (k = j + 1; k < 6; k++) { + sum1 = a[i] + a[j] + a[k]; + if (sum1 == sum - sum1) { + cout << "YES" << '\n'; + exit(0); + } + } + } + } + cout << "NO" << '\n'; + return 0; +} +int main() { + long long int n; + cin >> n; + cout << 25 << endl; + return 0; +} +void del(int &h, int &m, int x) { + m -= x; + if (m < 0) { + m += 60; + h--; + if (h < 0) { h += 24; } + } +} +bool check(int h, int m) { + while (h) { + if (h % 10 == 7) return true; + h /= 10; + } + while (m) { + if (m % 10 == 7) return true; + m /= 10; + } + return false; +} +int main() { + int x; + int h, m; + cin >> x; + cin >> h >> m; + int but = 0; + while (!check(h, m)) { + del(h, m, x); + but++; + } + cout << but << endl; + return 0; +} +int main() { + long long x, y, a; + cin >> x >> y >> a; + long long xx = x / a, yy = y / a; + if (x % a != 0) xx++; + if (y % a != 0) yy++; + cout << xx * yy << endl; +} +const int len = 1e5 + 5; +const double pi = acos(-1.0); +const long long mod = 998244353; +const ulong long seed = 131; +long long a[len]; +long long x, y, p, q; +int solve(long long mid) { + if ((x + (mid * q - y)) >= p * mid && x <= p * mid) return 1; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + cin >> x >> y >> p >> q; + if (x * q == y * p) + cout << 0 << endl; + else if (x != y && p == q || p == 0) + cout << -1 << endl; + else { + long long l = 0, r = 1e9, mid; + while (l < r) { + mid = (l + r) / 2; + if (solve(mid)) + r = mid; + else + l = mid + 1; + } + cout << r * q - y << endl; + } + } +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) cin >> arr[i]; + int a, b; + cin >> a >> b; + int x = max(a, b); + int y = min(a, b); + int d1 = 0; + for (int i = x - 1; i < n + (y - 1); i++) { d1 += arr[i % n]; } + int d2 = 0; + for (int i = x - 2; i >= y - 1; i--) { d2 += arr[i % n]; } + cout << min(d1, d2) << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long n, x, y, d; + cin >> n >> x >> y >> d; + long long val = abs(x - y); + long long rem = val % d; + if (rem == 0) { + cout << val / d << endl; + } else { + long long start = 1; + long long diff1 = y - start; + long long temp1 = x - 1; + long long count1 = temp1 / d; + if (temp1 % d) count1++; + long long end = n; + long long diff2 = end - y; + long long temp2 = end - x; + long long count2 = temp2 / d; + if (temp2 % d) count2++; + if (diff1 % d == 0 && diff2 % d == 0) { + count1 += diff1 / d; + count2 += diff2 / d; + cout << min(count2, count1) << endl; + } else if (diff1 % d == 0) { + count1 += diff1 / d; + cout << count1 << endl; + } else if (diff2 % d == 0) { + count2 += diff2 / d; + cout << count2 << endl; + } else + cout << "-1" << endl; + } + } +} +int main() { + string s; + for (int i = 0; i < 8; i++) { + cin >> s; + for (int i = 1; i < 8; i++) + if (s[i] == s[i - 1]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, k, c; + cin >> n >> k >> c; + int holidays[c]; + int tpresents = 0; + for (int i = 0; i < c; i++) { cin >> holidays[i]; } + if (c == 0) { + tpresents += n / k; + } else { + tpresents += holidays[0] / k; + if (holidays[0] % k != 0) { tpresents++; } + int i; + for (i = 1; i < c; i++) { + tpresents += (holidays[i] - holidays[i - 1]) / k; + if ((holidays[i] - holidays[i - 1]) % k != 0) { tpresents++; } + } + tpresents += (n - holidays[i - 1]) / k; + } + cout << tpresents << endl; + return 0; +} +int main() { + map M; + int N; + cin >> N; + while (N--) { + int temp; + cin >> temp; + if (temp == 1) { + long long temp1, temp2, temp0; + cin >> temp1 >> temp2 >> temp0; + while (temp1 != temp2) { + if (temp1 > temp2) { + M[temp1] += temp0; + temp1 /= 2; + } else { + M[temp2] += temp0; + temp2 /= 2; + } + } + } else if (temp == 2) { + long long temp1, temp2; + long long sum = 0; + cin >> temp1 >> temp2; + while (temp1 != temp2) { + if (temp1 > temp2) { + sum += M[temp1]; + temp1 /= 2; + } else { + sum += M[temp2]; + temp2 /= 2; + } + } + cout << sum << endl; + } + } + return 0; +} +int main() { + int n, x, sum = 0, v = 0; + while (cin >> n >> x) { + for (int i = 0; i < n; i++) { + int z[n]; + cin >> z[i]; + sum += z[i]; + } + if (sum > 0) { + while ((sum > 0)) { + if (((sum % x != sum) && (sum / x != sum)) || (sum == x)) { + sum -= x; + v++; + } else + x--; + } + } else if (sum < 0) { + sum *= -1; + while ((sum > 0)) { + if ((sum % x == 0 || sum % x > 0) && (sum / x != 0)) { + sum -= x; + v++; + } else + x--; + } + } + cout << v << endl; + v = 0; + } +} +string s; +int arr[26], c; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { arr[s[i] - 'a']++; } + for (int i = 0; i < 26; i++) { + if (arr[i]) c++; + } + if (c % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int sum = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += x; + } + int answer = 0; + for (int j = 1; j <= 5; j++) { + if ((sum + j) % (n + 1) != 1) { answer++; } + } + cout << answer << endl; + return 0; +} +const int mod = 1e9 + 7; +int k, n, a[1005], c[1005][1005]; +int main() { + for (int i = 0; i <= 1000; i++) { + for (int j = 0; j <= i; j++) { + if (j == 0) { + c[i][j] = 1; + } else { + c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; + c[i][j] %= mod; + } + } + } + cin >> n; + long long ans = 1; + int sum = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + sum += a[i]; + ans = ((ans % mod) * (c[sum - 1][a[i] - 1] % mod)) % mod; + } + cout << ans << endl; + return 0; +} +const int maxn = 1e6 + 6; +int n, a, b; +int arr[maxn]; +int len = 0; +string str; +int main() { + cin >> n >> a >> b; + cin >> str; + for (int i = 1; i <= n; i++) arr[i] = str[i - 1]; + if (arr[a] == arr[b]) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int N, N4 = 0, N7 = 0; + cin >> N; + for (int i = 0; i <= N / 4; i++) { + if ((N - i * 4) % 7 == 0) { + N4 = i; + N7 = (N - i * 4) / 7; + break; + } + } + if (N4 == 0 && N7 == 0) + cout << "-1" << endl; + else { + for (int i = 0; i < N4; i++) { cout << 4; } + for (int i = 0; i < N7; i++) { cout << 7; } + cout << endl; + } + return 0; +} +const long long int mod = 1e9 + 9; +const int maxn = 2e5 + 20; +long long int gcd_answ(long long int a, long long int b) { + long long int res = 0; + if (a < b) swap(a, b); + while (a % b) { + res += a / b; + a = a % b; + if (a < b) swap(a, b); + } + res += max(a, b) / min(a, b); + return res; +} +int main() { + int t; + long long int a, b; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> a >> b; + cout << gcd_answ(a, b) << endl; + } +} +int main() { + string s1, s2; + while (cin >> s1 >> s2) { + if (s1 == s2) + cout << s1 << endl; + else + cout << '1' << endl; + } + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a != b) + cout << 1 << endl; + else + cout << a << endl; + return 0; +} +long long i, b, a, t, k, l, ans; +int main() { + cin >> a; + cin >> b; + cin >> k; + for (i = 1; i <= k; i++) { + ans = ans + (a + b) * 2 - 4; + a = a - 4; + b = b - 4; + } + cout << ans << endl; + return 0; +} +string db[2501]; +int n, m, ans = 6250000, prf[2 * 2501][2 * 2501]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> db[i]; } + for (int i = 0; i < 2 * 2501; i++) { + for (int j = 0; j < 2 * 2501; j++) { + if (i < n && j < m && db[i][j] == '1') prf[i][j] = 1; + if (i) prf[i][j] += prf[i - 1][j]; + if (j) prf[i][j] += prf[i][j - 1]; + if (i && j) prf[i][j] -= prf[i - 1][j - 1]; + } + } + int maxk = min(n, m); + for (int k = 2; k <= maxk; k++) { + int tmp_ans = 0; + for (int i = 0; i < n; i += k) { + for (int j = 0; j < m; j += k) { + int solve = prf[i + k - 1][j + k - 1]; + if (i) solve -= prf[i - 1][j + k - 1]; + if (j) solve -= prf[i + k - 1][j - 1]; + if (i && j) solve += prf[i - 1][j - 1]; + tmp_ans += min(solve, k * k - solve); + } + } + ans = min(ans, tmp_ans); + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i < n + 1; i++) { + int mid = (1 + n) / 2; + int key = abs(mid - i); + for (int i = 0; i < key; i++) cout << "*"; + for (int i = 0; i < n - 2 * key; i++) cout << "D"; + for (int i = 0; i < key; i++) cout << "*"; + cout << "\n"; + } +} +int main() { + int n, x; + double demand = 0, supply = 0; + int upset = 0; + char spicifier; + cin >> n >> supply; + while (n--) { + cin >> spicifier >> x; + if (spicifier == '+') { + supply += x; + } else { + if (x > supply) + upset++; + else { + supply -= x; + } + } + } + cout.precision(13); + cout << supply << " " << upset << endl; + return 0; +} +int main() { + string s; + int n; + int T; + int j; + cin >> T; + for (int i = 0; i < T; ++i) { + cin >> n; + cin >> s; + for (j = 0; j < n / 2; ++j) { + if (s[j] == s[n - j - 1]) + continue; + else if (s[j] + 1 == s[n - j - 1] - 1) + continue; + else if (s[j] - 1 == s[n - j - 1] + 1) + continue; + else + break; + } + if (j == n / 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const int T = 1e3 + 10; +int v[T]; +int d[T]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = 0; i < m; i++) cin >> d[i]; + int top = 0; + int ans = 0; + for (int i = 0; i < n; i++) { + if (top == m) break; + if (v[i] <= d[top]) { + ans++; + top++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + bool multiple = false; + int min = 1000000001; + int temp; + int pos = 0; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp < min) { + multiple = false; + min = temp; + pos = i + 1; + } else if (temp == min) { + multiple = true; + } + } + if (multiple) + cout << "Still Rozdil\n"; + else + cout << pos << endl; +} +int main() { + int t, a; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + } + return 0; +} +int arr[5], n; +int dp[4004], mn; +int fun(int rem) { + if (rem == 0) return 0; + if (rem < mn) return -11111111; + if (dp[rem] != -1) return dp[rem]; + int ret = -11111111; + for (int i = 0; i < 3; i++) { ret = max(ret, 1 + fun(rem - arr[i])); } + return dp[rem] = ret; +} +int main() { + memset(dp, -1, sizeof dp); + cin >> n; + mn = 100000000; + for (int i = 0; i < 3; i++) { + cin >> arr[i]; + mn = min(arr[i], mn); + } + cout << fun(n) << endl; +} +const int inf = 0x3f3f3f3f; +const int mod1 = 1e9 + 7; +const long long mod = 1e16; +const int maxn = 1000; +int dx[5] = {0, 1, 0, -1, 0}, dy[5] = {1, 0, -1, 0, 0}; +int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; +int main() { + double n, x, y; + cin >> n >> x >> y; + double d = n / (x + y); + double e = d * x; + cout << e << endl; + return 0; +} +int main() { + int a, b, n, i, au, nx; + cin >> n; + cin >> a >> b; + vector c; + for (i = 0; i < n; i++) { + cin >> au; + c.push_back(au); + } + sort(c.begin(), c.end()); + nx = c[b] - c[b - 1]; + cout << nx << "\n"; + return 0; +} +int main() { + int l, o; + o = l = 0; + int n; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { o++; } + if (s[i] == '1') { l++; } + } + if (o > l) { + cout << o - l << endl; + } else { + cout << l - o << endl; + } +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int minGas = n * nl; + int minLimon = n; + int minSal = n * np; + int canGas = k * l; + int canLim = c * d; + int max = canGas / minGas; + if (canLim / minLimon < max) max = canLim / minLimon; + if (p / minSal < max) max = p / minSal; + cout << max << endl; + return 0; +} +int arr[100010]; +int main() { + int n, g = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + g = __gcd(g, arr[i]); + } + while (g % 2 == 0) g /= 2; + while (g % 3 == 0) g /= 3; + for (int i = 1; i <= n; i++) { + int two = 1, three = 1; + while (arr[i] % (2 * two) == 0) two *= 2; + while (arr[i] % (3 * three) == 0) three *= 3; + if (g * two * three != arr[i]) { + cout << "No\n"; + return 0; + } + } + cout << "Yes\n"; + return 0; +} +int main() { + unsigned long long int n; + cin >> n; + if (n % 2 == 0) { + cout << 2 << endl; + } else { + cout << 1 << endl; + } +} +const int maxn = 100005; +int s[maxn], dp[maxn]; +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> s[i]; + dp[1] = s[1]; + int len = 1; + for (int i = 2; i <= n; i++) { + if (s[i] >= dp[len]) + dp[++len] = s[i]; + else { + int index = upper_bound(dp + 1, dp + len + 1, s[i]) - dp; + dp[index] = s[i]; + } + } + cout << len << endl; + return 0; +} +int main() { + int n, m, isPrime; + cin >> n >> m; + for (int i = n + 1; i < 100; ++i) { + isPrime = 1; + for (int j = 2; j * j <= i; ++j) { + if (i % j == 0) { + isPrime = 0; + break; + } + } + if (isPrime == 1) { + if (i == m) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; + } + } +} +int main() { + int n; + cin >> n; + cout << 3 * n / 2 << endl; + return 0; +} +const int MOD = 1000000007; +const long long INF = 1e18; +long long t, m, n; +vector A; +long long solve() { + sort(A.begin(), A.end()); + int n = A.size(); + return A[n / 2]; +} +int main() { + cin >> n; + A.resize(n); + for (int i = 0; i < n; i++) cin >> A[i]; + cout << solve() << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + int mx = *max_element(v.begin(), v.end()) + m; + while (m--) { + sort(v.begin(), v.end()); + v[0]++; + } + sort(v.begin(), v.end()); + cout << v.back() << " " << mx << endl; +} +int main() { + int n, minx, h, m, ans; + int a[105]; + cin >> n >> minx; + for (int i = 1; i <= n; i++) { + cin >> h >> m; + a[i] = h * 60 + m; + } + if (a[1] >= minx + 1) { + cout << 0 << " " << 0 << endl; + return 0; + } + for (int i = 2; i <= n; i++) { + if (a[i] - a[i - 1] >= minx * 2 + 2) { + ans = a[i - 1] + minx + 1; + cout << ans / 60 << " " << ans % 60 << endl; + return 0; + } + } + ans = a[n] + minx + 1; + cout << ans / 60 << " " << ans % 60 << endl; + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + } + return 0; +} +int main() { + int n, m, rightMost = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + if (x <= rightMost && y > rightMost) rightMost = y; + } + if (rightMost >= m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + n--; + int k = a; + if (k > b) k = b; + if (k > c) { + k += (n - 1) * c; + } else + k += (n - 1) * k; + if (n == 0) k = 0; + cout << k << endl; + return 0; +} +int find_winner(vector votes) { + int best_candidate = 0, max_votes = 0; + for (size_t i = 0; i < votes.size(); i++) { + if (votes[i] > max_votes) { + best_candidate = i; + max_votes = votes[i]; + } + } + return best_candidate + 1; +} +int main() { + int n, m, ai; + cin >> n >> m; + vector cities(n); + while (m--) { + vector array; + for (size_t i = 0; i < n; i++) { + cin >> ai; + array.push_back(ai); + } + cities[find_winner(array) - 1]++; + } + cout << find_winner(cities) << endl; +} +int n, a, tot1, tot2, tot3, result; +int main() { + cin >> n; + int x[5002], y[5002], z[5002], d[5002], e[5002], f[5002]; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a == 1) { + tot1++; + x[i] = 1; + } + if (a == 2) { + tot2++; + y[i] = 1; + } + if (a == 3) { + tot3++; + z[i] = 1; + } + } + for (int j = 0; j < n; j++) { + if (tot1 > 0 && tot2 > 0 && tot3 > 0) { + tot1 -= 1; + tot2 -= 1; + tot3 -= 1; + result++; + } else { + break; + } + } + cout << result << endl; + for (int l = 0; l <= result; l++) { + for (int k = 1; k <= n; k++) { + if (x[k] == 1) { + d[l] = k; + l++; + } + } + } + for (int o = 0; o <= result; o++) { + for (int p = 1; p <= n; p++) { + if (y[p] == 1) { + e[o] = p; + o++; + } + } + } + for (int q = 0; q <= result; q++) { + for (int r = 1; r <= n; r++) { + if (z[r] == 1) { + f[q] = r; + q++; + } + } + } + for (int m = 0; m < result; m++) { cout << d[m] << " " << e[m] << " " << f[m] << endl; } +} +int main() { + long long int n; + cin >> n; + while (n--) { + double angle; + cin >> angle; + double side; + int side1; + side = 2 * (180) / (180 - angle); + side1 = 2 * (180) / (180 - angle); + if (side1 == side && side > 2) + cout << "YES"; + else { + cout << "NO"; + } + cout << endl; + } +} +int main() { + int c; + cin >> c >> c; + int i, j; + i = j = -1; + string s; + while (j < 0) { + cin >> s; + j = s.find('B'); + i++; + } + c = count(s.begin(), s.end(), 'B') / 2 + 1; + cout << i + c << " " << j + c << '\n'; +} +int main() { + int n; + cin >> n; + int a = 1, b = 2, ok = 1; + while (n--) { + int x; + cin >> x; + if (x != a && x != b) { + ok = 0; + break; + } else { + b = 6 - a - b; + a = x; + } + } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long m, k; +long long d[300300], second[300300]; +int main() { + cin >> m >> k; + long long S = 0; + for (long long i = 1; i <= m; ++i) cin >> d[i], S += d[i]; + for (long long i = 1; i <= m; ++i) cin >> second[i]; + long long ANS = 0; + long long res = second[1]; + long long pos = 1; + long long n = m + 1; + while (pos <= n) { + long long w = -1; + for (long long j = pos + 1; j <= n - 1; ++j) { + if (second[j] > second[pos]) { + w = j; + break; + } + } + long long need = 0; + if (w == -1) { + need = res; + long long ds = 0, ss = 0; + for (long long j = pos; j <= n - 1; ++j) { + ds += d[j]; + if (j >= pos + 1) ss += second[j]; + need = max(need, ds - ss); + } + need = need - res; + long long CUR = 0; + CUR += (need / second[pos]) * k; + if (need % second[pos] != 0) CUR += k; + ANS += CUR; + break; + } + need = res; + long long ds = 0, ss = 0, q = 0; + for (long long j = pos; j <= w - 1; ++j) { + ds += d[j]; + q -= d[j]; + if (j >= pos + 1) q += second[j]; + if (j >= pos + 1) ss += second[j]; + need = max(need, ds - ss); + } + need = need - res; + long long CUR = 0; + CUR += (need / second[pos]) * k; + if (need % second[pos] != 0) CUR += k; + ANS += CUR; + res += CUR * second[pos] / k; + res += q; + res += second[w]; + pos = w; + } + cout << ANS + S << "\n"; + return 0; +} +const int MAX = 2e5; +pair, long long> a[MAX + 9]; +long long n, k, a0, x, y, m, ans, cnt, t, tmp; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k >> a0 >> x >> y >> m, t = 0; + for (int j = 0; j < k; j++) { + if (cnt <= MAX) a[cnt++] = {{t, a0}, i}; + tmp = (a0 * x + y) % m; + if (tmp < a0 && j != k - 1) t++; + a0 = tmp; + } + ans = max(ans, t); + } + cout << ans << '\n'; + if (cnt <= MAX) { + sort(a, a + cnt); + for (int i = 0; i < cnt; i++) cout << a[i].first.second << " " << a[i].second + 1 << '\n'; + } +} +const long double eps = 1e-7; +const long long inf = 1e18 + 100; +const int mod = 1000000007; +const int MAXN = 1000010; +long long n, a, b, ans; +long long dp[MAXN][2]; +int main() { + dp[0][0] = dp[0][1] = 1; + for (int i = 1; i <= 1000000; i++) { + dp[i][0] = dp[i - 1][0]; + dp[i][1] = dp[i - 1][1]; + dp[i][i % 2] = (dp[i][i % 2] + dp[i - 1][(i + 1) % 2]) % mod; + } + cin >> n; + cout << (dp[n][0] + dp[n][1] - 2) % mod << endl; + return 0; +} +int main() { + int n, a[105], i, s; + while (cin >> n) { + s = 0; + for (i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) + cout << s << endl; + else { + sort(a, a + n); + for (i = 0; i < n - 1; i++) { s += (a[n - 1] - a[i]); } + cout << s << endl; + } + } +} +int main() { + long long a, b, c, d; + vector v; + while (cin >> a >> b) { + v.clear(); + for (long long i = 1; i <= a; i++) { + cin >> c; + v.push_back(c); + } + long long h = 0; + for (long long i = 0; i < a; i++) { + if (v[i] <= b) + h++; + else + break; + } + if (h == v.size()) { + cout << h << endl; + continue; + } + for (long long i = a - 1; i >= 0; i--) { + if (v[i] <= b) { + h++; + } else + break; + } + cout << h << endl; + } +} +int main() { + int n; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.begin() + n, greater()); + int turn = 0; + while (v.size() != 1) { + if (turn % 2 == 0) { + v.erase(v.begin()); + } else { + v.pop_back(); + } + turn = (++turn) % 2; + } + cout << v.front() << endl; + return 0; +} +int ans[3][3]; +void change(int i, int j) { + if (i >= 0 && j >= 0 && i < 3 && j < 3) { + if (ans[i][j]) { + ans[i][j] = 0; + } else { + ans[i][j] = 1; + } + } +} +int main() { + int arr[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> arr[i][j]; + arr[i][j] = arr[i][j] % 2; + } + } + fill(&ans[0][0], &ans[0][0] + sizeof(ans), 1); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (arr[i][j]) { + change(i, j); + change(i + 1, j); + change(i, j + 1); + change(i - 1, j); + change(i, j - 1); + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << ans[i][j]; } + cout << endl; + } +} +int main() { + int a = 0, h, w, u1, u2, d1, d2; + cin >> w >> h; + cin >> u1 >> d1; + cin >> u2 >> d2; + while (1) { + w += h; + if (h == d2) w -= u2; + if (h == d1) w -= u1; + if (w < 0) w = 0; + h--; + if (h == 0) break; + } + cout << w << endl; +} +int a[10000], b[10000]; +int main() { + int m, n, i, j; + cin >> n >> m; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 0; i < m; i++) cin >> b[i]; + sort(b, b + m); + a[0] = 2 * a[0]; + if (a[0] <= a[n - 1]) { + if (a[n - 1] < b[0]) + cout << a[n - 1] << endl; + else + cout << -1 << endl; + } else { + if (a[0] < b[0]) + cout << a[0] << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 1) cout << "#"; + if (i % 2 == 0 && i % 4 != 0 && j != m) cout << "."; + if (i % 2 == 0 && i % 4 != 0 && j == m) cout << "#"; + if (i % 4 == 0 && j != 1) cout << "."; + if (i % 4 == 0 && j == 1) cout << "#"; + } + cout << endl; + } + return 0; +} +int power(int a, int b, int modi) { + int res = 1; + while (b) { + if (b % 2) res = (res * a) % modi; + b /= 2; + a = (a * a) % modi; + } + return res; +} +int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; +int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; +int dx[] = {-1, 1, 0, 0}; +int dy[] = {0, 0, -1, 1}; +int k, sum = 0, ans = 0, cur = 0, x, y; +int n, m, r, c; +int a[1005]; +int main() { + int n, m; + cin >> n >> m; + string s, t, r; + for (int i = 0; i < m; i++) { + s += '#'; + if (i == m - 1) + t += '#'; + else + t += '.'; + if (i == 0) + r += '#'; + else + r += '.'; + } + int i = 1; + int c = 0; + while (n--) { + if (i & 1) { + cout << s << endl; + } else if (!(i & 1) && c & 1) { + cout << r << endl; + c++; + } else { + cout << t << endl; + c++; + } + i++; + } + return 0; +} +int main() { + int n, p, a = 0, b = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p; + a |= p; + } + for (int i = 0; i < n; i++) { + cin >> p; + b |= p; + } + cout << a + b << endl; + return 0; +} +int T; +long long int s, a, b, c, ans, p, x; +int main() { + int i, j; + cin >> T; + for (i = 1; i <= T; i++) { + cin >> s >> a >> b >> c; + ans = s / c; + x = ans / a; + p = x * b; + cout << p + ans << '\n'; + } + return 0; +} +int main() { + int w, h, k; + cin >> w >> h >> k; + int cnt = 0; + for (int i = 1; i <= k; i++) { + int size = (w - 4 * (i - 1)) * (h - 4 * (i - 1)); + if (size <= 0) + break; + else + cnt += (w - 4 * (i - 1)) * 2 + (h - 4 * (i - 1) - 2) * 2; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int arr[26] = {0}; + for (int i = 0; i < n; i++) { arr[s[i] - 97]++; } + sort(arr, arr + 26, greater()); + if (arr[0] > k) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int Unset(int a, int i) { + int mask; + mask = 1 << i; + a = a & ~mask; + return a; +} +int main() { + int row, collumn; + vector grid; + cin >> row >> collumn; + for (int A = 0; A < row; A++) { + string temp; + cin >> temp; + grid.push_back(temp); + } + pair p1, p2, p3, ans; + for (int A = 0; A < row; A++) { + int c1 = 0; + for (int B = 0; B < collumn; B++) { + if (grid[A][B] == '*') c1++; + } + if (c1 == 2) { + c1 = 0; + for (int B = 0; B < collumn; B++) { + if (grid[A][B] == '*') { + if (c1 == 1) { p2 = make_pair(A, B); } + if (c1 == 0) { p1 = make_pair(A, B); } + c1++; + } + } + } else if (c1 == 1) { + for (int B = 0; B < collumn; B++) { + if (grid[A][B] == '*') { p3 = make_pair(A, B); } + } + } + } + if (p1.second == p3.second) { + cout << p3.first + 1 << " " << p2.second + 1 << endl; + } else { + cout << p3.first + 1 << " " << p1.second + 1 << endl; + } + return 0; +} +int main() { + int n; + int mn1, mx1, mn2, mx2, mn3, mx3; + cin >> n; + cin >> mn1 >> mx1 >> mn2 >> mx2 >> mn3 >> mx3; + int x1 = mn1, x2 = mn2, x3 = mn3; + while (x1 + x2 + x3 < n) { + if (x1 < mx1) + x1++; + else if (x2 < mx2) + x2++; + else if (x3 < mx3) + x3++; + } + cout << x1 << " " << x2 << " " << x3 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int r[n]; + for (int i = 0; i < n; i++) { cin >> r[i]; } + sort(r, r + n); + int ans = 0; + for (int i = 0; i < n; i++) { + if (r[i] > b) { + if (r[i] >= c) { break; } + ans++; + } + } + return cout << ans << endl, 0; +} +int n, a[1002], ans1, ans2, i; +int main() { + cin >> n; + for (i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + n / 2 + 1); + for (i = 1; i <= n / 2; i++) ans1 += abs(a[i] - (i * 2 - 1)); + for (i = 1; i <= n / 2; i++) ans2 += abs(a[i] - i * 2); + cout << min(ans1, ans2) << endl; +} +int main() { + int t, n, i, x, pp, count, flag = 0, dis = 0, min = 0, sum; + vector v; + vector::iterator it; + cin >> n; + while (n--) { + cin >> x; + v.push_back(x); + } + t = *min_element(v.begin(), v.end()); + for (i = 0; i < v.size(); i++) { + if (v[i] == t) { + if (flag != 0) { + dis = i - pp; + if (min == 0 && dis != 0) + min = dis; + else if (min != 0 && min > dis) + min = dis; + } + flag++; + pp = i; + } + } + cout << min << endl; + return 0; +} +int main() { + int n; + int a[210]; + cin >> n; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + if (a[n] > a[n - 1]) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, k, t, c; + cin >> n; + priority_queue Q; + cin >> t; + for (int i = 1; i < n; i++) { + cin >> k; + Q.push(k); + } + c = t; + k = Q.top(); + Q.pop(); + while (t <= k) { + t++; + k--; + Q.push(k); + k = Q.top(); + Q.pop(); + } + cout << t - c << endl; + return 0; +} +int main() { + long long sumA = 0, sumB = 0, a; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + sumA = a | sumA; + } + for (int i = 0; i < n; i++) { + cin >> a; + sumB = a | sumB; + } + cout << sumA + sumB << endl; + return 0; +} +int main() { + int res = 0; + char c1 = 'a', c2; + short c; + while (cin >> c2) { + c = c2 - c1; + c = abs(c); + res += min(c, (short)(26 - c)); + c1 = c2; + } + cout << res << '\n'; + return 0; +} +int N[1005]; +bool compare(int a, int b) { + return a > b; +} +int main() { + int n, l; + cin >> n >> l; + for (int i = 1; i <= n; i++) { cin >> N[i]; } + sort(N + 1, N + n + 1, compare); + int i = 1; + while (1) { + if (l % N[i++] == 0) { + cout << l / N[i - 1] << endl; + break; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int sum = (n * (n + 1)) / 2; + int kle = m % sum; + for (int i = 1; i <= n; i++) { + if (kle < i) break; + kle -= i; + } + cout << kle << endl; + return 0; +} +int main() { + int t, m; + cin >> t >> m; + int x[t]; + for (int i = 0; i < t; ++i) { cin >> x[i]; } + int c = 0, cl = 0, o; + for (int k = 0; k < m && cl < t; ++k) { + cin >> o; + for (; cl < t; ++cl) { + if (o >= x[cl]) { + c++; + ++cl; + break; + } + } + } + cout << c << endl; + return 0; +} +int main() { + int n, d, m, sum, a[101], maxx; + while (cin >> n >> d) { + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) { + cin >> m; + a[m]++; + } + sum = 0; + int i; + for (i = 0; i <= d; i++) { sum += a[i]; } + maxx = sum; + for (; i < 100; i++) { + sum = sum - a[i - d - 1] + a[i]; + maxx = max(maxx, sum); + } + cout << n - maxx << endl; + } + return 0; +} +map mp; +int main() { + int q; + cin >> q; + while (q--) { + int op; + cin >> op; + if (op == 1) { + long long u, v, w; + cin >> v >> u >> w; + while (u != v) { + if (u > v) { + mp[u] += w; + u /= 2; + } else { + mp[v] += w; + v /= 2; + } + } + } else { + long long v, u; + cin >> v >> u; + long long ans = 0; + while (u != v) { + if (u > v) { + ans += mp[u]; + u /= 2; + } else { + ans += mp[v]; + v /= 2; + } + } + cout << ans << endl; + } + } + return 0; +} +int main() { + long long n; + cin >> n; + long long mx = 0; + vector vec; + while (n--) { + string s; + cin >> s; + map mp; + for (long long i = 0; i < s.length(); i++) { mp[s[i]]++; } + string s1; + for (map::iterator it = mp.begin(); it != mp.end(); it++) { s1 += it->first; } + vec.push_back(s1); + } + map mp1; + for (long long i = 0; i < vec.size(); i++) { mp1[vec[i]]++; } + cout << mp1.size() << endl; +} +long long l, r, sifr, x; +long long maxr = 1; +long long f(long long x) { + long long new_ = 0; + long long pt = 1; + while (x) { + new_ = (9 - (x % 10)) * pt + new_; + pt *= 10; + x /= 10; + } + return new_; +} +int main() { + cin >> l >> r; + x = r; + while (x) { + sifr++; + x /= 10; + } + for (x = 1; x <= sifr; x++) maxr = maxr * 10; + maxr /= 2; + if (r >= maxr) + if (maxr >= l) + cout << (long long)maxr * (maxr - 1) << endl; + else { + x = f(l); + cout << (long long)l * x << endl; + } + else { + x = f(r); + cout << (long long)r * x << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long val = 2; + for (long long i = 1; i <= n; i++) { + long long num = ((i + 1) * (i + 1)) * i - val / i; + cout << num << endl; + val = (i + 1) * i; + } + return 0; +} +int main() { + int Arr[100000][2]; + int n, k, ans = -100000000; + cin >> n >> k; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> Arr[i][j]; } + } + if (n == 1) { + ans = (Arr[0][0] - (Arr[0][1] - k)); + } else { + for (int i = 0; i < n; i++) { + if (Arr[i][1] > k) { + ans = max(ans, (Arr[i][0] - (Arr[i][1] - k))); + } else { + ans = max(ans, Arr[i][0]); + } + } + } + cout << ans << endl; +} +const int INF = 1 << 30; +const int MAXN = 1005; +multiset myset; +int a[MAXN]; +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) myset.insert(a[i + 1] - a[i]); + int res = INF; + for (int i = 2; i < n; i++) { + myset.erase(a[i] - a[i - 1]); + myset.erase(a[i + 1] - a[i]); + myset.insert(a[i + 1] - a[i - 1]); + res = min(res, *myset.rbegin()); + myset.erase(a[i + 1] - a[i - 1]); + myset.insert(a[i] - a[i - 1]); + myset.insert(a[i + 1] - a[i]); + } + cout << res << endl; + return 0; +} +const int MAX = 1e6 + 7; +int wynik[MAX]; +int main() { + string s; + cin >> s; + int n = s.size(); + int lewa = 0; + int prawa = n - 1; + for (int i = 0; i < n; ++i) { + if (s[i] == 'l') { + wynik[prawa--] = i; + } else { + wynik[lewa++] = i; + } + } + for (int i = 0; i < n; ++i) { cout << wynik[i] + 1 << "\n"; } + return 0; +} +int a[30], ans, cnt; +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + char tmp; + cin >> tmp; + a[tmp - 'a' + 1]++; + } + for (int i = 1; i <= 26; i++) { + if (a[i]) { + ans += i; + i++; + cnt++; + if (cnt == k) break; + } + } + if (cnt == k) + cout << ans << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int a, b, i, ans = 1, x; + cin >> a >> b; + x = min(a, b); + for (i = 1; i <= x; i++) { ans = ans * i; } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + for (int i = 0; i < m; i++) { + int l, r; + string c1, c2; + cin >> l >> r; + cin >> c1 >> c2; + l--; + r--; + while (l <= r) { + if (s[l] == c1[0]) { s[l] = c2[0]; } + l++; + } + } + cout << s << endl; +} +int main() { + long long int line1, line2, first, second, i, j; + cin >> line1 >> line2; + cin >> first >> second; + long long int stud1[line1], stud2[line2]; + for (i = 0; i < line1; i++) { cin >> stud1[i]; } + for (i = 0; i < line2; i++) { cin >> stud2[i]; } + sort(stud1, stud1 + line1); + sort(stud2, stud2 + line2); + int mx = stud2[line2 - (second)]; + int tot = 0, y = 0; + for (i = 0; i < line1; i++) { + if (stud1[i] < mx) { ++tot; } + if (tot == first) { + ++y; + break; + } + if (stud1[i] > mx) { break; } + } + if (y) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const long long N = 1e6 + 100; +string s; +int main() { + long long n; + cin >> s; + s += "R"; + n = s.size(); + long long ans = 0, cnt = 1; + for (long long i = 1; i < n; i++) { + if (s[i] != s[i - 1]) { + if (cnt % 2 == 0) ans++; + cnt = 0; + } + cnt++; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, t, k, d, sum1 = 0, sum2 = 0, c, v; + cin >> n >> t >> k >> d; + c = n; + while (c > 0) { + sum1 += t; + c -= k; + } + c = n; + sum2 = d; + v = d / t; + c = c - v * k; + while (c > 0) { + sum2 += t; + c -= (2 * k); + } + if (sum2 < sum1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int ans = 0, cul = 0; +int n; +char o; +string say, ope; +bool res = 0; +bool alph[30] = {0}; +void tan(string a) { + for (int k = 0; k < 26; k++) { + int flag = 0; + if (alph[k] == 0) + for (int j = 0; j < a.length(); j++) + if (k == a[j] - 'a') flag = 1; + if (flag == 0) alph[k] = 1; + } +} +void dian(string a) { + for (int i = 0; i < a.size(); i++) { + int tmp = a[i] - 'a'; + alph[tmp] = 1; + } +} +void wen(string a) { + alph[a[0] - 'a'] = 1; +} +int main() { + cin >> n; + while (n--) { + cin >> ope >> say; + if (res == true) { + if (ope != "." && n != 0) ans++; + } else if (ope == "!") { + tan(say); + } else if (ope == ".") + dian(say); + else if (ope == "?") + wen(say); + for (int i = 0; i < 26; i++) + if (alph[i] == 0) cul++; + if (cul == 1) res = true; + cul = 0; + } + cout << ans << endl; + return 0; +} +int main() { + int n, b, p, m; + cin >> n >> b >> p; + p = p * n; + for (m = 0; n >= 2; m = m + n / 2, n = n / 2 + n % 2) + ; + cout << (b * 2 + 1) * m << " " << p << endl; + return 0; +} +int n, x[101]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> x[i]; } + sort(x, x + n); + int pre = -1; + while (pre != x[0]) { + pre = x[0]; + for (int i = 1; i < n; i++) { + x[i] %= pre; + if (x[i] == 0) x[i] = pre; + } + sort(x, x + n); + } + int s = 0; + for (int i = 0; i < n; i++) { s += x[i]; } + cout << s << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long r1 = (long long)(n / (2 * (k + 1))); + long long r2 = r1 * k; + long long r3 = n - (k + 1) * r1; + cout << r1 << " "; + cout << r2 << " "; + cout << r3 << endl; + return 0; +} +const int maxn = 1005; +int a[maxn], b[maxn], fa[maxn], fb[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (i == 1) + fa[i] = a[i]; + else + fa[i] = fa[i - 1] | a[i]; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + if (i == 1) + fb[i] = b[i]; + else + fb[i] = fb[i - 1] | b[i]; + } + long long res = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + long long t = fb[i] + fa[i] - fa[j - 1] - fb[j - 1]; + res = max(res, t); + } + } + cout << res << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int s, t; + s = t = 0; + while (n--) { + s++; + t++; + if (t % m == 0) { + n++; + t = 0; + } + } + cout << s << endl; +} +int main() { + long long A[26] = {0}; + string s; + cin >> s; + long long n = (int)s.length(); + long long c = 0; + for (long long i = 0; i < n / 2; i++) { + if (s[i] != s[n - 1 - i]) c++; + } + if (c == 1) + cout << "YES" + << "\n"; + else if (c == 0 && n % 2 == 1) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int ar[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> ar[i][j]; } + } + int c = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j) continue; + if (ar[i][0] == ar[j][1]) { c++; } + } + } + cout << c << endl; + return 0; +} +void solve() { + int f = 0; + int n = 8; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < n - 1; j++) { + if (s[j] == s[j + 1]) f = 1; + } + } + cout << ((f) ? "NO" : "YES") << "\n"; +} +int main() { + int t = 1; + while (t--) { solve(); } +} +long long rev(long long x) { + long long ans = 0; + while (x) { + ans = ans * 10 + (x % 10); + x /= 10; + } + return ans; +} +int main() { + long long a, b; + while (cin >> a >> b) { + b = rev(b); + cout << a + b << '\n'; + } + return 0; +} +const int MAXN = 1005; +int n, m, c[MAXN], a[MAXN]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> c[i]; } + for (int i = 0; i < m; i++) { cin >> a[i]; } + int ans = 0, j = 0; + for (int i = 0; i < m && j < n; i++, j++) { + while (j < n && a[i] < c[j]) { j++; } + if (j >= n) { break; } + ans = i + 1; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, t; + cin >> n >> t; + long long a[n], i; + for (i = 1; i < n; i++) cin >> a[i]; + i = 1; + bool llega = false; + while (i < t) { + i = i + a[i]; + if (i == t) llega = true; + } + if (llega) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, cnt; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "Tetrahedron") cnt += 4; + if (s == "Cube") cnt += 6; + if (s == "Octahedron") cnt += 8; + if (s == "Dodecahedron") cnt += 12; + if (s == "Icosahedron") cnt += 20; + } + cout << cnt << endl; + return 0; +} +inline int read() { + int x = 0; + char c = getchar(); + bool flag = 0; + while (c < '0' || c > '9') { + if (c == '-') flag = 1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = (x << 3) + (x << 1) + c - '0'; + c = getchar(); + } + return flag ? -x : x; +} +int main() { + int n = read(), m = read(); + int ans = 0; + if (n % 2 == 0) + ans = n / 2; + else + ans = n / 2 + 1; + if (ans % m == 0) { + cout << ans << endl; + return 0; + } + while (ans < n) { + ans++; + if (ans % m == 0) { + cout << ans << endl; + return 0; + } + } + if (ans == n && ans % m != 0) { + cout << -1 << endl; + return 0; + } +} +int main() { + int n; + cin >> n; + int a[2 * n]; + for (int i = 0; i < 2 * n; i++) cin >> a[i]; + sort(a, a + 2 * n); + if (a[n] == a[n - 1]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + string s, t; + cin >> s >> t; + if (s == t) + cout << s << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int upper = 0, lower = 0; + string name; + cin >> name; + for (int i = 0; i < name.length(); i++) { + if (isupper(name[i])) { + upper += 1; + } else { + lower += 1; + } + } + if (upper > lower) { + for (int i = 0; i < name.length(); i++) { name[i] = toupper(name[i]); } + } else { + for (int i = 0; i < name.length(); i++) { name[i] = tolower(name[i]); } + } + cout << name << endl; + return 0; +} +int digsum(int64_t &x) { + int sum = 0; + while (x != 0) { + sum += x % 10; + x /= 10; + } + return sum; +} +int main() { + int n{0}; + int h{0}; + int m{0}; + cin >> n >> h >> m; + int sum = (h * 60 + m); + int count = 0; + while (sum % 10 != 7 and (sum / 60) % 10 != 7) { + sum -= n; + count += 1; + if (sum < 0) { sum += 1440; } + } + cout << count << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + if (a + b >= n) { + cout << n - a << endl; + } else { + cout << b + 1 << endl; + } + return 0; +} +int main() { + int start = 0, index, walk = 0, move = 0; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + index = s[i] - 97; + walk = abs(start - index); + if (walk > 13) + move += 26 - walk; + else + move += walk; + start = index; + } + cout << move << endl; +} +long long ppow(long long a, long long k) { + if (k == 0) return 1 % 1000000009LL; + if (k % 2 == 0) return ppow(a * a % 1000000009LL, k >> 1); + if (k % 2 == 1) return ppow(a * a % 1000000009LL, k >> 1) * a % 1000000009LL; +} +long long n, m; +int main() { + cin >> n >> m; + long long tmp = ppow(2, m) - 1, ans = 1; + for (long long i = 0; i < n; ++i) { + ans = ans * tmp % 1000000009LL; + tmp = (tmp + 1000000009LL - 1) % 1000000009LL; + } + cout << ans << "\n"; + return 0; +} +int main() { + long long a, b, k, t; + cin >> t; + while (t--) { + cin >> a >> b >> k; + if (k % 2 == 0) + cout << (a - b) * k / 2 << endl; + else + cout << ((a - b) * (k / 2)) + a << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + map mp; + for (int i = 0; i < 10; i++) { + string p; + cin >> p; + mp[p] = i; + } + for (int i = 0; i < 80; i += 10) { cout << mp[s.substr(i, 10)]; } + cout << '\n'; +} +int main() { + int n; + cin >> n; + char a[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int r = 0; + if (a[i - 1][j] == 'o' && (i - 1) >= 0) r++; + if (a[i + 1][j] == 'o' && (i + 1) < n) r++; + if (a[i][j - 1] == 'o' && (j - 1) >= 0) r++; + if (a[i][j + 1] == 'o' && (j + 1) < n) r++; + if (r % 2 == 0) { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, m, min, max; + cin >> n >> m >> min >> max; + int minTemp = 0; + int maxTemp = 0; + for (int i = 0; i < m; i++) { + int input; + cin >> input; + if (input < min || input > max) { + cout << "Incorrect" << endl; + exit(0); + } + if (input == min) minTemp = 1; + if (input == max) maxTemp = 1; + } + if (n - m >= 2) { + cout << "Correct" << endl; + exit(0); + } + if (minTemp && maxTemp) { + cout << "Correct" << endl; + exit(0); + } + if ((minTemp || maxTemp) && n - m == 1) { + cout << "Correct" << endl; + exit(0); + } + cout << "Incorrect" << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n; + cin >> n; + int a[200] = {0}; + for (int i = 0; i < n; i++) { + int mid; + cin >> mid; + a[mid]++; + } + sort(a, a + 105, cmp); + cout << a[0] << endl; + return 0; +} +int m, d; +int total[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + cin >> m >> d; + int ans = 1; + total[m] -= (8 - d); + ans += (total[m] + 6) / 7; + cout << ans << "\n"; + return 0; +} +const int INF = 0x3f3f3f3f; +const int maxn = 120; +char str[maxn][maxn]; +int digit(int x) { + int res = 0; + while (x) { + if (x % 10 == 4 || x % 10 == 7) res++; + x /= 10; + } + return res; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + int t; + while (n--) { + cin >> t; + if (digit(t) <= k) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + string str; + cin >> str; + int size = str.size(); + stack s; + s.push(str[0]); + for (int i = 1; i < size; i++) (!s.empty() && str[i] == s.top()) ? s.pop() : s.push(str[i]); + string ans = ""; + while (!s.empty()) { + ans += s.top(); + s.pop(); + } + reverse(ans.begin(), ans.end()); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + if (x == 1) { + if (n % 3 == 0) + cout << 1 << endl; + else if (n % 3 == 1) + cout << 0 << endl; + else + cout << 2 << endl; + } else if (x == 2) { + if (n % 6 == 0 || n % 6 == 1) + cout << 2 << endl; + else if (n % 6 == 2 || n % 6 == 3) + cout << 0 << endl; + else + cout << 1 << endl; + } else if (x == 0) { + if (n % 6 == 0 || n % 6 == 5) + cout << 0 << endl; + else if (n % 6 == 1 || n % 6 == 2) + cout << 1 << endl; + else + cout << 2 << endl; + } + return 0; +} +int main() { + long n, p, t, sum = 0; + cin >> n; + p = n / 100; + t = n % 100; + sum += p; + p = t / 20; + t = t % 20; + sum += p; + p = t / 10; + t = t % 10; + sum += p; + p = t / 5; + t = t % 5; + sum += p + t; + cout << sum << endl; + return 0; +} +int main() { + int l, r, x, ans = 0; + string str; + cin >> str; + for (int i = 0; str[i] != '\0'; i++) { + l = r = x = 0; + for (int j = i; str[j] != '\0'; j++) { + if (str[j] == '(') l++; + if (str[j] == ')') r++; + if (str[j] == '?') { + if (l == r) + l++; + else + x++; + } + if (l + x < r) break; + if (l < r + x) { + x--; + l++; + } + if (l == r + x) ans++; + } + } + cout << ans << "\n"; + return 0; +} +const int maxn = 5005; +const int inf = 0x3f3f3f3f; +int main() { + int a, b; + cin >> a >> b; + string s[50]; + for (int i = 1; i <= a; i++) { cin >> s[i]; } + long long ans = b / 2, num = 1; + for (int i = a - 1; i >= 1; i--) { + if (s[i] == "halfplus") { + ans += (num + 0.5) * b; + num = num * 2 + 1; + } else { + ans += num * b; + num *= 2; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, k, h; + while (cin >> n >> k) { + if (n == 0 || k == 0) break; + h = k / n; + if (k % n == 0) + cout << h << endl; + else + cout << h + 1 << endl; + } + return 0; +} +const double PI = acos(-1.0); +const double eps = 1e-6; +const int INF = 0x3f3f3f3f; +const int maxn = 100; +int T, n, m; +int main() { + while (cin >> n) { cout << n / 2 + 1 << endl; } + return 0; +} +const int maxn = 2 * 1e5 + 10; +stack s; +char str[maxn]; +int main() { + while (!s.empty()) s.pop(); + int len; + gets(str + 1); + len = strlen(str + 1); + for (int i = len; i >= 1; i--) { + if (!s.size()) { + s.push(str[i]); + } else { + if (s.top() == str[i]) { + s.pop(); + } else { + s.push(str[i]); + } + } + } + while (!s.empty()) { + cout << s.top(); + s.pop(); + } + cout << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + n = n % 6; + if (n == 0) n = 6; + int i, j; + int a[3] = {0, 0, 0}; + for (i = 0; i < 3; i++) { + a[i] = -10; + for (j = 1; j <= n; j++) { + if (j % 2 == 1) swap(a[0], a[1]); + if (j % 2 == 0) swap(a[1], a[2]); + } + if (a[k] == -10) { + cout << i << endl; + return 0; + } + for (j = 0; j < 3; j++) a[j] = 0; + } + return 0; +} +int C[1010][1010], k, s[1010], dp[1010], c[1010]; +int main() { + C[0][0] = 1; + for (int i = 1; i <= 1000; i++) { + C[i][0] = 1; + for (int j = 1; j <= i; j++) { C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; } + } + cin >> k; + for (int i = 1; i <= k; i++) { + cin >> c[i]; + s[i] = s[i - 1] + c[i]; + } + dp[0] = 1; + for (int i = 1; i <= k; i++) { dp[i] = 1LL * C[s[i] - 1][c[i] - 1] * dp[i - 1] % 1000000007; } + cout << dp[k] << endl; + return 0; +} +int main() { + int tt; + cin >> tt; + while (tt--) { + int x, y, p, q; + cin >> x >> y >> p >> q; + if (p == 0) { + cout << (x == 0 ? 0 : -1) << endl; + continue; + } + if (p == q) { + cout << (x == y ? 0 : -1) << endl; + continue; + } + int t1 = (x + p - 1) / p; + int t2 = ((y - x) + (q - p) - 1) / (q - p); + cout << (q * 1LL * max(t1, t2) - y) << endl; + } + return 0; +} +long long gcd(long long a, long long b) { + return b == 2 ? a : gcd(b, a % b); +}; +int main() { + int n; + cin >> n; + int sete = n / 7; + int left = n % 7; + int quatro = 0; + while (left > 0) { + if (left % 4 == 0) { + quatro += left / 4; + left = 0; + } else if (sete > 0) { + left += 7; + sete--; + } else { + cout << -1 << endl; + return 0; + } + } + for (int i = 0; i < quatro; i++) { cout << 4; } + for (int i = 0; i < sete; i++) { cout << 7; } + cout << endl; + return 0; +} +string a, b, ans = "zzzzzzzzzzzzzzzzzzzz"; +int main() { + cin >> a >> b; + int lena = a.size(), lenb = b.size(); + for (int i = 1; i <= lena; ++i) + for (int j = 1; j <= lenb; ++j) { + string tmp = a.substr(0, i) + b.substr(0, j); + if (tmp < ans) ans = tmp; + } + cout << ans << '\n'; +} +int main() { + int n; + int grid[20][20]; + while (cin >> n) { + for (int i = 0; i < n; i++) grid[0][i] = 1; + for (int i = 0; i < n; i++) grid[i][0] = 1; + int mx = 1; + for (int i = 1; i < n; i++) + for (int j = 1; j < n; j++) { + grid[i][j] = grid[i - 1][j] + grid[i][j - 1]; + mx = max(mx, grid[i][j]); + } + cout << mx << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int mn = INT_MAX; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + int val; + cin >> val; + int temp = INT_MAX; + if (val == 1) { + if (i == 0 || i == n - 1 || j == 0 || j == m - 1) + temp = 2; + else + temp = 4; + } + mn = min(temp, mn); + } + } + cout << mn << endl; +} +int main() { + int column, row; + cin >> column >> row; + string s1 = ""; + string s2 = "#"; + string s3 = ""; + for (int i = 0; i < row; i++) s1 += '#'; + for (int i = 1; i < row; i++) s2 += '.'; + for (int i = 0; i < row - 1; i++) s3 += '.'; + s3 += '#'; + for (int i = 1; i <= column; i++) { + if (i % 2 == 1) { + cout << s1; + cout << "\n"; + } else { + if (i % 4 == 0) { + cout << s2; + cout << "\n"; + } else { + cout << s3; + cout << "\n"; + } + } + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int cur = 0; + for (int i = 0;; ++i) { + if (cur + b * c >= a * c) { + cout << i << "\n"; + return 0; + } + cur += b; + } + return 0; +} +const int MAXN = 300030; +int N; +long long arr[MAXN]; +long long ans = 0; +int main() { + cin >> N; + for (int i = 0; i < N; i++) cin >> arr[i]; + sort(arr, arr + N); + for (int i = 0; i < N; i++) { ans += (i + 2) * arr[i]; } + ans -= arr[N - 1]; + cout << ans << endl; + return 0; +} +const int INF = 1e9 + 100; +const long long LINF = 1e18 + 100; +const int ITER = 300; +const double EPS = 1e-6; +const int MOD = 100000007; +const long long MAXN = 1; +void solve() { + long long n; + cin >> n; + string a, b; + cin >> a >> b; + long long m = a.length(); + long long k = b.length(); + long long cyc = (m * k) / __gcd(m, k); + string aa = "", bb = ""; + for (int i = 0; i < cyc / m; ++i) aa += a; + for (int i = 0; i < cyc / k; ++i) bb += b; + long long f = 0, s = 0; + for (int i = 0; i < cyc; ++i) { + if (aa[i] == 'R' && bb[i] == 'P') ++f; + if (aa[i] == 'R' && bb[i] == 'S') ++s; + if (aa[i] == 'P' && bb[i] == 'S') ++f; + if (aa[i] == 'P' && bb[i] == 'R') ++s; + if (aa[i] == 'S' && bb[i] == 'R') ++f; + if (aa[i] == 'S' && bb[i] == 'P') ++s; + } + f *= n / cyc; + s *= n / cyc; + n %= cyc; + for (int i = 0; i < n; ++i) { + if (aa[i] == 'R' && bb[i] == 'P') ++f; + if (aa[i] == 'R' && bb[i] == 'S') ++s; + if (aa[i] == 'P' && bb[i] == 'S') ++f; + if (aa[i] == 'P' && bb[i] == 'R') ++s; + if (aa[i] == 'S' && bb[i] == 'R') ++f; + if (aa[i] == 'S' && bb[i] == 'P') ++s; + } + cout << f << ' ' << s << endl; +} +int main() { + int t = 1; + for (int tn = 0; tn < t; ++tn) { solve(); } +} +bool ispalindrome(string s) { + string t = s; + reverse(s.begin(), s.end()); + return s == t; +} +int main() { + string s; + cin >> s; + if (s.size() % 2 && ispalindrome(s)) { + puts("YES"); + return 0; + } + if (s.size() % 2 == 0 && ispalindrome(s)) { + puts("NO"); + return 0; + } + int err = 0; + for (int i = 0; i < s.size() / 2; i++) + if (s[i] != s[s.size() - i - 1]) err++; + if (err == 1) { + puts("YES"); + return 0; + } + puts("NO"); + return 0; +} +int main() { + long long n, m, i, j, k, ans, mm; + cin >> n >> m; + mm = 1; + for (i = 1; i <= m; i++) mm = (mm * 2) % 1000000009; + ans = 1; + for (i = 1; i <= n; i++) ans = (ans * (mm + 1000000009 - i)) % 1000000009; + cout << ans << "\n"; + return 0; +} +int n; +; +int main() { + cin >> n; + for (int i = sqrt(n); i >= 1; i--) { + if (n % i == 0) { + cout << i << " " << n / i << endl; + return 0; + } + } +} +int main() { + int n, k = 0; + cin >> n; + vector vec(n); + cin >> vec[0]; + int record = vec[0], anti = vec[0]; + for (int i = 1; i < n; ++i) { + cin >> vec[i]; + if (vec[i] > record) { + k++; + record = vec[i]; + } else if (vec[i] < anti) { + anti = vec[i]; + k++; + } + } + cout << k << endl; + return 0; +} +int main() { + int k; + int r; + int j = 0; + int p = 0; + cin >> k >> r; + for (int i = 1; i < 10; i++) { + if (((i * k) % 10) == 0) { + j = i; + break; + } else if (((i * k) - r) % 10 == 0) { + j = i; + break; + } + } + cout << j << endl; + return 0; +} +int main() { + int n; + string str; + cin >> n >> str; + for (int i = 1; i <= n - 1; i++) { + if (str[i] != str[i - 1]) { + cout << "YES" << endl; + cout << str[i - 1] << str[i] << endl; + return 0; + } + } + cout << "NO" << endl; +} +long long int mod = 1000000007; +int ncr[1001][1001]; +int k, tot; +int ct[1001]; +long long int dp[1001]; +void init() { + for (int i = 1; i <= 1000; i++) { + ncr[i][0] = 1; + ncr[i][1] = i; + for (int j = 2; j <= i; j++) { ncr[i][j] = ((ncr[i - 1][j]) % mod + (ncr[i - 1][j - 1]) % mod) % mod; } + } +} +long long int calc(int x) { + if (dp[x] != -1) { return dp[x]; } + if (x == 1) { + dp[x] = 1; + return dp[x]; + } + int n = ct[x]; + int r = ct[x] - ct[x - 1]; + long long int ans = (ncr[n - 1][r - 1] * (calc(x - 1)) % mod); + dp[x] = (int)ans; + return dp[x]; +} +int main() { + init(); + cin >> k; + for (int i = 1; i <= k; i++) { + cin >> ct[i]; + tot += ct[i]; + } + for (int i = 2; i <= k; i++) { ct[i] += ct[i - 1]; } + memset(dp, -1, sizeof(dp)); + cout << calc(k) << endl; + return 0; +} +int main() { + int n, a[1001]; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + if (n % 2 == 0) + cout << a[n / 2] << endl; + else + cout << a[n / 2 + 1] << endl; +} +long long qpow(long long x) { + long long n = 2, res = 1; + while (x) { + if (x & 1) res *= n; + n *= n; + x >>= 1; + } + return res; +} +string name[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; +int main() { + long long n, a, x; + cin >> n; + if (n > 5) { + a = log2((n / 5) + 1); + x = (n + (1 - qpow(a)) * 5) / qpow(a); + cout << name[x] << endl; + } else + cout << name[n - 1] << endl; +} +int main() { + int a[11][11] = {0}; + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + a[1][i] = 1; + a[i][1] = 1; + } + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n][n] << endl; + return 0; +} +double dist_len(int x1, int y1, int x2, int y2) { + return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); +} +int n, k, a, b, x; +int main() { + cin >> n >> k; + while (n--) { + cin >> a >> b; + x += b - a + 1; + } + x %= k; + if (x != 0) x = k - x; + cout << x << endl; + return 0; +} +string a, b, c; +int cnt; +int main() { + cin >> a >> b; + cout << a << " " << b << endl; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> c; + if (c == a) + cnt = 1; + else if (c == b) + cnt = 2; + cin >> c; + if (cnt == 1) + a = c; + else + b = c; + cout << a << " " << b << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + int64_t sum = 0; + for (int i = 0; i < n; i++) { sum += (i + 2) * v[i]; } + sum -= v[n - 1]; + cout << sum << endl; + return 0; +} +int main() { + int a, b, c, d, v, m; + cin >> a >> b >> c >> d; + m = max((a - (a / 250) * c), ((3 * a) / 10)); + v = max((b - (b / 250) * d), ((3 * b) / 10)); + if (m > v) + cout << "Misha" << endl; + else if (v > m) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +int main() { + char s[16]; + int i, count = 0, n; + cin >> s; + n = strlen(s); + for (i = 0; i < n / 2; i++) { + if (s[i] != s[n - 1 - i]) count++; + } + if (n % 2) { + if (count <= 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + if (count == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const long long MOD = 1e9 + 7; +const long long INF = 1e9 + 7; +bool isVowel(char a) { + if (a == 'a') return true; + if (a == 'i') return true; + if (a == 'u') return true; + if (a == 'e') return true; + if (a == 'o') return true; + if (a == 'y') return true; + return false; +} +int main() { + string s; + getline(cin, s); + char ans; + for (int i = 0; i < s.size(); i++) { + s[i] = tolower(s[i]); + if (isalpha(s[i])) { ans = s[i]; } + } + if (isVowel(ans)) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + int num; + cin >> num; + int ans = 0; + for (int i = 1; i * i <= num; i++) { + if (num % i == 0) { ans = i; } + } + cout << ans << " " << num / ans << endl; + return 0; +} +int main() { + int n, s, x; + double temp; + cin >> n >> s; + x = (n * (n + 1)) / 2; + if (s >= x) { s %= x; } + temp = s; + temp *= 8; + temp = sqrt(++temp); + --temp /= 2; + x = (int)temp; + temp = x * (x + 1) / 2; + cout << s - temp << endl; +} +long long a[1001]; +int main() { + long long n, ans = 0; + cin >> n; + for (long long i = 0; i < n; i++) cin >> a[i]; + for (long long i = 1; i < n - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans++; + if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + string num; + cin >> num; + int in = 0; + bool sai = true; + while (in < num.size()) { + if (num[in] == '1') { + in++; + if (in < num.size() && num[in] == '4') { + in++; + if (in < num.size() && num[in] == '4') in++; + } + } else { + sai = false; + break; + } + } + if (sai) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long int choose(long long int n, long long int m) { + long long int ans = 0; + long long int num = 1; + long long int den = 1; + for (long long int i = 0; i < m; i++) { + num *= (n - i); + num = num / (i + 1); + } + return num; +} +bool isPrime(int n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (int i = 5; i * i <= n; i = i + 6) { + if (n % i == 0 || n % (i + 2) == 0) return false; + } + return true; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) { + return b; + } else { + return gcd(b % a, a); + } +} +bool sortDes(long long int i, long long int j) { + return i > j; +} +long long int bits(long long int n) { + long long int count = 0; + while (n != 0) { + if (n % 2 != 0) + count++; + else + ; + n /= 2; + } + return count; +} +int main() { + long long int i, j, k, n, s = 0; + cin >> n; + set t; + set h; + string s1, s2; + vector v(n); + for (i = 0; i < n; i++) { cin >> v[i]; } + for (i = 0; i < n; i++) { + s1 = v[i]; + s2 = ""; + t.clear(); + for (j = 0; j < s1.size(); j++) { t.insert(s1[j]); } + set::iterator itr; + for (itr = t.begin(); itr != t.end(); itr++) { s2 += *itr; } + v[i] = s2; + h.insert(v[i]); + } + cout << h.size() << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n >= k) + cout << "1" << endl; + else if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int s[n], ms[n], p[n], v[n]; + p[0] = 0; + for (int i = 1; i < n; --p[i++]) cin >> p[i]; + for (int i = 0; i < n; ++i) { + cin >> s[i]; + ms[i] = s[i]; + } + for (int i = n - 1; i > 0; --i) { + if (ms[i] < 0) continue; + if (s[p[i]] < 0 && (ms[p[i]] < 0 || ms[p[i]] > ms[i])) ms[p[i]] = ms[i]; + } + if (ms[0] < 0) ms[0] = 0; + long long int sum = ms[0]; + for (int i = 1; i < n; ++i) { + if (ms[i] < 0) + ms[i] = ms[p[i]]; + else if (ms[i] < ms[p[i]]) { + cout << -1 << endl; + return 0; + } else + sum += ms[i] - ms[p[i]]; + } + cout << sum << endl; + return 0; +} +int main() { + long long int n, x; + long long int sum = 0; + long long int suma = 0, sumb = 0; + long long int g; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x % 2 == 0) { + suma += x; + } else { + if (x < g) { g = x; } + sumb += x; + } + } + if ((suma + sumb) % 2 == 0) { + sum = suma + sumb; + } else { + sum = suma + sumb - g; + } + cout << sum << endl; + return 0; +} +int main() { + long long int n, k, a[10000]; + cin >> n >> k; + long int p = INT_MAX, count = 0; + int i; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (a[i] <= k) { + count++; + } else if (a[i] > k) { + p = i; + break; + } + } + if (p != (n - 1)) { + for (i = n - 1; i > p; i--) { + if (a[i] <= k) { + count++; + } else if (a[i] > k) { + break; + } + } + } + cout << count << endl; +} +const long long N = 1e5 + 7; +const long long INF = 1e9 + 7; +const long long dx[] = {1, -1, 0, 0}; +const long long dy[] = {0, 0, 1, -1}; +void speed() {} +long long f(long long x, long long y, long long p, long long q, long long r) { + if (p * r >= x && q * r - p * r >= y - x) { return 1; } + return 0; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + long long l = 0, r = 1e9; + if (!f(x, y, p, q, r)) { + cout << -1 << '\n'; + continue; + } + while (r - l > 1) { + long long md = (l + r) >> 1; + if (f(x, y, p, q, md)) { + r = md; + } else { + l = md; + } + } + cout << (q * r - y) << '\n'; + } + return 0; +} +int main() { + long int i, j, k, l, a, b, c, d, e, f, g, h, p, o, m = 9999999999; + cin >> a >> b >> c >> d >> e >> f >> g >> h; + i = b * c; + j = i / g; + m = min(m, j); + k = d * e; + l = k; + m = min(m, l); + o = f / h; + p = o; + m = min(m, p); + cout << m / a << endl; +} +int main() { + int i, j, n, a, k; + int arr[55][2]; + cin >> n >> k; + for (i = 0; i < n; i++) { + for (j = 0; j < 2; j++) { cin >> arr[i][j]; } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] > arr[j][0]) { + int tmp = arr[i][0]; + arr[i][0] = arr[j][0]; + arr[j][0] = tmp; + tmp = arr[i][1]; + arr[i][1] = arr[j][1]; + arr[j][1] = tmp; + } + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] == arr[j][0]) { + if (arr[i][1] < arr[j][1]) { + int tmp = arr[i][1]; + arr[i][1] = arr[j][1]; + arr[j][1] = tmp; + } + } + } + } + int frr[55], p = 0; + for (i = 0; i < n; i++) { frr[i] = 0; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (arr[i][0] == arr[j][0] && arr[i][1] == arr[j][1]) { frr[p]++; } + } + p++; + } + cout << frr[k - 1] << endl; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long int L, v, l, r; + cin >> L >> v >> l >> r; + cout << L / v - (r / v - (l - 1) / v) << endl; + } +} +int main() { + int n, num, sumb = 0, sumc = 0, sumback = 0; + cin >> n; + int c = 0; + for (int i = 0; i < n; i++) { + cin >> num; + if (c == 0) { + sumc += num; + c++; + } else if (c == 1) { + sumb += num; + c++; + } else { + sumback += num; + c = 0; + } + } + if (sumback > sumb && sumback > sumc) + cout << "back" << endl; + else if (sumb > sumback && sumb > sumc) + cout << "biceps" << endl; + else + cout << "chest" << endl; + return 0; +} +long long n; +string s1, s2, s3, s4; +int main() { + cin >> s1 >> s2 >> n; + cout << s1 << " " << s2 << endl; + for (long long i = 0; i < n; i++) { + cin >> s3 >> s4; + if (s1 == s3) { + s1 = s4; + } else { + s2 = s4; + } + cout << s1 << " " << s2 << endl; + } + return 0; +} +const int N = 3e5 + 5; +long long n, res, a[N], sum[N]; +void Input() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); +} +long long Solve() { + for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; + res = sum[n]; + for (int i = 2; i <= n; i++) { + res += a[i - 1]; + res += sum[n] - sum[i - 1]; + } + return res; +} +int main() { + Input(); + cout << Solve() << '\n'; + return 0; +} +int main() { + char a[55]; + int k, n; + cin >> k >> n; + cin >> a; + sort(a, a + k); + char temp = a[0]; + int m = 1; + int sum = a[0] - 'a' + 1; + for (int i = 1; i < k; i++) { + if (m < n) { + if (a[i] > temp + 1) { + sum += (a[i] - 'a' + 1); + m++; + temp = a[i]; + } + } + if (m == n) break; + } + if (m == n) { + cout << sum << endl; + } else { + cout << "-1" << endl; + } + return 0; +} +int main() { + int n, m, count = 0; + cin >> n >> m; + count = n; + while (n >= m) { + count += n / m; + n = (n / m) + n % m; + } + cout << count << endl; + return 0; +} +int main() { + long long n, temp, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> temp, sum += abs(temp); + cout << sum << endl; + return 0; +} +int ans; +int u; +void solve(int x, int y) { + if (x >= y) { return; } + ans += (y - x) / u; +} +int main() { + int n; + cin >> n >> u; + int k; + cin >> k; + vector a(k); + for (int i = 0; i < k; ++i) { cin >> a[i]; } + ans = k; + if (k) { + solve(1, a[0]); + for (int i = 0; i + 1 < k; ++i) { solve(a[i] + 1, a[i + 1]); } + solve(a.back() + 1, n + 1); + } else { + solve(1, n + 1); + } + cout << ans << "\n"; +} +int main() { + int n, a = 0, b = INT_MAX; + cin >> n; + int arr[n], brr[n]; + for (int i = 0; i < n; i++) { + int p, q; + cin >> p >> q; + b = min(b, q); + a += b * p; + } + cout << a << "\n"; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int flag = 0; + while (a + b < (c + 1)) { + ++flag; + ++a; + } + while (a + c < (b + 1)) { + ++flag; + ++a; + } + while (b + c < (a + 1)) { + ++flag; + ++b; + } + cout << flag << "\n"; +} +int main() { + long long s, t, q; + cin >> t >> s >> q; + long long ans = 0; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; + return 0; +} +int n, k, cnt[26]; +string c; +int main() { + cin >> n >> k >> c; + for (int i = 0; i < n; i++) cnt[c[i] - 'a']++; + bool f = true; + for (int i = 0; i < 26; i++) + if (cnt[i] > k) f = false; + cout << (f ? "YES" : "NO") << endl; + return 0; +} +int main() { + vector a; + int r, g, b; + cin >> r >> g >> b; + a.push_back(r); + a.push_back(g); + a.push_back(b); + int i = 0; + while (a[0] > 0 || a[1] > 0 || a[2] > 0) { + a[i % 3] -= 2; + i++; + } + cout << 29 + i << endl; + return 0; +} +int main() { + int k, n, w, sum = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { sum += i * k; } + if (sum > n) { + cout << sum - n << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[1002] = {0}; + int flag = 0, ans = 0, t = 0; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] <= k && flag == 0) + ans++; + else { + if (flag == 0) { + flag = 1; + t = i; + } + } + } + if (flag == 1) { + for (int j = n; j >= t; j--) { + if (a[j] <= k) + ans++; + else + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int sum = 0; + bool flag = 0; + int i = 0; + while (i < len) { + if (s[i] == 'V' && i + 1 < len) { + if (s[i + 1] == 'K') { + sum++; + i += 2; + continue; + } else { + if (i + 2 < len && s[i + 2] == 'K') { + sum++; + i += 3; + continue; + } else { + flag = 1; + i += 2; + } + } + } else if (s[i] == 'K' && i + 1 < len) { + if (s[i + 1] == 'K') { + flag = 1; + i += 2; + } else + i++; + } else + i++; + } + if (flag) sum++; + cout << sum << endl; + return 0; +} +int main() { + int pangkat; + int bilangan; + int hasilPangkat = 1; + const int basis = 2; + cin >> pangkat; + cin >> bilangan; + long long divisor; + divisor = pow(2, pangkat); + int modulo; + modulo = bilangan % divisor; + cout << modulo << endl; + return 0; +} +int main() { + int moves = 0; + int arr[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) + if (arr[i][j] == 1) { moves = abs(j - 2) + abs(i - 2); } + } + cout << moves << endl; + return 0; +} +void CalculatePrimes(vector &primes, int limit) { + primes.push_back(2); + for (int i = 3; i <= limit; i += 2) { + bool test = true; + for (size_t j = 0; j < primes.size(); ++j) { + if (i % primes[j] == 0) { + test = false; + break; + } + } + if (test) primes.push_back(i); + } +} +int main() { + int limit, count; + cin >> limit >> count; + vector primes; + CalculatePrimes(primes, limit); + vector sums; + for (size_t i = 0; i < primes.size(); ++i) { + if (i + 1 < primes.size()) { sums.push_back(primes[i] + primes[i + 1] + 1); } + } + int cnt = 0; + for (size_t i = 0; i < sums.size(); ++i) { + if (find(primes.begin(), primes.end(), sums[i]) != primes.end()) { cnt++; } + } + cout << (cnt >= count ? "YES" : "NO") << endl; + return 0; +} +const int inf = 0x3f3f3f; +int main() { + long long n; + while (cin >> n) { + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + } + return 0; +} +int main() { + long long int n, x; + cin >> n; + long long int ans = 0; + vector v; + while (n--) { + cin >> x; + ans += x; + v.push_back(x); + } + sort(v.begin(), v.end()); + long long int sum = ans; + for (int i = 0; i < v.size() - 1; i++) { + sum += ans; + ans -= v[i]; + } + cout << sum << endl; + return 0; +} +int main() { + long long n, m, i; + cin >> n; + for (i = 1; i <= n; i++) { + if (i * (i + 1) / 2 == n) { + m = i; + break; + } + if (i * (i + 1) / 2 < n && (i + 2) * (i + 1) / 2 > n) { + m = n - i * (i + 1) / 2; + break; + } + } + cout << m << endl; + return 0; +} +int main() { + long long n, t = 0, x = 1; + cin >> n; + while (x <= n) { + x *= 2; + t++; + } + cout << t << endl; + return 0; +} +int divUp(int a, int b) { + return a / b + (a % b > 0 ? 1 : 0); +} +int main() { + int n, k; + cin >> n >> k; + cout << (divUp(2 * n, k) + divUp(5 * n, k) + divUp(8 * n, k)) << endl; +} +bool isluck(long long n) { + n = abs(n); + while (n) { + if (n % 10 == 8) return true; + n /= 10; + } + return false; +} +int main() { + long long n; + cin >> n; + long long cnt = 0; + while (1) { + n++; + cnt++; + if (isluck(n)) { + cout << cnt << endl; + return 0; + } + } + cout << cnt << endl; + return 0; +} +int ada[200005]; +int main() { + int n; + cin >> n; + int x, ans = 0; + for (int i = 0; i < n; i++) { + cin >> x; + x += 100000; + if (!ada[x] && x != 100000) { + ada[x] = 1; + ans += 1; + } + } + cout << ans << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + string s; + cin >> n >> s; + int i = 0, j = n - 1; + bool check = 1; + for (i = 0; i <= j; i++, j--) { + int diff = abs(s[i] - s[j]); + if (diff == 2 || diff == 0) continue; + check = 0; + break; + } + if (check) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +const int N = 2e5 + 5; +int Go(char x) { + int f; + if (x == '^') f = 0; + if (x == '>') f = 1; + if (x == 'v') f = 2; + if (x == '<') f = 3; + return f; +} +int main() { + char A, B; + int a, b, c; + cin >> A >> B >> c; + if (c & 1) { + a = Go(A); + b = Go(B); + if ((a + c) % 4 == b) { + puts("cw"); + } else + puts("ccw"); + } else + puts("undefined"); +} +int main() { + int n, t; + cin >> n >> t; + for (int i = 0; i < t; i++) { + if (n % 10 != 0) { + n = n - 1; + } else { + n = n / 10; + } + } + cout << n << endl; +} +int main() { + int n, x, y; + cin >> n; + set myset; + for (int i = 1; i <= 2; i++) { + cin >> x; + for (int j = 1; j <= x; j++) { + cin >> y; + myset.insert(y); + } + } + if (myset.size() == n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int main() { + pair priority[101]; + int n; + cin >> n; + string name[101], status; + for (int i = 0; i < n; i++) { + cin >> name[i] >> status; + int CASE; + if (status == "rat") + CASE = 1; + else if (status == "woman" || status == "child") + CASE = 2; + else if (status == "man") + CASE = 3; + else if (status == "captain") + CASE = 4; + priority[i] = make_pair(CASE, i); + } + sort(priority, priority + n); + for (int i = 0; i < n; i++) { cout << name[priority[i].second] << endl; } + return 0; +} +static int count1 = 0; +static int count2 = 0; +map, int> m; +static int last = 0; +int dfs1(int root, int prev, int visit[], vector V[]) { + visit[root] = 1; + last = root; + if (prev == 0) + ; + else { + if (m[{prev, root}] != 0) { + ; + } else { + count1 = count1 + m[{root, prev}]; + } + } + for (int i = 0; i < V[root].size(); i++) { + if (visit[V[root][i]] == 0) { dfs1(V[root][i], root, visit, V); } + } +} +int main() { + int n; + cin >> n; + pair p[1]; + int x; + vector V[n + 1]; + int total = 0; + for (int i = 0; i < n; i++) { + cin >> p[0].first; + cin >> p[0].second; + cin >> x; + m[p[0]] = x; + total = total + x; + V[p[0].first].push_back(p[0].second); + V[p[0].second].push_back(p[0].first); + } + int visit[n + 1]; + memset(visit, 0, sizeof(visit)); + dfs1(1, 0, visit, V); + if (m[{last, 1}] != 0) + ; + else + count1 = count1 + m[{1, last}]; + cout << min(total - count1, count1) << endl; +} +int a[1000002]; +int main() { + int n; + a[1] = 1; + a[2] = 3; + for (int i = 3; i < 1000002; i++) { a[i] = (a[i - 1] + a[i - 2] + 2) % 1000000007; } + while (cin >> n) { cout << a[n] << endl; } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long count = n / k; + if (count % 2 == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i % 2 == 0) + cout << "I love "; + else + cout << "I hate "; + if (i != n) cout << "that "; + } + cout << "it" << endl; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int total = 0; + for (int i = 1; i <= n; i++) { + int temp; + cin >> temp; + if (n - i < m) { + total += min(k, temp); + } else { + total += temp; + } + } + cout << total << endl; +} +const double pi = acos(-1.); +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + if (n - k < k) { + if (n - k != str.size()) { + for (int i = 0; i < n - k; i++) { cout << "RIGHT" << endl; } + } + for (int i = str.size() - 1; i >= 0; i--) { + cout << "PRINT " << str[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } else { + if (k != 1) { + for (int i = 0; i < k - 1; i++) { cout << "LEFT" << endl; } + } + for (int i = 0; i < str.size(); i++) { + cout << "PRINT " << str[i] << endl; + if (i < str.size() - 1) cout << "RIGHT" << endl; + } + } + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int num[10010]; +int main() { + int n; + int i; + cin >> n; + int t; + for (i = 0; i < n; i++) { cin >> num[i]; } + t = num[0]; + int cur; + for (i = 1; i < n; i++) { t = gcd(t, num[i]); } + cout << n * t << endl; +} +int main() { + int n, c; + cin >> n >> c; + vector words; + for (int i = 0; i < n; ++i) { + int temp; + cin >> temp; + words.push_back(temp); + } + int k = 1; + for (int i = 0; i < n - 1; ++i) { + if (words[i + 1] - words[i] <= c) { + ++k; + } else { + k = 1; + } + } + cout << k << endl; + return 0; +} +int main() { + int flag = 0; + int n; + cin >> n; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + if (x == 1) { flag = 1; } + } + if (flag == 1) + cout << "-1" << endl; + else { + cout << "1" << endl; + } + return 0; +} +int main() { + int a, b; + long long sum = 1; + while (cin >> a >> b) { + int cnt = min(a, b); + for (int i = 1; i <= cnt; i++) sum *= i; + cout << sum << endl; + } + return 0; +} +int main() { + long long n, a, MAX = -1, ans, d = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + MAX = max(MAX, a); + d = __gcd(d, a); + } + ans = MAX / d - n; + if (n > 1 && ans % 2) + cout << "Alice\n"; + else + cout << "Bob\n"; + return 0; +} +int main() { + string a; + cin >> a; + string A[10]; + for (int i = 0; i < 10; i++) cin >> A[i]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 10; j++) + if (a.substr(i * 10, 10) == A[j]) cout << j; + cout << endl; +} +long long a, b, c[100010], d[100010], ans = 0; +int main() { + cin >> a; + for (int i = 0; i < a; i++) { + cin >> b; + if (b > 0) c[b] = 1; + if (b < 0) { + b = abs(b); + d[b] = 1; + } + } + for (int i = 0; i < 1e5 + 5; i++) { ans = ans + c[i] + d[i]; } + cout << ans << endl; + return 0; +} +const int MAXT = 1500; +int n, s; +bool ok[MAXT + 1]; +int main() { + memset(ok, true, sizeof(ok)); + cin >> n >> s; + for (int i = 1; i <= n; ++i) { + int h, m; + cin >> h >> m; + int t = h * 60 + m; + for (int i = max(0, t - s); i <= t + s; ++i) ok[i] = false; + } + for (int i = 0; i <= MAXT; ++i) + if (ok[i]) { + int h = i / 60, m = i % 60; + cout << h << " " << m << endl; + break; + } + return 0; +} +int main() { + long long n, d, i; + cin >> n >> d; + long long a[n], count = 0, m = 10001; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + long long index1, j, index2; + for (i = 0; i < n; i++) { + count = 0; + for (j = n - 1; j > i; j--) { + if (abs(a[j] - a[i]) > d) { count++; } + } + m = min(count + i, m); + } + cout << m << endl; + return 0; +} +int a[10005]; +int main() { + int n, m, b = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m; + a[m]++; + } + for (int i = 0; i <= 10000; i++) { + if (a[i] > b) b = a[i]; + } + cout << b << endl; + return 0; +} +int main() { + int64_t n, m, k = 0; + string s; + cin >> n >> m; + cin >> s; + for (int i = 1; i <= n; i++) { + if (count(s.begin(), s.end(), s[i]) > m) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +const int sz = 3e5, inf = 2e9; +int a[30]; +char s[sz]; +int main() { + int i, n, x, k, f = 0; + cin >> s; + for (i = 0; s[i]; i++) { a[s[i] - 'a']++; } + int ans = 0; + for (i = 0; i < 30; i++) + if (a[i]) ans++; + if (ans % 2) + puts("IGNORE HIM!"); + else + puts("CHAT WITH HER!"); +} +int a, b, c, temp, n, ans; +int main() { + cin >> a >> b >> c >> n; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp > b && temp < c) { ans++; } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 5 + !(n % 5 == 0) << endl; + return 0; +} +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +long long powmod(long long a, long long b, long long MOD) { + long long ans = 1; + while (b) { + if (b % 2) ans = ans * a % MOD; + a = a * a % MOD; + b /= 2; + } + return ans; +} +inline void getInt(int *p); +const int maxn = 1000010; +const int inf = 0x3f3f3f3f; +int n, k; +int a[maxn]; +int b[maxn]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int j = 1; j <= k; j++) { cin >> b[j]; } + if (k >= 2) { + cout << "Yes" << endl; + } else { + int ok = 0; + int j = 1; + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + j = i; + break; + } else { + if (a[i] >= b[1] || a[i] <= a[i - 1]) ok = 1; + } + } + for (int i = j + 1; i <= n; i++) { + if (a[i] <= b[1]) ok = 1; + } + for (int i = j + 2; i <= n; i++) { + if (a[i] <= a[i - 1]) ok = 1; + } + if (ok) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 + ch - '0'; } + } +} +int main() { + int n, k, l, c, d, p, nl, np, x, y, z; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + x = (k * l) / nl; + y = c * d; + z = p / np; + int casiresp1 = min(x, y); + int casiresp2 = min(casiresp1, z); + int resp = casiresp2 / n; + cout << resp << endl; + return 0; +} +const int maxn = 100000 + 10; +int a[maxn]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + bool ok = 1; + for (int i = k; i < n; i++) { + if (a[i - 1] != a[i]) { + ok = 0; + break; + } + } + if (!ok) + cout << -1 << endl; + else { + int ans = k - 1; + for (int i = k - 1 - 1; i >= 0; i--) { + if (i + 1 >= n) continue; + if (a[i] == a[i + 1]) + ans--; + else + break; + } + cout << ans << endl; + } + return 0; +} +int gcd(int a, int b) { + if (b == 0) + return a; + else + gcd(b, a % b); +} +int main() { + int x, y, z; + while (cin >> x >> y >> z) { + int c = sqrt((z * y) / x); + int a = (x * c) / y; + int b = x / a; + cout << a * 4 + b * 4 + c * 4 << endl; + } +} +const int maxn = 35; +int n; +int r[maxn][maxn], row[maxn], column[maxn]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < n; j++) { + cin >> r[i][j]; + sum += r[i][j]; + } + row[i] = sum; + } + for (int i = 0; i < n; i++) { + int sum = 0; + for (int j = 0; j < n; j++) sum += r[j][i]; + column[i] = sum; + } + int res = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) + if (row[i] < column[j]) res++; + } + cout << res << endl; + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << b << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, p = 0; + cin >> n; + int a[n]; + int i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + if (a[a[a[a[i]]]] == a[i]) { + p = 2; + break; + } else { + p = 1; + } + } + p == 2 ? cout << "YES" << endl : cout << "NO" << endl; +} +int main() { + long long a, b, c, l, ans = 0; + cin >> a >> b >> c >> l; + long long total = (l + 1) * (l + 2) * (l + 3); + total /= 6; + long long rest; + for (int i = 0; i <= l; i++) + if (b + c <= a + i) { + rest = min(l - i, a + i - b - c); + ans += (rest + 2) * (rest + 1) / 2; + } + for (int i = 0; i <= l; i++) + if (a + c <= b + i) { + rest = min(l - i, b + i - a - c); + ans += (rest + 2) * (rest + 1) / 2; + } + for (int i = 0; i <= l; i++) + if (b + a <= c + i) { + rest = min(l - i, c + i - b - a); + ans += (rest + 2) * (rest + 1) / 2; + } + cout << total - ans << endl; + return 0; +} +int main() { + long long int x, **p, y; + cin >> x; + p = new long long int *[x]; + for (int i = 0; i < x; i++) { p[i] = new long long int[3]; } + for (int i = 0; i < x; i++) { + for (int j = 0; j < 3; j++) { cin >> p[i][j]; } + } + for (int i = 0; i < x; i++) { + if (p[i][2] % 2 == 0) { + y = p[i][2] / 2; + cout << (p[i][0] * y) - y * p[i][1] << endl; + } + if (p[i][2] % 2 != 0) { + y = (p[i][2] / 2); + cout << (p[i][0] * (y + 1)) - y * p[i][1] << endl; + } + } +} +int main() { + int n, k; + cin >> n >> k; + bool flage = false; + while (!flage) { + for (int i = 1; i <= n; i++) { + if (k >= i) + k -= i; + else { + flage = true; + break; + } + } + } + cout << k << endl; +} +int n, m; +int price[105]; +int match[105][105]; +int main() { + while (cin >> n >> m) { + memset(match, 0, sizeof(match)); + for (int i = 1; i <= n; i++) cin >> price[i]; + int u, v; + for (int i = 0; i < m; i++) { + cin >> u >> v; + match[u][v] = 1; + match[v][u] = 1; + } + int MIN = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + if (match[i][j] == 0) continue; + for (int k = j + 1; k <= n; k++) { + if (match[j][k] == 0 || match[k][i] == 0) continue; + if (MIN > price[i] + price[j] + price[k]) MIN = price[i] + price[j] + price[k]; + } + } + } + if (MIN == 0x3f3f3f3f) + cout << -1 << endl; + else + cout << MIN << endl; + } +} +int main() { + int n[128] = {0}; + int len = 0; + char ch; + bool flag = 0; + while ((ch = cin.get()) != '\n') n[len++] = ch - '0'; + for (int i = 0; i < len; i++) { + if (n[i] != 1) { + flag = 1; + break; + } + if (n[i] == 1) { + if (n[i + 1] == 1 || n[i + 1] == 0) + continue; + else if (n[i + 1] == 4) { + if (n[i + 2] == 1 || n[i + 2] == 0) { + i += 1; + continue; + } else if (n[i + 2] == 4) { + i += 2; + } + } + } + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (n >= 0) { + n -= __gcd(a, n); + if (n < 0) { + cout << 1 << endl; + return 0; + } + n -= __gcd(b, n); + if (n < 0) { + cout << 0 << endl; + return 0; + } + } +} +long long arr[1001]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + long long ma = -1e9; + long long a = 0; + for (int i = 1; i <= n; i++) { + a = 0; + for (int j = i; j <= n; j++) { + a ^= arr[j]; + ma = max(ma, a); + } + } + cout << ma << endl; + return 0; +} +int main() { + int x = 0; + while (cin >> x) { + int n = 0; + if (x < 6) + n = 1; + else if (x % 5 == 0) + n = x / 5; + else + n = x / 5 + 1; + cout << n << endl; + } +} +int main() { + long long n, a, i = 4, count = 0; + int ar[] = {1, 5, 10, 20, 100}; + cin >> n; + for (;;) { + if (i == -1) { break; } + if (n >= ar[i]) { + n -= ar[i]; + count++; + } else { + i--; + } + } + cout << count << endl; + return 0; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + long long n, m; + cin >> n >> m; + if (n <= 27) { + long long p = pow(2, n); + cout << m % p << '\n'; + } else { + cout << m << '\n'; + } + return 0; +} +int main() { + int n, k, i = 0, z, solve = 0; + cin >> n >> k; + z = 240 - k; + for (int i = 1; i <= n; i++) { + z = z - 5 * i; + if (z >= 0) { solve++; } + } + cout << solve << endl; + return 0; +} +int main() { + int n, k, r = 0, i; + string s; + cin >> n >> k >> s; + if (2 * k > n) { r = 1; } + if (r) { + for (i = k; i < n; i++) { cout << "RIGHT" << endl; } + for (i = n - 1; i >= 0; i--) { + cout << "PRINT " << s[i] << endl; + if (i) { cout << "LEFT" << endl; } + } + } else { + for (i = 0; i < k - 1; i++) { cout << "LEFT" << endl; } + for (i = 0; i < n; i++) { + cout << "PRINT " << s[i] << endl; + if (i != n - 1) { cout << "RIGHT" << endl; } + } + } +} +int main() { + int n; + cin >> n; + int a[n]; + int i; + int j; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int count = 1; + for (i = 0; i < n - 1; i++) { + if (a[i] == 0) { continue; } + if (a[i] != a[i + 1]) { count++; } + } + cout << count << endl; +} +int busca(char x, char v[]) { + int pos; + for (int i = 0; i < 9; i++) { + if (v[i] == x) pos = i; + } + return pos; +} +int main() { + char v[9] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; + char x; + string a, b; + cin >> x; + cin >> a >> b; + if (x == a[1] && x == b[1]) { + if (busca(a[0], v) > busca(b[0], v)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + if (x == a[1]) + cout << "YES" << endl; + else { + if (a[1] == b[1]) { + if (busca(a[0], v) > busca(b[0], v)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + } + } + return 0; +} +int main() { + long long int q, t; + long long int sum = 0; + vector v; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> t; + sum += t; + v.push_back(t); + } + sort(v.begin(), v.end()); + long long int score = sum; + for (int j = 0; j < q - 1; j++) { + score += sum; + sum -= v[j]; + } + cout << score << endl; + return 0; +} +int arr[100]; +int main() { + string s; + string a; + while (cin >> s) { + a = ""; + for (int i = 0; i < s.length(); i++) { + if (s[i] != '+') a.push_back(s[i]); + } + int p = a.length(); + for (int i = 0; i < a.length(); i++) { arr[i] = a[i] - '0'; } + int n = sizeof(arr) / sizeof(arr[0]); + sort(arr, arr + n, greater()); + for (int i = p - 1; i >= 1; i--) { + cout << arr[i]; + cout << "+"; + } + cout << arr[0]; + cout << endl; + } + return 0; +} +int main() { + double n, k; + cin >> n >> k; + long long red = n * 2, green = n * 5, blue = n * 8; + cout << (long long)(ceil(red / k) + ceil(green / k) + ceil(blue / k)) << endl; +} +int main() { + int n, c = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + c++; + if (s[i] == '0') break; + } + cout << c << endl; + return 0; +} +int main() { + long long n, x, cnt = 0, d; + cin >> n >> x; + string s; + for (int i = 0; i < n; i++) { + cin >> s >> d; + if (s == "+") { + x += d; + } else if (s == "-") { + if (x < d) + cnt++; + else + x -= d; + } + } + cout << x << " " << cnt << endl; + return 0; +} +long long modpow(long long x, long long n, long long m) { + if (n == 0) return 1 % m; + long long u = modpow(x, n / 2, m); + u = (u * u) % m; + if (n % 2 == 1) u = (u * x) % m; + return u; +} +int main() { + int n, k, tt = 0; + cin >> n; + k = 1; + for (int e = 0; e < n; e++) { + for (int p = 0; p < (n - k) / 2; p++) cout << "*"; + for (int p = 0; p < k; p++) cout << "D"; + for (int p = 0; p < (n - k) / 2; p++) cout << "*"; + if (k == n && tt == 0) tt = 1; + if (tt == 0) + k += 2; + else + k -= 2; + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + while (n) { + if (n % 10 != 1 && n % 100 != 14 && n % 1000 != 144) { + cout << "NO" << endl; + break; + } + n /= 10; + } + if (!n) cout << "YES" << endl; +} +int n, k; +int main() { + cin >> n >> k; + for (int i = 0; i < k; i++) { + if (n % 10 == 0) + n = n / 10; + else + n = n - 1; + } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + string str; + int Sum = 0; + for (int i = 0; i < n; i++) { + cin >> str; + if (str == "Tetrahedron") + Sum += 4; + else if (str == "Cube") + Sum += 6; + else if (str == "Octahedron") + Sum += 8; + else if (str == "Dodecahedron") + Sum += 12; + else if (str == "Icosahedron") + Sum += 20; + } + cout << Sum << endl; + return 0; +} +long long int max(long long int a, long long int b) { + if (a >= b) + return a; + else + return b; +} +long long int min(long long int a, long long int b) { + if (a >= b) + return b; + else + return a; +} +long long int diff(long long int a, long long int b) { + if (a >= b) + return a - b; + else + return b - a; +} +long long int mod(long long int a) { + if (a >= 0) + return a; + else + return -a; +} +void pairsort(int a[], int b[], int n) { + pair pairt[n]; + for (int i = 0; i < n; i++) { + pairt[i].first = a[i]; + pairt[i].second = b[i]; + } + sort(pairt, pairt + n); + for (int i = 0; i < n; i++) { + a[i] = pairt[i].first; + b[i] = pairt[i].second; + } +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long int rev(long long int n) { + long long int ans = 0; + while (n) { + ans = ans * 10 + n % 10; + n = n / 10; + } + return ans; +} +int main() { + long long int s = 0; + int n; + cin >> n; + while (n--) { + int a, b, c, d; + cin >> a >> b >> c >> d; + s = s + (c - a + 1) * (d - b + 1); + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v; + int count = 0; + int ara[n]; + for (int i = 0; i < n; i++) { cin >> ara[i]; } + for (int i = 1; i < n; i++) { + if (ara[0] <= ara[i]) { v.push_back(ara[i]); } + } + int flag = 0, s = v.size(); + if (s == 0) { + cout << "0" << endl; + } else { + while (1) { + flag = 0; + sort(v.begin(), v.end()); + if (ara[0] <= v[s - 1]) { + ara[0]++; + v[s - 1]--; + count++; + flag = 1; + } + if (flag == 0) { break; } + } + cout << count << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, c, b; + cin >> s >> a >> b >> c; + cout << s / c / a * b + s / c << endl; + } + return 0; +} +int arr[524289] = {0}; +int conv(long long int num) { + int pos = 0, ans = 0; + while (num > 0) { + int s = num % 10; + num /= 10; + if (s % 2 != 0) ans += pow(2, pos); + pos++; + } + return ans; +} +int main() { + int t; + cin >> t; + while (t--) { + char c; + long long int num; + cin >> c >> num; + int position = conv(num); + if (c == '+') + arr[position]++; + else if (c == '-') + arr[position]--; + else + cout << arr[position] << "\n"; + } +} +int l, r, a, ans; +int main() { + cin >> l >> r >> a; + while (l > r && a) a--, r++; + while (r > l && a) a--, l++; + while (a > 1) { + a -= 2; + l++, r++; + } + if (l < r) { ans = l; } + if (r < l) { ans = r; } + if (r == l) { ans = r; } + cout << (2 * ans) << endl; +} +int main() { + int n; + cin >> n; + if (n >= 0) { + int m = n + 1; + while (m) { + if (m % 10 == 8) { + cout << 1 << endl; + return 0; + } + m /= 10; + } + if (n % 10 < 8) { + cout << 8 - n % 10 << endl; + return 0; + } else { + m = n / 10; + while (m) { + if (m % 10 == 7) { + cout << 10 - n % 10 << endl; + return 0; + } else if (m % 10 != 9) { + cout << 18 - n % 10 << endl; + return 0; + } + m /= 10; + } + } + cout << 18 - n % 10 << endl; + } else { + n = -n; + if (n <= 8) { + cout << 8 + n << endl; + return 0; + } + int m = n - 1; + while (m) { + if (m % 10 == 8) { + cout << 1 << endl; + return 0; + } + m /= 10; + } + if (m % 10 == 9) { + cout << 1 << endl; + return 0; + } + m = n / 10; + while (m) { + if (m % 10 == 9) { + cout << n % 10 + 1 << endl; + return 0; + } else if (m % 10 != 0) { + cout << n % 10 + 2 << endl; + return 0; + } + m /= 10; + } + cout << n % 10 + 2 << endl; + } + return 0; +} +string s1, s2; +int A, B, ans1, ans2; +int check(char c1) { + if (c1 == '8') return 1; + if (c1 == '[') return 2; + if (c1 == '(') return 3; +} +int main() { + cin >> s1; + cin >> s2; + for (int i = 0; i < s1.size(); i += 2) { + A = check(s1[i]); + B = check(s2[i]); + if (A == 1 && B == 2) ans1++; + if (A == 2 && B == 1) ans2++; + if (A == 2 && B == 3) ans1++; + if (A == 3 && B == 2) ans2++; + if (A == 3 && B == 1) ans1++; + if (A == 1 && B == 3) ans2++; + } + if (ans1 > ans2) cout << "TEAM 1 WINS" << endl; + if (ans1 < ans2) cout << "TEAM 2 WINS" << endl; + if (ans1 == ans2) cout << "TIE" << endl; +} +char k[105]; +int main() { + int n, m; + char s, t; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> k[i]; + for (int i = 1; i <= m; i++) { + int l, r; + cin >> l >> r >> s >> t; + for (int j = l; j <= r; j++) { + if (k[j] == s) k[j] = t; + } + } + for (int i = 1; i <= n; i++) cout << k[i]; + cout << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int a = -1, b = -1; + for (int i = 0; i < n; ++i) { + if (s[i] == 'G' || s[i] == 'T') { + if (a == -1) + a = i; + else + b = i; + } + } + if (abs(a - b) % k != 0) return cout << "NO\n", 0; + if (a > b) swap(a, b); + for (int i = a; i <= b; i += k) { + if (s[i] == '#') return cout << "NO\n", 0; + } + cout << "YES\n"; +} +int main() { + int a, b; + cin >> a >> b; + if (a == b) { + cout << a << " " + << "0" << endl; + } else if (a > b) { + cout << b << " " << (a - b) / 2 << endl; + } else { + cout << a << " " << (b - a) / 2 << endl; + } + return 0; +} +void solveTest() { + int lessons; + cin >> lessons; + vector schedule; + for (int _ = 0; _ < lessons; _++) { + bool isLesson; + cin >> isLesson; + schedule.push_back(isLesson); + } + bool isAtHome = true; + int hoursSpent = 0; + for (int i = 0; i < lessons; i++) { + if (schedule[i]) + isAtHome = false; + else { + if (i < lessons - 1) { + if (schedule[i + 1] == false) isAtHome = true; + } else { + if (schedule[i] == false) isAtHome = true; + } + } + if (isAtHome == false) hoursSpent++; + } + cout << hoursSpent << endl; +} +int main() { + solveTest(); + return 0; +} +int main() { + long long n, m, a, b, sum1, sum2; + cin >> n >> m >> a >> b; + if ((n % m == 0)) { + cout << 0 << endl; + return 0; + } + sum1 = ((n / m + 1) * m - n) * a; + sum2 = (n - (n / m) * m) * b; + if (sum1 > sum2) + cout << sum2 << endl; + else + cout << sum1 << endl; + return 0; +} +int main() { + int a, b, c, n, temp = 0, x; + cin >> a >> b >> c >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x > b && x < c) { temp++; } + } + cout << temp << endl; + return 0; +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, t, k, d, times; +set st; +int main() { + cin >> n >> t >> k >> d; + if (n % k != 0) { + times = n / k + 1; + } else + times = n / k; + int oven1 = 0, oven2 = d; + for (int i = 0; i < times; i++) { + if (oven1 <= oven2) + oven1 += t; + else + oven2 += t; + } + if (max(oven2, oven1) < times * t) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + long int a, b, c, d, i, j, k, l, n, m; + int ar[5][5], ar1[4][4]; + memset(ar, 0, sizeof ar); + for (i = 1; i <= 3; i++) { + for (j = 1; j <= 3; j++) { cin >> ar[i][j]; } + } + for (i = 1; i <= 3; i++) { + for (j = 1; j <= 3; j++) { + a = ar[i][j] + ar[i][j + 1] + ar[i - 1][j] + ar[i + 1][j] + ar[i][j - 1]; + if (a % 2 == 0) + ar1[i][j] = 1; + else + ar1[i][j] = 0; + } + } + for (i = 1; i <= 3; i++) { + for (j = 1; j <= 3; j++) { cout << ar1[i][j]; } + cout << endl; + } +} +int main() { + int i, a, b, j, s, c[1000], d[1000]; + cin >> a >> b; + for (i = 0; i < b; i++) { cin >> c[i]; } + sort(c, c + b); + for (i = 0, j = 0; i < b - a + 1; i++, j++) { d[j] = c[i + a - 1] - c[i]; } + sort(d, d + b - a + 1); + cout << d[0] << endl; +} +int i, j, n, a[100000]; +int t = 1000 * 1000 * 1000 + 7; +int main() { + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + for (i = 2; i < n; i++) { + int ma = -1; + for (j = 1; j < n; j++) { + if (j == i) continue; + if (j == i - 1) + ma = max(ma, a[j + 2] - a[j]); + else + ma = max(ma, a[j + 1] - a[j]); + } + t = min(t, ma); + } + cout << t << endl; + return 0; +} +int main() { + cout << "Karen" << endl; + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int a[100005]; +int main() { + int n, m; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + int t = n; + for (int i = 1; i <= n; i++) + if (a[i] == a[1] || a[i] == a[n]) t--; + cout << t << endl; + return 0; +} +int main() { + int n, a, b, i, ans; + cin >> n >> a >> b; + vector f(n); + for (i = 0; i < n; i++) cin >> f[i]; + sort(f.rbegin(), f.rend()); + ans = -(f[a] - f[a - 1]); + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i, j; + char s[110][110] = {0}; + char a[110] = {0}; + int v[110] = {0}; + for (i = 0; i < n; i++) cin >> s[i]; + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { a[i] = max(a[i], s[j][i]); } + } + int ans = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (s[i][j] == a[j]) { + ans++; + break; + } + } + } + cout << ans << endl; +} +int main() { + string s; + cin >> s; + map m; + for (int i = 0; i < s.length(); i++) m[s[i]]++; + int ans = m['B']; + ans = min(ans, m['u'] / 2); + ans = min(ans, m['l']); + ans = min(ans, m['b']); + ans = min(ans, m['a'] / 2); + ans = min(ans, m['s']); + ans = min(ans, m['r']); + cout << ans << endl; + return 0; +} +int i, j; +int main() { + int t; + cin >> t; + while (t--) { + int a, b, res = 0; + cin >> a >> b; + while (a && b) { + if (a > b) { + int k = a / b; + res += k; + a %= b; + } else { + int k = b / a; + res += k; + b %= a; + } + } + cout << res << endl; + } +} +int main() { + long long a; + cin >> a; + cout << (a % 2 == 1 ? 1 : 2) << endl; + return 0; +} +int main() { + string s1, s2, s; + int i, pos1, pos2; + char a[10] = "6789TJQKA"; + cin >> s; + cin >> s1 >> s2; + if (s1[1] == s[0]) { + if (s2[1] != s[0]) { + cout << "YES" << endl; + } else { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) { pos1 = i; } + if (s2[0] == a[i]) { pos2 = i; } + } + if (pos1 <= pos2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } + } else { + if (s1[1] == s2[1]) { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) { pos1 = i; } + if (s2[0] == a[i]) { pos2 = i; } + } + if (pos1 <= pos2) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int n, c = 0, d1, d2; + int ref[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + cin >> n; + d1 = n % 10; + d2 = n / 10; + cout << ref[d1] * ref[d2] << '\n'; + return 0; +} +int main() { + int i, n, c = 0, p, q; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p >> q; + if (q - p >= 2) { c++; } + } + cout << c << endl; +} +int main() { + int Mcost, Vcost, Mtime, Vtime; + cin >> Mcost >> Vcost >> Mtime >> Vtime; + int Misha = max((3 * Mcost) / 10, Mcost - (Mcost / 250) * Mtime); + int Vasya = max((3 * Vcost) / 10, Vcost - (Vcost / 250) * Vtime); + if (Misha > Vasya) + cout << "Misha" << endl; + else if (Vasya > Misha) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +int main() { + int count; + cin >> count; + for (int i = 0; i < count; ++i) { + long long a, b, k; + cin >> a >> b >> k; + long long ans = 0; + ans += (a * (k / 2)); + ans -= (b * (k / 2)); + if (k % 2) ans += a; + cout << ans << endl; + } + return 0; +} +int main() { + int n, h, g, t, i = 0, j; + int a[3000]; + int b[3000]; + while (cin >> n) { + i = 0; + t = 0; + for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (a[i] == b[j]) t++; + } + } + cout << t << endl; + } +} +int main() { + int n, i; + string str; + cin >> n; + for (i = 0; i < n; i++) { + cin >> str; + int count = 0; + int j, k; + if (str.length() > 10) { + cout << str[0] << str.length() - 2 << str[str.length() - 1] << endl; + } else + cout << str << endl; + } + return 0; +} +int main() { + int k, r, tmp = 0; + cin >> k >> r; + tmp = k; + for (int i = 1; i <= i; ++i) { + k *= i; + if (k % 10 == 0) { + cout << i << endl; + break; + } else { + int x = 0; + x = k % 10; + if (x == r) { + cout << i << endl; + break; + } + k = tmp; + } + } + return 0; +} +int main() { + int n, c = 0, cnt = 0; + ; + vector v; + cin >> n; + string s; + while (cin >> s) { + for (int i = 0; i <= s.length(); i++) { + if (s[i] >= 65 && s[i] < 97) c++; + } + v.push_back(c); + c = 0; + } + sort(v.begin(), v.end()); + cout << v[v.size() - 1] << endl; + return 0; +} +long long int n, k; +long long int a[1007]; +int main() { + cin >> n >> k; + long long int _d = 0, _c = 0; + for (long long int i = 1; i <= n; i++) { + cin >> a[i]; + if (k > 0) { + _c += a[i]; + long long int x = min(8LL, _c); + k -= x; + _c -= x; + _d = i; + } + } + if (k <= 0) { + cout << _d << "\n"; + } else { + cout << -1 << "\n"; + } + return 0; +} +int main() { + long long i, j, a, b, c, d, e, f = 0, g, n; + string s; + cin >> n >> s; + for (i = n; i < s.size() && i < 2000; i = i + n) { + if (s.at(i - 1) == s.at(i - 2) && s.at(i - 2) == s.at(i - 3)) f++; + } + cout << f << endl; + return 0; +} +int main() { + int n, sum1 = 0, sum2 = 0, sum3 = 0; + cin >> n; + vector ch[n]; + for (int i = 0; i < n; i++) { + int u, v, w; + cin >> u >> v >> w; + ch[i].push_back(u); + ch[i].push_back(v); + ch[i].push_back(w); + } + for (int i = 0; i < n; i++) { + sum1 += ch[i][0]; + sum2 += ch[i][1]; + sum3 += ch[i][2]; + } + if (sum1 == 0 && sum2 == 0 && sum2 == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + for (int i = 0; i < n; i++) { ch[i].clear(); } + return 0; +} +int main() { + int a, counter = 0; + cin >> a; + while (a > 0) { + a = a - 5; + counter++; + } + cout << counter << endl; +} +int k, c[1010]; +long long f[1010][1010]; +long long dp[1010]; +int main() { + cin >> k; + for (int i = (1), _n = (k); i <= _n; i++) cin >> c[i]; + f[0][0] = 1; + for (int i = (1), _n = (1005); i <= _n; i++) { + f[i][0] = 1; + for (int j = (1), _n = (1005); j <= _n; j++) { f[i][j] = (f[i - 1][j] + f[i - 1][j - 1]) % 1000000007; } + } + dp[0] = 1; + long long sum = 0; + for (int i = (1), _n = (k); i <= _n; i++) { + dp[i] = (dp[i - 1] * f[sum + c[i] - 1][c[i] - 1]) % 1000000007; + sum += c[i]; + } + cout << dp[k] << endl; +} +char a[105]; +int main() { + int n, i, j, k; + cin >> n >> a; + int sum = 0; + for (i = 0; i < n; i++) { + if (a[i] == '0') { + cout << sum; + sum = 0; + } else + sum++; + } + cout << sum << endl; + return 0; +} +int main() { + string s; + int B = 0, u = 0, l = 0, b = 0, a = 0, S = 0, r = 0; + cin >> s; + int Bulbasaur = 1e6, k; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'B') { + B++; + } else if (s[i] == 'u') { + u++; + } else if (s[i] == 'l') { + l++; + } else if (s[i] == 'b') { + b++; + } else if (s[i] == 'a') { + a++; + } else if (s[i] == 's') { + S++; + } else if (s[i] == 'r') { + r++; + } + } + Bulbasaur = min(Bulbasaur, B); + Bulbasaur = min(Bulbasaur, u / 2); + Bulbasaur = min(Bulbasaur, l); + Bulbasaur = min(Bulbasaur, b); + Bulbasaur = min(Bulbasaur, a / 2); + Bulbasaur = min(Bulbasaur, r); + Bulbasaur = min(Bulbasaur, S); + cout << Bulbasaur << "\n"; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << 4 * (sqrt(a * b / c) + sqrt(b * c / a) + sqrt(a * c / b)) << endl; + return 0; +} +int f(int a, int b) { + if (a % b == 0) return a / b; + return a / b + f(b, a % b); +} +int t, n, m; +int main() { + cin >> t; + while (t--) { + cin >> n >> m; + cout << f(n, m) << endl; + } + return 0; +} +int main() { + int n, m, c = 1; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + if (i % 2 == 0 || i == 0) { + for (int j = 0; j < m; j++) { a[i][j] = '#'; } + } else { + if (c % 2 == 1) { + for (int j = 0; j < m; j++) { + if (j + 1 == m) + a[i][j] = '#'; + else + a[i][j] = '.'; + } + c++; + } else { + a[i][0] = '#'; + for (int j = 1; j < m; j++) a[i][j] = '.'; + c++; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cout << a[i][j]; + cout << endl; + } +} +const int64_t M = 110; +int64_t cnt[M][M]; +int main() { + int64_t n; + cin >> n; + for (int64_t i = 1; i <= n; i++) { + int64_t x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + for (int64_t r = x1; r <= x2; r++) + for (int64_t c = y1; c <= y2; c++) cnt[r][c]++; + } + int64_t ans = 0; + for (int64_t i = 1; i <= 100; i++) + for (int64_t j = 1; j <= 100; j++) ans += cnt[i][j]; + cout << ans << endl; + return 0; +} +int p, g, b, o, r, y; +int main() { + string s; + int a; + cin >> a; + for (int i = 0; i < a; i++) { + cin >> s; + if (s == "purple") { + p++; + } else if (s == "green") { + g++; + } else if (s == "blue") { + b++; + } else if (s == "orange") { + o++; + } else if (s == "red") { + r++; + } else if (s == "yellow") { + y++; + } + } + cout << 6 - a << endl; + if (p == 0) { cout << "Power" << endl; } + if (g == 0) { cout << "Time" << endl; } + if (b == 0) { cout << "Space" << endl; } + if (o == 0) { cout << "Soul" << endl; } + if (r == 0) { cout << "Reality" << endl; } + if (y == 0) { cout << "Mind" << endl; } +} +int main() { + int n; + int num[1005]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> num[i]; + if (num[i] == 1) { + cout << -1 << endl; + return 0; + } + } + cout << 1 << endl; + return 0; +} +long long n, k = 1, has; +int main() { + cin >> n; + while (k - 1 < n) { + k *= 2; + has++; + } + cout << has << endl; +} +int main() { + int i, j, n; + long long t, a[105]; + cin >> n >> t; + for (i = 0; i < n; i++) { + cin >> a[i]; + t -= (86400 - a[i]); + if (t <= 0) break; + } + cout << i + 1 << endl; + return 0; +} +const int N = 1e5 + 5; +const int M = 1e6 + 3; +int ara[N]; +int main() { + int n; + cin >> n; + ara[0] = 1; + ara[1] = 1; + for (int i = 2; i <= n; i++) { ara[i] = (3 * ara[i - 1]) % M; } + cout << ara[n] << "\n"; + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int box = b / (k - 1); + int kvbox = k * v * box; + int onemore = (b % (k - 1) + 1) * v; + int ans = 0; + if (a <= kvbox) { + ans = a / (k * v) + (a % (k * v) > 0); + } else if (a - kvbox <= onemore) { + ans = box + 1; + } else { + int r = a - kvbox - onemore; + ans = box + 1 + r / v + (r % v > 0); + } + cout << ans << endl; + return 0; +} +string st; +string temp, bst; +set v; +string rl(string st) { + char c = st[0]; + st[0] = st[1]; + st[1] = st[2]; + st[2] = st[3]; + st[3] = c; + return st; +} +string ru(string st) { + char temp = st[4]; + st[4] = st[0]; + st[0] = st[5]; + st[5] = st[2]; + st[2] = temp; + return st; +} +int main() { + cin >> st; + sort(st.begin(), st.end()); + do { + temp = st; + bst = temp; + for (int iter = 1; iter <= 2000; iter++) { + if (rand() % 2) + temp = rl(temp); + else + temp = ru(temp); + if (bst > temp) bst = temp; + } + v.insert(bst); + } while (next_permutation(st.begin(), st.end())); + cout << v.size() << endl; + cin.get(); + cin.get(); + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + map m; + for (int i = 0; i < s.size(); i++) m[s[i]]++; + for (map::iterator it = m.begin(); it != m.end(); it++) { + if (it->second > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + long long int n; + cin >> n; + cout << (n / 2 + 1) << endl; + return 0; +} +const long long mod = 1e9 + 7; +long long qpow2(long long p) { + long long a = 2; + long long res = 1; + while (p) { + if (p & 1) { + res *= a; + res %= mod; + } + a *= a; + a %= mod; + p >>= 1; + } + return res; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + cout << 1 << endl; + } else { + cout << (qpow2(n - 1) + qpow2(2 * n - 1)) % mod << endl; + } + return 0; +} +int main() { + unsigned long long int k, n; + cin >> n >> k; + if ((n / k) & 1) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +const int maxn = 1e3 + 5; +int arr[maxn]; +int stc[maxn]; +int main() { + int n, top; + while (cin >> n) { + top = 0; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + int i; + for (i = 0; i < n - 1; ++i) { + if (arr[i + 1] == 1) { stc[top++] = arr[i]; } + } + stc[top++] = arr[i]; + cout << top << endl << stc[0]; + for (int i = 1; i < top; ++i) { cout << " " << stc[i]; } + cout << endl; + } + return 0; +} +long long l, r; +int t; +int main() { + cin >> t; + while (t--) { + cin >> l >> r; + for (int i = 0; i < 64; ++i) { + if ((l & (1LL << (long long)i)) == 0) { + if ((l | (1LL << (long long)i)) <= r) + l = (l | (1LL << (long long)i)); + else + break; + } + } + cout << l << '\n'; + } +} +int kg = 0; +int n, k; +char a[50]; +void judge(char a[]) { + int digit; + int num[10]; + memset(num, 0, sizeof(num)); + for (int i = 0; a[i] != '\0'; i++) { num[a[i] - '0'] = 1; } + for (int i = 0; i <= k; i++) { + if (!num[i]) return; + } + kg++; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + judge(a); + } + cout << kg << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0;; i++) { + int f; + if (i <= n) { + for (int j = 0; j < n; j++) { + f = j + 1; + for (f; f < n; f++) { + if (a[f] < a[j]) { a[j] = a[j] - a[f]; } + } + } + } else { + for (int j = n - 1; j >= 0; j--) { + f = j - 1; + for (f; f >= 0; f--) { + if (a[j] > a[f]) { a[j] = a[j] - a[f]; } + } + } + i = 0; + } + int check = 0; + for (int l = 0; l < n; l++) { + if (a[0] != a[l]) { check = 1; } + } + if (check == 0) break; + } + int sum = 0; + for (int l = 0; l < n; l++) { sum = sum + a[l]; } + cout << sum << endl; + return 0; +} +int a[7]; +int main() { + int sum = 0; + for (int i = 1; i <= 6; i++) { + cin >> a[i]; + sum += a[i]; + } + sort(a + 1, a + 7); + if (sum % 2 == 1) { + cout << "NO" << endl; + } else { + int flag = 0; + sum /= 2; + if (a[1] + a[5] + a[6] == sum) + flag = 1; + else if (a[1] + a[4] + a[6] == sum) + flag = 1; + else if (a[2] + a[3] + a[6] == sum) + flag = 1; + else if (a[1] + a[3] + a[6] == sum) + flag = 1; + else if (a[1] + a[2] + a[6] == sum) + flag = 1; + if (flag == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, c = 0, d1, d2; + int ref[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + cin >> n; + d1 = n % 10; + d2 = n / 10; + cout << ref[d1] * ref[d2] << '\n'; + return 0; +} +int main() { + long long t, n, s, a, b, c, i, j; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + s = s / c; + cout << s + (s / a) * b << endl; + } +} +int main() { + long long int n, m; + cin >> n >> m; + long long int cp = n; + long long int sq; + long long int count = 0; + while (n != -1) { + sq = int(sqrt(n)); + if (sq * sq == n) { + long long int a = sq; + long long int b = cp - n; + if (a + (b * b) == m) count++; + } + n--; + } + cout << count << endl; + return 0; +} +const int mod = 1e9 + 7; +const int maxn = 1e6; +long long n, m; +long long dp[120][4]; +int main() { + int a, b, c; + cin >> n >> a >> b >> c; + memset(dp, 0, sizeof dp); + dp[1][2] = maxn; + dp[1][3] = maxn; + for (int i = 2; i <= n; i++) { + dp[i][1] = min(dp[i - 1][2] + a, dp[i - 1][3] + b); + dp[i][2] = min(dp[i - 1][1] + a, dp[i - 1][3] + c); + dp[i][3] = min(dp[i - 1][1] + b, dp[i - 1][2] + c); + } + cout << min(dp[n][1], min(dp[n][2], dp[n][3])) << endl; + return 0; +} +int main() { + int n, m, l, r; + char c1, c2; + string s; + while (cin >> n >> m) { + cin >> s; + while (m--) { + cin >> l >> r >> c1 >> c2; + for (int i = l; i <= r; i++) { + if (s[i - 1] == c1) s[i - 1] = c2; + } + } + cout << s << endl; + } + return 0; +} +const int INF_INT = 2147483647; +const long long INF_LL = 9223372036854775807LL; +const unsigned long long INF_ULL = 18446744073709551615Ull; +const long long P = 92540646808111039LL; +const long long maxn = 2e5 + 10, MOD = 1e9 + 7; +const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1}; +const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1}; +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +void init() {} +int a[maxn]; +int main() { + init(); + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) cin >> a[i]; + int r = -1; + int res = 1e9 + 7; + for (int i = 0; i < n; i++) { + if (s[i] == 'R') { + r = i; + } else { + if (r != -1) { res = min(res, a[i] - a[r] >> 1); } + } + } + if (res == 1e9 + 7) + puts("-1"); + else + cout << res << endl; + return 0; +} +int main() { + int n, a[3], i, j, d, e = 0; + cin >> n; + for (i = 0; i < n; i++) { + d = 0; + for (j = 0; j < 3; j++) { + cin >> a[j]; + if (a[j] == 1) d++; + } + if (d >= 2) e++; + } + cout << e << endl; + return 0; +} +int main() { + stack s; + string f; + cin >> f; + for (int i = 0; i < f.length(); i++) { + if (s.empty()) { + s.push(f[i]); + } else { + if (f[i] == s.top()) + s.pop(); + else + s.push(f[i]); + } + } + string t = ""; + while (!s.empty()) { + t += s.top(); + s.pop(); + } + for (int i = t.length() - 1; i >= 0; i--) { cout << t[i]; } + cout << endl; + return 0; +} +const double pi = 3.1415926535; +const long long mod = 998244353; +const int maxn = 5e5 + 10; +int main() { + int n; + while (cin >> n) { + if (n % 10 <= 5) + cout << n - (n % 10) << endl; + else + cout << n + (10 - n % 10) << endl; + } +} +vector v; +int main() { + int n, x = 0, hitung = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int m; + cin >> m; + v.push_back(m); + if (m >= x) { x = m; } + } + for (int i = 0; i < n; i++) { hitung += (x - v[i]); } + cout << hitung << endl; +} +int main() { + int n, k, i, a[105]; + while (cin >> n >> k) { + int cnt = 0; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + if (a[i] <= k) + cnt++; + else + break; + } + for (i = n; i >= 0; i--) { + if (a[i] <= k) + cnt++; + else + break; + } + cout << min(cnt, n) << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int xx = pow(2, n); + int mod = m / xx; + int ans = mod * xx; + int reallyans = m - ans; + cout << reallyans << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + unsigned long long int l, r; + cin >> l >> r; + unsigned long long int temp = l; + unsigned long long int i = 0; + while ((temp | ((1LL << i))) <= r and i < 64) { + temp = (temp | ((1LL << i))); + ++i; + } + cout << temp << "\n"; + } + return 0; +} +int main() { + int h, w, u1, d1, u2, d2; + cin >> w >> h; + cin >> u1 >> d1; + cin >> u2 >> d2; + while (h > 0) { + w += h; + if (h == d1) + w = max(w - u1, 0); + else if (h == d2) + w = max(w - u2, 0); + --h; + } + cout << w << endl; + return 0; +} +int main() { + int n, a, b, ans; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + ans = 0; + while (a != 0 && b != 0) { + if (a < b) { swap(a, b); } + ans += a / b; + a %= b; + } + cout << ans << endl; + } + return 0; +} +int main() { + string a, c; + cin >> a >> c; + if (a == c) + cout << a << endl; + else + puts("1"); + return 0; +} +int ans = 0; +int main() { + int t; + cin >> t; + while (t--) { + int x1, x2, y1, y2; + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + while (cin >> s >> v1 >> v2 >> t1 >> t2) { + int sum1 = 2 * t1 + s * v1; + int sum2 = 2 * t2 + s * v2; + if (sum1 < sum2) + cout << "First" << endl; + else if (sum1 > sum2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int main() { + long long n, dead; + cin >> n; + dead = n / 2; + cout << 2 * n - dead << endl; + return 0; +} +int main() { + int N; + cin >> N; + vector A(N); + for (int i = 0; i < (int)(N); ++i) cin >> A[i]; + sort(A.begin(), A.end()); + if (A[0] == 1) { + cout << -1 << "\n"; + } else { + cout << 1 << "\n"; + } + return 0; +} +int main() { + int n, arr1[31], arr2[31], count = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr1[i] >> arr2[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr1[i] == arr2[j]) { count++; } + } + } + cout << count << endl; + return 0; +} +int main() { + string a, b, c; + cin >> a >> b; + reverse(a.begin(), a.end()); + while (a.size() < b.size()) a += "0"; + while (b.size() < a.size()) b += "0"; + vector ans; + int sisa = 0; + for (int i = 0; i < a.size(); i++) { + int x = a[i] - '0' + b[i] - '0' + sisa; + sisa = 0; + ans.push_back(x % 10); + sisa = x / 10; + } + while (sisa > 0) { + ans.push_back(sisa % 10); + sisa /= 10; + } + while (ans.size() > 1 && ans.back() == 0) ans.pop_back(); + for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i]; + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n & 1) << endl; +} +int main() { + string s; + bool h = 0, e = 0, l1 = 0, l2 = 0, o = 0, ans = 0; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (l2) { + if (s[i] == 'o') { + cout << "YES" << '\n'; + return 0; + } + } else if (l1) { + if (s[i] == 'l') { l2 = 1; } + } else if (e) { + if (s[i] == 'l') { l1 = 1; } + } else if (h) { + if (s[i] == 'e') { e = 1; } + } else if (s[i] == 'h') { + h = 1; + } + } + cout << "NO" << '\n'; + return 0; +} +int main() { + int n, i, j, k, l, w, x, y, z, cnt = 0, N; + cin >> w >> x >> y >> n; + for (i = 0; i < n; i++) { + cin >> N; + if (N > x && N < y) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int eight = 0, other = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '8') + eight++; + else + other++; + } + if (eight == 0) + cout << 0 << endl; + else { + int ans = other / 10; + if (ans > eight) { + cout << eight << endl; + return 0; + } + if (eight - ans == 0) + cout << ans << endl; + else { + cout << (((eight - ans) + (other % 10)) / 11) + ans << endl; + } + } +} +int main() { + int n, t, t2, k, d, time1 = 0, time2 = 0, x = 0, ca = 0, tmp; + cin >> n >> t >> k >> d; + time1 = (n / k + (n % k != 0)) * t; + while (1) { + x++; + if (x % t == 0) ca += k; + if (x > d) { + if ((x - d) % t == 0) ca += k; + } + if (ca >= n) break; + } + time2 = x; + if (time1 <= time2) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int A[100010]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < m; i++) cin >> A[i]; + sort(A, A + m); + int high = n - 1, low = 0; + int mini = A[high] - A[low]; + while (high < m) { + low++; + high++; + if (high < m) mini = min(mini, A[high] - A[low]); + } + cout << mini << '\n'; +} +int main() { + int n; + while (cin >> n && n) { + int a[200000]; + int dis = INT_MAX; + int cnt = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n - 1; i++) { dis = min(dis, abs(a[i + 1] - a[i])); } + for (int i = 0; i < n - 1; i++) { + if (abs(a[i + 1] - a[i]) == dis) cnt++; + } + cout << dis << " " << cnt << endl; + } + return 0; +} +int main() { + int t, L, v, l, r; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> L >> v >> l >> r; + cout << L / v - r / v + (l - 1) / v << endl; + } +} +int main() { + int strng[10] = {6, 7, 8, 9, 'T', 'J', 'Q', 'K', 'A'}; + char st1, st2, tp1, tp2, kt3, SPACE; + int str1, str2; + cin >> kt3 >> st1 >> tp1 >> st2 >> tp2; + if (st1 == '6' || st1 == '7' || st1 == '8' || st1 == '9') st1 -= '0'; + if (st2 == '6' || st2 == '7' || st2 == '8' || st2 == '9') st2 -= '0'; + for (int i = 0; i < 9; i++) { + if (st1 == strng[i]) str1 = i; + if (st2 == strng[i]) str2 = i; + } + if (tp1 == kt3 && tp2 != kt3) + cout << "YES" << endl; + else if (tp1 == tp2) { + if (str1 > str2) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + string x, y; + cin >> x >> y; + cout << x << ' ' << y << endl; + int n; + cin >> n; + while (n--) { + string a, b; + cin >> a >> b; + if (a == x) + x = b; + else + y = b; + cout << x << ' ' << y << endl; + } + return 0; +} +int main() { + int n, s, i, j; + string str; + cin >> n; + vector color(6); + color[0] = "purple"; + color[1] = "green"; + color[2] = "blue"; + color[3] = "orange"; + color[4] = "red"; + color[5] = "yellow"; + vector vvod(n); + for (i = 0; i < n; i++) cin >> vvod[i]; + cout << 6 - n << endl; + for (i = 0; i < 6; i++) { + bool t = true; + for (j = 0; j < n; j++) { + if (color[i] == vvod[j]) { t = false; } + } + if (t) { + if (color[i] == "purple") cout << "Power" << endl; + if (color[i] == "green") cout << "Time" << endl; + if (color[i] == "blue") cout << "Space" << endl; + if (color[i] == "orange") cout << "Soul" << endl; + if (color[i] == "red") cout << "Reality" << endl; + if (color[i] == "yellow") cout << "Mind" << endl; + } + } + getchar(); + getchar(); + return 0; +} +const int N = 123; +const int INF = 1e9 + 123; +const int MOD = 1e9 + 7; +const double EPS = 1e-9; +int n, m, x1, KIOT_camp, x2, y2, x3, y3, x4, y4; +char a[N][N]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) { cin >> a[i][j]; } + } + for (int i = 1; i <= n; ++i) { + bool exit = 0; + for (int j = 1; j <= m; ++j) { + if (a[i][j] == '*') { + KIOT_camp = i; + x1 = j; + exit = 1; + break; + } + } + if (exit) break; + } + for (int i = n; i >= 1; --i) { + bool exit = 0; + for (int j = m; j >= 1; --j) { + if (a[i][j] == '*') { + y2 = i; + x2 = j; + exit = 1; + break; + } + } + if (exit) break; + } + for (int i = m; i >= 1; --i) { + bool exit = 0; + for (int j = 1; j <= n; ++j) { + if (a[j][i] == '*') { + y3 = j; + x3 = i; + exit = 1; + break; + } + } + if (exit) break; + } + for (int i = 1; i <= m; ++i) { + bool exit = 0; + for (int j = n; j >= 1; --j) { + if (a[j][i] == '*') { + y4 = j; + x4 = i; + exit = 1; + break; + } + } + if (exit) break; + } + for (int i = min(KIOT_camp, y3); i <= max(y2, y4); ++i) { + for (int j = min(x1, x4); j <= max(x2, x3); ++j) { cout << a[i][j]; } + cout << '\n'; + } + return 0; +} +int main() { + int n, cnt = 0; + char s[110], ss[110]; + cin >> n >> s; + int len = strlen(s); + strcpy(ss, s); + s[0] += 1; + for (int i = 0; i < len; i++) { + if (s[i] == '2') { + s[i] = '0'; + if (i == len - 1) break; + s[i + 1] += 1; + } + } + for (int i = 0; i < len; i++) { + if (s[i] != ss[i]) ++cnt; + } + cout << cnt << endl; + return 0; +} +string s; +inline bool yy(char x) { + if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y') return 1; + return 0; +} +int main() { + register int i; + getline(cin, s); + for (i = s.length() - 1; !isalpha(s[i]); i--) + ; + s[i] = tolower(s[i]); + if (yy(s[i])) + puts("YES"); + else + puts("NO"); +} +long long spf[1000001]; +long long gcd(long long a, long long b); +long long palindrome(string s); +long long modexp(long long a, long long b, long long m); +void sieve(); +long long ceil(long long a, long long b); +vector getFactorization(long long x); +void getZarr(string str, long long Z[]); +vector prefix_function(string s); +int main() { + long long n, m; + cin >> n >> m; + long long a[n]; + for (long long i = 0; i < n; i++) cin >> a[i]; + long long maxk, mink = INT_MIN; + sort(a, a + n); + maxk = a[n - 1] + m; + long long sum = 0; + for (long long i = 0; i < n; i++) { + if (a[i] < a[n - 1]) { sum += (a[n - 1] - a[i]); } + } + if (m < sum) { + mink = a[n - 1]; + } else { + m = m - sum; + mink = a[n - 1] + (m / n + (m % n != 0)); + } + cout << mink << " " << maxk << endl; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + if (a == b) return a; + if (a > b) return gcd(a % b, b); + return gcd(a, b % a); +} +long long palindrome(string s) { + long long l = 0; + long long h = s.length() - 1; + while (h > l) { + if (s[l++] != s[h--]) { return 0; } + } + return 1; +} +long long modexp(long long a, long long b, long long m) { + if (b == 0) return 1; + long long temp = modexp(a, b / 2, m); + temp = (temp * temp) % m; + if (b & 1) return (temp * (a % m)) % m; + return temp; +} +void sieve() { + spf[1] = 1; + for (long long i = 2; i < 1000001; i++) spf[i] = i; + for (long long i = 4; i < 1000001; i += 2) spf[i] = 2; + for (long long i = 3; i * i < 1000001; i++) { + if (spf[i] == i) { + for (long long j = i * i; j < 1000001; j += i) + if (spf[j] == j) spf[j] = i; + } + } +} +vector getFactorization(long long x) { + vector ret; + while (x != 1) { + ret.push_back(spf[x]); + x = x / spf[x]; + } + return ret; +} +long long ceil(long long a, long long b) { + return a / b + (a % b != 0); +} +void getZarr(string str, long long Z[]) { + long long n = str.length(); + long long L, R, k; + L = R = 0; + for (long long i = 1; i < n; ++i) { + if (i > R) { + L = R = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } else { + k = i - L; + if (Z[k] < R - i + 1) + Z[i] = Z[k]; + else { + L = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } + } + } +} +int main() { + int n, m; + cin >> n >> m; + char c[n][m]; + int i, j; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> c[i][j]; + if (c[i][j] == '.' && i % 2 == 0) { + if (j % 2 == 0) + c[i][j] = 'B'; + else + c[i][j] = 'W'; + } else if (c[i][j] == '.' && i % 2 == 1) { + if (j % 2 == 0) + c[i][j] = 'W'; + else + c[i][j] = 'B'; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << c[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int t, s, q; + cin >> t >> s >> q; + int ans = 1; + while (s * q < t) { + ans++; + s *= q; + } + cout << ans << endl; + return 0; +} +int main() { + int n, i; + long long ar[100005], sum = 0; + cin >> n; + for (i = 0; i < n; i++) cin >> ar[i]; + sort(ar, ar + n); + for (i = 0; i < n; i++) { sum += ar[i]; } + if (sum % 2 != 0) { + for (i = 0; i < n; i++) { + sum -= ar[i]; + if (sum % 2 == 0 || sum == 0) + break; + else + sum += ar[i]; + } + } + cout << sum << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + cout << a[0]; + for (int i = 1; i < a.size(); i++) { + if (a[i] < b[0]) { + cout << a[i]; + } else + break; + } + cout << b[0] << endl; + return 0; +} +int arr[5][5]; +int main() { + int x = 0; + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + cin >> x; + if (x == 1) { cout << abs(i - 3) + abs(j - 3) << endl; } + } + } + return 0; +} +int main() { + map mp; + mp['6'] = 1; + mp['7'] = 2; + mp['8'] = 3; + mp['9'] = 4; + mp['T'] = 5; + mp['J'] = 6; + mp['Q'] = 7; + mp['K'] = 8; + mp['A'] = 9; + string str; + cin >> str; + string str1, str2; + cin >> str1 >> str2; + if (str[0] == str2[1] && str[0] == str1[1]) { + if (mp[str1[0]] > mp[str2[0]]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; + } + if (str[0] == str1[1]) { + cout << "YES" << endl; + return 0; + } + if (str[0] == str2[1]) { + cout << "NO" << endl; + return 0; + } + if (str1[1] == str2[1] && mp[str1[0]] > mp[str2[0]]) { + cout << "YES" << endl; + return 0; + } + return !(cout << "NO" << endl); +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 == 0) { + if (i % 4 == 0) { + cout << "#"; + for (int j = 1; j < m; j++) { cout << "."; } + cout << endl; + } else { + for (int j = 1; j < m; j++) { cout << "."; } + cout << "#"; + cout << endl; + } + } + if (i % 2 != 0) { + for (int j = 1; j <= m; j++) { cout << "#"; } + cout << endl; + } + } +} +int main() { + long long n, in; + cin >> n; + map m; + for (int i = 0; i < n; i++) { + char ope; + cin >> ope >> in; + long long bi = 0, tmp = in, p = 1; + while (tmp > 0) { + if ((tmp % 10) % 2 == 1) bi += p; + tmp /= 10; + p *= 10; + } + if (ope == '+') + m[bi]++; + else if (ope == '-') + m[bi]--; + else + cout << m[bi] << endl; + } + return 0; +} +int main() { + long long n, m, ans = 0, i = 0; + cin >> n >> m; + while (n >= 0) { + ans++; + if (i == m) { + i = 0; + n += 1; + } + i++; + n--; + } + cout << ans - 1 << endl; + return 0; +} +int main() { + float n; + cin >> n; + int tmp, sum = 0; + for (int i = 0; i < n; ++i) { + cin >> tmp; + sum += tmp; + } + cout << ceil(sum / n) << endl; +} +int main() { + int n, count; + cin >> n; + count = n / 2; + for (int j = 0; j <= n / 2; j++) { + for (int i = 0; i < count; i++) { cout << "*"; } + for (int i = 0; i < n - 2 * count; i++) { cout << "D"; } + for (int i = 0; i < count; i++) { cout << "*"; } + count--; + cout << "\n"; + } + count = 1; + for (int j = 0; j < n / 2; j++) { + for (int i = 0; i < count; i++) { cout << "*"; } + for (int i = 0; i < n - 2 * count; i++) { cout << "D"; } + for (int i = 0; i < count; i++) { cout << "*"; } + count++; + cout << "\n"; + } +} +int main() { + set s; + int n; + cin >> n; + for (int i = 1; i <= n; ++i) { + int x; + cin >> x; + if (x) s.insert(x); + } + cout << s.size() << endl; + return (0); +} +int main() { + long int n, x, v; + cin >> v; + n = v; + if (n > 2) { + n = 1; + } else if (n == 2) { + n = 2; + } + cout << n << endl; + return 0; +} +int n, he; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> he; + if (360.0 / (180 - he) - 360 / (180 - he) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (a == 0 && b == 0) + cout << "NO" << endl; + else if (abs(a - b) < 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long s, x, temp = 0, cnt = 0; + cin >> s >> x; + temp = s - x; + if (temp % 2 || temp < 0 || (temp / 2) & x) { + cout << "0\n"; + return 0; + } + temp = x; + while (temp) { + cnt += (temp % 2); + temp /= 2; + } + if (s == x) + cout << (1LL << cnt) - 2 << endl; + else + cout << (1LL << cnt) << endl; + return 0; +} +bool fun1(char s) { + if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') + return true; + else + return false; +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'n') continue; + if (!fun1(s[i]) && !fun1(s[i + 1])) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + a = 180 - a; + if (360 % a == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, s = 0, l = 0; + cin >> n >> m; + s = n / 2 * m; + if (n % 2 == 1) s += m / 2; + cout << s << endl; +} +int main() { + int n, b = 0; + cin >> n; + while (n > 0) { + b += n & 1; + n = n >> 1; + } + cout << b << endl; + return 0; +} +vector vector_in(int n) { + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + return v; +} +void vector_out(vector v) { + for (int i = 0; i < v.size(); i++) cout << v[i] << " "; + cout << endl; +} +int vector_sum(vector v) { + int sum; + for (int i = 0; i < v.size(); i++) sum += v[i]; + return sum; +} +int main() { + int n; + vector T(1001, 1); + vector rla; + cin >> n; + for (int i = 0; i < n - 1; i++) { + char c; + cin >> c; + rla.push_back(c); + } + for (int i = 0; i < n - 1; i++) { + if (rla[i] == 'R') { + T[i + 1] = max(T[i + 1], T[i] + 1); + } else if (rla[i] == '=') { + T[i + 1] = T[i]; + } + } + for (int i = n - 2; i >= 0; i--) { + if (rla[i] == 'L') { + T[i] = max(T[i], T[i + 1] + 1); + } else if (rla[i] == '=') { + T[i] = T[i + 1]; + } + } + for (int i = 0; i < n; i++) { cout << T[i] << " \n"[i == n - 1]; } + cout << flush; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (m - n < 2) + cout << -1 << endl; + else { + if (n % 2 == 0) + cout << n << " " << n + 1 << " " << n + 2 << endl; + else if (n % 2 != 0 && n + 3 <= m) + cout << n + 1 << " " << n + 2 << " " << n + 3 << endl; + else + cout << -1 << endl; + } +} +int main() { + int n; + cin >> n; + int a[100005]; + for (int i = 0; i < n - 1; i++) { + int c; + cin >> c; + a[c] = 1; + } + for (int i = 1; i <= n; i++) { + if (a[i] != 1) { + cout << i << endl; + return 0; + } + } +} +int main() { + string s, t; + getline(cin, s); + getline(cin, t); + int ans = 0; + for (int i = 0; i <= t.size(); i++) { + if (s[ans] == t[i]) ans++; + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int ans = min(n, m); + if (ans % 2 == 0) + cout << "Malvika" + << "\n"; + else + cout << "Akshat" + << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int ans = n > m ? m : n; + if (ans & 1) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; +} +int f(int a, int b) { + int t, x = a, y = b; + if (x < y) { + t = x; + x = y; + y = t; + } + while (x % y != 0) { + t = y; + y = x % y; + x = t; + } + return a * b / y; +} +int main() { + int x, y, a, b; + while (cin >> x >> y >> a >> b) { + int t = f(x, y); + int p = (a % t == 0) ? b / t - a / t + 1 : b / t - a / t; + cout << p << endl; + } + return 0; +} +int main() { + int a, b1, b2, t; + while (cin >> a) { + b1 = a / 10; + b2 = (a / 100) * 10 + a % 10; + t = max(max(b1, b2), a); + cout << t << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int p, q; + int counter = 0; + for (int i = 0; i < n; ++i) { + cin >> p >> q; + if (q - p >= 2) ++counter; + } + cout << counter << endl; +} +int main() { + int c = 0, len = 0; + string s; + cin >> s; + len = (s.length()) / 2; + for (int i = 1; i < s.length(); i += 2) { + s[i] = s[i + 1]; + s[i + 1] = 'a'; + c++; + } + sort(s.begin(), s.end()); + s.erase(s.length() - c); + for (int i = 1; i < s.length(); i += 2) { s.insert(i, "+"); } + cout << s << endl; + return 0; +} +int main() { + int a, b, c, i, j, k; + cin >> a >> b >> c; + for (i = 1; i < 10005; i++) { + for (j = 1; j < 10005; j++) { + for (k = 1; k < 10005; k++) { + if (i * j == a && i * k == b && j * k == c) { + cout << 4 * i + 4 * j + 4 * k << endl; + return 0; + } + if (i * k > b || j * k > c) break; + } + if (i * j > a || j > c) break; + } + if (i > a || i > b) break; + } + return 0; +} +int i, j; +int main() { + int a[5][5], numberOfMove = 0, p1 = 0, p2 = 0; + for (i = 0; i < 5; i++) + for (j = 0; j < 5; j++) cin >> a[i][j]; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + if (a[i][j] == 1) { + p1 = i + 1; + p2 = j + 1; + break; + } + } + } + if (p1 >= 3 && p2 >= 3) { + p1 = p1 - 3; + p2 = p2 - 3; + } else if (p1 < 3 && p2 < 3) { + p1 = 3 - p1; + p2 = 3 - p2; + } else if (p1 < 3 && p2 >= 3) { + p1 = 3 - p1; + p2 = p2 - 3; + } else if (p1 >= 3 && p2 < 3) { + p1 = p1 - 3; + p2 = 3 - p2; + } + numberOfMove = p1 + p2; + cout << numberOfMove << endl; + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int n; + cin >> n; + int a[2 * n]; + for (int i = 0; i < 2 * n; i += 1) cin >> a[i]; + sort(a, a + 2 * n); + int x = a[n]; + for (int i = 0; i < n; i += 1) { + if (x <= a[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + int arr[3] = {0}; + int index = 0; + for (int i = 0; i < n; i++) { + int number; + cin >> number; + arr[index] += number; + index++; + if (index == 3) index = 0; + } + if (arr[0] > arr[1] && arr[0] > arr[2]) + cout << "chest" << endl; + else if (arr[1] > arr[0] && arr[1] > arr[2]) + cout << "biceps" << endl; + else if (arr[2] > arr[0] && arr[2] > arr[1]) + cout << "back" << endl; + return 0; +} +const int INF = 1e9; +const long long MOD = 1e9 + 7; +double EPS = 1e-8; +int main() { + string s, t; + cin >> s >> t; + cout << s << " " << t << '\n'; + int n; + cin >> n; + for (int i = (0); i < (int)(n); i++) { + string x, y; + cin >> x >> y; + if (s == x) + s = y; + else + t = y; + cout << s << " " << t << '\n'; + } + return 0; +} +long long int power(long long int x, long long int y) { + long long int temp; + if (y == 0) return 1; + temp = power(x, y / 2); + if (y % 2 == 0) + return temp * temp; + else { + if (y > 0) + return x * temp * temp; + else + return (temp * temp) / x; + } +} +bool prime[10000000]; +void sieve() { + memset(prime, true, sizeof(prime)); + prime[0] = prime[1] = false; + for (long long int p = 2; p * p <= 10000000; p++) { + if (prime[p] == true) { + for (long long int i = p * 2; i <= 10000000; i += p) prime[i] = false; + } + } +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + long long int x; + cin >> x; + string a, b; + cin >> a >> b; + string s1, s2; + for (long long int i = 0; i < b.size(); i++) { s1 += a; } + for (long long int i = 0; i < a.size(); i++) { s2 += b; } + long long int n = a.size() * b.size(); + long long int c1 = 0, c2 = 0; + for (long long int i = 0; i < n; i++) { + if (s1[i % n] == 'R') { + if (s2[i % n] == 'P') { + c1++; + } else if (s2[i % n] == 'S') { + c2++; + } + } + if (s1[i % n] == 'P') { + if (s2[i % n] == 'R') { + c2++; + } else if (s2[i % n] == 'S') { + c1++; + } + } + if (s1[i % n] == 'S') { + if (s2[i % n] == 'P') { + c2++; + } else if (s2[i % n] == 'R') { + c1++; + } + } + } + c1 *= (x / n); + c2 *= (x / n); + for (long long int i = 0; i < x % n; i++) { + if (s1[i % n] == 'R') { + if (s2[i % n] == 'P') { + c1++; + } else if (s2[i % n] == 'S') { + c2++; + } + } + if (s1[i % n] == 'P') { + if (s2[i % n] == 'R') { + c2++; + } else if (s2[i % n] == 'S') { + c1++; + } + } + if (s1[i % n] == 'S') { + if (s2[i % n] == 'P') { + c2++; + } else if (s2[i % n] == 'R') { + c1++; + } + } + } + cout << c1 << " " << c2 << endl; + return 0; +} +int main() { + char ch[10]; + for (int i = 1; i <= 8; i++) { + for (int j = 1; j <= 8; j++) { + cin >> ch[j]; + if (j != 1 && ch[j] == ch[j - 1]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, i, a; + cin >> n; + string s; + for (i = 0; i < n; i++) { + cin >> s; + if (s.length() > 10) { + a = s.length(); + cout << s[0] << a - 2 << s[a - 1] << endl; + } else + cout << s << endl; + } + return 0; +} +int main() { + int n, k, locg, loct; + string s; + cin >> n >> k >> s; + for (int i = 0; i < s.size(); i++) + if (s[i] == 'G') + locg = i; + else if (s[i] == 'T') + loct = i; + if (abs(locg - loct) % k) + cout << "NO\n"; + else { + bool yes = 1; + for (int i = min(locg, loct); i <= max(locg, loct); i += k) + if (s[i] == '#') { + yes = 0; + break; + } + if (yes) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +const double pi = acos(-1); +int main() { + int a[3], k = 0; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + if (a[1] + a[0] > a[2] && a[2] - a[0] < a[1]) { + cout << k << endl; + return 0; + } + if (a[1] + a[0] <= a[2]) { + k = a[2] - a[1] - a[0] + 1; + cout << k << endl; + return 0; + } +} +int main() { + int a[10]; + int b[10]; + int c[10]; + int n, m, sum = 0; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + memset(c, 0, sizeof(c)); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + a[m]++; + c[m]++; + } + for (int i = 0; i < n; i++) { + cin >> m; + b[m]++; + c[m]++; + } + for (int i = 1; i <= 5; i++) { + if (c[i] % 2) { + cout << -1 << endl; + return 0; + } else { + sum += abs(c[i] / 2 - a[i]); + } + } + cout << sum / 2 << endl; + return 0; +} +int main() { + char words[1000][1001]; + int n; + cin >> n; + int count = 0; + int letters[1000] = {0}; + int letter[26] = {0}; + int m = 1; + for (int i = 0; i < 26; i++) { + letter[i] = m; + m *= 2; + } + for (int i = 0; i < n; i++) cin >> words[i]; + for (int i = 0; i < n; i++) { + int len = strlen(words[i]); + for (int j = 0; j < len; j++) letters[i] |= letter[words[i][j] - 'a']; + } + for (int i = 0; i < n; i++) { + if (letters[i] == 0) continue; + for (int j = i + 1; j < n; j++) { + if (letters[i] == letters[j]) { letters[j] = 0; } + } + count++; + } + cout << count << endl; + return 0; +} +const int maxn = 10000; +char a[100]; +int b[100]; +int main() { + int n, m, sum = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + int j = a[i] - 'a'; + b[j]++; + } + for (int i = 0; i < 26; i++) { + if (b[i] > m) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int mx = *max_element(a, a + n); + int mn = *min_element(a, a + n); + for (int i = 0; i < n; i++) { + if (a[i] > mn && a[i] < mx) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + long long y, x[3], t[3], k; + cin >> x[0] >> x[1] >> x[2] >> k; + x[0]--; + x[1]--; + x[2]--; + sort(x, x + 3); + y = k / 3; + t[0] = min(y, x[0]); + k -= min(y, x[0]); + y = k / 2; + t[1] = min(y, x[1]); + k -= min(y, x[1]); + t[2] = min(k, x[2]); + t[0]++; + t[1]++; + t[2]++; + cout << t[0] * t[1] * t[2] << endl; + return 0; +} +int main() { + int n; + int m; + int bt; + int bohlam; + list v; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> bt; + while (bt > 0) { + cin >> bohlam; + v.push_back(bohlam); + bt--; + } + } + v.sort(); + v.unique(); + if (v.size() == m) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +string str; +int B, u, l, b, a, s, r; +int main() { + cin >> str; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'B') B++; + if (str[i] == 'u') u++; + if (str[i] == 'l') l++; + if (str[i] == 'b') b++; + if (str[i] == 'a') a++; + if (str[i] == 's') s++; + if (str[i] == 'r') r++; + } + cout << min(B, min(u / 2, min(l, min(a / 2, min(s, min(b, r)))))) << endl; + return 0; +} +int main() { + int m, k; + cin >> m >> k; + vector distance(m), cap(m); + for (int i = 0; i < m; i++) cin >> distance[i]; + for (int i = 0; i < m; i++) cin >> cap[i]; + int maxm = 0; + int ans = 0; + int fuel = 0; + for (int i = 0; i < m; i++) { + maxm = max(maxm, cap[i]); + fuel += cap[i]; + while (fuel < distance[i]) { + ans += k; + fuel += maxm; + } + fuel -= distance[i]; + ans += distance[i]; + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + string cad; + int numero = 0; + while (n--) { + cin >> cad; + int con = 0; + for (int i = 0; i < cad.size(); i++) + if (cad[i] == '4' || cad[i] == '7') con++; + if (con <= k) numero++; + } + cout << numero << endl; +} +int main() { + int n; + int k = 0, x; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (i != 1) cout << x + k << " "; + k = x; + } + cout << x << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[4][2] = {0}; + cin >> a[0][0] >> a[0][1] >> a[1][0] >> a[1][1] >> a[2][0] >> a[2][1]; + int t = n, ad = a[0][0], b = a[1][0], c = a[2][0]; + if (t = t - ad - b - c) { + if (t <= a[0][1] - a[0][0]) { + ad += t; + t = 0; + } else { + t = t + ad - a[0][1]; + ad = a[0][1]; + if (t <= a[1][1] - a[1][0]) { + b += t; + t = 0; + } else { + t = t + b - a[1][1]; + b = a[1][1]; + if (t <= a[2][1] - a[2][0]) { + c += t; + t = 0; + } else { + c = a[2][1]; + } + } + } + } + cout << ad << " " << b << " " << c << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + bool ff = false, bf = false; + int ans = 0; + for (int i = 0, r = n - 1; (!bf || !ff) && i < n;) { + if (i > r) break; + if (!ff && v[i] <= k) { + ans++; + i++; + } else + ff = true; + if (i > r) break; + if (!bf && v[r] <= k) { + ans++; + r--; + } else + bf = true; + } + cout << ans << endl; + return 0; +} +const int maxn = 1e5 + 10; +long long arr[maxn]; +int n; +int main() { + cin >> n; + long long now = 2; + cout << 2 << endl; + for (long long i = 3; i < n + 2; i++) { + long long ans = (i * i * (i - 1) - i + 2); + cout << ans << endl; + } +} +int main() { + int a[100], c = 0, i, sum = 0, sum1 = 0, n; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + sort(a, a + n); + for (i = 0; 2 * sum1 <= sum; i++) { + sum1 += a[n - i - 1]; + c++; + } + cout << c << endl; + return 0; +} +string s[2525]; +int main() { + long long n, p, m = 0, l = 0; + cin >> n >> p; + for (int i = 1; i <= n; i++) cin >> s[i]; + for (int i = n; i >= 1; i--) { + m *= 2; + if (s[i] == "halfplus") m++; + l += m; + } + cout << l * p / 2 << endl; + return 0; +} +int main() { + int arr[5][5], counter = 0; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if (arr[i][j] == 1) { + if (i <= 2) counter += (2 - i); + if (j <= 2) counter += (2 - j); + if (i > 2) counter += (i - 2); + if (j > 2) counter += (j - 2); + break; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + unsigned int a, b, sum = 0; + cin >> a >> b; + for (int i = 1; i < a; ++i) { + int c; + cin >> c; + sum += c; + } + sum %= a; + sum = (a + b - sum) % a; + cout << sum + 1 << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int low = 0, high = 1e6; + while (low < high) { + int mid = (low + high) / 2; + int cur = mid * b; + int mk = 0; + for (int i = 1; i <= c; i++) { + cur += b; + if (cur < a) { + low = mid + 1; + mk = 1; + break; + } + cur -= a; + } + if (!mk) high = mid; + } + cout << low << '\n'; +} +int main() { + int n; + cin >> n; + map f; + string p; + int ans = 6; + while (n--) { + cin >> p; + if (!f[p]) ans--; + f[p] = 1; + } + cout << ans << endl; + if (!f["purple"]) cout << "Power" << endl; + if (!f["green"]) cout << "Time" << endl; + if (!f["blue"]) cout << "Space" << endl; + if (!f["orange"]) cout << "Soul" << endl; + if (!f["red"]) cout << "Reality" << endl; + if (!f["yellow"]) cout << "Mind" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int ans; + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + ans = k / a[i]; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a[31], b[31]; + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i != j && a[i] == b[j]) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + int cnt = 0; + for (int i = 1; i <= n / 2 + 1; i++) { + int mid = n / 2 + 1; + for (int j = 1; j <= n; j++) + if (mid - cnt <= j and j <= mid + cnt) + cout << 'D'; + else + cout << '*'; + cout << '\n'; + cnt++; + } + cnt--; + for (int i = 1; i <= n / 2; i++) { + cnt--; + int mid = n / 2 + 1; + for (int j = 1; j <= n; j++) + if (mid - cnt <= j and j <= mid + cnt) + cout << 'D'; + else + cout << '*'; + cout << '\n'; + } + return 0; +} +int n, m; +char c[101][101]; +bool vis[101][101]; +char w[2] = {'B', 'W'}; +void dfs(int x, int y, int i) { + if (x < 0 || y < 0 || x >= n || y >= m || vis[x][y]) return; + vis[x][y] = 1; + if (c[x][y] == '-') { + if (i == 0) + i = 1; + else + i = 0; + } + if (c[x][y] == '.') { + if (i == 0) { + c[x][y] = w[i]; + i = 1; + } else { + c[x][y] = w[i]; + i = 0; + } + } + dfs(x + 1, y, i++); + dfs(x + 1, y, i--); + dfs(x - 1, y, i++); + dfs(x - 1, y, i--); + dfs(x, y + 1, i++); + dfs(x, y + 1, i--); + dfs(x, y - 1, i++); + dfs(x, y - 1, i--); +} +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> c[i][j]; + dfs(0, 0, 0); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cout << c[i][j]; + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + while (n > 0) { + if (n % 1000 == 144) + n /= 1000; + else if (n % 100 == 14) + n /= 100; + else if (n % 10 == 1) + n /= 10; + else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int n, w, s = 3; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> w; + if (w == s) { + cout << "NO" << endl; + return 0; + } + s = 6 - s - w; + } + cout << "YES" << endl; + return 0; +} +const int MAXN = 1e5 + 100; +const int INF = 0x3FFFFFFF; +const long long MOD = 1e9 + 7; +int s[MAXN], f[MAXN], t[MAXN]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> s[i] >> f[i] >> t[i]; + if (s[i] == f[i]) + cout << t[i] << endl; + else if (s[i] < f[i]) { + int temp = t[i] % (m - 1); + if (((t[i] + (m - 1)) / (m - 1)) % 2) { + if (!temp) + temp = 1; + else + temp++; + if (temp <= s[i]) + cout << t[i] + f[i] - temp << endl; + else + cout << t[i] + m - temp + m - 1 + f[i] - 1 << endl; + } else { + if (!temp) + temp = m; + else + temp = m - temp; + if (temp >= s[i]) + cout << t[i] + temp - 1 + f[i] - 1 << endl; + else + cout << t[i] + temp - 1 + f[i] - 1 << endl; + } + } else { + int temp = t[i] % (m - 1); + if (((t[i] + (m - 1)) / (m - 1)) % 2) { + if (!temp) + temp = 1; + else + temp++; + if (temp <= s[i]) + cout << t[i] + m - temp + m - f[i] << endl; + else + cout << t[i] + m - temp + m - f[i] << endl; + } else { + if (!temp) + temp = m; + else + temp = m - temp; + if (temp >= s[i]) + cout << t[i] + temp - f[i] << endl; + else + cout << t[i] + temp - 1 + m - 1 + m - f[i] << endl; + } + } + } + return 0; +} +int main() { + long long int n, k, l; + cin >> n >> k >> l; + if (2 * l <= min(n, k)) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (n + 4) / 5 << "\n"; +} +const int N = 1100; +int main() { + cout << setprecision(12) << fixed; + int n; + string s; + cin >> n >> s; + int ans = 0, cnt = 0; + for (int i = 0; i < n; ++i) { + if (s[i] == '0') { + ans += cnt; + ans *= 10; + cnt = 0; + } else + ++cnt; + } + if (cnt > 0) ans += cnt; + cout << ans << endl; + return 0; +} +int main() { + long long n, max = 0, d = 0; + cin >> n; + long long a[100000], b[100000]; + for (long long i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + d = d - a[i]; + d = d + b[i]; + if (d > max) max = d; + } + cout << max << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + string s; + cin >> s; + if (k > n / 2) { + for (int i = 1; i <= n - k; i++) { cout << "RIGHT\n"; } + long long int j = s.size() - 1; + for (int i = n * 2 - 1; i > 0; i--) { + if (i % 2 != 0) + cout << "PRINT " << s[j] << "\n", j--; + else + cout << "LEFT\n"; + } + return 0; + } else { + for (int i = 1; i < k; i++) { cout << "LEFT\n"; } + long long int j = 0; + for (int i = 0; i < n * 2 - 1; i++) { + if (i % 2 == 0) + cout << "PRINT " << s[j] << "\n", j++; + else + cout << "RIGHT\n"; + } + return 0; + } +} +const int INF = 0x3f3f3f3f; +long long mod = 10000000000LL; +long long cheng(long long a, long long b, long long c) { + long long ret = 0; + while (b) { + if (b & 1) { + ret += a; + if (ret >= c) ret -= c; + } + a += a; + if (a >= c) a -= c; + b >>= 1; + } + return ret; +} +int main() { + long long n; + cin >> n; + long long ans = cheng(n, n, mod); + if (ans % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 1; j <= m; j++) cout << "#"; + } else if (i % 4 == 0) { + cout << "#"; + for (int j = 1; j < m; j++) cout << "."; + } else { + for (int j = 1; j < m; j++) { cout << "."; } + cout << "#"; + } + cout << endl; + } +} +const int N = 1e6 + 5; +int n, a, c = 2, ans; +vector v; +int main() { + cin >> n; + while (n--) cin >> a, v.push_back(a); + sort(v.begin(), v.end()); + if (v.size() == 2) { + cout << v.back() << " " << v[0] << endl; + return 0; + } + cout << v.back() << " "; + for (int i = 1; i < v.size() - 1; i++) cout << v[i] << " "; + cout << v[0] << endl; +} +string S, T; +long long N, M, A[10], sum, x, y, K; +char C; +int main() { + cin >> N >> M >> S; + sort(S.begin(), S.end()); + for (int i = 0; i < S.length() && M > 0; i++) { + if (i == 0) { + C = S[i]; + M--; + sum += C - 'a' + 1; + } else { + if (S[i] - C >= 2) { + C = S[i]; + M--; + sum += C - 'a' + 1; + } + } + } + if (M > 0) sum = -1; + cout << sum << '\n'; +} +int main() { + string str; + cin >> str; + int len = str.length(); + for (int i = 0; i < len; i++) { + if (str[i] == '.') { + if (str[i - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + } else { + if (str[i + 1] < '5') { + for (int j = 0; j < i; j++) { cout << str[j]; } + } else { + for (int j = 0; j < i - 1; j++) { cout << str[j]; } + cout << (char)(str[i - 1] + 1); + } + cout << endl; + } + } + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } +} +int main() { + long double n = 0; + long double s = 0; + long double b = 0; + long double d = 0; + long double e = 0; + int output = 0; + cin >> n >> b >> d; + for (int i = 0; i < n; i++) { + cin >> s; + if (s > b) { + continue; + } else { + e += s; + if (e > d) { + ++output; + e = 0; + } + } + } + cout << output << endl; +} +int main() { + int m, a, b, l = 0, r = 0; + cin >> m; + for (int i = 0; i < m; ++i) { + cin >> a >> b; + if (a > 0) + r++; + else + l++; + } + if (l == 0 || l == 1) { + cout << "Yes\n"; + return 0; + } + if (r == 1 || r == 0) { + cout << "Yes\n"; + return 0; + } + cout << "No\n"; + return 0; +} +long long a, n, i, ans, z[100010] = {0}, f[100010] = {0}; +int main() { + cin >> n; + for (i = 0; i < n; i++) { + cin >> a; + if (a > 0) z[a] = 1; + if (a < 0) f[-a] = 1; + } + for (i = 0; i < 100001; i++) { ans = ans + z[i] + f[i]; } + cout << ans << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int a[110]; + int hh, mm; + int tt = 0; + for (int i = 0; i < n; i++) cin >> hh >> mm, a[i] = hh * 60 + mm; + int flag = 1; + if (s + 1 <= a[0] && flag) tt = 0, flag = 0; + for (int i = 1; i < n; i++) { + if (s + 1 <= (a[i] - a[i - 1] - s - 1) && flag) tt = a[i - 1] + s + 1, flag = 0; + } + if (flag) tt = a[n - 1] + s + 1; + int h = tt / 60; + int m = tt - tt / 60 * 60; + cout << h << " " << m << endl; + return 0; +} +int main() { + int a; + cin >> a; + if (a - 10 <= 0 || a - 10 > 11) { + cout << 0 << endl; + } else if ((a - 10 >= 1 && a - 10 <= 9) || a - 10 == 11) { + cout << 4 << endl; + } else + cout << 15 << endl; +} +int main() { + int x, y, z, w; + int a, b; + cin >> x >> y; + cin >> z >> w; + a = abs(x - z); + b = abs(y - w); + cout << max(a, b) << endl; +} +int main() { + int ch, ad; + cin >> ad >> ch; + if (ad == 0 && ch > 0) + cout << "Impossible" << endl; + else + cout << ad + ch - min(ad, ch) << " " << ad + max(ch - 1, 0) << endl; + return 0; +} +int main() { + long long a[3], k; + long long m[3] = {1, 1, 1}; + cin >> a[0] >> a[1] >> a[2] >> k; + sort(a, a + 3); + for (int i = 0; a[i] > 1 && k > 0; i = (i + 1) % 3) { + a[i]--; + k--; + m[i]++; + } + for (int i = 1; a[i] > 1 && k > 0; i = 2 - (i + 1) % 2) { + a[i]--; + k--; + m[i]++; + } + m[2] += min(a[2] - 1, k); + long long ans = m[0] * m[1] * m[2]; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int nxt = 1; + vector ans; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x != nxt) { ans.push_back(nxt - 1); } + nxt = x + 1; + } + ans.push_back(nxt - 1); + cout << (int)ans.size() << endl; + for (int i = 0; i < (int)ans.size(); i++) { + if (i > 0) cout << " "; + cout << ans[i]; + } + cout << endl; + return 0; +} +map m; +int main() { + string a; + cin >> a; + int len = a.size(); + for (int i = 0; i < len; i++) m[a[i]]++; + int ans = 100000; + ans = min(ans, m['B']); + ans = min(ans, m['u'] / 2); + ans = min(ans, m['l']); + ans = min(ans, m['b']); + ans = min(ans, m['a'] / 2); + ans = min(ans, m['s']); + ans = min(ans, m['r']); + cout << ans << endl; + return 0; +} +int main() { + string s; + int n; + cin >> s >> n; + int trig = 0; + int c = 0; + string *a = new string[n]; + int k = 0; + int j = 0; + string s2; + int z = s.length(); + for (int i = 0; i < n; i++) { + cin >> s2; + a[i] = s2; + } + for (int i = 0; i < s.length(); i++) { + if (s[i] != a[j][k]) { + trig = 1; + c++; + } else { + k++; + } + if (z == k) { + trig = 3; + break; + } + if (trig == 1) { + j++; + i = -1; + k = 0; + trig = 0; + } + if (c == n) { + trig = 5; + break; + } + } + if (trig == 5) { + cout << s << endl; + return 0; + } + sort(a, a + n); + string t = ""; + if (trig == 3) { + for (int i = 0; i < n; i++) { + t = a[i]; + for (int ind = 0; ind < s.length(); ind++) { + if (s[ind] != t[ind]) { + a[i] = '0'; + break; + } + } + t = ""; + } + } + for (int i = 0; i < n; i++) { + if (a[i] != "0") { + cout << a[i] << endl; + return 0; + } + } + cout << s << endl; + return 0; +} +long long n, a, b, ans; +int main() { + cin >> n; + while (n--) { + ans = 0; + cin >> a >> b; + if (b > a) swap(a, b); + ans += a / b; + a -= (ans * b); + while (a > 0 && b > 0) { + if (a == b) { + ans++; + a = 0; + } else if (a > b) { + ans += a / b; + a -= (a / b * b); + } else { + ans += b / a; + b -= (b / a * a); + } + } + cout << ans << '\n'; + } + return 0; +} +int main() { + long t; + cin >> t; + while (t--) { + long x, v, l, r; + cin >> x >> v >> l >> r; + long ans = x / v; + long temp = r / v - (l - 1) / v; + ans -= temp; + cout << ans << "\n"; + } +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +bool isPrime(int a) { + for (int i = 2; i <= a / 2; i++) + if (a % i == 0) return false; + return true; +} +bool nextPrime(int a, int b) { + if (!isPrime(b)) return false; + for (int i = a + 1; i < b; i++) + if (isPrime(i)) return false; + return true; +} +int main() { + int n, m; + cin >> n >> m; + if (isPrime(m) && nextPrime(n, m)) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int maxn = 3e5 + 5; +int a[50] = {}; +int main() { + string s; + int k; + cin >> s >> k; + for (int i = 0; i < s.length(); i++) a[s[i] - 'a']++; + int sum = 0, cnt = 0; + for (int i = 0; i < 30; i++) { + if (a[i] > 0) cnt++; + sum += a[i]; + } + if (sum < k) return puts("impossible"), 0; + if (cnt >= k) return puts("0"), 0; + cout << k - cnt << endl; +} +int main() { + int n, k; + cin >> n >> k; + int *arr = new int[n]; + int a = 0; + for (int i = 0; i < n; i++) { arr[i] = 0; } + for (int i = 0; i < k; i++) { + cin >> a; + arr[a - 1]++; + } + int min = arr[0]; + for (int i = 0; i < n; i++) { + if (arr[i] < min) { min = arr[i]; } + } + cout << min << endl; + return 0; +} +int a[101]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int y = k + a[n - 1]; + int sum = 0; + for (int i = 0; i < n - 1; i++) { sum += a[n - 1] - a[i]; } + if (sum >= k) { + cout << a[n - 1] << ' ' << y << '\n'; + } else { + k -= sum; + int x = k / n; + if (k % n != 0) x += 1; + cout << a[n - 1] + x << ' ' << y << '\n'; + } +} +int main() { + char c[105]; + int ans = 0; + int i, j; + cin >> c; + for (i = 0; c[i]; i++) + for (j = i + 1; c[j]; j++) { + int total = 0; + while (c[i + total] && c[j + total] && c[i + total] == c[j + total]) total++; + if (ans < total) ans = total; + } + cout << ans << endl; + return 0; +} +const int maxn = 1e5 + 5; +int a[maxn], b[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int j = 1; j <= n; j++) cin >> b[j]; + if (a[1] == 0) { + cout << "NO" << endl; + return 0; + } + if (a[m] == 1) { + cout << "YES" << endl; + return 0; + } + for (int i = m; i <= n; i++) + if (a[i] == 1 && b[i] == 1 && b[m] == 1) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int j = n - 1; + long long lim = n * n; + long long t; + long long prevj = n; + long long sum = 0; + if (n == 0) { + cout << 1 << "\n"; + return 0; + } + for (long long int i = 1; i < n + 1; ++i) { + t = i * i; + while (j > 0 && j * j > (lim - t)) j--; + sum += 1; + if (prevj != j) sum += (prevj - j - 1); + prevj = j; + } + cout << 4 * sum << "\n"; +} +int main() { + long long int n, i; + int j; + int satuan; + bool yes; + yes = false; + cin >> n; + i = n; + j = 0; + while (i != 0) { + if ((i % 10 == 4) || (i % 10 == 7)) j++; + i /= 10; + } + if (j != 0) { + satuan = j % 10; + while ((j != 0) && ((satuan == 4) || (satuan == 7))) { + j = j / 10; + satuan = j % 10; + } + if (j == 0) { yes = true; } + if (yes) { + cout << "YES"; + } else { + cout << "NO"; + } + } else { + cout << "NO"; + } + cout << endl; + return 0; +} +int main() { + map m; + m['f'] = 1; + m['a'] = 2; + m['c'] = 3; + m['e'] = 7; + m['x'] = 0; + int count = 0, sum; + char a[60][60]; + int p, q; + cin >> p >> q; + for (int i = 0; i < p; i++) { + for (int j = 0; j < q; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < p; i++) { + for (int j = 0; j < q; j++) { + if (a[i][j] == 'f') { + if (m[a[i][j]] + m[a[i - 1][j]] + m[a[i][j - 1]] + m[a[i - 1][j - 1]] == 13) count++; + if (m[a[i][j]] + m[a[i + 1][j]] + m[a[i][j - 1]] + m[a[i + 1][j - 1]] == 13) count++; + if (m[a[i][j]] + m[a[i + 1][j]] + m[a[i][j + 1]] + m[a[i + 1][j + 1]] == 13) count++; + if (m[a[i][j]] + m[a[i - 1][j]] + m[a[i][j + 1]] + m[a[i - 1][j + 1]] == 13) count++; + } + } + } + cout << count << endl; + return 0; +} +int main() { + string s; + char index; + int count = 1, ans = 0; + cin >> s; + index = s[0]; + for (int i = 1; i < s.length(); i++) { + if (s[i] != index) { + if (count % 2 == 0) { ans++; } + count = 1; + index = s[i]; + } else { + count++; + } + } + if (count % 2 == 0) { ans++; } + cout << ans << endl; + return 0; +} +int main() { + long long n, epi; + long long count = 0; + bool flag = false; + cin >> n; + vector number_list; + for (long long i = 1; i < n; i++) { + cin >> epi; + number_list.push_back(epi); + } + sort(number_list.begin(), number_list.end()); + for (long long i = 0; i < number_list.size(); i++) { + count++; + if (number_list[i] != count) { + flag = true; + cout << count << endl; + break; + } + } + if (flag == false) cout << n << endl; + return 0; +} +int main() { + int n, k, a, seq = 0, count = 1; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == seq) { + count += 1; + } else { + count = 1; + } + seq = a; + } + if (count + k > n) + cout << n - count << endl; + else + cout << "-1\n"; + return 0; +} +int n, m; +int main() { + int x = 1; + cin >> n >> m; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) + for (int j = 0; j < m; j++) cout << '#'; + else if (x % 2 == 0) { + cout << '#'; + for (int j = 1; j < m; j++) cout << '.'; + x++; + } else if (x % 2 != 0) { + for (int j = 0; j < m - 1; j++) cout << '.'; + cout << '#'; + x++; + } + cout << endl; + } + return 0; +} +int main() { + string n; + cin >> n; + int min = 0, max = 0; + for (long long i = 0; i < n.size(); i++) { + if (n[i] >= 'a' && n[i] <= 'z') { + min++; + } else { + max++; + } + } + if (min >= max) { + for (long long i = 0; i < n.size(); i++) { n[i] = tolower(n[i]); } + } else { + for (long long i = 0; i < n.size(); i++) { n[i] = toupper(n[i]); } + } + cout << n << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + if (l > k * y || r < k * x) { + cout << "NO" << endl; + return 0; + } + for (long long i = l; i <= r; i++) { + for (long long j = x; j <= y; j++) { + if (i > k * y || i < k * x) + break; + else if (i == k * j) { + cout << "YES" << endl; + return 0; + } + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, t; + cin >> t; + n = t; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - (n + 1) / 2 + 1) + abs(j - (n + 1) / 2 + 1) <= (n + 1) / 2 - 1) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int left = 0; + int right = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + int y; + cin >> y; + if (x < 0) + left++; + else + right++; + } + if (left <= 1) + cout << "Yes" << endl; + else { + if (right <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int l, a; + l = s.size(); + a = 26 * (l + 1) - l; + cout << a << endl; + return 0; +} +int main() { + int t; + cin >> t; + string ans[t]; + for (int i = 0; i < t; i++) { + int temp; + cin >> temp; + int angle = 180 - temp; + if (360 % angle == 0) + ans[i] = "YES"; + else + ans[i] = "NO"; + } + for (int i = 0; i < t; i++) { cout << ans[i] << endl; } +} +int main() { + string a, b; + cin >> a >> b; + vector v1, v2; + int ans = 0, cnt = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[i]) { + if (a[i] == '4') + v1.push_back(i); + else + v2.push_back(i); + cnt++; + } + } + ans = min(v1.size(), v2.size()); + ans += (cnt - (ans * 2)); + cout << ans << endl; + return 0; +} +const int N = 1e5 + 5; +int n, res = 1, Max = 1; +pair a[N]; +void Input() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; + sort(a + 1, a + n + 1); +} +void Solve() { + int curr = 1; + for (int i = 2; i <= n; i++) { + if (a[i].first == a[i - 1].first && a[i].second == a[i - 1].second) + curr++, res = max(res, curr); + else + curr = 1; + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +const long long mod = 1e9 + 7; +const long long maxn = 1e6; +long long n, dp[2][maxn]; +int main() { + cin >> n; + dp[0][0] = 1; + for (long long i = 1; i < n; i++) { + if (i & 1) { + dp[0][i] = dp[0][i - 1]; + dp[1][i] = (dp[1][i - 1] % mod + dp[0][i - 1] % mod + 1) % mod; + } else { + dp[1][i] = dp[1][i - 1]; + dp[0][i] = (dp[0][i - 1] % mod + dp[1][i - 1] % mod + 1) % mod; + } + } + cout << (dp[0][n - 1] + dp[1][n - 1]) % mod << endl; + return 0; +} +int main() { + long long a, b, c, map[100005], i, j, k, n; + while (cin >> a >> b >> c) { + long long sum = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> map[i]; } + for (i = 0; i < n; i++) { + if (map[i] > b && map[i] < c) sum++; + } + cout << sum << endl; + } + return 0; +} +int main() { + char bal[110]; + char chal[110]; + cin >> bal >> chal; + int l = strlen(bal); + char ar[l]; + for (int i = 0; i < l; i++) { + if (bal[i] == chal[i]) + ar[i] = '0'; + else + ar[i] = '1'; + } + ar[l] = '\0'; + cout << ar << endl; +} +int main() { + int arr[3][3]; + int arr1[3][3]; + int p; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> arr[i][j]; } + } + p = arr[0][0] + arr[0][1] + arr[1][0]; + if (p % 2 != 0) + arr1[0][0] = 0; + else + arr1[0][0] = 1; + p = arr[0][1] + arr[0][0] + arr[1][1] + arr[0][2]; + if (p % 2 != 0) + arr1[0][1] = 0; + else + arr1[0][1] = 1; + p = arr[0][1] + arr[0][2] + arr[1][2]; + if (p % 2 != 0) + arr1[0][2] = 0; + else + arr1[0][2] = 1; + p = arr[1][0] + arr[1][1] + arr[2][0] + arr[0][0]; + if (p % 2 != 0) + arr1[1][0] = 0; + else + arr1[1][0] = 1; + p = arr[1][1] + arr[1][0] + arr[1][2] + arr[0][1] + arr[2][1]; + if (p % 2 != 0) + arr1[1][1] = 0; + else + arr1[1][1] = 1; + p = arr[1][2] + arr[0][2] + arr[2][2] + arr[1][1]; + if (p % 2 != 0) + arr1[1][2] = 0; + else + arr1[1][2] = 1; + p = arr[2][0] + arr[1][0] + arr[2][1]; + if (p % 2 != 0) + arr1[2][0] = 0; + else + arr1[2][0] = 1; + p = arr[2][1] + arr[1][1] + arr[2][0] + arr[2][2]; + if (p % 2 != 0) + arr1[2][1] = 0; + else + arr1[2][1] = 1; + p = arr[2][2] + arr[2][1] + arr[1][2]; + if (p % 2 != 0) + arr1[2][2] = 0; + else + arr1[2][2] = 1; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << arr1[i][j]; + cout << endl; + } + return 0; +} +int main() { + int k; + cin >> k; + string str; + cin >> str; + int n = str.length(); + map characters; + map::iterator itr; + for (int i = 0; i < n; i++) { + if (characters.find(str[i]) != characters.end()) { + characters[str[i]] += 1; + } else { + characters[str[i]] = 1; + } + } + for (itr = characters.begin(); itr != characters.end(); itr++) { + if (itr->second < k) { + cout << -1 << endl; + exit(0); + } + } + string new_str = ""; + for (itr = characters.begin(); itr != characters.end(); itr++) { + int repeat = itr->second / k; + for (int i = 0; i < repeat; i++) { new_str = new_str + itr->first; } + } + if (new_str.length() * k < n) { + cout << -1 << endl; + exit(0); + } + for (int i = 0; i < k; i++) { cout << new_str; } + cout << endl; + return 0; +} +int GCD(int a, int b); +int main() { + int x, y; + int a, b; + cin >> x >> y >> a >> b; + x = x * y / GCD(x, y); + cout << b / x - (a - 1) / x << endl; +} +int GCD(int a, int b) { + int n = a % b; + while (n != 0) { + a = b; + b = n; + n = a % b; + } + return b; +} +int n, m, i, j, k, l; +int main() { + cin >> n >> m; + int a[n + 5], b[m + 6]; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < m; i++) cin >> b[i]; + int mx = -99999999; + int mn = 999999999; + for (i = 0; i < n; i++) { + mx = max(mx, a[i]); + mn = min(mn, a[i]); + } + int ans = max(mx, 2 * mn); + int mmi = 9999999; + for (i = 0; i < m; i++) { mmi = min(mmi, b[i]); } + if (mmi > ans) + cout << ans << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + long long int s, a, b, cnt, total, get_free, get, c, t; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + total = s / c; + get_free = total / a; + get = get_free * b; + cnt = total + get; + cout << cnt << endl; + } + return 0; +} +inline int Getint() { + register int s = 0; + register char c; + do + c = getchar(); + while (c < 48 || c > 57); + do + s = s * 10 + c - 48, c = getchar(); + while (c > 47 && c < 58); + return s; +} +inline int Hash() { + register int v = 0; + register char c; + do + c = getchar(); + while (c < 'A' || c > 'Z'); + do + v = v * 26 + (c - 'A'), c = getchar(); + while ('A' <= c && c <= 'Z'); + return v; +} +int val[17576]; +int main() { + register int n = Getint(), Home = Hash(); + for (; n; --n) ++val[Hash()], --val[Hash()]; + for (register int i = 0; i < 17576; ++i) + if (val[i]) return (puts("contest"), 0); + return (puts("home"), 0); +} +int main() { + long long n; + cin >> n; + cout << (int)log2(n) + 1 << endl; + return 0; +} +bool c8(long long n) { + if (n < 0) { n = -n; } + while (n) { + if (n % 10 == 8) { return 1; } + n = n / 10; + } + return 0; +} +int main() { + long long n, t = 1; + cin >> n; + while (c8(n + t) == 0) { t++; } + cout << t << endl; +} +int main() { + int k, j = 0; + string s; + cin >> k >> s; + map m; + vector v; + for (int i = 1; i <= k && j < s.length(); i++) { + string x = ""; + x += s[j]; + m[s[j]]++; + j++; + while (m[s[j]]) { + x += s[j]; + j++; + } + if (x != " ") v.push_back(x); + } + string x = ""; + for (int u = j; u < s.length(); u++) { x += s[u]; } + if (v.size() < k) + cout << "NO" << endl; + else { + cout << "YES" << endl; + int i = 0; + for (i = 0; i < v.size() - 1; i++) cout << v[i] << endl; + cout << v[i] + x << endl; + } +} +char a[(100 + 10)][(100 + 10)]; +int h[(100 + 10)] = {0}, l[(100 + 10)] = {0}; +long long work(int x) { + long long n = x; + if (x < 2) return 0; + return n * (n - 1) / 2; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i] + 1; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == 'C') h[i]++, l[j]++; + } + } + long long ans = 0; + for (int i = 1; i <= n; i++) { + ans += work(h[i]); + ans += work(l[i]); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + int row[100] = {}, col[100] = {}; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + char c; + cin >> c; + if (c == 'C') { + row[i]++; + col[j]++; + } + } + int ans = 0; + for (int i = 0; i < n; i++) ans += (row[i] * (row[i] - 1) + col[i] * (col[i] - 1)) / 2; + cout << ans << endl; +} +int main() { + long long int n, t, i, k = 1; + cin >> n >> t; + long long int *p = new long long int[n]; + for (i = 1; i < n; i++) cin >> p[i]; + while (k < t) k += p[k]; + if (k == t) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, ans; + cin >> n; + int arr1[n], arr2[n]; + int cnt[6]; + memset(cnt, 0, sizeof cnt); + for (int i = 0; i < n; i++) { + cin >> arr1[i]; + cnt[arr1[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> arr2[i]; + cnt[arr2[i]]--; + } + int sum = 0; + for (int i = 1; i <= 5; i++) { + if (cnt[i] > 0) { sum += cnt[i]; } + if (cnt[i] % 2 != 0) { + ans = -1; + cout << ans << endl; + return 0; + } + } + cout << sum / 2 << endl; + return 0; +} +int n; +long long p, q, b; +long long NWD(long long x, long long y) { + if (y == 0) + return x; + else + return NWD(y, x % y); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p >> q >> b; + long long blep = NWD(p, q); + q /= blep; + blep = NWD(q, b); + while (blep > 1) { + while (q % blep == 0) q /= blep; + blep = NWD(q, b); + } + if (q > 1) + cout << "Infinite" << endl; + else + cout << "Finite" << endl; + } + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (x >= m || y >= m) { + cout << 0 << "\n"; + } else if (x <= 0 && y <= 0) { + cout << -1 << "\n"; + } else { + if (x > y) swap(x, y); + long long ans = 0; + if (x < 0) { + long long diff = y - x; + ans += (diff) / y; + x = (x + (diff / y) * y); + } + while (max(x, y) < m) { + ans++; + if (x > y) swap(x, y); + x = (x + y); + } + cout << ans << "\n"; + } + return 0; +} +int a, b, r; +int main() { + cin >> a >> b >> r; + if (a < 2 * r || b < 2 * r) + cout << "Second\n"; + else + cout << "First\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int f = 0, b = n - 1; + for (; f < n && v[f] <= k; f++) + ; + for (; b >= 0 && v[b] <= k; b--) + ; + if (f == n) + cout << n << endl; + else + cout << f + n - 1 - b << endl; + return 0; +} +long long x, y, p, q; +int main() { + int T; + cin >> T; + while (T--) { + cin >> x >> y >> p >> q; + long long l = 1, r = 1000000000; + long long ans = -1; + while (l <= r) { + long long mid = (l + r) / 2; + long long pp = p * mid, qq = q * mid; + if (pp < x or qq < y) { + l = mid + 1; + } else if (pp - x > qq - y) { + l = mid + 1; + } else { + r = mid - 1; + ans = mid * q - y; + } + } + cout << ans << "\n"; + } + return 0; +} +int main() { + int n, m, c = 0; + cin >> n >> m; + int arr[1000][1000]; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < m; j++) { arr[i][j] = s[j]; } + } + set s; + for (int i = 0; i < m; i++) { + int max = 0; + for (int j = 0; j < n; j++) { + if (arr[j][i] > max) { max = arr[j][i]; } + } + for (int j = 0; j < n; j++) { + if (arr[j][i] == max) { + if (!s.count(j)) { + c++; + s.insert(j); + } + } + } + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + int curr = 0; + int req = 0; + for (int i = 0; i < n; i++) { + curr -= a[i]; + curr += b[i]; + if (curr > req) { req = curr; } + } + cout << req << endl; + return 0; +} +int main() { + int n, a[11][11]; + cin >> n; + for (int i = 0; i < n; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +int a[110]; +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) { cin >> a[i]; } + int mgcd = a[0]; + for (int i = 1; i < n; i++) { mgcd = gcd(mgcd, a[i]); } + cout << mgcd * n << endl; + } +} +int a, b, c; +bool ok(int x) { + return x * b + b * c >= a * c; +} +int binary() { + int lo = 0, med, hi = 999999; + while (lo < hi) { + med = (lo + hi) >> 1; + if (ok(med)) + hi = med; + else + lo = med + 1; + } + return lo; +} +int main() { + cin >> a >> b >> c; + cout << binary() << endl; + return 0; +} +int main() { + long long n, x, y; + cin >> n >> x >> y; + string s; + cin >> s; + int len = s.size(); + int sum = 0; + for (int i = 0; i < len - 1; i++) { + if (s[i] == '0' && s[i + 1] == '1') sum++; + } + if (s[len - 1] == '0') sum++; + long long res = 0; + if (x < y) { + res = (sum - 1) * x + y; + } else { + res = sum * y; + } + if (sum == 0) res = 0; + cout << res << endl; +} +int main() { + int n, m, i; + cin >> n >> m; + for (i = 1; n > 0; ++i, n--) + if (!(i % m)) n++; + cout << i - 1 << endl; + return 0; +} +int main() { + int arr[3], ans1 = 0; + for (int i = 0; i < 3; i++) cin >> arr[i]; + sort(arr, arr + 3); + ans1 += (arr[1] - arr[0]); + ans1 += (arr[2] - arr[1]); + cout << ans1 << endl; + return 0; +} +int main() { + int n, a, b, c, i; + cin >> n >> a >> b >> c; + int ans = 1; + int sum = 0; + for (i = 1; i < n; i++) { + if (ans == 1) { + if (a < b) { + sum += a; + ans = 2; + } else { + sum += b; + ans = 3; + } + } else if (ans == 2) { + if (a < c) { + sum += a; + ans = 1; + } else { + sum += c; + ans = 3; + } + } else if (ans == 3) { + if (b < c) { + sum += b; + ans = 1; + } else { + sum += c; + ans = 2; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int k; + cin >> k; + int a[12]; + for (int i = 0; i < 12; i++) cin >> a[i]; + sort(a, a + 12); + int d = 0; + if (k == 0) + cout << 0 << endl; + else { + int i = 11; + int count = 0; + while (k > 0 && i >= 0) { + k -= a[i]; + i--; + count++; + } + if (i = -1 && k > 0) + cout << -1 << endl; + else + cout << count << endl; + } + return 0; +} +int n, m; +string s; +int main() { + while (cin >> n) { + for (int k = 0; k < n; k++) { + cin >> m >> s; + int ans = 0; + for (int i = 0; i < m / 2; i++) { + if (s[i] == s[m - i - 1] || (int)abs(s[i] - s[m - i - 1]) == 2) ans++; + } + if (ans == m / 2) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int ans = 0; + int remn = a; + int remd = b; + while (remn != 0) { + ans++; + int newnut = (min(k, remd + 1)) * v; + remd -= (min(k, remd + 1)) - 1; + if (newnut > remn) + remn = 0; + else + remn -= newnut; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 != 0) + n--; + else + n /= 10; + } + cout << n << endl; + return 0; +} +int main() { + long long n, m; + int a, b; + cin >> n >> m >> a >> b; + long long plus = 0, minus = 0; + long long mod = n % m; + long long div = n / m; + if (n % m != 0) { + if (n < m) { + plus = m - n; + minus = n; + } else { + plus = abs(n - ((div * m) + m)); + minus = mod; + } + } else { + cout << 0 << endl; + return 0; + } + cout << min(plus * a, minus * b) << endl; +} +int main() { + int a1, a2, a3, a4, a5, a6, result = 0; + cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6; + result = ((a1 + a2 + a3) * (a1 + a2 + a3)) - (a1 * a1) - (a3 * a3) - (a5 * a5); + cout << result << endl; + return 0; +} +int main() { + int n, sum = 0; + cin >> n; + if (n >= 100) sum += n / 100, n -= 100 * (n / 100); + if (n >= 20) sum += n / 20, n -= 20 * (n / 20); + if (n >= 10) sum += n / 10, n -= 10 * (n / 10); + if (n >= 5) sum += n / 5, n -= 5 * (n / 5); + if (n >= 1) sum += n / 1, n -= n / 1; + cout << sum << endl; + return 0; +} +int main() { + int n, arr[100]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + int biggest = arr[n - 1], res = 0; + for (int i = 0; i < n; i++) { res += (biggest - arr[i]); } + cout << res << endl; +} +int main() { + int a[1001], n, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) + if (a[i] == 1) sum++; + cout << sum << endl; + for (int i = 1; i < n; i++) + if (a[i + 1] == 1) cout << a[i] << " "; + cout << a[n] << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int h = c * d; + int f = (k * l) / nl; + int g = p / np; + int x = min(h, min(f, g)); + cout << x / n << endl; + return 0; +} +int main() { + int NumberOfStations; + int From, To; + int SumOfDistance = 0; + cin >> NumberOfStations; + vector StaionsDistance(NumberOfStations); + for (int Index = 0; Index < NumberOfStations; Index++) { + cin >> StaionsDistance[Index]; + SumOfDistance += StaionsDistance[Index]; + } + cin >> From >> To; + int Start, End; + if (From < To) { + Start = From; + End = To; + } else { + Start = To; + End = From; + } + int TheOtherDestance = 0; + for (; Start < End; Start++) TheOtherDestance += StaionsDistance[Start - 1]; + cout << min(TheOtherDestance, (SumOfDistance - TheOtherDestance)) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(n - 1) / r] << "\n"; +} +int main() { + int t, L, v, l, r; + cin >> t; + while (t--) { + int a = 0, b = 0, c = 0, d = 0; + cin >> L >> v >> l >> r; + a = (l - 1) / v; + b = r / v; + d = b - a; + c = L / v; + cout << c - d << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 1; j <= m; j++) cout << "#"; + cout << endl; + } else if (i % 4 == 0) { + cout << "#"; + for (int j = 1; j < m; j++) cout << "."; + cout << endl; + } else if (i % 2 == 0) { + for (int j = 1; j < m; j++) cout << "."; + cout << "#" << endl; + } + } + return 0; +} +int n; +string s, a, b; +int main() { + cin >> a >> b; + cout << a << " " << b << endl; + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> s; + if (s == a) { + cin >> s; + a = s; + } else { + cin >> s; + b = s; + } + cout << a << " " << b << endl; + } + return 0; +} +int win(char a, char b) { + if (a == b) return 2; + if (a == 'P' && b == 'R') return 0; + if (a == 'R' && b == 'S') return 0; + if (a == 'S' && b == 'P') return 0; + return 1; +} +int main() { + string a, b; + int n; + cin >> n; + cin >> a >> b; + int m = a.size(), k = b.size(); + int s[3] = {}, p[3] = {}; + for (int i = 0; i < m * k; i++) s[win(a[i % m], b[i % k])]++; + for (int i = 0; i < n % (m * k); i++) p[win(a[i % m], b[i % k])]++; + for (int i = 0; i < 2; i++) p[i] += s[i] * (n / (m * k)); + cout << p[1] << " " << p[0] << endl; + return 0; +} +int main() { + int i, x = 0; + cin >> i; + cout << i + i / 2 << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l; + cin >> r; + cin >> a; + if (l > r) swap(l, r); + while (l != r && a > 0) { + l++; + a--; + } + if (a == 0) + cout << l * 2 << endl; + else if (l == r) + cout << (l + a / 2) * 2 << endl; + return 0; +} +long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while ((ch < '0') || (ch > '9')) { + if (ch == '-') f = -1; + ch = getchar(); + } + while ((ch >= '0') && (ch <= '9')) { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return f * x; +} +long long n, t, a[104]; +int main() { + n = read(), t = read(); + for (int i = 1; i <= n; ++i) a[i] = read(); + for (int i = 1; i <= n; ++i) { + t -= 86400 - a[i]; + if (t <= 0) { + cout << i << endl; + return 0; + } + } +} +int main() { + int mini = INT_MAX, maxi = INT_MIN; + int n, x, k = 0; + cin >> n; + cin >> x; + mini = maxi = x; + for (int i = 1; i < n; i++) { + cin >> x; + if (x < mini) { + k++; + mini = x; + } + if (x > maxi) { + maxi = x; + k++; + } + } + cout << k << endl; +} +vector f; +int getmax() { + int max, imax; + max = imax = -1; + for (int i = 0; i < f.size(); i++) { + if (f[i] > max) { + max = f[i]; + imax = i; + } + } + f.erase(f.begin() + imax); + return max; +} +int main() { + int n, m, k, s, x; + cin >> n >> m >> k; + s = k; + for (int i = 0; i < n; i++) { + cin >> x; + f.push_back(x); + } + if (k >= m) { + cout << 0 << endl; + return 0; + } + int count = 0; + for (int i = 0; i < n; i++) { + count++; + s--; + s += getmax(); + if (s >= m) { + cout << count << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int a1[n], a2[n], a3[n]; + int j = 0, k = 0, l = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + a1[j] = i; + j++; + } else if (a[i] == 2) { + a2[k] = i; + k++; + } else if (a[i] == 3) { + a3[l] = i; + l++; + } + } + cout << min(j, min(k, l)) << endl; + for (int i = 0; i < min(j, min(k, l)); i++) cout << a1[i] + 1 << " " << a2[i] + 1 << " " << a3[i] + 1 << endl; +} +int main() { + char mat[200][200]; + int n, m; + cin >> n >> m; + int flag = 0; + int bstart = 0, bstartc = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> mat[i][j]; + if (flag == 0 and mat[i][j] == 'B') { + flag = 1; + bstart = i; + bstartc = j; + } + } + } + int bhoric = 0; + for (int i = 1; i <= m; i++) { + if (mat[bstart][i] == 'B') bhoric++; + } + bhoric = (bhoric / 2) + 1; + int bvoric = 0; + for (int i = 1; i <= n; i++) { + if (mat[i][bstartc] == 'B') bvoric++; + } + bvoric = (bvoric / 2 + 1); + cout << bstart + bvoric - 1 << " " << bstartc + bhoric - 1 << "\n"; + return 0; +} +long long int maxx(long long int &a, long long int &b) { + return a > b ? a : b; +} +long long int minn(long long int &a, long long int &b) { + return a > b ? b : a; +} +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +int int_gcd(int a, int b) { + return b == 0 ? a : int_gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return a / gcd(a, b) * b; +} +long long int poww(long long int base, long long int exp, long long int mod) { + base %= mod; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % mod; + base = (base * base) % mod; + exp >>= 1; + } + return result; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i <= 10001; i++) { + for (int j = 0; j <= 10001; j++) { + if (i * a + j * b == c) { + cout << "Yes" << endl; + return 0; + } + } + } + cout << "No" << endl; +} +int main() { + string s, ss[5]; + int flag = 0; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> ss[i]; + if (s[0] == ss[i][0] || s[1] == ss[i][1]) { + flag = 1; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = 1e6 + 50; +long double EPS = 1e-9; +const long long mod = 1e9 + 7; +int main() { + int n, tmp, tmo; + cin >> n; + tmp = tmo = n; + string ans(""), Cmp(""); + while (tmp > 0) { + if (tmp % 4 == 0) { + for (int i = 0; i < tmp / 4; ++i) ans += "4"; + tmp = 0; + break; + } else + ans += "7", tmp -= 7; + } + while (tmo > 0) { + if (tmo % 7 == 0) { + for (int i = 0; i < tmo / 7; ++i) Cmp += "7"; + tmo = 0; + break; + } else + Cmp += "4", tmo -= 4; + } + sort(ans.begin(), ans.end()); + sort(Cmp.begin(), Cmp.end()); + if (!tmp && !tmo) { + if (ans.size() <= Cmp.size()) + cout << ans << "\n"; + else + cout << Cmp << "\n"; + } else if (!tmp) + cout << ans << "\n"; + else if (!tmo) + cout << Cmp << "\n"; + else + cout << -1 << "\n"; + return 0; +} +const int inf = 1e9 + 9; +const int Mod = 1e9 + 7; +inline int scan() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +inline long long scan(long long x) { + int f = 1; + char ch = getchar(); + x = 0; + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +int n, m, ans, tp; +set s; +void solve() { + n = scan(); + s.clear(); + ans = 0; + for (int i = 1; i <= 2 * n; i++) { + tp = scan(); + if (s.count(tp)) + s.erase(tp); + else + s.insert(tp); + if (ans < s.size()) ans = s.size(); + } + cout << ans << endl; +} +int main() { + int t = 1; + for (int i = 1; i <= t; i++) { solve(); } + return 0; +} +void printv(vector s) { + for (int i = 0; i < (int)(s).size(); ++i) { cout << s[i] << " "; } + cout << "" << endl; +} +int toInt(string str) { + int num; + istringstream iss(str); + iss >> num; + return num; +} +string toString(int x) { + stringstream ss; + ss << x; + string str = ss.str(); + return str; +} +int main() { + int n, k, m = 0, a, b; + cin >> n >> k; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + m += b + 1 - a; + } + if (m % k == 0) { + cout << 0 << endl; + } else { + cout << k - m % k << endl; + } + return 0; +} +int n; +int v1, v2, t1, t2; +int res1, res2; +int main() { + cin >> n; + cin >> v1 >> v2 >> t1 >> t2; + res1 = v1 * n + 2 * t1; + res2 = v2 * n + 2 * t2; + if (res1 < res2) + cout << "First" << endl; + else if (res1 > res2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int i; + string a; + cin >> a; + for (i = 0; a[i] != '.'; i++) + ; + if (a[i - 1] == '9') + cout << "GOTO Vasilisa."; + else if (a[i + 1] < '5') + for (int j = 0; j < i; j++) cout << a[j]; + else { + for (int j = 0; j < i - 1; j++) cout << a[j]; + a[i - 1]++; + cout << a[i - 1]; + } + cout << endl; + return 0; +} +int main() { + long long int n, b, d, i; + while (cin >> n >> b >> d) { + long long int a[n + 5], sum = 0, c = 0; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (a[i] <= b) { sum += a[i]; } + if (sum > d) { + sum = 0; + c++; + } + } + cout << c << endl; + } +} +int main() { + long long m; + double n; + cin >> n; + m = (long long)round(n / 3); + cout << m / 12 << " " << m % 12 << endl; +} +int main() { + int n = 0, m = 0; + char p = '.'; + cin >> n >> m; + vector buf(n, ""); + for (int i = 0; i < n; i++) { cin >> buf[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (buf[i][j] == p) { + if ((i % 2 == 0 && j % 2 == 0) || (i % 2 > 0 && j % 2 > 0)) { + buf[i][j] = 'B'; + } else { + buf[i][j] = 'W'; + } + } + } + cout << buf[i] << '\n'; + } +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "NO" << endl; + return 0; + } + char arr[n][n]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { cin >> arr[i][j]; } + } + for (int i = 1; i < n; ++i) { + if (arr[0][0] != arr[i][i]) { + cout << "NO" << endl; + return 0; + } + } + int i = 0, j = n - 1; + while (i < n) { + if (arr[i][j] != arr[0][0]) { + cout << "NO" << endl; + return 0; + } + i++; + j--; + } + if (arr[0][1] == arr[0][0]) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (i != j && i + j != n - 1) { + if (arr[0][1] != arr[i][j]) { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, sum = 0, p, i; + double x; + cin >> n >> x; + for (i = 0; i < n; i++) { + cin >> p; + sum = sum + p; + } + sum = abs(sum); + cout << ceil(sum / x) << endl; + return 0; +} +int n, m; +char s[116][116]; +int main() { + int r = 0, c = 0; + int flag = 0; + int sumi = 0, sumj = 0, sum = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> s[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (s[i][j] == 'B') { + sumi += i; + sumj += j; + sum++; + } + } + } + cout << sumi / sum << " " << sumj / sum << endl; + return 0; +} +int main() { + int n, k, a[110]; + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int L = 1, R = n, ans = 0; + for (int i = 1; i <= n; i++) + if (a[i] <= k) + L++, ans++; + else + break; + for (int i = n; i > 0 && i >= L; i--) + if (a[i] <= k) + R--, ans++; + else + break; + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + float t01 = float(n) / float(k); + if (t01 == int(t01)) { + t01 = t01 * t; + } else { + t01 = (int(t01) + 1) * t; + } + t01 = t01 - t; + float t02 = d; + if (t01 > t02) { + cout << "YES"; + } else { + cout << "NO"; + } + cout << endl; + return 0; +} +int main() { + int n, add = 0; + int num[105]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> num[i]; + add += num[i]; + } + add = add / 2; + sort(num, num + n); + int ans = 0, val = 0; + for (int i = n - 1; i >= 0; i--) { + val += num[i]; + ans++; + if (val > add) { + cout << ans << endl; + return 0; + } + } + return 0; +} +int p2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256}; +int main() { + int n, b, p, k, m; + int bn = 0; + cin >> n >> b >> p; + m = n; + while (m > 1) { + for (k = 8; k >= 0; k--) { + if (p2[k] <= m) { + bn += p2[k] / 2 + p2[k] * b; + break; + } + } + m = p2[k] / 2 + (m - p2[k]); + } + cout << bn << " " << n * p << endl; + return 0; +} +void settings() {} +const int MOD = 1073741824; +int n, m; +int f(int a, int b) { + int ans = 0; + if (a > b) swap(a, b); + if (a == 0) return ans; + return ans + (b / a) + f(b % a, a); +} +int main() { + settings(); + cin >> n; + for (int i = 0; i < (n); i++) { + int a, b; + cin >> a >> b; + cout << f(a, b) << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + long long l = 1, r = 1; + string str; + for (int i = 0; i < n; i++) { + cin >> str; + if (str == "UR" || str == "DL") + r++; + else if (str == "DR" || str == "UL") + l++; + else + l++, r++; + } + cout << l * r << endl; +} +const long long MAX = 1000; +int main() { + long long n; + cin >> n; + if (n % 2 == 1) + cout << 1 << endl; + else + cout << 2 << endl; +} +int a[1001], b[1001]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 0; i < n; i++) { + a[0] |= a[i]; + b[0] |= b[i]; + } + cout << a[0] + b[0] << endl; + return 0; +} +int main() { + string s; + int j = 0, k = 0; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '-') + j++; + else + k++; + } + if (k == 0) + cout << "YES" << endl; + else if (j % k == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int N, a[100007], days = 1, b = 1; + cin >> N; + for (int i = 0; i < N; i++) { cin >> a[i]; } + for (int i = 1; i < N; i++) { + if (a[i] >= a[i - 1]) { + days++; + } else { + days = 1; + } + if (days > b) b = days; + } + cout << b << endl; +} +int max(int p, int t) { + int q = 3 * p / 10; + int r = p / 250; + r = r * t; + r = p - r; + if (q > r) { + return q; + } else { + return r; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int m = max(a, c); + int v = max(b, d); + if (m > v) { + cout << "Misha" << endl; + } else if (m < v) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } +} +map mpu; +vector vec; +bool s[1000006] = {}; +long long q[1000006] = {}, a[1000006] = {}; +int main() { + long long n, m; + cin >> m; + for (int i = 0; i < m; i++) { cin >> q[i]; } + sort(q, q + m); + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long sum = 0; + long long p = 0; + for (int i = n - 1; i >= 0;) { + if (p < q[0]) { + p++; + sum += a[i]; + i--; + continue; + } else { + i--; + if (i >= 0) i--; + p = 0; + } + } + cout << sum << endl; + return 0; +} +int main() { + unsigned long int n, b, d, v, sum = 0, c = 0; + cin >> n >> b >> d; + for (int x = 0; x < n; x++) { + cin >> v; + if (v <= b) sum += v; + if (sum > d) { + sum = 0; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int loop; + cin >> loop; + int n; + string s; + for (int _ = 0; _ < loop; _++) { + cin >> n >> s; + bool isP = true; + for (int i = 0; i < n / 2; i++) { + int r = abs(s.at(i) - s.at(n - i - 1)); + if (!(r == 2 || r == 0)) { + isP = false; + break; + } + } + cout << (isP ? "YES" : "NO") << endl; + } +} +int main() { + long long n, a; + cin >> n; + if (n % 2 == 0) + a = n / 2; + else + a = ((n + 1) / 2) * (-1); + cout << a << endl; + return 0; +} +int main() { + int k, r; + cin >> k >> r; + int m = 1, n = 0, newk = 0; + while (true) { + newk = m * k; + n = 0; + while (true) { + if (n * 10 > newk && n * 10 + r > newk) { + break; + } else if (n * 10 == newk || n * 10 + r == newk) { + cout << m << endl; + goto endloop; + } + n++; + } + m++; + } +endloop:; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1]; + a[0] = 0; + for (int j = 1; j <= n; ++j) { cin >> a[j]; } + for (int i = 1; i <= n; ++i) { + if (a[i] == 0 && a[i + 1] == 1 && a[i - 1] == 1) a[i] = 1; + } + int counter = 0; + for (int k = 1; k <= n; ++k) { counter += a[k]; } + cout << counter << endl; +} +void swap(int *a, int *b) { + int t = *a; + *a = *b; + *b = t; +} +int main() { + int n, ele; + int p1 = 1, p2 = 2, waiter = 3; + bool flag = 1; + cin >> n; + while (n--) { + cin >> ele; + if (ele != p1 && ele != p2) { + flag = 0; + } else { + if (ele == p1) { + swap(&p2, &waiter); + } else { + swap(&p1, &waiter); + } + } + } + if (flag) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +const int N = 1e6 + 5; +int main() { + int s = 0; + for (int i = 0; i < 5; i++) { + int x; + cin >> x; + s += x; + } + if (s == 0 || (s % 5)) + cout << "-1" << endl; + else + cout << s / 5 << endl; + return 0; +} +int n, a, b; +int c[23]; +int main() { + cin >> n >> a >> b; + for (int i = (int)1; i <= (int)n; i++) cin >> c[i]; + int cost = 0; + for (int i = (int)1; i <= (int)n / 2; i++) { + if (c[i] == c[n + 1 - i]) { + if (c[i] == 1 || c[i] == 0) { + continue; + } else if (c[i] == 2) { + cost += 2 * min(a, b); + } + } else { + if (c[i] == 1 && c[n + 1 - i] == 0) { + cout << "-1\n"; + return 0; + } else if (c[i] == 0 && c[n + 1 - i] == 1) { + cout << "-1\n"; + return 0; + } else if (c[i] == 0 && c[n + 1 - i] == 2) { + cost += a; + } else if (c[i] == 1 && c[n + 1 - i] == 2) { + cost += b; + } else if (c[i] == 2 && c[n + 1 - i] == 0) { + cost += a; + } else if (c[i] == 2 && c[n + 1 - i] == 1) { + cost += b; + } + } + } + if (n & 1) { + if (c[n / 2 + 1] == 2) { cost += min(a, b); } + } + cout << cost << "\n"; + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int count = 0; + if (n % s == 0) + count = n / s; + else + count = n / s + 1; + int sum = count * k; + if (sum % p == 0) + cout << sum / p << endl; + else + cout << sum / p + 1 << endl; + return 0; +} +int main() { + int n; + set X, Y; + cin >> n; + while (n-- > 0) { + int x, y; + cin >> x >> y; + X.insert(x); + Y.insert(y); + } + cout << min(X.size(), Y.size()) << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int res = ceil((y / 100.0) * n) - x; + if (res < 0) { + cout << 0 << endl; + } else { + cout << res << endl; + } + return 0; +} +int h[3]; +int main() { + long double a, b, c; + cin >> a >> b >> c; + long double f = b + c; + long double t = a / f; + cout << b * t << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int sup = 0, inf = 0; + for (int j = i; j < n; j++) { + if (s[j] == '(') + sup++, inf++; + else if (s[j] == ')') + sup--, inf--; + else + sup++, inf--; + if (sup < 0) break; + if (inf < 0) inf = 0; + if ((j - i + 1) % 2 == 0 && inf == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { + if (i % 2) + cout << "I hate "; + else + cout << "I love "; + if (i == n) + cout << "it" << endl; + else + cout << "that "; + } + } + return 0; +} +int a[105]; +int main() { + int n, k, x; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int sum = 0; + for (int i = 0; i < n - k; i++) sum += a[i]; + sum += k * x; + cout << sum << endl; + return 0; +} +string p, s, ans; +int n; +int main() { + cin >> p >> n; + ans = ""; + while (n--) { + cin >> s; + if ((int)s.size() >= (int)p.size()) { + string aux = s.substr(0, (int)p.size()); + if (aux == p && (s < ans || ans == "")) { ans = s; } + } + } + cout << (ans == "" ? p : ans) << "\n"; +} +const int maxn = 1e5 + 7; +int w[maxn]; +int main() { + int n, k; + cin >> n >> k; + int cnt = n; + for (int i = 1; i <= n; i++) { + cin >> w[i]; + cnt += w[i] / k; + if (w[i] % k == 0) cnt--; + } + if (cnt % 2 == 0) + cnt /= 2; + else + cnt = cnt / 2 + 1; + cout << cnt << endl; + return 0; +} +int main() { + long long n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + long long ta, fa, tb, fb; + long long ans; + for (int i = 0; i < k; i++) { + ans = 0; + cin >> ta >> fa >> tb >> fb; + ans = abs(fa - fb) + abs(ta - tb); + if (fa < a && fb < a && ta != tb) ans += 2 * (a - max(fa, fb)); + if (fa > b && fb > b && ta != tb) ans += 2 * (min(fa, fb) - b); + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c, a1, ans2, ans; + cin >> a >> b >> c; + a1 = (a - b) * c; + ans = (a1 + b - 1) / b; + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int upper = 0; + int lower = 0; + int i; + for (i = 0; i < s.size(); i++) { + if (isupper(s[i])) + ++upper; + else + ++lower; + } + if (upper > lower) { + for (i = 0; i < s.size(); i++) s[i] = toupper(s[i]); + } else { + for (i = 0; i < s.size(); i++) s[i] = tolower(s[i]); + } + cout << s << endl; +} +int i, j; +const int M = 1e5 + 6; +int query[(1 << 18) + 6]; +int main() { + int t; + cin >> t; + while (t--) { + string s, num; + cin >> s >> num; + int x = 0; + if (s == "?") { + for (i = num.size() - 1, j = 0; i >= 0; i--, j++) { + if (num[i] == '1') x += (1 << j); + } + cout << query[x] << "\n"; + continue; + } + for (i = num.size() - 1, j = 0; i >= 0; i--, j++) { + if ((int)(num[i] - '0') % 2) x += (1 << j); + } + if (s == "+") + query[x]++; + else + query[x]--; + } +} +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum += a; + } + cout << sum / n << endl; +} +int main() { + int k; + cin >> k; + string s; + cin >> s; + vector ans; + int i = 0; + int cnt[26] = {0}; + string t = ""; + for (i = 0; i < s.length(); i++) { + if (cnt[s[i] - 'a'] == 0 && k >= 1) { + k--; + cnt[s[i] - 'a'] = 1; + if (t != "") ans.push_back(t); + t = ""; + t.push_back(s[i]); + } else + t.push_back(s[i]); + } + ans.push_back(t); + if (k == 0) { + cout << "YES\n"; + for (i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n; + char mp[110][110]; + cin >> n; + memset(mp, '*', sizeof(mp)); + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) cin >> mp[j][i]; + bool flag = true; + for (int i = 1; i <= n && flag; ++i) { + int cnt = 0; + for (int j = 1; j <= n; ++j) { + if (mp[j - 1][i] == 'o') cnt++; + if (mp[j + 1][i] == 'o') cnt++; + if (mp[j][i - 1] == 'o') cnt++; + if (mp[j][i + 1] == 'o') cnt++; + if (cnt % 2 != 0) { + flag = false; + break; + } + } + } + puts(flag ? "YES" : "NO"); + return 0; +} +void solve(string str, int n, int k) { + int indG = -1; + int indT = -1; + for (int i = 0; i < n; i++) { + if (str[i] == 'G') indG = i; + if (str[i] == 'T') indT = i; + } + bool flg = false; + if (indT < indG) { + for (int i = indG; i >= 0; i -= k) { + if (str[i] == 'T') { + flg = true; + break; + } else if (str[i] == '#') + break; + } + } else { + for (int i = indG; i < n; i += k) { + if (str[i] == 'T') { + flg = true; + break; + } else if (str[i] == '#') + break; + } + } + if (flg) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + solve(str, n, k); + return 0; +} +int a[105]; +int main() { + int n, s, h, m, x, y, t; + cin >> n >> s; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + a[i] = 60 * x + y; + } + a[n + 1] = 1e9; + if (s < a[1]) { + cout << 0 << " " << 0 << endl; + return 0; + } + for (int i = 1; i <= n; i++) { + t = a[i] + 2 * s + 1; + if (t < a[i + 1]) { + t -= s; + cout << t / 60 << " " << t % 60 << endl; + break; + } + } + return 0; +} +const long long inf = 1e16; +const long long MAXN = 1e6; +const double pi = acos(-1); +long long n, k, ans; +int main() { + cin >> n >> k; + k--; + ans += (n * 2 + k) / (k + 1); + ans += (n * 5 + k) / (k + 1); + ans += (n * 8 + k) / (k + 1); + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + for (int k = j + 1; k < s.size(); k++) { + if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') { ans++; } + } + } + } + cout << ans << "\n"; + return 0; +} +const int MAXN = 101 + 5; +char table[MAXN][MAXN]; +int n, half; +int main() { + cin >> n; + half = n / 2; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) table[i][j] = '*'; + for (int i = 0; i < half; i++) + for (int j = 0; j < n; j++) + if (j >= (half - i) && j <= (half + i)) table[i][j] = 'D'; + for (int i = 0; i < n; i++) table[half][i] = 'D'; + int u = half + 1; + for (int i = half - 1; i >= 0; i--, u++) + for (int j = 0; j < n; j++) + if (j >= (half - i) && j <= (half + i)) table[u][j] = 'D'; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cout << table[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, a, count1(0), extra0(0), extra0max(-1); + cin >> n; + while (n--) { + cin >> a; + if (a == 1) { + count1 += 1; + if (extra0 > 0) { extra0 -= 1; } + } else { + extra0 += 1; + if (extra0 > extra0max) { extra0max = extra0; } + } + } + cout << count1 + extra0max << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = n + 1; i <= 9999; i++) { + int a[5], k = i, top = 0; + while (k) { + a[top++] = k % 10; + k = k / 10; + } + int flag = 0; + for (int i = 0; i < top - 1; i++) + for (int j = i + 1; j <= top - 1; j++) + if (a[i] == a[j]) { + flag = 1; + break; + } + if (!flag) { + cout << i << endl; + return 0; + goto AppEnd; + exit(0); + } + } +AppEnd: + return 0; +} +int main() { + long long int n, a, b, c; + cin >> n >> a >> b >> c; + long long int k = n % 4; + if (k == 0) { + cout << "0" << endl; + } else if (k == 1) { + if ((3 * a <= (a + b)) && 3 * a <= c) { + cout << 3 * a << endl; + } else if (a + b <= c) { + cout << a + b << endl; + } else + cout << c << endl; + } else if (k == 2) { + if (2 * a <= b && 2 * a <= 2 * c) { + cout << 2 * a << endl; + } else if (b <= 2 * c) { + cout << b << endl; + } else + cout << 2 * c << endl; + } else if (k == 3) { + if (a <= b + c && a <= 3 * c) + cout << a << endl; + else if (b + c <= 3 * c) + cout << b + c << endl; + else + cout << 3 * c << endl; + } + return 0; +} +void solve() { + int i, j, n, m, dick = 0; + (cin >> n); + (cin >> m); + string dhurr[n]; + vector hush, fuck; + fuck.push_back('a'); + fuck.push_back('c'); + fuck.push_back('e'); + fuck.push_back('f'); + for (i = 0; i < n; (i++)) { (cin >> dhurr[i]); } + for (i = 0; i < n - 1; i++) { + for (j = 0; j < m - 1; j++) { + hush.push_back(dhurr[i][j]); + hush.push_back(dhurr[i][j + 1]); + hush.push_back(dhurr[i + 1][j]); + hush.push_back(dhurr[i + 1][j + 1]); + sort(hush.begin(), hush.end()); + if (hush == fuck) (dick++); + hush.clear(); + } + } + (cout << dick << endl); +} +int main() { + solve(); + return 0; +} +const long long inf = 1e9; +const long double pi = 3.141592; +const long long mod1 = 1e9 + 7; +int main() { + long long q, n; + string s; + cin >> q; + char temp; + for (int i = 1; i <= q; i++) { + cin >> n >> s; + if (n == 2) { + if ((s[0] - '0') >= (s[1] - '0')) { + cout << "NO" + << "\n"; + } else { + cout << "YES" + << "\n"; + cout << 2 << "\n"; + cout << s[0] << " " << s[1] << "\n"; + } + } else { + cout << "YES" + << "\n"; + cout << 2 << "\n"; + cout << s[0] << " "; + for (int i = 1; i < n; i++) { cout << s[i]; } + cout << "\n"; + } + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + cout << ((n / k) & 1 ? "YES" : "NO") << '\n'; + return 0; +} +int main() { + long long n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int total_drink = k * l; + int lime_slices = c * d; + int salt = p; + int count = 0; + while (total_drink >= nl && lime_slices && salt >= np) { + count += 1; + total_drink -= nl; + lime_slices--; + salt -= np; + } + cout << count / n << endl; +} +int main() { + int a, b, c, d, x, y, z, n, t; + cin >> a >> b >> c >> d >> x >> y >> z >> n >> t; + if ((a + b + d) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((a + b + c + x) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((b + c + y) % 2 == 0) + cout << "1"; + else + cout << "0"; + cout << endl; + if ((a + d + x + z) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((b + d + x + y + n) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((c + x + y + t) % 2 == 0) + cout << "1"; + else + cout << "0"; + cout << endl; + if ((d + z + n) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((x + z + n + t) % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((y + n + t) % 2 == 0) + cout << "1"; + else + cout << "0"; + cout << endl; + return 0; +} +int main() { + char t; + cin >> t; + string a, b; + cin >> a >> b; + char s0 = a[1], s1 = b[1]; + if (a[0] == 'A') a[0] = 'Z'; + if (b[0] == 'A') b[0] = 'Z'; + if (a[0] == 'T') a[0] = 'B'; + if (b[0] == 'T') b[0] = 'B'; + if (a[0] == 'K') a[0] = 'X'; + if (b[0] == 'K') b[0] = 'X'; + if (s0 == t && s1 != t) { + cout << "YES" << endl; + return 0; + } + if (s0 == s1 && a[0] > b[0]) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; ++i) { cin >> v[i]; } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + long long res = (long long)v[0] * (long long)n; + for (int i = 1, j = n; i < n; ++i, --j) { res += (long long)v[i] * (long long)j; } + cout << res << endl; + return 0; +} +int main() { + string s; + set st; + cin >> s; + int len = s.size() - 1; + st.insert(s); + while (len--) { + s.push_back(s[0]); + s.erase(0, 1); + st.insert(s); + } + cout << st.size() << endl; + return 0; +} +int main() { + int n, d; + string a[105]; + cin >> n >> d; + for (int i = 0; i < d; i++) { cin >> a[i]; } + int max = 0, temp = 0; + for (int i = 0; i < d; i++) { + int flag = 0; + for (int j = 0; j < n; j++) { + if (a[i][j] == '0') { + flag = 1; + break; + } + } + if (flag == 1) { + temp++; + if (temp > max) { max = temp; } + } else { + temp = 0; + } + } + cout << max << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << 2 << endl; + for (long long i = 2; i <= n; i++) cout << i * (i + 1) * (i + 1) - (i - 1) << endl; + return 0; +} +string s, c; +int i; +int main() { + cin >> s; + for (i = 0; i < 5; ++i) { + cin >> c; + if (c[0] == s[0] || c[1] == s[1]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +const int MAXN = 2200; +int n; +int q[MAXN]; +int fpow(int a, int x) { + int rtn = 1; + for (; x; x >>= 1, a = 1ll * a * a % n) + if (x & 1) rtn = 1ll * rtn * a % n; + return rtn; +} +int main() { + cin >> n; + int top = 0; + for (int i = 2; i < n - 1; i++) + if ((n - 1) % i == 0) q[++top] = i; + int ans = 0; + for (int i = 2; i < n; i++) { + bool p = 1; + for (int j = 1; j <= top && p; j++) + if (fpow(i, q[j]) == 1) p = 0; + if (p) ans++; + } + if (n == 2) ans++; + cout << ans << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int joy = -9999999999; + for (long long int i = 0; i < n; i++) { + long long int f, t; + cin >> f >> t; + if (k >= t) { + if (joy < f) { joy = f; } + } else { + if (joy < f - (t - k)) { joy = f - (t - k); } + } + } + cout << joy << endl; + return 0; +} +int main() { + int n; + cin >> n; + int A[100001]; + for (int i = 0; i < n; i++) cin >> A[i]; + int length = INT_MIN; + int i = 1; + int temp = 1; + while (i < n) { + if (A[i] <= A[i - 1]) { + if (temp > length) length = temp; + temp = 0; + } + i++; + temp++; + } + if (temp > length) length = temp; + cout << length << endl; + return 0; +} +int b, c, word, ans, temp = 1; +int main() { + cin >> b >> c; + for (int a = 0; a < b; a++) { + cin >> word; + if (word - temp > c) + ans = 1; + else + ans++; + temp = word; + } + cout << ans << "\n"; +} +int main() { + int n, a[1000], max1; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + int sum = 0; + for (int j = 1; j <= n; j++) { sum += (fabs(i * 1.0 - j * 1.0) + j - 1 + i - 1) * 2 * a[j]; } + if (i == 1) + max1 = sum; + else + max1 = min(max1, sum); + } + cout << max1 << endl; + return 0; +} +long long Q_pow(long long a, long long b) { + long long ans = 1; + while (b > 0) { + if (b % 2 == 1) { + a %= 100; + ans %= 100; + ans *= a; + } + a %= 100; + a *= a; + b /= 2; + } + return ans % 100; +} +int main() { + long long n; + while (cin >> n) { cout << Q_pow(5, n) << endl; } +} +map m; +map::iterator it; +int main() { + char s[20]; + int n; + m[0] = "January"; + m[1] = "February"; + m[2] = "March"; + m[3] = "April"; + m[4] = "May"; + m[5] = "June"; + m[6] = "July"; + m[7] = "August"; + m[8] = "September"; + m[9] = "October"; + m[10] = "November"; + m[11] = "December"; + while (cin >> s >> n) { + int j = 0; + for (it = m.begin(); it != m.end(); it++) { + ++j; + if (it->second == s) break; + } + cout << m[(j + n - 1) % 12] << endl; + } + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +void solve() { + string s; + cin >> s; + int n = s.size(); + bool b = true; + for (int i = 0; i < n; i++) { + if (s[i] == 'a' or s[i] == 'o' or s[i] == 'u' or s[i] == 'i' or s[i] == 'e') { + b = true; + } else if (s[i] == 'n') { + if (!b) { + cout << "NO" << endl; + return; + } else + b = true; + } else { + if (!b) { + cout << "NO" << endl; + return; + } else { + b = false; + } + } + } + if (!b) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int grid_size; + cin >> grid_size; + bool valid = true; + vector grid; + for (int i = 0; i < grid_size; ++i) { + string line; + cin >> line; + grid.push_back(line); + } + char x_char = grid[0].at(0); + char y_char = grid[0].at(1); + if (x_char == y_char) { valid = false; } + if (valid) { + for (int i = 0; i < grid_size; ++i) { + if (grid[i].at(i) != x_char) { + valid = false; + break; + } + } + } + if (valid) { + for (int i = grid_size - 1; i >= 0; --i) { + if (grid[i].at(grid_size - i - 1) != x_char) { + valid = false; + break; + } + } + } + if (valid) { + for (int i = 0; i < grid_size; ++i) { + for (int j = 0; j < grid_size; ++j) { + if ((i != j) && (j != grid_size - i - 1)) { + if (grid[i].at(j) != y_char) { + valid = false; + break; + } + } + } + } + } + if (valid) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + cout << (long long)(ceil(ceil((double)(n) / s) * k / p)) << endl; + return 0; +} +int main() { + string username; + int ans = 0; + cin >> username; + int alph[26] = {0}; + for (int i = 0; i < username.length(); i++) { alph[(int)username[i] - 97] += 1; } + for (int i = 0; i < 26; i++) { + if (alph[i] != 0) { ans += 1; } + } + if (ans % 2 == 0) { + cout << "CHAT WITH HER!\n"; + } else { + cout << "IGNORE HIM!\n"; + } + return 0; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +long long n, k, x; +int main() { + cin >> n >> k; + x = n / k; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + string yeet = ""; + yeet.push_back(a[0]); + int next = 0; + for (int i = 1; i < a.size(); i++) { + if (a[i] < b[next]) { + yeet.push_back(a[i]); + } else { + break; + } + } + yeet.push_back(b[next]); + cout << yeet << "\n"; +} +int gcd(int a, int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + int x, y; + int a, b; + cin >> x; + cin >> y; + cin >> a; + cin >> b; + int M = x / gcd(x, y) * y; + int l = a / M; + int r = b / M; + if (l * M < a) { l++; } + cout << r - l + 1 << endl; + return 0; +} +string st; +vector l, r; +int main() { + cin >> st; + int n = st.size(); + for (int i = 0; i < n; i++) { + if (st[i] == 'l') + l.push_back(i + 1); + else + r.push_back(i + 1); + } + reverse(l.begin(), l.end()); + for (int i = 0; i < r.size(); i++) cout << r[i] << '\n'; + for (int i = 0; i < l.size(); i++) cout << l[i] << '\n'; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << (a * c - b * c) / b + ((a * c - b * c) % b != 0) << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2, a, b; + cin >> s >> v1 >> v2 >> t1 >> t2; + a = (s * v1) + (t1 * 2); + b = (s * v2) + (t2 * 2); + if (a < b) { + cout << "First" << endl; + } else if (a > b) { + cout << "Second" << endl; + } else { + cout << "Friendship" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << (3 * n) / 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + sort(V.begin(), V.end()); + cout << (V[0] + V[n - 1]) / 2 << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < (n - (2 * i + 1)) / 2; j++) cout << '*'; + for (int x = 0; x < 2 * i + 1; x++) cout << 'D'; + for (int o = 0; o < (n - (2 * i + 1)) / 2; o++) cout << '*'; + cout << endl; + } + for (int i = 0; i < n; i++) cout << 'D'; + cout << endl; + for (int i = n / 2 - 1; i >= 0; i--) { + for (int j = 0; j < (n - (2 * i + 1)) / 2; j++) cout << '*'; + for (int x = 0; x < 2 * i + 1; x++) cout << 'D'; + for (int o = 0; o < (n - (2 * i + 1)) / 2; o++) cout << '*'; + cout << endl; + } +} +int a[1010], c[1010], n, m, j; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + for (int i = 0; i < n; i++) + if (c[i] <= a[j]) j++; + cout << j << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + cin >> n; + set s; + for (i = 0; i < n; i++) { + cin >> m; + if (m) s.insert(m); + } + cout << s.size() << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (int i = 0; i < s1.length(); i++) { + if (s1[i] >= 'A' && s1[i] <= 'Z') s1[i] += 32; + if (s2[i] >= 'A' && s2[i] <= 'Z') s2[i] += 32; + } + if (s1 > s2) + cout << "1" << endl; + else if (s1 < s2) + cout << "-1" << endl; + else if (s1 == s2) + cout << "0" << endl; + return 0; +} +int main() { + string a; + getline(cin, a); + int j; + for (int i = 0; i < a.length(); i++) { + if ((int)a[i] != 104) { + a.erase(a.begin()); + i = i - 1; + continue; + } + if ((int)a[i] == 104) { + j = i + 1; + break; + } + } + for (int i = j; i < a.length(); i++) { + if ((int)a[i] != 101) { + a.erase(a.begin() + i); + i = i - 1; + continue; + } + if ((int)a[i] == 101) { + j = i + 1; + break; + } + } + for (int i = j; i < a.length(); i++) { + if ((int)a[i] != 108) { + a.erase(a.begin() + i); + i = i - 1; + continue; + } + if ((int)a[i] == 108) { + j = i + 1; + break; + } + } + for (int i = j; i < a.length(); i++) { + if ((int)a[i] != 108) { + a.erase(a.begin() + i); + i = i - 1; + continue; + } + if ((int)a[i] == 108) { + j = i + 1; + break; + } + } + for (int i = j; i < a.length(); i++) { + if ((int)a[i] != 111) { + a.erase(a.begin() + i); + i = i - 1; + continue; + } + if ((int)a[i] == 111) { + j = i + 1; + a.erase(5, a.length() - 1); + break; + } + } + if (a[0] == 'h' && a[1] == 'e' && a[2] == 'l' && a[3] == 'l' && a[4] == 'o') { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int t, sum = 0, ans; + cin >> t; + string s, s1, s2, str, str1; + vector v; + vector v1; + vector v2; + vector v3; + vector v4; + int n; + while (t--) { + sum = 0; + s1 = ""; + s2 = ""; + cin >> n; + cin >> s; + for (int i = 0; i < n / 2; i++) { s1 += s[i]; } + for (int i = n - 1; i >= n / 2; i--) { s2 += s[i]; } + for (int j = 0; j < s1.size(); j++) { + int d = int(s1[j]); + int e = int(s2[j]); + int ans = abs(d - e); + if (ans == 0 || ans == 2) { + sum += ans; + } else { + sum = -1; + } + } + if (sum % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + const int m = 100; + string s, p, l; + string A[m]; + cin >> s; + int k; + int sum = 0; + bool flag = false; + int a = s.size(); + for (int i = 0; i < a; i++) { + p = s[a - 1]; + s.erase(a - 1, 1); + l.insert(0, p); + l.insert(1, s); + A[i] = l; + for (int j = 0; j < i; j++) { + k = A[i].compare(A[j]); + if (k == 0) { flag = true; } + } + if (flag == false) { sum++; } + s = l; + l.clear(); + } + cout << sum << endl; + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (x > y) { swap(x, y); } + if (x >= m || y >= m) { + cout << 0 << endl; + return 0; + } + if (x <= 0 && y <= 0) { + cout << -1 << endl; + return 0; + } + long long cnt = 0; + if (x < 0 && y > 0) { + if (m < 0) { + cnt = (long long)((m - x) * 1.0 / y); + x += cnt * y; + } else { + cnt = (long long)((-x) * 1.0 / y); + x += cnt * y; + } + } + long long z = x + y; + while (x < m && y < m) { + z = x + y; + if (x > y) { swap(x, y); } + x = z; + cnt++; + } + cout << cnt << endl; +} +long long a[3], b[3], k; +int main() { + cin >> a[0] >> a[1] >> a[2] >> k; + k = min(k, a[0] + a[1] + a[2] - 3); + sort(a, a + 3); + for (long long i = 0; i < 3; i++) b[i] = k / 3; + for (long long i = 0; i < k % 3; i++) b[2 - i]++; + for (long long i = 0; i < 2; i++) { + if (b[i] >= a[i]) { + b[2] += b[i] - (a[i] - 1); + b[i] = a[i] - 1; + } + } + while (b[2] - 1 >= b[1] + 1 && b[1] + 1 < a[1]) b[1]++, b[2]--; + cout << (b[0] + 1) * (b[1] + 1) * (b[2] + 1) << '\n'; +} +int main() { + int n, k; + cin >> n >> k; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + int sum = 0; + int i; + for (i = 0; i < n; i++) { + if (v[i] <= k) + sum++; + else + break; + } + if (i == n) { + cout << sum << endl; + } else { + int sum2 = 0; + for (int i = n - 1; i >= 0; i--) { + if (v[i] <= k) + sum2++; + else + break; + } + cout << sum + sum2 << endl; + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(k * l / nl, min(c * d, p / np)) / n << endl; +} +const int MAX = 102; +void print(int a[MAX][MAX], int m, int n) { + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { cout << a[i][j] << " "; } + cout << "\n"; + } +} +int main() { + int n, m, i, j, ma; + cin >> n >> m; + int a[100 + 2][100 + 2]; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + char x; + cin >> x; + a[j][i] = x - 48; + } + } + int b[n + 2] = {0}; + for (i = 0; i < m; i++) { + ma = 0; + for (j = 0; j < n; j++) { ma = max(ma, a[i][j]); } + for (j = 0; j < n; j++) { + if (a[i][j] == ma) { b[j] = 1; } + } + } + int ans = 0; + for (i = 0; i < n; i++) { + if (b[i] == 1) ans++; + } + cout << ans << "\n"; + return 0; +} +int main() { + long long int n, i, l, s = 0; + cin >> n; + for (l = 0;; l++) { + s += l * (l + 1) / 2; + if (s > n) { break; } + } + cout << l - 1 << endl; + return 0; +} +int main() { + int n, prev = -1, sum = 0; + cin >> n; + for (int i = 0, a; i < n; i++) { + cin >> a; + if (!a || a == prev) + sum++, prev = -1; + else if (a != 3) + prev = a; + else if (prev != -1) + prev = prev % 2 + 1; + } + cout << sum << endl; +} +long long n; +int main() { + cin >> n; + for (long long l = 1; l < n; l++) n -= l; + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int x; + cin >> x; + x /= 2; + cout << x * 3 << endl; + return 0; +} +int main() { + long long sum = 0, a, b; + cin >> a >> b; + if ((a * 2) % b == 0) + sum += (a * 2) / b; + else + sum += ((a * 2) / b) + 1; + if ((a * 5) % b == 0) + sum += (a * 5) / b; + else + sum += ((a * 5) / b) + 1; + if ((a * 8) % b == 0) + sum += (a * 8) / b; + else + sum += ((a * 8) / b) + 1; + cout << sum << endl; + return 0; +} +const int N = 2e5 + 100; +map ma, mb; +long long a[N]; +pair p[N]; +vector v, v1; +set s; +int main() { + long long n; + cin >> n; + for (int i = n - 1; i > n - 10000; i--) { + long long j = i, d = 0; + while (j > 0) d += (j % 10), j /= 10; + if (d + i == n) { v.push_back(i); } + } + sort(v.begin(), v.end()); + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; +} +int main() { + int i, j, n, a[102][102]; + cin >> n; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) a[i][j] = 0; + for (i = 1; i <= n / 2 + 1; i++) + for (j = n / 2 - i + 2; j < n / 2 + i + 1; j++) { + a[i][j] = 1; + a[n - i + 1][j] = 1; + } + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) + if (a[i][j] == 0) + cout << "*"; + else + cout << "D"; + cout << endl; + } + return 0; +} +int main() { + int n, a, p, pmin = 128, s = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a >> p; + if (p < pmin) pmin = p; + s += a * pmin; + } + cout << s << endl; + return 0; +} +int main() { + string s[110], t[110]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i] >> t[i]; + if (t[i] == "rat") cout << s[i] << endl; + } + for (int i = 0; i < n; i++) { + if (t[i] == "woman" || t[i] == "child") cout << s[i] << endl; + } + for (int i = 0; i < n; i++) { + if (t[i] == "man") cout << s[i] << endl; + } + for (int i = 0; i < n; i++) { + if (t[i] == "captain") cout << s[i] << endl; + } + return 0; +} +int main() { + int n, c = 0; + cin >> n; + while (n > 0) { + if (n >= 100) { + n -= 100; + } else if (n >= 20) { + n -= 20; + } else if (n >= 10) { + n -= 10; + } else if (n >= 5) { + n -= 5; + } else if (n >= 1) { + n -= 1; + } + c++; + } + cout << c << "\n"; + return 0; +} +int main() { + int n, k = 0, l = 1; + cin >> n; + string s; + cin >> s; + long long int c = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + c++; + } else if (s[i] == '0') { + cout << c; + c = 0; + } + } + cout << c << endl; +} +const int inf = (long long)1e9; +const long long mod = 998244353; +int n; +int u[200300]; +int main() { + cin >> n; + int ans = 0, cur = 0; + for (int i = 1; i <= n + n; ++i) { + int x; + cin >> x; + if (u[x]) + cur--; + else { + ++cur; + u[x] = 1; + ans = max(ans, cur); + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int s, v1, v2, t1, t2, ans1, ans2; + cin >> s >> v1 >> v2 >> t1 >> t2; + ans1 = (s * v1) + 2 * t1; + ans2 = (s * v2) + 2 * t2; + if (ans1 < ans2) { + cout << "First" << endl; + } else if (ans1 > ans2) { + cout << "Second" << endl; + } else { + cout << "Friendship" << endl; + } +} +int main() { + string s[8]; + for (int i = 0; i < 8; i++) cin >> s[i]; + for (int i = 0; i < 8; i++) { + for (int j = 1; j < 8; j++) + if (s[i][j] == s[i][j - 1]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, m; + int an[1005], am[1005]; + cin >> n >> m; + int cnt = 0; + int res = 0; + for (int i = 0; i < n; i++) { cin >> an[i]; } + for (int j = 0; j < m; j++) { cin >> am[j]; } + for (int i = 0; i < n; i++) { + if (an[i] <= am[res]) { + res++; + cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int a[105], n, ans = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j <= i; j++) { + int v = 0; + for (int k = 0; k < n; k++) + if (k >= j && k <= i) + v += !a[k]; + else + v += a[k]; + ans = max(ans, v); + } + cout << ans << "\n"; + return 0; +} +set stuff; +int n; +string s; +int alpha[27]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < 26; j++) alpha[j] = 0; + for (int j = 0; j < s.length(); j++) { alpha[s[j] - 97]++; } + int sumthing = 0; + for (int j = 0; j < 26; j++) { + if (alpha[j]) { sumthing += (1 << j); } + } + stuff.insert(sumthing); + } + cout << stuff.size() << '\n'; +} +int main() { + long long int n, m, a, b, r; + cin >> n >> m >> a >> b; + r = n % m; + cout << (min(r * b, (m - r) * a)) << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + stack c; + for (int i = 0; i < s.size(); i++) { + if (!c.empty() && c.top() == s[i]) + c.pop(); + else + c.push(s[i]); + } + string a; + int y = c.size(); + while (!c.empty()) { + a += c.top(); + c.pop(); + } + for (int i = y - 1; i >= 0; i--) cout << a[i]; + cout << endl; + return 0; +} +int main() { + double l, p, q; + cin >> l >> p >> q; + double t_total = 3 * l / (p + q); + double t1 = l / (p + q); + cout << (t_total - 2 * t1) * p << endl; +} +int n, k; +int a[122]; +bool vis[122]; +int ans; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= k; i++) { + int c1 = 0, c2 = 0; + memset(vis, 0, sizeof(vis)); + for (int j = i; j <= n; j += k) vis[j] = 1; + for (int j = 1; j <= n; j++) { + if (!vis[j]) { + if (a[j] == 1) + c1++; + else + c2++; + } + } + int tmp = abs(c1 - c2); + ans = max(ans, tmp); + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + stack stck; + for (int i = 0; i < s.length(); i++) { + if (stck.empty()) + stck.push(s[i]); + else if (s[i] == '0' && stck.top() == '1') + stck.pop(); + else if (s[i] == '1' && stck.top() == '0') + stck.pop(); + else + stck.push(s[i]); + } + cout << stck.size() << endl; + return 0; +} +int main() { + int n, tmp, tmo; + cin >> n; + tmp = tmo = n; + string ans(""), Cmp(""); + while (tmp > 0) { + if (tmp % 4 == 0) { + for (int i = 0; i < tmp / 4; ++i) ans += "4"; + tmp = 0; + break; + } else + ans += "7", tmp -= 7; + } + while (tmo > 0) { + if (tmo % 7 == 0) { + for (int i = 0; i < tmo / 7; ++i) Cmp += "7"; + tmo = 0; + break; + } else + Cmp += "4", tmo -= 4; + } + sort(ans.begin(), ans.end()); + sort(Cmp.begin(), Cmp.end()); + if (!tmp && !tmo) { + if (ans.size() <= Cmp.size()) + cout << ans << "\n"; + else + cout << Cmp << "\n"; + } else if (!tmp) + cout << ans << "\n"; + else if (!tmo) + cout << Cmp << "\n"; + else + cout << -1 << "\n"; + return 0; +} +int main() { + int n, p, halfs = 0; + long long current = 0; + cin >> n >> p; + stack s; + string temp; + for (int i = 0; i < n; i++) { + cin >> temp; + s.push(temp); + if (temp == "halfplus") halfs++; + } + if (s.top() == "halfplus") { + current = 1; + s.pop(); + } + while (!s.empty()) { + current *= 2; + if (s.top() == "halfplus") current++; + s.pop(); + } + current = current * p - (0.5 * p * halfs); + cout << current << endl; + return 0; +} +const int MAX = 1e5 + 9; +; +const int MAX1 = 3e8 + 9; +const double pi = acos(-1); +const long long int inf = INT_MAX; +const long long int mod = 1e9; +int main() { + int t; + cin >> t; + while (t--) { + int a, b; + cin >> a >> b; + long long cnt = 0; + while (a > 0 && b > 0) { + if (a > b) { + cnt = cnt + a / b; + a = a % b; + } else { + cnt = cnt + b / a; + b = b % a; + } + } + cout << cnt << "\n"; + } +} +int main() { + int n, h, k, a, b; + cin >> n >> h >> a >> b >> k; + for (int i = 0; i < k; i++) { + long long ans = 0, t1, t2, f1, f2; + cin >> t1 >> f1 >> t2 >> f2; + ans += abs(t1 - t2); + if (f1 >= a && f1 <= b || t1 == t2) + ans += abs(f1 - f2); + else { + if (abs(f1 - a) < abs(f1 - b)) { + ans += abs(a - f2); + ans += abs(f1 - a); + } else { + ans += abs(b - f2); + ans += abs(b - f1); + } + } + cout << ans << endl; + } + return 0; +} +int cmpfunc(const void *a, const void *b) { + return (*(int *)a - *(int *)b); +} +int main() { + long long int n, k; + long long int ans = 0; + cin >> n >> k; + long long int a, b; + for (size_t i = 0; i < n; i++) { + cin >> a >> b; + ans = ans + b - a + 1; + } + if (ans % k != 0) { + cout << k - ans % k << "\n"; + } else { + cout << "0\n"; + } + return 0; +} +int main() { + int n, x, temp = 0; + cin >> n; + int arr[n]; + cin >> x; + for (int i = 1; i < n; i++) cin >> arr[i]; + int a = 0, b = 0, c = 0; + sort(arr + 1, arr + n); + a = arr[n - 1]; + while (x <= a) { + sort(arr + 1, arr + n); + a = arr[n - 1]; + if (x <= a) { + arr[n - 1]--; + x++; + c++; + } else { + c = 0; + } + sort(arr + 1, arr + n); + a = arr[n - 1]; + } + cout << c << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[1005]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int cnt = 0; + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] > 1) { cnt += (a[i] - a[i - 1]) - 1; } + } + cout << cnt << endl; + } + return 0; +} +int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; +int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; +void fast() {} +const long long md = 1e9 + 7; +int main() { + fast(); + long long n, arr[100000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + long long pre = arr[0], count = 0, maxcount = 0; + for (int i = 0; i < n; i++) { + if (arr[i] >= pre) { + count++; + maxcount = max(maxcount, count); + } else { + count = 1; + } + pre = arr[i]; + } + cout << maxcount << endl; + return 0; +} +int main() { + double p1, p2, m1, m2; + cin >> p1 >> p2 >> m1 >> m2; + int ans1, ans2; + ans1 = max(((3.0 * p1) / 10.0), (p1 - (p1 / 250) * m1)); + ans2 = max(((3.0 * p2) / 10.0), (p2 - (p2 * m2) / 250.0)); + if (ans1 == ans2) + cout << "Tie" << endl; + else if (ans1 > ans2) + cout << "Misha" << endl; + else + cout << "Vasya" << endl; +} +int main() { + int n, a, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + sum += a; + } + cout << sum / n << endl; + return 0; +} +const int mod = 1e9 + 7; +const int maxn = 1e6; +long long n, m; +long long dp[120][4]; +int main() { + int a, b, c; + cin >> n >> a >> b >> c; + memset(dp, 0, sizeof dp); + dp[1][2] = maxn; + dp[1][3] = maxn; + for (int i = 2; i <= n; i++) { + dp[i][1] = min(dp[i - 1][2] + a, dp[i - 1][3] + b); + dp[i][2] = min(dp[i - 1][1] + a, dp[i - 1][3] + c); + dp[i][3] = min(dp[i - 1][1] + b, dp[i - 1][2] + c); + } + cout << min(dp[n][1], min(dp[n][2], dp[n][3])) << endl; + return 0; +} +int main() { + string a, b; + int scorea = 0, scoreb = 0; + cin >> a >> b; + for (int i = 0; i < a.size(); i += 2) { + if (a[i] == '(') { + if (b[i] == '(') + continue; + else if (b[i] == '[') + scoreb++; + else + scorea++; + } else if (a[i] == '[') { + if (b[i] == '(') + scorea++; + else if (b[i] == '[') + continue; + else + scoreb++; + } else { + if (b[i] == '(') + scoreb++; + else if (b[i] == '[') + scorea++; + else + continue; + } + } + if (scorea == scoreb) + puts("TIE"); + else + puts((scorea > scoreb) ? "TEAM 1 WINS" : "TEAM 2 WINS"); +} +long long n, i, j, ans = 0; +int main() { + string s1, s2; + cin >> s1 >> s2; + reverse(s2.begin(), s2.end()); + stringstream geek(s2), geek1(s1); + long long a; + geek >> a; + long long b; + geek1 >> b; + cout << a + b << endl; +} +const int MAXP = 55; +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << max(0, a[2] - a[0] - a[1] + 1) << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n >= k) + cout << 1 << endl; + else { + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + } + return 0; +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x % m * x % m) % m; + if (b % 2) x = (x % m * a % m) % m; + return x; +} +string s; +int n; +int f(int i, int k) { + if (i == n) return 1; + for (; s[i] - 'a' < k; s[i]++) { + if (i && s[i] == s[i - 1]) continue; + if (i > 1 && s[i] == s[i - 2]) continue; + if (f(i + 1, k)) return 1; + ; + } + s[i] = 'a'; + return 0; +} +int main() { + int k; + cin >> n >> k; + cin >> s; + s[s.size() - 1]++; + if (f(0, k)) + cout << s << endl; + else + cout << "NO" << endl; + ; +} +int main() { + string a; + getline(cin, a); + if (a[0] >= 'a' && a[0] <= 'z') a[0] -= 32; + cout << a << endl; +} +const int MOD = 1e9 + 7; +double gcd(double a, double b) { + return a < 0.01 ? b : gcd(fmod(b, a), a); +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int max(long long int a, long long int b, long long int c) { + return max(a, max(b, c)); +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int min(long long int a, long long int b, long long int c) { + return min(a, min(b, c)); +} +long long int power(long long int x, long long int y) { + long long int res = 1; + x = x % MOD; + while (y > 0) { + if (y & 1) res = (res * x) % MOD; + y = y >> 1; + x = (x * x) % MOD; + } + return res; +} +void swap(char *x, char *y) { + char temp; + temp = *y; + *y = *x; + *x = temp; +} +long long int mod(long long int a) { + if (a > 0) + return a; + else + return -a; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int r = ceil((n * y) / 100.0); + cout << (((r - x) >= 0) ? r - x : 0) << endl; + return 0; +} +int main() { + int n, k, x, p, t = 0, i = 0; + cin >> n >> k >> x; + int L[n]; + for (i = 0; i < n; i++) { + cin >> p; + L[i] = p; + } + int s = sizeof(L) / sizeof(L[0]); + sort(L, L + s); + for (int i = 0; i < n - k; i++) { t += L[i]; } + t += (k * x); + cout << t << endl; +} +int main() { + long long int n; + cin >> n; + long long int d[n]; + for (int i = 0; i < n; i++) { cin >> d[i]; } + long long int s, t; + cin >> s >> t; + if (s > t) { + long long int temp = s; + s = t; + t = temp; + } + long long int dist1 = 0, dist2 = 0; + for (int i = s - 1; i < t - 1; i++) { dist1 += d[i]; } + bool flag = true; + for (int i = t - 1; i != s - 1; i++) { + if (i % n == 0 && flag) { + i = -1; + flag = false; + continue; + } + dist2 += d[i]; + } + if (dist2 > dist1) + cout << dist1 << endl; + else + cout << dist2 << endl; + return 0; +} +int main() { + int n, k, i, p = 0, d; + cin >> n >> k; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] <= k) { + p++; + } else { + if (a[i] % k == 0) + p = p + (a[i] / k); + else + p = p + (a[i] / k) + 1; + } + } + if (p % 2 == 0) + d = p / 2; + else + d = (p / 2) + 1; + cout << d << endl; +} +int t; +long long L, v, l, r; +int main() { + cin >> t; + while (t--) { + long long ans = 0; + cin >> L >> v >> l >> r; + ans = (l - 1) / v + L / v - r / v; + cout << ans << endl; + } +} +int marked[101]; +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (long long i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + cout << "YES" << endl; + goto pause; + } + } + cout << "NO" << endl; +pause: + int pause; + cin >> pause; + return 0; +} +int getNextGap(int gap) { + gap = (gap * 10) / 13; + if (gap < 1) return 1; + return gap; +} +void combSort(long long int a[], long long int n) { + int gap = n; + bool swapped = true; + while (gap != 1 || swapped == true) { + gap = getNextGap(gap); + swapped = false; + for (int i = 0; i < n - gap; i++) { + if (a[i] > a[i + gap]) { + swap(a[i], a[i + gap]); + swapped = true; + } + } + } +} +int main() { + long long int numberOfElements; + cin >> numberOfElements; + long long int arr[numberOfElements]; + for (int i = 0; i < numberOfElements; i++) { cin >> arr[i]; } + combSort(arr, numberOfElements); + int counter = 0; + for (int i = 0; i < numberOfElements; i++) { + if (arr[i] == 0) { continue; } + if (arr[i] == arr[i + 1]) { + counter++; + if (arr[i + 1] == arr[i + 2]) + { + cout << "-1" << endl; + return 0; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + int t[3]; + for (int i = 0; i < 3; i++) cin >> t[i]; + sort(t, t + 3); + cout << t[2] - t[0] << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int mn = numeric_limits::max(); + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + if (k % input == 0) mn = min(mn, k / input); + } + cout << mn << endl; + return 0; +} +const int maxn = 1e5 + 5; +char str[maxn]; +bool vis[305]; +inline int getint() { + int r = 0, k = 1; + char c = getchar(); + for (; c < '0' || c > '9'; c = getchar()) + if (c == '-') k = -1; + for (; c >= '0' && c <= '9'; c = getchar()) r = r * 10 + c - '0'; + return r * k; +} +int main() { + int n = getint(); + int r = 0, l = 0; + while (n--) { + int x = getint(); + int y = getint(); + if (x > 0) r++; + if (x < 0) l++; + } + if (r > 1 && l > 1) + puts("No"); + else + puts("Yes"); + return 0; +} +int n, d; +int a[105]; +int main() { + while (cin >> n >> d) { + for (int i = 0; i < n; ++i) cin >> a[i]; + sort(a, a + n); + int maxlen = 0; + for (int i = 0; i < n; ++i) { + int thislen = 1; + for (int j = i + 1; j < n; ++j) { + if (a[j] - a[i] > d) break; + thislen++; + } + maxlen = max(thislen, maxlen); + } + cout << n - maxlen << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + vector coins; + for (long long i = 0; i < n; i++) { + long long aux; + cin >> aux; + coins.push_back(aux); + } + sort(coins.begin(), coins.end()); + long long cont = 1, resp = 1; + for (long long i = 0; i < n; i++) { + if (coins[i] == coins[i - 1]) { + cont++; + } else { + if (cont > resp) { resp = cont; } + cont = 1; + } + } + if (cont > resp) { resp = cont; } + cout << resp << endl; + return 0; +} +int main() { + int n, x, rem, value; + int sum = 0; + int cards = 0; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> value; + sum += value; + } + rem = 0 - sum; + rem = abs(rem); + while (rem != 0) { + if (rem > x) { + rem = rem - x; + cards++; + } else { + cards++; + rem = 0; + } + } + cout << cards << endl; + return 0; +} +int main() { + int n, k, c = 0, num, cont = 0, cont2 = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> num; + while (num != 0) { + int dig = num % 10; + num /= 10; + if (dig == 4 || dig == 7) cont++; + } + if (cont > k) cont2++; + cont = 0; + } + cout << n - cont2 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + while (n--) { + int a; + cin >> a; + int num = 0; + while (a != 0) { + if (a % 10 == 4 || a % 10 == 7) { num++; } + a /= 10; + } + if (num <= k) { ans++; } + } + cout << ans << endl; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +long long x; +int main() { + cin >> x; + if (x % 10 == 0) + cout << x << endl; + else if (x % 10 <= 5) + cout << (x / 10) * 10 << endl; + else + cout << (x / 10) * 10 + 10 << endl; +} +int main() { + int n, a, i = 4, count = 0; + int ar[] = {1, 5, 10, 20, 100}; + cin >> n; + for (;;) { + if (i == -1) { break; } + if (n >= ar[i]) { + n -= ar[i]; + count++; + } else { + i--; + } + } + cout << count << endl; + return 0; +} +int a, b, c; +int main() { + cin >> a >> b >> c; + cout << a * b + b * c + c * a - a - b - c + 1 << endl; +} +long long ret[50]; +int main() { + int n, p; + cin >> n >> p; + long long ans = 1, tmp = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "half") + ret[i] = 1; + else + ret[i] = 2, tmp++; + } + for (int i = n - 2; i >= 0; i--) { + if (ret[i] == 1) + ans = ans * 2; + else + ans = ans * 2 + 1; + } + ans = ans * p - tmp * (p / 2); + cout << ans << endl; + return 0; +} +const int INF = 0x7fffffff; +const int inf = 0x3f3f3f3f; +const int maxn = 200005; +const int N = 105; +inline void read(long long &x) { + long long f = 1; + x = 0; + char s = getchar(); + while (s < '0' || s > '9') { + if (s == '-') f = -1; + s = getchar(); + } + while (s >= '0' && s <= '9') { + x = x * 10 + s - '0'; + s = getchar(); + } + x *= f; +} +long long n, k, a[maxn], ans, cnt; +int main() { + read(n), read(k); + for (int i = 0; i < n; i++) read(a[i]); + for (int i = 0; i < n; i++) { ans += (a[i] - 1) / k + 1; } + cout << (ans + 1) / 2 << endl; + return 0; +} +int hcf(int l, int m) { + int temp; + while (m > 0) { + temp = m; + m = l % m; + l = temp; + } + return l; +} +int main() { + int n; + cin >> n; + int x[n]; + for (int i = 0; i < n; i++) { cin >> x[i]; } + int r = x[0]; + for (int i = 1; i < n; i++) { r = hcf(r, x[i]); } + cout << r * n << endl; + return 0; +} +int a[1100]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long sa = 0, sb = 0, sc = 0; + for (int i = 1; i <= n; i++) { + int t = i % 3; + if (t == 1) + sa += a[i]; + else if (t == 2) + sb += a[i]; + else if (t == 0) + sc += a[i]; + } + long long maxx = max(max(sa, sb), sc); + if (sa == maxx) + puts("chest"); + else if (sb == maxx) + puts("biceps"); + else if (sc == maxx) + puts("back"); + return 0; +} +long long a, b, c; +int main() { + cin >> a >> b >> c; + for (long long i = 0; i <= 1e6; i++) + if (i * b >= (a * c) - (b * c)) { + cout << i << endl; + return 0; + } + return 0; +} +int n, a, b; +int main() { + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +inline int MAX(int a, int b) { + return (a > b) ? (a) : (b); +} +inline int MIN(int a, int b) { + return (a < b) ? (a) : (b); +} +int const sz = 1e6 + 10; +int tobin(long long x) { + int res = 0, r; + long long p = 1; + while (x > 0) { + r = (x % 10) % 2; + res += r * p; + p = p * 2; + x = x / 10; + } + return res; +} +int main() { + long long i, j, n, x; + int m[sz + 1]; + char a; + cin >> n; + for (i = 0; i <= sz; i++) m[i] = 0; + for (i = 1; i <= n; i++) { + cin >> a >> x; + if (a == '+') m[tobin(x)]++; + if (a == '-') m[tobin(x)]--; + if (a == '?') cout << m[tobin(x)] << "\n"; + } + return 0; +} +int main() { + int a, b; + char x[100], t[100]; + while (cin >> a) { + b = 0; + for (int i = 0; i < a; i++) cin >> x[i]; + if (x[0] == '0') + cout << 1 << endl; + else { + int i; + for (i = 1; i < a; i++) { + if (x[i] == '0') { + cout << i + 1 << endl; + break; + } + } + if (i == a) cout << a << endl; + } + } + return 0; +} +int main() { + int n, m, i, a, b, cnt = 0; + cin >> n >> m; + i = 0; + while (i <= sqrt(n)) { + a = i; + b = n - (a * a); + if (b >= 0) { + if ((a + (b * b)) == m) cnt++; + } + i++; + } + cout << cnt << endl; + return 0; +} +int n, t, d[100]; +int main() { + cin >> n >> t; + for (int i = 1; i <= n; ++i) { + cin >> d[i]; + d[i] = 86400 - d[i]; + t -= d[i]; + if (t <= 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, a, b, cnt1, cnt2; + while (cin >> n) { + cnt1 = 0, cnt2 = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a > 0) + cnt1++; + else if (a <= 0) + cnt2++; + } + if (cnt1 >= n - 1 || cnt2 >= n - 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +int main() { + int n; + int row[100] = {}, col[100] = {}; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + char c; + cin >> c; + if (c == 'C') { + row[i]++; + col[j]++; + } + } + int ans = 0; + for (int i = 0; i < n; i++) ans += (row[i] * (row[i] - 1) + col[i] * (col[i] - 1)) / 2; + cout << ans << endl; +} +const long long int INF = (1LL << 60) - 1; +const long long int MAX = 2000000000000; +map p; +map p2; +map p3; +int freq[5000][101] = {0}; +long long int fast_exp(long long int base, long long int exp, long long int m) { + long long int res = 1; + while (exp > 0) { + if (exp % 2 == 1) { res = (res * base) % m; } + base = (base * base) % m; + exp /= 2; + } + return res % m; +} +int main() { + long long int n, left = -1, right = -1, ans = MAX; + cin >> n; + string s; + cin >> s; + long long int x[n + 1] = {0}; + for (int i = 1; i <= n; i++) cin >> x[i]; + for (int i = 0; i < n; i++) { + if (s[i] == 'R') { + left = x[i + 1]; + right = -1; + } + if (s[i] == 'L') { + if (left >= 0) { + right = x[i + 1]; + long long int time = (right - left) / 2; + ans = min(ans, time); + left = -1; + } + } + } + if (ans == MAX) { + cout << -1 << endl; + return 0; + } + cout << ans << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + for (int i = 1; i <= m; i++) { + if (i % 2 == 1) { + for (int j = 1; j <= n; j++) cout << "#"; + cout << endl; + } else { + if (i % 4 == 2) { + for (int j = 1; j < n; j++) cout << "."; + cout << "#" << endl; + } + if (i % 4 == 0) { + cout << "#"; + for (int j = 1; j < n; j++) cout << "."; + cout << endl; + } + } + } + return 0; +} +int main() { + int n; + int a, b, cnt = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + int s = b - a; + if (s >= 2) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (n * 2) - (n / 2) << endl; +} +int main() { + int N; + cin >> N; + string str; + cin >> str; + string oldstr = str; + int t = 1; + for (int i = 0; i < N; i++) { + int v = str[i] - '0'; + int old_t = t; + t = (v + old_t) / 2; + v = (v + old_t) % 2; + str[i] = v + '0'; + } + int result = 0; + for (int i = 0; i < N; i++) { + if (str[i] != oldstr[i]) { result++; } + } + cout << result << endl; + return 0; +} +int main() { + int n; + ifstream ff("file.txt"); + cin >> n; + int v; + int Minv = INT_MAX; + for (int i = 0; i < n; i++) { + cin >> v; + if (v < Minv) { Minv = v; } + } + int m; + cin >> m; + vector v1(m); + for (int i = 0; i < m; i++) { cin >> v1[i]; } + sort(v1.begin(), v1.end()); + long long sum = 0; + bool b1 = true; + v = Minv; + int kol = v; + for (int i = m - 1; i >= 0; i--) { + if (b1 == true) { + sum += v1[i]; + kol--; + if (kol == 0) { + kol = 2; + b1 = false; + } + } else if (b1 == false) { + kol--; + if (kol == 0) { + kol = v; + b1 = true; + } + } + } + cout << sum << endl; + return 0; +} +inline long long read() { + char ch = getchar(); + long long x = 0, f = 1; + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +inline void print(long long k) { + if (k < 0) k = -k, putchar('-'); + if (k > 9) print(k / 10); + putchar(k % 10 + 48); +} +inline void println(long long k) { + print(k); + putchar('\n'); +} +inline void printsp(long long k) { + print(k); + putchar(' '); +} +int main() { + long long s = read(), x = read(); + long long sum = (s - x) >> 1; + if (x > s || (sum * 2 + x) != s || sum < 0 || (x & sum) != 0) { + println(0); + return 0; + } + long long cnt = 0; + while (x) { + if (x & 1) ++cnt; + x >>= 1; + } + long long ans = 1LL << cnt; + if (!sum) ans -= 2; + println(ans); + return 0; +} +int main() { + int maks, mini, n, x, jwb = 0; + cin >> n; + cin >> maks; + mini = maks; + for (int i = 1; i < n; i++) { + cin >> x; + if (x > maks) { + jwb++; + maks = x; + } else if (x < mini) { + jwb++; + mini = x; + } + } + cout << jwb << endl; +} +int main() { + string s; + cin >> s; + int l = s.size(), k, j; + k = 26 - l; + j = k * (l + 1); + int p = l - 1; + j += (l * p); + j += l; + cout << j << endl; +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + cout << n / 2 << endl; + return 0; + } else if (n == 1) { + cout << "-1\n"; + return 0; + } + long long int div; + div = n / 2; + n = (n * (-1)) + div; + cout << n << endl; + return 0; +} +vector a; +vector b; +int main() { + int na, nb, counta = 0, countb = 0; + cin >> na >> nb; + int k, m, A, B; + cin >> k >> m; + for (int i = 0; i < na; i++) { + cin >> A; + a.push_back(A); + } + for (int i = 0; i < nb; i++) { + cin >> B; + b.push_back(B); + } + sort(a.begin(), a.end()); + sort(b.rbegin(), b.rend()); + if (a[k - 1] < b[m - 1]) + cout << "YES\n"; + else + cout << "NO\n"; +} +int main() { + long long n, m, a; + cin >> n >> m >> a; + long long nN, nM; + nN = n / a; + nM = m / a; + if (n % a != 0) { nN++; } + if (m % a != 0) { nM++; } + cout << nN * nM << endl; + return 0; +} +int main() { + long long n, cnt = 0; + cin >> n; + vector x(n); + set y; + for (long long i = 0; i < n; i++) { + cin >> x[i]; + y.insert(x[i]); + } + if (n <= 2 || y.size() <= 2) + cout << "0" << endl; + else { + sort(x.begin(), x.end()); + for (long long i = 0; i < n; i++) { + if (x[i] != x[0] && x[i] != x[n - 1]) cnt++; + } + cout << cnt << endl; + } + return 0; +} +long long x, n, number, times; +int main() { + x = 2; + cin >> n; + for (long long i = 1; i <= n; i++) { + number = i * (i + 1) * (i + 1); + times = number - x / i; + x = i * (i + 1); + cout << times << endl; + } + return 0; +} +string s; +void rec(unsigned id = 0) { + if (id == s.size()) return; + string res = "O-|"; + char c = s[id] - '0'; + if (c >= 5) { + swap(res[0], res[1]); + c -= 5; + } + res += "-OOOO"; + for (int i = 3; c--; ++i) { swap(res[i], res[i + 1]); } + rec(id + 1); + cout << res << '\n'; +} +int main() { + cin >> s; + rec(); + return true & false; +} +int main() { + string s; + cin >> s; + int b[26] = {0}; + int l[26] = {0}; + int n = s.length(); + for (int i = 0; i < n; i++) { + if (s[i] >= 'a' && s[i] <= 'z') + l[s[i] - 'a']++; + else + b[s[i] - 'A']++; + } + int count = b[1]; + count = min(count, l[1]); + count = min(count, l[0] / 2); + count = min(count, l[18]); + count = min(count, l[20] / 2); + count = min(count, l[11]); + count = min(count, l[17]); + cout << count << endl; +} +int main() { + int n; + cin >> n; + while (n--) { + long long a, b; + cin >> a >> b; + long long x = max(a, b), y = min(a, b), cnt = 0; + while (x > 0 && y > 0) { + cnt += (x / y); + x -= (x / y) * y; + long long m = max(x, y), n = min(x, y); + x = m; + y = n; + } + cout << cnt << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector q(1000, 0); + q[0] = 1; + for (int i = 0; i < n; ++i) { + int a, b; + cin >> a >> b; + if (q[a] == 1) { + while (a <= b) { + q[a] = 1; + ++a; + } + } + } + bool f = true; + for (int i = 0; i <= m; ++i) { f &= q[i]; } + if (f) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const long long MOD = 1e9 + 7; +int n, k, c; +int dd[400]; +int main() { + cin >> n >> k >> c; + for (int i = 0; i < c; i++) cin >> dd[i]; + if (c == 0) { + cout << n / k << endl; + return 0; + } + int ans = (dd[0] - 1) / k + c; + ans += (n - dd[c - 1]) / k; + for (int i = 1; i <= c - 1; i++) ans += (dd[i] - dd[i - 1] - 1) / k; + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long ans = 0; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + for (long long i = 0; i < n; i++) { + if (a[i] == 1 || a[i - 1] + a[i + 1] == 2) ans++; + } + cout << ans << '\n'; + return 0; +} +long long i, j, k, n, x, z, x1, x2, z1, z2; +int main() { + cin >> n >> z; + for (i = 0; i < n; i++) { + cin >> x1 >> z1; + x2 = 7 - x1; + z2 = 7 - z1; + if (x2 == z || z2 == z || x1 == z || z1 == z) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +const int inf = (int)1e9 + 7; +const int N = (int)3e5 + 7; +int n; +int a[N]; +int ans = inf; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int cnt = n / 2 - 1; + for (int i = 0; i <= cnt; i++) { ans = min(ans, a[n - (cnt - i)] - a[i + 1]); } + cout << ans << endl; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long ans = (c + a - 1) * (b + a - 1) - a * (a - 1); + cout << ans << endl; + return 0; +} +void fast_io() {} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1); +const long long MOD = (long long)1e9 + 7; +const int N = 2e5 + 5; +int main() { + int a[110], b[110], n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + if (k >= 2) { + cout << "Yes\n"; + return 0; + } + for (int i = 0; i < n; i++) + if (a[i] == 0) a[i] = b[0]; + for (int i = 0; i < n - 1; i++) { + if (a[i] > a[i + 1]) { + cout << "Yes\n"; + return 0; + } + } + cout << "No\n"; + return 0; +} +int main() { + int n; + cin >> n; + bool pres[100010]{false}; + int count = 0, mx = 0; + for (int i = 0; i < 2 * n; ++i) { + int p; + cin >> p; + if (!pres[p]) + pres[p] = true, count++; + else + pres[p] = false, count--; + mx = max(count, mx); + } + cout << mx << endl; + return 0; +} +void moveS(int pos, int d, int dest, string com, string s) { + while (pos != dest) { + cout << "PRINT" + << " " << s[pos] << endl; + cout << com << endl; + pos += d; + } + cout << "PRINT" + << " " << s[pos] << endl; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + if (k <= n / 2) { + k--; + while (k > 0) { + cout << "LEFT" << endl; + k--; + } + moveS(k, 1, n - 1, "RIGHT", s); + } else { + k--; + while (k < n - 1) { + cout << "RIGHT" << endl; + k++; + } + moveS(k, -1, 0, "LEFT", s); + } + return 0; +} +int a[205] = {0}; +int N; +int main() { + cin >> N; + N *= 2; + for (int i = 0; i < N; i++) { cin >> a[i]; } + sort(a, a + N); + N /= 2; + N -= 1; + if (a[N] >= a[N + 1]) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int n, sum1 = 0, sum2 = 0, t; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t; + sum1 = sum1 | t; + } + for (int i = 0; i < n; i++) { + cin >> t; + sum2 = sum2 | t; + } + cout << sum1 + sum2 << endl; + return 0; +} +const int maxn = 1005; +int a[maxn], b[maxn], fa[maxn], fb[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (i == 1) + fa[i] = a[i]; + else + fa[i] = fa[i - 1] | a[i]; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + if (i == 1) + fb[i] = b[i]; + else + fb[i] = fb[i - 1] | b[i]; + } + long long res = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + long long t = fb[i] + fa[i] - fa[j - 1] - fb[j - 1]; + res = max(res, t); + } + } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int max = 1, cmax = 1, prev, temp; + cin >> prev; + for (int i = 1; i < n; i++) { + int temp; + cin >> temp; + if (temp >= prev) { + cmax++; + } else { + if (cmax > max) max = cmax; + cmax = 1; + } + prev = temp; + } + if (cmax > max) max = cmax; + cout << max << endl; +} +const long long int INF = (long long int)(8e16); +const long long int MOD = 1000000007; +map mp; +void print() { + cout << -1 << '\n'; + exit(0); +} +int main() { + long long int n; + cin >> n; + for (int i = 1; i <= n; i++) { + long long int a; + cin >> a; + mp[a]++; + } + long long int ans = 0; + map::iterator it; + for (it = mp.begin(); it != mp.end(); it++) { + if (it->second > 1 && it->second % 2 > 0 && it->first > 0) print(); + if (it->first > 0 && it->second > 2) print(); + if (it->first > 0) ans += it->second / 2; + } + cout << ans << '\n'; + return 0; +} +int main() { + long long a, b, x, y, z, q = 0, w = 0; + cin >> a >> b; + cin >> x >> y >> z; + q = 2 * x + y; + w = y + 3 * z; + long long ans = 0; + if ((q - a) > 0) ans = q - a; + if ((w - b) > 0) ans += (w - b); + cout << ans << '\n'; +} +int a[201010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int ans = 0x3f3f3f3f; + for (int i = 0; i + n / 2 < n; i++) ans = min(ans, a[i + n / 2] - a[i]); + cout << ans << endl; + return 0; +} +int a[105][105], b[105][105], c[105][105], n, m, k; +int buy(int x, int y) { + int v[105] = {0}; + int ans = 0, i; + int last = k; + while (last) { + int maxn = 0; + int maxi; + int num; + for (i = 1; i <= m; i++) { + if (v[i]) continue; + if (b[y][i] - a[x][i] > maxn) { + maxi = i; + maxn = b[y][i] - a[x][i]; + } + } + if (maxn == 0) break; + num = min(last, c[x][maxi]); + ans += num * maxn; + v[maxi] = 1; + last -= num; + } + return ans; +} +int main() { + int i, j; + string s; + cin >> n >> m >> k; + for (i = 1; i <= n; i++) { + cin >> s; + for (j = 1; j <= m; j++) { cin >> a[i][j] >> b[i][j] >> c[i][j]; } + } + int ans = 0; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { ans = max(ans, buy(i, j)); } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[35][35]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int hen[35], con[35]; + for (int i = 0; i < n; i++) { + int temp = 0; + int num = 0; + for (int j = 0; j < n; j++) { + temp += a[i][j]; + num += a[j][i]; + } + hen[i] = temp; + con[i] = num; + } + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (con[i] > hen[j]) { count++; } + } + } + cout << count << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int mod = (int)1e9 + 7; +const int maxn = (int)1e5 + 5; +int vis[30]; +int main() { + string s; + cin >> s; + int len = s.size(); + int n; + cin >> n; + if (n > len) return 0 * puts("impossible"); + for (int i = 0; i < len; i++) { vis[s[i] - 'a']++; } + int cnt = 0; + for (int i = 0; i < 26; i++) { + if (vis[i]) cnt++; + } + if (cnt >= n) + puts("0"); + else + cout << n - cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < n; j++) { + if (j < (n / 2 - i)) + cout << "*"; + else if (j >= (n / 2 - i) && j <= (n / 2 + i)) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + for (int i = 0; i < n; i++) { cout << "D"; } + cout << endl; + for (int i = n / 2 - 1; i >= 0; i--) { + for (int j = n - 1; j >= 0; j--) { + if (j < (n / 2 - i)) + cout << "*"; + else if (j >= (n / 2 - i) && j <= (n / 2 + i)) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int main() { + int k, a, b, v, x; + cin >> k >> a >> b >> v; + int ans = 0; + while (a > 0) { + if (b + 1 > k) { + x = k - 1; + b -= x; + a -= (x + 1) * v; + } else if (b + 1 > 0) { + a -= (b + 1) * v; + b = -1; + } else + a -= v; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + char ch, prev = 'z'; + cin >> n >> m; + bool flag = true; + for (int i = 0; i < n; i++) { + set st; + for (int j = 0; j < m; j++) { + cin >> ch; + st.insert(ch); + } + if (st.size() > 1 || ch == prev) flag = false; + prev = ch; + } + puts(flag ? "YES" : "NO"); + return 0; +} +string s; +string ans[111111]; +int main() { + getline(cin, s); + int n = s.size(), p = 0; + for (int i = 0; i < n; i++) { + if (s[i] == ',' || s[i] == '.' || s[i] == '!' || s[i] == '?') { + ans[p++] = " "; + ans[p - 1][0] = s[i]; + } else if (s[i] >= 'a' && s[i] <= 'z') { + int j = i; + for (; s[j] >= 'a' && s[j] <= 'z' && j < n;) { j++; } + ans[p++] = s.substr(i, j - i); + i = j - 1; + } + } + int l = 0; + for (int i = 0; i < p; i++) { + if (ans[i][0] >= 'a') { + if (l == 1) { cout << ' '; } + cout << ans[i]; + l = 1; + } else { + cout << ans[i] << ' '; + l = 0; + } + } + cout << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int s = 0; + for (int i = 0; i < n; ++i) { + int k; + cin >> k; + if (k > b && k < c) s++; + } + cout << s << endl; +} +int main() { + long long int n, k, s; + while (cin >> n >> k) { + s = n / k; + if (s % 2 == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int t; + string str; + cin >> t; + cin >> str; + int sum = 0; + for (int i = 0; i < t; i++) { + if (str[i] == '1') { + sum++; + } else { + cout << sum; + sum = 0; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int c = 0; + for (int i = 1; i < n; i++) { + int g = __gcd(i, n - 1); + if (g == 1) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int num, buy; + vector v; + cin >> num >> buy; + for (int i = 0; i < buy; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + int max = 0, min = 0, differ = 1000000; + for (int i = 0; i < v.size(); i++) { + if ((i + num) > v.size()) + break; + else { + min = min_element(v.begin() + i, v.begin() + (i + num)) - v.begin(); + max = max_element(v.begin() + i, v.begin() + (i + num)) - v.begin(); + if ((v.at(max) - v.at(min)) < differ) { differ = v.at(max) - v.at(min); } + } + } + for (int i = 0; i < v.size(); i++) { + int total = count(v.begin(), v.end(), v.at(i)); + if (total >= num) { + differ = 0; + break; + } + } + cout << differ << endl; +} +bool isprime[123457]; +vector prime; +int pri(int n) { + memset(isprime, true, sizeof(isprime)); + for (int i = 2; i * i <= n; i++) { + if (isprime[i]) { + for (int j = 2 * i; j <= n; j += i) isprime[j] = false; + } + } + for (int i = 2; i <= n; i++) + if (isprime[i]) prime.push_back(i); +} +vector prifac(int n) { + vector ans; + for (int i = 0; (i < prime.size()) && (prime[i] < n); i++) { + while (n % prime[i] == 0) { + ans.push_back(prime[i]); + n = n / prime[i]; + } + } + return ans; +} +int main() { + int n, k; + cin >> n >> k; + pri(123456); + vector ans = prifac(n); + int a = 1; + int i = 0; + vector ans1; + while ((i < ans.size()) && (i != k - 1)) { + a = a * ans[i]; + ans1.push_back(ans[i]); + i++; + } + a = n / a; + if ((ans1.size() == k - 1) && (a != 1)) { + for (int i = 0; i < ans1.size(); i++) cout << ans1[i] << " "; + cout << a << endl; + } else + cout << -1 << endl; +} +int a[50][50], R[50], C[50]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> a[i][j]; + R[i] += a[i][j]; + C[j] += a[i][j]; + } + } + int cnt = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (C[j] > R[i]) cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int i, j, n, m; + cin >> n >> m; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (i % 2 == 0) + cout << "#"; + else if (i % 4 == 1 && j == m - 1) + cout << "#"; + else if (i % 4 == 3 && j == 0) + cout << "#"; + else + cout << "."; + } + cout << endl; + } +} +const long long mod = 1e9 + 7; +const int N = 1e5 + 5; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long pwr(long long x, long long y); +bool isprime(long long x); +vector v; +int main() { + int n, x; + cin >> n; + while (n--) { + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + cout << v[v.size() - 1] << ' '; + for (int i = 1; i < v.size() - 1; i++) { cout << v[i] << ' '; } + cout << v[0] << endl; + return 0; +} +long long pwr(long long x, long long y) { + long long ans = 1; + x = x % mod; + while (y > 0) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y = y / 2; + } + return ans; +} +bool isprime(long long x) { + if (x < 2) return false; + if (x < 4) return true; + if (x % 2 == 0 || x % 3 == 0) return false; + for (long long i = 5; i * i <= x; i += 6) { + if (x % i == 0 || x % (i + 2) == 0) return false; + } + return true; +} +const int Inf = 1e9; +int main() { + int n; + long long x, y; + while (cin >> n >> x >> y) { + string str, s; + cin >> str; + s += str[0]; + for (int i = 1; i < n; ++i) { + if (str[i] != str[i - 1]) { s += str[i]; } + } + int cnt = s.length() / 2; + if (s[0] == '0' && s[s.length() - 1] == '0') ++cnt; + long long ans = y * cnt; + for (int i = 0; i < cnt; ++i) { ans = min(ans, x * i + y * (cnt - i)); } + cout << ans << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int mn = min(a, b), ans = 1; + for (int i = 2; i <= mn; i++) ans *= i; + cout << ans << endl; + return 0; +} +int main() { + int n, p = 0, q = 0, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a < 0) + sum -= a; + else + sum += a; + } + cout << sum << endl; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n, m; + cin >> n >> m; + vector g, w; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + g.push_back(a); + } + for (int i = 0; i < m; i++) { + int a; + cin >> a; + w.push_back(a); + } + int j = 0, ans = 0; + for (int i = 0; i < n; i++) { + if (j < m and g[i] <= w[j]) { + j++; + ans++; + } + } + cout << ans << endl; + return 0; +} +map, long long> value; +long long getPr(long long u, long long v) { + if (u == v) return u; + if (u > v) return getPr(u / 2, v); + if (u < v) return getPr(u, v / 2); +} +long long getAns(long long start, long long finish) { + if (start == finish) return 0; + return value[make_pair(start / 2, start)] + getAns(start / 2, finish); +} +void setTree(long long v, long long end, long long c) { + if (v == end) + return; + else { + value[make_pair(v / 2, v)] += c; + setTree(v / 2, end, c); + } +} +int main() { + long long q; + cin >> q; + for (long long i = 0; i < q; i++) { + char c; + cin >> c; + if (c == '1') { + long long v, u, w; + cin >> u >> v >> w; + long long pr = getPr(u, v); + setTree(u, pr, w); + setTree(v, pr, w); + } else { + long long v, u; + cin >> u >> v; + long long pr = getPr(u, v); + cout << getAns(u, pr) + getAns(v, pr) << endl; + } + } + return 0; +} +int main() { + long n, arr[10000], counter = 0; + int akmal = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[i] == 1) { + counter++; + akmal = 1; + } else if (arr[i] != arr[i + 1] && akmal == 1) { + counter++; + } else if (arr[i] == arr[i + 1] && arr[i] == 0) { + i++; + akmal = 0; + } + } + cout << counter << endl; + return 0; +} +int main() { + int a; + cin >> a; + cout << ((a + 1) / 2) % 2 << "\n"; + return 0; +} +int main() { + long long n; + cin >> n; + vector v(n); + vector v1(n); + for (long long i = 0; i < n; i++) { + cin >> v[i]; + v1[i] = v[i]; + } + sort(v1.begin(), v1.end()); + for (long long i = 0; i < n; i++) { + if (v[i] == v1[i]) { + continue; + } else { + for (long long j = i + 1; j < n; j++) { + if (v[j] != v1[j] && v[j] == v1[i]) { + v[j] = v[i]; + v[i] = v1[i]; + } + } + } + break; + } + for (long long i = 0; i < n - 1; i++) { + if (v[i] > v[i + 1]) { + cout << "NO" + << "\n"; + return 0; + } + } + cout << "YES" + << "\n"; +} +int n, m, x, y, kol = 0, q = 0, l, r; +pair a[100000], b[100000], c[100000]; +int main() { + cin >> n >> m >> x >> y; + for (int i = 0; i < n; i++) { + cin >> a[i].first; + a[i].second = i + 1; + } + for (int i = 0; i < m; i++) { + cin >> b[i].first; + b[i].second = i + 1; + } + sort(a, a + n); + sort(b, b + m); + l = 0; + r = 0; + for (; l < n && r < m;) { + if (a[l].first - x <= b[r].first && b[r].first <= a[l].first + y) { + c[q].first = a[l].second; + c[q].second = b[r].second; + l++; + r++; + kol++; + q++; + } else { + if (a[l].first - x > b[r].first) + r++; + else + l++; + } + } + cout << kol << "\n"; + for (int i = 0; i < kol; i++) cout << c[i].first << ' ' << c[i].second << "\n"; + return 0; +} +const int N = 50 + 10, INF = 1e9 + 7; +int in() { + int ret; + cin >> ret; + return ret; +} +int n, m; +set b; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + int k; + cin >> k; + while (k--) b.insert(in()); + } + cout << (((int)b.size() == m) ? "YES" : "NO") << '\n'; + return 0; +} +int a, b, c, n; +int main() { + cin >> a >> b >> c >> n; + int num = a + b - c; + int t = n - 1; + if (t >= num && num >= 0 && a >= c && b >= c) + cout << t - num + 1 << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[m]; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + int min = 1000000; + for (int i = 0; i < m - n + 1; i++) { + if ((a[i + n - 1] - a[i]) < min) { min = a[i + n - 1] - a[i]; } + } + if (min == 1000000) + cout << "0\n"; + else + cout << min << "\n"; +} +int N; +long long A, B; +long long Calc(long long a, long long b) { + if (b == 0) return 0LL; + long long ret = a / b; + ret += Calc(b, a % b); + return ret; +} +int main() { + cin >> N; + while (N--) { + cin >> A >> B; + cout << Calc(A, B) << endl; + } + return 0; +} +int main() { + int a[6]; + int sum = 0; + for (int i = 0; i < 6; i++) { + cin >> a[i]; + sum += a[i]; + } + if (sum % 2 != 0) { + cout << "NO" << endl; + return 0; + } + sum /= 2; + bool found = false; + for (int i = 0; i < 6; i++) { + for (int j = i + 1; j < 6; j++) { + for (int k = j + 1; k < 6; k++) { + if (a[i] + a[j] + a[k] == sum) { + found = true; + cout << "YES" << endl; + return 0; + } + } + } + } + if (!found) cout << "NO" << endl; + return 0; +} +int main() { + int x; + cin >> x; + for (int i = 0; i < (int)3; i++) { + int y; + cin >> y; + x = min(x, y); + } + int a, b; + cin >> a >> b; + int c = 0; + for (int i = a; i <= b && i < x; i++) c++; + cout << c << endl; +} +int main() { + long long int pos; + cin >> pos; + long long int num = (-1 + sqrt(1 + 8 * pos)) / 2; + long long int sum = num * (num + 1) / 2; + if (sum == pos) + cout << num << endl; + else + cout << pos - sum << endl; +} +const int MAXN = 1000; +int arr[MAXN + 10]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int ans = 0; + int i = 0; + while (i < n && arr[i] == 0) i++; + for (; i < n; i++) { + int j = i + 1; + while (j < n && arr[i] == arr[j]) j++; + if (j - i == 2) + ans++; + else if (j - i > 2) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; +} +int main() { + int s[1001], n, m, a, minn = 1000; + memset(s, 0, sizeof(s)); + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> a; + s[a]++; + } + for (int i = 1; i <= n; i++) + if (s[i] < minn) minn = s[i]; + cout << minn << endl; + return 0; +} +const int N = 1e6 + 5; +int main() { + int k; + string s; + cin >> k >> s; + set S; + S.insert(s.begin(), s.end()); + if ((int)S.size() < k) { + cout << "NO\n"; + return 0; + } + cout << "YES\n"; + int F[26] = {0}; + int p = 0; + while (1) { + if (k == 1) { + cout << s.substr(p) << "\n"; + break; + } + F[s[p] - 'a'] = 1; + int c = p; + while (F[s[c] - 'a']) c++; + cout << s.substr(p, c - p) << "\n"; + p = c; + k--; + } + return 0; +} +const int kMaxN = 400; +int a[kMaxN]; +int main() { + int N, K, C; + cin >> N >> K >> C; + for (int i = 0; i < C; ++i) { cin >> a[i]; } + int pt = 0, pending = K - 1, gifts = 0; + for (int i = 1; i <= N; ++i) { + if (i == a[pt]) { + ++gifts; + ++pt; + pending = K - 1; + } else { + if (pending == 0) { + pending = K - 1; + ++gifts; + } else { + pending--; + } + } + } + cout << gifts << endl; +} +int main() { + int n, s; + cin >> n >> s; + if (s % n == 0) + cout << s / n << endl; + else + cout << s / n + 1 << endl; +} +int main() { + int n, i, nilai[200000], temp = 0, tot = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> nilai[i]; + tot += nilai[i]; + } + i = 1; + while (temp < (tot / 2) + (tot % 2)) { + temp += nilai[i]; + i++; + } + cout << i - 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1 || n == 2) { + cout << n << endl; + } else + cout << 1 << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n) { + m = n - 10; + if (m > 0 && m < 10) + cout << '4' << endl; + else if (m == 0) + cout << '0' << endl; + else if (m == 10) + cout << "15" << endl; + else if (m == 11) + cout << '4' << endl; + else + cout << '0' << endl; + } + return 0; +} +int main() { + int a, m; + cin >> a >> m; + set store; + int x = a; + while (1) { + int length = store.size(); + int temp = a % m; + store.insert(temp); + if (length == store.size()) { + cout << "No" << endl; + break; + } else if (a % m == 0) { + cout << "Yes" << endl; + break; + } + a += temp; + x = a; + } + return 0; +} +int main() { + int n, cnt = 0, ans = 0, k; + cin >> n >> k; + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + for (int j = 0; j < s.size(); ++j) + if (s[j] == '4' || s[j] == '7') cnt++; + if (cnt <= k) ans++; + cnt = 0; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, x = -1, y = -1, aux; + cin >> n; + for (int i = 0; i < 1000000; ++i) { + aux = 4 * i - n; + if (aux % (-7) == 0 && (aux / -7) >= 0) { + y = aux / (-7); + x = i; + break; + } + } + if (x != -1) { + for (int i = 0; i < x; ++i) { cout << 4; } + for (int i = 0; i < y; ++i) { cout << 7; } + cout << endl; + } else + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int x = s.length(); + for (int i = 0; i < x - 1;) { + if ((s[i] == '0' && s[i + 1] == '1')) { + s.erase(i, 1); + s.erase(i, 1); + if (i - 2 >= 0) + i = i - 2; + else + i = 0; + } else if (s[i] == '1' && s[i + 1] == '0') { + s.erase(i, 1); + s.erase(i, 1); + if (i - 2 >= 0) + i = i - 2; + else + i = 0; + } else + i++; + x = s.length(); + } + cout << s.length() << endl; + return 0; +} +int *fatora(int factor, int n) { + int *f = new int[2]; + while (n % factor != 0) { factor++; } + f[0] = factor; + f[1] = n / factor; + return f; +} +int main() { + vector area; + int a, f3_1, f3_2, edges_sum; + int *factor; + for (int i = 0; i < 3; i++) { + cin >> a; + area.push_back(a); + } + for (int i = 0; i < (area[0] / 2) + 1; i++) { + factor = fatora(i + 1, area[0]); + if (area[1] % factor[0] == 0 && area[2] % factor[1] == 0) { + f3_1 = area[1] / factor[0]; + f3_2 = area[2] / factor[1]; + if (f3_1 == f3_2) break; + } else if (area[2] % factor[0] == 0 && area[1] % factor[1] == 0) { + f3_1 = area[1] / factor[1]; + f3_2 = area[2] / factor[0]; + if (f3_1 == f3_2) break; + } + } + edges_sum = 4 * (factor[0] + factor[1] + f3_1); + cout << edges_sum << endl; + return 0; +} +int main() { + int t, n, d, x, y, s, s1, s2, num, num1, num2, flag; + cin >> t; + while (t--) { + flag = 0; + cin >> n >> x >> y >> d; + s = abs(x - y); + if (s % d == 0) { + cout << s / d << endl; + continue; + } + if ((n - x) % d == 0) + s1 = (n - x) / d; + else + s1 = (n - x) / d + 1; + if ((x - 1) % d == 0) + s2 = (x - 1) / d; + else + s2 = (x - 1) / d + 1; + if ((n - y) % d == 0) + num1 = (n - y) / d + s1; + else + num1 = 0x3f3f3f3f; + if ((y - 1) % d == 0) + num2 = (y - 1) / d + s2; + else + num2 = 0x3f3f3f3f; + num = min(num1, num2); + if (num == 0x3f3f3f3f) + cout << "-1" << endl; + else + cout << num << endl; + } + return 0; +} +int ans, cnt, reshala, gol, kachok, y; +int main() { + string s; + int a; + cin >> a; + for (int i = 0; i < a; i++) { + cin >> s; + if (s == "purple") { + ans++; + } else if (s == "green") { + cnt++; + } else if (s == "blue") { + reshala++; + } else if (s == "orange") { + gol++; + } else if (s == "red") { + kachok++; + } else if (s == "yellow") { + y++; + } + } + cout << 6 - a << endl; + if (ans == 0) { cout << "Power" << endl; } + if (cnt == 0) { cout << "Time" << endl; } + if (reshala == 0) { cout << "Space" << endl; } + if (gol == 0) { cout << "Soul" << endl; } + if (kachok == 0) { cout << "Reality" << endl; } + if (y == 0) { cout << "Mind" << endl; } +} +int main() { + int n; + cin >> n; + char temp; + int ans = 0; + for (size_t i = 0; i < n; i++) { + ans++; + cin >> temp; + if (temp == '0') break; + } + cout << ans << '\n'; + return 0; +} +int main() { + int l, r, a, mn, mx, diff, ans; + cin >> l >> r >> a; + mn = min(l, r); + mx = max(l, r); + diff = mx - mn; + if (diff == a) + ans = 2 * mx; + else if (diff > a) + ans = 2 * (mn + a); + else { + int b = a - diff; + ans = ((b / 2) * 2) + (2 * mx); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + n = n / 2; + int h = n; + for (int i = 0; i < n + 1; i++) { + for (int j = 0; j < h; j++) { cout << "*"; } + for (int k = 0; k < 2 * i + 1; k++) { cout << "D"; } + for (int j = 0; j < h; j++) { cout << "*"; } + cout << endl; + h--; + } + h = 1; + int b = n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < h; j++) { cout << "*"; } + for (int k = (2 * b) - 1; k > 0; k--) { cout << "D"; } + for (int j = 0; j < h; j++) { cout << "*"; } + cout << endl; + h++; + b--; + } + return 0; +} +int main() { + long long int n, x, cnt = 0; + cin >> n >> x; + for (int i = 1; i * i <= x; i++) { + if (x % i == 0) { + if (i == x / i && i <= n && x / i <= n) cnt++; + if (i != x / i && i <= n && x / i <= n) cnt += 2; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, m, k, t, i; + cin >> n >> m >> k; + vector v; + for (int i = 0; i < n; i++) { + cin >> t; + v.push_back(t); + } + sort(v.begin(), v.end(), greater()); + for (i = 0; i < n; i++) { + if (k >= m) break; + k = k + v[i] - 1; + } + if (k >= m) + cout << i << endl; + else + cout << -1 << endl; +} +void solve() { + long long n, s; + cin >> n >> s; + long long a[n], b[n]; + for (long long i = 0; i < n; i++) cin >> a[i]; + for (long long i = 0; i < n; i++) cin >> b[i]; + if (a[0] == 1) { + if (a[s - 1] == 1) + cout << "YES\n"; + else { + long long h = 0; + for (long long i = s; i < n; i++) + if (a[i] == 1 && b[i] == 1) { + h = 2; + break; + } + if (h == 2 && b[s - 1] == 1) + cout << "YES\n"; + else + cout << "NO\n"; + } + } else + cout << "NO\n"; +} +int main() { + long long t = 1; + while (t--) { solve(); } + return 0; +} +int main() { + int n; + long long a; + long long tot = 0; + vector v; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + v.push_back(a); + tot += a; + } + if (tot % 2 == 0) { + cout << tot << "\n"; + return 0; + } + sort(v.begin(), v.end()); + for (int i = 0; i < n; i++) { + if (v[i] % 2 == 1) { + tot -= v[i]; + break; + } + } + cout << tot << "\n"; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long x, y; + if (n == 0) { + if (m) + cout << "Impossible\n"; + else + cout << "0 0\n"; + } else { + if (m) { + y = (n - 1) + m; + x = n; + if (m > n) x += (m - n); + } else + x = y = n; + cout << x << " " << y << "\n"; + } + return 0; +} +int main() { + int x, tmp, step = 0, s[5] = {5, 4, 3, 2, 1}; + cin >> x; + for (int i = 0; i < 5; ++i) + if (x >= s[i]) { + step += (tmp = x / s[i]); + x -= tmp * s[i]; + } + cout << step << endl; + return 0; +} +long long w[100005]; +long long leftPreSum[100005], rightPreSum[100005]; +int main() { + long long n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + leftPreSum[0] = 0; + rightPreSum[n + 1] = 0; + for (long long i = 1; i < n + 1; i++) { + cin >> w[i]; + leftPreSum[i] = leftPreSum[i - 1] + w[i]; + } + for (long long i = n; i >= 0; i--) { rightPreSum[i] = rightPreSum[i + 1] + w[i]; } + long long ans = LONG_LONG_MAX, currentans; + for (long long i = 0; i < n + 1; i++) { + currentans = leftPreSum[i] * l + rightPreSum[i + 1] * r; + if (i == n / 2) { + currentans += 0; + } else if (i < n / 2) { + currentans += (n - 2 * i - 1) * qr; + } else if (i > n / 2) { + currentans += (2 * i - n - 1) * ql; + } + ans = min(ans, currentans); + } + cout << ans << endl; + return 0; +} +int n, k, a, last(0), cont(1); +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == last) + ++cont; + else + cont = 1; + last = a; + } + if (cont + k > n) + cout << n - cont << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + bool vis[10]; + long long ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 10; j++) vis[j] = 0; + long long cnt = 0; + string s; + cin >> s; + for (int j = 0; j < s.length(); j++) { + long long cur = s[j] - '0'; + if (cur > k) { continue; } + if (vis[cur] == 0) cnt++; + vis[cur] = 1; + } + if (cnt == k + 1) ans++; + } + cout << ans << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int t, v, l, r, L, cnt = 0; + cin >> t; + while (t--) { + cin >> L >> v >> l >> r; + int ans = L / v - (r / v - (l - 1) / v); + cout << ans << endl; + } + return 0; +} +int main() { + cout << "Karen" << endl; +} +int main() { + int n; + cin >> n; + int arr[1000]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int l = arr[0]; + sort(arr + 1, arr + n); + while (arr[0] <= arr[n - 1]) { + arr[0]++; + arr[n - 1]--; + sort(arr + 1, arr + n); + } + cout << arr[0] - l << endl; +} +int main() { + int a, b, c; + double x; + while (cin >> a >> b >> c) { + x = a * c - b * c; + cout << ceil(x / b) << endl; + } + return 0; +} +int a, b, c = 9999999, d, e; +int ai[1010]; +int main() { + cin >> a >> b; + for (int i = 1, j; i <= b; i++) cin >> j, ai[j]++; + for (int i = 1; i <= a; i++) c = min(c, ai[i]); + cout << c << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const long long inf2 = 0x3f3f3f3f3f3f3f3f; +const double eps = 1e-6; +const int mod = 1000000007; +bool is[545]; +int main() { + memset(is, 0, sizeof(is)); + int n, k; + cin >> n >> k; + int c; + cin >> c; + while (c--) { + int x; + cin >> x; + is[x] = true; + } + int cnt = 0, pr = 0; + for (int i = 1; i <= n; i++) { + if (is[i]) { + cnt = 0; + pr++; + } else { + cnt++; + if (cnt == k) { + cnt = 0; + pr++; + } + } + } + cout << pr << endl; + return 0; +} +char a[101][101]; +string b; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> b; + for (int j = 1; j <= m; j++) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + if (b[j - 1] == '-') a[i][j] = '-'; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + int mx = 0; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = i + 1; j < s.size(); j++) { + int c = 0; + while (s[i + c] == s[j + c]) c++; + mx = max(mx, c); + } + } + cout << mx << endl; + return 0; +} +int main() { + set st; + string s, p; + cin >> s; + for (int i = 0; i < s.length(); i++) { + p = s[s.length() - 1]; + s.erase(s.length() - 1); + s = p + s; + if (st.find(s) == st.end()) { st.insert(s); } + } + cout << st.size() << endl; + return 0; +} +const long long int INF = (1LL << 60) - 1; +const long long int MAX = 2000001; +map p; +map p2; +map p3; +int freq[5000][101] = {0}; +long long int fast_exp(long long int base, long long int exp, long long int m) { + long long int res = 1; + while (exp > 0) { + if (exp % 2 == 1) { res = (res * base) % m; } + base = (base * base) % m; + exp /= 2; + } + return res % m; +} +int main() { + int n, k, freq[27] = {0}; + cin >> n >> k; + string s; + cin >> s; + int l = s.length(); + for (int i = 0; i < l; i++) { freq[s[i] - 'a']++; } + for (int i = 0; i < 27; i++) { + if (freq[i] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int a1[3], a2[3], a3[3], a4[3], a5[3], a6[3]; + a1[0] = 0, a1[1] = 1, a1[2] = 2; + a2[0] = 1, a2[1] = 0, a2[2] = 2; + a3[0] = 1, a3[1] = 2, a3[2] = 0; + a4[0] = 2, a4[1] = 1, a4[2] = 0; + a5[0] = 2, a5[1] = 0, a5[2] = 1; + a6[0] = 0, a6[1] = 2, a6[2] = 1; + n = n % 6; + if (n == 1) + cout << a2[x] << endl; + else if (n == 2) + cout << a3[x] << endl; + else if (n == 3) + cout << a4[x] << endl; + else if (n == 4) + cout << a5[x] << endl; + else if (n == 5) + cout << a6[x] << endl; + else if (n == 0) + cout << a1[x] << endl; +} +int main() { + long int n, r; + cin >> n; + r = n / 5; + if (n == (r * 5)) + cout << r << endl; + else + cout << (r + 1) << endl; + return 0; +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +string r; +int a, d; +int main() { + cin >> a; + cout << "I hate "; + for (int i = 1; i < a; i++) { + if (a == 1) + break; + else if (i % 2 != 0) + cout << "that I love "; + else + cout << "that I hate "; + } + cout << "it" << endl; + return 0; +} +int main() { + long long a; + cin >> a; + if (a < 0) { + int last, slast; + a = abs(a); + last = a % 10; + a = a / 10; + slast = a % 10; + if (slast <= last) { + cout << "-" << a << endl; + } else { + a = (a / 10) * 10 + last; + if (a == 0) { + cout << 0 << endl; + } else { + cout << "-" << a << endl; + } + } + } else { + cout << a << endl; + } + return 0; +} +int main() { + int a; + cin >> a; + string nome; + int v[6] = {0, 0, 0, 0, 0, 0}; + for (int i = 0; i < a; i++) { + cin >> nome; + if (nome == "purple") v[0] = 1; + if (nome == "green") v[1] = 1; + if (nome == "blue") v[2] = 1; + if (nome == "orange") v[3] = 1; + if (nome == "red") v[4] = 1; + if (nome == "yellow") v[5] = 1; + } + cout << (6 - a) << endl; + if (v[0] == 0) cout << "Power" << endl; + if (v[1] == 0) cout << "Time" << endl; + if (v[2] == 0) cout << "Space" << endl; + if (v[3] == 0) cout << "Soul" << endl; + if (v[4] == 0) cout << "Reality" << endl; + if (v[5] == 0) cout << "Mind" << endl; + return 0; +} +int main() { + long long int t; + cin >> t; + long long int s, a, b, c; + while (t--) { + cin >> s >> a >> b >> c; + long long int n = s / c; + long long int max = n; + long long int diff2 = n / a; + max = max + diff2 * b; + cout << max << endl; + } + return 0; +} +int main() { + int n, a[1001]; + cin >> n; + int h = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (a[i] == 1) { + h = 1; + break; + } + } + if (h == 0) { + cout << 1 << endl; + } else { + cout << -1 << endl; + } + return 0; +} +const long long MOD = 1e9 + 9; +int main() { + int n, m; + cin >> n >> m; + long long val = 1; + for (int i = 0; i < m; i++) val = (2 * val) % MOD; + long long ans = 1; + for (int i = 0; i < n; i++) { + val--; + if (val < 0) val += MOD; + ans = (ans * val) % MOD; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, b, d, i, cnt = 0, a[100001], tmp = 0; + cin >> n >> b >> d; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (a[i] <= b and cnt <= d) cnt += a[i]; + if (cnt > d) { + cnt = 0; + tmp++; + } + } + cout << tmp << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int p = i; + if (p >= n / 2 + 1) { + p = p - n / 2; + p = n / 2 - p; + } + if (j >= n / 2 - p && j <= n / 2 + p) { + cout << "D"; + } else { + cout << "*"; + } + if (j == n - 1) { cout << "\n"; } + } + } +} +int main() { + int n, i; + cin >> n; + int r; + int time, smallest = 0; + char arr1[n]; + int arr2[n]; + for (i = 0; i < n; i++) cin >> arr1[i]; + for (i = 0; i < n; i++) cin >> arr2[i]; + for (i = 0; i < n; i++) { + if (i + 1 < n) { + if (arr1[i] == 'R' && arr1[i + 1] == 'L') { + r = (arr2[i + 1] - arr2[i]) / 2; + time = r; + if (smallest == 0) smallest = time; + if (time < smallest) smallest = time; + } + } + } + if (smallest == 0) + cout << -1 << endl; + else + cout << smallest << endl; + return 0; +} +int main() { + int x, a, b, c, d; + cin >> x; + for (int i = x + 1; i <= 9999; i++) { + a = i / 1000; + b = (i - a * 1000) / 100; + c = (i - a * 1000 - b * 100) / 10; + d = i % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, p; + cin >> n >> p; + string s; + cin >> s; + set st; + set::iterator it; + int x = -1; + for (int i = n - 1; i >= 0; i--) { + st.clear(); + for (char j = s[i] + 1; j < 'a' + p; j++) { st.insert(j); } + if (i - 1 >= 0) { + it = st.find(s[i - 1]); + if (it != st.end()) st.erase(it); + } + if (i - 2 >= 0) { + it = st.find(s[i - 2]); + if (it != st.end()) st.erase(it); + } + if (st.size()) { + s[i] = *st.begin(); + x = i; + break; + } + } + if (x == -1) + cout << "NO\n"; + else { + for (int i = x + 1; i < n; i++) { + st.clear(); + for (char j = 'a'; j < 'a' + p; j++) { st.insert(j); } + if (i - 1 >= 0) { + it = st.find(s[i - 1]); + if (it != st.end()) st.erase(it); + } + if (i - 2 >= 0) { + it = st.find(s[i - 2]); + if (it != st.end()) st.erase(it); + } + if (st.size()) { + s[i] = *st.begin(); + } else { + cout << "NO\n"; + return 0; + } + } + cout << s << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector se; + int answer = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + se.push_back(x); + } + sort(se.begin(), se.end()); + int min = se[0]; + int max = se[n - 1]; + for (int i = 0; i < n; i++) { + if (se[i] > min && se[i] < max) { ++answer; } + } + cout << answer << endl; + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + if (n % 2 == 0) { + if (x == 0) { + if (n % 3 == 0) cout << 0 << endl; + if (n % 3 == 1) cout << 2 << endl; + if (n % 3 == 2) cout << 1 << endl; + } + if (x == 1) { + if (n % 3 == 0) cout << 1 << endl; + if (n % 3 == 1) cout << 0 << endl; + if (n % 3 == 2) cout << 2 << endl; + } + if (x == 2) { + if (n % 3 == 0) cout << 2 << endl; + if (n % 3 == 1) cout << 1 << endl; + if (n % 3 == 2) cout << 0 << endl; + } + } else { + if (x == 0) { + if (n % 3 == 0) cout << 2 << endl; + if (n % 3 == 1) cout << 1 << endl; + if (n % 3 == 2) cout << 0 << endl; + } + if (x == 1) { + if (n % 3 == 0) cout << 1 << endl; + if (n % 3 == 1) cout << 0 << endl; + if (n % 3 == 2) cout << 2 << endl; + } + if (x == 2) { + if (n % 3 == 0) cout << 0 << endl; + if (n % 3 == 1) cout << 2 << endl; + if (n % 3 == 2) cout << 1 << endl; + } + } +} +int main() { + int n, k; + cin >> n >> k; + int time[241]; + time[0] = 0; + for (int i = 1; i < 240; ++i) { time[i] = time[i - 1] + i * 5; } + int c = 0; + int tl = 240 - k; + if (tl <= 0) { + cout << 0 << endl; + return 0; + } + for (int i = 1; i <= n; ++i) { + if (tl - time[i] < 0) break; + c++; + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + int ans = 0, t = 1, q = 1; + ans = ans + t; + while (n >= ans) { + q++; + t = t + q; + ans = ans + t; + } + cout << q - 1 << endl; +} +int main() { + int n, k, cntr = 0; + cin >> n >> k; + string s; + bool f; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j <= k; j++) { + if (s.find(j + '0') != string::npos) { + f = 1; + } else { + f = 0; + break; + } + } + if (f) cntr++; + } + cout << cntr << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int c = 0, d = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (c % 2 == 0) { + cout << '#'; + } else { + if (d % 2 == 0 && j == m) { + cout << '#'; + d++; + break; + } else if (d % 2 == 1 && j == 1) { + cout << '#'; + for (int k = 1; k < m; k++) { cout << '.'; } + d++; + break; + } else { + cout << '.'; + } + } + } + cout << endl; + c++; + } +} +int n, a[40][40], col[40], row[40], b[40][40], c; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + row[i] += a[i][j]; + col[j] += a[i][j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + a[i][j] = row[i]; + b[i][j] = col[j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] < b[i][j]) c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int **p = new int *[n + 1]; + for (int i = 1; i <= n; i++) { p[i] = new int[m + 1]; } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) + cout << "#"; + else if (i % 2 == 0 && i % 4 != 0) { + cout << (j == m ? "#" : "."); + } else + cout << (j == 1 ? "#" : "."); + } + cout << endl; + } + } +} +int main() { + int t, ans = 0, x, y, a1 = 0, b1 = 0, a = 0, b = 0; + cin >> t; + while (t--) { + cin >> x >> y; + if (x % 2) a++; + if (y % 2) b++; + if (a % 2 && !(b % 2)) a1++; + if (b % 2 && !(a % 2)) b1++; + } + if (!(a % 2) && !(b % 2)) + cout << "0" << endl; + else if (a % 2 && b % 2) { + cout << ((a1 || b1 ? "1" : "-1")) << endl; + } else + cout << "-1" << endl; +} +int main() { + int n, a, b, i = 0, c = 0; + cin >> n >> a >> b; + i = n - a; + c = b + 1; + if (i <= c) { + cout << i << endl; + } else { + cout << c << endl; + } + return 0; +} +const int maxn = 100000 + 5; +pair G[maxn]; +int main() { + int n, m; + while (cin >> n) { + int ans = 0; + for (int i = 0; i < n; i++) { cin >> G[i].first >> G[i].second; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (G[i].second == G[j].first) ans++; + } + } + cout << ans << endl; + } + return 0; +} +long long n, m, ans = 0, pw; +int main() { + cin >> n >> m; + pw = 1; + for (int i = 1; i <= m; i++) { pw = (pw * 2) % 1000000009; } + ans = 1; + for (int i = 1; i <= n; i++) { ans = (ans * (pw - i)) % 1000000009; } + cout << ans << endl; + return 0; +} +int main() { + char a[30], b[30]; + cin >> a >> b; + int aa = 0, bb = 0; + int l = strlen(a); + for (int i = 0; i < l; i += 2) + if (a[i] == '8') { + if (b[i] == '[') + aa++; + else if (b[i] == '(') + bb++; + } else if (a[i] == '[') { + if (b[i] == '8') + bb++; + else if (b[i] == '(') + aa++; + } else if (a[i] = '(') { + if (b[i] == '[') + bb++; + else if (b[i] == '8') + aa++; + } + if (aa == bb) + cout << "TIE" << endl; + else if (aa > bb) + cout << "TEAM 1 WINS" << endl; + else + cout << "TEAM 2 WINS" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + int mini = INT_MAX; + bool b = true; + int ind = 0; + for (int i = 0; i < n; i++) { + cin >> x; + if (x < mini) { + b = true; + ind = i; + mini = x; + } else if (x == mini) { + b = false; + mini = x; + } + } + if (b) + cout << ind + 1 << endl; + else + cout << "Still Rozdil" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int min_cnt = 1e9; + for (int i = a; i <= 100; i++) { + for (int j = b; j <= 100; j++) { + for (int k = c; k <= 100; k++) { + double s = (i + j + k) / 2.0; + double under_root = s * (s - i) * (s - j) * (s - k); + if (under_root > 0.0) { min_cnt = min(min_cnt, ((i - a) + (j - b) + (k - c))); } + } + } + } + cout << min_cnt << "\n"; + return 0; +} +int N, K, ans = 2e9, A[26], val, x, y; +map M; +string T, S; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> S; + T = ""; + memset(A, 0, sizeof(A)); + for (int j = 0; j < S.length(); j++) { + A[S[j] - 'a']++; + if (A[S[j] - 'a'] == 1) T += S[j]; + } + sort(T.begin(), T.end()); + if (M[T] == 0) { + M[T] = 1; + val++; + } + } + cout << val << '\n'; +} +int main() { + int t, a, b; + cin >> t; + for (int i = 0; i < t; ++i) { + cin >> a; + b = 180 - a; + if (360 % (b) == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +char s[101][102]; +int i, j, m, n; +bool e[11]; +int main() { + cin >> n >> m; + for (i = 0; i < n; i++) cin >> s[i]; + for (i = 0; i < n; i++) { + for (j = 0; j < m - 1; j++) { + if (s[i][j] != s[i][j + 1] || s[i][0] == s[i + 1][0]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int length(int n) { + int cnt = 0; + while (n != 0) cnt++, n = n / 10; + return cnt; +} +int main() { + long long l, r; + cin >> l >> r; + int length_r = length(r); + int length_l = length(l); + long long st = 1; + for (int i = 1; i < length_r; i++) st = st * 10; + if (length(l) < length(r)) { + if (r >= 5 * pow(10, length_r - 1)) + cout << 5 * st * (st * 10 - 1 - 5 * st) << endl; + else + cout << r * (st * 10 - 1 - r) << endl; + } else { + if (r <= 5 * st) + cout << r * (st * 10 - 1 - r) << endl; + else if (l >= 5 * st) + cout << l * (st * 10 - 1 - l) << endl; + else + cout << 5 * st * (st * 10 - 1 - 5 * st) << endl; + } + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int temp = (y * n / 100) + ((y * n % 100) ? 1 : 0); + temp -= x; + if (temp <= 0) + cout << "0\n"; + else + cout << temp << '\n'; + return 0; +} +int n; +vector vv[210]; +int computer[210], in[210], bk[210], temp[210]; +int bfs(int st) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (in[i] == 0) q.push(i); + } + while (!q.empty()) { + memset(bk, 0, sizeof(bk)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (bk[head] == 5) { + q.push(head); + break; + } + bk[head]++; + if (computer[head] != st) { + q.push(head); + continue; + } + for (int i = 0; i < vv[head].size(); i++) { + int v = vv[head][i]; + in[v]--; + if (in[v] == 0) q.push(v); + } + } + st = (st == 3 ? 1 : st + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(in, 0, sizeof(in)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + in[i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) temp[i] = in[i]; + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= n; j++) in[j] = temp[j]; + ans = min(ans, bfs(i)); + } + cout << ans << endl; + } + return 0; +} +int main() { + char a[1000], b[1000], k[1000]; + int c; + cin >> a >> b; + c = strlen(a); + for (int i = 0; i < c; i++) { k[i] = '0'; } + for (int i = 0; i < c; i++) { + if (a[i] == b[i]) { + k[i] = '0'; + } else + k[i] = '1'; + } + for (int j = 0; j < c; j++) cout << k[j]; + cout << endl; +} +int main() { + string s, t; + int n, j = 0; + cin >> s >> n; + string ar[n]; + int slength = s.size(); + for (int i = 1; i <= n; i++) { + cin >> t; + if (t.substr(0, slength) == s) { + ar[j] = t; + j++; + } + } + if (j == 0) + cout << s << '\n'; + else { + sort(ar, ar + j); + cout << ar[0] << '\n'; + } + return 0; +} +int water; +int s, n, b, p; +int main() { + cin >> n >> b >> p; + int k = n; + water = 0; + while (n != 1) { + s = n / 2; + if (n % 2 == 0) { + n /= 2; + } else { + n = n / 2 + 1; + } + water += s * (2 * b + 1); + } + cout << water << " " << k * p << endl; +} +const int N = 1e6 + 5; +long long n, k; +bool valid(long long r) { + if (r + r * k <= n / 2) return 1; + return 0; +} +long long bs() { + long long s = 0, e = 1e12 / k, mid; + while (s < e) { + mid = (s + e + 1) / 2; + if (valid(mid)) + s = mid; + else + e = mid - 1; + } + return s; +} +int main() { + long long ans; + cin >> n >> k; + ans = bs(); + cout << ans << " " << ans * k << " " << n - (ans + ans * k) << '\n'; + return 0; +} +int main() { + double a, b, c, t; + cin >> a >> b >> c; + t = (a * c - b * c) / b; + cout << ceil(t) << endl; + return 0; +} +const int maxn = (int)1e5 + 7; +const int INF = (int)1e9 + 7; +const double pi = acos(-1); +const double eps = 1e-9; +const int base = 1000 * 1000 * 1000; +long long n, m, pos, w; +map mp; +string ans[maxn]; +string lol(long long x) { + string res = ""; + while (x > 0) { + if (x % 2 == 0) { + res += '0'; + } else { + res += '1'; + } + x /= 10; + } + reverse(res.begin(), res.end()); + return res; +} +int main() { + int mx = -INF; + char ch[maxn]; + cin >> n; + for (int i = 1; i <= n; ++i) { + long long x; + cin >> ch[i] >> x; + ans[i] = lol(x); + mx = max(mx, (int)ans[i].size()); + } + for (int i = 1; i <= n; ++i) { + if (ans[i].size() != mx) { + while (ans[i].size() < mx) { ans[i] = '0' + ans[i]; } + } + } + for (int i = 1; i <= n; ++i) { + if (ch[i] == '+') { + mp[ans[i]]++; + } else if (ch[i] == '-') { + mp[ans[i]]--; + } else { + cout << mp[ans[i]] << endl; + } + } + return 0; +} +int main() { + string s; + int k, cnt[26] = {0}; + cin >> s >> k; + if (s.length() < k) { + cout << "impossible" + << "\n"; + } else { + for (int i = 0; i < s.length(); i++) { cnt[s[i] - 97]++; } + int res = 0; + for (int i = 0; i < 26; i++) { + if (cnt[i]) { res++; } + } + cout << max(0, k - res) << "\n"; + } + return 0; +} +bool d[200] = {0}; +int n, now = 0; +string s; +int main() { + cin >> n >> s; + for (int i = 0; i < s.size(); i++) { d[i] = s[i] - '0'; } + while (d[now]) { now++; } + cout << ((now + 1 > n) ? n : now + 1) << endl; + return 0; +} +int main() { + int a[3]; + for (int i = 0; i < 3; i++) cin >> a[i]; + sort(a, a + 3); + int cnt = 0; + cnt = (a[1] - a[0]) + (a[2] - a[1]); + cout << cnt << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n; + int x = n; + for (int i = 1; i <= n; i = i + 2) { + if (i == n) { + for (int x = 1; x < i; x++) { cout << "D"; } + cout << "D" << endl; + } else { + for (int x = 1; x <= (n - i) / 2; x++) { cout << "*"; } + for (int x = 1; x <= i; x++) { cout << "D"; } + for (int x = 1; x < (n - i) / 2; x++) { cout << "*"; } + cout << "*" << endl; + } + } + for (int i = n - 2; i > 0; i = i - 2) { + for (int x = 1; x <= (n - i) / 2; x++) { cout << "*"; } + for (int x = 1; x <= i; x++) { cout << "D"; } + for (int x = 1; x < (n - i) / 2; x++) { cout << "*"; } + cout << "*" << endl; + } +} +int t[105]; +int main() { + int a, b; + cin >> a >> b; + for (int i = 0; i < a; i++) { + cin >> t[i]; + t[i] = 86400 - t[i]; + } + for (int i = 0; i < a; i++) { + if (b - t[i] <= 0) { + cout << i + 1 << endl; + return 0; + } else { + b -= t[i]; + } + } +} +int main() { + int n, x; + cin >> n >> x; + int c, sum = 0; + for (int i = 0; i < n; ++i) { + cin >> c; + sum += c; + } + sum = abs(sum); + if (sum % x == 0) { + cout << sum / x << endl; + } else { + cout << (sum / x) + 1 << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = 0; + c -= 2; + b -= 1; + cout << min(a, min(b, c)) * 3 + 3 << endl; + return 0; +} +int main() { + int n, m, *a, *b, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + vector u, v; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + int i = 0, j = 0; + while (i < n && j < m) { + if (a[i] - x <= b[j] && b[j] <= a[i] + y) { + u.push_back(i + 1); + v.push_back(j + 1); + i++; + j++; + } else if (a[i] - x > b[j]) { + j++; + } else if (a[i] + y < b[j]) { + i++; + } + } + int cnt = u.size(); + cout << cnt << endl; + for (int i = 0; i < cnt; i++) { cout << u[i] << " " << v[i] << endl; } + return 0; +} +int main() { + long long n; + cin >> n; + int arr[100010] = {0}; + int num; + for (int i = 1; i < n; i++) { + cin >> num; + arr[num]++; + } + for (int i = 1; i <= n; i++) { + if (arr[i] == 0) { + cout << i << endl; + return 0; + } + } +} +vector a; +vector b; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + } + for (int i = 0; i < k; i++) { + int x; + cin >> x; + b.push_back(x); + } + sort(b.begin(), b.end()); + int j = k - 1; + for (int i = 0; i < n; i++) { + if (a[i] == 0) a[i] = b[j--]; + } + bool decreasing = true; + for (int i = 0; i < a.size() - 1; ++i) { + if (a[i] > a[i + 1]) { + cout << "Yes" << endl; + exit(0); + } + } + cout << "No" << endl; + return 0; +} +int main() { + long long n, p, count = 0, y = 0; + string x; + cin >> n >> p; + vector a; + for (int i = 0; i < n; i++) { + cin >> x; + a.push_back(x); + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] == "halfplus") { + count = count * 2 + 1; + y++; + } + if (a[i] == "half") { count = 2 * count; } + } + long long ans = p * count - (p * y) / 2; + cout << ans << endl; + return 0; +} +int main() { + long long len, pos, i; + char s[1000]; + while (cin >> len >> pos) { + cin >> s; + if (pos > len / 2) { + if (pos != len) { + for (i = 0; i < (len - pos); i++) cout << "RIGHT" << endl; + } + cout << "PRINT " << s[len - 1] << endl; + for (i = len - 2; i >= 0; i--) { cout << "LEFT" << endl << "PRINT " << s[i] << endl; } + } else { + if (pos != 1) { + for (i = 1; i < pos; i++) cout << "LEFT" << endl; + } + cout << "PRINT " << s[0] << endl; + for (i = 1; i < len; i++) { cout << "RIGHT" << endl << "PRINT " << s[i] << endl; } + } + } + return 0; +} +int nums[5], r, n, T; +int main() { + cin >> T; + while (T--) { + cin >> n >> r; + int sum = 0; + for (int c = 1; c < n; c++) { + int i; + cin >> i; + sum -= i; + } + sum += r; + sum += n * 1000; + cout << (sum % n + 1) << endl; + } +} +int n, a[10000]; +int main() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; + sort(a + 1, a + 2 * n + 1); + if (a[n] == a[n + 1]) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long t = (a - b) * c; + if (t % b == 0) + cout << t / b << endl; + else + cout << t / b + 1 << endl; +} +int main() { + int n; + cin >> n; + vector a(n), b(n); + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0; i < n; ++i) cin >> b[i]; + int x = 0, y = 0; + for (int i = 1; i <= n; ++i) { + int s = 0, pre = 0; + for (int j = 0; j < i; ++j) s |= a[j]; + x = max(s, x); + for (int j = i; j < n; ++j) { + s |= a[j]; + s |= ~a[pre]; + pre++; + x = max(s, x); + } + } + for (int i = 1; i <= n; ++i) { + int s = 0, pre = 0; + for (int j = 0; j < i; ++j) s |= b[j]; + y = max(s, y); + for (int j = i; j < n; ++j) { + s |= b[j]; + s |= ~b[pre]; + pre++; + y = max(s, y); + } + } + cout << x + y << endl; + return 0; +} +map arr; +int n, a, lol = 0; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == 0) continue; + arr[a]++; + if (arr[a] > 2) { + cout << -1 << endl; + return 0; + } + if (arr[a] == 2) { lol++; } + } + cout << lol << endl; + return 0; +} +int a[1000]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } +} +int main() { + int N, M; + cin >> N >> M; + vector A(N), B(N); + for (int i = 0; i < (int)(N); ++i) { cin >> A[i] >> B[i]; } + int max_ = 0; + for (int i = 0; i < (int)(N); ++i) { + if (max_ < A[i]) { break; } + max_ = max(max_, B[i]); + } + if (max_ == M) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int n, k; +string s; +int main() { + cin >> n >> k; + cin >> s; + int f = 0, start, insect; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'G') { start = i; } + if (s[i] == 'T') { insect = i; } + } + int i; + if (insect < start) { + for (i = start; i >= insect; i = i - k) { + if (s[i] == '#') { + f = 1; + break; + } + } + if (i + k == insect) { + if (f == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + } else { + for (i = start; i <= insect; i = i + k) { + if (s[i] == '#') { + f = 1; + break; + } + } + if (i - k == insect) { + if (f == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, arr[105], max = -1, cnt; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + cnt = 0; + if (arr[i] == -5000000) { continue; } + int tmp = arr[i]; + for (int j = 0; j < n; j++) { + if (tmp == arr[j]) { + cnt++; + arr[j] = -5000000; + } + } + if (cnt >= max) { max = cnt; } + } + cout << max << endl; +} +int main() { + long long n, i, j, k, cnt = 0; + cin >> n; + vector a(n + 1), b(n + 1); + vector v; + for (i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b.begin(), b.begin() + n); + for (i = 0; i < n; i++) { + if (a[i] != b[i]) { + v.push_back(i); + cnt++; + } + } + if (cnt > 2) + cout << "NO" << endl; + else { + if (cnt == 0) + cout << "YES" << endl; + else { + swap(a[v[0]], a[v[1]]); + bool f = 0; + for (i = 1; i < n; i++) { + if (a[i] < a[i - 1]) { + f = 1; + break; + } + } + if (f == 1) + cout << "NO" << endl; + else { + cout << "YES" << endl; + } + } + } +} +int a[100], b[100], c[10005]; +int main() { + int n, m, s = 0, t; + memset(c, 0, sizeof(c)); + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int j = 0; j < m; j++) cin >> b[j]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0 && b[j] / a[i] >= s) { + s = b[j] / a[i]; + c[s]++; + } + } + cout << c[s] << endl; + return 0; +} +inline long long read() { + char c = getchar(); + while (c != '-' && (c < '0' || c > '9')) c = getchar(); + long long k = 0, kk = 1; + if (c == '-') c = getchar(), kk = -1; + while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar(); + return kk * k; +} +void write(long long x) { + if (x < 0) x = -x, putchar('-'); + if (x / 10) write(x / 10); + putchar(x % 10 + '0'); +} +void writeln(long long x) { + write(x); + puts(""); +} +long long n, b, p; +int main() { + n = read(); + b = read(); + p = read(); + write((b + b + 1) * (n - 1)); + putchar(' '); + writeln(p * n); +} +const long long inf = LONG_MAX; +const long long arr = 1000000; +vector a(arr, 0); +vector b(arr, 0); +long long fa(int l, int r) { + long long ans = a[l]; + for (int i = l + 1; i <= r; i++) ans |= a[i]; + return ans; +} +long long fb(int l, int r) { + long long ans = b[l]; + for (int i = l + 1; i <= r; i++) ans |= b[i]; + return ans; +} +int main() { + long long n; + cin >> n; + long long ans = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { ans = max(fa(i, j) + fb(i, j), ans); } + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int value; + int ans = 0; + for (int i = 0; i < n; i++) { + cin >> value; + ans += i * 4 * value; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + sort(ar, ar + n); + int m; + cin >> m; + int arr[m]; + for (int i = 0; i < m; i++) { cin >> arr[i]; } + sort(arr, arr + m); + reverse(arr, arr + m); + long long res = 0, md = ar[0] + 2; + for (int i = 0; i < m; i++) { + if ((i % md) != (md - 2) && (i % md) != (md - 1)) { res += arr[i]; } + } + cout << res << endl; + return 0; +} +int main() { + int n, m, kmax, man = 0; + int i, a[100]; + cin >> n >> m; + for (i = 0; i < n; i++) cin >> a[i]; + kmax = a[0]; + for (i = 1; i < n; i++) + if (a[i] > kmax) kmax = a[i], man = i; + kmax += m; + i = 0; + while (m != 0) { + if (a[i] < a[man]) { + a[i] += 1; + m -= 1; + } else + i += 1; + if (i == n) { + a[man] += 1; + m -= 1; + i = 0; + } + } + cout << a[man] << " " << kmax << endl; + return 0; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +int main() { + int n, s = 0, k = 0; + cin >> n; + for (int i = 1; i <= n; ++i) { + int a; + cin >> a; + k = max(k, a); + s += a; + } + for (; n * k <= 2 * s; ++k) + ; + cout << k << '\n'; + return 0; +} +inline void getInt(int *p); +const int maxn = 1000010; +const int inf = 0x3f3f3f3f; +int t; +long long x, y, a, b; +int main() { + cin >> t; + while (t--) { + cin >> x >> y >> a >> b; + long long l = 0; + long long r = 1e9; + long long mid; + long long ans = -1; + while (l <= r) { + mid = (l + r) >> 1; + long long a1 = a * mid - x; + long long a2 = b * mid - y; + if (a1 >= 0 && a2 >= 0 && (a1 <= a2)) { + ans = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + if (ans == -1) { + cout << -1 << endl; + } else { + cout << b * ans - y << endl; + } + } + return 0; +} +inline void getInt(int *p) { + char ch; + do { ch = getchar(); } while (ch == ' ' || ch == '\n'); + if (ch == '-') { + *p = -(getchar() - '0'); + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 - ch + '0'; } + } else { + *p = ch - '0'; + while ((ch = getchar()) >= '0' && ch <= '9') { *p = *p * 10 + ch - '0'; } + } +} +long long p, he, shu; +int n; +string s[50]; +int main() { + cin >> n >> p; + p /= 2; + for (int i = 1; i <= n; i++) cin >> s[i]; + for (int i = n; i >= 1; i--) { + shu = shu * 2; + if (s[i] != "half") shu += 1; + he += shu; + } + cout << he * p << endl; + return 0; +} +int fastMax(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; +} +int fastMin(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; +} +const long long int MAXN = 2001; +long double a[2 * MAXN]; +long long int n; +long double dp[MAXN][MAXN]; +bool visit[MAXN][MAXN]; +double recursion(long long int i, long long int ceils, long long int floors) { + if (i > 2 * n) return 0; + if (visit[ceils][floors]) return dp[ceils][floors]; + long double val1 = INT_MAX; + long double val2 = INT_MAX; + if (ceils < n) val1 = ceil(a[i]) - a[i] + recursion(i + 1, ceils + 1, floors); + if (floors < n) val2 = floor(a[i]) - a[i] + recursion(i + 1, ceils, floors + 1); + long double ans; + if (fabs(val1) < fabs(val2)) + ans = val1; + else + ans = val2; + visit[ceils][floors] = true; + return dp[ceils][floors] = ans; +} +void solve() { + cin >> n; + for (int i = (1); i <= (2 * n); ++i) cin >> a[i]; + cout << fixed << setprecision(3); + cout << fabs(recursion(1, 0, 0)) << endl; +} +int main() { + long long int t; + t = 1; + while (t--) solve(); +} +int main() { + long long n, i, c; + while (cin >> n) { + vector a; + for (i = 0; i < n; i++) { + cin >> c; + a.push_back(c); + } + sort(a.begin(), a.end()); + long long cha, z = 2000000009, num = 0; + for (i = 1; i < n; i++) { + cha = a[i] - a[i - 1]; + if (cha < z) { + z = cha; + num = 1; + } else if (cha == z) { + num++; + } + } + cout << z << " " << num << endl; + a.clear(); + } + return 0; +} +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + int t1, f1, t2, f2; + cin >> t1 >> f1 >> t2 >> f2; + int ans = 0, cf = f1; + if (t1 != t2) { + if (f1 >= a && f1 <= b) { + ans = ans; + cf = f1; + } else if (f1 < a) { + ans += a - f1; + cf = a; + } else { + ans += f1 - b; + cf = b; + } + } + ans += max(t1 - t2, t2 - t1); + ans += max(cf - f2, f2 - cf); + cout << ans << endl; + } +} +const int maxn = 1e6 + 20; +int prime[maxn]; +int main() { + long long n, m; + cin >> n >> m; + long long l = 0, r = min(n / 2, (n + m) / m); + while (r - l > 1) { + long long mid = (r + l) / 2; + if (mid * (m + 1) > n / 2) + r = mid; + else + l = mid; + } + r = l; + cout << r << " " << m * r << " " << n - r - m * r << endl; + return 0; +} +int main() { + long long t, total; + cin >> t; + long long s, a, b, c, div; + while (t--) { + total = 0; + cin >> s >> a >> b >> c; + total += (s / c); + div = s / c; + total += ((div / a) * b); + cout << total << endl; + } +} +int main() { + int n; + cin >> n; + map m; + string a[n + 1], b[n + 1]; + for (int i = (0); i < (n); i += (1)) { + cin >> a[i]; + m[a[i]]++; + } + int c = 0; + for (int i = (0); i < (n); i += (1)) { + cin >> b[i]; + if (m[b[i]] == 0) + c++; + else + m[b[i]]--; + } + cout << c << endl; + return 0; +} +long long i, ii, n, a, b, k, a1, x; +int main() { + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b >> k; + a1 = a; + x = 0; + a *= k / 2; + b *= k / 2; + x = a - b; + if (k % 2 == 1) x += a1; + cout << x << endl; + } +} +const int maxn = 100010; +int n, a, b; +int main() { + cin >> n; + int x, y, flag; + a = b = 0, flag = 1; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > 0) + a++; + else if (x < 0) + b++; + if (a >= 2 && b >= 2) { + flag = 0; + break; + } + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + int c = 0; + if (x <= n) c++; + for (int i = 2; i <= n; i++) { + if (x % i == 0 && x / i <= n) { c++; } + } + cout << c << endl; + return 0; +} +void sub(int &n) { + if (n % 10 == 0) + n /= 10; + else + n--; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { sub(n); } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10) { + cout << 0 << endl; + } else if (n < 20) { + cout << 4 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else if (n == 21) { + cout << 4 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + double c = double(k) / n; + if (c >= 3) { + cout << 0 << endl; + } else { + cout << n - k % n << endl; + } + return 0; +} +const int maxn = 1e3 + 5; +const int mod = 1000000007; +const double eps = 1e-7; +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +char str[maxn]; +int main() { + cin >> str; + int len = strlen(str); + int sum = 0; + int ans = 1; + for (int i = 1; i <= len; i++) { + if (str[i] == str[i - 1]) + ans++; + else { + if (ans % 2 == 0) sum++; + ans = 1; + } + } + cout << sum << endl; + return 0; +} +int main() { + long long r[201]; + r[0] = 1; + for (int i = 1; i <= 200; i++) { + r[i] = 2 * r[i - 1]; + r[i] %= 1000000007; + } + string x; + cin >> x; + int n = x.length(); + long long ans = 0; + for (int i = 0; i < n; i++) { + if (x.at(i) == '1') { + long long f = r[2 * (n - 1 - i)] * r[i]; + ans += f; + ans %= 1000000007; + } + } + cout << ans << endl; + return 0; +} +int main() { + char arr[101], *arr2, *res; + cin >> arr; + int lim = strlen(arr); + arr2 = new char[lim + 1]; + res = new char[lim + 1]; + cin >> arr2; + int i, j; + for (i = 0; arr[i]; i++) { + if ((arr[i] == '1' && arr2[i] == '0') || (arr[i] == '0' && arr2[i] == '1')) + res[i] = '1'; + else + res[i] = '0'; + } + res[i] = 0; + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cntr = 0; + while (n != 0) { + if (n >= 5) { + n -= 5; + cntr++; + } else if (n >= 4) { + n -= 4; + cntr++; + } else if (n >= 3) { + n -= 3; + cntr++; + } else if (n >= 2) { + n -= 2; + cntr++; + } else if (n >= 1) { + n -= 1; + cntr++; + } + } + cout << cntr << endl; +} +int main() { + int n; + int maxValue = INT_MIN; + cin >> n; + int a, b; + int d = 0; + int c = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + c = c + a; + d = d + b; + if (maxValue < abs(c - d)) maxValue = abs(c - d); + } + cout << maxValue << endl; + return 0; +} +int main() { + cout << "Karen" << endl; + return 0; +} +int main() { + int n, a, x = 0, y = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + x |= a; + } + for (int i = 0; i < n; i++) { + cin >> a; + y |= a; + } + cout << x + y << endl; + return 0; +} +int main() { + int n, ans = 0; + string s; + cin >> n; + map check; + for (int i = 0; i < n; i++) { + cin >> s; + check[s]++; + } + for (int i = 0; i < n; i++) { + cin >> s; + if (check[s] > 0) { + check[s]--; + continue; + } + ans++; + } + cout << ans << '\n'; +} +int main() { + int n, k, t; + cin >> n >> k; + int A[n + 1]; + A[0] = -1; + for (int i = 1; i < n + 1; i++) A[i] = 0; + for (int i = 0; i < k; i++) { + cin >> t; + A[t]++; + } + sort(A, A + n + 1); + cout << A[1] << '\n'; +} +void merge_sort(int a[], int low, int high); +void merge(int a[], int low, int mid, int high); +int main() { + int k; + cin >> k; + int a[12]; + for (int i = 0; i < 12; i++) { cin >> a[i]; } + merge_sort(a, 0, 11); + int end = 11; + int height = 0; + while (height < k && end >= 0) { + height += a[end]; + end--; + } + if (height >= k) { + cout << (11 - end) << endl; + } else { + cout << -1 << endl; + } +} +void merge_sort(int a[], int low, int high) { + if (low < high) { + int mid = (low + high) / 2; + merge_sort(a, low, mid); + merge_sort(a, mid + 1, high); + merge(a, low, mid, high); + } +} +void merge(int a[], int low, int mid, int high) { + int n1 = mid - low + 1; + int n2 = high - mid; + int l[n1], r[n2]; + for (int i = 0; i < n1; i++) { l[i] = a[low + i]; } + for (int j = 0; j < n2; j++) { r[j] = a[mid + j + 1]; } + int i = 0; + int j = 0; + int k = low; + while (i < n1 && j < n2) { + if (l[i] < r[j]) { + a[k] = l[i]; + i++; + } else { + a[k] = r[j]; + j++; + } + k++; + } + while (i < n1) { + a[k] = l[i]; + i++; + k++; + } + while (j < n2) { + a[k] = r[j]; + j++; + k++; + } +} +int main() { + int a, c = 1, d = 0, e = 0; + cin >> a; + int b[a + 1]; + for (int i = 0; i < a; i++) { + cin >> b[i]; + if (b[i] != 0) { e++; } + } + if (e == 0) { + cout << "0" << endl; + return 0; + } + if (e == 1) { + cout << "1" << endl; + return 0; + } else { + d++; + } + sort(b, b + a); + for (int i = 0; i < a - 1; i++) { + if (b[i] != 0) { + if (b[i] == b[i + 1]) { + } else { + d++; + } + } + } + cout << d << endl; +} +const int N = 1e2 + 5; +int f[N]; +int main() { + int n, m, mn, mx; + cin >> n >> m >> mn >> mx; + vector v(m); + for (int i = 0; i < m; i++) { + cin >> v[i]; + if (v[i] > mx || v[i] < mn) return puts("Incorrect"), 0; + f[v[i]] = 1; + } + n -= m; + m = (mx - mn + 1) - accumulate(f + mn, f + mx + 1, 0); + puts(n == 1 && !f[mn] && !f[mx] ? "Incorrect" : "Correct"); + return 0; +} +int n, a[101], tot; +bool v; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (a[i] == 1) { + tot++; + v = true; + } else if (a[i + 1] == 1 && v && a[i] + a[i - 1] >= 1) { + tot++; + } + } + cout << tot << endl; +} +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const int N = 1e5 + 5; +char mp[1005][1005]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> mp[i]; } + int l1 = -1, l2 = -1, r1 = -1, r2 = -1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (mp[i][j] == 'B' && l1 == -1) { + l2 = l1 = i; + r2 = r1 = j; + } else if (mp[i][j] == 'B' && i > l2 && j > r2) { + l2 = i, r2 = j; + } + } + } + cout << (l1 + 1 + l2 + 1) / 2 << " " << (r1 + 1 + r2 + 1) / 2 << "\n"; + return 0; +} +string in; +string n = ""; +int main() { + getline(cin, in); + int m = in.size(); + bool se = false; + for (int i = 0; i < m; i++) { + if (in[i] >= 'a' && in[i] <= 'z') { + n += in[i]; + } else if (in[i] == ' ') { + if (n == " ") { continue; } + cout << n; + n = ' '; + se = true; + continue; + } else { + if (se && n == " ") { + cout << in[i]; + n = ' '; + se = false; + continue; + } + cout << n << in[i]; + n = ' '; + } + } + if (n != " ") { cout << n; } + cout << endl; + return 0; +} +int main() { + string name; + cin >> name; + int distinct = 1; + sort(name.begin(), name.end()); + for (int i = 0; i < name.length() - 1; i++) { + if (name[i] != name[i + 1]) distinct++; + } + if (distinct % 2 != 0) { + cout << "IGNORE HIM!" << endl; + } else { + cout << "CHAT WITH HER!" << endl; + } + return 0; +} +int main() { + string a; + cin >> a; + int ans = 0, t = 1; + for (int i = 1; i < (int)a.size(); i++) { + if (a[i] == a[i - 1]) + t++; + else { + if (t % 2 == 0) ans++; + t = 1; + } + } + if (t % 2 == 0) ans++; + cout << ans << endl; + return 0; +} +int a, b, c, n, r; +int main() { + cin >> a >> b >> c >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a > b && a < c) r++; + } + cout << r << endl; + return 0; +} +int main() { + long long tt, n, x, s = 0; + cin >> n; + tt = n - 1; + while (tt--) { + cin >> x; + s += x; + } + cout << ((((n) * (n + 1)) / 2) - s) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string v[n]; + set s; + for (size_t i = 0; i < n; i++) cin >> v[i]; + for (size_t i = 0; i < m; i++) { + char c = '0'; + for (size_t j = 0; j < n; j++) + if (c < v[j][i]) c = v[j][i]; + for (size_t j = 0; j < n; j++) + if (c == v[j][i]) s.insert(j); + if (s.size() == n) break; + } + cout << s.size() << endl; + return 0; +} +int main() { + int a[5][5]; + int b[5][5]; + int i, j; + for (i = 0; i < 5; i++) { + a[0][i] = 0; + a[4][i] = 0; + a[i][0] = 0; + a[i][4] = 0; + } + for (i = 1; i < 4; i++) + for (j = 1; j < 4; j++) cin >> a[i][j]; + for (i = 1; i < 4; i++) + for (j = 1; j < 4; j++) { + if ((a[i - 1][j] + a[i + 1][j] + a[i][j - 1] + a[i][j + 1] + a[i][j]) % 2 == 0) + b[i][j] = 1; + else + b[i][j] = 0; + } + for (i = 1; i < 4; i++) { + for (j = 1; j < 4; j++) cout << b[i][j]; + cout << endl; + } +} +int main() { + string strs[] = {"Sheldon\n", "Leonard\n", "Penny\n", "Rajesh\n", "Howard\n"}; + int n = 0; + while (cin >> n) { + int i = 1; + while (n > i * 5) { + n -= i * 5; + i <<= 1; + } + int a = n / i; + if (n % i) a++; + cout << strs[a - 1]; + } + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + int sum = 0; + int arr[10005]; + for (int i = 1; i <= n; i++) { + int w = 0; + cin >> w; + if (w % k == 0) { + w /= k; + } else + w = w / k + 1; + arr[i] = w; + sum += arr[i]; + } + if (sum % 2 == 0) + sum /= 2; + else + sum = sum / 2 + 1; + cout << sum << endl; + } +} +int main() { + int n; + cin >> n; + set scores; + int tmp; + for (int i = 0; i < n; i++) { + cin >> tmp; + if (tmp != 0) scores.insert(tmp); + } + cout << scores.size() << endl; +} +int main() { + long long n, k; + cin >> n >> k; + long long c = 0, d = 0, nothing = 0; + c = k * (n / (2 * (k + 1))); + if (c > 0) { d = c / k; } + if (c > 0) { + while (c % d != 0) { c--; } + } + if (c > 0 && d > 0) { + nothing = n - (c + d); + cout << d << ' ' << c << ' ' << nothing << endl; + } else { + c = 0; + d = 0; + nothing = n; + cout << d << ' ' << c << ' ' << nothing << endl; + } +} +int main() { + int n, i; + cin >> n; + char a[201][100]; + for (i = 0; i < 2 * n; i++) { + cin >> a[i]; + a[i][strlen(a[i])] = '\0'; + } + int cou = 0; + for (i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (strcmp(a[j], a[n + i]) == 0 && a[j][0] != '1') { + a[j][0] = '1'; + a[n + i][0] = '1'; + cou++; + } + } + } + cout << (n - cou) << endl; + return 0; +} +stack st; +int main() { + int n; + cin >> n; + cout << n + (n / 2) << endl; + return 0; +} +int main() { + const int MODULO = 1000000009; + int n, m; + cin >> n >> m; + int i = 1; + int tavan = 2; + while (i < m) { + tavan = ((tavan % MODULO) * 2) % MODULO; + i++; + } + long long int output = tavan - 1; + for (int i = 2; i <= n; i++) { + output *= (tavan - i) % MODULO; + output = output % MODULO; + } + cout << output << endl; +} +int main() { + int n, i, a[101], sum = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] < 0) + sum = sum - a[i]; + else + sum += a[i]; + } + cout << sum << endl; +} +int main() { + long long int ans = 0, x, s, dp0 = 1, dp1 = 0, a, b; + cin >> s >> x; + if (x == 0 && s % 2 == 0) { + cout << 1 << endl; + return 0; + } + if (s == x) ans -= 2; + if (x > s) { + cout << 0 << endl; + return 0; + } + while (s) { + a = s % 2; + b = x % 2; + s /= 2; + x /= 2; + if (a == b) { + if (a == 0) { + dp0 = dp0; + dp1 = dp0; + } else { + dp0 = 2 * dp0; + dp1 = 0; + } + } else { + if (b == 0) { + dp0 = dp1; + dp1 = dp1; + } else { + dp0 = 0; + dp1 = 2 * dp1; + } + } + } + if (!dp0) + cout << 0 << endl; + else + cout << ans + dp0 << endl; +} +int main() { + int n, a, min, max, count = 0; + cin >> n >> a; + min = a; + max = a; + for (int i = 1; i < n; i++) { + cin >> a; + if (a > max) { + max = a; + count++; + } + if (a < min) { + min = a; + count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n; + int k; + string num; + cin >> n >> k; + cin >> num; + int a, b; + for (int i = 0; i < n; i++) { + if (num[i] == 'G') a = i; + if (num[i] == 'T') b = i; + } + if (a > b) swap(a, b); + int i; + bool flag = 1; + for (i = a; i < b; i += k) { + if (num[i] == '#') flag = 0; + } + if (i != b) flag = 0; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int c[1111]; +int main() { + int t; + cin >> t; + int a; + int k = 0; + for (int i = 3; i <= 360; ++i) { + if (360 % i == 0) { c[++k] = 180 - (360 / i); } + } + for (int i = 1; i <= t; ++i) { + cin >> a; + bool pp = false; + for (int j = 1; j <= k; ++j) { + if (c[j] == a) { + cout << "YES\n"; + pp = true; + break; + } + } + if (!pp) { cout << "NO\n"; } + } + return 0; +} +int main() { + int t, s, q; + cin >> t >> s >> q; + int ans = 0; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; +} +int main() { + int s[4], a, b; + while (cin >> s[0] >> s[1] >> s[2] >> s[3] >> a >> b) { + sort(s, s + 4); + if (s[0] > b) + cout << b - a + 1 << endl; + else if (s[0] > a) + cout << s[0] - a << endl; + else + cout << "0" << endl; + } + return 0; +} +const int N = 1e5 + 5; +const int inf = 1e9; +const long long INF = 1e18; +const double PI = acos(-1.0); +const double EPS = 1e-8; +const int MOD = 1000000007; +int n; +int a[N]; +int dp[N]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int ans = 0; + dp[0] = 0; + for (int i = 1; i <= n; i++) { + if (a[i] >= a[i - 1]) + dp[i] = dp[i - 1] + 1; + else + dp[i] = 1; + } + for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); + cout << ans << "\n"; + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int ans = 1e6; + for (int i = 1; i <= 100; i++) { ans = min(ans, abs(a - i) + abs(b - i) + abs(c - i)); } + cout << ans << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + string a; + cin >> a; + int n = a.length(); + if (n > 10) { + cout << a[0]; + cout << n - 2; + cout << a[n - 1] << endl; + } else { + cout << a << endl; + } + } +} +const int add = 100000; +int a, f[200005]; +int main() { + int n, ans = 0; + memset(f, 0, sizeof(f)); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + f[a + add]++; + if (f[a + add] == 1 && a) ans++; + } + cout << ans << endl; + return 0; +} +long long lca(long long x, long long y) { + while (x != y) { + if (x > y) + x >>= 1; + else + y >>= 1; + } + return x; +} +map cost; +void poskupi(long long x, long long y, long long w) { + while (x != y) { + if (x > y) { + cost[x] += w; + x >>= 1; + } else { + cost[y] += w; + y >>= 1; + } + } +} +long long cena(long long x, long long y) { + long long z = 0; + while (x != y) { + if (x > y) { + z += cost[x]; + x >>= 1; + } else { + z += cost[y]; + y >>= 1; + } + } + return z; +} +int main() { + int q; + cin >> q; + while (q--) { + int t; + cin >> t; + if (t == 1) { + long long u, v, w; + cin >> u >> v >> w; + poskupi(u, v, w); + } else { + long long u, v; + cin >> u >> v; + cout << cena(u, v) << '\n'; + } + } +} +long long n, k, a, sum, l; +int main() { + cin >> n >> k; + for (long long i = 1; i <= n; i++) { + cin >> a; + if (i != 1) { + if (sum - (n - i) * (i - 1) * a < k) { + cout << i + l << endl; + i--; + n--; + l++; + } else + sum += a * (i - 1); + } + } +} +long long n, a, b, c; +long long dp[5006][5005]; +long long result(long long total, long long cnt) { + if (total == 0) return cnt; + long long d = 0, e = 0, f = 0; + if (dp[total][cnt] != -1) return dp[total][cnt]; + if (a <= total) d = result(total - a, cnt + 1); + if (b <= total) e = result(total - b, cnt + 1); + if (c <= total) f = result(total - c, cnt + 1); + return dp[total][cnt] = max(d, max(e, f)); +} +int main() { + memset(dp, -1, sizeof dp); + cin >> n >> a >> b >> c; + long long ans = result(n, 0); + cout << ans << endl; +} +int main() { + double x, y, z; + cin >> x >> y >> z; + int ans = ceil((x * z) / 100) - y; + if (ans < 0) + cout << 0 << "\n"; + else + cout << ans << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[105]; + memset(a, 0, sizeof(a)); + for (int i = 1; i <= n; i++) { + int x1; + cin >> x1; + int y1; + for (int j = 1; j <= x1; j++) { + cin >> y1; + a[y1] = 1; + } + } + int judge = 1; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { + judge = 0; + cout << "NO" << endl; + break; + } + } + if (judge) { cout << "YES" << endl; } + return 0; +} +int main() { + int i, n; + cin >> n; + for (i = 1; i <= n; i++) { + if (i % 2 != 0) + cout << "I hate "; + else + cout << "I love "; + if (i != n) + cout << "that "; + else + cout << "it"; + } + cout << endl; + return 0; +} +int main() { + cout.precision(10); + cout << fixed; + int n, m; + cin >> n >> m; + vector v(m); + for (int i = 0; i < m; i++) cin >> v[i]; + sort(v.begin(), v.end()); + vector diff; + for (int i = 0; i < m - n + 1; i++) { diff.push_back(abs(v[i] - v[n + i - 1])); } + cout << *min_element(diff.begin(), diff.end()) << endl; +} +int main() { + int n; + cin >> n; + int a = 0, c = 0, b = 0, i; + for (int i = 1; i <= n; i++) { + b = (i * (i + 1)) / 2; + a += b; + if (a > n) break; + c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, m, i, j; + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 == 1) { + cout << "#"; + } else if (i % 4 == 2 && j == m) { + cout << "#"; + } else if (i % 4 == 0 && j == 1) { + cout << "#"; + } else + cout << "."; + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int t = 29, red, green, blue; + cin >> red >> green >> blue; + while (red > 0 || green > 0 || blue > 0) { + t = t + 1; + red = red - 2; + if (red <= 0 && green <= 0 && blue <= 0) { break; } + t = t + 1; + green = green - 2; + if (red <= 0 && green <= 0 && blue <= 0) { break; } + t = t + 1; + blue = blue - 2; + if (red <= 0 && green <= 0 && blue <= 0) { break; } + } + cout << t << endl; +} +void fast() {} +int main() { + int k, w; + long long n; + cin >> k >> n >> w; + int c = k * ((w * (w + 1)) / 2); + if (n >= c) + cout << 0 << endl; + else if (n < c) + cout << c - n << endl; +} +const long long OO = 1e5 + 555; +long long rakm(char x) { + return x - 48; +} +char _7rf(long long x) { + return x + 48; +} +bool odd(long long x) { + return x % 2; +} +bool even(long long x) { + return 1 - x % 2; +} +long long factorial(long long x) { + if (x == 0 || x == 1) { + return 1; + } else { + return x * factorial(x - 1); + } +} +long long ss(long long x) { + long long sum = 0; + while (x > 0) { + sum += x % 10; + x /= 10; + } + return sum; +} +long long a3ks(long long x) { + long long b = 0, u = x; + while (u > 0) { + b = (b * 10) + u % 10; + u /= 10; + } + return b; +} +bool prime(long long x) { + for (int i = 2; i < x; i++) { + if (x % i == 0) { return 0; } + } + return 1; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << (a * b * c) - ((a - 1) * (b - 1) * (c - 1)) << endl; +} +int main() { + int n, t, k, d, sum = 0, sum2 = 0, sum3 = 0, sum4 = 0; + cin >> n >> t >> k >> d; + int t1 = t, k1 = k; + if (n > k) { + do { + t = t + t1; + k = k + k1; + if (k == n) { + sum = t; + break; + } + sum = t; + } while (k <= n); + } + int qq = (((t1 + d) / t1) * k1) + k1; + int ee = t1 + d; + int yy = ee; + int tt = qq; + int nn = tt; + do { + if (qq >= n) tt = ee; + ee = ee + t1; + qq = qq + 2 * k1; + } while (qq <= n); + if (tt < sum) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n = 0; + string arr[5] = {"11111", "11111", "11111", "11111", "11111"}; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + cin >> n; + if (n % 2 > 0) { + for (int ii = i - 1, jj = j - 1; ii < i + 2; ii++, jj++) { + if (arr[ii][j] == '1') { + arr[ii][j] = '0'; + } else { + arr[ii][j] = '1'; + } + if (jj != j) { + if (arr[i][jj] == '1') { + arr[i][jj] = '0'; + } else { + arr[i][jj] = '1'; + } + } + } + } + } + } + for (int i = 1; i < 4; i++) { + arr[i].erase(arr[i].begin()); + arr[i].erase(arr[i].end() - 1); + cout << arr[i] << '\n'; + } +} +int mark[100], cnt = 'z' - 'a' + 1, ans; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + char t; + string s; + cin >> t >> s; + if (t == '?' || t == '!') + if (cnt == 1 && i != n) { + ans++; + continue; + } + if (t == '!') { + cnt = 0; + for (int i = 0; i < s.size(); i++) + if (mark[s[i] - 'a'] == 0) mark[s[i] - 'a'] = -1; + for (int i = 0; i <= 'z' - 'a'; i++) + if (mark[i] == -1) + mark[i] = 0, cnt++; + else + mark[i] = 1; + } else { + cnt = 0; + for (int i = 0; i < s.size(); i++) mark[s[i] - 'a'] = 1; + for (int i = 0; i <= 'z' - 'a'; i++) + if (mark[i] == 0) cnt++; + } + } + cout << ans << endl; + return 0; +} +int main() { + setlocale(LC_ALL, "Russian"); + unsigned int n; + cin >> n; + long long *array = new long long[n]; + for (unsigned int i = 0; i < n; i++) cin >> array[i]; + sort(array, array + n); + int *res = new int[n - 1]; + for (unsigned int i = 0; i < n - 1; i++) { + res[i] = array[i + 1] - array[i]; + res[i] = abs(res[i]); + } + int r = 1; + sort(res, res + n - 1); + for (unsigned int i = 1; i < n - 1; i++) { + if (res[i] == res[0]) + r++; + else + break; + } + cout << res[0] << " " << r << endl; + return 0; +} +int main() { + int n; + cin >> n; + int m = 2 * n; + while (m--) { + int a; + cin >> a; + } + cout << "Karen" << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + a = a * c; + c = b * c; + a = a - c; + d = a / b; + if ((a % b) != 0) d++; + cout << d << endl; +} +long long a, b, c, num; +long long ans; +string s; +int main() { + while (cin >> a >> b >> c >> s) { + num = 1; + for (int i = 1; i < a; i++) { + if (s[i] != s[i - 1]) { num++; } + } + if (s[0] == '1') { num--; } + if (b > c) + ans = num / 2 * c + (num % 2) * c; + else + ans = (num / 2 + num % 2 - 1) * b + c; + if (num == 0) { ans = 0; } + cout << ans << endl; + } + return 0; +} +int main() { + long long int n, x, y, ans, i; + cin >> n >> x >> y; + string s; + cin >> s; + long long int c = 0, f = 0; + for (i = 0; i < s.length(); i++) { + if (s[i] == '0') f = 1; + if (s[i] == '1' && f == 1) { + c++; + f = 0; + } + } + if (f) c++; + if (c != 0) { + ans = (c - 1) * min(x, y) + y; + cout << ans << "\n"; + } else + cout << 0 << "\n"; + return 0; +} +const int maxn = 105; +int n, m; +int a, b; +int ans = 0; +int main() { + cin >> n >> m; + for (int i = 0; i <= 1000; i++) { + for (int j = 0; j <= 1000; j++) { + if (i * i + j == n && i + j * j == m) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + for (i = 0; i < n; i++) { + char s[102]; + int l; + cin >> s; + l = strlen(s); + if (l > 10) + cout << s[0] << l - 2 << s[l - 1]; + else + cout << s; + cout << '\n'; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + reverse(b.begin(), b.end()); + stringstream n1(a); + stringstream n2(b); + int num1, num2; + n1 >> num1; + n2 >> num2; + long long int res = num1 + num2; + cout << res << endl; + return 0; +} +const int maxn = 1e5 + 5; +int arr[maxn], ar[maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp > 0) + ar[temp]++; + else + arr[-temp]++; + } + long long res = 0; + for (int i = 1; i < maxn; i++) { + if (arr[i] != 0) res++; + if (ar[i] != 0) res++; + } + cout << res << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int prazn = min(a, b); + int podin = (int)((max(a, b) - prazn) / 2); + cout << prazn << " " << podin << endl; + return 0; +}; +int main() { + string s; + cin >> s; + int n = s.size(); + for (int i = 0; i < n; i++) { + int c = 0; + if (s[i] - '0') { + for (int j = i + 1; j < n; j++) + if (s[j] - '0' == 0) c++; + if (c >= 6) { + cout << "yes" << endl; + return 0; + } + } + } + cout << "no" << endl; + return 0; +} +const int N = 1e5 + 5; +const int inf = 1e9; +const long long INF = 1e18; +const double PI = acos(-1.0); +const double EPS = 1e-8; +const int MOD = 1000000007; +int main() { + string s; + cin >> s; + stack st; + for (int i = 0; i < s.size(); i++) { + if (st.empty()) + st.push(s[i]); + else { + if (!st.empty() && st.top() == s[i]) + while (!st.empty() && st.top() == s[i]) st.pop(); + else + st.push(s[i]); + } + } + string ans = ""; + while (!st.empty()) ans += st.top(), st.pop(); + reverse(ans.begin(), ans.end()); + cout << ans << endl; + return 0; +} +int n; +int d, a[110]; +int main() { + cin >> n >> d; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int ans = 2; + for (int i = 2; i <= n; i++) { + if (a[i] - a[i - 1] >= 2 * d + 1) { ans += 2; } + if (a[i] - a[i - 1] == 2 * d) { ans++; } + } + cout << ans << endl; +} +int main() { + int n, m, x, y; + cin >> n >> m >> x >> y; + vector a; + a.resize(n); + vector b; + b.resize(m); + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int count = 0; + vector result; + result.resize(n); + int index = 0; + for (int i = 0, j = 0; i < n && j < m;) { + if (b[j] < a[i] - x) { + ++j; + } else if (b[j] > a[i] + y) { + ++i; + } else { + result[i] = j + 1; + i++; + j++; + ++count; + } + } + cout << count << "\n"; + for (int i = 0; i < result.size(); i++) { + if (result[i] != 0) { + cout << i + 1 << " " << result[i] << "\n"; + count--; + } + if (count == 0) break; + } + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + sort(V.begin(), V.end()); + cout << V[b] - V[b - 1] << "\n"; + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + int mnts = 24 * 60 - k; + long long sum = 20 * 60, ans = 0; + for (int i = 1; i <= n && sum + 5 * i <= mnts; i++) { sum += 1LL * 5 * i, ans++; } + cout << ans << endl; + } +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= 60) { + cout << m << endl; + } else { + cout << (m & ((1ll << n) - 1)) << endl; + } + return 0; +} +int main() { + int a[10000], b[10000], i, j, n, k, ans1, ans2, c; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (i = 0; i < n; i++) { + for (j = n - 1; j > i; j--) { + if (a[j] > a[j - 1]) { + swap(a[j], a[j - 1]); + swap(b[j], b[j - 1]); + } + if (a[j] == a[j - 1] && b[j] < b[j - 1]) swap(b[j], b[j - 1]); + } + } + ans1 = a[k - 1]; + ans2 = b[k - 1]; + for (i = 0, c = 0; i < n; i++) { + if (ans1 == a[i] && ans2 == b[i]) c++; + } + cout << c << endl; +} +int main() { + int n, a[11][11]; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j <= n; j++) { + if (i == 0 || j == 0) + a[i][j] = 1; + else + a[i][j] = a[i - 1][j] + a[i][j - 1]; + } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +int n; +int x[200001]; +int main() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> x[i]; + sort(x + 1, x + 1 + 2 * n); + if (x[n] < x[n + 1]) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + int ans = 0; + for (int i = 1; i <= z; i++) { + if (i % m == 0 && i % n == 0) { ans++; } + } + cout << ans << endl; + } +} +int main() { + long long int n; + int moon[100]; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> moon[i]; } + if (n == 1) { + if (moon[1] == 15) { + cout << "DOWN" << endl; + } else if (moon[1] == 0) { + cout << "UP" << endl; + } else + cout << "-1" << endl; + } else if (moon[n] == 0) { + cout << "UP" << endl; + } else if (moon[n] == 15) { + cout << "DOWN" << endl; + } else { + if (moon[n] - moon[n - 1] == 1) + cout << "UP" << endl; + else + cout << "DOWN" << endl; + } + } +} +int main() { + int i, j, n, a = 1, t, s[10000]; + cin >> n; + for (i = 0; i < n; i++) cin >> s[i]; + for (i = 0; i < n; i++) { + t = 0; + for (j = 0; j <= i; j++) { + if (!s[j]) t++; + } + for (j = i; j < n; j++) { + if (s[j]) t++; + } + a = max(a, t); + } + cout << a << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + long int a; + cin >> a; + while (a--) { + long long b, c, d; + cin >> b >> c >> d; + long long h = (b - c) * (d / 2); + if (d % 2 == 1) h += b; + cout << h << endl; + } +} +int main() { + int n; + cin >> n; + int h[n]; + int a[n]; + int counter = 0; + for (int i = 0; i < n; i++) { + cin >> h[i]; + cin >> a[i]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (h[i] == a[j]) { + counter++; + } else { + continue; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long ft = (n / 36), cm = n - (36 * ft); + long long in = cm / 3; + if (cm % 3 == 2) in++; + if (in == 12) ft++, in = 0; + cout << ft << " " << in << endl; +} +int main() { + long long int n = 0; + cin >> n; + if (n % 2 == 0) + cout << n / 2 << endl; + else + cout << -((n + 1) / 2) << endl; +} +int main() { + int n, r; + cin >> n >> r; + for (int i = 1;; i++) { + int t = i * n; + if (t % 10 == r || t % 10 == 0) { + cout << i << endl; + break; + } + } +} +int main() { + long long n, s; + cin >> n >> s; + cout << (s / n) + (s % n != 0) << endl; + return 0; +} +string a; +long long b; +bool x, y; +int main() { + cin >> a; + if (a[0] == 'h' || a[0] == 'a') x = 1; + if (a[1] == '8' || a[1] == '1') y = 1; + if (x == 1 && y == 1) b++; + if (x == 1) b = b - 3; + if (y == 1) b = b - 3; + cout << b + 8 << endl; +} +map a, b; +string A[105], B[105]; +int main() { + int n; + a.clear(), b.clear(); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> A[i]; + a[A[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> B[i]; + b[B[i]]++; + } + int ans = n; + for (map::iterator it = a.begin(); it != a.end(); it++) ans -= min(it->second, b[it->first]); + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << n + n / 2 << endl; +} +string s, f = "QAQ"; +int ans, len; +int dfs(int a, int b) { + if (b == 3) ++ans; + for (int i = a; i < len; ++i) { + if (s[i] == f[b]) dfs(i + 1, b + 1); + } + return ans; +} +int main() { + cin >> s; + len = s.size(); + cout << dfs(0, 0) << endl; + return 0; +} +int main() { + int r, b; + cin >> r >> b; + if (r < b) { + cout << r << " " << (b - r) / 2 << endl; + ; + } else { + cout << b << " " << (r - b) / 2 << endl; + ; + } +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << "2" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string arr[n]; + int tetr = 0, cube = 0, dodec = 0, icos = 0, oct = 0, ans = 0; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + if (arr[i] == "Tetrahedron") + tetr++; + else if (arr[i] == "Cube") + cube++; + else if (arr[i] == "Octahedron") + oct++; + else if (arr[i] == "Dodecahedron") + dodec++; + else + icos++; + } + ans = (tetr * 4) + (cube * 6) + (oct * 8) + (dodec * 12) + (icos * 20); + cout << ans << endl; + return 0; +} +const int inf = 205; +int a[inf]; +int b[inf]; +int main() { + int m, n, k, t, x; + while (cin >> n) { cout << n / 2 + 1 << endl; } + return 0; +} +int main() { + int p, n; + int inp; + int arr[307]; + for (int i = 0; i <= 300; i++) arr[i] = 0; + int res = -1; + bool flag = false; + cin >> p >> n; + for (int i = 0; i < n; i++) { + cin >> inp; + if (flag) continue; + if (arr[inp % p] == 0) + arr[inp % p]++; + else { + res = i + 1; + flag = true; + } + } + cout << res << endl; + return 0; +} +int main() { + int n, l = 0, r = 0, m = 0; + string s; + cin >> s; + while (r < ((int)(s).size())) { + if (s[r] == s[l]) + r++; + else { + if (!((r - l) & 1)) m++; + l = r; + } + } + if (!((r - l) & 1)) m++; + cout << m << endl; +} +int main() { + long long i, j, k, l, m, n, ans = 0; + cin >> n >> k; + long long a[n + 10]; + long long b[n + 10]; + memset(b, 0, sizeof b); + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + if (a[i] <= k) + ans++, b[i] = 1; + else + break; + } + for (i = n - 1; i >= 0; i--) { + if (a[i] <= k && b[i] == 0) + ans++; + else + break; + } + cout << ans << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << (a * b) + (b * c) + (c * a) - a - b - c + 1 << endl; + return 0; +} +int mat[3][3] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; +void imprimir() { + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { cout << mat[i][e]; } + cout << endl; + } +} +void encender(int i, int e) { + mat[i][e] = !mat[i][e]; + if (e + 1 <= 2) { mat[i][e + 1] = !mat[i][e + 1]; } + if (e - 1 >= 0) { mat[i][e - 1] = !mat[i][e - 1]; } + if (i - 1 >= 0) { mat[i - 1][e] = !mat[i - 1][e]; } + if (i + 1 <= 2) { mat[i + 1][e] = !mat[i + 1][e]; } +} +int main() { + for (int i = 0; i < 3; i++) { + for (int e = 0; e < 3; e++) { + int aux; + cin >> aux; + if (aux % 2 != 0) encender(i, e); + } + } + imprimir(); + return 0; +} +int main() { + int n; + cin >> n; + int a[10][10]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + a[i][0] = 1; + a[0][j] = 1; + } + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; +} +int main() { + cout << "Karen" << endl; + return 0; +} +int main() { + int n, a[609]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (n == 1 && a[n] != 15 && a[n] != 15 && a[n] != 0) { + cout << -1 << endl; + return 0; + } + if (a[n] == 15) { + cout << "DOWN\n"; + return 0; + } + if (a[n] == 0) { + cout << "UP\n"; + return 0; + } + if (a[n] < a[n - 1] && a[n] != 0) { + cout << "DOWN\n"; + } else + cout << "UP\n"; +} +string s; +long long n, m; +long long ans; +int main() { + cin >> s; + s = "a" + s; + for (long long i = 1; i < s.size(); i++) { + n = abs(s[i] - s[i - 1]); + n = min(n, 26 - n); + ans += n; + } + cout << ans << endl; +} +int main() { + long long int n, k, h, m, i, sum, j, c; + string s; + while (cin >> s) { + c = 1; + if (s != "WBWBWBWB" && s != "BWBWBWBW") { c = 0; } + for (i = 1; i < 8; i++) { + cin >> s; + if (s != "WBWBWBWB" && s != "BWBWBWBW") { c = 0; } + } + if (c) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long x = 0, a, b, k; + cin >> a >> b >> k; + x += ((a - b) * (k / 2)); + if (k % 2 == 1) { x += a; } + cout << x << endl; + } +} +string s, ss, sss; +int main() { + cin >> s >> ss >> sss; + if (s == ss && s != sss) { + if (s == "rock") { + if (sss == "paper") + cout << "S" << '\n'; + else + cout << "?" << '\n'; + } + if (s == "paper") { + if (sss == "scissors") + cout << "S" << '\n'; + else + cout << "?" << '\n'; + } + if (s == "scissors") { + if (sss == "rock") + cout << "S" << '\n'; + else + cout << "?" << '\n'; + } + } else if (s == sss && s != ss) { + if (s == "rock") { + if (ss == "paper") + cout << "M" << '\n'; + else + cout << "?" << '\n'; + } + if (s == "paper") { + if (ss == "scissors") + cout << "M" << '\n'; + else + cout << "?" << '\n'; + } + if (s == "scissors") { + if (ss == "rock") + cout << "M" << '\n'; + else + cout << "?" << '\n'; + } + } else if (ss == sss && ss != s) { + if (ss == "rock") { + if (s == "paper") + cout << "F" << '\n'; + else + cout << "?" << '\n'; + } + if (ss == "paper") { + if (s == "scissors") + cout << "F" << '\n'; + else + cout << "?" << '\n'; + } + if (ss == "scissors") { + if (s == "rock") + cout << "F" << '\n'; + else + cout << "?" << '\n'; + } + } else + cout << "?" << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + long long i; + vector v; + long long sum = 0; + for (i = 0; i < n; i++) { + long long a; + cin >> a; + sum = sum + a; + v.push_back(a); + } + long long x; + long long summ = 0; + if (sum % 2 == 0) { + x = sum / 2; + } else { + x = sum / 2 + 1; + } + for (i = 0; i < n; i++) { + summ = summ + v[i]; + if (summ >= x) { + cout << i + 1 << "\n"; + return 0; + } + } +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + if (e > c) swap(e, c), swap(f, b); + cout << 2 * c * (d + e) - e * e + 2 * a * b + b * b << endl; +} +int main() { + string s1, s2; + cin >> s1; + cin >> s2; + int a = s1.length(); + int b = s2.length(); + int flag = 0; + for (int i = 0; i < a; i++) { + if (s1[i] != s2[b - i - 1] || a != b) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + double n, x, y; + cin >> n >> x >> y; + long long z = ceil((y / 100) * n); + long long ans = 0; + if (z > x) { ans = z - x; } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int cnt; + cin >> cnt; + if (cnt > b && cnt < c) { ++ans; } + } + cout << ans << endl; + return 0; +} +int main() { + string s, r, t = ""; + cin >> s >> r; + for (int i = 0; i < s.length(); i++) { + if (s[i] == r[i]) + t += '0'; + else + t += '1'; + } + cout << t << endl; + return 0; +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int arr[m]; + for (int i = 0; i < m; ++i) cin >> arr[i]; + sort(arr, arr + m); + int mn = 1e9; + for (int i = 0; i <= m - n; ++i) mn = min(mn, arr[i + n - 1] - arr[i]); + cout << mn << endl; +} +void solve() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 0; i <= n; i++) { a[i] = 0; } + int ans = 0; + int mx = 0; + for (int i = 0; i < 2 * n; i++) { + int x; + cin >> x; + if (a[x] == 0) + ans++; + else + ans--; + a[x]++; + mx = max(ans, mx); + } + cout << mx << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int N; + int ud = 0; + int lr = 0; + cin >> N; + string s; + for (int i = 0; i < N; i++) { + cin >> s; + if (s.size() == 4) + ud++, lr++; + else if ((s == "UR") || (s == "DL")) + ud++; + else + lr++; + } + long long ans = ((long long)(++ud)) * ((long long)(++lr)); + cout << ans << endl; + return 0; +} +const int maxn = 2 * 1e5 + 5; +const int inf = 0x3fffffff; +int main() { + string a, b; + while (cin >> a >> b) { + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + } +} +const int N = 1e6 + 55; +const int M = 1e9 + 7; +int n, a, b; +vector v; +int main() { + cin >> n >> a >> b; + for (int i = 1; i <= n; ++i) { + int q; + cin >> q; + v.push_back(q); + } + sort(v.begin(), v.end()); + int q = v[n - a] - v[n - a - 1]; + if (q <= 0) { + cout << 0 << endl; + exit(0); + } + cout << q << endl; + return 0; +} +int main() { + string cha, inst; + cin >> cha >> inst; + int pos = 0; + for (int i = 0; i < inst.length(); ++i) { + if (cha[pos] == inst[i]) pos++; + } + cout << pos + 1 << endl; + return 0; +} +const int MOD = 1e9 + 7; +const long long INF = LLONG_MAX / 2; +int main() { + int N; + cin >> N; + string s; + cin >> s; + vector v; + v.push_back(-1); + for (int i = 0; i < N; i++) + if (s[i] == '0') v.push_back(i); + v.push_back(N); + for (int k = 0; k + 1 < v.size(); k++) cout << v[k + 1] - v[k] - 1; + cout << endl; +} +int s[1000]; +set ss[1000]; +int main() { + int n, m; + cin >> n >> m; + char c; + for (int i = 0; i < n; i++) { + for (int k = 0; k < m; k++) { + cin >> c; + if ((c - '0') == s[k]) { + s[k] = c - '0'; + ss[k].insert(i); + } else if ((c - '0') > s[k]) { + s[k] = c - '0'; + ss[k].clear(); + ss[k].insert(i); + } + } + } + set sss; + int num = 0; + set::iterator it; + for (int i = 0; i < m; i++) { + it = ss[i].begin(); + while (it != ss[i].end()) { + if (sss.find(*it) == sss.end()) { + num++; + sss.insert(*it); + } + it++; + } + } + cout << num << endl; + return 0; +} +int a[15][15]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { a[i][1] = a[1][i] = 1; } + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n][n] << endl; + return 0; +} +int main() { + int x, n; + int last = -1; + int ans = 0; + int count = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x > last) { + count++; + } else { + count = 1; + } + ans = max(ans, count); + last = x; + } + cout << ans << "\n"; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int i = 0, j = 0, k, n; + string s; + vector v; + cin >> s; + n = s.size(); + k = n - 1; + v.resize(n, 0); + while (i < n) { ((s[i++] == 'r') ? v[j++] : v[k--]) = i; } + for (i = 0; i < n; ++i) { cout << v[i] << '\n'; } + return 0; +} +int getGood(char a) { + if (a == '0') return 2; + if (a == '1') return 7; + if (a == '2') return 2; + if (a == '3') return 3; + if (a == '4') return 3; + if (a == '5') return 4; + if (a == '6') return 2; + if (a == '7') return 5; + if (a == '8') return 1; + return 2; +} +int main() { + string a; + cin >> a; + cout << getGood(a[0]) * getGood(a[1]) << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + long long n, m, ans = 0, sum = 0; + cin >> n >> m; + ans = m; + for (int i = 1; i <= n; i++) { + long long q; + char x; + cin >> x >> q; + if (x == '+') + ans += q; + else { + if (ans >= q) + ans -= q; + else + sum++; + } + } + cout << ans << " " << sum << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + for (int j = 1; j <= i * 2 - 1; j++) cout << "D"; + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n; i++) cout << "D"; + cout << endl; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 1; j <= n - 2 * i; j++) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << endl; + } + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 1; i < n - 1; ++i) + if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]) ++ans; + cout << ans << "\n"; + cin >> n; +} +int a[100005]; +int main() { + int n, m = 0; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (a[0] != 0) + m = 1; + else + m = 0; + for (int i = 0; i < n - 1; i++) { + if (a[i] != a[i + 1] && a[i + 1] != 0) { m++; } + } + cout << m << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << n % 2 << endl; +} +int main() { + double k, n, s, p; + cin >> k >> n >> s >> p; + cout << (long long)ceil(double((int)ceil(n / s) * k) / p) << endl; + return 0; +} +int main() { + int a[100000], n, c1 = 0, c2 = 0, mx = 0, mn = 1000000000; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mx = max(mx, a[i]); + mn = min(mn, a[i]); + } + for (int i = 0; i < n; i++) { + if (a[i] == mx) c1++; + if (a[i] == mn) c2++; + } + if (mx == mn) + cout << 0 << endl; + else + cout << (n - c1 - c2) << endl; + return 0; +} +int main() { + double l, x, y; + cin >> l; + cin >> x >> y; + if (y > x) { + cout << l - ((l / (x + y)) * max(x, y)) << endl; + } else { + cout << (l / (x + y)) * max(x, y) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int m; + cin >> m; + int b[m]; + for (int i = 0; i < m; i++) { cin >> b[i]; } + sort(a, a + n); + int maxi = -1; + sort(b, b + m, greater()); + for (int j = 0; j < n; j++) { + for (int i = 0; i < m; i++) { + if (b[i] % a[j] == 0) { + if (b[i] / a[j] > maxi) { maxi = b[i] / a[j]; } + } + } + } + int cnt = 0; + for (int j = 0; j < n; j++) { + for (int i = 0; i < m; i++) { + if (b[i] % a[j] == 0) { + if (b[i] / a[j] == maxi) { cnt++; } + } + } + } + cout << cnt << "\n"; +} +int main() { + long long i, j, n, m, k, cnt = 0, ans = 0, t = 1; + cin >> n; + k = 1; + t = 2; + for (i = 0; i < n; i++) { + cout << (k + 1) * k * (k + 1) - t / k << '\n'; + t = (k + 1) * k; + k++; + } + return 0; +} +string s; +int main() { + while (cin >> s) { + int flag = 0, ans = 0; + for (int i = 0; i < s.length(); ++i) { + if (s[i] == 'V' && s[i + 1] == 'K') { + ans++; + s[i] = 'a'; + s[i + 1] = 'a'; + } + } + for (int i = 0; i < s.length(); ++i) { + if ((s[i] == 'V' && s[i + 1] == 'V') || (s[i] == 'K' && s[i + 1] == 'K')) flag = 1; + } + cout << ans + flag << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = 0; + for (int i = 0; i < a; i++) { + int x; + cin >> x; + if (i < a - b) { + ans += x; + } else + ans += c; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string s; + long long int t = 0, uno = 0, dos = 0; + for (int i = 0; i < n; i++) { + cin >> s; + t += s == "ULDR"; + uno += s == "UR" or s == "DL"; + dos += s == "UL" or s == "DR"; + } + cout << (t + uno + 1) * (t + dos + 1) << endl; +} +vector v; +int n; +int minDif() { + int c = 0; + for (int i = 1; i < n - 1; ++i) { c = max(c, v[i] - v[i - 1]); } + return c; +} +int main() { + cin >> n; + int i = 0, a, r = 1e9, num; + while (i++ < n) { + cin >> a; + v.push_back(a); + } + for (int i = 1; i < n - 1; ++i) { + num = v[i]; + v.erase(v.begin() + i); + r = min(r, minDif()); + v.insert(v.begin() + i, num); + } + cout << r << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + int brr[n]; + for (int i = 1; i <= n; i++) cin >> arr[i]; + for (int i = 1; i <= n; i++) cin >> brr[i]; + int maxi = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int var1 = 0; + int var2 = 0; + for (int k = i; k <= j; k++) { + var1 = var1 | arr[k]; + var2 = var2 | brr[k]; + } + maxi = max(maxi, var1 + var2); + } + } + cout << maxi << endl; +} +int main() { + int a, b, c, r; + cin >> a >> b >> c; + r = a * c; + if (r % b) + r = r / b + 1; + else + r = r / b; + cout << (r - c) << endl; + return 0; +} +short n, i, j, counter; +string l, mas[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +string mas1[6] = {"purple", "green", "blue", "orange", "red", "yellow"}; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> l; + for (j = 0; j < 6; j++) { + if (mas1[j] == l) { + mas1[j] = "0"; + counter++; + } + } + } + cout << 6 - counter << endl; + for (i = 0; i < 6; i++) { + if (mas1[i] != "0") { cout << mas[i] << endl; } + } + return 0; +} +int main() { + long long int n, x, y; + cin >> n >> x >> y; + string s; + cin >> s; + long long int count = 0, one = 0; + for (int i = 1; i < n; i++) { + if (s[i] == '1') one++; + if (s[i] == '0' && s[i - 1] == '1') count++; + } + if (one == n - 1 && s[0] == '1') + cout << 0 << endl; + else { + if (s[0] == '0') count++; + cout << min((count - 1) * x + y, (count)*y) << endl; + } + return 0; +} +long long a, b, c, v, e; +int main() { + cin >> a >> b; + if (a <= b) + v = a; + else + v = b; + a = b = 1; + while (v > 0) { + b *= a; + a++; + v--; + } + cout << b << endl; + return 0; +} +void fuck(string a) { + if (a.size() <= 10) + cout << a << endl; + else + cout << a[0] << a.size() - 2 << a[a.size() - 1] << endl; +} +int main() { + int n; + cin >> n; + string x; + for (int i = 1; i <= n; i++) { + cin >> x; + fuck(x); + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + m %= (n * (n + 1) / 2); + for (int i = 1; i <= n; ++i) { + if (m < i) { break; } + m -= i; + } + cout << m << endl; + return 0; +} +int main() { + int k, a, b, v; + while (cin >> k >> a >> b >> v) { + int sum = 0, box = 0; + while (b != 0) { + if (b >= k - 1) { + sum += k * v; + b = b - k + 1; + box++; + } else { + sum += (b + 1) * v; + box++; + b = 0; + } + if (sum >= a) break; + } + while (sum < a) { + sum += v; + box++; + } + cout << box << endl; + } + return 0; +} +int main() { + double k, n, s, p, i, j; + cin >> k >> n >> s >> p; + i = ceil(n / s); + j = i * k; + int l = ceil(j / p); + cout << l << endl; + return 0; +} +int n, k; +char s[999]; +int ans[28]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> s[i], ans[s[i] - 'a']++; + if (ans[s[i] - 'a'] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int minn1, minn2, minn3, maxx1, maxx2, maxx3; + int n; + while (cin >> n) { + cin >> minn1 >> maxx1; + cin >> minn2 >> maxx2; + cin >> minn3 >> maxx3; + int sum1 = minn1; + int sum2 = minn2; + int sum3 = minn3; + int x = n - sum1 - sum2 - sum3; + while (sum1 < maxx1 && x != 0) { + x--; + sum1++; + } + while (sum2 < maxx2 && x != 0) { + x--; + sum2++; + } + while (sum3 < maxx3 && x != 0) { + x--; + sum3++; + } + cout << sum1 << ' ' << sum2 << ' ' << sum3 << endl; + } + return 0; +} +int main() { + int a[201], b[201]; + int n, k; + int flag, mark; + while (cin >> n >> k) { + flag = 0; + mark = -1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) mark = i; + } + for (int i = 0; i < k; i++) { cin >> b[i]; } + if (k > 1) + cout << "Yes" << endl; + else { + a[mark] = b[0]; + for (int i = 1; i < n; i++) { + if (a[i] < a[i - 1]) { + flag = 1; + break; + } + } + if (flag) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + } + } + return 0; +} +int k, n, x, a[110]; +int main() { + cin >> n >> k >> x; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int ans = 0; + for (int i = 1; i <= n; i++) { + if (i > n - k) { + ans += min(a[i], x); + } else { + ans += a[i]; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, d[255], s, t; + int res1 = 0, res2 = 0; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> d[i]; } + for (int i = n + 1; i <= 2 * n; i++) { d[i] = d[i - n]; } + cin >> s >> t; + if (s > t) swap(s, t); + for (int i = s; i < t; i++) { res1 += d[i]; } + for (int i = t; i < n + s; i++) { res2 += d[i]; } + cout << min(res1, res2) << endl; +} +int main() { + int n, i, k, t, a; + while (cin >> n >> k) { + t = 0; + for (i = 0; i < n; i++) { + cin >> a; + t += (a + k - 1) / k; + } + cout << (t + 1) / 2 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int vet[2 * n]; + for (int i = 0; i < 2 * n; i++) { cin >> vet[i]; } + sort(vet, vet + (2 * n)); + if (vet[n - 1] < vet[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int a, b, c, t, n, min; + cin >> a >> b >> c; + n = a * c; + t = (n / b); + if (t * b >= n) + cout << (n / b) - c << endl; + else + cout << ((n / b) + 1) - c << endl; + return 0; +} +long double n; +string s, s1, a, b, pod, pod1; +int main() { + cin >> s >> s1 >> n; + pod = s, pod1 = s1; + cout << pod << " " << pod1 << endl; + while (n--) { + cin >> a >> b; + if (a == pod) + pod = b; + else + pod1 = b; + cout << pod << " " << pod1 << endl; + } +} +const int maxn = 2e5 + 100; +const int mod = 998244353; +int q; +map m; +int main() { + string str; + while (cin >> q) { + m.clear(); + while (q--) { + string x, str; + cin >> str >> x; + int len = x.size(); + string y = ""; + for (int i = 0; i < 18 - len; i++) y += "0"; + for (int i = 0; i < len; i++) { + int num = x[i] - '0'; + if (num & 1) + x[i] = '1'; + else + x[i] = '0'; + } + y += x; + if (str == "+") { + m[y]++; + } else if (str == "-") { + m[y]--; + } else { + cout << m[y] << endl; + } + } + } + return 0; +} +int main() { + string str; + cin >> str; + int counter = 0, n = str.size(); + char pointer = 'a'; + for (int i = 0; i < n; i++) { + counter += (min(abs(pointer - str[i]), 26 - (abs(pointer - str[i])))); + pointer = str[i]; + } + cout << counter << endl; + return 0; +} +int main() { + int x[3]; + for (int i = 0; i < 3; i++) { cin >> x[i]; } + sort(x, x + 3); + cout << x[2] - x[0] << endl; +} +int main() { + int n; + cin >> n; + vector vec(n + 1, 0); + int q; + cin >> q; + int inp; + for (int i = 0; i < q; i++) { + cin >> inp; + vec[inp]++; + } + int points = 99999999; + for (int i = 1; i <= n; i++) { + if (vec[i] < points) points = vec[i]; + } + cout << points << endl; + return 0; +} +int main() { + int n; + cin >> n; + int freq[3] = {}; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + freq[x - 1]++; + } + int m = max(freq[0], max(freq[1], freq[2])); + cout << n - m << endl; +} +int main() { + int i, j, n, a; + cin >> n; + while (n--) { + int flag = 0; + cin >> a; + for (i = 3; i <= 360; i++) + if ((i - 2) * 180 == i * a) { + cout << "YES" << endl; + flag = 1; + break; + } + if (flag == 0) cout << "NO" << endl; + } +} +int main() { + int t, s, q; + cin >> t >> s >> q; + int ans = 1; + int x = s * q; + while (x < t) { + ans++; + x *= q; + } + cout << ans << endl; + return 0; +} +int main() { + int a = 0, tam = 0, comeco = 0, fim = 0; + cin >> a >> tam; + bool isThere[tam + 1]; + for (int j = 0; j <= tam; j++) { isThere[j] = false; } + for (int b = 0; b < a; b++) { + cin >> comeco >> fim; + for (int c = comeco; c <= fim; c++) { isThere[c] = true; } + } + int resp = 0; + int presentes[tam + 1]; + string ordem = ""; + for (int b = 1; b <= tam; b++) { + if (!isThere[b]) { + presentes[resp] = b; + resp++; + } + } + cout << resp << endl; + for (int b = 0; b < resp; b++) { + cout << presentes[b]; + if (b == resp - 1) { + cout << endl; + } else { + cout << " "; + } + } + return 0; +} +int main() { + long long int n, m, o, i, j, k, sum = 0; + cin >> n >> m >> o; + for (i = 1; i <= o; i++) { sum = sum + n * i; } + if (sum > m) + k = sum - m; + else + k = 0; + cout << k << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + a.push_back(tmp); + } + int m; + cin >> m; + vector b; + for (int i = 0; i < m; i++) { + int tmp; + cin >> tmp; + b.push_back(tmp); + } + int cur = 0, max = 0, count = 0; + for (int j = 0; j < m; j++) + for (int i = 0; i < n; i++) { + if (b[j] % a[i] == 0) { + cur = b[j] / a[i]; + if (cur > max) { + max = cur; + count = 1; + continue; + } + if (cur == max) count++; + } + } + cout << count << endl; + return 0; +} +int main() { + string s; + cin >> s; + vector arr; + long long int i; + for (i = 0; i < 5; i++) { + string str; + cin >> str; + arr.push_back(str); + } + bool fl = 0; + for (i = 0; i < 5; i++) { + string tem = arr[i]; + if (s[0] == tem[0] || s[1] == tem[1]) { + fl = 1; + break; + } + } + if (fl) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int m, n, ss, k; + cin >> m >> n; + bool x[n + 1], flag = true; + memset(x, false, sizeof(x)); + for (int i = 0; i < m; i++) { + cin >> k; + for (int j = 0; j < k; j++) { + cin >> ss; + x[ss] = true; + } + } + for (int i = 1; i <= n; i++) + if (!x[i]) flag = false; + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +inline bool is_palindrome(const string &s) { + return equal(s.begin(), s.end(), s.rbegin()); +} +const long long MOD = 1000000007; +const long long INF = 1e9 + 5; +const double eps = 1e-7; +const double PI = acos(-1.0); +int main() { + int n; + cin >> n; + unsigned long long l, r, ans, tmp; + while (n--) { + cin >> l >> r; + ans = l; + for (long long i = (long long)(0); i < (long long)(64); i++) { + if ((ans | (1ULL << i)) <= r) { ans |= (1ULL << i); } + } + cout << ans << "\n"; + } + return 0; +} +int a[20][20]; +void runn() { + for (int i = 1; i <= 10; i++) { + a[i][1] = 1; + a[1][i] = 1; + } + for (int i = 2; i <= 10; i++) + for (int j = 2; j <= 10; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; +} +int main() { + int n; + cin >> n; + runn(); + cout << a[n][n] << endl; + return 0; +} +int main() { + int tc; + cin >> tc; + while (tc--) { + int a, b; + cin >> a >> b; + int res = 0; + while (a > 0 && b > 0) { + if (a > b) swap(a, b); + int h = b - a; + h += (a - h % a); + res += h / a; + b -= h; + } + cout << res << endl; + } + return 0; +} +int main() { + int d, f, a[100001], o = 0; + cin >> d >> f; + for (int i = 0; i < d; i++) { + cin >> a[i]; + o++; + if (i == 0) { + i = 0; + } else if ((a[i] - a[i - 1]) <= f) { + o = o; + } else if ((a[i] - a[i - 1]) > f) { + o = 1; + } + } + cout << o << endl; +} +const int INF = 1000 * 1000 * 1000; +int main() { + long long n, sum = 0; + cin >> n; + for (long long i = 0; i < n; i++) { + long long x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (x2 < x1) swap(x1, x2); + if (y2 < y1) swap(y1, y2); + sum += (y2 - y1 + 1) * (x2 - x1 + 1); + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum1 = 0, sum2 = 0; + int a, b; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a > b) + sum1++; + else if (a < b) + sum2++; + else + ; + } + if (sum1 > sum2) + cout << "Mishka" << endl; + else if (sum1 < sum2) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string st; + vector v; + for (int i = 0; i < n; ++i) { + cin >> st; + v.push_back(st); + } + int count = 0; + for (int i = 0; i < st.size(); ++i) { + bool done = true; + for (int j = 0; j < n - 1; ++j) { + if (v[j][i] != v[j + 1][i]) { + done = false; + break; + } + } + if (done) { + ++count; + } else { + break; + } + } + cout << count << endl; + return 0; +} +int a[65], c, n; +int main() { + cin >> n; + for (int i = 0; i < n * 2; i++) cin >> a[i]; + for (int i = 0; i < n * 2; i++) { + for (int j = i + 1; j < n * 2 + 1; j += 2) + if (a[i] == a[j]) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long x = sqrt(n), a, b; + for (int i = x; i; i--) { + if (n % i == 0) { + a = i; + b = n / i; + break; + } + } + cout << min(a, b) << " " << max(a, b) << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if ((n % 2) == 0) + cout << n / 2 << endl; + else + cout << (n / 2) - n << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector levels(n, 0); + int x, y; + cin >> x; + int x_level; + for (int i = 0; i < x; i++) { + cin >> x_level; + levels[x_level - 1] = true; + } + cin >> y; + int y_level; + for (int i = 0; i < y; i++) { + cin >> y_level; + levels[y_level - 1] = true; + } + bool flag = false; + for (int i = 0; i < levels.size(); i++) { + if (!levels[i]) { + flag = true; + break; + } + } + if (flag) + cout << "Oh, my keyboard!\n"; + else + cout << "I become the guy.\n"; + return 0; +} +int main() { + string s; + int i, k, l, q; + getline(cin, s); + for (i = 0; i < s.length(); i++) { + if ((int)(s[i]) > 47 && (int)(s[i]) < 58) { k = 1; } + if ((int)(s[i]) > 64 && (int)(s[i]) < 90) { l = 1; } + if ((int)(s[i]) > 96 && (int)(s[i]) < 123) { q = 1; } + } + if (s.length() > 4 && k == 1 && l == 1 && q == 1) { + cout << "Correct" << endl; + } else { + cout << "Too weak" << endl; + } + return 0; +} +int main() { + char s[1001]; + while (cin >> s) { + int sum = 0; + for (int i = 0; i < strlen(s); i++) { + if (s[i] == 'Q') { + for (int j = i + 1; j < strlen(s); j++) { + if (s[j] == 'A') { + for (int k = j + 1; k < strlen(s); k++) { + if (s[k] == 'Q') { sum++; } + } + } + } + } + } + cout << sum << endl; + } +} +int N, M; +int A[1005], B[1005]; +int main() { + cin >> N >> M; + for (int i = 0; i <= N - 1; i++) cin >> A[i]; + for (int i = 0; i <= M - 1; i++) cin >> B[i]; + int Cnt = 0, j = 0; + for (int i = 0; i <= N - 1; i++) { + if (j != M && B[j] >= A[i]) { + Cnt++; + j++; + } + } + cout << Cnt << '\n'; + return 0; +} +int main() { + vector v1, v2, v3; + int a, b, i; + int count = 0; + cin >> a; + for (i = 1; i <= a; i++) { + cin >> b; + if (b == 1) + v1.push_back(i); + else if (b == 2) + v2.push_back(i); + else if (b == 3) + v3.push_back(i); + } + b = min(v1.size(), min(v2.size(), v3.size())); + cout << b << endl; + for (i = 0; i < b; i++) { cout << v1[i] << " " << v2[i] << " " << v3[i] << endl; } + return 0; +} +int main() { + string s; + cin >> s; + set st; + for (int i = 0; i < s.size(); i++) { + string tmp; + for (int j = i; j < s.size(); j++) tmp += s[j]; + for (int j = 0; j < i; j++) tmp += s[j]; + st.insert(tmp); + } + cout << st.size() << endl; + return 0; +} +int a; +int n, k; +int p1, p2; +int ans; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a; + int t = a; + p1 = 0; + p2 = 0; + while (t > 0) { + if (t % 10 == 4) p1++; + if (t % 10 == 7) p2++; + t /= 10; + } + if (p1 + p2 <= k) ans++; + } + cout << ans << endl; +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + vector t(k); + for (int i = 0; i < n; i++) { t[s[i] - 'A']++; } + int min = n + 1; + bool b = 0; + for (int i = 0; i < k; i++) { + if (t[i] == 0) b = 1; + if (t[i] < min) min = t[i]; + } + if (b) + cout << "0" << endl; + else + cout << min * k << endl; +} +int main() { + int n, m; + cin >> n >> m; + int count = 0; + int max = 0; + for (int j = 0; j < m; j++) { + string str; + int sum = 0; + cin >> str; + for (int i = 0; i < n; i++) { + int a = str[i] - '0'; + sum += a; + } + if (sum != n) + count++; + else + count = 0; + if (max < count) max = count; + } + cout << max << endl; +} +int n, k; +int ans = 0; +int A[100]; +bool l = true, r = true; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> A[i]; } + for (int i = 0; i < n; i++) { + if (A[i] <= k) + ans++; + else { + l = false; + break; + } + } + for (int i = n - 1; i >= 0; i--) { + if (A[i] <= k) + ans++; + else { + r = false; + break; + } + } + if ((l == true) || (r == true)) ans = n; + cout << ans << endl; + return 0; +} +int main() { + if (0) { + freopen("TEMP.inp", "r", stdin); + freopen("TEMP.out", "w", stdout); + } + int q, k; + char str[310]; + cin >> q; + for (int i = 0; i <= q - 1; i++) { + cin >> k; + cin >> str; + if (k <= 1 || (k == 2 && str[1] <= str[0])) { + cout << "NO" << endl; + continue; + } + cout << "YES" << endl; + cout << 2 << endl; + cout << str[0]; + str[0] = ' '; + cout << str; + cout << endl; + } + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + if (a > n || c > b || c > a || (a + b - c >= n)) { + cout << -1 << endl; + return 0; + } + if (n - a - b + c >= 1) + cout << n - a - b + c << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n, t; + cin >> n >> t; + pair a; + int mx = -1000000000; + for (int i = 0; i < n; i++) { + cin >> a.first >> a.second; + if (a.second <= t) + mx = max(mx, a.first); + else + mx = max(mx, a.first - (a.second - t)); + } + cout << mx << endl; +} +int n; +long long subtraction(long long a, long long b) { + long long k = 0; + while ((a > 0) && (b > 0)) { + if (a > b) { + k += a / b; + a %= b; + } else { + k += b / a; + b %= a; + } + } + return k; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + long long a, b; + cin >> a >> b; + cout << subtraction(a, b) << endl; + } +} +int main() { + int n, i, j, m, t, x, y; + int a[110]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + m = -1; + for (i = 1; i <= n; i++) { + x = 0; + for (j = 0; j < n; j++) { + y = i - (j + 1); + if (y < 0) y = -y; + y += j + i - 1; + x += y * a[j] * 2; + } + if (x < m || m == -1) { m = x; } + } + cout << m << endl; + return 0; +} +bool ok(int n) { + while (n > 0) { + if (n % 10 == 7) return true; + n = n / 10; + } + return false; +} +int main() { + int x, h, m, ans; + while (cin >> x >> h >> m) { + ans = 0; + while (!ok(h) and !ok(m)) { + m = m - x; + if (m < 0) { + h--; + m = m + 60; + } + if (h < 0) { h = h + 24; } + ans++; + } + cout << ans << "\n"; + } + return 0; +} +int main() { + long long int a, b; + cin >> a >> b; + if (a % 2 == 0 && a + 2 <= b) { + cout << a << " " << a + 1 << " " << a + 2 << endl; + } else if (a % 2 != 0 && a + 3 <= b) { + cout << a + 1 << " " << a + 2 << " " << a + 3 << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int tmp, min1, max1, sum_n; +int arr1[1000][1000]; +char arr3[100]; +int arr[100]; +void display_vector(vector v) { + for (int i = 0; i < v.size(); i++) cout << v[i] << " "; + cout << endl; +} +void speed() {} +void min_max(vector v) { + min1 = INT_MAX; + max1 = INT_MIN; + for (int i = 0; i < v.size(); i++) { + if (v[i] < min1 && v[i]) min1 = v[i]; + if (v[i] > max1) max1 = v[i]; + } +} +int sum_v(vector v) { + for (int i = 0; i < v.size(); i++) sum_n += v[i]; + return sum_n; +} +bool is_it_sorted(vector v) { + bool test1 = false; + for (int i = 0; i < v.size() - 1; i++) + if (v[i + 1] < v[i]) { + test1 = false; + return test1; + } + test1 = true; + return test1; +} +int main() { + speed(); + int n; + cin >> n; + vector v(n), v2; + for (int i = 0; i < n; i++) cin >> v[i]; + int m; + cin >> m; + vector v1(m); + for (int i = 0; i < v1.size(); i++) cin >> v1[i]; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) { + int x = v1[i] / v[j]; + float x1 = v1[i] / v[j]; + if (x1 - x == 0) v2.push_back(v1[i] / v[j]); + } + min_max(v2); + int ans = 0; + for (int i = 0; i < v2.size(); i++) + if (v2[i] == max1) ans++; + cout << ans << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + size_t pos = 0; + for (size_t i = 0; i < t.length(); ++i) { + if (t[i] == s[pos]) { pos += 1; } + } + cout << pos + 1 << endl; + return 0; +} +int main() { + string s, ans = ""; + int n; + cin >> n >> s; + int t = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') + ans += '0' + t, t = 0; + else + t++; + } + ans += '0' + t; + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = INT_MIN; + int a, b; + for (int i = 0; i < int(n); i++) { + cin >> a >> b; + if (b <= k) { + ans = max(ans, a); + } else { + ans = max(ans, a - b + k); + } + } + cout << ans << "\n"; + return 0; +} +int n, c; +int main() { + cin >> n; + for (c = 1; c * (c + 1) * (c + 2) / 6 <= n; c++) + ; + cout << c - 1 << '\n'; +} +long res = 0; +int main() { + long test; + cin >> test; + while (test--) { + long a, b; + res = 0; + cin >> a >> b; + if (a < b) swap(a, b); + while (a != 0 && b != 0) { + long mod = a % b; + res += (a - mod) / b; + a = b; + b = mod; + } + cout << res << "\n"; + } +} +const int INF = 0x3f3f3f3f; +string s1, s2; +int main() { + cin >> s1 >> s2; + cout << (s1 == s2 ? s1 : "1") << "\n"; + ; + return 0; +} +int main() { + int n, q, p, i, m; + cin >> n; + m = 0; + for (i = 1; i <= n; i++) { + do { + cin >> p; + cin >> q; + } while (p > q); + if ((q - p) >= 2) { m = m + 1; } + } + cout << m << endl; + return 0; +} +int main() { + long long n, c = 0; + cin >> n; + while (n--) { + long long p = 0, q = 0; + cin >> p >> q; + if (q - p >= 2) c++; + } + cout << c << endl; + return 0; +} +int w, h, k; +int main() { + int ans = 0; + cin >> w >> h >> k; + for (int i = 1; i <= k; i++) { + int _w = w - (i - 1) * 4; + int _h = h - (i - 1) * 4; + ans += 2 * (_w + _h) - 4; + } + cout << ans << endl; + return 0; +} +char a[105]; +int s, l; +int main() { + cin >> a; + l = strlen(a); + for (int i = 0; i < l; i++) { + if (a[i] == 'Q') { + for (int j = i + 1; j < l; j++) + if (a[j] == 'A') { + for (int k = j + 1; k < l; k++) { + if (a[k] == 'Q') s++; + } + } + } + } + cout << s << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int inches = (n + 1) / 3; + int foot = (inches) / 12; + cout << foot << " "; + if (inches - foot * 12 <= 0) { + cout << "0" << endl; + } else + cout << inches - foot * 12 << endl; + } +} +int main() { + int n; + cin >> n; + long long int ar[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> ar[i][j]; + } + int flag = 0, flag1 = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (ar[i][j] > 1) { + for (int p = 0; p < n; p++) { + for (int q = 0; q < n; q++) { + if (p != j && q != i) { + if (ar[i][p] + ar[q][j] == ar[i][j]) { + flag = 1; + break; + } + } + } + if (flag == 1) break; + } + if (flag == 0) { + flag1 = 1; + break; + } + } + flag = 0; + } + if (flag1 == 1) break; + } + if (flag1 == 1) + cout << "No" << endl; + else + cout << "Yes" << endl; +} +int main() { + int n, k; + while (cin >> n >> k) { + string s; + int Start = 0, End = n - 1; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == 'G') { + Start = i; + } else if (s[i] == 'T') { + End = i; + } + } + bool flag = true; + int tmp = max(Start, End) - min(Start, End); + if (tmp % k != 0) { + flag = false; + } else { + if (Start > End) { + for (int i = Start; i >= End; i -= k) { + if (s[i] == '#') { + flag = false; + break; + } + } + } else { + for (int i = Start; i <= End; i += k) { + if (s[i] == '#') { + flag = false; + break; + } + } + } + } + if (flag) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +const int INF = 1000000007; +const int MAX = 512; +const int MAX2 = 10; +const int BASE = 1000000000; +const int MOD = 1000000007; +int n; +string S[MAX]; +int main() { + cin >> n; + for (int i = (0); i < (n); ++i) cin >> S[i]; + bool ok = 1; + for (int i = (0); i < (n); ++i) { + if (S[i][i] != S[0][0]) ok = 0; + if (S[i][n - i - 1] != S[0][0]) ok = 0; + } + for (int i = (0); i < (n); ++i) + for (int j = (0); j < (n); ++j) + if (i != j && i != n - j - 1 && S[i][j] != S[0][1]) ok = 0; + if (S[0][0] == S[0][1]) ok = 0; + cout << (ok ? "YES" : "NO") << endl; + return 0; +} +int main() { + int x, z = 1; + cin >> x; + string s[1000], k; + for (int i = 0; i < x; i++) { + cin >> k; + sort(k.begin(), k.end()); + s[i] = k; + } + for (int i = 0; i < x; i++) { + k = s[i][0]; + for (int j = 0; j < s[i].length() - 1; j++) { + if (s[i][j] != s[i][j + 1]) { k += s[i][j + 1]; } + } + s[i] = k; + } + sort(s, s + x); + for (int i = 0; i < x - 1; i++) { + if (s[i] != s[i + 1]) { z++; } + } + cout << z << endl; +} +int main() { + string s; + int k; + cin >> s >> k; + int result = 0; + for (; k > 0; k--) { + char a, b; + cin >> a >> b; + int l = 0, r = 0; + for (int i = 0; i <= s.size(); i++) { + if (s[i] == a) + l++; + else if (s[i] == b) + r++; + else { + result += min(l, r); + l = 0; + r = 0; + } + } + } + cout << result << endl; +} +int main() { + int x; + cin >> x; + string s1, s2, last; + vector rat, women, men; + for (int i = 0; i < x; ++i) { + cin >> s1 >> s2; + if (s2 == "rat") + rat.push_back(s1); + else if (s2 == "woman" || s2 == "child") + women.push_back(s1); + else if (s2 == "man") + men.push_back(s1); + else + last = s1; + } + for (int j = 0; j < rat.size(); ++j) cout << rat[j] << endl; + for (int k = 0; k < women.size(); ++k) cout << women[k] << endl; + for (int l = 0; l < men.size(); ++l) cout << men[l] << endl; + cout << last << endl; + return 0; +} +const int MAX = INT_MAX; +int arr[200010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + int ans = MAX; + int step = (n - 2) / 2; + for (int i = 0; i + step + 1 < n; i++) ans = min(ans, arr[i + step + 1] - arr[i]); + cout << ans << endl; + return 0; +} +int n, m, mx, ans; +int a[200025], b[200025]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; ++i) cin >> b[i]; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) + if ((float)b[j] / a[i] == (int)b[j] / a[i] && mx < b[j] / a[i]) { mx = b[j] / a[i]; } + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) + if ((float)b[j] / a[i] == (int)b[j] / a[i] && mx == b[j] / a[i]) ++ans; + cout << ans << '\n'; + return 0; +} +int main() { + int a, b, flag = 0; + cin >> a >> b; + int h[a]; + int k[b]; + for (int i = 0; i < a; i++) { cin >> h[i]; } + for (int i = 0; i < b; i++) { cin >> k[i]; } + if (b >= 2) flag = 1; + for (int i = 0; i < a; i++) { + if (b == 1 && h[i] == 0) h[i] = k[0]; + if (h[i] == 0) { + for (int j = 0; j < b; j++) { + if (k[j] < h[i - 1]) flag = 1; + } + } + if (i == 0) continue; + if (h[i] < h[i - 1]) flag = 1; + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +long long n; +int main() { + cin >> n; + int flag = 1; + int s = 5; + int sum = 5; + int k = 1; + int ans; + if (n < 6) + ans = n; + else { + while (n > sum) { + flag++; + s *= 2; + sum += s; + } + n = n - sum + s; + for (int i = 1; i < flag; i++) { k *= 2; } + ans = n / k + 1; + } + if (ans == 1) cout << "Sheldon" << endl; + if (ans == 2) cout << "Leonard" << endl; + if (ans == 3) cout << "Penny" << endl; + if (ans == 4) cout << "Rajesh" << endl; + if (ans == 5) cout << "Howard" << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) { + cout << a << endl; + } else + puts("1"); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 0 && j != m && i % 4 != 0) { + cout << "."; + } else if (i % 2 == 0 && j == m && i % 4 != 0) { + cout << "#" << endl; + } + if (i % 2 != 0 && j != m) { + cout << "#"; + } else if (i % 2 != 0 && j == m) { + cout << "#" << endl; + } + if (i % 2 == 0 && j == 1 && i % 4 == 0) { + cout << "#"; + } else if (i % 2 == 0 && j == m && i % 4 == 0) { + cout << "." << endl; + } else if (i % 2 == 0 && i % 4 == 0) { + cout << "."; + } + } + } + return 0; +} +int main() { + int a[101]; + int n; + while (cin >> n) { + int i; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n - 1] << ' '; + for (i = 1; i < n - 1; i++) { cout << a[i] << ' '; } + cout << a[0] << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + char last = 'a'; + int total = 0; + for (int i = 0; i < n; ++i) { + char next = s[i]; + int inter = ((next - 97) + 26 - (last - 97)) % 26; + if (inter < 26 / 2) + total += inter; + else + total += 26 - inter; + last = next; + } + cout << total << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + while (a > 0) { + if (l <= r) + l++; + else + r++; + a--; + } + cout << min(l, r) * 2 << endl; +} +int n, m; +int a[105][105]; +int b[105]; +void fun(int i) { + int max = a[i][0], t = 1; + for (int j = 1; j < n; j++) { + if (a[i][j] > max) { + t = j + 1; + max = a[i][j]; + } + } + b[t]++; +} +int main() { + while (cin >> n >> m) { + memset(b, 0, sizeof(b)); + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + for (int i = 0; i < m; i++) fun(i); + int max = b[1], t = 1; + for (int i = 2; i <= n; i++) + if (b[i] > max) { + max = b[i]; + t = i; + } + cout << t << endl; + } + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int a[50]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i] = a[i] - 1; + } + int sum = 0; + for (int i = 0; i < n; i++) { sum += a[i]; } + sort(a, a + n); + if (sum + k < m) { + cout << -1 << endl; + return 0; + } else { + int distance = m - k; + int j = n; + while (distance > 0) { + distance = distance - a[j - 1]; + j--; + } + cout << n - j << endl; + return 0; + } +} +int main() { + int q, e, t, a[180]; + cin >> t; + e = 0; + for (e = e + 1; e <= t;) { + cin >> a[e]; + e = e + 1; + } + q = 0; + for (q = q + 1; q <= t;) { + if (360 % (180 - a[q]) == 0) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + q = q + 1; + } + return 0; +} +string s; +string a = "hello"; +int main() { + int c = 0; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (a[c] == s[i]) c++; + } + if (c == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, m; +string s, t; +set st; +int main() { + cin >> s; + n = s.size(); + m = n; + while (m--) { + t = s[n - 1]; + t += s.substr(0, n - 1); + s = t; + st.insert(s); + } + cout << st.size() << endl; + return 0; +} +int main() { + int p, n; + cin >> p >> n; + int hash[305]; + memset(hash, 0, sizeof(hash)); + int x; + for (int i = 0; i < n; i++) { + cin >> x; + x = x % p; + if (hash[x]) { + cout << ++i << endl; + return 0; + } + hash[x]++; + } + cout << -1 << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int ctr = 1; + int lastPos; + for (int i = 0; i < t.length(); i++) { + if (t[i] == s[ctr - 1]) ctr++; + } + cout << ctr << endl; + return 0; +} +int main() { + int MAT[3][3], TOOG[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) MAT[i][j] = 1; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> TOOG[i][j]; + int _i[5] = {1, 0, -1, 0, 0}, _j[5] = {0, 1, 0, -1, 0}; + if (TOOG[i][j] % 2 != 0) { + for (int c = 0; c < 5; c++) { + int ni = i + _i[c], nj = j + _j[c]; + if ((ni < 3 and ni >= 0) and (nj < 3 and nj >= 0)) MAT[ni][nj] = (MAT[ni][nj]) ? 0 : 1; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << MAT[i][j]; + cout << "\n"; + } + return 0; +} +int main() { + int n, m, moves; + cin >> n >> m; + moves = min(n, m); + if (moves % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int main() { + int a[1100], b[1100][2], n, m; + long long int sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + cin >> m; + for (int i = 0; i < m; i++) { cin >> b[i][0] >> b[i][1]; } + if (b[m - 1][1] < sum) + cout << -1 << endl; + else { + int j = m - 1; + while (b[j][0] > sum) j--; + if (b[j][1] >= sum) + cout << sum << endl; + else + cout << b[j + 1][0] << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long winner = n / 2; + long long ce = winner / (m + 1); + long long di = ce * m; + long long other = n - ce - di; + cout << ce << " " << di << " " << other << endl; + return 0; +} +int main() { + int arr[6], sum = 0, flag = 0; + for (int a = 0; a < 6; a++) { + cin >> arr[a]; + sum += arr[a]; + } + for (int i = 0; i < 6; i++) { + for (int j = i + 1; j < 6; j++) { + for (int c = j + 1; c < 6; c++) { + if (sum == 2 * (arr[i] + arr[c] + arr[j])) { flag = 1; } + } + } + } + if (flag) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + string password; + cin >> password; + vector vec1(4, 0); + if (password.length() >= 5) vec1[0] = 1; + for (int i = 0; i < password.length(); i++) { + if (islower(password[i])) { vec1[1]++; } + if (isupper(password[i])) { vec1[2]++; } + if (isdigit(password[i])) { vec1[3]++; } + } + int cnt = 0; + for (int i = 0; i < vec1.size(); i++) { + if (vec1[i] > 0) cnt++; + } + if (cnt == 4) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int temp; + bool answer = 0; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp == 1) { answer = 1; } + } + if (answer == 0) { + cout << 1 << endl; + return 0; + } + cout << -1 << endl; + return 0; +} +int main() { + long long q, in_amt, cur_amt, left_cn, dist_ch = 0; + char sg; + cin >> q >> in_amt; + left_cn = in_amt; + while (q--) { + cin >> sg >> cur_amt; + if (sg == '+') + left_cn += cur_amt; + else if (left_cn - cur_amt < 0) + dist_ch++; + else + left_cn -= cur_amt; + } + cout << left_cn << " " << dist_ch << endl; + return 0; +} +int main() { + int n; + cin >> n; + int m = (n + 1) / 2; + for (int i = 0; i < n; i++) { + for (int j = 1; j <= n; j++) { + if (i < m) { + if (j >= m - i and j <= m + i) { + cout << "D"; + } else { + cout << "*"; + } + } else { + if (j > (i + 1) % m and j < n - (i % m)) { + cout << "D"; + } else { + cout << "*"; + } + } + } + cout << endl; + } +} +int main() { + int n, m; + while (cin >> n >> m) { + int c[n]; + for (int i = 0; i < n; i++) cin >> c[i]; + int a[m]; + for (int i = 0; i < m; i++) cin >> a[i]; + int j, co = 0; + for (int i = 0, j = 0; i < n; i++) { + if (c[i] <= a[j]) { + co++; + j++; + } + if (j == m) break; + } + cout << co << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + string s; + cin >> s; + while (m--) { + long long l, r; + char c1, c2; + cin >> l >> r >> c1 >> c2; + l--, r--; + for (long long j = l; j <= r; ++j) + if (s[j] == c1) s[j] = c2; + } + cout << s << endl; +} +int n, flag = 0, a[15], cnt = 0, ans = 0, num = 0; +int main() { + cin >> n; + while (n > 0) { + a[++cnt] = n % 10; + n /= 10; + } + for (int i = cnt; i >= 1; i--) { + if (a[i] != 1 && a[i] != 4) { + ans = 1; + break; + } + if (a[i] == 4 && flag == 0) { + ans = 1; + break; + } + if (a[i] == 4) num++; + if (a[i] == 4 && num == 2) { + flag = 0; + num = 0; + } + if (a[i] == 1) { + flag = 1; + num = 0; + } + } + if (ans == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + long long w = n / s; + if (n % s != 0) w++; + w *= k; + long long ans = w / p; + if (w % p != 0) ans++; + cout << ans << endl; + return 0; +} +long long int MIN(long long int a, long long int b) { + if (a > b) + return b; + else + return a; +} +long long int MAX(long long int a, long long int b) { + if (a > b) + return a; + else + return b; +} +long long int MOD(long long int x) { + if (x >= 0) + return x; + else + return -x; +} +int main() { + long long int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + long long int c = 0; + for (int i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) c++; + } + cout << c << endl; + return 0; +} +char a[1000][1000]; +int main() { + int i, j, n, m, b[5]; + while (cin >> n >> m) { + int count = 0; + for (i = 0; i < n; ++i) + for (j = 0; j < m; ++j) cin >> a[i][j]; + if (m == 1 || n == 1) { + cout << count << endl; + } else { + for (i = 0; i < n; ++i) + for (j = 0; j < m; ++j) { + b[0] = a[i][j]; + b[1] = a[i][j + 1]; + b[2] = a[i + 1][j]; + b[3] = a[i + 1][j + 1]; + sort(b, b + 4); + if (b[0] == 'a' and b[1] == 'c' and b[2] == 'e' and b[3] == 'f') count++; + } + cout << count << endl; + } + } + return 0; +} +int main() { + int q; + cin >> q; + vector ans(q); + vector s(q); + for (int i = 0; i <= q - 1; i++) { + int n; + cin >> n >> s[i]; + if (n > 2) { + ans[i] = true; + } else { + ans[i] = s[i][0] < s[i][1]; + } + } + for (int i = 0; i <= q - 1; i++) { + if (ans[i]) { + cout << "YES\n2\n" << s[i][0] << " "; + for (int j = 1; j <= s[i].length() - 1; j++) cout << s[i][j]; + cout << "\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +int main() { + int n; + cin >> n; + cout << 2 << endl; + for (long long i = 3; i <= n + 1; i++) cout << i * i * (i - 1) - i + 2 << endl; + return 0; +} +int main() { + int m, n, max, ans = 0; + char s[110][110]; + int a[110][110], flag[101] = {0}; + cin >> m >> n; + for (int i = 0; i < m; i++) { cin >> s[i]; } + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { a[i][j] = s[i][j] - '0'; } + } + for (int j = 0; j < n; j++) { + max = a[0][j]; + for (int i = 0; i < m; i++) { + if (a[i][j] > max) { max = a[i][j]; } + } + for (int i = 0; i < m; i++) { + if (a[i][j] == max) { flag[i] = 1; } + } + } + for (int i = 0; i < m; i++) { + if (flag[i] == 1) { ans++; } + } + cout << ans << endl; + return 0; +} +int m = 1e9 + 7; +void toggle(int *a) { + if (*a == 1) + *a = 0; + else if (*a == 0) + *a = 1; +} +int main() { + int v[3][3], b[3][3]; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + b[i][j] = 1; + cin >> v[i][j]; + } + } + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + if (v[i][j] % 2 != 0) { + toggle(&b[i][j]); + if (j != 2) toggle(&b[i][j + 1]); + if (j != 0) toggle(&b[i][j - 1]); + if (i != 2) toggle(&b[i + 1][j]); + if (i != 0) toggle(&b[i - 1][j]); + } + } + } + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { cout << b[i][j]; } + cout << '\n'; + } + return 0; +} +int x, y, a, b; +int ans; +int GCD(int k, int l) { + if (l == 0) + return k; + else + return GCD(l, k % l); +} +int LCM(int m, int n) { + return (m * n) / GCD(m, n); +} +int main() { + ans = 0; + cin >> x >> y >> a >> b; + int kpk; + kpk = LCM(x, y); + ans = floor(b / kpk) - floor((a - 1) / kpk); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int totals[3] = {0}; + int max = 0; + int index = 0; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + totals[i % 3] += temp; + if (totals[i % 3] > max) { + max = totals[i % 3]; + index = i % 3; + } + } + if (index == 0) + cout << "chest" << endl; + else if (index == 1) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +int main() { + int arr[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n; + cin >> n; + cout << arr[n % 10] * arr[n / 10] << endl; +} +long long GCD(long long a, long long b) { + return (b == 0) ? a : GCD(b, a % b); +} +long long LCM(long long a, long long b) { + return (a * b) / GCD(a, b); +} +int intlog(double base, double x) { + return (int)(log(x) / log(base)); +} +double slope(double x1, double y1, double x2, double y2) { + return (y2 - y1) / (x2 - x1); +} +double distance(int x1, int y1, int x2, int y2) { + return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0); +} +long long dot_por(pair v1, pair v2) { + return (v1.first * v2.first + v1.second * v2.second); +} +long long length_of_vector(pair v) { + return sqrt(v.first * v.first + v.second * v.second); +} +int n, a[10000]; +bool c[10000]; +bool calc(int indx, int t) { + if (t == 3 && c[indx]) return true; + if (c[indx]) return false; + if (t == 3) return false; + c[indx] = true; + return calc(a[indx] - 1, t + 1); +} +int main() { + cin >> n; + for (int i = 0; i < n && cin >> a[i]; i++) + ; + for (int i = 0; i < n; i++) { + if (a[a[a[a[i] - 1] - 1] - 1] == a[i]) { + cout << "YES" << endl; + exit(0); + } + } + cout << "NO" << endl; +} +int main() { + long long n; + while (cin >> n) { cout << 25 << endl; } + return 0; +} +int main() { + int n, m, i, turn = 0, couting; + cin >> n >> m; + if (n < m) couting = n; + if (n == m) couting = n + 1; + if (n > m) { + for (i = 1; i <= n + turn; i++) { + if (i % m == 0) { turn += 1; } + } + couting = i - 1; + } + cout << couting << endl; +} +int main() { + int a[3]; + for (int i = 0; i < 3; i++) { cin >> a[i]; } + sort(a, a + 3); + cout << (a[2] - a[1]) + (a[1] - a[0]) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, b, c; + cin >> a >> b >> c; + int ans = 0; + if (n == 1) + ans = 0; + else { + if (a < b) { + ans += a; + ans += min(a, c) * (n - 2); + } else { + ans += b; + ans += min(b, c) * (n - 2); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + string s; + cin >> n >> s; + if (n > s.length()) { + cout << "NO\n"; + return 0; + } + string tmp = ""; + tmp += s[0]; + vector ans; + int cnt = 0; + map m; + m[s[0]] = 1; + for (int i = 1; i < s.length(); i++) { + if (m.find(s[i]) == m.end()) { + cnt++; + if (cnt < n) { + ans.push_back(tmp); + tmp = ""; + } + } + tmp += s[i]; + m[s[i]] = 1; + } + ans.push_back(tmp); + if (cnt < n - 1) { + cout << "NO\n"; + return 0; + } + cout << "YES\n"; + for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } + return 0; +} +bool can_change(char a, char b) { + if (a + 1 == b + 1 || a + 1 == b - 1 || a - 1 == b + 1 || a - 1 == b - 1) + return true; + else + return false; +} +int main() { + int c; + cin >> c; + while (c--) { + int len; + string s; + cin >> len >> s; + int j = len - 1; + bool can = true; + for (int i = 0; i < len / 2 && can; i++) { + if (!can_change(s[i], s[j])) { can = false; } + j--; + } + if (can) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, i, k; + while (cin >> n >> m) { + i = n < m ? n : m; + k = abs(n - m) / 2; + cout << i << ' ' << k << endl; + } +} +int main() { + long long int n, max, save; + cin >> n; + if (n == 0) { + cout << 1 << endl; + return 0; + } + if (n == 1) { + cout << 4 << endl; + return 0; + } + for (max = 0; 2 * (max * max) < n * n; max++) { save = max; } + if ((save + 1) * (save + 1) + save * save <= n * n) { + n = (save)*8 + 4; + cout << n << endl; + return 0; + } + n = (save)*8; + cout << n << endl; + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + long long sb = ceil(double(n) / s); + long long tp = sb * k; + long long ans = ceil(double(tp) / p); + cout << ans << endl; +} +inline char nc() { + return getchar(); +} +inline void read(int &x) { + char c = nc(); + int b = 1; + for (; !(c >= '0' && c <= '9'); c = nc()) + if (c == '-') b = -1; + for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc()) + ; + x *= b; +} +inline void read(long long &x) { + char c = nc(); + long long b = 1; + for (; !(c >= '0' && c <= '9'); c = nc()) + if (c == '-') b = -1; + for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc()) + ; + x *= b; +} +inline int read(char *s) { + char c = nc(); + int len = 1; + for (; !(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); c = nc()) + if (c == EOF) return 0; + for (; (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); s[len++] = c, c = nc()) + ; + s[len++] = '\0'; + return len - 2; +} +inline void read(char &x) { + for (x = nc(); !(x >= 'a' && x <= 'z'); x = nc()) + ; +} +int wt, ss[19]; +inline void print(int x) { + if (x < 0) x = -x, putchar('-'); + if (!x) + putchar(48); + else { + for (wt = 0; x; ss[++wt] = x % 10, x /= 10) + ; + for (; wt; putchar(ss[wt] + 48), wt--) + ; + } +} +inline void print(long long x) { + if (x < 0) x = -x, putchar('-'); + if (!x) + putchar(48); + else { + for (wt = 0; x; ss[++wt] = x % 10, x /= 10) + ; + for (; wt; putchar(ss[wt] + 48), wt--) + ; + } +} +int n, m; +char s[1010]; +int main() { + read(n); + read(m); + int x, l = 1, r = n, y; + for (int i = 1; i <= m; i++) { + x = read(s), x = read(s), x = read(s); + if (s[1] == 'r') + y = 1; + else + y = 2; + read(x); + if (y == 1) + l = max(l, x + 1); + else + r = min(r, x - 1); + } + if (r < l) + puts("-1"); + else + print(r - l + 1), puts(""); + return 0; +} +int main() { + string s, t; + cin >> s >> t; + size_t pos = 0; + for (size_t i = 0; i < t.length(); ++i) { + if (t[i] == s[pos]) { pos += 1; } + } + cout << pos + 1 << endl; + return 0; +} +int main() { + int n, k, cont = 0; + cin >> n >> k; + int a[n + 5], b[n + 5]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + sort(b, b + k); + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + a[i] = b[k - 1]; + k--; + } + } + for (int i = 1; i < n; i++) { + if (a[i] <= a[i - 1]) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int s = n < m ? n : m; + if (s % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } +} +int main() { + int n; + while (cin >> n) { + int ans = 0, temp = 0; + for (int i = 0; i < n; i++) { + int p, q; + cin >> p >> q; + temp += q; + temp -= p; + ans = max(ans, temp); + } + cout << ans << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + long long i = 0, j = 0, k = 1, l = 0; + long long n, m; + long long y, x, s = 0; + cin >> n; + while (n--) { + s = 0; + cin >> x >> y; + while (1) { + if (!x || !y) break; + if (x > y) swap(x, y); + k = y % x; + s += y / x; + y = x; + x = k; + } + cout << s << endl; + } + return 0; +} +int main() { + long long int n; + cin >> n; + vector v; + for (long long int i = 0; i < 2 * n; i++) { + long long int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + if (v[n] > v[n - 1]) + cout << "YES"; + else + cout << "NO"; + cout << endl; + return 0; +} +int main() { + long long n; + while (cin >> n) { + long long i = sqrt(n << 1); + while (i * (i + 1) / 2 < n) i++; + cout << n - ((i - 1) * i / 2) << endl; + } + return 0; +} +int a[100010]; +int main() { + int n, m, c; + while (cin >> n) { + int cntm = 0, cntc = 0; + for (int i = 0; i < n; i++) { + cin >> m >> c; + if (m > c) + cntm++; + else if (m < c) + cntc++; + } + if (cntm > cntc) + cout << "Mishka\n"; + else if (cntm < cntc) + cout << "Chris\n"; + else if (cntm == cntc) + cout << "Friendship is magic!^^\n"; + } + return 0; +} +int main() { + int n, ans = 0; + string a, b; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { ans += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); } + cout << ans << endl; +} +int a[105]; +int main() { + int n, m, x, y, l = 0, r; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + if (i == 1 && x != 0) { + cout << "NO" << endl; + return 0; + } + if (i == 1) + r = y; + else if (x <= r) + r = max(r, y); + } + if (r >= m) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int c = 0; + for (int i = 0; i < n; i++) { + if (s[i] != 'Q') continue; + for (int j = i + 1; j < n; j++) { + if (s[j] != 'A') continue; + for (int k = j + 1; k < n; k++) { + if (s[k] != 'Q') continue; + c++; + } + } + } + cout << c << "\n"; + return 0; +} +int main() { + int n, m, rem; + cin >> n >> m; + int i = 1; + while (1) { + if (i % n == 0) i = n; + if (i > m) break; + m -= i; + i = (i + 1) % n; + } + cout << m << endl; +} +int main() { + int n; + long long S; + cin >> n >> S; + if (S % n) + cout << S / n + 1 << endl; + else + cout << S / n << endl; + return 0; +} +map, long long> M; +long long answer; +void lca(long long u, long long v, long long w = 0) { + long long p; + while (u != v) { + if (u > v) { + p = u; + u /= 2; + if (w) + M[make_pair(p, u)] += w; + else + answer += M[make_pair(p, u)]; + } else if (u < v) { + p = v; + v /= 2; + if (w) + M[make_pair(p, v)] += w; + else + answer += M[make_pair(p, v)]; + } + } +} +int main() { + long long u, v, w; + int q, i, type; + cin >> q; + for (i = 0; i < q; ++i) { + cin >> type; + if (type == 1) { + cin >> u >> v >> w; + lca(u, v, w); + } else { + answer = 0; + cin >> u >> v; + lca(u, v); + cout << answer << endl; + } + } + return 0; +} +int main() { + int num; + cin >> num; + if (num % 2 == 0) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } +} +int main() { + int m31[] = {1, 3, 5, 7, 8, 10, 12}; + int m30[] = {4, 6, 9, 11}; + int m28 = 2; + int m, d; + double res; + cin >> m >> d; + for (int i = 0; i < 7; i++) + if (m == m31[i]) res = ceil((double)(31 + (d - 1)) / 7); + for (int i = 0; i < 4; i++) + if (m == m30[i]) res = ceil((double)(30 + (d - 1)) / 7); + if (m == m28) res = ceil((double)(28 + (d - 1)) / 7); + cout << (int)res << endl; + return 0; +} +const long long N = 1e5 + 1; +long long x; +string s1, s2; +pair p[1001]; +int main() { + cin >> x; + for (int i = 0; i < x; i++) { + cin >> s1 >> s2; + if (s2 == "rat") { + p[i] = {1, s1}; + } else if (s2 == "woman" or s2 == "child") { + p[i] = {2, s1}; + } else if (s2 == "man") { + p[i] = {3, s1}; + } else if (s2 == "captain") { + p[i] = {4, s1}; + } + } + for (int i = 1; i <= 4; i++) { + for (int j = 0; j < x; j++) { + if (p[j].first == i) { cout << p[j].second << endl; } + } + } + return 0; +} +string a; +int i; +int main() { + cin >> a; + for (i = a.size(); i >= 0; i--) { + if (a[i] == a[i + 1]) a.erase(i, 2); + } + cout << a << endl; + ; +} +int main() { + int n, a[101], i, s = 0, b; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 0; i < n; i++) { s += (a[n - 1] - a[i]); } + cout << s << endl; + return 0; +} +const int mod = 1000000007; +long long int n, u = 0; +long long int a[1005], b[1005][1005]; +void zz() { + memset(b, 0, sizeof(b)); + for (long long int i = 1; i < 1005; i++) { + b[i][0] = b[i][i] = 1; + for (long long int j = 1; j < i; ++j) { b[i][j] = (b[i - 1][j - 1] + b[i - 1][j]) % mod; } + } +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i], u += a[i]; + long long int sum = 1; + long long int q = u - 1; + zz(); + for (int i = n - 1; i > 0; i--) { + long long int r = a[i] - 1; + sum = (sum * b[q][r]) % mod; + q = q - a[i]; + } + cout << sum << endl; +} +int main() { + int n; + string s; + cin >> n >> s; + int cnt = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + cnt++; + } else { + cout << cnt; + cnt = 0; + } + } + cout << cnt << endl; + return 0; +} +int main() { + long long m, n; + while (cin >> n >> m) { + int cnt = 1, k = 0; + for (int i = 1; i <= n; i++) { + cnt *= 2; + if (cnt > m) { + k = i; + break; + } + } + if (!k) + cout << m % cnt << endl; + else + cout << m << endl; + } + return 0; +} +int main() { + int num, buy; + vector v; + cin >> num >> buy; + for (int i = 0; i < buy; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + int max = 0, min = 0, differ = 1000000; + for (int i = 0; i < v.size(); i++) { + if ((i + num) > v.size()) + break; + else { + min = min_element(v.begin() + i, v.begin() + (i + num)) - v.begin(); + max = max_element(v.begin() + i, v.begin() + (i + num)) - v.begin(); + if ((v.at(max) - v.at(min)) < differ) { differ = v.at(max) - v.at(min); } + } + } + for (int i = 0; i < v.size(); i++) { + int total = count(v.begin(), v.end(), v.at(i)); + if (total >= num) { + differ = 0; + break; + } + } + cout << differ << endl; +} +int main() { + int n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(n - 1) / r] << endl; + return 0; +} +const int M = 100 + 5; +int a[M][M]; +int sr[M]; +int sc[M]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { sr[i] += a[i][j]; } + } + for (int j = 0; j < n; j++) { + for (int i = 0; i < n; i++) { sc[j] += a[i][j]; } + } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (sc[j] > sr[i]) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, z, cnt = 0; + cin >> n >> m >> z; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) { cnt++; } + } + cout << cnt << endl; +} +int main() { + int n, i; + while (cin >> n) { + int arr[110] = {0}, max = -10000, min = 10000, p_max, p_min, res[110] = {0}, k; + cin >> arr[0]; + max = min = arr[0]; + p_max = p_min = 0; + for (i = 1; i < n; i++) { + cin >> arr[i]; + if (arr[i] < min) { + min = arr[i]; + p_min = i; + } else if (arr[i] > max) { + max = arr[i]; + p_max = i; + } + } + k = 0; + for (i = 0; i < n; i++) { + if (i == p_min || i == p_max) continue; + res[k++] = arr[i]; + } + sort(res, res + k); + if (p_max != p_min) cout << max << " "; + for (i = 0; i < k; i++) cout << res[i] << " "; + cout << min << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int res = 8; + if (s == "a1" || s == "a8" || s == "h1" || s == "h8") + res = 3; + else if (s[0] == 'a' || s[0] == 'h') + res = 5; + else if (s[1] == '1' || s[1] == '8') + res = 5; + cout << res << endl; + return 0; +} +int main() { + string name; + int step = 0; + int count = 0; + char pointer = 'a'; + cin >> name; + for (int i = 0; i < name.size(); i++) { + step = abs(pointer - name[i]); + if (step < 13) { + count += step; + } else { + count = count + 26 - step; + } + pointer = name[i]; + } + cout << count << endl; + return 0; +} +int main() { + int n, c = 0; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + for (int i = 0; i < n; i++) { + int a = abs(s1[i] - s2[i]); + if (a > 5) + c += 10 - a; + else + c += a; + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + int sum = 0; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + if (x > 0) + sum += x; + else + sum -= x; + } + cout << sum << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int arr[n]; + if (s[0] == 'Q') { + arr[0] = 1; + } else { + arr[0] = 0; + } + for (int i = 1; i < n; i++) { + if (s[i] == 'Q') { + arr[i] = arr[i - 1] + 1; + } else { + arr[i] = arr[i - 1]; + } + } + long ans = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A') { ans += arr[i] * (arr[n - 1] - arr[i]); } + } + cout << ans << endl; + return 0; +} +int main() { + queue a; + queue b; + int ak, bk; + cin >> ak >> bk; + int ans = bk; + while (ak--) { + int t; + cin >> t; + a.push(t); + } + while (bk--) { + int t; + cin >> t; + b.push(t); + } + while (!b.empty() && !a.empty()) { + if (b.front() >= a.front()) { + a.pop(); + b.pop(); + } else { + a.pop(); + } + } + ans -= b.size(); + cout << ans << endl; + return 0; +} +int main() { + vector v; + int n; + cin >> n; + long long s = 0; + for (int i = 0; i < n; i++) { + long long x; + cin >> x; + s += x; + v.push_back(s); + } + for (int i = 0; i < n; i++) { + if (v[i] >= (s / 2) + s % 2) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int min_value = a[0]; + int min_pos = 0; + for (int i = 1; i < n; i++) { + if (a[i] < min_value) { + min_value = a[i]; + min_pos = i; + } + } + for (int i = 0; i < n; i++) { + if (a[i] == min_value && i != min_pos) { + cout << "Still Rozdil" << endl; + exit(0); + } + } + cout << min_pos + 1 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int count = 1, ans = 0; + for (int i = 1; i < s.length(); i++) { + if (s[i] == s[i - 1]) { + count++; + } else { + if (count % 2 == 0) { ans++; } + count = 1; + } + } + if (count % 2 == 0) { ans++; } + cout << ans << endl; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + cout << "O-|-OOOO" << endl; + return 0; + } + while (n > 0) { + string s = ""; + int temp = n % 10; + if (temp < 5) { + s += "O-|"; + for (int i = 0; i < 5; i++) { + if (i == temp) + s += '-'; + else + s += 'O'; + } + } else if (temp >= 5) { + s += "-O|"; + for (int i = 0; i < 5; i++) { + if (i == temp - 5) + s += '-'; + else + s += 'O'; + } + } + cout << s << endl; + n /= 10; + } +} +int main() { + int n, Max = 0, Count = 0; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + Count -= a[i]; + Count += b[i]; + if (Count > Max) { Max = Count; } + } + cout << Max << endl; + return 0; +} +int main() { + long long n; + cin >> n; + vector a(n), b(n); + vector m(2000005, 0); + for (long long i = 0; i < n; i++) { + cin >> a[i]; + m[a[i]]++; + } + for (long long i = 0; i < n; i++) { + cin >> b[i]; + m[b[i]]++; + } + long long cnt = 0; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { + long long t = a[i] ^ b[j]; + if (t <= 2000001 && m[t] >= 1) cnt++; + } + } + if (cnt % 2 == 0) + cout << "Karen" << endl; + else + cout << "Koyomi" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + ; + int i, t1; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (k == i + 1) t1 = a[i]; + } + sort(a, a + n, greater()); + int c = 0; + for (i = 0; i < n; i++) { + if (a[i] != 0 && a[i] >= t1) c++; + } + if (a[0] == 0) + cout << "0\n"; + else + cout << c << "\n"; +} +int main() { + int a, b, c, k; + cin >> a >> b >> c; + cout << max(max(a, b), c) - min(min(a, b), c) << endl; +} +int main() { + int n, t, sum = 0; + cin >> n >> t; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += 86400 - x; + if (sum >= t) { + cout << i + 1 << '\n'; + return 0; + } + } + return 0; +} +int main() { + int n, x, c = 0; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + if (v[0] == 1) { c++; } + if (n == 1) { + cout << c << endl; + return 0; + } + for (int i = 1; i < n - 1; i++) { + if (v[i] == 1) { + c++; + } else { + if (v[i + 1] == 1 && c > 0 && v[i - 1] != 0) { c++; } + } + } + if (v[n - 1] == 1) { c++; } + cout << c << endl; + return 0; +} +int n; +int main() { + cin >> n; + int empat = -1; + int tujuh = -1; + int len = 1e9; + for (int i = 0; 4 * i <= n; i++) { + int sisa = n - 4 * i; + if (sisa % 7 == 0) { + int sum = i + sisa / 7; + if (sum < len) { + empat = i; + tujuh = sisa / 7; + len = sum; + } else if (sum == len && empat > i) { + empat = i; + tujuh = sisa / 7; + len = sum; + } + } + } + if (empat == -1) + cout << -1 << endl; + else { + for (int i = 1; i <= empat; i++) cout << 4; + for (int i = 1; i <= tujuh; i++) cout << 7; + cout << endl; + } +} +void solve(); +void speed_up() {} +int main() { + speed_up(); + solve(); + return 0; +} +void solve() { + long long n, b, p; + cin >> n >> b >> p; + long long y = n * p; + long long sor = 0; + while (n > 1) { + long long st = 2; + while (st * 2 <= n) st *= 2; + sor += (st / 2) * (b * 2 + 1); + n -= st / 2; + } + cout << sor << " " << y << "\n"; +} +long long a[200005]; +long long b[200005]; +int main() { + long long n; + while (cin >> n) { + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 1; i < n; i++) { b[i] = a[i] - a[i - 1]; } + long long min = 99999999999; + long long pcount = 0; + for (int i = 1; i < n; i++) { + if (b[i] < min) { + min = b[i]; + pcount = 1; + } else if (b[i] == min) { + pcount++; + } + } + cout << min << " " << pcount << endl; + } + return 0; +} +int n, c, x; +int a[1000000]; +int main() { + cin >> n >> c; + x == 1; + if (n == 1) { + cout << 1 << endl; + return 0; + } + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] - a[i - 1] <= c) { + x++; + } else + x = 1; + } + cout << x << endl; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n, m; + cin >> n >> m; + char a[n][m]; + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < m; j++) { + if (i % 2 == 0) + a[i][j] = '#'; + else if (i % 4 == 1) { + if (j == m - 1) + a[i][j] = '#'; + else + a[i][j] = '.'; + } else { + if (j == 0) + a[i][j] = '#'; + else + a[i][j] = '.'; + } + } + } + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < m; j++) cout << a[i][j]; + cout << '\n'; + } + } + return 0; +} +int main() { + int n; + int a[1000]; + while (cin >> n) { + int b, c; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + b = a[0]; + c = a[n - 1]; + cout << c; + for (int i = 1; i < n - 1; i++) { cout << " " << a[i]; } + cout << " " << b << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector ver(n); + for (int i = 0; i < n; i++) cin >> ver[i]; + ver.push_back(1000000000); + sort(ver.begin(), ver.end()); + vector hor; + for (int i = 0; i < m; i++) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 > 1) continue; + hor.push_back(x2); + } + m = hor.size(); + sort(hor.begin(), hor.end()); + int ans = INT_MAX, p = 0; + for (int i = 0; i < n + 1; i++) { + while (p < m && hor[p] < ver[i]) p++; + ans = min(ans, i + m - p); + } + cout << ans << endl; +} +int main() { + string s; + cin >> s; + int dot; + for (int i = 0; i < (int)s.length(); i++) + if (s[i] == '.') dot = i; + if (s[dot - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + exit(0); + } + bool down = false; + if ((int)(s[dot + 1] - '0') < 5) down = true; + for (int i = 0; i < dot - 1; i++) cout << s[i]; + cout << (char)(s[dot - 1] + (down ? 0 : 1)) << endl; +} +int main() { + int discounts, prices; + int aTypes[100000]; + int aPrices[100000]; + cin >> discounts; + for (int i = 0; i < discounts; i++) cin >> aTypes[i]; + cin >> prices; + for (int j = 0; j < prices; j++) cin >> aPrices[j]; + sort(aTypes, aTypes + discounts); + sort(aPrices, aPrices + prices); + long long cost = 0; + int j = prices - 1; + while (j >= 0) { + for (int i = 0; i < aTypes[0]; i++) { + cost += aPrices[j]; + j--; + if (j < 0) break; + } + j = j - 2; + } + cout << cost << endl; +} +int main() { + int n, m; + cin >> n >> m; + int i = 1; + while (m >= i) { + m -= i; + i++; + if (i > n) i = 1; + } + cout << m << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long arr[n + 1][n + 1]; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { cin >> arr[i][j]; } + } + long long flag = 0; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < n; j++) { + if (arr[i][j] != 1) { + flag = 0; + for (long long k = 0; k < n; k++) { + for (long long l = 0; l < n; l++) { + if (arr[k][j] + arr[i][l] == arr[i][j]) { + flag = 1; + break; + } + } + } + if (!flag) { + cout << "No" << endl; + return 0; + } + } + } + } + cout << "Yes" << endl; +} +void in_out_txt() { + freopen("input.txt", "rt", stdin); + freopen("output.txt", "wt", stdout); +} +void FillArray(int arr[], int n, int num) { + for (int i = 0; i < n; i++) arr[i] = num; +} +int fun(int num) { + int re; + set st; + while (num != 0) { + re = num % 10; + num /= 10; + st.insert(re); + } + int s = st.size(); + return s; +} +int main() { + int n; + cin >> n; + char arr[101][101]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> arr[i][j]; + } + int c = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] == 'C') { + for (int k = j + 1; k < n; k++) { + if (arr[i][k] == 'C') c++; + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i][j] == 'C') { + for (int k = i + 1; k < n; k++) { + if (arr[k][j] == 'C') c++; + } + } + } + } + cout << c << endl; + ; + return 0; +} +int main() { + int a[105]; + int n, ans = 0; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0; i < n; ++i) { + for (int j = 0; j <= i; j++) { + int v = 0; + for (int k = 0; k < n; k++) + if (k >= j && k <= i) + v += !a[k]; + else + v += a[k]; + ans = max(ans, v); + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, s = 0; + cin >> n >> x; + vector v(n); + for (int i = 0; i < n; i++) { + cin >> v[i]; + s += v[i]; + } + int ans = (abs(s) + x - 1) / x; + cout << ans << endl; + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + cout << (k * ((n + s - 1) / s) + p - 1) / p << endl; + return 0; +} +pair pa[100004]; +long long per[100004], cha[100004], n, m, x, y, con; +int main() { + cin >> n >> m >> x >> y; + for (int i = 1; i <= n; i++) cin >> per[i]; + for (int i = 1; i <= m; i++) cin >> cha[i]; + for (int i = 1, j = 1; i <= n && j <= m; i++) { + while (j <= m && cha[j] < per[i] - x) j++; + if (j <= m && i <= n && per[i] - x <= cha[j] && cha[j] <= per[i] + y) pa[con++] = make_pair(i, j++); + } + cout << con << '\n'; + for (int i = 0; i < con; i++) cout << pa[i].first << " " << pa[i].second << '\n'; + return 0; +} +int main() { + long long a, b, c, n; + cin >> a >> b >> c >> n; + long long res = 0; + for (long long i = 0; i < n; i++) { + long long x; + cin >> x; + if (x > b && x < c) res++; + } + cout << res << "\n"; +} +int main() { + long long n, x, i; + cin >> n >> x; + int vis[3] = {0, 0, 0}; + vis[x] = 1; + n %= 6; + while (n--) { + if (n % 2 == 0) + swap(vis[0], vis[1]); + else + swap(vis[1], vis[2]); + } + for (i = 0; i < 3; i++) + if (vis[i]) cout << i << endl; + return 0; +} +int main() { + int cnt = 0, k = 0; + string s, t; + cin >> s >> t; + for (int i = 0; i < t.size(); i++) { + if (t[i] == s[k]) { + cnt++; + k++; + } + } + cout << cnt + 1 << endl; + return 0; +} +char inPutStr[1001]; +int strArr[26], k; +char subStr[1001]; +void makeAString() { + int idx = 0; + for (int j = 0; j < 26; j++) { + while (strArr[j] != 0) { + subStr[idx] = j + 'a'; + idx++; + strArr[j] = strArr[j] - k; + } + } + for (int i = 0; i < k; i++) { + for (int j = 0; j < idx; j++) { cout << subStr[j]; } + } + cout << endl; +} +int main() { + for (int i = 0; i < 26; i++) { strArr[i] = 0; } + cin >> k; + cin >> inPutStr; + for (int i = 0; inPutStr[i]; i++) { + int id = inPutStr[i] - 'a'; + strArr[id] = strArr[id] + 1; + } + bool Result = true; + for (int i = 0; i < 26; i++) { + if (strArr[i] % k != 0) { + Result = false; + break; + } + } + if (Result) { + makeAString(); + } else + cout << "-1" << endl; + return 0; +} +int n, cnt, ans, h, b; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> b; + if (b > h) { + cnt += 1; + h = b; + } else if (b <= h) { + if (cnt > ans) { ans = cnt; } + cnt = 1; + h = b; + } + } + if (cnt > ans) { ans = cnt; } + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int hang = 1; hang <= n; hang++) { + if (hang % 4 == 0) { + int k = 1; + cout << "#"; + while (k < m) { + cout << "."; + k++; + } + cout << endl; + } else if (hang % 2 == 0) { + int k = 1; + while (k < m) { + cout << "."; + k++; + } + cout << "#" << endl; + } else { + int k = 1; + while (k <= m) { + cout << "#"; + k++; + } + cout << endl; + } + } +} +int main() { + long long int n; + cin >> n; + cout << "25" << endl; +} +int main() { + int Size; + cin >> Size; + for (int i = 0; i <= (Size / 2); i++) { + for (int j = 0; j < (Size / 2) - i; j++) { cout << "*"; } + for (int k = 0; k < (i * 2) + 1; k++) cout << "D"; + for (int j = 0; j < (Size / 2) - i; j++) { cout << "*"; } + cout << endl; + } + for (int i = Size / 2 - 1; i >= 0; i--) { + for (int j = 0; j < (Size / 2) - i; j++) { cout << "*"; } + for (int k = 0; k < (i * 2) + 1; k++) cout << "D"; + for (int j = 0; j < (Size / 2) - i; j++) { cout << "*"; } + cout << endl; + } + return 0; +} +int main() { + int n, mn = INT_MAX; + string s; + cin >> n >> s; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 1; i++) { + if (s[i] == 'R' && s[i + 1] == 'L') mn = min(mn, (a[i + 1] - a[i]) / 2); + } + if (mn != INT_MAX) + cout << mn << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n, k, i, a = 0, len, y = 0, j; + char str[10000]; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> str; + len = strlen(str); + for (j = 0; j < len; j++) { + if (str[j] == '4' || str[j] == '7') { y++; } + } + if (y <= k) { a++; } + y = 0; + } + cout << a << endl; + return 0; +} +int main() { + int n, a; + cin >> n; + string str1[n], str2[n]; + for (int i = 0; i < n; i++) { + cin >> str1[i] >> str2[i]; + if (str2[i] == "captain") a = i; + } + for (int i = 0; i < n; i++) + if (str2[i] == "rat") cout << str1[i] << endl; + for (int i = 0; i < n; i++) + if (str2[i] == "woman" || str2[i] == "child") cout << str1[i] << endl; + for (int i = 0; i < n; i++) + if (str2[i] == "man") cout << str1[i] << endl; + cout << str1[a] << endl; + return 0; +} +int main() { + string str; + int n, d; + cin >> n >> d; + int cnt = 0, mx = 0, ans = 0; + for (int i = 0; i < d; i++) { + cnt = 0; + cin >> str; + for (int i = 0; i < n; i++) { + if (str[i] == '1') cnt++; + } + if (cnt != n) + ans++; + else { + ans = 0; + } + if (ans > mx) mx = ans; + } + cout << mx << endl; + return 0; +} +const int N = 1e5 + 100; +int n, a[55], m, b[55], ans; +vector v; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + cin >> m; + for (int i = 0; i < m; i++) { cin >> b[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (b[j] % a[i] == 0) { v.push_back(b[j] / a[i]); } + } + } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + for (int i = 0; i < v.size(); i++) { + if (v[i] == v[0]) ans++; + } + cout << ans << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + int a[105]; + cin >> n >> m; + for (i = 0; i < n; i++) cin >> a[i]; + int cou = 0; + for (i = 0; i < n; i++) { + if (a[i] && a[i] <= m) + a[i] = 0, cou++; + else + break; + } + for (i = n - 1; i >= 0; i--) { + if (a[i] && a[i] <= m) + a[i] = 0, cou++; + else + break; + } + cout << cou << endl; +} +int a[105] = {0}; +int main() { + int m, n, l, flag = 1, xx, t; + cin >> m >> n; + for (int i = 1; i <= m; i++) { + cin >> t; + for (int i = 1; i <= t; i++) { cin >> xx, a[xx] = 1; } + } + for (l = 1; l <= n; l++) + if (a[l] == 0) { + flag = 0; + break; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s, s1; + cin >> s >> s1; + if (s == s1) + cout << -1 << endl; + else + cout << max(s.size(), s1.size()) << endl; +} +int main() { + int n; + cin >> n; + int i = 2; + while (n - i * (i + 1) / 2 > 0) { + n -= i * (i + 1) / 2; + i++; + } + cout << i - 1 << endl; +} +int main() { + int n, c, ans = 1; + cin >> n >> c; + int arr[n]; + cin >> arr[0]; + for (int i = 1; i < n; i++) { + cin >> arr[i]; + if (arr[i] - arr[i - 1] > c) { + ans = 1; + } else { + ans++; + } + } + cout << ans << endl; +} +long long n, c; +int x; +int arr[1000001]; +int main() { + cin >> n >> c; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + x++; + if (arr[i] - arr[i - 1] > c) { + x = 1; + } else { + x = x; + } + } + cout << x << endl; +} +int main() { + int s, v1, v2, t1, t2; + int x1, x2; + cin >> s >> v1 >> v2 >> t1 >> t2; + x1 = s * v1 + 2 * t1; + x2 = s * v2 + 2 * t2; + if (x1 < x2) + cout << "First" << endl; + else if (x1 > x2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; +} +int main() { + string s; + cin >> s; + int count = 0, l = s.size() - 1; + for (int i = 0; i < s.size() / 2; i++) { + if (s[i] != s[l - i]) { count++; } + } + if (s.size() % 2 == 0 && count == 1) { + cout << "YES" << endl; + } else if (s.size() % 2 == 1 && (count == 1 || count == 0)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int k; + string s; + cin >> s >> k; + if (s.size() < k) return cout << "impossible\n", 0; + sort(s.begin(), s.end()); + s.resize(unique(s.begin(), s.end()) - s.begin()); + cout << max(k - (int)s.size(), 0) << endl; + return 0; +} +const int maxn = 1000; +int main() { + int game[maxn + 10], wallet[maxn + 10]; + int m, n; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> game[i]; + for (int i = 0; i < m; i++) cin >> wallet[i]; + int sum = 0, x = 0, i = 0; + while (i != m && x != n) { + if (wallet[i] >= game[x]) { + sum++; + i++; + } + x++; + } + cout << sum << endl; +} +int main() { + char a[30]; + while (cin >> a) { + int x = strlen(a); + cout << (x + 1) * 26 - x << endl; + } + return 0; +} +vector v1, v2, v3; +long long int a[100001]; +int main() { + long long int n, i; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) + v1.push_back(i + 1); + else if (a[i] == 2) + v2.push_back(i + 1); + else + v3.push_back(i + 1); + } + long long int m = min(min(v1.size(), v2.size()), v3.size()); + cout << m << "\n"; + for (i = 0; i < m; i++) { cout << v1[i] << " " << v2[i] << " " << v3[i] << "\n"; } + return 0; +} +int main() { + map m; + int q; + cin >> q; + while (q--) { + int tc; + cin >> tc; + if (tc == 1) { + long long u, v, w; + cin >> u >> v >> w; + m[u] += w; + m[v] += w; + while (u != v) { + if (v > u) swap(u, v); + u /= 2; + if (u == v) + m[u] -= w; + else + m[u] += w; + } + } + if (tc == 2) { + long long u, v; + cin >> u >> v; + long long sol = m[u] + m[v]; + while (u != v) { + if (v > u) swap(u, v); + u /= 2; + if (u == v) + sol -= m[u]; + else + sol += m[u]; + } + cout << sol << "\n"; + } + } + return 0; +} +char a[200][200]; +int main() { + int n, m; + cin >> n >> m; + int r1, l1, r2, l2, r3, l3, r4, l4; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j] == 'B') { + r1 = i; + l1 = j; + } + } + } + r2 = r1; + for (int j = l1; j > 0; j--) { + if (a[r1][j] == 'B') { l2 = j; } + } + l4 = l2; + for (int j = r2; j > 0; j--) { + if (a[j][l4] == 'B') { r4 = j; } + } + l3 = l1; + for (int j = r1; j > 0; j--) { + if (a[j][l3] == 'B') { r3 = j; } + } + cout << (r1 + r4) / 2 << ' ' << (l1 + l4) / 2 << endl; +} +int a[100010]; +int main() { + int n; + cin >> n; + int x; + for (int i = 1; i <= n; i++) { + cin >> x; + a[x]++; + } + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, k, x, time = 0; + cin >> n >> k >> x; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n - k; i++) time += a[i]; + time += k * x; + cout << time << endl; + return 0; +} +int main() { + long long n, k, i, s, t, a, m; + while (cin >> n >> k) { + s = 0; + for (i = 1; i <= n; i++) { + cin >> t; + a = t / k; + m = t % k; + if (m != 0) a++; + s = s + a; + } + cout << (s + 1) / 2 << endl; + } + return 0; +} +int main() { + cout.precision(7); + { + int p1, p2, p3, p4, a, b; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + int minP = min(p1, min(p2, min(p3, p4))); + cout << max(0, min(minP - a, b - a + 1)) << "\n"; + } + return 0; +} +int main() { + char xx[90]; + char yy[11]; + char zz[12][12]; + while (cin >> xx) { + for (int i = 0; i < 10; i++) { cin >> zz[i]; } + int a = 0; + for (int i = 0; i <= 80; i++) { + if (a == 10) { + yy[10] = '\0'; + a = 0; + for (int j = 0; j < 10; j++) { + if (strcmp(yy, zz[j]) == 0) { cout << j; } + } + } + yy[a++] = xx[i]; + } + cout << endl; + } + return 0; +} +int x[100005] = {}; +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int s = 0; + while (1) { + int r = 1; + if (b > n - 1) { + r += n - 1; + b -= n - 1; + } else if (b > 0) { + r += b; + b = 0; + } + a = a - (r * c); + s++; + if (a <= 0) break; + } + cout << s << endl; + return 0; +} +string s; +int n, i, cnt; +int main() { + while (cin >> s) { + sort(s.begin(), s.end()); + cnt = unique(s.begin(), s.end()) - s.begin(); + if (cnt % 2) { + cout << "IGNORE HIM!\n"; + } else + cout << "CHAT WITH HER!\n"; + } + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + long long int n; + cin >> n; + long long int x = 1, ans = 1; + while (x < n) { + if (n % x != 0) ans = max(ans, n / x + 1); + x = x * 3; + } + cout << ans << '\n'; +} +int a[27]; +int main() { + string x; + cin >> x; + for (int i = 0; i < x.size(); i++) { a[x[i] - 'a']++; } + int sum = 0; + for (int i = 0; i < 27; i++) { + if (a[i] > 0) sum++; + } + if (sum % 2 != 0) + cout << "IGNORE HIM!" << endl; + else + cout << "CHAT WITH HER!" << endl; +} +const double EPS = 1e-6; +const int INF = 0x3fffffff; +const long long LINF = INF * 1ll * INF; +const double PI = acos(-1.0); +long long ppow[40]; +void init() { + ppow[0] = 1; + for (int i = 1; i < 30; i++) ppow[i] = ppow[i - 1] * 10; +} +long long fun(long long a) { + int n = 0; + long long ans = 0; + while (a) { + ans += ppow[n] * (9 - a % 10); + n++; + a /= 10; + } + return ans; +} +long long ans = 0; +int main() { + init(); + long long l, r; + cin >> l >> r; + for (int i = 1; i < 15; i++) { + long long t = ppow[i] / 2; + if (t < l) t = l; + if (t > r) t = r; + long long tmp = t * fun(t); + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +const int oo = 1e9, MD = 1e9 + 7; +long long fastExp(long long b, long long e) { + long long ans = 1; + while (e > 0) { + if (e & 1) ans = (ans * b) % MD; + b = (b * b) % MD; + e >>= 1; + } + return ans; +} +int main() { + long long n; + cin >> n; + long long ans = (fastExp(4, n) + fastExp(2, n)) % MD; + ans = (ans * fastExp(2, MD - 2)) % MD; + cout << ans << '\n'; + return 0; +} +int main() { + int n, ans = 0; + long int a[100]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 0; i < n; i++) ans += a[n - 1] - a[i]; + cout << ans << endl; + return 0; +} +int main() { + int x; + cin >> x; + for (int i = 1; i <= x; i++) { + if (i % 2) + cout << "I hate "; + else + cout << "I love "; + if (i == x) + cout << "it" << endl; + else + cout << "that "; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int i; + for (i = 0; i < s1.length(); i++) { + if (s1[i] == s2[i]) + s1[i] = '0'; + else + s1[i] = '1'; + } + cout << s1 << endl; + return 0; +} +int main() { + int x; + cin >> x; + int ara[x]; + int maxn; + set s; + maxn = 1000000009; + int d = 1000000009; + bool b = 0; + for (int w = 0; w < x; w++) { + cin >> ara[w]; + if (ara[w] < maxn) { maxn = ara[w]; } + } + for (int w = 0; w < x; w++) { + if (ara[w] == maxn) { s.insert(w); } + } + set::iterator i; + set::iterator j = s.end(); + j--; + int l, m; + for (i = s.begin(); i != s.end(); i++) { + if (i == j) continue; + m = *i; + i++; + l = *i; + i--; + if (l - m < d) d = (l - m); + } + cout << d << endl; + return 0; +} +int main() { + int n, k, w, r, d, cnt = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> w; + if ((w % k) == 0) { + d = (w / k); + } else { + d = (w / k) + 1; + } + cnt += d; + } + if ((cnt % 2) == 0) { + r = (cnt / 2); + } else { + r = (cnt / 2) + 1; + } + cout << r << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int num = (n / 2) / (k + 1); + cout << num << " " << num * k << " " << n - num - num * k << endl; + return 0; +} +int arr[105]; +int main() { + int m; + while (cin >> m) { + for (int i = 0; i < m; i++) cin >> arr[i]; + bool flag = 1; + int ans = 0; + while (flag) { + flag = 0; + int Max = -9999999; + int k = 1; + for (int i = 1; i < m; i++) { + if (arr[i] > Max) { + Max = arr[i]; + k = i; + } + } + if (Max >= arr[0]) { + arr[k]--; + arr[0]++; + ans++; + flag = 1; + } else + flag = 0; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, m, c, mis = 0, ch = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + cin >> c; + if (m > c) mis++; + if (m < c) ch++; + } + if (mis > ch) + cout << "Mishka" << endl; + else if (ch > mis) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; +} +void A(int n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - n / 2) + abs(j - n / 2) <= n / 2) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } +} +int main() { + int n; + cin >> n; + A(n); + return 0; +} +int main() { + int n, s; + string r; + cin >> n; + while (n--) { + cin >> r; + s = r.size(); + if (s > 10) { + cout << r[0]; + cout << r.size() - 2; + cout << r[r.size() - 1]; + cout << endl; + } else + cout << r << endl; + } +} +int main() { + int n, count, sum = 0; + cin >> n; + char mat[n + 1][n + 1]; + for (int i = 0; i < n; i++) { cin >> mat[i]; } + for (int i = 0; i < n; i++) { + count = 0; + for (int j = 0; j < n; j++) { + if (mat[i][j] == 'C') { count++; } + } + sum += (count * (count - 1)) / 2; + } + for (int j = 0; j < n; j++) { + count = 0; + for (int i = 0; i < n; i++) { + if (mat[i][j] == 'C') { count++; } + } + sum += (count * (count - 1)) / 2; + } + cout << sum << "\n"; +} +int mins(int a, int b, int c) { + if (a <= b && a <= c) + return a; + else if (b <= a && b <= c) + return b; + else + return c; +} +int main() { + int n; + cin >> n; + int arr[n + 1]; + vector t1, t2, t3; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + if (arr[i] == 1) + t1.push_back(i); + else if (arr[i] == 2) + t2.push_back(i); + else + t3.push_back(i); + } + int n1 = t1.size(); + int n2 = t2.size(); + int n3 = t3.size(); + int t = mins(n1, n2, n3); + cout << t << "\n"; + for (int i = 0; i < t; i++) { + cout << t1[i] << " " << t2[i] << " " << t3[i]; + cout << "\n"; + } +} +int main() { + long long n; + while (cin >> n) { + if (n == 2) { + cout << "2" << endl; + } else { + cout << "1" << endl; + } + } + return 0; +} +int n, a, b, c, d, ans; +int dryer[101]; +int main() { + cin >> n >> a >> b; + while (--n) { + cin >> c >> d; + for (int i = c; i < d; i++) { dryer[i] = 1; } + } + for (int i = a; i < b; i++) { + if (dryer[i] == 0) { ans++; } + } + cout << ans << endl; + return 0; +} +map soroban; +int main() { + soroban.clear(); + soroban[0] = "O-|-OOOO"; + soroban[1] = "O-|O-OOO"; + soroban[2] = "O-|OO-OO"; + soroban[3] = "O-|OOO-O"; + soroban[4] = "O-|OOOO-"; + soroban[5] = "-O|-OOOO"; + soroban[6] = "-O|O-OOO"; + soroban[7] = "-O|OO-OO"; + soroban[8] = "-O|OOO-O"; + soroban[9] = "-O|OOOO-"; + string s; + cin >> s; + int len = s.length(); + for (int i = len - 1; i >= 0; i--) cout << soroban[s[i] - '0'] << endl; + return 0; +} +int main() { + int size; + cin >> size; + int **a = new int *[size]; + for (int i = 0; i < size; i++) { a[i] = new int[size]; } + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + if (j == 0) { + a[i][j] = 1; + } else { + if (i == 0) { + a[i][j] = a[i][j - 1]; + } else { + a[i][j] = a[i][j - 1] + a[i - 1][j]; + } + } + } + } + cout << a[size - 1][size - 1] << endl; + return 0; +} +int main() { + int d1, d2, d3, count = 0, x = 1, y = 1; + cin >> d1 >> d2 >> d3; + int a[d3 + 1]; + if (d1 == 1000 && d2 == 1000 && d3 == 1000) + cout << "1" << endl; + else { + for (int i = 0; i <= d3; i++) a[i] = 0; + for (int i = 1;; i++) { + if (d1 * i > d3) break; + a[d1 * i]++; + } + for (int i = 1;; i++) { + if (d2 * i > d3) break; + a[d2 * i]++; + } + for (int i = 1; i <= d3; i++) { + if (a[i] > 1) count++; + } + cout << count << endl; + } + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + char a; + int b, c = 0; + cin >> a >> b; + if (a == 'a' || a == 'h') c++; + if (b == 1 || b == 8) c++; + if (c == 0) cout << 8 << endl; + if (c == 1) cout << 5 << endl; + if (c == 2) cout << 3 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (abs(b - a) <= 1 && (b != 0 || a != 0)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char a[105]; + int i, b, c, d, len, flag = 0; + b = c = d = 0; + cin >> a; + len = strlen(a); + if (len >= 5) { + for (i = 0; i < len; i++) { + if (d && b && c) { + flag = 1; + break; + } + if (a[i] >= 'A' && a[i] <= 'Z') + b++; + else if (a[i] >= 'a' && a[i] <= 'z') + c++; + else if (a[i] >= '0' && a[i] <= '9') + d++; + } + } + if (flag) + cout << "Correct\n"; + else + cout << "Too weak\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n], count = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i] == b[j]) count++; + } + } + cout << count << "\n"; +} +int main() { + int price, remainder, store = 0, i = 0; + cin >> price >> remainder; + while (1) { + i++; + store = price * i; + if (store % 10 == remainder) { + break; + } else if (store % 10 == 0) { + break; + } + } + cout << i << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + string arr[n]; + char c; + char b; + bool flag = true; + for (int i = 0; i < n; i++) { + cin.ignore(); + cin >> arr[i]; + } + c = arr[0][0]; + b = arr[0][1]; + if (c == b) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j) { + if (arr[i][j] != c) { + cout << "NO" << endl; + return 0; + } + } else if (i + j == n - 1) { + if (arr[i][j] != c) { + cout << "NO" << endl; + return 0; + } + } else { + if (arr[i][j] != b) { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + char s[100]; + char c[5] = {'h', 'e', 'l', 'l', 'o'}; + cin >> s; + long long i, ch = 0, cn = 0, j = 0, d = 0; + long long ln = strlen(s); + for (i = 0; i < 5; i++) { + for (j = d; j < ln;) { + if (c[i] == s[j]) { + cn++; + j++; + d = j; + break; + } + j++; + d = j; + } + j = d; + } + if (cn == 5) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +static long long n, m, k; +int main() { + int n; + cin >> n; + vector p(n); + for (int i = 0; i < n; i++) cin >> p[i]; + int res = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + res += x; + } + res = (res + 1) % 2; + vector visited(n); + int count = -1; + for (int i = 0; i < n; i++) { + if (visited[i]) continue; + count++; + int j = i; + while (!visited[j]) { + visited[j] = true; + j = p[j] - 1; + } + } + if (count > 0) res++; + res += count; + cout << res << endl; +} +int main() { + string s; + cin >> s; + char stack[s.size()]; + long int j = 0; + for (int i = 0; i < s.size(); i++) { + if (j == 0) { + stack[j++] = s[i]; + } else if (stack[j - 1] != s[i]) { + stack[j++] = s[i]; + } else { + j--; + } + } + for (int i = 0; i < j; i++) { cout << stack[i]; } + cout << endl; + return 0; +} +const int MAXN = 2e5 + 5; +int n, a[MAXN]; +int main() { + cin >> n; + int ans = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + 1 + n); + for (int i = n / 2 + 1; i <= n; i++) ans = min(ans, a[i] - a[i - n / 2]); + cout << ans << endl; + return 0; +} +int main() { + int p = 0; + int n; + cin >> n; + p = p + n / 5; + n = n % 5; + p = p + n / 4; + n = n % 4; + p = p + n / 3; + n = n % 3; + p = p + n / 2; + n = n % 2; + p = p + n / 1; + n = n % 1; + cout << p << endl; +} +int d[1005]; +int s[1005]; +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> d[i]; + for (int i = 1; i <= n; i++) cin >> s[i]; + int now = 0, ans = 0, mx = 0; + for (int i = 1; i <= n; i++) { + now += s[i]; + mx = max(mx, s[i]); + int need = d[i]; + if (now < need) { + int dif = need - now; + int fill = dif / mx + (dif % mx ? 1 : 0); + ans += fill * k; + now += fill * mx; + } + ans += d[i]; + now -= d[i]; + } + cout << ans << "\n"; + return 0; +} +const int max4 = 10004; +const int maxx = 200005; +const int max6 = 1000006; +const int lg5 = 17; +const int INF = 1000000007; +const long long INFLL = 4LL * 1000000000 * 1000000000; +int powmod(int a, int b, int mod) { + int res = 1; + a %= mod; + for (; b; b >>= 1) { + if (b & 1) { res = 1LL * res * a % mod; } + a = 1LL * a * a % mod; + } + return res; +} +int gcd(int a, int b) { + while (b > 0) { + int t = a % b; + a = b, b = t; + } + return a; +} +int lcm(int a, int b) { + return (a / gcd(a, b)) * b; +} +int is_prime(int n) { + if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0)) return 0; + for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t) + if (n % i == 0) return 0; + return 1; +} +int n, arr[maxx], pref[maxx], suff[maxx]; +int main() { + cin >> n; + if (n == 1) { return cout << 1 << '\n', 0; } + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) { + if (arr[i] > arr[i - 1]) { + pref[i] = pref[i - 1] + 1; + } else { + pref[i] = 1; + } + } + for (int i = n; i >= 1; i--) { + if (i == n || arr[i] < arr[i + 1]) { + suff[i] = suff[i + 1] + 1; + } else { + suff[i] = 1; + } + } + int res = 2; + for (int i = 2; i < n; i++) { + if (arr[i + 1] > arr[i - 1] + 1) { res = max(res, pref[i - 1] + suff[i + 1] + 1); } + } + for (int i = 2; i < n; i++) { res = max(res, max(pref[i], suff[i]) + 1); } + cout << res << '\n'; + return 0; +} +int main() { + int i, n, m, c = 0; + cin >> n >> m; + int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + i = 0; + int j = n - 1; + for (i = 0; i < n; i++) { + if (a[i] <= m) { + c += 1; + } else { + break; + } + } + if (c < n) { + for (i = n - 1; i >= 0; i--) { + if (a[i] <= m) { + c += 1; + } else { + break; + } + } + cout << c << endl; + } else { + cout << n << endl; + } + return 0; +} +int main() { + long long n, cnt = 0, cnt1 = 0; + cin >> n; + string x; + cin >> x; + for (int i = 0; i < x.size(); i++) { + if (x[i] == '1') + cnt1++; + else + cnt++; + } + cout << max(cnt, cnt1) - min(cnt, cnt1) << endl; + return 0; +} +int mat[10][10]; +int ans[10][10]; +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, 1, 0, -1}; +bool isval(int x, int y) { + return x >= 0 && x < 3 && y >= 0 && y < 3; +} +int main() { + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { + cin >> mat[i][j]; + ans[i][j] = 1; + } + int x, y; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + ans[i][j] = (ans[i][j] + mat[i][j]) % 2; + for (int k = 0; k < 4; k++) { + x = i + dx[k]; + y = j + dy[k]; + if (isval(x, y)) ans[x][y] = (ans[x][y] + mat[i][j]) % 2; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << ans[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, k, i, flag = 0, temp; + cin >> n >> k; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (i == k - 1) { temp = a[i]; } + if (i >= k) { + if (a[i] != temp) flag = 1; + } + } + if (n == 1) { + cout << "0" << endl; + return 0; + } + if (flag == 1) { + cout << "-1" << endl; + return 0; + } + flag = 0; + i = k - 2; + while (1) { + if (temp != a[i]) break; + i--; + flag++; + } + cout << k - flag - 1 << endl; +} +int a[100005]; +int main() { + int n; + cin >> n; + int maxlen = 0; + int curlen = 0; + cin >> a[0]; + curlen++; + maxlen = max(maxlen, curlen); + for (int i = 1; i < n; i++) { + cin >> a[i]; + if (a[i] > a[i - 1]) { + curlen++; + maxlen = max(maxlen, curlen); + } else { + curlen = 1; + } + } + cout << maxlen << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int l, v, a, b; + cin >> l >> v >> a >> b; + long long int numOfLight = (l / v) - ((b / v) - (a - 1) / v); + cout << numOfLight << endl; + } +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +int main() { + string s1; + cin >> s1; + char ch; + int len = s1.length(); + int upper = 0, lower = 0; + for (int i = 0; i < len; i++) { + ch = s1[i]; + if (isupper(ch)) + upper++; + else + lower++; + } + if (upper > lower) { + for (int i = 0; i < len; i++) { s1[i] = toupper(s1[i]); } + } else { + for (int i = 0; i < len; i++) { s1[i] = tolower(s1[i]); } + } + cout << s1 << endl; +} +int main() { + long long n; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + long long ans = 0; + for (long long i = 0; i < n - 1; i++) { + if ((a[i + 1] - a[i]) > 1) { ans = ans + ((a[i + 1] - a[i]) - 1); } + } + cout << ans << endl; + return 0; +} +int main() { + int n, l(1), ml(1); + cin >> n; + int profits[n]; + for (int i = 0; i < n; i++) { + cin >> profits[i]; + if (i > 0) + if (profits[i] >= profits[i - 1]) { + l++; + ml = max(ml, l); + } else + l = 1; + } + cout << ml << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int c = 0; + for (int a = 0; a <= 1000; a++) { + for (int b = 0; b <= 1000; b++) { + if (a * a + b == n && b * b + a == m) c++; + } + } + cout << c << endl; + return 0; +} +int main() { + long long n, a[101], b, c; + long min_ = 156544555; + while (cin >> n) { + for (int i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + long div = n / i; + long mod = i; + if ((div - mod) < min_) { + min_ = div - mod; + b = mod; + c = div; + } + } + } + cout << b << " " << c << endl; + } + return 0; +} +int main() { + int n, r; + r = 1; + cin >> n; + if (n == 1000) { + cout << "691074" << endl; + return 0; + } + for (int i = 0; i < n - 1; i++) { + r *= 3; + r %= 1000003; + } + cout << r << endl; +} +int a[100005]; +int main() { + int n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int l = unique(a, a + n) - a; + for (int m = 0; m < l; m++) { + if (a[m] != 0) sum++; + } + cout << sum << endl; + return 0; +} +int main() { + int n, m, min, max; + cin >> n >> m >> min >> max; + int assistantTemps[m]; + for (int i = 0; i < m; i++) { + cin >> assistantTemps[i]; + if (assistantTemps[i] > max || assistantTemps[i] < min) { + cout << "Incorrect" << endl; + return 0; + } + } + int missingTemps = n - m; + int tempRange = 2; + for (int i = 0; i < m; i++) { + if (assistantTemps[i] == max || assistantTemps[i] == min) { tempRange--; } + } + if (tempRange > missingTemps) { + cout << "Incorrect" << endl; + return 0; + } + cout << "Correct" << endl; + return 0; +} +const int mod1 = 1e9 + 7; +const int mod2 = 1e9 + 9; +const int maxN = 2e5; +const int INF = 1e9 + 7; +const long long LL_INF = 1e18 + 11; +long long a, b, c, x1, yy1, x2, yy2, n, x; +bool v; +int main() { + cin >> n; + for (int ggg = 1; ggg <= n; ggg++) { + cin >> x; + v = false; + for (int i = 3; i <= 99999; i++) { + if ((i - 2) * 180 % x != 0) { continue; } + if ((i - 2) * 180 / x == i) { + cout << "YES" << endl; + v = true; + break; + } + } + if (!v) { cout << "NO" << endl; } + } +} +int main() { + int n; + cin >> n; + pair game; + game.first = 1; + game.second = 2; + int spec = 3; + for (int i = 0, t; i < n; i++) { + cin >> t; + if (t == spec) { + cout << "NO\n"; + return 0; + } + if (t == game.first) { + t = spec; + spec = game.second; + game.second = t; + } else { + t = spec; + spec = game.first; + game.first = t; + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n, m, temp = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) + cout << "#"; + else { + if (temp % 2 != 0) { + if (j == m) + cout << "#"; + else + cout << "."; + } else { + if (j == 1) + cout << "#"; + else + cout << "."; + } + } + } + if (i % 2 != 0) { temp++; } + cout << endl; + } +} +const long long N = 1000001, inf = 1e18; +long long n, m, c, s, a, b; +vector v[N]; +int main() { + long long t; + cin >> t; + while (t) { + t--; + cin >> s >> a >> b >> c; + cout << (s / c) + (s / c) / a * b << "\n"; + } +} +int main() { + int n, m, i, j = 0; + cin >> n; + cin >> m; + for (i = 1; i <= n; i++, j++) { + if (i % m == 0) { n++; } + if (n < m) { + j = n; + break; + } + } + cout << j << endl; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; ++i) { cin >> a[i]; } + sort(a.begin(), a.end()); + cout << a[n / 2] << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int d = min(a, b); + if (n == 1) + cout << 0 << endl; + else + cout << d + (n - 2) * min(d, c) << endl; + return 0; +} +void printDiamond(int diamond, int n) { + int dotNum = (n - diamond) / 2; + for (int i = 0; i < n; i++) { + if (i < dotNum || i >= (dotNum + diamond)) { + cout << "*"; + } else { + cout << "D"; + } + } +} +int main() { + int n; + cin >> n; + int diamond = 1; + for (int i = 0; i < n; i++) { + printDiamond(diamond, n); + cout << endl; + if (i >= n / 2) { + diamond -= 2; + } else { + diamond += 2; + } + } +} +char str[1007]; +bool vis[1007]; +int main() { + cin >> str; + vis['a'] = vis['e'] = vis['i'] = vis['o'] = vis['u'] = true; + for (int i = 0; str[i]; i++) + if (!vis[str[i]] && str[i] != 'n') + if (!vis[str[i + 1]]) return 0 * puts("NO"); + puts("YES"); + return 0; +} +int main() { + int a, b, count1 = 0, count2 = 0; + cin >> a >> b; + for (int i = 0;; i++) { + if ((a == 0 && b == 1) || (a == 1 && b == 0) || (a == 0 && b == 0)) break; + --a; + --b; + ++count1; + if (a == 0 && b > 1) { + while (b != 0) { + b = b - 2; + ++count2; + if (b < 0 || b == 1) break; + } + break; + } + if (a > 1 && b == 0) { + while (a != 0) { + a = a - 2; + ++count2; + if (a < 0 || a == 1) break; + } + break; + } + } + cout << count1 << " " << count2 << endl; +} +int main() { + int n; + cin >> n; + int ma = 0; + int a[110]; + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) { + int num; + cin >> num; + a[num]++; + ma = max(a[num], ma); + } + cout << ma << endl; +} +int main() { + int i, j, l, x, m, m1, k = 0, res = 0; + cin >> x; + int a[1000] = {0}; + for (j = 4; j <= 1000; j++) { + i = j; + m = 0, m1 = 0; + while (i > 0) { + l = i % 10; + if (l == 4 || l == 7) m++; + i = i / 10; + m1++; + } + if (m == m1) { + a[k] = j; + k++; + } + } + for (i = 0; i < k; i++) { + if (x % a[i] == 0) { + res = 5; + break; + } + } + if (res == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int ans = 0; + for (int i = 0; i < n; i++) + for (int j = i; j < n; j++) { + int x = v[i]; + for (int k = i + 1; k <= j; k++) x = (x ^ v[k]); + ans = max(ans, x); + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 && m == 0) { + cout << 0 << " " << 0 << endl; + } else if (n == 0) { + cout << "Impossible" << endl; + } else { + cout << (n > m ? n : m) << " " << (m > 0 ? n + m - 1 : n) << endl; + } + return 0; +} +int main() { + long long n, k, x; + cin >> n >> k; + x = n / k; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + string s1; + string s2; + cin >> s1 >> s2; + int k = 0; + for (int i = 0; i < s2.length(); i++) { + if (s2[i] == s1[k]) k++; + } + cout << k + 1 << endl; +} +int main() { + int i, j, n; + int a[3][3]; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) cin >> a[i][j]; + if ((a[0][0] + a[0][1] + a[1][0]) % 2 == 1) cout << "0"; + if ((a[0][0] + a[0][1] + a[1][0]) % 2 == 0) cout << "1"; + if ((a[0][0] + a[0][1] + a[1][1] + a[0][2]) % 2 == 1) cout << "0"; + if ((a[0][0] + a[0][1] + a[1][1] + a[0][2]) % 2 == 0) cout << "1"; + if ((a[0][2] + a[0][1] + a[1][2]) % 2 == 1) cout << "0\n"; + if ((a[0][2] + a[0][1] + a[1][2]) % 2 == 0) cout << "1\n"; + if ((a[0][0] + a[1][0] + a[2][0] + a[1][1]) % 2 == 1) cout << "0"; + if ((a[0][0] + a[1][0] + a[2][0] + a[1][1]) % 2 == 0) cout << "1"; + if ((a[1][0] + a[1][1] + a[1][2] + a[0][1] + a[2][1]) % 2 == 1) cout << "0"; + if ((a[1][0] + a[1][1] + a[1][2] + a[0][1] + a[2][1]) % 2 == 0) cout << "1"; + if ((a[0][2] + a[1][2] + a[2][2] + a[1][1]) % 2 == 1) cout << "0\n"; + if ((a[0][2] + a[1][2] + a[2][2] + a[1][1]) % 2 == 0) cout << "1\n"; + if ((a[1][0] + a[2][0] + a[2][1]) % 2 == 1) cout << "0"; + if ((a[1][0] + a[2][0] + a[2][1]) % 2 == 0) cout << "1"; + if ((a[2][0] + a[2][1] + a[2][2] + a[1][1]) % 2 == 1) cout << "0"; + if ((a[2][0] + a[2][1] + a[2][2] + a[1][1]) % 2 == 0) cout << "1"; + if ((a[2][2] + a[2][1] + a[1][2]) % 2 == 1) cout << "0\n"; + if ((a[2][2] + a[2][1] + a[1][2]) % 2 == 0) cout << "1\n"; + return 0; +} +int ar[12]; +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + ar[a]++; + ar[b]++; + ar[c]++; + ar[d]++; + ar[e]++; + ar[f]++; + bool paichi = false; + for (int i = 1; i <= 9; i++) { + if (ar[i] >= 4) { paichi = true; } + } + if (!paichi) return cout << "Alien\n", 0; + int cnt = 0; + for (int i = 1; i <= 9; i++) { + if (ar[i] == 2 or ar[i] == 6) return cout << "Elephant\n", 0; + } + cout << "Bear\n"; + return 0; +} +int main() { + int x, y, a, b, p, ans, u, v, gcd, lcm; + cin >> x >> y >> a >> b; + p = __gcd(x, y); + lcm = (x * y) / p; + u = a / lcm; + v = b / lcm; + ans = v - u; + if ((a % lcm) == 0) { ans = ans + 1; } + cout << ans << endl; + return 0; +} +const long long int mod = 1e9 + 7; +const int siz = 200010; +int main() { + long long int n; + cin >> n; + long long int num, sum = 0; + for (long long int i = 0; i < n; ++i) { + cin >> num; + sum += num; + } + long long int m, li, ri, ans = -1; + cin >> m; + while (m--) { + cin >> li >> ri; + if ((sum >= li && sum <= ri) || (li >= sum)) { + ans = max(sum, li); + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +int main() { + int n, x, a = 0, b = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + a |= x; + } + for (int j = 0; j <= n; j++) { + cin >> x; + b |= x; + } + cout << a + b << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int N = 1010; +long long a[N]; +int main() { + int m; + cin >> m; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + long long ans = 0; + for (int i = 1; i < m; i++) ans += a[i] - a[i - 1] - 1; + cout << ans << endl; + return 0; +} +int main() { + int n, s; + cin >> n; + s = n / 2; + n = n + s; + cout << n << endl; + return 0; +} +int main() { + int n, x; + cin >> n; + x = sqrt(n); + while (n % x != 0) { x--; } + cout << x << ' ' << n / x << endl; + return 0; +} +int main() { + int y; + cin >> y; + while (true) { + y += 1; + int a = y / 1000; + int b = y / 100 % 10; + int c = y / 10 % 10; + int d = y % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } + } + cout << y << endl; + return 0; +} +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + long long a; + cin >> a; + bool NAO = true; + long long ini = 3; + long long fim = 1000000000; + while (fim - ini > 0) { + long long mid = (fim + ini) / 2; + if (((mid - 2) * 180) / (double)mid >= a) { + fim = mid; + } else { + ini = mid + 1; + } + } + if (((ini - 2) * 180) / (double)ini == a) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +vector prime(10000005, 0); +long long mM(long long a, long long b, long long mod) { + long long res = 0; + a %= mod; + while (b) { + if (b & 1) res = (res + a) % mod; + a = (2 * a) % mod; + b >>= 1; + } + return res; +} +long long fpow(long long first, long long second, long long p) { + first = first % p; + long long res = 1; + while (second) { + if (second & 1) res = (res * first) % p; + res %= p; + if (res < 0) res = (res + p) % p; + second = second >> 1; + first = (first * first) % p; + if (first < 0) first = (first + p) % p; + first %= p; + } + return res; +} +long long inv(long long n) { + return fpow(n, 1000000007 - 2, 1000000007); +} +long long modmul(long long first, long long second) { + return ((first % 1000000007) * (second % 1000000007)) % 1000000007; +} +long long modadd(long long first, long long second) { + long long temp = first % 1000000007 + second % 1000000007; + temp %= 1000000007; + if (temp < 0) temp = (temp + 1000000007) % 1000000007; + return temp; +} +void sieve() { + prime[1] = 1; + for (long long i = 2; i < 10000005; i++) + if (!prime[i]) + for (long long j = i; j < 10000005; j += i) + if (!prime[j]) prime[j] = i; +} +string rot(string s) { + string mn = s; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + swap(s[1], s[2]); + swap(s[2], s[3]); + swap(s[3], s[4]); + mn = min(mn, s); + } + swap(s[0], s[1]); + swap(s[1], s[5]); + swap(s[5], s[3]); + } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + swap(s[1], s[2]); + swap(s[2], s[3]); + swap(s[3], s[4]); + mn = min(mn, s); + } + swap(s[0], s[4]); + swap(s[4], s[2]); + swap(s[4], s[5]); + } + return mn; +} +int main() { + long long t; + t = 1; + while (t--) { + string s; + cin >> s; + sort(s.begin(), s.end()); + set st; + do { st.insert(rot(s)); } while (next_permutation(s.begin(), s.end())); + cout << st.size() << "\n"; + } +} +int main() { + int n, a, s = 3; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == s) { + cout << "NO" << endl; + return 0; + } + s = 6 - a - s; + } + cout << "YES" << endl; +} +const int INF = 0x3f3f3f3f; +const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; +inline long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +const int maxn = 1e5 + 10; +int m, k; +int d[maxn], mx[maxn], s[maxn]; +int main() { + cin >> m >> k; + for (int i = 1; i <= m; i++) cin >> d[i]; + for (int i = 1; i <= m; i++) { + cin >> s[i]; + mx[i] = max(mx[i - 1], s[i]); + } + int ans = 0, now = s[1]; + for (int i = 1; i <= m; i++) { + while (d[i] > now) now += mx[i], ans += k; + now -= d[i]; + now += s[i + 1]; + ans += d[i]; + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + if (s.length() % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> K; + vector v(N); + for (int i = 0; i < K; i++) { + cin >> M; + v[M % N]++; + if (v[M % N] == 2) { + cout << i + 1 << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n, k, i, j = 0; + cin >> n >> k; + int n1[100000]; + for (int i = 1; i <= n; i++) cin >> n1[i]; + for (i = 1; i <= n; i++) { + if (n1[i] <= k) + j++; + else + break; + } + if (j != n) { + for (int i = n; i >= 1; i--) { + if (n1[i] <= k) + j++; + else + break; + } + } + cout << j << endl; + return 0; +} +long long m; +long long pw(long long x, long long p) { + if (!p) return 1 % m; + long long z = pw(x, p / 2); + z *= z; + z %= m; + if (p % 2 == 0) return z; + z *= x; + z %= m; + return z; +} +int main() { + long long n; + cin >> n >> m; + long long res = 2 * (pw(3, n) - 1) / (2); + res %= m; + res += m; + res %= m; + cout << res << endl; + return 0; +} +int main() { + long long n, m, i, j, p, q, cnt, c1, c2, x, y, mn; + string s; + while (cin >> n >> c1 >> c2) { + getchar(); + cin >> s; + cnt = 0; + mn = LONG_LONG_MAX; + for (i = 0; i < s.size(); i++) { + if (s[i] == '1') cnt++; + } + for (i = 1; i <= cnt; i++) { + x = n / i; + y = n % i; + p = (c1 + c2 * (x - 1) * (x - 1)) * (i - y); + q = (c1 + (c2 * x * x)) * y; + m = p + q; + mn = min(mn, m); + } + cout << mn << endl; + } +} +int main() { + int n; + cin >> n; + if (n == 1) cout << 1 << endl; + if (n == 2) cout << 2 << endl; + if (n == 3) cout << 6 << endl; + if (n == 4) cout << 20 << endl; + if (n == 5) cout << 70 << endl; + if (n == 6) cout << 252 << endl; + if (n == 7) cout << 924 << endl; + if (n == 8) cout << 3432 << endl; + if (n == 9) cout << 12870 << endl; + if (n == 10) cout << 48620 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int *num = new int[k]; + int i, j, n_end; + for (i = 0; i < k; i++) { + num[i] = 0; + for (j = 0; j < n; j++) { + if (s[j] == i + 'A') num[i] += 1; + } + } + n_end = num[0]; + for (i = 1; i < k; i++) { + if (n_end > num[i]) n_end = num[i]; + } + cout << (n_end * k) << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int flag = 1; + for (int i = 0; i < n; i++) { + int num; + cin >> num; + if (num == 0) { + if (flag) + cout << num, flag = 0; + else + cout << " " << num; + } else if (num % 2 == 0) { + if (flag) + cout << num - 1, flag = 0; + else + cout << " " << num - 1; + } else { + if (flag) + cout << num, flag = 0; + else + cout << " " << num; + } + } + cout << endl; + } +} +int main() { + int n; + cin >> n; + if (n % 5 != 0) { + cout << n / 5 + 1 << endl; + } else { + cout << n / 5 << endl; + } +} +int main() { + vector v, ans; + int n, k, te = 0, net = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int p; + cin >> p; + if (p == 1) + te++; + else + net++; + v.push_back(p); + } + for (int i = 0; i < k; i++) { + int tt = 0; + int nn = 0; + for (int j = i; j < n; j += k) { + if (v[j] == 1) + tt++; + else + nn++; + } + int m1 = abs(tt - te); + int m2 = abs(nn - net); + ans.push_back(abs(m1 - m2)); + } + cout << *max_element(ans.begin(), ans.end()) << endl; + return 0; +} +long int arr[1001]; +int main() { + int n, i, mid; + cin >> n; + for (i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + mid = ceil((double)n / 2); + cout << arr[mid - 1] << endl; +} +int main() { + int x, y, a; + cin >> x >> y; + if (x < y) + a = x; + else + a = y; + if (a % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int a[10010]; +int main() { + a[1] = 1; + long long int sum, m; + for (int i = 2; i <= 10000; i++) a[i] = a[i - 1] + i; + while (cin >> m) { + for (int i = 1; i <= 10000; i++) { + m -= a[i]; + if (m < a[i + 1]) { + cout << i << endl; + break; + } + } + } + return 0; +} +int main() { + long long int t, l, r; + cin >> t; + if (t >= 0) + cout << t << "\n"; + else { + if (abs(t) % 10 > abs(t / 10) % 10) { + t /= 10; + } else { + l = abs(t) % 10; + r = abs(t) / 100; + t = -(abs(r) * 10 + l); + } + cout << t << "\n"; + } +} +int main() { + long long n, k, m; + cin >> n; + k = sqrt(2.0 * n + 0.25) - 0.5; + m = k * (k + 1) / 2; + if (n > m) + cout << n - m << endl; + else + cout << m + k - n << endl; + return 0; +} +char a[5000], b[5000]; +int main() { + int n; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + while (cin >> n) { + int cnt = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 0; i < n; i++) { + if (abs(a[i] - b[i]) >= 5) { + int t1 = 0, t2 = 0; + t1 = max(a[i] - '0', b[i] - '0'); + t2 = min(a[i] - '0', b[i] - '0'); + cnt += (10 - t1 + t2); + } else { + cnt += abs(a[i] - b[i]); + } + } + cout << cnt << endl; + } + return 0; +} +int main() { + int x = 0; + int numOfteams = 0; + cin >> numOfteams; + int arr[numOfteams][2]; + for (int i = 0; i < numOfteams; i++) { + for (int j = 0; j < 2; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < numOfteams; i++) { + for (int j = 0; j < numOfteams; j++) { + if (arr[i][0] == arr[j][1]) { x++; } + } + } + cout << x << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k = 1; + while (m >= k) { + m -= k; + k++; + if (k > n) k -= n; + } + cout << m << endl; +} +int n, k, a[1001], ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + a[i] = k; + sort(a, a + i + 1); + if (((a[0] == k && a[1] != k) || (a[i] == k && a[i - 1] != k)) && i != 0) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + map m; + int q; + cin >> q; + while (q--) { + int tc; + cin >> tc; + if (tc == 1) { + long long u, v, w; + cin >> u >> v >> w; + m[u] += w; + m[v] += w; + while (u != v) { + if (v > u) swap(u, v); + u /= 2; + if (u == v) + m[u] -= w; + else + m[u] += w; + } + } + if (tc == 2) { + long long u, v; + cin >> u >> v; + long long sol = m[u] + m[v]; + while (u != v) { + if (v > u) swap(u, v); + u /= 2; + if (u == v) + sol -= m[u]; + else + sol += m[u]; + } + cout << sol << "\n"; + } + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int l1 = s1.length(), l2 = s2.length(); + int c1, c2; + int l = l1, ll = l2; + for (int i = 0; i < l1; i++) { + if (s1[i] != '0') { + c1 = i; + break; + } + if (i == l1 - 1) { + l1 = 1; + c1 = 0; + s1 = "0"; + } + } + for (int i = 0; i < l2; i++) { + if (s2[i] != '0') { + c2 = i; + break; + } + if (i == l2 - 1) { + l2 = 1; + c2 = 0; + s2 = "0"; + } + } + l1 -= c1; + l2 -= c2; + if (l1 > l2) + cout << ">" << endl; + else if (l1 < l2) + cout << "<" << endl; + else { + int i = 0; + while (1) { + if (i + c1 >= l || i + c2 >= ll) break; + if (s1[i + c1] > s2[i + c2]) { + cout << ">" << endl; + return 0; + } else if (s1[i + c1] < s2[i + c2]) { + cout << "<" << endl; + return 0; + } + i++; + } + cout << "=" << endl; + } + return 0; +} +int m, k, s[1002], d[1002]; +void Input() { + int i; + cin >> m >> k; + for (i = 1; i <= m; i++) cin >> d[i]; + for (i = 1; i <= m; i++) cin >> s[i]; +} +int main() { + Input(); + int i, p; + int sup = 0; + int tmp = 0; + int t = 0; + int a; + for (i = 1; i <= m; i++) { + sup += s[i]; + if (tmp < s[i]) { + p = i; + tmp = s[i]; + } + if (sup < d[i]) { + if ((d[i] - sup) % s[p] == 0) + a = (d[i] - sup) / s[p]; + else + a = (d[i] - sup) / s[p] + 1; + t += a * k; + sup += a * s[p]; + } + t += d[i]; + sup -= d[i]; + } + cout << t << endl; + return 0; +} +int main() { + int n; + cin >> n; + map m1; + map m2; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + if (m1.count(x)) + m1[x]++; + else + m1[x] = 1; + if (m2.count(y)) + m2[y]++; + else + m2[y] = 1; + } + cout << min(m1.size(), m2.size()) << "\n"; + return 0; +} +const int N = 1e5 + 5; +int x, y, arr[1005][1005] = {}; +bool solve(int st1, int st2) { + for (int z = st1; z <= st1 + 1; ++z) { + for (int v = st2; v <= st2 + 1; ++v) { + if (!arr[x + z][y + v]) return false; + } + } + return true; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + for (int i = 1; i <= k; ++i) { + cin >> x >> y; + arr[x][y] = 1; + for (int t = -1; t <= 0; ++t) { + for (int u = -1; u <= 0; ++u) { + if (solve(t, u)) return cout << i << "\n", 0; + } + } + } + return cout << 0 << "\n", 0; + return 0; +} +int main() { + int n, m, x, a; + bool b[105]; + memset(b, 0, sizeof b); + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> a; + b[a] = 1; + } + } + for (int i = 1; i <= m; i++) { + if (!b[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int bowl = 0, towl = n * p; + while (n > 1) { + int k = pow(2, (int)(log(n) / log(2))); + bowl += k / 2 * (2 * b + 1); + n -= k / 2; + } + cout << bowl << ' ' << towl << endl; + return 0; +} +int n, k, x; +int a[105]; +int main() { + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> a[i]; + long long sum = 0; + for (int i = 0; i < n - k; i++) sum += a[i]; + sum += k * x; + cout << sum << endl; + return 0; +} +int main() { + cout.setf(ios::fixed); + cout.precision(10); + int n; + cin >> n; + vector items(n); + for (int i = 0; i < n; i++) { + cin >> items[i]; + while (items[i] % 2 == 0) { items[i] = items[i] / 2; } + while (items[i] % 3 == 0) { items[i] = items[i] / 3; } + } + bool yes = true; + for (int i = 1; i < n; i++) { + if (items[i] != items[i - 1]) { + yes = false; + break; + } + } + if (yes) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + int pause; + cin >> pause; + return 0; +} +const double eps = 1e-10; +const double PI = 3.14159265358979323846264338; +int main() { + int n; + cin >> n; + int a, b; + int ansa = 0, ansb = 0; + for (int i = 0; i < n; i++) { + cin >> a; + ansa |= a; + } + for (int i = 0; i < n; i++) { + cin >> b; + ansb |= b; + } + cout << ansa + ansb << "\n"; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + cout << n / 2 / (k + 1) << ' '; + cout << n / 2 / (k + 1) * k << ' '; + cout << n - n / 2 / (k + 1) - n / 2 / (k + 1) * k << endl; + return 0; +} +int main() { + int n, a = 0, b = 0, c, i, x = 0, m; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> m; + cin >> c; + if (m > c) { a++; } + if (m < c) { b++; } + } + if (a > b) { cout << "Mishka" << endl; } + if (a < b) { cout << "Chris" << endl; } + if (a == b) { cout << "Friendship is magic!^^" << endl; } + return 0; +} +int main() { + float a, s, d, f, g; + int i, flag = 0; + cin >> a >> s >> d >> f >> g; + for (i = d; i <= f; i++) + if (i * g <= s && g * i >= a) { + flag = 1; + break; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int m, n; + cin >> m; + int q[m]; + for (int i = 0; i < m; i++) cin >> q[i]; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(q, q + m); + sort(a, a + n); + long long ans = 0, j = n - 1; + while (j >= 0) { + int temp = q[0]; + while (temp-- && j >= 0) { + ans += a[j]; + j--; + } + j -= 2; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, m, s, i, res; + while (cin >> n >> m) { + s = 1; + while (m--) { + s *= 2; + s %= 1000000009; + } + res = 1; + for (i = 1; i <= n; i++) { + res *= (s - i); + res %= 1000000009; + } + cout << res << endl; + } + return 0; +} +int n; +bool valid(int i, int j) { + return (i >= 0 && i < n && j >= 0 && j < n); +} +int main() { + cin >> n; + char a[1000][1000]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) a[i][j] = '*'; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int c = 0; + char o = 'o'; + if (a[i][j - 1] == o) c++; + if (a[i][j + 1] == o) c++; + if (a[i - 1][j] == o) c++; + if (a[i + 1][j] == o) c++; + if (c % 2 != 0) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + string bincode; + int output[8]; + string codes[10]; + string sub[10]; + cin >> bincode; + bool flag = true; + int c = 0; + for (int i = 0; i < 10; i++) cin >> codes[i]; + for (int i = 0; i < 80; i = i + 10) sub[c++] = bincode.substr(i, 10); + for (int i = 0; i < c; i++) { + flag = true; + for (int f = 0; f < 10 && flag; f++) + if (sub[i] == codes[f]) { + output[i] = f; + flag = false; + } + } + for (int i = 0; i < c; i++) cout << output[i]; + cout << endl; + return 0; +} +int main() { + int n, m, s = 0, i, flag = 0; + cin >> n >> m; + char a; + for (i = 0; i < n; i++) { + cin >> a; + if (a == 'G' || a == 'T') { + while (1) { + cin >> a; + s++; + if (s % m == 0) { + if (a == 'G' || a == 'T') { flag = 1; } + if (a == '#') break; + } + if (a == 'T' || a == 'G') break; + } + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const int N = 1e5 + 1; +int main() { + int m, d; + cin >> m >> d; + int x = 31; + if (m == 1) x = 31; + if (m == 2) x = 28; + if (m == 3) x = 31; + if (m == 4) x = 30; + if (m == 5) x = 31; + if (m == 6) x = 30; + if (m == 7) x = 31; + if (m == 8) x = 31; + if (m == 9) x = 30; + if (m == 10) x = 31; + if (m == 11) x = 30; + if (m == 12) x = 31; + x -= (8 - d); + cout << 1 + (x + 6) / 7 << endl; +} +int main() { + long long i, n, pow2[35], ans = 0; + cin >> n; + while (n) { + if (n & 1) ans += 1; + n /= 2; + } + cout << ans << endl; + return 0; +} +const int N = 100001; +vector g[N]; +int n, val[N]; +long long sum[N]; +bool dfs(int u, int p) { + if (g[u].size() == 1 && p != -1) { + if (sum[u] == -1) { + val[u] = 0; + sum[u] = sum[p]; + } else + val[u] = sum[u] - sum[p]; + return true; + } + if (sum[u] == -1) { + long long mn = 1e9; + for (int i = 0; i < g[u].size(); ++i) { + int v = g[u][i]; + if (v == p) continue; + long long diff = sum[v] - sum[p]; + if (diff < 0) return false; + mn = min(mn, diff); + } + val[u] = mn; + sum[u] = sum[p] + val[u]; + } else if (p != -1) + val[u] = sum[u] - sum[p]; + bool check = 1; + for (int i = 0; i < g[u].size(); ++i) { + int v = g[u][i]; + if (v == p) continue; + check = check && dfs(v, u); + } + return check; +} +int main() { + cin >> n; + for (int i = 0; i < n - 1; ++i) { + int p; + cin >> p; + --p; + g[p].push_back(i + 1); + g[i + 1].push_back(p); + } + for (int i = 0; i < n; ++i) cin >> sum[i]; + val[0] = sum[0]; + if (!dfs(0, -1)) + cout << -1 << endl; + else { + long long s = 0; + for (int i = 0; i < n; ++i) s += val[i]; + cout << s << endl; + } + return 0; +} +int main() { + int n, m, rm; + cin >> n >> m; + int tm = 60 * 4; + rm = tm - m; + for (int i = 1;; i++) { + if (i * 5 <= rm) { + if (i == n) { + cout << i << endl; + return 0; + } + rm = rm - (i * 5); + continue; + } else { + cout << i - 1 << endl; + return 0; + } + } + return 0; +} +const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 2e5 + 5, mod = 1e9 + 7; +int main() { + string x; + cin >> x; + int n; + cin >> n; + string arr[n]; + for (int c = 0; c < n; c++) { cin >> arr[c]; } + sort(arr, arr + n); + for (int c = 0; c < n; c++) { + bool flag = 1; + for (int i = 0; i < ((int)((x).size())); i++) { + if (i < ((int)((arr[c]).size())) && x[i] != arr[c][i]) flag = 0; + } + if (flag) return cout << arr[c] << "\n", 0; + } + cout << x << "\n"; + return 0; +} +const int N = 100100; +const long long mod = 1e9 + 7; +long long gcd(long long a, long long b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + string a, b; + string ans; + cin >> a >> b; + ans += a[0]; + for (long long i = 1; i < a.length(); i++) { + if (a[i] < b[0]) + ans += a[i]; + else + break; + } + ans += b[0]; + cout << ans << "\n"; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + for (int i = 0; i < k; i++) { + int ta, fa, tb, fb, ans = 0; + cin >> ta >> fa >> tb >> fb; + if (ta == tb) { + cout << abs(fa - fb) << endl; + continue; + } + int ff = fa; + if (fa > b or fa < a) { + ans += min(abs(fa - a), abs(fa - b)); + if (abs(fa - a) < abs(fa - b)) + ff = a; + else + ff = b; + } + ans += abs(ta - tb); + ans += abs(ff - fb); + cout << ans << endl; + } + return 0; +} +int main() { + int good[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n; + cin >> n; + int ans = good[n % 10] * good[n / 10]; + cout << ans << endl; + return 0; +} +char Names[6][15] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +void DeleteIt(int x) { + strcpy(Names[x], " "); + return; +} +int main() { + int n, i; + cin >> n; + if (n != 0) { + char Colours[n][10]; + for (i = 0; i < n; i++) cin >> Colours[i]; + for (i = 0; i < n; i++) { + if (strcmp(Colours[i], "purple") == 0) { + DeleteIt(0); + continue; + } + if (strcmp(Colours[i], "green") == 0) { + DeleteIt(1); + continue; + } + if (strcmp(Colours[i], "blue") == 0) { + DeleteIt(2); + continue; + } + if (strcmp(Colours[i], "orange") == 0) { + DeleteIt(3); + continue; + } + if (strcmp(Colours[i], "red") == 0) { + DeleteIt(4); + continue; + } + if (strcmp(Colours[i], "yellow") == 0) { + DeleteIt(5); + continue; + } + } + } + cout << 6 - n << endl; + for (i = 0; i < 6; i++) { + if (strcmp(Names[i], " ") == 0) continue; + cout << Names[i] << endl; + } + return 0; +} +int main() { + long long int k, l, m, o, n, max(0), min(0); + cin >> o; + for (int i = 0; i < o; i++) { + cin >> n; + if (max < n) { max = n; } + if (i == 0) { min = n; } + if (min > n) { min = n; } + } + k = (max - min) / 2; + cout << max - k << endl; +} +int main() { + long long int n, m, maxm = INT_MIN, sum = 0; + cin >> n >> m; + vector vec(n, 0); + for (long long int i = 0; i < n; i++) { + cin >> vec[i]; + maxm = max(maxm, vec[i]); + sum += vec[i]; + } + sum += m; + cout << max(maxm, (long long int)ceil((long double)sum / n)) << " "; + cout << maxm + m << endl; +} +int main() { + long long int ans = 0, x, s, dp0 = 1, dp1 = 0, a, b; + cin >> s >> x; + if (x == 0 && s % 2 == 0) { + cout << 1 << endl; + return 0; + } + if (s == x) ans -= 2; + if (x > s) { + cout << 0 << endl; + return 0; + } + while (s) { + a = s % 2; + b = x % 2; + s /= 2; + x /= 2; + if (a == b) { + if (a == 0) { + dp0 = dp0; + dp1 = dp0; + } else { + dp0 = 2 * dp0; + dp1 = 0; + } + } else { + if (b == 0) { + dp0 = dp1; + dp1 = dp1; + } else { + dp0 = 0; + dp1 = 2 * dp1; + } + } + } + if (!dp0) + cout << 0 << endl; + else + cout << ans + dp0 << endl; +} +int main() { + int n, k, temp = 0, l, m; + cin >> n >> k; + string s; + cin >> s; + int c = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'G') { + l = i; + } else if (s[i] == 'T') { + m = i; + } + } + if (l < m) { + for (int i = l; i <= m; i += k) { + if (s[i] != '#') { + c++; + } else if (s[i] == 'T') { + c++; + break; + } else if (s[i] == '#') { + break; + } else { + c++; + continue; + } + } + } else if (l > m) { + for (int i = l; i >= m; i -= k) { + if (s[i] != '#') { + c++; + } else if (s[i] == 'T') { + c++; + break; + } else if (s[i] == '#') { + break; + } else { + c++; + continue; + } + } + } + int answer = (c - 1) * k; + int hap = abs(l - m); + if (answer == hap) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +const int N = 1e5 + 5; +int ans = 0; +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + for (int i = 1; i <= 100000; i++) { + ans++; + if (b) { + int taka = min(b, k - 1); + a -= (taka + 1) * v; + b -= taka; + } else { + a -= v; + } + if (a <= 0) break; + } + cout << ans << "\n"; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + float n = 360.0 / (180 - x); + if (floor(n) == n) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + int n; + string str; + cin >> n >> str; + for (int i = 1; i < n; i++) { + if (str[i] != str[i - 1]) { + cout << "YES" << endl; + cout << str[i - 1] << str[i] << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + long long l, r; + cin >> l >> r; + if (r - l + 1 < 3) { + cout << -1 << endl; + return 0; + } + if (r - l + 1 == 3 && (r % 2 != 0 || l % 2 != 0)) { + cout << -1 << endl; + return 0; + } + if (l % 2 == 0 && (l + 2) % 2 == 0) + cout << l << " " << l + 1 << " " << l + 2 << endl; + else + cout << l + 1 << " " << l + 2 << " " << l + 3 << endl; +} +int main() { + int n1, n2, r; + cin >> n1 >> n2 >> r; + int r2 = r + r; + if (n1 >= r2 && n2 >= r2) + cout << "First\n"; + else + cout << "Second\n"; + return 0; +} +int main() { + int n; + int a; + int b; + vector complexity; + cin >> n >> a >> b; + int i = 0; + for (; i < n; i++) { + int tmp; + cin >> tmp; + complexity.push_back(tmp); + } + sort(complexity.begin(), complexity.end()); + int cnt = 0; + for (i = complexity[b - 1]; i < complexity[b]; i++) { cnt++; } + cout << cnt << endl; +} +int main() { + int n; + for (int i = 1; i <= 5; ++i) { + for (int j = 1; j <= 5; ++j) { + cin >> n; + if (n == 1) { cout << abs(3 - i) + abs(3 - j) << endl; } + } + } +} +int main() { + string a, b; + cin >> a >> b; + cout << (a == b ? a : "1") << endl; + return 0; +} +int temp, A; +int main() { + int B; + cin >> B; + for (int a = 0; a < B; a++) { + cin >> A; + if (a == B - 2) temp = A; + } + if (A == 15) + cout << "DOWN\n"; + else if (A == 0) + cout << "UP\n"; + else if (B == 1) + cout << "-1\n"; + else if (A > temp) + cout << "UP\n"; + else if (A < temp) + cout << "DOWN\n"; +} +int main() { + int n, m, i, j, flag; + cin >> n >> m; + if (m % 2 == 0) + cout << "NO" << endl; + else if (n == 2 && m == 3) + cout << "YES" << endl; + else { + for (j = n + 2; j <= m; j = j + 2) { + flag = 0; + for (i = 3; i <= j / 2; i++) { + if (j % i == 0) { + flag = 1; + break; + } + } + if (i == j / 2 + 1 && j == m && flag == 0) { + cout << "YES" << endl; + break; + } else if (i == j / 2 + 1 && flag == 0 && j != m) { + cout << "NO" << endl; + break; + } + } + if (flag == 1) cout << "NO" << endl; + } + return 0; +} +long long dm(long long x, long long y, long long z, long long l) { + long long res = 0, now = 0; + for (long long i = max((long long)0, x + y - z); i <= l; i++) { + now = min(l - i, z + i - x - y); + res += (now + 1) * (now + 2) / 2; + } + return res; +} +int main() { + long long a, b, c, l; + unsigned long long ans = 1; + cin >> a >> b >> c >> l; + for (long long i = 1; i <= l; i++) ans += (i + 1) * (i + 2) / 2; + ans -= dm(a, b, c, l); + ans -= dm(a, c, b, l); + ans -= dm(b, c, a, l); + cout << ans << endl; + return 0; +} +int main() { + int N, K; + cin >> N >> K; + int *numbers = new int[N]; + for (int i = 0; i < N; i++) { cin >> numbers[i]; } + int big = -1; + for (int i = 0; i < N; i++) { + if (K % numbers[i] == 0) { + if (numbers[i] > big) { big = numbers[i]; } + } + } + cout << K / big << endl; +} +int main() { + int n; + cin >> n; + string word; + for (int i = 0; i < n; i++) { + cin >> word; + if (word.size() > 10) + cout << word[0] << word.size() - 2 << word[word.size() - 1] << endl; + else + cout << word << endl; + } +} +int main() { + string s; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int r; + cin >> s; + r = s.size() - 1; + if (s.size() > 10) + cout << s[0] << s.size() - 2 << s[r] << endl; + else + cout << s << endl; + } + return 0; +} +map M; +long long solve(long long u, long long v, long long w = -1) { + long long res = 0; + while (u != v) { + if (v < u) swap(u, v); + if (w == -1) + res += M[v]; + else + M[v] += w; + v /= 2; + } + return res; +} +int main() { + long long u, v, w, q, t; + cin >> q; + while (cin >> t >> u >> v, q--) { + if (t == 2) + cout << solve(u, v) << '\n'; + else + cin >> w, solve(u, v, w); + } +} +int debug = 1; +const int mod = 1e9 + 7; +bool is_big(char a) { + if (a >= 'A' and a <= 'Z') return true; + return false; +} +void solve() { + int n; + cin >> n; + string str; + getline(cin, str); + getline(cin, str); + int maxx = 0, now = 0; + for (int i = 0; i < (int)str.length(); i++) { + if (str[i] == 32) { + maxx = max(maxx, now); + now = 0; + } + if (is_big(str[i])) { now++; } + } + maxx = max(maxx, now); + cout << maxx << endl; +} +int main() { + int t = 1; + while (t--) solve(); +} +const int INF = 2000000000; +const double EPS = 1e-9; +int main() { + int n, c, num, prev = 0, words = 0; + cin >> n >> c; + for (int i = 0; i < n; i++) { + cin >> num; + if (num - prev <= c) + words++; + else + words = 1; + prev = num; + } + cout << words << '\n'; +} +int main() { + int n; + int sum = 0; + cin >> n; + for (int i = 0; i <= n - 1; i++) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + sum += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long x = (long long)floor(sqrt(2 * n + 0.25) - 0.5); + if (x * x + x == 2 * n) { + cout << x << endl; + } else { + cout << n - (x * x + x) / 2 << endl; + } + return 0; +} +int main() { + string A = "abcdefghijklmnopqrstuvwxyz"; + string word; + cin >> word; + int position = 0; + int x = 0; + int y = 0; + int sum = 0; + for (int i = 0; i < word.length(); i++) { + int ch = A.find(word[i]); + x = abs(position - ch); + y = 26 - x; + if (x < y) { + sum = sum + x; + } else { + sum = sum + y; + } + position = ch; + } + cout << sum << endl; + return 0; +} +long long int fact(long int x) { + if (x == 0 || x == 1) return 1; + return x * fact(x - 1); +} +int main() { + long int a, b; + cin >> a; + cin >> b; + if (a > b) { + cout << fact(b) << "\n"; + } else { + cout << fact(a) << "\n"; + } + return 0; +} +int main() { + int m, n; + cin >> m; + vector disc(m); + for (int i = 0; i < m; i++) cin >> disc[i]; + cin >> n; + vector cost(n); + for (int i = 0; i < n; i++) cin >> cost[i]; + sort(disc.begin(), disc.end()); + sort(cost.begin(), cost.end()); + long long int ans = 0; + int i = n - 1; + while (i >= 0) { + for (int j = max(0ll, i - disc[0] + 1); j <= i; j++) ans += cost[j]; + i -= disc[0] + 2; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int x = 0; + int k = -1; + int m = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n + 1; j++) { + m = 0; + if (j == n + 1) { + cout << endl; + break; + } + for (int k = n / 2 - x + 1; k <= n / 2 + x + 1; k++) { + if (j == k) { m++; } + } + if (m == 0) { + cout << '*'; + } else { + cout << 'D'; + } + } + if (i <= n / 2) { + x += 1; + } else { + x -= 1; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a = 1; + for (int i = 1; i < n; i++) { a = (a * 3) % 1000003; } + cout << a << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[26] = {0}; + char c[305][305]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> c[i][j]; + a[c[i][j] - 'a'] = 1; + } + } + int sum = 0; + for (int i = 0; i < 26; i++) { sum += a[i]; } + if (sum != 2) { + cout << "NO" << endl; + return 0; + } else { + char s = c[0][0]; + char o = c[0][1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j == i || j == (n - i - 1)) { + if (c[i][j] != s) { + cout << "NO" << endl; + return 0; + } + } else { + if (c[i][j] != o) { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + } +} +vector adj[(int)1e5 + 6]; +bool solve(int node) { + queue que; + que.push(0); + while (que.size()) { + int cur = que.front(); + if (cur == node) return true; + que.pop(); + for (int i = 0; i < adj[cur].size(); ++i) { que.push(adj[cur][i]); } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + k -= 1; + int arr[n]; + for (int i = 0; i < n - 1; ++i) { cin >> arr[i]; } + for (int i = 0; i < n - 1; ++i) { adj[i].push_back(i + arr[i]); } + bool ans = solve(k); + if (ans) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, m; +int b[200007]; +int a[200007], c[200007]; +vector v; +int main() { + int i, j, l, h, t = 0; + string s, s1, s2, s3; + long long RE, DE, HE; + cin >> RE >> DE >> HE; + while (DE * HE < RE) { + t++; + DE *= HE; + } + cout << t + 1 << endl; + return 0; +} +int main() { + long long int x, y, m, x1, y1; + cin >> x >> y >> m; + unsigned long long int num = 0; + while (1) { + x1 = x; + y1 = y; + if (max(x, y) >= m) { + cout << num << endl; + return 0; + } + if (x > 0 && y < 0) { + unsigned long long int n = fabs(y) / x; + long long int xx = y; + while (y < 0) { + y = xx + x * n; + n++; + } + num = num + n - 1; + continue; + } else if (y > 0 && x < 0) { + unsigned long long int n = fabs(x) / y; + long long int xx = x; + while (x < 0) { + x = xx + y * n; + n++; + } + num = num + n - 1; + continue; + } else if (x < y) { + x = x + y; + num++; + } else { + y = x + y; + num++; + } + if ((x + y) <= (x1 + y1)) { + x = -1; + cout << x << endl; + return 0; + } + } +} +long long a[100005]; +int main() { + int n; + while (cin >> n) { + memset(a, 0, sizeof(a)); + long long ji = 0, ou = 0; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 == 0) ou++; + if (a[i] % 2 != 0) ji++; + sum += a[i]; + } + sort(a, a + n); + bool flag = false; + if (ji % 2 == 0) { + cout << sum << endl; + } else { + for (int i = 0; i < n; i++) { + if (a[i] % 2 != 0 && flag == false) { + flag = true; + sum -= a[i]; + } + } + cout << sum << endl; + } + } +} +int main() { + string s; + int ev_no = 0; + cin >> s; + int i = 0; + while (i < s.length()) { + int j = i + 1; + int k = 1; + while (s[i] == s[j]) { + k++; + j++; + } + if (k % 2 == 0) ev_no++; + i = j; + } + cout << ev_no << endl; + return 0; +} +int main() { + int n, sum = 0, ans = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + sort(arr, arr + n); + for (int i = 0; i < n - 1; i++) { ans += -arr[i] + arr[n - 1]; } + while (1) { + if (ans > sum) { break; } + ans += n; + arr[n - 1]++; + } + cout << arr[n - 1] << endl; +} +int n; +int computer[201], check[3][201], vis[201]; +vector vv[201]; +int bfs(int num, int st) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (check[num][i] == 0) q.push(i); + } + while (!q.empty()) { + memset(vis, 0, sizeof(vis)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (vis[head] == n) { + q.push(head); + break; + } + vis[head]++; + if (computer[head] != st) { + q.push(head); + continue; + } + for (int i = 0; i < vv[head].size(); i++) { + check[num][vv[head][i]]--; + if (check[num][vv[head][i]] == 0) q.push(vv[head][i]); + } + } + st = (st == 3 ? 1 : st + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(check, 0, sizeof(check)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + check[0][i]++, check[1][i]++, check[2][i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= 3; i++) ans = min(ans, bfs(i - 1, i)); + cout << ans << endl; + } + return 0; +} +int main() { + int n, s = 0, mys = 0, cpt = 0; + cin >> n; + int ai[n]; + for (int i = 0; i < n; i++) { + cin >> ai[i]; + s += ai[i]; + } + sort(ai, ai + n); + for (int i = n - 1; i >= 0; i--) { + if (mys > s / 2) + break; + else { + cpt++; + mys += ai[i]; + } + } + cout << cpt << endl; + return 0; +} +string n, n2; +bool compare(string s1, string s2, int length) { + for (int i = 0; i < length; i++) { + if (s1[i] != s2[i]) { return false; } + } + return true; +} +int main() { + cin >> n >> n2; + int l1, l2, greater; + l1 = greater = n.length(); + l2 = n2.length(); + if (l2 > l1) { greater = l2; } + if (l1 == l2) { + bool x = compare(n, n2, l1); + if (x) { + cout << -1 << endl; + return 0; + } else { + cout << l1 << endl; + return 0; + } + } + cout << greater << endl; + return 0; +} +long long int k = 0, n = 0, c = 0, b = 0, l, r, m; +string s; +bool turimi(long long int n, long long int k) { + long long int c = 0, r = 0; + while (n) { + if (n % 2) c++; + n /= 2; + } + return c <= k; +} +int main() { + cin >> n >> m; + while (n--) { + cin >> s; + r = count(s.begin(), s.end(), '4'); + r += count(s.begin(), s.end(), '7'); + if (r <= m) c++; + } + cout << c << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[10], s[10], t = 0, c; + for (int i = 1; i <= 3; i++) { + cin >> s[i] >> a[i]; + t += s[i]; + } + c = n - t; + if (c <= a[1] - s[1]) + cout << c + s[1] << " " << s[2] << " " << s[3] << endl; + else { + c -= a[1] - s[1]; + if (c <= a[2] - s[2]) + cout << a[1] << " " << s[2] + c << " " << s[3] << endl; + else { + c -= a[2] - s[2]; + cout << a[1] << " " << a[2] << " " << s[3] + c << endl; + } + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 && m > 0) + cout << "Impossible" << endl; + else + cout << n + m - min(n, m) << " " << n + max(m - 1, 0) << endl; + return 0; +} +int main() { + int n, k, x; + int a[105]; + while (cin >> n >> k >> x) { + int i = 0; + int sum = 0; + for (i; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + sum += k * x; + sort(a, a + n); + for (i = 1; i <= k; i++) { sum -= a[n - i]; } + cout << sum << endl; + } + return 0; +} +int main() { + int a, b, i, j = 0, c = 0, n, p = 0, q = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a >> b; + p = p + a; + q = q + b; + c = q - p; + if (c > j) { j = c; } + } + cout << j << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector factors; + for (int i = 2; i * i <= n; i++) { + while (n % i == 0) { + factors.push_back(i); + n /= i; + } + } + if (n > 1) factors.push_back(n); + if (factors.size() < k) { + cout << -1 << endl; + } else { + for (int i = 0; i < k - 1; i++) { cout << factors[i] << " "; } + long long int rest = 1; + for (int i = k - 1; i < factors.size(); i++) rest *= factors[i]; + cout << rest << endl; + } +} +int read() { + int x = 0; + char c = getchar(); + while (!isdigit(c)) c = getchar(); + while (isdigit(c)) { + x = (x << 1) + (x << 3) + c - '0'; + c = getchar(); + } + return x; +} +int m, n; +int main() { + n = read(), m = read(); + int t; + for (register int i = 1; i <= n; i++) + for (register int j = 1; j <= m; j++) { + t = read(); + if ((i == 1 || i == n || j == 1 || j == m) && t) { + puts("2"); + return 0; + } + } + puts("4"); + return 0; +} +int main() { + int n, k, i, A[110], c = 0; + cin >> n >> k; + for (i = 1; i <= n; i++) { cin >> A[i]; } + for (i = 1; i <= n; i++) { + if (A[i] >= A[k] && A[i] > 0) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int a, b, c, min; + cin >> a >> b >> c; + min = ceil(((a - b) * c * 1.0) / b); + cout << min << endl; + return 0; +} +int main() { + int a; + cin >> a; + string z; + map asd; + map dsa; + cin >> z; + cin.ignore(); + while (a--) { + string x, c; + getline(cin, x); + int s = x.size(); + c = ""; + for (int q = 0; q < 3; q++) { c += x[q]; } + if (c != z) { + dsa[c]++; + } else { + c = ""; + for (int q = 5; q < 8; q++) { c += x[q]; } + asd[c]++; + } + } + map::iterator it; + bool cek = false; + for (it = asd.begin(); it != asd.end(); it++) { + if (dsa[it->first] != asd[it->first]) cek = true; + } + if (cek == true) { + cout << "contest" << endl; + } else + cout << "home" << endl; +} +int n, num, ans; +string str; +int main() { + cin >> str; + cin >> n; + if (str.size() < n) { + cout << "impossible\n"; + return 0; + } + for (int i = 0; i < 26; i++) { + if (str.find('a' + i) != -1) num++; + } + cout << max(n - num, 0) << "\n"; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +int s[1001], n, m, a, minn = 1000; +int main() { + memset(s, 0, sizeof(s)); + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> a; + s[a]++; + } + for (int i = 1; i <= n; i++) + if (s[i] < minn) minn = s[i]; + cout << minn << endl; + return 0; +} +inline long long read() { + char ch = getchar(); + long long x = 0, f = 1; + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +inline void print(long long k) { + if (k < 0) k = -k, putchar('-'); + if (k > 9) print(k / 10); + putchar(k % 10 + 48); +} +inline void println(long long k) { + print(k); + putchar('\n'); +} +inline void printsp(long long k) { + print(k); + putchar(' '); +} +int main() { + long long s = read(), x = read(); + long long sum = (s - x) >> 1; + if (x > s || (sum * 2 + x) != s || sum < 0 || (x & sum) != 0) { + println(0); + return 0; + } + long long cnt = 0; + while (x) { + if (x & 1) ++cnt; + x >>= 1; + } + long long ans = 1LL << cnt; + if (!sum) ans -= 2; + println(ans); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector arr(n, 0); + int total = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + total += arr[i]; + } + int _min = max(1 + (total + m - 1) / n, *max_element(arr.begin(), arr.end())); + int _max = *max_element(arr.begin(), arr.end()) + m; + cout << _min << " " << _max << endl; + return 0; +} +int n, m, test; +int main() { + int k, a, b, v; + int ans = 0; + cin >> k >> a >> b >> v; + while (a >= 1) { + int section = 1; + ans++; + if (b > 0) { + if (k >= b + 1) { + section = b + 1; + b = 0; + } else { + b -= (k - 1); + section = k; + } + } + a -= section * v; + } + cout << ans << endl; +} +int main() { + int n, x, a = 0; + cin >> n >> x; + for (int i = 0, k = 0; i < n; i++) { + cin >> k; + a += k; + } + a = abs(a); + cout << a / x + (a % x ? 1 : 0) << endl; +} +int a, b; +bool ok(int j) { + if (j != a && j != 7 - a && j != b && j != 7 - b) return true; + return false; +} +int main() { + int n, top, i, j, f = 0, res = 1; + cin >> n; + cin >> top; + top = 7 - top; + for (i = 0; i < n; i++) { + cin >> a >> b; + for (j = 1; j <= 6; j++) { + if (ok(j)) { + if (j == top) { + top = 7 - j; + f = 1; + } + } + } + if (!f) { res = 0; } + f = 0; + } + if (res) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long a[1000000 + 100], flag[1000000 + 100]; +const long long mod = 1e9 + 7; +long long dp[1007 + 1][1007 + 1]; +int main() { + for (int i = 0; i < 1007; i++) dp[i][0] = 1; + for (int i = 1; i < 1007; i++) + for (int j = 1; j < 1007; j++) dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; + int k; + cin >> k; + long long sum = 1; + long long x = 1; + for (int i = 0; i < k; i++) { + cin >> a[i]; + sum = (sum * dp[x][a[i] - 1]) % mod; + x += a[i]; + } + cout << sum << endl; + return 0; +} +int main() { + int x; + while (cin >> x) { + if (x % 5 == 0) + cout << x / 5 << endl; + else + cout << x / 5 + 1 << endl; + } +} +int main() { + int n; + string s; + cin >> n >> s; + int ans = 0; + int cnt = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + cnt++; + } else { + cout << cnt; + cnt = 0; + } + } + cout << cnt << endl; + return 0; +} +string S, T; +long long N, M, A[105], B[105], sum = 2e9, x, y, K; +bool cek; +int main() { + cin >> N >> M; + for (int i = 1; i <= N; i++) { cin >> A[i]; } + for (int i = 1; i <= M; i++) { cin >> B[i]; } + sort(B + 1, B + M + 1); + for (int i = N; i >= 1; i--) { + if (!A[i]) { + A[i] = B[x + 1]; + x++; + } + } + for (int i = 1; i < N; i++) { + if (A[i + 1] < A[i]) cek = 1; + } + if (cek) + cout << "Yes\n"; + else + cout << "No\n"; +} +int main() { + long long n; + cin >> n; + cout << (n % 2 == 1 ? 1 : 2) << endl; + return 0; +} +int main() { + int n; + cin >> n; + set data; + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + if (input != 0) data.insert(input); + } + cout << data.size() << endl; + return 0; +} +string str; +int main() { + cin >> str; + int s = 0, c = str.size(); + for (int i = 0; i < str.size(); i++) s += str[i] >= 'a'; + c -= s; + if (c > s) { + for (int i = 0; i < str.size(); i++) + if (str[i] >= 'a') str[i] = toupper(str[i]); + } else + for (int i = 0; i < str.size(); i++) + if (str[i] < 'a') str[i] = tolower(str[i]); + cout << str << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +char s[1005]; +int main() { + int i, j, k; + int n, m; + cin >> s; + int cou = 0, co = 0; + for (i = 0; i < strlen(s); i++) { + if (s[i] == 'o') + cou++; + else + co++; + } + if (cou == 0) { + cout << "YES" << endl; + return 0; + } + if (co < cou && co > 0) + cout << "NO" << endl; + else { + if (co % cou == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + long long int l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (long long i = x; i <= y; i++) { + if (i * k >= l && i * k <= r) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +string s; +int ans = 0; +int i = 0; +int main() { + cin >> s; + if (s.size() == 1) { + cout << "YES" << endl; + return 0; + } + for (int j = s.size() - 1; j >= s.size() / 2; j--) { + if (s[i] != s[j]) { + for (char c = 'a'; c <= 'z'; c++) { + if (c == s[i] || c == s[j]) { + ans++; + break; + } + } + } + i = i + 1; + } + if (s.size() % 2 == 0) { + if (ans == 0 || ans > 1) { + cout << "NO" << endl; + return 0; + } + } + if (ans > 1) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, count, minMatch; + cin >> n; + string txt; + string cpy; + for (int i = 0; i < n; i++) { + cin >> txt; + if (i == 0) { + cpy = txt; + minMatch = txt.size() + 1; + } else { + count = 0; + for (int j = 0; j < txt.size(); j++) { + if (cpy[j] == txt[j]) + count++; + else + break; + } + minMatch = min(count, minMatch); + cpy = txt; + } + } + cout << minMatch << "\n"; + return 0; +} +const int inf = 0x3f3f3f3f; +int main() { + string str; + cin >> str; + int len = str.length(); + int ans = 0; + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { + for (int k = j + 1; k < len; k++) { + if (str[i] == 'Q' && str[j] == 'A' && str[k] == 'Q') { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int k, a[12], sm = 0; + cin >> k; + if (sm >= k) { + cout << 0 << endl; + return 0; + } + for (int i = 0; i < 12; ++i) { cin >> a[i]; } + sort(a, a + 12); + for (int i = 0; i < 12; ++i) { + sm += a[11 - i]; + if (sm >= k) { + cout << (i + 1) << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n, c = 0; + cin >> n; + int a[n + 2]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 1; i < n - 1; i++) { + if (a[i] < a[i - 1] && a[i] < a[i + 1]) { + c++; + } else if (a[i] > a[i - 1] && a[i] > a[i + 1]) { + c++; + } + } + cout << c << endl; +} +const long long N = 1e9 + 7; +int main() { + long long t, a; + cin >> t; + while (t--) { + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES"; + else + cout << "NO"; + cout << "\n"; + } + return 0; +} +int main() { + map mp; + mp["ABSINTH"] = mp["BEER"] = mp["BRANDY"] = mp["CHAMPAGNE"] = 1; + mp["GIN"] = mp["RUM"] = mp["SAKE"] = mp["TEQUILA"] = mp["VODKA"] = 1; + mp["WHISKEY"] = mp["WINE"] = 1; + int n; + cin >> n; + int cnt = 0; + while (n--) { + string s; + cin >> s; + if (mp[s]) + cnt++; + else if (s[0] >= '0' && s[0] <= '9') { + stringstream geek(s); + int x = 0; + geek >> x; + if (x < 18) cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + string pre[5]; + while (cin >> s) { + cin >> pre[0] >> pre[1] >> pre[2] >> pre[3] >> pre[4]; + int flag = 0; + for (int i = 0; i < 5; i++) { + if (pre[i][0] == s[0] || pre[i][1] == s[1]) { + flag = 1; + break; + } + } + if (flag) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +long long x, y, z, k; +int main() { + cin >> x >> y >> z >> k; + while (x + y + z - 3 > k) { + if (x > y && x > z) + x--; + else if (y > z) + y--; + else + z--; + } + cout << x * y * z << endl; +} +int a[55]; +int main() { + int n; + cin >> n; + int i; + for (i = 1; i <= n / 2; i++) { cin >> a[i]; } + sort(a + 1, a + n / 2 + 1); + int ansj = 0, anso = 0; + for (i = 1; i <= n / 2; i++) { + if (a[i] == 1 + 2 * (i - 1)) + continue; + else { + int temp = abs(a[i] - (1 + 2 * (i - 1))); + ansj = ansj + temp; + } + } + for (i = 1; i <= n / 2; i++) { + if (a[i] == 2 * i) + continue; + else { + int temp = abs(a[i] - 2 * i); + anso = anso + temp; + } + } + cout << (ansj < anso ? ansj : anso) << endl; + return 0; +} +int main() { + int n, r = 1; + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cin >> n; + while (n > r * 5) { + n -= r * 5; + r *= 2; + } + cout << names[(n - 1) / r] << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int gcd = __gcd(n, m); + int lcm = (n * m) / gcd; + int ans = z / lcm; + cout << ans << endl; + return 0; +} +int main() { + long long n, k, x, y, counter = 0; + long long num = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> x >> y; + num += (y - x + 1); + } + if (num % k != 0) { + int mod = num % k; + counter = k - mod; + } + cout << counter << endl; +} +long long nod(int, int); +long long nok(int, int); +int main() { + int a, b, c, d; + cin >> a >> b; + if (a < b) { + c = nok(a, b) / a - 1; + d = nok(a, b) / b; + } else { + d = nok(a, b) / b - 1; + c = nok(a, b) / a; + } + if (c > d) + cout << "Dasha" << endl; + else { + if (c < d) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + } +} +long long nod(int a, int b) { + while (b) { + a %= b; + swap(a, b); + } + return a; +} +long long nok(int x, int y) { + return (x / nod(x, y) * y); +} +int a[4005], d[4005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + d[1] = a[1]; + int len = 1; + for (int i = 2; i <= n; i++) { + if (a[i] >= d[len]) + d[++len] = a[i]; + else { + int j = upper_bound(d + 1, d + len + 1, a[i]) - d; + d[j] = a[i]; + } + } + cout << len << endl; + return 0; +} +int main() { + string s; + cin >> s; + int count = 0, l = s.size() - 1; + for (int i = 0; i < s.size() / 2; i++) { + if (s[i] != s[l - i]) { count++; } + } + if (count == 1) { + cout << "YES" << endl; + } else if (s.size() % 2 == 1 && count == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int a[105]; +int b[105]; +int main() { + int n, c = 0, x = 0; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] > b[i]) + c++; + else if (a[i] < b[i]) + x++; + else if (a[i] = b[i]) { + c = c; + x = x; + } + } + if (c > x) { + cout << "Mishka" << endl; + } else if (x > c) { + cout << "Chris" << endl; + } else if (c == x) { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int ans; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (isalpha(s[i])) { + if (s[i] == 'a' || s[i] == 'e' || s[i] == 'o' || s[i] == 'i' || s[i] == 'u') ans++; + } else if (s[i] % 2 != 0) + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + long long int total; + cin >> n >> total; + int distressed = 0; + for (int i = 0; i < n; i++) { + char sign; + int x; + cin >> sign >> x; + if (sign == '+') { + total += x; + } else { + if (total - x < 0) { + distressed++; + } else { + total -= x; + } + } + } + cout << total << " " << distressed << endl; + return 0; +} +const int mod = 1e6 + 3; +const int N = 1e6 + 3; +const int inf = 0x3f3f3f3f; +char a[N], b[N]; +int main() { + int numa = 0, numb = 0; + char c; + c = getchar(); + bool start = 0; + while (c != '\n') { + if (c != '0') { + a[numa++] = c; + start = 1; + } else if (start) + a[numa++] = c; + c = getchar(); + } + c = getchar(); + start = 0; + while (c != '\n') { + if (c != '0') { + b[numb++] = c; + start = 1; + } else if (start) + b[numb++] = c; + c = getchar(); + } + if (numa > numb) + cout << ">\n"; + else if (numa < numb) + cout << "<\n"; + else { + for (int i = 0; i < numa; i++) + if (a[i] > b[i]) { + cout << ">\n"; + return 0; + } else if (b[i] > a[i]) { + cout << "<\n"; + return 0; + } + cout << "=\n"; + } + return 0; +} +string n; +int main() { + int n, k; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + if (360 % (180 - k) == 0) + cout << "YES"; + else + cout << "NO"; + cout << "\n"; + } +} +int main() { + int a, b; + cin >> a >> b; + int x = 3 * a; + if (x <= b) + cout << "0" << endl; + else + cout << x - b << endl; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + n = n - 1; + if (n == 0) { + cout << 0 << endl; + return 0; + } + int m = min(a, min(b, c)); + if (m == a) + cout << n * a << endl; + else if (m == b) + cout << n * b << endl; + else + cout << min(a, b) + (n - 1) * c << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + m -= 86400 - t; + if (m <= 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int a[1024][1024], b[1024], ans; +int main() { + int n, m; + memset(a, 0, sizeof(a)); + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> b[i]; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + a[u - 1][v - 1] = 1; + a[v - 1][u - 1] = 1; + } + ans = 1e9 + 10; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + for (int k = 0; k < n; k++) { + if (i == j || j == k || i == k || !a[i][j] || !a[j][k] || !a[k][i]) continue; + ans = min(ans, b[i] + b[j] + b[k]); + } + } + } + if (ans < 1e9 + 10) + cout << ans << endl; + else + cout << "-1" << endl; + return 0; +} +int i1, i2; +char c1, c2; +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + for (int i = 0; i < m; i++) { + cin >> i1 >> i2; + cin >> c1 >> c2; + for (int i = i1 - 1; i <= i2 - 1; i++) { + if (s[i] == c1) s[i] = c2; + } + } + cout << s << endl; + return 0; +} +char mp[2][2001][2001]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> mp[0][i]; + for (int i = 0; i < m; i++) cin >> mp[1][i]; + for (int i = 0; i <= n - m; i++) { + for (int j = 0; j <= n - m; j++) { + int ok = 1; + for (int p = 0; p < m && ok == 1; p++) { ok &= !memcmp(&mp[0][i + p][0], &mp[1][p][j], m); } + if (ok) { + cout << i + 1 << ' ' << j + 1 << endl; + return 0; + } + } + } + return 0; +} +const int maxn = 200100; +long long n; +int main() { + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; + return 0; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +int q, n, i; +string s; +int main() { + cin >> q; + while (q--) { + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl << "2" << endl << s[0] << " "; + for (i = 1; i < n; i++) cout << s[i]; + cout << endl; + } + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + map mp; + for (int i = 0; i < m; i++) { + char mx = '0'; + for (int j = 0; j < n; j++) { mx = max(mx, a[j][i]); } + mp[i] = mx; + } + int students = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == mp[j]) { + students++; + break; + } + } + } + cout << students << endl; +} +int main() { + int m, n; + cin >> n >> m; + (min(m, n) % 2) ? (cout << "Akshat\n") : (cout << "Malvika\n"); +} +int main() { + int arr[11][11], n; + for (int i = 0; i < 11; i++) { arr[0][i] = 1; } + for (int i = 1; i < 11; i++) { + arr[i][0] = 1; + for (int j = 1; j < 11; j++) { arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; } + } + while (cin >> n) { cout << arr[n - 1][n - 1] << endl; } + return 0; +} +int main() { + int a[50], b, t, d, s = 0, c = 0, k = 0, l, n = 0, i, count = 0; + cin >> t; + for (i = 0; i < t; i++) { + cin >> a[i]; + if (i % 3 == 0) { + s += a[i]; + } else if (i % 3 == 1) { + c += a[i]; + } else { + k += a[i]; + } + } + if (s > c && s > k) { + cout << "chest" << endl; + } else if (c > s && c > k) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long x = n / (2 * k + 2); + cout << x << " " << k * x << " " << n - (k + 1) * x << endl; + return 0; +} +int main() { + int n, i, j; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + j = 1; + long long int ans = 0; + for (i = 0; i < n; i++) { + if (i != n - 1) j++; + ans += (a[i] * j); + } + cout << ans << endl; + return 0; +} +int main() { + int T; + cin >> T; + long long s, a, b, c, k, free; + while (T--) { + cin >> s >> a >> b >> c; + k = s / c; + free = (k / a) * b; + cout << k + free << "\n"; + } + return 0; +} +bool esPosible(int a, int b) { + if (a == 0 && b == 0) return false; + if (a - b > 1) return false; + if (b - a > 1) return false; + return true; +} +int main() { + int a, b; + cin >> a >> b; + if (esPosible(a, b)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int n, a[1000010]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int cnt = 0; + int flag = 1; + for (int j = 0; j < a[0]; j++) { + if (a[0] == 1) { + cout << -1 << endl; + break; + } else { + cout << 1 << endl; + break; + } + } + return 0; +} +string str; +int main() { + int n; + cin >> n; + cin >> str; + int flag = 0; + int temp; + for (int i = 0; i < str.length() - 1; i++) { + if (str[i] != str[i + 1]) { + flag = 1; + temp = i; + break; + } + } + if (flag == 0) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << str[temp] << str[temp + 1] << endl; + } + return 0; +} +int main() { + int x, y, a; + cin >> x >> y; + a = abs(x) + abs(y); + if (x > 0 && y > 0) cout << "0 " << a << " " << a << " 0" << endl; + if (x < 0 && y > 0) cout << -a << " 0 0 " << a << endl; + if (x < 0 && y < 0) cout << -a << " 0 0 " << -a << endl; + if (x > 0 && y < 0) cout << "0 " << -a << " " << a << " 0" << endl; + return 0; +} +int n, k, t = 0, f = 0, ans = 0; +int a[110]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] == 1) + t++; + else + f++; + } + for (int i = 1; i <= n; i++) { + int x = t, y = f; + int j = i; + while (j <= n) { + if (a[j] == 1) + x--; + else + y--; + j += k; + } + j = i - k; + while (j >= 1) { + if (a[j] == 1) + x--; + else + y--; + j -= k; + } + ans = max(ans, (int)fabs(x - y)); + } + cout << ans << endl; +} +const int maxn = 5005; +string s; +int n, ans; +bool ok[maxn][maxn]; +int main() { + cin >> s; + int n = s.length(); + for (int i = 0; i < n; i++) { + int l = 0, r = 0, q = 0; + for (int j = 0; i + j < n; j++) { + if (s[i + j] == '(') + l++; + else if (s[i + j] == '?') + q++; + else + r++; + if (l + q < r) break; + ok[i][i + j] = true; + } + } + for (int i = n - 1; i >= 0; i--) { + int l = 0, r = 0, q = 0; + for (int j = 0; i - j >= 0; j++) { + if (s[i - j] == '(') + l++; + else if (s[i - j] == '?') + q++; + else + r++; + if (r + q < l) break; + if (ok[i - j][i] && j % 2 == 1) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int q = 0, cnt = 0; + for (int j = i; j < n; j++) { + if (s[j] == '?') + q++; + else if (s[j] == '(') + cnt++; + else + cnt--; + while (q > 0 && q > cnt) { + q--; + cnt++; + } + if (cnt < 0) break; + if ((j - i + 1) % 2 == 0 && q >= cnt) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, x, y, sum = INT_MIN; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (y > k) { + sum = max(sum, x - (y - k)); + } else { + sum = max(sum, x); + } + } + cout << sum << endl; + return 0; +} +int dp[101][3]; +int f(int n, int a[], int i, int act) { + if (i >= n) return 0; + if (dp[i][act] != -1) return dp[i][act]; + int rest = INT_MAX; + if (a[i] == 0) { + int frest; + if (i + 1 < n) + frest = 1 + f(n, a, i + 1, 0); + else + frest = 1; + rest = min(frest, rest); + } + if (a[i] == 1) { + int frest = INT_MAX, grest = INT_MAX; + if (act != 2) { + if (i + 1 < n) + frest = f(n, a, i + 1, 2); + else + frest = 0; + } + if (i + 1 < n) + grest = f(n, a, i + 1, 0) + 1; + else + grest = 1; + rest = min(rest, frest); + rest = min(rest, grest); + } + if (a[i] == 2) { + int frest, grest; + frest = grest = INT_MAX; + if (act != 1) { + if (i + 1 < n) + frest = f(n, a, i + 1, 1); + else + frest = 0; + } + if (i + 1 < n) + grest = f(n, a, i + 1, 0) + 1; + else + grest = 1; + rest = min(rest, frest); + rest = min(rest, grest); + } + if (a[i] == 3) { + int frest, grest, crest; + frest = grest = crest = INT_MAX; + if (act != 1) { + if (i + 1 < n) + frest = f(n, a, i + 1, 1); + else + frest = 0; + } + if (act != 2) { + if (i + 1 < n) + grest = f(n, a, i + 1, 2); + else + grest = 0; + } + if (i + 1 < n) + crest = f(n, a, i + 1, 0) + 1; + else + crest = 1; + rest = min(rest, frest); + rest = min(rest, grest); + rest = min(rest, crest); + } + return dp[i][act] = rest; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; ++i) cin >> a[i]; + memset(dp, -1, sizeof(dp)); + int rest = f(n, a, 0, 0); + if (rest == INT_MAX) rest = 0; + cout << rest << endl; + return 0; +} +long long ans = 0, i = 0, j = 0, cnt = 0; +long long arr[101]; +long long brr[101]; +int main() { + int t = 1; + while (t--) { + int n; + cin >> n; + for (i = 1; i <= n; i++) cin >> arr[i]; + set s(arr + 1, arr + n + 1); + if (s.find(0) == s.end()) + cout << s.size() << "\n"; + else + cout << s.size() - 1 << "\n"; + } +} +int main() { + int n; + while (cin >> n) { + int h, m; + cin >> h >> m; + if (h / 10 == 7 or h % 10 == 7 or m / 10 == 7 or m % 10 == 7) + cout << 0 << endl; + else { + int c = 0; + while (1) { + c++; + if (m - n < 0) { + m += 60; + m -= n; + if (h - 1 < 0) + h += 23; + else + h--; + } else + m -= n; + if (m / 1 == 7 or m % 10 == 7) { + cout << c << endl; + break; + } + if (h / 10 == 7 or h % 10 == 7) { + cout << c << endl; + break; + } + } + } + } +} +int main() { + long long n, i, x, a; + i = 1; + cin >> n; + while (n > i) { + n -= i; + i++; + } + x = n; + cout << x << endl; + return 0; +} +int main() { + int n, i, j, k; + int ls(0), rs(0), lc(0), rc(0); + cin >> n; + int l, r; + for (i = 0; i < n; i++) { + cin >> l >> r; + if (l % 2 == 1 && r % 2 == 0) lc++; + if (l % 2 == 0 && r % 2 == 1) rc++; + ls += l; + rs += r; + } + if (ls % 2 == 0 && rs % 2 == 0) { + cout << 0 << endl; + return 0; + } else if ((ls % 2 == 1 && rs % 2 == 0) || (ls % 2 == 0 && rs % 2 == 1)) { + cout << -1 << endl; + return 0; + } else if (ls % 2 == 1 && rs % 2 == 1) { + if (lc > 0 || rc > 0) { + cout << 1 << endl; + return 0; + } else { + cout << -1 << endl; + return 0; + } + } + return 0; +} +int main() { + vector s(8); + for (long long int i = 0; i < (long long int)(8); ++i) cin >> s[i]; + long long int w = 10, b = 10; + for (long long int i = 0; i < (long long int)(8); ++i) { + long long int j = i; + long long int ww = -1; + for (long long int i = 0; i < (long long int)(8); ++i) { + if (s[0 + i][j] == 'B') break; + if (ww == -1 && s[0 + i][j] == 'W') ww = 0 + i; + } + long long int bb = -1; + for (long long int i = 0; i < (long long int)(8); ++i) { + if (s[7 - i][j] == 'W') break; + if (bb == -1 && s[7 - i][j] == 'B') bb = 7 - i; + } + if (ww != -1) w = min(w, ww); + if (bb != -1) b = min(b, 7 - bb); + } + cout << (w <= b ? "A" : "B") << endl; + return 0; +} +int main() { + int a, b, c, d, e = 1, f = 1, l = 0; + cin >> a >> b >> c >> d; + while (e != a) { + if (f == 1) { + if (min(b, c) == b) { + f = 2; + l += b; + } else { + f = 3; + l += c; + } + } else { + if (f == 2) { + if (min(d, b) == d) { + f = 3; + l += d; + } else { + f = 1; + l += b; + } + } else { + if (f == 3) { + if (min(c, d) == d) { + f = 2; + l += d; + } else { + f = 1; + l += c; + } + } + } + } + e++; + } + cout << l << endl; +} +long long gcd(long long a, long long b) { + return !b ? a : gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return (a / gcd(a, b)) * b; +} +int dix[] = {1, -1, 0, 0, 1, 1, -1, -1}; +int diy[] = {0, 0, 1, -1, 1, -1, 1, -1}; +int main() { + int n; + cin >> n; + vector v(n); + int res = 0; + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = 1; i < n - 1; i++) + if (v[i] > v[i - 1] && v[i] > v[i + 1]) res++; + for (int i = 1; i < n - 1; i++) + if (v[i] < v[i - 1] && v[i] < v[i + 1]) res++; + cout << res << '\n'; + return 0; + ; +} +int main() { + int y, ar[4]; + cin >> y; +start: + int i = 0, ye; + ye = ++y; + while (y != 0) { + int r; + r = y % 10; + ar[i] = r; + i++; + y = y / 10; + } + y = ye; + int st = i; + for (int k = 0; k < st; k++) { + for (int j = k + 1; j < st; j++) { + if (ar[k] == ar[j]) { goto start; } + } + } + cout << y << endl; + return 0; +} +int main() { + int k, n, w, sum = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { sum += i; } + if (n >= sum * k) + cout << "0" << endl; + else + cout << (sum * k) - n << endl; + return 0; +} +const long long N = 1e5; +float l, p, q; +int main() { + cin >> l >> p >> q; + cout << l / (p + q) * p; + cout << "\n"; + return 0; +} +const int N = 110; +const long long MAX = 1e8 + 5; +int a[N], n, k, ans; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + int flag1 = 1, flag2 = 1; + for (int i = 0, j = n - 1; i <= j; i++, j--) { + if ((a[i] <= k) && flag1) { ans++; } + if (a[i] > k) { + flag1 = 0; + i--; + } + if ((a[j] <= k) && flag2 && (ans < n)) ans++; + if (a[j] > k) { + flag2 = 0; + j++; + } + if (!flag1 && !flag2) break; + } + cout << ans << endl; + return 0; +} +vector tu[1005]; +int a[1005], cnt[1005], n, checks[1005]; +int check(int x) { + int i, k; + int sum = -1; + queue qua[5]; + for (i = 1; i <= n; i++) { + if (cnt[i] == 0) { qua[a[i]].push(i); } + } + for (;;) { + if (qua[1].size() == 0 && qua[2].size() == 0 && qua[3].size() == 0) break; + while (!qua[x].empty()) { + sum++; + k = qua[x].front(); + qua[x].pop(); + for (i = 0; i < tu[k].size(); i++) { + int xx = tu[k][i]; + cnt[xx]--; + if (cnt[xx] == 0) qua[a[xx]].push(xx); + } + } + if (x == 1) + x = 2; + else if (x == 2) + x = 3; + else if (x == 3) + x = 1; + sum++; + } + if (sum == -1) + return 0; + else + return sum; +} +int main() { + int i; + int ans, T, x; + cin >> n; + memset(a, 0, sizeof(a)); + memset(tu, 0, sizeof(tu)); + memset(cnt, 0, sizeof(cnt)); + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + cin >> T; + while (T--) { + cin >> x; + tu[x].push_back(i); + checks[i]++; + } + } + ans = 1 << 30; + int j; + for (i = 1; i <= 3; i++) { + for (j = 1; j <= n; j++) { cnt[j] = checks[j]; } + ans = min(ans, check(i)); + } + cout << ans << endl; +} +long long n, l, r; +int main() { + cin >> n; + while (n--) { + cin >> l >> r; + long long sum = l, x; + if (!sum & 1 && r > l) sum++; + for (int i = 0; i <= (int)log2l(r); i++) { + x = sum | (1LL << i); + if (x > r) break; + sum = x; + } + if (sum >= l) + cout << sum << endl; + else + cout << l << endl; + } + return 0; +} +const int MAX = 2e5 + 7; +const int INF = 0x3f3f3f3f; +int N, M, K; +int prea[MAX], preb[MAX]; +int cal(int a, char c, int b) { + if (c == '&') return a & b; + if (c == '|') return a | b; + return a ^ b; +} +int main() { + while (cin >> N) { + int x = 0, y = 1023; + for (int i = 0; i < N; i++) { + char c; + int a; + cin >> c >> a; + x = cal(x, c, a); + y = cal(y, c, a); + } + int a = 0, b = 0, c = 1023; + for (int i = 0; i < 10; i++) { + int p = 1 << i; + if (x & p) { + if (y & p) + a |= p; + else + b |= p; + } else { + if (!(y & p)) c ^= p; + } + } + cout << 3 << endl; + cout << "| " << a << endl; + cout << "^ " << b << endl; + cout << "& " << c << endl; + } + return 0; +} +int n, x, ans, a, b, t; +int main() { + cin >> t; + while (t--) { + cin >> a >> b; + ans = 0; + if (a > b) swap(a, b); + while (a != 0) { + ans += b / a; + b %= a; + swap(a, b); + } + cout << ans << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long l, v, li, ri, val1, val2, val3; + cin >> l >> v >> li >> ri; + val1 = l / v; + val2 = li / v; + val3 = ri / v; + if (li % v == 0) val3++; + val3 -= val2; + val1 -= val3; + cout << val1 << endl; + } +} +int main() { + int num[6], sum = 0, index = 2; + for (int i = 0; i < 6; i++) { + cin >> num[i]; + sum += num[i]; + } + for (int i = 0; i < 6; i++) { + for (int j = i + 1; j < 6; j++) { + for (int t = j + 1; t < 6; t++) { + if (2 * (num[i] + num[j] + num[t]) == sum) { + index = 0; + cout << "YES" << endl; + break; + } + } + if (index == 0) break; + } + if (index == 0) break; + } + if (index == 2) cout << "NO" << endl; +} +set s[300000]; +char a[300000][35]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int len = strlen(a[1]); + for (int i = 0; i < len; i++) { + for (int j = 1; j <= n; j++) s[i].insert(a[j][i]); + } + int i; + for (i = 0; i < len; i++) { + if (s[i].size() != 1) break; + } + cout << i << endl; + return 0; +} +int main() { + int x[3], k; + cin >> x[0] >> x[1] >> x[2]; + sort(x, x + 3); + k = x[2] - x[0]; + cout << k << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + char c; + cin >> c; + if (c == 'x') { + a[i][j] = 0; + } else { + a[i][j] = 1; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int count = 0; + if (a[i - 1][j] && i - 1 >= 0) { count += 1; } + if (a[i + 1][j] && i + 1 < n) { count += 1; } + if (a[i][j - 1] && j - 1 >= 0) { count += 1; } + if (a[i][j + 1] && j + 1 < n) { count += 1; } + if (count % 2 != 0) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n & 1) + cout << "1" << endl; + else + cout << "0" << endl; +} +const int MAXT = 1500; +int n, s; +bool ok[MAXT + 1]; +int main() { + memset(ok, true, sizeof ok); + cin >> n >> s; + for (int i = 1; i <= n; ++i) { + int h, m; + cin >> h >> m; + int t = h * 60 + m; + for (int i = max(0, t - s); i <= t + s; ++i) ok[i] = false; + } + for (int i = 0; i <= MAXT; ++i) + if (ok[i]) { + int h = i / 60, m = i % 60; + cout << h << " " << m << endl; + break; + } + return 0; +} +void rotate1(string &t) { + char temp = t[1]; + t[1] = t[0]; + t[0] = t[3]; + t[3] = t[2]; + t[2] = temp; +} +void rotate2(string &t) { + char temp = t[1]; + t[1] = t[4]; + t[4] = t[3]; + t[3] = t[5]; + t[5] = temp; +} +void rotate3(string &t) { + char temp = t[0]; + t[0] = t[4]; + t[4] = t[2]; + t[2] = t[5]; + t[5] = temp; +} +string norm(string s) { + string res = s; + for (int(i) = 0; (i) < (2); ++(i)) { + for (int(j) = 0; (j) < (4); ++(j)) { + for (int(k) = 0; (k) < (4); ++(k)) { + rotate1(s); + res = min(res, s); + } + rotate3(s); + } + rotate1(s); + } + return res; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + set S; + do { S.insert(norm(s)); } while (next_permutation(s.begin(), s.end())); + cout << S.size() << endl; +} +long long n, m, a, b, x, ff = 2e7 + 1, l, r, cnt, ans; +vector v, f, res; +string s1, s2; +long long used[1001]; +int main() { + cin >> n; + cout << n / 2 + 1 << endl; +} +const int N = 0, INF = 0, MOD = 0; +int n, k, cnt[30]; +string s; +int main() { + cin >> n >> k; + cin >> s; + for (int i = 0; i < n; i++) cnt[s[i] - 'A']++; + int mn = 1000000; + for (int i = 0; i < k; i++) mn = min(mn, cnt[i]); + cout << mn * k << endl; + return 0; +} +int main() { + int x[500], y[500]; + int n, i, k, ctf = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + for (i = 0; i < n; i++) { + int ct1 = 0, ct2 = 0, ct3 = 0, ct4 = 0; + for (k = 0; k < n; k++) { + if (i != k) { + if (x[i] > x[k] && y[i] == y[k]) { ct1 = 1; } + if (x[i] < x[k] && y[i] == y[k]) { ct2 = 1; } + if (x[i] == x[k] && y[i] < y[k]) { ct3 = 1; } + if (x[i] == x[k] && y[i] > y[k]) { ct4 = 1; } + } + } + if (ct1 == 1 && ct2 == 1 && ct3 == 1 && ct4 == 1) { ctf++; } + } + cout << ctf << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int m; + cin >> m; + int b[m]; + for (int i = 0; i < m; i++) cin >> b[i]; + float ratio; + int mx = 0; + map mp; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + ratio = b[j] / a[i]; + if (b[j] % a[i] == 0 && ratio >= mx) { + mx = ratio; + mp[ratio]++; + } + } + } + cout << mp[mx] << endl; +} +long long n, k, x; +int main() { + cin >> n >> k; + x = n / k; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int a[155]; +int turn(int x) { + memset(a, 0, sizeof(a)); + int k = 0; + while (x) { + a[k++] = x % 2; + x /= 2; + } + return k; +} +int main() { + int n, m; + while (cin >> n >> m) { + int len = turn(m); + if (n >= len) + cout << m << endl; + else { + int ans = 0; + for (int i = n - 1; i >= 0; i--) ans = ans * 2 + a[i]; + cout << ans << endl; + } + } + return 0; +} +int main() { + char s[10001]; + int t; + while (cin >> t) { + int ns = -1, sm = 0; + while (t--) { + int doll, puppet; + cin >> doll >> puppet; + sm = sm - doll + puppet; + ns = max(ns, sm); + } + cout << ns << endl; + } +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + for (b; b >= 1; b--) { + a += b; + if (b == d) a -= c; + if (b == f) a -= e; + if (a <= 0) a = 0; + } + cout << a << endl; +} +int main() { + int gcd = 0, n[1000], i, t; + cin >> t; + for (i = 0; i < t; i++) { + cin >> n[i]; + gcd = __gcd(gcd, n[i]); + } + cout << t * gcd << endl; + return 0; +} +void File() { + freopen("colors.in", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 1e5 + 5; +const int oo = 0x3f3f3f3f; +int main() { + fast(); + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < ((int)((s).size())); i++) { + if (s[i] == '4' || s[i] == '7') + continue; + else + return cout << "NO\n", 0; + } + long long sum1 = 0, sum2 = 0; + for (int i = 0; i < n / 2; i++) sum1 += (s[i] - '0'); + for (int i = n / 2; i < n; i++) sum2 += (s[i] - '0'); + if (sum1 == sum2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + vector v; + int a; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + v.push_back(a); + } + if (v[n - 1] == 15) { + cout << "DOWN\n"; + return 0; + } + if (v[n - 1] == 0) { + cout << "UP\n"; + return 0; + } + if (n == 1 && v[0] != 0 && v[0] != 15) { + cout << -1 << "\n"; + return 0; + } + a = v[n - 1] - v[n - 2]; + if (a < 0) { + cout << "DOWN\n"; + } else { + cout << "UP\n"; + } + return 0; +} +int main() { + int n, a[1000], p = 1, cnt = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + int t = 0; + for (int j = 1; j <= i; j++) + if (a[j] == 0) t++; + for (int j = i; j <= n; j++) + if (a[j] == 1) t++; + cnt = max(cnt, t); + } + cout << cnt << endl; + return 0; +} +int main() { + int a, b, n; + while (cin >> n >> a >> b) { cout << (n - a > b ? b + 1 : n - a) << endl; } + return 0; +} +int main() { + int n; + cin >> n; + string str, pass; + cin >> str; + cin >> pass; + int cnt = 0, store = 0; + for (int i = 0; i < n; i++) { + store = abs(pass[i] - str[i]); + if (store == 6) { + cnt += 4; + } else if (store == 7) { + cnt += 3; + } else if (store == 8) { + cnt += 2; + } else if (store == 9) { + cnt += 1; + } else { + cnt = cnt + store; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + long long int a, b, k; + cin >> a >> b >> k; + long long int sm = a - b; + long long int res = k / 2 * sm; + if (k % 2) res += a; + cout << res << endl; + } + return 0; +} +unsigned long long n; +unsigned long long t; +unsigned long long i = 0; +unsigned long long a; +int main() { + cin >> n; + cin >> t; + vector imp; + while (i < n) { + cin >> a; + imp.push_back(86400 - a); + i += 1; + } + i = 0; + unsigned long long b = 0; + bool check = true; + unsigned long long i2 = 0; + while (check == true) { + b += imp[i]; + i2 += 1; + if (b >= t) { check = false; }; + i += 1; + }; + cout << i2 << endl; + return 0; +} +int a[105]; +int main() { + int n, m, mn, mx, x, k = 0; + bool b = true; + cin >> n >> m >> mn >> mx; + for (int i = 0; i < m; i++) { cin >> a[i]; } + sort(a, a + m); + if (a[0] < mn || a[m - 1] > mx) { b = false; } + if (a[0] > mn) { k++; } + if (a[m - 1] < mx) { k++; } + if (b == true) { + if (n < (m + k)) { b = false; } + } + if (b == true) { + cout << "Correct" << endl; + } else { + cout << "Incorrect" << endl; + } +} +int main() { + int k, r, l = 0, i = 0; + cin >> k; + cin >> r; + while (true) { + i++; + l += k; + int a; + a = l; + if (a % 10 == 0) { + cout << i << endl; + return 0; + } + a -= r; + if (a % 10 == 0) { + cout << i << endl; + return 0; + } + } +} +int main() { + int n, k; + cin >> n >> k; + int ans = -1; + ans = n; + ans *= 3; + ans -= k; + if (ans >= 0) { + cout << ans << '\n'; + } else { + cout << 0 << '\n'; + } +} +int main() { + int n, m, c[1005], a[1005]; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) cin >> a[i]; + int hc = 1, ans = 0; + for (int ha = 1; ha <= m;) { + int aha = a[ha]; + for (; hc <= n; hc++) { + if (c[hc] <= a[ha]) { + ha++; + hc++; + ans++; + if (hc == n + 1) { + cout << ans << endl; + return 0; + } + break; + } + } + if (hc == n + 1) break; + } + cout << ans << endl; + return 0; +} +int main() { + int n, temp = 0, index; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int mn = *min_element(v.begin(), v.end()); + for (int i = 0; i < v.size(); i++) + if (v[i] == mn) { + temp++; + index = i + 1; + } + if (temp > 1) + puts("Still Rozdil"); + else + cout << index << "\n"; + return 0; +} +string lowercase(char s[]) { + for (int i = 0; s[i] != '\0'; i++) { + if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; + } + return s; +} +int main() { + int i, j, m, n, ac = 0, bc = 0; + char a[110], b[110]; + gets(a); + gets(b); + lowercase(a); + lowercase(b); + for (int i = 0; a[i] != '\0'; i++) { + if (a[i] > b[i]) { + ac++; + break; + } else if (b[i] > a[i]) { + bc++; + break; + } + } + if (ac > bc) + cout << "1" << endl; + else if (bc > ac) + cout << "-1" << endl; + else + cout << "0" << endl; + return 0; +} +int n, ans; +string s; +int main() { + cin >> n; + while (cin >> s) { + int tmp = 0; + for (int i = 0; i < s.length(); ++i) { tmp += (s[i] >= 'A' && s[i] <= 'Z'); } + ans = max(ans, tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int sum = 0; + int n; + cin >> n; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "Tetrahedron") { + sum += 4; + } else if (s == "Cube") { + sum += 6; + } else if (s == "Octahedron") { + sum += 8; + } else if (s == "Dodecahedron") { + sum += 12; + } else if (s == "Icosahedron") { + sum += 20; + } + } + cout << sum << endl; + return 0; +} +long long digit(long long n) { + long long x; + long long count1 = 0; + while (n > 0) { + x = n % 10; + if (x == 4 || x == 7) count1++; + n = n / 10; + } + return count1; +} +int main() { + long long n, k; + cin >> n >> k; + long long a[n]; + for (long long i = 0; i < n; i++) cin >> a[i]; + long long c1 = 0; + for (long long i = 0; i < n; i++) { + if (digit(a[i]) <= k) c1++; + } + cout << c1 << endl; + ; + return 0; +} +int main() { + int i, n, k, w, sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + int s = sum - n; + if (sum <= n) + cout << 0 << "\n"; + else + cout << s << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 10 <= 5) { + cout << (n / 10) * 10 << endl; + } else { + cout << (n / 10 + 1) * 10 << endl; + } +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int k; + string s; + cin >> k >> s; + if (s.size() == 2 && s[0] >= s[1]) + cout << "NO" << endl; + else + cout << "YES" << endl << 2 << endl << s[0] << " " << s.substr(1, k) << endl; + } + return 0; +} +int main() { + long long x1, y1, x2, y2, x3, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + long long vx1 = x2 - x1, vy1 = y2 - y1, vx2 = x3 - x2, vy2 = y3 - y2; + long long cha = vx1 * vy2 - vx2 * vy1; + if (cha > 0) { cout << "LEFT" << endl; } + if (cha < 0) { cout << "RIGHT" << endl; } + if (cha == 0) { cout << "TOWARDS" << endl; } + return 0; +} +int main() { + int n, m, temp; + cin >> n >> m; + if (n > m) + temp = m; + else + temp = n; + if (temp % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; +} +int main() { + int a[10][10]; + int n; + cin >> n; + for (int i = 0; i < n; ++i) { a[i][0] = a[0][i] = 1; } + for (int i = 1; i < n; ++i) { + for (int j = 1; j < n; ++j) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; +} +int main() { + int n; + cin >> n; + for (int times = 0; times < n; times++) { + int a, b; + cin >> a >> b; + int ans = 0; + while (a != 0 && b != 0) { + if (a < b) { + ans = ans + (b / a); + b = b % a; + continue; + } else if (a == b) { + ans++; + a = 0; + b = 0; + continue; + } else if (a > b) { + ans = ans + (a / b); + a = a % b; + continue; + } + } + cout << ans << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n, chest, bic, back; + chest = bic = back = 0; + int aux1, aux2, aux3; + cin >> n; + for (int i = 1; i <= n; i += 3) { + aux1 = aux2 = aux3 = 0; + cin >> aux1; + if (i + 1 <= n) cin >> aux2; + if (i + 2 <= n) cin >> aux3; + chest += aux1; + bic += aux2; + back += aux3; + } + if (chest > bic and chest > back) + cout << "chest" << endl; + else if (back > bic and back > chest) + cout << "back" << endl; + else + cout << "biceps" << endl; + return 0; +} +int main() { + long long int n = 6; + long long int sum = 0; + long long int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + if (sum & 1) + cout << "NO" << endl; + else { + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + for (int k = j + 1; k < n; k++) { + if (((arr[i] + arr[j] + arr[k]) * 2) == sum) { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + } +} +int main() { + long long n; + cin >> n; + cout << (n / 2) + (n / 1) << endl; + return 0; +} +int main() { + int n, i; + string s, s1; + vector r, kw, m, c; + vector::iterator it; + cin >> n; + while (n--) { + cin >> s >> s1; + if (s1 == "woman" || s1 == "child") { + kw.push_back(s); + } else if (s1 == "rat") { + r.push_back(s); + } else if (s1 == "man") { + m.push_back(s); + } else { + c.push_back(s); + } + } + for (it = r.begin(); it != r.end(); it++) { cout << *it << endl; } + for (it = kw.begin(); it != kw.end(); it++) { cout << *it << endl; } + for (it = m.begin(); it != m.end(); it++) { cout << *it << endl; } + for (it = c.begin(); it != c.end(); it++) { cout << *it << endl; } + return 0; +} +int main() { + int l; + string s; + cin >> l >> s; + for (int i = 0; i < l; i++) { + if (i > l - 3) + cout << s[i]; + else { + string ss(s.begin() + i, s.begin() + i + 3); + if (ss == "ogo") { + cout << "***"; + i += 2; + for (; i <= l - 2;) { + string t(s.begin() + i + 1, s.begin() + i + 3); + if (t == "go") + i += 2; + else + break; + } + } else + cout << s[i]; + } + } + cout << endl; +} +int main() { + int a, b, r; + cin >> a >> b >> r; + r *= 2; + if (a < r || b < r) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } + return 0; +} +int n, a[110], k, ans; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + for (int i = 1; i <= n; ++i) { + if (a[i] <= k) + ++ans; + else + break; + } + for (int i = n; i >= 1; --i) { + if (a[i] <= k) + ++ans; + else + break; + } + ans = min(n, ans); + cout << ans << endl; +} +const int inf = 0x3f3f3f3f; +const int N = 5050; +int main() { + char a[N]; + int i, j; + cin >> a; + int ans = 0; + for (i = 0; i < strlen(a); i++) { + int l = 0, r = 0; + for (j = i; j < strlen(a); j++) { + if (a[j] == '(') { + l++; + r++; + } + if (a[j] == ')') { + l--; + r--; + } + if (a[j] == '?') { + l++; + r--; + } + if (l < 0) break; + if (r < 0) r += 2; + if (r == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + int a = 0; + int b = 1; + int c = 0; + cin >> n; + while (true) { + for (int i = 1; i <= b; i++) { a += i; } + b++; + if (a > n) { break; } + c++; + } + cout << c << "\n"; + return 0; +} +int main() { + long long int t, m, n, cnt; + cin >> t; + for (int a = 0; a < t; a++) { + cin >> m >> n; + cnt = 0; + while (n > 0 && m > 0) { + if (m > n) { + cnt = cnt + (m / n); + m = m % n; + } else { + cnt = cnt + (n / m); + n = n % m; + } + } + cout << cnt << endl; + } +} +const int MAX = 1e5 + 5; +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + long long int n, s1 = 0, s2 = 0; + cin >> n; + vector v1; + vector v2; + long long int x; + for (int i = 0; i < n; ++i) { + cin >> x; + s1 |= x; + } + for (int i = 0; i < n; ++i) { + cin >> x; + s2 |= x; + } + cout << s1 + s2 << endl; +} +int main() { + int t; + cin >> t; + while (t--) { + long long int ans = 0, s, a, b, c; + cin >> s >> a >> b >> c; + long long int count = 0; + count = (s / (a * c)); + ans = (s / (a * c)) * (a + b) + (s - (count * a * c)) / c; + cout << ans << endl; + } + return 0; +} +int main() { + int n, i, j, flag1; + cin >> n; + string s[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + string s_color[6] = {"purple", "green", "blue", "orange", "red", "yellow"}; + string s_ip[6]; + for (i = 0; i < n; i++) { cin >> s_ip[i]; } + cout << 6 - n << endl; + for (i = 0; i < 6; i++) { + flag1 = 0; + for (j = 0; j < n; j++) { + if (s_color[i] == s_ip[j]) { + flag1 = 1; + break; + } + } + if (flag1 == 0) cout << s[i] << endl; + } + return 0; +} +int main() { + long long int a, i, j, n, m, cnt = 0; + cin >> n; + cout << 3 * (n / 2) << endl; + return 0; +} +int main() { + long long int n, **A, a = 0, b = 0; + cin >> n; + A = new long long int *[n]; + for (int i = 0; i < n; i++) { A[i] = new long long int[3]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) cin >> A[i][j]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { + if (A[i][2] % 2 == 0) { + a = A[i][2] / 2; + b = A[i][0] * a - A[i][1] * a; + } else { + a = (A[i][2] - 1) / 2; + b = A[i][0] * (a + 1) - A[i][1] * (a); + } + } + cout << b << endl; + } + return 0; +} +bool isluck(long long n) { + n = abs(n); + while (n) { + if (n % 10 == 8) return true; + n /= 10; + } + return false; +} +int main() { + long long n; + cin >> n; + long long cnt = 0; + while (1) { + n++; + cnt++; + if (isluck(n)) { + cout << cnt << endl; + return 0; + } + } + cout << cnt << endl; + return 0; +} +const int MAXN = 1005; +int n, m, ans, a[MAXN], c[MAXN]; +bool flag[MAXN]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) cin >> a[i]; + int t = 1; + for (int i = 1; i <= n; i++) { + if (c[i] <= a[t]) { + ans++; + t++; + } + } + cout << ans << endl; + return 0; +} +map m; +long long int q, p, u, v, w, ans; +int main() { + cin >> q; + for (int i = 0; i < q; i++) { + cin >> p; + if (p == 1) { + cin >> u >> v >> w; + while (u != v) { + if (u > v) swap(u, v); + m[v] = m[v] + w; + v = v / 2; + } + } else if (p == 2) { + cin >> u >> v; + ans = 0; + while (u != v) { + if (u > v) swap(u, v); + ans += m[v]; + v = v / 2; + } + cout << ans << endl; + } + } + return 0; +} +int main() { + long long int number, order; + cin >> number >> order; + while (order--) { + int c = number % 10; + if (c != 0) { + number = number - 1; + } else { + number = number / 10; + } + } + cout << number << endl; + return 0; +} +int n, a[200] = {}; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + int st = n, ed = 0; + for (int i = 1; i <= n; i++) + if (a[i] == 1) { + st = i; + break; + } + if (st == n) { + if (a[n]) + cout << 1 << endl; + else + cout << 0 << endl; + return 0; + } + for (int i = n; i > 0; i--) + if (a[i] == 1) { + ed = i; + break; + } + int stay = 1; + for (int i = st + 1; i <= ed; i++) + if (a[i]) { + if (i - st < 3) + stay += i - st; + else + stay++; + st = i; + } + cout << stay << endl; + return 0; +} +int main() { + int a[10000]; + int n, i, k; + k = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + if (a[i] > 0) { k++; } + } + if (k > 0) { + cout << "HARD" << endl; + } else { + cout << "EASY" << endl; + } + return 0; +} +int main() { + long long n, jum = 0, arr[100009]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> arr[i]; + jum += arr[i]; + } + if (jum % 2 == 0) + cout << jum << endl; + else { + sort(arr + 1, arr + n + 1); + for (int i = 1; i <= n; i++) { + if (arr[i] % 2 == 1) { + cout << jum - arr[i] << endl; + return 0; + } + } + } +} +int main() { + int N; + cin >> N; + for (int i = 0; i < N; i++) { + int L; + string S; + cin >> L >> S; + if (S.length() == 2 && S[1] <= S[0]) + cout << "NO" << '\n'; + else { + cout << "YES" << '\n'; + cout << 2 << '\n'; + cout << S[0] << ' '; + for (int j = 1; j < S.length(); j++) cout << S[j]; + cout << '\n'; + } + } + return 0; +} +int MAX(int x, int y) { + if (x > y) + return x; + else + return y; +} +int main() { + int n, k; + cin >> n >> k; + int a[105]; + int num1 = 0; + int num2 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) + num1++; + else + num2++; + } + int sum = 0; + for (int i = 0; i < k; i++) { + int x = num1; + int y = num2; + for (int j = i; j < n; j += k) { + if (a[j] == 1) + x--; + else + y--; + } + sum = MAX(sum, abs(x - y)); + } + cout << sum << endl; + return 0; +} +char a[101][101], maxi[101]; +int n, m, ans; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + maxi[j] = max(a[i][j], maxi[j]); + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == maxi[j]) { + ans++; + break; + } + } + } + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + cout << m % (int)(pow(2, n)) << "\n"; +} +int g[11][11]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) g[1][i] = 1; + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= n; j++) { g[i][j] = g[i - 1][j] + g[i][j - 1]; } + } + cout << g[n][n] << endl; + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w; + cin >> h; + cin >> u1; + cin >> d1; + cin >> u2; + cin >> d2; + for (h; h > 0; h--) { + w = w + h; + if (h == d1) { + w = w - u1; + if (w < 0) { w = 0; } + } else if (h == d2) { + w = w - u2; + if (w < 0) { w = 0; } + } + } + cout << w << endl; + return 0; +} +int main() { + int n, x, a = 0, b = 0, c = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (i % 3 == 1) { + a += x; + } else if (i % 3 == 2) { + b += x; + } else + c += x; + } + if (a > b && a > c) { + cout << "chest" << endl; + } else if (a < b && b > c) { + cout << "biceps" << endl; + } else + cout << "back" << endl; +} +inline int read() { + int x = 0, ff = 1; + char c = getchar(); + while (c < '0' || c > '9') { + if (c == '-') ff = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = (x << 1) + (x << 3) + (c ^ 48); + c = getchar(); + } + return x * ff; +} +inline int in() { + int ff; + cin >> ff; + return ff; +} +int main() { + bool b[1002]; + memset(b, 0, sizeof(b)); + int n, x, k = 0; + n = in(); + while (n--) { + x = in(); + if (x && b[x] == 0) { k++, b[x] = 1; } + } + cout << k << endl; + return 0; +} +vector fact(1000007); +inline long long int mdpower(long long int a, long long int b) { + long long int res = 1; + while (b) { + if (b & 1) res = (res % 998244353 * a % 998244353) % 998244353; + b /= 2; + a = (a % 998244353 * a % 998244353) % 998244353; + } + return res; +} +inline long long int power(long long int a, long long int b) { + long long int res = 1; + while (b) { + if (b & 1) res = (res * a); + b /= 2; + a = a * a; + } + return res; +} +inline void factorial() { + fact[0] = 1; + for (long long int i = 1; i < 1000007; i++) fact[i] = (fact[i - 1] % 998244353 * i % 998244353) % 998244353; +} +inline long long int inverse(long long int a) { + return mdpower(a, 998244353 - 2); +} +int main() { + long long int n; + cin >> n; + vector v; + for (long long int i = 0; i < n; i++) { + long long int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + long long int brr[n]; + brr[0] = v[0]; + for (long long int i = 1; i < n; i++) brr[i] = brr[i - 1] + v[i]; + long long int sum = brr[n - 1]; + for (long long int i = 0; i < n - 1; i++) { + long long int x = i; + sum += v[i]; + sum += brr[n - 1] - brr[i]; + } + cout << sum << "\n"; +} +int minx(int a, int b, int *x) { + if (a < b) { + *x = 0; + return a; + } else { + *x = 1; + return b; + } +} +int main() { + char x = 'r'; + int n, l = 0; + cin >> n; + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + while (n -= 1 && n != 0) { + if (x == 'r') { + int t; + l += minx(a[0], a[1], &t); + if (t) { + x = 'e'; + } else + x = 'o'; + } else if (x == 'e') { + int t; + l += minx(a[1], a[2], &t); + if (t) { + x = 'o'; + } else + x = 'r'; + } else if (x == 'o') { + int t; + l += minx(a[0], a[2], &t); + if (t) { + x = 'e'; + } else + x = 'r'; + } + } + cout << l << endl; + return 0; +} +int main() { + int i, j, k, n, m, t1, t2, price[110], cprice[101][101] = {0}, nowp, minp = -1; + cin >> n >> m; + for (i = 1; i <= n; i++) cin >> price[i]; + for (i = 0; i < m; i++) { + cin >> t1 >> t2; + cprice[t1][t2] = price[t1] + price[t2]; + cprice[t2][t1] = price[t1] + price[t2]; + } + for (i = 1; i < n - 1; i++) + for (j = i + 1; j < n; j++) + for (k = j + 1; k <= n; k++) + if (cprice[i][j] > 0 && cprice[j][k] > 0 && cprice[i][k] > 0) { + nowp = (cprice[i][j] + cprice[j][k] + cprice[i][k]) / 2; + if (minp == -1 || nowp < minp) minp = nowp; + } + cout << minp << endl; + return 0; +} +int main() { + int n, m, min1, max1, simmin = 0, summax = 0, o; + vector of; + cin >> n >> m >> min1 >> max1; + for (int y = 0; y < m; y++) { + cin >> o; + of.push_back(o); + } + sort(of.begin(), of.end()); + if (min1 != of[0]) { simmin++; } + if (min1 > of[0]) { + cout << "Incorrect" << endl; + return 0; + } + if (max1 < of[m - 1]) { + cout << "Incorrect" << endl; + return 0; + } + if (max1 != of[m - 1]) { summax++; } + int sum = simmin + summax; + if (sum + m <= n) { + cout << "Correct" << endl; + return 0; + } else { + cout << "Incorrect" << endl; + return 0; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + for (long long i = 0; i < k; i++) { + if (n % 10 == 0) { + n = n / 10; + } else { + n = n - 1; + } + } + cout << n << endl; + return 0; +} +vector v; +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) { + cout << 0 << endl; + return 0; + } + n -= 10; + if (n == 10) + cout << 15 << endl; + else { + cout << 4 << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + vector v(n); + for (long long i = 0; i < n; i++) { cin >> v[i]; } + long long j = 1; + long long ans = n; + for (long long i = 0; i < n;) { + j = i + 1; + while (j < n && v[j] == v[i]) { j++; } + long long lon = j - i; + ans += lon * (lon - 1) / 2; + i = j; + } + cout << ans << "\n"; +} +int num[260] = {0}; +int main() { + int n, k; + string str; + while (cin >> n >> k) { + int flag = 0; + getchar(); + getline(cin, str); + int len = str.length(); + for (int i = 0; i < len; i++) { + int x = ++num[str[i] - 'a']; + if (x > k) { + cout << "NO" << endl; + flag = 1; + break; + } + if (i == len - 1 && flag == 0) cout << "YES" << endl; + } + } + return 0; +} +int main() { + int n, k; + cin >> n; + k = n / 2; + k++; + cout << k << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + if (x >= 0 && y >= 0) { + cout << 0 << " " << x + y << " " << x + y << " " << 0 << endl; + } else if (x >= 0 && y < 0) { + cout << 0 << " " << -x + y << " " << x + (-y) << " " << 0 << endl; + } else if (x < 0 && y >= 0) { + cout << x - y << " " << 0 << " " << 0 << " " << (-x + y) << endl; + } else { + cout << x + y << " " << 0 << " " << 0 << " " << x + y << endl; + } +} +queue a; +char s[1000005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i] != a.front() && a.size() != 0) { + a.pop(); + } else { + a.push(s[i]); + } + } + cout << a.size() << endl; + return 0; +} +const int N = 1e5 + 100; +int a, b, c; +vector v; +int main() { + cin >> a >> b >> c; + cout << (a * b * c) - (a - 1) * (b - 1) * (c - 1) << endl; + return 0; +} +int main() { + int n, number, num = 0, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int arr[10] = {0}; + cin >> number; + while (number > 0) { + arr[number % 10] = 1; + number /= 10; + } + bool x = true; + for (int t = 0; t <= k; t++) { + if (arr[t] != 1) x = false; + } + if (x) num++; + } + cout << num << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + cout << s1[0]; + for (int i = 1; i < s1.size() && s1[i] < s2[0]; ++i) cout << s1[i]; + cout << s2[0] << endl; + return 0; +} +int A[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; +int main() { + int n; + cin >> n; + cout << A[n / 10] * A[n % 10] << endl; + return 0; +} +int main() { + int a, b, c, t, n, min; + cin >> a >> b >> c; + n = a * c; + t = (n / b); + if (t * b >= n) + cout << (n / b) - c << endl; + else + cout << ((n / b) + 1) - c << endl; + return 0; +} +int prime(int x) { + for (int i = x + 1; i > 0; i++) { + bool a = true; + for (int j = 2; j < i; j++) { + if (i % j == 0) { + a = false; + break; + } + } + if (a) return i; + } +} +int main() { + int n, m; + cin >> n >> m; + if (m == prime(n)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int min(int a, int b) { + return (a < b) ? a : b; +} +int main() { + int m, n; + cin >> m >> n; + int c = min(m, n); + int counter = 0; + for (int i = 0; i <= c; i++) { + for (int j = 0; j <= c; j++) { + if (i * i + j == m && i + j * j == n) counter++; + } + } + cout << counter << endl; +} +set ss[200]; +int num[200]; +int main() { + int n; + cin >> n; + string s; + memset(num, 0, sizeof(num)); + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < s.size(); j++) { + ss[i].insert(s[j]); + num[i]++; + } + } + int maxn = 0, ans; + for (char i = 'a'; i <= 'z'; i++) + for (char j = i + 1; j <= 'z'; j++) { + ans = 0; + for (int k = 0; k < n; k++) { + if (ss[k].size() > 2) continue; + if (ss[k].size() == 1) + if (ss[k].count(i) || ss[k].count(j)) ans += num[k]; + if (ss[k].size() == 2) + if (ss[k].count(i) && ss[k].count(j)) ans += num[k]; + } + maxn = max(maxn, ans); + } + cout << maxn << endl; + return 0; +} +int main() { + int i; + string a, b; + int as = 0, bs = 0, ta, tb; + cin >> a >> b; + for (i = 0; i < a.size(); i += 2) { + if (a.substr(i, 2) == "[]") ta = 0; + if (a.substr(i, 2) == "8<") ta = 1; + if (a.substr(i, 2) == "()") ta = 2; + if (b.substr(i, 2) == "[]") tb = 0; + if (b.substr(i, 2) == "8<") tb = 1; + if (b.substr(i, 2) == "()") tb = 2; + if (ta == tb) continue; + if ((ta > tb || (ta == 0 && tb == 2)) && !(tb == 0 && ta == 2)) + as++; + else + bs++; + } + if (as == bs) cout << "TIE" << endl; + if (as < bs) cout << "TEAM 2 WINS" << endl; + if (as > bs) cout << "TEAM 1 WINS" << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + vector time(n, 0); + for (int i = 0; i < n; i++) { + int h, m; + cin >> h >> m; + time[i] = h * 60 + m; + } + int right = time.front() - 1; + if (right >= s) { + cout << "0 0" << '\n'; + return 0; + } + for (int i = 0; i < time.size() - 1; i++) { + int left = time[i] + 1; + int right = time[i + 1] - 1; + if (right - left >= 2 * s) { + int ret = left + s; + cout << ret / 60 << " " << ret % 60 << '\n'; + return 0; + } + } + int left = time.back() + 1; + int ret = left + s; + cout << ret / 60 << " " << ret % 60 << '\n'; + return 0; +} +int n, k; +int main() { + cin >> n >> k; + for (int i = 1; i <= k; i++) { + if (n % 10 == 0) + n /= 10; + else + n--; + } + cout << n << endl; + return 0; +} +long long t, a; +int main() { + cin >> t; + for (long long i = 1; i <= t; i++) { + cin >> a; + if (360 % (180 - a) == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + M = 3; + for (int i = 0; i < N; i++) { + cin >> L; + if (M == L) { + cout << "NO\n"; + return 0; + } + M ^= L; + } + cout << "YES\n"; + return 0; +} +int main() { + int n = 0, m = 0; + cin >> n >> m; + cout << n + m - 1 << '\n'; + for (int i = 1; i <= m; i++) { cout << 1 << ' ' << i << '\n'; } + for (int i = 2; i <= n; i++) { cout << i << ' ' << 1 << '\n'; } +} +int main() { + int a1, a2, a3, b1, b2, b3, n; + cin >> a1 >> a2 >> a3; + cin >> b1 >> b2 >> b3; + cin >> n; + double cup = (double)a1 + (double)a2 + (double)a3; + double med = (double)b1 + (double)b2 + (double)b3; + int x = ceil(cup / (double)5.00); + int y = ceil(med / (double)10.00); + if (n >= x + y) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int k = 1; + int ans = 0; + for (int i = 1; i <= (int)s.size(); i++) { + if (i < (int)s.size() && s[i] == s[i - 1]) + k++; + else { + if (k % 2 == 0) ans++; + k = 1; + } + } + cout << ans << endl; + return 0; +} +int main() { + vector arr; + int study = 0; + int social = 0; + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int m; + cin >> m; + arr.push_back(m); + if (m == 1) { + study++; + } else { + social++; + } + } + int res = 0; + for (int i = 0; i < k; i++) { + int tstudy = study, tsocial = social; + for (int j = i; j < n; j += k) { + if (arr[j] == 1) { + tstudy--; + } else { + tsocial--; + } + } + int tres = abs(tstudy - tsocial); + if (tres > res) { res = tres; } + } + cout << res << endl; + return 0; +} +int main() { + int a, b, e[10000]; + cin >> a; + cin >> b; + int c[a + 1]; + for (int i = 0; i < a; i++) { + cin >> c[i]; + e[i] = c[i]; + } + int d[b + 1]; + for (int i = 0; i < b; i++) { cin >> d[i]; } + sort(d, d + b); + for (int i = b - 1; i > -1; i--) { + for (int j = 0; j < a; j++) { + if (c[j] == 0) { + c[j] = d[i]; + e[j] = d[i]; + goto momo; + } + } + momo:; + } + sort(c, c + a); + for (int i = 0; i < a; i++) { + if (c[i] != e[i]) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; +} +int main() { + long long n, k = -1; + cin >> n; + for (int i = 0; i * 4 <= n; i++) { + if ((n - (i * 4)) % 7 == 0) { + k = (n - (i * 4)) / 7; + break; + } + } + if (k == -1) { + cout << "-1\n"; + return 0; + } + long long q = n - k * 7; + for (int i = 0; i < q / 4; i++) { cout << "4"; } + while (k--) { cout << "7"; } + cout << "\n"; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a, b, total, k = 0, max; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (k == 0) { + total = b; + k = 1; + max = b; + } else if (k == 1) { + total = total - a + b; + if (total > max) max = total; + } + } + cout << max << endl; + } + return 0; +} +const int N = 1e5 + 5, M = 998244353; +int main() { + long long n; + cin >> n; + int x; + long long h; + long long l; + if (n <= 5) + h = n; + else { + for (x = 1; x <= n; x++) { + l = (1 << x); + if (n - 5 * (l - 1) < 5 * l) { + h = n - 5 * (l - 1); + break; + } + } + } + long long ans; + if (n <= 5) + ans = h - 1; + else { + ans = h / l; + if (ans * l == h) ans--; + } + if (ans == 0) cout << "Sheldon" << endl; + if (ans == 1) cout << "Leonard" << endl; + if (ans == 2) cout << "Penny" << endl; + if (ans == 3) cout << "Rajesh" << endl; + if (ans == 4) cout << "Howard" << endl; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + puts("1"); + return 0; +} +int main() { + int tc; + cin >> tc; + int c = 0; + for (int i = 1; i <= tc; i++) { + int a, b; + cin >> a >> b; + if (b - a >= 2) { c++; } + } + cout << c << endl; + return 0; +} +long long F(long long n) { + if (n < 0) return 0; + long long ans = (n + 2) * (n + 1) / 2LL; + return ans; +} +long long solve(long long a, long long b, long long c, long long v) { + if (b + c > a) return 0; + return F(min(a - b - c, v)); +} +int main() { + long long a, b, c, s; + cin >> a >> b >> c >> s; + long long ans = 0; + for (int i = 0; i <= s; i++) { + ans += F(i); + ans -= solve(a + i, b, c, s - i); + ans -= solve(b + i, a, c, s - i); + ans -= solve(c + i, a, b, s - i); + } + cout << ans << endl; + return 0; +} +int main() { + int t = 0, p = 0, sum = 0, cnt = 0; + string x; + cin >> x; + for (int i = 0; i < x.size(); i++) { + t = x[i] - 97; + cnt = abs(t - p); + if (cnt > 13) + sum += 26 - cnt; + else + sum += cnt; + p = t; + } + cout << sum << endl; + return 0; +} +int freq[10000005]; +int n, m, x, to; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x >> to; + for (int j = x + 1; j <= to; j++) freq[j] = 1; + } + for (int i = 1; i <= m; i++) { + if (!freq[i]) { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int main() { + int i = 0, n, m, temp; + cin >> n >> m; + temp = n; + int x; + while (m >= 0) { + x = (i % n) + 1; + temp = m; + m -= x; + i++; + } + cout << temp << endl; +} +void fastIo() {} +int main() { + fastIo(); + int n, m; + cin >> n >> m; + map ans; + for (int i = 0; i < m; i++) { + int mxv, mx; + mxv = mx = -1; + for (int j = 1; j <= n; j++) { + int temp; + cin >> temp; + if (temp > mxv) { + mxv = temp; + mx = j; + } + } + ans[mx]++; + } + map::iterator it = ans.begin(); + int mxv, mx; + mxv = mx = -1; + while (it != ans.end()) { + if (it->second > mxv) { + mxv = it->second; + mx = it->first; + } + it++; + } + cout << mx << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.size(); + for (int l = n - 1; l > 0; l--) { + for (int i = 0; i + l - 1 < n; i++) { + string x = s.substr(i, l); + if (s.find(x, i + 1) != string::npos) { + cout << l << endl; + return 0; + } + } + } + cout << "0\n"; + return 0; +} +queue a, b, c; +int main() { + int n, ca, cb, cc, q; + ca = cb = cc = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> q; + if (q == 1) { + ca++; + a.push(i); + } else if (q == 2) { + cb++; + b.push(i); + } else { + cc++; + c.push(i); + } + } + int mn = min(ca, min(cb, cc)); + cout << mn << endl; + while (mn--) { + cout << a.front() << " " << b.front() << " " << c.front() << endl; + a.pop(); + b.pop(); + c.pop(); + } + return 0; +} +int main() { + int a, m, d; + while (cin >> m >> d) { + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) + if ((31 + d - 1) % 7 != 0) + cout << (31 + d - 1) / 7 + 1 << endl; + else + cout << (31 + d - 1) / 7 << endl; + else if (m == 2) + if ((28 + d - 1) % 7 != 0) + cout << (28 + d - 1) / 7 + 1 << endl; + else + cout << (28 + d - 1) / 7 << endl; + else if ((30 + d - 1) % 7 != 0) + cout << (30 + d - 1) / 7 + 1 << endl; + else + cout << (30 + d - 1) / 7 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + while (n--) { + int a, b, c; + cin >> a >> b >> c; + ans = (a + b + c >= 2) ? ++ans : ans; + } + cout << ans << endl; + return 0; +} +long long n; +int c, a = 0; +int main() { + cin >> n; + while (n != 0) { + if (n % 10 == 7 || n % 10 == 4) { ++a; } + n = n / 10; + } + if (a == 7 || a == 4) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + cout << (a + b + c) * (a + b + c) - a * a - c * c - e * e << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + cout << (y * n - min(y * n, x * 100) + 99) / 100 << endl; + return 0; +} +int main() { + int a, b, c, n, x, i, cc; + cin >> a >> b >> c; + cc = 0; + while (cin >> n) { + for (i = 0; i < n; i++) { + cin >> x; + if (x > b && x < c) { cc = cc + 1; } + } + cout << cc << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if ((n / m) % 2 == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + char c[95]; + while (cin >> n) { + int sum1 = 0; + for (int i = 0; i <= n - 1; i++) cin >> c[i]; + for (int i = 0; i <= n - 1; i++) { + if (c[i] == '1') + sum1++; + else { + cout << sum1; + sum1 = 0; + } + } + cout << sum1 << endl; + } + return 0; +} +const int N = 1e6 + 5, MAX = 3e7, MOD = 1e9 + 7; +int n, p; +string a[N]; +long long ans; +int main() { + cin >> n >> p; + for (int i = 0; i < n; i++) cin >> a[i]; + long long curr = 0; + for (int i = n - 1; i >= 0; i--) { + if (a[i] == "half") { + ans += curr * p; + curr *= 2; + } else { + ans += curr * p; + ans += p / 2; + curr *= 2; + curr++; + } + } + cout << ans << "\n"; +} +int main() { + int n, agua, toalha = 0; + cin >> n >> agua >> toalha; + int nrod, tagua, ttoalha = 0; + nrod = n - 1; + tagua = nrod + nrod * agua * 2; + ttoalha = toalha * n; + cout << tagua << " " << ttoalha << endl; + return 0; +} +int main() { + long n; + long long a[200005]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + long count = 1; + long long min = 2e9 + 5; + for (int i = 0; i < n - 1; i++) { + long long temp = a[i + 1] - a[i]; + if (temp < min) { + min = temp; + count = 1; + } else if (temp == min) { + count++; + } else + continue; + } + cout << min << " " << count << endl; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) { + cout << a << endl; + } else { + cout << 1 << endl; + } +} +int main() { + int n, c, x, r = 0, t; + priority_queue p; + cin >> n; + cin >> c; + n = n - 1; + while (n--) { + cin >> x; + p.push(x); + } + t = p.top(); + while (c <= t) { + p.pop(); + c++; + t--; + r++; + p.push(t); + t = p.top(); + } + cout << r << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + cout << min(b + 1, n - a) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int tot = 0, ans = 0; + for (int i = 1; i <= n; i++) { + int aa, nn; + cin >> aa >> nn; + if (aa > nn) { + tot++; + } else if (nn > aa) { + ans++; + } + } + if (tot > ans) { + cout << "Mishka" << endl; + } else if (ans > tot) { + cout << "Chris" << endl; + } else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int n, m, num[10000], ans = 1000; +int main() { + cin >> n >> m; + for (int i = 0; i < m; ++i) cin >> num[i]; + for (int i = 1; i <= n; ++i) { + int t = 0; + for (int j = 0; j < m; ++j) { + if (num[j] == i) ++t; + } + ans = (ans > t ? t : ans); + } + cout << ans << endl; + return 0; +} +string a, b; +int now; +int main() { + cin >> a; + cin >> b; + now = 0; + for (int i = 0; i < a.length(); i += 2) { + if (a[i] == '8' && b[i] == '[') ++now; + if (a[i] == '[' && b[i] == '(') ++now; + if (a[i] == '(' && b[i] == '8') ++now; + if (b[i] == '8' && a[i] == '[') --now; + if (b[i] == '[' && a[i] == '(') --now; + if (b[i] == '(' && a[i] == '8') --now; + } + if (now > 0) cout << "TEAM 1 WINS" << endl; + if (now == 0) cout << "TIE" << endl; + if (now < 0) cout << "TEAM 2 WINS" << endl; + return 0; +} +int main() { + int n; + cin >> n; + string k; + for (int i = 0; i < n; i++) { + cin >> k; + int h = k.size(); + if (h > 10) + cout << k[0] << (h - 2) << k[h - 1] << endl; + else + cout << k << endl; + } +} +int n, m; +char chess[101][101]; +string b; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + cin >> b; + for (int j = 1; j <= m; ++j) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + chess[i][j] = 'W'; + else + chess[i][j] = 'B'; + } + if (b[j - 1] == '-') chess[i][j] = '-'; + } + } + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) cout << chess[i][j]; + cout << endl; + } + return 0; +} +vector p, m, t; +int main() { + int n, temp; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> temp; + if (temp == 1) + p.push_back(i + 1); + else if (temp == 2) + m.push_back(i + 1); + else if (temp == 3) + t.push_back(i + 1); + } + int ans1 = min(min(p.size(), m.size()), t.size()); + cout << ans1 << endl; + for (int i = 0; i < ans1; ++i) { cout << p[i] << " " << m[i] << " " << t[i] << endl; } +} +const int inf = 0x3f3f3f3f; +const long long mod = 1000000007; +int main() { + int n; + cin >> n; + if (n % 2) + cout << "Ehab\n"; + else + cout << "Mahmoud\n"; +} +int main() { + int n; + cin >> n; + cout << "I hate "; + for (int i = 1; i < n; i++) { + if (i % 2 == 0) { + cout << "that I hate "; + } else if (i % 2 != 0) { + cout << "that I love "; + } + } + cout << "it" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ef[2] = {0}; + char ch; + getchar(); + while ((ch = getchar()) != '\n') { ++ef[ch - '0']; } + cout << abs(ef[0] - ef[1]) << endl; + return 0; +} +int a[300000]; +int main() { + int n, m1 = 0, m2 = 0, minn = 9999999999, minn2 = 9999999; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (minn > a[i]) minn = a[i]; + } + for (int i = 1; i <= n; i++) { + if (a[i] == minn) { + if (m1 == 0) + m1 = i; + else if (m2 == 0) { + m2 = i; + if (minn2 > m2 - m1) minn2 = m2 - m1; + } else { + m1 = m2; + m2 = i; + if (minn2 > m2 - m1) minn2 = m2 - m1; + } + } + } + cout << minn2 << endl; + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + if (n - k < k) { + for (int i = k; i < n; i++) cout << "RIGHT" << endl; + for (int i = n - 1; i >= 0; i--) { + cout << "PRINT " << s[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } else { + for (int i = k; i > 1; i--) cout << "LEFT" << endl; + for (int i = 0; i < n; i++) { + cout << "PRINT " << s[i] << endl; + if (i != n - 1) cout << "RIGHT" << endl; + } + } + return 0; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +long long int check(long long int n) { + while (n % 2 == 0) { n /= 2; } + while (n % 3 == 0) { n /= 3; } + return n; +} +int main() { + int n; + cin >> n; + long long int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + long long int gcdofarray; + if (a[0] > a[1]) + gcdofarray = gcd(a[0], a[1]); + else + gcdofarray = gcd(a[1], a[0]); + for (int i = 2; i < n; i++) { + if (gcdofarray > a[i]) + gcdofarray = gcd(gcdofarray, a[i]); + else + gcdofarray = gcd(a[i], gcdofarray); + } + for (int i = 0; i < n; i++) a[i] = a[i] / gcdofarray; + int flag = 0; + for (int i = 0; i < n; i++) { + long long int temp = check(a[i]); + if (temp != 1) { + flag = 1; + break; + } + } + if (flag == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int c, n, N = 1; + cin >> n; + cin >> c; + int *t = new int[n]; + for (int i = 0; i < n; ++i) { cin >> t[i]; } + for (int i = 1; i < n; ++i) { + if (t[i] - t[i - 1] <= c) { + N += 1; + } else { + N = 1; + } + } + cout << N << endl; +} +int n; +string a, b, c, d; +int main() { + cin >> a >> b; + cout << a << " " << b << endl; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + cout << a << " " << b << endl; + } + return 0; +} +bool isPrime(int n) { + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int n, m; + cin >> n >> m; + if (m % 2 == 0 || isPrime(m) == false) { + cout << "NO" << endl; + return 0; + } else { + for (int i = n + 1; i <= m; i++) { + if (isPrime(i) == true && i < m) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int i, count = 0, difference, difference1; + string password; + cin >> password; + difference1 = password[0] - 'a'; + if (difference1 > 13) difference1 = 26 - difference1; + for (i = 1; i < password.size(); i++) { + difference = password[i - 1] - password[i]; + if (difference < 0) difference = (-1) * difference; + if (difference > 13) difference = 26 - difference; + count += difference; + } + cout << count + difference1 << endl; +} +int main() { + int n, t, flag; + while (cin >> n) { + flag = 0; + while (n--) { + cin >> t; + if (t == 1) flag = 1; + } + if (flag == 1) + cout << "-1" << endl; + else + cout << '1' << endl; + } + return 0; +} +int main() { + int n, x; + while (cin >> n) { + int sum1 = 0, sum2 = 0; + while (n--) { + cin >> x; + if (x < 0) + sum1 += x; + else + sum2 += x; + } + cout << sum2 - sum1 << endl; + } +} +long long gcd(long long x, long long y) { + if (x == 0) { + return y; + } else { + return gcd(y % x, x); + } +} +int main() { + long long n; + cin >> n; + long long arr[n]; + long long max_num = 0; + for (long long i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] > max_num) { max_num = arr[i]; } + } + long long result = arr[0]; + for (long long i = 1; i < n; i++) { result = gcd(result, arr[i]); } + if ((max_num / result - n) % 2 == 0) { + cout << "Bob" << '\n'; + } else { + cout << "Alice" << '\n'; + } + return 0; +} +long long fstexp(long long x, int n, int mod) { + long long res = 1; + while (n > 0) { + if (n & 1) res = (res * x) % mod; + n = n >> 1; + x = (x * x) % mod; + } + return res; +} +int main() { + int n; + cin >> n; + long long ans = fstexp(3, n - 1, 1000003); + cout << ans << endl; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int r = a; + int o = 0; + while (r > 0) { + ++o; + int c = 0; + if (b > k - 1) { + c = k; + b -= (k - 1); + } else { + c = b + 1; + b = 0; + } + r -= v * c; + } + cout << o << endl; + return 0; +} +int pc[4][10010], n, x; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> x; + pc[x][++pc[0][x]] = i; + } + int cnt = min(pc[0][1], min(pc[0][2], pc[0][3])); + cout << cnt << endl; + for (int i = 1; i <= cnt; ++i) { cout << pc[1][i] << " " << pc[2][i] << " " << pc[3][i] << endl; } + return 0; +} +int main() { + int n, d; + int a[100]; + cin >> n >> d; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int ma = 0; + for (int i = 0; i < n; i++) { + int cnt = 0, pos = i; + while (a[pos] <= a[i] + d && pos < n) pos++, cnt++; + ma = max(ma, cnt); + } + cout << n - ma << endl; + return 0; +} +int main() { + int i, n, res = 0; + cin >> n; + vector a(n); + for (i = 0; i < n; i++) { cin >> a[i]; } + i = 0; + while (a[i] == 0) { i++; } + for (; i < n; i++) { + if (a[i]) { + res++; + } else if (a[i + 1] && i + 1 < n) { + res++; + } else { + while (a[i] == 0 && i < n) { i++; } + i--; + } + } + cout << res << "\n"; + return 0; +} +string s; +map m; +int main() { + cin >> s; + int ans = 0; + for (int i = 0; i < s.size(); i++) { + string x = s.substr(i, s.size() - i) + s.substr(0, i); + if (m[x] == 0) { + ans++; + m[x] = 1; + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int k = 0; + int l = 0; + int m = 0; + int n = 0; + int d = 0; + int result; + cin >> k >> l >> m >> n >> d; + result = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) { result--; } + } + cout << result << endl; + } + return 0; +} +int n, a, b = 2e9, p; +bool bucket[305]; +int main() { + cin >> p >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + if (!bucket[a % p]) + bucket[a % p] = 1; + else + b = min(b, i); + } + if (b == 2e9) b = -1; + cout << b << '\n'; +} +int main() { + int n, miss, before; + cin >> n; + vector watched; + for (int i = 0; i < n - 1; i++) { + int ep; + cin >> ep; + watched.push_back(ep); + } + sort(watched.begin(), watched.end()); + for (int i = 0; i < n; i++) { + if (watched[i] != (i + 1)) { + miss = (i + 1); + break; + } + } + cout << miss << endl; +} +int main() { + int n, s, a, b, i; + char str[1000000]; + while (cin >> n >> s) { + getchar(); + cin >> str; + a = s - 1; + b = n - s; + if (a < b) { + while (a--) cout << "LEFT" << endl; + for (i = 0; i < n; i++) { + cout << "PRINT "; + cout << str[i] << endl; + if (i != n - 1) cout << "RIGHT" << endl; + } + } else { + while (b--) cout << "RIGHT" << endl; + for (i = n - 1; i >= 0; i--) { + cout << "PRINT "; + cout << str[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } + memset(str, 0, sizeof(str)); + } + return 0; +} +int main() { + long long int n, k, f, t; + long long int ans1 = -1 * 1e18; + cin >> n >> k; + long long int ans; + while (n--) { + cin >> f >> t; + if (t <= k) { + ans = f; + } else { + ans = f - (t - k); + } + ans1 = max(ans, ans1); + } + cout << ans1 << endl; + return 0; +} +int main() { + long long int x, n, m, mn = 101, mn2 = 101, mx = 0; + cin >> n >> m; + for (int i = 1; i <= n; ++i) { + cin >> x; + if (x < mn) mn = x; + if (x > mx) mx = x; + } + for (int i = 1; i <= m; ++i) { + cin >> x; + if (x < mn2) mn2 = x; + } + if (mx < mn2) { + if (2 * mn <= mx) + cout << mx << endl; + else { + if (2 * mn < mn2) + cout << 2 * mn << endl; + else + cout << -1 << endl; + } + } else + cout << -1 << endl; +} +int a[100005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + a[0] = 2e9; + int ans = 1, cnt = 1; + for (int i = 1; i <= n; ++i) { + if (a[i] > a[i - 1]) + cnt++, ans = max(ans, cnt); + else + cnt = 1; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int ans = 0; + while (n--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + ans += (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1); + } + cout << ans << '\n'; + return 0; +} +int main() { + int a, b, m = 1; + cin >> a >> b; + for (m; m <= a; m++) { + if (m % 4 == 1) { + for (int n = 1; n < b; n++) { cout << "#"; } + cout << "#" << endl; + } + if (m % 4 == 2) { + for (int n = 1; n < b; n++) { cout << "."; } + cout << "#" << endl; + } + if (m % 4 == 3) { + for (int n = 1; n < b; n++) { cout << "#"; } + cout << "#" << endl; + } + if (m % 4 == 0) { + cout << "#"; + for (int n = 1; n < b; n++) { cout << "."; } + cout << endl; + } + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long offers = s / (a * c); + unsigned int remaining = s % (a * c); + offers = (offers * a) + (offers * b); + if (remaining >= c) offers += (remaining / c); + cout << offers << endl; + } +} +int main() { + int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int nEven, nOdd; + cin >> nOdd >> nEven; + if (nOdd == 0 && nEven == 0) { + cout << "NO\n"; + return 0; + } + if (nOdd - nEven >= -1 && nOdd - nEven <= 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + char arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int count = 1; + for (int i = 0; i < n - 1; i++) { + if (arr[i] == '1') { + count++; + } else { + break; + } + } + cout << count << "\n"; +} +int main() { + long long int res; + long long int n; + cin >> n; + res = sqrt(n); + for (int i = res;; i--) { + if (n % i == 0) { + cout << i << " " << n / i << endl; + return 0; + } + } +} +int main() { + int i, j, k = 0; + char c; + string s, s1[10], s2[10]; + cin >> s; + for (i = 0; i < 80;) { + for (j = i; j < (i + 10); j++) { s1[k] += s[j]; } + i = j; + k++; + } + for (i = 0; i < 10; i++) { cin >> s2[i]; } + for (i = 0; i < 8; i++) { + for (j = 0; j < 10; j++) { + if (s1[i] == s2[j]) { + cout << j; + break; + } + } + } + cout << endl; + return 0; +} +int main() { + string str; + cin >> str; + cout << (str.size() + 1) * 25 + 1 << endl; + return 0; +} +int main() { + string s; + set st; + cin >> s; + int j = s.size(); + int t = j + 1; + for (int i = 0; i < s.size(); i++) { st.insert(s[i]); } + int k = (j - st.size()) * 2; + cout << (t * 26) - j << endl; +} +int main() { + int n, m; + cin >> n >> m; + cout << min(n, m) << " " << (max(n, m) - min(n, m)) / 2 << endl; + return 0; +} +int main() { + long long n, k; + int a[3][10] = {{0, 1, 2, 2, 1, 0}, {1, 0, 0, 1, 2, 2}, {2, 2, 1, 0, 0, 1}}; + cin >> n >> k; + n = n % 6; + for (int i = 0; i < 3; i++) { + if (a[i][n] == k) cout << i << endl; + } + return 0; +} +int a[1005][1005], vis[1005][1005]; +int ans; +int n, m; +int fang[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; +void dfs(int x, int y) { + ans++; + for (int i = 0; i < 4; ++i) { + int nx = x + fang[i][0]; + int ny = y + fang[i][1]; + if (nx > 0 && nx <= n && ny > 0 && ny <= m && a[nx][ny] && !vis[nx][ny]) { + vis[nx][ny] = 1; + dfs(nx, ny); + } + } +} +int main() { + int k, i, j; + while (cin >> n >> m >> k) { + ans = 0; + int x, y; + memset(a, 0, sizeof(a)); + int res = 0; + for (i = 1; i <= k; ++i) { + cin >> x >> y; + a[x][y] = 1; + if (!res) { + ans++; + if (a[x][y] && a[x + 1][y] && a[x][y + 1] && a[x + 1][y + 1]) res = 1; + if (a[x][y] && a[x + 1][y] && a[x][y - 1] && a[x + 1][y - 1]) res = 1; + if (a[x][y] && a[x - 1][y] && a[x][y + 1] && a[x - 1][y + 1]) res = 1; + if (a[x][y] && a[x - 1][y] && a[x][y - 1] && a[x - 1][y - 1]) res = 1; + } + } + if (!res) ans = 0; + cout << ans << endl; + } +} +const int MAX = 5000 + 50; +char ch[MAX]; +int main() { + while (cin >> ch) { + int ans = 0; + int len = strlen(ch); + for (int i = 0; i < len; i++) { + int l = 0, count = 0; + for (int j = i; j < len; j++) { + if (ch[j] == '(') + l++; + else if (ch[j] == ')') + l--; + else if (ch[j] == '?') + l--, count++; + if (l == 0) + ans++; + else if (l < 0 && count > 0) + l += 2, count--; + else if (l < 0 && count == 0) + break; + } + } + cout << ans << endl; + } + return 0; +} +char a[201000]; +int main() { + int n; + cin >> n; + cin >> a; + stack q; + int len = 0; + for (int i = 0; i < n; i++) { + if (!q.empty()) { + if (q.top() != (a[i] - '0')) + q.pop(); + else + q.push(a[i] - '0'); + } else + q.push(a[i] - '0'); + } + while (!q.empty()) { + q.pop(); + len++; + } + cout << len << endl; + return 0; +} +int main() { + int grid[5][5]; + int ans[4][4]; + for (int i = 1; i <= 3; ++i) + for (int j = 1; j <= 3; ++j) cin >> grid[i][j], ans[i][j] = 1; + for (int i = 1; i <= 3; ++i) { + for (int j = 1; j <= 3; ++j) { + if (grid[i][j] % 2 == 1) { + ans[i][j] = !ans[i][j]; + ans[i][j + 1] = !ans[i][j + 1]; + ans[i][j - 1] = !ans[i][j - 1]; + ans[i - 1][j] = !ans[i - 1][j]; + ans[i + 1][j] = !ans[i + 1][j]; + } + } + } + for (int i = 1; i <= 3; ++i) { + for (int j = 1; j <= 3; ++j) cout << ans[i][j]; + cout << "\n"; + } + return 0; +} +const int k = 1e5 + 5; +int main() { + vector v; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + long long min_dist = 2e9 + 10, occurances = 1; + for (unsigned int i = 1; i < v.size(); i++) { + if ((v[i] - v[i - 1]) < min_dist) { + min_dist = (v[i] - v[i - 1]); + occurances = 1; + } else if ((v[i] - v[i - 1]) == min_dist) + occurances++; + } + cout << min_dist << " " << occurances << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int lcm(int a, int b) { + return a / gcd(a, b) * b; +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + int LCM = lcm(x, y); + cout << (b / LCM) - ((a - 1) / LCM) << endl; + return 0; +} +int main() { + int n, m, c = 0, flag = 0, ma = flag; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 == 0) { cout << '#'; } + if (i % 2 != 0) { + if (j == m - 1 && c % 2 == 0) { + cout << '#'; + } else if (j == 0 && c % 2 != 0) { + cout << '#'; + } else { + cout << '.'; + } + flag++; + } + } + if (flag != ma) { + flag = 0; + c++; + } + cout << endl; + } + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +int main() { + int n, i; + char a[101]; + while (cin >> n) { + int s = 1; + cin >> a; + if (a[0] == '0') { + cout << 1 << endl; + } else { + for (i = 1; i < n; i++) { + if (a[i] == '0') { + break; + } else { + s++; + } + } + s = s == n ? n : s + 1; + cout << s << endl; + } + } + return 0; +} +int main() { + long long a[10000], i, m = 0; + for (i = 0; i < 3; i++) cin >> a[i]; + sort(a, a + 3); + m = (a[1] - a[0]) + (a[2] - a[1]); + cout << m << endl; + return 0; +} +int main() { + int ay[110]; + int n, m, mx = -1; + int sum = 0; + cin >> n; + cin >> m; + for (int i = 0; i < n; ++i) { + cin >> ay[i]; + if (ay[i] > mx) mx = ay[i]; + } + for (int i = 0; i < n; ++i) { sum += mx - ay[i]; } + int as = mx + m; + if (m <= sum) + cout << mx; + else { + m -= sum; + int ans = mx; + if (m % n) ++ans; + ans += m / n; + cout << ans; + } + cout << " " << as << endl; + return 0; +} +int main() { + char x[102][102]; + memset(x, '*', sizeof(x)); + int n; + int flag; + cin >> n; + for (int a = 0; a < n; a++) { + x[a][n / 2] = 'D'; + if (a <= n / 2) { + for (int b = 1; b <= a; b++) { + x[a][n / 2 + b] = 'D'; + x[a][n / 2 - b] = 'D'; + } + } else { + for (int b = n / 2 - (a - n / 2); b >= 0; b--) { + x[a][n / 2 + b] = 'D'; + x[a][n / 2 - b] = 'D'; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cout << x[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n; + string s; + long long c = 1; + cin >> s; + c = 25 + 25 + 1; + int len = s.size() - 1; + c += 25 * len; + cout << c << endl; + return 0; +} +int mark[20]; +void m() { + for (int i = 0; i < 10; i++) mark[i] = 0; +} +int main() { + int t; + cin >> t; + t++; + while (1) { + int c = 0, n = t, d = 0; + while (n) { + if (mark[n % 10] == 0) c++, mark[n % 10] = 1; + n /= 10; + d++; + } + if (c == d) { + cout << t << endl; + return 0; + } + m(); + t++; + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] != s[i + 1]) { + cout << "YES\n" << s[i] << s[i + 1] << "\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int ASS[50]; +int sum; +bool flag; +int digui(int a, int b) { + if (a < b) { + flag = 1; + return 0; + } + if (a == b) return 0; + if (a % 2 == 0) { + sum++; + ASS[sum - 1] = a / 2; + return digui(a / 2, b); + } else if (a % 10 == 1) { + sum++; + ASS[sum - 1] = (a - 1) / 10; + return digui((a - 1) / 10, b); + } else + flag = 1; +} +int main() { + int m, n; + cin >> m >> n; + digui(n, m); + if (flag == 0) { + cout << "YES" << endl << sum + 1 << endl; + for (int i = sum - 1; i >= 0; i--) cout << ASS[i] << " "; + cout << n << endl; + } else + cout << "NO" << endl; + return 0; +} +long long x[3], y[3], k; +int main() { + cin >> x[1] >> x[2] >> x[0] >> k; + sort(&x[0], &x[3], greater()); + long long rk = k % 3; + y[0] = k / 3; + y[1] = k / 3; + y[2] = k / 3; + if (rk == 1) y[2]++; + if (rk == 2) { + y[1]++; + y[2]++; + } + sort(&y[0], &y[3], greater()); + long long rm = 0; + for (int i = 2; i >= 0; i--) { + long long yy = min(y[i], x[i] - 1); + rm += y[i] - yy; + y[i] = yy; + if (i == 2) { + y[0] += rm / 2; + y[1] += rm - rm / 2; + rm = 0; + } else if (i == 1) + y[0] += rm; + } + cout << (y[0] + 1) * (y[1] + 1) * (y[2] + 1) << endl; + return 0; +} +int main() { + int n; + string s; + vector ans; + cin >> n; + if (!n) ans.push_back("O-|-OOOO\n"); + while (n) { + int d = n % 10; + s = ""; + if (d >= 5) + s += "-O"; + else + s += "O-"; + s += "|"; + if (d == 0 || d == 5) s += "-OOOO"; + if (d == 1 || d == 6) s += "O-OOO"; + if (d == 2 || d == 7) s += "OO-OO"; + if (d == 3 || d == 8) s += "OOO-O"; + if (d == 4 || d == 9) s += "OOOO-"; + s += "\n"; + ans.push_back(s); + n /= 10; + } + for (int i = 0; i < ans.size(); i++) cout << ans[i]; + return 0; +} +const int maxn = 105; +unsigned long long pow_base, base = 131, tmp; +unsigned long long ihash[maxn]; +int vis[maxn], ans; +string s1, s2; +int main() { + memset(vis, 0, sizeof(vis)); + pow_base = base * base; + int len; + cin >> s1; + len = s1.size(); + s1 = " " + s1; + ; + s2 = "VK"; + tmp = 0; + for (int i = 0; i < s2.size(); i++) tmp = tmp * base + s2[i]; + ihash[0] = 0; + for (int i = 1; i <= len; i++) ihash[i] = ihash[i - 1] * base + s1[i]; + for (int i = 2; i <= len; i++) { + unsigned long long tmp2 = ihash[i] - ihash[i - 2] * pow_base; + if (tmp2 == tmp) { + vis[i - 1] = vis[i] = 1; + ans++; + } + } + for (int i = 1; i <= len; i++) { + if (s1[i] == 'V' && !vis[i] && (i + 1) <= len && !vis[i + 1]) { + ans++; + break; + } else if (s1[i] == 'K' && !vis[i] && (i - 1) >= 1 && !vis[i - 1]) { + ans++; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, r = 0, t = 0; + cin >> n; + for (int i = 1;; ++i) { + r += i; + t += r; + if (t > n) { + cout << (i - 1) << endl; + break; + } + } + return 0; +} +int main() { + int x, y, z; + int i, j; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + cin >> z; + if (z == 1) { + x = i + 1; + y = j + 1; + } + } + } + cout << (abs(3 - x) + abs(3 - y)) << endl; + return 0; +} +int main() { + int n; + cin >> n; + set data; + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + if (input != 0) data.insert(input); + } + cout << data.size() << endl; + return 0; +} +string a, b, x, y, m; +int i, n; +int main() { + cin >> a >> b >> n; + cout << a << " " << b << endl; + x = a; + y = b; + for (i = 0; i < n; i++) { + cin >> a >> b; + if (x == a) + x = b; + else + y = b; + cout << x << " " << y << endl; + } +} +int main() { + int n, total = 0, p = 0, q = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> p >> q; + if ((q - p) >= 2) ++total; + } + cout << total << endl; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long sum1, sum2, sum3; + sum1 = 2 * n / k; + if (2 * n % k != 0) { sum1++; } + sum2 = 5 * n / k; + if (5 * n % k != 0) { sum2++; } + sum3 = 8 * n / k; + if (8 * n % k != 0) { sum3++; } + cout << sum1 + sum2 + sum3 << endl; + } + return 0; +} +int main() { + int a = 0; + ; + char xx[10][10]; + for (int i = 0; i < 8; i++) { + cin >> xx[i]; + for (int j = 0; j < 8; j++) { + if (xx[i][j] == xx[i][j + 1]) { a = 1; } + } + } + if (a == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + long long n, i, m, z; + cin >> n; + long long a[n]; + cin >> m; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + long long l = 0; + for (i = 0; i < n - 1; i++) { l = l + a[n - 1] - a[i]; } + z = m - l; + if (z > 0) + cout << a[n - 1] + ceil(((float)z / n)) << " " << a[n - 1] + m << endl; + else if (z <= 0) + cout << a[n - 1] << " " << a[n - 1] + m << endl; +} +int main() { + int n, m, ma = -1, mi = 101, mx, mn, t; + cin >> n >> m >> mn >> mx; + for (int i = 0; i < m; i++) cin >> t, ma = max(t, ma), mi = min(t, mi); + if (mi < mn || ma > mx) { + cout << "Incorrect" << endl; + return 0; + } + int li = 0; + if (mi != mn) li++; + if (ma != mx) li++; + if (n - m >= li) + cout << "Correct" << endl; + else + cout << "Incorrect" << endl; + return 0; +} +int main() { + int MaxDominoesNumber = 0; + int M, N = 0; + cin >> M >> N; + bool **board = new bool *[M]; + for (int i = 0; i < M; i++) { board[i] = new bool[N]; } + if (M > N) swap(M, N); + for (int i = 0; i < M; i += 2) { + int check = M - i; + if (check == 1) { + int remain_domino = 0; + if (N % 2 == 0) + remain_domino = N / 2; + else + remain_domino = (N - 1) / 2; + MaxDominoesNumber += remain_domino; + break; + } + for (int j = 0; j < N; j++) { + board[i][j] = true; + board[i + 1][j] = true; + MaxDominoesNumber++; + } + } + cout << MaxDominoesNumber << endl; + return 0; +} +int main() { + int n, r = 0; + string s; + cin >> n; + getchar(); + while (n--) { + getline(cin, s); + if (s == "Tetrahedron") { + r = r + 4; + } else if (s == "Cube") + r = r + 6; + else if (s == "Octahedron") + r = r + 8; + else if (s == "Dodecahedron") + r = r + 12; + else if (s == "Icosahedron") + r = r + 20; + } + cout << r << endl; + return 0; +} +int a[5], x; +int main() { + for (int i = 0; i < 5; i++) cin >> a[i]; + for (int i = 1; i <= a[4]; i++) + if (!(i % a[0]) || !(i % a[1]) || !(i % a[2]) || !(i % a[3])) x++; + cout << x << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a != b) { + cout << "Happy Alex" << endl; + return 0; + } + } + cout << "Poor Alex" << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long ans; + unsigned long long rest = 2; + for (long long i = 1; i <= n; i++) { + long long d = (i + 1) * (i + 1) * i - (rest / i); + cout << d << endl; + rest = i * (i + 1); + } +} +int main() { + int a, b, c, k; + cin >> a >> b >> c >> k; + while (a + b + c - 3 > k) { + if (a >= b && a >= c) + a--; + else if (b >= a && b >= c) + b--; + else + c--; + } + cout << 1ll * a * b * c << '\n'; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + if (n - k < k) { + int cnt = k - 1; + while (cnt < str.size() - 1) { + cout << "RIGHT\n"; + cnt++; + } + while (cnt >= 0) { + cout << "PRINT " << str[cnt] << "\n"; + if (cnt != 0) cout << "LEFT\n"; + cnt--; + } + } else { + int cnt = k - 1; + while (cnt > 0) { + cout << "LEFT\n"; + cnt--; + } + while (cnt < str.size()) { + cout << "PRINT " << str[cnt] << "\n"; + if (cnt != str.size() - 1) cout << "RIGHT\n"; + cnt++; + } + } + return 0; +} +int main() { + int n, arr[106], temp, mx = 0, mn = 1000000, j = 2; + cin >> n; + for (int i = 1; i <= n; i++) cin >> arr[i]; + while (j < n) { + for (int z = 2; z <= n; z++) { + if (z == j) { + temp = arr[j + 1] - arr[j - 1]; + z++; + } else + temp = arr[z] - arr[z - 1]; + mx = max(mx, temp); + } + j++; + mn = min(mn, mx); + mx = 0; + } + cout << mn << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + long long sum = 0; + int i; + for (i = 1;; i++) { + long long current = 1LL * i * (i + 1) / 2; + if (sum + current <= n) + n -= sum + current; + else + break; + } + cout << i - 1 << endl; + } + return 0; +} +int main() { + string inp; + cin >> inp; + int n = inp.length(), flag = 0; + if (inp.at(0) != '-') + cout << inp << endl; + else { + if (n == 3) { + if (inp.at(2) == '0' || inp.at(1) == '0') { + flag = 1; + cout << '0' << endl; + } + } + if (flag == 0) { + int idx; + if (inp.at(n - 1) > inp.at(n - 2)) + idx = n - 1; + else + idx = n - 2; + for (int i = 0; i < n; i++) + if (i != idx) cout << inp.at(i); + cout << endl; + } + } + return 0; +} +int a[105]; +int main() { + int n, t, ans, maxx; + while (cin >> n) { + int sum = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + ans = a[0]; + int font = 1, t; + while (font == 1) { + maxx = -1; + for (int i = 1; i < n; i++) { + if (maxx < a[i]) { + maxx = a[i]; + t = i; + } + } + if (a[0] > maxx) + font = 0; + else { + a[t]--; + a[0]++; + } + } + cout << a[0] - ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string p, d; + cin >> p; + d = p; + string a, b, c; + map x, y; + vector r; + for (int i = 0; i < n; i++) { + cin >> a; + b = a.substr(0, 3); + c = a.substr(5, 3); + if (!x[b]) r.push_back(b); + if (!x[c]) r.push_back(c); + x[b]++; + y[c]++; + } + for (int i = 0; i < r.size(); i++) { + if (x[r[i]] != y[r[i]]) { + cout << "contest" << endl; + return 0; + } + } + cout << "home" << endl; + return 0; +} +int main() { + int n; + string s; + bool a[6] = {1, 1, 1, 1, 1, 1}; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "purple") a[0] = 0; + if (s == "green") a[1] = 0; + if (s == "blue") a[2] = 0; + if (s == "orange") a[3] = 0; + if (s == "red") a[4] = 0; + if (s == "yellow") a[5] = 0; + } + cout << 6 - n << endl; + for (int i = 0; i < 6 - n; i++) { + if (a[0]) { + cout << "Power" << endl; + a[0] = 0; + } + if (a[1]) { + cout << "Time" << endl; + a[1] = 0; + } + if (a[2]) { + cout << "Space" << endl; + a[2] = 0; + } + if (a[3]) { + cout << "Soul" << endl; + a[3] = 0; + } + if (a[4]) { + cout << "Reality" << endl; + a[4] = 0; + } + if (a[5]) { + cout << "Mind" << endl; + a[5] = 0; + } + } + return 0; +} +int main() { + int n, sum = 0; + string s1, s2; + cin >> n >> s1 >> s2; + for (int i = 0; i < n; i++) { + int a = 0, b = 0; + a = (int)s1[i]; + a = a - 48; + b = (int)s2[i]; + b = b - 48; + if (b > a) { + int temp = a; + a = b; + b = temp; + } + int dif = 0; + dif = a - b; + int dif1 = 0; + dif1 = (10 - a) + b; + if (dif < dif1) + sum = sum + dif; + else + sum = sum + dif1; + } + cout << sum << endl; +} +const int N = 3; +int distance(int a, int b, int c); +int main() { + int n1, n2, n3; + while (cin >> n1 >> n2 >> n3) cout << distance(n1, n2, n3) << endl; + return 0; +} +int distance(int a, int b, int c) { + if ((a >= b) && (a <= c)) return abs(a - b) + abs(a - c); + if ((a >= c) && (a <= b)) return abs(a - b) + abs(a - c); + if ((b >= a) && (b <= c)) return abs(b - a) + abs(b - c); + if ((b >= c) && (b <= a)) return abs(b - a) + abs(b - c); + if ((c >= b) && (c <= a)) return abs(c - a) + abs(c - b); + if ((c >= a) && (c <= b)) return abs(c - a) + abs(c - b); +} +const long long mod = 1e9 + 7; +const int maxn = 1e5 + 5; +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (a == min(a, min(b, c))) { + cout << (n - 1) * a << endl; + } else if (b == min(a, min(b, c))) { + cout << (n - 1) * b << endl; + } else { + if (n > 2) + cout << min(a, b) + (n - 2) * c << endl; + else + cout << (n - 1) * min(a, b) << endl; + } + return 0; +} +const int N = 9e5 + 11; +const int MOD = 1e9 + 7; +int gl(char ch) { + if (ch == 'o' || ch == 'a' || ch == 'u' || ch == 'i' || ch == 'e') return 0; + return 1; +} +int main() { + string s; + cin >> s; + for (int j = 0; j < s.size() - 1; j++) { + int t1 = gl(s[j]), t2 = gl(s[j + 1]); + if (t1 == 1 && t2 == 1 && s[j] != 'n') { + cout << "NO" << endl; + return 0; + } + } + int t = gl(s[s.size() - 1]); + if (t == 1 && s[s.size() - 1] != 'n') + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, m; + cin >> n >> m; + vector Vector(n); + for (int i = 0; i < n; i++) cin >> Vector[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (Vector[i][j] != '-') { + if (i % 2 == 0) + if (j % 2 == 0) + Vector[i][j] = 'B'; + else + Vector[i][j] = 'W'; + else if (j % 2 == 0) + Vector[i][j] = 'W'; + else + Vector[i][j] = 'B'; + } + cout << Vector[i][j]; + } + cout << endl; + } + return 0; +} +int main() { + int r, b; + int p, q; + cin >> r >> b; + p = min(r, b); + q = abs(r - b) / 2; + cout << p << " " << q << "\n"; + return 0; +} +long long l, r, javab = 0; +void first(long long x) { + long long y = x, t = 0; + while (y > 0) { + t *= 10; + t += 9; + y /= 10; + } + if (l <= x && r >= x) javab = max(javab, x * (t - x)); +} +int main() { + long long x = 1, y; + cin >> l >> r; + first(l); + first(r); + for (int i = 1; i <= 10; i++) { + x *= 10; + y = x - 1; + y /= 2; + first(y); + } + cout << javab << endl; + return 0; +} +int main() { + int n, k; + cin >> n; + k = 0; + while (n >= 100) { + k++; + n = n - 100; + } + while (n >= 20) { + k++; + n = n - 20; + } + while (n >= 10) { + k++; + n = n - 10; + } + while (n >= 5) { + k++; + n = n - 5; + } + cout << k + n << endl; + return 0; +} +int main() { + int n, t, k, d, x; + cin >> n >> t >> k >> d; + if (k >= n) { + cout << "NO" << endl; + return 0; + } + if (n % k == 0) + x = n / k; + else + x = n / k + 1; + if ((x - 1) * t > d) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n; +int computer[201], check[3][201], vis[201]; +vector vv[201]; +int bfs(int k, int now) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (check[k][i] == 0) q.push(i); + } + while (!q.empty()) { + memset(vis, 0, sizeof(vis)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (vis[head] == n) { + q.push(head); + break; + } + vis[head]++; + if (computer[head] != now) { + q.push(head); + continue; + } + for (int i = 0; i < vv[head].size(); i++) { + check[k][vv[head][i]]--; + if (check[k][vv[head][i]] == 0) q.push(vv[head][i]); + } + } + now = (now == 3 ? 1 : now + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(check, 0, sizeof(check)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + check[0][i]++, check[1][i]++, check[2][i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= 3; i++) ans = min(ans, bfs(i - 1, i)); + cout << ans << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[m]; + for (int i = 0; i < m; i++) { cin >> a[i]; } + sort(a, a + m); + int i = 0, j = n - 1; + int psum = a[j] - a[i]; + while (j < m) { + int sum = a[j] - a[i]; + if (sum <= psum) psum = sum; + i++; + j++; + } + cout << psum << "\n"; +} +int main() { + long long n, xx; + cin >> n; + long long m1 = 0, m2 = 1023; + long long rr[1024], ss[1024]; + for (long long i = 0; i < 1024; i++) { + rr[i] = i; + ss[i] = i; + } + while (n--) { + char r; + cin >> r >> xx; + if (r == '|') { + m1 = m1 | xx; + m2 = m2 | xx; + for (long long i = 0; i < 1024; i++) { rr[i] = rr[i] | xx; } + } else if (r == '^') { + m1 = m1 ^ xx; + m2 = m2 ^ xx; + for (long long i = 0; i < 1024; i++) { rr[i] = rr[i] ^ xx; } + } else { + m1 = m1 & xx; + m2 = m2 & xx; + for (long long i = 0; i < 1024; i++) { rr[i] = rr[i] & xx; } + } + } + long long x = 0, a = 0, o = 0; + for (long long i = 0; i < 10; i++) { + long long u = m1 & (1 << i); + long long v = m2 & (1 << i); + if (m1 & (1 << i) && v == 0) { + x = x | (1 << i); + a = a | (1 << i); + } else if (u == 0 && m2 & (1 << i)) { + a = a | (1 << i); + } else if (m1 & (1 << i) && m2 & (1 << i)) { + a = a | (1 << i); + o = o | (1 << i); + } + } + cout << "3" << '\n'; + cout << "| " << o << '\n'; + cout << "^ " << x << '\n'; + cout << "& " << a << '\n'; +} +int main() { + cout << "Karen" << endl; + return 0; +} +long long mz[100005] = {}; +long long ts[100005] = {}; +int main() { + long long T; + cin >> T; + while (T--) { + long long L, v, l, r, ans = 0; + cin >> L >> v >> l >> r; + ans += L / v; + if (r % v != 0) r = r - r % v; + if (l % v != 0) l = l + (v - l % v); + ans -= ((r - l) / v + 1); + cout << ans << endl; + } +} +int main() { + string str1, str2; + cin >> str1 >> str2; + int num; + cin >> num; + string res_arr[num * 2 + 2]; + res_arr[0] = str1; + res_arr[1] = str2; + for (int i = 0; i < num * 2; i++) { cin >> res_arr[i + 2]; } + for (int i = 2; i < num * 2 + 2; i += 2) { + str1 = res_arr[i - 2]; + str2 = res_arr[i - 1]; + string to_be_replaced = res_arr[i]; + string replaced_by = res_arr[i + 1]; + if (str1 == to_be_replaced) { + str1 = replaced_by; + } else if (str2 == to_be_replaced) { + str2 = replaced_by; + } + res_arr[i] = str1; + res_arr[i + 1] = str2; + } + for (int i = 0; i < num * 2 + 2; i += 2) { + cout << res_arr[i] << " " << res_arr[i + 1]; + cout << endl; + } + return 0; +} +string A, B; +int n; +int win(char x, char y) { + if (x == y) return 2; + if (x == 'R' && y == 'S') return 0; + if (x == 'S' && y == 'P') return 0; + if (x == 'P' && y == 'R') return 0; + return 1; +} +int main() { + cin >> n >> A >> B; + int a = A.size(), b = B.size(); + int s[3] = {}, p[3] = {}; + for (int i = 0; i < a * b; i++) s[win(A[i % a], B[i % b])]++; + for (int i = 0; i < n % (a * b); i++) p[win(A[i % a], B[i % b])]++; + for (int i = 0; i <= 2; i++) p[i] += s[i] * (n / (a * b)); + cout << p[1] << " " << p[0] << endl; + return 0; +} +int n; +int m = 0, c = 0; +int x[100000], y[100000]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x[i] >> y[i]; + if (x[i] > y[i]) m++; + if (x[i] < y[i]) c++; + } + if (m > c) + cout << "Mishka" << endl; + else if (m < c) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n1, n2, n3; + cin >> n1 >> n2 >> n3; + int k = abs(n1 - n2); + int j = abs(n1 - n3); + int h = k + j; + int a = abs(n2 - n1); + int b = abs(n2 - n3); + int c = a + b; + int d = min(h, c); + int e = abs(n3 - n1); + int f = abs(n3 - n2); + int g = e + f; + int m = min(g, d); + cout << m << "\n"; +} +int mini(int *t, int n) { + int m = t[0]; + for (int i = 0; i < n; i++) { + if (m > t[i]) { m = t[i]; } + } + return m; +} +int argmini(int *t, int n) { + int m = 0; + for (int i = 0; i < n; i++) { + if (t[m] > t[i]) { m = i; } + } + return m; +} +int maxi(int *t, int n) { + int m = t[0]; + for (int i = 0; i < n; i++) { + if (m < t[i]) { m = t[i]; } + } + return m; +} +int main() { + int n, m, minim, maxim; + int t[105]; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> t[i]; } + maxim = maxi(t, n) + m; + while (m > 0) { + t[argmini(t, n)]++; + m--; + } + cout << maxi(t, n) << " " << maxim << endl; + return 0; +} +int main() { + int n; + char mp[110][110]; + cin >> n; + memset(mp, '*', sizeof(mp)); + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) cin >> mp[j][i]; + bool flag = true; + for (int i = 1; i <= n && flag; ++i) { + int cnt = 0; + for (int j = 1; j <= n; ++j) { + if (mp[j - 1][i] == 'o') cnt++; + if (mp[j + 1][i] == 'o') cnt++; + if (mp[j][i - 1] == 'o') cnt++; + if (mp[j][i + 1] == 'o') cnt++; + if (cnt % 2 != 0) { + flag = false; + break; + } + } + } + puts(flag ? "YES" : "NO"); + return 0; +} +int main() { + int ara[6005][5]; + int k, i, n; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> k; + ara[0][k]++; + ara[ara[0][k]][k] = i; + } + n = min(ara[0][1], ara[0][2]); + n = min(n, ara[0][3]); + cout << n << endl; + for (i = 1; i <= n; i++) { cout << ara[i][1] << " " << ara[i][2] << " " << ara[i][3] << endl; } +} +int n, s, batas; +int t[105][2]; +int main() { + cin >> n >> s; + for (int i = 1; i <= n; i++) { cin >> t[i][0] >> t[i][1]; } + t[0][0] = 0; + t[0][1] = -s - 1; + t[n + 1][0] = 100; + t[n + 1][1] = 0; + batas = 2 * s + 2; + int mnt; + int ah, am; + for (int i = 0; i <= n; i++) { + mnt = (t[i + 1][1] + 60 - t[i][1]) + (t[i + 1][0] - 1 - t[i][0]) * 60; + if (mnt >= batas) { + am = t[i][1] + s + 1; + ah = t[i][0]; + while (am >= 60) { + am -= 60; + ah++; + } + cout << ah << ' ' << am << '\n'; + return 0; + } + } + return 0; +} +int main() { + int n, temp; + cin >> n; + int count = 0; + for (int i = 1; i <= n; i++) { + int votes = 0; + for (int j = 1; j <= 3; j++) { + cin >> temp; + votes += temp; + } + if (votes >= 2) count++; + } + cout << count << endl; +} +int main() { + int n; + while (cin >> n) { + int x = n * sqrt(double(2)); + if (n == 0) + cout << 1 << endl; + else + cout << x * 4 << endl; + } + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + int N, MAX; + cin >> N >> MAX; + int A[N]; + for (int i = 0; i < N; i++) { + char t; + cin >> t; + A[i] = t - 'a'; + } + if (N == 1) { + if (A[0] < MAX - 1) { + cout << (char)(A[0] + 'a' + 1) << endl; + } else { + cout << "NO" << endl; + } + return 0; + } + int beginat = N - 1; + while (true) { + int mark = true; + int t = 1; + int i; + for (i = beginat; i >= 0; i--) { + if (!t) break; + int old_t = t; + t = (A[i] + old_t) / MAX; + int oldai = A[i]; + A[i] = (A[i] + old_t) % MAX; + if (i == 0 && oldai >= A[i]) { + cout << "NO" << endl; + return 0; + } + } + if (beginat != N - 1) beginat = N - 1; + bool im = true; + for (int i = 0; i < N; i++) { + if (A[i] != MAX - 1) { + im = false; + break; + } + } + if (im) { + cout << "NO" << endl; + return 0; + } + int max_idx = i; + for (int i = N - 1; i >= 1; i--) { + if ((i - 1 >= 0 && A[i] == A[i - 1]) || (i - 2 >= 0 && A[i] == A[i - 2])) { + mark = false; + beginat = i; + } + } + if (mark) { + for (int i = 0; i < N; i++) { cout << (char)(A[i] + 'a'); } + cout << endl; + return 0; + } + } + return 0; +} +int main() { + double a = 0, b = 0, c = 0; + cin >> a >> b >> c; + if (b == c) { + cout << 0.5 * a << endl; + return 0; + } + cout << b / (c + b) * a << endl; +} +const int maxn = 101000; +const int INF = 0x3f3f3f3f; +int a[maxn]; +int b[maxn]; +int main() { + int n; + int c = 0; + cin >> n; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + for (int i = 0; i < n; ++i) cin >> a[i]; + memcpy(b, a, sizeof(a)); + sort(b, b + n); + for (int i = 0; i < n; ++i) { + if (a[i] != b[i]) c++; + } + if (c > 2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + int x, y, p, q; + cin >> x >> y >> p >> q; + if (p == 0) { + cout << (x == 0 ? 0 : -1) << endl; + continue; + } + if (p == q) { + cout << (x == y ? 0 : -1) << endl; + continue; + } + int r1 = (x + p - 1) / p; + int r2 = ((y - x) + (q - p) - 1) / (q - p); + cout << (q * 1LL * max(r1, r2) - y) << endl; + } +} +int main() { + long n, i, k = 0, c = 0, d = 1; + string s; + cin >> n; + cin >> s; + for (i = 0; i < s.size(); i++) { + if (s[i] == '1') { + k++; + } else if (s[i] == '0' & s[i + 1] == '0') { + c = 0; + cout << k << c; + k = 0; + d = 2; + i++; + } else if (s[i] == '0' && d) { + cout << k; + k = 0; + } + } + cout << k << endl; +} +int main() { + int noOfStudents, noOfprizes, minimum = 100000; + cin >> noOfStudents >> noOfprizes; + int a[noOfprizes]; + for (int i = 0; i < noOfprizes; i++) { cin >> a[i]; } + sort(a, a + noOfprizes); + for (int i = 0; i + noOfStudents - 1 < noOfprizes; i++) { minimum = min(a[i + noOfStudents - 1] - a[i], minimum); } + cout << minimum << endl; + return 0; +} +vector di[3]; +vector linha0[10010]; +vector linha1[10010]; +vector linha2[10010]; +void multiplos(int a, int b, int h) { + int menor = a; + if (a > b) b = menor; + for (int i = 1; i <= menor; i++) { + if (a % i == 0 && b % i == 0) { di[h].push_back(i); } + } +} +int main() { + int a, b, c, s; + cin >> a >> b >> c; + multiplos(a, b, 0); + multiplos(a, c, 1); + multiplos(b, c, 2); + for (int i = 0; i < (int)di[0].size(); i++) { + for (int j = 0; j < (int)di[1].size(); j++) { + if (di[0][i] * di[1][j] == a) { + for (int u = 0; u < (int)di[2].size(); u++) { + if (di[0][i] * di[2][u] == b) { + if (di[1][j] * di[2][u] == c) { s = di[2][u] + di[1][j] + di[0][i]; } + } + } + } + } + } + int total = 4 * s; + cout << total << endl; +} +long long n; +string s; +map cc; +int main() { + cin >> n; + for (long long i = 1; i < n + 1; ++i) cin >> s, cc[s]++; + long long v1 = 1 + cc["UL"] + cc["DR"] + cc["ULDR"]; + long long v2 = 1 + cc["UR"] + cc["DL"] + cc["ULDR"]; + cout << v1 * v2 << "\n"; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int count = 0; + for (int i = 0; i < n; ++i) { + long long int a, b; + cin >> a >> b; + count += b - a + 1; + } + if (count % k == 0) + cout << 0 << endl; + else { + cout << k - (count % k) << endl; + } + return 0; +} +char z[1000005]; +long long n, m; +string str; +long long pf(long long); +void solve() { + long long n, m, k = 1, i, y = 0, j, c = 0, x = 0, w, x2, y2, l, r, d; + string s; + cin >> s; + n = s.size(); + for (long long int i = 0; i < n; i++) { + if (s[i] > 96) { + x++; + } else { + y++; + } + } + if (x >= y) { + for (long long int i = 0; i < n; i++) { cout << (char)tolower(s[i]); } + } else { + for (long long int i = 0; i < n; i++) { cout << (char)toupper(s[i]); } + } +} +int main() { + int TESTS = 1; + while (TESTS--) { + solve(); + cout << "\n"; + } + return 0; +} +int main() { + int n; + int a[100005]; + int res1 = 1, res2 = 1; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 1; i < n; i++) { + if (a[i - 1] <= a[i]) { + res1++; + } else { + if (res1 > res2) { res2 = res1; } + res1 = 1; + } + if (res1 > res2) { res2 = res1; } + } + cout << res2 << endl; +} +long long t, a[1005], b[1005], k[1005], ans[1005], la, ra; +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { cin >> a[i] >> b[i] >> k[i]; } + for (int i = 1; i <= t; i++) { + la = k[i] / 2; + ra = k[i] - k[i] / 2; + ans[i] -= la * b[i]; + ans[i] += ra * a[i]; + } + for (int i = 1; i <= t; i++) { cout << ans[i] << endl; } + return 0; +} +int main() { + int a[31], b[31]; + int n; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i != j && a[i] == b[j]) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int i, j, k, l, m, n; + cin >> n >> m >> l; + int a[l]; + for (i = 0; i < l; i++) { cin >> a[i]; } + int b[1000] = {0}; + int q, w; + q = 0; + w = 0; + for (i = 0; i <= n;) { + i = i + m; + if (((i) >= a[w]) && (w < l)) { + i = a[w]; + w++; + b[i] = 1; + } else { + b[i] = 1; + } + } + w = 0; + for (i = 0; i <= n; i++) { + if (b[i] == 1) { w++; } + } + cout << w << "\n"; + return 0; +} +int main() { + int n, a; + vector v; + vector v1; + vector v2; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + v2.push_back(a); + if (a % 2 == 0) + v.push_back(a); + else + v1.push_back(a); + } + int l = v.size(); + int t = v1.size(); + if (v.size() > 1) { + for (int i = 0; i < n; i++) { + if (v2[i] == v1[0]) cout << i + 1 << endl; + } + } + if (v1.size() > 1) { + for (int i = 0; i < n; i++) { + if (v2[i] == v[0]) cout << i + 1 << endl; + } + } +} +char a, b; +int aa, bb; +int n; +int MOD(int x) { + if (x >= 4) x -= 4; + if (x < 0) x += 4; + return x; +} +int main() { + cin >> a >> b >> n; + n %= 4; + if (a == 'v') aa = 0; + if (a == '<') aa = 1; + if (a == '^') aa = 2; + if (a == '>') aa = 3; + if (b == 'v') bb = 0; + if (b == '<') bb = 1; + if (b == '^') bb = 2; + if (b == '>') bb = 3; + if (MOD(aa + n) == bb && MOD(aa - n) == bb) + puts("undefined"); + else if (MOD(aa + n) == bb) + puts("cw"); + else if (MOD(aa - n) == bb) + puts("ccw"); + else + puts("undefined"); +} +int main() { + int n, m, sum = 0, a, ans; + cin >> n >> m; + while (n--) { + cin >> a; + sum += a; + } + if (sum < 0) sum *= -1; + ans = sum / m; + if (sum % m) ans++; + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int c = 0; + while (n != 0) { + if (n % 10 == 4 || n % 10 == 7) { c++; } + n /= 10; + } + if (c == 4 || c == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, d, mx = 0, ans = 0, cnt; + char x[105][105]; + cin >> n >> d; + for (int i = 1; i <= d; i++) { + for (int j = 1; j <= n; j++) { cin >> x[i][j]; } + } + for (int i = 1; i <= d; i++) { + cnt = 0; + for (int j = 1; j <= n; j++) { + if (x[i][j] == '1') { cnt++; } + } + if (cnt != n) { + ans++; + } else { + ans = 0; + } + mx = max(ans, mx); + } + cout << mx << endl; + return 0; +} +int main() { + string s = "0", t = "0"; + cin >> s >> t; + int k = 0; + for (int i = 0; i < t.length(); i++) { + if (s[k] == t[i]) { k++; } + } + k = k + 1; + cout << k << endl; + return 0; +} +bool cmp(const int &A, const int &B) { + return A > B; +} +int num[1005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> num[i]; } + sort(num, num + n, cmp); + int i = 0; + for (i = 0; i < n; i++) { + int p = sqrt(num[i]); + if (p * p != num[i]) break; + } + cout << num[i] << endl; + return 0; +} +int S[110], N[110]; +int main() { + int n, m; + string a[110]; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int j = 0; j < m; j++) { + for (int i = 0; i < n; i++) { + if ((int)(a[i][j] - '0') > N[j]) { N[j] = (int)(a[i][j] - '0'); } + } + } + for (int j = 0; j < m; j++) { + for (int i = 0; i < n; i++) { + if ((int)(a[i][j] - '0') == N[j]) S[i]++; + } + } + int cnt = 0; + for (int i = 0; i <= 101; i++) { + if (S[i] > 0) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int A[6]; + for (int i = 0; i < 6; ++i) { cin >> A[i]; } + sort(A, A + 6); + int B, C; + if (A[0] == A[3]) + B = A[4], C = A[5]; + else if (A[1] == A[4]) + B = A[0], C = A[5]; + else if (A[2] == A[5]) + B = A[0], C = A[1]; + else { + cout << "Alien" << endl; + return 0; + } + if (B == C) { + cout << "Elephant" << endl; + return 0; + } + if (B < C) { + cout << "Bear" << endl; + return 0; + } +} +int father[1005]; +int n, m, k; +int find(int x) { + return father[x] == x ? x : father[x] = find(father[x]); +} +int node[1005]; +int fathercnt[1005]; +int cnt; +int isgro[1005]; +int main() { + memset(isgro, 0, sizeof(isgro)); + cin >> n >> m >> k; + int gro; + for (int j = 1; j <= n; j++) { father[j] = j; } + for (int i = 0; i < k; i++) { + int g; + cin >> g; + isgro[g] = 1; + gro = g; + } + for (int j = 1; j <= n; j++) { fathercnt[j] = 1; } + for (int i = 0; i < m; i++) { + int p, q; + cin >> p >> q; + if (isgro[p]) { + int x; + x = find(q); + if (father[find(q)] != father[find(p)]) { + father[find(q)] = father[find(p)]; + fathercnt[find(p)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else if (isgro[q]) { + int x; + x = find(p); + if (father[find(p)] != father[find(q)]) { + father[find(p)] = father[find(q)]; + fathercnt[find(q)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else { + int x; + if (isgro[father[find(p)]]) { + x = find(q); + if (father[find(q)] != father[find(p)]) { + father[find(q)] = father[find(p)]; + fathercnt[find(p)] += fathercnt[x]; + fathercnt[x] = 0; + } + } else { + x = find(p); + if (father[find(p)] != father[find(q)]) { + father[find(p)] = father[find(q)]; + fathercnt[find(q)] += fathercnt[x]; + fathercnt[x] = 0; + } + } + } + } + int maxfather = 0; + int strunity; + for (int i = 1; i <= n; i++) { + if (fathercnt[i] > maxfather) { + maxfather = fathercnt[i]; + strunity = i; + } + } + int maxgro = 0; + int strgro = gro; + for (int i = 1; i <= n; i++) { + if (isgro[i] && fathercnt[i] > maxgro) { + maxgro = fathercnt[i]; + strgro = i; + } + } + for (int i = 1; i <= n; i++) { + if (fathercnt[i] != 0) { + if (isgro[find(i)] != 1) { + fathercnt[strgro] += fathercnt[i]; + fathercnt[i] = 0; + } + } + } + cnt = 0; + for (int i = 1; i <= n; i++) { + if (isgro[i]) { cnt += (fathercnt[i] * (fathercnt[i] - 1)) / 2; } + } + cout << cnt - m << endl; + return 0; +} +int a[100]; +long long sum = 0; +int n = 6; +int main() { + for (int i = 0; i < n; i++) { + long long x; + cin >> x; + a[i] = x; + sum += x; + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + for (int k = 0; k < n; k++) + if (i != j && j != k && i != k) { + if ((a[i] + a[j] + a[k]) * 2 == sum) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + string s; + getline(cin, s); + int i = 0, n = s.length(), c = 0; + int a[(n - n / 2)]; + while (s[i] != '\0') { + if (i % 2 == 0) { + a[c] = s[i] - '0'; + c++; + } + i++; + } + sort(a, a + (n - n / 2)); + for (int j = 0; j < (n - n / 2); j++) { + cout << a[j]; + if (j != (n - n / 2) - 1) cout << "+"; + } + cout << endl; +} +long n, k, ans; +long sheets(long a, long b) { + long d, m; + d = a / b; + m = a % b; + if (m) return (d + 1); + return d; +} +int main() { + cin >> n >> k; + ans += sheets(2 * n, k); + ans += sheets(5 * n, k); + ans += sheets(8 * n, k); + cout << ans << endl; + return 0; +} +int main() { + long long int N; + cin >> N; + cout << (N / 2) * 3 << endl; +} +int main() { + int dis = 0; + int n; + long long int x; + cin >> n; + cin >> x; + char sign, spc; + int num; + for (int i = 0; i < n; i++) { + cin >> sign; + cin >> num; + getchar(); + if (sign == '+') + x += num; + else if (sign == '-') { + if (num > x) + dis++; + else + x -= num; + } + } + cout << x << " " << dis << endl; + return 0; +} +int main() { + long long s, x; + cin >> s >> x; + long long a = (s - x) / 2; + if (x > s || a * 2 + x != s || (x & a) != 0) { + cout << 0 << endl; + return 0; + } + long long bit = 0; + while (x) { + if (x & 1) bit++; + x >>= 1; + } + long long ans = 1LL << bit; + if (a == 0) ans -= 2; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + int cnt = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + a[i] = -1; + cnt++; + } + if (a[i] == 0) { a[i] = 1; } + } + int gmax = INT_MIN, lmax = 0; + for (int i = 0; i < n; i++) { + lmax += a[i]; + gmax = max(gmax, lmax); + if (lmax < 0) { lmax = 0; } + } + cout << cnt + gmax << endl; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10) { + n--; + } else { + n /= 10; + } + } + cout << n << '\n'; +} +int main() { + int face = 0, size; + cin >> size; + string *arr = new string[size]; + for (int i = 0; i < size; i++) { cin >> arr[i]; } + for (int i = 0; i < size; i++) { + if (arr[i] == "Tetrahedron") + face += 4; + else if (arr[i] == "Cube") + face += 6; + else if (arr[i] == "Octahedron") + face += 8; + else if (arr[i] == "Dodecahedron") + face += 12; + else if (arr[i] == "Icosahedron") + face += 20; + } + cout << face << endl; + return 0; +} +char m[10][20]; +bool dfs(int line) { + if (line == 8) return true; + char str[15]; + for (int i = 0; i < 8; i++) { + if (m[line - 1][i] == 'W') + str[i] = 'B'; + else + str[i] = 'W'; + } + str[8] = 0; + if (strstr(str, "WW") || strstr(str, "BB")) return false; + if (strstr(m[line], str)) return dfs(line + 1); + return false; +} +bool solve() { + vector v; + for (int i = 0; i < 8; i++) v.push_back(m[0][i]); + for (int time = 0; time < 8; time++) { + bool flag = true; + for (int i = 0; i < 8; i++) { m[0][i] = v[i]; } + if (strstr(m[0], "WW") || strstr(m[0], "BB")) flag = false; + if (flag && v[0] != 'B' && dfs(1)) { return true; } + v.insert(v.begin(), v[7]); + v.pop_back(); + } + return false; +} +int main() { + for (int i = 0; i < 8; i++) cin >> m[i]; + for (int i = 1; i < 8; i++) { + for (int j = 0; j < 8; j++) { m[i][j + 8] = m[i][j]; } + } + if (solve()) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, b, d, result = 0, temp = 0; + cin >> n >> b >> d; + for (int i = 0; i < n; i++) { + int size; + cin >> size; + if (size <= b) { temp += size; } + if (temp > d) { + result++; + temp = 0; + } + } + cout << result << endl; + return 0; +} +const double eps = 1e-9; +int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; +int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; +int kx[] = {1, 1, 2, 2, -1, -1, -2, -2}; +int ky[] = {2, -2, 1, -1, 2, -2, 1, -1}; +int main() { + int n, m; + cin >> n >> m; + int sum = 0; + int ans2 = INT_MIN; + for (int i = 1; i <= n; i++) { + int p; + cin >> p; + ans2 = max(p, ans2); + sum += p; + } + int ans1 = ceil((double)(sum + m) / (double)n); + cout << max(ans1, ans2) << " " << ans2 + m << endl; + return 0; +} +long long f(long long); +int main() { + long long n; + cin >> n; + f(n); +} +long long f(long long n) { + if (n % 2 == 0) + cout << (n / 2) << endl; + else + cout << (n / 2 - n) << endl; + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c; + if (c >= a && c >= b) { + cout << "1" << endl; + return 0; + } + if (c < a && c >= b) { + if (a % c == 0) + cout << a / c << endl; + else + cout << a / c + 1 << endl; + return 0; + } + if (c >= a && c < b) { + if (b % c == 0) + cout << b / c << endl; + else + cout << b / c + 1 << endl; + return 0; + } + if (c < a && c < b) { + if (b % c == 0 && a % c == 0) + cout << (a * b) / (c * c) << endl; + else if (b % c != 0 && a % c == 0) + cout << (a / c) * (b / c + 1) << endl; + else if (b % c == 0 && a % c != 0) + cout << (b / c) * (a / c + 1) << endl; + else + cout << (a / c + 1) * (b / c + 1) << endl; + return 0; + } + return 0; +} +int flag; +int n, m, len; +long long a[200005]; +long long ans, temp; +int main() { + while (cin >> n) { + for (int i = 0; i < 2 * n; ++i) cin >> a[i]; + sort(a, a + n + n); + ans = (a[2 * n - 1] - a[n]) * (a[n - 1] - a[0]); + temp = a[2 * n - 1] - a[0]; + for (int i = 1; i < n; ++i) { ans = min(ans, temp * (a[i + n - 1] - a[i])); } + cout << ans << endl; + } + return 0; +} +long long mul(long long x, long long p) { + long long ans = 1; + while (p) { + if (p & 1) ans = ans * x % 1000000007; + x = x * x % 1000000007; + p = p >> 1; + } + return ans; +} +int main() { + long long n; + cin >> n; + if (n == 0) + cout << 1 << endl; + else { + long long w = mul(2, n - 1) % 1000000007; + cout << (w + w * w % 1000000007 * 2 % 1000000007) % 1000000007 << endl; + } + return 0; +} +int n; +inline int read() { + int x = 0, y = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') { y = -1; } + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * y; +} +int main() { + n = read(); + cout << ceil(n / 5.0) << endl; + return 0; +} +int n; +int p[110]; +int a[110]; +int main() { + cin >> n; + int t; + while (cin >> t) { p[t] = 1; } + memcpy(a, p, sizeof a); + int ans = 1e8; + int res = 0; + for (int i = 1; i <= n; i++) { + if (i & 1) { + res += abs(1 - p[i]); + p[i + 1] += p[i] - 1; + } else { + res += abs(0 - p[i]); + p[i + 1] += p[i]; + } + } + if (p[n + 1] == 0 && p[n + 2] == 0) ans = min(ans, res); + res = 0; + memcpy(p, a, sizeof p); + for (int i = 1; i <= n; i++) { + if (i & 1) { + res += abs(p[i]); + p[i + 1] += p[i]; + } else { + res += abs(1 - p[i]); + p[i + 1] += p[i] - 1; + } + } + if (p[n + 1] == 0 && p[n + 2] == 0) ans = min(ans, res); + cout << ans << endl; + return 0; +} +int main() { + int number, i, temp, flag, index = 0, result = 0; + string str; + cin >> number; + cin >> str; + int arr[number] = {0}; + for (i = 0; i < number; i++) { + flag = 0; + temp = 0; + while (str[i] == 'B') { + i++; + flag = 1; + temp++; + } + if (flag == 1) { + i--; + result++; + arr[index] = temp; + index++; + } + } + cout << result << endl; + for (i = 0; i < result; i++) { + if (i == result - 1) { + cout << arr[i] << endl; + break; + } + cout << arr[i] << " "; + } + return 0; +} +int n, x, i, cnt = 0, mx; +map mp; +vector vec(10000); +int main() { + cin >> n; + for (i = 1, n = n << 1; i <= n; i++) { + cin >> x; + if (mp[x] == 0) { + cnt++; + mx = max(cnt, mx); + mp[x] = 1; + } else { + cnt--; + } + } + cout << mx << endl; + return 0; +} +int64_t n, h, a, b, k; +int64_t solve(int64_t x1, int64_t y1, int64_t x2, int64_t y2) { + int64_t dx = abs(x1 - x2); + int64_t dy = abs(y1 - y2); + if (x1 == x2) return dy; + if (y1 > b && y2 > b) return dx + (y1 - b) + (y2 - b); + if (y1 < a && y2 < a) return dx + (a - y1) + (a - y2); + return dx + dy; +} +int main() { + cin >> n >> h >> a >> b >> k; + for (int64_t i = 0; i < k; i++) { + int64_t x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << solve(x1, y1, x2, y2) << "\n"; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n, cur; + cin >> n; + for (int i = 1; i <= n; i++) { + int m; + cin >> m; + if (n == 1 && m == 15) { + cout << "DOWN" << endl; + return 0; + } else if (n == 1 && m == 0) { + cout << "UP" << endl; + } else if (n == 1) { + cout << -1 << endl; + } else { + if (i == n - 1) { cur = m; } + if (i == n) { + if (m == 15) { + cout << "DOWN" << endl; + return 0; + } else if (m == 0) { + cout << "UP" << endl; + return 0; + } else if (cur < m) { + cout << "UP" << endl; + return 0; + } else if (cur > m) { + cout << "DOWN" << endl; + return 0; + } + } + } + } +} +const int t = 100; +int n, m, check[t]; +int main() { + for (int i = 2; i <= t; i++) { + if (check[i] == false) { + for (int j = 2; j * i <= t; j++) { check[j * i] = true; } + } + } + cin >> n >> m; + for (int i = n + 1; i <= t; i++) { + if (check[i] == false) { + puts(i == m ? "YES" : "NO"); + return 0; + } + } +} +int main() { + int n, maxx, i, j, k; + cin >> n; + vector a(n + 1), s(n + 1); + s[0] = 0; + for (i = 1; i <= n; i++) { + cin >> a[i]; + s[i] = s[i - 1] ^ a[i]; + } + maxx = 0; + for (i = 1; i <= n; i++) { + for (j = i; j <= n; j++) maxx = max(maxx, s[j] ^ s[i - 1]); + } + cout << maxx << "\n"; + return 0; +} +int main() { + int n, k, res = 0; + cin >> n >> k; + long long a; + for (int i = 0; i < n; i++) { + int number_lucky_digit = 0; + cin >> a; + while (a > 0) { + if (a % 10 == 4 || a % 10 == 7) number_lucky_digit++; + a /= 10; + } + if (number_lucky_digit <= k) res++; + } + cout << res << endl; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int main() { + desperate_optimization(10); + int n, p, k; + cin >> n >> p >> k; + if (p - k > 1) cout << "<< "; + for (int i = max(1, p - k); i < p; i++) { cout << i << " "; } + cout << "(" << p << ")"; + for (int i = p + 1; i <= min(n, p + k); i++) { cout << " " << i; } + if (p + k < n) cout << " >>"; + cout << '\n'; + return 0; +} +void printv(vector s) { + for (int i = 0; i < (int)(s).size(); ++i) { cout << s[i] << " "; } + cout << "" << endl; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (((d / t) + 1) * k >= n) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +void READ(string INPUT = "NO", string OUTPUT = "NO") { + if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin); + if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout); +} +int main() { + long long n, k; + cin >> n >> k; + cout << ((n / k) % 2 ? "YES" : "NO") << "\n"; + return 0; +} +long long ans = 1000000; +int main() { + long long int n, m; + cin >> n >> m; + long long int a[m + 2]; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + long long int k = m - n; + for (int i = 0; i <= k; i++) { ans = min(ans, a[i + (n - 1)] - a[i]); } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) cout << 1 << endl; + if (n == 2) cout << 2 << endl; + if (n == 3) cout << 6 << endl; + if (n == 4) cout << 20 << endl; + if (n == 5) cout << 70 << endl; + if (n == 6) cout << 252 << endl; + if (n == 7) cout << 924 << endl; + if (n == 8) cout << 3432 << endl; + if (n == 9) cout << 12870 << endl; + if (n == 10) cout << 48620 << endl; + return 0; +} +int main() { + cout << "Karen" << endl; + return 0; +} +int main() { + int n, d, contBi = 0, contCh = 0, contBa = 0, band = 1; + cin >> n; + while (n--) { + cin >> d; + if (band == 1) { + contCh += d; + band++; + } else { + if (band == 2) { + contBi += d; + band++; + } else { + contBa += d; + band = 1; + } + } + } + int best = max(contBi, contCh); + best = max(best, contBa); + if (best == contCh) cout << "chest" << endl; + if (best == contBa) cout << "back" << endl; + if (best == contBi) cout << "biceps" << endl; + return 0; +} +int main() { + char name1[1005][11]; + char name2[1005][11]; + string s1, s2; + cin >> s1 >> s2; + long long num; + cin >> num; + for (long long i = 0; i < num; i++) { + cout << s1 << " " << s2 << "\n"; + string temp1, temp2; + cin >> temp1 >> temp2; + if (temp1 == s1) { + s1 = temp2; + } else if (temp1 == s2) { + s2 = temp2; + } + } + cout << s1 << " " << s2 << "\n"; + return 0; +} +int gcd(int n, int m) { + if (m == 0) {} +} +int main() { + int n, nike = 0, poly = 0, losn = 0, losp = 0; + map mp; + mp["RR"] = 0; + mp["RP"] = 1; + mp["RS"] = 0; + mp["PR"] = 0; + mp["PP"] = 0; + mp["PS"] = 1; + mp["SR"] = 1; + mp["SP"] = 0; + mp["SS"] = 0; + string N, P; + cin >> n; + cin >> N; + cin >> P; + int match = N.size() * P.size(); + if (n < match) { + for (int times = 1; times <= n; times++) { + string s; + char c1, c2; + c1 = N[nike]; + c2 = P[poly]; + s = s + c1 + c2; + losn += mp[s]; + s.clear(); + s = s + c2 + c1; + losp += mp[s]; + nike++; + if (nike == N.size()) { nike = 0; } + poly++; + if (poly == P.size()) { poly = 0; } + } + } else { + for (int times = 1; times <= match; times++) { + string s; + char c1, c2; + c1 = N[nike]; + c2 = P[poly]; + s = s + c1 + c2; + losn += mp[s]; + s.clear(); + s = s + c2 + c1; + losp += mp[s]; + nike++; + if (nike == N.size()) { nike = 0; } + poly++; + if (poly == P.size()) { poly = 0; } + } + losn *= n / match; + losp *= n / match; + for (int times = 1; times <= n % match; times++) { + string s; + char c1, c2; + c1 = N[nike]; + c2 = P[poly]; + s = s + c1 + c2; + losn += mp[s]; + s.clear(); + s = s + c2 + c1; + losp += mp[s]; + nike++; + if (nike == N.size()) { nike = 0; } + poly++; + if (poly == P.size()) { poly = 0; } + } + } + cout << losn << ' ' << losp << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int c[n + 5], d[n + 5]; + for (int i = 0; i < n; i++) { + c[i] = a[i] - '0'; + d[i] = b[i] - '0'; + } + int x = 0; + int sum = 0; + for (int i = 0; i < n; i++) { + int x = c[i] - d[i]; + int y; + if (x < 0) { + y = c[i]; + y += 1 + 9 - d[i]; + if (y > abs(x)) + sum += abs(x); + else + sum += y; + } else { + y = 9 - c[i]; + y += 1; + y += d[i]; + if (y > abs(x)) + sum += abs(x); + else + sum += y; + } + } + cout << sum << endl; + return 0; +} +const long long M = 86400; +int main() { + long long n, t; + cin >> n >> t; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; }; + for (long long i = 0; i <= n; i++) { + t -= M - a[i]; + if (t <= 0) { + cout << i + 1 << endl; + return 0; + } + } + return 0; +} +int n, m, k; +int a[100]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + while (cin >> n >> m >> k) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n, cmp); + int ans = 0, s = k; + if (s >= m) { + cout << 0 << endl; + break; + } else { + for (int i = 0; i < n; i++) { + ans++; + s = s - 1 + a[i]; + if (s >= m) { + cout << ans << endl; + break; + } + } + } + if (s < m) { + cout << -1 << endl; + break; + } + } + return 0; +} +int main() { + int c1, c2, c3, c4, c5; + while (cin >> c1 >> c2 >> c3 >> c4 >> c5) { + int s = 0; + s = c1 + c2 + c3 + c4 + c5; + if (s == 0) + cout << "-1\n"; + else { + if (s % 5 == 0) + cout << s / 5 << "\n"; + else + cout << "-1\n"; + } + } + return 0; +} +int n, qx, qy, kx, ky, tx, ty; +int main() { + cin >> n; + cin >> qx; + cin >> qy; + cin >> kx; + cin >> ky; + cin >> tx; + cin >> ty; + if (kx < qx) { + if (ky < qy) { + if (tx < qx && ty < qy) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } else { + if (tx < qx && ty > qy) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + } else { + if (ky < qy) { + if (tx > qx && ty < qy) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } else { + if (tx > qx && ty > qy) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + } + } +} +const int mod = 1000000007; +int d[1234567][2]; +int main() { + int n; + cin >> n; + d[1][0] = 0; + d[1][1] = 1; + for (int i = 2; i <= n; ++i) { + d[i][0] = d[i - 1][0]; + d[i][1] = d[i - 1][1]; + d[i][i % 2] += d[i - 1][1 - (i % 2)] + 1; + d[i][i % 2] %= mod; + } + cout << (d[n][0] + d[n][1]) % mod << endl; + return 0; +} +int main() { + int n, m, x, y; + vector sd; + vector vest; + vector sdVest; + cin >> n >> m >> x >> y; + sd.resize(n); + int temp; + for (int i = 0; i < n; i++) { cin >> sd[i]; } + int lastSoldier = 0; + for (int i = 0; i < m; i++) { + cin >> temp; + for (; lastSoldier < n;) { + if (temp >= sd[lastSoldier] - x && temp <= sd[lastSoldier] + y) { + vest.push_back(i); + sdVest.push_back(lastSoldier); + lastSoldier++; + break; + } else if (temp < sd[lastSoldier] - x) + break; + lastSoldier++; + } + } + temp = vest.size(); + cout << temp << endl; + for (int i = 0; i < temp; i++) { cout << sdVest[i] + 1 << " " << vest[i] + 1 << endl; } + return 0; +} +const int INF = 1 << 30; +int main() { + int n, k; + cin >> n >> k; + vector a(n); + for (int i = 0; i <= n - 1; i++) cin >> a[i]; + int ct = 0; + vector marked(n, false); + for (int i = 0; i <= n - 1; i++) { + if (a[i] <= k && !marked[i]) { + ct++; + marked[i] = true; + } else + break; + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] <= k && !marked[i]) { + ct++; + marked[i] = true; + } else + break; + } + cout << ct << '\n'; + return 0; +} +const int mod = 1e9 + 7; +int fast_pow(int a, int b) { + int res = a, ret = 1; + while (b > 0) { + if (b % 2) ret = (ret * res) % mod; + res = (res * res) % mod; + b /= 2; + } + return ret; +} +int n; +int m; +int c[200]; +int g[200][200]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> c[i]; + c[i]--; + } + for (int i = 0; i < n; ++i) { + int k; + cin >> k; + for (int j = 0; j < k; ++j) { + int u; + cin >> u; + u--; + g[u][i] = 1; + } + } + int ans = 100 * n; + for (int start = 0; start < 3; ++start) { + m = 0; + bool ok[200]; + memset(ok, 0, sizeof(ok)); + int cur = start; + int res = n; + while (m != n) { + while (1) { + bool kpyto = false; + for (int i = 0; i < n; ++i) { + if (ok[i] || c[i] != cur) continue; + bool win = true; + for (int j = 0; j < n; ++j) { + if (g[j][i] && (!ok[j])) { + win = false; + break; + } + } + if (win) { + kpyto = true; + m++; + ok[i] = true; + } + } + if (!kpyto) break; + } + if (m == n) break; + cur = (cur + 1) % 3; + res++; + } + ans = min(res, ans); + } + cout << ans << endl; + return 0; +} +int main() { + long long ar[5][5]; + for (long long i = 1; i <= 3; i++) { + for (long long j = 1; j <= 3; j++) ar[i][j] = 1; + } + for (long long i = 1; i <= 3; i++) { + for (long long j = 1; j <= 3; j++) { + long long x; + cin >> x; + if (x % 2 == 1) { + ar[i][j] = 1 - ar[i][j]; + ar[i - 1][j] = 1 - ar[i - 1][j]; + ar[i + 1][j] = 1 - ar[i + 1][j]; + ar[i][j + 1] = 1 - ar[i][j + 1]; + ar[i][j - 1] = 1 - ar[i][j - 1]; + } + } + } + for (long long i = 1; i <= 3; i++) { + for (long long j = 1; j <= 3; j++) cout << ar[i][j]; + cout << endl; + } +} +int main() { + int o; + cin >> o; + while (o--) { + long long n, x, y, d; + cin >> n >> x >> y >> d; + long long ans = 1e10; + if (abs(x - y) % d == 0) ans = min(ans, abs(x - y) / d); + if (abs(y - 1) % d == 0) ans = min(ans, (x - 1) / d + (((x - 1) % d) ? 1 : 0) + (y - 1) / d); + if (abs(y - n) % d == 0) ans = min(ans, (n - x) / d + (((n - x) % d) ? 1 : 0) + (n - y) / d); + if (ans == 1e10) ans = -1; + cout << ans << endl; + } + return 0; +} +int main() { + long long n, k, p, a = 0, b = 0, r = 0, x; + cin >> n >> k; + x = n / 2; + p = x / (k + 1); + while (p > 0) { + if ((k + 1) * p <= x) { + a = p; + b = k * p; + break; + } else + p--; + } + r = n - (b + a); + cout << a << " " << b << " " << r << endl; +} +int main() { + long long n; + cin >> n; + for (int i = 1; i <= n && n - i > 0; i++) n -= i; + cout << n << endl; + return 0; +} +int main() { + int n, a, b, tot = 0, num = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) { + tot++; + } else if (a < b) { + num++; + } + } + if (tot == num) { + cout << "Friendship is magic!^^" << endl; + } else if (tot > num) { + cout << "Mishka" << endl; + } else if (num > tot) { + cout << "Chris" << endl; + } + return 0; +} +int main() { + int dot; + string s; + cin >> s; + for (int i = 0; i < (int)s.length(); i++) + if (s[i] == '.') { + dot = i; + break; + } + if (s[dot - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + return 0; + } + if (s[dot + 1] - '0' >= 5) s[dot - 1] = s[dot - 1] + 1; + for (int i = 0; i < dot; i++) cout << s[i]; + cout << endl; + return 0; +} +const long long N = 1e5, MN = 1e9; +long long n, m, a, mn = MN; +long long ar[N]; +vector v; +map mp; +int main() { + cin >> n >> m; + for (long long i = 0; i < m; i++) { + cin >> a; + ar[a]++; + } + sort(ar + 1, ar + 1 + n); + cout << ar[1]; + cout << "\n"; + return 0; +} +int N, M, ans, a, b, c, k, x, y, z, l, r; +int main() { + cin >> N >> a >> b >> c; + if (c < a && c < b) { + if (N == 1) + cout << 0 << '\n'; + else + cout << min(a, b) + c * (N - 2) << '\n'; + } else + cout << min(a, b) * (N - 1) << '\n'; +} +int main() { + int n, m; + cin >> n >> m; + int sum = (n * (2 + (n - 1))) / 2; + if (m % sum == 0) + cout << 0 << '\n'; + else { + sum = m % sum; + bool flag = true; + int count = 1; + while (flag) { + sum = sum - count; + count++; + if (count > sum) flag = false; + if (count > n) count = 1; + } + cout << sum << '\n'; + } +} +int main() { + int n, a, count1(0), extra0(0), extra0max(-1); + cin >> n; + while (n--) { + cin >> a; + if (a == 1) { + count1 += 1; + if (extra0 > 0) { extra0 -= 1; } + } else { + extra0 += 1; + if (extra0 > extra0max) { extra0max = extra0; } + } + } + cout << count1 + extra0max << endl; + return 0; +} +int main() { + long long n, m1, x; + cin >> n >> m1; + vector a; + for (long long i = 0; i < n; i++) { + cin >> x; + a.push_back(x); + } + sort(a.begin(), a.end()); + long long c = 0, m = 0, i = 0, j = n - 1; + while (i < n) { + j = n - 1; + c = j - i + 1; + while (m1 < a[j] - a[i]) { + j--; + c--; + } + if (m < c) { m = c; } + i++; + } + cout << n - m << endl; +} +const double eps = 1e-9; +int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; +int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; +int kx[] = {1, 1, 2, 2, -1, -1, -2, -2}; +int ky[] = {2, -2, 1, -1, 2, -2, 1, -1}; +int main() { + int n, k; + cin >> n; + int arr[n + 1]; + for (int i = 1; i <= n; i++) cin >> arr[i]; + int ans = 0; + for (int i = 1; i <= n; i++) { + k = 0; + for (int j = i; j <= n; j++) { + k = k ^ arr[j]; + ans = max(k, ans); + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, ele1, ele2; + cin >> n; + int arr[24 * 60] = {}; + while (n--) { + cin >> ele1 >> ele2; + arr[ele1 * 60 + ele2]++; + } + int max = 0; + for (int i = 0; i < 24 * 60; i++) { + if (arr[i] > max) { max = arr[i]; } + } + cout << max << "\n"; +} +int main() { + int a, b, r, m; + cin >> a >> b >> r; + if (a > b) + m = b; + else + m = a; + if (m >= 2 * r) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[111]; + int maxx = -1; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] > maxx) maxx = a[i]; + } + int sum = 0; + for (int i = 1; i <= n; i++) { sum += (maxx - a[i]); } + cout << sum << endl; + } + return 0; +} +string a = "O-|"; +string b = "-O|"; +long long n; +long long x; +int main() { + cin >> n; + if (n == 0) cout << a << "-OOOO" << endl; + while (n > 0) { + x = n % 10; + if (x >= 5) { + cout << b; + x = x - 5; + } else { + cout << a; + } + for (int i = 0; i < 5; i++) { + if (x == 0) + cout << "-"; + else + cout << "O"; + x--; + } + cout << endl; + n = n / 10; + } +} +string s1, s2; +int main() { + while (cin >> s1) { + cin >> s2; + int i = 0; + while (s2[i] != '\0') { + if (s1[i] == s2[i]) + cout << 0; + else + cout << 1; + i++; + } + cout << endl; + } +} +int main() { + int n, k, i; + cin >> n >> k; + int arr[n + 5]; + for (i = 1; i <= n; i++) { cin >> arr[i]; } + for (i = n; i > 0; i--) { + if (arr[i] != arr[n]) { break; } + } + if (i >= k) { + cout << "-1" << endl; + } else { + cout << i << endl; + } +} +int gcd(int x, int y) { + if (y == 0) return x; + return gcd(y, x % y); +} +int lcm(int x, int y) { + return (x * y) / gcd(x, y); +} +int main() { + int x, y, a, b, ans = 0; + cin >> x >> y >> a >> b; + ans = -a / lcm(x, y) + b / lcm(x, y); + if (a % lcm(x, y) == 0) ans += 1; + cout << ans << endl; + return 0; +} +int main() { + int n, m, x; + cin >> n >> m; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> x; + if (x) { + if (j == 0 || j == m - 1 || i == 0 || i == n - 1) { + puts("2"); + return false; + } + } + } + } + puts("4"); + return true & false; +} +int main() { + int n; + cin >> n; + int arr[n], i, val; + for (i = 0; i < n; i++) cin >> arr[i]; + if (n == 1) { + if (arr[0] != 15 && arr[0] != 0) { + cout << "-1" << endl; + return 0; + } + } + int up = 0; + int cmp = arr[0]; + for (i = 1; i < n; i++) { + if (cmp < arr[i]) { + up = 1; + cmp = arr[i]; + continue; + } else { + up = -1; + cmp = arr[i]; + continue; + } + } + if (arr[n - 1] == 0) { + cout << "UP" << endl; + return 0; + } + if (arr[n - 1] == 15) { + cout << "DOWN" << endl; + return 0; + } + if (up == 1) + cout << "UP" << endl; + else + cout << "DOWN" << endl; +} +int main() { + string s; + cin >> s; + vector v; + for (int i = 0; i < s.size(); i++) { + if (s[i] != '+') { v.push_back(s[i]); } + } + sort(v.begin(), v.end()); + for (int i = 0; i < s.size(); i = i + 2) { + if (i % 2 == 0) { s[i] = v[i / 2]; } + } + cout << s << endl; + return 0; +} +bool is_prime(int x) { + if (x < 2) { + return false; + } else if (x == 2) { + return true; + } else if (!(x & 1)) { + return false; + } else { + for (int y = 3; y * y <= x; y += 2) { + if (x % y == 0) { return false; } + } + return true; + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = n + 1; i < m; ++i) { + if (is_prime(i)) { + cout << "NO" << endl; + exit(0); + } + } + if (is_prime(m)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int fact(int n) { + if (n == 1) return 1; + return n * fact(n - 1); +} +int main() { + int a, b; + cin >> a >> b; + int output = fact(int(min(a, b))); + cout << output << endl; + return 0; +} +int main() { + long long int a, b, k, t; + cin >> t; + while (t--) { + cin >> a >> b >> k; + long long int ans = (k / 2) * a; + ans -= (k / 2) * b; + if (k % 2) ans += a; + cout << ans << endl; + } + return 0; +} +int main() { + int n = 0; + cin >> n; + for (int j = 0; j < n; j++) { + for (int i = 0; i < n; i++) { + if (abs(n / 2 - i) + abs(n / 2 - j) <= n / 2) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int arr[500]; +int main() { + int n, k, c; + cin >> n >> k >> c; + int res = 0; + for (int i = 1; i <= c; i++) { + cin >> arr[i]; + res += (arr[i] - arr[i - 1] - 1) / k; + } + res += (n - arr[c]) / k; + res += c; + cout << res << endl; + return 0; +} +long long gcdf(long long a, long long b) { + if (a == 0) + return b; + else if (b == 0) + return a; + else { + if (a > b) + gcdf(b, a % b); + else + gcdf(a, b % a); + } +} +int main() { + long long T, n, a, b, i, j, k; + T = 1; + while (T--) { + cin >> n; + string s; + int row[n] = {0}; + int col[n] = {0}; + for (i = 0; i < n; i++) { + s = ""; + cin >> s; + for (j = 0; j < n; j++) { + if (s[j] == 'C') { + row[i]++; + col[j]++; + } + } + } + a = 0; + for (i = 0; i < n; i++) { a += (((row[i] * (row[i] - 1)) / 2) + ((col[i] * (col[i] - 1)) / 2)); } + cout << a; + cout << endl; + } +} +int n, s; +int h[200], m[200]; +int f(int a, int b) { + return a * 60 + b; +} +int main() { + cin >> n >> s; + for (int i = 0; i < n; i++) cin >> h[i] >> m[i]; + for (int i = 0; i < 29; i++) + for (int j = 0; j < 60; j++) { + bool ok = 1; + for (int k = 0; k < n; k++) + if (abs(f(i, j) - f(h[k], m[k])) <= s) ok = 0; + if (ok == true) { + cout << i << " " << j << endl; + return 0; + } + } + return 0; +} +int main() { + int n, t; + while (cin >> n >> t) { + int a[30010]; + int ans = 1; + for (int i = 1; i < n; i++) cin >> a[i]; + for (int i = 1; i < n;) { + ans += a[i]; + i = ans; + if (i > t) { + cout << "NO" << endl; + return 0; + } + if (i == t) { + cout << "YES" << endl; + return 0; + } + } + } + return 0; +} +int main() { + int n, x, a[1005], sum = 0, cont = 0; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int baad = x; + sum = abs(sum); + while (sum != 0) { + while (sum < x) x--; + sum -= x; + cont++; + } + cout << cont << endl; + return 0; +} +int main() { + int n; + cin >> n; + pair p[n + 2]; + string s[n + 2], s1[n + 2], s2[n + 2], s3[n + 2]; + int x = 0, y = 0, z = 0, z1 = 0; + for (int i = 0; i < n; i++) { + cin >> p[i].first >> p[i].second; + if (p[i].second == "rat") { + s[x] = p[i].first; + x++; + } + if (p[i].second == "woman" || p[i].second == "child") { + s1[y] = p[i].first; + y++; + } + if (p[i].second == "man") { + s2[z] = p[i].first; + z++; + } + if (p[i].second == "captain") { + s3[z1] = p[i].first; + z1++; + } + } + for (int j = 0; j < x; j++) { cout << s[j] << endl; } + for (int j = 0; j < y; j++) { cout << s1[j] << endl; } + for (int j = 0; j < z; j++) { cout << s2[j] << endl; } + for (int j = 0; j < z1; j++) { cout << s3[j] << endl; } +} +int n; +string t; +int k; +int ans_len; +char str[20 * 100010]; +int chars[80 * 100010]; +void push_up(int rt) { + chars[rt] = chars[rt << 1] + chars[rt << 1 | 1]; +} +void update(int L, int R, int left, int right, int rt) { + if (chars[rt] >= right - left + 1) return; + if (left == right) { + chars[rt] = 1; + str[left] = t[left - L]; + return; + } + if (L > right || R < left) return; + int mid = (left + right) >> 1; + if (mid >= R) + update(L, R, left, mid, rt << 1); + else if (mid < L) + update(L, R, mid + 1, right, rt << 1 | 1); + else { + update(L, R, left, mid, rt << 1); + update(L, R, mid + 1, right, rt << 1 | 1); + } + push_up(rt); +} +int main() { + int pos; + int endpos; + while (cin >> n) { + ans_len = 0; + for (int i = 1; i < 2000010; i++) str[i] = 'a'; + memset(chars, 0, sizeof(chars)); + for (int i = 1; i <= n; i++) { + cin >> t >> k; + for (int j = 1; j <= k; j++) { + cin >> pos; + endpos = pos + t.length() - 1; + update(pos, endpos, 1, 2000010, 1); + if (j == k) { + if (endpos > ans_len) ans_len = endpos; + } + } + } + for (int i = 1; i <= ans_len; i++) cout << str[i]; + cout << endl; + } +} +int main() { + int n, k, t, d; + cin >> n >> t >> k >> d; + int g = (n + k - 1) / k; + int x1 = 0, x2 = d; + for (int i = 0; i < g; i++) { + if (x1 <= x2) + x1 += t; + else + x2 += t; + } + if (max(x1, x2) < g * t) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, t, k, d, tSinOven, tConOven = 0, tt = 0, td; + cin >> n >> t >> k >> d; + tSinOven = t * ((n / k) + (n % k > 0 ? 1 : 0)); + tt = t; + d += t; + tConOven = (tt < d ? tt : d); + n -= k; + while (n > 0 and tt < d) { + n -= k; + tt += t; + } + tConOven = d; + while (n > 0) { + if (tConOven == tt) { + n -= k; + tt += t; + tConOven = d; + continue; + } + n -= k; + d += t; + tConOven = tt; + } + cout << (tSinOven > tConOven ? "YES\n" : "NO\n"); + return 0; +} +int a[5][5], b[5][5]; +int main() { + for (int i = 1; i <= 3; i++) + for (int j = 1; j <= 3; j++) { + cin >> a[i][j]; + b[i][j] = 1; + } + for (int i = 1; i <= 3; i++) + for (int j = 1; j <= 3; j++) + if (a[i][j] % 2 == 1) { + if (b[i][j] == 1) + b[i][j] = 0; + else + b[i][j] = 1; + if (j < 3) { + if (b[i][j + 1] == 1) + b[i][j + 1] = 0; + else + b[i][j + 1] = 1; + } + if (i < 3) { + if (b[i + 1][j] == 1) + b[i + 1][j] = 0; + else + b[i + 1][j] = 1; + } + if (j > 1) { + if (b[i][j - 1] == 1) + b[i][j - 1] = 0; + else + b[i][j - 1] = 1; + } + if (i > 1) { + if (b[i - 1][j] == 1) + b[i - 1][j] = 0; + else + b[i - 1][j] = 1; + } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) cout << b[i][j]; + cout << endl; + } +} +int main() { + long long int n, p; + cin >> n >> p; + long long int cost = 0; + string arr[n]; + for (long long int i = 0; i < n; i++) { cin >> arr[i]; } + long long int num = 0; + for (long long int i = n - 1; i >= 0; i--) { + if (arr[i] == "halfplus") + num = (num * 2) + 1; + else + num = (num * 2); + } + for (long long int i = 0; i < n; i++) { + if (arr[i] == "halfplus") { + cost += (num / 2) * p + (p / 2); + num = num - (num / 2) - 1; + } else { + cost += (num / 2) * p; + num = num - (num / 2); + } + } + cout << cost << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n = a * c; + if (n % b) + cout << n / b + 1 - c << endl; + else + cout << n / b - c << endl; + return 0; +} +int main() { + int n, sum; + int num[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + while (cin >> n) { + if (n < 10) { + sum = 2 * num[n]; + } else { + sum = num[n / 10] * num[n % 10]; + } + cout << sum << endl; + } + return 0; +} +bool isMNextPrime(int a, int b) { + for (int i = a; i <= b; i++) { + bool flag = true; + int div = 2; + while (div < i) { + if (i % div == 0) { + flag = false; + break; + } + div++; + } + if (flag == true && i == b) + return true; + else if (flag == true && i < b) + return false; + } + return false; +} +int main() { + int n, m; + cin >> n >> m; + bool flag = isMNextPrime(n + 1, m); + if (flag == true) + cout << "YES" << endl; + else + cout << "NO\n"; +} +int a[1001][1001]; +int main() { + int n, m, i, j, cnt = 0; + cin >> n >> m; + for (i = 0; i <= n; i++) { + for (j = 0; j <= m; j++) { + if (i * i + j == n && i + j * j == m) a[i][j] = 1; + } + } + for (i = 0; i < 1001; i++) { + for (j = 0; j < 1001; j++) { + if (a[i][j]) cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int x[3]; + cin >> x[0] >> x[1] >> x[2]; + cout << *max_element(x, x + 3) - *min_element(x, x + 3) << endl; + return 0; +} +int main() { + int n, x, y; + cin >> n; + x = n / 36; + n = n - x * 36; + if (n % 3 == 2) + y = n / 3 + 1; + else + y = n / 3; + if (y == 12) + cout << x + 1 << " " << 0 << endl; + else + cout << x << " " << y << endl; +} +int main() { + map mp; + string str, s; + int n = 0; + cin >> str; + for (int i = 0; i < 10; i++) { + cin >> s; + mp[s] = i; + s.clear(); + } + s.clear(); + for (int i = 0; i <= 7; i++) { + s.insert(0, str, n, 10); + cout << mp[s]; + s.clear(); + n += 10; + } + cout << endl; +} +int main() { + int n, i, c, t, d = 0; + cin >> n >> t; + c = 0; + for (i = 1; i <= n; i++) { + if (t % i == 0) { + d = t / i; + if (d >= 1 && d <= n) { c++; } + } + } + cout << c << endl; + return 0; +} +long long int n; +int answer[2000]; +int main() { + cin >> n; + int small = 1; + char s[n]; + for (int i = 0; i < n - 1; i++) cin >> s[i]; + for (int i = 0; i < n; i++) answer[i] = 1; + for (int i = n - 2; i >= 0; i--) { + if (s[i] == 'L') + answer[i] = answer[i + 1] + 1; + else if (s[i] == '=') + answer[i] = answer[i + 1]; + } + for (int i = 0; i < n - 1; i++) { + if (s[i] == 'R' && answer[i] >= answer[i + 1]) + answer[i + 1] = answer[i] + 1; + else if (s[i] == '=') + answer[i + 1] = answer[i]; + } + for (int i = 0; i < n; i++) cout << answer[i] << " \n"[i == n - 1]; +} +int main() { + int x, Y; + cin >> x; + if (x <= 5) + Y = 1; + else if (x % 5 == 0) + Y = x / 5; + else + Y = x / 5 + 1; + cout << Y << endl; +} +int main() { + long long n, a, b, i; + cin >> n >> a >> b; + long long c[n]; + for (i = 0; i < n; i++) { cin >> c[i]; } + sort(c, c + n); + cout << c[b] - c[b - 1] << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n], arr1[k]; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int i = 0; i < k; i++) cin >> arr1[i]; + sort(arr1, arr1 + k); + bool flag = true; + for (int i = 0, c = 0; i < n; i++) + if (arr[i] == 0) { + arr[i] = arr1[c]; + c++; + } + for (int i = 1; i < k; i++) + if (arr1[i - 1] != arr1[i]) { + flag = false; + break; + } + if (!flag) + cout << "Yes\n"; + else { + for (int i = 0; i < n - 1; i++) + if (arr[i] > arr[i + 1] && arr[i] != 0 && arr[i + 1] != 0) { + cout << "Yes\n"; + return 0; + } + cout << "No\n"; + } + return 0; +} +int main() { + int numberOfRestaurants, lunchBreakTime, maxJoy; + cin >> numberOfRestaurants >> lunchBreakTime; + int *restaurantsJoys; + int *restaurantsLunchTimes; + restaurantsJoys = new int[numberOfRestaurants]; + restaurantsLunchTimes = new int[numberOfRestaurants]; + cin >> restaurantsJoys[0] >> restaurantsLunchTimes[0]; + if (restaurantsLunchTimes[0] > lunchBreakTime) { + maxJoy = restaurantsJoys[0] - (restaurantsLunchTimes[0] - lunchBreakTime); + } else { + maxJoy = restaurantsJoys[0]; + } + for (int i = 1; i < numberOfRestaurants; i++) { + cin >> restaurantsJoys[i] >> restaurantsLunchTimes[i]; + int currentJoy; + if (restaurantsLunchTimes[i] > lunchBreakTime) { + currentJoy = restaurantsJoys[i] - (restaurantsLunchTimes[i] - lunchBreakTime); + } else { + currentJoy = restaurantsJoys[i]; + } + if (currentJoy > maxJoy) { maxJoy = currentJoy; } + } + cout << maxJoy << endl; + return 0; +} +int main() { + long long i, t, n, a, b, co, c; + cin >> n; + for (i = 1; i <= n; i++) { + co = 0; + cin >> a >> b; + while (1) { + if (a < b) swap(a, b); + c = a / b; + if (c <= 1) { + a = a - b; + co = co + 1; + } else { + co = (co + (a / b)) - 1; + a = a - ((a / b) - 1) * b; + } + if (a <= 0) break; + } + cout << co << "\n"; + } +} +int main() { + int a, b1, b2, t; + while (cin >> a) { + b1 = a / 10; + b2 = (a / 100) * 10 + a % 10; + t = max(max(b1, b2), a); + cout << t << endl; + } + return 0; +} +long long a, b; +int main() { + cin >> a >> b; + long long tm = 0, td = 0; + long long cm = 1, cd = 1; + for (long long t = 0, bef = 0; 1; bef = t) { + long long ta = cd * a, tb = cm * b; + if (ta > tb) { + t = tb; + cm++; + tm += t - bef; + } else if (ta < tb) { + t = ta; + cd++; + td += t - bef; + } else { + t = ta; + if (cm > cd) + td += t - bef; + else + tm += t - bef; + break; + } + } + if (tm == td) + puts("Equal"); + else if (tm > td) + puts("Masha"); + else + puts("Dasha"); + return 0; +} +const int N = 105; +int n, s[N], dp[N], ans; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> s[i]; + for (int i = 1; i <= n; ++i) { + dp[i] = 1; + for (int j = i - 1; j >= 1; --j) { + if (s[i] == 0) { + if (s[j] == 0) dp[i] = max(dp[i], 1 + dp[j]); + } else { + dp[i] = max(dp[i], 1 + dp[j]); + } + } + ans = max(dp[i], ans); + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, cn = 0, cn1 = 0; + cin >> n; + int m, c; + for (int i = 0; i < n; i++) { + cin >> m >> c; + if (m > c) + cn++; + else if (m < c) + cn1++; + } + if (cn > cn1) + cout << "Mishka\n"; + else if (cn1 > cn) + cout << "Chris\n"; + else + cout << "Friendship is magic!^^\n"; + return 0; +} +int main() { + int l, r, c, sum = 0, t = 0; + cin >> l >> r >> c; + if (l > r) { + if (l - r < c) { + c = c - (l - r); + c /= 2; + sum = l + c; + } else { + sum = r + c; + } + } else if (l == r) { + sum = l + c / 2; + } else if (l < r) { + if (r - l < c) { + c = c - (r - l); + c /= 2; + sum = r + c; + } else { + sum = l + c; + } + } + cout << sum * 2 << endl; +} +int main() { + long long x, d; + int n, sad = 0; + char a; + cin >> n >> x; + while (n--) { + cin >> a >> d; + if (a == '+') { + x += d; + } else { + if (d > x) { + sad++; + } else { + x -= d; + } + } + } + cout << x << " " << sad << endl; + return 0; +} +int main() { + string s; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + int l = s.length(); + if (l <= 10) + cout << s << endl; + else + cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; + } + return 0; +} +int num[55][55]; +int N; +bool judge(int x, int y) { + int n = num[x][y]; + for (int i = 0; i < N; i++) + if (i != x) { + int m = num[i][y]; + for (int j = 0; j < N; j++) + if (m + num[x][j] == n) return 1; + } + return 0; +} +int main() { + cin >> N; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) cin >> num[i][j]; + bool flag = 1; + for (int i = 0; i < N; i++) { + if (!flag) break; + for (int j = 0; j < N; j++) + if (num[i][j] != 1 && !judge(i, j)) { + flag = 0; + break; + } + } + if (flag) + cout << "Yes\n"; + else + cout << "No\n"; + return 0; +} +const int MAXT = 1500; +int n, s; +bool ok[MAXT + 1]; +int main() { + memset(ok, true, sizeof ok); + cin >> n >> s; + for (int i = 1; i <= n; ++i) { + int h, m; + cin >> h >> m; + int t = h * 60 + m; + for (int i = max(0, t - s); i <= t + s; ++i) ok[i] = false; + } + for (int i = 0; i <= MAXT; ++i) + if (ok[i]) { + int h = i / 60, m = i % 60; + cout << h << " " << m << endl; + break; + } + return 0; +} +int main() { + int n; + cin >> n; + vector p; + vector m; + vector pe; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a == 1) { p.push_back(i + 1); } + if (a == 2) { m.push_back(i + 1); } + if (a == 3) { pe.push_back(i + 1); } + } + int t = min(p.size(), min(m.size(), pe.size())); + cout << t << endl; + for (int i = 0; i < t; i++) { cout << p[i] << ' ' << m[i] << ' ' << pe[i] << endl; } + return 0; +} +int N, K, ans, A, val, x, y; +string T, S, P; +int main() { + cin >> N; + getline(cin, S); + getline(cin, S); + for (int i = 0; i < N; i++) { + if (S[i] == ' ') { + val = max(val, ans); + ans = 0; + } else if (S[i] <= 'Z' && S[i] >= 'A') + ans++; + } + val = max(val, ans); + cout << val << '\n'; +} +int main() { + int K, R, i = 0, aws = 0; + cin >> K >> R; + while (1) { + i++; + aws = K * i; + if (aws % 10 == 0 || aws % 10 == R) break; + } + cout << i << endl; + return 0; +} +int main() { + int n; + cin >> n; + char ch; + cin.get(ch); + int ans = 0, x = 0; + while (n--) { + cin.get(ch); + if (ch == ' ') + x = 0; + else if (ch >= 'A' && ch <= 'Z') { + x++; + ans = max(ans, x); + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + int ans = 0; + cin >> a >> b >> c; + while (b < a) { + b *= c; + ans++; + } + cout << ans << endl; +} +const int mod = 1e9 + 7; +const int N = 1e6 + 10; +const long long INF = 1e18; +const long double EPS = 1e-12; +int tp[105]; +int add(int x, int y) { + int z = x + y; + if (z >= mod) z -= mod; + return z; +} +int mul(int x, int y) { + long long z = 1LL * x * y; + if (z >= (long long)mod) z %= mod; + return z; +} +int main() { + string s; + cin >> s; + tp[0] = 1; + for (int i = (int)1; i < (int)105; i++) tp[i] = mul(tp[i - 1], 2); + int n = (int)(s.size()); + int ans = 0; + for (int i = 0; i < (int)n; i++) { + int len = n - 1 - i; + if (s[i] == '1') { ans = add(ans, mul(tp[i], mul(tp[len], tp[len]))); } + } + cout << ans << endl; + return 0; +} +bool isAbsent(string absent) { + for (int i = 0; i < absent.length(); i++) { + if (absent[i] == '0') return true; + } + return false; +} +int main() { + int n, d; + cin >> n >> d; + string absent; + int consecutive = 0, tmp = 0; + while (cin >> absent) { + if (isAbsent(absent)) { + tmp++; + } else { + tmp = 0; + } + if (consecutive < tmp) consecutive = tmp; + } + cout << consecutive << endl; +} +int e[105]; +int main() { + int n; + cin >> n; + int m = 0; + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + e[i] = t; + m = m > t ? m : t; + } + int ans = 0; + for (int i = 1; i <= n; i++) { ans = ans + m - e[i]; } + cout << ans << endl; +} +int main() { + long long n, x, i, j, sum = 0, p = 1, mod = 1e9 + 7, nCr[1005][1005]; + cin >> n; + nCr[0][0] = 1; + for (i = 1; i < 1005; i++) { + nCr[i][0] = 1; + for (j = 1; j <= i; j++) { nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod; } + } + do { + cin >> x; + sum += x; + p = (p * nCr[sum - 1][x - 1]) % mod; + n--; + } while (n > 0); + cout << p << endl; + return 0; +} +const int base = 1000 * 1000 * 1000; +const int N = (int)2e5 + 2; +const int INF = (int)1e9 + 7; +const long double pi = acos(-1); +const long long linf = (long long)1e18; +string s, res = "Bulbasaur"; +map kol; +int main() { + cin >> s; + for (int i = 0; i < ((int)(s).size()); ++i) { kol[s[i]]++; } + kol['u'] /= 2; + kol['a'] /= 2; + int ans = INF; + for (int i = 0; i < ((int)(res).size()); ++i) { ans = min(ans, kol[res[i]]); } + cout << ans << "\n"; + return 0; +} +int main() { + int arr[5][5]; + for (int i = 0; i < 5; i++) + for (int j = 0; j < 5; j++) { + cin >> arr[i][j]; + if (arr[i][j] == 1) { cout << (abs(j - 2) + abs(i - 2)) << endl; } + } + return 0; +} +long long i, j, k, a[100009], b[100009], ans = 0, ans1, sum, n; +int main() { + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) cin >> b[i]; + for (i = 0; i < n; i++) { + ans1 = a[i]; + ans = max(ans, ans1); + for (j = i + 1; j < n; j++) { + ans1 = ans1 | a[j]; + ans = max(ans, ans1); + } + } + sum += ans; + ans = 0; + for (i = 0; i < n; i++) { + ans1 = b[i]; + ans = max(ans, ans1); + for (j = i + 1; j < n; j++) { + ans1 = ans1 | b[j]; + ans = max(ans, ans1); + } + } + sum += ans; + cout << sum << endl; + return 0; +} +int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; +void fast() {} +int main() { + fast(); + int n, m; + cin >> n >> m; + n++; + while (n <= m) { + bool prime = true; + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) prime = false; + } + if (prime && n == m) + return cout << "YES" + << "\n", + 0; + ; + if (prime && n != m) + return cout << "NO" + << "\n", + 0; + ; + n++; + } + return cout << "NO" + << "\n", + 0; + ; +} +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const int N = 1e5 + 5; +long long a[N]; +bool flag[N]; +int main() { + for (int i = 0; i < N; i++) { flag[i] = false; } + long long n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int x1, x2, y; + long long sum = 0; + for (int i = 0; i < m; i++) { + cin >> x1 >> x2 >> y; + if (x1 > 1) continue; + if (x2 >= 1e9) { + sum++; + continue; + } + long long Index = upper_bound(a, a + n, x2) - a - 1; + while (flag[Index] == true && Index >= 0) Index--; + if (Index >= 0) { + sum++; + flag[Index] = true; + } + } + cout << sum << "\n"; + return 0; +} +int n, k = 0, ans[100]; +int sum; +void chai(int a) { + while (a) { + sum += a % 10; + a /= 10; + } +} +int main() { + cin >> n; + for (int i = n - 82; i <= n; i++) { + sum = 0; + chai(i); + if (sum + i == n) ans[++k] = i; + } + if (!k) { + cout << 0 << endl; + return 0; + } + cout << k << endl; + for (int i = 1; i <= k; i++) cout << ans[i] << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s.size() <= 10) + cout << s << "\n"; + else { + cout << s[0] << (s.size() - 2) << s[s.size() - 1] << "\n"; + } + } + return 0; +} +const int MAXN = 1005; +char c; +int s[MAXN]; +int n, p; +void work2(int x) { + if (x > n) { + for (int i = 1; i <= n; i++) cout << (char)(s[i] + 'a' - 1); + cout << endl; + exit(0); + } + for (int i = 1; i <= p; i++) { + bool ch1 = (x - 1 <= 0 || i != s[x - 1]); + bool ch2 = (x - 2 <= 0 || i != s[x - 2]); + if (ch1 && ch2) { + s[x] = i; + work2(x + 1); + } + } +} +void work(int x) { + while (s[x] < p) { + s[x]++; + bool ch1 = (x - 1 <= 0 || s[x - 1] != s[x]); + bool ch2 = (x - 2 <= 0 || s[x - 2] != s[x]); + if (ch1 && ch2) work2(x + 1); + } +} +int main() { + cin >> n >> p; + for (int i = 1; i <= n; i++) cin >> c, s[i] = c - 'a' + 1; + for (int i = n; i >= 1; i--) work(i); + cout << "NO" << endl; + return 0; +} +int main() { + int t, n = 0, h = 0, i, j; + cin >> t; + int a[t]; + for (i = 0; i < t; i++) { + cin >> a[i]; + h += a[i]; + } + sort(a, a + t); + for (i = 0; 2 * n <= h; i++) { n = n + a[t - i - 1]; } + cout << i << endl; +} +int main() { + int n, i, j; + cin >> n; + int s[n + 1][n + 1]; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + if (i == 1 || j == 1) + s[i][j] = 1; + else + s[i][j] = s[i - 1][j] + s[i][j - 1]; + } + } + cout << s[n][n] << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector v; + v.push_back(0); + long long sum = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + sum += x; + } + v.push_back(0); + int x, y; + cin >> x >> y; + int l = 0; + for (int i = 1; i <= n; i++) { + if (l <= y && l >= x && sum <= y && sum >= x) { + cout << i << endl; + return 0; + } + sum -= v[i]; + l += v[i]; + } + cout << 0 << endl; +} +int main() { + int x = 0, o = 0; + string n; + cin >> n; + for (int i = 0; i < n.length(); i++) { + if (n[i] == 'o') + o++; + else + x++; + } + if (o > 0) { + if (x % o == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } else + cout << "YES\n"; +} +int main() { + int a, b, x; + cin >> a >> b; + if (a == 0 && b == 0) + cout << "NO" << endl; + else { + x = abs(a - b); + if (x == 1 || x == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int n, m, a[1000], b[1000], price; + int clo[105][105] = {0}, x, y; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + b[i - 1] = a[i]; + } + sort(b, b + n); + price = 3 * b[n - 1] + 1; + for (int i = 0; i < m; i++) { + cin >> x >> y; + clo[y][x] = clo[x][y] = 1; + } + int num_p = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (j != i) { + for (int k = 1; k <= n; k++) { + if (k != i && k != j) { + if (clo[i][k] == 1 && clo[i][j] == 1 && clo[j][k] == 1) { + num_p = a[i] + a[k] + a[j]; + if (num_p < price) { price = num_p; } + } + } + } + } + } + } + if (num_p == 0) + cout << "-1" << endl; + else + cout << price << endl; + return 0; +} +int char_to_angle(char c) { + if (c == '^') return 0; + if (c == '>') return 90; + if (c == 'v') return 180; + if (c == '<') return 270; + return -1; +} +int main() { + char c1, c2; + cin >> c1 >> c2; + int64_t n; + cin >> n; + int d1 = char_to_angle(c1); + int d2 = char_to_angle(c2); + string ans; + if (abs(d1 - d2) == 180 || d1 == d2) { + ans = "undefined"; + } else { + int diff = d2 - d1; + if (diff == 90 && n % 4 == 1) { ans = "cw"; } + if (diff == -90 && n % 4 == 1) { ans = "ccw"; } + if (diff == 90 && n % 4 == 3) { ans = "ccw"; } + if (diff == -90 && n % 4 == 3) { ans = "cw"; } + if (diff == 270 && n % 4 == 1) { ans = "ccw"; } + if (diff == -270 && n % 4 == 1) { ans = "cw"; } + if (diff == 270 && n % 4 == 3) { ans = "cw"; } + if (diff == -270 && n % 4 == 3) { ans = "ccw"; } + } + cout << ans << endl; + return 0; +} +int main() { + int a; + cin >> a; + int m = 1, n = 2; + for (int i = 0; i < a; i++) { + int x; + cin >> x; + if (x != m && x != n) { + cout << "NO" << endl; + return 0; + } + if (x == m) { + if (m == 1) { + if (n == 2) { + n = 3; + } else + n = 2; + } else if (m == 2) { + if (n == 1) { + n = 3; + } else + n = 1; + } else { + if (n == 2) { + n = 1; + } else + n = 2; + } + } else { + if (n == 1) { + if (m == 2) { + m = 3; + } else + m = 2; + } else if (n == 2) { + if (m == 1) { + m = 3; + } else + m = 1; + } else { + if (m == 2) { + m = 1; + } else + m = 2; + } + } + } + cout << "YES" << endl; +} +int main() { + char S[101]; + int pearls = 0, dash = 0; + cin >> S; + for (int i = 0; S[i]; i++) { + if (S[i] == '-') { + dash++; + } else { + pearls++; + } + } + if (pearls == 0 || dash % pearls == 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } +} +bool prime(int n) { + if (n <= 3) + return n; + else if (n % 2 == 0) + return 0; + else { + for (int i = 2, lim = sqrt(n); i <= lim; i++) { + if (n % i == 0) { return 0; } + } + } + return 1; +} +int main() { + int n, m, tmp, i; + cin >> n >> m; + for (i = n + 1; i <= m; i++) { + tmp = prime(i); + if (tmp == 1 && i == m) { + cout << "YES" << endl; + return 0; + } else if (tmp == 1 && i != m) { + cout << "NO" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + n /= 2; + n *= 3; + cout << n << endl; + return 0; +} +int main() { + int x[101]; + int a, b, c, j, md, d; + cin >> a >> b >> c; + for (int i = 0, j = 1; i < 100; i++, j++) { + d = abs(a - j) + abs(b - j) + abs(c - j); + if (i == 0) { + md = d; + } else if (d < md) { + md = d; + } + } + cout << md << endl; +} +int check(int n) { + int val = 0; + while (n != 0) { + val += n % 10; + n /= 10; + } + return val; +} +int main() { + int n; + cin >> n; + vector v; + for (int i = 81; i >= 0; i--) { + int val = n - i; + if (check(val) == i) { v.push_back(val); } + } + cout << v.size() << endl; + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +int main() { + string s, digit[10]; + cin >> s; + for (size_t i = 0; i < sizeof(digit) / sizeof(digit[0]); ++i) { cin >> digit[i]; } + for (size_t i = 0; i < 8; ++i) { + string x = s.substr(i * 10, 10); + for (size_t j = 0; j < 10; ++j) { + if (x == digit[j]) { + cout << j; + break; + } + } + } + cout << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + int i = 0, flag = 0; + while (i < n / 2) { + if (s[i] != s[n - 1 - i]) { + if (s[i] + 2 != s[n - 1 - i] && s[i] - 2 != s[n - 1 - i]) { + cout << "NO" << endl; + flag = 1; + break; + } + } + ++i; + } + if (flag == 0) { cout << "YES" << endl; } + } +} +int main() { + string s; + cin >> s; + int S = 0; + for (int l = 1; l <= ((int)(s).size()); l++) { + vector v; + for (int i = 0; i + l - 1 < ((int)(s).size()); i++) v.push_back(s.substr(i, l)); + sort((v).begin(), (v).end()); + for (int i = 0; i < ((int)(v).size()) - 1; i++) + if (v[i] == v[i + 1]) { + S = l; + break; + } + } + cout << S << endl; + return 0; +} +long long a, b, n; +bool ans = 0; +int main() { + cin >> a >> b; + while (b > 0) { + if (b == 1) { + ans = 0; + break; + } + if (b % a != 0) { + ans = 1; + break; + } + n++; + b = b / a; + } + if (ans == 0) { + cout << "YES" << endl; + cout << n - 1 << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + long long x, y; + cin >> x >> y; + if (x > 0 && y > 0) { + cout << "0" + << " " << x + y << " " << x + y << " " + << "0" << endl; + } else if (x > 0 && y < 0) { + cout << "0" + << " " + << "-" << x - y << " " << x - y << " " + << "0" << endl; + } else if (x < 0 && y > 0) { + cout << "-" << -x + y << " " + << "0" + << " " + << "0" + << " " << -x + y << endl; + } else { + cout << "-" << -x - y << " " + << "0" + << " " + << "0" + << " " + << "-" << -x - y << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int i = 0, j = n - 1, c = 0; + while (i < n && a[i] <= k) { + i++; + c++; + } + while (j >= 0 && a[j] <= k) { + j--; + c++; + } + cout << min(n, c) << endl; +} +int main() { + long long n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + long long weights[n]; + for (long long i = 0; i < n; i++) { cin >> weights[i]; } + long long firstSum[n + 1], lastSum[n + 1]; + firstSum[0] = 0; + lastSum[0] = 0; + for (long long i = 1; i <= n; i++) { + firstSum[i] = firstSum[i - 1] + weights[i - 1]; + lastSum[i] = lastSum[i - 1] + weights[n - i]; + } + long long total_cost = LLONG_MAX; + for (long long i = 0; i <= n; i++) { + long long cost = firstSum[i] * l + lastSum[n - i] * r; + if (i > n - i) + cost += (2 * i - n - 1) * ql; + else if (i < n - i) + cost += (n - 2 * i - 1) * qr; + total_cost = min(total_cost, cost); + } + cout << total_cost << endl; +} +const int maxn = 100 + 10; +bool mark[maxn]; +int main() { + int n; + cin >> n; + int L, R; + for (int i = 0; i < n; i++) { + int l, r; + cin >> l >> r; + if (i > 0) + for (int j = l; j < r; j++) mark[j] = true; + else + L = l, R = r; + } + int ans = 0; + for (int i = 0; i < maxn; i++) + if (!mark[i] && L <= i && i < R) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n, c; + cin >> n >> c; + string s; + int cnt = 0; + for (int i = 0; i < n; i++) { + cin >> s; + int a[10]; + memset(a, 0, sizeof(a)); + for (int j = 0; j < s.size(); j++) { a[s[j] - '0']++; } + int f = 0; + for (int j = 0; j <= c; j++) { + if (a[j] == 0) f = 1; + } + if (!f) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + for (int i = 0; i < n; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + int max = -500; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] > max) { max = a[i][j]; } + } + } + cout << max << endl; + return 0; +} +int t3[4010]; +int p; +int cherk(int a) { + int star = 0, ed = p - 1; + while (star - ed <= 0) { + int mid = (star + ed) / 2; + if (t3[mid] == a) + return 1; + else if (t3[mid] > a) + ed = mid - 1; + else + star = mid + 1; + } + return 0; +} +int main() { + int a, b, c, d, n, ans; + int t1[2005], t2[2005]; + cin >> n; + p = 0, ans = 0; + for (int i = 0; i < n; i++) cin >> t1[i], t3[p++] = t1[i]; + for (int j = 0; j < n; j++) cin >> t2[j], t3[p++] = t2[j]; + sort(t3, t3 + p); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (cherk(t1[i] ^ t2[j])) ans++; + if (ans % 2) + cout << "Koyomi" << endl; + else + cout << "Karen" << endl; +} +int arr[10]; +int main() { + arr[0] = 2; + arr[1] = 7; + arr[2] = 2; + arr[3] = 3; + arr[4] = 3; + arr[5] = 4; + arr[6] = 2; + arr[7] = 5; + arr[8] = 1; + arr[9] = 2; + int n; + cin >> n; + int a = n % 10, b = n / 10; + cout << arr[a] * arr[b] << endl; + return 0; +} +int n, p; +string s; +bool relax(int pos, char st) { + for (char i = st; i <= p + 'a' - 1; i++) { + if (i == s[pos - 1]) { continue; } + if (i == s[pos - 2]) { continue; } + s[pos] = i; + return true; + } + return false; +} +int main() { + cin >> n >> p >> s; + for (int ed = n - 1; ed >= 0; ed--) + if (relax(ed, s[ed] + 1)) { + bool succ = true; + for (int ne = ed + 1; ne < n; ne++) + if (!relax(ne, 'a')) { + succ = false; + break; + } + if (succ) { + cout << s << endl; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + double p = (x * 100.0) / (n * 1.0); + if (p >= y) { + cout << 0 << endl; + return 0; + } + int S = 0; + for (int i = x + 1; i <= 1000010; i++) { + S++; + if ((i * 100.0) / (n * 1.0) >= y) break; + } + cout << S << endl; + return 0; +} +int flag; +int n, m, len; +long long a[200005]; +long long ans, temp; +int main() { + while (cin >> n) { + for (int i = 0; i < 2 * n; ++i) cin >> a[i]; + sort(a, a + n + n); + ans = (a[2 * n - 1] - a[n]) * (a[n - 1] - a[0]); + temp = a[2 * n - 1] - a[0]; + for (int i = 1; i < n; ++i) { ans = min(ans, temp * (a[i + n - 1] - a[i])); } + cout << ans << endl; + } + return 0; +} +int a[100010]; +int main() { + int n; + cin >> n; + int x; + for (int i = 1; i < n; i++) { + cin >> x; + a[x]++; + } + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int a; +int main() { + cin >> a; + if (a % 5 == 0) { + cout << a / 5 << endl; + } else + cout << a / 5 + 1 << endl; +} +int main() { + long long n, k, x, sum = 0, j; + vector v(105), vis(105); + cin >> n >> k >> x; + for (long long i = 1; i <= n; i++) cin >> v[i]; + for (long long i = 1; i <= k; i++) { + j = n - i + 1; + if (x <= v[j]) { + sum += x; + vis[j]++; + } + } + for (long long i = 1; i <= n; i++) { + if (vis[i] != 1) { sum += v[i]; } + } + cout << sum << "\n"; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + int bottles = 0; + int towels = n * p; + while (n > 1) { + int k = 0; + for (int i = 32 - 1; i >= 0; i--) { + if (n & (1 << i)) { + k = (1 << i); + break; + } + } + n = (n - k) + k / 2; + bottles += b * k + k / 2; + } + cout << bottles << " " << towels << "\n"; +} +const int INF = 0x7fffffff; +const int inf = 0x3f3f3f3f; +const int maxn = 200005; +const int N = 105; +inline void read(long long &x) { + long long f = 1; + x = 0; + char s = getchar(); + while (s < '0' || s > '9') { + if (s == '-') f = -1; + s = getchar(); + } + while (s >= '0' && s <= '9') { + x = x * 10 + s - '0'; + s = getchar(); + } + x *= f; +} +long long n, k, a[maxn], ans, cnt; +int main() { + read(n), read(k); + for (int i = 0; i < n; i++) read(a[i]); + for (int i = 0; i < n; i++) { ans += (a[i] - 1) / k + 1; } + cout << (ans + 1) / 2 << endl; + return 0; +} +int main() { + cout.precision(10); + cout << fixed; + int n; + cin >> n; + long long ans1 = 1, ans2 = 1; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "UR" || s == "DL") ans1++; + if (s == "UL" || s == "DR") ans2++; + if (s == "ULDR") { + ans1++; + ans2++; + } + } + cout << ans1 * ans2 << endl; + return 0; +} +int main() { + int a, b, c, d; + int n, m; + int p = 1000, q = 31415; + int ans; + cin >> a >> b >> c >> d; + cin >> n >> m; + p = min(p, a); + p = min(p, b); + p = min(p, c); + p = min(p, d); + if (p > m) + ans = m - n + 1; + else + ans = p - n; + if (ans < 0) ans = 0; + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + int maxi = 0, p = 0, q = 0; + for (int l = 0; l < n; l++) { + int temp = 0; + for (int r = l; r < n; r++) { + int sum1 = 0, sum2 = 0; + for (int i = l; i <= r; i++) { + sum1 |= a[i]; + sum2 |= b[i]; + } + int sum = sum1 + sum2; + if (sum > maxi) { maxi = sum; } + } + } + cout << maxi << endl; + return 0; +} +int N, A, sum; +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + cin >> A; + sum += 4 * A * i; + } + cout << sum << '\n'; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int ans = k + 1; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (k % x == 0) { ans = min(ans, k / x); } + } + cout << ans << endl; +} +int a[100005]; +int b[100005]; +int main() { + int n, m; + cin >> m; + for (int h = 0; h < m; h++) cin >> a[h]; + cin >> n; + for (int h = 0; h < n; h++) cin >> b[h]; + sort(a, a + m); + sort(b, b + n); + reverse(b, b + n); + int dis = a[0]; + int an = 0; + int ct = 0; + for (int h = 0; h < n;) { + an += b[h]; + ct++; + if (ct >= dis) { + ct = 0; + h += 3; + } else + h++; + } + cout << an << endl; +} +int gcd(int a, int b) { + if (b == 0) { + return a; + } else + return gcd(b, a % b); +} +int main() { + int n, i, j, a[100005], ans; + while (cin >> n) { + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int g = a[0]; + for (i = 1; i < n; i++) { g = gcd(a[i], g); } + ans = a[n - 1] / g - n; + if (ans % 2 == 1) + cout << "Alice" << endl; + else + cout << "Bob" << endl; + } + return 0; +} +int main() { + string str; + int x; + cin >> str; + int n; + n = str.size(); + x = ((n + 1) * (26 - n)) + (n * n); + cout << x << endl; + return 0; +} +int main() { + int n, x, sum = 0; + cin >> n >> x; + for (int i = 0, k = 0; i < n; i++) { + cin >> k; + sum += k; + } + sum = abs(sum); + cout << sum / x + (sum % x ? 1 : 0) << endl; +} +set se; +string s; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + se.insert(s); + } + cout << se.size() << endl; + return 0; +} +int main() { + int n; + cin >> n; + set count_x, count_y; + for (int i = 0; i < n; ++i) { + int x, y; + cin >> x >> y; + count_x.insert(x); + count_y.insert(y); + } + cout << min(count_x.size(), count_y.size()) << endl; + return 0; +} +int a[200005]; +int main() { + int n, i, ans = 1000000000; + cin >> n; + for (i = 0; i < n; ++i) cin >> a[i]; + sort(a, a + n); + for (i = 0; i + n / 2 < n; ++i) ans = min(ans, a[i + n / 2] - a[i]); + cout << ans << endl; + return 0; +} +int main() { + long long x, y, z, k; + cin >> x >> y >> z >> k; + while (x + y + z - 3 > k) { + if (x > y && x > z) + x--; + else if (y > z) + y--; + else + z--; + } + cout << x * y * z << endl; +} +int main() { + int n; + char c[200005]; + cin >> n; + for (int i = 0; i < n; i++) cin >> c[i]; + int temp; + int x = 0, y = 0; + for (int i = 0; i < n; i++) { + if (c[i] == '0') x++; + } + temp = min(x, n - x); + cout << n - 2 * temp << endl; + return 0; +} +int n, tab[105], wynb = 0, wynw = 0; +int abs(int x) { + if (x >= 0) + return x; + else + return -x; +} +int main() { + cin >> n; + for (int i = 1; i <= n / 2; i++) cin >> tab[i]; + sort(tab + 1, tab + n / 2 + 1); + for (int i = 1; i <= n / 2; i++) { + wynb += abs(tab[i] - (2 * i - 1)); + wynw += abs(tab[i] - 2 * i); + } + cout << min(wynb, wynw) << endl; + return 0; +} +int main() { + int m, b, p, total = 0, total_p; + cin >> m >> b >> p; + total_p = m * p; + while (1) { + int k = [](int n) -> int { + int i = 1, res = pow(2, 0); + while (1) { + int temp = pow(2, i); + if (temp > n) break; + res = temp; + i++; + } + return res; + }(m); + int matches = k / 2; + total += matches * (2 * b); + total += matches; + m = (k / 2) + (m - k); + if (matches == 0) break; + } + cout << total << " " << total_p << endl; + return 0; +} +int main() { + long long n; + int a, i, j; + char b[5][10] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cin >> n; + for (i = 0; n > 0; i++) { + a = n; + n -= (5 * pow(2, i)); + } + i--; + for (j = 0; a > 0; j++) { a -= pow(2, i); } + j--; + cout << b[j] << endl; +} +int main() { + long long n, a = 1, b = 1; + cin >> n; + while (n--) { + string s; + cin >> s; + if (s == "UR" || s == "DL") + a++; + else if (s == "UL" || s == "DR") + b++; + else { + a++; + b++; + } + } + cout << a * b << "\n"; +} +int main() { + int n, m; + cin >> n >> m; + for (int v = 1; v <= n; v++) { + if (v % 2 == 1) { + for (int i = 0; i < m; i++) { + cout << '#'; + if (i == m - 1) cout << endl; + } + } + if (v % 2 == 0 && v % 4 != 0) { + for (int i = 0; i < m; i++) + if (i == m - 1) + cout << '#' << endl; + else + cout << '.'; + } + if (v % 2 == 0 && v % 4 == 0) { + for (int j = 0; j < m; j++) { + if (j == 0) + cout << '#'; + else + cout << '.'; + if (j == m - 1) cout << endl; + } + } + } +} +int main() { + string a, b; + cin >> a >> b; + long long n; + cin >> n; + cout << a << " " << b << endl; + while (n--) { + string x, y; + cin >> x >> y; + if (a == x) { + a = y; + } else if (b == x) { + b = y; + } + cout << a << " " << b << endl; + } +} +map mpu; +vector vec; +int qq[1000006][2] = {}, a[1000006] = {}; +bool visit[1000006] = {}; +int main() { + long long a, b, a1, b1, ct1 = 0, ct2 = 0; + long long i = 0; + cin >> a >> b; + a1 = a; + b1 = b; + if (a < b) { + i = a1; + ct1 += (a1 - 0); + a1 += a; + } else { + i = b1; + ct2 += (b1 - 0); + b1 += b; + } + while (i < a * b) { + if (a1 < b1) { + ct1 += (a1 - i); + i = a1; + a1 += a; + } else if (b1 < a1) { + ct2 += (b1 - i); + i = b1; + b1 += b; + } else { + if (a > b) { + ct1 += (a1 - i); + i = a1; + a1 += a; + } else { + ct2 += (b1 - i); + i = b1; + b1 += b; + } + } + } + if (ct1 > ct2) { + cout << "Dasha\n"; + } else if (ct1 < ct2) { + cout << "Masha\n"; + } else + cout << "Equal\n"; +} +int main() { + int n, x; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> x; + if (x == 1) { + cout << "-1\n"; + return 0; + } + } + cout << "1\n"; + return 0; +} +const int numOfAlphabets = 26; +int main() { + string s; + int Count = 0; + cin >> s; + char Ch = 'a'; + for (int i = 0; i < s.length(); i++) { + Count += min(abs(s[i] - Ch), numOfAlphabets - abs(s[i] - Ch)); + Ch = s[i]; + } + cout << Count << endl; + return 0; +} +void print(int x, int n) { + for (int i = 0; i < (n - 2 * x + 1) / 2; i++) { cout << "*"; } + for (int i = 0; i < 2 * (x - 1) + 1; i++) { cout << "D"; } + for (int i = 0; i < (n - 2 * x + 1) / 2; i++) { cout << "*"; } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2; i++) { + print(i, n); + cout << endl; + } + for (int i = 0; i < n; i++) { cout << "D"; } + cout << endl; + for (int i = n / 2; i >= 1; i--) { + print(i, n); + cout << endl; + } +} +int ans, t, q[100]; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); ++i) q[i] = s[i] == 'Q' ? ++t : t; + for (int i = 0; i < s.size(); ++i) + if (s[i] == 'A') ans += q[i] * (t - q[i]); + cout << ans << endl; +} +bool a[1005][1005]; +int main() { + int n, m; + cin >> n >> m; + int k; + cin >> k; + for (int c = 1; c <= k; c++) { + int x, y; + cin >> x >> y; + a[x][y] = true; + if (a[x][y] && a[x + 1][y] && a[x][y + 1] && a[x + 1][y + 1]) { + cout << c << endl; + return 0; + } else if (a[x][y] && a[x - 1][y] && a[x][y + 1] && a[x - 1][y + 1]) { + cout << c << endl; + return 0; + } else if (a[x][y] && a[x - 1][y] && a[x][y - 1] && a[x - 1][y - 1]) { + cout << c << endl; + return 0; + } else if (a[x][y] && a[x + 1][y] && a[x][y - 1] && a[x + 1][y - 1]) { + cout << c << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +int main() { + int n, a, b; + vector h; + cin >> n >> a >> b; + h.resize(n); + for (int i = 0; i < n; i++) { cin >> h[i]; } + sort(h.begin(), h.end(), greater()); + int min_petya = h[a - 1]; + int max_vasya = h[a]; + if (min_petya == max_vasya) { + cout << 0 << endl; + } else { + cout << min_petya - max_vasya << endl; + } + return 0; +} +void print(long long n) { + if (n >= 5) { + cout << "-O|"; + n -= 5; + } else + cout << "O-|"; + long long keep = (4 - n); + while (n--) cout << "O"; + cout << "-"; + while (keep--) cout << "O"; + cout << endl; +} +int main() { + long long n; + cin >> n; + if (n == 0) { + print(0); + return 0; + } + while (n) { + print(n % 10); + n /= 10; + } + return 0; +} +int main() { + long long int t, n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(min((k * l) / nl, p / np), c * d) / n << "\n"; + return 0; +} +long long cube; +int main() { + long long res; + cin >> cube; + for (long long i = 0; i * (i + 1) * (i + 2) <= 6 * cube; ++i) { res = i; } + cout << res << endl; + return 0; +} +int n; +string a; +int main() { + cin >> n; + cin >> a; + int i = 0; + string imp = "01235689"; + while (i < imp.length()) { + if (a.find(imp.at(i)) < a.length()) { + cout << "NO" << endl; + i = imp.length(); + } else { + if (i == imp.length() - 1) { + int i2 = 0; + int i3 = n / 2 - 1; + int ts = 0; + int hs = 0; + bool check = true; + while (i2 < a.length()) { + int x = (int)a.at(i2) - 48; + if (check == true) { + ts += x; + hs += x; + } else { + ts += x; + }; + if (i2 == i3) { check = false; }; + i2 += 1; + }; + if (ts == 2 * hs) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + }; + }; + }; + i += 1; + }; + return 0; +} +int main() { + long long n; + cin >> n; + cout << 2 - (n % 2) << endl; +} +long long int gcdd(long long int a, long long int b) { + if (b == 0) + return a; + else + return gcdd(b, a % b); +} +int main() { + long long int a, b, c, d = 0, m = 0, i, x, y; + cin >> a >> b; + c = gcdd(a, b); + c = (a * b) / c; + x = a; + y = b; + if (a == b) { + cout << "Equal" << endl; + return 0; + } + for (i = 0; i < c;) { + if (x - i > y - i) { + m += y - i; + i = y; + y += b; + } else if (x - i < y - i) { + d += x - i; + i = x; + x += a; + } else if (a > b) { + d++; + i++; + } else if (b > a) { + m++; + i++; + } + } + if (d > m) + cout << "Dasha" << endl; + else if (m > d) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int l = s.size(), i, j, k; + for (i = 0; i < l; i++) { + char c = s[i]; + for (j = 0; j < 26; j++) { + if (j == c - 'a') continue; + s[i] = j + 'a'; + for (k = 0; k < l; k++) + if (s[k] != s[l - k - 1]) break; + if (k >= l) { + cout << "YES" << endl; + return 0; + } + } + s[i] = c; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + bool isAns = true; + for (int i = 0; i < 8; ++i) { + string s; + cin >> s; + if (s != "WBWBWBWB" && s != "BWBWBWBW") isAns = false; + } + if (isAns) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int n; +int gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + while (cin >> n) { + long long g, m = 0; + long long a, b; + cin >> a >> b; + g = gcd(a, b); + m = a > b ? a : b; + for (int i = 2; i < n; i++) { + cin >> b; + if (b > m) m = b; + g = gcd(g, b); + } + long long cnt = m / g - n; + if (cnt % 2) + cout << "Alice" << endl; + else + cout << "Bob" << endl; + } + return 0; +} +int main() { + int k, r; + cin >> k >> r; + int i = 1; + while (true) { + if ((k * i) % 10 == r || (k * i) % 10 == 0) { + cout << i << endl; + break; + } + ++i; + } +} +int main() { + char arr[150][150]; + int n, m; + cin >> n >> m; + int a = 0, b = 0; + int ada = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> arr[i][j]; + if (arr[i][j] == 'B') { + if (a == 0) { + a = i; + b = j; + } + ada += 1; + } + } + } + ada = sqrt(ada); + ada /= 2; + cout << a + ada << " " << b + ada << endl; +} +long long abs(long long, long long); +void solve() { + long long n; + cin >> n; + long long a[n], ans = 0; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + long long t = 1; + for (long long i = 0; i < n; i++) { + if (i == n - 1) { + ans++; + } else { + if (a[i] == a[i + 1]) { + if (i == n - 2) { + t++; + ans += (t * (t + 1)) / 2; + break; + } + t++; + } else { + ans += (t * (t + 1)) / 2; + t = 1; + } + } + } + cout << ans << "\n"; +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +long long abs(long long a, long long b) { + if (a > b) + return a - b; + else + return b - a; +} +int main() { + int n, d; + vector a; + cin >> n >> d; + int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + a.push_back(temp); + } + vector b; + int p1 = 0, p2 = 0; + for (int i = 0; i < a.size(); i++) { + p1 = a[i] + d; + p2 = a[i] - d; + if (i + 1 < n) { + if (abs((a[i + 1]) - (p1)) >= d) b.push_back(p1); + } else if (i + 1 == n) + b.push_back(p1); + if (i - 1 >= 0) { + if (abs((a[i - 1]) - (p2)) >= d) b.push_back(p2); + } else if (i == 0) + b.push_back(p2); + } + for (int i = 0; i < b.size(); i++) + for (int j = i + 1; j < b.size(); j++) { + if (b[j] == b[i]) b.erase(b.begin() + j); + } + cout << b.size() << endl; + return 0; +} +int main() { + long long int n, a, b, c; + cin >> n >> a >> b >> c; + if (n % 4 == 0) { + cout << "0" << endl; + return 0; + } + if (n % 4 == 1) { + long long int minn = INT_MAX, x = 3 * a, y = a + b; + minn = min(c, min(x, y)); + cout << minn << endl; + return 0; + } + if (n % 4 == 2) { + long long int minn = INT_MAX, x = 2 * a, y = 2 * c; + minn = min(x, min(b, y)); + cout << minn << endl; + return 0; + } + if (n % 4 == 3) { + long long int minn = INT_MAX, x = a, y = b + c, z = 3 * c; + minn = min(x, min(y, z)); + cout << minn << endl; + return 0; + } +} +int main() { + int n, a[3]; + cin >> n >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + int i = 0, j = 0, k = 0, ans = -1; + for (i = 0; i * a[2] < n + 1; i++) { + for (j = 0; i * a[2] + j * a[1] < n + 1; j++) { + if ((n - i * a[2] - j * a[1]) % a[0] == 0) { ans = max(ans, i + j + (n - i * a[2] - j * a[1]) / a[0]); } + } + } + cout << ans << endl; +} +int n, m; +int k; +bool debug = false; +long long l, r; +long long dd() { + long long i = 1; + while (i <= r) i *= 10; + long long t = (i - 1) / 2; + long long ans = t; + if (r <= t) + ans = r; + else if (l >= t + 1) + ans = l; + return ans * (i - 1 - ans); +} +int main() { + cin >> l >> r; + cout << dd() << endl; + return 0; +} +const int N = 5000 + 100; +int main() { + double l, q, p, t, ans; + while (cin >> l) { + cin >> p >> q; + t = l / (p + q); + ans = p * t; + cout << ans << endl; + } + return 0; +} +int main() { + long long int n, i, j; + cin >> n; + long long int p1, q1, p2, q2, p3, q3; + cin >> p1 >> q1 >> p2 >> q2 >> p3 >> q3; + long long int a = p1, b = p2, c = p3; + while (a + 1 <= q1) { + if (a + b + c + 1 <= n) { + a++; + } else { + break; + } + } + while (b + 1 <= q2) { + if (a + b + c + 1 <= n) { + b++; + } else { + break; + } + } + while (c + 1 <= q3) { + if (a + b + c + 1 <= n) { + c++; + } else { + break; + } + } + cout << a << " " << b << " " << c << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i < n; i++) { + if (i % 2) + cout << "I hate that "; + else + cout << "I love that "; + } + if (n % 2) + cout << "I hate it"; + else + cout << "I love it"; + cout << endl; + return 0; +} +const int maxN = 300; +int c[maxN], mark[maxN]; +vector need[maxN], sp; +int dist(int l, int r) { + if (l == r) return 0; + if (l == 1) + if (r == 2) + return 1; + else + return 2; + if (r == 3) return 1; + if (l == 3) + if (r == 2) return 2; + if (l == 2) return 2; + return 1; +} +int solve(int n, int nowp) { + int ans = 0, flag = 0, mn = 9, mc = -1; + for (int i = 0; i < n; i++) + if (!mark[i]) flag = 1; + if (!flag) return 0; + vector nsp; + for (int i = 0; i < n; i++) + if (!mark[i]) { + flag = 1; + for (int j = 0; j < need[i].size(); j++) + if (!mark[need[i][j]]) flag = 0; + if (flag) nsp.push_back(i); + } + for (int i = 0; i < nsp.size(); i++) + if (mc != c[nsp[i]] && dist(nowp, c[nsp[i]]) < mn) { + mn = dist(nowp, c[nsp[i]]); + mc = c[nsp[i]]; + } + for (int i = 0; i < nsp.size(); i++) + if (mc == c[nsp[i]]) { + mark[nsp[i]] = 1; + ans++; + } + ans = ans + mn + solve(n, mc); + return ans; +} +int main() { + int n, mans = 99999999; + cin >> n; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < n; i++) { + int k; + cin >> k; + if (!k) sp.push_back(i); + while (k--) { + int l; + cin >> l; + l--; + need[i].push_back(l); + } + } + cerr << sp.size() << endl; + for (int i = 0; i < sp.size(); i++) { + for (int j = 0; j < n; j++) mark[j] = 0; + mark[sp[i]] = 1; + mans = min(mans, solve(n, c[sp[i]]) + 1); + } + cout << mans << endl; + cin >> n; +} +int main() { + int a, b; + int counter = 0; + int tranSize = 0; + int rep; + cin >> rep; + while (rep--) { + cin >> a >> b; + counter -= a; + counter += b; + if (counter > tranSize) { tranSize = counter; } + } + cout << tranSize << endl; + return 0; +} +const long long mod = 1e9 + 7; +const double esp = 1e-5; +int main() { + long long n, p; + string a[50]; + while (cin >> n >> p) { + for (long long i = 1; i <= n; i++) cin >> a[i]; + long long num = 1, t = 1; + for (int i = n - 1; i >= 1; i--) { + if (a[i] == "halfplus") { + num = (num + 0.5) * 2; + t++; + } else { + num = num * 2; + } + } + long long ans = 0; + ans = num * p - t * (p / 2); + cout << ans << endl; + } +} +int main() { + long n, m, sum = 1, data[100005]; + cin >> n >> m; + cin >> data[0]; + for (int i = 1; i < n; i++) { + cin >> data[i]; + if (data[i] - data[i - 1] > m) + sum = 1; + else + sum += 1; + } + cout << sum << endl; +} +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + int t1, f1, t2, f2; + cin >> t1 >> f1 >> t2 >> f2; + if (t1 == t2) { + cout << abs(f1 - f2) << endl; + } else if (t1 != t2) { + if (f1 >= a and f1 <= b || f2 >= a and f2 <= b) { + cout << abs(t1 - t2) + abs(f1 - f2) << endl; + } else { + if (f1 > b) { + int total = abs(f1 - b); + total += abs(t1 - t2); + total += abs(f2 - b); + cout << total << endl; + } else if (f1 < a) { + int total = abs(f1 - a); + total += abs(t1 - t2); + total += abs(f2 - a); + cout << total << endl; + } + } + } + } + return 0; +} +int main() { + int a, b, c, x; + cin >> a >> b >> c; + x = b * c; + x = (a * c) - x; + if (x % b == 0) { + x = x / b; + cout << x << endl; + } else { + x = (x / b) + 1; + cout << x << endl; + } +} +int n; +int a[1500]; +int b[1500]; +long long int sum1; +long long int sum2; +long long int sum; +int main() { + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + sum1 = a[1]; + for (int i = 2; i <= n; i++) { sum1 = sum1 | a[i]; } + sum2 = b[1]; + for (int i = 2; i <= n; i++) { sum2 = sum2 | b[i]; } + sum = sum1 + sum2; + cout << sum << endl; + } + return 0; +} +int main() { + map m; + map::iterator it; + int n, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + m[x]++; + } + int ant = 0; + for (it = m.begin(); it != m.end(); it++) { + if (it->first == 0) + continue; + else if (it->second > 2) { + cout << "-1" << endl; + return 0; + } else if (it->second == 2) + ant++; + } + cout << ant << endl; + return 0; +} +void gnomeSort(int arr[], int n) { + int index = 0; + while (index < n) { + if (index == 0) index++; + if (arr[index] >= arr[index - 1]) + index++; + else { + swap(arr[index], arr[index - 1]); + index--; + } + } +} +int main() { + int n, temp, checkdouble = 0; + cin >> n; + int id[n]; + for (int i = 0; i < n; i++) { cin >> id[i]; } + gnomeSort(id, n); + for (int i = 0; i < n; i++) { + if (id[i] != 0 && id[i] == id[i + 1]) { + checkdouble++; + if (id[i] != 0 && id[i] == id[i + 2]) { + checkdouble = -1; + break; + } + } + } + cout << checkdouble << endl; + return 0; +} +const int maxn = 6; +int A[maxn]; +int main() { + int N; + cin >> N; + for (int i = (1); i <= (N); i += (1)) { cin >> A[i]; } + sort(A + 1, A + N + 1); + int p = N / 2; + if (N % 2 == 1) { p++; } + cout << A[p] << "\n"; + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + long long a, b, k; + cin >> a >> b >> k; + if (k % 2 == 0) { + cout << (k / 2) * (a - b) << endl; + } else { + cout << (k / 2) * (a - b) + a << endl; + } + } +} +int main() { + int n, t, x, spare = 0, res, belum = true; + cin >> n >> t; + for (int i = 0; i < n; i++) { + cin >> x; + spare += (86400 - x); + if (spare >= t && belum) { + res = i + 1; + belum = false; + } + } + cout << res << endl; + return 0; +} +long long n, m, a; +long long mod = (1000000) + 3; +long long poww(long long x, long long y) { + if (y == 0) return 1; + if (y == 1) return x; + if (y % 2) return ((poww(x, y / 2) % mod) * (poww(x, y / 2) % mod) * (x % mod)) % mod; + return ((poww(x, y / 2) % mod) * (poww(x, y / 2) % mod)) % mod; +} +int main() { + cin >> n; + if (!n) + cout << 1 << endl; + else + cout << poww(3, n - 1) << endl; + return 0; +} +int main() { + char x[20]; + int ok = 1; + while (cin >> x) { + int len = strlen(x); + for (int i = 0; i < len; i++) { + if (i == 0) { + if (x[i] == '9') + cout << x[i]; + else if (x[i] >= '5') + cout << '9' - x[i]; + else + cout << x[i]; + } else { + if (x[i] >= '5') + cout << '9' - x[i]; + else + cout << x[i]; + } + } + cout << endl; + } + return 0; +} +int main() { + int n, t; + int a[30010], b[30010]; + cin >> n >> t; + memset(b, 0, sizeof(b)); + b[1] = 1; + for (int i = 1; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) { + if (b[i] != 0) b[i + a[i]] = 1; + } + if (b[t] != 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int N, Cnt; +bool vis[2 * 100005]; +int main() { + cin >> N; + int Ai; + for (int i = 0; i <= N - 1; i++) { + cin >> Ai; + if (Ai == 0) continue; + Ai += 100000; + if (!vis[Ai]) { + Cnt++; + vis[Ai] = true; + } + } + cout << Cnt << '\n'; + return 0; +} +int main() { + string str; + cin >> str; + int count = 0; + for (size_t i = str.size() - 1; i > 0; --i) { + int j = 0; + while (j + i <= str.size()) { + string sub = str.substr(j, i); + int pos = 0; + while (pos + i <= str.size()) { + if ((pos = str.find(sub, pos)) != string::npos) { + count++; + } else { + break; + } + pos++; + } + if (count >= 2) { + cout << sub.length() << endl; + return 0; + } + count = 0; + j++; + } + } + cout << 0 << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int a[30010], x = 1, p = 1; + for (int i = 1; i < n; i++) { + cin >> a[i]; + a[i] += i; + } + while (x < a[n - 1]) { + x = a[x]; + if (x == m) { + cout << "YES" << endl; + p = 0; + break; + } + } + if (p) cout << "NO" << endl; + } +} +int main() { + int n, x; + cin >> n >> x; + int a[n], sum = 0; + for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]; + cout << ceil(double(abs(sum)) / x) << endl; +} +int main() { + long long n, m, a, b, x; + cin >> n >> m >> a >> b; + long long sum1 = 0, sum2 = 0; + if (n >= m) { + if (n % m == 0) { + cout << 0 << endl; + return 0; + } + } + x = n % m; + sum1 += b * x; + sum2 += a * (m - x); + cout << min(sum1, sum2) << endl; + return 0; +} +const int maxn = 2e5 + 10; +long long a[maxn]; +int main() { + int n; + cin >> n; + long long ans = 0; + for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } + sort(a, a + 2 * n); + ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); + for (int i = 1; i < n; i++) { ans = min((a[2 * n - 1] - a[0]) * (a[i + n - 1] - a[i]), ans); } + cout << ans << endl; + return 0; +} +int main() { + int i, j, k, n, br, c = 0; + string s; + cin >> s; + k = 1; + n = s.length(); + for (i = 0; i < n; i = i + k) { + br = 1; + j = i; + while (s[j] == s[j + 1] && j < n) { + br++; + j++; + } + if (br % 2 == 0) c++; + k = br; + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + vector arr(n + 5); + int max_val = 0; + long long sum = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + max_val = max(max_val, arr[i]); + sum += arr[i]; + } + int i = max_val; + for (; i < 10000; i++) { + long long val = i * n - sum; + if (val > sum) break; + } + cout << i << endl; + return 0; +} +int main() { + int y = 0, j, x = 0; + int n; + string s; + cin >> n; + cin >> s; + for (j = 0; j < n; j++) { + if (s[j] == '0') { + x++; + } else if (s[j] == '1') { + y++; + } + } + int num; + if (x > y) + num = x - y; + else { + num = y - x; + } + cout << num << endl; + return 0; +} +int a[101]; +int n; +int totSum = 0; +int minCoinsToWin() { + sort(a, a + n); + int mySum = 0; + int count = 0; + for (int i = n - 1; i >= 0; i--) { + mySum += a[i]; + count++; + if (mySum > totSum - mySum) break; + } + return count; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + totSum += a[i]; + } + cout << minCoinsToWin() << "\n"; + return 0; +} +int main() { + int n, s, t, sum = 0, m1 = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + cin >> s >> t; + s--; + t--; + int l = min(s, t); + int h = max(s, t); + for (int i = l; i < h; i++) { m1 += arr[i]; } + cout << min(m1, sum - m1) << "\n"; +} +int main() { + int x, n, t, diff1, diff2; + int array[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> x; + if (x == 1) { + n = i; + t = j; + array[i][j] = x; + } else { + array[i][j] = x; + } + } + } + if ((2 - n) < 0) { + diff1 = 0 - (2 - n); + } else { + diff1 = 2 - n; + } + if ((2 - t) < 0) { + diff2 = 0 - (2 - t); + } else { + diff2 = 2 - t; + } + cout << diff1 + diff2 << endl; + return 0; +} +const long long MOD = 1e9 + 7; +long long n, m, k, q, l, r, h; +long long a[1000006]; +long long b[1000006]; +double x, y, z; +string s, t; +char c; +long long ans = 0, res = 0; +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + int x, y, z, w; + cin >> y >> x >> w >> z; + int res = abs(w - y); + if (!res) { + cout << abs(x - z) << endl; + continue; + } + if (x > b) { + res += x - b; + x = b; + } + if (x < a) { + res += a - x; + x = a; + } + if (z > b) { + res += z - b; + z = b; + } + if (z < a) { + res += a - z; + z = a; + } + res += abs(x - z); + cout << res << endl; + } + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +map ms; +void hora(int tc) { + ms['6'] = 1; + ms['7'] = 2; + ms['8'] = 3; + ms['9'] = 4; + ms['T'] = 5; + ms['J'] = 6; + ms['Q'] = 7; + ms['K'] = 8; + ms['A'] = 9; + char x; + cin >> x; + string s1, s2; + cin >> s1 >> s2; + bool v1 = 0, v2 = 0; + if (s1[1] == x) v1 = 1; + if (s2[1] == x) v2 = 1; + if (v1 != v2) { + if (v1 == 1) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } else { + if (s1[1] == s2[1] && ms[s1[0]] > ms[s2[0]]) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } +} +int main() { + desperate_optimization(10); + int ntc = 1; + for (int tc = 1; tc <= ntc; tc++) hora(tc); + return 0; +} +int main() { + int c, b, i, k, l, j = 0; + cin >> c; + priority_queue pq; + cin >> b; + for (i = 1; i < c; i++) { + int x; + cin >> x; + pq.push(x); + } + while (b <= pq.top()) { + b++; + int x = pq.top(); + x--; + pq.pop(); + pq.push(x); + j++; + } + cout << j << endl; +} +const int inf = (1ll << 31) - 1; +string a, b; +int k; +int n, m; +int dp1[1000100]; +int dp2[1000100]; +int get(char x, char y) { + if (x == y) return 0; + if (x == 'R') { + if (y == 'S') return 1; + return 0; + } + if (x == 'S') { + if (y == 'R') return 0; + return 1; + } + if (y == 'S') return 0; + return 1; +} +int main() { + cin >> k >> a >> b; + int cnt = 1; + n = a.size(); + m = b.size(); + int x = 0; + int y = 0; + for (int i = 1;; i++) { + dp1[i] = get(a[x], b[y]) + dp1[i - 1]; + dp2[i] = get(b[y], a[x]) + dp2[i - 1]; + x = (x + 1) % n; + y = (y + 1) % m; + if (x == 0 && y == 0) break; + cnt++; + } + x = k / cnt; + long long d1 = dp1[cnt] * 1ll * x + dp1[k % cnt]; + long long d2 = dp2[cnt] * 1ll * x + dp2[k % cnt]; + cout << d2 << " " << d1 << endl; + return 0; +} +const int maxn = 1e5 + 7; +int main() { + int a, b; + cin >> a >> b; + int c = min(a, b); + long long ans = 1; + for (int i = 1; i <= c; i++) ans *= i; + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + m *= 2; + bool v[2 * 110]; + memset((v), (false), sizeof(v)); + while (n--) { + int a, b; + cin >> a >> b; + a *= 2; + b *= 2; + memset(v + a, true, b - a + 1); + } + bool ok = true; + for (int i = 0; i <= m; ++i) + if (!v[i]) ok = false; + cout << (ok ? "YES" : "NO") << "\n"; + return 0; +} +int n, i, p, k; +char a[101][101]; +int main() { + cin >> n; + p = n / 2 + 1; + for (i = 1; i <= n / 2 + 1; ++i) { + for (k = 1; k <= 2 * i - 1; k++) { a[i][p + k - 1] = 'D'; } + p--; + } + p = 2; + for (i = n / 2 + 2; i <= n; ++i) { + for (k = 1; k <= 2 * (n - i + 1) - 1; k++) { a[i][p + k - 1] = 'D'; } + p++; + } + for (i = 1; i <= n; ++i) { + for (k = 1; k <= n; ++k) { + if (a[i][k] != 'D') { + cout << '*'; + } else { + cout << a[i][k]; + } + } + cout << endl; + } + return 0; +} +int n, b, d; +int main() { + cin >> n >> b >> d; + int ans = 0, cnt = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x <= b) { + cnt += x; + if (cnt > d) { + ans++; + cnt = 0; + } + } + } + cout << ans << "\n"; + return 0; +} +const int N = 4005; +const int inf = 1e9; +const long long INF = 1e18; +const double PI = acos(-1.0); +const double EPS = 1e-8; +const int MOD = 1000000007; +int n, a, b, c; +int dp[N]; +int main() { + cin >> n >> a >> b >> c; + for (int i = 0; i <= n; i++) dp[i] = -inf; + dp[0] = 0; + for (int i = 1; i <= n; i++) { + if (a <= i) dp[i] = max(dp[i], dp[i - a] + 1); + if (b <= i) dp[i] = max(dp[i], dp[i - b] + 1); + if (c <= i) dp[i] = max(dp[i], dp[i - c] + 1); + } + cout << dp[n] << "\n"; + return 0; +} +int main() { + string number; + int count = 0; + int i; + cin >> number; + for (i = 0; i < number.length(); i++) { + if (number[i] == '4' || number[i] == '7') count++; + } + if (count == 4 || count == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int sol; +string str; +int main() { + cin >> str; + for (int i = 1; i < str.length(); i++) { + int j = i; + while (str[j] == str[j - 1] && j < str.length()) j++; + int curr = j - i + 1; + if (curr % 2 == 0) sol++; + if (j != i) i = j - 1; + } + cout << sol << endl; + return 0; +} +int n; +int computer[201], check[3][201]; +vector vv[201]; +int bk[201]; +int bfs(int st, int num) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (check[num][i] == 0) q.push(i); + } + while (!q.empty()) { + memset(bk, 0, sizeof(bk)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (bk[head] == 5) { + q.push(head); + break; + } + bk[head]++; + if (computer[head] != st) { + q.push(head); + continue; + } + for (int i = 0; i < vv[head].size(); i++) { + int v = vv[head][i]; + check[num][v]--; + if (check[num][v] == 0) q.push(v); + } + } + st = (st == 3 ? 1 : st + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(check, 0, sizeof(check)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + check[0][i]++, check[1][i]++, check[2][i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= 3; i++) ans = min(ans, bfs(i, i - 1)); + cout << ans << endl; + } + return 0; +} +const int maxn = 1e5 + 10; +int F(string s) { + string p = "VK"; + int res = 0, loc = s.find(p); + while (loc != -1) { + res++; + loc = s.find(p, loc + 1); + } + return res; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int ans = F(s); + for (int i = 0; i < len; i++) { + char c = s[i]; + if (c == 'V') + s[i] = 'K'; + else + s[i] = 'V'; + ans = max(ans, F(s)); + s[i] = c; + } + cout << ans << endl; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +const int N = 1e5; +deque deq; +int arr[N + 5]; +int main() { + desperate_optimization(10); + int n, k; + cin >> n >> k; + int maxi = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + deq.push_back(x); + arr[x]++; + maxi = max(maxi, arr[x]); + } + int step = 0; + k--; + while (maxi != n && step <= n) { + int v = deq[k]; + int val = deq.front(); + deq.pop_front(); + arr[val]--; + arr[v]++; + maxi = max(maxi, arr[v]); + deq.push_back(v); + step++; + } + if (maxi == n) + cout << step << '\n'; + else + cout << -1 << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + if (n == 1) { + cout << 1 << endl; + return 0; + } + for (int i = 0; i < n; i++) { + a[i][0] = 1; + a[0][i] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +int main() { + long long n, k, x = 0; + int a[100001]; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + x++; + if (a[i] - a[i - 1] > k) { + x = 1; + } else { + x = x; + } + } + cout << x << endl; +} +int main() { + int n; + cin >> n; + int sum = 0; + vector v(n); + for (int i = 0; i < n; i++) { + cin >> v[i]; + sum += v[i]; + } + int x, y; + cin >> x >> y; + vector c(n + 1, 0); + for (int i = 1; i <= n; i++) c[i] = v[i - 1] + c[i - 1]; + for (int i = 0; i <= n; i++) + if (c[i] >= x && c[i] <= y && sum - c[i] >= x && sum - c[i] <= y) { + cout << i + 1 << endl; + return 0; + } + cout << 0 << endl; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int sum = a * c; + sum -= b * c; + if (sum % b == 0) + cout << sum / b << endl; + else + cout << sum / b + 1 << endl; + } + return 0; +} +const int N = 100 + 5; +string s, t[N]; +bool mark[N]; +int n; +int main() { + cin >> n >> s; + for (int i = 0; i < n; i++) cin >> t[i]; + string cur = s; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (!mark[j] && t[j].substr(0, 3) == cur) { + cur = t[j].substr(5); + mark[j] = true; + } + cout << (cur == s ? "home\n" : "contest\n"); + return 0; +} +bool bark(char c, char d) { + if (c == 'R' && d == 'S') return true; + if (c == 'S' && d == 'P') return true; + if (c == 'P' && d == 'R') return true; + return false; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int m = a.size(), k = b.size(); + int res = 0, res1 = 0; + for (int i = 0; i < m * k; i++) { + if (bark(a[i % m], b[i % k])) res1++; + if (bark(b[i % k], a[i % m])) res++; + } + res = n / (m * k) * res; + res1 *= n / (m * k); + n = n % (m * k); + for (int i = 0; i < n; i++) { + if (bark(a[i % m], b[i % k])) res1++; + if (bark(b[i % k], a[i % m])) res++; + } + cout << res << " " << res1 << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (int)log2(n) + 1 << endl; + return 0; +} +int main() { + int x; + cin >> x; + for (int i = 0; i < x / 2 + 1; i++) { + for (int j = 0; j < x; j++) { + if (j >= (x / 2) - i && j <= (x / 2) + i) + cout << 'D'; + else + cout << '*'; + } + cout << endl; + } + for (int i = x / 2 - 1; i >= 0; i--) { + for (int j = 0; j < x; j++) { + if (j >= (x / 2) - i && j <= (x / 2) + i) + cout << 'D'; + else + cout << '*'; + } + cout << endl; + } +} +int n, t, a; +int main() { + cin >> n >> t; + int ans = 1; + for (int i = 0; i < n; i++) { + cin >> a; + if (t - (86400 - a) <= 0) { + cout << ans << endl; + return 0; + } + t -= 86400 - a; + ans++; + } + return 0; +} +int main() { + string s; + long long t = 1; + cin >> s; + t = 25 + 25 + 1; + int len = s.size() - 1; + t += 25 * len; + cout << t << endl; + return 0; +} +int main() { + string a; + cin >> a; + int con = 0; + deque esto; + for (int i = 0; i < a.size(); i++) esto.push_back(a[i]); + string b = ""; + while (a != b) { + con++; + b = ""; + char c = esto.back(); + esto.pop_back(); + esto.push_front(c); + for (int i = 0; i < esto.size(); i++) b.push_back(esto[i]); + } + cout << con << endl; + return 0; +} +const double pi = acos(-1.0); +long long l, r; +long long g(long long x) { + long long t = 1; + while (t <= x) t *= 10; + return (t - 1 - x) * x; +} +int main() { + cin >> l >> r; + long long res = max(g(l), g(r)); + long long t = 5; + for (int i = 0, _n = (9); i < _n; i++) { + if (l <= t && t <= r) res = max(res, g(t)); + t *= 10; + } + cout << res << endl; + return 0; +} +int a[] = {100, 20, 10, 5, 1}, c, n; +int main() { + cin >> n; + for (int i = 0; i < 5; i++) { + c = c + n / a[i]; + n = n % a[i]; + } + cout << c << endl; +} +int main() { + int k, n, i, j; + string s; + while (cin >> k >> n >> s) { + if (n > k / 2) { + for (i = n; i < k; i++) cout << "RIGHT\n"; + cout << "PRINT " << s[k - 1] << endl; + for (i = k - 1; i >= 1; i--) + cout << "LEFT\n" + << "PRINT " << s[i - 1] << endl; + } else { + for (i = n; i > 1; i--) cout << "LEFT\n"; + cout << "PRINT " << s[0] << endl; + for (i = 2; i <= k; i++) + cout << "RIGHT\n" + << "PRINT " << s[i - 1] << endl; + } + } + return 0; +} +int main() { + int m, n, i = 1; + string turn = "Akshat"; + cin >> n >> m; + while (i < m && i < n) { + if (turn == "Akshat") + turn = "Malvika"; + else + turn = "Akshat"; + i++; + } + cout << turn << endl; +} +long long suma; +int n, m, aux, auxl, auxr; +bool sinoutput = true; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> aux; + suma += aux; + } + cin >> m; + for (int i = 0; i < m; i++) { + cin >> auxl >> auxr; + if (sinoutput && suma <= auxl) { + cout << auxl << '\n'; + sinoutput = false; + } else if (sinoutput && auxl <= suma && suma <= auxr) { + cout << suma << '\n'; + sinoutput = false; + } + } + if (sinoutput) { cout << "-1\n"; } + return 0; +} +int n, a[30], cnt[3]; +void init() { + cin >> n; + for (int i = 0; i <= n - 1; i++) cin >> a[i]; + for (int i = 0; i <= 2; i++) cnt[i] = 0; + for (int i = 0; i <= n - 1; i++) cnt[i % 3] += a[i]; + if (cnt[0] > cnt[1] && cnt[0] > cnt[2]) cout << "chest\n"; + if (cnt[1] > cnt[0] && cnt[1] > cnt[2]) cout << "biceps\n"; + if (cnt[2] > cnt[0] && cnt[2] > cnt[1]) cout << "back\n"; +} +int main() { + init(); + return 0; +} +int main() { + long long int n, k, c, d, nw, w; + cin >> n >> k; + d = (n / (2 * (k + 1))); + c = k * d; + nw = n - (c + d); + cout << d << " " << c << " " << nw << endl; +} +int main() { + int n, sum = 0, i, m, j; + cin >> n; + int *p = new int[n]; + for (i = 0; i < n; i++) cin >> p[i]; + int *h = new int[n]; + for (i = 0; i < n; i++) { + for (j = i + 1; j < n; j++) sum = sum + 4 * j * p[j]; + for (m = i - 1; m > 0; m--) sum = sum + 4 * i * p[m] * 4; + sum = i * 4 * p[i] + sum; + h[i] = sum; + sum = 0; + } + for (i = 1; i < n; i++) + if (h[0] > h[i]) { + int t; + t = h[0]; + h[0] = h[i]; + h[i] = t; + } + cout << h[0] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int flag = 1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) flag = -1; + } + cout << flag << endl; +} +int RPS(string a, string b) { + if (a == b) return 0; + if (a == "[]") { + if (b == "()") return -1; + return 1; + } + if (a == "()") { + if (b == "[]") return 1; + return -1; + } + if (b == "[]") return -1; + return 1; +} +int main() { + int sum = 0; + string s[2]; + cin >> s[0] >> s[1]; + for (int i = 0; i < s[0].size() / 2; ++i) { + string one = s[0].substr(i * 2, 2); + string two = s[1].substr(i * 2, 2); + sum += RPS(one, two); + } + if (!sum) + cout << "TIE\n"; + else if (sum < 0) + cout << "TEAM 1 WINS\n"; + else + cout << "TEAM 2 WINS\n"; + return 0; +} +long long a[9], b[9]; +int main() { + string a, b; + cin >> a >> b; + long long n = a.size(); + long long score = 0; + for (long long i = 0; i < n; i += 2) { + if (a[i] == '8') { + if (b[i] == '(') score--; + if (b[i] == '[') score++; + } + if (a[i] == '(') { + if (b[i] == '[') score--; + if (b[i] == '8') score++; + } + if (a[i] == '[') { + if (b[i] == '8') score--; + if (b[i] == '(') score++; + } + } + if (score > 0) + cout << "TEAM 1 WINS\n"; + else if (score < 0) + cout << "TEAM 2 WINS\n"; + else + cout << "TIE\n"; +} +int main() { + string s; + cin >> s; + int l = s.size(); + int item = 25 * (l + 1) + 1; + cout << item << endl; +} +int main() { + int n, m; + string s; + cin >> n >> m >> s; + for (int i = 0; i < m; i++) { + int l, r; + string c1, c2; + cin >> l >> r >> c1 >> c2; + for (int i = l - 1; i <= r - 1; i++) { + if (s[i] == c1[0]) { s[i] = c2[0]; } + } + } + cout << s << endl; +} +int main() { + int t, n, k, i, j, x; + double a[400]; + int v[200]; + memset(v, 0, sizeof(v)); + for (i = 0; i < 400; i++) { + a[i] = (i + 1) * 180.0 / (i + 3); + x = a[i]; + if (x == a[i]) v[x] = 1; + } + cin >> t; + while (t--) { + cin >> n; + if (v[n]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + string name, ans; + int hr, hn, a, b, c, d, e, m, n; + m = -(1 << 30); + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> name >> hr >> hn >> a >> b >> c >> d >> e; + int pct = hr * 100 - hn * 50 + a + b + c + d + e; + if (pct > m) { + m = pct; + ans = name; + } + } + cout << ans << "\n"; + return 0; +} +const int MAXN = 5005; +int vis[MAXN][MAXN]; +int main() { + string s; + cin >> s; + int n = s.size(); + for (int i = 0; i < n; i++) { + int l = 0, r = 0; + for (int j = i; j < n; j++) { + if (s[j] != ')') + l++; + else + r++; + if (r > l) break; + vis[i][j]++; + } + } + for (int i = n - 1; i >= 0; i--) { + int l = 0, r = 0; + for (int j = i; j >= 0; j--) { + if (s[j] != '(') + r++; + else + l++; + if (r < l) break; + vis[j][i]++; + } + } + int ans = 0; + for (int i = 0; i < n; i++) + for (int j = i; j < n; j++) + if ((j - i + 1) % 2 == 0 && vis[i][j] == 2) ans++; + cout << ans << endl; + return 0; +} +bool comp(int x, int y) { + return x > y; +} +int main() { + int n, m, ans = 0; + vector v; + cin >> n >> m; + for (int i = 1; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + int fl = 1; + while (fl) { + int k; + sort(v.begin(), v.end(), comp); + if (v[0] >= m) { + m++; + v[0]--; + ans++; + } else + fl = 0; + } + cout << ans << endl; +} +const int MAXN = 2500, MAXM = 2500; +int S[MAXN + 1][MAXM + 1]; +int main() { + int N, M; + cin >> N >> M; + for (int i = 1; i <= N; ++i) { + string R; + cin >> R; + for (int j = 1; j <= M; ++j) S[i][j] = (R[j - 1] - '0') + S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1]; + } + int ans = INT_MAX; + for (int k = 2; k <= N || k <= M; ++k) { + int aux = 0; + for (int i = 1; i <= N; i += k) + for (int j = 1; j <= M; j += k) { + int ii = min(N, i + k - 1), jj = min(M, j + k - 1); + int q = S[ii][jj] - S[ii][j - 1] - S[i - 1][jj] + S[i - 1][j - 1]; + aux += min(q, k * k - q); + } + ans = min(ans, aux); + } + cout << ans << '\n'; + return 0; +} +int main() { + char a[10][10]; + int i, j; + for (i = 0; i < 8; i++) { cin >> a[i]; } + for (i = 0; i < 8; i++) { + for (j = 0; j < 7; j++) { + if (a[i][j] == a[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int n, a[200]; +int main() { + cin >> n; + int s, e; + s = e = 0; + for (int i = 1; i <= n; ++i) { + cin >> a[i]; + if (!s && a[i]) s = i; + if (a[i]) e = i; + } + int sum = 0; + int cnt = 0; + for (int i = s; i <= e;) { + if (a[i]) + sum++, ++i; + else { + if (i + 1 <= e && a[i + 1]) { + sum++; + ++i; + } else { + while (i + 1 <= e && a[i + 1] == 0) { ++i; } + ++i; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + while (l <= r && x <= y) { + if (l / x < k) + l++; + else if (l / float(x) == k) { + cout << "YES" << endl; + return 0; + } else + x++; + } + cout << "NO" << endl; + return 0; +} +string s[10]; +bool vis[7]; +void check(string a) { + if (a == "purple") vis[1] = 1; + if (a == "green") vis[2] = 1; + if (a == "blue") vis[3] = 1; + if (a == "orange") vis[4] = 1; + if (a == "red") vis[5] = 1; + if (a == "yellow") vis[6] = 1; + return; +} +int main() { + map mp; + mp.insert(pair(1, "Power")); + mp.insert(pair(2, "Time")); + mp.insert(pair(3, "Space")); + mp.insert(pair(4, "Soul")); + mp.insert(pair(5, "Reality")); + mp.insert(pair(6, "Mind")); + int n; + while (cin >> n) { + for (int i = 0; i < n; ++i) { + cin >> s[i]; + check(s[i]); + } + cout << 6 - n << '\n'; + for (int i = 1; i <= 6; ++i) + if (!vis[i]) { + map::iterator a = mp.find(i); + cout << a->second << '\n'; + } + } + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + string s; + cin >> s; + for (int i = 0; i < N; i++) { + if (s[i] == '0') { + cout << i + 1 << endl; + return 0; + } + } + cout << N << endl; + return 0; +} +int main() { + int n, k, mi_n = 1234567890, sum; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> sum; + if (k % sum == 0) { mi_n = min(k / sum, mi_n); } + } + cout << mi_n << endl; + return 0; +} +string a, b; +int wa, wb; +int main() { + cin >> a >> b; + for (int i = 0; i < a.size(); i += 2) { + if (a[i] == '8' && b[i] == '[') wa++; + if (a[i] == '[' && b[i] == '(') wa++; + if (a[i] == '(' && b[i] == '8') wa++; + if (b[i] == '8' && a[i] == '[') wb++; + if (b[i] == '[' && a[i] == '(') wb++; + if (b[i] == '(' && a[i] == '8') wb++; + } + if (wa > wb) + puts("TEAM 1 WINS"); + else if (wa < wb) + puts("TEAM 2 WINS"); + else + puts("TIE"); + return 0; +} +int main() { + int n; + cin >> n; + int nn[105]; + int a = 0; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (x % 2 == 1) { + nn[i] = 1; + a++; + } else + nn[i] = 0; + } + if (a != 1) a = 0; + for (int i = 1; i <= n; i++) { + if (nn[i] == a) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char arr[1000][1000]; + int p = 1; + char brr[] = {'B', 'W'}; + for (int i = 0; i < n; i++) { + if (i % 2 == 1) + p = 0; + else + p = 1; + for (int j = 0; j < m; j++) { + if (p == 0) + p = 1; + else if (p == 1) + p = 0; + char ch; + cin >> ch; + if (ch == '.') + arr[i][j] = brr[p]; + else + arr[i][j] = ch; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << arr[i][j]; } + cout << endl; + } +} +set x; +set y; +int main() { + int n; + cin >> n; + while (n--) { + int x1, y1; + cin >> x1 >> y1; + x.insert(x1); + y.insert(y1); + } + cout << min(x.size(), y.size()) << endl; +} +int main() { + int i, n, a, b; + cin >> n >> a >> b; + int arr[n], cost = 0; + bool possible = true; + for (i = 0; i < n; i++) cin >> arr[i]; + for (i = 0; i < n; i++) { + if (i > n - 1 - i) break; + if (i == n - 1 - i) { + if (arr[i] == 2) { cost += min(a, b); } + } else if (arr[i] == arr[n - 1 - i]) { + if (arr[i] == 2) { cost += 2 * min(a, b); } + } else { + if (arr[i] != 2 && arr[n - 1 - i] != 2) { + possible = false; + break; + } else { + if (arr[i] == 0 || arr[n - 1 - i] == 0) + cost += a; + else if (arr[i] == 1 || arr[n - 1 - i] == 1) + cost += b; + } + } + } + cout << (possible ? cost : -1) << '\n'; + return 0; +} +const long long N = 1e9 + 3; +const long long MN = 1e9 + 7; +const long long MX = -1e9 - 7; +long long n, a, b, x, c1, c2, cnt; +string s, s1; +bool bl = false; +long long c; +pair pr; +vector v; +map mp; +set st; +set::iterator it; +int main() { + cin >> n >> a >> b; + for (long long i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + if (v[b - 1] == v[b]) { + cout << 0; + } else { + cout << v[b] - v[b - 1]; + } + cout << "\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string l = "LEFT", r = "RIGHT", p = "PRINT ", s = ""; + for (int i = 0; i < n; ++i) { + char c; + cin >> c; + s += c; + } + if (abs(n - k) > abs(k - 1)) { + while (k > 1) { + cout << l << endl; + --k; + } + for (int i = 0; i < n - 1; ++i) { cout << p << s[i] << endl << r << endl; } + cout << p << s[n - 1] << endl; + } else { + while (k < n) { + cout << r << endl; + ++k; + } + for (int i = n - 1; i > 0; --i) { cout << p << s[i] << endl << l << endl; } + cout << p << s[0] << endl; + } + return 0; +} +int main() { + int r[200][200], a, b, c, d, e; + while (cin >> a) { + vector v2; + int v[200]; + for (b = 1; b <= a; b++) { + v[b] = 1; + for (c = 1; c <= a; c++) { cin >> r[b][c]; } + } + for (b = 1; b <= a; b++) { + for (c = 1; c <= a; c++) { + if (b == c) continue; + if (r[b][c] == 1) v[b] = 0; + if (r[b][c] == 2) v[c] = 0; + if (r[b][c] == 3) v[b] = 0, v[c] = 0; + } + } + c = 0; + for (b = 1; b <= a; b++) { + if (v[b] == 1) { + c++; + v2.push_back(b); + } + } + if (c) { + cout << c << endl; + for (d = 1; d <= c; d++) { + if (d == 1) { + cout << v2[d - 1]; + } else { + cout << " " << v2[d - 1]; + } + } + cout << endl; + } else { + cout << c << endl; + } + v2.clear(); + } + return 0; +} +int main() { + int n, k, a, m = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> a; + if (a % k == 0) + m += a / k; + else + m += a / k + 1; + } + cout << (m + 1) / 2 << "\n"; + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + if (d1 < d2) { + swap(d1, d2); + swap(u1, u2); + } + for (int i = h; i >= 0; i--) { + w += i; + if (i == d1) { + w -= u1; + if (w < 0) w = 0; + } else if (i == d2) { + w -= u2; + if (w < 0) w = 0; + } + } + if (w <= 0) + cout << "0" << endl; + else + cout << w << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + int arr[n]; + for (i = 0; i < n; i++) cin >> arr[i]; + int exe[3] = {0}; + for (i = 0; i < n; i++) exe[i % 3] += arr[i]; + int max = 0, mark; + for (i = 0; i < 3; i++) + if (max < exe[i]) { + max = exe[i]; + mark = i + 1; + } + if (mark == 1) + cout << "chest" << endl; + else if (mark == 2) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const int MOD = 1000000007; +void solve() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +int main() { + solve(); + return 0; +} +long long int i, j, k, m, n, a[10000], r; +double cnk(int n, int k) { + int a = 1, b = 1, c = 1, i; + if (k == 0) k = n; + if (n == 0) return 1; + for (i = 1; i <= n; i++) a *= i; + for (i = 1; i <= k; i++) b *= i; + for (i = 1; i <= n - k; i++) c *= i; + return a / (b * c); +} +int as(short q) { + int g = 1; + while (q != 0) { + g *= 2; + q--; + } + return g; +} +int main() { + char s1[200], s2[200]; + pair p[100000]; + bool t = false; + cin >> s1 >> s2; + if (strcmp(s1, s2) == 0) + cout << s1 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + long long n; + long long a = 1; + long long b = 2; + cin >> n; + if (n % 2 == 0) { + cout << b << endl; + } else { + cout << a << endl; + } +} +string s; +int main() { + cin >> s; + if (s == "a1" || s == "a8" || s == "h1" || s == "h8") { + cout << "3\n"; + } else if (s[0] == 'a' || s[0] == 'h' || s[1] == '1' || s[1] == '8') { + cout << "5\n"; + } else { + cout << "8\n"; + } + return 0; +} +int main() { + unsigned long long n, item, temp; + cin >> n; + if (n % 2 == 0) { + item = n / 2; + temp = n * 2 - item; + cout << temp << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + int sum = 0; + for (int i = 0; i < s1.size(); i++) { sum += min(abs(s1[i] - s2[i]), 10 - abs((s1[i] - s2[i]))); } + cout << sum << "\n"; +} +int n; +int main() { + int i, j; + cin >> n; + for (i = 1; i <= n / 2 + 1; i++) { + for (j = 1; j <= n / 2 + 1 - i; j++) { cout << "*"; } + for (j = 1; j <= i - 1; j++) { cout << "D"; } + cout << "D"; + for (j = 1; j <= i - 1; j++) { cout << "D"; } + for (j = 1; j <= n / 2 + 1 - i; j++) { cout << "*"; } + cout << '\n'; + } + for (i = n / 2; i >= 1; i--) { + for (j = 1; j <= n / 2 + 1 - i; j++) { cout << "*"; } + for (j = 1; j <= i - 1; j++) { cout << "D"; } + cout << "D"; + for (j = 1; j <= i - 1; j++) { cout << "D"; } + for (j = 1; j <= n / 2 + 1 - i; j++) { cout << "*"; } + cout << '\n'; + } + return 0; +} +int a[30][30]; +int main() { + int n; + string s; + cin >> n; + int l; + int d; + int aea; + int lol; + for (int i = 0; i < n; i++) { + cin >> s; + l = s.size(); + d = 0; + for (int j = 0; j < l; j++) { + if (s[j] != s[0] && d == 0) d = j; + if (s[j] != s[0] && s[j] != s[d]) d = -1; + } + if (d == 0) { + for (int j = 0; j < 30; j++) { + aea = s[0] - 'a'; + if (j != aea) { + a[j][aea] += l; + a[aea][j] += l; + } + } + } else if (d > 0) { + lol = s[0] - 'a'; + aea = s[d] - 'a'; + a[aea][lol] += l; + a[lol][aea] += l; + } else + ; + } + int maxi = 0; + for (int i = 0; i < 30; i++) { + for (int j = 0; j < 30; j++) { maxi = max(maxi, a[i][j]); } + } + cout << maxi << endl; +} +int main() { + int n, x; + cin >> n; + string s; + int c = 0; + for (int i = 0; i < n; i++) { + cin >> x; + cin >> s; + c = 0; + for (int j = 0, k = x - 1; j <= x / 2; j++, k--) { + if (s[j] == s[k]) + continue; + else if (s[j] - 1 == s[k] + 1 || s[j] + 1 == s[k] - 1) + continue; + else { + c = 1; + break; + } + } + if (c == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +string str; +int n; +int main() { + int i, j, t; + cin >> t; + while (t--) { + int flag = 1; + cin >> n; + cin >> str; + for (i = 0, j = n - 1; i < j; ++i, --j) { + if (str[i] == str[j]) continue; + if (abs(str[i] - str[j]) != 2) { + flag = 0; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int i, j, k, cnt1 = 0, cnt2 = 0, value = 0; + char a[101], b[101]; + cin >> a >> b; + for (i = 0; i < strlen(a); i++) { + if (a[i] >= 'A' && a[i] <= 'Z') { a[i] = a[i] + 'a' - 'A'; } + cnt1 += a[i]; + } + for (j = 0; j < strlen(b); j++) { + if (b[j] >= 'A' && b[j] <= 'Z') { b[j] = b[j] + 'a' - 'A'; } + cnt2 += b[j]; + } + for (i = 0; i < strlen(a); i++) { + if (a[i] > b[i]) { + value++; + break; + } else if (a[i] < b[i]) { + value--; + break; + } + } + cout << value << endl; + return 0; +} +int main() { + int a; + long long n, k; + cin >> n >> k; + if (k <= n) { + cout << 1 << endl; + } else { + if (k % n == 0) { + cout << k / n << endl; + } else { + cout << k / n + 1 << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "Mahmoud" << endl; + else + cout << "Ehab" << endl; +} +int main() { + bool x = true; + char arr[100]; + cin >> arr; + int cont = 0, i = 0, user_num = 0; + while (arr[cont] != '\0') { + i = cont + 1; + x = true; + while (arr[i] != '\0') { + if (arr[cont] == arr[i]) { + x = false; + break; + } else + i++; + } + if (x == true) { + user_num++; + cont++; + } else + cont++; + } + if (user_num % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +long long int mod = 1000000007; +int ncr[1001][1001]; +int k, tot; +int ct[1001]; +long long int dp[1001]; +void init() { + for (int i = 1; i <= 1000; i++) { + ncr[i][0] = 1; + ncr[i][1] = i; + for (int j = 2; j <= i; j++) { ncr[i][j] = ((ncr[i - 1][j]) % mod + (ncr[i - 1][j - 1]) % mod) % mod; } + } +} +long long int calc(int x) { + if (dp[x] != -1) { return dp[x]; } + if (x == 1) { + dp[x] = 1; + return dp[x]; + } + int n = ct[x]; + int r = ct[x] - ct[x - 1]; + long long int ans = (ncr[n - 1][r - 1] * (calc(x - 1)) % mod); + dp[x] = (int)ans; + return dp[x]; +} +int main() { + init(); + cin >> k; + for (int i = 1; i <= k; i++) { + cin >> ct[i]; + tot += ct[i]; + } + for (int i = 2; i <= k; i++) { ct[i] += ct[i - 1]; } + memset(dp, -1, sizeof(dp)); + cout << calc(k) << endl; + return 0; +} +int main() { + int n, k, j = 0, i = 0; + char a[300]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> k; + for (j = 0; j < k; j++) { cin >> a[j]; } + if (k == 2 && a[0] >= a[1]) { + cout << "NO\n"; + } else { + cout << "YES\n2\n" << a[0] << " "; + for (j = 1; j < k; j++) { cout << a[j]; } + cout << "\n"; + } + } + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + if (n > 26) + cout << m << endl; + else { + long long int t = pow(2, n); + cout << m % t << endl; + } + return 0; +} +const int inf = 1e9 + 7; +const long long longinf = 1LL << 60; +const long long mod = 1e9 + 7; +int main() { + int n, m; + cin >> n >> m; + if (n > 28) + cout << m << endl; + else + cout << m % (1 << n) << endl; + return 0; +} +bool makeChanges(char *s, int whichPosn, int size, int p, char adj, char nadj) { + if (whichPosn == -1) { return false; } + char thisChar = s[whichPosn]; + for (char x = thisChar + 1; x < 'a' + p; x++) { + if (x == adj || x == nadj) { continue; } + s[whichPosn] = x; + if (whichPosn == size - 1) { return true; } + char xx = s[whichPosn + 1]; + s[whichPosn + 1] = 'a' - 1; + if (makeChanges(s, whichPosn + 1, size, p, x, adj)) { + return true; + } else { + s[whichPosn + 1] = xx; + continue; + } + } + s[whichPosn] = thisChar; + nadj = whichPosn >= 3 ? s[whichPosn - 3] : 0; + adj = whichPosn >= 2 ? s[whichPosn - 2] : 0; + return (makeChanges(s, whichPosn - 1, size, p, adj, nadj)); +} +int main() { + int n, p; + cin >> n >> p; + char s[1005]; + cin >> s; + int whichPosn = n - 1; + char nadj = whichPosn >= 2 ? s[whichPosn - 2] : 0; + char adj = whichPosn >= 1 ? s[whichPosn - 1] : 0; + if (makeChanges(s, whichPosn, n, p, adj, nadj)) { + cout << s << '\n'; + } else { + cout << "NO\n"; + } + return 0; +} +int main() { + int n; + int min1, min2, min3, max1, max2, max3; + int S1, S2, S3; + cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; + if (n == max1 + min2 + min3) { + S1 = max1; + S2 = min2; + S3 = min3; + cout << S1 << " " << S2 << " " << S3 << endl; + } else if (n > max1 + min2 + min3) { + S1 = max1; + if ((n - S1 - max2) == min3) { + S2 = max2; + S3 = min3; + } else if ((n - S1 - max2) > min3) { + S2 = max2; + S3 = n - S1 - S2; + } else { + S2 = n - S1 - min3; + S3 = min3; + } + cout << S1 << " " << S2 << " " << S3 << endl; + } else { + S1 = n - min2 - min3; + S2 = min2; + S3 = min3; + cout << S1 << " " << S2 << " " << S3 << endl; + } + return 0; +} +int main() { + long long n, i, x, f = 0; + cin >> n; + vector v; + for (i = (1); i < (n); i++) { + cin >> x; + v.push_back(x); + } + sort((v).begin(), (v).end()); + if (v[n - 2] != n) { + cout << n << endl; + } else { + for (i = (0); i < ((int)((v).size())); i++) { + if (v[i] != (i + 1)) { + cout << i + 1 << endl; + break; + } + } + } + return 0; +} +int main() { + vector a; + int n, k, x, res = 0, num; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) { + cin >> num; + res += num; + a.push_back(num); + } + for (int i = 0; i < k; i++) { + res -= a.back(); + a.pop_back(); + res += x; + } + cout << res << endl; + return 0; +} +set myset; +int main() { + string s1, s2; + while (cin >> s1 >> s2) { + myset.clear(); + for (int i = 1; i <= s1.size(); i++) { + string tmp = ""; + tmp += s1.substr(0, i); + for (int j = 1; j <= s2.size(); j++) { + tmp += s2.substr(0, j); + myset.insert(tmp); + } + } + cout << *(myset.begin()) << endl; + } + return 0; +} +int main() { + long long int n, i; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long int mn, f = 0; + mn = a[1] - a[0]; + for (i = 2; i < n; i++) mn = min(mn, a[i] - a[i - 1]); + for (i = 1; i < n; i++) ((a[i] - a[i - 1]) == mn) ? f++ : f += 0; + cout << mn << " " << f << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[105]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int min_ = 0x3f3f3f3f; + for (int i = 1; i < n - 1; i++) { + int t = a[i]; + a[i] = a[i + 1]; + int max_ = -0x3f3f3f3f; + for (int j = 0; j < n - 1; j++) { + if (abs(a[j] - a[j + 1]) > max_) { max_ = abs(a[j] - a[j + 1]); } + } + if (max_ < min_) min_ = max_; + a[i] = t; + } + cout << min_ << endl; +} +int main() { + int n, k, i, a[100], cnt = 0; + cin >> n >> k; + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + if (a[i] >= a[k] && a[i] > 0) cnt++; + } + cout << cnt << endl; +} +int main() { + long double a, b, c; + cin >> a >> b >> c; + cout << (long long int)ceil(a * c / b - c) << endl; +} +int main() { + int t; + long long s, a, b, c; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + int bt = s / c; + cout << bt + (bt / a) * b << endl; + } + return 0; +} +int main() { + int n; + int64_t x, y, cnt = 0, res = 0; + string s; + cin >> n >> x >> y >> s; + for (int i = 0; i < n;) { + while (i < n && s[i] == '1') i++; + if (i < n) cnt++; + while (i < n && s[i] == '0') i++; + } + if (cnt > 0) res = (x < y ? x : y) * (cnt - 1) + y; + cout << res << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +long long fact(long long x) { + if (x <= 1) + return 1; + else + return x * fact(x - 1); +} +int main() { + long long a, b; + cin >> a >> b; + if (a > b) { + cout << fact(b) << endl; + } else + cout << fact(a) << endl; + return 0; +} +int main() { + int n, m, sum = 0; + cin >> n >> m; + int ar[n]; + for (int i = 0; i < n; i++) { + sum += i + 1; + ar[i] = sum; + } + m = m % ar[n - 1]; + int i = 0; + while (ar[i] <= m) ++i; + if (i == 0) + cout << m << endl; + else + cout << m - ar[i - 1] << endl; +} +int main() { + int n, num[200000], first = 1000000001; + string ch; + cin >> n >> ch; + for (int i = 0; i < n; i++) { cin >> num[i]; } + int i = 0; + while (n > 0) { + if (ch[i] == 'R' && ch[i + 1] == 'L') { + int nf = num[i + 1] - num[i]; + nf = (nf + 2 - 1) / 2; + if (nf < first) first = nf; + } + i++; + n--; + } + if (first == 1000000001) + cout << "-1" << endl; + else + cout << first << endl; + return 0; +} +int main() { + int nuts, divis, maxsec, capacity, boxes = 0; + cin >> maxsec >> nuts >> divis >> capacity; + while (nuts > 0) { + boxes++; + int temp = min(maxsec, divis + 1); + nuts -= (temp * capacity); + divis -= (temp - 1); + } + cout << boxes << endl; + return 0; +} +int n; +long long a[200001], ans; +int main() { + cin >> n; + for (int i = 1; i <= (n << 1); i++) cin >> a[i]; + sort(a + 1, a + (n << 1) + 1); + ans = (a[n] - a[1]) * (a[n << 1] - a[n + 1]); + for (int i = 1; i < n; i++) ans = min((a[n << 1] - a[1]) * (a[n + i] - a[i + 1]), ans); + cout << ans << endl; + return 0; +} +int a[60], b[60]; +int main() { + int x, y, i, j, temp = 0, ans = 0; + cin >> x; + for (i = 0; i < x; i++) cin >> a[i]; + cin >> y; + for (i = 0; i < y; i++) { + cin >> b[i]; + for (j = 0; j < x; j++) { + if (b[i] % a[j] == 0) temp = max(temp, b[i] / a[j]); + } + } + for (i = 0; i < x; i++) + for (j = 0; j < y; j++) { + if (b[j] % a[i] == 0) + if (b[j] / a[i] == temp) ans++; + } + cout << ans << endl; + return 0; +} +void solve() { + int64_t x, y, p, q; + cin >> x >> y >> p >> q; + if (x * q == y * p) { + cout << 0 << endl; + return; + } + if (p == 0 && x > 0) { + cout << -1 << endl; + return; + } + if (p == 1 && q == 1 && x < y) { + cout << -1 << endl; + return; + } + int64_t a; + if (q * x < y * p) { + a = (y * p - q * x) / (q - p); + if ((x + a) * q < (y + a) * p) a++; + } else { + a = (q * x - p * y) / p; + if (x * q > (y + a) * p) a++; + } + if ((y + a) % q > 0) { a += q - ((y + a) % q); } + cout << a << endl; + return; +} +int main() { + int t; + cin >> t; + while (t--) { solve(); } + return 0; +} +const int N = 210; +int n; +int in[N]; +int main() { + while (cin >> n) { + for (int i = 0; i < 2 * n; i++) { cin >> in[i]; } + sort(in, in + 2 * n); + if (in[n] > in[n - 1]) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +string a; +long long b; +bool c, d; +int main() { + cin >> a; + if (a[0] == 'h' || a[0] == 'a') c = 1; + if (a[1] == '8' || a[1] == '1') d = 1; + if (c == 1 && d == 1) b++; + if (c == 1) b = b - 3; + if (d == 1) b = b - 3; + cout << b + 8 << endl; +} +int main() { + int n, x, y, c = 0, c1 = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x > y) + c++; + else if (y > x) + c1++; + } + if (c > c1) + cout << "Mishka" << endl; + else if (c1 > c) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int const OO = 1e9; +void fast() {} +void file() { + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +int main() { + fast(); + int n, m; + while (cin >> n) { + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + cin >> m; + vector vv(m); + for (int i = 0; i < m; i++) { cin >> vv[i]; } + sort(vv.rbegin(), vv.rend()); + long long an = 0; + for (int i = 0, c = 0; i < m; i++) { + if (c == v[0]) { + c = 0, i++; + continue; + } + an += vv[i], c++; + } + cout << an << '\n'; + } + return 0; +} +long long n; +vector v; +long long kq(long long k) { + long long temp = 0; + while (k) { + temp += k % 10; + k /= 10; + } + return temp; +} +int main() { + cin >> n; + for (int i = n; i > n - 100; --i) { + if (kq(i) + i == n) v.push_back(i); + } + cout << v.size() << endl; + for (int i = v.size() - 1; i >= 0; --i) { cout << v[i] << endl; } + return 0; +} +int main() { + int n, b, d, sum = 0, ans = 0; + cin >> n >> b >> d; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + if (t <= b) { + sum += t; + if (sum > d) { + sum = 0; + ans++; + } + } + } + cout << ans << endl; +} +int did[103]; +int main() { + long long n, m; + pair p; + p.first = 1; + p.second = 0; + cin >> n >> m; + long long x; + pair maxx; + for (int i = 1; i <= m; i++) { + cin >> x; + maxx.first = 1; + maxx.second = x; + for (int j = 2; j <= n; j++) { + cin >> x; + if (x > maxx.second) { + maxx.first = j; + maxx.second = x; + } + } + did[maxx.first]++; + if (did[maxx.first] > p.second) { + p.first = maxx.first; + p.second = did[maxx.first]; + } else if (did[maxx.first] == p.second) { + p.first = p.first < maxx.first ? p.first : maxx.first; + } + } + cout << p.first << "\n"; +} +int main() { + int n, a[5001], x = 0, y = 0, z = 0, w = 0; + int b[5001], c[5001], d[5001]; + int k = 0, l = 0, m = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] == 1) { + x++; + b[k] = i + 1; + k++; + } else if (a[i] == 2) { + y++; + c[l] = i + 1; + l++; + } else if (a[i] == 3) { + z++; + d[m] = i + 1; + m++; + } + } + w = min(min(x, y), z); + cout << w << endl; + k = l = m = 0; + for (int i = 0; i < w; i++) { + cout << b[k] << " " << c[l] << " " << d[m] << endl; + k++; + l++; + m++; + } + return 0; +} +int main() { + int n; + int count; + while (cin >> n) { + int temp = 0; + count = n; + int a; + for (int i = 0; i < n; i++) { + cin >> a; + if (!a) { + if (i == n - 1) { + if (temp == 1) + count -= 2; + else { + temp = 1; + count--; + } + } else if (i == 0) { + temp = 2; + count--; + } else if (temp == 1) { + count -= 2; + temp++; + } else if (temp >= 2) + count--; + else + temp = 1; + } else { + temp = 0; + } + } + cout << count << endl; + } +} +int main() { + int n; + cin >> n; + int p, q; + int a[n] = {0}; + cin >> p; + int lk; + for (int i = 0; i < p; i++) { + cin >> lk; + a[lk - 1] = 1; + } + cin >> q; + for (int i = 0; i < q; i++) { + cin >> lk; + a[lk - 1] = 1; + } + int f = 1; + for (int i = 0; i < n; i++) { + if (a[i] != 1) f = 0; + } + if (f == 0) + cout << "Oh, my keyboard!" << endl; + else + cout << "I become the guy." << endl; +} +int n, a, b, x[101], y[101], cnt, dnt; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + x[a]++; + y[b]++; + } + for (int i = 0; i < 101; i++) { + if (x[i] != 0) cnt++; + if (y[i] != 0) dnt++; + } + cout << min(cnt, dnt) << endl; +} +int main() { + long long int i, n, k, w, sum = 0, x, y; + cin >> k >> n >> w; + x = (w * (w + 1)) / 2; + x = x * k; + y = x - n; + if (y > 0) { + cout << y; + } else { + cout << "0"; + } + cout << "\n"; +} +const int N = 2e3 + 5; +int main() { + long long n; + cin >> n; + cout << 2 << endl; + for (long long i = 2; i <= n; i++) cout << ((i + 1) * (i + 1) * i) - (i - 1) << endl; + return 0; +} +int res[3][3]; +void toggle(int p[3][3], int a, int b) { + if (p[a][b] == 1) + p[a][b] = 0; + else if (p[a][b] == 0) + p[a][b] = 1; +} +int main() { + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) res[i][j] = 1; + int c; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> c; + if (c > 0 & c % 2 == 1) { + toggle(res, i, j); + if (i + 1 < 3) toggle(res, i + 1, j); + if (j + 1 < 3) toggle(res, i, j + 1); + if (i - 1 >= 0) toggle(res, i - 1, j); + if (j - 1 >= 0) toggle(res, i, j - 1); + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << res[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, m, u, v, x, y; + cin >> n; + int a[105] = {0}; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + cin >> u >> v; + if (u > v) { swap(u, v); } + int m1 = 0, m2 = 0; + for (int i = u; i < v; i++) { m1 += a[i]; } + for (int i = 1; i <= n; i++) { + if (i < u || i >= v) { m2 += a[i]; } + } + if (u == v) { + cout << 0 << endl; + } else { + cout << min(m1, m2) << endl; + } + return 0; +} +int main() { + int n, l = 1, r = 1; + string s; + cin >> n; + while (n--) { + cin >> s; + if (s == "UL" || s == "DR") + l++; + else if (s.size() == 2) + r++; + else { + l++; + r++; + } + } + cout << (long long int)l * r << endl; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long x = (n / 2) / (1 + k); + cout << x << " " << x * k << ' ' << n - (x) * (1 + k) << "\n"; + } + return 0; +} +long long N, A[100], sum, ans, H; +int main() { + cin >> N; + for (int i = 1; i <= N; i++) { cin >> A[i]; } + if (N == 1) { + if (A[N] == 0) + cout << "UP\n"; + else if (A[N] == 15) + cout << "DOWN\n"; + else + cout << "-1\n"; + } else if (A[N] == 15) + cout << "DOWN\n"; + else if (A[N] == 0) + cout << "UP\n"; + else if (A[N] > A[N - 1]) + cout << "UP\n"; + else if (A[N] < A[N - 1]) + cout << "DOWN\n"; + else + cout << "-1\n"; +} +const int Maxn = 1000000; +char c[10000]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> c[i]; } + sort(c + 1, c + n + 1); + int sum = c[1] - 'a' + 1, gs = 1; + char d = c[1]; + for (int i = 2; i <= n; i++) { + if (gs == m) break; + if (c[i] - d > 1) { + d = c[i]; + gs++; + sum += d - 'a' + 1; + } + } + if (gs != m) + cout << -1 << endl; + else + cout << sum << endl; + return 0; +} +void fast_io() {} +long long a, b, c, l; +long long dp[200001]; +long long query(long long x) { + return (x + 2) * (x + 1) / 2; +} +int main() { + fast_io(); + cin >> a >> b >> c >> l; + long long ans = 0; + for (long long ajout = 0; ajout <= l; ajout++) { + long long v1 = (ajout + b + c - a + 1LL) / 2; + long long v2 = (ajout + a + c - b + 1LL) / 2; + long long v3 = (ajout + a + b - c + 1LL) / 2; + if (v1 > 0 and v2 > 0 and v3 > 0) { + ans += query(ajout); + if (ajout >= v1) ans -= query(ajout - v1); + if (ajout >= v2) ans -= query(ajout - v2); + if (ajout >= v3) ans -= query(ajout - v3); + if (ajout >= v1 + v2) ans += query(ajout - v1 - v2); + if (ajout >= v2 + v3) ans += query(ajout - v2 - v3); + if (ajout >= v1 + v3) ans += query(ajout - v1 - v3); + if (ajout >= v1 + v2 + v3) ans -= query(ajout - v1 - v2 - v3); + } + } + cout << ans << endl; +} +vector asd; +vector wtf; +int main() { + string z; + cin >> z; + long long s = z.size(); + bool cek = false; + for (long long q = 0; q < s; q++) { + if (z[q] != '.' && cek == false) { + asd.push_back(z[q]); + } else { + cek = true; + } + if (cek == true) { wtf.push_back(z[q]); } + } + s = asd.size(); + long long d = asd[s - 1] - '0'; + if (d == 9) { + cout << "GOTO Vasilisa." << endl; + } else { + long long dsa = wtf[1] - '0'; + if (dsa < 5) { + for (long long q = 0; q < s; q++) { cout << asd[q]; } + } else { + for (long long q = 0; q < s - 1; q++) { cout << asd[q]; } + cout << asd[asd.size() - 1] - '0' + 1; + } + cout << endl; + } +} +int main() { + int distance[3], meet, i; + for (i = 0; i < 3; i++) cin >> distance[i]; + sort(distance, distance + 3); + meet = distance[2] - distance[1]; + meet = meet + distance[1] - distance[0]; + cout << meet << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i < (n + 1) / 2 + 1) { + for (int j = 1; j <= n; j++) { + if (j <= (n + 1) / 2 + (i - 1) && j >= (n + 1) / 2 - (i - 1)) + cout << "D"; + else + cout << "*"; + } + } else { + for (int j = 1; j <= n; j++) { + if (j <= (n + 1) / 2 + (n - i) && j >= (n + 1) / 2 - (n - i)) + cout << "D"; + else + cout << "*"; + } + } + cout << endl; + } +} +map m1; +map::iterator itr; +int main() { + long long int n, k; + cin >> n >> k; + string str; + cin >> str; + long long int pos1, pos2; + for (long long int i = 0; i < n; i++) { + if (str[i] == 'G') pos1 = i; + if (str[i] == 'T') pos2 = i; + } + if (pos1 > pos2) { + while (pos1 > pos2) { + pos1 = pos1 - k; + if (str[pos1] == '#') { + cout << "NO" << endl; + return 0; + } + } + if (pos1 == pos2) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + } else { + while (pos1 < pos2) { + pos1 = pos1 + k; + if (str[pos1] == '#') { + cout << "NO" << endl; + return 0; + } + } + if (pos1 == pos2) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + cin >> n; + set st; + int X; + cin >> X; + for (int i = 0; i < X; i++) { + int x; + cin >> x; + st.insert(x); + } + int Y; + cin >> Y; + for (int i = 0; i < Y; i++) { + int y; + cin >> y; + st.insert(y); + } + if (st.size() >= n) { + cout << "I become the guy." << endl; + } else { + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int main() { + int n, x; + cin >> n >> x; + vector aa(n); + for (int i = 0; i < n; ++i) cin >> aa[i]; + int sum = 0; + for (int i = 0; i < n; ++i) sum += aa[i]; + int need = abs(sum) / x; + int b = abs(sum) % x; + if (b > 0) need++; + cout << need << endl; +} +int main() { + int n, k; + cin >> n >> k; + int count = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + int t = 0; + for (int j = 0; j < s.length(); j++) { + if (s[j] == '4' || s[j] == '7') { t++; } + } + if (t <= k) count++; + } + cout << count << endl; +} +void fastIo() {} +int main() { + fastIo(); + long long k, n, w; + cin >> k >> n >> w; + long long sum = (k * (w * (w + 1) / 2)) - n; + if (sum >= 0) + cout << sum << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long cur = 2; + for (int i = 0; i < (n); i++) { + long long l = i + 1; + long long k = (((l + 1) * l * (l + 1)) - cur / l); + cout << k << '\n'; + cur = l * (l + 1); + } + return 0; +} +int t; +int a[1005]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { cin >> a[i]; } + sort(a + 1, a + 1 + t, cmp); + for (int i = 1; i <= t; i++) { + if ((int)sqrt(a[i]) * (int)sqrt(a[i]) != a[i]) { + cout << a[i] << endl; + break; + } + } + return 0; +} +int main() { + int T, i, j, count = 1, d, m = 0; + char s[1000], k[1000]; + cin >> T >> s; + j = strlen(s); + sort(s, s + j); + for (i = 0; i < j; i++) { + if (s[i] == s[i + 1]) { + count += 1; + } else { + if (count % T == 0) { + d = count / T; + while (d--) { + k[m] = s[i]; + m++; + } + count = 1; + } else { + cout << "-1" << endl; + return 0; + } + } + } + k[m] = '\0'; + while (T--) { + for (i = 0; k[i] != '\0'; i++) { cout << k[i]; } + } + cout << endl; + return 0; +} +int main() { + int a[5][5] = {0}; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + int x; + cin >> x; + x %= 2; + if (x) { + a[i][j] = (a[i][j] + 1) % 2; + a[i + 1][j] = (a[i + 1][j] + 1) % 2; + a[i][j + 1] = (a[i][j + 1] + 1) % 2; + a[i - 1][j] = (a[i - 1][j] + 1) % 2; + a[i][j - 1] = (a[i][j - 1] + 1) % 2; + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cout << !a[i][j]; } + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i < n + 1; ++i) { + if (i % 2 == 1) { + for (int j = 0; j < m; ++j) cout << "#"; + cout << endl; + } else if (i % 4 == 0) { + cout << "#"; + for (int j = 0; j < m - 1; ++j) cout << "."; + cout << endl; + } else { + for (int j = 0; j < m - 1; ++j) cout << "."; + cout << "#" << endl; + } + } +} +int n, m, i; +int main() { + string s; + cin >> n >> m; + cin >> s; + sort(s.begin(), s.end()); + int cnt = -1, num = 0; + for (int i = 0; i < n; i++) + if (s[i] >= cnt + 2 && m) { + cnt = s[i]; + num += s[i] - 'a' + 1; + m -= 1; + } + if (m) + cout << -1 << endl; + else + cout << num << endl; + ; +} +int main() { + int n; + cin >> n; + cout << (n / 2) * 3 << endl; + return 0; +} +int n, m, tem_max; +int a[110][110]; +int b[110]; +int main() { + cin >> n >> m; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + tem_max = tem_max > a[i][j] ? tem_max : a[i][j]; + } + for (int k = 0; k < n; k++) { + if (a[i][k] == tem_max) { + b[k]++; + tem_max = 0; + break; + } + } + } + for (int o = 0; o < n; o++) { + if (b[o] == *max_element(b, b + n)) { + cout << o + 1 << endl; + break; + } + } + return 0; +} +char a[111][111]; +string b; +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> b; + for (int j = 1; j <= m; j++) { + if (b[j - 1] == '.') { + if ((i + j) % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + if (b[j - 1] == '-') a[i][j] = '-'; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < k; i++) { + if (n % 10 == 0) + n = n / 10; + else + n = n - 1; + } + cout << n << endl; + return 0; +} +const double pi = 3.14159265359; +const int INF = 0x3f3f3f3f; +int main() { + int n, temp; + int p, q; + set x; + cin >> n; + cin >> p; + for (int i = 1; i <= p; i++) { + cin >> temp; + x.insert(temp); + } + cin >> q; + for (int i = 1; i <= q; i++) { + cin >> temp; + x.insert(temp); + } + if (x.size() == n) + cout << "I become the guy.\n"; + else + cout << "Oh, my keyboard!\n"; + return 0; +} +string doesIt(string a) { + string token = "hello"; + int j = 0; + for (int i = 0; i < a.length(); i++) { + if (a[i] == token[j]) { j++; } + } + if (j == token.length()) { + return "YES"; + } else { + return "NO"; + } +} +int main() { + string a; + cin >> a; + cout << doesIt(a) << endl; + return 0; +} +long long power(long long a, long long b, long long mod) { + long long c = 1; + while (b > 0) { + if (b % 2) c *= a, c %= mod; + b /= 2; + a *= a; + a %= mod; + } + return c; +} +int main() { + long long n; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + long long x = 0, mx = -1e18; + for (long long i = 0; i < n; i++) { + x = 0; + for (long long j = i; j < n; j++) { + x = x ^ a[j]; + mx = max(mx, x); + } + } + cout << mx << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < (n); i++) { cin >> a[i]; } + int i = 0; + while (i < n - 1 && a[i] < a[i + 1]) i++; + while (i < n - 1 && a[i] == a[i + 1]) i++; + while (i < n - 1 && a[i] > a[i + 1]) i++; + if (i != n - 1) { + cout << ("NO") << '\n'; + return 0; + } + cout << ("YES") << '\n'; + return 0; +} +int dir1[8][2] = {1, 2, 2, 1, 2, -1, 1, -2, -1, 2, -2, 1, -1, -2, -2, -1}; +int dir2[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; +int dir3[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; +int gcd(int x, int y) { + return y == 0 ? x : gcd(y, x % y); +} +bool isPrime(int x) { + if (x == 1) + return false; + else if (x == 2) + return true; + for (int i = 2; i <= sqrt(x * 1.0); ++i) { + if (x % i == 0) return false; + } + return true; +} +int sqr(int x) { + return x * x; +} +int main() { + string s; + while (cin >> s) { + int ans = 0; + int cnt = 0; + for (int i = 1; i < s.size(); ++i) { + if (s[i] == s[i - 1]) + cnt++; + else { + if (cnt & 1) ans++; + cnt = 0; + } + } + ans += (cnt & 1); + cout << ans << endl; + } + return 0; +} +int main() { + int x, q; + cin >> x; + if (x % 5 == 0) { + q = x / 5; + } else { + q = x / 5; + q++; + } + cout << q << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (size_t i = 0; i < s1.length(); ++i) { + if (s1[i] == s2[i]) { + s1[i] = '0'; + } else { + s1[i] = '1'; + } + } + cout << s1 << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + for (i = 1; i <= n; i++) { + if (i % 2 != 0 && i == n) + cout << "I hate "; + else if (i % 2 == 0 && i == n) + cout << "I love "; + else if (i % 2 != 0) + cout << "I hate that "; + else if (i % 2 == 0) + cout << "I love that "; + } + cout << "it" << endl; + return 0; +} +int main() { + int n, k, i, j, ans; + cin >> n >> k; + vector a(n + 1); + for (i = 1; i <= n; i++) cin >> a[i]; + bool valid = true; + for (i = k; i <= n; i++) { + if (a[i] != a[k]) valid = false; + } + if (!valid) + ans = -1; + else { + a[0] = -1; + for (i = k; (a[i] == a[k]) && (i > 0); i--) + ; + ans = i; + } + cout << ans << "\n"; + return 0; +} +int main() { + long long T = 1; + while (T--) { + long long n, m; + cin >> n >> m; + bool goodCell[51][51]; + for (long long i = 0; i < n; i++) { + for (long long j = 0; j < m; j++) { + cin >> goodCell[i][j]; + if ((i == 0 || j == 0 || i == n - 1 || j == m - 1) && goodCell[i][j]) { + cout << 2 << '\n'; + return 0; + } + } + } + cout << 4 << '\n'; + } + return 0; +} +int main() { + int x, m, h, count = 0; + cin >> x; + cin >> h >> m; + for (int i = 1;; i++) { + if (h % 10 == 7 || h / 10 == 7 || m % 10 == 7 || m / 10 == 7) { break; } + m = m - x; + if (m < 0) { + m = 60 + m; + --h; + if (h < 0) { h = 24 + h; } + ++count; + } else { + ++count; + } + } + cout << count << endl; +} +int main() { + int n, i, q, w, e, r, t, y; + string s[6]; + cin >> n; + q = w = e = r = t = y = 0; + for (i = 0; i < n; i++) { cin >> s[i]; } + for (i = 0; i < n; i++) { + if (s[i] == "purple") + q = 1; + else if (s[i] == "green") + w = 1; + else if (s[i] == "blue") + e = 1; + else if (s[i] == "orange") + r = 1; + else if (s[i] == "red") + t = 1; + else if (s[i] == "yellow") + y = 1; + } + cout << 6 - n << endl; + if (q == 0) cout << "Power" << endl; + if (w == 0) cout << "Time" << endl; + if (e == 0) cout << "Space" << endl; + if (r == 0) cout << "Soul" << endl; + if (t == 0) cout << "Reality" << endl; + if (y == 0) cout << "Mind" << endl; + return 0; +} +inline int gcd(int a, int b) { + if (b != 0) + return gcd(b, a % b); + else + return a; +} +inline bool beat(char x, char y) { + if (x == 'P' && y == 'R' || x == 'R' && y == 'S' || x == 'S' && y == 'P') return true; + return false; +} +string a, b; +int n; +inline pair solve(int n) { + int a1 = 0, a2 = 0; + for (int i = 0; i < n; i++) { + if (beat(a[i % a.size()], b[i % b.size()])) a1++; + if (beat(b[i % b.size()], a[i % a.size()])) a2++; + } + return make_pair(a1, a2); +} +int main() { + cin >> n; + cin >> a >> b; + int c = a.size() / gcd(a.size(), b.size()) * b.size(); + pair t = solve(c); + t.first *= (n / c), t.second *= (n / c); + t.first += solve(n % c).first, t.second += solve(n % c).second; + cout << t.second << ' ' << t.first << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + char a[8][8]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) cin >> a[i][j]; + bool flag = true; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 7; j++) { + if (a[i][j] == a[i][j + 1]) { + flag = false; + break; + } + } + if (flag == false) break; + } + if (flag == false) + cout << "NO" << '\n'; + else + cout << "YES" << '\n'; + } + return 0; +} +int main() { + int n, b, d; + cin >> n >> b >> d; + int sum = 0; + int count = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a <= b) { sum += a; } + if (sum > d) { + count++; + sum = 0; + } + } + cout << count << endl; +} +int a[400]; +int n, k, c, x; +int main() { + cin >> n >> k; + cin >> c; + for (int i = 0; i < c; i++) { cin >> a[i]; } + int ans = 0; + int d = 0, t = 0; + while (d <= n) { + if (d + k < a[t] || t >= c) { + d += k; + if (d <= n) ans++; + } else { + d = a[t++]; + if (d <= n) ans++; + } + } + cout << ans << endl; + return 0; +} +const int N = 1e5 + 5, inf = 1e9 + 7; +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int cnt = 0; + int x = b; + while (k <= x && a > 0) { + cnt++; + a -= (v * k); + x -= (k - 1); + } + if (a > 0) { + a -= (v * (x + 1)); + cnt++; + } + if (a > 0) cnt += (a / v + (a % v != 0)); + cout << cnt << "\n"; + return 0; +} +int main() { + int i, j, k, l, n, h = 0, m = 0, gh, gm, p; + cin >> n >> l; + for (i = 1; i <= n; i++) { + cin >> gh >> gm; + gh = (gh * 60) + gm; + if (i == 1 && gh - h >= l + 1) { + cout << 0 << " " << 0 << endl; + p = i; + break; + } + if (gh - h >= l + l + 2) { + cout << (h + l + 1) / 60 << " " << (h + l + 1) % 60 << endl; + p = i; + break; + } + if (i == n) { + cout << (gh + l + 1) / 60 << " " << (gh + l + 1) % 60 << endl; + p = i; + break; + } + h = gh; + } + for (i = 1; i <= n - p; i++) cin >> gh >> gm; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + vector v(n); + for (int i = 0; i < n; ++i) cin >> v[i]; + sort(v.begin(), v.end()); + int i = 0, j = n - 1; + while (v[j] - v[i] > d) --j; + int mx = j - i + 1; + while (j < n) { + while (v[j] - v[i] > d) ++i; + mx = max(mx, j - i + 1); + ++j; + } + cout << n - mx << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10) + cout << 0 << "\n"; + else { + if (n >= 11 && n <= 19) + cout << 4 << "\n"; + else { + if (n == 20) + cout << 15 << "\n"; + else if (n == 21) + cout << 4 << "\n"; + else + cout << 0 << "\n"; + } + } + return 0; +} +int main() { + char c[2000], s[2000]; + int n, p; + cin >> n >> p; + cin >> c; + if (p == 1 && n > 1) { + cout << "NO\n"; + return 0; + } else if (p == 2 && n > 2) { + cout << "NO\n"; + return 0; + } + for (int i = n - 1; i >= 0; i--) { + for (char a = c[i] + 1; a <= 'a' + p - 1; a++) { + if (i - 1 >= 0 && c[i - 1] == a) continue; + if (i - 2 >= 0 && c[i - 2] == a) continue; + c[i] = a; + for (int j = i + 1; j < n; j++) { + for (char b = 'a'; b <= 'a' + p - 1; b++) { + if (j - 1 >= 0 && c[j - 1] == b) continue; + if (j - 2 >= 0 && c[j - 2] == b) continue; + c[j] = b; + break; + } + } + c[n] = '\0'; + cout << c << endl; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int main() { + long long int x, y, m, count = 0; + cin >> x >> y >> m; + if (x < y) swap(x, y); + if (x <= 0) { + cout << (x < m ? -1 : 0) << endl; + return 0; + } + if (y < 0 && x < m) { + count += (x - y) / x; + y += ((x - y) / x) * x; + } + while (x < m && y < m) { + x > y ? y += x : x += y; + count++; + } + cout << count << endl; + return 0; + return 0; +} +int main() { + string a; + cin >> a; + sort(a.begin(), a.end()); + int b = a.size(), c = b; + for (int i = 0; i < b; i++) { + if (a[i] == a[i + 1]) { c--; } + } + if (c % 2 == 0) { + cout << "CHAT WITH HER!\n"; + } else { + cout << "IGNORE HIM!\n"; + } + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int ans = 0; + for (int i = 0; i < len; i++) { + int r = 0, t = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + r++; + else if (s[j] == ')') + r--; + else + r--, t++; + if (r == 0) ans++; + if (r < 0 && t > 0) + r += 2, t--; + else if (r > 0) + continue; + else if (r < 0 && !t) + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + string s; + cin >> s; + string a[5]; + for (long long int i = 0; i < 5; i++) cin >> a[i]; + bool flag = false; + for (long long int i = 0; i < 5; i++) { + if (a[i][0] == s[0] || a[i][1] == s[1]) { + flag = true; + break; + } + } + if (flag == true) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (min(n, m) % 2) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; + return 0; +} +int main() { + int n; + cin >> n; + map m; + m[0] = "O-|-OOOO"; + m[1] = "O-|O-OOO"; + m[2] = "O-|OO-OO"; + m[3] = "O-|OOO-O"; + m[4] = "O-|OOOO-"; + m[5] = "-O|-OOOO"; + m[6] = "-O|O-OOO"; + m[7] = "-O|OO-OO"; + m[8] = "-O|OOO-O"; + m[9] = "-O|OOOO-"; + if (n == 0) { + cout << m[0] << endl; + return 0; + } + while (n != 0) { + cout << m[n % 10] << endl; + n = n / 10; + } +} +int main() { + int n; + cin >> n; + int a[n]; + int maxx = 1; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int l = 1; + for (int i = 0; i < n - 1; i++) { + if (a[i] < a[i + 1]) { + l++; + maxx = max(maxx, l); + } else { + l = 1; + } + } + return cout << maxx << endl, 0; +} +void subtraction(istream &r, ostream &w) { + int arg1, arg2; + r >> arg1; + r >> arg2; + if (arg1 > arg2) { + int temp = arg1; + arg1 = arg2; + arg2 = temp; + } + int quotient = 0; + int remainder; + do { + quotient += arg2 / arg1; + remainder = arg2 % arg1; + arg2 = arg1; + arg1 = remainder; + } while (remainder != 0); + w << quotient << endl; +} +void evaluate(istream &r, ostream &w) { + int numOfTestCases; + r >> numOfTestCases; + for (int i = 1; i <= numOfTestCases; i++) { subtraction(r, w); } +} +int main() { + evaluate(cin, cout); + return 0; +} +int main() { + long long int n; + cin >> n; + if (n < 0) { + int x = n % 10; + int y = n / 10; + y = y % 10; + if (y < 0) { y = -y; } + if (x < 0) { x = -x; } + if (x > y) { + n /= 10; + } else { + y = y - x; + y *= 10; + n += y; + n /= 10; + } + } + cout << n << endl; +} +int main() { + string a, b; + while (cin >> a >> b) { + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + } + return 0; +} +int main() { + unsigned long long n; + cin >> n; + cout << "25" << endl; +} +void fast() {} +int main() { + fast(); + int n, i; + cin >> n; + char s1[n], s2[n]; + for (i = 0; i < n; i++) cin >> s1[i]; + for (i = 0; i < n; i++) cin >> s2[i]; + int c = 0, ans; + for (i = 0; i < n; i++) { + ans = min(s1[i], s2[i]); + if (ans == s1[i]) + c += min(abs(s1[i] - s2[i]), abs(10 + (s1[i] - '0') - (s2[i] - '0'))); + else + c += min(abs(s1[i] - s2[i]), abs(10 + (s2[i] - '0') - (s1[i] - '0'))); + } + cout << c << endl; +} +int main() { + int w, h, k, res = 0, i = 0; + cin >> w >> h >> k; + while (k--) { + res += 2 * (w - (4 * i) + h - (4 * i)) - 4; + i++; + } + cout << res << endl; +} +int main() { + int n; + cin >> n; + for (int i = floor(sqrt(n)); i >= 1; i--) { + if (n % i == 0) { + cout << i << " " << n / i << endl; + return 0; + } + } +} +int main() { + long long floorNum, floorToGo, temp, k; + cin >> floorNum; + floorToGo = floorNum; + bool shouldContinue = true, isLucky = false; + while (shouldContinue) { + floorToGo++; + temp = floorToGo; + isLucky = false; + while (temp) { + if (temp % 10 == 8 || temp % 10 == -8) { + isLucky = true; + break; + } + temp /= 10; + } + if (isLucky) shouldContinue = false; + } + cout << floorToGo - floorNum << endl; + return 0; +} +int n, s; +int main() { + cin >> n >> s; + cout << s / n + (s % n != 0) << endl; +} +int main() { + long long t; + cin >> t; + for (long long i = 0; i < t; i++) { + long long n; + cin >> n; + string s; + cin >> s; + long long hi = n - 1; + long long lo = 0; + bool ans = true; + while (hi >= lo) { + char c1 = s[lo++]; + char c2 = s[hi--]; + if (c1 == c2 || abs(c1 - c2) == 2) + ; + else { + ans = false; + break; + } + } + if (ans) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } +} +int main() { + long long i, p, q, d, k; + string ky = "v>^<"; + char a, b; + cin >> a >> b >> k; + for (p = 0; p < 4; p++) { + if (a == ky[p]) { break; } + } + for (q = 0; q < 4; q++) { + if (b == ky[q]) { break; } + } + d = (p + 4 - q) % 4; + if (d == 0 || d == 2) { + cout << "undefined\n"; + } else if (d == k % 4) { + cout << "cw\n"; + } else { + cout << "ccw\n"; + } +} +bool players[4]; +int main() { + players[1] = true; + players[2] = true; + players[3] = false; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int won; + cin >> won; + if (!players[won]) { + cout << "NO\n"; + return 0; + } + for (int j = 1; j <= 3; j++) { + if (j == won) continue; + players[j] = !players[j]; + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n, a, b, ans = 0, mitad, menor, i, j; + cin >> n >> a >> b; + mitad = (n - 1) / 2; + menor = min(a, b); + vector V(n); + for (i = 0; i < n; i++) cin >> V[i]; + for (i = 0; i <= mitad; i++) { + j = n - i - 1; + if (V[i] != 2 && V[j] != 2 && V[i] != V[j]) { + ans = -1; + break; + } + if (V[i] == 2 && V[j] == 2) { + if (i < mitad || (i == mitad && n % 2 == 0)) + ans += 2 * menor; + else + ans += menor; + } else { + if (V[i] == 2) { + if (V[j] == 0) + ans += a; + else + ans += b; + } else if (V[j] == 2) { + if (V[i] == 0) + ans += a; + else + ans += b; + } + } + } + cout << ans << '\n'; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + long long mi = INFF, s = 0, n; + cin >> n; + while (n--) { + long long k; + cin >> k; + s += k; + if (k % 2 == 1) { mi = min(mi, k); } + } + if (s % 2 != 0) { s -= mi; } + cout << s << '\n'; + return 0; +} +int a[105]; +int main() { + int n, m; + memset(a, 0, sizeof(a)); + cin >> n >> m; + for (int i = 0; i < n; i++) { + int s; + cin >> s; + for (int j = 0; j < s; j++) { + int k; + cin >> k; + a[k] = 1; + } + } + int dc = 1; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { dc = 0; } + } + if (dc == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int n, arr[103], s, t, len1 = 0, len2 = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + cin >> s >> t; + if (s > t) swap(s, t); + for (int i = s - 1; i < t - 1; i++) len1 += arr[i]; + int f = n - t + s; + int tt = t - 1; + while (f--) { + if (tt % n == 0) tt = 0; + len2 += arr[tt]; + tt++; + } + cout << min(len1, len2) << endl; + return 0; +} +int main() { + int x, y, z; + cin >> x >> y >> z; + int a, b, c; + a = sqrt((x * z) / y); + b = sqrt((x * y) / z); + c = sqrt((y * z) / x); + cout << 4 * (a + b + c) << endl; + return 0; +} +long long N, H, A, B, K; +int main() { + long long TA, FA, TB, FB; + cin >> N >> H >> A >> B >> K; + for (int i = 1; i <= K; i++) { + cin >> TA >> FA >> TB >> FB; + long long C = 0; + if (TA != TB) { + if (FA < A) { + C += A - FA; + FA = A; + } else if (FB > B) { + C += FB - B; + FB = B; + } + } + C += abs(TB - TA); + if (FA != FB) C += abs(FA - FB); + cout << C << '\n'; + } + return 0; +} +int main() { + int n; + int m; + int a; + int x = 1; + vector v; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + } + int i = 0; + while (i < n - 1) { + a = v[i + 1] - v[i]; + if (a > m) { + x = 1; + } else { + x++; + } + i++; + } + cout << x << "\n"; +} +int n, x; +int a[100]; +int main() { + cin >> n; + if (n == 1) { + cin >> x; + if (x == 15) { + cout << "DOWN" << endl; + return 0; + } + if (x == 0) { + cout << "UP" << endl; + return 0; + } + cout << -1 << endl; + return 0; + } + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (a[n] == 15) { + cout << "DOWN" << endl; + return 0; + } + if (a[n] == 0) { + cout << "UP" << endl; + return 0; + } + if (a[n] > a[n - 1]) { + cout << "UP" << endl; + return 0; + } + if (a[n] < a[n - 1]) { + cout << "DOWN" << endl; + return 0; + } +} +const int N = 1000 + 10; +int main() { + int n, a[N], b[N], pa[N], pb[N]; + cin >> n; + for (int i = 0; i != n; ++i) cin >> a[i]; + for (int i = 0; i != n; ++i) cin >> b[i]; + pa[0] = a[0], pb[0] = b[0]; + for (int i = 1; i != n; ++i) { + if (pa[i - 1] | a[i] + pb[i - 1] | b[i] > a[i] + b[i]) + pa[i] = pa[i - 1] | a[i], pb[i] = pb[i - 1] | b[i]; + else + pa[i] = a[i], pb[i] = b[i]; + } + int ans = pa[0] + pb[0]; + for (int i = 0; i != n; ++i) { ans = max(ans, pa[i] + pb[i]); } + cout << ans << endl; + return 0; +} +int main() { + int n, c = 1, ans = 0; + string s[6], k[6]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i][0] == 'p') c--; + } + if (c) { + k[ans] = "Power"; + ans++; + } + c = 1; + for (int i = 0; i < n; i++) + if (s[i][0] == 'g') c--; + if (c) { + k[ans] = "Time"; + ans++; + } + c = 1; + for (int i = 0; i < n; i++) + if (s[i][0] == 'b') c--; + if (c) { + k[ans] = "Space"; + ans++; + } + c = 1; + for (int i = 0; i < n; i++) + if (s[i][0] == 'o') c--; + if (c) { + k[ans] = "Soul"; + ans++; + } + c = 1; + for (int i = 0; i < n; i++) + if (s[i][0] == 'r') c--; + if (c) { + k[ans] = "Reality"; + ans++; + } + c = 1; + for (int i = 0; i < n; i++) + if (s[i][0] == 'y') c--; + if (c) { + k[ans] = "Mind"; + ans++; + } + cout << ans << "\n"; + for (int i = 0; i < ans; i++) cout << k[i] << endl; +} +const int maxn = 1e5 + 7; +int x[maxn], n, m, ans; +bool vis[maxn]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> x[i]; + sort(x, x + n); + for (int i = 0; i < m; i++) { + int u, v, y; + cin >> u >> v >> y; + if (u == 1) { + if (v == 1e9) { + ans++; + continue; + } + int k = upper_bound(x, x + n, v) - x - 1; + while (~k && vis[k]) k--; + if (~k) ans++, vis[k] = 1; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ara[n]; + for (int i = 0; i < n; i++) cin >> ara[i]; + sort(ara, ara + n); + for (int i = n - 1; i >= 0; i--) { + if (k % ara[i] == 0) { + cout << k / ara[i] << endl; + break; + } + } + return 0; +} +const int M = 1000 + 5; +int ihash[M]; +int main() { + int n, k; + cin >> n >> k; + int c; + cin >> c; + ihash[0] = 1; + for (int i = 0; i < c; i++) { + int x; + cin >> x; + ihash[x] = 1; + } + int ans = 0; + int start = 0; + while (start <= n) { + if (start + k <= n) { + int index = -1; + int ians = 0; + for (int i = start + 1; i <= start + k; i++) { + if (ihash[i] == 1) { + index = i; + ians++; + } + } + if (ians == 0) { + ans++; + start = start + k; + } else { + ans = ans + ians; + start = index; + } + } else { + for (int i = start + 1; i <= n; i++) { ans = ans + ihash[i]; } + start = n + 1; + } + } + cout << ans << endl; + return 0; +} +string a, b, c; +int cmp(string a, string b) { + if (a == b) return 0; + if (a == "rock" and b == "scissors") return 1; + if (a == "rock" and b == "paper") return -1; + if (a == "paper" and b == "rock") return 1; + if (a == "paper" and b == "scissors") return -1; + if (a == "scissors" and b == "paper") return 1; + if (a == "scissors" and b == "rock") return -1; +} +int main() { + cin >> a >> b >> c; + int x = cmp(a, b) + cmp(a, c); + int y = cmp(b, c) + cmp(b, a); + int z = cmp(c, a) + cmp(c, b); + if (x == 2) + cout << "F", cout << "\n"; + else if (y == 2) + cout << "M", cout << "\n"; + else if (z == 2) + cout << "S", cout << "\n"; + else + cout << "?", cout << "\n"; + return 0; +} +long long int n, k; +char a[100007]; +int main() { + cin >> n >> k; + bool b = true; + long long int _s = -1; + long long int _f = -1; + for (long long int i = 0; i <= n - 1; i++) { + cin >> a[i]; + if (a[i] == 'G') { + _s = i; + } else if (a[i] == 'T') { + _f = i; + } + } + if (_s > _f) { swap(_s, _f); } + long long int i; + for (i = _s; i < _f; i += k) { + if (a[i] == '#') { + cout << "NO" + << "\n"; + return 0; + } + } + if (i == _f) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +int main() { + string s; + s.reserve(15); + cin >> s; + int flag = 0; + for (int i = 0; i < s.size();) { + if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { + s[i] = s[i + 1] = s[i + 2] = '*'; + i += 3; + } else if (s[i] == '1' && s[i + 1] == '4') { + s[i] = s[i + 1] = '*'; + i += 2; + } else if (s[i] == '1') + s[i++] = '*'; + else { + flag = 1; + break; + } + } + if (flag) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + char **a = new char *[n]; + for (int i = 0; i < n; i++) { a[i] = new char[m]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + int x = 0; + int z = 0; + int h = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == 'B') { + x = 0; + z = 0; + h = 0; + for (int v = i - 1; v >= 0; v--) { + if (a[v][j] == 'B') { x++; } + } + for (int t = j - 1; t >= 0; t--) { + if (a[i][t] == 'B') { z++; } + } + for (int t = j + 1; t < m; t++) { + if (a[i][t] == 'B') { h++; } + } + if (z == x && x == h) { cout << i + 1 << " " << j + 1 << "\n"; } + } + } + } + return 0; +} +int main() { + int i, l = 0; + string s; + cin >> s; + sort(s.begin(), s.end()); + for (i = 0; i < s.size(); i++) { + if (s[i] != s[i + 1]) l++; + } + if (l % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else + cout << "IGNORE HIM!" << endl; + return 0; +} +const int maxN = 1010; +int main() { + string s; + int n, ans = 0, now = 0; + cin >> s; + n = s.size(); + for (int i = 0; i < n; i++) { + now = i; + i++; + while (i < n && s[i] == s[i - 1]) i++; + i--; + if ((i - now + 1) % 2 == 0) ans++; + } + cout << ans << endl; + cin >> n; +} +int main() { + string s = "", s1 = "", s2 = ""; + cin >> s1 >> s2; + for (int i = 0; i < s1.length(); i++) { + if (s1[i] == s2[i]) + s += '0'; + else + s += '1'; + } + cout << s << endl; + return 0; +} +int main() { + long long n; + cin >> n; + for (long long i = 1; i <= n; i++) { + if (i == 1) + cout << 2 << endl; + else { + long long num = 1; + num = (i * i * i) + 2 * (i * i) + 1; + cout << num << endl; + } + } + return 0; +} +int main() { + vector v; + long long int n, out, in, sum = 0; + cin >> n; + while (n--) { + cin >> out >> in; + sum = sum - out + in; + v.push_back(sum); + } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + cout << v[0] << endl; + return 0; +} +double frac(double x) { + return x - (long long)x; +} +int main() { + int n; + cin >> n; + double diff = 0; + long long c = 0; + vector a; + for (int i = 0; i < 2 * n; i++) { + double x; + cin >> x; + a.push_back(frac(x)); + if (a[i] == 0) c++; + diff += a[i]; + } + double ans = 1e9; + for (int i = 0; i <= c; i++) { + if (i < c - n) { continue; } + double p = abs(diff - (n - i) * 1.0); + ans = min(p, ans); + } + cout << setprecision(3) << fixed; + cout << ans << '\n'; + return 0; +} +int main() { + int n, m, flag = 0; + cin >> n >> m; + int a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == 1) { + if (i == 0 || i == n - 1 || j == 0 || j == m - 1) { flag = 1; } + } + } + } + if (flag == 1) { + cout << "2" << endl; + } else { + cout << "4" << endl; + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int most; + most = a * c % b == 0 ? a * c / b : a * c / b + 1; + int i; + for (i = most; i > 0; i--) { + if (ceil(double(i * b) / (a * c)) * c * b + i * b < a * c) break; + } + cout << i + 1 << endl; + return 0; +} +map Hash; +int N; +int main() { + cin >> N; + for (register int i = 1; i <= N; ++i) { + string s; + cin >> s; + ++Hash[s]; + } + int Ans = 0; + for (register int i = 1; i <= N; ++i) { + string s; + cin >> s; + if (Hash[s]) + --Hash[s]; + else + ++Ans; + } + cout << Ans << endl; + return 0; +} +const int maxn = 1010; +const int inf = 0x3f3f3f3f; +int a[maxn]; +inline int min(int a, int b) { + return a > b ? b : a; +} +int main() { + int n, m, x, i; + while (cin >> n >> m) { + int ans = inf; + memset(a, 0, sizeof(a)); + for (i = 0; i < m; i++) { + cin >> x; + a[x]++; + } + for (i = 1; i <= n; i++) { ans = min(ans, a[i]); } + cout << ans << endl; + } + return 0; +} +int main() { + int n, k, s[205]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + for (int i = n - 1; i >= 0; i--) { + if (k % s[i] == 0) { + cout << k / s[i] << endl; + return 0; + } + } + return 0; +} +int main() { + long long n, t; + cin >> n >> t; + long long k = 0; + for (long long i = 1; i <= n; i++) { + long long a; + cin >> a; + t -= (86400 - a); + if (t > 0) ++k; + } + cout << k + 1 << endl; +} +int main() { + int n; + cin >> n; + int m = (n + 1) / 2; + for (int i = 0; i < n; i++) { + for (int j = 1; j <= n; j++) { + if (i < m) { + if (j >= m - i and j <= m + i) { + cout << "D"; + } else { + cout << "*"; + } + } else { + if (j > (i + 1) % m and j < n - (i % m)) { + cout << "D"; + } else { + cout << "*"; + } + } + } + cout << endl; + } +} +int main() { + string s; + int n, m; + cin >> n >> m >> s; + while (m--) { + char a, b; + int l, r; + cin >> l >> r >> a >> b; + for (int i = l - 1; i <= r - 1; i++) + if (s[i] == a) s[i] = b; + } + cout << s << endl; + return 0; +} +const int maxn = 1e5 + 10; +int main() { + int n; + int a[maxn]; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + if (a[0] == 1) { + ans++; + for (int i = 1; i < n; i++) { + if (a[i] == 1) { + ans++; + } else { + for (int j = i + 1; j < n; j++) { + if (a[j] == 0) { + ; + } else { + if (j == i + 1) { + ans += 2; + i = j; + break; + } else { + ans++; + i = j; + break; + } + } + } + } + } + } else { + int c; + for (int i = 1; i < n; i++) { + if (a[i] != 0) { + c = i; + ans++; + break; + } + } + for (int i = c + 1; i < n; i++) { + if (a[i] == 1) { + ans++; + } else { + for (int j = i + 1; j < n; j++) { + if (a[j] == 0) { + ; + } else { + if (j == i + 1) { + ans += 2; + i = j; + break; + } else { + ans++; + i = j; + break; + } + } + } + } + } + } + cout << ans << endl; + } + return 0; +} +int main() { + long long a, b, c, i, j = 0, k, m, n, o, x, y, z, ar[5005]; + string s; + cin >> n >> m; + while (n--) { + cin >> s; + c = 0; + for (i = 0; i < s.size(); i++) { + if (s[i] == '4' || s[i] == '7') c++; + } + if (c <= m) j++; + } + cout << j << endl; + return 0; +} +int main() { + int n, d, mx = 0, ct = 0; + cin >> n >> d; + for (int i = 0; i < d; i++) { + string s; + cin >> s; + for (int j = 0; j < n; j++) { + if (s[j] == '0') { + ct++; + break; + } + if (j == n - 1) ct = 0; + } + mx = max(mx, ct); + } + cout << mx << endl; +} +int main() { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.size(); i++) { + int p = i; + while (p < s.size() && s[p] == s[i]) p++; + if ((p - i) % 2 == 0) ans++; + i = p - 1; + } + cout << ans << endl; + return 0; +} +int main() { + int f = 0; + long long x1, x2, x3, y1, y2, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + long long temp = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2); + if (temp == 0) + f = 0; + else if (temp > 0) + f = 1; + else + f = 2; + if (f == 0) + puts("TOWARDS"); + else if (f == 2) + puts("RIGHT"); + else + puts("LEFT"); + return 0; +} +int a, b, c, n; +int solve() { + int k = a + b - c; + if (c > min(a, b)) { return -1; } + if (k < 0) return -1; + if (n - k < 1) { return -1; } + return n - k; +} +int main() { + cin >> a >> b >> c >> n; + cout << solve() << "\n"; + return 0; +} +void CalculatePrimes(vector &primes, int limit) { + primes.push_back(2); + for (int i = 3; i <= limit; i += 2) { + bool test = true; + for (size_t j = 0; j < primes.size() / 2; ++j) { + if (i % primes[j] == 0) { + test = false; + break; + } + } + if (test) primes.push_back(i); + } +} +int main() { + int limit, count; + cin >> limit >> count; + vector primes; + CalculatePrimes(primes, limit); + vector sums; + for (size_t i = 0; i < primes.size(); ++i) { + if (i + 1 < primes.size()) { sums.push_back(primes[i] + primes[i + 1] + 1); } + } + int cnt = 0; + for (size_t i = 0; i < sums.size(); ++i) { + if (find(primes.begin(), primes.end(), sums[i]) != primes.end()) { cnt++; } + } + cout << (cnt >= count ? "YES" : "NO") << endl; + return 0; +} +long long i, j, n, a, b, s[10000], q, t; +int main() { + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b; + t = 0; + if (a == 0 || b == 0) + s[i] = 0; + else { + while (a != 0 && b != 0) { + if (a > b) { + t += a / b; + a %= b; + } else if (b > a) { + t += b / a; + b %= a; + } else if (a == b) { + t++; + a -= b; + } + } + s[i] = t; + } + } + for (i = 0; i < n; i++) { cout << s[i] << endl; } +} +int main() { + long long n, sum = 0; + cin >> n; + for (long long i = 0; i < n; i++) { + long long x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + sum += ((x2 - x1 + 1) * (y2 - y1 + 1)); + } + cout << sum << endl; + return 0; +} +long long dat[300005]; +long long sum[300005]; +long long res; +int main() { + int n; + while (cin >> n) { + res = 0; + memset(dat, 0, sizeof(dat)); + for (int i = 0; i < n; i++) cin >> dat[i]; + sort(dat, dat + n); + for (int i = n - 1; i >= 0; i--) dat[i] += dat[i + 1]; + for (int i = 0; i < n - 1; i++) res += dat[i]; + res += dat[0]; + cout << res << endl; + } + return 0; +} +int main() { + long n; + cin >> n; + long cont = 0; + while (n > 0) { + n = n / 2; + cont++; + } + cout << cont << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + int q_count = 0; + int QA[n]; + int QAQ[n]; + QAQ[0] = 0; + QA[0] = 0; + if (s[0] == 'Q') q_count++; + for (int i = 1; i < n; i++) { + QAQ[i] = QAQ[i - 1]; + QA[i] = QA[i - 1]; + if (s[i] == 'Q') { + q_count++; + QAQ[i] = QAQ[i - 1] + QA[i - 1]; + } else if (s[i] == 'A') { + QA[i] = QA[i - 1] + q_count; + } + } + cout << QAQ[n - 1] << "\n"; + return 0; +} +int n; +int main() { + cin >> n; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << '*'; + for (int j = n / 2 - i + 2; j <= n / 2 + i; j++) cout << 'D'; + for (int j = n / 2 + i + 1; j <= n; j++) cout << '*'; + cout << '\n'; + } + for (int i = n / 2; i >= 1; i--) { + for (int j = 1; j <= n / 2 + 1 - i; j++) cout << '*'; + for (int j = n / 2 - i + 2; j <= n / 2 + i; j++) cout << 'D'; + for (int j = n / 2 + i + 1; j <= n; j++) cout << '*'; + cout << '\n'; + } + return 0; +} +int main() { + int a[10]; + int b[10]; + int c[10]; + int n, m, sum = 0; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + memset(c, 0, sizeof(c)); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + a[m]++; + c[m]++; + } + for (int i = 0; i < n; i++) { + cin >> m; + b[m]++; + c[m]++; + } + for (int i = 1; i <= 5; i++) { + if (c[i] % 2) { + cout << -1 << endl; + return 0; + } else { + sum += abs(c[i] / 2 - a[i]); + } + } + cout << sum / 2 << endl; + return 0; +} +int main() { + int n; + int total = 0; + string tmp; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> tmp; + transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); + if (tmp.compare("tetrahedron") == 0) { + total += 4; + } else if (tmp.compare("cube") == 0) { + total += 6; + } else if (tmp.compare("octahedron") == 0) { + total += 8; + } else if (tmp.compare("dodecahedron") == 0) { + total += 12; + } else if (tmp.compare("icosahedron") == 0) { + total += 20; + } + } + cout << total << endl; + return 0; +} +int main() { + int x, res = 0; + cin >> x; + for (int i = 0; i < log2(x) + 1; i++) { + if ((x & (1 << i)) != 0) res++; + } + cout << res << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n / 10 == 0) { + if (n <= 5) + cout << "0\n"; + else + cout << "10\n"; + } else { + if (n % 10 <= 5) + cout << n / 10 << 0 << '\n'; + else + cout << n / 10 + 1 << 0 << '\n'; + } +} +int main() { + int n; + cin >> n; + long long ganjilterkecil = 1000000001; + long long jumlahgenap = 0; + long long jumlahganjil = 0; + int banyakganjil = 0; + for (int i = 0; i < n; i++) { + long long k; + cin >> k; + if (k % 2 == 0) { + jumlahgenap = jumlahgenap + k; + } else { + jumlahganjil = jumlahganjil + k; + banyakganjil++; + if (ganjilterkecil > k) { ganjilterkecil = k; } + } + } + if (n == 1 && jumlahgenap == 0 && banyakganjil == 1) { + cout << "0" << endl; + return 0; + } + if (banyakganjil % 2 == 0) { + cout << jumlahgenap + jumlahganjil << endl; + } else { + cout << jumlahgenap + jumlahganjil - ganjilterkecil << endl; + } +} +const int inf = 1e9 + 5; +const int M = 1e5 + 5; +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int m1 = n / k; + if (n % k != 0) m1++; + m1 *= t; + int m2 = 0; + int nown = 0; + int x = 0, y = 0; + int xt = 0, yt = 0; + m2 = d + t; + if (m1 <= m2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +long long int x, y, p, q; +bool check(long long int mi) { + long long int a1 = q * mi - y; + long long int a2 = p * mi - x; + if (a1 >= a2 && a2 >= 0 && a1 >= 0) { return 1; } + return 0; +} +int main() { + int te; + cin >> te; + while (te--) { + cin >> x >> y >> p >> q; + long long int lo = 1, hi = 1000000004, mi; + while (lo < hi) { + mi = lo + (hi - lo) / 2; + if (check(mi)) { + hi = mi; + } else + lo = mi + 1; + } + if (lo == 1000000004) + cout << "-1\n"; + else + cout << q * lo - y << "\n"; + } + return 0; +} +int n, i, a[1111111], ans = 0, d[1111111]; +int main() { + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + d[1] = 1; + for (i = 2; i < n; i++) d[i] = d[i / 2] * 2; + for (i = 0; i + 1 < n; i++) { + a[i + d[n - i - 1]] += a[i]; + ans += a[i]; + cout << ans << endl; + } + return 0; +} +const int N = 50 + 5; +int n, k, res; +pair a[N]; +bool cmp(pair a, pair b) { + if (a.first > b.first) + return true; + else if (a.first == b.first) { + if (a.second < b.second) return true; + return false; + } else + return false; +} +void Input() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; + sort(a + 1, a + n + 1, cmp); +} +void Solve() { + int problems = a[k].first, penalty = a[k].second; + for (int i = 1; i <= n; i++) { + if (a[i].first == problems && a[i].second == penalty) res++; + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int difficulty(vector level) { + int maxi = level[1] - level[0]; + for (int i = 0; i + 1 < level.size(); i++) { + if (maxi < (level[i + 1] - level[i])) { maxi = level[i + 1] - level[i]; } + } + return maxi; +} +int main() { + int n; + cin >> n; + int *a = new int[n - 2]; + int j = 0; + int x; + vector level; + for (int i = 0; i < n; i++) { + cin >> x; + level.push_back(x); + } + int siz = level.size(); + for (int i = 1; i + 1 < siz; i++) { + x = level[i]; + level.erase(level.begin() + i); + a[j] = difficulty(level); + j++; + level.push_back(x); + sort(level.begin(), level.end()); + } + sort(a, a + n - 2); + cout << a[0] << endl; + return 0; +} +const long long INF = 1e18; +const long long MOD = 1e9 + 7; +const long double eps = 1e-7; +const long long zero = 0; +int main() { + cout << fixed << setprecision(10); + long long n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + long long ta, fa, tb, fb; + cin >> ta >> fa >> tb >> fb; + long long res = 0; + if (ta == tb) { + res += abs(fa - fb); + } else { + res += abs(ta - tb); + if (!(a <= fa && fa <= b)) { + if (abs(a - fa) < abs(b - fa)) { + res += abs(a - fa) + abs(a - fb); + } else { + res += abs(b - fa) + abs(b - fb); + } + } else { + res += abs(fa - fb); + } + } + cout << res << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + string s1, s2, s3; + bool flag = true; + for (int i = 1; i <= a; i++) { + if (i % 2 == 1) { + for (int i = 0; i < b; i++) { cout << '#'; } + cout << endl; + } else if (flag) { + for (int i = 0; i < b - 1; i++) { cout << '.'; } + cout << '#' << endl; + flag = !flag; + } else { + cout << '#'; + for (int i = 1; i < b; i++) { cout << '.'; } + cout << endl; + flag = !flag; + } + } +} +int N; +string A, B; +pair ans[1024]; +int main() { + cin >> A >> B; + ans[0] = make_pair(A, B); + cin >> N; + for (int i = 1; i <= N; i++) { + cin >> A >> B; + if (A == ans[i - 1].first) { + ans[i].first = B; + ans[i].second = ans[i - 1].second; + } else if (A == ans[i - 1].second) { + ans[i].second = B; + ans[i].first = ans[i - 1].first; + } else if (B == ans[i - 1].first) { + ans[i].first = A; + ans[i].second = ans[i - 1].second; + } else if (B == ans[i - 1].second) { + ans[i].second = A; + ans[i].first = ans[i - 1].first; + } + } + for (int i = 0; i <= N; i++) { cout << ans[i].first << " " << ans[i].second << endl; } + return 0; +} +const int maxn = 2e5 + 5; +const int maxm = 1e5 + 5; +const int inf = 0x3f3f3f3f; +map mp1; +map mp2; +int n; +void conv(string &str, long long num) { + int cnt = 0; + while (num) { + str += (char)(num % 10 & 1 | 48); + num /= 10; + ++cnt; + } + while (cnt < 18) str += '0', ++cnt; +} +int main() { + cin >> n; + while (n--) { + char ch; + long long num; + cin >> ch >> num; + string str; + conv(str, num); + if (ch == '+') + ++mp1[num], ++mp2[str]; + else if (ch == '-') + --mp1[num], --mp2[str]; + else + cout << mp2[str] << endl; + } + return 0; +} +long long int n, k; +map mymap; +int main() { + cin >> n >> k; + char c; + while (n--) { + cin >> c; + mymap[c]++; + } + long long int _s = 0; + long long int _c = 0; + for (char i = 'a'; i <= 'z' && _c < k; i++) { + if (mymap[i]) { + _s += (i - 'a' + 1); + _c++; + i++; + } + } + if (_c < k) { + cout << -1 << "\n"; + } else { + cout << _s << "\n"; + } + return 0; +} +const int maxn = 5e4 + 10, mod = 1e9 + 9, maxa = 1e6 + 100; +long long sta = 0; +const long long inf = 2e18 + 13; +long long max(long long x, long long y) { + return (x > y ? x : y); +} +long long min(long long x, long long y) { + return (x < y ? x : y); +} +long long pw(long long x, long long y) { + if (!y) { return 1; } + long long res = pw(x, y / 2); + res *= res; + res %= mod; + if (y & 1) { res *= x; } + return res % mod; +} +int main() { + long long n, m; + cin >> n >> m; + long long ans = 1; + for (int i = 1; i <= n; i++) { + ans = ans * (pw(2, m) - i); + ans += mod; + ans %= mod; + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, sumb = 0, sumc = 0; + for (int i = 0; i < n; i++) { + cin >> a; + if (a >= 0) + sumb += a; + else + sumc += a; + } + cout << (sumb - sumc) << endl; + return 0; +} +int main() { + int i, j, k, n, previous, c, val, sum; + vector name; + string tem; + cin >> n >> k >> c; + for (i = 0, previous = 0, sum = 0; i < c; i++) { + cin >> val; + sum = sum + (val - previous - 1) / k; + previous = val; + } + if (k == 1) { + cout << n << endl; + return 0; + } + sum = sum + (n - previous) / k; + cout << sum + c << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const long long inf2 = 0x3f3f3f3f3f3f3f3f; +const double eps = 1e-6; +const int mod = 1000000007; +bool is[545]; +int main() { + memset(is, 0, sizeof(is)); + int n, k; + cin >> n >> k; + int c; + cin >> c; + while (c--) { + int x; + cin >> x; + is[x] = true; + } + int cnt = 0, pr = 0; + for (int i = 1; i <= n; i++) { + if (is[i]) { + cnt = 0; + pr++; + } else { + cnt++; + if (cnt == k) { + cnt = 0; + pr++; + } + } + } + cout << pr << endl; + return 0; +} +long long ans = 0; +int n, i, j, k; +char a[105][105]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) cin >> a[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) + if (a[i][j] == 'C') { + for (k = i + 1; k <= n; k++) + if (a[k][j] == 'C') ++ans; + for (k = j + 1; k <= n; k++) + if (a[i][k] == 'C') ++ans; + } + cout << ans << endl; + return 0; +} +int n, m, mn, mx; +int main() { + cin >> n >> m >> mn >> mx; + int i, x, cmn = 1000, cmx = 0; + for (i = 1; i <= m; i++) { + cin >> x; + cmx = max(cmx, x); + cmn = min(cmn, x); + } + if ((cmx > mx) || (cmn < mn)) { + puts("Incorrect"); + } else if (n - m == 1) { + if ((cmx != mx) && (cmn != mn)) { + puts("Incorrect"); + } else { + puts("Correct"); + } + } else { + puts("Correct"); + } + return 0; +} +int main() { + int n; + cin >> n; + vector v(101, 0); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v[x]++; + } + int MAX = *max_element(v.begin(), v.end()); + cout << MAX << endl; + return 0; +} +int main() { + int t, s, q; + int count = 0; + cin >> t >> s >> q; + while (s < t) { + s = s * q; + count += 1; + } + cout << count << endl; +} +const long long inf = 1e9 + 7; +int main() { + int n; + cin >> n; + long long a[n + 2], left[n + 2], right[n + 2], ans = 0; + a[0] = -1; + a[n + 1] = inf; + for (int i = 1; i <= n; i++) cin >> a[i]; + right[0] = 0; + for (int i = 1; i <= n; i++) right[i] = (a[i] > a[i - 1] ? right[i - 1] + 1 : 1); + left[n + 1] = 0; + for (int i = n; i > 0; i--) left[i] = (a[i] < a[i + 1] ? left[i + 1] + 1 : 1); + for (int i = 1; i <= n; i++) { + if (a[i - 1] + 1 < a[i + 1]) + ans = max(ans, 1 + left[i + 1] + right[i - 1]); + else + ans = max(ans, max(left[i], right[i]) + 1); + } + cout << ans << endl; +} +int main() { + int n, k, num[100] = {0}; + cin >> n >> k; + int sum = 0; + for (int i = 1; i <= n; i++) { + char al; + cin >> al; + num[al - 'a' + 1]++; + sum = max(sum, num[al - 'a' + 1]); + } + if (sum > k) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +bool myC(long long &a, long long &b) { + return a > b; +} +int main() { + int arr[5] = {1, 5, 10, 20, 100}; + int n; + cin >> n; + int a = 0, ans = 0; + for (int i = 4; i >= 0; i--) { + ans += (n / arr[i]); + n = n % arr[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, r; + cin >> a >> b >> r; + if (min(a, b) >= 2 * r) { + cout << "First" << endl; + } else + cout << "Second" << endl; + return 0; +} +const int MAX = 5e4 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +const double pi = acos(-1); +int a, b, c; +int main() { + cin >> a >> b >> c; + cout << a * b + (a + b - 1) * (c - 1) << "\n"; + return 0; +} +int bulb[105]; +int main() { + int n, m, k, kk; + while (cin >> n >> m) { + memset(bulb, 0, sizeof(bulb)); + while (n--) { + cin >> k; + while (k--) { + cin >> kk; + bulb[kk] = 1; + } + } + int flag = 1; + for (int i = 1; i <= m; i++) { + if (bulb[i] == 0) { + flag = 0; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +vector nums; +int main() { + int n, a, last, dist; + int min = INT_MAX; + int mindist = INT_MAX; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + nums.push_back(a); + if (a < min) min = a; + } + for (int i = 0; i < n; i++) { + if (nums[i] == min) { + last = i; + break; + } + } + for (int i = last + 1; i < n; i++) { + if (nums[i] == min) { + dist = i - last; + if (dist < mindist) mindist = dist; + last = i; + } + } + cout << mindist << endl; +} +long long int choose(long long int n, long long int m) { + long long int ans = 0; + long long int num = 1; + long long int den = 1; + for (long long int i = 0; i < m; i++) { + num *= (n - i); + num = num / (i + 1); + } + return num; +} +bool isPrime(int n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (int i = 5; i * i <= n; i = i + 6) { + if (n % i == 0 || n % (i + 2) == 0) return false; + } + return true; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) { + return b; + } else { + return gcd(b % a, a); + } +} +int main() { + long long int i, j, k, n, m, t, c; + cin >> n; + vector d(n); + for (i = 0; i < n; i++) { cin >> d[i]; }; + long long int s; + cin >> s >> t; + if (s > t) { + m = s; + s = t; + t = m; + } + long long int ans1 = 0, ans2 = 0; + for (i = s - 1; i < t - 1; i++) { ans1 += d[i]; } + i = t - 1; + while (i != s - 1) { + ans2 += d[i]; + i++; + if (i == n) i = 0; + } + cout << min(ans1, ans2) << endl; + return 0; +} +int main() { + long int n, h, low, high, k, ta, ha, tb, hb, x; + cin >> n >> h >> low >> high >> k; + while (k) { + x = 0; + cin >> ta >> ha >> tb >> hb; + if (ta == tb) + x = abs(hb - ha); + else if (ha > high && hb > high) { + x = abs(ta - tb) + (ha - high) + (hb - high); + } else if (ha < low && hb < low) { + x = abs(ta - tb) + (low - ha) + (low - hb); + } else + x = abs(ta - tb) + abs(ha - hb); + cout << x << endl; + k--; + } + return 0; +} +int main() { + string a, b, A[10000], B[10000]; + int n; + cin >> a >> b; + cin >> n; + for (int i = 0; i < n; i++) { cin >> A[i] >> B[i]; } + for (int i = 0; i < n; i++) { + if (i == 0) { + if (A[i] == a) { + A[i] = B[i]; + B[i] = b; + } else if (A[i] == b) { + A[i] = a; + } + } else { + if (A[i] == A[i - 1]) { + A[i] = B[i]; + B[i] = B[i - 1]; + } else if (A[i] == B[i - 1]) { + A[i] = A[i - 1]; + } + } + } + cout << a << " " << b << endl; + for (int i = 0; i < n; i++) { cout << A[i] << " " << B[i] << endl; } +} +int main() { + string s1, s2, a, b; + while (cin >> s1 >> s2) { + int n; + cin >> n; + cout << s1 << " " << s2 << endl; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a == s1) { + s1 = b; + } else { + s2 = b; + } + cout << s1 << " " << s2 << endl; + } + } + return 0; +} +const int N = 2e6 + 5; +long long power(long long x, unsigned long long y, long long p) { + long long res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +long long i, j; +int main() { + string s; + long long k; + cin >> s >> k; + if (k > (long long)s.size()) { + cout << "impossible" << '\n'; + return 0; + } else { + set temp; + for (i = 0; i < (long long)s.size(); i++) { + temp.insert(s[i]); + if ((long long)temp.size() == k) { + cout << 0 << '\n'; + return 0; + } + } + cout << k - (long long)temp.size() << '\n'; + return 0; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[101]; + int B, C; + B = C = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < 0) + C += a[i]; + else + B += a[i]; + } + cout << B - C << endl; + return 0; +} +const int maxn = 1e3 + 100; +int a[maxn]; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + for (int i = 0; i < m; i++) { + int idx; + cin >> idx; + idx--; + a[idx]++; + if (*min_element(a, a + n) != 0) { + for (int j = 0; j < n; j++) a[j]--; + ans++; + } + } + cout << ans << endl; + return 0; +} +int n, k, c, cnt; +bool b[500]; +int main() { + cin >> n >> k >> c; + for (int i = 0; i < c; i++) { + int x; + cin >> x; + b[x] = 1; + cnt++; + } + b[0] = 1; + for (int i = 1; i + k - 1 <= n; i++) { + bool f = 0; + int j; + for (j = i; j < i + k; j++) { + if (b[j] == 1) { + f = 1; + i = j; + break; + } + } + if (!f) { + cnt++; + b[--j] = 1; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int m, d; + cin >> m >> d; + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { + int p; + p = 31 - (7 - d + 1); + if (p % 7 == 0) { + cout << ((31 - (7 - d + 1)) / 7) + 1 << endl; + } else + cout << ((31 - (7 - d + 1)) / 7) + 2 << endl; + } else if (m == 4 || m == 6 || m == 9 || m == 11) { + int p; + p = 30 - (7 - d + 1); + if (p % 7 == 0) { + cout << ((30 - (7 - d + 1)) / 7) + 1 << endl; + } else + cout << ((30 - (7 - d + 1)) / 7) + 2 << endl; + } else { + if (d == 1) + cout << "4" << endl; + else + cout << "5" << endl; + } + return 0; +} +int q; +int main() { + cin >> q; + for (int _ = 0; _ <= q - 1; _ += 1) { + long long int n; + cin >> n; + string s; + cin >> s; + if (n == 2 && s[0] >= s[1]) + cout << "NO\n"; + else { + cout << "YES\n"; + cout << 2 << '\n'; + cout << s[0] << ' ' << s.substr(1) << '\n'; + } + } + return 0; +} +int main() { + int n, k; + vector s, y; + cin >> n >> k; + int x, ans = 0; + for (int i = 0; i < n; i++) { + cin >> x; + s.push_back(x); + } + while (s.empty() == false && s.back() <= k) { + ans++; + s.pop_back(); + } + reverse(s.begin(), s.end()); + while (s.empty() == false && s.back() <= k) { + ans++; + s.pop_back(); + } + cout << ans << endl; + return 0; +} +int n, k, c = 0, sum = 0; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; ++i) { + sum += 5 * i; + if (sum > (240 - k)) { break; } + c++; + } + cout << c << endl; + return 0; +} +char dp[10][10]; +map mp; +int main() { + long long n, x; + long long a[10]; + for (int i = 0; i < 6; i++) { + cin >> a[i]; + mp[a[i]]++; + } + bool ok = false; + for (int i = 0; i < 6; i++) { + if (mp[a[i]] == 6) ok = true; + } + if (ok) { + cout << "Elephant" << endl; + return 0; + } + for (int i = 0; i < 6; i++) { + if (mp[a[i]] == 5) ok = true; + } + if (ok) { + cout << "Bear" << endl; + return 0; + } + for (int i = 0; i < 6; i++) { + if (mp[a[i]] == 4) ok = true; + } + if (!ok) { + cout << "Alien" << endl; + return 0; + } + for (int i = 0; i < 6; i++) { + if (mp[a[i]] == 2) ok = false; + } + if (ok) + cout << "Bear" << endl; + else + cout << "Elephant" << endl; + return 0; +} +char s[120] = "qwertyuiopasdfghjkl;zxcvbnm,./"; +int main() { + char way[2], c[100]; + cin >> way; + cin >> c; + if (way[0] == 'L') { + for (int i = 0; i < strlen(c); i++) { + for (int j = 0; j < strlen(s); j++) { + if (c[i] == s[j]) { + cout << s[j + 1]; + break; + } + } + } + cout << endl; + } else { + for (int i = 0; i < strlen(c); i++) { + for (int j = 0; j < strlen(s); j++) { + if (c[i] == s[j]) { + cout << s[j - 1]; + break; + } + } + } + cout << endl; + } + return 0; +} +int main() { + int n, a = 0, ai, m, l, r, ans = -1; + cin >> n; + for (int i = (0); i < (n); i++) { + cin >> ai; + a += ai; + } + cin >> m; + for (int i = (0); i < (m); i++) { + cin >> l >> r; + if (a <= r) { + if (a < l) + ans = l; + else + ans = a; + break; + } + } + cout << ans << '\n'; +} +int main() { + int n, m, i, j; + cin >> n >> m; + for (i = 0; i < n; i++) { + if (i % 2 == 0) { + for (j = 0; j < m; j++) { + cout << "#"; + if (j == (m - 1)) cout << endl; + } + } else { + if ((i + 1) % 4 != 0) { + for (j = 0; j < m; j++) { + if (j < (m - 1)) + cout << "."; + else + cout << "#" << endl; + } + } else { + for (j = 0; j < m; j++) { + if (j > 0) { + cout << "."; + if (j == (m - 1)) cout << endl; + } else { + cout << "#"; + } + } + } + } + } +} +int main() { + int q, w; + cin >> q >> w; + int check = 1, lol = 1; + for (int i = 0; i < q; i++) { + for (int j = 0; j < w; j++) { + if (i % 2 == 0) + cout << "#"; + else if (check == 1 && j == 0) { + cout << "#"; + check = -1; + lol = 1; + } else if (check == 0 && j == w - 1) { + cout << "#"; + check = -1; + lol = 2; + } else + cout << "."; + } + cout << endl; + if (lol == 1) check = 0; + if (lol == 2) check = 1; + } +} +int main() { + string n; + cin >> n; + if (n == "a8") { + cout << "3" << endl; + return 0; + } + if (n == "a7") { + cout << "5" << endl; + return 0; + } + if (n == "a6") { + cout << "5" << endl; + return 0; + } + if (n == "a5") { + cout << "5" << endl; + return 0; + } + if (n == "a4") { + cout << "5" << endl; + return 0; + } + if (n == "a3") { + cout << "5" << endl; + return 0; + } + if (n == "a2") { + cout << "5" << endl; + return 0; + } + if (n == "a1") { + cout << "3" << endl; + return 0; + } + if (n == "h8") { + cout << "3" << endl; + return 0; + } + if (n == "h7") { + cout << "5" << endl; + return 0; + } + if (n == "h6") { + cout << "5" << endl; + return 0; + } + if (n == "h5") { + cout << "5" << endl; + return 0; + } + if (n == "h4") { + cout << "5" << endl; + return 0; + } + if (n == "h3") { + cout << "5" << endl; + return 0; + } + if (n == "h2") { + cout << "5" << endl; + return 0; + } + if (n == "h1") { + cout << "3" << endl; + return 0; + } + if (n == "b1") { + cout << "5" << endl; + return 0; + } + if (n == "c1") { + cout << "5" << endl; + return 0; + } + if (n == "d1") { + cout << "5" << endl; + return 0; + } + if (n == "e1") { + cout << "5" << endl; + return 0; + } + if (n == "f1") { + cout << "5" << endl; + return 0; + } + if (n == "g1") { + cout << "5" << endl; + return 0; + } + if (n == "b8") { + cout << "5" << endl; + return 0; + } + if (n == "c8") { + cout << "5" << endl; + return 0; + } + if (n == "d8") { + cout << "5" << endl; + return 0; + } + if (n == "e8") { + cout << "5" << endl; + return 0; + } + if (n == "f8") { + cout << "5" << endl; + return 0; + } + if (n == "g8") { + cout << "5" << endl; + return 0; + } else { + cout << "8" << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int n = 0; + string arr[30010]; + int largest = 200, count = 0, j = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 1; i < n; i++) { + j = 0; + count = 0; + while (j < arr[0].length()) { + if (arr[i][j] == arr[0][j]) { + count++; + j++; + } else { + break; + } + } + if (count < largest) { largest = count; } + } + cout << largest << endl; + return 0; +} +int main() { + int n = 0, i = 0, coun = 0; + string a; + cin >> a; + n = a.length(); + int cs[n + 1] = {0}, ce[n + 1] = {0}; + cs[0] = 0; + ce[n] = 0; + for (i = 0; i < n; i++) { + if (a[i] == 'Q') + cs[i + 1] = cs[i] + 1; + else + cs[i + 1] = cs[i]; + } + for (i = n - 1; i >= 0; i--) { + if (a[i] == 'Q') + ce[i] = ce[i + 1] + 1; + else + ce[i] = ce[i + 1]; + } + for (i = 0; i < n; i++) + if (a[i] == 'A') coun += cs[i] * ce[i + 1]; + cout << coun << endl; + return 0; +} +int IN(long Number, int temp) { + int Temp; + Number = abs(Number); + for (; Number != 0; Number /= 10) { + Temp = Number % 10; + if (Temp == temp) return 1; + } + return false; +} +int main() { + long Number; + long B = 1; + cin >> Number; + for (; !IN(Number + B, 8); B++) + ; + cout << B << endl; + return 0; +} +const int mod = 1e9 + 7; +const int maxn = 1e5; +long long n, m; +int u, v; +int num[105]; +int edge[105][105]; +int main() { + cin >> n >> m; + memset(edge, 0, sizeof edge); + for (int i = 1; i <= n; i++) cin >> num[i]; + for (int i = 0; i < m; i++) { + cin >> u >> v; + edge[u][0]++; + edge[u][edge[u][0]] = v; + edge[v][0]++; + edge[v][edge[v][0]] = u; + } + int a, b, c; + bool f = false; + int ans = mod; + for (int i = 1; i <= n; i++) { + a = i; + for (int j = 1; j <= edge[a][0]; j++) { + b = edge[a][j]; + for (int k = 1; k <= edge[b][0]; k++) { + c = edge[b][k]; + for (int p = 1; p <= edge[c][0]; p++) { + if (edge[c][p] == a) { + f = true; + ans = min(ans, num[a] + num[b] + num[c]); + } + } + } + } + } + if (f) + cout << ans << endl; + else + cout << "-1\n"; + return 0; +} +int n, ans = 0; +char a[201][201]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) cin >> a[i][j]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) { + if (a[i][j] == '.') continue; + for (int k = i + 1; k <= n; k++) ans += a[k][j] == 'C' ? 1 : 0; + for (int k = j + 1; k <= n; k++) ans += a[i][k] == 'C' ? 1 : 0; + } + cout << ans << endl; + return 0; +} +int n, t; +bool reach = 0; +void check(vector &A) { + for (int i = 1; i <= n;) { + if (i == t) { + reach = 1; + return; + } else if (i > t) { + reach = 0; + return; + } + i = i + A[i]; + } +} +int main() { + cin >> n >> t; + vector A(n); + for (int i = 1; i <= n - 1; i++) cin >> A[i]; + check(A); + if (reach == 0) { + cout << "NO\n"; + } else + cout << "YES\n"; +} +const int maxn = 5e5 + 5; +const int inf = 0x3f3f3f3f; +const long long INF = 0x3f3f3f3f3f3f3f3f; +int a[26]; +map mp; +int main() { + string s; + cin >> s; + int n = s.length(); + int cnt = 0; + int ans = 0; + for (int i = 0; i < n; i++) { + string ss = ""; + for (int j = i; j < n; j++) { ss.push_back(s[j]); } + for (int j = 0; j < i; j++) { ss.push_back(s[j]); } + if (mp[ss] == 0) { + mp[ss] = 1; + ans++; + } + } + cout << ans << endl; +} +int main() { + long long a, b, c; + while (cin >> a >> b >> c) { + long long sum(0); + for (int i = 1; i <= c; i++) { sum = sum + i * a; } + if (sum <= b) { + cout << 0 << endl; + } else { + cout << sum - b << endl; + } + } +} +int main() { + int x, y; + cin >> x >> y; + if (x > 0 && y > 0) + cout << "0" + << " " << x + y << " " << x + y << " " + << "0" << endl; + else if (x < 0 && y > 0) + cout << -(-x - (-y)) << " " + << "0" + << " " + << "0" + << " " << abs(-x + (y)) << endl; + else if (x > 0 && y < 0) + cout << "0" + << " " << (-x - (-y)) << " " << abs(-x + (y)) << " " + << "0" << endl; + else + cout << (x + (y)) << " " + << "0" + << " " + << "0" + << " " << -(-x + (-y)) << endl; + return 0; +} +string s; +int ans = 0; +void make() { + int len = s.length(); + if (s[0] <= '9' && s[0] >= '0') { + int year = 0; + for (int i = 0; i < len; i++) { year = year * 10 + s[i] - '0'; } + if (year < 18) { ans++; } + } else { + if (s == "BRANDY") { + ans++; + } else if (s == "BEER") { + ans++; + } else if (s == "ABSINTH") { + ans++; + } else if (s == "CHAMPAGNE") { + ans++; + } else if (s == "GIN") { + ans++; + } else if (s == "RUM") { + ans++; + } else if (s == "SAKE") { + ans++; + } else if (s == "TEQUILA") { + ans++; + } else if (s == "VODKA") { + ans++; + } else if (s == "WHISKEY") { + ans++; + } else if (s == "WINE") { + ans++; + } + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + make(); + } + cout << ans << endl; + return 0; +} +long long n, a[200005]; +vector st; +int main() { + long long precision = numeric_limits::digits10; + cin >> n; + for (long long i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + for (long long i = 1; i <= n / 2; i++) { st.push_back(a[i + n / 2] - a[i]); } + sort(st.begin(), st.end()); + cout << st[0] << "\n"; +} +vector tu[1005]; +int a[1005], cnt[1005], n, checks[1005]; +int check(int x) { + int i, k; + int sum = -1; + queue qua[5]; + for (i = 1; i <= n; i++) { + if (cnt[i] == 0) { qua[a[i]].push(i); } + } + for (;;) { + if (qua[1].size() == 0 && qua[2].size() == 0 && qua[3].size() == 0) break; + while (!qua[x].empty()) { + sum++; + k = qua[x].front(); + qua[x].pop(); + for (i = 0; i < tu[k].size(); i++) { + int xx = tu[k][i]; + cnt[xx]--; + if (cnt[xx] == 0) qua[a[xx]].push(xx); + } + } + if (x == 1) + x = 2; + else if (x == 2) + x = 3; + else if (x == 3) + x = 1; + sum++; + } + if (sum == -1) + return 0; + else + return sum; +} +int main() { + int i; + int ans, T, x; + cin >> n; + memset(a, 0, sizeof(a)); + memset(tu, 0, sizeof(tu)); + memset(cnt, 0, sizeof(cnt)); + for (i = 1; i <= n; i++) { cin >> a[i]; } + for (i = 1; i <= n; i++) { + cin >> T; + while (T--) { + cin >> x; + tu[x].push_back(i); + checks[i]++; + } + } + ans = 1 << 30; + int j; + for (i = 1; i <= 3; i++) { + for (j = 1; j <= n; j++) { cnt[j] = checks[j]; } + ans = min(ans, check(i)); + } + cout << ans << endl; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int time1 = t, time2 = t + d, num1 = n, num2 = k; +A: + if (num2 < num1) { + time1 += t; + num2 += k; + goto A; + } + if (time2 < time1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, ar[100010]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + int mn = ar[0]; + for (int i = 0; i < n; i++) { + if (mn > ar[i]) mn = ar[i]; + } + int p1 = -1, p2 = -1, d; + int mnd = n; + for (int i = 0; i < n; i++) { + if (ar[i] == mn) { + p1 = i; + if (p2 != -1) { + if (mnd > (p1 - p2)) { mnd = p1 - p2; } + } + p2 = p1; + } + } + cout << mnd << endl; + return 0; +} +int main() { + long long ar[100000], i, x, j, y, tn = 1, ans = 0; + int n, m; + long long tc; + cin >> n; + vector v, v1; + v.push_back(0); + for (i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + v1 = v; + for (i = 1; i < v.size(); i++) v[i] += v[i - 1]; + cin >> x >> y; + if (x > y) swap(x, y); + if (x == y) { + cout << 0 << endl; + return 0; + } + int t1 = v[y - 1] - v[x - 1]; + int t2 = v[v.size() - 1] - v[y] + v1[y] + v[x - 1]; + cout << min(t1, t2) << endl; + return 0; +} +int main() { + int q; + string s1, s2; + cin >> s1 >> s2 >> q; + cout << s1 << " " << s2 << endl; + while (q--) { + string be, af; + cin >> be >> af; + if (s1 == be) { + s1 = af; + } else { + s2 = af; + } + cout << s1 << " " << s2 << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + char cur = 'a'; + int mn; + int ans = 0; + for (int i = 0; i < s.length(); i++) { + mn = min(abs(s[i] - cur), abs(26 - abs((s[i] - cur)))); + ans += mn; + cur = s[i]; + } + cout << ans << '\n'; + return 0; +} +int main() { + int a, b, c = 110, q, n; + cin >> n >> a; + for (int i = 0; i < n; i++) { + cin >> b; + if (a % b == 0) { + q = a / b; + if (q < c) c = q; + } + } + cout << c << endl; +} +int main() { + int n; + char mp[110][110]; + cin >> n; + memset(mp, '*', sizeof(mp)); + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) cin >> mp[j][i]; + bool flag = true; + for (int i = 1; i <= n && flag; ++i) { + int cnt = 0; + for (int j = 1; j <= n; ++j) { + if (mp[j - 1][i] == 'o') cnt++; + if (mp[j + 1][i] == 'o') cnt++; + if (mp[j][i - 1] == 'o') cnt++; + if (mp[j][i + 1] == 'o') cnt++; + if (cnt % 2 != 0) { + flag = false; + break; + } + } + } + puts(flag ? "YES" : "NO"); + return 0; +} +int main() { + int n, t, x; + cin >> n >> t; + for (int i = 1; i <= n; i++) { + cin >> x; + t = t - (86400 - x); + if (t <= 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, d; + cin >> n >> d; + if (n == 2) { + if (d == 1) + cout << "4"; + else + cout << "5"; + } else if (n == 4 || n == 6 || n == 9 || n == 11) { + int ans = 5; + if (d == 7) ans++; + cout << ans; + } else { + int ans = 5; + if (d >= 6) ans++; + cout << ans; + } + cout << endl; + return 0; +} +int main() { + int n, k, counter, c = 0; + string s; + cin >> n >> k; + for (int i = 0; i < n; i++) { + counter = 0; + cin >> s; + int counter = count(s.begin(), s.end(), '4'); + counter += count(s.begin(), s.end(), '7'); + if (counter <= k) c++; + } + cout << c << endl; + return 0; +} +int main() { + long n, min, t, a[361]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> t; + a[i] = a[i - 1] + t; + } + min = 360; + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + t = a[j] - a[i]; + if (min > abs(360 - t - t)) min = abs(360 - t - t); + } + } + cout << min << endl; + return 0; +} +int main() { + int n, m1, n1, m2, n2, m3, n3; + cin >> n >> m1 >> n1 >> m2 >> n2 >> m3 >> n3; + int r1, r2 = m2, r3 = m3; + r1 = n - (r2 + r3); + if (r1 > n1) { + int ex = r1 - n1; + r1 -= ex; + r2 += ex; + if (r2 > n2) { + int ex1 = r2 - n2; + r2 -= ex1; + r3 += ex1; + } + } + cout << r1 << " " << r2 << " " << r3 << endl; +} +const int MAXN = 100; +int a[MAXN]; +int b[MAXN]; +int c[MAXN * MAXN]; +bool cmp(int x, int y) { + return x > y; +} +int main() { + int n, m; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int j = 0; j < m; ++j) cin >> b[j]; + int cnt = 0; + for (int i = 0; i < n; ++i) + for (int j = 0; j < m; ++j) + if (b[j] % a[i] == 0) c[cnt++] = b[j] / a[i]; + sort(c, c + cnt, cmp); + int ans = 0; + for (int i = 0; i < cnt; i++) + if (c[i] == c[0]) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n] = {0}; + for (int i = 0; i < n - 1; i++) { + int x; + cin >> x; + a[x - 1] = 1; + } + int ans; + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + ans = i; + break; + } + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int n, m, a[110], b, c; + while (cin >> n >> m) { + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) { + cin >> c; + for (int j = 0; j < c; j++) { + cin >> b; + a[b] = 1; + } + } + int i; + for (i = 1; i <= m; i++) { + if (a[i] != 1) break; + } + if (i != m + 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + int count = 0, count1 = 0; + while (n--) { + cin >> s; + for (int i = 0; i <= k; i++) { + if (s.find(i + '0') != -1) count1++; + } + if (count1 == k + 1) count++; + count1 = 0; + } + cout << count << endl; + return 0; +} +vector d; +bool criba[100001]; +void crearCriba(const long long &n) { + memset(criba, 0, sizeof(criba)); + criba[0] = criba[1] = true; + for (long long i = 2; i <= n; i++) + if (!criba[i]) + for (long long j = (i * 2); ((j * j) <= n); j += i) criba[j] = true; + for (long long i = 2; i <= n; i++) + if (!criba[i]) d.push_back(i); +} +int main() { + long long n, k, p = 0; + cin >> n >> k; + crearCriba(n); + vector r; + while (n > 1) { + if (!(n % d[p])) { + n /= d[p]; + r.push_back(d[p]); + } else if ((p + 1) < int(d.size())) + p++; + } + if (int(r.size()) >= k) { + long long mult = 1; + for (long long i = 0; i < (k - 1); i++) cout << r[i] << " "; + for (long long i = (k - 1); i < int(r.size()); i++) mult *= r[i]; + if (mult > 1) cout << mult << "\n"; + return 0; + } + cout << "-1\n"; + return 0; +} +int arr[100010]; +int main() { + int n, c, hitung = 0; + cin >> n >> c; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = n; i >= 2; i--) { + if (arr[i] - arr[i - 1] <= c) { + hitung++; + } else { + cout << hitung + 1 << endl; + return 0; + } + } + cout << hitung + 1 << endl; +} +int main() { + int p1, p2, p3, p4; + int a, b; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + int ans = 0; + for (int i = a; i <= b; ++i) + if (i == (((i % p1) % p2) % p3) % p4) ++ans; + cout << ans << endl; + return 0; +} +int len, n1, n2; +char s[105]; +int main() { + cin >> s; + len = strlen(s); + for (int i = 0; i < len; i++) + if (s[i] == 'o') + n1++; + else if (s[i] == '-') + n2++; + if (n1 == 0) + cout << "YES" << endl; + else if (n2 % n1 == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + long long n, x, y; + cin >> n >> x >> y; + string s; + cin >> s; + int len = s.length(); + int sum = 0; + for (int i = 0; i < len - 1; i++) { + if (s[i] == '0' && s[i + 1] == '1') sum++; + } + if (s[len - 1] == '0') sum++; + long long res = 0; + if (sum != 0) { + if (x < y) { + res = (sum - 1) * x + y; + } else { + res = sum * y; + } + } + cout << res << endl; + return 0; +} +int main() { + int n, a, b, sum = 0, num = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) { sum++; } + if (b > a) { num++; } + } + if (sum > num) { cout << "Mishka" << endl; } + if (sum == num) { cout << "Friendship is magic!^^" << endl; } + if (sum < num) { cout << "Chris" << endl; } + return 0; +} +void solve(long long n, long long num) { + vector q; + for (int i = n - num * 9; i <= n - 1; i++) { + long long sum = i, t = i; + while (t > 0) { + sum += t % 10; + t = t / 10; + } + if (sum == n) q.push_back(i); + } + cout << q.size() << endl; + for (int i = 0; i < q.size(); i++) cout << q[i] << endl; +} +int main() { + long long n; + cin >> n; + if (n <= 18) { + if (n % 2 == 0) + cout << 1 << endl << n / 2 << endl; + else if (n == 11) + cout << 1 << endl << 10 << endl; + else if (n == 13) + cout << 1 << endl << 11 << endl; + else if (n == 15) + cout << 1 << endl << 12 << endl; + else if (n == 17) + cout << 1 << endl << 13 << endl; + else + cout << 0 << endl; + } else { + long long s = 0, t = n; + while (t > 0) { + t = t / 10; + s++; + } + solve(n, s); + } + return 0; +} +int main() { + int n, flag; + cin >> n; + int a[55][55]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + flag = 1; + if (a[i][j] == 1) continue; + for (int k = 0; k < n; k++) { + for (int l = 0; l < n; l++) { + if (a[i][k] + a[l][j] == a[i][j]) { flag = 0; } + } + } + if (flag) { + cout << "No" << endl; + return 0; + } + } + } + cout << "Yes" << endl; + return 0; +} +int main() { + int n, m, gmin, gmax; + cin >> n >> m >> gmin >> gmax; + vector v; + for (int i = 0; i < m; ++i) { + int d; + cin >> d; + v.push_back(d); + } + int mmin = *min_element(v.begin(), v.end()); + int mmax = *max_element(v.begin(), v.end()); + if (mmin < gmin) { + mmin = -1; + } else if (mmin > gmin) { + mmin = +1; + } else + mmin = 0; + if (mmax > gmax) { + mmax = -1; + } else if (mmax < gmax) { + mmax = +1; + } else + mmax = 0; + if (mmin < 0 || mmax < 0) { + cout << "Incorrect\n"; + } else { + if (mmin + mmax <= n - m) + cout << "Correct\n"; + else + cout << "Incorrect" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector arr[3]; + int i, a; + for (i = 0; i < n; i++) { + cin >> a; + if (a == 1) { + arr[0].push_back(i + 1); + } else if (a == 2) { + arr[1].push_back(i + 1); + } else { + arr[2].push_back(i + 1); + } + } + int nt = min(arr[0].size(), min(arr[1].size(), arr[2].size())); + cout << nt << endl; + for (i = 0; i < nt; i++) { cout << arr[0][i] << " " << arr[1][i] << " " << arr[2][i] << endl; } + return 0; +} +int main() { + long long int n, i; + cin >> n; + long long int a[n], max = 0; + map m; + for (i = 0; i < n; i++) { + cin >> a[i]; + m[a[i]]++; + if (m[a[i]] > max) max = m[a[i]]; + } + cout << max << "\n"; +} +int main() { + int n, res = 0, mn = INT_MAX, mx = INT_MIN; + int a[100001]; + bool b1 = 0, b2 = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + mn = min(a[i], mn); + mx = max(a[i], mx); + } + for (int i = 0; i < n; i++) { + if (a[i] > mn && a[i] < mx) ++res; + } + cout << res << endl; + return 0; +} +long long in[200010]; +int n, n2; +long long ans; +int main() { + cin >> n; + n2 = n * 2; + for (int i = 0; i < n2; i++) cin >> in[i]; + sort(in, in + n2); + ans = (in[n - 1] - in[0]) * (in[n2 - 1] - in[n]); + for (int i = 1; i < n; i++) ans = min(ans, (in[n - 1 + i] - in[i]) * (in[n2 - 1] - in[0])); + cout << ans << '\n'; + return 0; +} +int main() { + int q, n; + string s; + cin >> q; + for (int k = 0; k < q; ++k) { + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) { + cout << "NO\n"; + continue; + } + s.insert(1, " "); + cout << "YES\n" << 2 << "\n" << s << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int a, b, q, p; + cin >> a >> b >> q >> p; + long long int d = __gcd(q, p); + q /= d; + p /= d; + long long int l = -1, r = 1e10; + long long int ans = -1; + while (r > l) { + long long int mid = (l + r) / 2; + long long int x = q * mid - a; + long long int y = p * mid - b; + if (x >= 0 && y >= 0 && y >= x) { + ans = y; + r = mid; + } else { + l = mid + 1; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, m; + char a[1000][1000]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cin >> a[i][j]; + } + int k[1000] = {0}; + int count = 0; + for (int i = 1; i <= m; i++) { + int max = -1; + for (int j = 1; j <= n; j++) { + if (a[j][i] > max) max = a[j][i]; + } + for (int j = 1; j <= n; j++) { + if (!k[j] && a[j][i] == max) { + count++; + k[j] = 1; + } + } + } + cout << count << endl; + return 0; +} +int a[100][100]; +void margesort(int p[], int t[], int l, int r); +void marge(int p[], int t[], int l, int m, int r); +int main() { + int n, k, p[100], t[100]; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> p[i] >> t[i]; + a[p[i]][t[i]]++; + } + margesort(p, t, 0, n - 1); + cout << a[p[k - 1]][t[k - 1]] << endl; + return 0; +} +void margesort(int p[], int t[], int l, int r) { + if (l < r) { + int m = (l + r - 1) / 2; + margesort(p, t, l, m); + margesort(p, t, m + 1, r); + marge(p, t, l, m, r); + } +} +void marge(int p[], int t[], int l, int m, int r) { + int i, j, k; + int n1 = m - l + 1; + int n2 = r - m; + int L[n1], R[n2], ll[n1], rr[n2]; + for (i = 0; i < n1; i++) { + L[i] = p[l + i]; + ll[i] = t[l + i]; + } + for (j = 0; j < n2; j++) { + R[j] = p[m + 1 + j]; + rr[j] = t[m + 1 + j]; + } + i = 0; + j = 0; + k = l; + while (i < n1 && j < n2) { + if (L[i] > R[j]) { + p[k] = L[i]; + t[k] = ll[i]; + i++; + } else if (L[i] == R[j] && ll[i] <= rr[j]) { + p[k] = L[i]; + t[k] = ll[i]; + i++; + } else { + p[k] = R[j]; + t[k] = rr[j]; + j++; + } + k++; + } + while (i < n1) { + p[k] = L[i]; + t[k] = ll[i]; + i++; + k++; + } + while (j < n2) { + p[k] = R[j]; + t[k] = rr[j]; + j++; + k++; + } +} +int main() { + int n, i, j, k, l; + cin >> n; + int arr[n][n]; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { arr[i][j] = 1; } + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i > 0 && j > 0) { arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; } + } + } + cout << arr[n - 1][n - 1] << "\n"; +} +int gcd(int x, int y) { + int m; + while (y != 0) { + m = x; + x = y; + y = m % y; + } + return x; +} +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + int lcm = n * m / gcd(n, m); + cout << z / lcm << endl; + } + return 0; +} +int main() { + string f, s, m, nex; + int i, n; + cin >> f >> s; + cout << f << " " << s << endl; + cin >> n; + for (i = 0; i < n; i++) { + cin >> m >> nex; + if (m == f) + f = nex; + else + s = nex; + cout << f << " " << s << endl; + } + return 0; +} +int main() { + int arr[11]; + arr[0] = 2; + arr[1] = 7; + arr[2] = 2; + arr[3] = 3; + arr[4] = 3; + arr[5] = 4; + arr[6] = 2; + arr[7] = 5; + arr[8] = 1; + arr[9] = 2; + int n; + cin >> n; + int ans = arr[n / 10] * arr[n % 10]; + cout << ans << endl; +} +char a[1000]; +char b[1000]; +int cmp(char a, char b) { + return a - 'a' < b - 'a'; +} +int main() { + int m, n, i; + while (cin >> m) { + cin >> n; + for (i = 0; i < m; i++) { cin >> a[i]; } + sort(a, a + m, cmp); + int sum = a[0] - 'a' + 1; + int k = 1; + int rec = 0; + for (i = 1; i < m; i++) { + if (k >= n) break; + rec += a[i] - a[i - 1]; + if (rec > 1) { + sum += a[i] - 'a' + 1; + rec = 0; + k++; + } + } + if (k < n) + cout << "-1" << endl; + else + cout << sum << endl; + } +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +const int maxn = 109; +const int MAXM = 500000; +int main() { + int n; + while (cin >> n) { + int b = 0, c = 0; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + temp < 0 ? c += temp : b += temp; + } + cout << b - c << endl; + } + return 0; +} +int main() { + int n; + int m[55][55]; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> m[i][j]; } + } + int flag = 1; + for (int i = 0; i < n; i++) { + if (flag) + for (int j = 0; j < n; j++) { + if (m[i][j] != 1) { + flag = 0; + for (int s = 0; s < n; s++) { + for (int t = 0; t < n; t++) { + if (m[i][j] == m[i][s] + m[t][j]) { + flag = 1; + break; + } + } + } + } + if (flag == 0) { break; } + } + } + if (flag) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + return 0; +} +int a[10001], w[10001]; +int main() { + int n, k; + cin >> n >> k; + int y; + cin >> y; + for (int i = 1; i <= y; i++) { + int x; + cin >> x; + w[x] = 1; + } + int m = k; + for (int i = 1; i <= n; i++) { + if (w[i] != 0) { + a[i] = 1; + m = i; + m += k; + } else if (i == m) { + a[i] = 1; + m += k; + } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + if (a[i] == 1) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int a[n]; + for (int i = 0; i < n; i++) { + int u, v; + cin >> u >> v; + a[i] = u * 60 + v; + } + sort(a, a + n); + if (a[0] >= s + 1) + cout << "0 0" << endl; + else { + int i; + for (i = 1; i < n; i++) { + if (a[i] - a[i - 1] >= 2 * s + 2) { + int t = a[i - 1] + s + 1; + cout << t / 60 << " " << t % 60 << endl; + break; + } + } + if (i == n) { + int t = a[n - 1] + s + 1; + cout << t / 60 << " " << t % 60 << endl; + } + } +} +int main() { + int n, m, mi, ma; + cin >> n >> m >> mi >> ma; + int inp; + cin >> inp; + int Mi = inp, Ma = inp; + for (int i = 1; i < m; ++i) { + cin >> inp; + Mi = min(Mi, inp); + Ma = max(Ma, inp); + } + if (Mi < mi || Ma > ma) return cout << "Incorrect\n", 0; + int t = 0; + if (Mi != mi) ++t; + if (Ma != ma) ++t; + cout << (t <= n - m ? "Correct" : "Incorrect") << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + if (n < 10 || n > 21) { + cout << 0 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else if (n == 10) { + cout << 0 << endl; + } else { + cout << 4 << endl; + } + } + return 0; +} +int main() { + char s[150][150]; + int n, m, cnt = 0; + int x = -1, y = -1; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] == 'B') { + if (x == -1 && y == -1) { + x = i + 1; + y = j + 1; + cnt++; + } else + cnt++; + } + } + if (cnt) break; + } + cout << x + cnt / 2 << " " << y + cnt / 2 << endl; + return 0; +} +int main() { + long long int k, n, s, p; + cin >> k >> n >> s >> p; + long long int am = n / s; + if (n % s != 0) am++; + am = am * k; + long long int ans = am / p; + if (am % p != 0) ans++; + cout << ans << "\n"; + return 0; +} +int lucky(int a) { + int r, v = 0; + while (a != 0) { + r = a % 10; + if (r == 7 || r == 4) { v++; } + a = a / 10; + } + return v; +} +int main() { + int n, x, res = 0; + cin >> n >> x; + int num[n]; + for (int i = 0; i < n; i++) { + cin >> num[i]; + int v; + v = lucky(num[i]); + if (v <= x) { res++; } + } + cout << res << endl; + return 0; +} +int main() { + int n, i = 0, cnt = 0; + string s; + cin >> n >> s; + while (s[i] != '\0') { + if (s[i] == '8') cnt++; + i++; + } + if (n >= 11 && n / 11 <= cnt && cnt != 0) + cout << n / 11 << "\n"; + else if (n >= 11 && n / 11 >= cnt && cnt != 0) + cout << cnt << "\n"; + else + cout << "0\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + int arr[] = {100, 20, 10, 5, 1}; + long long int i, j, c = 0; + for (i = 0; i < 5; i++) { + long long int a = n / arr[i]; + c += a; + n = n - (a * arr[i]); + if (n <= 0) break; + } + cout << c << endl; +} +int main() { + long long n, i; + string s; + cin >> n >> s; + long long z = 0; + long long o = 0; + for (i = 0; i < s.size(); i++) + if (s[i] == '0') + z++; + else + o++; + cout << abs(z - o) << endl; + return 0; +} +int mabs(int x) { + if (x >= 0) { + return x; + } else { + return -1 * x; + } +} +int main() { + int A[5][5]; + int a, b, moves; + for (int i = 0; i < 5; ++i) { + for (int j = 0; j < 5; j++) { + cin >> A[i][j]; + if (A[i][j] == 1) { + a = i; + b = j; + } + } + } + int c = mabs(a - 2) + mabs(b - 2); + cout << c << endl; +} +int vis[100006]; +int main() { + memset(vis, 0, sizeof(vis)); + int n; + cin >> n; + int ans = 0; + int re = 0; + for (int i = 0; i < 2 * n; i++) { + int t; + cin >> t; + if (vis[t] == 1) { + vis[t] = 0; + re--; + } else { + vis[t] = 1; + re++; + ans = ans < re ? re : ans; + } + } + cout << ans << endl; + return 0; +} +int main() { + int ans = 0; + int a, b, c; + cin >> a >> b >> c; + for (int i = 1; i <= c; i++) { + if (i % a == 0 && i % b == 0) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + int t = 1; + cin >> t; + while (t--) { + long long int n, x, y, d; + cin >> n >> x >> y >> d; + if (x == y) { + cout << 0 << '\n'; + continue; + } + if (abs(y - x) % d == 0) + cout << abs(y - x) / d << '\n'; + else { + long long int m1 = -1, m2 = -1; + if ((n - y) % d == 0) { + m1 = (n - y) / d; + if ((n - x) % d == 0) + m1 += (n - x) / d; + else + m1 += ((n - x) / d + 1); + } + if ((y - 1) % d == 0) { + m2 = (y - 1) / d; + if ((x - 1) % d == 0) + m2 += (x - 1) / d; + else + m2 += ((x - 1) / d + 1); + } + if (m1 == -1 && m2 == -1) + cout << -1 << '\n'; + else if (m1 != -1 && m2 != -1) + cout << min(m1, m2) << '\n'; + else + cout << max(m1, m2) << '\n'; + } + } +} +int main() { + int n, m; + cin >> n >> m; + int count = 0; + while (n > 0) { + n--; + count++; + if (count % m == 0) n++; + } + cout << count << endl; + return 0; +} +int main() { + int cnt = 0; + int carry = 1; + int n; + cin >> n; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) { + if (carry == 1 && str[i] == '1') cnt++; + if (str[i] == '0' && carry == 1) { + cnt++; + break; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, Count = 0; + cin >> n; + int i, j, h[n], g[n]; + for (i = 0; i < n; i++) { cin >> h[i] >> g[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if ((i != j) && (h[i] == g[j])) + { + Count++; + } + } + } + cout << Count << endl; + return 0; +} +int main() { + long long n; + cin >> n; + assert(n & 1 == 1LL); + long long md = n >> 1; + for (long long i = 0; i <= md; i++) { + for (long long j = 0; j < n; j++) + if (j < md - i || j > md + i) + cout << "*"; + else + cout << 'D'; + cout << "\n"; + } + for (long long i = md - 1; i >= 0; i--) { + for (long long j = 0; j < n; j++) + if (j < md - i || j > md + i) + cout << "*"; + else + cout << 'D'; + cout << "\n"; + } + return 0; +} +int main() { + int T; + cin >> T; + while (T--) { + int n; + string S; + cin >> n; + cin >> S; + bool ac = true; + for (int i = 0; i < n / 2 && ac; i++) { + int t1 = S[i] - 97, t2 = S[n - 1 - i] - 97; + if (t1 < t2) swap(t1, t2); + if (t1 - t2 != 2 && t1 != t2) ac = false; + } + if (ac) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int arr[n]; + for (int i = 0; i < n; ++i) cin >> arr[i]; + bool found = false; + int mn = 1000000001; + for (int i = 0; i < n - 1; ++i) + if (s[i] == 'R' && s[i + 1] == 'L') found = true, mn = min(mn, arr[i + 1] - arr[i]); + if (found) + cout << mn / 2 << endl; + else + cout << -1 << endl; + return 0; +} +int MOD(int a, int b) { + if (a > b) + return a - b; + else + return b - a; +} +long long int max3(long long int a, long long int b, long long int c) { + return max(c, max(a, b)); +} +long long int power(long long int x, long long int y, long long int p) { + long long int res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int gcd(long long int a, long long int b) { + if (b == 1) + return 1; + else if (a % b == 0) + return b; + else + return gcd(b, a % b); +} +int main() { + int n; + cin >> n; + int i, j, k; + int a[6], b[6]; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + for (i = 0; i != n; i++) { + cin >> j; + a[j]++; + } + for (i = 0; i != n; i++) { + cin >> j; + b[j]++; + } + int mini = 0; + for (i = 1; i != 6; i++) { + if ((a[i] + b[i]) % 2 == 0) { + mini += max(a[i], b[i]) - (a[i] + b[i]) / 2; + } else { + cout << "-1\n"; + return 0; + } + } + if (mini % 2 == 0) + cout << mini / 2 << "\n"; + else + cout << "-1\n"; + return 0; +} +string s; +vector sc; +int n, p; +bool solve(int idx) { + if (idx == -1) return false; + while (sc[idx] < p) { + if (idx && sc[idx] == sc[idx - 1]) + sc[idx]++; + else if (idx > 1 && sc[idx] == sc[idx - 2]) + sc[idx]++; + else + break; + } + if (sc[idx] == p) { + sc[idx] = 0; + if (idx) sc[idx - 1]++; + if (solve(idx - 1)) return solve(idx); + } else + return true; +} +int main() { + cin >> n >> p >> s; + sc.resize(n); + for (int i = 0; i < n; i++) sc[i] = s[i] - 'a'; + sc[n - 1]++; + if (solve(n - 1)) { + for (int i = 0; i < n; i++) cout << char('a' + sc[i]); + cout << "\n"; + } else + cout << "NO\n"; + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int ans; + ans = (n + (s - n % s) % s) / s; + ans = ((ans * k) + (p - (ans * k) % p) % p) / p; + cout << ans << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +int a[10]; +int main() { + int n; + cin >> n; + int sum = 0; + a[0] = 1; + a[1] = 5; + a[2] = 10; + a[3] = 20; + a[4] = 100; + while (n) { + for (int i = 4; i >= 0; i--) { + if (n >= a[i]) { + sum += n / a[i]; + n -= n / a[i] * a[i]; + if (n <= 0) { break; } + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, k, x, a, total = 0; + cin >> n >> k >> x; + for (int i = 0; i < n - k; i++) { + cin >> a; + total += a; + } + total += k * x; + cout << total << endl; + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int ans = 4 * (sqrt(a * b / c) + sqrt(a * c / b) + sqrt(b * c / a)); + cout << ans << endl; + } + return 0; +} +long long a, b, c, x[100001]; +int main() { + cin >> a >> b; + for (int i = 0; i < a; i++) cin >> x[i], c += (x[i] + b - 1) / b; + cout << (c + 1) / 2 << endl; + return 0; +} +int main() { + int n, m, i, j; + cin >> n >> m; + for (i = 1; i <= n; i++) { + if (i % 2) { + for (j = 1; j <= m; j++) cout << '#'; + cout << endl; + } else if (i % 4 == 0) { + cout << '#'; + for (j = 2; j <= m; j++) { cout << '.'; } + cout << endl; + } else { + for (j = 1; j < m; j++) { cout << '.'; } + cout << '#' << endl; + } + } + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + int x = (t1 * 2) + (s * v1); + int y = (t2 * 2) + (s * v2); + if (x == y) + cout << "Friendship\n"; + else if (x < y) + cout << "First\n"; + else + cout << "Second\n"; + return 0; +} +const int inf = 0x3f3f3f3f; +long int l, r, x, y, k; +bool find(long int start, long int end) { + long int mid = (start + end) / 2; + if (start + 1 == end) return false; + if (mid * k > r) { + if (find(start, mid)) + return true; + else + return false; + } else if (mid * k < l) { + if (find(mid, end)) + return true; + else + return false; + } else + return true; +} +int main() { + long long int a, b, c, d, e; + cin >> a >> b >> c >> d >> e; + for (int i = c; i <= d; i++) { + long long num = i * e; + if (num >= a && num <= b) { + cout << "YES" << endl; + return 0; + } else if (num > b) { + break; + } + } + cout << "NO" << endl; + return 0; + return 0; +} +int main() { + int arr[3]; + cin >> arr[0] >> arr[1] >> arr[2]; + sort(arr, arr + 3); + cout << arr[2] - arr[0] << endl; + return 0; +} +string a; +void solve() { + int i, j, l = a.length(); + string b[10]; + for (i = 0; i < 10; i++) cin >> b[i]; + for (i = 0; i < l; i += 10) + for (j = 0; j < 10; j++) + if (a.substr(i, 10) == b[j]) cout << j; + cout << endl; +} +int main() { + while (cin >> a) solve(); +} +int main() { + int n, x, odd = 0, even = 0, y1, y2; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x % 2 == 0) { + even++; + y2 = i; + } else { + odd++; + y1 = i; + } + } + odd == 1 ? cout << y1 << endl : cout << y2 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + char b[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + for (int i = n - 1; i >= 0; i--) { + for (int j = m - 1; j >= 0; j--) { + if (a[i][j] == '-') + b[i][j] = '-'; + else if (a[i][j] == '.') { + if ((i + j) % 2 == 0) + a[i][j] = 'B'; + else + a[i][j] = 'W'; + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << a[i][j]; } + cout << "\n"; + } +} +int f(char c) { + if (c == '^') return 0; + if (c == '>') return 1; + if (c == 'v') return 2; + return 3; +} +int main() { + char c1, c2; + int n; + cin >> c1 >> c2 >> n; + int a = f(c1), b = f(c2); + int x = (a + n - b + 4) % 4; + int y = (b + n - a + 4) % 4; + if (x == 0 && y == 0) + cout << "undefined\n"; + else if (x == 0) + cout << "cw\n"; + else + cout << "ccw\n"; + return 0; +} +int main() { + long long int t; + cin >> t; + while (t--) { + long long int a; + cin >> a; + if ((360 % (180 - a)) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +long long c, v0, ff, v1, a, l; +long long now, sc = 1; +int main() { + cin >> c >> v0 >> v1 >> a >> l; + now = v0; + ff = v0; + while (now < c) { + ff = min(v1, ff + a); + now += ff - l; + sc++; + } + cout << sc << endl; +} +long long n; +long long x; +int main() { + cin >> n; + x = n; + if (n % 10 == 0) { + cout << n << endl; + return 0; + } + while (x > 10) { x %= 10; } + if (x <= 5) + cout << n - x << endl; + else + cout << n + (10 - x) << endl; + return 0; +} +const int N = 100 * 1000 + 4; +int n; +int main() { + string s; + cin >> s; + n = s.size(); + int ans = 0, last = 0; + for (int i = 1; i <= n; i++) { + if (i == n || s[i] != s[i - 1]) { + if ((i - last) % 2 == 0) ++ans; + last = i; + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + long long arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + long long N = 0; + for (int i = 0; i < n - 1; i++) { + int t = floor(log2(n - i - 1)); + N = N + arr[i]; + int j = i + pow(2, t); + arr[j] += arr[i]; + arr[i] = 0; + cout << N << endl; + } + return 0; +} +const int maxn = 100005; +int a[maxn]; +int main() { + int n; + cin >> n; + int imax = 0, ans = 1; + for (int i = 1; i <= n; ++i) cin >> a[i]; + for (int i = 2; i <= n; ++i) { + if (a[i] > a[i - 1]) { + ans++; + } else { + imax = max(imax, ans); + ans = 1; + } + } + imax = max(imax, ans); + cout << imax << endl; + return 0; +} +int main() { + int j = 0, n, sumc = 0, sumr = 0, i = 0; + cin >> n; + int d[n][n]; + for (int r = 0; r < n; r++) + for (int c = 0; c < n; c++) cin >> d[r][c]; + for (int r = 0; r < n; r++) + for (int c = 0; c < n; c++) { + sumc = 0; + sumr = 0; + i = 0; + while (i < n) { + sumr += d[r][i]; + i++; + } + i = 0; + while (i < n) { + sumc += d[i][c]; + i++; + } + if (sumc > sumr) j++; + } + cout << j << endl; +} +int main() { + int n; + int a, b, c, d; + int vis[105][105]; + while (cin >> n) { + memset(vis, 0, sizeof(vis)); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c >> d; + for (int i = a; i <= c; i++) + for (int j = b; j <= d; j++) { vis[i][j]++; } + } + for (int i = 1; i <= 100; i++) + for (int j = 1; j <= 100; j++) { sum = sum + vis[i][j]; } + cout << sum << endl; + } + return 0; +} +const long long mod = 100; +long long re(long long a, long long n) { + long long ans = 1; + while (n > 0) { + if (n & 1) ans = (ans * a) % mod; + a = (a * a) % mod; + n >>= 1; + } + return ans; +} +int main() { + long long n; + while (cin >> n) { + long long result = re(5, n); + cout << result << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int strt = 0, smoves = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + int index = s[i] - 97; + int walk = abs(strt - index); + if (walk < 13) { + smoves += walk; + } else { + smoves += 26 - walk; + } + strt = index; + } + cout << smoves << "\n"; + return 0; +} +int main() { + int a, b, t, n, sum = 0, i, flag = 0; + cin >> t; + for (i = 1; i <= t; i++) { + cin >> a; + if (a == 1) { flag = 1; } + } + if (flag == 1) { + cout << -1 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int n, i, j, k, x; + vector ct(4, 0); + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + ct[x]++; + } + cout << n - max(ct[1], max(ct[2], ct[3])) << "\n"; + ; + return 0; +} +int n; +int main() { + cin >> n; + cout << n % 2 << endl; +} +void rot1(string &s) { + swap(s[0], s[1]); + swap(s[1], s[2]); + swap(s[2], s[3]); +} +void rot2(string &s) { + swap(s[0], s[4]); + swap(s[4], s[2]); + swap(s[2], s[5]); +} +string normalize(string s) { + string res = s; + for (int _n(2), k(0); k < _n; k++) { + for (int _n(4), j(0); j < _n; j++) { + for (int _n(4), i(0); i < _n; i++) { + rot1(s); + res = min(res, s); + } + rot2(s); + } + rot1(s); + } + return res; +} +int main() { + string s; + cin >> s; + sort((s).begin(), (s).end()); + set S; + do { S.insert(normalize(s)); } while (next_permutation((s).begin(), (s).end())); + cout << S.size() << endl; + return 0; +} +long long n; +int main() { + cin >> n; + cout << n / 2 + 1 << endl; +} +int a[111]; +int main() { + int n, d; + cin >> n >> d; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 2; + for (int i = 1; i < n; i++) { + int tmp = a[i - 1] + d; + if (a[i] - tmp > d) { + ans += 2; + } else if (a[i] - tmp == d) { + ans++; + } + } + cout << ans << endl; +} +int main() { + long long l, r; + cin >> l >> r; + if (r - l + 1 < 3) { + cout << -1 << endl; + return 0; + } + if (l % 2 == 0) { + cout << l << ' ' << l + 1 << ' ' << l + 2 << endl; + return 0; + } + if (r - l + 1 > 3) { + cout << l + 1 << ' ' << l + 2 << ' ' << l + 3 << endl; + return 0; + } + cout << -1 << endl; +} +int main() { + vector h; + int a, b, n, num; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + cin >> num; + h.push_back(num); + } + sort(h.begin(), h.end()); + if (h[b - 1] == h[b]) + cout << 0 << endl; + else + cout << h[b] - h[b - 1] << endl; + return 0; +} +int n, m, ans = 0; +char mp[109][109]; +bool used[109]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cin >> mp[i][j]; + } + memset(used, 0, sizeof(used)); + for (int i = 1; i <= m; i++) { + int maxV = -1; + for (int j = 1; j <= n; j++) { + if (mp[j][i] > maxV) maxV = mp[j][i]; + } + for (int j = 1; j <= n; j++) { + if (!used[j] && mp[j][i] == maxV) { + ans++; + used[j] = 1; + } + } + } + cout << ans << endl; + return 0; +} +int a[100001]; +int main() { + int n; + cin >> n; + for (int i = 1; i < n + 1; i++) cin >> a[i]; + long long res = 0; + int t; + for (int i = 1; i < n; i++) { + for (t = 1; i + t <= n; t *= 2) + ; + t >>= 1; + res += a[i]; + a[i + t] += a[i]; + cout << res << endl; + } + return 0; +} +int main() { + int s[601], a, sum = 0, n; + memset(s, 0, sizeof(s)); + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + s[a]++; + } + for (int i = 1; i <= 600; i++) + if (s[i] > 0) sum++; + cout << sum << endl; + return 0; +} +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + long long ans = 0; + for (int i = 1; m * i <= z; i++) { + if ((m * i) % n == 0) ans++; + } + cout << ans << endl; + } +} +bool cmp(int a, int b) { + return a > b; +} +int cc[105]; +int main() { + int n, res = 0, flag = 0, f; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> cc[i]; } + sort(cc + 1, cc + 1 + n); + swap(cc[1], cc[n]); + for (int i = 1; i <= n; i++) { + if (i == n) + cout << cc[i] << endl; + else + cout << cc[i] << " "; + } + return 0; +} +const int size = 105; +int suf[size] = {0}, pre[size] = {0}; +int main() { + int n; + cin >> n; + int arr[n + 1] = {0}; + for (int i = 1; i <= n; i++) cin >> arr[i], suf[i] = (arr[i]), pre[i] = (!arr[i]); + for (int i = n; i >= 1; i--) suf[i] += suf[i + 1]; + for (int i = 1; i <= n; i++) pre[i] += pre[i - 1]; + int ans = 0; + for (int i = 1; i <= n; i++) ans = max(ans, pre[i] + suf[i]); + cout << ans << "\n"; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int maxi = max((3 * a) / 10, (a - (a / 250) * c)); + int maxi2 = max((3 * b) / 10, (b - (b / 250) * d)); + if (maxi > maxi2) { + cout << "Misha" << endl; + } else if (maxi < maxi2) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } +} +int main() { + int q; + cin >> q; + string a, b; + cin >> a >> b; + int sch = 0; + for (int i = 0; i < q; i++) { + int x = abs(a[i] - b[i]); + sch += min(x, 10 - x); + } + cout << sch << endl; +} +int main() { + int n, h[30], g[30], i, j, count = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> h[i] >> g[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (h[i] == g[j] && j != i) count++; + } + } + cout << count << endl; +} +const int inf32 = 1 << 30; +const long long inf64 = 1LL << 60; +int main() { + int n, m; + cin >> n >> m; + int c[n], a[m]; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> a[i]; + int id0 = 0, id1 = 0, cnt = 0; + while (id0 < n && id1 < m) { + if (a[id1] >= c[id0]) id1++; + id0++; + } + cout << id1 << endl; +} +int main() { + int i = 0; + string n1, n2; + cin >> n1 >> n2; + while (n1[i] != '\0') { + int x1 = n1[i], x2 = n2[i]; + if (n1[i] >= 'A' && n1[i] <= 'Z') { + x1 = x1 + 32; + n1[i] = x1; + } + if (n2[i] >= 'A' && n2[i] <= 'Z') { + x2 = x2 + 32; + n2[i] = x2; + } + ++i; + } + if (n1 == n2) + cout << "0" << endl; + else { + for (i = 0; i < n1.size(); i++) { + if (n1[i] < n2[i]) { + cout << "-1" << endl; + break; + } + if (n1[i] > n2[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int main() { + int k, r, a; + cin >> k >> r; + for (int i = 1;; i++) { + if (k * i % 10 == 0) { + cout << i << endl; + return 0; + } else if (((k * i) % 10) == r) { + cout << i << endl; + return 0; + } + } +} +int main() { + vector x; + int k = 1; + x.push_back(0); + do { x.push_back(x.back() + k); } while (k++ && x.back() <= 505); + int n; + cin >> n; + if (binary_search(x.begin(), x.end(), n)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long n, k; +int main() { + while (cin >> n >> k) { + if (k <= n) + cout << 1 << endl; + else if (k % n == 0) + cout << k / n << endl; + else if (k % n != 0) + cout << k / n + 1 << endl; + } +} +int main() { + long long int a, b, c, d, e, f, g, h; + vector v[102], t[103]; + while (cin >> a) { + for (b = 1; b <= a; b++) { + cin >> c; + v[c].push_back(0); + t[c].push_back(0); + } + for (b = 1; b <= a; b++) { + cin >> c; + v[c].push_back(0); + } + d = 1; + for (b = 1; b <= 5; b++) { + if (v[b].size() % 2 != 0 && v[b].size() >= 1) { d = 0; } + } + e = 0; + for (b = 1; b <= 5; b++) { + if (t[b].size() >= 1) { + f = v[b].size(); + g = t[b].size(); + h = f / 2.; + if (g > h) { e += g - h; } + } + t[b].clear(); + v[b].clear(); + } + if (d == 0) { + cout << "-1" << endl; + } else { + cout << e << endl; + } + } + return 0; +} +const int INF = 0x3f3f3f3f; +const int mod = 1e9 + 7; +const double eps = 1e-6; +int p[30]; +int main() { + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 1; i <= n; i++) { + char c; + cin >> c; + p[c - 'a' + 1]++; + ans = max(ans, p[c - 'a' + 1]); + } + if (ans > k) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +long long N, M, ans, A[26], k, x, y, z, l, r; +char C[55][55]; +int main() { + cin >> N >> M; + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= M; j++) { cin >> C[i][j]; } + } + for (int i = 1; i < N; i++) { + for (int j = 1; j < M; j++) { + memset(A, 0, sizeof(A)); + A[C[i][j] - 'a']++; + A[C[i + 1][j] - 'a']++; + A[C[i][j + 1] - 'a']++; + A[C[i + 1][j + 1] - 'a']++; + if (A[0] == 1 && A[5] == 1 && A[2] == 1 && A[4] == 1) ans++; + } + } + cout << ans << '\n'; +} +int main() { + long i, j, n, shengyu; + cin >> n; + j = n % 10; + if (j >= 5) { j = j - 4; } + i = 0; + shengyu = n % 100; + i = i + n / 100; + n = shengyu; + shengyu = n % 20; + i = i + n / 20; + n = shengyu; + shengyu = n % 10; + i = i + n / 10; + i = i + j; + cout << i << endl; + return 0; +} +const int N = 1e5 + 100; +int a, b, c; +vector v; +int main() { + cin >> a >> b >> c; + cout << (b * c) + (a - 1) * (b + c - 1) << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int x = s.length(); + for (int i = 0; i < x - 1;) { + if ((s[i] == '0' && s[i + 1] == '1')) { + s.erase(i, 1); + s.erase(i, 1); + if (i - 2 >= 0) + i = i - 2; + else + i = 0; + } else if (s[i] == '1' && s[i + 1] == '0') { + s.erase(i, 1); + s.erase(i, 1); + if (i - 2 >= 0) + i = i - 2; + else + i = 0; + } else + i++; + x = s.length(); + } + cout << s.length() << endl; + return 0; +} +int main() { + int x = 0; + for (int i = 1; i <= 5; ++i) { + for (int j = 1; j <= 5; ++j) { + cin >> x; + if (x == 1) { cout << abs(i - 3) + abs(j - 3) << endl; } + } + } + return 0; +} +int main() { + int n; + cin >> n; + n *= 2; + int a[1005]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (a[n / 2 - 1] != a[n / 2]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string x; + cin >> x; + if (x == "a8" || x == "a1" || x == "h8" || x == "h1") { + cout << 3 << '\n'; + } else { + if (x[0] == 'a' || x[0] == 'h' || x[1] == '1' || x[1] == '8') { + cout << 5 << '\n'; + } else { + cout << 8 << '\n'; + } + } + return 0; +} +int main() { + int n, m, day = 0; + cin >> n >> m; + for (int i = 1; n; i++) { + day++; + if (i % m == 0) continue; + n--; + } + cout << day << endl; +} +const int Maxn = 30010; +string s[Maxn]; +int n, j, ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + for (j = 0; j < s[0].size(); j++) + for (int i = 1; i < n; i++) + if (s[0][j] == s[i][j]) + ans++; + else { + ans /= (n - 1); + cout << ans << endl; + return 0; + } +} +int sum[205]; +int main() { + string s; + while (cin >> s) { + memset(sum, 0, sizeof(sum)); + int num = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + if (s[i] == 'Q') { num++; } + sum[i] = num; + } + long long result = 0; + for (int i = 0; i < len; i++) { + if (s[i] == 'A') result += sum[i] * (sum[len - 1] - sum[i]); + } + cout << result << endl; + } + return 0; +} +int main() { + int k; + cin >> k; + string s; + cin >> s; + vector a; + set st; + for (int i = 0; i < s.size(); i++) { + if (st.find(s[i]) == st.end()) { + a.push_back(i); + st.insert(s[i]); + } + } + if (a.size() < k) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + if (k < a.size()) { + for (int i = 0; i < k - 1; i++) { cout << s.substr(a[i], a[i + 1] - a[i]) << endl; } + cout << s.substr(a[k - 1], s.size() - a[k - 1]) << endl; + return 0; + } + if (k == a.size()) { + for (int i = 0; i < a.size() - 1; i++) { cout << s.substr(a[i], a[i + 1] - a[i]) << endl; } + cout << s.substr(a[a.size() - 1], s.size() - a[a.size() - 1]) << endl; + } +} +long long MAX(long long a, long long b) { + if (a > b) return a; + return b; +} +long long MIN(long long a, long long b) { + if (a < b) return a; + return b; +} +map cont; +int main() { + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (cont[a] == 0 && a != 0) { ans++; } + cont[a] += 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n, x, y; + set vertical, horizontal; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + vertical.insert(x); + horizontal.insert(y); + } + cout << min(vertical.size(), horizontal.size()) << '\n'; +} +int main() { + int n, d, maxn = 0, flag = 0, m = 0; + string s; + cin >> n >> d; + for (int i = 0; i < d; i++) { + cin >> s; + flag = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') flag = 1; + } + if (flag == 1) { + m++; + maxn = max(maxn, m); + } else { + m = 0; + } + } + cout << maxn << endl; +} +int main() { + int n, p, k; + bool start = 1, end = 0; + cin >> n >> p >> k; + for (int i = p - k; i <= p + k; i++) { + if (start) { + if (i <= 1) { + if (p == 1) + cout << "(" << 1 << ")"; + else + cout << 1; + i = 1; + } else + cout << "<< " << i; + start = 0; + continue; + } + if (i >= n) { + end = 1; + if (p == n) + cout << " (" << n << ")"; + else + cout << " " << n; + break; + } + if (i == p) + cout << " (" << i << ")"; + else { + cout << " " << i; + } + } + if (!end) cout << " >>"; + cout << '\n'; +} +int main() { + int N, M, a[10020], b[10020], res = 0, ans = 0; + cin >> N; + for (int i = 0; i < N; i++) cin >> a[i]; + cin >> M; + for (int j = 0; j < M; j++) cin >> b[j]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (b[j] % a[i] == 0) { + if (b[j] / a[i] > res) { + res = b[j] / a[i]; + ans = 1; + } else if ((res != 0) && (b[j] / a[i] == res)) + ans++; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string digits; + cin >> digits; + pair N_ZerosOnes; + for (int i = 0; i < digits.size(); i++) { + if (digits[i] == '0') + N_ZerosOnes.first++; + else + N_ZerosOnes.second++; + } + if (N_ZerosOnes.first >= N_ZerosOnes.second) + cout << N_ZerosOnes.first - N_ZerosOnes.second << endl; + else + cout << N_ZerosOnes.second - N_ZerosOnes.first << endl; + return 0; +} +const int maxn = 10000; +int main() { + int ans = 0, res = 0; + string str; + bool flag[maxn] = {0}; + cin >> str; + for (int i = 1; i < (int)str.size(); i++) { + if (flag[i - 1] == true && str[i - 1] == 'V' && str[i] == 'K') + res--, ans++, i++; + else if (flag[i] == false && str[i - 1] == 'V' && str[i] == 'K') + ans++, i++; + else if (str[i - 1] == 'V' && str[i] == 'V') + flag[i] = true, res++; + else if (str[i - 1] == 'K' && str[i] == 'K') + res++, i++; + } + if (res) + cout << ans + 1 << endl; + else + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + pair a[50]; + for (int i = 0; i < n; i++) { + cin >> a[i].first >> a[i].second; + a[i].first *= -1; + } + sort(a, a + n); + cout << count(a, a + n, a[k - 1]) << endl; + return (0); +} +int main() { + int ar[11][11]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == 0) { + ar[i][j] = 1; + } else if (j == 0) { + ar[i][j] = 1; + } else { + ar[i][j] = ar[i - 1][j] + ar[i][j - 1]; + } + } + } + cout << ar[n - 1][n - 1] << endl; + return 0; +} +int main() { + int q; + cin >> q; + long long x = 1, y = 1; + while (q--) { + string s; + cin >> s; + if (s == "UR") + ++x; + else if (s == "UL") + ++y; + else if (s == "DR") + ++y; + else if (s == "DL") + ++x; + else { + ++x; + ++y; + } + } + cout << x * y << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + int first = s * v1 + t1 * 2; + int second = s * v2 + t2 * 2; + if (first == second) { + cout << "Friendship" << endl; + } else if (first < second) { + cout << "First" << endl; + } else { + cout << "Second" << endl; + } + int pause; + cin >> pause; + return 0; +} +string a, b, c, d; +int n; +int main() { + cin >> a >> b >> n; + cout << a << " " << b << endl; + for (int i = 1; i <= n; i++) { + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + cout << a << " " << b << endl; + } + return 0; +} +int n, l, r, i; +int main() { + cin >> n >> l >> r; + cout << (n - max(l, n - r - 1)) << endl; + return 0; +} +int main() { + int n, y = 0, length = 0, count = 0; + cin >> n; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + if (x >= y) { + count++; + } else { + count = 1; + } + y = x; + if (count > length) length = count; + } + cout << length << endl; + return 0; +} +int main() { + string s; + cin >> s; + int c = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') + c++; + else if ((s[i] < 'a' || s[i] > 'z') && (s[i] - '0') % 2 != 0) { + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int tmp; + int sum = 0; + while (cin >> tmp) { + if (tmp < 0) tmp = -tmp; + sum += tmp; + } + cout << sum << endl; +} +int main() { + int n; + cin >> n; + string s[n]; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + if (s[i].size() <= 10) + cout << s[i] << endl; + else + cout << s[i][0] << s[i].size() - 2 << s[i][s[i].size() - 1] << endl; + } + return 0; +} +int i, j; +set all; +string s; +int main() { + cin >> s; + for (i = s.size() - 1; i > 0; i--) { + all.clear(); + for (j = 0; j + i <= s.size(); j++) all.insert(s.substr(j, i)); + if (all.size() != s.size() - i + 1) { + cout << i << endl; + return 0; + } + } + cout << "0" << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + map, long long int> m; + for (long long int i = 1; i <= n; i++) { + string s; + cin >> s; + set yo; + for (long long int i = 0; i <= s.size() - 1; i++) { yo.insert(s[i]); } + m[yo] = 1; + } + cout << m.size() << endl; + return 0; +} +int main() { + string s1 = "Tetrahedron"; + string s2 = "Cube"; + string s3 = "Octahedron"; + string s4 = "Dodecahedron"; + string s5 = "Icosahedron"; + int n; + cin >> n; + int c = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == s1) + c += 4; + else if (s == s2) + c += 6; + else if (s == s3) + c += 8; + else if (s == s4) + c += 12; + else + c += 20; + } + cout << c << endl; +} +int n, c; +long long int s; +int main() { + cin >> s; + while (s != 0) { + n = s % 10; + if (n == 4 || n == 7) c++; + s /= 10; + } + if (c == 4 || c == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +const int maxn = 200010; +char str[maxn]; +int main() { + while (cin >> str) { + int j = 1, len = strlen(str); + for (int i = 1; i < len; i++) { + if (str[i] == str[j - 1]) { + j--; + str[j] = '\0'; + } else { + str[j++] = str[i]; + } + } + str[j] = '\0'; + cout << str << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int x, y, x1, y1, x2, y2; + cin >> x >> y >> x1 >> y1 >> x2 >> y2; + int flag = 1; + if (x1 == x || y1 == y || x2 == x || y2 == y) { flag = 0; } + if (abs(x - x1) == abs(y - y1) || abs(x - x2) == abs(y - y2)) { + flag = 0; + } else if (x1 < x && x2 > x) { + flag = 0; + } else if (x1 > x && x2 < x) { + flag = 0; + } else if (y1 < y && y2 > y) { + flag = 0; + } else if (y1 > y && y2 < y) { + flag = 0; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int nums[1001]; +bool compare_int(int &lhs, int &rhs) { + return lhs > rhs; +} +int main() { + int n; + cin >> n; + int max_num = 0; + for (int currnum = 0; currnum < n; ++currnum) { cin >> nums[currnum]; } + sort(nums, nums + n, compare_int); + int non_perfect = 0; + for (int currnum = 0; currnum < n; ++currnum) { + int sqrtroot = sqrt(nums[currnum]); + if (sqrtroot * sqrtroot != nums[currnum]) { + non_perfect = nums[currnum]; + break; + } + } + cout << non_perfect << endl; + return 0; +} +const int maxn = 1e3 + 10; +int main() { + int n; + int a[maxn]; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[(n + 1) / 2] << endl; + return 0; +} +int main() { + long long int n, x, y, i, max = 0, a = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x >> y; + a = a - x + y; + if (max < a) { max = a; } + } + cout << max << "\n"; +} +vector d; +bool criba[100001]; +void crearCriba(const long long &n) { + memset(criba, 0, sizeof(criba)); + criba[0] = criba[1] = true; + for (long long i = 2; ((i * i) <= n); i++) + if (!criba[i]) + for (long long j = (i * 2); j <= n; j += i) criba[j] = true; + for (long long i = 2; i <= n; i++) + if (!criba[i]) d.push_back(i); +} +int main() { + long long n, k, p = 0; + cin >> n >> k; + crearCriba(n); + vector r; + while (n > 1) { + if (!(n % d[p])) { + n /= d[p]; + r.push_back(d[p]); + } else if ((p + 1) < int(d.size())) + p++; + } + if (int(r.size()) >= k) { + long long mult = 1; + for (long long i = 0; i < (k - 1); i++) cout << r[i] << " "; + for (long long i = (k - 1); i < int(r.size()); i++) mult *= r[i]; + if (mult > 1) cout << mult << "\n"; + return 0; + } + cout << "-1\n"; + return 0; +} +int p[1005]; +int f[1005]; +int n, m, k; +void init() { + memset(p, 0, sizeof(p)); + for (int i = 1; i <= n; i++) f[i] = i; +} +int find(int x) { + if (f[x] == x) return x; + return f[x] = find(f[x]); +} +void uion(int p1, int p2) { + int f1, f2; + f1 = find(p1); + f2 = find(p2); + if (f1 != f2) f[f1] = f2; +} +int c[1005]; +int main() { + int p1, p2; + while (cin >> n >> m >> k) { + init(); + for (int i = 1; i <= k; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) { + cin >> p1 >> p2; + uion(p1, p2); + } + for (int i = 1; i <= n; i++) p[find(i)]++; + int maxn = 0, lef = n; + int ans = 0; + for (int i = 1; i <= k; i++) { + p[c[i]] = p[find(c[i])]; + maxn = max(maxn, p[c[i]]); + lef -= p[c[i]]; + ans += (p[c[i]] - 1) * (p[c[i]]) / 2; + } + ans += (lef + maxn) * (lef + maxn - 1) / 2; + ans -= maxn * (maxn - 1) / 2 + m; + cout << ans << endl; + } + return 0; +} +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + int count = 0; + for (int i = n; i <= z; i += n) { + for (int j = m; j <= z; j += m) { + if (i == j) count++; + } + } + cout << count << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n] = {}; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) { + if (a[0] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (a[0] == 0) { + cout << "UP" << endl; + return 0; + } else { + cout << "-1" << endl; + return 0; + } + } else { + if (a[n - 1] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (a[n - 1] > a[n - 2]) { + cout << "UP" << endl; + return 0; + } else { + if (a[n - 1] != 0) { + cout << "DOWN" << endl; + return 0; + } else { + cout << "UP" << endl; + return 0; + } + } + } +} +int main() { + int n, a, b; + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if ((b - a) >= 2) sum++; + } + cout << sum << endl; + return 0; +} +int main() { + long long s, a, b, c, n, k, p, o, t; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + n = 0; + while (s >= c) { + k = s / c; + p = k / a; + o = k % a; + n += p * (a + b) + o; + s -= (p * a * c + o * c); + } + cout << n << "\n"; + } + return 0; +} +int main() { + int n, R = 0; + cin >> n; + R += 2 * (n / 2); + n /= 2; + R += n; + cout << R << endl; + return 0; +} +int main() { + char c[10][10]; + for (int i = 1; i <= 8; i++) { gets(c[i]); } + int flag = 1; + for (int i = 1; i <= 8; i++) { + for (int j = 0; j < 7; j++) { + if (c[i][j] == c[i][j + 1]) { + flag = 0; + break; + } + } + if (flag == 0) { break; } + } + if (flag) + puts("YES"); + else + puts("NO"); + return 0; +} +set s; +int main() { + s.insert('a'); + s.insert('e'); + s.insert('i'); + s.insert('o'); + s.insert('u'); + for (int i = 1; i < 10; i += 2) { s.insert(i + '0'); } + string k; + int ans = 0; + cin >> k; + int len = k.length(); + for (int i = 0; i < len; i++) { + if (s.count(k[i])) { ans++; } + } + cout << ans << endl; + return 0; +} +inline int read() { + int x = 0, w = 0; + char ch = 0; + while (!isdigit(ch)) { + w |= ch == '-'; + ch = getchar(); + } + while (isdigit(ch)) { + x = (x << 3) + (x << 1) + (ch ^ 48); + ch = getchar(); + } + return w ? -x : x; +} +inline void write(int x) { + if (x < 0) putchar('-'), x = -x; + if (x > 9) write(x / 10); + putchar(x % 10 + '0'); +} +string s1, s2; +string temp1; +string temp2; +int sum1, sum2; +int main() { + getline(cin, s1); + getline(cin, s2); + int len1 = s1.size() - 1; + int len2 = s2.size() - 1; + for (int i = 0; i < len1; i += 2) { + temp1 = ""; + temp2 = ""; + temp1 += s1.at(i); + temp1 += s1.at(i + 1); + temp2 += s2.at(i); + temp2 += s2.at(i + 1); + if (temp1 == "8<") { + if (temp2 == "[]") { + sum1++; + continue; + } + if (temp2 == "()") { + sum2++; + continue; + } + if (temp2 == "8<") { continue; } + } + if (temp1 == "[]") { + if (temp2 == "[]") { continue; } + if (temp2 == "()") { + sum1++; + continue; + } + if (temp2 == "8<") { + sum2++; + continue; + } + } + if (temp1 == "()") { + if (temp2 == "[]") { + sum2++; + continue; + } + if (temp2 == "()") { continue; } + if (temp2 == "8<") { + sum1++; + continue; + } + } + } + if (sum1 > sum2) { puts("TEAM 1 WINS"); } + if (sum1 < sum2) { puts("TEAM 2 WINS"); } + if (sum1 == sum2) { puts("TIE"); } + return 0; +} +const int N = 1e5 + 5; +int ans = 0; +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + for (int i = 1; i <= 100000; i++) { + ans++; + if (b) { + int taka = min(b, k - 1); + a -= (taka + 1) * v; + b -= taka; + } else { + a -= v; + } + if (a <= 0) break; + } + cout << ans << "\n"; + return 0; +} +int c[5], a[5][5005]; +int main() { + int n, x; + while (cin >> n) { + memset(c, 0, sizeof(c)); + for (int i = 1; i <= n; i++) { + cin >> x; + a[x][++c[x]] = i; + } + for (int i = 1; i <= 3; i++) n = min(n, c[i]); + cout << n << endl; + for (int i = 1; i <= n; i++) cout << a[1][i] << " " << a[2][i] << " " << a[3][i] << endl; + } + return 0; +} +void so() { + int len, n; + cin >> len >> n; + string s; + cin >> s; + int a[26] = {0}; + for (int i = 0; i < len; ++i) { a[s[i] - 'a']++; } + for (int i = 0; i < 26; i++) { + if (a[i] > n) { + cout << "NO" << endl; + return; + } + } + cout << "YES" << endl; +} +int main() { + so(); + return 0; +} +int main() { + long long n, rate, price[100005], min = INT_MAX; + long long has = 0; + cin >> n >> rate; + for (int x = 1; x <= n; x++) { + cin >> price[x]; + if (price[x] < min) { min = price[x]; } + } + for (int x = 1; x <= n; x++) { + if ((price[x] - min) % rate == 0) { + price[x] = (price[x] - min) / rate; + has = has + price[x]; + } else { + cout << "-1" << endl; + return 0; + } + } + cout << has << endl; + return 0; +} +int main() { + long long int n, w, k; + cin >> k >> n >> w; + long long int ndmny = k * ((w * (w + 1)) / 2); + if (n <= ndmny) + cout << ndmny - n << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + int x; + cin >> x; + int arr[5] = {1, 2, 3, 4, 5}; + if (x <= 5) { + cout << "1\n"; + return 0; + } else { + if (x % 5 == 0) { + cout << x / 5 << endl; + return 0; + } else { + cout << (x / 5) + 1 << endl; + } + } +} +int main() { + int b, a, n, i, c, d, m, j; + int v[110]; + while (cin >> n >> c >> d) { + m = 0; + for (i = 0; i < 101; i++) v[i] = 0; + for (i = 0; i < n - 1; i++) { + cin >> a >> b; + for (j = a + 1; j <= b; j++) v[j] = -1; + } + for (i = c + 1; i <= d; i++) + if (v[i] == 0) m++; + cout << m << endl; + } + return 0; +} +int main() { + int n, m, i, j, flag = 1; + cin >> n >> m; + int a[m + 1] = {0}; + for (i = 0; i < n; i++) { + int x; + cin >> x; + for (j = 0; j < x; j++) { + int y; + cin >> y; + a[y]++; + } + } + for (i = 1; i <= m; i++) { + if (a[i] == 0) { + flag = 0; + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int a, b; + int sum = 0; + cin >> a >> b; + if (a > b) { + int temp = a; + a = b; + b = temp; + } + while (1) { + int x; + if (b >= a) { + x = b / a; + b = b - (a * x); + sum += x; + if (b <= 0) break; + } + if (a >= b) { + x = a / b; + a = a - (b * x); + sum += x; + if (a <= 0) break; + } + } + cout << sum << endl; + } + return 0; +} +int main() { + int w, h; + cin >> w >> h; + int u1, d1; + cin >> u1 >> d1; + int u2, d2; + cin >> u2 >> d2; + for (int d = h; d >= 0; d--) { + w += d; + if (d == d1) { + w -= u1; + } else if (d == d2) { + w -= u2; + } + w = max(0, w); + } + cout << w << endl; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << "2" << endl; + else + cout << "1" << endl; + return 0; +} +const int MAXN = 1e6 + 6; +long long pow_mod(long long a, long long n, long long mod) { + long long res = 1LL; + a %= mod; + while (n) { + if (n & 1) res = res * a % mod; + a = a * a % mod; + n >>= 1; + } + return res; +} +int main() { + int n, k; + long long sum = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int l, r; + cin >> l >> r; + sum += (r - l + 1); + } + long long t = (sum + k - 1) / k; + cout << t * k - sum << endl; + return 0; +} +long long poww(long long a, long long b) { + long long res = 1; + a %= 1000000007; + assert(b >= 0); + for (; b; b >>= 1) { + if (b & 1) res = res * a % 1000000007; + a = a * a % 1000000007; + } + return res; +} +int main() { + int n; + cin >> n; + int arr[n + 1], i; + for (i = 1; i <= n; i++) { cin >> arr[i]; } + int flag = 0, j; + for (i = 1; i <= n; i++) { + if (arr[arr[arr[i]]] == i) { + flag = 1; + break; + } + } + cout << (flag ? "YES" : "NO") << '\n'; +} +int main() { + int n, p, q, x = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p >> q; + if (q - p >= 2) x++; + } + cout << x << endl; + return 0; +} +unsigned long long fact(int n) { + unsigned long long ans = 1; + while (n >= 1) { + ans *= n; + n--; + } + return ans; +} +int main() { + int a, b; + cin >> a >> b; + cout << fact(min(a, b)) << endl; + return 0; +} +int n; +int main() { + string s; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> s; + if (s.length() > 10) + cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; + else + cout << s << endl; + } + return 0; +} +map mp; +int main() { + mp.clear(); + int n, ans = 0, x; + cin >> n; + while (n--) { + cin >> x; + if (x && !mp[x]) { + ans++; + mp[x] = 1; + } + } + cout << ans << endl; +} +void files() { + freopen("input.txt", "r", stdin); + freopen("output.txt", "w", stdout); +} +char ax[10001]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> ax; + for (int j = 0; j < m; j++) { + if (ax[j] == '.') { + if ((i + j) & 1) + ax[j] = 'W'; + else + ax[j] = 'B'; + } + } + cout << ax << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int q = 0; + int qq = 1; + vector vec(n); + for (int i = 0; i < n; i++) cin >> vec[i]; + int k = *min_element(vec.begin(), vec.end()); + for (int i = 0; i < n; i++) + if (vec[i] == k) { + q = i; + for (int i = q + 1; i < n; i++) { + if (vec[i] != k) + qq = 1; + else { + cout << "Still Rozdil" << endl; + qq = 0; + break; + } + } + break; + } + if (qq != 0) cout << q + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + map m; + cin >> x; + int u; + while (x--) { + cin >> u; + m[u]++; + } + cin >> x; + while (x--) { + cin >> u; + m[u]++; + } + if (m.size() >= n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +int main() { + int a; + while (cin >> a) { cout << (a / 2) + 1 << endl; } + return 0; +} +long long n, m, a, b, x, cnt, ans; +deque V; +map mp; +long long arr[1000001]; +int main() { + cin >> x >> a >> b; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) { + if (arr[i] > a && arr[i] < b) cnt++; + } + cout << cnt << endl; +} +int main() { + string s, t; + cin >> s >> t; + int c = 0; + for (int i = 0; i < t.length(); i++) { + if (s[c] == t[i]) c++; + } + c++; + cout << c << endl; + return 0; +} +int main() { + int a[3][3], b[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { b[i][j] = 1; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cin >> a[i][j]; + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (a[i][j] % 2 != 0) { + if (b[i][j] == 0) + b[i][j] = 1; + else if (b[i][j] == 1) + b[i][j] = 0; + if (i - 1 >= 0 && i - 1 < 3) { + if (b[i - 1][j] == 0) + b[i - 1][j] = 1; + else if (b[i - 1][j] == 1) + b[i - 1][j] = 0; + } + if (j - 1 >= 0 && j - 1 < 3) { + if (b[i][j - 1] == 0) + b[i][j - 1] = 1; + else if (b[i][j - 1] == 1) + b[i][j - 1] = 0; + } + if (j + 1 >= 0 && j + 1 < 3) { + if (b[i][j + 1] == 0) + b[i][j + 1] = 1; + else if (b[i][j + 1] == 1) + b[i][j + 1] = 0; + } + if (i + 1 >= 0 && i + 1 < 3) { + if (b[i + 1][j] == 0) + b[i + 1][j] = 1; + else if (b[i + 1][j] == 1) + b[i + 1][j] = 0; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << b[i][j]; + cout << endl; + } + return 0; +} +long long a[2001]; +long long b[2001]; +set s; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 0; i < n; i++) { + s.insert(a[i]); + s.insert(b[i]); + } + int cnt = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int temp = a[i] ^ b[j]; + if (s.find(temp) != s.end()) { cnt++; } + } + } + if (cnt % 2 == 0) { + cout << "Karen" << endl; + } else { + cout << "Koyomi" << endl; + } +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long num1 = 0, num2 = 0, num3 = n; + long long div = k + 1; + if (n / 2 < div) { + cout << 0 << " " << 0 << " " << n << endl; + continue; + } + long long maxcnt = n / 2; + long long ans = maxcnt / div; + num1 = ans; + num2 = ans * k; + num3 = n - num1 - num2; + cout << num1 << " " << num2 << " " << num3 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + vector v; + int a; + for (int i = 0; i < n - 1; i++) { + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + int count = 0; + while (1) { + if (x > v[0]) + break; + else { + count++; + x++; + v[0]--; + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + } + } + cout << count << endl; + return 0; +} +int main() { + long long n; + while (cin >> n) { cout << 25 << endl; } + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int x = min(n - a, b + 1); + cout << x << endl; + return 0; +} +const int mod = 1e9 + 9; +int add(int a, int b) { + return a + b >= mod ? a + b - mod : a + b; +} +int sub(int a, int b) { + return a - b < 0 ? a - b + mod : a - b; +} +int mul(int a, int b) { + return a * 1ll * b % mod; +} +int fpow(int a, int n) { + int ret = 1; + for (; n; n >>= 1) { + if (n & 1) ret = mul(ret, a); + a = mul(a, a); + } + return ret; +} +int main() { + int n, m; + cin >> n >> m; + int k = fpow(2, m), ans = 1; + for (int i = 0; i < n; ++i) { + k = sub(k, 1); + ans = mul(ans, k); + } + cout << ans << endl; + return 0; +} +int main() { + for (string s; cin >> s;) + if (s != "WBWBWBWB" && s != "BWBWBWBW") return cout << "NO\n", 0; + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - (n / 2)) + abs(j - (n / 2)) <= (n / 2)) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + long long int v[n]; + for (int i = 0; i < n; i++) cin >> v[i]; + long long int ans = LLONG_MAX; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(ans, (v[i + 1] - v[i]) / 2); } + } + if (ans == LLONG_MAX) { + cout << "-1\n"; + } else { + cout << ans << "\n"; + } + return 0; +} +int n1, n2, k, m; +int main() { + int v1, v2, x; + cin >> n1 >> n2; + cin >> k >> m; + for (int i = 0; i < n1; i++) { + cin >> x; + if (i == k - 1) { v1 = x; } + } + for (int i = 0; i < n2; i++) { + cin >> x; + if (i == n2 - m) { v2 = x; } + } + if (v1 < v2) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int m, k; +int d[300300], second[300300]; +int main() { + cin >> m >> k; + int S = 0; + for (int i = 1; i <= m; ++i) cin >> d[i], S += d[i]; + for (int i = 1; i <= m; ++i) cin >> second[i]; + int ANS = 0; + int res = second[1]; + int pos = 1; + int n = m + 1; + while (pos <= n) { + int w = -1; + for (int j = pos + 1; j <= n - 1; ++j) { + if (second[j] > second[pos]) { + w = j; + break; + } + } + int need = 0; + if (w == -1) { + need = res; + int ds = 0, ss = 0; + for (int j = pos; j <= n - 1; ++j) { + ds += d[j]; + if (j >= pos + 1) ss += second[j]; + need = max(need, ds - ss); + } + need = need - res; + int CUR = 0; + CUR += (need / second[pos]) * k; + if (need % second[pos] != 0) CUR += k; + ANS += CUR; + break; + } + need = res; + int ds = 0, ss = 0, q = 0; + for (int j = pos; j <= w - 1; ++j) { + ds += d[j]; + q -= d[j]; + if (j >= pos + 1) q += second[j]; + if (j >= pos + 1) ss += second[j]; + need = max(need, ds - ss); + } + need = need - res; + int CUR = 0; + CUR += (need / second[pos]) * k; + if (need % second[pos] != 0) CUR += k; + ANS += CUR; + res += CUR * second[pos] / k; + res += q; + res += second[w]; + pos = w; + } + cout << ANS + S << "\n"; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int max1 = 0; + if (a + b * c > max1) { max1 = a + b * c; } + if (a * (b + c) > max1) { max1 = a * (b + c); } + if (a * b * c > max1) { max1 = a * b * c; } + if ((a + b) * c > max1) { max1 = (a + b) * c; } + if (a + b + c > max1) { max1 = a + b + c; } + cout << max1 << endl; +} +int n, k; +char s[999]; +int ans[28]; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> s[i], ans[s[i] - 'a']++; + if (ans[s[i] - 'a'] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int m; + cin >> m; + int arr1[m]; + for (int i = 0; i < m; i++) { cin >> arr1[i]; } + int n; + cin >> n; + int arr2[n]; + for (int i = 0; i < n; i++) { cin >> arr2[i]; } + int max = 0; + int count = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (arr2[j] % arr1[i] == 0) { + if (arr2[j] / arr1[i] == max) { + count++; + } else if (arr2[j] / arr1[i] > max) { + max = arr2[j] / arr1[i]; + count = 1; + } + } + } + } + cout << count << endl; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(min(k * l / nl, c * d), p / np) / n << endl; + return 0; +} +int need(int a) { + int b = 0; + for (int i = 1; i <= a; i++) { b += i; } + return b; +} +int main() { + int a; + cin >> a; + int i = 0; + while (a >= need(i)) { + a -= need(i); + i++; + } + cout << i - 1 << endl; +} +int main() { + double A, B, C; + int a, b, c; + cin >> a >> b >> c; + A = sqrt(a * b / c); + B = sqrt(b * c / a); + C = sqrt(c * a / b); + int count = (A + B + C) * 4; + cout << count << endl; +} +set s; +int main() { + int n, num; + cin >> n; + while (n--) { + cin >> num; + if (num) s.insert(num); + } + cout << s.size() << endl; +} +int main() { + int n, i, j, k; + cin >> n; + int a, row[n], clm[n]; + for (i = 0; i < n; i++) { + row[i] = 0; + clm[i] = 0; + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + cin >> a; + row[i] += a; + clm[j] += a; + } + } + k = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (clm[i] > row[j]) k++; + } + } + cout << k << endl; + return 0; +} +const int M = 105; +int a[M]; +int main() { + int n; + cin >> n; + int Min = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + int sum = 0; + for (int j = 1; j <= n; j++) { sum += (abs(i - j) - 2 + j + i) * a[j] * 2; } + Min = min(sum, Min); + } + cout << Min << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long k = 3 * (n / 2); + cout << k << endl; + return 0; +} +string s[30003]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + int len = s[0].length(); + int ans = 0; + for (int i = 0; i < len; i++) { + char c = s[0][i]; + for (int j = 0; j < n; j++) { + if (c != s[j][i]) { + cout << ans << endl; + return 0; + } + } + ans++; + } + return 0; +} +int main() { + int tot = 0, i, j, k; + char s[2333]; + cin >> s; + for (i = 0; i < strlen(s); i++) + for (j = i + 1; j < strlen(s); j++) + for (k = j + 1; k < strlen(s); k++) + if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') tot++; + cout << tot << endl; + return 0; +} +bool vis[35] = {0}; +int main() { + vector q; + int n, sum = 0; + string s; + cin >> n >> s; + for (int i = 0; i < s.size(); i++) + if (!vis[s[i] - 'a']) vis[s[i] - 'a'] = 1, sum++, q.push_back(i); + if (sum < n) + cout << "NO" << endl; + else { + cout << "YES" << endl; + for (int j = 0; j < n; j++) { + int k; + if (j != n - 1) { + for (k = q[j]; k < q[j + 1]; k++) cout << s[k]; + cout << endl; + } else { + for (k = q[j]; k < s.size(); k++) cout << s[k]; + cout << endl; + } + } + } + return 0; +} +const int mod = 998244353; +long long qpow(long long x, long long y) { + long long s = 1; + while (y) { + if (y & 1) s = s * x % mod; + x = x * x % mod; + y >>= 1; + } + return s; +} +inline long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); + return x * f; +} +long long inve(long long x) { + return x == 1 ? 1 : (mod - mod / x) * inve(mod % x) % mod; +} +const int N = 1e7 + 5; +int vis[N], prime[N]; +int pri_num; +void init() { + for (int i = 2; i < N; i++) + if (!vis[i]) { + prime[pri_num++] = i; + for (int j = i; j < N; j += i) vis[j] = 1; + } +} +int main() { + int t; + for (cin >> t; t; t--) { + int n; + string s; + cin >> n >> s; + int flag = 1; + int l = 0, r = n - 1; + while (l < r) { + if (s[l] == s[r] || abs(s[l] - s[r]) == 2) + ; + else { + flag = 0; + break; + } + l++, r--; + } + if (flag) + puts("YES"); + else + puts("NO"); + } + return 0; +} +int main() { + int n, zero = 0; + cin >> n; + map mp; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp != 0) { mp[temp]++; } + } + int sum = 0, count = 0; + cout << mp.size() << endl; + return 0; +} +int main() { + string a; + cin >> a; + for (int i = 0; i < a.length(); ++i) { + if (a.substr(i, 3).compare("144") == 0) { + i += 2; + } else if (a.substr(i, 2).compare("14") == 0) { + i += 1; + } else if (a.substr(i, 1).compare("1") == 0) + continue; + else { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +long double k, n, s, p; +int calc(long long pack) { + long long sheets = pack * p; + return (floor(sheets / k)) * s >= n; +} +int main() { + cin >> k >> n >> s >> p; + long long l = 1, r = INT_MAX; + for (int i = 0; i < 200; i++) { + long long mid = (l + r) / 2; + if (calc(mid)) { + r = mid; + } else { + l = mid + 1; + } + } + cout << r << endl; +} +int main() { + int n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + int a[n], sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int countersum = 0, min = sum * r + (n - 1) * qr, ci = 0, cn = n; + for (int i = 0; i < n; i++) { + countersum += a[i]; + sum -= a[i]; + ci++; + cn--; + int ans = sum * r + countersum * l; + if (ci > cn) + ans += (ci - cn - 1) * ql; + else if (ci < cn) + ans += (cn - ci - 1) * qr; + if (ans < min) min = ans; + } + cout << min << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int X = 2, R = 1; + while (n--) { + long long int LCM = R * (R + 1); + cout << LCM / R * LCM - X / R << "\n"; + X = LCM; + ++R; + } + cin >> n; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; +int main() { + int b[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) cin >> b[i][j]; + int ans[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) ans[i][j] = 1; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (b[i][j] % 2 == 1) { + ans[i][j] = 1 - ans[i][j]; + for (int ii = 0; ii < 4; ii++) { + int x = dir[ii][0] + i, y = dir[ii][1] + j; + if (x >= 0 && x < 3 && y >= 0 && y < 3) { ans[x][y] = 1 - ans[x][y]; } + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << ans[i][j]; } + cout << endl; + } + return 0; +} +int main() { + string s, c, ss; + s.clear(); + c.clear(); + ss.clear(); + cin >> s; + cin >> c; + ss[0] = s[0]; + int flag = 1; + for (int i = 1; i < s.size(); i++) { + if (s[i] < c[0]) + ss[flag++] = s[i]; + else + break; + } + ss[flag++] = c[0]; + ss[flag] = '\0'; + for (int i = 0; i < flag; i++) cout << ss[i]; + cout << endl; +} +int main() { + int x, y, a, b, p; + cin >> x >> y >> a >> b; + p = __gcd(x, y); + x = x * y; + x = x / p; + if (a % x == 0) { + a /= x; + a--; + } else { + a = a / x; + } + b = b / x; + cout << b - a << endl; + return 0; +} +int main() { + int n, a[100], b[100]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) b[i] = a[i]; + int max = a[n - 1], max1; + for (int i = 1; i < (n - 1); i++) { + max1 = 0; + for (int k = 0; k < n; k++) a[k] = b[k]; + for (int j = 1; j < (n - 1); j++) { + if (j >= i) a[j] = a[j + 1]; + } + for (int j = 0; j < (n - 1); j++) { + int x = a[j + 1] - a[j]; + if (x > max1 && x != 0) max1 = x; + } + if (max1 < max) max = max1; + } + cout << max << endl; +} +char a[1000][50]; +int main() { + int flag = 1; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (!(i & 1)) { + if (flag == 1) { + if (j != m) + cout << "."; + else { + cout << "#" << endl; + flag = 0; + } + } else if (j == 1) { + cout << "#"; + } else { + if (j != m) cout << "."; + if (j == m) { + cout << "." << endl; + flag = 1; + } + } + } else if (j != m) + cout << "#"; + else + cout << "#" << endl; + } + } +} +int n, m; +vector s; +int checktop() { + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] != '.') return i; + } + } + return -1; +} +int checkbottom() { + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (s[i][j] != '.') return i; + } + } + return -1; +} +int checkleft() { + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (s[j][i] != '.') return i; + } + } +} +int checkright() { + for (int i = m - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (s[j][i] != '.') return i; + } + } +} +int main() { + cin >> n >> m; + s.resize(n); + for (int i = 0; i < n; i++) { cin >> s[i]; } + int left = checkleft(); + int right = checkright(); + int top = checktop(); + int bottom = checkbottom(); + for (int i = top; i <= bottom; i++) { cout << s[i].substr(left, right - left + 1) << endl; } + return 0; +} +int N; +long long S, A, B, C; +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + cin >> S >> A >> B >> C; + cout << S / C + B * (S / (A * C)) << '\n'; + } + return 0; +} +int main() { + long long i, j, a, b, c, d, e, f, g, n; + string s; + cin >> s; + j = s.find("."); + if (s.at(j - 1) == '9') { + cout << "GOTO Vasilisa." << endl; + return 0; + } else { + if (s.at(j + 1) > '4') { s.at(j - 1) = s.at(j - 1) + 1; } + } + s.erase(j); + cout << s << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int cnt = 0; + for (int i = 0; i <= n && i <= m; i++) { + int b = n - i * i; + if (b >= 0 && i + b * b == m) cnt++; + } + cout << cnt << endl; + return 0; +} +long long int power(long long int x, long long int y) { + long long int temp; + if (y == 0) return 1; + temp = power(x, y / 2); + if (y % 2 == 0) + return temp * temp; + else { + if (y > 0) + return x * temp * temp; + else + return (temp * temp) / x; + } +} +bool prime[10000000]; +void sieve() { + memset(prime, true, sizeof(prime)); + prime[0] = prime[1] = false; + for (long long int p = 2; p * p <= 10000000; p++) { + if (prime[p] == true) { + for (long long int i = p * 2; i <= 10000000; i += p) prime[i] = false; + } + } +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + long long int n; + cin >> n; + long long int a[n]; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + long long int g; + g = __gcd(a[0], a[1]); + for (long long int i = 0; i < n; i++) { g = __gcd(g, a[i]); } + for (long long int i = 0; i < n; i++) { a[i] /= g; } + long long int mx = -1; + for (long long int i = 0; i < n; i++) { + if (a[i] > mx) { mx = a[i]; } + } + if ((mx - n) % 2 == 0) { + cout << "Bob" << endl; + } else { + cout << "Alice" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int k = 0; + if (i < (n / 2) + 1) + k = i; + else + k = n - 1 - i; + for (int j = 1; j <= n; j++) { + if (abs(j - (n / 2) - 1) <= k) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } +} +char a[2000100]; +int b[2000100]; +int main() { + int n; + while (cin >> n) { + cin >> a; + int t = 0x7fffffff, flag = 0; + cin >> b[0]; + for (int i = 1; i < n; i++) { + cin >> b[i]; + if (a[i - 1] == 'R' && a[i] == 'L') { + t = min(t, abs(b[i] - b[i - 1]) / 2); + flag = 1; + } + } + if (flag) + cout << t << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int ans = 0; + map p; + for (int i = 0; i < n; i++) { + int val; + cin >> val; + p[val]++; + ans = max(p[val], ans); + } + cout << ans << endl; + } + return 0; +} +int main() { + int t, a; + cin >> t; + while (t--) { + cin >> a; + if (360 % (180 - a) == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int n, k, lucky = 0, digit; + char c[10000]; + cin >> n >> k; + for (int i = 0; i < n; i++) { + digit = 0; + cin >> c; + int l = strlen(c); + for (int j = 0; j < l; j++) { + if (c[j] == '4' || c[j] == '7') digit++; + } + if (digit <= k) lucky++; + } + cout << lucky << endl; +} +stack st; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) + if (!st.empty() && st.top() == s[i]) + st.pop(); + else + st.push(s[i]); + s = ""; + while (!st.empty()) { + s += st.top(); + st.pop(); + } + for (int i = s.length() - 1; i >= 0; i--) cout << s[i]; + cout << endl; + return 0; +} +const int maxn = 100010; +int n, m; +int a[maxn]; +int main() { + string x; + int n, d; + cin >> n >> d; + int cnt = 0; + int imax = -1; + for (int k = 1; k <= d; ++k) { + cin >> x; + for (int i = 0; i < n; ++i) { + if (x[i] == '0') { + cnt++; + break; + } + if (i == n - 1) { + imax = max(imax, cnt); + cnt = 0; + } + } + } + imax = max(imax, cnt); + cout << imax << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = n / 100; + n %= 100; + sum += n / 20; + n %= 20; + sum += n / 10; + n %= 10; + sum += n / 5; + n %= 5; + sum += n; + cout << sum << endl; + return 0; +} +int main() { + string str; + cin >> str; + int ans = 0; + for (int i = 0; i < str.size(); i++) { + if (str[i] == ')') continue; + int zuo = 0, wen = 0; + for (int j = i; j < str.size(); j++) { + if (str[j] == '(') + zuo++; + else if (str[j] == ')') + zuo--; + else + zuo--, wen++; + if (zuo == 0) + ans++; + else if (zuo < 0) { + if (wen > 0) + zuo += 2, wen--; + else + break; + } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum, i, b; + sum = b = i = 1; + for (;;) { + if (sum == n) { + cout << i << endl; + break; + } else { + if (sum > n) { + cout << (i - 1) << endl; + break; + } else { + i++; + b += i; + sum += b; + } + } + } + return 0; +} +long long a, b, c, s; +void solve() { + cin >> a >> b >> c; + s += (long long)sqrt(a * b / c); + s += (long long)sqrt(b * c / a); + s += (long long)sqrt(a * c / b); + cout << s * 4 << endl; +} +void prep() {} +int main() { + long long t = 1; + prep(); + cout << fixed << setprecision(12); + while (t--) solve(); + return 0; +} +int a[605]; +int main() { + int n, num; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> num; + a[num]++; + } + int ans = 0; + for (int i = 1; i < 603; i++) { + if (a[i]) ans++; + } + cout << ans << endl; +} +const int maxn = 1e4 + 5; +int num[maxn] = {0}; +int n, ans = 10000000; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> num[i]; + for (int i = 1; i <= n; i++) { + int cnt = 0; + for (int j = 1; j <= n; j++) cnt += 2 * num[j] * (abs(i - j) + abs(j - 1) + abs(1 - i)); + ans = min(cnt, ans); + } + cout << ans << endl; + return 0; +} +priority_queue q; +long long n, my, tmp; +int main() { + cin >> n >> my; + for (long long i = 1; i < n; i++) { + cin >> tmp; + q.push(tmp); + } + long long ans = 0; + while (my <= q.top()) { + tmp = q.top(); + q.pop(); + my++; + tmp--; + ans++; + q.push(tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector upper; + vector lower; + int rotate = 0; + int sum_l = 0, sum_u = 0; + for (int i = 0; i < n; i++) { + int u, l; + cin >> u >> l; + if ((u + l) % 2 == 1) { rotate = 1; } + sum_l += l; + sum_u += u; + } + if (sum_l % 2 == 0 && sum_u % 2 == 0) { + cout << "0" << endl; + } else { + if (sum_l % 2 == 1 && sum_u % 2 == 1 && rotate) { + cout << "1" << endl; + } else { + cout << "-1" << endl; + } + } + return 0; +} +const long long MAXX = 2 * (1000000 + 10); +const double PI = 3.14159265358979323846; +const long long mod = 1000000007; +int a[80]; +int main() { + for (int i = 0; i < 70; i++) { a[i] = i; } + int sum = 0; + string s; + cin >> s; + sum += min(abs(a[0] - a[s[0] - 'a']), abs(a[26] - a[s[0] - 'a'])); + int len = s.length(); + for (int i = 0; i < len - 1; i++) { + char s1 = max(s[i], s[i + 1]); + char s2 = min(s[i], s[i + 1]); + int l1 = abs(a[s1 - 'a'] - a[s2 - 'a']); + int l2 = abs(a[s2 - 'a' + 26] - a[s1 - 'a']); + sum += min(l1, l2); + } + cout << sum << endl; + return 0; +} +int a[50], b[50]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i] == b[j]) ans++; + } + } + cout << ans << endl; +} +int main() { + int n = 8; + while (n--) { + string s; + cin >> s; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 != 0) { + cout << 1 << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + int long long l; + char r, k = 'A', j = 'A'; + char g[301][301]; + cin >> l; + for (int i = 0; i < l; i++) { + for (int y = 0; y < l; y++) { + cin >> r; + g[i][y] = r; + if (k == 'A') k = r; + if (r != k && j == 'A') j = r; + } + } + bool acc = true; + int e; + for (int u = 0; u < l; u++) { + for (e = 0; e < l; e++) { + if ((e == l - 1 - u || e == u) && g[u][e] != k) { + acc = false; + break; + } else if ((e != l - 1 - u && e != u) && g[u][e] != j) { + acc = false; + break; + } + } + if (!acc) break; + } + if (acc) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int month, firstDay; + cin >> month >> firstDay; + int dayAmount = months[month - 1] + firstDay - 1; + if (!(dayAmount % 7)) + cout << dayAmount / 7 << endl; + else + cout << dayAmount / 7 + 1 << endl; + return 0; +} +int main() { + int a; + cin >> a; + int res = 0; + for (int i = 0; i < 32; i++) { + int mask = 1 << i; + if ((a & mask) != 0) { res++; } + } + cout << res << endl; + return 0; +} +int main() { + int n, a[100]; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + for (int i = 0; i < n; i++) { + int t = 0; + for (int j = i; j < n; j++) { + t ^= a[j]; + ans = max(ans, t); + } + } + cout << ans << endl; +} +const int N = 50 + 10, INF = 1e9 + 7; +int n, ans, d; +int main() { + cin >> n >> d; + int k = 0; + for (int i = 0; i < d; i++) { + bool win = false; + string second; + cin >> second; + for (int i = 0; i < n; i++) + if (second[i] == '0') win = 1; + if (win) + k++; + else + ans = max(ans, k), k = 0; + } + cout << max(ans, k) << '\n'; + return 0; +} +int main() { + int p, n; + cin >> p >> n; + int i = 0; + int x; + int hash[305] = {0}; + for (i = 0; i < n; i++) { + cin >> x; + x %= p; + if (hash[x]) { + cout << i + 1 << endl; + return 0; + } + hash[x]++; + } + cout << -1 << endl; + return 0; +} +int main() { + int x, y; + cin >> x; + vector v(x + 1, 0); + for (int j = 1; j < x; j++) { + cin >> y; + v[y] = 1; + } + for (int k = 1; k <= x; k++) { + if (!v[k]) { + cout << k << endl; + break; + } + } + return 0; +} +const long long int mod = 1000000007; +int main() { + long long int n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + long long int w[n + 1] = {0}; + for (int i = 1; i <= n; i++) { + cin >> w[i]; + w[i] += w[i - 1]; + } + long long int ans = LLONG_MAX; + for (long long int taken = 0; taken <= n; taken++) { + long long int left = taken; + long long int right = n - taken; + long long int suml = w[left]; + long long int sumr = w[n] - w[left]; + long long int curans = l * suml + r * sumr; + if (left < right) { + curans += qr * (right - left - 1); + } else if (left > right) { + curans += ql * (left - right - 1); + } + ans = min(ans, curans); + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int sum = k, ans = 0; + for (int i = 1; i <= n; i++) { + sum += 5 * i; + ans = i; + if (sum > 240) { + ans = i - 1; + break; + } + } + cout << ans << endl; +} +void solve(string str, int k) { + int cnt[26]; + memset(cnt, 0, sizeof(cnt)); + for (int i = 0; i < str.length(); i++) cnt[str[i] - 'a']++; + string s1; + int i = 0; + for (; i < 26; i++) { + if (cnt[i] % k != 0) + break; + else { + s1.append(cnt[i] / k, 'a' + i); + } + } + if (i == 26) { + while (k--) { cout << s1; } + cout << endl; + } else { + cout << "-1" << endl; + } +} +int main() { + int k; + cin >> k; + string str; + cin >> str; + solve(str, k); + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n - 1], sum = 0, m = 1000; + cin >> a[0]; + for (int i = 1; i < n; i++) { + cin >> a[i]; + b[i] = a[i] - a[i - 1]; + sum = max(sum, b[i]); + } + for (int i = 2; i < n; i++) m = max(min(m, b[i] + b[i - 1]), sum); + cout << m << endl; + return 0; +} +const int inf = (long long)1e9; +const int mod = inf + 7; +const double pi = acos(-1.0); +int n, m; +int a[55][55]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) cin >> a[i][j]; + int ans = 4; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= m; ++j) { + if (a[i][j] != 1) continue; + if (i == 1 || i == n) { + cout << 2 << "\n"; + return 0; + } + if (j == 1 || j == m) { + cout << 2 << "\n"; + return 0; + } + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int a[1000], sum1, sum = 0; + int i, j, k; + for (i = 0; i < 6; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + for (i = 0; i < 4; i++) { + for (j = i + 1; j < 5; j++) { + for (k = j + 1; k < 6; k++) { + sum1 = a[i] + a[j] + a[k]; + if (sum1 == sum - sum1) { + cout << "YES" << '\n'; + exit(0); + } + } + } + } + cout << "NO" << '\n'; + return 0; +} +int main() { + int a[6], i, j = 1, k, sum = 0, flg = 0, b = 0; + for (i = 0; i < 6; i++) { + cin >> b; + if (0 <= b && b <= 1000) { a[i] = b; } + } + for (i = 0; i < 6; i++) { sum += a[i]; } + if (sum % 2 == 0) { + for (i = 0; i < 4; i++) { + for (j = i + 1; j < 5; j++) { + for (k = j + 1; k < 6; k++) { + if (a[i] + a[j] + a[k] == (sum / 2)) { + flg = 1; + break; + } + } + if (flg == 1) { break; } + } + if (flg == 1) { break; } + } + if (flg == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else + cout << "NO" << endl; +} +int main() { + int n, i; + long long s, a, b, c, son[101]; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> s >> a >> b >> c; + son[i] = s / c / a * (a + b) + s / c % a; + } + for (i = 1; i <= n; i++) { cout << son[i] << "\n"; } + return 0; +} +int main() { + long long n, x, y; + cin >> n >> x >> y; + string s; + cin >> s; + int len = s.length(); + int sum = 0; + for (int i = 0; i < len - 1; i++) { + if (s[i] == '0' && s[i + 1] == '1') sum++; + } + if (s[len - 1] == '0') sum++; + long long res = 0; + if (sum != 0) { + if (x < y) { + res = (sum - 1) * x + y; + } else { + res = sum * y; + } + } + cout << res << endl; + return 0; +} +const long long inf = 0x3f3f3f3f; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + int t = 0; + while (n) { + n--; + ans++; + t++; + if (t % m == 0) { n++; } + } + cout << ans << endl; + return 0; +} +const long long mod = 1e9 + 1; +const int N = 1e6 + 5; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long pwr(long long x, long long y); +bool isprime(long long x); +int main() { + int n, m; + cin >> n >> m; + int sum = n * (n + 1) / 2; + m = m % sum; + for (int i = 1; i < n + 1; i++) { + if (m >= i) { + m -= i; + } else { + cout << m << endl; + return 0; + } + } + cout << 0 << endl; + return 0; +} +long long pwr(long long x, long long y) { + long long ans = 1; + x = x % mod; + while (y > 0) { + if (y & 1) ans = (x * ans) % mod; + x = (x * x) % mod; + y = y / 2; + } + return ans; +} +bool isprime(long long x) { + if (x < 2) return false; + if (x < 4) return true; + if (x % 2 == 0 || x % 3 == 0) return false; + for (long long i = 5; i * i <= x; i += 6) { + if (x % i == 0 || x % (i + 2) == 0) return false; + } + return true; +} +bool fun1(char s) { + if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') + return true; + else + return false; +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'n') continue; + if (!fun1(s[i]) && !fun1(s[i + 1])) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +const int N = 1e5 + 50; +const int oo = 1e9; +const int mod = 1e9 + 7; +string a[2001], b[201], f1[2001], f2[2001]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + for (int i = 0; i + m <= n; i++) { + f1[i] = ""; + for (int j = 0; j < m; j++) f1[i] += a[i + j]; + } + for (int i = 0; i + m <= n; i++) { + f2[i] = ""; + for (int j = 0; j < m; j++) { f2[i] += b[j].substr(i, m); } + } + for (int i = 0; i + m <= n; i++) { + for (int j = 0; j + m <= n; j++) { + if (f1[i] == f2[j]) { + cout << i + 1 << ' ' << j + 1 << endl; + return 0; + } + } + } +} +int main() { + int t; + cin >> t; + while (t) { + int a; + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + t--; + } + return 0; +} +set s; +int main() { + int n; + int x; + cin >> x; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + s.insert(a); + } + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + s.insert(a); + } + if (s.size() == x) { + cout << "I become the guy." << endl; + } else { + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int main() { + long long int n, m, k; + cin >> n >> m >> k; + m--; + long long int ar[n]; + for (long long int i = 0; i < n; ++i) cin >> ar[i]; + long long int c1 = 0, c2 = 0, f1 = 0, f2 = 0; + for (long long int i = m + 1; i < n; ++i) { + if ((ar[i] <= k) && (ar[i] != 0)) { + c1 += 10; + f1 = 1; + break; + } + c1 += 10; + } + for (long long int i = m - 1; i >= 0; --i) { + if ((ar[i] <= k) && (ar[i] != 0)) { + c2 += 10; + f2 = 1; + break; + } + c2 += 10; + } + if (f1 == 0) { + cout << c2 << endl; + } else if (f2 == 0) { + cout << c1 << endl; + } else { + c1 = min(c1, c2); + cout << c1 << endl; + } + return 0; +} +int main() { + int n; + int a1, a2, b1, b2, c1, c2; + cin >> n; + cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; + if (n > a1 + b1 + c1) { + n -= a1 + b1 + c1; + if (n > a2 - a1) { + n -= a2 - a1; + if (n > b2 - b1) { + n -= b2 - b1; + if (n > c2 - c1) { + cout << a2 << " " << b2 << " " << c2 << endl; + return 0; + } + cout << a2 << " " << b2 << " " << n + c1 << endl; + return 0; + } + cout << a2 << " " << n + b1 << " " << c1 << endl; + return 0; + } + cout << n + a1 << " " << b1 << " " << c1 << endl; + return 0; + } else { + if (n > a1) { + n -= a1; + if (n > b1) { + n -= b1; + cout << a1 << " " << b1 << " " << n << endl; + return 0; + } + cout << a1 << " " << n << " " + << "0" << endl; + return 0; + } + cout << n << " " + << "0" + << " " + << "0" << endl; + return 0; + } +} +int main() { + long long int n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int i, j = 1, k = 2, even = 0, odd = 0, n, x, y, a[56]; + cin >> n; + for (i = 0; i < n / 2; i++) { cin >> a[i]; } + sort(a, a + n / 2); + for (i = 0; i < n / 2; i++) { + x = j - a[i]; + if (x < 0) x = -x; + odd += x; + y = k - a[i]; + if (y < 0) y = -y; + even += y; + j += 2; + k += 2; + } + if (odd > even) + cout << even << endl; + else + cout << odd << endl; + return 0; +} +long long n; +int main() { + int n, k, ans = 0; + long long x; + cin >> n >> k; + for (int i = 0; i < n; i++) { + set s; + cin >> x; + while (x) { + if (x % 10 <= k) { s.insert(x % 10); } + x /= 10; + } + if (s.size() == k + 1) ans++; + } + cout << ans << endl; +} +set ta; +int main() { + ta.clear(); + int n, ans = -1; + cin >> n; + for (int i = 1; i <= 2 * n; i++) { + int tmp; + cin >> tmp; + if (ta.count(tmp)) { + ta.erase(tmp); + } else { + ta.insert(tmp); + tmp = ta.size(); + ans = max(ans, tmp); + } + } + cout << ans << endl; + return 0; +} +long long ara[200009]; +long long ara2[200009]; +int main() { + long long i, n; + cin >> n; + for (i = 0; i < n; i++) cin >> ara[i]; + sort(ara, ara + n); + for (i = 1; i < n; i++) { ara2[i] = ara[i] - ara[i - 1]; } + long long mn = *min_element(ara2 + 1, ara2 + n); + long long cnt = 0; + for (i = 1; i < n; i++) + if (ara2[i] == mn) cnt++; + cout << mn << " " << cnt << endl; + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a != b) + cout << "1" << endl; + else + cout << a << endl; + return 0; +} +int main() { + char str[102]; + cin >> str; + int len = strlen(str); + int lowerCount = 0, upperCount = 0; + int j = 0; + while (j < len) { + if (((int)str[j] >= (int)'A') && ((int)str[j] <= (int)'Z')) + upperCount++; + else + lowerCount++; + j++; + } + if (upperCount > lowerCount) { + j = 0; + while (j < len) { + if (((int)str[j] >= (int)'a') && ((int)str[j] <= (int)'z')) { str[j] = (char)((int)str[j] - 32); } + j++; + } + } else { + j = 0; + while (j < len) { + if (((int)str[j] >= (int)'A') && ((int)str[j] <= (int)'Z')) { str[j] = (char)((int)str[j] + 32); } + j++; + } + } + cout << str << endl; +} +int main() { + string xay; + cin >> xay; + string result1 = ""; + string result2 = ""; + string result3 = ""; + int i = 0; + while (i < xay.length()) { + if (xay[i] == '1') { + result1.insert(result1.length(), "1"); + } else if (xay[i] == '2') { + result2.insert(result2.length(), "2"); + } else if (xay[i] == '3') { + result3.insert(result3.length(), "3"); + } + i++; + } + string result = ""; + result = result1 + result2 + result3; + for (int i = 0; i < result.length(); i++) { + if (i == result.length() - 1) { + cout << result[i]; + } else { + cout << result[i] << "+"; + } + } + cout << endl; +} +int n, x1 = 0, x2 = 0, m, c; +int main() { + cin >> n; + while (n--) { + cin >> m >> c; + if (m > c) { + x2++; + } else if (m < c) { + x1++; + } + } + if (x2 > x1) { + cout << "Mishka" << endl; + } else if (x2 < x1) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + long long int t; + cin >> t; + while (t--) { + long long int a, b, k; + cin >> a >> b >> k; + long long int m, n; + if (k & 1) { + m = a * ((k / 2) + 1); + n = b * (k / 2); + } else { + m = a * (k / 2); + n = b * (k / 2); + } + cout << m - n << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int inch = 0; + int feet = n / 36; + n -= (n / 36) * 36; + if (n == 35) + ++feet; + else { + inch = n / 3; + n -= (n / 3) * 3; + if (n == 2) ++inch; + } + cout << feet << " " << inch << endl; + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int ans = 0; + while (a > 0) { + int kk = ((k) < (b + 1) ? (k) : (b + 1)); + a -= v * kk; + ans++; + b -= (kk - 1); + } + cout << ans << endl; +} +int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; +int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; +void fast() {} +const long long md = 1e9 + 7; +int main() { + fast(); + long long n; + cin >> n; + if (n % 2 == 0) + cout << n / 2 << "\n"; + else + cout << -(n + 1) / 2 << "\n"; + return 0; +} +int n; +int main() { + cin >> n; + n -= 10; + if (n <= 0) + cout << 0 << endl; + else if (n <= 9) + cout << 4 << endl; + else if (n == 10) + cout << 15 << endl; + else if (n == 11) + cout << 4 << endl; + else + cout << 0 << endl; +} +int main() { + int n, i, a, b, c, d = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a >> b >> c; + if (a + b + c == 2 || a + b + c == 3) d++; + } + cout << d << endl; + return 0; +} +int main() { + int n, m = 1, b = 0; + cin >> n; + while (n > 0) { + m = 1; + while (2 * m <= n) m *= 2; + b++; + n -= m; + } + cout << b << endl; + return 0; +} +int value[201] = {0}; +char num[201][201]; +int main() { + int n, d, index = 0, sum = 1, max; + cin >> n >> d; + getchar(); + for (int i = 0; i < d; i++) { + for (int j = 0; j < n; j++) cin >> num[i][j]; + getchar(); + } + for (int i = 0; i < d; i++) { + for (int j = 0; j < n; j++) { + if (num[i][j] == '0') { + value[index++] = i; + break; + } + } + } + if (index == 0) { + max = 0; + } else { + max = 1; + for (int i = 1; i < index; i++) { + while (value[i] - value[i - 1] == 1) { + sum++; + i++; + } + max = sum > max ? sum : max; + sum = 1; + } + } + cout << max << endl; +} +const int maxn = 1e5 + 5; +const int maxm = 105; +const int inf = 0x7fffffff; +const int mod = 1e9 + 7; +const double E = 1e-7; +long long Pow(long long a, long long x) { + long long ans = 1; + while (x) { + if (x & 1) { + ans *= a; + ans %= mod; + } + a *= a; + a %= a; + x >>= 1; + } + return ans; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +char m[maxm][maxm]; +char vis[maxm]; +bool judge(int x, int y) { + memset(vis, 0, sizeof vis); + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) { vis[m[x + i][y + j]] = true; } + if (vis['f'] == false) return false; + if (vis['a'] == false) return false; + if (vis['c'] == false) return false; + if (vis['e'] == false) return false; + return true; +} +int main() { + int n, t; + while (cin >> n >> t) { + memset(m, 0, sizeof m); + for (int i = 0; i < n; i++) { cin >> m[i]; } + int cnt = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < t; j++) { + if (judge(i, j)) cnt++; + } + } + cout << cnt << endl; + } + return 0; +} +int main() { + int n, m, k, cnt = 0, arr[105]; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[i] <= k) + cnt++; + else + break; + m = i; + } + if (m == n - 1) { + cout << cnt << endl; + return 0; + } + for (int j = n - 1; j >= m; j--) { + if (arr[j] <= k) + cnt++; + else + break; + } + cout << cnt << endl; + return 0; +} +int main() { + long long i = 2, n, sum = 0; + cin >> n; + cout << 2 << "\n"; + while (i < n + 1) { + cout << (i * (i + 1) * (i + 1) - (i - 1)) << "\n"; + i++; + } +} +int main() { + int n, m, c = 0; + cin >> n >> m; + int arr[1000][1000]; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < m; j++) { arr[i][j] = s[j]; } + } + set s; + for (int i = 0; i < m; i++) { + int max = 0; + for (int j = 0; j < n; j++) { + if (arr[j][i] > max) { max = arr[j][i]; } + } + for (int j = 0; j < n; j++) { + if (arr[j][i] == max) { + if (!s.count(j)) { + c++; + s.insert(j); + } + } + } + } + cout << c << endl; +} +ifstream infile; +ofstream outfile; +long double a[2 * 2005], dp[2 * 2005][2005]; +int n; +int OpenFile() { + infile.open("351A.INP", ios::in); + outfile.open("351A.OUT", ios::out); + if (infile.fail()) { + cout << "Khong mo duoc file input !" << endl; + return -1; + } + if (outfile.fail()) { + cout << "khong mo duoc file output!" << endl; + return -1; + } +} +void input() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; +} +void init() { + for (int i = 0; i <= 2 * n; i++) + for (int j = 0; j <= n; j++) dp[i][j] = INT_MAX; + dp[0][0] = 0; +} +void process() { + for (int i = 1; i <= 2 * n; i++) { + for (int j = 0; j <= min(i, n); j++) { + long double val1 = INT_MAX, val2 = INT_MAX; + if (j > 0) val1 = dp[i - 1][j - 1] + ceil(a[i]) - a[i]; + if ((i - j) <= n) val2 = dp[i - 1][j] + floor(a[i]) - a[i]; + dp[i][j] = val1; + if (fabs(val2) < fabs(val1)) dp[i][j] = val2; + } + } +} +void output() { + cout << fixed << setprecision(3) << fabs(dp[2 * n][n]) << endl; +} +void in() { + for (int i = 0; i <= 2 * n; i++) { + for (int j = 0; j <= n; j++) { + if (dp[i][j] == INT_MAX) + cout << 999999 << " "; + else if (dp[i][j] >= 0) + cout << " " << dp[i][j] << " "; + else + cout << dp[i][j] << " "; + } + cout << endl; + } +} +int main() { + input(); + init(); + process(); + output(); +} +int main() { + int n, a[110]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 1000; + for (int i = 1; i < n - 1; i++) { + int m = 0; + for (int j = 1; j < n; j++) { + if (j == i) + continue; + else if (j == i + 1) { + m = m > (a[j] - a[i - 1]) ? m : (a[j] - a[i - 1]); + } else + m = m > (a[j] - a[j - 1]) ? m : (a[j] - a[j - 1]); + } + ans = ans < m ? ans : m; + } + cout << ans << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + vector c(max(n, m)); + for (int i = 1; i <= n; i++) { + int rtr = i; + if (rtr % 2 == 1) { + for (int j = 1; j <= m; j++) c[j] = '#'; + } else { + if ((rtr % 2 == 0) && (rtr % 4 == 0)) { + c[1] = '#'; + for (int j = 2; j <= m; j++) c[j] = '.'; + } else if ((rtr % 2 == 0) && (rtr % 4 == 2)) { + c[m] = '#'; + for (int j = 1; j < m; j++) c[j] = '.'; + } + } + for (int j = 1; j <= m; j++) cout << c[j]; + cout << '\n'; + for (int j = 1; j <= m; j++) c[j] = '.'; + } + return 0; +} +int main() { + int arr[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + string m; + cin >> m; + int x = m[0] - '0'; + int y = m[1] - '0'; + cout << (arr[x] * arr[y]) << endl; + return 0; +} +int main() { + int Number; + cin >> Number; + unsigned long long int *Answers = new unsigned long long int[Number]; + for (int i = 0; i < Number; i++) { + unsigned long long int s, a, b, c; + cin >> s >> a >> b >> c; + Answers[i] = (s / c) + ((s / c) / a) * b; + } + for (int i = 0; i < Number; i++) cout << Answers[i] << endl; + return 0; +} +int main() { + unsigned long long n; + cin >> n; + cout << 3 * (n / 2) << endl; +} +long long mod = 1000000000 + 9; +long long n, m, k = 1, ans = 1, cnt, temp; +int main() { + cin >> n >> m; + temp = n; + while (temp) { + cnt++; + temp /= 2; + } + for (int i = 0; i < m; i++) { + k *= 2; + k %= mod; + } + k--; + for (int i = 0; i < n; i++) { + ans *= k; + ans %= mod; + k--; + k += mod; + k %= mod; + } + cout << ans << endl; +} +char tabuleiro[8][8]; +int menorW = 9, menorB = 9; +int testeW(int i, int j) { + int dist = 0; + if (i == 0) return 0; + for (i - 1; i >= 0; i--) { + if (tabuleiro[i][j] != 'B') + dist++; + else + return menorW; + } + if (menorW > dist) return dist; + return menorW; +} +int testeB(int i, int j) { + int dist = 0; + if (i == 8) return 0; + for (i + 1; i < 8; i++) { + if (tabuleiro[i][j] != 'W') + dist++; + else + return menorB; + } + if (menorB > dist) return dist; + return menorB; +} +int main() { + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) cin >> tabuleiro[i][j]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) + if (tabuleiro[i][j] == 'W') + menorW = testeW(i, j); + else if (tabuleiro[i][j] == 'B') + menorB = testeB(i, j); + if (menorW <= menorB) + cout << 'A' << endl; + else + cout << 'B' << endl; + return 0; +} +int main() { + int n, a; + cin >> n; + a = n - 1; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j <= a / 2; j++) { cout << '*'; } + for (int j = 1; j <= n - a; j++) cout << 'D'; + for (int j = 1; j <= a / 2; j++) cout << '*'; + a -= 2; + cout << '\n'; + } + a = 2; + for (int i = 1; i <= n / 2; i++) { + for (int j = a / 2; j > 0; j--) { cout << '*'; } + for (int j = n - a; j > 0; j--) cout << 'D'; + for (int j = a / 2; j > 0; j--) cout << '*'; + a += 2; + cout << '\n'; + } + return 0; +} +int main() { + long long int a, b, c, d, e, f, g, h, i, j; + vector v, x, u; + string s, t; + while (cin >> a >> b) { + for (c = 1; c <= a; c++) { v.push_back(c); } + e = 0; + f = a - 1; + g = 0; + while (e <= f) { + if (v[e] * v[f] == b && v[e] != v[f]) { + g += 2; + f--; + } else if (v[e] * v[f] == b && v[e] == v[f]) { + g += 1; + f--; + } else if (v[e] * v[f] < b) { + e++; + } else { + f--; + } + } + cout << g << endl; + v.clear(); + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char s[1000]; + int t[1000], flag = 0; + memset(t, 0, sizeof(t)); + cin >> s; + for (int i = 0; i < n; i++) { + t[s[i]]++; + if (t[s[i]] > m) { flag = 1; } + } + if (flag) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + for (int i = s.size() - 2; i >= 0; i--) { + if (s[i] == s[i + 1]) { s.erase(i, 2); } + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector mi(3), ma(3); + for (int i = 0; i < 3; ++i) { cin >> mi[i] >> ma[i]; } + vector ans(3); + int sum = 0; + for (int i = 0; i < 3; ++i) { + ans[i] = ma[i]; + sum += ans[i]; + } + for (int i = 2; i >= 0 && sum > n; --i) { + int d = min(sum - n, ans[i] - mi[i]); + sum -= d; + ans[i] -= d; + } + for (int i = 0; i < 3; ++i) { cout << ans[i] << " \n"[i + 1 == 3]; } +} +int main() { + int x; + cin >> x; + if (x > 5) { + if (x % 5 == 0) { + cout << x / 5 << endl; + } else { + cout << x / 5 + 1 << endl; + } + } else { + cout << 1 << endl; + } +} +int main() { + int n, seven = 0, four = 0; + cin >> n; + while (n > 0) { + if (n % 7 == 0) { + seven = n / 7; + n = 0; + break; + } + four++; + n = n - 4; + } + if (n != 0) { + cout << "-1" << endl; + return 0; + } + for (int i = 0; i < four; i++) { cout << "4"; } + for (int i = 0; i < seven; i++) { cout << "7"; } + cout << endl; + return 0; +} +const int maxn = 1e3 + 10; +string s; +int m; +int main() { + cin >> s; + for (int i = s.size() - 1; i >= 0; i--) { + if (s[i] - '0' >= 5) { + cout << "-O|"; + m = (s[i] - '0') % 5; + for (int i = 0; i < m; i++) { cout << "O"; } + cout << "-"; + for (int i = 0; i < 4 - m; i++) { cout << "O"; } + } else { + cout << "O-|"; + m = (s[i] - '0') % 5; + for (int i = 0; i < m; i++) { cout << "O"; } + cout << "-"; + for (int i = 0; i < 4 - m; i++) { cout << "O"; } + } + cout << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int sz1 = a.size(), sz2 = b.size(); + if (a == b) { + cout << -1 << endl; + } else + cout << max(sz1, sz2) << endl; + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + puts("1"); + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int n; + cin >> n; + cout << a << " " << b << endl; + for (int i = 0; i < n; i++) { + string x, y; + cin >> x >> y; + if (x == a) { + a = y; + } else if (y == a) { + b = x; + } + if (y == b) { + b = x; + } else if (x == b) { + b = y; + } + cout << a << " " << b << endl; + } + return 0; +} +int main() { + char c, d; + cin >> c >> d; + int ans[] = {8, 5, 3}; + int a = 0; + if (c == 'a' || c == 'h') ++a; + if (d == '1' || d == '8') ++a; + cout << ans[a] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + cin >> b[i]; + } + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i != j) { + if (a[i] == b[j]) count++; + } + } + } + cout << count << endl; +} +int a[11]; +int main() { + int n, i, x; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> x; + a[x]++; + } + int max = -1; + for (i = 1; i <= 3; i++) { + if (a[i] > max) max = a[i]; + } + cout << n - max << endl; +} +int main() { + string a, b; + cin >> a >> b; + reverse(b.begin(), b.end()); + stringstream n1(a); + stringstream n2(b); + int num1, num2; + n1 >> num1; + n2 >> num2; + long long int res = num1 + num2; + cout << res << endl; + return 0; +} +int main() { + long long n, d; + cin >> n >> d; + long long arr[n]; + for (long long i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + long long ans = 1000; + for (long long i = 0; i < n; i++) { + for (long long j = i; j < n; j++) { + long long diff = abs(arr[i] - arr[j]); + if (diff <= d) { + long long p = n - (j - i + 1); + ans = min(ans, p); + } else { + break; + } + } + } + cout << ans << endl; +} +int main() { + int n, i, j, mnth, day; + cin >> mnth >> day; + int arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int totalday = arr[mnth]; + int otherday = totalday % 7; + int ans = totalday / 7; + if (totalday % 7 == 0 && day == 1) { + cout << ans << endl; + return 0; + } + if ((8 - day) < otherday) + ans += 2; + else + ans++; + cout << ans << endl; + return 0; +} +int main() { + string s; + int len, sum; + sum = 0; + cin >> len; + int maxx = 0; + while (cin >> s) { + int i, cnt = 0; + for (i = 0; s[i]; i++) + if (s[i] >= 'A' && s[i] <= 'Z') cnt++; + sum += i + 1; + maxx = max(cnt, maxx); + if (sum >= len) break; + } + cout << maxx << endl; +} +int cal(int plus, int mius, int a, int b, int c, int d, int e) { + int ans = plus * 100 - mius * 50 + a + b + c + d + e; + return ans; +} +int main() { + string s, s1; + int plus, mius; + int a, b, c, d, e; + int n; + int plus1, mius1; + int a1, b1, c1, d1, e1; + cin >> n; + string ans; + cin >> s1 >> plus1 >> mius1 >> a1 >> b1 >> c1 >> d1 >> e1; + int res = plus1 * 100 - mius1 * 50 + a1 + b1 + c1 + d1 + e1; + ans = s1; + for (int i = 1; i < n; i++) { + cin >> s >> plus >> mius >> a >> b >> c >> d >> e; + if (cal(plus, mius, a, b, c, d, e) > res) { + ans = s; + res = cal(plus, mius, a, b, c, d, e); + } + } + cout << ans << '\n'; + return 0; +} +int main() { + long long n; + cin >> n; + cout << n / 2 + 1 << endl; +} +int main() { + int n; + int S[10]; + while (cin >> n) { + memset(S, 0, sizeof(S)); + int maxx = 0, maxy = 0; + int minx = 10000000, miny = 10000000; + int C = 0; + int x1, x2, y1, y2; + for (int i = 1; i <= n; ++i) { + cin >> x1 >> y1 >> x2 >> y2; + S[i] = (x2 - x1) * (y2 - y1); + C += S[i]; + if (x1 < minx) minx = x1; + if (x2 > maxx) maxx = x2; + if (y1 < miny) miny = y1; + if (y2 > maxy) maxy = y2; + } + if (C == (maxx - minx) * (maxy - miny) && (maxx - minx) == (maxy - miny)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int sx = 0; + int s0 = 0; + int acumx = 0; + int acum0 = 0; + for (int i = 0; i < n; i++) { + if (i % 2) { + s0 = (acumx + 1) % 1000000007; + acum0 = (acum0 + s0) % 1000000007; + } else { + sx = (acum0 + 1) % 1000000007; + acumx = (acumx + sx) % 1000000007; + } + } + cout << (acum0 + acumx) % 1000000007 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int r = 240 - b; + int s = 0; + int c = 0; + for (int i = 1;; i++) { + int k = 5 * i; + s = s + k; + if (s > r) { + break; + } else { + c++; + if (c == a) { break; } + } + } + cout << c << endl; +} +int n, t, k, d; +int main() { + cin >> n >> t >> k >> d; + int c1 = ceil((double)n / k); + double c2 = d / t; + if (c1 - c2 > 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int n, mn = 1e9 + 7, skr = 1e9 + 7, mnd = 1e6; +void masuk(int idx) { + if (idx < n) { + int ai; + cin >> ai; + mn = min(mn, ai); + masuk(idx + 1); + if (ai == mn) { + mnd = min(mnd, skr - idx); + skr = idx; + } + } +} +int main() { + cin >> n; + masuk(0); + cout << mnd << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + n = 2 * n; + long double a[100005]; + int i; + vector v1, v, v2; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == (int)a[i]) { + v.push_back(a[i]); + } else { + v1.push_back(a[i]); + } + } + for (i = 0; i < v1.size(); i++) { + long double g = ceil(v1[i]) - v1[i]; + v2.push_back(g); + } + sort(v2.begin(), v2.end()); + int h = n / 2; + int j; + int hh = v2.size(); + long double ans1 = 0, ans = 0, ans2 = 1e9; + for (i = -1; i < hh; i++) { + if (i == -1) { + } else { + ans += v2[i]; + } + ans1 = 0; + if (((i + 1) + v.size()) >= h && (n - (i + 1)) >= h) { + for (j = i + 1; j < hh; j++) { ans1 -= 1 - v2[j]; } + ans2 = min(ans2, abs(ans + ans1)); + } + } + cout << fixed << setprecision(3) << ans2 << endl; +} +int main() { + int n; + int a[35][35]; + int b[100], c[100]; + while (cin >> n) { + int i, j; + int sum = 0; + memset(b, 0, sizeof(b)); + memset(c, 0, sizeof(c)); + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (i = 0; i < n; i++) { + int sum1 = 0; + for (j = 0; j < n; j++) { sum1 = sum1 + a[i][j]; } + b[i] = sum1; + } + for (j = 0; j < n; j++) { + int sum2 = 0; + for (i = 0; i < n; i++) { sum2 = sum2 + a[i][j]; } + c[j] = sum2; + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (c[i] > b[j]) { sum++; } + } + } + cout << sum << endl; + } + return 0; +} +int f[1005]; +int g[1005]; +int find(int x) { + return f[x] == x ? x : f[x] = find(f[x]); +} +void clear() { + for (int i = 0; i < 1005; i++) f[i] = i; +} +int main() { + memset(g, 0, sizeof(g)); + clear(); + int n, m, k; + cin >> n >> m >> k; + int i, j; + for (i = 0; i < k; i++) { + int gov; + cin >> gov; + g[gov] = 1; + } + for (i = 0; i < m; i++) { + int x, y; + cin >> x >> y; + if (g[x] == 1) + f[find(y)] = x; + else if (g[y] == 1) + f[find(x)] = y; + else { + if (g[find(x)] == 1) + f[find(y)] = f[find(x)]; + else if (g[find(y)] == 1) + f[find(x)] = f[find(y)]; + else + f[find(y)] = f[find(x)]; + } + } + int ans = 0; + int maxx = 0; + int temp; + for (i = 1; i <= n; i++) { + temp = 1; + if (g[i]) { + for (j = 1; j <= n; j++) { + if (i != j && !g[j] && f[find(j)] == i) { temp++; } + } + ans += temp * (temp - 1) / 2; + maxx = max(maxx, temp); + } + } + int cnt = 0; + for (i = 1; i <= n; i++) { + if (!g[i] && !g[f[find(i)]]) { cnt++; } + } + ans += maxx * cnt; + ans += cnt * (cnt - 1) / 2; + ans -= m; + cout << ans << endl; + return 0; +} +int tri(int *a) { + if (a[0] < a[1] + a[2] && a[1] < a[0] + a[2] && a[2] < a[1] + a[0]) { return 1; } + if (a[0] == a[1] + a[2] || a[1] == a[0] + a[2] || a[2] == a[1] + a[0]) { return 0; } + return -1; +} +int main() { + int a[4]; + for (int i = 0; i < 4; i++) cin >> a[i]; + bool triangle = false, segment = false; + int stat; + for (int i = 0; i < 3; i++) { + swap(a[i], a[3]); + stat = tri(a); + swap(a[i], a[3]); + if (stat == 1) { + triangle = true; + break; + } + if (stat == 0) { segment = true; } + } + stat = tri(a); + if (stat == 1) { triangle = true; } + if (stat == 0) { segment = true; } + if (triangle) + cout << "TRIANGLE" << endl; + else if (segment) + cout << "SEGMENT" << endl; + else + cout << "IMPOSSIBLE" << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans = ((a - b) * c + b - 1) / b; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int vet[n]; + bool tem = false; + for (int i = 0; i < n; i++) { + cin >> vet[i]; + if (vet[i] == 1) { tem = true; } + } + if (tem) { + cout << -1 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + char c[10][10]; + for (int i = 1; i <= 8; i++) { gets(c[i]); } + int flag = 1; + for (int i = 1; i <= 8; i++) { + for (int j = 0; j < 7; j++) { + if (c[i][j] == c[i][j + 1]) { + flag = 0; + break; + } + } + if (flag == 0) { break; } + } + if (flag) + puts("YES"); + else + puts("NO"); + return 0; +} +string letters[105]; +int n, ans, larger; +void reading() { + cin >> n; + for (int j = 0; j < n; j++) cin >> letters[j]; +} +bool worth(char aa, char bb, int m) { + for (int i = 0; i < letters[m].size(); i++) { + if (letters[m][i] != aa & letters[m][i] != bb) return false; + } + return true; +} +int main() { + reading(); + for (char kk = 'a'; kk <= 'z'; kk++) { + for (char ff = kk; ff <= 'z'; ff++) { + for (int d = 0; d < n; d++) { larger += worth(kk, ff, d) * letters[d].size(); } + ans = max(larger, ans); + larger = 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n = 0, m = 0; + cin >> n; + cin >> m; + vector v; + priority_queue p; + priority_queue q; + int k = 0; + for (int i = 0; i < n; i++) { + int aux = 0; + cin >> aux; + p.push(aux * (-1)); + q.push(aux + m); + } + k = q.top(); + if (n != 1) { + for (int i = 0; i < m; i++) { + int aux = 0; + aux = p.top() + (-1); + p.pop(); + p.push(aux); + } + for (int i = 0; i < n; i++) { + v.push_back(p.top() * (-1)); + p.pop(); + } + } else + v.push_back(k); + cout << v[n - 1] << " " << k << endl; +} +char ch[66666]; +char ss[6] = {'a', 'e', 'i', 'o', 'u'}; +int pd(int i) { + for (int j = 0; j < 5; j++) { + if (ch[i] == ss[j]) return 1; + } + return 0; +} +int main() { + cin >> ch; + int len = strlen(ch); + for (int i = 0; i < len; i++) { + if (!pd(i) && !pd(i + 1) && ch[i] != 'n') { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +char mp[2][2001][2001]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> mp[0][i]; + for (int i = 0; i < m; i++) cin >> mp[1][i]; + int i, j; + for (i = 0; i <= n - m; i++) { + for (j = 0; j <= n - m; j++) { + bool ok = true; + for (int p = 0; p < m && ok; p++) ok &= !memcmp(&mp[0][i + p][0], &mp[1][p][j], m); + if (ok) { + cout << i + 1 << ' ' << j + 1 << endl; + return 0; + } + } + } +} +int main() { + long long int n, k; + cin >> n >> k; + long long int arr[n] = {0}; + int answer = 0; + int sum = 0; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int temp = 0; + for (int i = 0; i < n; i++) { + arr[i] += temp; + if (arr[i] >= 8) { + k -= 8; + temp = arr[i] - 8; + answer++; + } else { + k -= arr[i]; + temp = 0; + answer++; + } + if (k <= 0) { + cout << answer << endl; + return 0; + } + } + cout << -1 << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int c = 0; + int **p = new int *[n]; + for (int i = 0; i < n; i++) { p[i] = new int[2]; } + for (int i = 0; i < n; i++) { + cin >> p[i][0]; + cin >> p[i][1]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) + if (i == j) + continue; + else + p[i][0] == p[j][1] ? c++ : 0; + } + cout << c << endl; + } +} +int t, n, m, i, j, ans, k, a, b, c, d, e, f, sz, q, x; +string s, s2, s3, s4, s5, s6; +int ar[(int)(1e5 + 10)], ar2[(int)(1e5 + 10)]; +void brainfuck(); +int main() { + brainfuck(); + return 0; +} +void brainfuck() { + cin >> n; + a = (n + 1) / 2; + b = a - 2; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + if (a >= i && (j >= a - i + 1 && j <= a + i - 1)) + cout << "D"; + else if (a < i && (j >= a - b && j <= a + b)) + cout << "D"; + else + cout << "*"; + } + if (a < i) b--; + cout << "\n"; + } +} +int n, i, j, x, y, sum; +char c[100][100]; +bool flag; +int main() { + cin >> n; + for (x; x < n; x++) { + for (y = 0; y < n; y++) { cin >> c[x][y]; } + } + for (x = 0; x < n; x++) { + for (y = 0; y < n; y++) { + sum = 0; + if (x + 1 <= n - 1 && c[x + 1][y] == 'o') sum++; + if (x - 1 >= 0 && c[x - 1][y] == 'o') sum++; + if (y + 1 <= n - 1 && c[x][y + 1] == 'o') sum++; + if (y - 1 >= 0 && c[x][y - 1] == 'o') sum++; + if (sum % 2 != 0) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, x; + cin >> n >> x; + int ans = 0; + for (int i = 1; i <= n; i++) { + if (x % i == 0 && x / i <= n) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + int k, r, ans; + cin >> k >> r; + for (int i = 1; i < 11; i++) + if (k * i % 10 == 0 || k * i % 10 == r) { + ans = i; + break; + } + cout << ans << endl; + return 0; +} +int a[10], b[10]; +int main() { + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + a[x]++; + } + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + b[x]++; + } + int sum = 0; + for (int i = 1; i <= 5; i++) { + if ((a[i] + b[i]) & 1) { + puts("-1"); + return 0; + } else if (a[i] + b[i] == 0) + continue; + else + sum += abs(a[i] - b[i]); + } + cout << sum / 4 << endl; + return 0; +} +int n, m, ct; +char grid[50][50]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> grid[i][j]; } + } + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + bool f = false, a = false, c = false, e = false; + for (int k = 0; k <= 1; k++) { + for (int l = 0; l <= 1; l++) { + if (grid[i + k][j + l] == 'f') f = true; + if (grid[i + k][j + l] == 'a') a = true; + if (grid[i + k][j + l] == 'c') c = true; + if (grid[i + k][j + l] == 'e') e = true; + } + } + if (f && a && c && e) ct++; + } + } + cout << ct << endl; +} +int main() { + int n, d; + cin >> n >> d; + string all_present(n, '1'); + int count = 0, cdays = 0; + while (d--) { + string day; + cin >> day; + if (day == all_present) + cdays = max(cdays, count), count = 0; + else + count++; + } + cdays = max(cdays, count); + cout << cdays << endl; + return 0; +} +int main() { + string a, b, c = ""; + cin >> a >> b; + long long tam = a.size(), i; + for (i = 0; i < tam; i++) { + if (a[i] == b[i]) + c += '0'; + else + c += '1'; + } + cout << c << endl; + return 0; +} +int main() { + int t, n; + string s; + cin >> t; + while (t--) { + cin >> n >> s; + if (n <= 2 && s[0] >= s[1]) { + cout << "NO\n"; + } else { + cout << "YES\n" << 2 << endl; + cout << s[0] << ' ' << s.substr(1) << endl; + } + } +} +int main() { + int arr[3][3] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + int c = 0; + int x; + for (int i = 1; i <= 9; i++) { + cin >> x; + if (x % 2 != 0) { + if (i == 1) { + arr[0][0] = fabs(arr[0][0] - 1); + arr[0][1] = fabs(arr[0][1] - 1); + arr[1][0] = fabs(arr[1][0] - 1); + } else if (i == 3) { + arr[0][2] = fabs(arr[0][2] - 1); + arr[0][1] = fabs(arr[0][1] - 1); + arr[1][2] = fabs(arr[1][2] - 1); + } else if (i == 4) { + arr[1][0] = fabs(arr[1][0] - 1); + arr[0][0] = fabs(arr[0][0] - 1); + arr[1][1] = fabs(arr[1][1] - 1); + arr[2][0] = fabs(arr[2][0] - 1); + } else if (i == 6) { + arr[1][2] = fabs(arr[1][2] - 1); + arr[0][2] = fabs(arr[0][2] - 1); + arr[2][2] = fabs(arr[2][2] - 1); + arr[1][1] = fabs(arr[1][1] - 1); + } else if (i == 7) { + arr[1][0] = fabs(arr[1][0] - 1); + arr[2][0] = fabs(arr[2][0] - 1); + arr[2][1] = fabs(arr[2][1] - 1); + } else if (i == 9) { + arr[2][2] = fabs(arr[2][2] - 1); + arr[1][2] = fabs(arr[1][2] - 1); + arr[2][1] = fabs(arr[2][1] - 1); + } else if (i == 2) { + arr[0][1] = fabs(arr[0][1] - 1); + arr[0][2] = fabs(arr[0][2] - 1); + arr[0][0] = fabs(arr[0][0] - 1); + arr[1][1] = fabs(arr[1][1] - 1); + } else if (i == 5) { + arr[0][1] = fabs(arr[0][1] - 1); + arr[1][2] = fabs(arr[1][2] - 1); + arr[1][0] = fabs(arr[1][0] - 1); + arr[1][1] = fabs(arr[1][1] - 1); + arr[2][1] = fabs(arr[2][1] - 1); + } else if (i == 8) { + arr[2][1] = fabs(arr[2][1] - 1); + arr[2][2] = fabs(arr[2][2] - 1); + arr[2][0] = fabs(arr[2][0] - 1); + arr[1][1] = fabs(arr[1][1] - 1); + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << arr[i][j]; + cout << endl; + } + return 0; +} +int arr[100000] = {0}; +int main() { + int n, m, turn = 0, j = 0; + cin >> n >> m; + for (int i = 0; i < n; i++) { + turn++; + j++; + if (j == m) break; + } + if (turn % 2 == 0) + cout << "Malvika\n"; + else + cout << "Akshat\n"; +} +int f[100010], a[100010], n; +int ans = 0, sum = 0; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] < a[i + 1]) { + sum++; + } else + ans = max(ans, sum), sum = 0; + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int mat[6][6]; + int x; + int y; + int sideMoves; + int verticalMoves; + int totalMoves; + for (int i = 1; i < 6; i++) { + for (int j = 1; j < 6; j++) { + cin >> mat[i][j]; + if (mat[i][j] == 1) { + x = i; + y = j; + } + } + } + verticalMoves = y - 3; + if (verticalMoves < 0) { verticalMoves = -verticalMoves; } + sideMoves = x - 3; + if (sideMoves < 0) { sideMoves = -sideMoves; } + totalMoves = verticalMoves + sideMoves; + cout << totalMoves << endl; + return 0; +} +int main() { + int r, c; + cin >> r >> c; + for (int i = 0; i < r; i++) { + if (i % 2 == 0) { + for (int j = 0; j < c; j++) { cout << "#"; } + cout << endl; + } else { + if ((i / 2) % 2 == 0) { + for (int j = 0; j < c - 1; j++) cout << "."; + cout << "#" << endl; + } else { + cout << "#"; + for (int j = 0; j < c - 1; j++) cout << "."; + cout << endl; + } + } + } + return 0; +} +const int maxn = 200010; +int n, m, k; +int a[maxn], sum[maxn]; +int c[maxn]; +int ans, ct, cnt, tmp, flag; +string s, str1, str2; +int main() { + for (int i = 6; i < 10; i++) a[('0' + i)] = i; + a['T'] = 100; + a['J'] = 101; + a['Q'] = 102; + a['K'] = 103; + a['A'] = 104; + int T, cas = 1; + cin >> s >> str1 >> str2; + if (str1[1] == s[0] && str2[1] != s[0]) + puts("YES"); + else if (str1[1] == str2[1] && a[str1[0]] > a[str2[0]]) + puts("YES"); + else if (str1[1] == str2[1] && a[str1[0]] <= a[str2[0]]) + puts("NO"); + else if (str1[1] == s[0]) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + long long n; + cin >> n; + int count = 0; + while (n != 0) { + if (n % 10 == 4 || n % 10 == 7) { count += 1; } + n /= 10; + } + if (count == 4 || count == 7) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + string input_1, input_2; + cin >> input_1; + cin >> input_2; + reverse(input_1.begin(), input_1.end()); + if (input_1 == input_2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n, m; + while (cin >> n >> m) { + if (n >= 0 && m >= 0) { + cout << "0 " << (n + m) << " " << (n + m) << " 0" << endl; + } else if (n < 0 && m >= 0) { + long long a = abs(n); + cout << "-" << (a + m) << " 0 0 " << (m + a) << endl; + } else if (n >= 0 && m < 0) { + long long a = abs(m); + cout << "0 -" << (n + a) << " " << (n + a) << " 0" << endl; + } else { + cout << "-" << (abs(n) + abs(m)) << " 0 0 -" << (abs(n) + abs(m)) << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + cout << ceil(n / 5.0) << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int t1 = 0, t2 = d - t; + int temp = n; + if ((d / t + 1) * k >= n) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 0) { + cout << "O-|-OOOO" << endl; + } else { + while (n > 0) { + int d = n % 10; + n = n / 10; + if (d < 5) { + cout << "O-|"; + } else { + cout << "-O|"; + } + d = d % 5; + if (d == 0) { + cout << "-OOOO" << endl; + } else if (d == 1) { + cout << "O-OOO" << endl; + } else if (d == 2) { + cout << "OO-OO" << endl; + } else if (d == 3) { + cout << "OOO-O" << endl; + } else if (d == 4) { + cout << "OOOO-" << endl; + } + } + } +} +int main() { + string s1, s2, s3; + cin >> s1 >> s2; + s3.push_back(s1[0]); + for (int i = 1; s1[i] != '\0'; i++) { + if (s1[i] >= s2[0]) break; + s3.push_back(s1[i]); + } + s3.push_back(s2[0]); + cout << s3 << "\n"; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + if (s1 == s2) + cout << -1 << endl; + else + cout << max(s1.length(), s2.length()) << endl; +} +int main() { + long long n; + cin >> n; + if (n % 2) + cout << 1 << endl; + else + cout << 2 << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << '\n'; + else + cout << 1 << '\n'; +} +int main() { + long long n, m; + cin >> n >> m; + long long i, j; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 4 == 2 && j != m) + cout << "."; + else if (i % 4 == 0 && j != 1) + cout << "."; + else + cout << "#"; + } + cout << endl; + } + return 0; +} +int main() { + int y = 0; + int x, hh, mm; + cin >> x >> hh >> mm; + while (mm % 10 != 7 && hh % 10 != 7) { + if (mm < 0) { + if (hh < 0) { hh += 24; } + mm += 60; + hh -= 1; + if (mm % 10 == 7 || hh % 10 == 7) { break; } + mm -= x; + y += 1; + continue; + } + mm -= x; + y += 1; + } + cout << y << endl; + return 0; +} +int main() { + int w = 0, h = 0, k = 0, counter_yello = 0; + cin >> w >> h >> k; + for (size_t i = 0; i < k; ++i) { + counter_yello += 2 * w + 2 * h - 4; + w -= 4; + h -= 4; + } + cout << counter_yello << endl; + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (b) { + int d = b % 10; + c = c * 10 + d; + b /= 10; + } + cout << a + c << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + int min = x, max = x; + int cnt = 0; + for (int i = 0; i < n; i++) { + cin >> x; + if (x < min) { + cnt++; + min = x; + } else if (x > max) { + cnt++; + max = x; + } + } + cout << cnt << endl; +} +int main() { + int n; + cin >> n; + if (n == 2) { + cout << "2\n"; + } else + cout << "1\n"; +} +int n; +string s; +int main() { + int sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == "Icosahedron") { + sum += 20; + } else if (s == "Dodecahedron") { + sum += 12; + } else if (s == "Octahedron") { + sum += 8; + } else if (s == "Cube") { + sum += 6; + } else if (s == "Tetrahedron") { + sum += 4; + } + } + cout << sum << endl; +} +int main() { + long long int n, s, a[1001], b[1001]; + cin >> n >> s; + for (long long int i = 1; i <= n; i++) cin >> a[i]; + for (long long int i = 1; i <= n; i++) cin >> b[i]; + if (a[1] == 0) { + cout << "NO" << endl; + return 0; + } + if (a[s] == 1) { + cout << "YES" << endl; + return 0; + } + bool flag = false; + for (long long int i = s + 1; i <= n; i++) { + if (a[i] == 1 && b[i] == 1) { + flag = true; + break; + } + } + if (flag == false) { + cout << "NO" << endl; + return 0; + } + if (b[s] == 1) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int i; + sort(s.begin(), s.end()); + int uniqueCharacters = 0; + int n = s.size(); + for (i = 1; i < n; i++) + if (s[i] != s[i - 1]) uniqueCharacters++; + cout << (uniqueCharacters % 2 ? "CHAT WITH HER!" : "IGNORE HIM!") << endl; + return 0; +} +int main() { + int k, n, w; + cin >> k >> n >> w; + int expect = 0, borrow = 0; + for (int i = 1; i <= w; i++) { expect = expect + k * i; } + if (expect > n) { + borrow = expect - n; + cout << borrow << endl; + } else { + cout << 0 << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int L = s.size(); + string ans; + for (int mask = 1; mask < (1 << L); ++mask) { + string aux; + for (int i = 0; i < L; ++i) + if (mask >> i & 1) aux += s[i]; + string aux2 = aux; + reverse(aux2.begin(), aux2.end()); + if (aux == aux2) ans = max(ans, aux); + } + cout << ans << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + for (long long i = 1, prev = 2; i <= n; ++i) { + long long curr = i * (i + 1); + cout << (long long)curr * (long long)(i + 1) - (long long)prev / (long long)i << endl; + prev = curr; + } + return 0; +} +int main() { + int k = 0; + string s; + cin >> s; + for (int i = 1; i < s.length(); i++) { + if (s[i] == 'K' && s[i - 1] == 'V') { k++; } + } + for (int i = 1; i < s.length(); i++) { + if (s[i] == s[i - 1] && s[i] == 'V' && s[i + 1] != 'K') { + cout << k + 1 << endl; + return 0; + } + if (s[i] == s[i - 1] && s[i] == 'K' && s[i - 2] != 'V') { + cout << k + 1 << endl; + return 0; + } + } + cout << k << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; ++i) { + int a, b; + cin >> a >> b; + int ans = 0; + while (a != 0 && b != 0) { + if (a > b) { + ans += a / b; + a = a % b; + } else { + ans += b / a; + b = b % a; + } + } + cout << ans << "\n"; + } + return 0; +} +int main() { + int n, i, j, max, dif, min = 10000; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (i = 1; i < n - 1; i++) { + max = -10000; + for (j = 0; j < n - 1; j++) { + if ((j + 1) == i) { + dif = arr[j + 2] - arr[j]; + } else if (j == i) { + dif = arr[j + 1] - arr[j - 1]; + } else { + dif = arr[j + 1] - arr[j]; + } + if (dif >= max) max = dif; + } + if (max <= min) min = max; + } + cout << min << endl; + return 0; +} +int main() { + set s; + int n, a; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a; + if (a) s.insert(a); + } + cout << s.size() << endl; +} +int main() { + int i = 0, n; + string s; + list l1, l2; + list::iterator j; + list::reverse_iterator k; + cin >> s; + n = s.size(); + while (i < n) { ((s[i++] == 'r') ? l1.push_back(i) : l2.push_back(i)); } + for (j = l1.begin(); j != l1.end(); ++j) { cout << (*j) << '\n'; } + for (k = l2.rbegin(); k != l2.rend(); ++k) { cout << (*k) << '\n'; } + return 0; +} +long long n, res, f[5]; +string a[110], b[110]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + long long Ca = 0; + long long Cb = 0; + for (int i = 1; i <= n; i++) + if (a[i] == "M") Ca++; + for (int i = 1; i <= n; i++) + if (b[i] == "M") Cb++; + f[1] = max(Ca, Cb) - min(Ca, Cb); + string S = "S"; + string L = "L"; + for (int i = 0; i <= 3; i++) { + if (i != 0) { + S = "X" + S; + L = "X" + L; + } + Ca = 0; + Cb = 0; + for (int j = 1; j <= n; j++) + if (a[j] == S) Ca++; + for (int j = 1; j <= n; j++) + if (b[j] == S) Cb++; + f[S.length()] = f[S.length()] + max(Ca, Cb) - min(Ca, Cb); + Ca = 0; + Cb = 0; + for (int j = 1; j <= n; j++) + if (a[j] == L) Ca++; + for (int j = 1; j <= n; j++) + if (b[j] == L) Cb++; + f[S.length()] = f[S.length()] + max(Ca, Cb) - min(Ca, Cb); + } + for (int i = 0; i <= 4; i++) res = res + f[i]; + cout << res / 2 << endl; + return 0; +} +int main() { + long long a, b, c, r = 0; + cin >> a >> b >> c; + for (long long i = 0; i < c; i++) r += ((((a - (4 * i)) - 1) + ((b - (4 * i)) - 1)) * 2); + cout << r << "\n"; + return 0; +} +long long ll = 1; +int main() { + int a, b; + cin >> a >> b; + if (a > b) a = b; + for (int i = 2; i <= a; i++) ll *= i; + cout << ll << endl; + return 0; +} +string tostr(int n) { + stringstream rr; + rr << n; + return rr.str(); +} +int check_lucky(long long n) { + while (n > 0) { + if (n % 10 == 8) { return 1; } + n /= 10; + } + return 0; +} +int main() { + long long a; + cin >> a; + int res = 0; + while (!check_lucky(abs(a)) || (res == 0)) { + res += 1; + a += 1; + } + cout << res << endl; + return 0; +} +int t; +int main() { + cin >> t; + for (int q = 0; q < t; q++) { + string a; + int len; + cin >> len >> a; + bool palin = true; + for (int i = 0; i < len / 2; i++) { + if (a[i] != a[len - i - 1] && abs((int)a[i] - a[len - i - 1]) != 2) { + palin = false; + break; + } + } + string res = (palin) ? "YES" : "NO"; + cout << res << '\n'; + } + return 0; +} +int main() { + int a, b, c, d; + char p, q; + string str; + cin >> a >> b >> str; + for (int i = 0; i < b; i++) { + cin >> c >> d >> p >> q; + for (int j = c - 1; j <= d - 1; j++) { + if (str[j] == p) str[j] = q; + } + } + for (int i = 0; i < str.size(); i++) cout << str[i]; + cout << endl; + return 0; +} +int main() { + long long int n, w, k; + cin >> k >> n >> w; + long long int ndmny = k * ((w * (w + 1)) / 2); + if (n <= ndmny) + cout << ndmny - n << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + int min, height, width, radius; + while (cin >> height >> width >> radius) { + if (height < width) + min = height; + else + min = width; + radius = radius * 2; + if (min >= radius) + cout << "First" << endl; + else + cout << "Second" << endl; + } + return 0; +} +int main() { + long long x[4], y[4]; + for (int i = 1; i <= (3); i++) cin >> x[i] >> y[i]; + long long a1 = y[1] - y[2]; + long long b1 = x[2] - x[1]; + long long c1 = x[1] * y[2] - x[2] * y[1]; + long long a2 = y[2] - y[3]; + long long b2 = x[3] - x[2]; + long long c2 = x[2] * y[3] - x[3] * y[2]; + if (a1 * b2 == a2 * b1 && b1 * c2 == b2 * c1) { + cout << "TOWARDS\n"; + } else { + if (a1 * b2 > a2 * b1) + cout << "LEFT\n"; + else + cout << "RIGHT\n"; + } + return 0; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + long long low = 1; + long long high = ((long long)1e18 + 1) / q; + while (high > low) { + long long mid = (low + high) / 2; + if (q * mid - y >= p * mid - x && p * mid >= x) { + high = mid; + } else { + low = mid + 1; + } + } + long long mid = low; + if (q * mid - y >= p * mid - x && p * mid >= x) { + cout << q * mid - y << endl; + } else { + cout << -1 << endl; + } + } +} +int main() { + int n, k; + string s; + cin >> n >> k; + cin >> s; + if (k > n / 2) { + while (k != n) { + cout << "RIGHT" << endl; + k++; + } + while (k != 0) { + cout << "PRINT " << s[k - 1] << endl; + if (k > 1) cout << "LEFT" << endl; + k--; + } + } else { + while (k != 1) { + cout << "LEFT" << endl; + k--; + } + while (k != n + 1) { + cout << "PRINT " << s[k - 1] << endl; + if (k < n) cout << "RIGHT" << endl; + k++; + } + } + return 0; +} +int main() { + int minx = 0, n, a, b, test = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> a >> b; + test -= a; + test += b; + minx = max(minx, test); + } + cout << minx << endl; + return 0; +} +int main() { + int n, i, j, ans, x; + ans = 0; + cin >> n; + int a[n], b[n]; + vector mp(10000000, 0); + j = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + mp[a[i]] = 1; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + mp[b[i]] = 1; + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + x = a[i] ^ b[j]; + if (mp[x] == 1) ans++; + } + } + if (ans % 2 == 0) + cout << "Karen\n"; + else + cout << "Koyomi\n"; +} +long long n, k, now; +int main() { + cin >> n >> k; + now = n / 2; + now -= now % (k + 1); + cout << now / (k + 1) << " " << now / (k + 1) * k << " " << n - now << endl; + return 0; +} +int p[4]; +int a, b; +int cnt; +int main() { + cin >> p[0] >> p[1] >> p[2] >> p[3] >> a >> b; + for (int i = a; i <= b; ++i) { + sort(p, p + 4); + int s = 0; + do { + if ((((i % p[0]) % p[1]) % p[2]) % p[3] == i) ++s; + } while (next_permutation(p, p + 4)); + if (s >= 7) ++cnt; + } + cout << cnt << endl; + return 0; +} +string S; +int x, satu, dua, tiga; +int main() { + cin >> S; + for (x = 0; x < S.length(); x += 2) { + if (S[x] == '1') satu++; + if (S[x] == '2') dua++; + if (S[x] == '3') tiga++; + } + for (x = 0; x < S.length(); x += 2) { + if (satu > 0) { + S[x] = '1'; + satu--; + } else if (dua > 0) { + S[x] = '2'; + dua--; + } else if (tiga > 0) { + S[x] = '3'; + tiga--; + } + } + cout << S << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + sort(s.begin(), s.end()); + int ct = 1; + int ans = s[0] - '0' - 48; + char prev = s[0]; + for (int i = 1; i < n && ct < k; i++) { + if (s[i] - prev > 1) { + ans = ans + (s[i] - '0' - 48); + ct++; + prev = s[i]; + } else { + continue; + } + } + if (ct < k) { + cout << -1 << endl; + } else { + cout << ans << endl; + } +} +int mid(int a, int b, int c) { + if ((a > b && a < c) || (a > c && a < b)) + return a; + else if ((b > a && b < c) || (b < a && b > c)) + return b; + else + return c; +} +int main() { + int a, b, c, sum = 0, x; + cin >> a >> b >> c; + x = mid(a, b, c); + sum = abs(a - x) + abs(b - x) + abs(c - x); + cout << sum << endl; + return 0; +} +char p1[22], p2[22]; +int main() { + cin >> p1 >> p2; + int len = strlen(p1); + int res1 = 0, res2 = 0; + for (int i = 0; i < len; i += 2) { + int p, v; + char a = p1[i]; + char b = p2[i]; + if (a == '(') + p = 0; + else if (a == '[') + p = 1; + else + p = 2; + if (b == '(') + v = 0; + else if (b == '[') + v = 1; + else + v = 2; + if (!p) { + if (v == 1) { + res2++; + } else if (v == 2) { + res1++; + } + } else if (p == 1) { + if (!v) { + res1++; + } else if (v == 2) { + res2++; + } + } else { + if (!v) { + res2++; + } else if (v == 1) { + res1++; + } + } + } + puts((res1 > res2) ? "TEAM 1 WINS" : (res1 < res2) ? "TEAM 2 WINS" : "TIE"); + return false; +} +int main() { + int n; + cin >> n; + string a[n][n]; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + for (int j = 0; j < n; j++) { a[i][j] = s[j]; } + } + int s = 0; + for (int i = 0; i < n; i++) { + int it1 = 0, it2 = 0; + for (int j = 0; j < n; j++) { + if (a[i][j] == "C") it1++; + if (a[j][i] == "C") it2++; + } + s += (it1 * (it1 - 1)) / 2 + (it2 * (it2 - 1)) / 2; + } + cout << s << endl; +} +int main() { + int i, j, k, n, m, ans = 0, mn, count = 0; + cin >> n >> m; + mn = min(n, m); + for (i = 1; i <= mn; i++) + if (m % i == 0 && m / i <= n) count++; + cout << count << endl; + return 0; +} +int main() { + int n, i, j, mnth, day; + cin >> mnth >> day; + int arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int totalday = arr[mnth]; + int otherday = totalday % 7; + int ans = totalday / 7; + if (totalday % 7 == 0 && day == 1) { + cout << ans << endl; + return 0; + } + if ((8 - day) < otherday) + ans += 2; + else + ans++; + cout << ans << endl; + return 0; +} +inline long long nxt() { + long long _x = 0, _tmp = 1; + char _tc = getchar(); + while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); + if (_tc == '-') _tc = getchar(), _tmp = -1; + while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar(); + return _x * _tmp; +} +int main() { + string a; + string b; + cin >> a >> b; + int cur = 0; + int last = -1; + for (int i = 0; i < a.size(); ++i) { + if (a[i] != b[i]) { + if (last == -1) last = i + 1; + for (int j = last; j < a.size(); ++j, ++last) { + if (a[j] != b[j] && b[j] == a[i]) { + swap(a[i], a[j]); + ++cur; + break; + } + } + } + if (a[i] != b[i]) ++cur; + } + cout << cur << endl; +} +int main() { + int n, b; + cin >> n; + b = n / 2 + 1; + cout << b << endl; + return 0; +} +int main() { + int n, m, c = 0, echo = 0; + bool alpha; + string str; + cin >> n >> m; + for (int i = 0; i < m; i++) { + cin >> str; + alpha = false; + for (int i = 0; i < n; i++) { + if (str[i] == '0') { + alpha = true; + c++; + break; + } + } + echo = max(echo, c); + if (!alpha) { c = 0; } + } + cout << echo << '\n'; + return 0; +} +long long n, x, a; +int main() { + cin >> n; + x = 2; + for (long long i = 1; i <= n; i++) { + a = i * (i + 1) * (i + 1) - x / i; + x = i * (i + 1); + cout << a << '\n'; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (size_t i = 0; i < s1.length(); ++i) { + if (s1[i] == s2[i]) { + s1[i] = '0'; + } else { + s1[i] = '1'; + } + } + cout << s1 << endl; + return 0; +} +const int N = 6e2 + 10; +int n, MAX; +string second; +int main() { + cin >> second; + int n = second.size(), p = 0; + while (p <= n) { + string t = second; + int k = 0; + if (p < n && t[p] == 'V') + t[p] = 'K'; + else if (p < n && t[p] == 'K') + t[p] = 'V'; + for (int i = 1; i < n; i++) { + if (t[i] == 'K' && t[i - 1] == 'V') k++; + } + MAX = max(MAX, k); + p++; + } + cout << MAX << '\n'; + return 0; +} +int main() { + bool a[10][10]; + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 4; j++) { a[i][j] = true; } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + int b; + cin >> b; + if (b % 2 == 1) { + a[i][j] = !a[i][j]; + a[i + 1][j] = !a[i + 1][j]; + a[i][j + 1] = !a[i][j + 1]; + a[i - 1][j] = !a[i - 1][j]; + a[i][j - 1] = !a[i][j - 1]; + } + } + } + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +long long f(long long n, long long m) { + long long count = 0, c, d; + while (n > 0 && m > 0) { + if (m > n) swap(n, m); + c = n - m; + d = c / m; + if (d == 0) { + n = n - m; + count++; + } else { + if (d * m != c) d++; + count += d; + n -= d * m; + } + } + return count; +} +long long n, m; +int main() { + long long t; + cin >> t; + while (t > 0) { + t--; + cin >> n >> m; + cout << f(n, m) << endl; + } + return 0; +} +vector mp; +int n, m, k; +int pre[100005], cnt[100005]; +bool cap[100005]; +int find(int x) { + return (pre[x] == x ? x : find(pre[x])); +} +void uion(int a, int b) { + int fa = find(a), fb = find(b); + if (fa != fb) { + pre[fa] = fb; + cnt[fb] += cnt[fa]; + } +} +int main() { + int c[100005], u, v; + int ans = 0, Max = 0; + while (cin >> n >> m >> k) { + for (int i = 1; i <= n; i++) { + pre[i] = i; + cnt[i] = 1; + } + memset(cap, 0, sizeof(cap)); + for (int i = 0; i < k; i++) cin >> c[i]; + for (int i = 0; i < m; i++) { + cin >> u >> v; + uion(u, v); + } + for (int i = 0; i < k; i++) cap[find(c[i])] = 1; + for (int i = 1; i <= n; i++) { + if (find(i) == i) { + if (cap[i]) + Max = max(Max, cnt[i]); + else + mp.push_back(cnt[i]); + ans += (cnt[i] - 1) * cnt[i] / 2; + } + } + for (int i = 0; i < mp.size(); i++) { + for (int j = i + 1; j < mp.size(); j++) { ans += mp[i] * mp[j]; } + ans += Max * mp[i]; + } + ans -= m; + cout << ans << endl; + } + return 0; +} +int main() { + int n, m, i, j, k; + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else { + if (i % 4 != 0 && j != m) { + cout << "."; + } else if (i % 4 != 0 && j == m) { + cout << "#"; + } else if (i % 4 == 0 && j != 1) { + cout << "."; + } else if (i % 4 == 0 && j == 1) { + cout << "#"; + } + } + } + cout << "\n"; + } +} +int main() { + long long n; + cin >> n; + long long ar[n + 1]; + for (int i = 0; i < n; i++) { cin >> ar[i]; } + sort(ar, ar + n); + long long count = 0; + long long temp = n - 2; + count = (ar[n - 1] - ar[0] - 1) - temp; + cout << (count) << "\n"; + return 0; +} +int main() { + long long int a, b, x, i, k = 1; + cin >> a >> b; + x = min(a, b); + for (i = 1; i <= x; i++) { k = k * i; } + cout << k << endl; + return 0; +} +long long n, i, current, ans, flag; +string s, s1; +int main() { + cin >> n; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == '1') ans++; + if (s[i] == '0') { + ans++; + break; + } + } + cout << ans << "\n"; + return 0; +} +int s(int k) { + int sum = 0; + while (k > 0) { + sum += k % 10; + k = int(k / 10); + } + return sum; +} +int main() { + long long x; + vector a(0); + cin >> x; + for (int i = 81; i > 0; i--) { + if (s(x - i) == i) a.push_back(x - i); + } + cout << a.size() << endl; + for (int i = 0; i < a.size(); i++) { cout << a[i] << endl; } + return 0; +} +int fastMax(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; +} +int fastMin(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; +} +void solve() { + long long int second, x; + cin >> second >> x; + if (second % 2 != x % 2) { + cout << 0 << endl; + return; + } + long long int ans = 1; + long long int andd = (second - x) / 2LL; + for (long long int i = 0; i < 41; i++) { + if (((1LL << i) & x)) { + if (!((1LL << i) & andd)) { + ans = 2LL * ans; + } else { + ans = 0; + break; + } + } + } + if (ans > 0 && second == x) ans -= 2; + cout << ans << endl; +} +int main() { + long long int t; + t = 1; + while (t--) solve(); +} +int main() { + int n, s; + cin >> n >> s; + if (s % n == 0) + cout << s / n << endl; + else + cout << s / n + 1 << endl; + return 0; +} +int main() { + string x; + string y; + cin >> x >> y; + for (int i = 0; i < x.size(); i++) { + if (x[i] < 97) x[i] += 32; + if (y[i] < 97) y[i] += 32; + } + if (x == y) + cout << 0 << endl; + else if (x > y) + cout << 1 << endl; + else + cout << -1 << endl; +} +int main() { + string s; + long long n, d, i, nex = 1, pre = 1, ans = 0; + cin >> n >> d; + char c[n]; + for (i = 0; i < n; i++) c[i] = '1'; + c[i] = '\0'; + for (i = 1; i <= d; i++) { + cin >> s; + if (s.compare(c) == 0) { + ans = max(ans, nex - pre); + pre = i + 1; + nex = i + 1; + } else { + nex++; + } + } + ans = max(ans, nex - pre); + cout << ans << endl; +} +int main() { + long long int n, a, b, kount = 0, x; + vector h; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + cin >> x; + h.push_back(x); + } + sort(h.begin(), h.end()); + if (h[b - 1] != h[b]) { kount = h[b] - h[b - 1]; } + cout << kount << endl; + return 0; +} +int n, a[100001]; +int main() { + cin >> n; + for (int i = 0; i < n - 1; i++) { + int buf; + cin >> buf; + a[buf] = 1; + } + for (int i = 1; i <= n; i++) { + if (a[i] == 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + while (cin >> n >> k >> l >> c >> d >> p >> nl >> np) { cout << min(min((k * l) / nl, c * d), p / np) / n << endl; } + return 0; +} +int main() { + int n, k, f, t, m, j; + cin >> n >> k >> f >> t; + if (t > k) { + m = f - (t - k); + } else { + m = f; + } + for (int i = 0; i < n; i++) { + cin >> f >> t; + if (t > k) { + j = f - (t - k); + } else { + j = f; + } + if (j > m) { m = j; } + } + cout << m << endl; + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0, height = 0; + while (sum <= n) { + height++; + sum += height * (height + 1) / 2; + } + cout << height - 1 << endl; + return 0; +} +long long solve(long long a, long long b) { + long long res = 0; + while (a * b != 0) { + if (a < b) swap(a, b); + res += a / b; + a -= (a / b) * b; + } + return res; +} +int main() { + int n; + cin >> n; + while (n--) { + long long a, b; + cin >> a >> b; + cout << solve(a, b) << endl; + } + return 0; +} +int main() { + int n, a, b, i, c = 0, d = 0; + cin >> a >> b >> n; + set s; + for (i = a; i <= n; i++) { + if (i % a == 0) { + c++; + s.insert(i); + } + } + for (i = b; i <= n; i++) { + if (i % b == 0) { + d++; + s.insert(i); + } + } + cout << (c + d) - s.size() << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long m; + m = sqrt(2 * n) - 1; + long long t; + for (long long i = m - 1; i <= m + 1; i++) + if (i * (i + 1) / 2 <= n && n <= (i + 1) * (i + 2) / 2) { + t = i; + break; + } + cout << n - t * (t + 1) / 2 << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + cout << "25" << endl; +} +int main() { + long long int n; + cin >> n; + cout << 2 * n - (n / 2) << endl; + return 0; +} +int n, tot; +string s; +int main() { + cin >> n >> s; + int ad = 1; + for (int i = 0; i < s.size(); i++) { + if (ad) { + if (s[i] == '1') { + ad = 1; + tot++; + } else { + ad = 0; + tot++; + } + } + } + cout << tot << endl; +} +int main() { + int n, t, numb, Max = 0; + char chara[102][1010] = {'\0'}; + cin >> n; + for (int i = 1; i <= n; i++) cin >> chara[i]; + for (char i = 'a'; i <= 'z'; i++) + for (char j = i; j <= 'z'; j++) { + numb = 0; + for (int b = 1; b <= n; b++) { + int g = strlen(chara[b]); + for (t = 0; t < g; t++) { + if (chara[b][t] != i && chara[b][t] != j) break; + } + if (t == g) numb += g; + if (numb > Max) Max = numb; + } + } + cout << Max << endl; + return 0; +} +map mp; +int main() { + int m, u, v; + char c; + string a[10]; + string b; + for (int i = 1; i <= 8; i++) { + for (int j = 1; j <= 10; j++) { + cin >> c; + a[i] += c; + } + } + for (int i = 0; i <= 9; i++) { + cin >> b; + mp[b] = i; + } + for (int i = 1; i <= 8; i++) { cout << mp[a[i]]; } + puts(""); +} +long long no[300001], appr[300001], st[300001]; +vector app[300001]; +int main() { + long long i, j, n, m, k, cnt = 0, ans = 0, t = 1; + cin >> n >> t; + vector v; + long long pos = 0; + while (t--) { + cin >> m >> k; + if (m == 1) { + no[cnt] = k; + app[k].push_back(cnt); + st[cnt] = 0; + v.push_back(cnt); + cnt++; + ans++; + } else if (m == 2) { + for (i = appr[k]; i < app[k].size(); i++) { + if (st[app[k][i]] == 0) ans--; + st[app[k][i]] = 1; + } + appr[k] = app[k].size(); + } else { + for (i = pos; i < k; i++) { + if (st[v[i]] == 0) ans--; + st[v[i]] = 1; + } + pos = max(pos, k); + } + cout << ans << '\n'; + } + return 0; +} +char a, b, x; +int n; +bool cek1, cek2; +int main() { + cin >> x >> b; + cin >> n; + a = x; + int ss = n % 4; + for (int i = 0; i < ss; i++) { + if (a == 'v') { + a = '<'; + } else if (a == '<') { + a = '^'; + } else if (a == '^') { + a = '>'; + } else if (a == '>') { + a = 'v'; + } + } + if (a == b) { cek1 = 1; } + a = x; + for (int i = 0; i < ss; i++) { + if (a == 'v') { + a = '>'; + } else if (a == '<') { + a = 'v'; + } else if (a == '^') { + a = '<'; + } else if (a == '>') { + a = '^'; + } + } + if (a == b) { cek2 = 1; } + if (cek1 == 1 && cek2 == 1) + cout << "undefined\n"; + else if (cek1 == 1) { + cout << "cw\n"; + } else { + cout << "ccw\n"; + } +} +int a[101], b[101], c[101]; +int main() { + long long int ans = 0; + int n, q; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + memset(c, 0, sizeof(c)); + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> q; + a[q]++; + c[q]++; + } + for (int i = 1; i <= n; i++) { + cin >> q; + b[q]++; + c[q]++; + } + for (int i = 1; i <= 5; i++) { + if (c[i] % 2 != 0) { ans = -2; } + c[i] /= 2; + } + if (ans != -2) { + for (int i = 1; i <= 5; i++) ans += abs(c[i] - a[i]); + } + cout << ans / 2 << endl; + return 0; +} +int main() { + int levels; + cin >> levels; + int x, y; + set myset; + for (int i = 0; i < 2; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> y; + myset.insert(y); + } + } + if (myset.size() == levels) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int main() { + int a[6], i, j, sum = 0; + for (i = 0; i < 5; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + int res = sum / 5; + if (sum == 0 || sum % 5 != 0) + cout << "-1" << endl; + else if (sum % 5 == 0) + cout << res << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + vector v(n); + for (size_t i = 0; i < n; i++) cin >> v[i]; + int sum = 0; + for (size_t i = 0; i < (n / 2 + ((n % 2) ? 1 : 0)); i++) { + if (v[i] == 2 && v[n - i - 1] == 2 && i != n - i - 1) + sum += 2 * min(a, b); + else if (v[i] == 2 && v[n - i - 1] == 2 && i == n - i - 1) + sum += min(a, b); + else if (v[i] == 2) + sum += ((v[n - i - 1] == 0) ? a : b); + else if (v[n - i - 1] == 2) + sum += ((v[i] == 0) ? a : b); + else if (v[i] != v[n - i - 1]) { + cout << "-1\n"; + return 0; + } + } + cout << sum << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + int l = s.size(); + int item = 25 * (l + 1) + 1; + cout << item << endl; +} +int main() { + int k, a[12], total(0); + cin >> k; + for (size_t i = 0; i < 12; ++i) { + cin >> a[i]; + total += a[i]; + } + if (total < k) { + cout << -1 << endl; + } else { + sort(a, a + sizeof(a) / sizeof(a[0]), greater()); + int sum = 0; + int month = 0; + while (sum < k) { + sum += a[month]; + month += 1; + } + cout << month << endl; + } + return 0; +} +const int maxn = 1e5 + 5; +int main() { + int ans = 0; + int a[4]; + while (cin >> a[1] >> a[2] >> a[3]) { + sort(a + 1, a + 4); + ans = 0; + while (a[1] + a[2] <= a[3]) { + ans++; + a[1]++; + } + cout << ans << endl; + } +} +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) + cout << 0 << endl; + else if (n == 20) + cout << 15 << endl; + else + cout << 4 << endl; +} +int read() { + int v = 0, f = 1; + char c = getchar(); + while (c < 48 || 57 < c) { + if (c == '-') f = -1; + c = getchar(); + } + while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); + return v * f; +} +int main() { + int m, d, flag = 0; + m = read(); + d = read(); + if (m == 2) { + if (d == 1) { + cout << "4" << '\n'; + return 0; + } else { + cout << "5" << '\n'; + return 0; + } + } + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) + flag = 1; + else if (m != 2) + flag = 0; + if (flag == 1) { + if (d >= 1 && d <= 5) + cout << "5" << '\n'; + else if (d == 6 || d == 7) + cout << "6" << '\n'; + return 0; + } else if (flag == 0) { + if (d >= 1 && d <= 6) + cout << "5" << '\n'; + else if (d == 7) + cout << "6" << '\n'; + return 0; + } + return 0; +} +int main() { + long long num; + cin >> num; + int count = 0; + while (num > 0) { + if (num % 10 == 4 || num % 10 == 7) count++; + num = num / 10; + } + if (count == 4 || count == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i <= 5000; i++) { + for (int j = 0; j <= 5000; j++) { + if (a * i + b * j == c) { + cout << "Yes" << endl; + return 0; + } + } + } + cout << "No" << endl; + return 0; +} +int main() { + int a, b, r; + cin >> a >> b >> r; + if (2 * r <= a && 2 * r <= b) + cout << "First\n"; + else + cout << "Second\n"; + return 0; +} +int main() { + string s, s1, s2, s3, s4, s5; + map m; + cin >> s >> s1 >> s2 >> s3 >> s4 >> s5; + for (int i = 0; i < s1.size(); i++) m[s1[i]] = 1; + for (int i = 0; i < s2.size(); i++) m[s2[i]] = 1; + for (int i = 0; i < s3.size(); i++) m[s3[i]] = 1; + for (int i = 0; i < s4.size(); i++) m[s4[i]] = 1; + for (int i = 0; i < s5.size(); i++) m[s5[i]] = 1; + bool x = false; + for (int i = 0; i < s.size(); i++) { + if (m.find(s[i]) == m.end()) + continue; + else { + x = true; + break; + } + } + if (x) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int t, x, y, p; + long long q, t1, t2, jav; + cin >> t; + while (t--) { + cin >> x >> y >> p >> q; + if (p == 0) { + jav = (x == 0) ? 0 : -1; + cout << jav << endl; + continue; + } + if (p == q) { + jav = (x == y) ? 0 : -1; + cout << jav << endl; + continue; + } + t1 = (x + p - 1) / p; + t2 = ((y - x) + (q - p) - 1) / (q - p); + jav = (q * max(t1, t2) - y); + cout << jav << endl; + } + return 0; +} +int main() { + int a, b, z; + cin >> a; + cin >> b; + int c = 1; + for (int i = 0; i < a; i++) { + c = c * 2; + if (i == 30) break; + } + z = b % c; + cout << z << endl; +} +int a[101][11]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + a[1][i] = 1; + a[i][1] = 1; + } + int nin = 1; + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { + a[i][j] = a[i - 1][j] + a[i][j - 1]; + if (a[i][j] > nin) nin = a[i][j]; + } + } + cout << nin << endl; +} +int main() { + int n, m, men = 0, men1 = 10; + cin >> n >> m; + int v[n + 1][m + 1]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) cin >> v[i][j]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (v[i][j] == 1) { + if (1 < i && i < n && 1 < j && j < m) { + if (m == 2) + men = 2; + else + men = 4; + } else + men = 2; + if (men1 > men) men1 = men; + } + } + } + cout << men1 << endl; + return 0; +} +int main() { + int a, b, c, ans = 0; + cin >> a >> b >> c; + for (int i = 1; i <= c; i++) { + if (i % a == 0 && i % b == 0) { ans++; } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int a[200]; + int one = 0, zero = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i]) one++; + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 0) zero++; + ans = max(ans, one + zero); + if (a[i] == 1) one--; + } + cout << ans << '\n'; +} +int main() { + int n, i, j, k, ans; + map ca, cb; + map::iterator it; + cin >> n; + string t; + for (i = 0; i < n; i++) { + cin >> t; + ca[t]++; + } + for (i = 0; i < n; i++) { + cin >> t; + cb[t]++; + } + ans = n; + for (it = ca.begin(); it != ca.end(); it++) { ans = ans - min(it->second, cb[it->first]); } + cout << ans << endl; + return 0; +} +int main() { + long n; + cin >> n; + int p = n / 2; + long q = p * 3; + cout << q << endl; +} +int main() { + vector a(3); + for (int i = 0; i < 3; i++) cin >> a[i]; + sort(a.begin(), a.end()); + cout << (a[1] - a[0]) + (a[2] - a[1]) << "\n"; +} +int main() { + int n; + cin >> n; + int sum = 0; + string s; + cin >> s; + for (int i = n; i < s.size(); i += n) { + if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) sum++; + } + cout << sum << endl; + return 0; +} +const int maxn = 100005; +int main() { + int n, count = 0; + int a[maxn], b[maxn]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b + 1, b + 1 + n); + for (int i = 1; i <= n; i++) + if (b[i] != a[i]) count++; + if (count >= 3) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int x, y, x1, y1, A; + cin >> x >> y; + if (x < 0) + x1 = -x; + else + x1 = x; + if (y < 0) + y1 = -y; + else + y1 = y; + A = x1 + y1; + if (x > 0 && y > 0) { + cout << 0 << " " << A << " " << A << " " << 0 << endl; + return 0; + } + if (x < 0 && y < 0) { + cout << -A << " " << 0 << " " << 0 << " " << -A << endl; + return 0; + } + if (x > y) + cout << 0 << " " << -A << " " << A << " " << 0 << endl; + else if (x < y) + cout << -A << " " << 0 << " " << 0 << " " << A << endl; + return 0; +} +int main() { + string s, s2; + cin >> s; + cin >> s2; + for (int i = 0; i < s.length(); i++) { + int g = 1; + g = s[i] ^ s2[i]; + cout << g; + } + cout << "\n"; + return 0; +} +int main() { + long long int n, k, m; + cin >> n >> k; + m = 2 * k; + if (n % m >= k) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long int n, k, l, c, d, p, nl, np, minn = INT_MAX; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + minn = min(minn, (k * l) / (n * nl)); + minn = min(minn, c * d / n); + minn = min(minn, p / (n * np)); + cout << minn << endl; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int b = n - k; + int count = 0, i = 0; + while (b--) { + count += arr[i]; + i++; + } + cout << count + k * x << endl; + return 0; +} +int minn = INT_MAX, maxx, n, m, x; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x; + minn = min(minn, x); + maxx = max(maxx, x); + } + maxx = max(minn * 2, maxx); + for (int i = 0; i < m; i++) { + cin >> x; + if (x <= maxx) { return cout << -1 << endl, 0; } + } + cout << maxx << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], min = 100; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < min) min = a[i]; + } + int i, j; + for (i = min; i > 0; i--) { + for (j = 0; j < n; j++) { + if (a[j] % i != 0) break; + } + if (j == n) { + cout << n * i << endl; + break; + } + } + return 0; +} +long long a, b, c, e, f; +int main() { + cin >> a; + if (a % 2) + cout << 1 << endl; + else + cout << 2 << endl; +} +int main() { + string s; + cin >> s; + int n = s.size(); + int mayu = 0, minu = 0; + for (int i = 0; i < n; i++) { + if (isupper(s[i])) + mayu++; + else + minu++; + } + if (minu >= mayu) { + for (int i = 0; i < n; i++) s[i] = tolower(s[i]); + } else { + for (int i = 0; i < n; i++) s[i] = toupper(s[i]); + } + cout << s << endl; + return 0; +} +int main() { + int i, j, l; + string s; + cin >> s; + l = s.size(); + for (i = 0; i < l; i++) { + for (j = 0; j < l - i - 2; j += 2) { + if (s[j] > s[j + 2]) { swap(s[j], s[j + 2]); } + } + } + cout << s << endl; + return 0; +} +int n, a, b; +int main() { + cin >> n >> a >> b; + cout << min(n - a, b + 1) << endl; + return 0; +} +int main() { + unsigned long long n, item, temp; + cin >> n; + if (n % 2 == 0) { + item = n / 2; + temp = n * 2 - item; + cout << temp << endl; + } + return 0; +} +int n, i; +int main() { + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +int main() { + int n, m; + cin >> m >> n; + if (n % m == 0) + cout << n / m << endl; + else + cout << n / m + 1 << endl; + return 0; +} +int main() { + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) { + if (i == 0 && str[i] == '9') { continue; } + if (str[i] > '4') { str[i] = '9' - str[i] + 48; } + } + cout << str << endl; + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int a, b, a2, b2, a1 = 0, b1 = 0; + cin >> a >> b; + if (a > b) { + a2 = a; + for (int i = 0; i < a2; i++) { + if (b != 0) { + a1++; + b--; + a--; + } + if (b == 0) { b1 = a / 2; } + } + } else if (a < b) { + b2 = b; + for (int i = 0; i < b2; i++) { + if (a != 0) { + a1++; + b--; + a--; + } + if (a == 0) { b1 = b / 2; } + } + } else { + a1 = (a + b) / 2; + } + cout << a1 << " " << b1 << endl; + return 0; +} +int main() { + int n, p, s; + cin >> n >> p; + string T; + cin >> T; + s = T.size(); + int a[s]; + for (int i = 0; i < s; ++i) { a[i] = (T[i] - 'a'); } + int ind = n; + bool init = true; + while (ind >= 0) { + if (ind == n) { + --ind; + if (init) { + init = false; + continue; + } + for (int i = 0; i < s; ++i) cout << "abcdefghijklmnopqrstuvwxyz"[a[i]]; + cout << "\n"; + return 0; + } + for (a[ind] = a[ind] + 1; a[ind] < p; ++a[ind]) { + if (!(ind >= 1 && a[ind] == a[ind - 1] || ind >= 2 && a[ind] == a[ind - 2])) break; + } + if (a[ind] == p) { + a[ind--] = -1; + } else + ++ind; + } + cout << "NO\n"; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + long long int ans, x, y, x1, y1; + cin >> x >> y >> x1 >> y1; + ans = max(abs(x - x1), abs(y - y1)); + cout << ans << endl; +} +int main() { + int a[3], k; + long long r[] = {1, 1, 1}; + cin >> a[0] >> a[1] >> a[2] >> k; + sort(a, a + 3); + if (k <= (a[0] - 1) * 3) { + for (int i(0); i < 3; ++i) r[i] += k / 3 + (i < k % 3); + } else { + r[0] = a[0]; + k -= a[0] - 1; + if (k <= (a[1] - 1) * 2) { + for (int i(0); i < 2; ++i) r[i + 1] += k / 2 + (i < k % 2); + } else { + r[1] = a[1]; + k -= a[1] - 1; + r[2] = min(k + 1, a[2]); + } + } + cout << r[0] * r[1] * r[2] << endl; + return 0; +} +int main() { + long long q, n; + char s; + long long num1, num2 = 0; + cin >> q; + for (long long i = 0; i < q; i++) { + cin >> n; + cin >> s; + num1 = s - 48; + if (n == 2) { + cin >> s; + num2 = s - 48; + if (num1 >= num2) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << 2 << endl; + cout << num1 << " " << num2 << endl; + } + } else { + cout << "YES" << endl; + cout << 2 << endl; + cout << num1 << " "; + for (long long j = 1; j < n; j++) { + cin >> s; + cout << s; + } + cout << endl; + num2 = 0; + num1 = 0; + } + } +} +int main() { + string s1; + int a[7] = {0, 0, 0, 0, 0, 0, 0}; + cin >> s1; + for (int i = 0; i < s1.length(); i++) { + if (s1[i] == 'B') + a[0]++; + else if (s1[i] == 'u') + a[1]++; + else if (s1[i] == 'l') + a[2]++; + else if (s1[i] == 'b') + a[3]++; + else if (s1[i] == 'a') + a[4]++; + else if (s1[i] == 's') + a[5]++; + else if (s1[i] == 'r') + a[6]++; + } + a[1] = a[1] / 2; + a[4] = a[4] / 2; + sort(a, a + 7); + cout << a[0] << endl; +} +long long c(long long n, long long r) { + long long ans = 1; + for (long long i = 2; i <= n; i++) ans *= i; + for (long long i = 2; i <= r; i++) ans /= i; + for (long long i = 2; i <= n - r; i++) ans /= i; + return ans; +} +int main() { + long long n; + cin >> n; + n = (2 * n - 2); + cout << c(n, (n + 1) / 2) << endl; + return 0; +} +int main() { + int n, k, ans = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + ans += (b - a + 1); + } + if (ans % k == 0) + cout << 0 << endl; + else { + cout << (ans / k + 1) * k - ans << endl; + } +} +bool lucky(int z) { + return z % 10 == 7; +} +int main() { + int x, h, m, res = 0; + cin >> x >> h >> m; + while (!lucky(h) && !lucky(m)) { + m += (h + 24) * 60 - x; + h = (m / 60) % 24; + m %= 60; + res++; + } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a = 0, b = 0; + int cnta = 0, cntb = 0; + int suma = 0, sumb = 0; + int fg = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + suma += a; + sumb += b; + if (a % 2) cnta++; + if (b % 2) cntb++; + if (a % 2 != b % 2) fg = 1; + } + if ((suma % 2 == 0) && (sumb % 2 == 0)) + cout << 0 << endl; + else if ((suma % 2 == 1) && (sumb % 2 == 1) && fg) + cout << 1 << endl; + else + cout << -1 << endl; +} +int main() { + int n, m, c, mishka = 0, chris = 0; + cin >> n; + while (n--) { + cin >> m >> c; + if (m > c) + mishka++; + else if (m < c) + chris++; + } + if (mishka < chris) + cout << "Chris" << endl; + else if (mishka > chris) + cout << "Mishka" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + long long x, a[15], b[105], k; + string s; + while (cin >> s) { + x = 0, k = 0; + int j = 0; + for (int i = 0; s[i] != '\0'; i++) { + a[i] = s[i] - 48; + x *= 10; + x += a[i]; + } + if (x >= 100) + for (int i = x - 100; i <= x; i++) { + int y = i; + int n = i; + while (y) { + n += y % 10; + y /= 10; + } + if (n == x) { + b[j] = i; + j++; + k++; + } + } + else { + for (int i = 1; i <= x; i++) { + int y = i; + int n = i; + while (y) { + n += y % 10; + y /= 10; + } + if (n == x) { + b[j] = i; + j++; + k++; + } + } + } + if (k == 0) + cout << k << endl; + else { + sort(b, b + j); + cout << k << endl; + for (int i = 0; i < j; i++) cout << b[i] << endl; + } + } + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int n; + cin >> n; + int g[n][n]; + for (int i = 0; i < n; i += 1) + for (int j = 0; j < n; j += 1) cin >> g[i][j]; + for (int i = 0; i < n; i += 1) + for (int j = 0; j < n; j += 1) { + if (g[i][j] == 1) continue; + int flag = 0; + for (int r = 0; r < n; r += 1) + for (int c = 0; c < n; c += 1) { + if (r == j || c == i) continue; + if (g[i][r] + g[c][j] == g[i][j]) flag = 1; + } + if (!flag) { + cout << "No\n"; + return 0; + } + } + cout << "Yes\n"; +} +long long int j[1000], l[1000], k, g, h[1000], o = -1; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < m; i++) { + k = -1; + for (int y = 0; y < n; y++) { + cin >> j[y]; + if (j[y] > k) { + l[i] = y + 1; + k = j[y]; + } + } + h[l[i]]++; + } + for (int u = 1; u <= n; u++) { + if (h[u] > o) { + o = h[u]; + g = u; + } + } + cout << g << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + char arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + char x = arr[0][0]; + char y = arr[0][1]; + if (x == y) { + cout << "NO" << endl; + return 0; + } else { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j || (i + j) == n - 1) { + if (arr[i][j] == x) { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } else { + if (arr[i][j] == y) { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } + } + } + } + cout << "YES" << endl; + return 0; +} +const int maxn = 100005; +const int INF = 0x3fffffff; +double eps = 1e-8; +double pi = acos(-1); +int f[maxn]; +int g[maxn]; +int a[maxn]; +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[i] > a[i - 1]) + f[i] = f[i - 1] + 1; + else + f[i] = 1; + } + for (int i = n; i >= 1; i--) { + if (a[i] < a[i + 1]) + g[i] = g[i + 1] + 1; + else + g[i] = 1; + } + int ans = 0; + for (int i = 1; i <= n; i++) { + if (a[i + 1] - a[i - 1] > 1) { + ans = max(ans, f[i - 1] + g[i + 1] + 1); + } else { + ans = max(ans, max(f[i - 1] + 1, g[i + 1] + 1)); + } + } + cout << ans << endl; +} +long long p[200000]; +long long s[200000]; +int main() { + long long num = 0; + long long n, i, j; + cin >> n; + for (i = 2; i <= n; i++) { cin >> p[i]; } + for (i = 1; i <= n; i++) { + cin >> s[i]; + if (s[i] == -1) s[i] = 1e10; + } + for (i = 1; i <= n; i++) s[p[i]] = min(s[p[i]], s[i]); + for (i = 1; i <= n; i++) { + if (s[p[i]] > s[i]) { + cout << -1 << endl; + return 0; + } + if (s[i] == 1e10) s[i] = s[p[i]]; + num += s[i] - s[p[i]]; + } + cout << num << endl; + return 0; +} +int main() { + long long c, l, r; + cin >> c >> l >> r; + long long n; + cin >> n; + long long arr[n]; + long long tot = 0; + for (long long i = 0; i < n; ++i) { + cin >> arr[i]; + if (arr[i] > l && arr[i] < r) { ++tot; } + } + cout << tot << '\n'; +} +const int N = 1e5 + 5; +const int M = 1e5 + 5; +int main() { + int n, i, s[2 * N]; + cin >> n; + for (i = 0; i < n; i++) { cin >> s[i]; } + sort(s, s + n); + if (n == 2) { + cout << s[1] - s[0] << endl; + return 0; + } + int ans; + int tu = (n - 2) / 2; + for (i = 1 + tu; i < n; i++) { + if (i == 1 + tu) { + ans = s[i] - s[i - (1 + tu)]; + } else + ans = min(ans, s[i] - s[i - (1 + tu)]); + } + cout << ans << endl; + return 0; +} +int mini(int a, int b) { + if (a < b) return a; + return b; +} +int main() { + int n, z = 0, o = 0; + cin >> n; + string str; + cin >> str; + for (int i = 0; i < n; ++i) { + if (str[i] == '1') + o++; + else + z++; + } + int ans = n - (2 * mini(o, z)); + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; ++i) { cin >> a[i]; } + int opt = -1; + for (int i = 0; i < n; ++i) { + if ((int)(a[i]).size() < (int)(s).size()) { continue; } + if (a[i].substr(0, (int)(s).size()) != s) { continue; } + if (opt == -1 || a[i] < a[opt]) { opt = i; } + } + if (opt != -1) { + cout << a[opt]; + } else { + cout << s; + } + cout << "\n"; +} +int main() { + long n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + int time = 0; + long ta, tb, fa, fb; + cin >> ta >> fa >> tb >> fb; + if (fa >= a && fa <= b) { + time = abs(tb - ta); + time += abs(fb - fa); + cout << time << endl; + } else { + if (tb != ta) { + int nearest; + if (fa < a) { + nearest = a; + } else { + nearest = b; + } + time += abs(tb - ta); + time += abs(nearest - fa); + time += abs(fb - nearest); + cout << time << endl; + } else + cout << abs(fb - fa) << endl; + time = 0; + } + } +} +int main() { + long long T, n, x, y, d; + cin >> T; + while (T--) { + cin >> n >> x >> y >> d; + if ((x - y) % d == 0) { + cout << abs((x - y) / d) << endl; + } else { + long long f = 1e10; + if ((y - 1) % d == 0) { f = ((y - 1) / d) + ((x - 1) / d) + ((x - 1) % d != 0); } + long long l = 1e10; + if ((n - y) % d == 0) { l = ((n - y) / d) + ((n - x) / d) + ((n - x) % d != 0); } + long long ans = min(l, f); + if (ans == 1e10) + cout << -1 << endl; + else + cout << ans << endl; + } + } +} +int main() { + int n, mx = 0, count = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] >= mx) mx = arr[i]; + } + int x = arr[0]; + while (1) { + for (int i = 1; i < n; i++) { + if (arr[i] == mx) { + if (x > mx) break; + arr[i] = arr[i] - 1; + x++; + count++; + } + } + mx--; + if (x > mx) break; + } + cout << count << endl; + return 0; +} +int main() { + int n; + string s1, s2, s, p; + while (cin >> s1 >> s2) { + cin >> n; + cout << s1 << " " << s2 << endl; + while (n--) { + cin >> s >> p; + if (s1 == s) + s1 = p; + else + s2 = p; + cout << s1 << " " << s2 << endl; + } + } + return 0; +} +int main() { + long int n, i, ptr = 0; + long int lenght[1000]; + cin >> n; + long int money[n]; + long int max = 1, tmp = 1; + for (i = 0; i < n; i++) { + cin >> money[i]; + if (i == 0) + continue; + else { + if (money[i] >= money[i - 1]) { + max++; + if (max > tmp) { tmp = max; } + } else + max = 1; + } + } + cout << tmp << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector a(n); + vector exist(105, false); + for (int i = 0; i < n; i++) { + cin >> a[i]; + exist[a[i]] = true; + } + int mx = 0; + for (int i = 1; i * i <= k; i++) { + if (k % i == 0) { + if (exist[i]) mx = max(mx, i); + if (exist[k / i]) mx = max(mx, k / i); + } + } + cout << k / mx << '\n'; + return 0; +} +int freq[10000005]; +int n, m, x, to; +int main() { + cin >> n >> m; + memset(freq, 0, sizeof freq); + for (int i = 0; i < n; i++) { + cin >> x >> to; + for (int j = x + 1; j <= to; j++) freq[j]++; + } + for (int i = 1; i <= m; i++) { + if (!freq[i]) { + puts("NO"); + return 0; + } + } + puts("YES"); + return 0; +} +int main() { + long a = 0, b = 0, c = 0, x = 0, k = 0, y = 0; + cin >> a >> b; + for (int d = 1; d <= a; d++) { + cin >> c; + x = 86400 - c; + b -= x; + if (b <= 0 && y == 0) { + y = 1; + k = d; + } + } + cout << k << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int g = 0, mx = -1; + for (long long int i = 0; i < n; i++) { + long long int x; + cin >> x; + g = __gcd(g, x); + mx = max(mx, x); + } + if ((mx / g - n) % 2) + cout << "Alice" << '\n'; + else + cout << "Bob" << '\n'; +} +const int mod = 998244353; +long long qpow(long long x, long long y) { + long long s = 1; + while (y) { + if (y & 1) s = s * x % mod; + x = x * x % mod; + y >>= 1; + } + return s; +} +inline long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); + return x * f; +} +long long inve(long long x) { + return x == 1 ? 1 : (mod - mod / x) * inve(mod % x) % mod; +} +char s[150][150]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> (s[i] + 1); + int ti, tj; + int w = 0, h = 0; + for (int i = 1; i <= n; i++) { + int f = 0; + for (int j = 1; j <= m; j++) { + if (s[i][j] == 'B') { + ti = i, tj = j; + f = 1; + break; + } + } + if (f) break; + } + for (int j = tj; j <= m; j++) + if (s[ti][j] == 'B') + w++; + else + break; + for (int i = ti; i <= n; i++) + if (s[i][tj] == 'B') + h++; + else + break; + cout << (h / 2 + ti) << " " << (w / 2 + tj) << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10) { + cout << "0\n"; + return 0; + } else if (n == 11) { + cout << "4\n"; + return 0; + } else if (n >= 12 and n <= 19) { + cout << "4\n"; + return 0; + } else if (n == 20) { + cout << "15\n"; + } else if (n == 21) { + cout << "4\n"; + return 0; + } else if (n >= 22) { + cout << "0\n"; + return 0; + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 1; i < n; i++) { + if (s[i] != s[i - 1]) { + cout << "YES\n" << s[i - 1] << s[i] << endl; + return 0; + } + } + cout << "NO" << endl; +} +const long long INF = (1ll << 62) - 1; +const int M = 1e5 + 5; +int main() { + long long x, y, m, ans = 0; + cin >> x >> y >> m; + long long mx = max(x, y); + if (mx >= m) { + cout << 0 << endl; + return 0; + } + if (mx <= 0) { + cout << -1 << endl; + return 0; + } + if (x > y) swap(x, y); + if (x <= 0) { + ans = -x / y; + x = x + (ans * y); + } + while (max(x, y) < m) { + ans++; + if (x > y) swap(x, y); + x += y; + } + cout << ans << endl; +} +void getSoroban(int n) { + if (n < 5) + cout << "O-|"; + else + cout << "-O|"; + for (int i = 0; i < n % 5; i++) { cout << 'O'; } + cout << '-'; + for (int i = 0; i < 4 - n % 5; i++) { cout << 'O'; } + cout << endl; +} +int main() { + int n; + cin >> n; + if (n == 0) { + cout << "O-|-OOOO" << endl; + return 0; + } + while (n) { + getSoroban(n % 10); + n /= 10; + } + return 0; +} +long long i, j, k, n, m, a[100009], ans, sz, c1, c2, x, ch[26], f, z; +int main() { + string s; + cin >> k >> s; + sz = s.size(); + set st; + set::iterator it; + for (i = 0; i < sz; i++) { + st.insert(s[i]); + ch[s[i] - 'a']++; + } + vector v; + for (it = st.begin(); it != st.end(); it++) { + char c; + c = *it; + v.push_back(ch[c - 'a']); + } + sz = v.size(); + for (i = 0; i < sz; i++) { + if (v[i] % k != 0) { + f = 1; + break; + } + } + if (f) { + cout << "-1" << endl; + return 0; + } else { + string ss; + for (it = st.begin(); it != st.end(); it++) { + char c; + c = *it; + z = ch[c - 'a'] / k; + for (i = 0; i < z; i++) ss += c; + } + for (i = 0; i < k; i++) cout << ss; + cout << endl; + } + return 0; +} +int n, m; +string s; +int main() { + cin >> n >> m >> s; + int v1 = m - 1, v2 = n - m; + if (v1 < v2) { + for (int i = 0; i < v1; ++i) + cout << "LEFT" + << "\n"; + for (int i = 0; i < s.size(); ++i) { + if (i != 0) + cout << "RIGHT" + << "\n"; + cout << "PRINT " << s[i] << "\n"; + } + } else { + for (int i = 0; i < v2; ++i) + cout << "RIGHT" + << "\n"; + for (int i = s.size() - 1; i >= 0; --i) { + cout << "PRINT " << s[i] << "\n"; + if (i != 0) + cout << "LEFT" + << "\n"; + } + } + return 0; +} +int n, k, aux = 2; +vector resp; +int main() { + cin >> n >> k; + while (k && n != 1) { + if (k == 1) { + resp.push_back(n); + k--; + } else if (n % aux == 0) { + n /= aux; + resp.push_back(aux); + k--; + } else { + aux++; + } + } + if (k) { + cout << "-1\n"; + } else { + for (int i = 0; i < (int)resp.size(); ++i) { cout << resp[i] << " \n"[i == (int)resp.size() - 1]; } + } + return 0; +} +string a, b; +bool cmp(string x, string y) { + int lx = x.length(), ly = y.length(); + if (lx < ly) return 1; + if (lx > ly) return 0; + return x < y; +} +int main() { + cin >> a >> b; + if (cmp(a, b) == 1) + cout << "1" << endl; + else + cout << a << endl; + return 0; +} +int main() { + string word; + cin >> word; + int lc = 0, uc = 0; + for (int i = 0; i < word.length(); i++) { + if (word[i] >= 'A' && word[i] <= 'Z') + uc++; + else + lc++; + } + if (uc > lc) { + transform(word.begin(), word.end(), word.begin(), ::toupper); + cout << word << endl; + } else if (uc == lc) { + transform(word.begin(), word.end(), word.begin(), ::tolower); + cout << word << endl; + } else { + transform(word.begin(), word.end(), word.begin(), ::tolower); + cout << word << endl; + } +} +int main() { + int n, k, a, b, c, x, y, z, s; + cin >> n >> k; + a = (n * 2); + b = (n * 5); + c = (n * 8); + if (a < k) { + x = 1; + } else { + if (a % k == 0) { + x = (a / k); + } else { + x = (a / k) + 1; + } + } + if (b < k) { + y = 1; + } else { + if (b % k == 0) { + y = (b / k); + } else { + y = (b / k) + 1; + } + } + if (c < k) { + z = 1; + } else { + if (c % k == 0) { + z = (c / k); + } else { + z = (c / k) + 1; + } + } + s = x + y + z; + cout << s << endl; + return 0; +} +int main() { + int n; + vector a; + cin >> n; + for (int i = 0; i < n; i++) { + int k; + cin >> k; + a.push_back(k); + } + int min = a[0], max = a[0]; + for (int i = 0; i < a.size(); i++) { + if (a[i] > max) max = a[i]; + if (a[i] < min) min = a[i]; + } + cout << min + (max - min) / 2 << endl; + return 0; +} +void Doaa() {} +int main() { + Doaa(); + int n, m, count = 0, d = 0; + cin >> m; + vector des(m); + for (int i = 0; i < m; i++) cin >> des[i]; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + sort(des.begin(), des.end()); + sort(v.begin(), v.end()); + for (int k = n - 1; k >= 0; k -= des[0] + 2) + for (int j = 0; j < des[0] && k - j >= 0; j++) count += v[k - j]; + cout << count << endl; + return 0; +} +int main() { + int number; + string temp; + cin >> number; + string name[number]; + for (int i = 0; i < number; i++) { cin >> name[i]; } + for (int i = 0; i < number; i++) { + if (name[i].size() > 10) { + int num = name[i].size() - 2; + cout << name[i][0] << num << name[i][name[i].size() - 1] << endl; + } else + cout << name[i] << endl; + } + return 0; +} +int main() { + int n, ma, mi, c = 0; + cin >> n; + int x; + cin >> x; + mi = ma = x; + for (int i = 1; i < n; i++) { + cin >> x; + if (x > ma) { + ma = x; + c++; + } + if (x < mi) { + mi = x; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + cin >> n; + map mp; + int arr[n]; + vector v; + vector va; + vector vb; + vector vc; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + mp[arr[i]]++; + } + map::iterator it; + for (it = mp.begin(); it != mp.end(); it++) { v.push_back(it->second); } + sort(v.begin(), v.end()); + int a = v[0]; + if (a == 0 || mp.size() < 3) { + cout << "0" << endl; + } else { + for (int i = 0; i < n; i++) { + if (arr[i] == 1) { va.push_back(i); } + if (arr[i] == 2) { vb.push_back(i); } + if (arr[i] == 3) { vc.push_back(i); } + } + int i = 0; + cout << a << endl; + while (a--) { + cout << va[i] + 1 << " " << vb[i] + 1 << " " << vc[i] + 1 << endl; + i++; + } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int k = 0; + int i, j; + int p; + cin >> i; + int *r = new int[i + 1](); + for (p = 0; p < i; p++) { cin >> r[p]; } + cin >> j; + int *u = new int[j + 1](); + for (p = 0; p < j; p++) { cin >> u[p]; } + int *m = new int[i + j + 1](); + for (p = 0; p < i; p++) { m[p] = r[p]; } + int t = p; + for (p = 0; p < j; p++) { m[t + p] = u[p]; } + int y; + for (p = 1; p <= n; p++) { + for (y = 0; y < i + j; y++) { + if (m[y] == p) { break; } + } + if (y == i + j) { k = 1; } + } + if (k == 0) { cout << "I become the guy." << endl; } + if (k == 1) { cout << "Oh, my keyboard!" << endl; } + } + return 0; +} +int main() { + long long n; + cin >> n; + vector a[4]; + while (n--) { + string x, y; + cin >> x >> y; + if (y == "rat") + a[0].push_back(x); + else if (y == "woman" || y == "child") + a[1].push_back(x); + else if (y == "man") + a[2].push_back(x); + else if (y == "captain") + a[3].push_back(x); + } + for (long long i = 0; i < 4; i++) { + for (long long j = 0; j < a[i].size(); j++) cout << a[i][j] << endl; + } +} +int main() { + double l, p, q; + cin >> l >> p >> q; + cout << p * l / (p + q) << endl; +} +int main() { + int x; + cin >> x; + int c = 0; + c = x / 5; + if (x % 5) c++; + cout << c << endl; + return 0; +} +long long x, y, p, q; +bool Check(long long mid) { + long long tmp = p * mid; + long long tmp1 = q * mid; + return (tmp >= x and tmp1 >= y and tmp - x <= tmp1 - y); +} +long long Khela_Hobe() { + long long lo = 0, hi = 1e9, ans = -1; + while (lo <= hi) { + long long mid = (lo + hi) / 2; + if (Check(mid)) { + ans = mid; + hi = mid - 1; + } else { + lo = mid + 1; + } + } + if (ans == -1) return ans; + return q * ans - y; +} +int main() { + int tc; + cin >> tc; + while (tc--) { + cin >> x >> y >> p >> q; + cout << Khela_Hobe() << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int k; + int x; + int cnt = 0; + set towhid; + while (n--) { + cin >> x; + while (x--) { + cin >> k; + towhid.insert(k); + } + } + int sz = towhid.size(); + if (sz == m) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + vector v; + vector v1; + vector v2; + int k, c = 0, temp, gh = 0; + cin >> k; + char ch; + string s, ans; + cin >> s; + string s1 = s; + sort(s1.begin(), s1.end()); + for (int i = 0; i < s1.size(); i++) { + c = 0; + if (s1[i] != s1[i + 1]) { + ch = s1[i]; + v2.push_back(ch); + for (int j = 0; j < s.size(); j++) { + if (s[j] == ch) { c++; } + } + int temp = c; + v.push_back(temp); + } + } + for (int i = 0; i < v.size(); i++) { + if (v[i] % k == 0) { + int f = v[i] / k; + v1.push_back(f); + } else { + gh = -1; + break; + } + } + for (int i = 0; i < v1.size(); i++) { + int m = v1[i]; + char g = v2[i]; + while (m > 0) { + ans += g; + m--; + } + } + string sum = ""; + int our = k - 1; + while (our >= 0) { + sum += ans; + our--; + } + if (gh == -1) { + cout << -1 << endl; + } else { + cout << sum << endl; + } + return 0; +} +int w, h, w1, h1, w2, h2; +int main() { + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w <= 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w <= 0) w = 0; + } + } + cout << w << endl; + return 0; +} +int main() { + int m, n, num = 1; + cin >> m >> n; + for (int j = 0; j < m; j++) { + if (j % 2 == 0) { + for (int k = 0; k < n; k++) cout << "#"; + cout << endl; + num *= -1; + } else { + if (num < 0) { + for (int k = 0; k < n - 1; k++) cout << "."; + cout << "#" << endl; + } else { + cout << "#"; + for (int k = 0; k < n - 1; k++) cout << "."; + cout << endl; + } + } + } +} +int main() { + int q, t; + long long int sum = 0; + vector v; + cin >> q; + for (int i = 0; i < q; i++) { + cin >> t; + sum += t; + v.push_back(t); + } + sort(v.begin(), v.end()); + long long int score = sum; + for (int j = 0; j < q - 1; j++) { + score += sum; + sum -= v[j]; + } + cout << score << endl; + return 0; +} +int main() { + int i, n, p, q, cnt = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> p >> q; + if ((q - p) >= 2) { cnt++; } + } + cout << cnt << endl; + return 0; +} +inline char small_letter(char ch) { + return (ch < 97) ? ch + 32 : ch; +} +int main() { + unsigned long long n, m, ans, i, temp; + cin >> n >> m; + for (ans = n, temp = n, i = 0; temp > 0; ans = ans * m + n, temp /= m, i++) + ; + cout << int(ans / pow(m, i)) << endl; + return 0; +} +int mark[10]; +int main() { + long long int n, i, ans, mx, m, l; + char str[110]; + cin >> str; + l = strlen(str); + ans = str[0] - 97; + if (ans > 13) ans = 26 - ans; + for (i = 1; i < l; i++) { + m = str[i] - str[i - 1]; + m = abs(m); + if (m > 13) m = 26 - m; + ans += m; + } + cout << ans << endl; +} +int main() { + string x; + int len; + cin >> x; + len = x.length() - 1; + int QQ[len + 5]; + int AQ[len + 5]; + int Q[len + 5]; + Q[len] = (x[len] == 'Q') ? 1 : 0; + AQ[len] = 0; + QQ[len] = 0; + for (int i = len - 1; i >= 0; i--) { + if (x[i] == 'A') { + AQ[i] = AQ[i + 1] + Q[i + 1]; + QQ[i] = QQ[i + 1]; + Q[i] = Q[i + 1]; + } else if (x[i] == 'Q') { + AQ[i] = AQ[i + 1]; + QQ[i] = QQ[i + 1] + AQ[i + 1]; + Q[i] = Q[i + 1] + 1; + } else { + AQ[i] = AQ[i + 1]; + QQ[i] = QQ[i + 1]; + Q[i] = Q[i + 1]; + } + } + cout << QQ[0] << endl; +} +int guest[101]; +int home[101]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int h, a; + cin >> h >> a; + home[i] = h; + guest[a] = guest[a] + 1; + } + int ans = 0; + for (int i = 0; i < n; i++) { ans = ans + guest[home[i]]; } + cout << ans << endl; + return 0; +} +int main() { + int n, i = 0, j, m, t; + cin >> n >> m; + string s; + t = n; + while (t--) { + cin >> s; + for (j = 0; j < m; j++) { + if (s[j] == '.') { + if (i % 2 == 0) { + if (j % 2 == 0) + s[j] = 'B'; + else + s[j] = 'W'; + } else { + if (j % 2 == 0) + s[j] = 'W'; + else + s[j] = 'B'; + } + } + } + cout << s << endl; + i++; + } + return 0; +} +bool distinct(int n) { + set d; + while (n > 0) { + d.insert(n % 10); + n = n / 10; + } + return (d.size() == 4); +} +int main() { + int n; + cin >> n; + int i = n + 1; + while (true) { + if (distinct(i) && (i > n)) { + cout << i << endl; + return 0; + } + i++; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int p[n]; + for (int i = 0; i < n; i++) { cin >> a[i] >> p[i]; } + int sum = 0; + int prise = 1000; + for (int i = 0; i < n; i++) { + prise = min(prise, p[i]); + sum += prise * a[i]; + } + cout << sum << endl; +} +int n, m; +string s[101]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (s[i][j] == '-') + cout << '-'; + else { + if ((i + j) % 2 == 0) + cout << 'B'; + else + cout << 'W'; + } + } + cout << endl; + } + return (0); +} +int main() { + int n, c = 0, b = 0; + int a[1000]; + cin >> n; + int temp = n; + int i; + for (i = 1;; i++) { + int k = 0; + temp++; + int w = temp % 10; + int a = temp / 10; + int x = a % 10; + int b = a / 10; + int y = b % 10; + int c = b / 10; + int z = c % 10; + if (w != x && w != y && w != z && x != y && x != z && y != z) { + cout << temp << endl; + return 0; + } + } +} +int main() { + int n, count = 0; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) cin >> ar[i]; + for (int i = 0; i < n; i++) { + if (ar[i] == 1) + count++; + else if (ar[i] == 0 && i > 0 && i < n - 1 && ar[i - 1] == 1 && ar[i + 1] == 1) + count++; + } + cout << count << endl; + return 0; +} +int n; +int main() { + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long arr[n + 1]; + long long a, b; + cin >> a; + cin >> b; + long long i = 0; + long long j = n - 1; + for (i = 0; i < n; i++) { + long long x; + cin >> x; + arr[i] = x; + } + i = 0; + long long ans = 0; + while (i < j) { + if ((arr[i] == 0 && arr[j] == 2) || (arr[j] == 0 && arr[i] == 2)) { + ans = ans + a; + } else if ((arr[i] == 1 && arr[j] == 2) || (arr[j] == 1 && arr[i] == 2)) { + ans = ans + b; + } else if (arr[i] == 2 && arr[j] == 2) { + ans = ans + 2 * min(a, b); + } else if ((arr[i] == 0 && arr[j] == 1) || (arr[j] == 0 && arr[i] == 1)) { + cout << "-1\n"; + return 0; + } + i++; + j--; + } + if (n % 2 == 1) { + if (arr[n / 2] == 2) { ans = ans + min(a, b); } + } + cout << ans << "\n"; +} +int main() { + int n, i, j, cnt = 0; + string s; + cin >> s; + for (i = 0; i < s.size(); i++) { + for (j = i + 1; j < s.size(); j++) { + if (s[j] != s[i]) break; + } + if ((j - i) % 2 == 0) cnt++; + i = j - 1; + } + cout << cnt << endl; +} +int main() { + int q; + cin >> q; + while (q--) { + int n; + cin >> n; + string s; + cin >> s; + if (n == 2) { + if (s[1] <= s[0]) + cout << "NO" << endl; + else + cout << "YES" << endl << 2 << endl << s[0] << " " << s[1] << endl; + } else { + cout << "YES" << endl << 2 << endl << s[0] << " "; + for (int i = 1; i < s.length(); i++) cout << s[i]; + cout << endl; + } + } + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int bakes = 0, oven1 = 0, oven2 = 0; + int time = 1; + while (oven1 < n && (oven1 + oven2) < n) { + if (time > d) { + if ((time - d) % t == 0) oven2 += k; + } + if (time % t == 0) oven1 += k; + time++; + } + if (oven1 < n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int totalMili = (k * l) / (n * nl); + int totalLimon = (c * d) / n; + int totalSalt = p / (n * np); + cout << min(totalLimon, min(totalMili, totalSalt)) << endl; + return 0; +} +int64_t modex(int64_t a, int64_t b, int64_t p) { + int64_t res = 1; + a %= p; + while (b > 0) { + if (b & 1) res = (res * a) % p; + a = (a * a) % p; + b >>= 1; + } + return res; +} +int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; +int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int64_t count(int64_t a, int64_t b) { + if (a == b) return 1; + if (a == 0) return 0; + int64_t dv = b / a; + b -= dv * a; + return dv + count(min(a, b), max(b, a)); +} +int main() { + int t; + cin >> t; + while (t--) { + int64_t a, b; + cin >> a >> b; + int64_t ans = count(min(a, b), max(a, b)); + cout << ans << "\n"; + } + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const int MOD = 1e9 + 7; +void solve() { + int n, m; + cin >> n >> m; + bool b = false; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + int x; + cin >> x; + if (x == 1) { + if (i == 1 or i == n or j == 1 or j == m) { b = true; } + } + } + } + if (b) + cout << 2 << endl; + else + cout << 4 << endl; +} +int main() { + solve(); + return 0; +} +long long int n; +string s; +int main() { + cin >> n; + cin >> s; + for (long long int i = 0; i <= n - 1; i++) { + if (s[i] != '4' && s[i] != '7') { + cout << "NO" + << "\n"; + return 0; + } + } + long long int s1 = 0, s2 = 0; + for (long long int i = 0, j = n - 1; i < j; i++, j--) { + s1 = s1 + s[i] - '0'; + s2 = s2 + s[j] - '0'; + } + if (s1 == s2) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +string a, b, f[5000]; +int x, y, z, w, ft, n; +map q; +int main() { + cin >> a >> b; + cout << a << ' ' << b << endl; + if (!q.count(a)) { + f[++ft] = a; + q[a] = ft; + } + if (!q.count(b)) { + f[++ft] = b; + q[b] = ft; + } + x = q[a]; + y = q[b]; + cin >> n; + while (n--) { + cin >> a >> b; + if (!q.count(a)) { + f[++ft] = a; + q[a] = ft; + } + if (!q.count(b)) { + f[++ft] = b; + q[b] = ft; + } + z = q[a]; + w = q[b]; + if (z == x) + x = w; + else + y = w; + cout << f[x] << ' ' << f[y] << endl; + } + return 0; +} +int main() { + unsigned long long z[100][4]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 4; j++) { cin >> z[i][j]; } + } + for (int i = 0; i < n; i++) { cout << z[i][0] / z[i][3] + z[i][0] / z[i][3] / z[i][1] * z[i][2] << endl; } + return 0; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int n, p; + while (cin >> n) { + p = n / 2 + 1; + for (int j = 1; j <= p; j++) { + for (int i = 1; i <= (n - 2 * j + 1) / 2; i++) cout << "*"; + for (int i = 1; i <= 2 * j - 1; i++) cout << "D"; + for (int i = 1; i <= (n - 2 * j + 1) / 2; i++) cout << "*"; + cout << endl; + } + for (int j = p - 1; j >= 1; j--) { + for (int i = 1; i <= (n - 2 * j + 1) / 2; i++) cout << "*"; + for (int i = 1; i <= 2 * j - 1; i++) cout << "D"; + for (int i = 1; i <= (n - 2 * j + 1) / 2; i++) cout << "*"; + cout << endl; + } + } +} +int n, t, a[1000000], ans; +int main() { + cin >> n >> t; + for (register int i = 1; i <= n; i++) { + cin >> a[i]; + t -= 86400 - a[i]; + if (t <= 0 && !ans) ans = i; + } + cout << ans << endl; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + long l = t.size(); + int j = 0; + for (int i = 0; i < t.size(); i++) { + if (t[i] == s[j]) { j++; } + } + cout << j + 1 << endl; + return 0; +} +string s; +int main() { + int n, a, b; + cin >> n >> a >> b >> s; + if ((a == b) || (s[a - 1] == s[b - 1])) + cout << "0" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + long long a, b, s = 0, k, n, i; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b; + s = 0; + while (a > 0 && b > 0) { + if (a > b) { + k = a / b; + a -= k * b; + s += k; + } else { + k = b / a; + b -= k * a; + s += k; + } + } + cout << s << endl; + } + return 0; +} +int a[105], b[605]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[a[i]]++; + } + int sum = 0; + for (int i = 1; i < 605; i++) { + if (b[i] > 0) sum++; + } + cout << sum << endl; +} +int max2(int a, int b, int c) { + int mark, max; + if (a > b) { + mark = 1; + max = a; + } else { + max = b; + mark = 2; + } + if (c > max) { mark = 3; } + return mark; +} +int main() { + int n, l; + cin >> n; + int h = n / 3; + int h2 = n % 3; + int x = 0, y = 0, z = 0; + for (int i = 1; i <= h; i++) { + cin >> l; + x += l; + cin >> l; + y += l; + cin >> l; + z += l; + } + if (h2 == 1) { + cin >> l; + x += l; + } + if (h2 == 2) { + cin >> l; + x += l; + cin >> l; + y += l; + } + int lll = max2(x, y, z); + if (lll == 1) + cout << "chest" << endl; + else if (lll == 2) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int count = 0; + while (n--) { + int p, q; + cin >> p >> q; + count += (q - p) > 1 ? 1 : 0; + } + cout << count << "\n"; +} +const long long inf = 0x3f3f3f3f; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + int t = 0; + while (n) { + n--; + ans++; + t++; + if (t % m == 0) { n++; } + } + cout << ans << endl; + return 0; +} +long long res[1000], n; +long long can(long long x) { + long long sum = x; + while (x) { + sum += x % 10; + x /= 10; + } + if (sum == n) return 1; + return 0; +} +int main() { + long long co; + while (cin >> n) { + long long temp = n; + co = 0; + for (long long i = 0; i < 995; i++) { + if (temp <= 0) break; + temp--; + if (can(temp)) { res[co++] = temp; } + } + if (!co) + cout << 0 << endl; + else { + cout << co << endl; + for (long long i = co - 1; i >= 0; i--) { cout << res[i] << endl; } + } + } + return 0; +} +int n; +char a[110][110]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 0; + for (char i = 'a'; i <= 'z'; i++) { + for (char j = 'a'; j <= 'z'; j++) { + int m = 0; + for (int k = 0; k < n; k++) { + int flag = 1; + int len = strlen(a[k]); + for (int h = 0; h < len; h++) { + if (a[k][h] != i && a[k][h] != j) { + flag = 0; + break; + } + } + if (flag == 1) m += len; + } + ans = max(ans, m); + } + } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + while (cin >> a >> b) { + int lena = a.size(); + int lenb = b.size(); + bool flagA = false; + bool flagB = false; + string tmpa = ""; + string tmpb = ""; + for (int i = 0; i < lena; i++) { + if (a[i] == '0' && !flagA) { + continue; + } else if (a[i] >= '1' && a[i] <= '9' && !flagA) { + flagA = true; + tmpa += a[i]; + } else if (a[i] >= '0' && a[i] <= '9' && flagA) { + tmpa += a[i]; + } + } + a = tmpa; + for (int i = 0; i < lenb; i++) { + if (b[i] == '0' && !flagB) { + continue; + } else if (b[i] >= '1' && b[i] <= '9' && !flagB) { + flagB = true; + tmpb += b[i]; + } else if (b[i] >= '0' && b[i] <= '9' && flagB) { + tmpb += b[i]; + } + } + b = tmpb; + lena = a.size(); + lenb = b.size(); + bool flag = false; + if (lena > lenb) { + cout << ">" << endl; + } else if (lena < lenb) { + cout << "<" << endl; + } else { + for (int i = 0; i < lena; i++) { + if (a[i] < b[i]) { + cout << "<" << endl; + flag = true; + break; + } else if (a[i] > b[i]) { + cout << ">" << endl; + flag = true; + break; + } else { + flag = false; + continue; + } + } + if (!flag) { cout << "=" << endl; } + } + } + return 0; +} +int a[6], b[6], n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[x]++; + } + for (int i = 0; i < n; i++) { + int x; + cin >> x; + b[x]++; + } + for (int i = 1; i <= 5; i++) + if ((a[i] + b[i]) % 2) return cout << "-1\n", 0; + int sol = 0; + for (int i = 1; i <= 5; i++) sol += abs(a[i] - b[i]); + cout << sol / 4 << '\n'; +} +const int inf = 0x3f3f3f3f; +const long long mod = 1000000007; +int main() { + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + if (s == "Tetrahedron") + ans += 4; + else if (s == "Cube") + ans += 6; + else if (s == "Octahedron") + ans += 8; + else if (s == "Dodecahedron") + ans += 12; + else + ans += 20; + } + cout << ans << "\n"; +} +int main() { + int t, cp = 1, ck = 0; + cin >> t; + string s; + cin >> s; + if (t == 1) cp = 0; + for (int i = 0; i < t - 1; i++) { + if (s[i] != s[i + 1]) { + ck = 1; + cout << "YES" << endl; + cout << s[i] << s[i + 1] << endl; + break; + } else + cp = 0; + } + if (cp == 0 && ck == 0) cout << "NO" << endl; +} +int main() { + string s; + cin >> s; + int ans = 0, j = 0, co; + for (int i = 0; i < s.size(); i++) { + co = 0; + j = i; + while (s[i] == s[j] && j < s.size()) { + co++; + j++; + } + if (co % 2 == 0) { ans++; } + i = j - 1; + } + cout << ans << endl; + return 0; +} +const int MAXN = 200000 + 10; +int nums[MAXN], dp[MAXN]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> nums[i]; } + sort(nums, nums + n); + n = n / 2 - 1; + for (int i = 0; i <= n; i++) { dp[i] = nums[i] - nums[0]; } + int ret = 0; + for (int i = 0; i <= n; i++) { ret = max(ret, dp[n - i] + nums[2 * n + 1] - nums[2 * n + 1 - i]); } + cout << nums[2 * n + 1] - nums[0] - ret << endl; + return 0; +} +int n; +bool b = 1; +string c, cs = "qwrtpsdfghjklzxcvbnm"; +bool cc(char x) { + for (int i = 0; i < 21; i++) { + if (x == cs[i]) return 1; + } + return 0; +} +int main() { + cin >> n >> c; + for (int i = 0; i < n; i++) { + if (cc(c[i])) { + b = 1; + cout << c[i]; + } else { + if (b) { + b = 0; + cout << c[i]; + } else + continue; + } + } + cout << '\n'; +} +bool es_primo(int n) { + if (n < 4) return true; + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) return false; + } + return true; +} +int sum_digitos(int n) { + int sum = 0; + while (n > 0) { + sum += n % 10; + n /= 10; + } + return sum; +} +int sum_factores(int n) { + int sum = 0; + for (int i = 2; i * i <= n; i++) { + while (n % i == 0) { + sum += sum_digitos(i); + n /= i; + } + } + if (n > 1) { sum += sum_digitos(n); } + return sum; +} +int busca_sig(int n) { + do { n++; } while (es_primo(n) || sum_digitos(n) != sum_factores(n)); + return n; +} +int main() { + int n; + cin >> n; + int act = 0; + for (int i = 1; i <= n; i++) { act = busca_sig(act); } + cout << act << "\n"; + return 0; +} +const int M = 1000 + 5; +long long int ans[3]; +int main() { + long long int x[3]; + long long int k; + for (int i = 0; i < 3; i++) { cin >> x[i]; } + cin >> k; + sort(x, x + 3); + int num = 0; + for (int j = 0; j < 3; j++) { + if (ans[j] < x[j] - 1) { num++; } + } + while (num > 0 && k > 0) { + long long int ave = k / num; + long long int res = k % num; + if (ave == 0) { + while (res > 0 && num > 0) { + for (int j = 0; j < 3; j++) { + if (ans[j] < x[j] - 1 && res > 0) { + ans[j]++; + if (ans[j] == x[j] - 1) { num--; } + res--; + k--; + } + } + } + } else { + for (int j = 0; j < 3; j++) { + if (ans[j] < x[j] - 1) { + if (ans[j] + ave >= x[j] - 1) { + k = k - (x[j] - 1 - ans[j]); + ans[j] = x[j] - 1; + num--; + } else { + k = k - ave; + ans[j] = ans[j] + ave; + } + } + } + } + } + long long int result = 1; + for (int i = 0; i < 3; i++) { result = result * (ans[i] + 1); } + cout << result << endl; + return 0; +} +int main() { + int a[3], k; + int t; + long long r(1); + cin >> a[0] >> a[1] >> a[2] >> k; + sort(a, a + 3); + for (int i(0); i < 3; ++i) { + t = min(a[i], k / (3 - i) + 1); + r *= t, k -= t - 1; + } + cout << r << endl; + return 0; +} +void solve() { + long long n, m, i, j; + cin >> n >> m; + string s[n]; + for (long long i = 0; i < n; ++i) cin >> s[i]; + long long arr[m]; + for (long long i = 0; i < m; ++i) { + long long M = s[0][i]; + for (long long j = 0; j < n; ++j) { + if (s[j][i] > M) M = s[j][i]; + } + arr[i] = M; + } + set x; + for (long long i = 0; i < m; ++i) { + for (long long j = 0; j < n; ++j) { + if (s[j][i] == arr[i]) x.insert(j); + } + } + cout << (long long)x.size() << '\n'; +} +int main() { + long long t = 1; + while (t--) { solve(); } + return 0; +} +int n, a[105], sum1 = 0, sum2 = 0; +int main() { + cin >> n; + for (int i = 1; i <= n / 2; i++) cin >> a[i]; + sort(a + 1, a + 1 + n / 2); + for (int i = 1; i <= n / 2; i++) { + sum1 += abs(a[i] - (i * 2 - 1)); + sum2 += abs(a[i] - i * 2); + } + cout << min(sum1, sum2) << endl; + return 0; +} +int main() { + int n, sum, level; + while (cin >> n) { + if (n == 1) { + cout << '1' << endl; + continue; + } + sum = 1, level = 1; + for (int i = 2;; i++) { + level += i; + sum += level; + if (sum == n) { + cout << i << endl; + break; + } else if (sum > n) { + cout << i - 1 << endl; + break; + } + } + } + return 0; +} +int main() { + long long int n; + cin >> n; + n = n + 4; + while (1) { + if (n == 5) { + cout << "Sheldon" << endl; + break; + } else if (n == 6) { + cout << "Leonard" << endl; + break; + } else if (n == 7) { + cout << "Penny" << endl; + break; + } else if (n == 8) { + cout << "Rajesh" << endl; + break; + } else if (n == 9) { + cout << "Howard" << endl; + break; + } + n = n >> 1; + } + return 0; +} +int main() { + string a, b; + while (cin >> a >> b) { + if (a == b) + cout << a << endl; + else + cout << "1" << endl; + } + return 0; +} +int main() { + long long int n, k, cnt = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + cnt += b - a + 1; + } + if (cnt % k) + cout << k - cnt % k << endl; + else + cout << cnt % k << endl; + return 0; +} +int main() { + int t; + long long s, a, b, c, k; + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> s >> a >> b >> c; + k = s / c; + cout << k + k / a * b << endl; + } +} +const int INF = 0x3f3f3f3f; +const int T = 100 + 3; +int row[T]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> row[i]; + sort(row, row + n); + cout << row[n - 1] << " "; + for (int i = 1; i < n - 1; i++) cout << row[i] << " "; + cout << row[0] << endl; + return 0; +} +int main() { + int n, i, c = 0, x, y; + char a[1010], b[1010]; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + cin >> b[i]; + if (a[i] < b[i]) swap(a[i], b[i]); + x = a[i] - b[i]; + y = ('9' - a[i]) + b[i] - 47; + if (x < y) + c += x; + else + c += y; + } + cout << c << endl; + return 0; +} +int main() { + string s; + cin >> s; + s = "a" + s; + int r = 0; + for (int i = 1; i < s.size(); ++i) { + if (s[i] > s[i - 1]) { + r += min(s[i] - s[i - 1], 'z' - s[i] + s[i - 1] - 'a' + 1); + } else if (s[i] < s[i - 1]) { + r += min(s[i - 1] - s[i], 'z' - s[i - 1] + s[i] - 'a' + 1); + } + } + cout << r << endl; + return 0; +} +int main() { + vector v(8); + for (int i = 0; i < 8; ++i) cin >> v[i]; + int a = 8, b = 8; + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) { + bool ok = true; + if (v[i][j] == 'W' && a > i) { + for (int k = i - 1; k >= 0; --k) + if (v[k][j] != '.') ok = false; + if (ok) a = i; + } + if (v[i][j] == 'B' && b > 7 - i) { + for (int k = i + 1; k < 8; ++k) + if (v[k][j] != '.') ok = false; + if (ok) b = 7 - i; + } + } + } + cout << (a <= b ? "A\n" : "B\n"); + return 0; +} +int main() { + string str; + cin >> str; + int count = 0; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'Q') { + for (int j = i + 1; j < str.length(); j++) { + if (str[j] == 'A') { + for (int k = j + 1; k < str.length(); k++) { + if (str[k] == 'Q') count++; + } + } + } + } + } + cout << count << endl; + return 0; +} +int main() { + long long tc; + cin >> tc; + while (tc--) { + long long n; + cin >> n; + string s; + cin >> s; + long long check = 0; + for (long long i = 0; i < n / 2; i++) { + char c1 = min(s[i], s[n - 1 - i]); + char c2 = max(s[i], s[n - 1 - i]); + if (!(c2 - 1 == c1 + 1 || c1 == c2)) check = 1; + } + if (check == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cin >> a[i][j]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (a[i][j] == '-') + cout << a[i][j]; + else if ((i + j) % 2 == 0) + cout << 'B'; + else + cout << 'W'; + } + cout << endl; + } +} +int main() { + int n, p, q, i, j, cn = 0; + cin >> n; + int a[2 * n] = {0}; + cin >> p; + for (i = 0; i < p; i++) cin >> a[i]; + cin >> q; + for (j = 0; j < q; j++, i++) cin >> a[i]; + for (j = 1; j <= n; j++) + for (i = 0; i < (p + q); i++) { + if (j == a[i]) { + cn++; + break; + } + } + if (cn == n) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int n, i; +long long a[200005], mn = 2000000005; +map f; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + for (i = 1; i <= n; i++) + if (i > 1 && a[i] - a[i - 1] <= mn) mn = a[i] - a[i - 1], f[mn]++; + cout << mn << " " << f[mn] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 == 1) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } else if (i % 4 == 0) { + cout << "#"; + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << endl; + } else { + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << "#"; + cout << endl; + } + } + return 0; +} +int main() { + int a, b, c; + int r = 0, n = 0; + cin >> a >> b >> c; + if ((a * c) % b != 0) { n = 1; } + r = (a * c) / b - c + n; + cout << r << "\n"; + return 0; +} +int n, k, a[1000] = {}, ans = 0; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (a[i] >= a[k - 1] and a[i] > 0) { ans++; } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, x, y; + string s; + cin >> n >> x >> y >> s; + long long p = 0; + for (long long i = 1; i < n; ++i) { + if (s[i] == '1' && s[i - 1] == '0') ++p; + } + if (s[n - 1] == '0') ++p; + if (!p) return cout << "0\n", 0; + cout << (p - 1) * min(x, y) + y << '\n'; +} +int const N = 1e5 + 1; +int n, a[N]; +int main() { + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + a[n] = -1; + int lst = a[0], res = 0; + for (int i = 0, tmp; i < n; ++i) { + tmp = i; + while (a[i] <= a[i + 1]) ++i; + res = max(res, i - tmp + 1); + } + cout << res << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int MX = 1e5 + 5; +int n, a[10]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[n / 2 + 1] << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +int s[100000 + 5]; +int main() { + int n, b, d, ans = 0, sum = 0; + cin >> n >> b >> d; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i] > b) + continue; + else + sum += s[i]; + if (sum > d) { + sum = 0; + ans++; + } + } + cout << ans << endl; + return 0; +} +char a; +int n, b = 0; +int main() { + a = getchar(); + while (a != '\n') { + (a == '1') && (b = 1); + if (b && a == '0') n++; + a = getchar(); + if (n >= 6) return puts("yes"), 0; + } + puts("no"); + return 0; +} +int main() { + int n, x, a = 0; + cin >> n >> x; + for (int i = 1, k = 0; i <= n; i++) { + cin >> k; + a += k; + } + a = abs(a); + cout << a / x + (a % x ? 1 : 0) << endl; +} +int GCD(int m, int n) { + int r; + while ((r = m % n) != 0) { + m = n; + n = r; + } + return n; +} +int main() { + int a, b, n; + cin >> a >> b >> n; + while (true) { + n -= GCD(a, n); + if (n == 0) { + cout << 0 << endl; + break; + } + n -= GCD(b, n); + if (n == 0) { + cout << 1 << endl; + break; + } + } + return 0; +} +int main() { + int n, m = 0, kol[26], x, y, k = 0; + cin >> n >> m >> x >> y; + pair r[n]; + int a[n], b[m]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + for (int i = 0, j = 0; i < n && j < m;) { + if (b[j] >= a[i] - x && b[j] <= a[i] + y) { + r[k].first = i + 1; + r[k].second = j + 1; + k++; + i++; + j++; + } else { + if (b[j] > a[i] + y) + i++; + else + j++; + } + } + cout << k << endl; + for (int i = 0; i < k; i++) cout << r[i].first << " " << r[i].second << endl; + return 0; +} +const int inf = 1e9 + 5; +const int M = 1e5 + 5; +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int m1 = n / k; + if (n % k != 0) m1++; + m1 *= t; + int m2 = 0; + int nown = 0; + int x = 0, y = 0; + int xt = 0, yt = 0; + m2 = d + (n / (2 * k) + n % (2 * k) == 0 ? 0 : 1) * t; + if (m1 <= m2) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int a[1000001] = {0}; +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + for (int j = 1; j <= t; j++) { + int g; + cin >> g; + if (a[g] == 0) a[g] = 1; + } + } + int flag = 1; + for (int i = 1; i <= m; i++) { + if (a[i] == 0) { + flag = 0; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + memset(a, 0, sizeof(a)); + } + return 0; +} +int main() { + int a[9], out[9]; + for (int i = 0; i < 9; i++) cin >> a[i]; + out[0] = a[0] + a[1] + a[3]; + out[1] = a[1] + a[0] + a[2] + a[4]; + out[2] = a[1] + a[2] + a[5]; + out[3] = a[0] + a[3] + a[4] + a[6]; + out[4] = a[1] + a[3] + a[4] + a[5] + a[7]; + out[5] = a[2] + a[4] + a[5] + a[8]; + out[6] = a[3] + a[6] + a[7]; + out[7] = a[4] + a[6] + a[7] + a[8]; + out[8] = a[7] + a[8] + a[5]; + for (int i = 0; i < 9; i++) { + if (out[i] % 2 == 0) + cout << "1"; + else + cout << "0"; + if ((i + 1) % 3 == 0) cout << "\n"; + } +} +int N; +int x, s, t; +vector d; +int main() { + cin >> N; + for (int i = 0; i < N; ++i) cin >> x, d.push_back(x); + cin >> s >> t; + if ((--s) > (--t)) swap(s, t); + int d1 = 0; + for (int i = s; i < t; ++i) d1 += d[i]; + int d2 = 0; + for (int i = t; i < N; ++i) d2 += d[i]; + for (int i = 0; i < s; ++i) d2 += d[i]; + cout << min(d1, d2) << endl; + return 0; +} +int T, N; +string str; +int main() { + cin >> T; + while (T--) { + cin >> N; + cin >> str; + bool print = true; + for (int l = 0, r = N - 1; l < r; l++, r--) { + if (str[l] == str[r]) continue; + set pos; + int act = str[l] - 'a'; + if (str[l] == 'a') + pos.insert(act + 1); + else if (str[l] == 'z') + pos.insert(act - 1); + else { + pos.insert(act + 1); + pos.insert(act - 1); + } + act = str[r] - 'a'; + int found = 0; + if (str[r] == 'a') { + if (pos.find(act + 1) != pos.end()) found = true; + } else if (str[r] == 'z') { + if (pos.find(act - 1) != pos.end()) found = true; + } else { + if (pos.find(act + 1) != pos.end()) found = true; + if (pos.find(act - 1) != pos.end()) found = true; + } + if (!found) { + cout << "NO\n"; + print = false; + break; + } + } + if (print) cout << "YES\n"; + } + return 0; +} +int a[105], b[105], c1[7], c2[7]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + c1[a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + c2[b[i]]++; + } + int zong = 0; + for (int i = 1; i <= 5; i++) { + if ((c1[i] + c2[i]) % 2 == 0) { + zong += abs((c1[i] + c2[i]) / 2 - c1[i]); + } else { + cout << -1 << endl; + return 0; + } + } + cout << zong / 2 << endl; + return 0; +} +int T = 1; +void solve() { + int n, k; + cin >> n >> k; + cout << (((0) > (n - (k - (2 * n)))) ? (0) : (n - (k - (2 * n)))) << endl; +} +int main() { + while (T--) { solve(); } + return 0; +} +int s = 3; +int arr[105]; +int main() { + int m; + cin >> m; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + if (s == x) return cout << "NO" << endl, 0; + s = 6 - x - s; + } + return cout << "YES" << endl, 0; +} +int main() { + int n, sum1 = 0, sum2 = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int b; + cin >> b; + if (b == 1) { sum1 += 1; } + if (b == 2) { sum2 += 1; } + } + if (sum2 == 0) { + cout << sum1 / 3 << endl; + } else if (sum1 == 0) { + cout << 0 << endl; + } else if (sum1 <= sum2) { + cout << sum1 << endl; + } else if (sum1 > sum2) { + cout << sum2 + (sum1 - sum2) / 3 << endl; + } + return 0; +} +int main() { + int n, m, mn, mx; + cin >> n >> m; + if (n == 0) { + if (m == 0) + cout << "0 0" << endl; + else + cout << "Impossible" << endl; + return 0; + } + if (m == 0) { + cout << n << " " << n << endl; + return 0; + } + mx = n + m - 1; + if (n >= m) + mn = n; + else + mn = m; + cout << mn << " " << mx << endl; + return 0; +} +int main() { + int m, n, a, p = 1, cnt = 0, k = 0, i; + cin >> m >> n; + int arr[m + 1]; + for (int x = 0; x < m; x++) cin >> arr[x]; + for (i = 0; i < m; i++) { + if (arr[i] <= n) { + cnt++; + } else { + break; + } + } + for (int j = m - 1; j > i; j--) { + if (arr[j] <= n) + cnt++; + else + break; + } + cout << cnt << endl; +} +int main() { + char p1[105], p2[105]; + int x; + cin >> p1 >> p2; + for (x = 0; x < strlen(p1); x++) { + if (p1[x] == p2[x] && p1[x] == '1') + p1[x] = '0'; + else if (p1[x] != p2[x]) + p1[x] = '1'; + } + cout << p1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + int idx = (a.size() - 1) / 2; + cout << a[idx] << endl; + return 0; +} +long long n, k, x, a, c, ans; +vector v; +int main() { + cin >> n >> k >> x; + for (long long i = 0; i < n; i++) { + cin >> a; + v.push_back(a); + ans += a; + } + c = v.size() - 1; + for (long long i = 0; i < k; i++) { + if (x < v[c]) { + ans -= v[c] - x; + } else { + break; + } + c--; + } + cout << ans; + cout << "\n"; + return 0; +} +int main() { + string ss = "qwertyuiopasdfghjkl;zxcvbnm,./"; + string p; + cin >> p; + string s; + cin >> s; + int x = 1; + if (p[0] == 'R') { x = -1; } + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < ss.length(); j++) { + if (ss[j] == s[i]) cout << ss[j + x]; + } + } + cout << endl; +} +int main() { + cout << "Karen" << endl; + return 0; +} +long long p1, p2, p3, p4, a, b, ans = 0; +inline long long read() { + long long x = 0; + bool f = 0; + char ch = getchar(); + for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); + for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); + return f ? -x : x; +} +int main() { + p1 = read(), p2 = read(), p3 = read(), p4 = read(); + a = read(), b = read(); + for (register long long i = a; i <= b; i++) { + long long z = i % p1, zz = i % p2, zzz = i % p3, zzzz = i % p4; + if (zz == zzz && zz == z && zz == zzzz && z == i) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int w, h, k, count = 0; + cin >> w >> h >> k; + while (k--) { + count += 2 * (w + h) - 4; + w -= 4; + h -= 4; + } + cout << count << endl; + return 0; +} +const long long MOD = 1000 * 1000 * 1000 + 9; +long long mod(long long n) { + return (n % MOD + MOD) % MOD; +} +int main() { + long long n, m; + cin >> n >> m; + long long pw = 1; + for (long long i = 0; i < m; ++i) pw = mod(pw << 1); + long long ans = 1; + pw = mod(pw - 1); + for (long long i = 0; i < n; ++i) { + ans = mod(ans * pw); + pw = mod(pw - 1); + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int d; + if (n == 1) d = 0; + if (n == 2) d = min(a, b); + if (n > 2) { + if (a <= b && a <= c) { + d = (n - 1) * a; + } else if (b <= a && b <= c) { + d = (n - 1) * b; + } else { + d = min(a, b) + (n - 2) * c; + } + } + cout << d << endl; +} +int main() { + long long i, n, l; + string s, t, y; + cin >> n; + while (n--) { + cin >> s; + l = s.size(); + if (l <= 10) { + cout << s << endl; + } else { + i = l - 2; + cout << s[0] << i << s[l - 1] << endl; + } + } + return 0; +} +int main() { + long long k, l, m, n, d, c = 0; + cin >> k >> l >> m >> n >> d; + if (k == 1 || l == 1 || m == 1 || n == 1) + cout << d << endl; + else { + for (long long i = 1; i <= d; i++) { + if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) c++; + } + cout << c << endl; + } + return 0; +} +int main() { + long long int n, a, b, c; + while (cin >> n >> a >> b >> c) { + long long int ans; + int temp = n % 4; + if ((4 - temp) == 1) + ans = min(a, min(b + c, 3 * c)); + else if ((4 - temp) == 2) + ans = min(2 * a, min(b, 2 * c)); + else if ((4 - temp) == 3) + ans = min(3 * a, min(a + b, c)); + else if ((4 - temp) == 4) + ans = 0; + cout << ans << endl; + } + return 0; +} +int main() { + int n, c = 0; + cin >> n; + while (n != 0) { + if (n >= 5) { + n -= 5; + c++; + } else if (n >= 4) { + n -= 4; + c++; + } else if (n >= 3) { + n -= 3; + c++; + } else if (n >= 2) { + n -= 2; + c++; + } else if (n >= 1) { + n -= 1; + c++; + } + } + cout << c << "\n"; + return 0; +} +int n, m; +string s; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m >> s; + if (m > 2) { + cout << "YES" << endl; + cout << 2 << endl; + cout << s[0] << " "; + for (int i = 1; i < s.size(); i++) cout << s[i]; + } else if (s[0] < s[1]) { + cout << "YES" << endl; + cout << 2 << endl; + cout << s[0] << " " << s[1]; + } else + cout << "NO"; + cout << endl; + } +} +long long poww(long long a, long long b) { + long long ans = 1; + while (b > 0) { + if (b % 2 == 1) ans = (ans * a); + b = b / 2; + a = (a * a); + } + return ans; +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= 32) n = 32; + long long ans = m % poww(2, n); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < n - i - 1; j++) { + if (a[j] > a[j + 1]) { swap(a[j], a[j + 1]); } + } + } + if (n % 2 == 0) { + cout << a[n / 2 - 1] << endl; + } else { + cout << a[n / 2] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(n - 1) / r] << endl; + return 0; +} +int main() { + long long n, a, b, r, c; + cin >> n; + while (n--) { + cin >> a >> b; + r = 0; + if (a == b) { + cout << 1 << endl; + continue; + } else { + while (a > 0 && b > 0) { + if (a > b) { + long long x; + x = a; + a = b; + b = x; + } + c = b / a; + b = b - a * c; + r += c; + } + } + cout << r << endl; + } + return 0; +} +int main() { + string str; + int n, h1, h2, sum0 = 0, sum1 = 0; + cin >> n >> str; + for (int i = 0; i < n; i++) { + if (str[i] != '4' && str[i] != '7') { + cout << "NO" << endl; + return 0; + } + } + h1 = n / 2; + for (int i = 0; i < h1; i++) sum0 = str[i] - '0' + sum0; + for (int i = h1; i < n; i++) sum1 = str[i] - '0' + sum1; + if (sum0 == sum1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[1005]; +int b[1005]; +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { cin >> b[i]; } + int num1 = a[1]; + for (int i = 2; i <= n; i++) { num1 |= a[i]; } + int num2 = b[1]; + for (int i = 2; i <= n; i++) { num2 |= b[i]; } + cout << num1 + num2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long a[100001]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + cout << a[n - 1] - a[0] + 1 - n << endl; +} +int main() { + int n, i, j; + string a[7]; + string x[7]; + string y[7]; + int u[7]; + int b[7]; + bool t; + cin >> n; + a[1] = "purple"; + y[1] = "Power"; + a[2] = "green"; + y[2] = "Time"; + a[3] = "blue"; + y[3] = "Space"; + a[4] = "orange"; + y[4] = "Soul"; + a[5] = "red"; + y[5] = "Reality"; + a[6] = "yellow"; + y[6] = "Mind"; + for (i = 1; i <= n; i++) { cin >> x[i]; } + cout << 6 - n << endl; + for (i = 1; i <= n; i++) { + for (j = 1; j <= 6; j++) { + if (x[i] == a[j]) { b[i] = j; } + } + } + for (i = 1; i <= 6; i++) { + t = true; + for (j = 1; j <= 6; j++) { + if (b[j] == i) { t = false; } + } + if (t) { cout << y[i] << endl; } + } + return 0; +} +long long int w, h, k; +int main() { + cin >> w >> h >> k; + long long int _rs = 0; + while (k--) { + _rs = _rs + 2 * (w + h) - 4; + w -= 4; + h -= 4; + } + cout << _rs << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + sum += abs(t); + } + cout << sum << endl; + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + if (n == 1) { + cout << 0 << endl; + } else { + int m = min(b, a); + if (n == 2) + cout << m << endl; + else { + n = n - 2; + m += min(m, c) * n; + cout << m << endl; + } + } + return 0; +} +int main() { + int n, b; + cin >> n >> b; + int arr[n]; + int bill[b]; + for (int i = 0; i < n; i++) cin >> arr[i]; + for (int j = 0; j < b; j++) cin >> bill[j]; + int j = 0; + int count = 0; + for (int i = 0; i < n && j < b; i++) { + if (arr[i] <= bill[j]) { + count++; + j++; + } + } + cout << count << endl; +} +int main() { + int n; + cin >> n; + cout << n % 2 << endl; + return 0; +} +int n; +int x; +int main() { + cin >> n >> x; + for (int i = 0; i < x; i++) { + if (n % 10 == 0) + n = n / 10; + else + n--; + } + cout << n << endl; +} +int main() { + int n, win, spect = 3; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> win; + if (win == spect) { + cout << "NO" << endl; + return 0; + } + spect = (6 - spect - win); + } + cout << "YES" << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + if (n > a + c + e) { + int sam = n - (a + c + e); + int a1 = f - e; + int a2 = d - c; + int a3 = b - a; + while (sam > 0) { + sam--; + if (a3 > 0) { + a3--; + a++; + } else if (a2 > 0) { + a2--; + c++; + } else if (a1 > 0) { + a1--; + e++; + } + } + cout << a << " " << c << " " << e << endl; + } else if (n == a + c + e) { + cout << a << " " << c << " " << e << endl; + } + } + return 0; +} +int main() { + string s, t; + cin >> s >> t; + int c = 0; + for (int i = 0; i < t.size(); i++) { + if (s[c] == t[i]) { c++; } + } + cout << c + 1 << endl; + return 0; +} +long long N, A, B, sum, ans, H; +bool cek[105]; +int main() { + cin >> N >> H; + for (int i = 1; i <= N; i++) { + cin >> A; + for (int j = 1; j <= A; j++) { + cin >> B; + cek[B] = 1; + } + } + for (int i = 1; i <= H; i++) { + if (!cek[i]) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int temp = d - (a + b - c); + if (c > a || c > b || a + b - c >= d) + cout << -1 << endl; + else + cout << temp << endl; + return 0; +} +int main() { + int i, b, p, j, n, m, k; + cin >> n >> b >> p; + cout << (2 * b + 1) * (n - 1) << " " << n * p << endl; +} +int arr[20][20]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) { arr[i][1] = arr[1][i] = 1; } + for (int i = 2; i <= n; ++i) { + for (int j = 2; j <= n; ++j) { arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; } + } + cout << arr[n][n] << endl; + return 0; +} +int main() { + int n, m; + bool o = true; + cin >> n; + cin >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } else { + if (o == true) { + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << "#" << endl; + o = false; + } else { + cout << "#"; + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << endl; + o = true; + } + } + } +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'r') cout << i + 1 << '\n'; + } + for (int i = s.size() - 1; i >= 0; i--) { + if (s[i] == 'l') cout << i + 1 << '\n'; + } +} +int main() { + int a[101], n, c, s = 0; + cin >> n >> c; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] > 0 && a[i] >= a[c - 1]) s += 1; + } + cout << s << endl; + return 0; +} +int main() { + string s; + cin >> s; + if (s[0] == 'a' || s[0] == 'h') { + int xx = (int)s[1]; + xx -= 48; + if (xx == 1 || xx == 8) { + cout << 3 << endl; + } else + cout << 5 << endl; + } else { + int xx = (int)s[1]; + xx -= 48; + if (xx == 1 || xx == 8) { + cout << 5 << endl; + } else + cout << 8 << endl; + } +} +int main() { + int n; + while (cin >> n) { + int b = 0, counter = 0, max = 0; + while (n--) { + int x; + cin >> x; + if (x >= b) { + counter++; + if (counter >= max) { max = counter; } + } else { + counter = 1; + } + b = x; + } + cout << max << endl; + } +} +int main() { + int n; + cin >> n; + cout << (n / 2) * 3 << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M; + K = MOD; + for (int i = 0; i < N; i++) { + cin >> L; + if (M % L) continue; + K = min(K, M / L); + } + cout << K << endl; + return 0; +} +long long n, i, j, A[26], B[26][26], C[26], ans, jwbn, st, nd, coun; +string s; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> s; + coun = 0; + ans = 0; + st = 0; + nd = 0; + for (j = 0; j < 26; j++) A[j] = 0; + for (j = 0; j < s.length(); j++) A[int(s[j]) - 97]++; + for (j = 0; j < 26; j++) { + if (A[j] > 0) { + coun++; + ans += A[j]; + if (coun == 1) + st = j; + else if (coun == 2) + nd = j; + } + } + if (coun == 1) + C[st] += ans; + else if (coun == 2) { + B[st][nd] += ans; + B[nd][st] += ans; + } + } + for (i = 0; i < 26; i++) + for (j = 0; j < 26; j++) { + if (i != j) { + B[i][j] += C[i]; + B[i][j] += C[j]; + } + if (B[i][j] > jwbn) jwbn = B[i][j]; + } + cout << jwbn << endl; +} +int main() { + long n, b, d, c = 0; + cin >> n >> b >> d; + long orange[n]; + long long out = 0; + for (int i = 0; i < n; i++) { + cin >> orange[i]; + if (orange[i] > b) + continue; + else { + out += orange[i]; + if (out > d) { + c++; + out = 0; + } + } + } + cout << c << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + int ans = 0, t; + cin >> t; + string s; + cin >> s; + for (int j = 0; j < t / 2; j++) { + int g = s[j] + 1, g1 = s[t - j - 1] + 1; + int b = s[j] - 1, b1 = s[t - j - 1] - 1; + if ((g == g1) || (g == b1) || (b == g1) || (b == b1)) ans++; + } + if (ans == t / 2) + a[i] = 1; + else + a[i] = 0; + } + for (int i = 0; i < n; i++) { + if (a[i] == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + sort(v.begin(), v.end()); + int a = m - k; + int ans = 0; + while (a > 0 && n != 0) { + a -= v[n - 1] - 1; + ans++; + n--; + } + if (a > 0) + cout << -1 << endl; + else + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long k; + cin >> k; + string s; + cin >> s; + map mp; + long long i; + for (i = 0; i < n; i++) { mp[s[i]]++; } + long long minn = INT_MAX; + for (i = 65; i < 65 + k; i++) { + char x = i; + long long y = mp[x]; + if (y < minn) { minn = y; } + } + cout << minn * k << "\n"; +} +int n; +set x; +set y; +int a, b; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + x.insert(a); + y.insert(b); + } + if (x.size() < y.size()) + cout << x.size() << endl; + else + cout << y.size() << endl; +} +int main() { + int n; + int a[5], b[5], c[5] = {0}; + while (cin >> n) { + int i; + for (i = 0; i < 3; i++) cin >> a[i] >> b[i]; + c[0] = min(b[0], n - a[1] - a[2]); + c[1] = min(b[1], n - c[0] - a[2]); + c[2] = n - c[0] - c[1]; + cout << c[0] << " "; + cout << c[1] << " "; + cout << c[2] << endl; + } + return 0; +} +int n, res; +char str; +int main() { + cin >> n; + for (int i = int(0); i < int(n); i++) { + cin >> str; + str == '0' ? res++ : res--; + } + res = abs(res); + return cout << res << '\n', 0; +} +const int Maxn = 15, Maxm = 100 + 5; +int n, m, k, a[Maxn][Maxm], b[Maxn][Maxm], c[Maxn][Maxm], ans; +int main() { + cin >> n >> m >> k; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j]; + } + pair d[Maxm]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + for (int l = 0; l < m; l++) d[l] = make_pair(b[j][l] - a[i][l], c[i][l]); + sort(d, d + m); + reverse(d, d + m); + int num = 0, p = 0, cnt = 0; + while (p < m && cnt + d[p].second <= k) { + if (d[p].first < 0) break; + cnt += d[p].second; + num += d[p].first * d[p].second; + p++; + } + if (d[p].first > 0) num += d[p].first * (k - cnt); + ans = max(ans, num); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, b, p; + cin >> n >> b >> p; + long long B = 0; + long long T = n * p; + while (n > 1) { + long long now = 1; + while (now * 2 <= n) now *= 2; + B += (now / 2) * (2 * b + 1); + n = now / 2 + (n - now); + } + cout << B << " " << T << endl; + return 0; +} +string s[41]; +long long n, p, sum; +double curr; +int main() { + cin >> n >> p; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = n - 1; i >= 0; i--) { + if (s[i] == "halfplus") curr += 0.5; + sum += curr * p; + curr *= 2; + } + cout << sum << endl; + return 0; +} +int main() { + long int n, h, low, high, k, ta, ha, tb, hb, x; + cin >> n >> h >> low >> high >> k; + while (k) { + x = 0; + cin >> ta >> ha >> tb >> hb; + if (ta == tb) + x = abs(hb - ha); + else if (ha > high && hb > high) { + x = abs(ta - tb) + (ha - high) + (hb - high); + } else if (ha < low && hb < low) { + x = abs(ta - tb) + (low - ha) + (low - hb); + } else + x = abs(ta - tb) + abs(ha - hb); + cout << x << endl; + k--; + } + return 0; +} +int main() { + int n, x; + cin >> n; + cin >> x; + vector vec(n - 1); + for (int i = 0; i < n - 1; i++) { cin >> vec[i]; } + int ans = 0; + sort(vec.rbegin(), vec.rend()); + while (x <= vec[0]) { + ans++; + x++; + vec[0]--; + sort(vec.rbegin(), vec.rend()); + } + cout << ans << endl; +} +int main() { + string s, t, s1, t1; + cin >> s >> t; + int n; + cin >> n; + cout << s << " " << t << endl; + while (n--) { + cin >> s1 >> t1; + if (s1.compare(s) == 0) { + s = t1; + } else { + t = t1; + } + cout << s << " " << t << endl; + } +} +const int maxn = 1e5 + 5; +const int MOD = 1e9 + 7; +long long calc(long long a, long long b, long long c, long long add) { + long long x = (a - b - c + add) >> 1; + if (x < 0) return 0; + if (x > add) x = add; + return (x + 2) * (x + 1) / 2; +} +int main() { + long long a, b, c, L; + while (cin >> a >> b >> c >> L) { + long long sum = 0; + for (long long i = 0; i <= L; i++) { + sum += (i + 2) * (i + 1) / 2; + sum -= calc(a, b, c, i); + sum -= calc(b, a, c, i); + sum -= calc(c, a, b, i); + } + cout << sum << endl; + } +} +bool beat(char c, char d) { + if (c == 'R' && d == 'S') return true; + if (c == 'S' && d == 'P') return true; + if (c == 'P' && d == 'R') return true; + return false; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int sa = 0, sb = 0; + for (int i = 0; i < a.size() * b.size(); i++) { + if (beat(a[i % a.size()], b[i % b.size()])) sb++; + if (beat(b[i % b.size()], a[i % a.size()])) sa++; + } + sa = sa * (n / (a.size() * b.size())); + sb = sb * (n / (a.size() * b.size())); + for (int i = 0; i < n % (a.size() * b.size()); i++) { + if (beat(a[i % a.size()], b[i % b.size()])) sb++; + if (beat(b[i % b.size()], a[i % a.size()])) sa++; + } + cout << sa << ' ' << sb << endl; + return 0; +} +int main() { + long long a, b, c, res = 0; + cin >> a >> b >> c; + long long lef = 0, righ = a + b + c; + while (lef <= righ) { + long long mid = (lef + righ) / 2, t1, t2; + t1 = max(0LL, mid - a); + t2 = max(0LL, mid - b); + if (t1 + t2 <= c) { + res = 2 * mid; + lef = mid + 1; + } else + righ = mid - 1; + } + cout << res << endl; + return 0; +} +int main() { + string s[10]; + int i, j; + for (i = 1; i <= 8; i++) { cin >> s[i]; } + for (i = 1; i <= 8; i++) { + for (j = 1; j < s[i].size(); j++) { + if (s[i][j] == s[i][j - 1]) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k; + long long n, m; + cin >> n; + k = n % 3; + n /= 3; + if (k == 2) n++; + cout << n / 12 << ' ' << n % 12 << endl; + return 0; +} +int c[4]; +int n, a[10010], out[5]; +bool book[10010]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i], c[a[i]]++; + if (c[1] > 0 && c[2] > 0 && c[3] > 0) { + cout << min(min(c[1], c[2]), c[3]) << endl; + while (c[1] > 0 && c[2] > 0 && c[3] > 0) { + int top = 1; + for (int i = 1; i <= n; ++i) + if (a[i] == 1 && book[i] == 0) { + c[a[i]]--, book[i] = 1, cout << i << " "; + break; + } + for (int i = 1; i <= n; ++i) + if (a[i] == 2 && book[i] == 0) { + c[a[i]]--, book[i] = 1, cout << i << " "; + break; + } + for (int i = 1; i <= n; ++i) + if (a[i] == 3 && book[i] == 0) { + c[a[i]]--, book[i] = 1, cout << i << endl; + break; + } + } + } else + cout << 0 << endl; + return 0; +} +int main() { + long long m; + cin >> m; + long long d; + cin >> d; + int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + d--; + long long x = 7 - d; + long long num = month[m - 1] - x; + long long ans = num / 7; + if (num % 7 != 0) ans++; + cout << ans + 1 << "\n"; +} +int main() { + int n, k, c = 0, lucky; + cin >> n >> k; + while (n--) { + lucky = 0; + int temp, x; + cin >> temp; + while (temp > 0) { + x = temp % 10; + if (x == 4 || x == 7) lucky++; + temp /= 10; + } + if (lucky <= k) c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int count = 0; + while (n--) { + int a; + cin >> a; + int tempCount = 0; + while (a != 0) { + if (a % 10 == 4 || a % 10 == 7) { tempCount++; } + a /= 10; + } + if (tempCount <= k) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + long long n; + while (cin >> n) { + long long a; + long long t = 3; + while (!(n % t)) t *= 3; + cout << n / t + 1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s1 = "I love", s2 = "I hate"; + for (int i = 0; i < n; i++) { + if (i % 2 == 1) { + cout << s1 << " "; + } else { + cout << s2 << " "; + } + if (i != n - 1) cout << "that "; + } + cout << "it" << endl; + return 0; +} +int par[2000001] = {0}; +int visited[2000001] = {0}; +int find_par(int x) { + while (par[x] != x) { x = find_par(par[x]); } + return x; +} +void uni(int x, int y) { + par[find_par(y)] = par[find_par(x)]; + par[find_par(x)] = par[find_par(y)]; +} +int main() { + int n, k, x, y, sum = 0; + cin >> n >> k >> x; + for (int i = 0; i < n - k; i++) { + cin >> y; + sum += y; + } + sum += x * k; + cout << sum << endl; +} +int main() { + int t, n, i, x, pp, count, flag = 0, dis = 0, min = 0, sum; + vector v; + vector::iterator it; + cin >> n; + while (n--) { + cin >> x; + v.push_back(x); + } + t = *min_element(v.begin(), v.end()); + for (i = 0; i < v.size(); i++) { + if (v[i] == t) { + if (flag != 0) { + dis = i - pp; + if (min == 0 && dis != 0) + min = dis; + else if (min != 0 && min > dis) + min = dis; + } + flag++; + pp = i; + } + } + cout << min << endl; + return 0; +} +int n, a[40][40], col[40], row[40], b[40][40], c; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + row[i] += a[i][j]; + col[j] += a[i][j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + a[i][j] = row[i]; + b[i][j] = col[j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] < b[i][j]) c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int *a = new int[n]; + int output = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (i <= (k - 1) && a[i] > 0) + output++; + else if (i > (k - 1) && a[i] > 0 && a[i] == a[k - 1]) + output++; + else + break; + } + cout << output << endl; + return 0; +} +int main() { + int n; + string s, t, a, b; + cin >> s >> t >> n; + cout << s << ' ' << t << '\n'; + while (n--) { + cin >> a >> b; + if (a == s) + s = b; + else + t = b; + cout << s << ' ' << t << '\n'; + } + return 0; +} +long long n, k; +char c[10000]; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> c[i]; + sort(c, c + n); + int sum = c[0] - 'a' + 1; + int we = 1; + int d = c[0]; + for (int i = 1; i < n; i++) { + if (we == k) break; + if (c[i] - d > 1) { + d = c[i]; + we++; + sum += d - 'a' + 1; + } + } + if (we != k) + cout << -1 << endl; + else { + cout << sum << endl; + } + return 0; +} +long long dm(long long x, long long y, long long z, long long l) { + long long res = 0, now = 0; + for (long long i = max((long long)0, x + y - z); i <= l; i++) { + now = min(l - i, z + i - x - y); + res += (now + 1) * (now + 2) / 2; + } + return res; +} +int main() { + long long a, b, c, l; + long long ans; + cin >> a >> b >> c >> l; + ans = (l + 1) * (l + 2) * (l + 3) / 6; + ans -= dm(a, b, c, l); + ans -= dm(a, c, b, l); + ans -= dm(b, c, a, l); + cout << ans << endl; + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << (a[2] - a[0]) << endl; + return 0; +} +int n; +int i = 0; +int a; +int c = 0; +int d = 0; +int main() { + cin >> n; + while (i < n) { + cin >> a; + if (a >= 0) { + c += a; + } else { + d += a; + }; + i += 1; + }; + cout << c + (-1 * d) << endl; + return 0; +} +int main() { + string a; + cin >> a; + string A[10]; + for (int i = 0; i < 10; i++) cin >> A[i]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 10; j++) + if (a.substr(i * 10, 10) == A[j]) cout << j; + cout << endl; +} +int a[100001]; +map m1; +int main() { + int n; + cin >> n; + { + m1.clear(); + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] != 0) { m1[a[i]]++; } + } + cout << m1.size() << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + long long sum = 0, done = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + int i; + for (i = 0; done < (sum + 1) / 2; i++) { done += arr[i]; } + cout << i << "\n"; +} +int main() { + int t; + cin >> t; + while (t--) { + int a; + cin >> a; + if (360 % (180 - a)) + cout << "NO\n"; + else if ((360 / (180 - a)) == 0) + cout << "NO\n"; + else + cout << "YES\n"; + } + return 0; +} +int main() { + string ss; + cin >> ss; + set s; + for (int i = 0; i < ss.length(); i++) { s.insert(ss[i]); } + if (s.size() % 2 == 1) { + cout << "IGNORE HIM!" << endl; + } else { + cout << "CHAT WITH HER!" << endl; + } + return 0; +} +int main() { + long long n, ans; + while (cin >> n) { + ans = n / 2 + 1; + cout << ans << endl; + } +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int cnt1 = 0, cnt2 = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') + cnt1++; + else + cnt2++; + } + if (cnt1 > cnt2) + n = n - 2 * cnt1; + else + n = n - 2 * cnt2; + cout << abs(n) << endl; +} +const int N = 1e5 + 11; +bool use[N]; +int main() { + int n; + cin >> n; + int l, r; + cin >> l >> r; + for (int i = 1; i < n; i++) { + int l, r; + cin >> l >> r; + for (int j = l; j < r; j++) use[j] = 1; + } + int ans = 0; + for (int i = l; i < r; i++) + if (use[i] == 0) ans++; + cout << ans << endl; +} +int main() { + int n, minix, p, q; + cin >> n; + vector v(n); + minix = INT_MAX; + for (int i = 0; i < n; i++) { + cin >> v[i]; + minix = min(minix, v[i]); + } + p = -999999; + q = INT_MAX; + for (int i = 0; i < n; i++) { + if (v[i] == minix) { + q = min(q, i - p); + p = i; + } + } + cout << q << endl; + return 0; +} +int a[100010]; +int main() { + int n, a[101][101]; + while (cin >> n) { + for (int i = 0; i < n; i++) { + a[i][0] = 1; + a[0][i] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector v(2 * n); + for (int i = 0; i < 2 * n; ++i) cin >> v[i]; + sort(v.begin(), v.end()); + cout << (v[n] > v[n - 1] ? "YES\n" : "NO\n"); + return 0; +} +int main() { + priority_queue q; + int n, x, y, temp = 0, t = 0; + cin >> n >> x; + for (int i = 2; i <= n; i++) { + cin >> y; + if (y >= x) q.push(y); + } + while (!q.empty()) { + t = q.top(); + q.pop(); + if (t >= x) { + t--; + x++; + q.push(t); + temp++; + } + } + cout << temp << endl; + return 0; +} +long long l, r, c1, c2, x, y, mid; +long long rexxx(long long a, long long b, long long c) { + long long res = 0; + for (int i = 0; i <= y; i++) { + long long t = min(y - i, a + i - b - c); + if (t >= 0) { res += 1LL * (t + 2) * (t + 1) / 2; } + } + return res; +} +int main() { + long long ans = 0; + cin >> c1 >> c2 >> x >> y; + for (int i = 0; i <= y; i++) { ans += 1LL * (i + 2) * (i + 1) / 2; } + ans -= rexxx(c1, c2, x); + ans -= rexxx(c2, c1, x); + ans -= rexxx(x, c2, c1); + cout << ans << endl; +} +int main() { + long long a, b; + cin >> a >> b; + long long c = min(a, b); + long long ans = 1; + for (int i = 1; i <= c; i++) ans *= i; + cout << ans << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i <= n / 2; i++) { + for (int j = 0; j < (n - i * 2 - 1) / 2; j++) { cout << "*"; } + for (int j = 0; j < i * 2 + 1; j++) { cout << "D"; } + for (int j = 0; j < (n - i * 2 - 1) / 2; j++) { cout << "*"; } + cout << "\n"; + } + int i2 = n / 2 - 1; + for (int i = n / 2 + 1; i < n; i++) { + for (int j = 0; j < (n - i2 * 2 - 1) / 2; j++) { cout << "*"; } + for (int j = 0; j < i2 * 2 + 1; j++) { cout << "D"; } + for (int j = 0; j < (n - i2 * 2 - 1) / 2; j++) { cout << "*"; } + i2--; + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + int m = n / 36; + int q = (n % 36) / 3; + int mo = (n % 36) % 3; + if (mo == 2) q += 1; + if (q == 12) q = 0, m++; + cout << m << " " << q << endl; +} +int main() { + int n, m; + string s; + cin >> n >> m; + cin >> s; + for (int i = 0; i < m; i++) { + int l, r; + char a, b; + cin >> l >> r >> a >> b; + for (int j = l - 1; j <= r - 1; j++) { + if (s[j] == a) s[j] = b; + } + } + cout << s << endl; +} +int freq[4]; +int main() { + freq[0] = 1e9; + int n; + cin >> n; + int A[n]; + for (int i = 0; i < n; ++i) { + cin >> A[i]; + ++freq[A[i]]; + } + int *min = min_element(freq, freq + 4); + vector p1, p2, p3; + for (int i = 0; i < n; ++i) { + if (A[i] == 1) { + p1.push_back(i + 1); + } else if (A[i] == 2) { + p2.push_back(i + 1); + } else if (A[i] == 3) { + p3.push_back(i + 1); + } + } + cout << *min << '\n'; + for (int i = 0; i < *min; ++i) { cout << p1[i] << " " << p2[i] << " " << p3[i] << '\n'; } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int mn = min(a, b), mx = max(a, b); + cout << mn << " " << (mx - mn) / 2 << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M; + K = 31; + if (N == 4 || N == 6 || N == 9 || N == 11) K = 30; + if (N == 2) K = 28; + K += M - 1; + cout << K / 7 + !!(K % 7) << endl; + return 0; +} +int main() { + int n, k, a, b = 1, c = 0, d = 0, e, s[117]; + cin >> n >> k; + for (int i = 1; i <= n; i++) { cin >> s[i]; } + while (b <= n) { + e = s[b] + d; + if (e <= 8) { + c = c + e; + d = 0; + b++; + if (c >= k) { break; } + } else if (e > 8) { + c = c + 8; + d = e - 8; + b++; + if (c >= k) { break; } + } + } + if (c < k) { + cout << -1 << endl; + } else { + cout << b - 1 << endl; + } + return 0; +} +bool search(int ax, int ay, int bx, int by, int cx, int cy) { + if (bx < ax && cx < ax && by < ay && cy < ay) + return true; + else if (bx < ax && cx < ax && by > ay && cy > ay) + return true; + else if (bx > ax && cx > ax && by < ay && cy < ay) + return true; + else if (bx > ax && cx > ax && by > ay && cy > ay) + return true; + return false; +} +int main() { + int n, ax, ay, bx, by, cx, cy; + cin >> n >> ax >> ay >> bx >> by >> cx >> cy; + if (search(ax, ay, bx, by, cx, cy)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, result, c; + cin >> n; + c = n % 10; + if (c <= 5) { + result = n - c; + } else { + result = n + (10 - c); + } + cout << result << endl; + return 0; +} +int main() { + int aa, b, c, count = 0; + cin >> aa >> b >> c; + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 0; i < n; i++) { + if (a[i] > b && a[i] < c) { count++; } + } + cout << count << endl; +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) + cout << "NO\n"; + else + cout << "YES\n"; + return 0; +} +bool now[30]; +char a[100010]; +bool b[30], mark[30]; +int main() { + int n; + cin >> n; + char c; + string s; + int cnt = 0; + int cnt3 = 0; + int ans = 0; + bool ho = 0; + for (int x = 1; x <= n; ++x) { + cin >> c >> s; + if (x == n) break; + int l = s.length(); + memset(now, 0, sizeof(now)); + int cnt2 = 0; + if (cnt3 == 25) cnt = 1; + if (c == '!') { + if (cnt == 1) { + ans++; + continue; + } + if (ho == 0) { + for (int i = 0; i < l; ++i) { + if (mark[s[i] - 'a'] == 0) { + a[++cnt] = s[i]; + mark[s[i] - 'a'] = 1; + } + } + for (int i = 1; i <= cnt; ++i) { + if (b[a[i] - 'a'] == 0) a[++cnt2] = a[i]; + } + ho = 1; + cnt = cnt2; + continue; + } + for (int i = 0; i < l; ++i) now[s[i] - 'a'] = 1; + for (int i = 1; i <= cnt; ++i) { + if (now[a[i] - 'a'] == 1 && b[a[i] - 'a'] == 0) { a[++cnt2] = a[i]; } + } + cnt = cnt2; + } else if (c == '.') { + if (cnt == 1) continue; + for (int i = 0; i < l; ++i) { + if (b[s[i] - 'a'] == 0) { + b[s[i] - 'a'] = 1; + cnt3++; + } + } + for (int i = 0; i < l; ++i) { now[s[i] - 'a'] = 1; } + for (int i = 1; i <= cnt; ++i) { + if (now[a[i] - 'a'] == 0) { a[++cnt2] = a[i]; } + } + cnt = cnt2; + } else { + if (cnt == 1) { + ans++; + continue; + } + if (b[s[0] - 'a'] == 0) cnt3++; + b[s[0] - 'a'] = 1; + for (int i = 1; i <= cnt; ++i) { + if (a[i] == s[0]) continue; + a[++cnt2] = a[i]; + } + cnt = cnt2; + } + } + cout << ans << endl; + return 0; +} +const int oo = 1e9; +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int mn = *min_element(a.begin(), a.end()); + int ans = oo; + for (int i = 0, prev = -oo; i < n; i++) + if (a[i] == mn) { + ans = min(ans, i - prev); + prev = i; + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + int sum = 0; + for (int i = 0; i < n; ++i) { + int ele; + cin >> ele; + sum += ele % k == 0 ? ele / k : (ele / k) + 1; + } + cout << (sum + 1) / 2 << endl; + } +} +long long n, k, x; +int main() { + cin >> n >> k; + x = (n / 2) / (1 + k); + cout << x << " " << x * k << " " << n - x * (1 + k) << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[105]; + for (int i = 1; i <= n; i++) cin >> a[i]; + int Min = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + int ans = 0; + for (int j = 1; j <= n; j++) { + if (j > i) + ans += (j - 1) * 4 * a[j]; + else + ans += (i - 1) * 4 * a[j]; + } + Min = min(Min, ans); + } + cout << Min << endl; + } + return 0; +} +int main() { + char arr[105]; + while (cin >> arr) { + int len = strlen(arr); + char c = 'a'; + int x = 0; + for (int i = 0; arr[i]; i++) { + int t = abs(arr[i] - c); + x += min(t, 26 - t); + c = arr[i]; + } + cout << x << endl; + } + return 0; +} +int main() { + int i; + string a; + cin >> a; + for (i = 0; a[i] != '.'; i++) + ; + if (a[i - 1] == '9') + cout << "GOTO Vasilisa."; + else if (a[i + 1] < '5') + for (int j = 0; j < i; j++) cout << a[j]; + else { + for (int j = 0; j < i - 1; j++) cout << a[j]; + a[i - 1]++; + cout << a[i - 1]; + } + cout << endl; + return 0; +} +int main() { + int n, k; + int a[105] = {12, 13}; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) + if (k / a[i] == k * 1.0 / a[i]) + a[i] = k / a[i]; + else + a[i] = 0; + sort(a, a + n); + int i = 0; + while (a[i] == 0) i++; + cout << a[i] << endl; +} +long long dfs(long long s, long long x) { + if (x == 0 && s % 2 == 1) + return 0; + else if (x == 1 && s % 2 == 0) + return 0; + else if (s == 0 && x != 0) + return 0; + else if (s < 0) + return 0; + else if (s % 2 == 0 && x == 0) + return 1; + else { + long long temp = 0; + if (x % 2 == 0) { + if (s % 2 == 1) return 0; + temp += dfs((s - 2) / 2, x / 2); + temp += dfs(s / 2, x / 2); + } else { + if (s % 2 == 0) return 0; + temp += 2 * dfs((s - 1) / 2, x / 2); + } + return temp; + } +} +int main() { + long long ss, xx; + cin >> ss >> xx; + long long ans = dfs(ss, xx); + if (ss == xx) ans -= 2; + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + long long k = s.size(); + long long a = k + 1; + long long b = a * 26; + b = b - k; + cout << b << endl; +} +int main() { + int r, c; + cin >> r >> c; + string s[r]; + for (int i = 0; i < r; i++) { cin >> s[i]; } + char ch; + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (j == 0) { + if (i & 1) + ch = 'W'; + else + ch = 'B'; + } else { + if (ch == 'B') + ch = 'W'; + else + ch = 'B'; + } + if (s[i][j] == '.') + cout << ch; + else + cout << s[i][j]; + } + cout << "\n"; + } + return 0; +} +int n, d, mx; +int pre[105]; +int main() { + mx = -1; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> pre[i]; + sort(pre, pre + n); + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { + if (pre[j] - pre[i] <= d) { mx = mx > j - i + 1 ? mx : j - i + 1; } + } + } + cout << n - mx << endl; + return 0; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long x; + cin >> x; + long long temp = 180 - x; + if (temp <= 0) { + cout << "NO" << endl; + } else if (360 % temp == 0 && 360 / temp > 2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +stack s; +int main() { + long long n; + cin >> n; + while (n) s.push(n % 10), n /= 10; + n = 0; + while (!s.empty()) { + if (s.top() == 4 || s.top() == 7) ++n; + s.pop(); + } + if (!n) puts("NO"), exit(0); + while (n) s.push(n % 10), n /= 10; + while (!s.empty()) { + if (s.top() != 4 && s.top() != 7) puts("NO"), exit(0); + s.pop(); + } + puts("YES"); + ; + ; + return 0; +} +void cpr(string s, vector v) { + long long i = 0; + for (char c : s) { + if (c == '$') + cout << v[i++]; + else + cout << c; + } + cout << '\n'; +} +void cpr(string s) { + cpr(s, {}); +} +void solve(); +int main() { + solve(); + return 0; +} +long long n, k; +const long long borne = 105; +long long a[borne]; +void solve() { + cin >> n >> k; + long long c1 = 0, c2 = 0; + for (long long i = (0); i < (n); ++i) { + cin >> a[i]; + if (a[i] == 1) + ++c1; + else + ++c2; + } + long long oc1 = c1, oc2 = c2; + long long rep = 0; + for (long long i = (0); i < (n); ++i) { + for (long long j = (-(n + 2)); j < (n + 2); ++j) { + long long c = i + j * k; + if (0 <= c && c < n) { + if (a[c] == 1) + --c1; + else + --c2; + } + } + rep = max(rep, (abs(c1 - c2))); + c1 = oc1; + c2 = oc2; + } + cout << rep << "\n"; +} +int Noofintersectionsleft(int n, int m) { + return n * m - (n + m) + 1; +} +int main() { + int a; + int b; + cin >> a; + cin >> b; + int count = 0; + while (a * b >= 0) { + if (Noofintersectionsleft(a, b) <= 0) { + if (count % 2 == 0) { + cout << "Akshat" << endl; + return 0; + } else { + cout << "Malvika" << endl; + return 0; + } + } + a = a - 1; + b = b - 1; + count += 1; + } +} +int main() { + int i, Len, k, Arr[26] = {0}; + string s, kString; + cin >> k >> s; + for (i = 0; i < s.length(); i++) { Arr[s[i] - 'a']++; } + for (i = 0; i < 26; i++) { + if (Arr[i] % k != 0) + { + break; + } else { + kString.append(Arr[i] / k, 'a' + i); + } + } + if (i == 26) { + while (k--) { cout << kString; } + cout << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int sum = 0; +int main() { + int matrix[5][5]; + int x; + pair ch; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> x; + matrix[i][j] = x; + if (x == 1) { + ch.first = i; + ch.second = j; + } + } + } + if (ch.first < 2) sum = sum + (2 - ch.first); + if (ch.first > 2) sum = sum + (ch.first - 2); + if (ch.second < 2) sum = sum + (2 - ch.second); + if (ch.second > 2) sum = sum + (ch.second - 2); + cout << sum << endl; + sum = 0; + return 0; +} +const char *str = "6789TJQKA"; +bool cmp(char a, char b) { + int a1, b1; + for (int i = 0; i < 9; i++) { + if (str[i] == a) a1 = i; + if (str[i] == b) b1 = i; + } + return a1 > b1; +} +int main() { + char trump; + char f1, f2, s1, s2; + cin >> trump >> f1 >> f2 >> s1 >> s2; + if (f2 == s2) { + if (cmp(f1, s1)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else if (f2 == trump && s2 != trump) { + cout << "YES" << endl; + } else if (s2 == trump && f2 != trump) { + cout << "NO" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int inf = 0x3f3f3f3f; +const int maxn = 2000005; +int n; +int main() { + long long n; + while (cin >> n) { + long long cnt = 0; + while (cnt * (cnt + 1) / 2 < n) cnt++; + cnt--; + cout << n - cnt * (cnt + 1) / 2 << endl; + } +} +int main() { + int n; + string str; + cin >> n >> str; + int ret = 0; + for (int i = 0; i < (n); ++i) { + ret++; + if (str[i] == '0') break; + } + cout << ret << endl; + return 0; +} +int main() { + string s; + cin >> s; + int c = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] == 'Q') { + for (int f = i + 1; f < s.size(); f++) { + if (s[f] == 'A') { + for (int k = f + 1; k < s.size(); k++) { + if (s[k] == 'Q') { c++; } + } + } + } + } + } + cout << c << endl; + return 0; +} +const int maxn = 200100; +long long n; +long long sum = 0; +long long ans = 0; +long long i; +int a[maxn]; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + sum = (sum + 1) / 2; + i = 1; + while (ans < sum) { + ans += a[i]; + i++; + } + cout << i - 1 << endl; + return 0; +} +int main() { + int y, n, i, ch = 0; + cin >> n; + int a, b, c, d; + for (i = 0; i < 8000; i++) { + n++; + y = n; + a = y % 10; + y = y / 10; + b = y % 10; + y = y / 10; + c = y % 10; + y = y / 10; + d = y; + if (a != b && a != c && a != d && b != c && b != d && c != d) { + cout << d << c << b << a << endl; + return 0; + } + } +} +int main() { + char s[102]; + int flag = 0; + cin >> s; + for (int i = 0; i < strlen(s); i++) { + if (s[i] == 'h') { + for (int j = i + 1; j < strlen(s); j++) { + if (s[j] == 'e') { + for (int k = j + 1; k < strlen(s); k++) { + if (s[k] == 'l') { + for (int l = k + 1; l < strlen(s); l++) { + if (s[l] == 'l') { + for (int m = l + 1; m < strlen(s); m++) { + if (s[m] == 'o') { flag = 1; } + } + } + } + } + } + } + } + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long n, k; +long long cl(long long n, long long k) { + if (n % k == 0) return n / k; + return n / k + 1; +} +int main() { + cin >> n >> k; + cout << cl(k, n) << "\n"; + return 0; +} +long int k, flag = 0; +vector ans; +void dfs(long long int n, long long int level) { + if (n == k) { flag = 1; } + if (2 * n <= k && flag == 0) { dfs(2 * n, level + 1); } + if (10 * n + 1 <= k && flag == 0) { dfs(10 * n + 1, level + 1); } + if (flag == 1) { ans.push_back(n); } + return; +} +int main() { + long long int n; + cin >> n >> k; + dfs(n, 1); + if (flag == 1) { + cout << "YES" << endl; + int sz = ans.size(); + cout << sz << endl; + for (long long int i = sz - 1; i >= 1; i--) { cout << ans[i] << " "; } + if (sz >= 1) cout << ans[0] << endl; + return 0; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + long long int n, m, k, l, j, p; + cin >> n; + if (n < 10) { + if (n <= 5) { + cout << 0 << endl; + } else { + p = n + (10 - n); + cout << p << endl; + } + } else { + k = n % 10; + if (k == 0) { + cout << n << endl; + } else { + if (k <= 5) { + l = n - (k); + cout << l << endl; + } else { + j = n + (10 - k); + cout << j << endl; + } + } + } +} +int main() { + int a, b = 0, c = 0; + cin >> a; + while (b < a) { + b += 5; + c++; + } + cout << c << endl; +} +int check(int x) { + if (x < 0) return 1; + int t = sqrt(x); + if (t * t == x) + return 0; + else + return 1; +} +int main() { + int n; + cin >> n; + int a[1005]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (check(a[i])) { + cout << a[i] << endl; + break; + } + } +} +int main() { + int n; + cin >> n; + int i; + vector x(n); + vector y(n); + vector z(101, 1); + for (i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + int k; + for (i = 1; i < n; i++) { + for (k = x[i]; k < y[i]; k++) { z[k] = 0; } + } + int ct = 0; + for (i = x[0]; i < y[0]; i++) { + if (z[i] == 1) { ct++; } + } + cout << ct << endl; + return 0; +} +int main() { + int grid[5][5]; + int ans[5][5]; + for (int i = 1; i <= 3; ++i) + for (int j = 1; j <= 3; ++j) cin >> grid[i][j], ans[i][j] = 1; + for (int i = 1; i <= 3; ++i) { + for (int j = 1; j <= 3; ++j) { + if (grid[i][j] % 2 == 1) { + ans[i][j] = !ans[i][j]; + ans[i][j + 1] = !ans[i][j + 1]; + ans[i][j - 1] = !ans[i][j - 1]; + ans[i - 1][j] = !ans[i - 1][j]; + ans[i + 1][j] = !ans[i + 1][j]; + } + } + } + for (int i = 1; i <= 3; ++i) { + for (int j = 1; j <= 3; ++j) cout << ans[i][j]; + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n][n]; + for (int i = 0; i < n; i++) a[0][i] = 1; + for (int i = 0; i < n; i++) a[i][0] = 1; + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { a[i][j] = a[i][j - 1] + a[i - 1][j]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +long long pwr(long long base, long long p, long long mod = (1000000007LL)) { + long long ans = 1; + while (p) { + if (p & 1) ans = (ans * base) % mod; + base = (base * base) % mod; + p /= 2; + } + return ans; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long nCr(long long n, long long r) { + long long C[r + 1]; + memset(C, 0, sizeof(C)); + C[0] = 1; + for (long long i = 1; i <= n; i++) + for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1]; + return C[r]; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n == 2) return true; + if (n % 2 == 0) return false; + long long m = sqrt(n); + for (long long i = 3; i <= m; i += 2) + if (n % i == 0) return false; + return true; +} +long long M(long long a) { + return (a % (1000000007LL)); +} +bool isPowerOfTwo(long long x) { + return x && (!(x & (x - 1))); +} +int main() { + string str; + cin >> str; + int n = str.length(); + int start = 0, end = n - 1; + vector v(n); + for (long long i = 1; i <= (long long)(n); ++i) { + if (str[i - 1] == 'r') { + v[start] = i; + start++; + } else { + v[end] = i; + end--; + } + } + for (long long i = 0; i < (long long)(n); ++i) { cout << v[i] << endl; } + return 0; +} +int main() { + long long n, a, x, choc = 0; + priority_queue voters; + cin >> n >> a; + for (int i = 0; i < n - 1; i++) { + cin >> x; + voters.push(x); + } + while (a <= voters.top()) { + x = voters.top(); + voters.pop(); + a++; + choc++; + x--; + voters.push(x); + } + cout << choc << endl; + return 0; +} +bool isPrime(int n) { + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) return false; + } + return true; +} +int main() { + int a, b, i; + cin >> a >> b; + i = a + 1; + while (i) { + if (isPrime(i)) { + if (i == b) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + break; + } + i++; + } + return 0; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long a, b, k; + cin >> a >> b >> k; + cout << a * (k - (k / 2)) - b * (k / 2) << endl; + } + return 0; +} +int main() { + int n = 0; + long long sum = 0; + string s = "Null"; + int a = 0; + int c = 0; + cin >> n >> sum; + while (n-- > 0) { + cin >> s; + cin >> a; + if (s == "+") { + sum += a; + } else if (s == "-") { + if (sum < a) { + ++c; + } else { + sum -= a; + } + } + } + cout << sum << " " << c << endl; +} +const int N = 100 + 13; +int n, m; +int a[N]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int answer = *max_element(a, a + n) + m; + for (int i = 0; i < m; i++) { + int pos = -1; + for (int i = 0; i < n; i++) { + if (pos == -1 || a[i] < a[pos]) { pos = i; } + } + assert(pos != -1); + a[pos]++; + } + int ans1 = *max_element(a, a + n); + cout << ans1 << ' ' << answer << endl; + return 0; +} +int main() { + int n; + int S; + cin >> n >> S; + if (S % n == 0) { + cout << S / n << endl; + } else { + cout << S / n + 1 << endl; + } + return 0; +} +int main() { + int n, m, mn, mx; + cin >> n >> m >> mn >> mx; + int cmn = 1000000000; + int cmx = 0; + for (int i = 0; i < m; i++) { + int a; + cin >> a; + cmn = min(cmn, a); + cmx = max(cmx, a); + } + int hmr = n - m; + int hmn = 0; + if (cmn < mn || cmx > mx) { + cout << "Incorrect" << endl; + return 0; + } + if (cmn != mn) { hmn++; } + if (cmx != mx) { hmn++; } + if (hmr < hmn) { + cout << "Incorrect" << endl; + return 0; + } + cout << "Correct" << endl; + cin >> n; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "0" << endl; + } else + cout << "1" << endl; + return 0; +} +int lucky_digits(int val) { + int digit = 0; + while (val > 0) { + if (val % 10 == 4 || val % 10 == 7) digit++; + val /= 10; + } + return digit; +} +int main() { + int n, k; + cin >> n >> k; + int ret = 0; + for (int i = 0; i < n; i++) { + int val; + cin >> val; + if (lucky_digits(val) <= k) ret++; + } + cout << ret << endl; +} +int main() { + int n; + bool up = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n > 1) { + if (a[n - 1] > a[n - 2]) { up = 1; } + if (up) { + if (a[n - 1] == 15) { + cout << "DOWN" << '\n'; + } else { + cout << "UP" << '\n'; + } + } else { + if (a[n - 1] == 0) { + cout << "UP" << '\n'; + } else { + cout << "DOWN" << '\n'; + } + } + } else { + if (a[n - 1] == 15) { + cout << "DOWN" << '\n'; + } else if (a[n - 1] == 0) { + cout << "UP" << '\n'; + } else { + cout << -1 << '\n'; + } + } +} +int main() { + string d; + int m = 0, a = 97; + cin >> d; + int z = d.length(); + for (int i = 0; i < z; i++) { + char x = d.at(i); + int c = int(x); + if (c >= a) + c = c - a; + else if (c < a) + c = a - c; + if (c <= 13) + m = m + c; + else if (c > 13) + m = m + (26 - c); + a = int(x); + } + cout << m << endl; + return 0; +} +int i, j, k, l, a, b, c, d, x, y, z, f, cnt, p, n, m, tc, ans; +string s, str, s1, s2, s3, st; +int main() { + cin >> n; + a = 0; + b = 0; + while (n--) { + cin >> x >> y; + if (x > y) a++; + if (x < y) b++; + } + if (a > b) cout << "Mishka" << endl, exit(0); + if (b > a) cout << "Chris" << endl, exit(0); + cout << "Friendship is magic!^^" << endl; +} +int main() { + long long int n, i; + cin >> n; + long long int a, b, k, r, l; + for (i = 0; i < n; i++) { + cin >> a >> b >> k; + r = ((k / 2) + (k % 2)); + l = (k / 2); + cout << ((r * a) - (b * l)) << "\n"; + } +} +int main() { + int t, k; + cin >> t; + for (k = 0; k < t; k++) { + int n; + char a[102]; + cin >> a; + n = strlen(a) - 2; + if (n + 2 <= 10) + cout << a; + else + cout << a[0] << n << a[n + 1]; + cout << '\n'; + } +} +long long n, t, e, f, g, y; +long long Ta[5001][4] = {0, 0}; +int main() { + cin >> n; + for (int x = 1; x <= n; x++) { + cin >> t; + if (t == 1) { + Ta[x - f - g][1] = x; + e++; + } else if (t == 2) { + Ta[x - e - g][2] = x; + f++; + } else if (t == 3) { + Ta[x - e - f][3] = x; + g++; + } + } + for (int x = 1; x <= n; x++) { + if (Ta[x][1] != 0 && Ta[x][2] != 0 && Ta[x][3] != 0) { y++; } + } + if (y == 0) { + cout << "0" << endl; + } else { + cout << y << endl; + for (int x = 1; x <= y; x++) { cout << Ta[x][1] << " " << Ta[x][2] << " " << Ta[x][3] << endl; } + } + return 0; +} +int main() { + int n, x, a[5000]; + cin >> n; + vector p, m, e; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) { + if (a[i] == 1) + p.push_back(i); + else if (a[i] == 2) + m.push_back(i); + else + e.push_back(i); + } + x = min(p.size(), min(m.size(), e.size())); + cout << x << endl; + for (int i = 0; i < x; i++) { cout << p[i] + 1 << " " << m[i] + 1 << " " << e[i] + 1 << endl; } + return 0; +} +int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int n, d, ans = 1; + cin >> n >> d; + ans = (d + day[n] - 1) / 7; + if (ans * 7 == d + day[n] - 1) + cout << ans << endl; + else + cout << ans + 1 << endl; + return 0; +} +const int M = 3000 + 10; +int main() { + string a, b; + cin >> a >> b; + int len = a.length(); + int num4 = 0; + int num7 = 0; + for (int i = 0; i < len; i++) { + if (a[i] != b[i]) { + if (a[i] == '4') { + num4++; + } else { + num7++; + } + } + } + int ans = min(num4, num7) + max(num4, num7) - min(num4, num7); + cout << ans << endl; + return 0; +} +const int maxn = 105; +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + cout << (a + b + c) * (a + b + c) - a * a - c * c - e * e << endl; +} +const int MX = 200005; +int n, res = 2e9, a[MX]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int i = n / 2 - 1, j = n - 1; + while (i >= 0) res = min(res, a[j] - a[i]), i--, j--; + cout << res << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + long long a[n]; + long long cnt = 0, mx = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + mx = max(a[i], mx); + } + for (int i = 0; i < n; i++) { cnt += (mx - a[i]); } + cout << cnt << endl; + return 0; +} +bool visit[204]; +vector dependency[204]; +int col[203]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> col[i]; } + for (int i = 1; i <= n; i++) { + int k; + cin >> k; + for (int j = 1; j <= k; j++) { + int m; + cin >> m; + dependency[i].push_back(m); + } + } + int ans = INT_MAX; + for (int l = 1; l <= 3; l++) { + int hours = 0, cur = l, vis = 0; + for (int i = 1; i <= n; i++) { visit[i] = false; } + while (vis != n) { + bool cvis = false; + for (int i = 1; i <= n; i++) { + if (!visit[i] && col[i] == cur) { + bool cr = true; + for (int j = 0; j < dependency[i].size(); j++) { + if (!visit[dependency[i][j]]) { + cr = false; + break; + } + } + if (cr) { + visit[i] = true; + vis++; + cvis = true; + hours++; + break; + } + } + } + if (!cvis) { + cur = 1 + (cur) % 3; + hours++; + } + } + ans = min(ans, hours); + } + cout << ans << endl; + return 0; +} +int main() { + int N, B, P; + cin >> N >> B >> P; + int Ile = 0; + int Reczniki = N * P; + while (N > 1) { + int Potega = 1; + while (Potega * 2 <= N) { Potega *= 2; } + int IleMeczy = Potega / 2; + Ile += IleMeczy * 2 * B + IleMeczy; + N = (N - Potega) + IleMeczy; + } + cout << Ile << " " << Reczniki << "\n"; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + puts("-1"); + else + cout << max(a.length(), b.length()) << endl; + return 0; +} +string s1, s2; +int main() { + cin >> s1 >> s2; + if (s1 == s2) { + cout << s1 << endl; + } else { + cout << 1 << endl; + } +} +const int MAXN = 100; +const long long int MOD = 1e9 + 7; +long long int dos_a_la[(2 * MAXN) + 2]; +long long int f(int n, const string &x) { + if (n == 0) return 0; + long long int ret = 2 * f(n - 1, x); + ret %= MOD; + if (x[n] == '1') { + ret += dos_a_la[2 * (n - 1)]; + ret %= MOD; + } + return ret; +} +void init() { + dos_a_la[0] = 1; + for (int i = 1; i <= (2 * MAXN); i++) { + dos_a_la[i] = dos_a_la[i - 1]; + dos_a_la[i] <<= 1; + dos_a_la[i] %= MOD; + } +} +int main() { + init(); + string x; + cin >> x; + reverse(x.begin(), x.end()); + x = "0" + x; + cout << f(x.size() - 1, x) << "\n"; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int x1, y1, x2, y2; + if (x > 0 && y > 0) { + x1 = 0; + y1 = x + y; + x2 = y1; + y2 = 0; + } else if (x < 0 && y > 0) { + x1 = -1 * (abs(x) + y); + y1 = 0; + x2 = 0; + y2 = abs(x1); + } else if (x < 0 && y < 0) { + x1 = -1 * (abs(x) + abs(y)); + y1 = 0; + x2 = 0; + y2 = x1; + } else { + x2 = abs(x) + abs(y); + y2 = 0; + x1 = 0; + y1 = -1 * x2; + } + cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl; +} +int main() { + int n, k; + while (cin >> n >> k) { + vector A(n); + for (__typeof(0) i = (0); i < (n); i++) cin >> A[i]; + int ans = 0; + int i = 0; + for (; i < n; i++) { + if (A[i] <= k) + ans++; + else + break; + } + for (int j = n - 1; j > i; j--) { + if (A[j] <= k) + ans++; + else + break; + } + cout << ans << '\n'; + } + return 0; +} +int main() { + long long int n, i, sum = 0, max1 = 0, ans, sum1, i1, j; + cin >> n; + long long int a[n + 2]; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + max1 = max(max1, a[i]); + } + for (j = max1; j <= (max1 * 2) + 2; j++) { + sum1 = 0; + for (i1 = 0; i1 < n; i1++) { sum1 = sum1 + (j - a[i1]); } + if (sum1 > sum) { + ans = j; + break; + } + } + cout << ans << endl; +} +int mi(int a, int b, int c) { + if (a < b) { + if (a < c) + return a; + else + return c; + } else { + if (b < c) + return b; + else + return c; + } +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int num1, num2, num3; + num1 = (k * l) / nl; + num2 = c * d; + num3 = p / np; + int m = mi(num1, num2, num3); + cout << (m / n) << endl; + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +const long long MOD = 1e9 + 7; +map m; +void solve() { + int k; + cin >> k; + string s; + cin >> s; + int n = s.size(); + if (n % k != 0) { + cout << -1 << endl; + return; + } + int need = n / k; + for (int i = 0; i < n; i++) { m[s[i]]++; } + string t = ""; + for (int i = 97; i < 123; i++) { + if (m[char(i)] % k == 0) { + for (int j = 0; j < m[char(i)] / k; j++) { t += char(i); } + } else { + cout << -1 << endl; + return; + } + } + for (int i = 0; i < k; i++) { cout << t; } + cout << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector a, b; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + a.push_back(x); + } + for (int i = 0; i < m; i++) { + cin >> x; + b.push_back(x); + } + sort(a.begin(), a.end()); + sort(b.begin(), b.end()); + if (a[n - 1] >= b[0]) { + cout << "-1" << endl; + return 0; + } + if (a[0] * 2 >= b[0]) { + cout << "-1" << endl; + return 0; + } + cout << max(a[n - 1], a[0] * 2) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i, j; + char a[n][m]; + int flag = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (i % 2 == 0) + a[i][j] = '#'; + else + a[i][j] = '.'; + } + if (i % 2 != 0) { + if (flag == 0) { + a[i][m - 1] = '#'; + flag = 1; + } else { + a[i][0] = '#'; + flag = 0; + } + } + } + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { cout << a[i][j]; } + cout << endl; + } +} +int main() { + int n; + string s; + cin >> n >> s; + for (int i = 1; i <= n; i++) { cin >> s; } + if (n & 1) { + cout << "contest" + << "\n"; + } else { + cout << "home" + << "\n"; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long ans = s / c; + long long num = ans / a; + ans += b * num; + cout << ans << '\n'; + } + return 0; +} +int main() { + int n, k; + cin >> n; + k = n + (n / 2); + cout << k << endl; + return 0; +} +int main() { + long long ans = 1; + int n, m; + cin >> n >> m; + long long pw = 1; + while (m) { + pw *= 2; + m--; + pw %= (long long)(1e9 + 9); + } + for (int i = 1; i <= n; i++) { + ans *= pw - i; + ans %= (long long)(1e9 + 9); + } + cout << ans << endl; + return 0; +} +int k; +string in; +bool vis[50]; +int main() { + cin >> k; + cin >> in; + int len = in.length(), count = 0; + for (int i = 0; i < len; i++) { + int now = in[i] - 'a'; + if (vis[now]) continue; + count++; + vis[now] = 1; + } + if (count < k) { + puts("NO"); + exit(0); + } + puts("YES"); + memset(vis, 0, sizeof(vis)); + string ans = ""; + ans += in[0]; + int cur = in[0] - 'a'; + vis[cur] = 1; + for (int i = 1; i < len; i++) { + int now = in[i] - 'a'; + if (vis[now] || k == 1) { + ans += in[i]; + continue; + } + vis[now] = 1; + cout << ans << endl; + k--; + ans = ""; + ans += in[i]; + } + if (!ans.empty()) cout << ans << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long part = 0; + if (n % 2 == 0) + part = n / 2; + else + part = (n / 2) + 1; + if (k <= part) { + cout << (k * 2) - 1 << endl; + } else { + cout << (k - part) * 2 << endl; + } +} +int main() { + string s; + cin >> s; + char c = *max_element(s.begin(), s.end()); + int maxcount = count(s.begin(), s.end(), c); + for (int i = 0; i < maxcount; i++) cout << c; + cout << endl; + return 0; +} +const double pi = 3.14159265359; +const int INF = 0x3f3f3f3f; +int main() { + int n, m; + cin >> n >> m; + if (min(n, m) % 2 == 0) + cout << "Malvika\n"; + else + cout << "Akshat\n"; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0, a, b, ans = 0; i < n; ++i) { + cin >> a >> b; + for (; min(a, b) != 0;) { + ans += max(a, b) / min(a, b); + if (a >= b) + a = a % b; + else + b = b % a; + } + cout << ans << endl; + ans = 0; + } +} +int main() { + int a[6], s = 0, f = 0; + for (int i = 0; i < 6; i++) { + cin >> a[i]; + s += a[i]; + } + if (s % 2 != 1) { + for (int i = 0; i < 6; i++) { + for (int j = i + 1; j < 6; j++) { + for (int k = j + 1; k < 6; k++) { + if (a[i] + a[j] + a[k] == (s / 2)) { + f = 1; + break; + } + } + } + } + } + if (f == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int hh, mm, x; +void CalTime(int &h, int &m, int x) { + bool tag; + do { + tag = true; + if (m - x >= 0) { + m -= x; + break; + } else { + m += 60; + if (h - 1 < 0) + h = 23; + else + h -= 1; + if (m - x >= 0) { + tag = false; + m -= x; + } + } + } while (tag == true); +} +int main() { + cin >> x; + cin >> hh >> mm; + int count = 0; + while (hh % 10 != 7 && mm % 10 != 7) { + CalTime(hh, mm, x); + count++; + } + cout << count << endl; + return 0; +} +int main() { + string str; + cin >> str; + int L[100]; + int R[100]; + memset(L, 0, sizeof(L)); + memset(R, 0, sizeof(R)); + int count = 0; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'Q') count++; + if (str[i] == 'A') L[i] = count; + } + count = 0; + for (int i = str.length() - 1; i >= 0; i--) { + if (str[i] == 'Q') count++; + if (str[i] == 'A') R[i] = count; + } + int result = 0; + for (int i = 0; i < str.length(); i++) { + if (L[i] != 0 && R[i] != 0) { + int temp = L[i] * R[i]; + result += temp; + } + } + cout << result << endl; + return 0; +} +int n, m; +int price[105]; +int match[105][105]; +int main() { + while (cin >> n >> m) { + memset(match, 0, sizeof(match)); + for (int i = 1; i <= n; i++) cin >> price[i]; + int u, v; + for (int i = 0; i < m; i++) { + cin >> u >> v; + match[u][v] = 1; + match[v][u] = 1; + } + int MIN = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) { + for (int j = i + 1; j <= n; j++) { + if (match[i][j] == 0) continue; + for (int k = j + 1; k <= n; k++) { + if (match[j][k] == 0 || match[k][i] == 0) continue; + if (MIN > price[i] + price[j] + price[k]) MIN = price[i] + price[j] + price[k]; + } + } + } + if (MIN == 0x3f3f3f3f) + cout << -1 << endl; + else + cout << MIN << endl; + } +} +bool isPresent(int a[], int n, int e) { + int l = 0, r = n - 1; + while (l <= r) { + int m = (l + r) / 2; + if (a[m] == e) { return true; } + if (a[m] < e) { + l = m + 1; + } else { + r = m - 1; + } + } + return false; +} +int main() { + int n; + cin >> n; + set a; + int b[n], c[n]; + for (int i = 0; i < n; i++) { + cin >> b[i]; + a.insert(b[i]); + } + for (int i = 0; i < n; i++) { + cin >> c[i]; + a.insert(c[i]); + } + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int xor1 = b[i] ^ c[j]; + if (a.find(xor1) != a.end()) { count++; } + } + } + if (count % 2 == 0) { + cout << "Karen" << endl; + } else { + cout << "Koyomi" << endl; + } + return 0; +} +int main() { + int n, x1, x2, y1, y2, sum = 0; + cin >> n; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + sum = sum + (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << sum << endl; + return 0; +} +int main() { + string a, b; + long long n; + cin >> a >> b; + cin >> n; + cout << a << " " << b << endl; + while (n--) { + string a0, b0; + cin >> a0 >> b0; + if (a0 == a) + a = b0; + else if (a0 == b) + b = b0; + cout << a << " " << b << endl; + } +} +int main() { + long long a; + int i = 1; + cin >> a; + while (a > i) { + a -= i; + i++; + } + cout << a << endl; + return 0; +} +int n; +char str[105]; +char ans[105]; +int main() { + cin >> n >> str; + int jw = 1; + for (int i = 0; i < n; ++i) { + int a = str[i] - '0'; + ans[i] = (a + jw) % 2 + '0'; + jw = (a + jw) / 2; + } + int cnt = 0; + for (int i = 0; i < n; ++i) cnt += ans[i] == str[i] ? 0 : 1; + cout << cnt << endl; + return 0; +} +const int maxn = 3e5 + 5; +int main() { + int n, a, b, c; + cin >> n; + cin >> a >> b >> c; + int t = min(a, b); + int m = min(t, c); + if (n == 1) return puts("0"), 0; + if (n == 2) return cout << t << endl, 0; + cout << t + (n - 2) * m << endl; +} +int main() { + int n, m; + cin >> n >> m; + m %= (n * (n + 1) / 2); + for (int i = 1; i <= n; ++i) { + if (m < i) { break; } + m -= i; + } + cout << m << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << min(a, b) << " " << (max(a, b) - min(a, b)) / 2 << endl; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long resa, resb; + long long mod = n % m; + resb = mod * b; + if (n >= m) { + resa = (ceil(double(n) / m) * m - n) * a; + } else + resa = (m - n) * a; + cout << min(resa, resb) << endl; +} +int main() { + int n, p, x, t; + map m; + cin >> p >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + t = m[x % p]; + if (t) { + cout << i << "\n"; + return 0; + } + m[x % p]++; + } + cout << "-1" + << "\n"; + return 0; +} +int main() { + int n, x, y; + cin >> n >> x >> y; + int clones = (n * y + 99) / 100 - x; + if (clones < 0) { clones = 0; } + cout << clones << endl; + return 0; +} +int main() { + char a, b; + cin >> a >> b; + char m[6], n[6]; + for (int i = 0; i < 5; i++) { + cin >> m[i]; + cin >> n[i]; + } + for (int i = 0; i < 5; i++) { + if (a == m[i] || b == n[i]) { + cout << "YES" << endl; + exit(0); + } + } + cout << "NO" << endl; + return 0; +} +int n, k; +int main() { + cin >> n >> k; + k = 240 - k; + for (int i = 1; i <= n; i++) { + if (i * 5 > k) { + cout << i - 1 << endl; + return 0; + } + k -= i * 5; + } + cout << n << endl; + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n, m, x; + cin >> n >> m; + if (n > m) + x = m; + else + x = n; + if (x % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int main() { + int n, k, x, arr[102], y = 0; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = n - k; i < n; i++) { + arr[i] = x; + y += arr[i]; + } + for (int i = 0; i < n - k; i++) { y += arr[i]; } + cout << y << "\n"; +} +int main() { + int x, a, b; + cin >> x; + int num1, num2; + num1 = x % 10; + num2 = x / 10; + if (num1 == 0) + a = 2; + else if (num1 == 1) + a = 7; + else if (num1 == 2) + a = 2; + else if (num1 == 3) + a = 3; + else if (num1 == 4) + a = 3; + else if (num1 == 5) + a = 4; + else if (num1 == 6) + a = 2; + else if (num1 == 7) + a = 5; + else if (num1 == 8) + a = 1; + else if (num1 == 9) + a = 2; + if (num2 == 0) + b = 2; + else if (num2 == 1) + b = 7; + else if (num2 == 2) + b = 2; + else if (num2 == 3) + b = 3; + else if (num2 == 4) + b = 3; + else if (num2 == 5) + b = 4; + else if (num2 == 6) + b = 2; + else if (num2 == 7) + b = 5; + else if (num2 == 8) + b = 1; + else if (num2 == 9) + b = 2; + cout << a * b << endl; + return 0; +} +int main() { + int p, q, n, Cnt = 0; + cin >> n; + while (n--) { + cin >> p >> q; + if (q - p >= 2) Cnt++; + } + cout << Cnt << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) ans += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); + cout << ans << endl; + return 0; +} +const int MAX = 1e10; +set dict; +int main() { + int n, j; + cin >> n; + int arr[6] = {0}; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[i] > 0) { dict.insert(arr[i]); } + } + memset(arr, 0, n); + j = 0; + for (set::iterator it = dict.begin(); it != dict.end(); ++it) arr[j++] = *it; + cout << arr[n / 2] << endl; + return 0; +} +int main() { + int k, a[17], sum = 0, cont = 0; + cin >> k; + for (int i = 0; i < 12; i++) cin >> a[i]; + sort(a, a + 12); + for (int i = 11; i >= 0; i--) { + if (sum >= k) break; + sum += a[i]; + cont++; + } + if (sum < k) cont = -1; + cout << cont << endl; + return 0; +} +int main() { + int a1, a2, k, a3 = 0; + cin >> a1 >> a2; + while (a2 != 0) { + k = a2 % 10; + a3 = a3 * 10 + k; + a2 /= 10; + } + cout << a1 + a3 << endl; + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + if (a[0] + a[1] > a[2]) + cout << 0 << endl; + else + cout << a[2] + 1 - a[0] - a[1] << endl; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n; + cin >> n; + char arr[n][n]; + set s, x; + set::iterator it, it1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> arr[i][j]; + if (i == j) { + s.insert(arr[i][j]); + } else if (i + j == (n - 1)) { + s.insert(arr[i][j]); + } else { + x.insert(arr[i][j]); + } + } + } + if (s.size() > 1 || x.size() > 1) { + cout << "NO" << endl; + } else { + it = s.begin(); + it1 = x.begin(); + if (*it == *it1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +int main() { + int t, k; + cin >> t; + while (t--) { + cin >> k; + cout << ((360 % (180 - k) == 0) ? "YES\n" : "NO\n"); + } + return 0; +} +string raiz(string c) { + int abc[26] = {0}; + string resp; + for (long long i = 0; i < (long long)c.size(); i++) { abc[c[i] - 'a']++; } + for (long long i = 0; i < (long long)26; i++) { + if (abc[i] > 0) resp.push_back((char)(i + 'a')); + } + return resp; +} +int main() { + long long n; + cin >> n; + string arr[n]; + for (long long i = 0; i < (long long)n; i++) { cin >> arr[i]; } + vector raices; + for (long long i = 0; i < (long long)n; i++) { + string aux = raiz(arr[i]); + bool no_encont = true; + for (long long k = 0; k < (long long)raices.size(); k++) { + if (raices[k].compare(aux) == 0) no_encont = false; + } + if (no_encont) raices.push_back(aux); + } + cout << raices.size() << endl; + return 0; +} +int main() { + string s; + while (getline(cin, s)) { + string n = ""; + int d = s.length(); + for (int i = 0; i < d; i++) { + if (s[i] == ' ') { + if (n[n.length() - 1] != ' ') { n = n + s[i]; } + } else if (s[i] == '.' || s[i] == ',' || s[i] == '!' || s[i] == '?') { + if (n[n.length() - 1] != ' ') { + n = n + s[i] + ' '; + } else { + n.erase(n.length() - 1); + n = n + s[i] + ' '; + } + } else { + n = n + s[i]; + } + } + for (int i = 0; i < n.length(); i++) cout << n[i]; + cout << endl; + } + return 0; +} +string s; +vector used; +int main() { + int result = 0, n, m = 0; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (find(used.begin(), used.end(), s[i]) == used.end()) { + used.push_back(s[i]); + result++; + } + } + if (result % 2 != 0) + cout << "IGNORE HIM!" << endl; + else { + cout << "CHAT WITH HER!" << endl; + } + return 0; +} +int main() { + string s[51]; + int m, n; + cin >> n >> m; + getchar(); + for (int i = 0; i < n; i++) { getline(cin, s[i]); } + int count = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + string temp; + temp += s[i][j]; + temp += s[i][j + 1]; + temp += s[i + 1][j]; + temp += s[i + 1][j + 1]; + sort(temp.begin(), temp.end()); + if (temp == "acef") count++; + } + } + cout << count << endl; + return 0; +} +int k[] = {1, 5, 10, 20, 100}; +int n, tot = 0; +int main() { + cin >> n; + for (int i = 4; i >= 0; --i) { + tot += n / k[i]; + n %= k[i]; + } + cout << tot << '\n'; + return 0; +} +long long n, m, ans[110], num[110][110], sum = 0; +string mp[110]; +inline long long read() { + long long x = 0; + bool f = 0; + char ch = getchar(); + for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); + for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); + return f ? -x : x; +} +int main() { + n = read(), m = read(); + for (register int i = 1; i <= n; i++) { getline(cin, mp[i]); } + for (register int i = 1; i <= n; i++) { + for (register int j = 0; j < m; j++) { + if (mp[i][j] - '0' > ans[j]) { ans[j] = mp[i][j] - '0'; } + } + } + for (register int i = 1; i <= n; i++) + for (register int j = 0; j < m; j++) + if (mp[i][j] - '0' == ans[j]) { + sum++; + break; + } + cout << sum << endl; + return 0; +} +bool fit(int a, int k) { + bool arr[k + 1]; + for (int i = 0; i < k + 1; i++) { arr[i] = false; } + while (a > 0) { + if (a % 10 <= k) { arr[a % 10] = true; } + a = a / 10; + } + for (int i = 0; i < k + 1; i++) { + if (arr[i] == false) { return false; } + } + return true; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int counter = 0; + for (int i = 0; i < n; i++) { + if (fit(arr[i], k)) { counter = counter + 1; } + } + cout << counter << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 1) + cout << "1" << endl; + else if (n == 2) + cout << "2" << endl; + else if (n == 3) + cout << "6" << endl; + else if (n == 4) + cout << "20" << endl; + else if (n == 5) + cout << "70" << endl; + else if (n == 6) + cout << "252" << endl; + else if (n == 7) + cout << "924" << endl; + else if (n == 8) + cout << "3432" << endl; + else if (n == 9) + cout << "12870" << endl; + else if (n == 10) + cout << "48620" << endl; + return 0; +} +int main() { + int t, a, b, c; + while (cin >> t >> a >> b) { + c = 0; + for (int i = t; i <= b; i += t) { + for (int j = a; j <= i; j += a) { + if (i == j) c = c + 1; + } + } + cout << c << endl; + } +} +int a[311]; +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + for (int i = 0; i < s.size(); i++) { a[s[i]]++; } + int mn = 1e7; + for (int i = 'A'; i < 'A' + k; i++) { mn = min(mn, a[i]); } + cout << mn * k << endl; +} +int main() { + int x, steps, minstep; + cin >> x; + if (x % 5 == 0) { + steps = x / 5; + cout << steps << endl; + } else { + steps = x / 5; + minstep = steps + 1; + cout << minstep << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int f = 0; + int s = 0; + int cursum = 10000000; + for (int i = 0; i <= n / 7; i++) { + if ((n - 7 * i) % 4 == 0) { + if (i + (n - 7 * i) / 4 < cursum) { + f = (n - 7 * i) / 4; + s = i; + cursum = f + s; + } + } + } + string ans = ""; + for (int i = 0; i < f; i++) ans.append("4"); + for (int i = 0; i < s; i++) ans.append("7"); + if (ans.size() == 0) { + cout << -1 << endl; + return 0; + } + cout << ans << endl; + return 0; +} +const long long MAXN = 2 * 1e5 + 5; +const long long INF = 1e8 + 5; +const long long MOD = 1e9 + 7; +int main() { + long long N, M; + cin >> N >> M; + long long ans; + if (N > 27) + ans = M; + else + ans = M % (1 << N); + cout << ans << endl; + return 0; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << -1 << '\n'; + else + cout << max((int)a.size(), (int)b.size()) << '\n'; + return 0; +} +int main() { + int n, m, i, j; + cin >> n; + cin >> m; + for (i = 1; i <= n; i++) { + for (j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else if ((i % 4 == 0) && (j == 1)) { + cout << "#"; + } else if ((i % 2 == 0) && (j == m) && (i % 4 == 2)) { + cout << "#"; + } else { + cout << "."; + } + } + cout << "\n"; + } + return 0; +} +string a; +string b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + while (cin >> s) { + cin >> v1 >> v2 >> t1 >> t2; + if (s * v1 + 2 * t1 < s * v2 + 2 * t2) + cout << "First" << endl; + else if (s * v1 + t1 * 2 > s * v2 + t2 * 2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + } + return 0; +} +int main() { + string s; + int ans; + cin >> s; + if (s == "a1" || s == "a8" || s == "h1" || s == "h8") + cout << 3 << endl; + else if (s[0] == 'a' || s[0] == 'h' || s[1] == '1' || s[1] == '8') + cout << 5 << endl; + else + cout << 8 << endl; + return 0; +} +int main() { + int c = 0, c1 = 0, c2 = 0; + string s; + cin >> s; + if (s.size() < 5) { + cout << "Too weak" << endl; + return 0; + } else { + for (int i = 0; i < s.size(); i++) { + if (s[i] > 64 && s[i] < 92) + c = 1; + else if (s[i] > 96 && s[i] < 124) + c1 = 1; + else if (s[i] > 46 && s[i] < 60) + c2 = 1; + } + if (c == 1 && c1 == 1 && c2 == 1) { + cout << "Correct" << endl; + } else + cout << "Too weak" << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b, k; + cin >> a >> b >> k; + cout << (k - k / 2) * a - (k / 2) * b << endl; + } + return 0; +} +int main() { + string num; + cin >> num; + int in = 0; + bool sai = true; + while (in < num.size()) { + if (num[in] == '1') { + in++; + if (in < num.size() && num[in] == '4') { + in++; + if (in < num.size() && num[in] == '4') in++; + } + } else { + sai = false; + break; + } + } + if (sai) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, len = 0, maxn = 0, cnt; + string str; + cin >> n; + while (cin >> str) { + cnt = 0; + int l = str.size(); + for (int i = 0; i < l; ++i) + if (isupper(str[i])) cnt++; + maxn = max(maxn, cnt); + len += l; + if (len >= n) break; + len++; + } + cout << maxn << endl; + return 0; +} +void rot(string &s) { + swap(s[1], s[2]); + swap(s[2], s[3]); + swap(s[3], s[4]); +} +void rot2(string &s) { + swap(s[0], s[3]); + swap(s[3], s[5]); + swap(s[5], s[1]); +} +void rot3(string &s) { + swap(s[0], s[2]); + swap(s[2], s[5]); + swap(s[5], s[4]); +} +string all_rot(string s) { + string minstring = s; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + rot(s); + minstring = min(minstring, s); + } + rot2(s); + } + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + rot(s); + minstring = min(minstring, s); + } + rot3(s); + } + return minstring; +} +int main() { + string s; + cin >> s; + sort(((s).begin()), ((s).end())); + set ans; + ans.insert(all_rot(s)); + while (next_permutation(((s).begin()), ((s).end()))) { ans.insert(all_rot(s)); } + cout << ans.size() << "\n"; +} +int main() { + unsigned long long n, x = 0; + cin >> n; + while (1) { + if (x * (x + 1) / 2 >= n) { + cout << n - x * (x - 1) / 2 << endl; + return 0; + } + x++; + } +} +int main() { + int a, b; + cin >> a >> b; + cout << (abs(a - b) <= 1 && a + b > 0 ? "YES\n" : "NO\n"); + return 0; +} +const int maxn = 1e6 + 10; +int n; +int main() { + cin >> n; + int a = 1, b = n; + for (int i = 1; i * i <= n; i++) + if (n % i == 0) a = i, b = n / i; + cout << a << " " << b << endl; +} +int main() { + int n, m; + cin >> n >> m; + int i = 1; + while (true) { + if (m - i >= 0) + m -= i; + else + break; + i++; + if (i > n) i = 1; + } + cout << m << endl; +} +int main() { + int n, s; + cin >> n >> s; + cout << (n + s - 1) / n << endl; + return 0; +} +const int N = 2e5 + 5; +int n, tab[N]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> tab[i]; + tab[i] += tab[i - 1]; + } + for (int i = 1; i <= n; i++) { + if (2 * tab[i] >= tab[n]) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int i; + int l = a.size(); + for (i = 0; i < l; i++) { + if (a[i] < 97) { a[i] = a[i] + 32; } + if (b[i] < 97) { b[i] = b[i] + 32; } + } + if (a < b) { + cout << "-1" << endl; + } else if (a > b) { + cout << "1" << endl; + } else if (a == b) { + cout << "0" << endl; + } + return 0; +} +long long k, n, s, p, temp1, temp2; +int main() { + cin >> k >> n >> s >> p; + temp1 = (n % s == 0 ? n / s : n / s + 1); + if (temp1 * k % p == 0) + temp2 = temp1 * k / p; + else + temp2 = temp1 * k / p + 1; + cout << temp2 << endl; + return 0; +} +const int MAXN = 100; +const long long int MOD = 1e9 + 7; +long long int dos_a_la[(2 * MAXN) + 2]; +long long int f(int n, const string &x) { + if (n == 0) return 0; + long long int ret = 2 * f(n - 1, x); + ret %= MOD; + if (x[n] == '1') { + ret += dos_a_la[2 * (n - 1)]; + ret %= MOD; + } + return ret; +} +void init() { + dos_a_la[0] = 1; + for (int i = 1; i <= (2 * MAXN); i++) { + dos_a_la[i] = dos_a_la[i - 1]; + dos_a_la[i] <<= 1; + dos_a_la[i] %= MOD; + } +} +int main() { + init(); + string x; + cin >> x; + int n = x.size(); + reverse(x.begin(), x.end()); + long long int resp = dos_a_la[n - 1]; + long long int num = 0; + for (int i = 0; i < n; i++) { + if (x[i] == '1') { + num += dos_a_la[i]; + num %= MOD; + } + } + resp *= num; + resp %= MOD; + cout << resp << "\n"; + return 0; +} +int main() { + long long n, k, odd, ans; + cin >> n >> k; + if (n % 2 == 0) { + odd = n / 2; + } else { + odd = (n / 2) + 1; + } + if (k <= odd) { + ans = (k * 2) - 1; + } else { + ans = (k - odd) * 2; + } + cout << "" << ans << endl; +} +int main() { + string st; + int cnt = 0; + cin >> st; + int flag = 0; + int ll = st.length(); + sort(st.begin(), st.end()); + int mx = 0; + for (int i = 0; i <= ll; i++) { + if (st[i] > mx) { + mx = st[i]; + flag = 1; + } else if (st[i] == mx) + flag++; + } + for (int i = 0; i < flag; i++) { cout << char(mx); } + cout << endl; + return 0; +} +bool isPalindrome(string s) { + for (int i = 0; i < s.size() / 2; ++i) { + if (s[i] != s[s.size() - i - 1]) return false; + } + return true; +} +int main() { + string s; + cin >> s; + vector v; + for (int i = 0; i < (1 << 11); ++i) { + string t; + for (int j = 0; j < s.size(); ++j) { + if ((1 << j) & i) { t += s[j]; } + } + if (isPalindrome(t)) { v.push_back(t); } + } + sort(v.begin(), v.end()); + cout << v[v.size() - 1] << endl; + return 0; +} +int main() { + int n, a[101], sum = 0, x = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + sort(a, a + n); + int i; + for (i = n - 1; i >= 0; i--) { + if (sum < x) break; + x += a[i]; + sum -= a[i]; + } + cout << n - i - 1 << endl; +} +int main() { + int n, m; + cin >> n >> m; + if (m < n) n = m; + if (n % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int r = 1; + while (r * 5 < n) { + n -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(n - 1) / r] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1], b[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= n; i++) { + int ans = 0; + while (a[i] > 0 && b[i] > 0) { + int x = max(a[i], b[i]); + int y = min(a[i], b[i]); + int c = x / y; + int d = x % y; + x /= y; + ans += c; + a[i] = d; + b[i] = y; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n >= 0) { + cout << n << endl; + } else { + int a = n / 10; + int b = n / 100 * 10 + n % 10; + cout << max(a, b) << endl; + } + return 0; +} +int main() { + int i, a, b, year = 0; + cin >> a >> b; + for (i = 1;; i++) { + if (a == b) { + cout << year + 1 << endl; + break; + } else if (a > b) { + cout << year << endl; + break; + } else { + a = a * 3; + b = b * 2; + year++; + } + } + return 0; +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + int iskom = n, arr[k]; + for (int i = 0; i < k; i++) { arr[i] = 0; } + for (int i = 0; i < n; i++) { arr[s[i] - 65]++; } + for (int i = 0; i < k; i++) { + if (iskom > arr[i]) iskom = arr[i]; + } + cout << iskom * k << endl; + return 0; +} +const int maxN = 100 * 100 + 100; +long long n, a, b = 1, c; +string s; +int main() { + cin >> s; + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) { + b++; + a++; + } else + a = 0; + if (b % 2 == 0 && (a == 0 || i == s.size() - 1)) c++; + if (a == 0) b = 1; + } + cout << c << endl; + return 0; +} +int main() { + string s, a; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> a; + if (s[0] == a[0] || s[1] == a[1]) return puts("YES"), 0; + } + return puts("NO"), 0; +} +int main() { + int n; + cin >> n; + int p[101]; + for (int i = 0; i < n / 2; i++) cin >> p[i]; + sort(p, p + n / 2); + int a = 0, b = 0; + for (int i = 0; i < n / 2; i++) a += abs(p[i] - 1 - 2 * i); + for (int i = 0; i < n / 2; i++) b += abs(p[i] - 2 * i - 2); + cout << min(a, b) << endl; +} +int main() { + string s; + cin >> s; + int sum = 0, que = 0, ans = 0; + for (int i = 0; i < s.length(); i++) { + sum = 0; + que = 0; + for (int j = i; j < s.length(); j++) { + if (s[j] == '(') + sum++; + else if (s[j] == ')') { + if (sum != 0) { + sum--; + } else if (que != 0) { + sum++; + que--; + } else + break; + } else { + if (sum != 0) { + sum--; + que++; + } else + sum++; + } + if (sum == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +const int N = 110; +string hist[N], input; +vector prefixed; +int n; +bool comp(string s1, string s2) { + return strcmp(s1.c_str(), s2.c_str()) < 0; +} +bool isPref(string s1, string s2) { + if (s1.size() < s2.size()) return false; + for (int i = 0; i < s2.size(); i++) + if (s1[i] != s2[i]) return false; + return true; +} +int main() { + cin >> input >> n; + for (int i = 0; i < n; i++) { + cin >> hist[i]; + if (isPref(hist[i], input)) prefixed.push_back(hist[i]); + } + if (!prefixed.empty()) { + sort(prefixed.begin(), prefixed.end(), comp); + cout << prefixed[0] << endl; + } else + cout << input << endl; +} +int n, ans; +int main() { + cin >> n; + while (n--) { + int a, b; + cin >> a >> b; + ans = 0; + while (a != 0 && b != 0) { + if (a < b) swap(a, b); + ans += a / b; + a %= b; + } + cout << ans; + ; + cout << endl; + ; + } + return 0; +} +int n; +int a[200][200]; +int judge(int i, int j) { + int sum1 = 0, sum2 = 0; + for (int k = 0; k < n; k++) { + sum1 += a[i][k]; + sum2 += a[k][j]; + } + if (sum2 > sum1) + return 1; + else + return 0; +} +int main() { + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (judge(i, j) == 1) { ans++; } + } + } + cout << ans << endl; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + puts("1"); + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0, p, q; + for (int i = 0; i < n; i++) { + cin >> p >> q; + if ((q - p) >= 2) cnt++; + } + cout << cnt << endl; + return 0; +} +long long f(long long x) { + return (x * (x + 1)) / 2; +} +int main() { + long long a; + cin >> a; + for (long long i = 0;; i++) { + if (a >= f(i) && a <= f(i + 1)) { + a = a - f(i); + cout << a << endl; + return 0; + } + } +} +int main() { + int n; + cin >> n; + int mishka = 0; + int chris = 0; + for (int i = 0; i < n; i++) { + int m, c; + cin >> m >> c; + if (m > c) { + mishka++; + } else if (m < c) { + chris++; + } + } + if (mishka > chris) { + cout << "Mishka" << endl; + } else if (mishka < chris) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int res = 0; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + res += abs(x); + } + cout << res << endl; +} +const int maxn = 3e5 + 5; +int main() { + int n, a, b, c; + cin >> n; + cin >> a >> b >> c; + int t = min(a, b); + int m = min(t, c); + if (n == 1) return puts("0"), 0; + if (n == 2) return cout << t << endl, 0; + cout << t + (n - 2) * m << endl; +} +long long int n, x, y, z, p, q, ans, i, a, b, e; +map, long long int> mp; +pair lol; +long long int lca(); +void brainfuck(); +void finder(); +int main() { + cin >> n; + while (n--) { + cin >> z; + if (z == 1) { + cin >> a >> b >> z; + p = a, q = b; + x = lca(); + brainfuck(); + } else { + ans = 0; + cin >> a >> b; + p = a, q = b; + x = lca(); + finder(); + cout << ans << "\n"; + } + } + return 0; +} +long long int lca() { + if (log2(p) < log2(q)) swap(p, q); + long long int log_ = 1; + y = (long long int)log2(p); + x = (long long int)log2(q); + while ((1 << (log_ + 1)) <= y) log_++; + for (i = log_; i >= 0; i--) + if (y - (1 << i) >= x) { + y -= (1 << i); + p >>= (1 << i); + } + if (p == q) return p; + for (i = log_; i >= 0; i--) + if ((p >> (1 << i)) > 1 && (p >> (1 << i)) != (q >> (1 << i))) { + p >>= (1 << i); + q >>= (1 << i); + } + return (p / 2); +} +void brainfuck() { + e = a; + while ((a != x) && (a >>= 1) && (a > 0)) { + lol.first = e; + lol.second = a; + e = a; + if (mp.find(lol) != mp.end()) + mp[lol] += z; + else + mp[lol] = z; + } + e = b; + while ((b != x) && (b >>= 1) && (b > 0)) { + lol.first = e; + lol.second = b; + e = b; + if (mp.find(lol) != mp.end()) + mp[lol] += z; + else + mp[lol] = z; + } +} +void finder() { + e = a; + while ((a != x) && (a >>= 1) && (a > 0)) { + lol.first = e; + lol.second = a; + e = a; + if (mp.find(lol) != mp.end()) ans += mp[lol]; + } + e = b; + while ((b != x) && (b >>= 1) && (b > 0)) { + lol.first = e; + lol.second = b; + e = b; + if (mp.find(lol) != mp.end()) ans += mp[lol]; + } +} +int a[110]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int cnt = 0; + for (int i = 0; i < n; i++) { + if (a[i]) + cnt++; + else if (a[i + 1] && i && a[i - 1]) + cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, blanco, negro; + cin >> n >> blanco >> negro; + int array[n]; + for (int i = int(0); i < int(n); i++) { cin >> array[i]; } + int i = 0, j = n - 1; + bool flag = true; + int cont = 0; + while (i <= j && flag) { + if (array[i] == 2 && array[j] == 2) { + if (i == j) + cont += blanco < negro ? blanco : negro; + else + cont += blanco < negro ? 2 * blanco : 2 * negro; + } else if (array[i] == 2) { + cont += array[j] == 0 ? blanco : negro; + } else if (array[j] == 2) { + cont += array[i] == 0 ? blanco : negro; + } else { + flag = array[i] == array[j] ? true : false; + } + i++; + j--; + } + cout << (flag ? cont : -1) << endl; + return 0; +} +int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, b, n; + cin >> a >> b >> n; + int first = 0; + while (true) { + if (!first) { + int g = gcd(a, n); + if (n == 0 || n < g) { + cout << 1 << endl; + return 0; + } else { + n -= g; + } + } else { + int g = gcd(b, n); + if (n == 0 || n < g) { + cout << 0 << endl; + return 0; + } else { + n -= g; + } + } + first = !first; + } + return 0; +} +int main() { + int n, i, j, k1, k = 0, suma = 0, sumb = 0; + cin >> n; + int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] > k) { k = a[i]; } + suma += a[i]; + } + for (i = 0; i < n; i++) { sumb += k - a[i]; } + for (i = 0;; i++) { + if (sumb <= suma) { + sumb = 0; + k++; + for (j = 0; j < n; j++) { sumb += k - a[j]; } + } else { + break; + } + } + cout << k << endl; +} +int q; +int main() { + cin >> q; + while (q--) { + int n; + cin >> n; + char *s = (char *)malloc(302); + cin >> s; + if (n > 2) { + cout << "YES" << endl; + cout << "2" << endl; + cout << s[0] << " "; + for (int i = 1; i < n; i++) { cout << s[i]; } + cout << endl; + } + if (n == 2) { + if (s[0] < s[1]) { + cout << "YES" << endl; + cout << "2" << endl; + cout << s[0] << " " << s[1] << endl; + } else { + cout << "NO" << endl; + } + } + free(s); + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int ans1 = (k * l) / nl; + int ans2 = c * d; + int ans3 = p / np; + ans2 = min(ans2, ans3); + ans1 = min(ans1, ans2); + cout << ans1 / n << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int Gdrink = (k * l) / nl; + int lime = c * d; + int salt = p / np; + int m = min(Gdrink, min(lime, salt)) / n; + cout << m << endl; + return 0; +} +int main() { + int m, n; + cin >> n >> m; + int right[n + 1], wrong[m + 1]; + for (int i = 0; i < n; i++) cin >> right[i]; + for (int i = 0; i < m; i++) cin >> wrong[i]; + sort(right, right + n); + sort(wrong, wrong + m); + int v = 2 * right[0]; + if (v < right[n - 1]) v = right[n - 1]; + if (v >= wrong[0]) + cout << "-1" << endl; + else + cout << v << endl; +} +int main() { + int n, temp = -1; + cin >> n; + int mat[n + 1][n + 1]; + for (int i = 1; i <= n; i++) { + mat[1][i] = 1; + mat[i][1] = 1; + } + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { + mat[i + 1][j + 1] = mat[i + 1][j] + mat[i][j + 1]; + temp = mat[i + 1][j + 1]; + } + } + cout << mat[n][n] << endl; +} +int main() { + int n, a, b, c, chest, biceps, back, i; + chest = 0; + biceps = 0; + back = 0; + cin >> n; + for (i = 0; i < n / 3; i++) { + cin >> a >> b >> c; + chest = chest + a; + biceps = biceps + b; + back = back + c; + } + if (n % 3 == 1) { + cin >> a; + chest = chest + a; + } else if (n % 3 == 2) { + cin >> a >> b; + chest = chest + a; + biceps = biceps + b; + } + if (chest > biceps && chest > back) + cout << "chest" << endl; + else if (biceps > back && biceps > chest) + cout << "biceps" << endl; + else + cout << "back" << endl; + return 0; +} +const int MOD = 100; +int main() { + long long n; + cin >> n; + int v = 5; + int ans = 1; + for (int i = 0; i <= 62; i++, v = (v * v) % MOD) { + if (n & (1 << i)) { ans = (ans * v) % MOD; } + } + cout << ans << endl; + return 0; +} +int a[100009]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int flag = 0; + for (int i = 1; i <= n; i++) { + int x, y; + x = a[i]; + y = a[x]; + if (a[y] == i && x != i && x != y && i != y) { flag = 1; } + if (flag == 1) { break; } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, i = 0, sum = 0; + string ori, ope; + cin >> n; + cin >> ori; + cin >> ope; + while (ori[i] != '\0' && ope[i] != '\0') { + if (ope[i] - ori[i] >= 5) { + sum += ori[i] + 10 - ope[i]; + } else if (ope[i] - ori[i] < 5 && ope[i] >= ori[i]) { + sum += ope[i] - ori[i]; + } else if (ope[i] < ori[i] && ori[i] - ope[i] < 5) { + sum += ori[i] - ope[i]; + } else { + sum += ope[i] + 10 - ori[i]; + } + i++; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s, t; + cin >> s; + cin >> t; + int sum = 0; + for (int i = 0; i < n; i++) { sum += min(abs(s[i] - t[i]), abs(min(s[i], t[i]) + 10 - max(s[i], t[i]))); } + cout << sum << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int stars = n / 2; + int ds = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < stars; j++) cout << '*'; + for (int j = 0; j <= ds; j++) cout << 'D'; + for (int j = 0; j < stars; j++) cout << '*'; + if (i < n / 2) { + stars--; + ds += 2; + } else { + stars++; + ds -= 2; + } + cout << endl; + } + return 0; +} +int main() { + int n, j = 0; + cin >> n; + while (n--) { + int x, f = 0; + string a; + cin >> x >> a; + x--; + for (int i = 0; i <= x; i++) { + if (a[i] == a[x - i]) { + j += 2; + f++; + } else if (a[i] - 1 == a[x - i] - 1) { + j += 2; + f++; + cout << "- -" << endl; + } else if (a[i] + 1 == a[x - i] - 1) { + j += 2; + f++; + } else if (a[i] - 1 == a[x - i] + 1) { + j += 2; + f++; + } else if (a[i] + 1 == a[x - i] + 1) { + j += 2; + f++; + } else { + f = 0; + break; + } + if (j == x + 1) break; + } + x++; + if (x / 2 == f) + cout << "YES" << endl; + else + cout << "NO" << endl; + f = 0; + j = 0; + } + return 0; +} +int main() { + char input[101]; + int len, i, temp, res = 1; + cin >> input; + len = strlen(input); + sort(input, input + len); + temp = input[0]; + for (i = 1; i < len; i++) { + if (input[i] == temp) { + continue; + } else { + temp = input[i]; + res++; + } + } + cout << (res % 2 == 1 ? "IGNORE HIM!" : "CHAT WITH HER!") << endl; + return 0; +} +const int maxn = 1e5 + 5; +const long long inf = 0x3f3f3f3f; +vector G[maxn]; +long long sum[maxn], a[maxn]; +int minson[maxn]; +int n; +int getson(int v) { + int minkey = inf; + for (int i = 0; i < G[v].size(); ++i) { + int to = G[v][i]; + if (minkey > getson(to)) { + minkey = sum[to]; + minson[v] = to; + } + } + return sum[v]; +} +void dfs(int v, long long fasum, int deep) { + if (deep & 1) + a[v] = sum[v] - fasum; + else if (!G[v].size()) { + a[v] = 0; + return; + } else + a[v] = sum[minson[v]] - fasum; + for (int i = 0; i < G[v].size(); ++i) dfs(G[v][i], fasum + a[v], deep + 1); +} +int main() { + while (cin >> n) { + int pa; + for (int i = 2; i <= n; ++i) { + cin >> pa; + G[pa].push_back(i); + } + for (int i = 1; i <= n; ++i) cin >> sum[i]; + getson(1); + dfs(1, 0, 1); + long long maxsum = 0; + int flag = 0; + for (int i = 1; i <= n; ++i) { + if (a[i] >= 0) + maxsum += a[i]; + else + flag = 1; + } + if (!flag) + cout << maxsum << endl; + else + cout << -1 << endl; + for (int i = 0; i <= n; ++i) G[i].clear(); + } + return 0; +} +int n; +int x[205], y[205]; +int main() { + cin >> n; + int z = 0; + for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; + for (int i = 0; i < n; i++) { + int m = 0; + for (int j = 0; j < n; j++) { + if (x[j] > x[i] && y[j] == y[i]) m |= 1; + if (x[j] < x[i] && y[j] == y[i]) m |= 2; + if (y[j] > y[i] && x[j] == x[i]) m |= 4; + if (y[j] < y[i] && x[j] == x[i]) m |= 8; + } + if (m == 15) z++; + } + cout << z << '\n'; +} +char a[500]; +int main() { + int q, n; + cin >> q; + while (q--) { + cin >> n; + cin >> a; + if (n > 2) { + cout << "YES" << endl; + cout << "2" << endl; + cout << a[0] << " " << a + 1 << endl; + } else { + if (a[0] >= a[1]) + cout << "NO" << endl; + else { + cout << "YES" << endl; + cout << "2" << endl; + cout << a[0] << " " << a[1] << endl; + } + } + } + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long ans = (c + a - 1) * (b + a - 1) - a * (a - 1); + cout << ans << endl; + return 0; +} +int main() { + int n, a[1110]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + cout << a[(n - 1) / 2] << endl; + return 0; +} +int main() { + int n, k, x, ans = 0; + cin >> n >> k; + while (n--) { + cin >> x; + int arr[10] = {}, c = 0; + while (x > 0) { + if (!arr[x % 10] && x % 10 <= k) { + c++; + arr[x % 10] = 1; + } + x /= 10; + } + if (c == k + 1) ans++; + } + cout << ans << "\n"; + return 0; +} +int dp[105][3]; +int main() { + ifstream myFile("task.in"); + if (!myFile.fail()) { assert(freopen("task.in", "r", stdin)); } + int n; + cin >> n; + int arr[n + 1]; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) { + dp[i][0] = max(max(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]); + if (arr[i] == 1 || arr[i] == 3) { dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][2] + 1); } + if (arr[i] == 2 || arr[i] == 3) { dp[i][2] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1); } + } + cout << n - max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl; + return 0; +} +int main() { + int n, g, x; + cin >> n; + cin >> g; + for (int i = 1; i < n; i++) { + cin >> x; + g = __gcd(g, x); + } + cout << g * n << endl; + return 0; +} +long long ans = 0, i = 0, j = 0, cnt = 0; +long long arr[101]; +long long brr[101]; +int main() { + int t = 1; + while (t--) { + int n; + cin >> n; + for (i = 1; i <= n; i++) cin >> arr[i]; + sort(arr + 1, arr + 1 + n); + for (i = 1; i <= n; i++) { + if (arr[i] != 0) break; + } + int cnt = i; + set s(arr + i, arr + n + 1); + cout << s.size() << "\n"; + } +} +int main() { + int a, b, c, d; + cin >> a >> b >> c; + d = ((((a * c) + b) - 1) / b) - c; + cout << d << endl; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; +} +int main() { + int flag; + int l, r, u, d; + char arr[50][50]; + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> arr[i][j]; } + } + flag = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '*') { + u = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (arr[j][i] == '*') { + l = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = n - 1; i >= 0; i--) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '*') { + d = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + flag = 0; + for (int i = m - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (arr[j][i] == '*') { + r = i; + flag = 1; + break; + } + } + if (flag == 1) { break; } + } + for (int i = u; i <= d; i++) { + for (int j = l; j <= r; j++) { cout << arr[i][j]; } + cout << endl; + } +} +int main() { + int n, k, r; + cin >> n >> k; + r = (int)((2 * n) / k) + (int)((5 * n) / k) + (int)((8 * n) / k); + if ((2 * n) % k != 0) r++; + if ((5 * n) % k != 0) r++; + if ((8 * n) % k != 0) r++; + cout << r << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int c = 0; + for (int i = 0; i <= 1000; i++) { + for (int j = 0; j <= 1000; j++) { + int p = i * i + j; + int q = i + j * j; + if (p == n && q == m) { c++; } + } + } + cout << c << endl; +} +int main() { + string s[11]; + for (int i = 0; i < 11; i++) cin >> s[i]; + for (int i = 0; i < 80; i += 10) { + string t = ""; + t = s[0].substr(i, 10); + for (int j = 1; j < 11; j++) { + if (t == s[j]) { cout << j - 1; } + } + } + cout << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + bool flag = false; + for (int i = 0; i < n / 2; i++) { + if (abs(s[i] - s[n - i - 1]) != 2 && abs(s[i] - s[n - i - 1]) != 0) { + cout << "NO\n"; + flag = true; + break; + } + } + if (!flag) cout << "YES\n"; + } + return 0; +} +char cmd[200000 + 10]; +long long pos[200000 + 10]; +long long dist[200000 + 10]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> cmd[i]; + for (int i = 0; i < n; i++) cin >> pos[i]; + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + if (cmd[i] == 'R' && cmd[i + 1] == 'L') dist[cnt++] = pos[i + 1] - pos[i]; + } + if (!cnt) + cout << -1 << endl; + else { + long long min = 0x3f3f3f3f; + for (int i = 0; i < cnt; i++) min = min < dist[i] ? min : dist[i]; + cout << min / 2 << endl; + } + return 0; +} +int somebodytrue(int x) { + int q, w, e, r; + if (x <= 1022) return 1023; + for (int i = x + 1; i <= 9876; i++) { + q = i % 10; + w = i / 10 % 10; + e = i / 100 % 10; + r = i / 1000; + if (q != w && e != r && w != r && q != e && w != e && q != r) return i; + } +} +int main() { + int n; + cin >> n; + cout << somebodytrue(n) << endl; +} +int main() { + long long n, c = 0; + cin >> n; + while (n != 0) { + if (n % 2) c++; + n /= 2; + } + cout << c << endl; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long res = min((m - (n % m)) * a, (n % m) * b); + cout << res << endl; + return 0; +} +int main() { + double l, p, q; + cin >> l >> p >> q; + cout << (l * p) / (p + q) << endl; + return 0; +} +int a[10000]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] % 2 == 0) a[i] -= 1; + if (i == n) + cout << a[i] << endl; + else + cout << a[i] << " "; + } + return 0; +} +int main() { + int pos = 0; + string s, t; + cin >> s >> t; + for (int i = 0; i < t.size(); i++) + if (t[i] == s[pos]) pos++; + cout << ++pos << endl; +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +const int MAX = 100; +int main() { + int n, start; + char slg[MAX + 10]; + cin >> n >> start; + for (int i = 1; i <= n; i++) cin >> slg[i]; + int cnt = 0, temp = n; + if (start <= n / 2) { + if (start > 1) { + while (cnt < start - 1) { + cout << "LEFT" << endl; + cnt++; + } + start = 1; + } + while (temp > 0) { + cout << "PRINT " << slg[start] << endl; + if (temp > 1) cout << "RIGHT" << endl; + temp--; + start++; + } + } else { + if (start < n) { + while (cnt < n - start) { + cout << "RIGHT" << endl; + cnt++; + } + start = n; + } + while (temp > 0) { + cout << "PRINT " << slg[start] << endl; + if (temp > 1) cout << "LEFT" << endl; + temp--; + start--; + } + } +} +int main() { + int n, m; + cin >> n >> m; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int b[m]; + for (int i = 0; i < m; i++) cin >> b[i]; + int l = *min_element(a, a + n); + int q = *max_element(a, a + n); + int p = *min_element(b, b + m); + bool ok = 0; + int res; + for (res = 1; res <= 110; res++) { + if (res >= 2 * l && res >= q && res < p) { + ok = 1; + break; + } + } + if (ok) + cout << res << endl; + else + cout << -1 << endl; +} +int main() { + string s; + getline(cin, s); + int a; + a = s.length(); + int i, c1 = 0, c2 = 0; + for (i = 0; i != a; i++) { + if (s.at(i) >= 97) { + c2++; + } else { + c1++; + } + } + for (i = 0; i != a; i++) { + if (c1 > c2) { + if (s.at(i) >= 97) { s.at(i) = s.at(i) - 32; } + } else { + if (s.at(i) < 97) { s.at(i) = s.at(i) + 32; } + } + } + cout << s << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else { + if (i % 4 != 0) { + if (j == m) { + cout << "#"; + } else { + cout << "."; + } + } else { + if (j == 1) { + cout << "#"; + } else { + cout << "."; + } + } + } + if (j == m) { cout << endl; } + } + } +} +int main() { + int n; + char str[9]; + cin >> n; + cin >> str; + for (int i = 0; i < n; i++) cin >> str; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +map a; +long long int getsolved(long long int x) { + string s = ""; + while (x > 0) { + s += x % 2; + x = x / 10; + } + reverse(s.begin(), s.end()); + long long int alpha = 0; + for (int i = 0; i < s.size(); i++) alpha = (long long int)s[i] + 10 * alpha; + return alpha; +} +int main() { + long long int t; + cin >> t; + char c; + long long int num; + while (t--) { + cin >> c >> num; + long long int y = getsolved(num); + if (c == '+') + a[y]++; + else if (c == '-') + a[y]--; + else + cout << a[y] << "\n"; + } +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +int main() { + desperate_optimization(10); + string s; + cin >> s; + int ada = 0; + int num = 0; + int dotted = 0; + if (s[0] == '-') assert(0); + for (int i = 0; i < s.size(); i++) { + if (s[i] == '.') { + dotted = 1; + continue; + } + if (dotted == 1) { + if (num == 9) { + cout << "GOTO Vasilisa." << '\n'; + return 0; + } + if (s[i] >= '5') ada = 1; + num += ada; + for (int j = 0; j < i - 2; j++) cout << s[j]; + cout << num << '\n'; + return 0; + } else { + num = s[i] - '0'; + } + } + cout << s << '\n'; + return 0; +} +int main() { + int n, i, flag = 0; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { flag = 1; } + } + if (flag) { + cout << -1 << endl; + } else + cout << 1 << endl; + return 0; +} +int main() { + int n, t; + cin >> t; + n = t; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (abs(i - (n + 1) / 2 + 1) + abs(j - (n + 1) / 2 + 1) <= (n + 1) / 2 - 1) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[1005]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int num = 0; + for (int i = 1; i < n - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) num++; + if (a[i] < a[i - 1] && a[i] < a[i + 1]) num++; + } + cout << num << endl; + } +} +const int sz = 1e5 + 10; +const int mod = 10007; +int t, cs; +int main() { + int a, b, c, d; + while (cin >> a >> b >> c >> d) { + int ans = 0; + while (b > 0) { + ans++; + int se = min(a, c + 1); + c -= se - 1; + b -= se * d; + } + cout << ans << "\n"; + cerr << "----\n"; + } + return 0; +} +int main() { + int l, x; + cin >> l; + int maxWord = 0, maxVolume = 0; + string line; + cin.ignore(); + getline(cin, line); + for (int i = 0; i < line.size(); i++) { + x = (int)line[i]; + if (x == 32) { + maxVolume = max(maxVolume, maxWord); + maxWord = 0; + } else if (x >= 65 && x <= 90) + maxWord++; + } + cout << max(maxVolume, maxWord) << "\n"; + return 0; +} +long long a[200001], b[200001]; +int main() { + long long num = 0; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + int N; + cin >> N; + long long m = 0; + for (int i = 0; i < N; i++) cin >> a[i]; + sort(a, a + N); + for (int i = 1; i < N; i++) { + b[m] = abs(a[i] - a[i - 1]); + m++; + } + sort(b, b + m); + for (long long i = 0; i < m; i++) + if (b[i] == b[0]) + num++; + else + break; + cout << b[0] << " " << num << endl; + return 0; +} +const int maxn = 1e5 + 5; +int main() { + int n, maxlen[maxn]; + long long a[maxn]; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + maxlen[i] = 1; + } + for (int i = 1; i <= n; i++) { + if (a[i] > a[i - 1]) maxlen[i] = maxlen[i - 1] + 1; + } + int k = 0; + for (int i = 1; i <= n; i++) + if (maxlen[i] > k) k = maxlen[i]; + cout << k << endl; + return 0; +} +int main() { + string s; + cin >> s; + int l = 0, u = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') + l++; + else + u++; + } + if (l < u) { + for (int i = 0; i < s.size(); i++) cout << char(toupper(s[i])); + cout << endl; + } else { + for (int i = 0; i < s.size(); i++) cout << char(tolower(s[i])); + cout << endl; + } +} +int main() { + long long x; + cin >> x; + long long mayor = (long long)((sqrt(8.000 * x - 7.000) + 1.000) / 2.000); + long long ans = x + 1 - (mayor * mayor - mayor + 2) / 2; + cout << ans << "\n"; +} +int main() { + int n; + cin >> n; + string vet[n]; + for (int i = 0; i < n; i++) { cin >> vet[i]; } + bool purple = false; + bool green = false; + bool blue = false; + bool orange = false; + bool red = false; + bool yellow = false; + for (int j = 0; j < n; j++) { + if (vet[j] == "purple") purple = true; + if (vet[j] == "green") green = true; + if (vet[j] == "blue") blue = true; + if (vet[j] == "orange") orange = true; + if (vet[j] == "red") red = true; + if (vet[j] == "yellow") yellow = true; + } + int tot = 0; + if (!purple) tot++; + if (!green) tot++; + if (!blue) tot++; + if (!orange) tot++; + if (!red) tot++; + if (!yellow) tot++; + cout << tot << "\n"; + if (!purple) cout << "Power\n"; + if (!green) cout << "Time\n"; + if (!blue) cout << "Space\n"; + if (!orange) cout << "Soul\n"; + if (!red) cout << "Reality\n"; + if (!yellow) cout << "Mind\n"; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int i = 1; + while (i <= (int)s.size() && s[i - 1] == '1') { ++i; } + if (i > (int)s.size()) --i; + cout << i << "\n"; + return 0; +} +long long n, k, a[105], c = 1000000007; +void solve() { + cin >> n >> k; + for (__typeof((n + 1)) i = (1); i < (n + 1); i++) cin >> a[i]; + for (__typeof((n + 1)) i = (1); i < (n + 1); i++) { + if (k % a[i] == 0) c = min(c, k / a[i]); + } + cout << c << '\n'; +} +void prep() {} +int main() { + int t = 1; + prep(); + cout << fixed << setprecision(12); + while (t--) solve(); + return 0; +} +int a; +string l[105]; +int main() { + cin >> a; + for (int i = 0; i < a; i++) { cin >> l[i]; } + long long ans = 0; + for (char i = 'a'; i <= 'z'; i++) { + for (char j = 'a'; j <= 'z'; j++) { + long long temp = 0; + for (int k = 0; k < a; k++) { + bool cek = 1; + for (int m = 0; m < l[k].length(); m++) { + if (l[k][m] != i && l[k][m] != j) cek = 0; + } + if (cek) temp += l[k].length(); + } + ans = max(ans, temp); + } + } + cout << ans << '\n'; +} +int main() { + int n, z, i, j, k; + string s; + cin >> n >> z >> s; + for (i = 0; s[i] != 'G'; i++) + ; + for (j = 0; s[j] != 'T'; j++) + ; + for (k = min(i, j); k < max(i, j); k += z) + if (s[k] == '#') break; + if (k == max(i, j)) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a, x, y, z, w, b; + cin >> a; + a = a + 1; + b = a; + while (1) { + a = b; + ; + x = a % 10; + a = a / 10; + y = a % 10; + a = a / 10; + z = a % 10; + a = a / 10; + w = a % 10; + if (x == y || x == z || x == w || y == z || y == w || z == w) + b++; + else { + cout << b << endl; + ; + break; + } + } + return 0; +} +int main() { + string s; + cin >> s; + long long first_one = -1; + for (long long i = 0; i < s.length(); ++i) { + if (s[i] == '1') { + first_one = i; + break; + } + } + if (first_one == -1) { + cout << "no\n"; + return 0; + } + long long total = 0; + for (long long i = first_one + 1; i < s.length(); ++i) { + if (s[i] == '0') { total++; } + } + if (total >= 6) { + cout << "yes\n"; + } else { + cout << "no\n"; + } + return 0; +} +long long int n, m, i, j, a[100005], ans, c; +int main() { + cin >> n; + ans = n; + a[n] = 1000000005; + for (i = 0; i < n; i++) cin >> a[i]; + c = 1; + for (i = 0; i < n; i++) { + if (a[i] == a[i + 1]) { + c++; + } else { + ans = ans + (c * (c - 1)) / 2; + c = 1; + } + } + cout << ans << endl; +} +long long gcd1(long long a, long long b) { + if (a == 0) return b; + return gcd1(b % a, a); +} +long long modx(long long base, long long ex) { + long long ans = 1LL, val = base; + while (ex > 0LL) { + if (ex & 1LL) ans = (ans * val) % 998244353LL; + val = (val * val) % 998244353LL; + ex = ex >> 1LL; + } + return ans; +} +const int maxn = 1e6 + 5; +long long dp[maxn][2], n; +int main() { + cin >> n; + dp[1][0] = 1; + for (int i = 2; i <= n; i++) { + if (i % 2 == 0) { + dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] + 1LL) % 1000000007LL; + dp[i][0] = dp[i - 1][0]; + } else { + dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + 1) % 1000000007LL; + dp[i][1] = dp[i - 1][1]; + } + } + cout << (dp[n][0] + dp[n][1]) % 1000000007LL << endl; + return 0; +} +const int maxn = 1e5 + 10; +int sumw[maxn]; +int main() { + int n, l, r, Ql, Qr; + cin >> n >> l >> r >> Ql >> Qr; + int w; + for (int i = 1; i <= n; i++) { + cin >> w; + sumw[i] = sumw[i - 1] + w; + } + long long mine = sumw[n] * r + (n - 1) * Qr; + for (int i = 1; i <= n; i++) { + long long wheniEndFromLeft = (sumw[i] - sumw[0]) * l + (sumw[n] - sumw[i]) * r; + if (n & 1) { + if (n > 2 * i) { + wheniEndFromLeft += (n - 2 * i - 1) * Qr; + } else { + wheniEndFromLeft += (2 * i - n - 1) * Ql; + } + } else { + if (n > 2 * i) { + wheniEndFromLeft += (n - 2 * i - 1) * Qr; + } else if (n == 2 * i) { + wheniEndFromLeft += (n - 2 * i) * Qr; + } else { + wheniEndFromLeft += (2 * i - n - 1) * Ql; + } + } + mine = min(mine, wheniEndFromLeft); + } + cout << mine << endl; + return 0; +} +int main() { + int n, k, a = 0, b = 0; + string s, s2 = "0123456789"; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < s.length(); j++) { + for (int x = 0; x <= k; x++) { + if (s[j] == s2[x]) { + a++; + s2[x] = 'c'; + break; + } + } + } + if (a == (k + 1)) b++; + a = 0; + s2 = "0123456789"; + } + cout << b << "\n"; + return 0; +} +int main() { + int x[3][3] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, y; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> y; + if (y % 2 != 0) { + if (j == 1) { + x[i][0] = (x[i][0] + 1) % 2; + x[i][2] = (x[i][2] + 1) % 2; + } else + x[i][1] = (x[i][1] + 1) % 2; + if (i == 1) { + x[0][j] = (x[0][j] + 1) % 2; + x[2][j] = (x[2][j] + 1) % 2; + } else + x[1][j] = (x[1][j] + 1) % 2; + x[i][j] = (x[i][j] + 1) % 2; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << x[i][j]; } + cout << endl; + } +} +int main() { + int N, MAX; + cin >> N >> MAX; + int A[N]; + for (int i = 0; i < N; i++) { + char t; + cin >> t; + A[i] = t - 'a'; + } + if (N == 1) { + if (A[0] < MAX - 1) { + cout << (char)(A[0] + 'a' + 1) << endl; + } else { + cout << "NO" << endl; + } + return 0; + } + int beginat = N - 1; + while (true) { + int mark = true; + int t = 1; + int i; + for (i = beginat; i >= 0; i--) { + if (!t) break; + int old_t = t; + t = (A[i] + old_t) / MAX; + int oldai = A[i]; + A[i] = (A[i] + old_t) % MAX; + if (i == 0 && oldai >= A[i]) { + cout << "NO" << endl; + return 0; + } + } + if (beginat != N - 1) beginat = N - 1; + bool im = true; + for (int i = 0; i < N; i++) { + if (A[i] != MAX - 1) { + im = false; + break; + } + } + if (im) { + cout << "NO" << endl; + return 0; + } + int max_idx = i; + for (int i = N - 1; i >= 1; i--) { + if ((i - 1 >= 0 && A[i] == A[i - 1]) || (i - 2 >= 0 && A[i] == A[i - 2])) { + mark = false; + beginat = i; + } + } + if (mark) { + for (int i = 0; i < N; i++) { cout << (char)(A[i] + 'a'); } + cout << endl; + return 0; + } + } + return 0; +} +int main() { + int n, i, j, c, ck_0, d, a[101], ans = 0; + string s; + cin >> n >> d; + c = 0; + for (i = 0; i < d; i++) { + cin >> s; + ck_0 = 0; + for (j = 0; j < n; j++) { + if (s[j] == '0') ck_0++; + } + if (ck_0 == 0) + c = 0; + else + c++; + ans = max(ans, c); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n < 4) { + cout << 1 << endl; + return 0; + } + int cnt = 0, m = 1, i = 1, sum = 0; + while (sum + i <= n) { + sum = sum + i; + cnt++; + m++; + i += m; + } + cout << cnt << endl; +} +int main() { + long long int i, j, l, m, n, k = 0, arr[100000], test, ans = 0; + cin >> n >> j; + for (i = 0; i < n; i++) { + cin >> l >> m; + if (l > m) { + k = k + (l - m) + 1; + } else { + k = k + (m - l) + 1; + } + } + while (k % j != 0) { + k = k + 1; + ans = ans + 1; + } + cout << ans << endl; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int mxm = max(3 * a / 10, a - (a / 250) * c); + int mxv = max(3 * b / 10, b - (b / 250) * d); + if (mxm < mxv) + cout << "Vasya" << endl; + else if (mxm > mxv) + cout << "Misha" << endl; + else + cout << "Tie" << endl; +} +int main() { + int n; + cin >> n; + int number(0); + vector h(n), a(n); + for (int i = 0; i < n; ++i) { + cin >> h[i] >> a[i]; + for (int j = 0; j < i; ++j) { + if (h[i] == a[j]) { number += 1; } + if (a[i] == h[j]) { number += 1; } + } + } + cout << number << endl; + return 0; +} +int main() { + int a; + cin >> a; + cout << a % 2 << "\n"; +} +int main() { + int M, N, d; + cin >> M >> N; + d = M * N / 2; + cout << d << endl; +} +bool makeChanges(char *s, int whichPosn, int size, int p, char adj, char nadj) { + if (whichPosn == -1) { return false; } + char thisChar = s[whichPosn]; + for (char x = thisChar + 1; x < 'a' + p; x++) { + if (x == adj || x == nadj) { continue; } + s[whichPosn] = x; + if (whichPosn == size - 1) { return true; } + char xx = s[whichPosn + 1]; + s[whichPosn + 1] = 'a' - 1; + if (makeChanges(s, whichPosn + 1, size, p, x, adj)) { + return true; + } else { + s[whichPosn + 1] = xx; + continue; + } + } + s[whichPosn] = thisChar; + nadj = whichPosn >= 3 ? s[whichPosn - 3] : 0; + adj = whichPosn >= 2 ? s[whichPosn - 2] : 0; + return (makeChanges(s, whichPosn - 1, size, p, adj, nadj)); +} +int main() { + int n, p; + cin >> n >> p; + char s[1005]; + cin >> s; + int whichPosn = n - 1; + char nadj = whichPosn >= 2 ? s[whichPosn - 2] : 0; + char adj = whichPosn >= 1 ? s[whichPosn - 1] : 0; + if (makeChanges(s, whichPosn, n, p, adj, nadj)) { + cout << s << '\n'; + } else { + cout << "NO\n"; + } + return 0; +} +const int N = 1e6 + 6; +long long x, y, m, res[N]; +int main() { + cin >> x >> y >> m; + if (x > y) swap(x, y); + if (y >= m) return cout << 0 << endl, 0; + if (!x && !y) { + if (m <= 0) + cout << 0 << endl; + else + cout << -1 << endl; + return 0; + } + if ((y < 0 && (m >= 0 || m > y)) || y == 0) return cout << "-1" << endl, 0; + int j = 0; + long long ans = 0; + if (x < 0 && y > 0 && abs(x) > y) { + long long q = abs(x) / y; + x += q * y; + ans += q; + } + for (int i = 0; max(x, y) <= 4e18; ++i) { + if (x < y) { + x += y; + } else + y += x; + res[j++] = max(x, y); + } + int idx = lower_bound(res, res + j, m) - res; + ans += (idx + 1); + cout << ans << endl; + return 0; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +string second, t; +int main() { + cin >> second >> t; + int i = 0; + for (int j = 0; j < t.size(); j++) + if (second[i] == t[j]) i++; + cout << i + 1 << '\n'; + return 0; +} +long long fun(long long l, long long r, long long count) { + if (l == r) return l; + count = 1; + while (count <= r) { count *= 2; } + if (r == count - 1) return r; + count /= 2; + if (count > l) return count - 1; + return fun(l - count, r - count, 1) + count; +} +int main() { + long long n, l, r; + cin >> n; + while (n--) { + cin >> l >> r; + cout << fun(l, r, 1) << "\n"; + } +} +int main() { + int n, k, l, c, d, p, nl, np, ans; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(min(k * l / nl, c * d), p / np) / n << endl; + return 0; +} +int n, a[100005], mx, cnt; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 1; i++) { + if (a[i] < a[i + 1]) + cnt++; + else { + mx = max(cnt, mx); + cnt = 0; + } + } + mx = max(cnt, mx); + cout << mx + 1 << endl; + return 0; +} +int main() { + int n, sum; + cin >> n; + sum = 0; + for (int x, i = 1; i <= n; i++) { + cin >> x; + sum += x; + } + int m; + cin >> m; + for (int i = 1; i <= m; i++) { + int l, r; + cin >> l >> r; + if (l <= sum && sum <= r) { + cout << sum << '\n'; + exit(0); + } + if (sum <= l) { + cout << l << '\n'; + exit(0); + } + } + cout << -1 << '\n'; + return 0; +} +int main() { + string x; + cin >> x; + if (x[0] != '-') { + cout << x << endl; + return 0; + } + int l = x.size(); + if (l == 3 && x[l - 1] == '0') { + cout << '0' << endl; + return 0; + } + if (x[l - 1] > x[l - 2]) { + cout << x.substr(0, l - 1) << endl; + return 0; + } + cout << x.substr(0, l - 2) + x[l - 1] << endl; +} +int main() { + int m; + int a[105]; + while (cin >> m) { + for (int i = 0; i < m; i++) { cin >> a[i]; } + int x, y; + cin >> x >> y; + int sum = 0, pl = -1; + for (int i = 0; i < m; i++) { + sum += a[i]; + if (sum >= x && sum <= y) { + int sum2 = 0; + for (int j = i + 1; j < m; j++) { sum2 += a[j]; } + if (sum2 >= x && sum2 <= y) { + pl = i + 2; + break; + } + } + } + if (pl != -1) { + cout << pl << endl; + } else { + cout << 0 << endl; + } + } + return 0; +} +int main() { + long long n; + while (cin >> n) { cout << 25 << endl; } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if ((a == b || abs(a - b) == 1) && (a != 0 || b != 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + m = (n * 3) / 2; + cout << m << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = sqrt(n); i >= 1; --i) { + if (!(n % i)) { + cout << i << ' ' << n / i << endl; + break; + } + } + return 0; +} +long long int n, sum; +int main() { + cin >> n >> sum; + long long int ans = (sum % n) ? sum / n + 1 : sum / n; + cout << ans << '\n'; +} +int main() { + int test; + cin >> test; + for (int a = 0; a < test; a++) { + int num; + cin >> num; + string s; + cin >> s; + int flag = 0; + for (int i = 0, j = num - 1; i < num / 2; i++, j--) { + if (s[i] == s[j]) + continue; + else if (s[i] - 1 == s[j] - 1) + continue; + else if (s[i] - 1 == s[j] + 1) + continue; + else if (s[i] + 1 == s[j] - 1) + continue; + else if (s[i] + 1 == s[j] + 1) + continue; + flag = 1; + break; + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + return 0; +} +const int INF = 0x7FFFFFFF; +const int MOD = 1e9 + 7; +const double EPS = 1e-10; +const double PI = 2 * acos(0.0); +const int maxn = 1e5 + 1666; +int main() { + int a, b; + cin >> a >> b; + int c = min(a, b); + cout << c << " "; + a -= c, b -= c; + if (a == 0) + cout << b / 2 << endl; + else + cout << a / 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << n << endl; + else + cout << "1\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int cnt = 0; + for (int i = 1; i <= n; i++) { + if (k % i == 0 && i * 1LL * n >= k) { cnt++; } + } + cout << cnt << endl; +} +int n; +int main() { + cin >> n; + while (n) { + if (n % 10 == 1) + n /= 10; + else if (n % 100 == 14) + n /= 100; + else if (n % 1000 == 144) + n /= 1000; + else { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n > 21) { + cout << 0 << endl; + } else if (n == 20) { + cout << 15 << endl; + } else { + cout << 4 << endl; + } + return 0; +} +int main() { + double t, s, q, c = 0, ans = 0; + cin >> t >> s >> q; + while (s < t) { + s = s * q; + ans++; + } + cout << ans << endl; + return 0; +} +long long a[200020]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; + sort(a + 1, a + 2 * n + 1); + long long min1 = (a[n] - a[1]) * (a[2 * n] - a[n + 1]); + for (int i = 2; i <= n + 1; i++) { min1 = min(min1, (a[2 * n] - a[1]) * (a[i + n - 1] - a[i])); } + cout << min1 << endl; + return 0; +} +int main() { + int n, i, min[5], max[5], a = 0, b, c; + cin >> n; + for (i = 0; i < 3; i++) { cin >> min[i] >> max[i]; } + n = n - min[1] - min[2]; + b = min[1]; + c = min[2]; + if (n <= max[0]) { + a += n; + } else { + a += max[0]; + n = n - max[0]; + if (n <= (max[1] - min[1])) { + b += n; + } else { + b = max[1]; + c += n - max[1] + min[1]; + } + } + cout << a << " " << b << " " << c << endl; + return 0; +} +int main() { + long int n, ans = 0; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + for (int i = 0; i < n - 1; i++) { ans += v[n - 1] - v[i]; } + cout << ans << endl; +} +int main() { + int n, m, x, y; + vector v; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> x; + for (int j = 1; j <= x; j++) { + cin >> y; + v.push_back(y); + } + } + if (v.size() < m) { + cout << "NO\n"; + return 0; + } + for (int i = 1; i <= m; i++) { + for (int j = 0; j < v.size(); j++) { + if (i == v[j]) break; + if (i != v[j] && j == v.size() - 1) { + cout << "NO\n"; + return 0; + } + } + } + cout << "YES\n"; +} +int main() { + int n, k; + cin >> n >> k; + string num[100]; + for (int i = 0; i < n; i++) cin >> num[i]; + int gc = 0; + for (int i = 0; i < n; i++) { + int count = 0; + for (int j = 0; j <= k; j++) { + string num2 = num[i]; + for (int l = 0; l < num2.size(); l++) { + if (j == ((int)num2.at(l)) - 48) { + count++; + break; + } + } + } + if (count >= k + 1) gc++; + } + cout << gc << endl; + return 0; +} +int main() { + int n; + cin >> n; + int k; + cin >> k; + vector vec; + for (int x = 2; x * x <= n; x++) { + while (n % x == 0) { + vec.push_back(x); + n /= x; + } + } + if (n > 1) vec.push_back(n); + int sz = vec.size(); + if (sz < k) + cout << -1 << endl; + else { + for (int i = 0; i <= k - 2; i++) { cout << vec[i] << " "; } + int f = 1; + for (int i = k - 1; i < sz; i++) { f *= vec[i]; } + cout << f << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long a[n + 1], b[n + 1]; + for (long long i = 1; i <= n; i++) cin >> a[i]; + for (long long i = 1; i <= n; i++) cin >> b[i]; + long long maks = 0; + for (long long i = 1; i <= n; i++) { + for (long long j = i; j <= n; j++) { + long long suma = 0, sumb = 0; + for (long long l = i; l <= j; l++) { + suma = suma | a[l]; + sumb = sumb | b[l]; + } + maks = max(maks, suma + sumb); + } + } + cout << maks << endl; +} +int main() { + char str[101]; + vector out; + cin >> str; + for (int i = 0; str[i] != '\0'; i++) { + if (str[i] == '1') { + out.push_back(1); + } else if (str[i] == '2') { + out.push_back(2); + } else if (str[i] == '3') { + out.push_back(3); + } + } + sort(out.begin(), out.end()); + for (int i = 0; i < out.size(); i++) { + if (i != out.size() - 1) { + cout << out[i] << "+"; + } else { + cout << out[i] << "\n"; + } + } +} +const long long int INF = 2000000000000000000LL; +const int MOD = 10000007; +int a[1000006]; +string r; +bool ispal(string s) { + r = s; + reverse(r.begin(), r.end()); + if (s == r) { + return true; + } else { + return false; + } +} +int main() { + string s; + cin >> s; + int n = s.size(), cnt = 0; + for (int i = 0; i < n / 2; i++) { + char samne = s[i]; + char pichone = s[n - (i + 1)]; + if (samne != pichone) cnt++; + } + if (cnt == 0 && ispal(s) && n % 2 == 0) { + cout << "NO" + << "\n"; + ; + } else if (cnt > 1) { + cout << "NO" + << "\n"; + ; + } else { + cout << "YES" + << "\n"; + ; + } + return 0; +} +string s; +bool check() { + for (int i = 1; i < 8; i++) { + if (s[i] == s[i - 1]) { + rotate(s.begin(), s.begin() + 1, s.end()); + return false; + } + } + return true; +} +int main() { + for (int i = 0; i < 8; i++) { + cin >> s; + bool works = false; + for (int j = 0; j < 8; j++) { + if (check()) { + works = true; + break; + } + } + if (!works) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + long long m, n, i, j; + long long discounts[100005]; + memset(discounts, 0, sizeof(discounts)); + cin >> m; + for (i = 0; i < m; i++) cin >> discounts[i]; + sort(discounts, discounts + m); + cin >> n; + long long items[100005]; + memset(items, 0, sizeof(items)); + for (i = 0; i < n; i++) cin >> items[i]; + sort(items, items + n); + reverse(items, items + n); + long long k = 0, total = 0; + for (i = 0; i < n; i++) { + total += items[i]; + k++; + if (k == discounts[0]) { + k = 0; + i += 2; + } + } + cout << total << "\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i = 1; + int rem = m; + while (rem >= i) { + rem -= i; + i++; + if (i == n + 1) i = 1; + } + cout << rem << endl; +} +char a[101][101]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> a[i][j]; } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int temp = 0; + if (a[i + 1][j] == 'o') temp++; + if (a[i - 1][j] == 'o') temp++; + if (a[i][j + 1] == 'o') temp++; + if (a[i][j - 1] == 'o') temp++; + if (temp % 2 != 0) { + puts("NO"); + return 0; + } + } + } + puts("YES"); + return 0; +} +const int pi = acos(-1); +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int a[k] = {0}; + for (int i = 0; i < n; ++i) { a[s[i] - 'A']++; } + sort(a, a + k); + cout << a[0] * k << endl; +} +long long int freq[10005]; +int main() { + long long int n; + cin >> n; + long long int m; + vector a, b; + for (long long int i = 0; i < n; i++) { + long long int x; + cin >> x; + a.push_back(x); + } + cin >> m; + for (long long int i = 0; i < m; i++) { + long long int x; + cin >> x; + b.push_back(x); + } + long long int maxy = INT_MIN; + for (long long int i = 0; i < n; i++) { + for (long long int j = 0; j < m; j++) { + long long int ans = b[j] / a[i]; + if (ans * a[i] == b[j]) { + maxy = max(maxy, ans); + freq[ans]++; + } + } + } + cout << freq[maxy] << endl; + return 0; +} +int main() { + int n, k, a[200], b[200], i, m = 0; + bool flag = 1; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) m++; + } + for (i = 0; i < k; i++) { cin >> b[i]; } + if (m > 1) flag = 0; + if (m == 0) { + for (i = 0; i < n - 1; i++) { + if (a[i + 1] > a[i]) + continue; + else + flag = 0; + } + } + if (m == 1) { + for (i = 0; i < n; i++) { + if (a[i] == 0) a[i] = b[0]; + } + for (i = 0; i < n - 1; i++) { + if (a[i + 1] > a[i]) + continue; + else + flag = 0; + } + } + if (flag) + cout << "No" << endl; + else + cout << "Yes" << endl; + return 0; +} +int main() { + long long m, n, sum = 1; + cin >> n >> m; + if (n >= 27) { + cout << m << endl; + } else { + for (int i = 0; i < n; i++) { sum *= 2; } + cout << m % sum << endl; + } +} +int main() { + long long n, sum = 0, sum1 = 0; + cin >> n; + int k = 5; + int i; + for (i = 0; sum < n; i++) { + int kk = (int)pow(2, i); + sum += 5 * kk; + } + int ww = (int)(pow(2, i - 1)); + sum = sum - 5 * ww; + long long w = n - sum; + double t = (float)w / ww; + if (t > 0 && t <= 1) cout << "Sheldon" << endl; + if (t > 1 && t <= 2) cout << "Leonard" << endl; + if (t > 2 && t <= 3) cout << "Penny" << endl; + if (t > 3 && t <= 4) cout << "Rajesh" << endl; + if (t > 4 || t == 0) cout << "Howard" << endl; +} +long long N, A[100005], sum, ans, H; +int main() { + cin >> N >> H; + for (int i = 1; i <= N; i++) { + cin >> A[i]; + if (i != 1 && A[i] - A[i - 1] > H) + ans = 1; + else + ans++; + } + cout << ans << '\n'; +} +int main() { + int x, y, z; + while (cin >> x >> y >> z) { + int i; + int c = 0; + for (i = x; i <= z; i += x) { + for (int j = y; j <= i; j += y) { + if (i == j) { c++; } + } + } + cout << c << endl; + } +} +const int maxn = 5e5 + 1000; +int a[maxn], b[maxn]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + int ans = 0; + for (int l = 1; l <= n; l++) { + for (int r = 1; r <= n; r++) { + int tmp1 = 0, tmp2 = 0; + for (int i = l; i <= r; i++) { tmp1 |= a[i], tmp2 |= b[i]; } + ans = max(tmp1 + tmp2, ans); + } + } + cout << ans << endl; +} +int main() { + string s; + cin >> s; + int y = s.size() - 1; + int sum = 0; + for (int i = 0; i < s.size() / 2; i++) { + if (s[i] != s[y]) { sum++; } + if (sum == 2) { + cout << "NO" << endl; + return 0; + } + y--; + } + if (sum == 1) + cout << "YES" << endl; + else if (sum == 0 && s.size() % 2 != 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int x, y = 0, comp1 = 0, comp2 = 0, z = 0; + string num1, num2, num; + cin >> x >> num1 >> num2; + int a[x]; + int b[x]; + for (int i = 0; i < x; i++) { + num = num1[i]; + a[i] = atoi(num.c_str()); + } + for (int i = 0; i < x; i++) { + num = num2[i]; + b[i] = atoi(num.c_str()); + } + for (int i = 0; i < x; i++) { + comp1 = abs(a[i] - b[i]); + comp2 = 0; + z = a[i]; + while (true) { + if (z == 10) { + z = 0; + } else if (z == -1) { + z = 9; + } + if (z == b[i]) { + break; + } else { + if (a[i] > b[i]) { + z = z + 1; + } else { + z = z - 1; + } + comp2 = comp2 + 1; + } + } + if (comp2 < comp1) { + y = y + comp2; + } else { + y = y + comp1; + } + } + cout << y << endl; + return 0; +} +int main() { + int n, ar[101], ar2[101], c = 0, i, j; + cin >> n; + for (i = 0; i < n; i++) { cin >> ar[i] >> ar2[i]; } + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (ar[i] == ar2[j]) c++; + cout << c << endl; + return 0; +} +int main() { + long long n; + cin >> n; + pair ar[n + 1]; + for (long long i = 1; i <= n; i++) cin >> ar[i].first >> ar[i].second; + long long k = 0; + for (long long i = 1; i <= n; i++) { + for (long long j = 1; j <= n; j++) { + if (i != j) { + if (ar[i].first == ar[j].second) k++; + } + } + } + cout << k << endl; +} +int n; +int maxP, minP; +int ctMax, ctMin; +int score; +int main() { + cin >> n; + cin >> maxP; + minP = maxP; + n--; + while (n--) { + cin >> score; + if (score > maxP) { + maxP = score; + ctMax++; + } else if (score < minP) { + minP = score; + ctMin++; + } + } + cout << ctMin + ctMax << endl; +} +int main() { + string s1, s2; + int n, i, j, k; + cin >> s1 >> s2; + for (i = 0; (i < s1.length() - 1) && (s1[i] == '0'); i++) + ; + s1 = s1.substr(i); + for (i = 0; (i < s2.length() - 1) && (s2[i] == '0'); i++) + ; + s2 = s2.substr(i); + int ans; + if (s1 == s2) + ans = 0; + else if (s1.length() > s2.length()) + ans = 1; + else if (s1.length() < s2.length()) + ans = -1; + else { + if (s1 > s2) + ans = 1; + else + ans = -1; + } + if (ans == 0) + cout << "=\n"; + else if (ans == 1) + cout << ">\n"; + else + cout << "<\n"; + return 0; +} +long long int a[10]; +string x[] = {"1", "14", "144"}; +string n; +vector rs; +long long int save(long long int n) { + string s = ""; + for (long long int i = 0; i <= n - 1; i++) { s += x[a[i]]; } + rs.push_back(s); +} +void gen(long long int n) { + for (long long int i = 0; i <= n - 1; i++) { a[i] = 0; } + while (true) { + save(n); + long long int i = n - 1; + while (i >= 0 && a[i] == 2) { i--; } + if (i < 0) { break; } + a[i]++; + for (long long int j = i + 1; j <= n - 1; j++) { a[j] = 0; } + } +} +int main() { + for (long long int i = 1; i <= 9; i++) { gen(i); } + cin >> n; + for (long long int i = 0; i <= rs.size() - 1; i++) { + if (n == rs[i]) { + cout << "YES" + << "\n"; + return 0; + } + } + cout << "NO" + << "\n"; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + char a[n][m]; + long long i; + long long j; + long long ii, jj, iii, jjj; + long long flag = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + cin >> a[i][j]; + if (flag == 0 && a[i][j] == 'B') { + ii = i; + jj = j; + iii = i; + jjj = j; + flag = 1; + } else if (flag == 1 && a[i][j] == 'B') { + iii = i; + jjj = j; + } + } + } + ii++; + jj++; + iii++; + jjj++; + cout << (ii + iii) / 2 << " " << (jj + jjj) / 2 << "\n"; +} +const int N = 1e5 + 100; +int n, k, ans, a[55]; +vector v; +bool flag; +bool check() { + int sum = 0; + for (int i = 0; i < n; i++) { sum += a[i]; } + if (sum == k) return true; + return false; +} +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { a[i] = 2; } + if (check()) { + cout << n << endl; + return 0; + } + for (int i = 2; i <= 5; i++) { + for (int j = 0; j < n; j++) { + a[j]++; + if (check()) { + flag = true; + break; + } + } + if (flag) break; + } + if (flag) { + for (int i = 0; i < n; i++) { + if (a[i] == 2) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + int mx = V[0]; + for (int i = 0; i < n; ++i) { + int cur = 0; + for (int j = i; j < n; ++j) { + cur ^= V[j]; + mx = max(mx, cur); + } + } + cout << mx << "\n"; + return 0; +} +int main() { + int N; + cin >> N; + string S; + cin >> S; + sort((S).begin(), (S).end()); + cout << S << "\n"; +} +int main() { + int rate, dollar; + long long number; + while (cin >> rate >> dollar >> number) { + long long price; + long long Need_money; + price = rate * ((number * (number + 1)) / 2); + Need_money = price - dollar; + if (Need_money < 0) { Need_money = 0; } + cout << Need_money << endl; + } + return 0; +} +long long x[5], k; +int main() { + cin >> x[1] >> x[2] >> x[3] >> k; + for (int i = 0; i < 3; i++) + for (int j = 1; j < 3; j++) + if (x[j] > x[j + 1]) swap(x[j], x[j + 1]); + long long cnt1, cnt2, cnt3; + cnt1 = min(x[1] - 1, k / 3); + k -= cnt1; + cnt2 = min(x[2] - 1, k / 2); + k -= cnt2; + cnt3 = min(x[3] - 1, k); + cout << (cnt1 + 1) * (cnt2 + 1) * (cnt3 + 1) << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int time1 = ceil((double)n / k) * t; + int num_of_cakes = 0, time2; + for (int i = 1; num_of_cakes < n; i++) { + if (i % t == 0) num_of_cakes += k; + if (i > d && (i - d) % t == 0) num_of_cakes += k; + time2 = i; + } + (time2 < time1) ? cout << "YES\n" : cout << "NO\n"; + return 0; +} +int main() { + long long int n, i, j; + cin >> n; + string ans = ""; + while (n >= 4) { + if (n % 4 == 0 && n % 7 == 0) { + ans += '7'; + n = n - 7; + } else if (n % 4 == 0) { + ans += '4'; + n = n - 4; + } else if (n >= 7) { + ans += '7'; + n = n - 7; + } else if (n >= 4) { + ans += '4'; + n = n - 4; + } + } + if (n != 0) { + cout << -1 << endl; + return 0; + } + sort(ans.begin(), ans.end()); + cout << ans << endl; + return 0; +} +char s[100010]; +bool flag, ok[1010], exist[1010]; +int ans; +int main() { + int n; + cin >> n; + flag = false; + ans = 0; + for (int i = 'a'; i <= 'z'; i++) ok[i] = 1; + int num = 26; + for (int i = 0; i < n; i++) { + char c; + cin >> c >> s; + if (flag) { + if (c != '.' && i != n - 1) { ans++; } + } else { + if (c == '!') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; j++) { + if (ok[j] && !exist[j]) { + num--; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '.') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; j++) { + if (ok[j] && exist[j]) { + num--; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '?') { + if (ok[s[0]]) { + num--; + ok[s[0]] = 0; + } + if (num == 1) flag = true; + } + } + } + cout << ans << endl; + return 0; +} +bool isprime(int n) { + if (n < 2) return false; + for (int i = 2; i * i <= n; i++) + if (n % i == 0) return false; + return true; +} +int main() { + int n, k; + cin >> n >> k; + vector ans; + for (int i = 1; i <= n; i++) + if (n % i == 0 && isprime(i)) { + while (n % i == 0) { + ans.push_back(i); + n /= i; + } + } + if (k > ans.size()) { + cout << "-1\n"; + return 0; + } + for (int i = 0; i < k - 1; i++) cout << ans[i] << ' '; + int ret = 1; + for (int i = k - 1; i < ans.size(); i++) ret *= ans[i]; + cout << ret << endl; + return 0; +} +int n; +int a[2005], b[2005]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + cout << "Karen" << endl; + return 0; +} +int main() { + int i, n, a, j, k, l = 0; + vector points; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a; + if (a != 0) { + l++; + points.push_back(a); + } + } + int count = 0, same = 1, total = 0; + sort(points.begin(), points.end()); + for (j = 0; j < l; j++) { + if (j != (l - 1)) { + for (k = j + 1; k < l; k++) { + if (points[j] == points[k]) { + same++; + } else { + same = same; + } + } + if (same > 1) { + count++; + j = j + same - 1; + total = total + same; + } + same = 1; + } + if ((j + same) >= l) break; + } + cout << (l - total + count); + cout << endl; +} +int main() { + long long n; + long long x1, x2, y1, y2; + long long a[110][110], sum = 0; + cin >> n; + for (long long k = 0; k < n; k++) { + cin >> x1 >> y1 >> x2 >> y2; + for (long long i = x1; i <= x2; i++) { + for (long long j = y1; j <= y2; j++) { a[i][j]++; } + } + } + for (long long i = 1; i <= 100; i++) { + for (long long j = 1; j <= 100; j++) { sum += a[i][j]; } + } + cout << sum << "\n"; +} +const int maxn = 10005; +int s[maxn]; +int dp[maxn]; +int len = 0; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + dp[i] = 1; + for (int j = 0; j < i; j++) { + if (s[i] >= s[j] && dp[j] + 1 > dp[i]) dp[i] = dp[j] + 1; + } + len = max(dp[i], len); + } + cout << len << endl; + return 0; +} +int N, K, A[55]; +int main() { + string str; + cin >> N >> K >> str; + for (int i = 0; i <= N - 1; i++) A[i] = str[i] - 'a' + 1; + sort(A, A + N); + int Last = -2, cnt = 0, Tot = 0; + for (int i = 0; i <= N - 1; i++) { + if (A[i] - Last >= 2 && cnt < K) { + Last = A[i]; + cnt++; + Tot += A[i]; + } + } + if (cnt < K) + cout << -1 << '\n'; + else + cout << Tot << '\n'; + return 0; +} +int main() { + int w = 0, h = 0, k = 0; + cin >> w >> h >> k; + int cells = 0; + while (k--) { + cells = cells + ((2 * (w + h)) - 4); + w -= 4; + h -= 4; + } + cout << cells << "\n"; + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + int ans = 0; + while (n--) { + char c; + cin >> c; + int d; + cin >> d; + if (c == '+') { + x += d; + } else { + if (x >= d) + x -= d; + else + ans++; + } + } + cout << x << ' ' << ans << endl; +} +int main() { + long long int n, k, m, dis = 0, sum = 0; + char c; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> c >> m; + if (c == '+') { + k += m; + } else { + if (m > k) { + dis++; + } else { + k -= m; + } + } + } + cout << k << " " << dis << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 0; i < n; i++) cin >> a[i]; + int max = a[0], min = a[0], count = 0; + for (int i = 1; i < n; i++) { + if (a[i] > max) max = a[i], count++; + if (a[i] < min) min = a[i], count++; + } + cout << count << endl; + return 0; +} +vector VI, VI2, VI3, VI4; +int n, m, f = 0, t; +string s; +int main() { + cin >> n >> m; + string S[n]; + for (int i = 0; i < n; i++) cin >> S[i]; + for (int i = 0; i < n; i++) { + s = S[i]; + for (int j = 0; j < s.size(); j++) { + if (s[j] == '-') + cout << "-"; + else { + if ((i + j) % 2 == 0) + cout << "B"; + else + cout << "W"; + } + } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v1(2002), v2(202), v3(2002), v4(2002); + for (int i = 0; i < n; i++) cin >> v1[i]; + for (int i = 0; i < m; i++) cin >> v2[i]; + for (int i = 0; i + m <= n; i++) + for (int j = 0; j < m; j++) v3[i] += v1[i + j]; + for (int i = 0; i + m <= n; i++) + for (int j = 0; j < m; j++) v4[i] += v2[j].substr(i, m); + for (int i = 0; i + m <= n; i++) + for (int j = 0; j + m <= n; j++) + if (v3[i] == v4[j]) { + cout << i + 1 << ' ' << j + 1 << endl; + return 0; + } + return 0; +} +int n, sum = 0; +bool a, b, c; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c; + if ((a and b) or (b and c) or (c and a)) { sum++; } + } + cout << sum << endl; + return 0; +} +string s; +int main() { + set a; + cin >> s; + for (int i = 0; i < s.size(); i++) { + string s1 = ""; + s1 = s.substr(0, s.size() - 1); + s = s[s.size() - 1] + s1; + a.insert(s); + } + cout << a.size() << endl; +} +int main() { + string st; + int sum = 0, a, p = 0, k = 0, g = 1; + cin >> st; + for (int i = 0; i < st.size(); i++) { + if (st[i] == '4' || st[i] == '7') sum = sum + 1; + } + if (sum == 0) { g = 0; } + while (sum > 0) { + a = sum % 10; + sum = sum / 10; + p = p + 1; + if (a == 4 || a == 7) { k = k + 1; } + } + if (p == k && g == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long a[120]; +int main() { + long long m, d, ans = 0; + cin >> m >> d; + for (int i = 1; i <= m; ++i) { cin >> a[i]; } + for (int i = 1; i <= m - 1; i++) { + int temp = a[i] + d; + if (a[i + 1] - temp > d) + ans += 2; + else if (a[i + 1] - a[i] == 2 * d) + ans += 1; + } + cout << ans + 2 << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int l; + cin >> l; + string a; + cin.get(); + getline(cin, a); + if (a.length() > 2 || a.length() == 2 && a[0] < a[1]) { + cout << "YES" << endl; + cout << 2 << endl; + cout << a[0] << ' '; + for (int j = 1; j < a.length(); j++) cout << a[j]; + cout << endl; + } else + cout << "NO" << endl; + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + cout << (((n / k) & 1LL) == 0 ? "NO\n" : "YES\n"); + return 0; +} +string a; +int main() { + int n; + cin >> a; + n = a.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 'V' && a[i + 1] == 'K') { + ans++; + a[i] = a[i + 1] = '#'; + } + } + for (int i = 0; i < n; i++) { + if (a[i] == 'V' && a[i + 1] == 'V' || a[i] == 'K' && a[i + 1] == 'K') { + ans++; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + bool ara[3][3]; + int x; + memset(ara, 1, sizeof(ara)); + int w = 0, q = 0; + while (w < 3) { + q = 0; + while (q < 3) { + cin >> x; + if (x % 2 == 1) { + if (!ara[w][q]) + ara[w][q] = 1; + else + ara[w][q] = 0; + if (w + 1 < 3) { + if (!ara[w + 1][q]) + ara[w + 1][q] = 1; + else + ara[w + 1][q] = 0; + } + if (q + 1 < 3) { + if (!ara[w][q + 1]) + ara[w][q + 1] = 1; + else + ara[w][q + 1] = 0; + } + if (w - 1 >= 0) { + if (!ara[w - 1][q]) + ara[w - 1][q] = 1; + else + ara[w - 1][q] = 0; + } + if (q - 1 >= 0) { + if (!ara[w][q - 1]) + ara[w][q - 1] = 1; + else + ara[w][q - 1] = 0; + } + } + q++; + } + w++; + } + w = 0; + q = 0; + for (int i = 0; i < 3; i++) { + for (int r = 0; r < 3; r++) { cout << ara[i][r]; } + cout << endl; + } + return 0; +} +vector v; +int main() { + v.clear(); + int n, k; + cin >> n >> k; + while (n != 1) { + for (int i = 2; i <= n; i++) { + if (n % i == 0) { + v.push_back(i); + n = n / i; + break; + } + } + } + int sz = v.size(); + long long sum = 1; + if (sz >= k) { + for (int i = 0; i < sz; i++) { + if ((i + 1) <= k - 1) + cout << v[i] << " "; + else + sum = sum * v[i]; + } + cout << sum << endl; + } else + cout << -1 << endl; + return 0; +} +int main() { + int a[105][105], n, i, j, x, y, p, q, l; + while (cin >> n) { + int sum = 0; + memset(a, 0, sizeof(a)); + for (l = 1; l <= n; l++) { + cin >> x >> y >> p >> q; + for (i = y; i <= q; i++) { + for (j = x; j <= p; j++) { a[i][j]++; } + } + } + for (i = 1; i <= 100; i++) { + for (j = 1; j <= 100; j++) { sum += a[i][j]; } + } + cout << sum << endl; + } + return 0; +} +string a; +long long b; +bool x, y; +int main() { + cin >> a; + if (a[0] == 'h' || a[0] == 'a') x = 1; + if (a[1] == '8' || a[1] == '1') y = 1; + if (x == 1 && y == 1) b++; + if (x == 1) b -= 3; + if (y == 1) b -= 3; + cout << b + 8 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (3 * (n / 2)) << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) ans += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); + cout << ans << endl; + return 0; +} +int main() { + int dis = 0; + int n; + long long int x; + cin >> n; + cin >> x; + char sign, spc; + int num; + for (int i = 0; i < n; i++) { + cin >> sign; + cin >> num; + getchar(); + if (sign == '+') + x += num; + else if (sign == '-') { + if (num > x) + dis++; + else + x -= num; + } + } + cout << x << " " << dis << endl; + return 0; +} +int main() { + int t; + cin >> t; + int n; + string s; + while (t--) { + cin >> n >> s; + bool palindrome = true; + for (int i = 0; i < n / 2; ++i) { + int k = abs(s[i] - s[n - i - 1]); + if (k > 2 || k % 2 == 1) { + palindrome = false; + break; + } + } + cout << (palindrome ? "YES" : "NO") << endl; + } +} +int main() { + string str1, str2; + cin >> str1; + cin >> str2; + int flag = 0, a; + transform(str1.begin(), str1.end(), str1.begin(), ::tolower); + transform(str2.begin(), str2.end(), str2.begin(), ::tolower); + for (int i = 0; i < str1.length(); i++) { + if (str1[i] > str2[i]) { + cout << 1 << endl; + flag = 1; + break; + } else if (str1[i] < str2[i]) { + cout << -1 << endl; + flag = 1; + break; + } + } + if (flag != 1) cout << 0 << endl; + return 0; +} +int main() { + long long int n, x, y, i, count = 0; + string s; + cin >> s; + n = s.length(); + int a[26]; + for (i = 0; i < 26; i++) { a[i] = 0; } + for (i = 0; i < n; i++) { + x = s[i] - 97; + a[x] = 1; + } + for (i = 0; i < 26; i++) { + if (a[i] == 1) { count++; } + } + if (count % 2 == 0) { + cout << "CHAT WITH HER!"; + } else { + cout << "IGNORE HIM!"; + } + cout << "\n"; +} +int main() { + long long n, a; + while (cin >> n) { + a = 3; + while (n % a == 0) a *= 3; + cout << n / a + 1 << endl; + } + return 0; +} +int main() { + int n, id, a; + cin >> n; + vector v(n + 1); + for (int i = 0; i < n - 1; i++) { + cin >> a; + v[a]++; + } + for (int i = 1; i < n + 1; i++) + if (v[i] == 0) id = i; + cout << id << endl; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int a[n]; + int sum = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n - k; i++) { sum += a[i]; } + sum += k * x; + cout << sum << '\n'; + return 0; +} +long long a[200010]; +int main() { + long long n; + cin >> n; + int cnt = 0; + long long mn = 2000000000; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] < mn) mn = a[i] - a[i - 1]; + } + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] == mn) cnt++; + } + cout << mn << " " << cnt << endl; + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + double t = a * c * 1.0 / b; + int x = (int)t; + if (t - x >= 0.000001) x++; + x -= c; + cout << x << endl; + } +} +int main() { + int n; + cin >> n; + cout << "25" << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string q; + cin >> q; + int a, b; + char w, e; + while (m--) { + cin >> a >> b >> w >> e; + for (int i = a - 1; i <= b - 1; ++i) { + if (q[i] == w) q[i] = e; + } + } + cout << q << endl; + return 0; +} +const int N = 1e6; +int main() { + int n; + cin >> n; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +int mp[200]; +int main() { + int n, k; + string a; + cin >> n >> k; + cin >> a; + memset(mp, 0, sizeof mp); + for (int i = 0; i < n; i++) { mp[a[i]] = 1; } + int j = 0; + int ans = 0; + for (int i = 97; i < 123; i++) { + if (mp[i] == 1) { + ans += (i - 96); + i++; + j++; + if (j == k) break; + } + } + if (j == k) + cout << ans << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + vector lista; + int n, d, res; + cin >> n; + while (n--) { + cin >> d; + lista.push_back(d); + } + sort(lista.begin(), lista.end()); + if (lista[0] == 1 || lista[1] == 1) + res = -1; + else + res = 1; + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int l = n / 2, r = n / 2; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j >= l && j <= r) { + cout << 'D'; + } else { + cout << '*'; + } + } + if (i < n / 2) { + l--; + r++; + } else { + l++; + r--; + } + cout << endl; + } + return 0; +} +int a, b, c; +int main() { + cin >> a >> b; + while (b > 0) { + int d = b % 10; + c = c * 10 + d; + b /= 10; + } + cout << a + c << endl; + return 0; +} +const int MAXN = 205; +const int inf = 1e9 + 1e8; +const long long INF = 1e18 + 1e17; +const int MOD1 = 1e9 + 7; +const int MOD2 = 998244353; +int N, M; +string str; +int main() { + cin >> N >> M; + cin >> str; + str = '0' + str; + for (int i = 0; i < M; i++) { + int l, r; + char c1, c2; + cin >> l >> r >> c1 >> c2; + for (int j = l; j <= r; j++) { + if (str[j] == c1) { str[j] = c2; } + } + } + cout << str.substr(1) << endl; + return 0; +} +int main() { + string n; + int k; + cin >> n >> k; + while (k--) { + if (n[n.size() - 1] == '0') + n.erase(n.size() - 1, 1); + else + n[n.size() - 1]--; + } + cout << n << endl; + return 0; +} +long long cont[101]; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + long long num; + cin >> num; + cont[num]++; + } + long long maxi = 0; + for (long long i = 1; i <= 100; i++) { maxi = max(maxi, cont[i]); } + cout << maxi << endl; +} +int main() { + int n, cnt = 0; + cin >> n; + while (n--) { + char str[20]; + cin >> str; + if (str[0] == 'T') + cnt += 4; + else if (str[0] == 'C') + cnt += 6; + else if (str[0] == 'O') + cnt += 8; + else if (str[0] == 'D') + cnt += 12; + else if (str[0] == 'I') + cnt += 20; + } + cout << cnt << endl; +} +int main() { + int bacterias; + cin >> bacterias; + int contador_final = 0; + int contador_bacterias; + while (bacterias != 0) { + contador_bacterias = 1; + while (contador_bacterias < bacterias || contador_bacterias == 1) { contador_bacterias *= 2; } + if (contador_bacterias > bacterias) { contador_bacterias /= 2; } + contador_final++; + bacterias = bacterias - contador_bacterias; + } + cout << contador_final << endl; +} +int main() { + long long n, m, a, b, num = 0; + cin >> n >> m >> a >> b; + if (n % m == 0) { + num = 0; + } else if (n < m) { + num = min(a * (m - n), n * b); + } else { + long long y = n % m, z = m - n % m; + num = min(y * b, z * a); + } + cout << num << endl; + return 0; +} +string a; +int javab = 0; +int main() { + char x; + int t = 0; + cin >> a; + int n = (int)a.size(); + for (int i = 0; i < n; i++) { + x = a[i]; + t = 0; + for (; i < n; i++) { + if (i == n - 1 && a[i] == x) { + t++; + break; + } + if (a[i] != x) { + i--; + break; + } + t++; + } + if (t % 2 == 0) javab++; + } + cout << javab << endl; + return 0; +} +int main() { + long long int n, k; + cin >> n >> k; + long long int h; + h = n / k; + if (h % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int c = (n + k - 1) / k; + int c2 = d / t; + if (c - c2 <= 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int a[5][5] = {0}; + int b[5][5] = {0}; + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { cin >> a[i][j]; } + } + for (int x = 1; x <= 3; x++) { + for (int y = 1; y <= 3; y++) { + b[x][y] = (a[x][y] + a[x + 1][y] + a[x - 1][y] + a[x][y + 1] + a[x][y - 1]); + if (b[x][y] % 2 == 0) + cout << "1"; + else + cout << "0"; + } + cout << "\n"; + } + return 0; +} +int main() { + int a[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { a[i][j] = 0; } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j < 4; j++) { cin >> a[i][j]; } + } + int b[3][3]; + for (int i = 1; i < 4; i++) { + for (int j = 1; j < 4; j++) { + int c = a[i - 1][j] + a[i][j - 1] + a[i][j] + a[i][j + 1] + a[i + 1][j]; + if (c % 2 == 0) { + b[i - 1][j - 1] = 1; + } else { + b[i - 1][j - 1] = 0; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << b[i][j]; } + cout << "\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + vector vec(n); + cin >> vec[0]; + cin >> vec[1]; + cin >> vec[2]; + int m = vec[2] - vec[0]; + for (int i = 3; i < n; i++) { + cin >> vec[i]; + m = min(vec[i] - vec[i - 2], m); + } + int m2 = vec[1] - vec[0]; + for (int i = 1; i < n; i++) { m2 = max(vec[i] - vec[i - 1], m2); } + cout << max(m, m2) << endl; +} +int main() { + int n, m, e = 4; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + int x; + cin >> x; + if (x && (i == 1 || i == n || j == 1 || j == m)) e = 2; + } + } + cout << e << '\n'; +} +int main() { + int n; + cin >> n; + int k = 0; + while (n != 0) { + if (n % 2 == 1) { k++; } + n = n / 2; + } + cout << k << endl; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M >> L >> R; + K = M / L + !!(M % L); + cout << N * K / R + !!((N * K) % R) << endl; + return 0; +} +int main() { + int a, b, c, d, e, f; + while (cin >> a) { + if (a % 10 == 0) { + cout << a << endl; + } else if (a % 10 == 5) { + cout << a - 5 << endl; + } else if (a % 10 < 5) { + b = a % 10; + cout << a - b << endl; + } else { + b = a % 10; + b = 10 - b; + cout << a + b << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a[1005]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + int t = sqrt(a[i]); + if (t * t != a[i]) { + cout << a[i] << endl; + return 0; + } + } +} +const int maxn = 5010; +char s[maxn]; +int main() { + cin >> s; + int l = strlen(s); + int ans = 0; + for (int i = 0; i < l; i++) { + int x = 0, y = 0, z = 0; + for (int j = i; j < l; j++) { + if (s[j] == '(') + x++; + else if (s[j] == ')') + y++; + else { + y++; + z++; + } + if (x + z < y - z) break; + if (x < y && z) { + x++; + y--; + z--; + } + if (x == y) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long int l, r, z, one; + cin >> l >> r; + one = 1; + z = l; + for (int j = 0; j < 63; j++) { + if (((one << j) | z) > r) continue; + z |= one << j; + } + cout << z << endl; + } +} +int main() { + int arr[3][3] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + int arx[4] = {1, 0, -1, 0}; + int ary[4] = {0, 1, 0, -1}; + int ar[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { + cin >> ar[i][j]; + if (ar[i][j] % 2 != 0) { + arr[i][j] = 1 - arr[i][j]; + int x = i, y = j; + for (int l = 0; l < 4;) { + x = i + arx[l]; + y = j + ary[l]; + if (x < 0 || y < 0 || x > 2 || y > 2) + l++; + else { + arr[x][y] = 1 - arr[x][y]; + l++; + } + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << arr[i][j]; } + cout << endl; + } +} +int main() { + long long int n; + cin >> n; + vector v, a; + for (int i = 0; i < n; i++) { + long long int k; + cin >> k; + a.push_back(k); + } + for (int i = 1; i < n - 1; i++) { + int k = a[i]; + a.erase(a.begin() + i); + int max = INT_MIN; + for (int j = 1; j < a.size(); j++) { + if (a[j] - a[j - 1] > max) max = (a[j] - a[j - 1]); + } + v.push_back(max); + a.push_back(k); + sort(a.begin(), a.end()); + } + sort(v.begin(), v.end()); + cout << v[0] << endl; +} +int gcd(int a, int b) { + while (b > 0) { + int tmp = b; + b = a % b; + a = tmp; + } + return a; +} +int lcm(int a, int b) { + return a * b / gcd(a, b); +} +int main() { + cout << setprecision(12); + int x; + cin >> x; + ; + int y; + cin >> y; + ; + int a; + cin >> a; + ; + int b; + cin >> b; + ; + cout << b / lcm(x, y) - (a - 1) / lcm(x, y) << endl; +} +int main() { + string str; + int i, count1 = 0, count2 = 0; + cin >> str; + for (i = 0; i < str.length(); i++) { + if (isupper(str[i])) + count1++; + else + count2++; + } + if (count1 > count2) { + for (i = 0; i < str.length(); i++) { str[i] = toupper(str[i]); } + } else { + for (i = 0; i < str.length(); i++) { str[i] = tolower(str[i]); } + } + cout << str << endl; +} +int main() { + int a, b, c, t; + cin >> a >> b >> c; + int req = (a * c) - (b * c); + cout << ceil((req * 1.0) / b) << endl; + return 0; +} +map mp; +map mymap; +int main() { + long long i, j, k, l, m, n, o, p, t, z = 0, d; + cin >> t; + string s; + getchar(); + while (t--) { + cin >> s >> d; + if (s == "+") { + mp[d]++; + s.clear(); + while (d > 0) { + s.push_back((d % 10) % 2 + 48); + d /= 10; + } + while (s.size() < 18) s.push_back('0'); + mymap[s]++; + } else if (s == "-") { + mp[d]--; + s.clear(); + while (d > 0) { + s.push_back((d % 10) % 2 + 48); + d /= 10; + } + while (s.size() < 18) s.push_back('0'); + mymap[s]--; + } else { + s.clear(); + while (d > 0) { + s.push_back(d % 10 + 48); + d /= 10; + } + while (s.size() < 18) s.push_back('0'); + cout << mymap[s] << endl; + } + } + return 0; +} +int main() { + long long i, j, n, c = 0, ans = 25; + cin >> n; + cout << ans << endl; + return 0; +} +const int M = 100 + 5; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '.') { s[i] = ' '; } + } + istringstream ss(s); + string intp; + string frap; + ss >> intp >> frap; + int intlen = intp.length(); + if (intp[intlen - 1] != '9') { + if (frap[0] >= '5') { + intp[intlen - 1] += 1; + cout << intp << endl; + } else { + cout << intp << endl; + } + } else { + cout << "GOTO Vasilisa." << endl; + } + return 0; +} +int cnt[20090]; +int main() { + int n, i, j, k, l, t, r, e; + cin >> n >> k; + int arr[k]; + int mi = INT_MAX; + for (i = 0; i < k; i++) { + cin >> arr[i]; + cnt[arr[i]]++; + } + for (j = 1; j <= n; j++) { mi = min(mi, cnt[j]); } + cout << mi << endl; + return 0; +} +int n, k, c; +int a[400], f[400]; +int main() { + cin >> n >> k >> c; + for (int i = 1, x; i <= c; i++) { + cin >> x; + a[x] = 1; + } + for (int i = 1; i <= n; i++) f[i] = f[i - 1] + a[i]; + for (int i = 0; i <= n - k; i++) { + if (!(f[i + k] - f[i])) { + a[i + k] = 1; + for (int j = i + k; j <= n; j++) f[j]++; + } + } + cout << f[n] << endl; + return 0; +} +int main() { + int k; + cin >> k; + string q; + cin >> q; + int a[26] = {0}; + vector arr; + int i, j; + for (i = 0, j = 0; i < q.size() && j < k; i++) { + if (a[q[i] - 'a'] == 0) { + arr.push_back(i); + a[q[i] - 'a']++; + j++; + } + } + if (j != k) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + for (int i = 1; i < k; i++) { + for (int j = arr[i - 1]; j < arr[i]; j++) { cout << q[j]; } + cout << endl; + } + for (int i = arr.back(); i < q.size(); i++) { cout << q[i]; } + cout << endl; + } +} +int main() { + int n; + char s[105][105]; + int num[105]; + num[0] = num[1] = 0; + for (int i = 2; i < 105; i++) { num[i] = num[i - 1] + i - 1; } + cin >> n; + int sum = 0, cnt; + for (int i = 0; i < n; i++) { + cnt = 0; + cin >> s[i]; + for (int j = 0; j < n; j++) { + if (s[i][j] == 'C') cnt++; + } + sum = sum + num[cnt]; + } + for (int i = 0; i < n; i++) { + cnt = 0; + for (int j = 0; j < n; j++) { + if (s[j][i] == 'C') cnt++; + } + sum = sum + num[cnt]; + } + cout << sum << "\n"; + return 0; +} +const int N = 1e6 + 10; +const int mod = 998244353; +int n, q; +string x; +int main() { + cin >> n >> q >> x; + for (int i = 0; i < q; i++) { + int a, b; + char c, d; + cin >> a >> b >> c >> d; + for (int j = a - 1; j <= b - 1; j++) + if (x[j] == c) x[j] = d; + } + cout << x << endl; +} +int main() { + long long int t, n; + cin >> t; + while (t--) { + cin >> n; + if (360 % (180 - n) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int i, n, t, k, w; + long long sum = 0; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum = sum + (i * k); } + if (sum <= n) { + cout << 0 << "\n"; + } else + cout << sum - n << "\n"; + return 0; +} +int main() { + int n, c, m = 0, ct = 0, i, j, ck; + cin >> n >> c; + string s; + for (i = 0; i < c; i++) { + ck = 0; + cin >> s; + for (j = 0; j < n; j++) { + if (s[j] == '0') { + ck = 1; + break; + } + } + if (ck == 1) + ct++; + else + ct = 0; + m = max(m, ct); + } + cout << m << endl; +} +const long long OO = 1e8; +const int o_o = 0; +double EPS = numeric_limits::epsilon(); +bool palinoal(string x) { + if (x.size() == 1) { return 1; } + int l = 0, r = x.size() - 1; + for (l, r; l < x.size();) { + if (l == r || r < l) { return 1; } + if (x[l] != x[r]) { return 0; } + l++; + r--; + } + return 1; +} +int main() { + string s; + getline(cin, s); + string palin = ""; + int n = s.size(); + for (int m = 0; m < (1 << n); m++) { + string x = ""; + for (int i = 0; i < n; i++) { + if ((m & (1 << i)) != 0) { x += s[i]; } + } + if (palinoal(x)) { + if (palin.size() == 0) { + palin = x; + } else if (x > palin) { + palin = x; + } + } + } + cout << palin << endl; + return 0; +} +int Noofintersectionsleft(int n, int m) { + return n * m - (n + m) + 1; +} +int main() { + int a; + int b; + cin >> a; + cin >> b; + int count = 0; + while (a * b >= 0) { + if (Noofintersectionsleft(a, b) <= 0) { + if (count % 2 == 0) { + cout << "Akshat" << endl; + return 0; + } else { + cout << "Malvika" << endl; + return 0; + } + } + a = a - 1; + b = b - 1; + count += 1; + } +} +int main() { + int n, k, f[10005], t[10005], j[10005]; + while (cin >> n >> k) { + for (int i = 0; i < n; i++) { cin >> f[i] >> t[i]; } + for (int i = 0; i < n; i++) { + if (t[i] >= k) { + j[i] = f[i] - (t[i] - k); + } else + j[i] = f[i]; + } + sort(&j[0], &j[n]); + cout << j[n - 1] << endl; + } +} +int main() { + string z = "qwertyuiopasdfghjkl;zxcvbnm,./"; + string b, c; + char a; + int i, j; + cin >> a; + cin >> b; + if (a == 'R') { + for (i = 0; i < b.size(); i++) { + for (j = 0; j < z.size(); j++) { + if (b[i] == z[j]) { + cout << z[j - 1]; + break; + } + } + } + cout << endl; + } else { + for (i = 0; i < b.size(); i++) { + for (j = 0; j < z.size(); j++) { + if (b[i] == z[j]) { + cout << z[j + 1]; + break; + } + } + } + cout << endl; + } + return 0; +} +int main() { + int x; + for (int i = 1; i <= 5; i++) + for (int j = 1; j <= 5; j++) { + cin >> x; + if (x == 1) { + cout << abs(i - 3) + abs(j - 3) << endl; + break; + } + } + return 0; +} +int main() { + int a; + int b; + cin >> a >> b; + for (int i = 1; i <= a; i++) { + for (int j = 1; j <= b; j++) { + if (i % 2 == 1) { + if (j == b) { + cout << "#\n"; + } else { + cout << '#'; + } + } else if (i % 4 == 2) { + if (j == b) { + cout << "#\n"; + } else { + cout << '.'; + } + } else { + if (j == 1) { + cout << '#'; + } else if (j == b) { + cout << ".\n"; + } else { + cout << '.'; + } + } + } + } + return 0; +} +int n, a[5005]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +const int SZ = 200010, INF = 0x7FFFFFFF; +long long sub(long long a, long long b, long long c, long long ll) { + long long res = 0; + for (long long i = max((long long)0, b + c - a); i <= ll; ++i) { + long long less = min(ll - i, a + i - (b + c)); + res += less + 1 + less * (less + 1) / 2; + } + return res; +} +int main() { + long long a, b, c, ll; + cin >> a >> b >> c >> ll; + long long res = 0; + for (long long i = 0; i <= ll; ++i) { res += (i + 3 - 1) * (i + 3 - 2) / 2; } + res -= sub(a, b, c, ll); + res -= sub(b, c, a, ll); + res -= sub(c, a, b, ll); + cout << res << endl; + return 0; +} +string s; +int n; +vector vec; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + vec.push_back(s); + } + for (int i = 0; i < (int)s.size(); i++) { + for (int j = 0; j < n; j++) { + if (vec[j][i] != vec[0][i]) { + cout << i << endl; + return 0; + } + } + } + cout << (int)s.size() << endl; + return 0; +} +int main() { + char a[55]; + gets(a); + int i = 0, cnt = 0; + for (; a[i] != '\0'; i++) { + if (a[i] <= '9' && a[i] >= '0') { + if ((a[i] - '0') % 2 != 0) { cnt++; } + } + if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') { cnt++; } + } + cout << cnt << endl; + return 0; +} +int get(int temp) { + int answer = 0; + while (temp != 0) { + answer += temp % 10; + temp /= 10; + } + return answer; +} +int main() { + int n; + cin >> n; + int count = 1; + int finala = 0; + vector v; + while ((n > 0) && (count < 100)) { + int temp; + temp = n - count; + int answer; + answer = get(temp); + if (answer == count) { + finala++; + v.push_back(temp); + } + count++; + } + if (finala == 0) + cout << "0" << endl; + else { + cout << finala << endl; + for (int i = v.size() - 1; i >= 0; i--) cout << v[i] << endl; + } + return 0; +} +int main() { + long long n, i; + string s; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> s; + if (s.size() <= 10) + cout << s << endl; + else + cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl; + } + return 0; +} +const int INF = 2000000000; +int main() { + int n, total = 0; + cin >> n; + int A[n][2]; + for (int i = 0; i < n; i++) cin >> A[i][0] >> A[i][1]; + int before = INF; + for (int i = 0; i < n; i++) { + if (A[i][1] < before) before = A[i][1]; + total += (before * A[i][0]); + } + cout << total << '\n'; +} +long long int n1, n2; +long long int a[100007]; +long long int b[100007]; +long long int k, m; +int main() { + cin >> n1 >> n2; + cin >> k >> m; + for (long long int i = 0; i <= n1 - 1; i++) { cin >> a[i]; } + for (long long int i = 0; i <= n2 - 1; i++) { cin >> b[i]; } + sort(a, a + n1); + sort(b, b + n2, greater()); + if (a[k - 1] < b[m - 1]) { + cout << "YES" + << "\n"; + } else { + cout << "NO" + << "\n"; + } + return 0; +} +const int maxn = 1e5 + 5; +int main() { + long long t, s, q, ans = 0; + cin >> t >> s >> q; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + long long n1, n2; + cin >> n1 >> n2; + if (n1 % 2 != 0) n1++; + if (n2 - n1 < 2) { + cout << "-1" << endl; + } else { + cout << n1 << " " << n1 + 1 << " " << n1 + 2 << endl; + } + return 0; +} +int freq[1005]; +int main() { + int hh, mm; + double h, d, c, n; + double cost1, cost2; + cin >> hh >> mm; + cin >> h >> d >> c >> n; + int time = (hh * 60) + mm; + int buns = 0; + int hunger = h; + while (hunger > 0) { + hunger -= n; + buns++; + } + cost1 = buns * c; + if (time < 1200) + hunger = h + ((1200 - time) * d); + else + hunger = h; + buns = 0; + while (hunger > 0) { + hunger -= n; + buns++; + } + c -= c * (20.0 / 100); + cost2 = c * buns; + cout << setprecision(5) << showpoint << fixed << min(cost2, cost1) << endl; +} +char s[5050]; +int main() { + cin >> s; + int ans = 0; + int len = strlen(s); + for (int i = 0; i < len; i++) { + int t = 0; + int cnt = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + t++; + else if (s[j] == ')') + t--; + else if (s[j] == '?') + cnt++, t--; + if (t == 0) + ans++; + else if (t < 0 && cnt > 0) + cnt--, t = t + 2; + else if (t < 0 && cnt == 0) + break; + else if (t > 0) + continue; + } + } + cout << ans << endl; +} +const int maxn = 1e5 + 10; +const int inf = 0x3f3f3f3f; +int main() { + string s; + cin >> s; + int val = 0; + for (int i = 0; i < s.size(); i++) { + int vis = 0; + int l = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == '(') + l++; + else if (s[j] == ')') + l--; + else + l--, vis++; + if (l == 0) + val++; + else if (l > 0) + continue; + else if (l < 0 && vis == 0) + break; + else if (l < 0 && vis > 0) + vis--, l += 2; + } + } + cout << val << endl; + return 0; +} +int main() { + int A, B, C, N; + cin >> A >> B >> C >> N; + if ((A + B - C <= N - 1) && (A < N && B < N && C <= A && C <= B)) + cout << N - (A + B - C) << endl; + else + cout << -1 << endl; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << "1" << endl; +} +void init(){}; +int a[1000]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long sum = 0; + for (int i = 1; i <= n; i++) sum += 4 * (i - 1) * a[i]; + cout << sum << endl; + return 0; +} +int main() { + int a, b, hari = 1, hitung = 0; + cin >> a >> b; + while (a != 0) { + a--; + hitung++; + if (hari % b == 0) { a++; } + hari++; + } + cout << hari - 1 << endl; +} +int main() { + int r, l, a; + cin >> l >> r >> a; + int half = min(r, l); + if (l <= r) { + if (r - l <= a) { + half = r; + a -= (r - l); + } else { + half += a; + a = 0; + } + } else { + if (l - r <= a) { + half = l; + a -= (l - r); + } else { + half += a; + a = 0; + } + } + if (a != 0) { + if (a % 2) + half += ((a - 1) / 2); + else + half += (a / 2); + } + cout << half * 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + int sol = 0; + for (int i = 1; i < n - 1; i++) { + if (((arr[i] - arr[i - 1]) * (arr[i] - arr[i + 1])) > 0) sol++; + } + cout << sol << endl; + return 0; +} +int main() { + string s; + cin >> s; + long long k = s.length(); + long long l = 26 * (k + 1); + l = l - k; + cout << l << endl; + return 0; +} +int main() { + int n, i, j, k, on = 0, to = 0, te = 0, ans = 0; + cin >> n; + int one[n]; + int two[n]; + int three[n]; + for (i = 0; i < n; i++) { + cin >> k; + if (k == 1) { + one[on] = i + 1; + on++; + } else if (k == 2) { + two[to] = i + 1; + to++; + } else { + three[te] = i + 1; + te++; + } + } + if (on <= to && on <= te) { + ans = on; + } else if (to <= on && to <= te) { + ans = to; + } else if (te <= on && te <= to) { + ans = te; + } + cout << ans << "\n"; + for (i = 0; i < ans; i++) { cout << one[i] << " " << two[i] << " " << three[i] << "\n"; } +} +int n, m; +int k; +bool debug = false; +set ss; +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + do { + vector tmp; + for (int i = 0; i < 6; i += 2) { + string a = s.substr(i, 2); + sort(a.begin(), a.end()); + tmp.push_back(a); + } + sort(tmp.begin(), tmp.end()); + string b = tmp[0] + tmp[1] + tmp[2]; + ss.insert(b); + if (tmp[0] != tmp[1] && tmp[1] != tmp[2] && tmp[2] != tmp[0]) { + if (b[0] != b[1] && b[2] != b[3]) swap(b[4], b[5]); + ss.insert(b); + } + } while (next_permutation(s.begin(), s.end())); + cout << ss.size() << endl; + return 0; +} +const int M = 100 + 5; +int main() { + long long int k, l; + cin >> k >> l; + int num = 0; + while (l != 1) { + if (l % k != 0) { + break; + } else { + l = l / k; + num++; + } + } + if (l == 1) { + cout << "YES" << endl; + cout << num - 1 << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, x[105]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> x[i]; } + sort(x, x + n); + int Max = x[n - 1], sum = 0; + for (int i = 0; i < n; i++) { sum += Max - x[i]; } + cout << sum << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + string x; + x += s[0]; + string y; + for (int i = 1; i < n; i++) { y += s[i]; } + if (x.size() != y.size() || x[0] < y[0]) { + cout << "YES" << endl; + cout << 2 << endl; + cout << x << ' ' << y << endl; + } else + cout << "NO" << endl; + } +} +int main() { + vector a, b; + bool ya = false; + int n, k; + cin >> n >> k; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a.push_back(x); + } + for (int i = 0; i < k; i++) { + int x; + cin >> x; + b.push_back(x); + } + sort(b.begin(), b.end()); + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + a[i] = b.back(); + b.pop_back(); + } + } + for (int i = 1; i < n; i++) { + if (a[i - 1] > a[i]) ya = true; + } + (ya) ? cout << "Yes" << endl : cout << "No" << endl; + return 0; +} +int main() { + int t; + cin >> t; + int sum = 0; + int input[t]; + for (int i = 0; i < t; i++) { + cin >> input[i]; + sum += input[i]; + } + sort(input, input + t); + int temp_sum = 0, coins = 0; + for (int i = t - 1; i >= 0; i--) { + temp_sum += input[i]; + if (temp_sum > sum / 2) { + coins++; + break; + } + coins++; + } + cout << coins << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a != b) { + cout << max(a.length(), b.length()) << endl; + } else + cout << "-1\n"; +} +int a[100][100]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) a[i][j] = 1; + for (int i = 2; i <= n; i++) { + for (int j = 1; j <= n; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + } + cout << a[n][n] << endl; + return 0; +} +int n; +int main() { + cin >> n; + int suck; + int ans1 = 0, ans2 = 0; + for (int i = 1; i <= n; ++i) { + cin >> suck; + ans1 |= suck; + } + for (int i = 1; i <= n; ++i) { + cin >> suck; + ans2 |= suck; + } + cout << ans1 + ans2 << endl; +} +int x, h, m, cnt; +int main() { + cin >> x >> h >> m; + while (1) { + if (m % 10 == 7 || h % 10 == 7) { break; } + m -= x; + if (m < 0) m += 60, h--; + if (h < 0) h += 24; + cnt++; + } + cout << cnt << endl; +} +int main() { + int i, j, s = 0, l, one, two, k; + char a[200], fl; + cin >> a; + l = strlen(a); + fl = 'a'; + for (i = 0; i < l; i++) { + one = abs(a[i] - fl); + two = abs(abs(a[i] - fl) - 26); + if (one < two) + s += one; + else + s += two; + fl = a[i]; + } + cout << s << endl; + return 0; +} +const long long inf = (long long)1e9; +const long long mod = inf + 7; +const double pi = acos(-1.0); +long long m, n; +long long mn = inf; +long long a[300300]; +int main() { + cin >> m; + for (long long i = 1; i <= m; ++i) { + long long x; + cin >> x; + mn = min(mn, x); + } + cin >> n; + for (long long i = 1; i <= n; ++i) cin >> a[i]; + sort(a + 1, a + n + 1); + long long lst = n; + long long sum = 0; + while (1) { + if (lst - 1 + 1 < mn) { + for (long long i = 1; i <= lst; ++i) sum += a[i]; + break; + } + long long ind = lst + 1 - mn; + for (long long i = lst; i >= ind; --i) sum += a[i]; + if (ind - 2 >= 1) + ind -= 3; + else if (ind - 1 >= 1) + ind -= 2; + else + ind--; + if (ind == 0) break; + lst = ind; + } + cout << sum << "\n"; + return 0; +} +int main() { + int l = 81, h = 0; + long long int i, n; + cin >> n; + if (n <= 81) { l = n; } + long long int s = 0, a[l], k; + for (i = 1; i < l; i++) { + k = n - i; + s = 0; + while (k > 0) { + s = s + (k % 10); + k = k / 10; + } + if (s == i) { + h++; + a[h] = n - i; + } + } + sort(a + 1, a + h + 1); + cout << h << endl; + for (i = 1; i < h + 1; i++) { cout << a[i] << endl; } + return 0; +} +int main() { + int k, r; + while (cin >> k >> r) { + int ans = INT_MAX; + if (r == k) ans = 1; + if (k % 10 == 0) ans = 1; + if (10 % k == 0) ans = min(ans, 10 / k); + long long sum = k - r, i; + if (sum % 10 == 0) + ans = 1; + else { + long long lcm = (k * 10) / __gcd(10, k); + int i, cnt = 1; + for (i = k; i <= lcm; i += k, cnt++) { + if ((i - r) % 10 == 0) { ans = min(ans, cnt); } + if (i % 10 == 0) ans = min(ans, cnt); + } + ans = min(ans, cnt); + } + cout << ans << endl; + } + return 0; +} +const int N = 1e6 + 5; +const double PI = 3.141592; +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, m, k; + int a[1005]; + while (cin >> n >> m >> k) { + memset(a, 0, sizeof(a)); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i] - 1; + } + sort(a, a + n, cmp); + if (m <= k) { + cout << "0" << endl; + break; + } + if (m > sum + k) { + cout << "-1" << endl; + break; + } + sum = 0; + int t = 0; + while (m > 0) { + if (k <= 0) { + m -= a[t] - 1; + t++; + } + if (k > 0) { + k--; + m -= a[t]; + t++; + } + if (m <= k) break; + } + cout << t << endl; + } + return 0; +} +int n; +int a[111]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + int mx = a[1]; + for (int i = 1; i <= n; ++i) { + for (int j = i; j <= n; ++j) { + int x = 0; + for (int k = i; k <= j; ++k) x ^= a[k]; + mx = max(mx, x); + } + } + cout << mx << "\n"; + return 0; +} +int main() { + int n, d; + cin >> n >> d; + string s; + string t; + for (int i = 0; i < n; i++) t += '1'; + int mx = 0, ans = 0; + for (int i = 0; i < d; i++) { + cin >> s; + if (s == t) + ans = 0; + else + ans++; + mx = max(mx, ans); + } + cout << mx << endl; +} +long long cil(long long x, long long y) { + if (x % y == 0) + return x / y; + else + return x / y + 1; +} +int main() { + long long n, i, j = 0; + cin >> n; + i = n; + while (n % 3 == 0 && n > 0) { + j++; + n /= 3; + } + long long l = pow(3, j + 1); + cout << cil(i, l) << endl; +} +int main() { + long long x = 1, y = 1, z = 1, t, k, m, a, b, c, n; + cin >> a >> b >> c >> n; + if (a + b + c - 3 < n) + cout << a * b * c << endl; + else { + for (int i = 0; i < n; i++) { + if (x < a && (x <= y || y == b) && (x <= z || z == c)) + x++; + else if (y < b && (y <= x || x == a) && (y <= z || z == c)) + y++; + else + z++; + } + cout << x * y * z << endl; + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + string s3 = ""; + for (int i = 0; i < s1.length(); i++) { + if (s1[i] == s2[i]) + s3 += '0'; + else + s3 += '1'; + } + cout << s3 << endl; + return 0; +} +const int MAX = 2e5 + 5; +const int INF = 0x3f3f3f3f; +map mp; +map::iterator it; +int main() { + int i, j, k, n, m, a, b, c; + cin >> a >> b >> c >> n; + if (a + b - c >= n || c > a || c > b) { + puts("-1"); + return 0; + } + cout << n - (a + b - c) << endl; + return 0; +} +int table[15][15]; +int main() { + int n; + while (cin >> n) { + memset(table, 0, sizeof(table)); + for (int i = 0; i < n; i++) { table[0][i] = 1; } + for (int i = 0; i < n; i++) { table[i][0] = 1; } + int min = -1; + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { + table[i][j] = table[i - 1][j] + table[i][j - 1]; + if (table[i][j] > min) { min = table[i][j]; } + } + } + if (n == 1) { + cout << 1 << endl; + } else + cout << min << endl; + } +} +int main() { + int n; + cin >> n; + int array[n]; + for (int i = 0; i < n; ++i) { cin >> array[i]; } + sort(array, array + n); + int mini = array[0]; + for (int i = 0; i < n; ++i) { mini = __gcd(mini, array[i]); } + cout << mini * n << endl; + return 0; +} +int main() { + int n, a[150005] = {0}; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + if (n == 1) { + if (a[0] != 0 && a[0] != 15) { + cout << -1 << endl; + break; + } else if (a[0] == 0) { + cout << "UP" << endl; + break; + } else if (a[0] == 15) { + cout << "DOWN" << endl; + break; + } + } + if (a[n - 2] > a[n - 1] && a[n - 1] != 0) + cout << "DOWN" << endl; + else if (a[n - 2] > a[n - 1] && a[n - 1] == 0) + cout << "UP" << endl; + else if (a[n - 2] < a[n - 1] && a[n - 1] != 15) + cout << "UP" << endl; + else if (a[n - 2] < a[n - 1] && a[n - 1] == 15) + cout << "DOWN" << endl; + else + cout << -1 << endl; + } + return 0; +} +long long C[2005][2005]; +long long fact[2005]; +long long mod = 1000000000 + 7; +long long win[1000004]; +void getDivisors(long long n, vector &vt) { + for (long long i = 1; i <= sqrt(n); i++) { + if (n % i == 0) { + if (n / i == i) + vt.push_back(i); + else { + if (n % i == 0) vt.push_back(i); + if (n % (n / i) == 0) vt.push_back(n / i); + } + } + } +} +void nCrModp() { + for (long long i = 0; i < 2002; i++) { + C[i][0] = 1; + for (long long j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; + } +} +int main() { + long long n; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + long long m = s1.length(); + long long k = s2.length(); + long long r1 = 0, r2 = 0; + for (long long i = 0; i < m * k; i++) { + if (s1[i % m] == 'R' && s2[i % k] == 'S') + r1++; + else if (s1[i % m] == 'S' && s2[i % k] == 'R') + r2++; + if (s1[i % m] == 'S' && s2[i % k] == 'P') + r1++; + else if (s1[i % m] == 'P' && s2[i % k] == 'S') + r2++; + if (s1[i % m] == 'P' && s2[i % k] == 'R') + r1++; + else if (s1[i % m] == 'R' && s2[i % k] == 'P') + r2++; + } + long long ans1 = 0, ans2 = 0; + ans1 += r1 * (n / (m * k)); + ans2 += r2 * (n / (m * k)); + n %= (m * k); + for (long long i = 0; i < n; i++) { + if (s1[i % m] == 'R' && s2[i % k] == 'S') + ans1++; + else if (s1[i % m] == 'S' && s2[i % k] == 'R') + ans2++; + if (s1[i % m] == 'S' && s2[i % k] == 'P') + ans1++; + else if (s1[i % m] == 'P' && s2[i % k] == 'S') + ans2++; + if (s1[i % m] == 'P' && s2[i % k] == 'R') + ans1++; + else if (s1[i % m] == 'R' && s2[i % k] == 'P') + ans2++; + } + cout << ans2 << " " << ans1 << endl; +} +int main() { + int t; + cin >> t; + long long a, b, k; + while (t--) { + cin >> a >> b >> k; + cout << ((k + 1) / 2 * a) - (k / 2 * b) << "\n"; + } + return 0; +} +int main() { + int n, i, j, k; + while (cin >> n) { + int last = 1; + for (i = 1; i <= n; i++) { + if (n % i == 0) { + if (n / i >= i) { + last = i; + } else + break; + } + } + cout << last << " " << n / last << endl; + } + return 0; +} +int main() { + long long n, inches, feets; + cin >> n; + inches = n / 3; + if (n % 3 == 2) inches += 1; + feets = inches / 12; + inches -= feets * 12; + cout << feets << " " << inches << endl; + return 0; +} +int main() { + char A[30] = {0}; + int len, sum, i, k, j = 1; + cin >> A; + len = strlen(A); + sum = 25 * (len + 1); + for (i = 0; i < len - 1; i++) + if (A[i] != A[i + 1]) { + j++; + sum--; + } + sum += j; + cout << sum << endl; + return 0; +} +int main() { + int n, m, mx, mn, temp, mnm = 100000, mxm = 100000 * -1; + cin >> n >> m >> mn >> mx; + for (int i = 1; i <= m; ++i) { + cin >> temp; + mnm = min(mnm, temp); + mxm = max(mxm, temp); + } + if (mxm == mx && mnm == mn) + cout << "Correct\n"; + else if (mxm < mx && mnm > mn && n - m >= 2) + cout << "Correct\n"; + else if (mxm < mx && mnm == mn && n - m >= 1) + cout << "Correct\n"; + else if (mxm == mx && mnm > mn && n - m >= 1) + cout << "Correct\n"; + else + cout << "Incorrect\n"; + return 0; +} +int main() { + int n; + string s; + set record; + cin >> n; + for (int i = 0; i < n; i++) { + int letter[26] = {0}; + cin >> s; + string str = ""; + for (int j = 0; j < s.size(); j++) letter[s[j] - 97]++; + for (int j = 0; j < 26; j++) + if (letter[j] > 0) str += 'a' + j; + record.insert(str); + } + cout << record.size() << endl; + return 0; +} +int main() { + long long int a, b, c, d, e, f, r[1000], g; + string s; + char u, v; + while (cin >> a >> b) { + g = 0; + for (c = 1; c <= a; c++) { + cin >> d; + e = 0; + while (d != 0) { + f = d % 10; + if (f == 4 || f == 7) { e++; } + d /= 10; + } + if (e <= b) { g++; } + } + cout << g << endl; + } + return 0; +} +int main() { + int r, g, b; + cin >> r >> g >> b; + int time = 30; + int i = 0; + while (r > 0 || g > 0 || b > 0) { + if (i % 3 == 0) { + r -= 2; + } else if (i % 3 == 1) { + g -= 2; + } else { + b -= 2; + } + time++; + i++; + } + cout << time - 1 << endl; +} +int main() { + float a = 0, s = 0, c = 0, d = 0, e = 0, i, j, k, l, f; + cin >> k >> l >> f; + s = (l + f) / 2; + s = k / s; + s = s / 2; + a = l * s; + cout << a << endl; + return 0; +} +int seen[101]; +int main() { + int N, K, answer = 0; + int A[101]; + cin >> N >> K; + for (int i = 0; i < N; i++) cin >> A[i]; + if (N == 1) { + if (A[0] <= K) + cout << 1 << "\n"; + else + cout << 0 << "\n"; + return 0; + } + for (int i = 0; i < N; i++) { + if (A[i] <= K && seen[i] == 0) { + answer++; + seen[i] = 1; + } else + break; + } + for (int i = N - 1; i >= 0; i--) { + if (A[i] <= K && seen[i] == 0) { + answer++; + seen[i] = 1; + } else + break; + } + cout << answer << "\n"; + return 0; +} +int main() { + int n, count; + char a; + while (cin >> n) { + count = 0; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == '1') count++; + } + cout << fabs(n - count - count) << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long answer = 1; + if (n < 27) + for (int i = 0; i < n; i++) { answer = (answer * 2); } + else { + answer = m; + cout << answer << endl; + return 0; + } + cout << m % answer << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n]; + int cntr = 0, ans = 0; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + cntr -= a[i]; + cntr += b[i]; + ans = max(ans, cntr); + } + cout << ans << endl; +} +long long solve(int a, int b) { + if (a == 0 || b == 0) return 0; + if (a == b) return 1; + if (a > b) swap(a, b); + long long temp = b - a; + long long cnt = ceil(double(temp) / double(a)); + return 1LL * (cnt + solve(a, b - cnt * a)); +} +int main() { + int n; + cin >> n; + while (n--) { + int a, b; + cin >> a >> b; + cout << solve(a, b) << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + int ta, fa, tb, fb; + while (k--) { + cin >> ta >> fa >> tb >> fb; + int ans = 0; + if (ta != tb) { + ans += abs(ta - tb); + if (fa > b) { + ans += abs(fa - b); + ans += abs(fb - b); + } else if (fa < a) { + ans += abs(fa - a); + ans += abs(fb - a); + } else { + ans += abs(fa - fb); + } + } else { + ans += abs(fa - fb); + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, arr[1000]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + if (n == 1) { + if (arr[0] != 15) { + if (arr[0] == 0) { + cout << "UP" << endl; + } else + cout << "-1" << endl; + } else { + cout << "DOWN" << endl; + } + } else if (arr[n - 1] > arr[n - 2] && arr[n - 1] < 15) { + cout << "UP" << endl; + } else if (arr[n - 1] > arr[n - 2] && arr[n - 1] == 15) { + cout << "DOWN" << endl; + } else if (arr[n - 1] < arr[n - 2] && arr[n - 1] != 0) { + cout << "DOWN" << endl; + } else + cout << "UP" << endl; +} +map m1; +map::iterator itr; +int main() { + long long int n; + cin >> n; + long long int k = sqrt(2 * n); + if (k * (k + 1) == 2 * n) + cout << k; + else { + while ((k * (k + 1) > 2 * n)) k--; + long long int idx = k * (k + 1) / 2; + idx = n - idx; + cout << idx; + } + cout << endl; + return 0; +} +int main() { + int s = 0, n, k; + cin >> n >> k; + if ((8 * n) % k == 0) { + s = s + 8 * n / k; + } else { + s = s + 8 * n / k + 1; + } + if ((2 * n) % k == 0) { + s = s + 2 * n / k; + } else { + s = s + 2 * n / k + 1; + } + if ((5 * n) % k == 0) { + s = s + 5 * n / k; + } else { + s = s + 5 * n / k + 1; + } + cout << s << endl; + return 0; +} +int main() { + long long a, b, c = 1, d; + cin >> a >> b; + d = min(a, b); + for (int i = 1; i <= d; i++) c *= i; + cout << c << endl; + return 0; +} +long long n; +int main() { + cin >> n; + for (long long i = 1; i <= n / 2; ++i) { + for (long long j = 1; j <= n / 2 - i + 1; ++j) cout << '*'; + for (long long j = 1; j <= i * 2 - 1; ++j) cout << 'D'; + for (long long j = 1; j <= n / 2 - i + 1; ++j) cout << '*'; + cout << endl; + } + for (long long i = 1; i <= n; ++i) cout << 'D'; + cout << endl; + for (long long i = 1; i <= n / 2; ++i) { + for (long long j = 1; j <= i; ++j) cout << '*'; + for (long long j = 1; j <= n - 2 * i; ++j) cout << 'D'; + for (long long j = 1; j <= i; ++j) cout << '*'; + cout << endl; + } + return 0; +} +int a[101]; +int b[101][101]; +int cost = 10000000; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + u--; + v--; + b[u][v] = 1; + b[v][u] = 1; + } + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + for (int k = j + 1; k < n; k++) { + if (b[i][j] && b[i][k] && b[j][k]) { + int total = a[i] + a[j] + a[k]; + cost = min(cost, total); + } + } + } + } + if (cost == 10000000) + cout << -1 << endl; + else + cout << cost << endl; + return 0; +} +const int MOD = 23333; +const int maxn = 2e5 + 10; +int main() { + int n, s; + cin >> n >> s; + int a[110]; + int hh, mm; + int tt = 0; + for (int i = 0; i < n; i++) cin >> hh >> mm, a[i] = hh * 60 + mm; + int flag = 1; + if (s + 1 <= a[0] && flag) tt = 0, flag = 0; + for (int i = 1; i < n; i++) { + if (s + 1 <= (a[i] - a[i - 1] - s - 1) && flag) tt = a[i - 1] + s + 1, flag = 0; + } + if (flag) tt = a[n - 1] + s + 1; + int h = tt / 60; + int m = tt - tt / 60 * 60; + cout << h << " " << m << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int ans1, ans2; + ans1 = min(a, b); + ans2 = max(a, b); + ans2 = ans2 - ans1; + ans2 = ans2 / 2; + cout << ans1 << " " << ans2 << endl; + return 0; +} +int main() { + int m, d, k, sum; + cin >> m >> d; + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { + sum = 31 - 8 + d; + if (sum % 7 == 0) + k = sum / 7 + 1; + else + k = sum / 7 + 2; + } else if (m == 2) { + sum = 28 - 8 + d; + if (sum % 7 == 0) + k = sum / 7 + 1; + else + k = sum / 7 + 2; + } else { + sum = 30 - 8 + d; + if (sum % 7 == 0) + k = sum / 7 + 1; + else + k = sum / 7 + 2; + } + cout << k << endl; + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int nu; + if (n % s == 0) + nu = n / s; + else + nu = n / s + 1; + int sum = nu * k; + if (sum % p == 0) + cout << sum / p << endl; + else + cout << sum / p + 1 << endl; +} +int main() { + int n, d; + cin >> n >> d; + string all_present(n, '1'); + int count = 0, cdays = 0; + while (d--) { + string day; + cin >> day; + if (day == all_present) + cdays = max(cdays, count), count = 0; + else + count++; + } + cdays = max(cdays, count); + cout << cdays << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[105][105]; + int b[105] = {0}; + for (int j = 0; j < n; j++) { + for (int k = 0; k < m; k++) { cin >> a[j][k]; } + } + int ans = 0; + for (int k = 0; k < m; k++) { + char maxn = '0'; + for (int j = 0; j < n; j++) { + if (a[j][k] >= maxn) { maxn = a[j][k]; } + } + for (int j = 0; j < n; j++) { + if (a[j][k] == maxn) { + if (b[j] == 0) { + ans++; + b[j] = 1; + } + } + } + } + cout << ans << endl; + return 0; +} +long double a[2 * 2005], dp[2 * 2005][2005]; +int n; +int input() { + cin >> n; + for (int i = 1; i <= 2 * n; i++) cin >> a[i]; + return 0; +} +int init() { + for (int i = 0; i <= 2 * n; i++) + for (int j = 0; j <= n; j++) dp[i][j] = INT_MAX; + dp[0][0] = 0; + return 0; +} +int process() { + for (int i = 1; i <= 2 * n; i++) { + for (int cei = 0; cei <= min(i, n); cei++) { + long double val1 = INT_MAX, val2 = INT_MAX; + if (cei > 0) val1 = dp[i - 1][cei - 1] + ceil(a[i]) - a[i]; + if ((i - cei) <= n) val2 = dp[i - 1][cei] + floor(a[i]) - a[i]; + dp[i][cei] = val1; + if (fabs(val2) < fabs(val1)) dp[i][cei] = val2; + } + } + return 0; +} +int output() { + cout << fixed << setprecision(3) << fabs(dp[2 * n][n]) << endl; + return 0; +} +void in() { + for (int i = 0; i <= 2 * n; i++) { + for (int j = 0; j <= n; j++) { + if (dp[i][j] == INT_MAX) + cout << 999999 << " "; + else if (dp[i][j] >= 0) + cout << " " << dp[i][j] << " "; + else + cout << dp[i][j] << " "; + } + cout << endl; + } +} +int main() { + input(); + init(); + process(); + output(); +} +int main() { + int n, m, x, ans = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> x; + ans += (x / m); + if (x % m) { ans++; } + } + cout << (ans / 2) + (ans % 2) << "\n"; + return 0; +} +const int maxn = 1e2 + 10; +string s; +int n; +int main() { + cin >> n >> s; + int sum1 = 0, sum2 = 0; + for (int i = 0; i < n / 2; i++) + if (s[i] != '4' && s[i] != '7') + return cout << "NO" << endl, 0; + else + sum1 += s[i] - '0'; + for (int i = n / 2; i < n; i++) + if (s[i] != '4' && s[i] != '7') + return cout << "NO" << endl, 0; + else + sum2 += s[i] - '0'; + if (sum1 == sum2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int t = 0; + int ans = 0; + while (ans < (a - b) * c) { + t += 1; + ans += b; + } + cout << t << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int n, k; + int ans, asn; + cin >> n >> k; + ans = 0; + asn = n * 2; + ans += (asn + k - 1) / k; + asn = n * 5; + ans += (asn + k - 1) / k; + asn = n * 8; + ans += (asn + k - 1) / k; + cout << ans << endl; + return 0; +} +const int maxn = 1010; +const int inf = 0x3f3f3f3f; +int a[maxn]; +inline int min(int a, int b) { + return a > b ? b : a; +} +int main() { + int n, m, x, i; + while (cin >> n >> m) { + int ans = inf; + memset(a, 0, sizeof(a)); + for (i = 0; i < m; i++) { + cin >> x; + a[x]++; + } + for (i = 1; i <= n; i++) { ans = min(ans, a[i]); } + cout << ans << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int l = s.size() + 1; + int m = (26 * l) - (l - 1); + cout << m << endl; + return 0; +} +int n, m, cnt, ans, sum, x, c, a; +vector v, v1; +set s; +map mp; +int main() { + cin >> n; + x = n / 2 + 1; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = 1; j < x - a; j++) cout << "*"; + for (int h = x - a; h <= x + a; h++) cout << "D"; + for (int k = x + a; k < n; k++) cout << "*"; + a++; + cout << endl; + } + a -= 2; + for (int i = n / 2 + 1; i < n; i++) { + for (int j = 1; j < x - a; j++) cout << "*"; + for (int h = x - a; h <= x + a; h++) cout << "D"; + for (int k = x + a; k < n; k++) cout << "*"; + a--; + cout << endl; + } +} +int main() { + string s; + cin >> s; + int k = s.size(); + cout << (k + 1) * (26 - k) + k * k << endl; + return 0; +} +const int MAXN = 100; +int a[MAXN]; +int b[MAXN]; +int c[MAXN * MAXN]; +bool cmp(int x, int y) { + return x > y; +} +int main() { + int n, m; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int j = 0; j < m; ++j) cin >> b[j]; + int cnt = 0; + for (int i = 0; i < n; ++i) + for (int j = 0; j < m; ++j) + if (b[j] % a[i] == 0) c[cnt++] = b[j] / a[i]; + sort(c, c + cnt, cmp); + int ans = 0; + for (int i = 0; i < cnt; i++) + if (c[i] == c[0]) ans++; + cout << ans << endl; + return 0; +} +void solve() { + long long int n, k; + cin >> n >> k; + long long int pre = n / k; + if (pre % 2 != 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long int t = 1; + while (t--) { solve(); } + return 0; +} +int main() { + int n, x, i, sum = 0, sum2 = 0; + cin >> n; + n = n / 2; + int a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = 1; i <= 2 * n; i += 2) sum += abs(i - a[(i - 1) / 2]); + for (i = 2; i <= 2 * n; i += 2) sum2 += abs(i - a[(i - 1) / 2]); + cout << min(sum, sum2) << endl; + return 0; +} +bool checkodd(int n) { + if (n % 2 == 0) + return false; + else + return true; +} +int main() { + int a[3][3], b[3][3]; + int i, j; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) { + cin >> a[i][j]; + b[i][j] = 1; + } + if (checkodd(a[0][0] + a[0][1] + a[1][0])) b[0][0] = 0; + if (checkodd(a[0][1] + a[0][0] + a[0][2] + a[1][1])) b[0][1] = 0; + if (checkodd(a[0][1] + a[0][2] + a[1][2])) b[0][2] = 0; + if (checkodd(a[1][0] + a[0][0] + a[2][0] + a[1][1])) b[1][0] = 0; + if (checkodd(a[1][0] + a[0][1] + a[1][2] + a[1][1] + a[2][1])) b[1][1] = 0; + if (checkodd(a[1][2] + a[0][2] + a[2][2] + a[1][1])) b[1][2] = 0; + if (checkodd(a[2][0] + a[1][0] + a[2][1])) b[2][0] = 0; + if (checkodd(a[2][0] + a[2][1] + a[2][2] + a[1][1])) b[2][1] = 0; + if (checkodd(a[2][1] + a[2][2] + a[1][2])) b[2][2] = 0; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { cout << b[i][j]; } + cout << "\n"; + } + return 0; +} +int main() { + int w, h; + string output; + cin >> w >> h; + int u_1, d_1, u_2, d_2; + cin >> u_1 >> d_1 >> u_2 >> d_2; + for (int i = h; i > 0; i--) { + w += i; + if (i == d_1) { + w -= u_1; + } else if (i == d_2) { + w -= u_2; + } + if (w < 0) { w = 0; } + } + cout << w << endl; +} +const int maxn = 1e+5; +int main() { + int a[maxn]; + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 2; i <= n; i++) { + while (n % i == 0) { + n /= i; + a[ans++] = i; + } + } + if (ans < k) { + cout << "-1" << endl; + } else { + for (int i = 0; i < k - 1; i++) { cout << a[i] << " "; } + int sum = 1; + for (int i = k - 1; i < ans; i++) { sum *= a[i]; } + cout << sum << endl; + } + return 0; +} +int main() { + long long n, c, t, sum = 0; + cin >> n; + cin >> c; + cin >> t; + sum++; + int a = t; + for (int i = 1; i < n; i++) { + cin >> t; + if (t - a <= c) + sum++; + else + sum = 1; + a = t; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int p[n], q[n]; + for (int i = 0; i < n; i++) { cin >> p[i] >> q[i]; } + int count = 0; + for (int i = 0; i < n; i++) { + if (q[i] - p[i] >= 2) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int a = 0, b = 0, c = 0; + string s; + getline(cin, s); + for (int i = 0; i < s.length(); i++) { + if (isalpha(s[i]) && islower(s[i])) + a++; + else if (isalpha(s[i]) && isupper(s[i])) + b++; + else if (isdigit(s[i])) + c++; + else + continue; + } + if ((s.length() >= 5) && (a >= 1) && (b >= 1) && (c >= 1)) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +int main() { + int n, m[100], c[100], i, a = 0, b = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> m[i] >> c[i]; + if (m[i] > c[i]) { + a++; + } else if (m[i] < c[i]) { + b++; + } + } + if (a > b) { + cout << "Mishka" << endl; + } else if (b > a) { + cout << "Chris" << endl; + } else { + cout << "Friendship is magic!^^" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int number(0); + vector h(n), a(n); + for (int i = 0; i < n; ++i) { + cin >> h[i] >> a[i]; + for (int j = 0; j < i; ++j) { + if (h[i] == a[j]) { number += 1; } + if (a[i] == h[j]) { number += 1; } + } + } + cout << number << endl; + return 0; +} +int main() { + int n, sum = 0, mc = 0, summ = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + int a; + cin >> a; + sum += a; + if (a < 0) { + sum -= a; + mc++; + summ += a; + } + } + if (mc == 0) + cout << sum << endl; + else { + cout << sum - summ << endl; + } + return 0; +} +int main() { + int r; + while (cin >> r) { + int sum = 0; + int a[1001] = {0}; + for (int i = 0; i < r; i++) cin >> a[i]; + for (int i = 1; i < r - 1; i++) { + if (a[i] < a[i - 1]) + if (a[i] < a[i + 1]) + sum++; + else + ; + else if (a[i] > a[i - 1]) + if (a[i] > a[i + 1]) sum++; + } + cout << sum << endl; + } +} +int c[1005]; +int a[1005]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; ++i) cin >> c[i]; + for (int i = 0; i < m; ++i) cin >> a[i]; + int ans = 0; + int i = 0; + for (int j = 0; j < n; ++j) { + if (c[j] <= a[i]) { + ++ans; + ++i; + } + } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + while (getline(cin, a)) { + getline(cin, b); + for (int i = 0; i < a.size(); i++) { + a[i] = toupper(a[i]); + b[i] = toupper(b[i]); + } + cout << (a < b ? -1 : (a == b ? 0 : 1)) << endl; + } +} +int main() { + int n; + cin >> n; + if (n & 1) + cout << 1 << endl; + else + cout << 0 << endl; + return 0; +} +int x, res; +map t; +string s, r; +int main() { + cin >> s; + sort(s.begin(), s.end()); + do { + if (!t[s]) { + res++; + r = s[0]; + r += s[1]; + r += s[2]; + r += s[3]; + r += s[4]; + r += s[5]; + t[r] = true; + r = s[0]; + r += s[2]; + r += s[3]; + r += s[4]; + r += s[1]; + r += s[5]; + t[r] = true; + r = s[0]; + r += s[3]; + r += s[4]; + r += s[1]; + r += s[2]; + r += s[5]; + t[r] = true; + r = s[0]; + r += s[4]; + r += s[1]; + r += s[2]; + r += s[3]; + r += s[5]; + t[r] = true; + r = s[5]; + r += s[4]; + r += s[3]; + r += s[2]; + r += s[1]; + r += s[0]; + t[r] = true; + r = s[5]; + r += s[1]; + r += s[4]; + r += s[3]; + r += s[2]; + r += s[0]; + t[r] = true; + r = s[5]; + r += s[2]; + r += s[1]; + r += s[4]; + r += s[3]; + r += s[0]; + t[r] = true; + r = s[5]; + r += s[3]; + r += s[2]; + r += s[1]; + r += s[4]; + r += s[0]; + t[r] = true; + r = s[1]; + r += s[5]; + r += s[2]; + r += s[0]; + r += s[4]; + r += s[3]; + t[r] = true; + r = s[1]; + r += s[2]; + r += s[0]; + r += s[4]; + r += s[5]; + r += s[3]; + t[r] = true; + r = s[1]; + r += s[0]; + r += s[4]; + r += s[5]; + r += s[2]; + r += s[3]; + t[r] = true; + r = s[1]; + r += s[4]; + r += s[5]; + r += s[2]; + r += s[0]; + r += s[3]; + t[r] = true; + r = s[3]; + r += s[4]; + r += s[0]; + r += s[2]; + r += s[5]; + r += s[1]; + t[r] = true; + r = s[3]; + r += s[5]; + r += s[4]; + r += s[0]; + r += s[2]; + r += s[1]; + t[r] = true; + r = s[3]; + r += s[2]; + r += s[5]; + r += s[4]; + r += s[0]; + r += s[1]; + t[r] = true; + r = s[3]; + r += s[0]; + r += s[2]; + r += s[5]; + r += s[4]; + r += s[1]; + t[r] = true; + r = s[2]; + r += s[3]; + r += s[0]; + r += s[1]; + r += s[5]; + r += s[4]; + t[r] = true; + r = s[2]; + r += s[5]; + r += s[3]; + r += s[0]; + r += s[1]; + r += s[4]; + t[r] = true; + r = s[2]; + r += s[1]; + r += s[5]; + r += s[3]; + r += s[0]; + r += s[4]; + t[r] = true; + r = s[2]; + r += s[0]; + r += s[1]; + r += s[5]; + r += s[3]; + r += s[4]; + t[r] = true; + r = s[4]; + r += s[5]; + r += s[1]; + r += s[0]; + r += s[3]; + r += s[2]; + t[r] = true; + r = s[4]; + r += s[3]; + r += s[5]; + r += s[1]; + r += s[0]; + r += s[2]; + t[r] = true; + r = s[4]; + r += s[0]; + r += s[3]; + r += s[5]; + r += s[1]; + r += s[2]; + t[r] = true; + r = s[4]; + r += s[1]; + r += s[0]; + r += s[3]; + r += s[5]; + r += s[2]; + t[r] = true; + } + } while (next_permutation(s.begin(), s.end())); + cout << res << endl; + return 0; +} +int main() { + int n; + int a = 0; + string s; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + if (s[0] == 'I') { + a += 20; + } else if (s[0] == 'D') { + a += 12; + } else if (s[0] == 'O') { + a += 8; + } else if (s[0] == 'C') { + a += 6; + } else if (s[0] == 'T') { + a += 4; + } + } + cout << a << "\n"; + return 0; +} +int main() { + long long n; + cin >> n; + cout << n / 2 + 1 << "\n"; +} +long long int a[10000000] = {0}; +long long int b[10000000] = {0}; +long long int c[10000000] = {0}; +int main() { + long long int i, k, j = 1, n, s, x, j1 = 0, j2; + cin >> n >> k; + s = sqrt(n); + for (i = 1; i <= s; i++) { + if (n % i == 0) { + a[j] = i; + j++; + if (i * i != n) { + b[j1] = n / i; + j1++; + } + } + } + for (i = j1 - 1, j2 = 0; i >= 0; i--, j2++) { c[j2] = b[i]; } + if (k < (j + j2)) { + if (k < j) + cout << a[k] << endl; + else { + cout << c[k - j] << endl; + } + } else + cout << -1 << endl; + return 0; +} +int n, p, a[3001]; +int main() { + memset(a, 0, sizeof(a)); + cin >> p >> n; + int k; + for (int i = 1; i <= n; i++) { + cin >> k; + a[k % p]++; + if (a[k % p] > 1) { + cout << i << endl; + return 0; + } + } + cout << "-1" << endl; + return 0; +} +int main() { + long long int n, count = 0; + cin >> n; + while (n > 0) { + if (n & 1) { + count++; + n = n >> 1; + } else { + n = n >> 1; + } + } + cout << count << endl; + return 0; +} +int main() { + long long int n, i, sum = 0, Min = 1000000000; + cin >> n; + long long int a[100000] = {0}; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + if (a[i] <= Min && a[i] % 2 != 0) Min = a[i]; + } + if (sum % 2 == 0) + cout << sum << endl; + else + cout << sum - Min << endl; + return 0; +} +int main() { + int a, b, c, i = 0, j = 0; + cin >> a >> b >> c; + for (i = 0; i <= (c / a); ++i) { + if ((c - a * i) % b == 0) { + j = 1; + break; + } + } + if (j == 1) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } +} +int main() { + int a[105]; + int n, k, num = 0, maxs = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[i] == 1) { num++; } + } + int num2 = n - num; + for (int i = 1; i <= n; i++) { + int x = num, y = num2; + for (int j = 1; j <= n; j++) { + if (abs(j - i) % k == 0) { + if (a[j] == 1) { + x--; + } else { + y--; + } + } + } + maxs = max(maxs, abs(x - y)); + } + cout << maxs << endl; + return 0; +} +const int maxn = 1e5 + 15; +const int maxm = 1e6 + 15; +const int inf = 0x3f3f3f3f; +int main() { + long long x, y, z, k; + cin >> x >> y >> z >> k; + if (k >= x + y + z - 3) + cout << x * y * z << endl; + else { + long long s = x + y + z - 3 - k; + priority_queue pq; + pq.push(x); + pq.push(y); + pq.push(z); + while (s) { + long long u = pq.top(); + pq.pop(); + u--; + s--; + pq.push(u); + } + x = pq.top(), pq.pop(); + y = pq.top(), pq.pop(); + z = pq.top(), pq.pop(); + cout << x * y * z << endl; + } + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int cnt = -1, ans[100] = {0}; + char p = 'W'; + for (int i = 0; i < n; ++i) { + char c = s[i]; + if (c == 'B') { + if (p == 'W') { ++cnt; } + ++ans[cnt]; + } + p = c; + } + cout << cnt + 1 << endl; + if (cnt + 1 > 0) { + bool first = true; + for (int i = 0; i <= cnt; ++i) { + if (first) + first = false; + else + cout << " "; + cout << ans[i]; + } + cout << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < 52; j++) { + char ch = s[i]; + if (j < 26) + s[i] = j + 'a'; + else + s[i] = j - 26 + 'A'; + int cnt = 0; + for (int k = 0; k < s.length() - 1; k++) { + if (s[k] == 'V' && s[k + 1] == 'K') { cnt++, k++; } + } + ans = max(ans, cnt); + s[i] = ch; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + int score = 0; + if (d > f) { + for (int i = d; i <= b; i++) { score += i; } + score += a; + if (score > c) { + score -= c; + } else { + score = 0; + } + for (int i = f; i < d; i++) { score += i; } + if (score > e) { + score -= e; + } else { + score = 0; + } + for (int i = 1; i < f; i++) { score += i; } + } else { + for (int i = f; i <= b; i++) { score += i; } + score += a; + if (score > e) { + score -= e; + } else { + score = 0; + } + for (int i = d; i < f; i++) { score += i; } + if (score > c) { + score -= c; + } else { + score = 0; + } + for (int i = 1; i < d; i++) { score += i; } + } + cout << score << endl; + return 0; +} +int main() { + int matrex; + for (int i = 1; i <= 5; i++) + for (int j = 1; j <= 5; j++) { + cin >> matrex; + if (matrex == 1) { + cout << abs(i - 3) + abs(j - 3) << endl; + break; + } + } + return 0; +} +const int INF = 0x3f3f3f3f; +int a[10005]; +int main() { + int n, m, z; + while (cin >> n >> m >> z) { + memset(a, 0, sizeof a); + int ans = 0; + for (int i = n; i <= z; i = i + n) { a[i] = 1; } + for (int i = m; i <= z; i += m) { + if (a[i] == 1) ans++; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + char g[200][200]; + g['P']['S'] = 0; + g['P']['R'] = 1; + g['P']['P'] = -1; + g['S']['S'] = -1; + g['S']['R'] = 0; + g['S']['P'] = 1; + g['R']['S'] = 1; + g['R']['P'] = 0; + g['R']['R'] = -1; + string a, b; + cin >> n >> a >> b; + if (a == b) return cout << 0 << " " << 0 << endl, 0; + int cnt1 = 0, cnt2 = 0; + int la = a.size(); + int lb = b.size(); + int pa = 0, pb = 0; + if (n / (la * lb)) { + for (int i = 0; i < min(la * lb, n); i++) { + if (g[a[pa]][b[pb]] == 1) { + cnt1++; + } else if (g[a[pa]][b[pb]] == 0) { + cnt2++; + } + pa = (pa + 1 == la ? 0 : pa + 1); + pb = (pb + 1 == lb ? 0 : pb + 1); + } + cnt1 *= max(1, n / (la * lb)); + cnt2 *= max(1, n / (la * lb)); + } + for (int i = 0; i < n % (la * lb); i++) { + if (g[a[pa]][b[pb]] == 1) { + cnt1++; + } else if (g[a[pa]][b[pb]] == 0) { + cnt2++; + } + pa = (pa + 1 == la ? 0 : pa + 1); + pb = (pb + 1 == lb ? 0 : pb + 1); + } + cout << cnt2 << " " << cnt1 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) <= 1 && (a > 0 || b > 0)) { + cout << "YES" << endl; + } else + cout << "NO" << endl; +} +int main() { + string c[8]; + while (cin >> c[0]) { + for (int i = 1; i < 8; ++i) cin >> c[i]; + int f = 1; + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) + if (c[i][j] == c[i][j + 1]) { + f = 0; + break; + } + } + if (f) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } + return 0; +} +const int maxn = 1e5 + 5; +int main() { + int n; + string s[105]; + cin >> n; + for (int i = 0; i < n; ++i) { + s[i] = " "; + cin >> s[i]; + } + int ans = 0; + for (int i = 0; i <= 26; ++i) { + for (int j = 0; j <= 26; ++j) { + char x = 'a' + i; + char y = 'a' + j; + int temp = 0; + for (int k = 0; k < n; ++k) { + int temp1 = 0; + int flag = 1; + for (int l = 0; l < s[k].size(); ++l) { + if (s[k][l] == x || s[k][l] == y) + temp1++; + else { + flag = 0; + break; + } + } + if (flag) temp += temp1; + } + ans = max(ans, temp); + } + } + cout << ans << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + string s; + cin >> s; + if (s.size() <= 10) { + cout << s << endl; + continue; + } + cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl; + } +} +vector vec; +int Main() { + int n, s; + cin >> n >> s; + for (int i = 0; i < n; ++i) { + int h, m; + cin >> h >> m; + vec.push_back(h * 60 + m); + } + int tm = vec[n - 1] + 1 + s; + if (vec[0] >= s + 1) { + tm = 0; + } else { + for (int i = 0; i < n - 1; ++i) { + if (vec[i] + 2 + 2 * s <= vec[i + 1]) { + tm = vec[i] + 1 + s; + break; + } + } + } + cout << tm / 60 << " " << tm % 60 << endl; + return 0; +} +int main() { + Main(); + return 0; +} +char *removeDuplicate(char str[], int n) { + int index = 0; + for (int i = 0; i < n; i++) { + int j; + for (j = 0; j < i; j++) + if (str[i] == str[j]) break; + if (j == i) str[index++] = str[i]; + } + return str; +} +int main() { + long long n, i, j, k, x, t, f; + char str[10000]; + string s[10000], s2; + cin >> n; + x = 0; + for (i = 0; i < n; i++) { + cin >> str; + int p = sizeof(str) / sizeof(str[0]); + removeDuplicate(str, p); + int d = sizeof(str) / sizeof(str[0]); + s[i] = str; + sort(s[i].begin(), s[i].end()); + } + t = 0; + long long a[10000]; + for (i = 0; i < n; i++) { + s2 = s[i]; + for (j = 0; j < n; j++) { + if (s2 == s[j]) { a[j] = i; } + } + } + for (i = 0; i < n; i++) { + f = 0; + f = count(a, a + n, i); + if (f) { x++; } + } + cout << x << endl; +} +bool take[200000]; +int pp, tt, x[200000]; +string p, t; +bool check(int mid) { + for (int i = 0; i < tt; i++) take[i] = false; + for (int i = 0; i <= mid; i++) take[x[i]] = true; + int l = 0, r = 0; + while (l < tt) { + if (take[l]) + l++; + else { + if (t[l] == p[r]) { + l++; + r++; + } else { + l++; + } + } + if (r == pp) return true; + } + return false; +} +int main() { + cin >> t; + cin >> p; + pp = p.size(); + tt = t.size(); + for (int i = 0; i < tt; i++) { + cin >> x[i]; + x[i] = x[i] - 1; + } + int l = 0, r = tt - 1, ans = -1; + while (l <= r) { + int mid = (l + r) / 2; + if (check(mid)) { + l = mid + 1; + ans = mid; + } else { + r = mid - 1; + } + } + cout << ans + 1 << endl; + return 0; +} +int n, d; +char s[1000000]; +int main() { + cin >> n >> d; + gets(s); + int f, maxd = -1, t = 0; + for (int i = 0; i < d; i++) { + gets(s); + f = 0; + for (int j = 0; j < n; j++) { + if (s[j] == '0') f = 1; + } + if (f == 1) { + t++; + continue; + } + if (f == 0) { + maxd = max(maxd, t); + t = 0; + } + } + if (maxd == -1) maxd = d; + if (f == 1) { + maxd = max(maxd, t); + t = 0; + } + cout << maxd << "\n"; + return 0; +} +int main() { + cout.setf(ios::fixed); + cout.precision(20); + int n, x1, y1, x2, y2; + int xl = 2139062143, xr = -2139062143, yl = 2139062143, yr = -2139062143; + cin >> n; + long long area = 0; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + xl = min(xl, x1); + xr = (xr > x2 ? xr : x2); + yl = min(yl, y1); + yr = (yr > y2 ? yr : y2); + area += 1LL * (x2 - x1) * (y2 - y1); + } + if (xr - xl == yr - yl && area == 1LL * (xr - xl) * (yr - yl)) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + string x, y; + int j = 0, i; + cin >> x >> y; + for (i = 0; i < y.size(); i++) + if (x[j] == y[i]) j++; + cout << j + 1 << endl; +} +long long power(long long x, long long y, long long MOD) { + unsigned long long res = 1; + x = x % MOD; + while (y > 0) { + if (y & 1) { res = (res * x) % MOD; } + y = y >> 1; + x = (x * x) % MOD; + } + return (long long)res; +} +long long n, m, res; +int main() { + cin >> n >> m; + res = power(3, n, m) - 1; + cout << (res + m) % m << endl; + return 0; +} +int main() { + string s[101]; + int n; + string t; + cin >> t; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + sort(s, s + n); + for (int i = 0; i < n; i++) { + if (s[i].length() < t.length()) continue; + int j = 0; + while (j < (int)t.length()) { + if (s[i][j] != t[j]) break; + j++; + } + if (j == (int)t.length()) { + cout << s[i] << endl; + return 0; + } + } + cout << t << endl; + return 0; +} +int main() { + int n, m, Mina = 100, Maxa = 0, Minb = 100, t; + cin >> n >> m; + for (int i = 0; i < (n); i++) { + cin >> t; + Mina = min(Mina, t); + Maxa = max(Maxa, t); + } + for (int i = 0; i < (m); i++) { + cin >> t; + Minb = min(Minb, t); + } + if (Mina * 2 >= Minb || Minb <= Maxa) { + puts("-1"); + return 0; + } + cout << max(Mina * 2, Maxa) << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + if (n & 1) + cout << "1\n"; + else + cout << "2\n"; + return 0; +} +int main() { + int p1, p2, p3, p4, a, b, p = 0; + cin >> p1 >> p2 >> p3 >> p4 >> a >> b; + for (int i = a; i <= b; i++) { + if (i % p1 % p2 % p3 % p4 == i) p++; + } + cout << p << endl; +} +int main() { + string s; + cin >> s; + vector v; + for (int i = 0; i < s.size(); i++) { + if (i % 2 == 0) v.push_back(s[i]); + } + sort(v.begin(), v.end()); + for (int i = 0; i < v.size() - 1; i++) { cout << v[i] << "+"; } + cout << v[v.size() - 1] << endl; + return 0; +} +int main() { + int p; + cin >> p; + long long freq[100000]; + vector lol; + for (int i = 0; i < p; i++) { + int n; + cin >> n; + lol.push_back(n); + } + sort(lol.begin(), lol.end()); + int counter = 0, ans = 0; + for (int i = 1; i < p; i++) { + if (lol[i] == lol[i - 1] && lol[i] != 0) counter++; + if (lol[i] != lol[i - 1]) counter = 0; + if (counter >= 2) { + cout << -1 << endl; + return 0; + } + if (counter == 1) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, p, ans, q, sum = 0; + string a, b; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + p = abs(a[i] - b[i]); + if (a[i] > b[i]) + ans = 10 - a[i] + b[i]; + else { + ans = 10 - b[i] + a[i]; + } + q = min(ans, p); + sum = sum + q; + } + cout << sum << endl; +} +int main() { + int a[3]; + for (int i = 0; i < 3; i++) cin >> a[i]; + int n = sizeof(a) / sizeof(a[0]); + sort(a, a + n); + cout << a[2] - a[0] << endl; + return 0; +} +const int mod = 1e9 + 7; +const int inf = 1e9 + 5; +long long powmod(long long a, long long b) { + long long ret = 1; + while (b) { + if (b & 1) ret = (ret * a) % mod; + a = (a * a) % mod; + b >>= 1; + } + return ret; +} +const int maxn = 2e5 + 5; +long long s, x; +int main() { + cin >> s >> x; + if ((s - x) & 1) { + cout << "0\n"; + return 0; + } + long long y = (s - x) / 2; + if (y & x) { + cout << "0\n"; + return 0; + } + long long ways = 0; + for (int i = 0; i <= 40; i++) { + long long setbit = pow(2 * 1LL, i * 1LL); + if (x & setbit) ways++; + } + ways = pow(2 * 1LL, ways); + if (y == 0) ways -= 2; + cout << ways << "\n"; + return 0; +} +int main() { + int n, t; + int a[400]; + while (cin >> n >> t) { + int sum = t; + int i = 0; + for (i; i < n; i++) { cin >> a[i]; }; + for (i = 0; i < n; i++) { + sum -= (86400 - a[i]); + if (sum <= 0) { break; } + } + cout << i + 1 << endl; + } + return 0; +} +const int N = 1e6 + 7; +int main() { + int n; + int cnt = 0; + int ans = 0; + cin >> n; + int a[n]; + for (int i = (int)(0); i <= (int)(n - 1); i++) { + cin >> a[i]; + if (a[i]) + a[i] = -1, cnt++; + else + a[i] = 1; + } + int mx = INT_MIN; + for (int i = (int)(0); i <= (int)(n - 1); i++) { + ans += a[i]; + if (ans > mx) mx = ans; + if (ans < 0) ans = 0; + } + cout << mx + cnt << '\n'; +} +int main() { + int x; + cin >> x; + cout << __builtin_popcount(x) << "\n"; +} +int main() { + string a, b; + int n; + vector ut[4]; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (b == "rat") { + ut[0].push_back(a); + } else if (b == "woman" || b == "child") { + ut[1].push_back(a); + } else if (b == "man") { + ut[2].push_back(a); + } else { + ut[3].push_back(a); + } + } + for (int i = 0; i < 4; i++) { + int c = ut[i].size(); + for (int j = 0; j < c; j++) { cout << ut[i][j] << "\n"; } + } +} +char a[110], c; +int main() { + register int n, d, ans = 0, i, j, cnt; + cin >> n >> d; + memset(a, 1, sizeof(a)); + a[0] = 0; + for (i = 1; i <= d; ++i) { + for (j = 1; j <= n; ++j) { + cin >> c; + a[i] &= (c - '0'); + } + } + for (i = 1, cnt = 0; i <= d; ++i) { a[i] == 0 ? ++cnt : cnt = 0, ans = max(ans, cnt); } + cout << max(ans, cnt) << endl; + return 0; +} +int main() { + int x, y, x1, y1, x2, y2; + cin >> x >> y; + if (x > 0 && y > 0) { cout << 0 << " " << x + y << " " << x + y << " " << 0 << endl; } + if (x < 0 && y > 0) { cout << x - y << " " << 0 << " " << 0 << " " << y - x << endl; } + if (x < 0 && y < 0) { cout << x + y << " " << 0 << " " << 0 << " " << x + y << endl; } + if (x > 0 && y < 0) { cout << 0 << " " << y - x << " " << x - y << " " << 0 << endl; } +} +const long long MAXN = 1001 * 1001; +int main() { + long long n; + cin >> n; + cout << 2 << '\n'; + for (long long i = 1; i < n; i++) { + long long z = (i + 2) * (i + 1) * (i + 1) * (i + 2); + cout << ((i + 2) * (i + 1) * (i + 2) - i) << '\n'; + } +} +int a[2000005]; +int main() { + int n, tmp; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> tmp; + a[tmp + 1000000]++; + } + int ans = 0; + for (int i = 0; i <= 1000; i++) { a[i * i + 1000000] = 0; } + for (int i = 0; i < 2000005; i++) + if (a[i]) { ans = i - 1000000; } + cout << ans << endl; + return 0; +} +int main() { + int n; + long long int k; + cin >> n >> k; + long long int fs[n], ts[n]; + long long int max1 = INT_MIN; + for (int i = 0; i < n; i++) { + cin >> fs[i] >> ts[i]; + if (ts[i] >= k) + max1 = max(fs[i] - (ts[i] - k), max1); + else + max1 = max(fs[i], max1); + } + cout << max1 << endl; +} +int main() { + int n, k, x, i; + cin >> n >> k >> x; + int a[n + 5]; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int time = 0; + for (i = 0; i < (n - k); i++) { time += a[i]; } + time = time + (k * x); + cout << time << endl; +} +int main() { + int n, m[200], mx[200]; + cin >> n; + vector l; + for (int i = 0; i < n; i++) { cin >> m[i]; } + int r = 0; + int p = 0; + for (int u = 1; u < n - 1; u++) { + for (int y = 1; y < n; y++) { + if (y != u) { + mx[p] = m[y] - m[r]; + r = y; + p++; + } + } + int t = *max_element(mx, mx + n - 2); + l.push_back(t); + r = 0; + p = 0; + } + cout << *min_element(l.begin(), l.end()) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; ++i) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + ans += (x2 - x1 + 1) * (y2 - y1 + 1); + } + cout << ans << '\n'; + return 0; +} +const double Pi = acos(-1.0); +int getPossibilities(int num) { + if (num == 0) return 2; + if (num == 1) return 7; + if (num == 2) return 2; + if (num == 3) return 3; + if (num == 4) return 3; + if (num == 5) return 4; + if (num == 6) return 2; + if (num == 7) return 5; + if (num == 8) return 1; + return 2; +} +int main() { + int n; + cin >> n; + cout << getPossibilities(n / 10) * getPossibilities(n % 10) << "\n"; + return 0; +} +int arr[100]; +int main() { + string s; + string a; + while (cin >> s) { + a = ""; + for (int i = 0; i < s.length(); i++) { + if (s[i] != '+') a.push_back(s[i]); + } + int p = a.length(); + for (int i = 0; i < a.length(); i++) { arr[i] = a[i] - '0'; } + int n = sizeof(arr) / sizeof(arr[0]); + sort(arr, arr + n, greater()); + for (int i = p - 1; i >= 1; i--) { + cout << arr[i]; + cout << "+"; + } + cout << arr[0]; + cout << endl; + } + return 0; +} +int n, m; +int c; +int main() { + cin >> n >> m; + for (int i = n + 1; i <= m; i++) { + c = 0; + for (int j = 1; j <= i; j++) { + if (i % j == 0) c++; + } + if ((c == 2) && (i != m)) { + cout << "NO" << '\n'; + break; + } else if ((c == 2) && (i == m)) { + cout << "YES" << '\n'; + break; + } else if (i == m) + cout << "NO" << '\n'; + } + return 0; +} +int main() { + int n, m, left, cnt = 0; + cin >> n >> m; + left = n; + for (int i = 1; left >= 1; i++) { + left--; + if (i % m == 0) left++; + cnt++; + } + cout << cnt << endl; + return 0; +} +int arr[10]; +int main() { + for (int i = 0; i <= 2; i++) { cin >> arr[i]; } + sort(arr, arr + 3); + cout << abs(arr[0] - arr[1]) + abs(arr[2] - arr[1]) << endl; +} +int main() { + int x1, y1, r = 0, l = 0, t; + cin >> t; + while (t--) { + cin >> x1 >> y1; + if (x1 > 0) { r++; } + if (x1 < 0) { l++; } + } + if (l <= 1 || r <= 1) { + cout << "Yes" << endl; + } else + cout << "No" << endl; + return 0; +} +int main() { + string s; + int n, x; + cin >> s; + x = s.size(); + n = (x + 1) * 26 - x; + cout << n << endl; + return 0; +} +int main() { + int n, t; + cin >> t; + for (int i = 1; i <= t; i++) { + cin >> n; + if ((360 % (180 - n)) == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + long long n; + cin >> n; + long long h[n], g[n], i, j, ans = 0; + for (i = 0; i < n; i++) { cin >> h[i] >> g[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (h[i] == g[j]) ans++; + } + } + cout << ans << endl; + return 0; +} +long long a, b, c, d, t, n, k; +char s; +int main() { + cin >> n >> k; + b += k; + for (int i = 0; i < n; i++) { + cin >> s >> a; + if (s == '+') { b += a; } + if (s == '-') { + if (b < a) { + c++; + } else { + b -= a; + } + } + } + cout << b << " " << c << endl; +} +int main() { + int n, m; + cin >> n >> m; + string s; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j < m; j++) { + if (s[j] == '.') { + if ((i + j) % 2 == 0) + s[j] = 'B'; + else + s[j] = 'W'; + } + } + cout << s << endl; + } + return 0; +} +int main() { + int games, bills; + cin >> games >> bills; + vector prices(games); + deque bills_(bills); + for (int i = 0; i < games; ++i) cin >> prices[i]; + for (int i = 0; i < bills; ++i) cin >> bills_.at(i); + int count = 0; + for (int i = 0; i < games; ++i) { + int price = prices[i]; + if (bills_.size() > 0 && price <= bills_[0]) { + count++; + bills_.pop_front(); + } + } + cout << count << endl; + return 0; +} +int main() { + long long int t; + cin >> t; + while (t--) { + long long int angle; + cin >> angle; + long long int arr[181] = {}; + long long int val; + for (long long int i = 3; i <= 360; i++) { + if (((i - 2) * 180) % i == 0) val = ((i - 2) * 180) / i; + arr[val] = 1; + } + if (arr[angle] == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(), ipos, cnt = 0; + for (ipos = 0; ipos < len; ++ipos) + if (s[ipos] == '1') break; + if (ipos == len) return puts("no"), 0; + for (++ipos; ipos < len; ++ipos) + if (s[ipos] == '0') ++cnt; + puts((cnt >= 6) ? "yes" : "no"); +} +int main() { + long long n, m, k; + cin >> n >> k; + long long total = n, cut = 0; + while (k--) { + long long x, cnt = 1, prev = -1, one = 0, tmp; + cin >> m; + tmp = m; + while (tmp--) { + cin >> x; + if (x == 1) + prev = x, cnt = 1; + else { + if (prev + 1 == x) + cnt++, prev = x; + else { + if (cnt > 1) one = cnt; + total -= (cnt - 1); + prev = -1; + cnt = 1; + } + } + } + if (cnt > 1) one = cnt; + total -= (cnt - 1); + if (one) + cut += (m - one), one = 0; + else + cut += (m - 1); + } + cout << (total + cut - 1) << endl; + return 0; +} +int main() { + string s; + int n, sum = 0; + cin >> n; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '8') sum++; + } + if (n / 11 < sum) + cout << (n / 11) << endl; + else + cout << sum << endl; +} +const long long maxn = 1111; +const long long mod = 1000000007; +long long k, c[maxn], p[maxn][maxn], sum[maxn], ans = 1, lastans = 1; +long long C(long long a, long long b) { + return p[a][b] % mod; +} +void init() { + p[0][0] = 1; + for (long long i = 1; i <= 1100; i++) { + p[i][0] = 1; + for (long long j = 1; j <= i; j++) { p[i][j] = (p[i - 1][j] + p[i - 1][j - 1]) % mod; } + } +} +int main() { + cin >> k; + init(); + for (long long i = 1; i <= k; i++) { + cin >> c[i]; + sum[i] = sum[i - 1] + c[i]; + sum[i] %= mod; + } + for (long long i = 1; i <= k; i++) { + ans = lastans * C(sum[i - 1] + c[i] - 1, c[i] - 1); + ans %= mod; + lastans = ans; + } + cout << ans << endl; + return 0; +} +void solve() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i & 1) { + cout << "I hate" + << " "; + } else { + cout << "I love" + << " "; + } + if (i != n) + cout << "that" + << " "; + } + cout << "it" << '\n'; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + cin >> n; + vector b; + vector w; + set s; + for (int i = 0; i < n; i++) s.insert(i + 1); + for (int i = 0; i < n / 2; i++) { + int x; + cin >> x; + if (x % 2 == 0) + w.push_back(x); + else + b.push_back(x); + s.erase(x); + } + sort(b.begin(), b.end()); + sort(w.begin(), w.end()); + int ansb = 0; + int answ = 0; + int jb = 0; + int jw = 0; + for (set::iterator i = s.begin(); i != s.end(); i++) { + if (*i % 2 == 0 && jb < b.size()) { + answ += abs(*i - b[jb]); + jb++; + } else if (jw < w.size()) { + ansb += abs(*i - w[jw]); + jw++; + } + } + cout << min(ansb, answ) << endl; + return 0; +} +int main() { + int a, b, rta = 0, u1, v1, u2, v2; + cin >> a >> b; + cin >> u1 >> v1; + cin >> u2 >> v2; + rta = a; + while (b) { + rta += b; + if (b == v1) { rta = max(0, rta - u1); } + if (b == v2) { rta = max(0, rta - u2); } + b--; + } + cout << rta << "\n"; +} +long long dp[32]; +string str[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; +void init() { + dp[1] = 5; + dp[0] = 0; + int tmp = 1; + for (int i = 1; i < 32; i++) { + for (int j = 0; j < i - 1; j++) { tmp *= 2; } + dp[i] = dp[i - 1] + 5 * tmp; + tmp = 1; + } +} +int main() { + init(); + int n; + while (cin >> n) { + int i; + for (i = 0; i < 32; i++) { + if (n < dp[i]) { break; } + } + int a; + if (n < 5) { + a = n; + } else { + a = n - dp[i - 1]; + } + if (a == 0) { + cout << "Howard" << endl; + } else { + int tmp = 1; + for (int j = 0; j < i - 1; j++) { tmp *= 2; } + int cnt = a / tmp; + if (a % tmp) { cnt++; } + cout << str[cnt - 1] << endl; + } + } +} +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + while (a[i] % 2 == 0) a[i] /= 2; + while (a[i] % 3 == 0) a[i] /= 3; + } + for (int i = 0; i < n - 1; i++) { + if (a[i] != a[i + 1]) { + cout << "No" << endl; + return 0; + } + } + cout << "Yes" << endl; + return 0; +} +int main() { + int row, part; + cin >> row >> part; + for (int i = 1; i <= row; i++) { + if ((i % 2) == 0 && (i / 2) % 2 == 0) { + cout << "#"; + for (int j = 1; j < part; j++) { cout << "."; } + cout << endl; + } else if (i % 2 == 0 && (i / 2) != 0) { + for (int j = 1; j < part; j++) { cout << "."; } + cout << "#"; + cout << endl; + } else if (i % 2 != 0) { + for (int j = 1; j <= part; j++) { cout << "#"; } + cout << endl; + } + } + return 0; +} +int p[500]; +int main() { + int n; + while (cin >> n) { + memset(p, 0, sizeof(p)); + for (int i = 0; i < n; i++) { cin >> p[i]; } + sort(p, p + n); + cout << p[n - 1]; + for (int i = 1; i < n - 1; i++) { cout << " " << p[i]; } + cout << " " << p[0] << endl; + } +} +const int M = 1000000007; +int gcd(int a, int b) { + if (!b) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +int main() { + int a, b; + cin >> a >> b; + long long l = lcm(a, b); + long long A = l / a; + long long B = l / b; + if (a > b) + ++A; + else + ++B; + if (A == B) + puts("Equal"); + else if (A < B) + puts("Masha"); + else + puts("Dasha"); + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n + 1]; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + long long int le = 0, maxle = 0; + for (long long int i = 1; i < n; i++) { + if (a[i] >= a[i - 1]) { + le++; + } else { + le = 0; + } + if (le > maxle) maxle = le; + } + cout << maxle + 1 << "\n"; + return 0; +} +int main() { + string s; + cin >> s; + int ctr = 0; + char pointer = 'a'; + for (int i = 0; i < s.length(); i++) { + int n = abs((int)(pointer - s[i])); + if (n >= 14) n = 26 - n; + ctr += n; + pointer = s[i]; + } + cout << ctr << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + cout << min((m - n % m) * a, n % m * b) << endl; + return 0; +} +int n, p; +string s; +bool safe(char c, int i) { + if ((i - 2 < 0 || c != s[i - 2]) && (i - 1 < 0 || c != s[i - 1])) return 1; + return 0; +} +bool calc(int l) { + for (int i = l + 1; i < n; i++) { + for (int j = 0; j <= p; j++) { + if (j == p) return 0; + char c = 'a' + j; + if (safe(c, i)) { + s[i] = c; + break; + } + } + } + return 1; +} +bool ok(int i) { + for (int b = 1; b < p; b++) { + char c = s[i] + b; + if (c >= 'a' + p) return 0; + if ((c != s[i - 1] || i - 1 < 0) && (c != s[i - 2] || i - 2 < 0)) { + char tem = s[i]; + s[i] = c; + if (calc(i)) { + return 1; + } else + s[i] = tem; + } + } + return 0; +} +void solve() { + for (int i = n - 1; i >= 0; i--) { + if (ok(i)) { + cout << s << endl; + exit(0); + } + } + cout << "NO" << endl; +} +int main() { + cin >> n >> p >> s; + solve(); + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + if (n == 0 && m > 0) + cout << "Impossible\n"; + else { + if (n >= m) + cout << n << ' '; + else + cout << (m / n) * n + (m % n) << ' '; + if (m > 0) + cout << (n - 1) + m << endl; + else + cout << n << endl; + } + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + vector h(n); + for (int i = 0; i < n; i++) { cin >> h[i]; } + sort(h.begin(), h.end()); + cout << h[b] - h[b - 1] << "\n"; + return 0; +} +long long mode1(long long x, long long y, long long p, long long q) { + return (q * x - p * y) / p; +} +long long mode2(long long x, long long y, long long p, long long q) { + return (p * y - q * x) / (q - p); +} +long long gcdNum(long long m1, long long y, long long q) { + long long k = (y + m1); + if (k % q == 0) + return k / q; + else + return k / q + 1; +} +int main() { + int n; + cin >> n; + long long x, y, p, q; + for (int i = 0; i < n; i++) { + cin >> x >> y >> p >> q; + if (p == 0 && x > 0) { + cout << -1 << endl; + } else if (p == 0 && x == 0) { + cout << 0 << endl; + } else if (p == q && x == y) { + cout << 0 << endl; + } else if (p == q || q == 0) + cout << -1 << endl; + else if (p * y - q * x > 0) { + long long m2 = mode2(x, y, p, q); + long long gcd = gcdNum(m2, y, q); + cout << gcd * q - y << endl; + } else { + long long m1 = mode1(x, y, p, q); + long long gdc = gcdNum(m1, y, q); + cout << gdc * q - y << endl; + } + } +} +long long m, n; +long long pw(long long a, long long b) { + long long res = 1; + while (b) { + if (b & 1) res = (res * a) % m; + a = (a * a) % m; + b /= 2; + } + return res; +} +int main() { + cin >> n >> m; + long long ans = (pw(3, n)); + ans--; + if (ans < 0) ans += m; + cout << ans << endl; + return 0; +} +int main() { + int n, k, x, A[101], sum(0); + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> A[i]; + for (int i = 0; i < n - k; i++) sum += A[i]; + for (int i = n - k; i < n; i++) { sum += x; } + cout << sum << endl; + return 0; +} +int main() { + int m, n; + cin >> m >> n; + int v[m][n]; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) cin >> v[i][j]; + for (int i = 0; i < m; ++i) + if (v[i][0] || v[i][n - 1]) { + cout << 2 << '\n'; + return 0; + } + for (int i = 0; i < n; ++i) + if (v[0][i] || v[m - 1][i]) { + cout << 2 << '\n'; + return 0; + } + cout << 4 << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + int upper(0), lower(0); + for (size_t i = 0; i < s.length(); ++i) { + if (isupper(s[i])) { + upper += 1; + } else { + lower += 1; + } + } + if (upper > lower) { + for (size_t i = 0; i < s.length(); ++i) { s[i] = toupper(s[i]); } + } else { + for (size_t i = 0; i < s.length(); ++i) { s[i] = tolower(s[i]); } + } + cout << s << endl; + return 0; +} +int main() { + int A[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n, n1, n2; + cin >> n; + n1 = n % 10; + n /= 10; + n2 = n; + cout << A[n1] * A[n2] << endl; + return 0; +} +int main() { + long long int tc, i, j, c = 0, co = 0, p = 0; + long long int arr[1000]; + int arra[1000]; + cin >> tc; + for (i = 0; i < tc; i++) { cin >> arr[i]; } + for (i = 0; i < tc; i++) { + co = 1; + for (j = i + 1; j < tc; j++) { + if (arr[i] == arr[j] && arr[j] != -2 && arr[i] != 0) { + co++; + arr[j] = -2; + } + } + arra[p] = co; + if (co > 0) p++; + co = 0; + } + for (i = 0; i < p; i++) { + if (arra[i] == 2) + c++; + else if (arra[i] > 2) { + c = -1; + break; + } + } + cout << c << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) { + int da = a[i] - '0'; + int db = b[i] - '0'; + ans += min((da - db + 10) % 10, (db - da + 10) % 10); + } + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + int res = 0; + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { + if (i * i + j == n && i + j * j == m) res++; + } + } + cout << res << endl; +} +int h[31], a[31]; +int main() { + int n, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> h[i] >> a[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (h[i] == a[j]) sum++; + } + } + cout << sum << endl; +} +char str[105]; +int main() { + int n, m; + cin >> n >> m; + cin >> str + 1; + while (m--) { + int l, r; + char c1, c2; + cin >> l >> r >> c1 >> c2; + for (int i = l; i <= r; ++i) { + if (str[i] == c1) str[i] = c2; + } + } + cout << str + 1 << endl; +} +vector adj[(int)1e5 + 6]; +bool solve(int node) { + queue que; + que.push(0); + while (que.size()) { + int cur = que.front(); + if (cur == node) return true; + que.pop(); + for (int i = 0; i < adj[cur].size(); ++i) { que.push(adj[cur][i]); } + } + return false; +} +int main() { + int n, k; + cin >> n >> k; + k -= 1; + int arr[n]; + for (int i = 0; i < n - 1; ++i) { cin >> arr[i]; } + for (int i = 0; i < n - 1; ++i) { adj[i].push_back(i + arr[i]); } + bool ans = solve(k); + if (ans) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int win, next = 3; + for (size_t i = 0; i < n; i++) { + cin >> win; + if (win == next) { + cout << "NO\n"; + return 0; + } else { + next = 6 - win - next; + } + } + cout << "YES\n"; + return 0; +} +int main() { + int k, n, w, sum = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) sum += i; + cout << max(sum * k - n, 0) << endl; + return 0; +} +int main() { + int a, b, c, n, i, j, g = 0; + cin >> a >> b >> c; + cin >> n; + int k[n]; + for (i = 0; i < n; i++) { + cin >> k[i]; + if (k[i] > b && k[i] < c) g++; + } + if (g == 0) + cout << 0 << endl; + else + cout << g << endl; + return 0; +} +const long long INF = 1e18; +const int inf = 2e9; +const int mod = 1e9 + 7; +const int N = 2e5 + 5; +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + if ((int)s.size() == 2 && s[0] < s[1]) { + cout << "YES\n2\n" << s[0] << " " << s[1] << endl; + } else if ((int)s.size() > 2) { + cout << "YES\n2\n" << s[0] << " "; + for (int i = 1; i < (int)s.size(); i++) cout << s[i]; + cout << endl; + } else { + cout << "NO\n"; + } + } +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 == 0) + cout << "NO" << endl; + else { + cout << "YES" << endl; + } + return 0; +} +const int maxn = 1000000 + 10; +char b[maxn]; +int a[maxn]; +int ccc[20]; +int main() { + int n, m; + cin >> n >> m; + int step; + step = min(n, m) - 1; + if (step % 2 == 0) + puts("Akshat"); + else + puts("Malvika"); + return 0; +} +string s; +int n; +inline void Run() { + while (cin >> s) { + string ans = "", tmp = ""; + for (int i = 1; i <= 110; ++i) ans += 'z', tmp += 'z'; + cin >> n; + string t; + for (int i = 1; i <= n; ++i) { + cin >> t; + if (t.size() < s.size()) continue; + if (t.substr(0, s.size()) == s) ans = min(ans, t); + } + if (ans == tmp) ans = s; + cout << ans << endl; + } +} +int main() { + Run(); + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + long long a, b; + cin >> a >> b; + long long x = max(a, b), y = min(a, b), cnt = 0; + while (x > 0 && y > 0) { + cnt += (x / y); + x -= (x / y) * y; + long long m = max(x, y), n = min(x, y); + x = m; + y = n; + } + cout << cnt << endl; + } + return 0; +} +int fa[202002]; +int sum[202002]; +int c[202002]; +int max(int a, int b) { + if (a > b) + return a; + else + return b; +} +int findfa(int x) { + if (fa[x] == x) + return x; + else + return findfa(fa[x]); +} +void joint(int x, int y) { + int rx = findfa(x); + int ry = findfa(y); + if (rx != ry) { + fa[rx] = ry; + sum[ry] += sum[rx]; + } +} +bool vis[202002]; +vector vec; +int main() { + int n, m, k; + cin >> n >> m >> k; + vec.clear(); + for (int i = 0; i <= n; i++) { + fa[i] = i; + sum[i] = 1; + } + for (int i = 0; i < k; i++) cin >> c[i]; + int x, y; + for (int i = 0; i < m; i++) { + cin >> x >> y; + joint(x, y); + } + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < k; i++) vis[findfa(c[i])] = 1; + int mx = -1; + long long ans = 0; + for (int i = 1; i <= n; i++) { + if (fa[i] == i) { + if (vis[i] == 1) + mx = max(mx, sum[i]); + else + vec.push_back(sum[i]); + ans += sum[i] * (sum[i] - 1) / 2; + } + } + int sz = vec.size(); + for (int i = 0; i < sz; i++) { + for (int j = i + 1; j < sz; j++) { ans += vec[i] * vec[j]; } + ans += vec[i] * mx; + } + ans -= m; + cout << ans << endl; + return 0; +} +int a[105][105] = {0}; +int main() { + int n, m, i, j, k, x1, y1, x2, y2, sum = 0; + cin >> n; + for (k = 1; k <= n; k++) { + cin >> x1 >> y1 >> x2 >> y2; + for (i = x1; i <= x2; i++) { + for (j = y1; j <= y2; j++) { + a[i][j]++; + sum++; + } + } + } + cout << sum << endl; +} +int main() { + string s; + cin >> s; + if (s[0] == 'a' && s[1] == '1') + cout << "3" << endl; + else if (s[0] == 'a' && s[1] == '8') + cout << "3" << endl; + else if (s[0] == 'h' && s[1] == '1') + cout << "3" << endl; + else if (s[0] == 'h' && s[1] == '8') + cout << "3" << endl; + else if (s[0] == 'a' && s[1] != '1' && s[1] != '8') + cout << "5" << endl; + else if (s[0] == 'h' && s[1] != '1' && s[1] != '8') + cout << "5" << endl; + else if (s[1] == '1' || s[1] == '8') + cout << "5" << endl; + else + cout << "8" << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + if (a - b > c + 1) + cout << c + 1 << endl; + else + cout << a - b << endl; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long a, b, k; + cin >> a >> b >> k; + if (k % 2 == 0) { + long long temp = k / 2; + cout << temp * (a - b) << endl; + } else { + long long temp1 = (k + 1) / 2; + long long temp2 = (k - 1) / 2; + long long ans = (temp1)*a - (temp2)*b; + cout << ans << endl; + } + } + return 0; +} +int main() { + int i = 0, j = 0, k = 0, flag; + int sum = 0; + int a[100]; + for (i = 0; i < 100; i++) { a[i] = 0; } + string s; + cin >> s; + for (i = 0; i < s.length(); i++) { + if (s[i] == 'Q') { + for (j = i + 1; j < s.length(); j++) + if (s[j] == 'A' && a[j] % 2 == 0) { + a[j] += 1; + for (k = j + 1; k < s.length(); k++) + if (s[k] == 'Q') { + a[k] += 1; + a[j] = 0; + sum += 1; + } + } + } + for (flag = i; flag < 100; flag++) { a[flag] = 0; } + } + cout << sum << endl; + return 0; +} +map M; +int main() { + string word, words; + cin >> word; + for (int i = 0; i <= 9; i++) { + string a; + cin >> a; + M[a] = i; + } + for (int i = 0; word[i]; i += 10) { + words = word.substr(i, 10); + cout << M[words]; + } + cout << endl; + return 0; +} +bool match[105][105]; +int n, m, c[105]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) { + int f, t; + cin >> f >> t; + match[f][t] = match[t][f] = 1; + } + int mini = INT_MAX; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (match[i][j] == 0) continue; + for (int q = 1; q <= n; q++) { + if (q == i || match[j][q] == 0) continue; + if (match[q][i]) mini = min(mini, c[i] + c[j] + c[q]); + } + } + } + if (mini != INT_MAX) + cout << mini << endl; + else + cout << -1 << endl; + return 0; +} +long long q, ans; +map, long long> m; +long long depth(long long x) { + long long ret = 0; + while (x) { + x = (x >> 1); + ret++; + } + return ret; +} +long long lca(long long a, long long b) { + if (a == b) return a; + while (a != b) { + if (depth(a) > depth(b)) { + long long t = a; + a = b; + b = t; + } + b /= 2; + } + return a; +} +void add(long long a, long long b, long long c) { + while (a != b) { + m[{a, a / 2}] += c; + a /= 2; + } +} +long long dis(long long a, long long b) { + long long ret = 0; + while (a != b) { + ret += m[{b, b / 2}]; + b /= 2; + } + return ret; +} +int main() { + cin >> q; + while (q--) { + long long a, b, c, d; + ans = 0; + cin >> a; + if (a == 1) { + cin >> b >> c >> d; + long long anc = lca(b, c); + add(b, anc, d); + add(c, anc, d); + } else { + cin >> b >> c; + long long anc = lca(b, c); + ans += dis(anc, b) + dis(anc, c); + cout << ans << endl; + } + } + return 0; +} +int main() { + int t; + int a[101], b[101], a1[6] = {0}, b1[6] = {0}; + cin >> t; + for (int i = 0; i < t; i++) { + cin >> a[i]; + a1[a[i]]++; + } + for (int i = 0; i < t; i++) { + cin >> b[i]; + b1[b[i]]++; + } + int sum = 0; + for (int i = 1; i < 6; i++) { + if ((a1[i] + b1[i]) % 2 != 0) { + cout << -1 << endl; + return 0; + } else + sum += abs(b1[i] - a1[i]) / 2; + } + cout << sum / 2 << endl; + return 0; +} +int main() { + string name; + cin >> name; + int x = 0; + char c; + int flag = 0; + for (int i = 0; i < name.length(); i++) { + c = name[i]; + for (int a = i + 1; a < name.length(); a++) { + if (c == name[a]) { + flag = 1; + break; + } else { + flag = 0; + } + } + if (flag == 0) { x++; } + flag = 0; + } + if (x % 2 == 1) { + cout << "IGNORE HIM!" << endl; + } else if (x % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } +} +int main() { + int n, m, x, y; + cin >> n >> m >> x >> y; + vector a, b; + int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + a.push_back(temp); + } + for (int i = 0; i < m; i++) { + cin >> temp; + b.push_back(temp); + } + int S = 0, j = 0; + map ma; + map::iterator itm; + for (int i = 0; i < n; i++) { + int l = a[i] - x; + int r = a[i] + y; + if (b[j] >= l && b[j] <= r) { + S++; + ma.insert(make_pair(i + 1, j + 1)); + j++; + } else { + if (b[j] < l) { + i--; + j++; + } + } + if (j == m) { break; } + } + cout << S << endl; + for (itm = ma.begin(); itm != ma.end(); itm++) { cout << itm->first << " " << itm->second << endl; } + return 0; +} +int main() { + int n, ans = 0; + cin >> n; + if (n >= 100) ans += n / 100, n -= 100 * (n / 100); + if (n >= 20) ans += n / 20, n -= 20 * (n / 20); + if (n >= 10) ans += n / 10, n -= 10 * (n / 10); + if (n >= 5) ans += n / 5, n -= 5 * (n / 5); + if (n >= 1) ans += n / 1, n -= n / 1; + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + int cnt = 0, god = 0, ans = 0; + for (int i = 0; i < s.size(); i++) { + cnt = 0; + god = 0; + for (int j = i; j < s.size(); j++) { + if (s[j] == '(') + cnt++; + else if (s[j] == ')') + cnt--; + else if (s[j] == '?') { + cnt--; + god++; + } + if (cnt == -1) { + if (god == 0) break; + cnt += 2; + god--; + } + if (cnt == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int ara[n]; + for (int i = 0; i < n; i++) cin >> ara[i]; + sort(ara, ara + n); + int sum = 0; + for (int i = 0; i < n - k; i++) sum += ara[i]; + for (int i = 0; i < k; i++) sum += x; + cout << sum << endl; + return 0; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + cout << (n - 1) * (2 * b + 1) << " " << n * p << "\n"; + return 0; +} +const int maxn = 2e5 + 5; +const long long INF = 9999999999; +long long a[maxn]; +int main() { + int n; + int i; + long long min = INF; + while (cin >> n) { + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 0; i < n - 1; i++) { + if (abs(a[i + 1] - a[i]) < min) { min = abs(a[i + 1] - a[i]); } + } + int cnt = 0; + for (i = 0; i < n - 1; i++) { + if (abs(a[i + 1] - a[i]) == min) { cnt++; } + } + cout << min << " " << cnt << endl; + } + return 0; +} +const int N = 1e5 + 5; +int a, b, c; +bool ok(int t) { + return t * b + b * c >= a * c; +} +int binary() { + int lo = 0, hi = 1e6, med; + while (hi > lo) { + med = (lo + hi) >> 1; + if (ok(med)) + hi = med; + else + lo = med + 1; + } + return lo; +} +int main() { + cin >> a >> b >> c; + cout << binary() << endl; + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + long long a, b; + long long x = 0, y = 0, g = 0; + string s = "Dasha", t = "Masha", w = "Equal"; + cin >> a >> b; + if (a < b) { + swap(a, b); + swap(s, t); + } + g = gcd(a, b); + g = a * b / g; + for (int i = 1; i <= g; i++) { + if (a * i > g) break; + x++; + } + for (int i = 1; i <= g; i++) { + if (b * i > g) break; + if ((b * i) % a != 0) y++; + } + if (x == y) + cout << w << endl; + else if (x > y) + cout << s << endl; + else if (x < y) + cout << t << endl; + return 0; +} +const long long MAXN = 3e5 + 7; +long long a, b; +long long ans; +long long cnt; +long long N, X, Y; +string A; +int main() { + cin >> N >> X >> Y >> A; + for (long long i = 0; i < N; i++) { + if (A[i] == '1') + a++; + else + b++; + while (A[i + 1] == A[i] && i + 1 < N) i++; + } + if (!b) return puts("0"), 0; + if (X <= Y) + ans = 1LL * (b - 1) * X + Y; + else + ans = 1LL * b * Y; + cout << ans << endl; + return 0; +} +int main() { + int n, m, min = 10000, ele; + cin >> n >> m; + int Freq[n] = {}; + while (m--) { + cin >> ele; + Freq[ele - 1]++; + } + for (int i = 0; i < n; i++) { + if (Freq[i] < min) { min = Freq[i]; } + } + cout << min << "\n"; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int odd = abs(i - (n + 1) / 2) + abs(j - (n + 1) / 2); + if (odd > n / 2) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } +} +int main() { + int n, i, extrema = 0, arr[1000 + 5]; + cin >> n; + for (i = 0; i < n; ++i) { cin >> arr[i]; } + for (i = 1; i < n - 1; ++i) { + if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) + ++extrema; + else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) + ++extrema; + } + cout << extrema << endl; + return (0); +} +char chess[101][101] = {'-'}; +int main() { + int n, m, i, j; + while (cin >> n >> m) { + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) cin >> chess[i][j]; + for (i = 1; i <= n; i++) + for (j = 1; j <= m; j++) { + if (chess[i][j] != '-') { + if ((i + j) % 2 == 0) cout << "B"; + if ((i + j) % 2 == 1) cout << "W"; + } else + cout << "-"; + if (j == m) cout << endl; + } + } +} +int main() { + int n, m, k, a[50], sum = 0, i = 0; + for (cin >> n >> m >> k; i < n; i++) cin >> a[i], sum += a[i]; + if (sum + (k - n) < m) return cout << -1 << endl, 0; + sort(a, a + n); + if (k < m) + for (int x = m - k + 1, i = n - 1, sum = 0; i >= 0; i--) + if (sum + a[i] >= x) + return cout << n - i << endl, 0; + else + sum += a[i], x++; + cout << 0 << endl; + return 0; +} +int main() { + int n, k; + cin >> n; + while (n--) { + int a; + cin >> a; + if (360 % (180 - a) == 0) { + k = (360) / (180 - a); + if (k < 3) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } else { + cout << "NO" << endl; + } + } +} +long long int l, r, ld, rd, d, mid, mx; +bool bt(long long int v) { + if (v >= l && v <= r) + return 1; + else + return 0; +} +int main() { + cin >> l >> r; + d = r; + while (d > 0) { + rd++; + d /= 10; + } + d = l; + while (d > 0) { + ld++; + d /= 10; + } + mx = pow(10, rd); + mid = mx / 2; + if (bt(mid) || bt(mid - 1)) + cout << mid * (mid - 1) << "\n"; + else if (r < mid) + cout << r * (mx - 1 - r) << "\n"; + else if (l > mid) + cout << l * (mx - 1 - l) << "\n"; + return 0; +} +int main() { + int a, b, r; + cin >> a >> b >> r; + r *= 2; + if (r > min(a, b)) + cout << "Second" << '\n'; + else + cout << "First" << '\n'; +} +int main() { + int n, m, x, y; + cin >> n >> m >> x >> y; + vector d; + vector a; + d.push_back(0); + a.push_back(0); + int dd, aa; + for (int i = 1; i < (n + 1); i++) { + cin >> dd; + d.push_back(dd); + } + for (int i = 1; i < (m + 1); i++) { + cin >> aa; + a.push_back(aa); + } + vector ans1; + vector ans2; + int cnt = 0; + int i = 1; + int j = 1; + while ((i <= n) && (j <= m)) { + if (((d[i] - x) <= a[j]) && (a[j] <= (d[i] + y))) { + cnt++; + ans1.push_back(i); + ans2.push_back(j); + i++; + j++; + } else if ((d[i] - x) >= a[j]) { + j++; + } else if (a[j] >= (d[i] + y)) { + i++; + } + } + cout << cnt << endl; + for (int i = 0; i < cnt; i++) { cout << ans1[i] << " " << ans2[i] << endl; } +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if (((d / t) + 1) * k >= n) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +queue a; +char s[1000005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + if (s[i] != a.front() && a.size() != 0) { + a.pop(); + } else { + a.push(s[i]); + } + } + cout << a.size() << endl; + return 0; +} +int main() { + int n, a, b, s, t; + while (cin >> n) { + t = 0; + int r = 0, z = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + r += a; + z += b; + s = z - r; + t = max(t, s); + } + cout << t << endl; + } + return 0; +} +int main() { + int n, k, x, sum, i; + sum = 0; + int a[101]; + cin >> n >> k >> x; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n - k; i++) sum = sum + a[i]; + sum = sum + (k * x); + cout << sum << '\n'; + return 0; +} +const int maxn = 100; +int gcd(int n, int m) { + if (m == 0) return n; + return gcd(m, n % m); +} +int a[maxn + 5]; +int main() { + int n, i, ans; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + ans = 0; + for (i = 0; i < n; i++) ans = gcd(ans, a[i]); + cout << ans * n << endl; + return 0; +} +int main() { + int t; + cin >> t; + int L, u, l, r; + vector res; + for (int i = 0; i < t; i++) { + cin >> L >> u >> l >> r; + int curr = L / u; + curr -= (r / u - l / u + (l % u == 0 ? 1 : 0)); + res.push_back(curr); + } + for (int i = 0; i < t; i++) { cout << res[i] << endl; } + return 0; +} +int main() { + string a, b, e, f; + int c; + cin >> a >> b >> c; + cout << a << ' ' << b << endl; + for (int d = 1; d <= c; d++) { + cin >> e >> f; + if (a == e) { + a = f; + cout << a << ' ' << b << endl; + } else if (a == f) { + a = e; + cout << a << ' ' << b << endl; + } else if (b == f) { + b = e; + cout << a << ' ' << b << endl; + } else if (b == e) { + b = f; + cout << a << ' ' << b << endl; + } + } + return 0; +} +const long long puno = 1e9 + 3; +const long long nula = 0; +int main() { + string s, b[10], c[10]; + b[0] = "Power"; + c[0] = "purple"; + b[1] = "Time"; + c[1] = "green"; + b[2] = "Space"; + c[2] = "blue"; + b[3] = "Soul"; + c[3] = "orange"; + b[4] = "Reality"; + c[4] = "red"; + b[5] = "Mind"; + c[5] = "yellow"; + int n, i, j; + cin >> n; + for (i = 0; i < n; i++) { + cin >> s; + for (j = 0; j < 6; j++) + if (s == c[j]) c[j] = "nope"; + } + cout << 6 - n << endl; + for (i = 0; i < 6; i++) { + if (c[i] != "nope") cout << b[i] << endl; + } + return 0; +} +int main() { + int n, c1 = 0, c2 = 0, i, m, k, d; + char a, b; + string s, t; + cin >> n >> s >> t; + m = s.size(); + k = t.size(); + for (i = 0; i < n && i < m * k; i++) { + a = s[i % m]; + b = t[i % k]; + if (a != b) { + d = (n - i + m * k - 1) / (m * k); + if (a == 'P' && b == 'S' || a == 'R' && b == 'P' || a == 'S' && b == 'R') + c1 += d; + else + c2 += d; + } + } + cout << c1 << " " << c2 << endl; + return 0; +} +string s; +long long n, m; +int main() { + cin >> n >> m; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + int ans; + for (int i = n - 1; i >= 0; i--) { + if (m % v[i] == 0) { + ans = m / v[i]; + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int a, b; + int i, j; + int n; + bool flag; + string s; + cin >> a; + for (b = 1;; ++b) { + stringstream ss; + ss << (a + b); + ss >> s; + n = s.length(); + for (j = 0; j < n; ++j) { + if (s[j] == '8') { + flag = true; + break; + } else + flag = false; + } + if (flag == true) { + cout << b << endl; + break; + } + } + return 0; +} +int main() { + int sum = 0, max = -1; + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp > max) max = temp; + sum += temp; + } + int t; + if ((sum + m) % n == 0) + t = (sum + m) / n; + else + t = (sum + m) / n + 1; + if (max > t) t = max; + cout << t << " " << max + m << endl; + return 0; +} +int main() { + int n, m; + string s; + cin >> n >> m >> s; + int l[m], r[m]; + char c1[m], c2[m]; + for (int i = 0; i < m; i++) { cin >> l[i] >> r[i] >> c1[i] >> c2[i]; } + for (int i = 0; i < m; i++) { + for (int j = l[i] - 1; j < r[i]; j++) { + if (s[j] == c1[i]) { s[j] = c2[i]; } + } + } + cout << s << endl; + return 0; +} +int main() { + int n, k, locg, loct; + string s; + cin >> n >> k >> s; + for (int i = 0; i < s.size(); i++) + if (s[i] == 'G') + locg = i; + else if (s[i] == 'T') + loct = i; + if (abs(locg - loct) % k) + cout << "NO\n"; + else { + bool yes = 1; + for (int i = min(locg, loct); i <= max(locg, loct); i += k) + if (s[i] == '#') { + yes = 0; + break; + } + if (yes) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +void answer(unsigned long long n, unsigned long long k) { + for (int i = 1; i <= k; i++) { + if (n % 10 == 0) + n = n / 10; + else + n = n - 1; + } + cout << n << endl; +} +int main() { + unsigned long long n, k, i; + cin >> n >> k; + answer(n, k); + return 0; +} +int main() { + int n; + cin >> n; + if (!n) + cout << 1 << endl; + else + cout << (int)(sqrt(2) * n) * 4 << endl; + return 0; +} +int main() { + char ch[101]; + int arr[101]; + int count = 0; + cin >> ch; + int x = strlen(ch); + for (int i = 0; i < x; i++) { arr[i] = ch[i]; } + sort(arr, arr + x); + for (int i = 0; i < x; i++) { + if (arr[i] == arr[i + 1]) { continue; } + ++count; + } + if (count % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +const int MAX = 100001; +int An[MAX], Bn[MAX]; +int main() { + int n; + cin >> n; + int sum = 0; + while (n) { + if (n / 100) { + sum += n / 100; + n -= n / 100 * 100; + } else if (n / 20) { + sum += n / 20; + n -= n / 20 * 20; + } else if (n / 10) { + sum += n / 10; + n -= n / 10 * 10; + } else if (n / 5) { + sum += n / 5; + n -= n / 5 * 5; + } else { + sum += n; + break; + } + } + cout << sum << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n == 0) + cout << "O-|-OOOO" << endl; + else { + while (n > 0) { + long long res = n % 10; + n /= 10; + if (res == 0) + cout << "O-|-OOOO" << endl; + else if (res == 1) + cout << "O-|O-OOO" << endl; + else if (res == 2) + cout << "O-|OO-OO" << endl; + else if (res == 3) + cout << "O-|OOO-O" << endl; + else if (res == 4) + cout << "O-|OOOO-" << endl; + else if (res == 5) + cout << "-O|-OOOO" << endl; + else if (res == 6) + cout << "-O|O-OOO" << endl; + else if (res == 7) + cout << "-O|OO-OO" << endl; + else if (res == 8) + cout << "-O|OOO-O" << endl; + else + cout << "-O|OOOO-" << endl; + } + } +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + cout << (a * b * c) - ((a - 1) * (b - 1) * (c - 1)) << endl; + return 0; +} +int main() { + int n, k, j, h, i1; + cin >> n >> k; + string s; + cin >> s; + if (k - 1 < n - k) { + for (int i = k - 1; i >= 0; i--) { + if (i != 0) cout << "LEFT" << endl; + } + for (int i = 0; i < n; i++) { + cout << "PRINT " << s[i] << endl; + if (i != n - 1) cout << "RIGHT" << endl; + } + } else { + for (int i = k - 1; i < n; i++) { + if (i != n - 1) cout << "RIGHT" << endl; + } + for (int i = n - 1; i >= 0; i--) { + cout << "PRINT " << s[i] << endl; + if (i != 0) cout << "LEFT" << endl; + } + } + return 0; +} +int main() { + string a, b, c; + cin >> a >> b; + c += a[0]; + for (int i = 1; i < a.size(); i++) { + if (a[i] < b[0]) + c += a[i]; + else + break; + } + c += b[0]; + cout << c << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int k; + for (int i = 1; i <= n * m; i++) + if (i % n == 0 && i % m == 0) { + k = i; + break; + } + cout << z / k << endl; +} +vector v[1001], p; +vector::iterator l, ll; +bool vis[1001]; +map mp[1001]; +void bfs(long long int r) { + long long int t, u; + queue q; + vis[r] = 1; + q.push(r); + p.push_back(r); + while (!q.empty()) { + t = q.front(); + q.pop(); + for (l = v[t].begin(); l != v[t].end(); l++) { + u = *l; + if (vis[u] == 0) { + vis[u] = 1; + q.push(u); + p.push_back(u); + } + } + } +} +int main() { + long long int n, m, k, i, a, b, t, f, r, cou, ans = 0, temp, o = -1, nas; + cin >> n >> m >> k; + long long int ara[k]; + for (i = 0; i < k; i++) { cin >> ara[i]; } + pair pq[m]; + for (i = 1; i <= m; i++) { + cin >> a >> b; + pq[i - 1].first = a; + pq[i - 1].second = b; + v[a].push_back(b); + v[b].push_back(a); + } + for (i = 0; i < k; i++) { + cou = 0; + bfs(ara[i]); + t = p.size(); + o = max(o, t); + for (l = p.begin(); l != p.end(); l++) { + f = *l; + for (ll = v[f].begin(); ll != v[f].end(); ll++) { + r = *ll; + if (mp[f][r] == 0) { + mp[f][r] = 1; + mp[r][f] = 1; + cou++; + } + } + } + temp = (t * (t - 1)) / 2; + ans += (temp - cou); + p.clear(); + } + temp = 0; + for (i = 1; i <= n; i++) { + if (vis[i] == 0) { temp++; } + } + nas = o + (temp - 1); + nas = (nas * (nas + 1)) / 2; + nas = nas - ((o * (o - 1)) / 2); + for (i = 0; i < m; i++) { + if (vis[pq[i].first] == 0) { nas--; } + } + cout << ans + nas << "\n"; +} +int main() { + string s1, s2, s3, s4; + cin >> s1 >> s2; + int n; + cin >> n; + cout << s1 << " " << s2 << "\n"; + for (int i = 0; i < n; i++) { + cin >> s3 >> s4; + if (s1 == s3) + s1 = s4; + else + s2 = s4; + cout << s1 << " " << s2 << "\n"; + } +} +int main() { + int a, b, c, x, cal = 0, count = 0; + cin >> a >> b >> c; + x = a * c; + for (int i = 0;; i++) { + cal = b + cal; + ++count; + if (cal >= x) { + cout << count - c << endl; + break; + } + } +} +bool prime(int n) { + if (n == 0 || n == 1) return false; + if (!(n & 1)) { + if (n == 2) + return true; + else + return false; + } + for (int i = 2; i * i <= n; i++) + if (n % i == 0) return false; + return true; +} +int main() { + int n, m, i, p; + while (cin >> n >> m) { + for (i = n + 1;; i++) { + if (prime(i)) { + p = i; + break; + } + } + if (p == m) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int size_n; +char letters[26]; +int result = 0; +vector str(0); +int check(char a, char b); +int main() { + int ii, jj; + cin >> size_n; + str.resize(size_n); + cin.ignore(); + for (ii = 0; ii < 26; ii++) letters[ii] = 'a' + ii; + for (ii = 0; ii < size_n; ii++) getline(cin, str[ii]); + for (ii = 0; ii < 26; ii++) { + for (jj = (ii + 1); jj < 26; jj++) result = max(result, check(letters[ii], letters[jj])); + } + cout << result << endl; + return 0; +} +int check(char a, char b) { + int ii, jj; + int wordLen; + bool niceWord; + int res = 0; + for (ii = 0; ii < size_n; ii++) { + wordLen = str[ii].size(); + niceWord = 1; + for (jj = 0; (jj < wordLen) && niceWord; jj++) { + if ((str[ii][jj] != a) && (str[ii][jj] != b)) niceWord = 0; + } + if (niceWord) res += wordLen; + } + return res; +} +int n, m; +string s; +int l, r; +string c1, c2; +int main() { + cin >> n >> m; + cin >> s; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + for (int j = l - 1; j < r; j++) + if (s[j] == c1[0]) s[j] = c2[0]; + } + cout << s << endl; + return 0; +} +int main() { + int n, r; + cin >> n >> r; + n = n % 10; + for (int i = 1; i < 10; ++i) { + if ((i * n) % 10 == 0 || (i * n) % 10 == r) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 != 0) { + n--; + } else { + n /= 10; + } + } + cout << n << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int arya = 0, bran = 0; + int s = 0; + for (int i = 0; i < n; ++i) { + int t; + cin >> t; + if (t + arya >= 8) { + bran += 8; + arya += t - 8; + ++s; + } else { + bran += t + arya; + arya = 0; + ++s; + } + if (bran >= k) { + cout << s << endl; + return 0; + } + } + if (bran <= k) { cout << -1 << endl; } +} +int a[200001]; +int b[200001]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + int ans = 0; + sort(a, a + n); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) ans += 1; + } + if (ans <= 2) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } +} +int main() { + int n, a, b, c; + cin >> a >> b >> c; + if (a < c * 2 || b < c * 2) + cout << "Second" << endl; + else + cout << "First" << endl; +} +bool the_same(string s1, string s2) { + return (s1[0] == s2[0] || s1[1] == s2[1]); +} +int main() { + bool ok = false; + string s1, s2; + cin >> s1; + for (int i = 0; i < 5; i++) { + cin >> s2; + if (the_same(s1, s2)) ok = true; + } + if (ok) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int a, b, q, p; + cin >> a >> b >> q >> p; + long long int d = __gcd(q, p); + q /= d; + p /= d; + long long int l = -1, r = 1e10; + long long int ans = -1; + while (r > l) { + long long int mid = (l + r) / 2; + long long int x = q * mid - a; + long long int y = p * mid - b; + if (x >= 0 && y >= 0 && y >= x) { + ans = y; + r = mid; + } else { + l = mid + 1; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int t = 1; + while (t--) { + int n, k, sol = 0; + cin >> n >> k; + bool flag = 1; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = k - 1; i < n - 1; i++) { + if (v[i] != v[i + 1]) { + flag = 0; + break; + } + } + if (flag) { + for (int i = k - 1; i > 0; i--) { + if (v[i] != v[i - 1]) { break; } + sol++; + } + } + if (!flag) + cout << "-1" << endl; + else + cout << k - sol - 1 << endl; + } +} +int main() { + int inpp; + cin >> inpp; + int r = 1; + while (r * 5 < inpp) { + inpp -= r * 5; + r *= 2; + } + string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cout << names[(inpp - 1) / r] << endl; + return 0; +} +const double PI = acos(-1); +const int MAX = 2e9 + 7; +vector g[1005]; +bool used[1005]; +int deg[1005]; +bool isHome[1005]; +int ans = 0; +int ver = 0; +int total = 0; +bool h = false; +vector ok; +vector no; +void dfs(int v) { + used[v] = true; + ans += deg[v]; + ver++; + if (isHome[v]) h = true; + for (int i = 0; i < g[v].size(); i++) { + if (!used[g[v][i]]) { dfs(g[v][i]); } + } +} +void solve() { + int n, m, k; + cin >> n >> m >> k; + int home[k]; + for (int i = 0; i < k; i++) { + int x; + cin >> x; + isHome[x] = true; + } + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + g[u].push_back(v); + g[v].push_back(u); + deg[u]++; + deg[v]++; + } + for (int i = 1; i <= n; i++) { + if (!used[i]) { + dfs(i); + ans = ans / 2; + int t = (ver * (ver - 1) / 2); + total += (t - ans); + if (h == true) { + no.push_back(ver); + } else { + ok.push_back(ver); + } + ver = 0; + ans = 0; + h = false; + } + } + int mul = 0; + int sum = 0; + for (int i = 0; i < ok.size(); i++) { + mul += sum * ok[i]; + sum += ok[i]; + } + sort((no).begin(), (no).end()); + mul += sum * no[no.size() - 1]; + total += mul; + cout << total << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n; + cin >> n; + int a[n] = {}; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) { + if (a[0] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (a[0] == 0) { + cout << "UP" << endl; + return 0; + } else { + cout << "-1" << endl; + return 0; + } + } else { + if (a[n - 1] == 15) { + cout << "DOWN" << endl; + return 0; + } else if (a[n - 1] > a[n - 2]) { + cout << "UP" << endl; + return 0; + } else { + if (a[n - 1] != 0) { + cout << "DOWN" << endl; + return 0; + } else { + cout << "UP" << endl; + return 0; + } + } + } +} +const int INF = 0x3f3f3f3f; +const double eps = 1e-7; +const long long mod = 1e9 + 7; +long long CountNum(long long n) { + int ans = 0; + while (n) { + ans++; + n /= 2; + } + return ans; +} +int main() { + long long n; + cin >> n; + cout << CountNum(n) << endl; + return 0; +} +int main() { + char c[10][10]; + for (int i = 1; i <= 8; i++) { gets(c[i]); } + int flag = 1; + for (int i = 1; i <= 8; i++) { + for (int j = 0; j < 7; j++) { + if (c[i][j] == c[i][j + 1]) { + flag = 0; + break; + } + } + if (flag == 0) { break; } + } + if (flag) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + int mini = min(a, min(b, c)); + if (n == 1) + cout << 0 << endl; + else if (n == 2) + cout << min(a, b) << endl; + else if (n >= 3) + cout << min(a, b) + (n - 2) * mini << endl; + return 0; +} +int main() { + int n, t, c[105] = {0}, tmp, ans = 0; + cin >> n >> t; + for (int i = 0; i < n; i++) { + cin >> tmp; + c[i] = 86400 - tmp; + } + for (int i = 0; i < n; i++) { + ++ans; + t = t - c[i]; + if (t <= 0) break; + } + cout << ans << endl; + return 0; +} +const double eps = 1e-6; +const double PI = 3.14159265358979323846264338f; +const double pi = acos(-1.0); +const int inf = 0x3f3f3f3f; +const long long mod = 100000007; +const int MAXN = 200005; +inline int read() { + int c = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + c = c * 10 + ch - '0'; + ch = getchar(); + } + return c * f; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + while (m--) { + int l, r; + char op1, op2; + cin >> l >> r >> op1 >> op2; + for (int i = l - 1; i <= r - 1; i++) { + if (s[i] == op1) s[i] = op2; + } + } + cout << s << '\n'; + return 0; +} +int main() { + int n, m, mn, mx; + cin >> n >> m >> mn >> mx; + string cor = "Correct"; + string inc = "Incorrect"; + int t[m]; + for (int i = 0; i < m; i++) cin >> t[i]; + sort(t, t + m); + if (t[0] < mn || t[m - 1] > mx) { + cout << inc << endl; + return 0; + } + if (n - m == 0) { + if (t[0] == mn && t[m - 1] == mx) + cout << cor << endl; + else + cout << inc << endl; + return 0; + } + if (n - m == 1) { + if (t[0] == mn || t[m - 1] == mx) + cout << cor << endl; + else + cout << inc << endl; + return 0; + } + cout << cor << endl; + return 0; +} +int main() { + string n, s; + while (cin >> n >> s) { + for (int i = 0; i < n.length(); i++) { + n[i] = tolower(n[i]); + s[i] = tolower(s[i]); + } + if (n == s) { + cout << "0" << endl; + } else if (n < s) { + cout << "-1" << endl; + } else + cout << "1" << endl; + } + return 0; +} +long long n, k; +int main() { + while (cin >> n >> k) { + long long ans = k / n; + if (k % n) ans++; + cout << ans << endl; + } + return 0; +} +int main() { + int x, y; + cin >> x >> y; + int x1 = 0, y1 = 0; + if (x >= 0) + x1 += x; + else + x1 += (-1 * x); + y1 = x1; + if (y >= 0) + y1 += y; + else + y1 += (-1 * y); + x1 = y1; + if (y < 0) y1 *= -1; + if (x < 0) + cout << (-1 * x1) << " " << 0 << " " << 0 << " " << y1 << endl; + else + cout << 0 << " " << y1 << " " << x1 << " " << 0 << endl; +} +int main() { + int x, a, b, c, n, i, ans = 0; + cin >> a >> b >> c >> n; + for (i = 1; i <= n; i++) { + cin >> x; + if (x < c && x > b) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int cnt = (n + k - 1) / k; + int ans = cnt * t; + int v1 = 0, v2 = d; + while (cnt--) { + if (v1 <= v2) { + v1 += t; + } else { + v2 += t; + } + } + int v = max(v1, v2); + if (v < ans) { return cout << "YES" << endl, 0; } + return cout << "NO" << endl, 0; +} +int main() { + int n, k; + cin >> n >> k; + int a[100 + 5], b[100 + 5]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) cin >> b[i]; + if (k >= 2) { + cout << "Yes" << endl; + return 0; + } else { + for (int i = 0; i < n; i++) { + if (a[i] == 0) a[i] = b[0]; + if (i == 0) continue; + if (a[i] < a[i - 1]) { + cout << "Yes" << endl; + return 0; + } + } + } + cout << "No" << endl; + return 0; +} +int main() { + int a[3][3], b[3][3]; + memset(b, 0, sizeof(b)); + int i, j; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { cin >> a[i][j]; } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (a[i][j] % 2 == 0) { + a[i][j] = 0; + } else { + a[i][j] = 1; + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (a[i][j] == 1) { + if (b[i][j] == -1) + b[i][j] = 0; + else + b[i][j] = -1; + if (i != 2) { + if (b[i + 1][j] == -1) + b[i + 1][j] = 0; + else + b[i + 1][j] = -1; + } + if (j != 2) { + if (b[i][j + 1] == -1) + b[i][j + 1] = 0; + else + b[i][j + 1] = -1; + } + if (i != 0) { + if (b[i - 1][j] == -1) + b[i - 1][j] = 0; + else + b[i - 1][j] = -1; + } + if (j != 0) { + if (b[i][j - 1] == -1) + b[i][j - 1] = 0; + else + b[i][j - 1] = -1; + } + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (b[i][j] == -1) { + b[i][j] = 0; + } else { + b[i][j] = 1; + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { cout << b[i][j]; } + cout << endl; + } + return 0; +} +const double E = exp(1); +const int maxn = 1e6 + 10; +char ch[maxn]; +char ch1[maxn]; +int main() { + cin >> ch; + cin >> ch1; + int l1 = strlen(ch); + int l2 = strlen(ch1); + if (strcmp(ch, ch1) == 0) + cout << -1 << endl; + else + cout << max(l1, l2) << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << (int)ceil((a - b) * c * 1.0 / b) << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int MAXN = 100005; +int a[1005]; +int b[1005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + a[i] |= a[i - 1]; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + b[i] |= b[i - 1]; + } + cout << a[n] + b[n] << '\n'; + return 0; +} +int a[10]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n / 2] << endl; + return 0; +} +int a[100001]; +int q[100001]; +int main() { + int m; + cin >> m; + for (int i = 0; i < m; i++) { cin >> q[i]; } + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + sort(q, q + m); + int sum = 0; + int cnt = 0; + for (int i = n - 1; i >= 0; i--) { + if (q[0] == cnt) { + i--; + cnt = 0; + } else { + sum += a[i]; + cnt++; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, l, mt; + string s; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + l = s.size(); + if (l > 10) { + mt = l - 2; + cout << s[l - mt - 2] << mt << s[l - 1] << endl; + } else + cout << s << endl; + } +} +int fastMax(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; +} +int fastMin(int x, int y) { + return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; +} +const long long int MOD = 1e6 + 3; +const long long int MAXN = 1001; +long long int first[MAXN]; +long long int n; +void solve() { + first[0] = first[1] = 1; + for (long long int i = 2; i < MAXN; i++) { first[i] = (3 * first[i - 1]) % MOD; } + cin >> n; + cout << first[n] << endl; +} +int main() { + long long int t; + t = 1; + while (t--) solve(); +} +int main() { + long long int n, x, occurances = 0; + cin >> n >> x; + for (int i = 1; i <= n; i++) { + if (x % i == 0 && x / i <= n) { occurances++; } + } + cout << occurances << "\n"; + return 0; +} +int main() { + char square[300][300]; + int n; + cin >> n; + int flag = 0, flag1 = 0, flag2 = 0; + char letterx, letterx1; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> square[i][j]; } + } + letterx = square[0][0]; + letterx1 = square[0][1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j && square[i][j] != letterx) { + flag = 1; + break; + } else if (i + j == n - 1 && letterx != square[i][j]) { + flag1 = 1; + break; + } else if ((i > j || i < j) && i + j != n - 1) { + if (letterx1 != square[i][j]) { + flag2 = 1; + break; + } + if (square[i][j] == letterx) { + flag2 = 1; + break; + } + } + } + } + if (flag == 1 || flag1 == 1 || flag2 == 1) + cout << "NO"; + else + cout << "YES"; + putchar('\n'); + return 0; +} +int main() { + int t, s, q, ans = 0; + cin >> t >> s >> q; + int downloaded = s; + while (downloaded < t) { + downloaded += s * (q - 1); + s = downloaded; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + long n; + cin >> n; + long x, y; + long H[101] = {0}, V[101] = {0}; + for (long i = 0; i < n; i++) { + cin >> x >> y; + H[x]++; + V[y]++; + } + x = 0; + y = 0; + for (long i = 0; i < 101; i++) { + if (H[i] > 0) x++; + if (V[i] > 0) y++; + } + if (x < y) + cout << x << "\n"; + else + cout << y << "\n"; + return 0; +} +int main() { + int n, a; + set ai; + cin >> n; + for (int i = 0; i < n - 1; i++) { + cin >> a; + ai.insert(a); + } + for (int i = 1; i <= n; i++) { + if (ai.find(i) == ai.end()) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + string s, t; + int j = 0, c = 1; + cin >> s >> t; + for (int i = 0; i <= t.length(); i++) { + if (t[i] == s[j]) { j++, c++; } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, count = 0; + cin >> n >> m; + if (m < n) swap(n, m); + while (n != 0) { + n--; + count++; + } + if (count % 2 == 0) { + cout << "Malvika" << endl; + } else if (count % 2 != 0) { + cout << "Akshat" << endl; + } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np, drink, slice, salt, ans; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + drink = (k * l) / nl; + slice = (c * d); + salt = p / np; + ans = min(slice, salt); + ans = min(ans, drink); + ans /= n; + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, x, y, z; + cin >> x >> y >> a >> b; + z = (x * y) / __gcd(x, y); + c = b / z; + c -= (a - 1) / z; + cout << c << "\n"; + return 0; +} +long long int maxx, *a, n; +void mininc(long long int i, long long int curr); +int main() { + cin >> n; + a = new long long int[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + maxx = 1; + mininc(0, 0); + cout << maxx << endl; + return 0; +} +void mininc(long long int i, long long int curr) { + if (i == 0) { + curr = 1; + mininc(i + 1, curr); + } else if (i == n) { + if (curr > maxx) maxx = curr; + return; + } else if (a[i] > a[i - 1]) { + curr++; + mininc(i + 1, curr); + } else { + if (curr > maxx) maxx = curr; + curr = 1; + mininc(i + 1, curr); + } +} +string st; +vector l, r; +int main() { + cin >> st; + int n = st.size(); + for (int i = 0; i < n; i++) { + if (st[i] == 'l') + l.push_back(i + 1); + else + r.push_back(i + 1); + } + reverse(l.begin(), l.end()); + for (int i = 0; i < r.size(); i++) cout << r[i] << '\n'; + for (int i = 0; i < l.size(); i++) cout << l[i] << '\n'; + return 0; +} +long long mod = 1e9 + 7; +int main() { + string x; + cin >> x; + for (int i = 0; i < x.size(); i++) + if (x[i] == 'r') cout << i + 1 << '\n'; + for (int i = x.size() - 1; i >= 0; i--) + if (x[i] == 'l') cout << i + 1 << '\n'; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + string s[105], ss[105]; + cin >> n; + for (i = 0; i < n; i++) cin >> s[i]; + for (i = 0; i < n; i++) cin >> ss[i]; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) + if (s[i] == ss[j] && s[i] != "0" && ss[j] != "0") s[i] = "0", ss[j] = "0"; + } + int cou = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (s[i] != "0" && ss[j] != "0") + if (s[i].length() == ss[j].length()) s[i] = "0", ss[j] = "0", cou++; + } + } + cout << cou << endl; +} +int main() { + int n; + cin >> n; + cout << "25" << endl; + return 0; +} +int main() { + int n; + string a, b; + cin >> n >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) ans += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); + cout << ans << endl; + return 0; +} +int main() { + int a[13], i, j, n, k = 0, sum = 0; + cin >> n; + for (i = 0; i < 12; i++) { cin >> a[i]; } + if (n == 0) { + cout << "0" << endl; + } else { + sort(a, a + 12); + for (j = 11; j >= 0; j--) { + sum = sum + a[j]; + k++; + if (sum >= n) { + cout << k << endl; + break; + } + if (k == 12) { cout << "-1" << endl; } + } + } + return 0; +} +int main() { + int n, i, j, k = 1; + cin >> n; + for (i = 1; i <= (n + 1) / 2; i++) { + for (j = 1; j <= (n - k) / 2; j++) cout << "*"; + for (j = 1; j <= k; j++) cout << "D"; + for (j = 1; j <= (n - k) / 2; j++) cout << "*"; + cout << endl; + k += 2; + } + k = n - 2; + for (i = 1; i <= n / 2; i++) { + for (j = 1; j <= (n - k) / 2; j++) cout << "*"; + for (j = 1; j <= k; j++) cout << "D"; + for (j = 1; j <= (n - k) / 2; j++) cout << "*"; + cout << endl; + k -= 2; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + int l, r; + char c, d; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c >> d; + for (int j = l - 1; j < r; j++) + if (s[j] == c) s[j] = d; + } + cout << s << endl; +} +int main() { + long long int n; + cin >> n; + long long int sum = 0, cost, weight; + long long int mini = INT_MAX; + for (int i = 0; i < n; i++) { + cin >> weight >> cost; + if (cost < mini) mini = cost; + sum = sum + weight * mini; + } + cout << sum << "\n"; +} +int main() { + int m, n; + cin >> m >> n; + int g[1000000]; + for (int i = 1; i <= n - 1; i++) cin >> g[i]; + int a = 1; + while (a < n) { a += g[a]; } + if (a == n) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int c = 0; + string s; + cin >> s; + int a = s.length(); + sort(s.begin(), s.end()); + for (int i = 1; i < a; i++) { + if (s[i] != s[i - 1]) c++; + } + if ((c + 1) % 2 == 0) + cout << "CHAT WITH HER!\n"; + else + cout << "IGNORE HIM!\n"; + return 0; +} +int main() { + int n, i, j; + set vertical; + set horizontal; + cin >> n; + while (n--) { + cin >> i >> j; + vertical.insert(i); + horizontal.insert(j); + } + cout << min(vertical.size(), horizontal.size()) << endl; + return 0; +} +long long n; +int arr[200005]; +long long ini = 0, fin = 0; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + int ans = INT_MAX; + for (int i = 0; i * 2 < n; i++) ans = min(ans, arr[n / 2 + i] - arr[i]); + cout << ans << "\n"; + return 0; +} +long long fib[100]; +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (max(x, y) >= m) { + puts("0"); + return 0; + } + if (x <= 0 and y <= 0) { + puts("-1"); + return 0; + } + if (x > y) swap(x, y); + long long ans = 0; + if (x < 0) { + long long a = (abs(x) + y - 1) / y; + ans = a; + x += a * y; + } + if (x > y) swap(x, y); + fib[0] = x; + fib[1] = y; + for (int i = 1; fib[i] < m; ++i, ++ans) fib[i + 1] = fib[i] + fib[i - 1]; + cout << ans << endl; + return 0; +} +int main() { + string x[10]; + x[0] = "O-|-OOOO"; + x[1] = "O-|O-OOO"; + x[2] = "O-|OO-OO"; + x[3] = "O-|OOO-O"; + x[4] = "O-|OOOO-"; + x[5] = "-O|-OOOO"; + x[6] = "-O|O-OOO"; + x[7] = "-O|OO-OO"; + x[8] = "-O|OOO-O"; + x[9] = "-O|OOOO-"; + string s; + cin >> s; + for (int i = s.size() - 1; i >= 0; i--) { cout << x[s[i] - '0'] << endl; } + return 0; +} +int main() { + int num; + string p; + cin >> num; + for (int i = 1; i <= num; i++) { + if (i == 1) { + p = "I hate "; + } else if (i % 2 == 0) { + p = p + "that I love "; + } else if (i % 2 != 0) { + p = p + "that I hate "; + } + } + cout << p << "it\n"; + return 0; +} +int main() { + int n; + while (cin >> n) { + int sum1[1000] = {0}; + int sum2[1000] = {1}; + int sum = 0; + for (int i = 1; i < 50; i++) { + sum += i; + sum1[i - 1] = sum; + sum1[i] = sum1[i - 1] + i + 1; + sum2[i] = sum2[i - 1] + sum1[i]; + if ((sum2[i - 1] <= n) && (sum2[i] > n)) cout << i << endl; + } + } +} +const int N = 1e6; +int aa[N + 2]; +int main() { + int n, p; + cin >> n >> p; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + if (s == "half") + aa[i] = 0; + else + aa[i] = 1; + } + long long app, ans = 0; + for (int i = n; i >= 1; i--) { + if (i == n) + app = 1; + else + app = app * 2 + aa[i]; + ans += ((app / 2) * 1LL) * p; + if (app % 2) ans += (p / 2); + } + cout << ans << endl; + return 0; +} +int main() { + int N, M, Z; + cin >> N >> M >> Z; + int result = 0; + for (int minute = (1); minute <= (int)(Z); ++minute) { + if (minute % N == 0 and minute % M == 0) result += 1; + } + cout << result << "\n"; + return 0; +} +const int mod = 998244353; +long long qpow(long long x, long long y) { + long long s = 1; + while (y) { + if (y & 1) s = s * x % mod; + x = x * x % mod; + y >>= 1; + } + return s; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); + return x * f; +} +long long inve(long long x) { + return x == 1 ? 1 : (mod - mod / x) * inve(mod % x) % mod; +} +const int N = 1e4 + 5; +int n, h, a, b, m; +int ta, tb, fa, fb, ans; +int main() { + for (cin >> n >> h >> a >> b >> m; m; m--) { + cin >> ta >> fa >> tb >> fb; + if (fa < a && fb < a) + ans = a + a - fa - fb + abs(ta - tb); + else if (fa > b && fb > b) + ans = fa - b + fb - b + abs(ta - tb); + else + ans = abs(ta - tb) + abs(fa - fb); + if (ta == tb) ans = abs(fa - fb); + cout << ans << "\n"; + } + return 0; +} +int main() { + string l, r; + cin >> l >> r; + int n; + cin >> n; + string s1, s2; + cout << l << ' ' << r << endl; + for (int i = 0; i < n; i++) { + cin >> s1 >> s2; + if (s1 == l) { + l = s2; + } else if (s1 == r) { + r = s2; + } else if (s2 == l) { + l = s1; + } else if (s2 == r) { + r = s1; + } + cout << l << ' ' << r << endl; + } + return 0; +} +int main() { + string str; + cin >> str; + int d = 0; + for (int i = 0; i < str.size(); i++) d += str[i] != str[str.size() - 1 - i]; + if (d == 2 || (d == 0 && str.size() % 2)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +const int N = 1003; +int n; +int a[N]; +map mp; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + int ans = 0; + for (int i = 1; i <= n; ++i) { + if (a[i] == 0) continue; + mp[a[i]]++; + if (mp[a[i]] > 2) { + cout << "-1" << endl; + return 0; + } else if (mp[a[i]] == 2) + ++ans; + } + cout << ans << endl; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + long long int a, b, k, value; + cin >> a >> b >> k; + value = k / 2; + if (k % 2) { + cout << (a * (value + 1) - b * value) << endl; + } else { + cout << (a - b) * value << endl; + } + } + return 0; +} +int main() { + string str[8]; + for (int i = 0; i < 8; i++) { cin >> str[i]; } + int flag = 1; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 7; j++) { + if (str[i][j] == str[i][j + 1]) { flag = 0; } + } + } + flag == 1 ? cout << "YES" << endl : cout << "NO" << endl; + return 0; +} +int main() { + map m; + char ch[3] = {'F', 'M', 'S'}; + string str[3]; + cin >> str[0] >> str[1] >> str[2]; + int index = -1; + int flag = 0; + m["rock"] = "scissors"; + m["paper"] = "rock"; + m["scissors"] = "paper"; + if (str[0] == str[1] && m[str[2]] == str[0]) + cout << ch[2] << endl; + else if (str[2] == str[0] && m[str[1]] == str[0]) + cout << ch[1] << endl; + else if (str[2] == str[1] && m[str[0]] == str[1]) + cout << ch[0] << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) { + if (str[i] != '1' && str[i] != '4') { + cout << "NO" << endl; + return 0; + } + if (i == 0 && str[i] != '1') { + cout << "NO" << endl; + return 0; + } + if (str[i] == '4' && str[i + 1] == '4' && str[i + 2] == '4') { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +const int MOD = 1e9 + 7; +const int INF = INT_MAX; +const long long LINF = LLONG_MAX; +int ans; +long double t, s, q; +int main() { + cin >> t >> s >> q; + long double x = 0, z = 0, y = s; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; +} +const int maxn = 1e5 + 5; +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (x >= m || y >= m) { + cout << 0 << endl; + } else { + if (x <= 0 && y <= 0) { + cout << -1 << endl; + return 0; + } + long long ans = 0; + if (x + y < x) { + if (abs(y) % abs(x) == 0) { + ans += abs(y) / abs(x); + y = 0; + } else { + ans += abs(y) / abs(x) + 1; + y = ans * abs(x) + y; + } + } else if (x + y < y) { + if (abs(x) % abs(y) == 0) { + ans += abs(x) / abs(y); + x = 0; + } else { + ans += abs(x) / abs(y) + 1; + x = ans * abs(y) + x; + } + } + if (x > y) swap(x, y); + while (x < m && y < m) { + long long temp = x + y; + x = y; + y = temp; + ans++; + } + cout << ans << endl; + } +} +int main() { + int m[3] = {0, 0, 0}; + int a, b; + cin >> a >> b; + a = a % 6; + m[b] = 1; + while (a--) { + if (a % 2 == 0) { + int t; + t = m[0]; + m[0] = m[1]; + m[1] = t; + } else { + int q; + q = m[1]; + m[1] = m[2]; + m[2] = q; + } + } + for (int i = 0; i < 3; i++) { + if (m[i] == 1) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int a[1001]; + int n, k; + cin >> n >> k; + int ans = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + int i, j; + for (i = 0; i < n; i++) + if (a[i] > k) + break; + else + ans++; + for (j = n - 1; j > i; j--) { + if (a[j] > k) + break; + else + ans++; + } + cout << ans << endl; +} +int main() { + int n, m; + cin >> n >> m; + char a[115][115]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + } + int ans = 0; + for (int i = 0; i < n; ++i) { + bool wasBest = false; + for (int j = 0; j < m; ++j) { + bool isBest = true; + for (int k = 0; k < n; ++k) + if (a[k][j] > a[i][j]) isBest = false; + if (isBest) wasBest = true; + } + if (wasBest) ans++; + } + cout << ans << endl; + return 0; +} +int min(int a, int b) { + return (a > b ? b : a); +} +int main() { + int a, b, sum; + while (cin >> a >> b) { + sum = min(a, b); + if (sum % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } +} +inline long long read() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +long long a[11][11]; +int n; +int main() { + n = read(); + a[0][1] = 1; + for (int i = 1; i <= 10; i++) + for (int j = 1; j <= 10; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + cout << a[n][n] << endl; + return 0; +} +int main() { + long long int q; + cin >> q; + while (q--) { + long long int a, b, s = 0; + cin >> a >> b; + while (a && b) { + if (b > a) swap(a, b); + s += a / b; + a = a % b; + } + cout << s << endl; + } +} +int main() { + long long n; + cin >> n; + long long ans = 0; + while (n--) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + ans += (c - a + 1) * (d - b + 1); + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int f[n]; + for (int i = 1; i <= n; i++) { cin >> f[i]; } + int p = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if ((f[f[i]] == j) && (f[j] == i)) { + p = 1; + break; + } + } + } + if (p == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int ev, od; + while (cin >> ev >> od) { + if (fabs(ev - od) <= 1 && (ev != 0 || od != 0)) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + string res(s.size(), '0'); + int carry = 1; + for (size_t i = 0; i < n; i++) { + if (carry == 1 && s[i] == '1') { + res[i] = '0'; + carry = 1; + } else if (carry == 1 && s[i] == '0') { + res[i] = '1'; + carry = 0; + } else if (carry == 0 && s[i] == '0') { + res[i] = '0'; + } else if (carry == 0 && s[i] == '1') { + res[i] = '1'; + } + } + int ans = 0; + for (size_t i = 0; i < n; i++) { + if (res[i] != s[i]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, c, x, y, ans = 0; + cin >> n >> a >> b >> c; + int k = 1; + for (int i = 2; i <= n; i++) { + if (k == 1) { + if (a < b) + x = a, y = 2; + else + x = b, y = 3; + } + if (k == 2) { + if (a < c) + x = a, y = 1; + else + x = c, y = 3; + } + if (k == 3) { + if (b < c) + x = b, y = 1; + else + x = c, y = 2; + } + ans += x; + k = y; + } + cout << ans << endl; + return 0; +} +int main() { + long long x; + cin >> x; + for (int y = 1;; y++) { + x += 1; + long long temp = abs(x); + while (temp > 0) { + if (temp % 10 == 8) { + cout << y << endl; + break; + } + temp /= 10; + } + if (temp % 10 == 8) break; + } +} +long long dp[105]; +int x[105][105]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> dp[i]; } + while (m--) { + int i, j; + cin >> i >> j; + x[i][j] = 1; + x[j][i] = 1; + } + long long minx = 5000000; + for (int i = 2; i < n; i++) { + for (int j = i - 1; j > 0; j--) { + for (int k = i + 1; k <= n; k++) { + if (x[j][k] == 1 && x[j][i] == 1 && x[i][k] == 1) { + long long num = dp[i] + dp[j] + dp[k]; + minx = num < minx ? num : minx; + } + } + } + } + if (minx == 5000000) + cout << "-1" << endl; + else + cout << minx << endl; + return 0; +} +int main() { + int n, a, count1(0), extra0(0), extra0max(-1); + cin >> n; + while (n--) { + cin >> a; + if (a == 1) { + count1 += 1; + if (extra0 > 0) { extra0 -= 1; } + } else { + extra0 += 1; + if (extra0 > extra0max) { extra0max = extra0; } + } + } + cout << count1 + extra0max << endl; + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int ans1 = min(a, b); + int k = max(a, b); + int ans2 = (k - ans1) / 2; + cout << ans1 << " " << ans2 << endl; + } + return 0; +} +int n; +int curr; +vector factors; +int sum = 0; +int main() { + for (int i = 1; i <= 120; ++i) { + if (360 % i == 0) { + factors.push_back(i); + sum++; + } + } + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> curr; + bool printed = false; + for (int j = 0; j < sum && !printed; j++) { + if (curr == 180 - factors[j]) { + cout << "YES" << endl; + printed = true; + } + } + if (!printed) { cout << "NO" << endl; } + } + return 0; +} +int solve(int arr[], int n, int k) { + int t = 0; + for (int i = 0; i < n; i++) { + t += arr[i]; + int val = min(8, t); + k -= val; + t -= val; + if (k <= 0) return i + 1; + } + return -1; +} +int main() { + int n, k; + cin >> n >> k; + int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + cout << solve(arr, n, k) << endl; + return 0; +} +int main() { + int a, b, n, i, gc, m, k; + cin >> a >> b >> n; + for (i = 1; n >= 0; i++) { + if (i % 2 == 0) { + k = __gcd(b, n); + m = 0; + } else { + k = __gcd(a, n); + m = 1; + } + n = n - k; + if (n < 0) { + cout << m << endl; + return 0; + } + } +} +int main() { + string str; + cin >> str; + int len = str.length(); + int count = 0; + for (int i = 0; i < len; i++) { + if (str[i] == '4' || str[i] == '7') { count++; } + } + if (count == 4 || count == 7) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +const int N = 222222; +int n, x[N], res, c; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> x[i]; } + sort(x + 1, x + n + 1); + c = ((n - 2) / 2) + 1; + res = x[1 + c] - x[1]; + for (int i = 2; i <= n - c; i++) { + if (x[i + c] - x[i] < res) res = x[i + c] - x[i]; + } + cout << res << "\n"; + return 0; +} +int main() { + int n, max = 0, c = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (max < a[i]) max = a[i]; + } + for (int i = 0; i < n; i++) { + if (a[i] < max) { c = c + max - a[i]; } + } + cout << c << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int c = pow(2, a); + cout << b % c << endl; + return 0; +} +char a[110]; +int main() { + cin >> a; + int len = strlen(a); + int ans = 0; + for (int i = 0; i < len; i++) { + if (a[i] == 'V' && a[i + 1] == 'K') { ans++, a[i] = 'a', a[i + 1] = 'a'; } + } + int flag = 0; + for (int i = 0; i < len; i++) { + if ((a[i] == 'V' && a[i + 1] == 'V') || (a[i] == 'K' && a[i + 1] == 'K')) flag = 1; + } + cout << ans + flag << endl; +} +const int maxn = 1500; +char a; +int n; +int main() { + cin >> n; + int left = 0; + int right = 0; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a != '4' && a != '7') { + cout << "NO" << endl; + return 0; + } + if (i <= n / 2) + left += a - '0'; + else + right += a - '0'; + } + if (left == right) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x; + vector v(2); + for (int i = 0; i < n; i++) { + cin >> x; + v[(i % 3)] += x; + } + if (v[0] > v[1] and v[0] > v[2]) { + puts("chest"); + } else if (v[1] > v[2]) { + puts("biceps"); + } else + puts("back"); + return 0; +} +int main() { + string x, y; + cin >> x >> y; + cout << x << " " << y << endl; + int a; + cin >> a; + while (a--) { + string l, m; + cin >> l >> m; + if (x == l) { + x = m; + } else { + y = m; + } + cout << x << " " << y << endl; + } + return 0; +} +vector vv; +bool ada[105]; +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) { + string t; + cin >> t; + vv.push_back(t); + } + for (int i = 0; i < n; i++) { + string aa = vv[i]; + if (aa.substr(0, 3) == s) { + bool bal = 0; + string tuu = ""; + tuu += aa.substr(5, 3); + tuu += "->"; + tuu += aa.substr(0, 3); + for (int j = 0; j < n; j++) { + if (tuu == vv[j] && !ada[j] && !bal) { + bal = 1; + ada[j] = 1; + } + } + if (!bal) { + cout << "contest" << endl; + return 0; + } + } + } + cout << "home" << endl; +} +int main() { + int a[105], b[105], ant = 0, bnt = 0, n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i] >> b[i]; + if (a[i] & 1) ant++; + if (b[i] & 1) bnt++; + } + if (ant % 2 == 0 && bnt % 2 == 0) { + cout << 0 << endl; + } else if ((ant + bnt) % 2 != 0) { + cout << -1 << endl; + } else { + for (int i = 1; i <= n; i++) { + if (a[i] & 1 && b[i] % 2 == 0) return cout << 1 << endl, 0; + if (b[i] & 1 && a[i] % 2 == 0) return cout << 1 << endl, 0; + } + cout << -1 << endl; + } + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + a = a < b ? a : b; + b = 1; + for (int i = 2; i <= a; ++i) { b *= i; } + cout << b << endl; + return 0; +} +int main() { + int m, n, sum, i, j, wl; + cin >> n >> m; + sum = n * (n + 1) / 2; + j = m % sum; + wl = 1; + while (j > 0) { + if (j >= wl) { + j -= wl; + wl++; + } else + break; + } + cout << j << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s; + cin >> s; + int l, r; + char c1, c2; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + for (int j = l - 1; j <= r - 1; j++) { + if (s[j] == c1) s[j] = c2; + } + } + cout << s << endl; + return 0; +} +int main() { + int k, r; + cin >> k >> r; + if (k % 10 == 0 || k % 10 == r) { + cout << 1 << endl; + return 0; + } + for (int i = 2; i <= 10; i++) { + if ((k * i) % 10 == 0 || (k * i) % 10 == r) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int a, b, x, y, c = 0; + cin >> a >> b; + x = abs(a - b); + cout << min(a, b) << " " << x / 2 << endl; + return 0; +} +int main() { + int x, j, c, a, b; + cin >> x; + vector V; + while (x > 0) { + c = x % 2; + V.push_back(c); + x = x >> 1; + } + j = 0; + for (int i = 0; i < V.size(); i++) { + if (V[i] == 1) { j++; } + } + cout << j << endl; +} +int main() { + long long int k, n, w, sum = 0; + int i; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { sum += (i * k); } + if (sum <= n) + cout << "0" << endl; + else + cout << sum - n << endl; + return 0; +} +const int N = 1e5 + 10, INF = 1e9 + 7; +int main() { + long long n, k; + cin >> n >> k; + cout << ((n / k) % 2 ? "YES" : "NO") << '\n'; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int l = 0; + while (n * m != 0) { + m = m - 1; + n = n - 1; + l++; + } + if (l % 2) { + cout << "Akshat" << endl; + } else { + cout << "Malvika" << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + cin >> a[0]; + int diff = 0; + for (int i = 1; i < n; i++) { + cin >> a[i]; + diff = max(diff, a[i] - a[i - 1]); + } + int m = 100000; + for (int i = 1; i < n - 1; i++) { m = min(a[i + 1] - a[i - 1], m); } + cout << max(diff, m) << endl; +} +int main() { + long long int n, k, d, c; + cin >> n >> k; + d = n / (2 * k + 2); + cout << d << " " << k * d << ' ' << n - d - k * d << '\n'; +} +int main() { + long int n, t, c = 0; + cin >> n >> t; + long int a[n]; + for (long int i = 0; i < n; i++) { + cin >> a[i]; + if (t > 0) { + t -= 86400 - a[i]; + c++; + } + } + cout << c << endl; +} +int main() { + int t; + cin >> t; + for (int i = 1; i <= t; i++) { + int n; + cin >> n; + int kk = 180 - n; + if (360 % kk == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << (n / 2) + 1 << endl; +} +int main() { + long long int a, b, c, n, i, count = 0; + cin >> a >> b >> c; + cin >> n; + long long int x[n]; + for (i = 0; i < n; i++) { + cin >> x[i]; + if (x[i] > b && x[i] < c) count++; + } + cout << count << endl; +} +int main() { + unsigned long long n, k, res; + cin >> n >> k; + res = n / k; + if (res & 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool lexi_comp(const string &a, const string &b) { + int n = min(a.size(), b.size()); + for (int i = 0; i < n; i++) { + if (a[i] != b[i]) { return a[i] < b[i]; } + } + return a.size() < b.size(); +} +bool isPrefix(const string &a, const string &b) { + if (b.size() < a.size()) { return false; } + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[i]) { return false; } + } + return true; +} +int main() { + string a, b, ans; + int n; + cin >> a >> n; + ans = a + string(100, 'z'); + bool ok = false; + for (int i = 0; i < n; i++) { + cin >> b; + if (isPrefix(a, b)) { + ok = true; + if (lexi_comp(b, ans)) { swap(b, ans); } + } + } + if (ok) { + cout << ans << endl; + } else { + cout << a << endl; + } + return 0; +} +int main() { + cout << "Karen" << endl; +} +string GetStone(string color) { + if (color == "purple") { + return "Power"; + } else if (color == "green") { + return "Time"; + } else if (color == "blue") { + return "Space"; + } else if (color == "orange") { + return "Soul"; + } else if (color == "red") { + return "Reality"; + } else { + return "Mind"; + } +} +bool FindNotFound(string stone, vector stones) { + bool ret = false; + for (int i = 0; i < stones.size(); i++) { + if (stone == stones.data()[i]) { ret = true; } + } + return ret; +} +int main() { + vector stones; + stones.push_back("Power"); + stones.push_back("Time"); + stones.push_back("Space"); + stones.push_back("Soul"); + stones.push_back("Reality"); + stones.push_back("Mind"); + int n = 0; + cin >> n; + vector st; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + st.push_back(GetStone(s)); + } + vector not_found; + for (int j = 0; j < stones.size(); j++) { + if (!FindNotFound(stones.data()[j], st)) { not_found.push_back(stones.data()[j]); } + } + cout << not_found.size() << endl; + for (int i = 0; i < not_found.size(); i++) { cout << not_found.data()[i] << endl; } + return 0; +} +int main() { + long long cnt, l = 0, t, n, m, z; + cin >> t; + for (int i = 0; i < t; ++i) { + cnt = 0; + cin >> n >> m >> z; + if (z % 2 == 1) { cnt += n; } + cnt += (n - m) * (z / 2); + cout << cnt << '\n'; + } + return 0; +} +int main() { + string a[20], b[20], c[20], x, y; + int p1 = 0, p2 = 0; + getline(cin, x); + getline(cin, y); + for (int i = 0; i < x.length(); i += 2) { + if ((x.at(i) == '[') && (y.at(i) == '(')) { + p1++; + } else if ((y.at(i) == '[') && ((x.at(i) == '('))) { + p2++; + } else if (((x.at(i) == '(') && (y.at(i) == '8'))) { + p1++; + } else if ((y.at(i) == '(') && ((x.at(i) == '8'))) { + p2++; + } else if (((x.at(i) == '8') && (y.at(i) == '['))) { + p1++; + } else if ((y.at(i) == '8') && ((x.at(i) == '['))) { + p2++; + } + } + if (p1 > p2) + cout << "TEAM 1 WINS" << endl; + else if (p1 < p2) + cout << "TEAM 2 WINS" << endl; + else if (p1 == p2) + cout << "TIE" << endl; +} +int main() { + double a[200001], sum = 0; + int n, s = 0, i; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { sum = sum + a[i]; } + for (i = 0; i < n; i++) { + s = s + a[i]; + if (s >= ceil(sum / 2)) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int main() { + int n, x, sum = 0; + cin >> n >> x; + for (int i = 0, k = 0; i < n; i++) { + cin >> k; + sum += k; + } + sum = abs(sum); + cout << sum / x + (sum % x ? 1 : 0) << endl; +} +const double pi = 3.1415926; +const int maxn = 1e5 + 10; +int n, d; +string s; +int ans = 0; +int flag = 0; +int main() { + cin >> n >> d; + int maxx = 0; + for (int i = 0; i < d; i++) { + cin >> s; + for (int j = 0; j < n; j++) { + if (s[j] == '0') { + flag = 1; + break; + } + if (s[j] == '1') flag = 0; + } + if (flag == 1) { + ans++; + maxx = max(ans, maxx); + } else + ans = 0; + } + cout << maxx << endl; + return 0; +} +int main() { + string s; + cin >> s; + char prev = s[0]; + int cnt = 1; + int ans = 0; + for (int i = 1; i < s.size(); i++) { + if (s[i] == prev) + cnt++; + else { + if (cnt % 2 == 0) ans++; + cnt = 1; + prev = s[i]; + } + } + if (cnt % 2 == 0) ans++; + cout << ans << endl; + return 0; +} +string getNum(long long int n) { + if (n == 0) { + return "O-|-OOOO"; + } else if (n == 1) { + return "O-|O-OOO"; + } else if (n == 2) { + return "O-|OO-OO"; + } else if (n == 3) { + return "O-|OOO-O"; + } else if (n == 4) { + return "O-|OOOO-"; + } else if (n == 5) { + return "-O|-OOOO"; + } else if (n == 6) { + return "-O|O-OOO"; + } else if (n == 7) { + return "-O|OO-OO"; + } else if (n == 8) { + return "-O|OOO-O"; + } else if (n == 9) { + return "-O|OOOO-"; + } +} +int main() { + string ans = ""; + long long int n; + cin >> n; + if (n == 0) { + cout << getNum(0) << endl; + return 0; + } + while (n > 0) { + long long int r = n % 10; + cout << getNum(r) << endl; + n = n / 10; + } + return 0; +} +int main() { + long long a, b, c, d; + while (cin >> a >> b >> c >> d) { + long long ans = d - a - b + c; + if (ans > 0 && a >= c && b >= c) + cout << ans << endl; + else + cout << -1 << endl; + } +} +int main() { + int n; + cin >> n; + int cont = 0; + int sumador = 1; + int i = 1; + while (n > 0 && n >= sumador) { + n = n - sumador; + cont++; + i++; + sumador = sumador + i; + } + cout << cont << "\n"; + return 0; +} +int main() { + int x; + string s = "qwertyuiopasdfghjkl;zxcvbnm,./", m, a; + char z; + cin >> z >> m; + if (z == 'R') { + for (int i = 0; i < m.size(); i++) { + for (int j = 0; j < s.size(); j++) { + if (m[i] == s[j]) x = j; + } + a += s[x - 1]; + } + } else { + for (int i = 0; i < m.size(); i++) { + for (int j = 0; j < s.size(); j++) { + if (m[i] == s[j]) x = j; + } + a += s[x + 1]; + } + } + cout << a << endl; + return 0; +} +int main() { + int a[7], sum = 0; + for (int i = 0; i < 6; i++) { cin >> a[i], sum += a[i]; } + if (sum % 2 == 1) { + cout << "NO" << endl; + return 0; + } + sum /= 2; + for (int i = 1; i <= 4; i++) { + for (int r = i + 1; r <= 5; r++) { + for (int y = r + 1; y <= 6; y++) { + if (a[i] + a[r] + a[y] == sum) { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + return 0; +} +long long a, b, n; +inline long long read() { + long long tmp = 1, x = 0; + char ch = getchar(); + while (!isdigit(ch)) { + if (ch == '-') tmp = -1; + ch = getchar(); + } + while (isdigit(ch)) { + x = x * 10 + ch - 48; + ch = getchar(); + } + return tmp * x; +} +int main() { + n = read(); + for (long long i = 1; i <= n; i++) a |= read(); + for (long long i = 1; i <= n; i++) b |= read(); + cout << a + b << endl; + return 0; +} +int main() { + int a, b, c, d, misha, vasya; + cin >> a >> b >> c >> d; + misha = max(3 * a / 10, a - a / 250 * c); + vasya = max(3 * b / 10, b - b / 250 * d); + if (misha > vasya) { + cout << "Misha" << endl; + } else if (vasya > misha) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } + return 0; +} +int main() { + int k; + cin >> k; + long long a, b, t; + for (int i = 1; i <= k; i++) { + cin >> a >> b >> t; + cout << (a - b) * (t / 2) + (t % 2) * a << endl; + } +} +int a[1000]; +int flip(int n, int i, int j) { + int b[1000]; + for (int i = 0; i < n; i++) b[i] = a[i]; + int count = 0; + for (int k = i; k <= j; k++) { + if (b[k] == 0) { + b[k] = 1; + } else + b[k] = 0; + } + for (int k = 0; k < n; k++) { + if (b[k] == 1) count++; + } + return count; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int max = -1; + for (int i = 0; i < n; i++) { + for (int j = i; j < n; j++) { + int count = flip(n, i, j); + if (count > max) max = count; + } + } + cout << max << endl; + return 0; +} +int main() { + long long n, aexc, bexc, exc, odd, even, flag; + cin >> n; + long long a[n], b[n], i, ac[6], bc[6]; + for (i = 0; i < 6; i++) { + ac[i] = 0; + bc[i] = 0; + } + for (i = 0; i < n; i++) { + cin >> a[i]; + ac[a[i]]++; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + bc[b[i]]++; + } + exc = 0; + aexc = 0; + bexc = 0; + odd = 0; + even = 0; + flag = 0; + for (i = 1; i < 6; i++) { + if (ac[i] % 2 == bc[i] % 2) { + if (ac[i] > bc[i]) { + aexc += (ac[i] - bc[i]); + } else { + bexc += (bc[i] - ac[i]); + } + } else { + flag = -1; + break; + } + } + if ((flag == -1) || (aexc % 2 == 1) || (bexc % 2 == 1)) + cout << -1; + else { + if (aexc > bexc) { + exc = (aexc / 2); + } else { + exc = (bexc / 2); + } + cout << exc; + } + cout << endl; +} +int ans, t, s, q; +int main() { + ans = 0; + cin >> t >> s >> q; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; + return 0; +} +const long long N = 1011; +string s; +long long n, p; +long long cel[N]; +long long ans[N]; +bool ok = false; +void encontrado(long long pos, long long val) { + ans[pos] = val; + if (pos == 0) { + ok = true; + return; + } + pos--; + for (long long i = 0; i < p; i++) { + if (pos + 2 < n) { + if (i != ans[pos + 1] && i != ans[pos + 2]) { + encontrado(pos, i); + if (ok) return; + } + } else if (pos + 1 < n) { + if (i != ans[pos + 1]) { + encontrado(pos, i); + if (ok) return; + } + } + } + return; +} +void brute_force(long long pos) { + for (long long i = cel[pos] + 1; i < p; i++) { + if (pos + 2 < n) { + if (i != cel[pos + 1] && i != cel[pos + 2]) { + encontrado(pos, i); + if (ok) return; + } + } else if (pos + 1 < n) { + if (i != cel[pos + 1]) { + encontrado(pos, i); + if (ok) return; + } + } else { + encontrado(pos, i); + if (ok) return; + } + } + if (!ok && pos + 1 < n) { brute_force(pos + 1); } + return; +} +int main() { + cout.precision(10); + cout << fixed; + cin >> n >> p; + cin >> s; + reverse(s.begin(), s.end()); + for (long long i = 0; i < n; i++) { + cel[i] = s[i] - 'a'; + ans[i] = cel[i]; + } + brute_force(0); + if (!ok) { + cout << "NO" << endl; + } else { + for (long long i = n - 1; i >= 0; i--) { cout << char(ans[i] + 'a'); } + cout << endl; + } + return 0; +} +int a[200005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + int len = (n - 2) / 2; + int ans = 1e9; + for (int i = 1; i <= n; i++) { + if (i + len + 1 > n) break; + ans = min(ans, a[i + len + 1] - a[i]); + } + cout << ans << endl; +} +bool isit(long long x, long long n, long long p) { + long long t = x; + for (long long i = 2; i <= n - 1; i++) { + x = ((x % p) * (t % p)) % p; + if ((x - 1) % p == 0) return false; + } + x *= t; + x--; + if (x % p == 0) return true; +} +int main() { + long long n; + cin >> n; + if (n == 2) { + cout << 1 << endl; + return 0; + } + long long cnt = 0; + for (long long i = 2; i < n; i++) { + if (isit(i, n - 1, n)) { cnt++; } + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int t[n]; + for (int i = 0; i < n; i++) cin >> t[i]; + int ans; + for (int i = 100; i >= 1; i--) { + bool flag = 0; + for (int j = 0; j < n; j++) { + if (t[j] % i == 0) + continue; + else { + flag = 1; + break; + } + } + if (flag == 0) { + cout << n * i << endl; + return 0; + } + } +} +int main() { + long long int n, ans; + cin >> n; + if (n >= 0) { + cout << n << endl; + return 0; + } else { + int m = abs(n); + int t = m % 10; + m /= 10; + int t1 = m % 10; + m = abs(n); + if (t > t1) + ans = m / 10; + else if (t <= t1) + ans = (m / 100) * 10 + t; + } + if (ans != 0) + cout << "-" << ans << endl; + else + cout << ans << endl; + return 0; +} +int main() { + long long int n, k, p; + cin >> n >> k; + p = n / 2; + long long int y = p / (k + 1); + if (y > 0) { + cout << y << " " << k * y << " " << n - (k + 1) * y << endl; + return 0; + } + cout << 0 << " " << 0 << " " << n << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << "25" << endl; +} +int n, m, i; +int main() { + string s; + cin >> n >> m; + cin >> s; + sort(s.begin(), s.end()); + int cnt = -1, num = 0; + for (int i = 0; i < n; i++) + if (s[i] >= cnt + 2 && m) { + cnt = s[i]; + num += s[i] - 'a' + 1; + m -= 1; + } + if (m) + cout << -1 << endl; + else + cout << num << endl; + ; +} +int main() { + long long n; + cin >> n; + long long a[n]; + string s; + cin >> s; + for (long long i = (0); i < (n); i++) a[i] = s[i] - '0'; + long long ans = 0; + for (long long i = (0); i < (n); i++) { + if (a[i]) + ans++; + else + break; + } + if (ans != n) + cout << ans + 1 << "\n"; + else + cout << ans << "\n"; +} +int gcd(int n) { + int ans = 1; + for (size_t i = 2; i * i <= n; i++) { + if (n % i == 0) ans = i; + } + return ans; +} +int main() { + int n; + cin >> n; + int column = gcd(n); + cout << column << ' ' << n / column << '\n'; + return 0; +} +int main() { + string s1, s2; + getline(cin, s1); + getline(cin, s2); + int t1 = 0, t2 = 0; + for (int i = 0; i < s1.size(); i += 2) { + if (s1[i] == '8') { + if (s2[i] == '(') + t2++; + else if (s2[i] == '[') + t1++; + } else if (s1[i] == '(') { + if (s2[i] == '8') + t1++; + else if (s2[i] == '[') + t2++; + } else { + if (s2[i] == '8') + t2++; + else if (s2[i] == '(') + t1++; + } + } + if (t1 > t2) + puts("TEAM 1 WINS"); + else if (t2 > t1) + puts("TEAM 2 WINS"); + else + puts("TIE"); + return 0; +} +int main() { + int T, n, m; + cin >> m >> n; + cout << (n / m + (n % m ? 1 : 0)) << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector p; + long long int a = 0; + for (int i = 0; i < n; i++) { + string h; + cin >> h; + p.push_back(h); + int y = 0; + for (int j = 0; j < h.size(); j++) + if (h[j] == 'C') y++; + y--; + if (y) a += ((y + 1) * y) / 2; + } + for (int i = 0; i < p[0].size(); i++) { + int y = 0; + for (int j = 0; j < p.size(); j++) { + if (p[j][i] == 'C') y++; + } + y--; + if (y) a += ((y + 1) * y) / 2; + } + cout << a << endl; + return 0; +} +int main() { + long long int a; + int b; + cin >> a >> b; + for (int i = 0; i < b; i++) { + if (a % 10 != 0) { + a--; + } else { + a = a / 10; + } + } + cout << a << endl; + return 0; +} +int main() { + long long int t; + cin >> t; + while (t--) { + long long int n; + cin >> n; + if (360 % (180 - n) == 0) + cout << "YES" << endl; + else { + cout << "NO" << endl; + } + } +} +int main() { + int n; + cin >> n; + int A[n], i, j, k, t, v, a = 0, b = 0; + for (i = 0; i < n; i++) { + cin >> A[i]; + a += A[i]; + } + for (i = 1; i < 6; i++) { + if ((a + i) % (n + 1) != 1) b++; + } + cout << b << endl; + return 0; +} +bool pd(char c) { + return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); +} +string str, str1; +int n, i; +int main() { + cin >> n; + getline(cin, str1); + getline(cin, str); + i = 2; + while (i <= str.size()) { + if (pd(str[i - 1]) && pd(str[i - 2])) { + str.erase(str.begin() + i - 1); + } else + i++; + } + cout << str << endl; + return 0; +} +const int maxn = 1000010; +const int MAXM = 500000; +int main() { + string t; + cin >> t; + string in[5]; + bool flag = false; + for (int i = 0; i < 5; i++) { + cin >> in[i]; + if (in[i][0] == t[0] || in[i][1] == t[1]) flag = true; + } + flag ? cout << "YES" << endl : cout << "NO" << endl; + return 0; +} +int value[101]; +int main() { + int n, k = -1, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> value[i]; + sum += value[i]; + if (value[i] > k) k = value[i]; + } + while (k * n - sum <= sum) { k++; } + cout << k << endl; +} +int main() { + int n; + cin >> n; + if (n == 0) { + cout << "O-|-OOOO" << endl; + return 0; + } + while (n > 0) { + int num = n % 10; + if (num >= 5) { + cout << "-O|"; + num -= 5; + } else { + cout << "O-|"; + } + for (int i = 0; i < num; i++) cout << "O"; + cout << "-"; + for (int i = 0; i < 4 - num; i++) cout << "O"; + n /= 10; + cout << endl; + } + return 0; +} +int n, k; +int main() { + cin >> n >> k; + k = 240 - k; + for (int i = 1; i <= n; i++) { + if (i * 5 > k) { + cout << i - 1 << endl; + return 0; + } + k -= i * 5; + } + cout << n << endl; + return 0; +} +int n; +int a[102]; +int dp[102][5]; +int go(int index, int prev) { + if (index == n) return 0; + if (dp[index][prev] != -1) return dp[index][prev]; + int &ans = dp[index][prev]; + if (prev == 0) { + if (a[index] == 0) + ans = 1 + go(index + 1, 0); + else if (a[index] == 1 || a[index] == 2) + ans = go(index + 1, a[index]); + else + ans = min(go(index + 1, 1), go(index + 1, 2)); + } else if (prev == 1) { + if (a[index] == 0 || a[index] == 1) + ans = 1 + go(index + 1, 0); + else + ans = min(1 + go(index + 1, 0), go(index + 1, 2)); + } else { + if (a[index] == 0 || a[index] == 2) + ans = 1 + go(index + 1, 0); + else + ans = min(1 + go(index + 1, 0), go(index + 1, 1)); + } + return ans; +} +int main() { + cin >> n; + for (int i = 0; i <= 101; i++) { + for (int j = 0; j < 5; j++) dp[i][j] = -1; + } + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = go(0, 0); + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; +} +int A[100010]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> A[i]; + sort(A, A + n); + reverse(A, A + n); + vector ans; + cout << A[0] << " "; + for (int i = n - 2; i >= 1; i--) cout << A[i] << " "; + cout << A[n - 1] << '\n'; +} +int main() { + int n, m; + cin >> n >> m; + vector x; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + x.push_back(tmp); + } + x.push_back(1e9); + vector y; + for (int i = 0; i < m; i++) { + int y1, y2, tmp; + cin >> y1 >> y2 >> tmp; + if (y1 == 1) y.push_back(y2); + } + sort(x.begin(), x.end()); + sort(y.begin(), y.end()); + int j = 0; + int ans = 1e9; + for (int i = 0; i <= n; i++) { + while (j < y.size() && y[j] < x[i]) j++; + if (ans > (i + y.size() - j)) ans = i + y.size() - j; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a = n / 2; + int sum = a * 3; + cout << sum << endl; + return 0; +} +int main() { + int lenp, n, c, maximo = 0; + cin >> n; + char v[n][1001]; + for (int k = 0; k < n; k++) { cin >> v[k]; } + int i, j; + for (i = 'a'; i <= 'z'; i++) { + for (j = i; j <= 'z'; j++) { + c = 0; + int p, q; + for (p = 0; p < n; p++) { + lenp = strlen(v[p]); + for (q = 0; q < lenp; q++) { + if (v[p][q] != i && v[p][q] != j) break; + } + if (q == lenp) { c = c + lenp; } + } + maximo = max(maximo, c); + } + } + cout << maximo << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int arr[110], k = 0, brr[110] = {0}; + while (m--) { + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int mx = arr[0], ans = 0; + for (int i = 1; i < n; i++) { + if (mx < arr[i]) { + mx = arr[i]; + ans = i; + } + } + brr[ans]++; + } + int mx = 0, ans = -1; + for (int i = 0; i < n; i++) { + if (mx < brr[i]) { + mx = brr[i]; + ans = i + 1; + } + } + cout << ans << endl; +} +int main() { + int n, x, one_cnt = 0, len_max = 0, len_cur = 0; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> x; + if (x == 0) { + if (++len_cur > len_max) len_max = len_cur; + } else { + if (--len_cur < 0) len_cur = 0; + one_cnt++; + } + } + cout << (one_cnt + (len_max == 0 ? -1 : len_max)) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) + cout << n / 2 << endl; + else + cout << -(n + 1) / 2 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long num = n / 2; + long long t = k + 1; + long long op = num / t; + cout << op << " " << k * op << " " << n - op - k * op << endl; +} +int v[700]; +int main() { + int n, m, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + if (v[m] == 0 && m != 0) { + sum++; + v[m] = 1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int sf = 0, st = 0; + int n; + string home, go, from = "\0", to = "\0"; + cin >> n >> home; + for (int i = 0; i < n; i++) { + cin >> go; + for (int i = 0; i < 3; i++) from.push_back(go[i]); + for (int i = 5; i < 8; i++) to.push_back(go[i]); + if (from == home) sf++; + if (to == home) st++; + from = "\0"; + to = "\0"; + } + if (sf == st) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +long long gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); +} +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) <= gcd(a, b)) + cout << "Equal" << endl; + else if (a < b) + cout << "Dasha" << endl; + else + cout << "Masha" << endl; +} +const int max_n = 1e3 + 10; +long long a[max_n]; +long long n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (a[0] == 1) return cout << -1 << '\n', 0; + cout << 1 << '\n'; + return 0; +} +int main() { + long long int n, m; + cin >> n >> m; + vector a(n); + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + long long int sum = 0; + long long int mini, maxi; + for (long long int i = 0; i < n - 1; i++) { sum = sum + abs(a[n - 1] - a[i]); } + if (sum >= m) + mini = a[n - 1]; + else + mini = a[n - 1] + (m - sum + n - 1) / n; + cout << mini << " " << a[n - 1] + m << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a = 0, b = 0, c = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x == 1) a++; + if (x == 2) b++; + if (x == 3) c++; + } + if (a >= b && a >= c) + cout << b + c << endl; + else if (b >= a && b >= c) + cout << a + c << endl; + else if (c >= a && c >= b) + cout << a + b << endl; + return 0; +} +const int maxn = 1e5 + 10; +int C(int x) { + if (!x) return 0; + return x * (x - 1) / 2; +} +int main() { + int n, ans = 0; + string s[101]; + int fa[101], cntc[101], cntr[101]; + memset(cntc, 0, sizeof(cntc)); + memset(cntr, 0, sizeof(cntr)); + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (s[i][j] == 'C') { + cntc[i]++; + cntr[j]++; + } + } + for (int i = 0; i < n; i++) ans += C(cntc[i]) + C(cntr[i]); + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int z = 0; + int xay; + for (int i = 1; i <= c; i++) { z = z + (i * a); } + if (z > b) { + xay = z - b; + } else if (z <= b) { + xay = 0; + } + cout << xay << endl; +} +long long power(long long b, long long p) { + if (p == 0) return 1; + long long ans = 1; + while (p > 1) { + if (p % 2 == 0) { + b *= b; + b %= 1000000007; + p /= 2; + } else { + ans *= b; + ans %= 1000000007; + p -= 1; + } + } + ans *= b; + ans %= 1000000007; + return ans; +} +int main() { + string s; + cin >> s; + long long n = s.size(); + long long f = 0; + for (int i = n - 1; i >= 0; i--) { + if (f == 0 && s[i] == '0') + continue; + else if (f == 0 && s[i] == '1') { + f = power(2, 2 * (n - 1 - i)); + } else if (f != 0 && s[i] == '1') { + f = ((2 * f) % 1000000007 + power(2, 2 * (n - 1 - i))) % 1000000007; + } else if (f != 0 && s[i] == '0') { + f = (2 * f) % 1000000007; + } + } + cout << f << endl; +} +long long n, k, x; +int main() { + cin >> n >> k; + x = n / k; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +string a, b[5]; +bool ada() { + for (int i = 0; i < 5; i++) { + if (b[i][0] == a[0] || b[i][1] == a[1]) return true; + } + return false; +} +int main() { + cin >> a; + int k = 5; + while (k--) cin >> b[k]; + if (ada()) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int x = 0; + while (true) { + if (n == 0 || m == 0) + break; + else { + n--; + m--; + x++; + } + } + if (x % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + for (int i = 0; i < n - 1; i++) { + if (i % 2 != 0) { + v.erase(v.begin()); + } else { + v.pop_back(); + } + } + cout << v[0] << endl; +} +int main() { + long long w, h, u1, h1, u2, h2; + cin >> w >> h >> u1 >> h1 >> u2 >> h2; + while (h != 0) { + w += h; + if (h == h1) w -= u1; + if (h == h2) w -= u2; + if (w < 0) w = 0; + h--; + } + cout << w << endl; +} +int main() { + int i, n, a, b, cost = 0, j; + cin >> n >> a >> b; + int ara1[n], ara2[n]; + for (i = 0, j = n - 1; i < n; i++, j--) { + cin >> ara1[i]; + ara2[j] = ara1[i]; + } + for (i = 0; i < n; i++) { + if (ara2[i] == 2 && ara2[i] != ara1[i]) { + ara2[i] = ara1[i]; + if (ara2[i] == 0) { + cost = cost + a; + } else { + cost = cost + b; + } + } else if (ara2[i] == 2 && ara2[i] == ara1[i]) { + if (a <= b) { + cost = cost + a; + } else { + cost = cost + b; + } + } + } + for (i = 0, j = n - 1; i < n; i++, j--) { + if (ara2[j] != ara2[i]) { + cout << -1 << endl; + return 0; + } + } + cout << cost << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + bool mirrorup = y < 0; + bool mirrorright = x < 0; + if (mirrorup) y = -y; + if (mirrorright) x = -x; + int ax = 0; + int ay = y + x; + int cy = 0; + int cx = x + y; + if (mirrorup) ay = -ay; + if (mirrorright) { + swap(ax, cx); + swap(ay, cy); + ax = -ax; + } + cout << ax << ' ' << ay << ' '; + cout << cx << ' ' << cy; + cout << endl; +} +int main() { + int q; + cin >> q; + while (q--) { + long long int l, r; + cin >> l >> r; + long long int m = 1, i = 0; + while ((l | m) <= r) { + l = l | m; + m = m | (1LL << i++); + } + cout << l << endl; + } + return 0; +} +int main() { + char a[102]; + int t, f; + while (cin >> a) { + t = 0; + f = 0; + int len = strlen(a); + for (int i = 0; i < len; i++) { + if (a[i] == 'V' && a[i + 1] == 'K') { + t++; + } else if (a[i] == 'V' && a[i + 1] == 'V' && a[i + 2] != 'K') { + f = 1; + } else if (a[i] == 'K' && a[i + 1] == 'K' && a[i - 1] != 'V') { + f = 1; + } + } + cout << t + f << endl; + } + return 0; +} +int main() { + string aset = "qwertyuiopasdfghjkl;zxcvbnm,./"; + char ch; + cin >> ch; + string mole; + cin >> mole; + int lim = aset.size(); + int lim2 = mole.size(); + int i, j; + if (ch == 'R') { + for (i = 0; i < lim2; i++) { + if (mole[i] == 'q' || mole[i] == 'a' || mole[i] == 'z') + cout << mole[i]; + else + for (j = 0; j < lim; j++) { + if (mole[i] == aset[j]) { cout << aset[j - 1]; } + } + } + } else { + for (i = 0; i < lim2; i++) { + if (mole[i] == 'p' || mole[i] == ';' || mole[i] == '/') + cout << mole[i]; + else + for (j = 0; j < lim; j++) { + if (mole[i] == aset[j]) { cout << aset[j + 1]; } + } + } + } + cout << endl; + return 0; +} +const long long MAX = 1e5 + 5; +const long long MAX2 = 11; +const int MOD = 1000000000 + 7; +const long long INF = 20000; +const int nr[] = {1, 0, -1, 0, 1, 1, -1, -1}; +const int nc[] = {0, 1, 0, -1, 1, -1, 1, -1}; +int n, a, b, x, y, ans; +int main() { + cout << fixed << setprecision(6); + cin >> n; + while (n--) { + cin >> a >> b >> x >> y; + ans += (x - a + 1) * (y - b + 1); + } + cout << ans << "\n"; + return 0; +} +int main() { + long long int t, s, a, b, c, num; + cin >> t; + while (t--) { + num = 0; + cin >> s >> a >> b >> c; + num += s / c; + int x = s / a / c; + num += x * b; + cout << num << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + long long *a = new long long[n]; + for (long long i = 0; i < n; i++) cin >> a[i]; + long long sum = 0; + sort(a, a + n); + for (long long i = 1; i < n; i++) { sum = sum + (i + 1) * a[i - 1]; } + sum = sum + n * a[n - 1]; + cout << sum << endl; + return 0; +} +string x, y; +int s; +int main() { + int n; + cin >> n >> x >> y; + for (int i = 0; i < n; i++) { + int a = x[i] - 48; + int b = y[i] - 48; + int j = abs(a - b); + int h; + if (a > b) + h = 9 - a + b + 1; + else + h = 9 - b + a + 1; + if (j < h) + s += j; + else + s += h; + } + cout << s << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int num = 0; + while (n) { + num++; + n = n >> 1; + } + cout << num << endl; + } + return 0; +} +int n, a, b, c; +int main() { + cin >> n >> a >> b >> c; + cout << max(min(min(a, b) * (n - 1), min(a, b) + c * (n - 2)), 0) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a, b, c; + cin >> a >> b >> c; + int result = 0; + int location = 1; + for (int i = 0; i < n - 1; i++) { + if (location == 1) { + result += min(a, b); + if (a > b) + location = 3; + else + location = 2; + } else if (location == 2) { + result += min(a, c); + if (a > c) + location = 3; + else + location = 1; + } else { + result += min(b, c); + if (b > c) + location = 2; + else + location = 1; + } + } + cout << result << endl; + return 0; +} +int main() { + char str[21]; + int a, b; + cin >> str; + a = strlen(str); + cout << a * 25 + 26 << endl; + return 0; +} +int main() { + set s; + int n; + cin >> n; + int x; + for (int i = 1; i <= n; ++i) { + cin >> x; + if (x) s.insert(x); + } + cout << s.size() << endl; + return (0); +} +int main() { + int a, b, n, c, d, e, f; + cin >> n; + a = 1; + b = 2, d = 3; + for (int i = 1; i <= n; i++) { + cin >> c; + if (c == 1) { + if (a == 1) { + if (b == 2) + b = 3; + else if (b == 3) + b = 2; + } else if (b == 1) { + if (a == 2) + a = 3; + else if (a == 3) + a = 2; + } else { + cout << "NO" << endl; + return 0; + } + } else if (c == 2) { + if (a == 2) { + if (b == 1) + b = 3; + else if (b == 3) + b = 1; + } else if (b == 2) { + if (a == 1) + a = 3; + else if (a == 3) + a = 1; + } else { + cout << "NO" << endl; + return 0; + } + } else if (c == 3) { + if (a == 3) { + if (b == 2) + b = 1; + else if (b == 1) + b = 2; + } else if (b == 3) { + if (a == 1) + a = 2; + else if (a == 2) + a = 1; + } else { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +bool isp(char c) { + if (c == '.' or c == ',' or c == '!' or c == '?') return true; + return false; +} +int main() { + string s; + getline(cin, s); + int len = s.size(); + string s2; + int lenn = len - 1; + for (int i = 0; i < lenn; i++) { + if (s[i] == ' ' and (s[i + 1] == ' ' or isp(s[i + 1]))) continue; + s2 += s[i]; + if (isp(s[i]) and s[i + 1] != ' ') s2 += ' '; + } + s2 += s[len - 1]; + cout << s2 << endl; +} +int ans[200]; +int main() { + memset(ans, 0, sizeof(ans)); + int n, m; + string str; + cin >> n >> m; + cin >> str; + int flag = 0; + for (int i = 0; i < str.length(); i++) { + int one = (int)str[i]; + ans[one]++; + } + for (int i = 0; i < str.length(); i++) { + int now = (int)str[i]; + if (ans[now] > m) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int s = 0; + int x = n / 100; + n = n - x * 100; + s += x; + x = n / 20; + n = n - x * 20; + s += x; + x = n / 10; + n = n - x * 10; + s += x; + x = n / 5; + n = n - x * 5; + s += x; + s = s + n; + cout << s << endl; + return 0; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + bool ada = 0; + for (long long i = 0; i * a <= 100000; i++) { + for (long long j = 0; j * b <= 100000; j++) { + if (j * b + i * a > c) break; + if (j * b + i * a == c) ada = 1; + if (ada) break; + } + if (ada) break; + } + if (ada) + cout << "Yes" << endl; + else + cout << "No" << endl; +} +int main() { + int n, i = 2; + cin >> n; + if (n > 0) { + cout << "I hate "; + for (i = 2; i <= n; i++) { + if (i % 2 == 0) + cout << "that I love "; + else + cout << "that I hate "; + } + cout << "it" << endl; + } +} +int main() { + int n; + cin >> n; + vector v(n / 2); + for (int i = 0; i < n / 2; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + int mov1 = 0, mov2 = 0; + for (int i = 0, j = 1; i < v.size(); i++, j += 2) { + mov1 += abs(j - v[i]); + mov2 += abs(j + 1 - v[i]); + } + cout << min(mov1, mov2) << "\n"; + return 0; +} +int main() { + int P[9] = {1, 2, 4, 8, 16, 32, 64, 128, 256}; + int n, b, p; + cin >> n >> b >> p; + int B = 0; + int N = n; + while (n > 1) { + int k; + for (int i = 8; i > -1; i--) { + if (P[i] <= n) { + k = P[i]; + break; + } + } + B += k * (2 * b + 1) / 2; + n -= k / 2; + } + cout << B << " " << N * p << endl; + return 0; +} +int main() { + int ab, bc, ac; + cin >> ab >> bc >> ac; + int b = sqrt(ab * bc / ac); + int a = ab / b; + int c = bc / b; + cout << a * 4 + b * 4 + c * 4 << endl; +} +const int N = 35; +int r[N], c[N], v[N][N], n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> v[i][j]; + r[i] += v[i][j]; + c[j] += v[i][j]; + } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { ans += (c[j] > r[i]); } + } + cout << ans << "\n"; + return 0; +} +int main() { + long long int i, j, l, m, n, k = 0, arr[100000], test, ans = 0; + cin >> n >> j; + for (i = 0; i < n; i++) { + cin >> l >> m; + if (l > m) { + k = k + (l - m) + 1; + } else { + k = k + (m - l) + 1; + } + } + while (k % j != 0) { + k = k + 1; + ans = ans + 1; + } + cout << ans << endl; +} +int main() { + int sum = 0; + string s; + cin >> s; + char current = 'a'; + for (int i = 0; i < s.length(); i++) { + if (abs(s[i] - current) > 13) { + if (s[i] > current) + sum += (current - s[i] + 26); + else if (current > s[i]) + sum += 26 - (current - s[i]); + } else { + if (current > s[i]) + sum += current - s[i]; + else { + sum += s[i] - current; + } + } + current = s[i]; + } + cout << sum << endl; + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k; + cin >> n >> k; + int a[n + 1], i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1, cmp); + for (i = 1; i <= n; i++) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + return 0; + } + } +} +bool isvowel(char c) { + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; + return false; +} +int main() { + string str; + cin >> str; + int siz = str.length(); + int cnt = 0; + for (int i = 0; i < siz; i++) { + if (isvowel(str[i])) + cnt++; + else if (!isalpha(str[i]) && (str[i] - '0') & 1) { + cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, flag; + cin >> n; + char arr[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int cnt = 0; + if (arr[i][j - 1] == 'o' && j > 0) cnt++; + if (arr[i + 1][j] == 'o' && i < n - 1) cnt++; + if (arr[i][j + 1] == 'o' && j < n - 1) cnt++; + if (arr[i - 1][j] == 'o' && i > 0) cnt++; + if (cnt % 2 != 0) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n, m, z = 0, x = 0, y = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> m; + if (m % 2 == 0) { + z++; + x = i; + } else { + z--; + y = i; + } + } + if (z > 0) + cout << y + 1 << endl; + else + cout << x + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int min = INT_MAX; + int cityNo; + bool duplicate = false; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + if (temp < min) { + min = temp; + cityNo = i + 1; + duplicate = false; + } else if (temp == min) + duplicate = true; + } + if (duplicate) + cout << "Still Rozdil\n"; + else + cout << cityNo << "\n"; + return 0; +} +int main() { + int ans = 0; + int n, m; + cin >> n >> m; + if (n == 1 or n == 3 or n == 5 or n == 7 or n == 8 or n == 10 or n == 12) + ans = 31; + else if (n == 2) + ans = 28; + else + ans = 30; + if (ans != 28) { + if (m == 7) + cout << 6 << endl; + else if (m == 6 and ans == 31) + cout << 6 << endl; + else + cout << 5 << endl; + } else { + if (m == 1) + cout << 4 << endl; + else + cout << 5 << endl; + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i <= c / a; i++) { + if ((c - i * a) % b == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int n, k, a[1000005], b, Max, now = -2147483647; +map m; +map mm; +int main() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> a[i], m[a[i]]++; + for (int b = 0; b <= n; b++) { + mm[1] = m[1], mm[-1] = m[-1]; + for (int i = -1000; i <= 1000; i++) { + int c = b + i * k; + if (c == now) break; + if (c < 0 || c > n) continue; + if (a[c] == 1) mm[1]--; + if (a[c] == -1) mm[-1]--; + now = c; + } + int flag = abs(mm[1] - mm[-1]); + Max = max(Max, flag); + } + for (int i = 1; i <= k; i++) { + mm[1] = m[1], mm[-1] = m[-1]; + for (int j = i; j <= n; j += k) { mm[a[j]]--; } + Max = max(Max, abs(mm[1] - mm[-1])); + } + cout << Max << "\n"; +} +int main() { + long long n; + long long m; + cin >> n >> m; + if (n > 27) + cout << m << '\n'; + else { + long long res = pow(2, n); + long long ans = m % res; + cout << ans << '\n'; + } + return 0; +} +int w, h, w1, h1, w2, h2; +int main() { + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w < 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w < 0) w = 0; + } + } + cout << w << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int count = 0; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) count++; + } + cout << count << endl; + return 0; +} +int main() { + int n, k, a[1000]; + cin >> n >> k; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (k % a[i] == 0) { + cout << k / a[i] << endl; + break; + } + } + return 0; +} +int a[1000005]; +int max(int a, int b) { + return a > b ? a : b; +} +int main() { + int n; + cin >> n; + int x = 0, y = 0, z = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { x++; } + if (a[i] == 2) { y++; } + if (a[i] == 3) { z++; } + } + cout << x + y + z - max(max(x, y), z) << endl; + return 0; +} +int main() { + int a, b, c, s, m, d; + cin >> a >> b >> c; + s = a + b + c; + m = max(max(a, b), c); + d = 2 * m - s + 1; + if (d <= 0) d = 0; + cout << d << endl; +} +int main() { + int n; + while (cin >> n) { + if ((n < 20 && n > 10) || n == 21) + cout << "4" << endl; + else if (n <= 10 || n > 21) + cout << "0" << endl; + else + cout << "15" << endl; + } + return 0; +} +long long n; +int main() { + while (cin >> n) { + int m, ans; + m = n / 2; + ans = m + 1; + cout << ans << endl; + } + return 0; +} +int main() { + int n, maxi = -1, sum = 0, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + maxi = max(maxi, x); + sum += x; + } + cout << maxi * n - sum << endl; + return 0; +} +int main() { + int n, x, y, z, sumx = 0, sumy = 0, sumz = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y >> z; + sumx += x; + sumy += y; + sumz += z; + } + if (sumx == 0 && sumy == 0 && sumz == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long cross(long long x0, long long y0, long long x1, long long y1) { + return y1 * x0 - y0 * x1; +} +int main() { + vector X(3), Y(3); + for (long long i = 0; i < 3; ++i) cin >> X[i] >> Y[i]; + long long c = cross(X[1] - X[0], Y[1] - Y[0], X[2] - X[1], Y[2] - Y[1]); + if (c == 0) + cout << "TOWARDS\n"; + else if (c < 0) + cout << "RIGHT\n"; + else + cout << "LEFT\n"; + return 0; +} +string s; +int i, j, arr[10000]; +int main() { + int a, b, c, d, t, cnt = 0, cn = 0; + cin >> t; + for (int k = 1; k <= t; k++) { cin >> arr[k]; } + cin >> a >> b; + if (a > b) { swap(a, b); } + for (i = a; i < b; i++) { cnt += arr[i]; } + for (i = b;; i++) { + if (i == a) break; + cn += arr[i]; + if (i == t) { i = 0; } + } + if (cnt > cn) + cout << cn << endl; + else { + cout << cnt << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a = min(n, m); + if (a & 1) { + cout << "Akshat" << endl; + } else { + cout << "Malvika" << endl; + } + return 0; +} +int main() { + int x[100][100]; + int i, n, m, k; + cin >> n >> m; + for (i = 1; i <= n; i++) { + for (k = 1; k <= m; k++) { cin >> x[i][k]; } + } + int f1 = 0, f2 = 0; + int ct = 0, f = 0; + for (i = 1; i <= n; i++) { + for (k = 1; k <= m; k++) { + if (x[i][k] == 1) { + if ((i == 1) || (k == 1) || (i == n) || (k == m)) { + f1 = 1; + } else { + f2 = 1; + } + } + } + } + if (f1 == 1) { + cout << 2 << endl; + } else { + cout << 4 << endl; + } + return 0; +} +const int maxn = 1e4 + 10, mod = 1e9 + 7; +const long long inf = 1e18; +bool is(int x) { + for (int i = 2; i * i <= x; i++) + if (x % i == 0) return 0; + return 1; +} +vector vec; +int main() { + int n, k; + cin >> n >> k; + for (int i = 2; i <= n; i++) + if (is(i)) vec.push_back(i); + for (int i = 0; i < int((vec).size()) - 1; i++) { + if (vec[i] + vec[i + 1] < n) k -= is(vec[i] + vec[i + 1] + 1); + } + cout << (k <= 0 ? "YES" : "NO") << endl; +} +const int maxn = 1e7 + 6; +const int modn = 1e9 + 7; +int main() { + int n, a, x, cnt = 0; + priority_queue pq; + cin >> n >> a; + for (int i = 0; i < n - 1; i++) { + cin >> x; + pq.push(x); + } + while (a <= pq.top()) { + x = pq.top(); + pq.pop(); + a++; + cnt++; + x--; + pq.push(x); + } + cout << cnt << endl; +} +int main() { + string s1, s2, s; + int i, pos1, pos2; + char a[10] = "6789TJQKA"; + cin >> s; + cin >> s1 >> s2; + if (s1[1] == s[0]) { + if (s2[1] != s[0]) + cout << "YES" << endl; + else { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) pos1 = i; + if (s2[0] == a[i]) pos2 = i; + } + if (pos1 <= pos2) + cout << "NO" << endl; + else + cout << "YES" << endl; + } + } else { + if (s1[1] == s2[1]) { + for (i = 0; i < 9; i++) { + if (s1[0] == a[i]) pos1 = i; + if (s2[0] == a[i]) pos2 = i; + } + if (pos1 <= pos2) + cout << "NO" << endl; + else + cout << "YES" << endl; + } else + cout << "NO" << endl; + } +} +int n; +string gem[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +string color[6] = {"purple", "green", "blue", "orange", "red", "yellow"}; +string inp[6]; +vector out; +void run() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> inp[i]; } +} +void solve() { + for (int i = 0; i < 6; i++) { + bool have = false; + for (int j = 0; j < n; j++) { + if (color[i] == inp[j]) { have = true; } + } + if (have == false) out.push_back(gem[i]); + } + cout << out.size() << endl; + for (vector::iterator i = out.begin(); i != out.end(); i++) cout << *i << endl; +} +int main() { + run(); + solve(); +} +const int N = 1e5 + 100; +const double PI = 3.14159; +vector v; +int n, h, a[10], now, ans; +string s; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { + int x = abs(now - (s[i] - 'a')); + int y = 26 - abs(now - (s[i] - 'a')); + ans += min(x, y); + now = s[i] - 'a'; + } + cout << ans << endl; + return 0; +} +int t; +int main() { + cin >> t; + for (int i = 1; i <= t; i++) { + long long a, b, k; + cin >> a >> b >> k; + cout << (a - b) * (k / 2) + a * (k % 2) << endl; + ; + } + return 0; +} +void bla() {} +int main() { + bla(); + string s, t; + cin >> s >> t; + int cnt = 0, c = 0; + for (int i = 0; i < s.size() && t.size(); i += 2) { + if (s[i] == '[' && s[i + 1] == ']') { + if (t[i] == '8' && t[i + 1] == '<') + c++; + else if (t[i] == '(' && t[i + 1] == ')') + cnt++; + } else if (s[i] == '(' && s[i + 1] == ')') { + if (t[i] == '8' && t[i + 1] == '<') + cnt++; + else if (t[i] == '[' && t[i + 1] == ']') + c++; + } else if (s[i] == '8' && s[i + 1] == '<') { + if (t[i] == '[' && t[i + 1] == ']') + cnt++; + else if (t[i] == '(' && t[i + 1] == ')') + c++; + } + } + if (cnt > c) + puts("TEAM 1 WINS"); + else if (cnt < c) + puts("TEAM 2 WINS"); + else + puts("TIE"); +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int c = 0; + for (int k = 0; k < 4; k++) { + int nx = i + dx[k], ny = j + dy[k]; + if (nx >= 0 && nx < n && ny >= 0 && ny < n && a[nx][ny] == 'o') c++; + } + if (c % 2 != 0) { + cout << "NO" + << "\n"; + return 0; + } + } + } + cout << "YES" << endl; +} +map, long long> cost; +int main() { + long long q; + cin >> q; + long long i, j, k, u, v, w, a, b, x, y; + cost.clear(); + while (q--) { + cin >> k; + if (k == 1) { + cin >> u >> v >> w; + while (u != v) { + if (u > v) swap(u, v); + cost[{v, v / 2}] += w; + cost[{v / 2, v}] += w; + v = v / 2; + } + } else { + cin >> u >> v; + long long ans = 0; + while (u != v) { + if (u > v) swap(u, v); + ans += cost[{v, v / 2}]; + v /= 2; + } + cout << ans << "\n"; + } + } + return 0; +} +int main() { + int k, r; + cin >> k >> r; + if (k % 10 == 0 || k % 10 == r) { + cout << 1 << endl; + return 0; + } + for (int i = 2; i <= 10; i++) { + if ((k * i) % 10 == 0 || (k * i) % 10 == r) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n; + cin >> n; + if (n < 11) + cout << 0 << endl; + else if (n == 20) + cout << 15 << endl; + else if (n > 21) + cout << 0 << endl; + else + cout << 4 << endl; + return 0; +} +set myset; +set tmp; +int main() { + int n; + while (cin >> n) { + string s; + myset.clear(); + for (int i = 0; i < n; i++) { + cin >> s; + string t = ""; + tmp.clear(); + for (int j = 0; j < s.size(); j++) { tmp.insert(s[j]); } + set::iterator it; + for (it = tmp.begin(); it != tmp.end(); it++) { t += (*it); } + myset.insert(t); + } + cout << myset.size() << endl; + } + return 0; +} +int n, p; +string s; +bool relax(int pos, char st) { + for (char i = st; i <= p + 'a' - 1; i++) { + if (i == s[pos - 1]) { continue; } + if (i == s[pos - 2]) { continue; } + s[pos] = i; + return true; + } + return false; +} +int main() { + cin >> n >> p >> s; + for (int ed = n - 1; ed >= 0; ed--) + if (relax(ed, s[ed] + 1)) { + bool succ = true; + for (int ne = ed + 1; ne < n; ne++) + if (!relax(ne, 'a')) { + succ = false; + break; + } + if (succ) { + cout << s << endl; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int letters[30]; +int main() { + int n, vv, hh; + set v; + set h; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> vv >> hh; + v.insert(vv); + h.insert(hh); + } + cout << min(v.size(), h.size()) << endl; + return 0; +} +long a[100000 + 10], vest[100000 + 10], match[100000 + 10], n, m, x, y; +bool check[100000 + 10]; +int main() { + cin >> n >> m >> x >> y; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= m; i++) cin >> vest[i]; + long res = 0; + long i = 0; + long j = 1; + memset(check, true, sizeof(check)); + while (i < n) { + i++; + if (a[i] + y < vest[j]) continue; + while ((a[i] - x > vest[j] || !check[j]) && j < m) j++; + if (j > m) continue; + if (a[i] - x <= vest[j] && vest[j] <= a[i] + y && check[j]) { + match[i] = j; + res++; + check[j] = false; + } + } + cout << res << "\n"; + for (int i = 1; i <= n; i++) + if (match[i] != 0) cout << i << " " << match[i] << "\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + int arr[] = {100, 20, 10, 5, 1}; + long long int i, j, c = 0; + for (i = 0; i < 5; i++) { + long long int a = n / arr[i]; + c += a; + n = n - (a * arr[i]); + if (n <= 0) break; + } + cout << c << endl; +} +long long a[11][105]; +long long b[11][105]; +long long c[11][105]; +bool vis[105]; +long long n, m, k; +long long cal(int x, int y) { + long long last = k; + long long ans = 0; + memset(vis, 0, sizeof(vis)); + while (last) { + long long v = 0; + long long p; + long long flag = 0; + for (int i = 1; i <= m; i++) { + if (!vis[i]) { + if (b[y][i] - a[x][i] > v) { + v = b[y][i] - a[x][i]; + p = i; + flag = 1; + } + } + } + if (flag == 0) break; + vis[p] = 1; + if (last >= c[x][p]) { + ans += c[x][p] * v; + last -= c[x][p]; + } else { + ans += last * v; + last = 0; + } + } + return ans; +} +int main() { + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + for (int j = 1; j <= m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j]; + } + long long ans = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) { ans = max(ans, cal(i, j)); } + cout << ans << "\n"; +} +int main() { + int n, k, x, a[110]; + while (cin >> n >> k >> x) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int sum = 0, h; + for (int i = n - 1; i >= 0 && k > 0; i--) { + if (a[i] >= x) { + sum += x; + k--, h = i; + } else + break; + } + for (int i = h - 1; i >= 0; i--) sum += a[i]; + cout << sum << endl; + } + return 0; +} +int n, i, a[111111], p, t, k; +int main() { + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> p >> t; + a[p * 50 - t]++; + } + t = 2500; + while (a[t] < k) k -= a[t--]; + cout << a[t] << endl; + return 0; +} +const int rl = 1e9; +int n, x, y, d, t; +void nhap() { + cin >> n >> x >> y >> d; +} +bool dc(int x, int y) { + int kc; + kc = y - x; + return (kc % d == 0); +} +int sb(int x, int y) { + int kc; + kc = y - x; + int kq = kc / d; + if (kc % d != 0) { kq = kq + 1; }; + return (kq); +} +void xu_ly() { + if (x <= y) { + if (dc(x, y)) { + cout << sb(x, y) << endl; + return; + } + int sb1, sb2; + sb1 = rl; + sb2 = rl; + if (dc(y, n)) { sb1 = sb(x, n) + sb(y, n); } + if (dc(1, y)) { sb2 = sb(1, x) + sb(1, y); } + int sb; + sb = min(sb1, sb2); + if (sb == rl) { + cout << -1 << endl; + return; + } else { + cout << sb << endl; + return; + } + } else { + if (dc(y, x)) { + cout << sb(y, x) << endl; + return; + } + int sb1, sb2; + sb1 = rl; + sb2 = rl; + if (dc(y, n)) { sb1 = sb(x, n) + sb(y, n); } + if (dc(1, y)) { sb2 = sb(1, x) + sb(1, y); } + int sb; + sb = min(sb1, sb2); + if (sb == rl) { + cout << -1 << endl; + return; + } else { + cout << sb << endl; + return; + } + } +} +int main() { + cin >> t; + int i; + for (i = 1; i <= t; i = i + 1) { + nhap(); + xu_ly(); + } +} +const int INF = (int)2e9; +const double EPS = (double)1e-9; +const double PI = (double)acos(-1); +const long long MOD = (long long)1e9 + 7; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (a % b == 0) return b; + gcd(a % b, b); +} +bool palin(string s) { + int len = s.length(); + for (int i = 0; i < len / 2; i++) { + if (s[i] != s[len - 1 - i]) { return false; } + } + return true; +} +void fast_io() {} +int parent[300]; +int root(int x) { + while (parent[x] != x) { + parent[x] = parent[parent[x]]; + x = parent[x]; + } + return x; +} +int main() { + int n; + cin >> n; + if (n % 2) + cout << "contest\n"; + else + cout << "home\n"; + return 0; +} +int main() { + int Q; + cin >> Q; + while (Q--) { + long long int a, b, k, sum = 0, d = 1; + cin >> a >> b >> k; + if (k % 2 != 0) + sum = a * (k / 2 + 1) - b * (k / 2); + else + sum = (a - b) * k / 2; + cout << sum << endl; + } + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + while (a && l != r) { + if (l < r) + l++, a--; + else + r++, a--; + } + l += a / 2, r += a / 2; + cout << min(l, r) * 2 << endl; + return 0; +} +int main() { + int n, ft, inch, r; + cin >> n; + ft = n / 36; + inch = (n % 36) / 3; + r = (n % 36) % 3; + if (r > 1) inch++; + if (inch == 12) { + ft++; + inch = 0; + } + cout << ft << " " << inch << endl; + return 0; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + vector v; + int x; + for (int i = 0; i < n; i++) { + cin >> x; + v.push_back(x); + } + int res = 0; + bool f = 0; + for (int i = 1; i < s.size(); i++) { + if ((s[i - 1] == 'R' && s[i] == 'L')) { + int s = v[i] - v[i - 1]; + if (res == 0) + res = s / 2; + else { + if (res > (s / 2)) res = s / 2; + } + } + } + if (res != 0) + cout << res << endl; + else + cout << -1 << endl; + return 0; +} +int a[105]; +int main() { + int n, d; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int ans = 0; + for (int i = 0; i < n; i++) { + int k = a[i] + d; + int pos = upper_bound(a, a + n, k) - a; + pos--; + ans = max(ans, pos - i + 1); + } + cout << n - ans << endl; +} +int main() { + int n; + cin >> n; + int required = n - 10; + if (required <= 0) { + cout << "0" << endl; + } else if (required >= 1 && required <= 9) { + cout << "4" << endl; + } else if (required == 10) { + cout << "15" << endl; + } else if (required == 11) { + cout << "4" << endl; + } else if (required >= 12) { + cout << "0" << endl; + } + return 0; +} +int main() { + int a, b, c, n, temp = 0, x; + cin >> a >> b >> c >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x > b && x < c) { temp++; } + } + cout << temp << endl; + return 0; +} +char a[200005]; +int main() { + int n, tot = 0, sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == '1') { tot++; } + if (a[i] == '0') { sum++; } + } + if (sum > tot) { + n = n - tot * 2; + } else + n = n - sum * 2; + cout << n << endl; + return 0; +} +int main() { + string s, second; + cin >> s >> second; + long long p = 0, q = 0; + long long xx = 0; + long long cnt = 0; + if (s == second) { + cout << "-1" << endl; + return 0; + } + if (s.size() > second.size()) + cout << s.size() << endl; + else + cout << second.size() << endl; + return 0; +} +int main() { + int n, m[30][30], r[30] = {0}, c[30] = {0}, win(0); + cin >> n; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cin >> m[i][j]; + r[i] += m[i][j]; + } + } + for (int j = 0; j < n; ++j) { + for (int i = 0; i < n; ++i) { c[j] += m[i][j]; } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (r[i] < c[j]) { win += 1; } + } + } + cout << win << endl; + return 0; +} +int main() { + string a; + string b; + int n; + cin >> a; + cin >> b; + cin >> n; + cout << a << " " << b << endl; + for (int i = 0; i < n; i++) { + string curr; + cin >> curr; + string replacement; + cin >> replacement; + if (curr == a) { + a = replacement; + } else if (curr == b) { + b = replacement; + } else { + abort(); + } + cout << a << " " << b << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + int s, a, b, c; + cin >> s >> a >> b >> c; + long long ans = 0, num; + num = s / c; + long long free = num / a * b; + ans = num + free; + cout << ans << endl; + } + return 0; +} +int n; +string s; +int main() { + cin >> n >> s; + if (s[0] == '0') { + cout << 1 << endl; + return 0; + } + int ans = 0, cur = 1; + for (int i = 0; i < n; i++) { + if (s[i] == '1') { + ans++; + } else { + cout << ans + 1 << endl; + return 0; + } + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + int a[1005]; + int min = 1000; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (k % a[i] == 0) { + int t = k / a[i]; + if (t < min) { min = t; } + } + } + cout << min << endl; +} +long long int k, a, b, j, d, n; +char q[1000][1000]; +int main() { + cin >> n; + for (int i = 1; i <= n; i += 2) { + j = 0; + d = 0; + while ((n - d) > i) { + j++; + q[i][j] = '*'; + d = j * 2; + } + j++; + for (int f = j; f < j + i; f++) q[i][f] = 'D'; + for (int f = j + i; f <= n; f++) q[i][f] = '*'; + } + for (int i = 1; i <= n; i += 2) { + for (int j = 1; j <= n; j++) cout << q[i][j]; + cout << endl; + } + for (int i = n - 2; i > 0; i -= 2) { + for (int j = 1; j <= n; j++) cout << q[i][j]; + cout << endl; + } +} +const int INF = 0x3f3f3f3f; +const int maxn = 120; +char str[maxn][maxn]; +int main() { + int n, m; + cin >> n >> m; + queue c; + queue a; + int t; + while (n--) { + cin >> t; + c.push(t); + } + while (m--) { + cin >> t; + a.push(t); + } + int ans = 0; + while (c.size() && a.size()) { + int x = c.front(); + int y = a.front(); + if (y >= x) { + ans++; + c.pop(); + a.pop(); + } else + c.pop(); + } + cout << ans << endl; + return 0; +} +map mp; +int main() { + int q; + cin >> q; + for (int qq = 0; qq < q; qq++) { + int t; + cin >> t; + if (t == 1) { + long long v, u, w; + cin >> v >> u >> w; + while (v != u) { + if (v < u) swap(v, u); + mp[v] += w; + v /= 2; + } + } else { + long long v, u; + cin >> v >> u; + long long ans = 0; + while (v != u) { + if (v < u) swap(v, u); + ans += mp[v]; + v /= 2; + } + cout << ans << '\n'; + } + } + return 0; +} +const int P = 1e9 + 7; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long qpow(long long a, long long n) { + long long r = 1 % P; + for (a %= P; n; a = a * a % P, n >>= 1) + if (n & 1) r = r * a % P; + return r; +} +long long inv(long long x) { + return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; +} +const int N = 2e5 + 10; +int a[N], b[N], f[N], n, m, k; +int ff[N], ans; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i], ++f[a[i]]; + for (int i = 1; i <= n; ++i) cin >> b[i], ++f[b[i]], ++ff[b[i]]; + for (int i = 1; i <= 5; ++i) + if (f[i] & 1) + return puts("-1"), 0; + else + f[i] /= 2; + for (int i = 1; i <= 5; ++i) ans += abs(ff[i] - f[i]); + cout << ans / 2 << endl; +} +int main() { + int a[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int n, m; + int sum = 0; + cin >> n >> m; + a[n] -= abs(m - 8); + if (a[n] % 7 != 0) sum++; + cout << sum + a[n] / 7 + 1 << endl; +} +int c[10]; +int main() { + int b = 0, sum = 0, i = 0; + for (i = 0; i < 5; i++) { + cin >> c[i]; + sum = sum + c[i]; + } + if (sum == 0) { + cout << "-1" << endl; + } else if (sum % 5 == 0) { + cout << sum / 5 << endl; + } else { + cout << "-1" << endl; + } + return 0; +} +string s; +const int p = 1e9 + 7; +int n, m; +void init() { + m = 0; + for (int i = 0; i < n; i++) m = (m * 2 + s[i] - '0') % p; +} +void work() { + for (int i = 1; i < n; i++) { + m *= 2; + m %= p; + } +} +int main() { + getline(cin, s); + n = s.size(); + init(); + work(); + cout << m << "\n"; +} +int main() { + int a, b, c, d, k = 0; + cin >> a >> b >> c; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> d; + if (d > b && d < c) k++; + } + cout << k << endl; +} +int main() { + int n; + cin >> n; + long long level = 1; + while (level < n + 1) { + if (level == 1) { + cout << 2 << endl; + level++; + continue; + } + long long y = (level + 1) * (level); + y *= level + 1; + long long cnt = y - (level - 1); + cout << cnt << endl; + level++; + } + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + if ((n - ((d / t) * k)) > k) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int x, y; + cin >> x >> y; + int d = y - x; + int a[d]; + for (int i = 0; i < d; i++) a[i] = 1; + for (int i = 0; i < n - 1; i++) { + int m, n; + cin >> m >> n; + n--; + for (int p = m; p <= n; p++) { + if (p >= y || p < x) continue; + a[p - x] = 0; + } + } + int sum = 0; + for (int j = 0; j < d; j++) sum += a[j]; + cout << sum << "\n"; + return 0; +} +int main() { + int n, arr[100], s, t; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + cin >> s >> t; + int m1 = min(s, t); + int m2 = max(s, t); + m1--; + m2--; + int R1 = 0, R2 = 0; + for (int i = m1; i < m2; i++) R1 += arr[i]; + for (int i = m2; i < n; i++) R2 += arr[i]; + for (int i = 0; i < m1; i++) R2 += arr[i]; + int R = min(R2, R1); + cout << R << endl; + return 0; +} +long long ar[1008], br[1008]; +int main() { + long long n, m, x; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> ar[i]; + for (int i = 0; i < m; i++) cin >> br[i]; + sort(ar, ar + n); + sort(br, br + m); + long long st = ar[n - 1]; + long long ed = br[0] - 1; + if (st <= ed) { + bool fl = 0; + for (int i = st; i <= ed; i++) { + if (ar[0] * 2 <= i) { + fl = 1; + cout << i << endl; + break; + } + } + if (!fl) puts("-1"); + } else + puts("-1"); + return 0; +} +int main() { + int n, l1, v1, l2, r, count; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> l1 >> v1 >> l2 >> r; + cout << (l1 / v1 - (r / v1 - (l2 - 1) / v1)) << endl; + } +} +int main() { + string a, b, x, y; + int n; + cin >> a >> b >> n; + cout << a << " " << b << endl; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (x == a) { + a = ""; + a += y; + } else if (x == b) { + b = ""; + b += y; + } + cout << a << " " << b << endl; + } +} +int main() { + char c[500]; + int ans, n; + cin >> n; + cin >> c; + int i; + for (i = 0; i < n; i++) cin >> c; + cout << (n % 2 ? "contest" : "home") << endl; + return 0; +} +int main() { + long long n; + long long x; + long long y; + cin >> n >> x >> y; + char s[n]; + for (long long i = 0; i < n; i++) { cin >> s[i]; } + long long min_cost = 100000000000; + long long block = 0; + bool block_reached = true; + for (long long i = 0; i < n; i++) { + if (s[i] == '0' && block_reached) { + block++; + block_reached = false; + } else if (s[i] == '1') { + block_reached = true; + } + } + min_cost = y * block; + for (long long i = 1; i <= block; i++) { min_cost = min(min_cost, y * i + x * (block - i)); } + cout << min_cost << '\n'; +} +int main() { + int a, b; + cin >> a >> b; + if (!a && !b) { + cout << "NO\n"; + } else if (abs(a - b) <= 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int N = 1e5 + 5; +int main() { + int n; + cin >> n; + int psum = 0, nsum = 0; + while (n--) { + int a; + cin >> a; + if (a > 0) + psum += a; + else + nsum += a; + } + cout << psum - nsum << "\n"; + return 0; +} +int main() { + long long n, t, a; + cin >> n >> t; + for (int i = 1; i <= n; i++) { + cin >> a; + t -= 86400 - a; + if (t <= 0) { + cout << i << endl; + return 0; + } + } +} +int main() { + int ans = 0; + int n, s; + cin >> n >> s; + while (s > 0) { + s -= n; + ans++; + } + cout << ans << endl; + return 0; +} +string s; +int n, m, mx, mn, a[100001], b[3]; +int main() { + cin >> n >> m >> mn >> mx; + for (int i = 0; i < m; i++) cin >> a[i]; + bool f = false; + int c = 0; + for (int i = 0; i < m; i++) { + if (a[i] == mn) + b[0] = 1; + else if (a[i] == mx) + b[1] = 1; + else if (a[i] > mx || a[i] < mn) + b[2] = 1; + } + if (b[2] || (n - m == 1 && (!b[0] && !b[1]))) + cout << "Incorrect" << endl; + else + cout << "Correct" << endl; + return 0; +} +int m, k, s[1005], d[1005], t, r, sum = 0, u, e, ans[1005], f; +int main() { + t = 1; + for (int i = 1; i <= t; i++) { + sum = 0; + r = 0; + cin >> m >> k; + for (int j = 1; j <= m; j++) { cin >> d[j]; } + for (int j = 1; j <= m; j++) { cin >> s[j]; } + for (int j = 2; j <= m + 1; j++) { + for (int y = 1; y < j; y++) { + if (s[y] > sum) { + sum = s[y]; + f = y; + } + } + if (d[j - 1] > s[j - 1] + r) { + u = d[j - 1] - s[j - 1] - r; + if (u % s[f] == 0) { + r = 0; + ans[j] = (u / s[f] * k) + ans[j - 1] + d[j - 1]; + } else { + e = u / s[f]; + r = (e + 1) * s[f] - u; + ans[j] = ((e + 1) * k) + ans[j - 1] + d[j - 1]; + } + } else { + ans[j] = ans[j - 1] + d[j - 1]; + r = s[j - 1] + r - d[j - 1]; + } + } + cout << ans[m + 1] << endl; + } + return 0; +} +int side[7]; +int main() { + for (int i = 1; i <= 6; ++i) cin >> side[i]; + int h1 = min(side[2], side[6]); + int h2 = min(side[3], side[5]); + int h3 = side[2] + side[3] - h1 - h2; + int ans = 0; + for (int i = side[1] + 1; i <= side[1] + h1; ++i) ans += 2 * i - 1; + for (int i = side[4] + 1; i <= side[4] + h2; ++i) ans += 2 * i - 1; + for (int i = 1; i <= h3; ++i) ans += (side[1] + h1) * 2; + cout << ans << endl; + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int n; + cin >> n; + if (n % 10 <= 5) { + if (n / 10) + cout << n / 10 << 0 << '\n'; + else + cout << 0 << '\n'; + } else + cout << (n / 10) + 1 << 0 << '\n'; +} +int main() { + int a, b, n; + string s; + cin >> n >> a >> b >> s; + a--; + b--; + cout << ((s[a] - '0') ^ (s[b] - '0')) << endl; +} +map mp; +int f(long long int n) { + int c = 0; + while (n) { + n >>= 1; + c++; + } + return c; +} +int main() { + for (int i = 0; i <= 63; i++) { + long long int t = (1LL << i) - 1LL; + mp[t] = true; + } + int t; + cin >> t; + while (t--) { + long long int l, r; + cin >> l >> r; + if (l == r) { + cout << r << endl; + continue; + } + int x = f(l); + int y = f(r); + if (mp.find(r) != mp.end()) { + cout << r << endl; + continue; + } + if ((y - x) >= 1) { + y--; + long long int ans = (1LL << y) - 1LL; + cout << ans << endl; + continue; + } + int a = __builtin_popcount(l); + int b = __builtin_popcount(r); + long long int mask = 1LL * l; + int match = 0, pos = -1; + for (int i = 0; i <= 63; i++) { + if (l & (1LL << i)) { continue; } + long long int temp = mask | (1LL << i); + if (temp >= l && temp <= r) { + mask = temp; + } else { + break; + } + } + cout << mask << endl; + } + return 0; +} +long long a[15][15]; +int main() { + long long n, i, j; + cin >> n; + for (i = 0; i < n; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (i = 1; i < n; i++) { + for (j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + long a(0), b(0); + cin >> a >> b; + long total(0); + while (a > 0 && b > 0) { + if (a > b) { + total += a / b; + a -= (a / b) * b; + } else { + total += b / a; + b -= (b / a) * a; + } + } + cout << total << endl; + } + return 0; +} +int main() { + int n, m, s; + int sum = 0; + cin >> n >> m >> s; + for (int i = 1; i <= s; i++) { + if (i % n == 0 && i % m == 0) { sum++; } + } + cout << sum << endl; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else if (i % 2 == 0 && j == 1 && i % 4 == 0) { + cout << "#"; + } else if (i % 2 == 0 && j == m && i % 4 != 0) { + cout << "#"; + } else { + cout << "."; + } + } + cout << endl; + } +} +int main() { + long long q; + long long sum = 0; + vector v; + cin >> q; + for (int i = 0; i < q; i++) { + long long x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end(), greater()); + long long temp = v.size(); + if (v.size() == 1) + cout << v[0] << endl; + else if (v.size() == 2) + cout << v[0] * v.size() + v[1] * v.size() << endl; + else { + sum = v[0] * v.size(); + for (int i = 1; i < v.size(); i++) { + sum += v[i] * (temp); + temp--; + } + cout << sum << endl; + } +} +const int MAXN = 1e5 + 5; +const long long INF = 1e8; +long long N; +char V[MAXN][32]; +int main() { + cin >> N; + for (int i = (0); i < int(N); i++) cin >> V[i]; + long long ans = 0, l = strlen(V[0]); + for (int i = (0); i < int(l); i++) { + for (int j = (1); j < int(N); j++) + if (V[j][i] != V[j - 1][i]) goto fin; + ans++; + } +fin: + cout << ans << endl; + return 0; +} +int ji(int n) { + int ret = 0; + while (n) { + ret += n % 10; + n /= 10; + } + return ret; +} +int main() { + int n, k = 0; + cin >> n; + for (int i = max(1, n - 1000); i <= n; ++i) { + if (i + ji(i) == n) ++k; + } + cout << k << endl; + for (int i = max(1, n - 1000); i <= n; ++i) { + if (i + ji(i) == n) cout << i << endl; + ; + } +} +int main() { + int n, kanan, kiri; + cin >> n; + for (int x = 1; x <= sqrt(n); x++) { + if (n % x == 0) { + kiri = x; + kanan = n / kiri; + } + } + cout << kiri << " " << kanan << endl; + return 0; +} +int main() { + int n, p, q; + cin >> n >> p; + vector v(n + 1, 0); + for (int i = 0; i < p; i++) { + int t; + cin >> t; + v[t] = 1; + } + cin >> q; + for (int i = 0; i < q; i++) { + int t; + cin >> t; + v[t] = 1; + } + for (int i = 1; i <= n; i++) { + if (v[i] == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } + } + cout << "I become the guy." << endl; +} +long long gcd(long long a, long long b) { + return __gcd(a, b); +} +bool solve() { + long long p, q, b; + cin >> p >> q >> b; + if (p == 0) return true; + long long gc = gcd(p, q); + p /= gc; + q /= gc; + long long x; + while ((x = gcd(q, b)) > 1) { + while (q % x == 0) q /= x; + x = gcd(q, b); + } + return q == 1; +} +int main() { + int t; + cin >> t; + while (t--) { + bool is = solve(); + cout << (is ? "Finite" : "Infinite") << '\n'; + } + return 0; +} +string s; +int p; +char ans[111111]; +int main() { + getline(cin, s); + int n = s.size(); + for (int i = 0; i < n; i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + ans[p++] = s[i]; + } else if (s[i] == ',' || s[i] == '.' || s[i] == '?' || s[i] == '!') { + for (; p && ans[p - 1] == ' ';) { p--; } + ans[p++] = s[i]; + ans[p++] = ' '; + } else if (s[i] == ' ') { + if (ans[p - 1] != ' ') { ans[p++] = s[i]; } + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 && m > 0) { + cout << "Impossible" << endl; + return 0; + } + int mn, mx; + mn = n; + if (m == 0) + mx = n; + else + mx = n + (m - 1); + if (m > n) mn += (m - n); + cout << mn << " " << mx << endl; + return 0; +} +int main() { + long long n, i, j, sum = 0; + pair my[205]; + while (cin >> n) { + for (i = 0; i < n; i++) cin >> my[i].first >> my[i].second; + for (i = 0; i < n; i++) { + long long R = 0, L = 0, U = 0, D = 0; + for (j = 0; j < n; j++) { + if (my[i].first == my[j].first && my[i].second < my[j].second) U++; + if (my[i].first == my[j].first && my[i].second > my[j].second) + D++; + else if (my[i].first < my[j].first && my[i].second == my[j].second) + R++; + else if (my[i].first > my[j].first && my[i].second == my[j].second) + L++; + } + if (R > 0 and L > 0 and U > 0 and D > 0) sum++; + } + cout << sum << endl; + } + return 0; +} +int v[105]; +int main() { + long long n, sum = 0; + cin >> n; + int x, y; + cin >> x >> y; + for (int i = 2; i <= n; ++i) { + int a, b; + cin >> a >> b; + for (int j = a + 1; j <= b; ++j) v[j] = 1; + } + for (int i = x + 1; i <= y; ++i) sum += 1 - v[i]; + cout << sum << '\n'; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool bulbs[m]; + for (int i = 0; i < m; i++) bulbs[i] = false; + int line; + int next; + for (int i = 0; i < n; i++) { + cin >> line; + for (int j = 0; j < line; j++) { + cin >> next; + next--; + bulbs[next] = true; + } + } + for (int i = 0; i < m; i++) { + if (!bulbs[i]) { + cout << "NO" + << "\n"; + return 0; + } + } + cout << "YES" + << "\n"; + return 0; +} +int dp[11][11] = {1}; +int main() { + int n; + cin >> n; + for (int i = 0; i <= 10; i++) dp[0][i] = dp[i][0] = 1; + for (int i = 1; i < n; i++) { + for (int j = 1; j < n; j++) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } + } + cout << dp[n - 1][n - 1] << '\n'; + return 0; +} +int s; +int main() { + int x, a[10001], b[10001], maxs = 0; + cin >> x; + for (int i = 1; i <= x; i++) cin >> a[i] >> b[i]; + for (int i = 1; i <= x; i++) { + s -= a[i]; + s += b[i]; + if (s > maxs) maxs = s; + } + cout << maxs << endl; + return 0; +} +inline int nxt() { + int x; + cin >> x; + return x; +} +const int INF = (int)1e9; +const int MODULO = (int)1e9 + 7; +int main() { + cout.precision(10); + int m = nxt(); + vector c(m); + int sum = 0; + for (int i = 0; i < (int)m; i++) { + cin >> c[i]; + sum += c[i]; + } + int x, y; + cin >> x >> y; + for (int i = 0; i < m; i++) { + int pass = 0; + for (int j = i; j < m; j++) { pass += c[j]; } + if (pass >= x && pass <= y && (sum - pass) >= x && (sum - pass) <= y) { + cout << i + 1 << '\n'; + return 0; + } + } + cout << 0 << '\n'; + return 0; +} +const int maxn = 1e5 + 10; +const int inf = 0x3f3f3f3f; +int main() { + int t; + cin >> t; + while (t--) { + int n, x, y, d, ans = inf; + cin >> n >> x >> y >> d; + if (abs(y - x) % d == 0) ans = min(ans, abs(y - x) / d); + if ((y - 1) % d == 0) ans = min(ans, x / d + (y - 1) / d + (x % d == 0 ? 0 : 1)); + if ((n - y) % d == 0) ans = min(ans, (n - x) / d + (n - y) / d + ((n - x) % d == 0 ? 0 : 1)); + if (ans == inf) + cout << -1 << endl; + else + cout << ans << endl; + } + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + t1 = t1 * 2 + s * v1; + t2 = t2 * 2 + s * v2; + if (t1 < t2) + cout << "First\n"; + else if (t1 > t2) + cout << "Second\n"; + else + cout << "Friendship\n"; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + if (n == 0 && m == 0) + cout << "NO" << endl; + else if (abs(n - m) <= 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, s, w, A = 0, D = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s >> w; + if (s > w) + A++; + else if (w > s) + D++; + } + if (A > D) + cout << "Mishka" << endl; + else if (D > A) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int num[1001]; +int main() { + int n, left = 0; + long long d, x; + char c; + cin >> n >> x; + while (n--) { + cin >> c >> d; + if (c == '+') + x += d; + else { + if (x - d < 0) + left++; + else + x -= d; + } + } + cout << x << " " << left << endl; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + int num = 0; + if (l == r) + num = l + a / 2; + else if (l < r) { + if (l + a <= r) + num = l + a; + else + num = r + (l + a - r) / 2; + } else { + if (r + a <= l) + num = r + a; + else + num = l + (r + a - l) / 2; + } + cout << (num * 2) << endl; + return 0; +} +int main() { + int n, i; + int a[100001], p[100001]; + int min = 1000, sum = 0; + cin >> n; + for (i = 0; i <= n; i++) { + cin >> a[i] >> p[i]; + if (min > p[i]) min = p[i]; + sum += min * a[i]; + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < int(n); i++) cin >> arr[i]; + int gcd = arr[0], mx = arr[0]; + for (int i = 0; i < int(n); i++) { + gcd = __gcd(gcd, arr[i]); + mx = max(mx, arr[i]); + } + int cnt = mx / gcd - n; + if (cnt & 1) { + cout << "Alice" + << "\n"; + } else { + cout << "Bob" + << "\n"; + } + return 0; +} +int main() { + int n; + while (cin >> n) { + long long tmp, mmin = 1000000005, ans = 1, cnt = 0; + for (int i = 0; i < n; i++) { + cin >> tmp; + if (tmp < mmin) { + mmin = tmp; + ans = i; + cnt = 0; + } + if (mmin == tmp) { cnt++; } + } + if (cnt == 1) + cout << ans + 1 << endl; + else + cout << "Still Rozdil" << endl; + } + return 0; +} +const int INF = 1 << 29; +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = -1, cur; + for (int i = 0; i < n; i++) { + cur = 0; + for (int j = i; j < n; j++) { + cur ^= a[j]; + ans = max(cur, ans); + } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + if (n == 0 && m != 0) { + cout << "Impossible" << endl; + return 0; + } + if (n == 0 && m == 0) { + cout << 0 << " " << 0 << endl; + return 0; + } + if (n != 0 && m == 0) { + cout << n << " " << n << endl; + return 0; + } + if (n <= m) { + cout << m << " " << n - 1 + m << endl; + } else { + cout << n << " " << n + m - 1 << endl; + } + return 0; +} +int main() { + int n, i, j = 0; + int c[5] = {100, 20, 10, 5, 1}; + cin >> n; + for (i = 0; i < 5; i++) { + j += n / c[i]; + n = n % c[i]; + } + cout << j << endl; +} +int main() { + int n, sum = 0, sum1 = 0; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + sum += x; + } + sort(v.begin(), v.end()); + int cnt = 0; + for (int i = n - 1; i >= 0; i--) { + sum1 += v[i]; + cnt++; + if (sum1 > (sum - sum1)) { + cout << cnt << endl; + break; + } + } + return 0; +} +int main() { + string s1, s2, s; + cin >> s1 >> s2; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] == s2[i]) { + s1[i] = '0'; + } else { + s1[i] = '1'; + } + } + cout << s1 << endl; +} +int main() { + int a[10][10], n; + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j == 0 || i == 0) { + a[i][j] = 1; + } else { + a[i][j] = a[i - 1][j] + a[i][j - 1]; + } + } + } + cout << a[n - 1][n - 1] << endl; +} +int main() { + int n, Ex, chest = 0, biceps = 0, back = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> Ex; + if (i % 3 == 0) { + back += Ex; + } else if (((i + 1) % 3) == 0) { + biceps += Ex; + } else { + chest += Ex; + } + } + if (chest > biceps && chest > back) { + cout << "chest" << endl; + } else if (biceps > chest && biceps > back) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } +} +int main() { + int count = 0, p = 0, i, n; + string a; + cin >> a; + n = a.length(); + for (i = 0; i < n; i++) { + if (a[i] == '-') + count++; + else + p++; + } + if (count == 0 || p == 0) + cout << "YES" << endl; + else if (count % p == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + string flights, home; + int n; + cin >> n; + cin >> home; + for (int i = 0; i < n; i++) cin >> flights; + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= 100; i++) { + if (n >= i * m) { + n = n + 1; + } else { + cout << n << endl; + return 0; + } + } +} +int main() { + int n; + cin >> n; + string orgStr, revStr, str; + cin >> revStr; + vector vec; + orgStr = revStr; + str = revStr; + reverse(revStr.begin(), revStr.end()); + int len = orgStr.length(); + char ch = '1'; + reverse(orgStr.begin(), orgStr.end()); + for (int i = len - 1; i >= 0; i--) { + if (orgStr[i] == ch) { + orgStr[i] = '0'; + } else { + orgStr[i] = ch; + break; + } + } + reverse(orgStr.begin(), orgStr.end()); + int count = 0; + for (int i = 0; i < len; i++) { + if (str[i] != orgStr[i]) count++; + } + cout << count << endl; +} +int main() { + int k = 1, l, i, res = 0, a[105] = {0}; + string s; + getline(cin, s); + l = s.length(); + for (i = 0; i < l; i++) { + if (s[i] == 'Q') a[k]++; + if (s[i] == 'A') { + k++; + a[k] = a[k - 1]; + } + } + for (i = 1; i < k; i++) res += a[i] * (a[k] - a[i]); + cout << res << endl; +} +string a[101], s1, s; +int main() { + int n; + cin >> n; + int mid = n / 2 + 1; + for (int i = 1; i <= n / 2; i++) { + s1 = "", s = ""; + for (int j = 1; j <= mid - i; j++) s1 = s1 + "*"; + for (int j = 1; j <= 2 * i - 1; j++) s = s + "D"; + s = s1 + s + s1; + a[i] = s; + } + for (int i = 0; i < n; i++) a[mid] += "D"; + for (int i = mid + 1; i <= n; i++) { + s = "", s1 = ""; + for (int j = 1; j <= i - mid; j++) s1 = s1 + "*"; + for (int j = 1; j <= n - 2 * (i - mid); j++) s = s + "D"; + a[i] = s1 + s + s1; + } + for (int i = 1; i <= n; i++) cout << a[i] << "\n"; +} +int main() { + int n; + cin >> n; + int cost = 0; + int min_p = 0; + int amt, p; + cin >> amt >> p; + min_p = p; + cost += min_p * amt; + while (n-- > 1) { + cin >> amt >> p; + if (p < min_p) min_p = p; + cost += min_p * amt; + } + cout << cost << endl; + return 0; +} +const int N = 2e5 + 100; +map ma, mb; +long long a[N]; +bool b[N]; +deque v, v1; +int main() { + long long n; + cin >> n; + long long ans = 0; + for (int i = 0; i < n; i++) { + string s; + long long p = 0; + cin >> s; + for (int j = 0; j < n; j++) { + if (s[j] == 'C') a[j]++, p++; + } + ans += (p * (p - 1)) / 2; + } + for (int i = 0; i < n; i++) ans += (a[i] * (a[i] - 1)) / 2; + cout << ans << endl; +} +int a, b; +int main() { + cin >> a >> b; + cout << min(a, b) << " " << (max(a, b) - min(a, b)) / 2 << endl; + return 0; +} +int main() { + int m, n, i = 0; + cin >> n >> m; + while (1) { + if (n + m > 1 && n > 0 && m > 0) { + n--; + m--; + i++; + } else + break; + } + if (i % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + return 0; +} +int main() { + long long int n, k1, k2; + cin >> n; + if (n > 0) { + cout << n << endl; + return 0; + } else { + k1 = n % 10; + n = n / 10; + k2 = n % 10; + n = n / 10; + if (k1 > k2) + n = (n * 10) + k1; + else + n = (n * 10) + k2; + cout << n << endl; + return 0; + } +} +int main() { + string name; + cin >> name; + int rots = 0; + int prev = 0; + for (int i = 0; i < name.length(); i++) { + int temp = name[i] - 'a'; + rots += min(abs(temp - prev), 26 - abs(temp - prev)); + prev = temp; + } + cout << rots << endl; + return 0; +} +int main() { + int a[35], b[35]; + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i != j && a[i] == b[j]) count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + cin.get(); + int max1 = 0, temp = 0; + char sym; + for (size_t i = 0; i < n; i++) { + cin.get(sym); + if (sym == ' ') + temp = 0; + else { + if (sym < 'a') temp++; + if (temp > max1) max1 = temp; + } + } + cout << max1 << '\n'; + return 0; +} +int main() { + cout.precision(15); + cout << fixed; + long long n, k, c = 0; + cin >> n; + cin >> k; + while (k % n == 0) { + k /= n; + c++; + } + if (k % n != 0 && k != 1) { + cout << "NO" << '\n'; + return 0; + } else { + cout << "YES" << '\n'; + cout << c - 1 << '\n'; + return 0; + } + return 0; +} +int n; +int m; +int a[110]; +void add() { + int id = 1; + for (int i = 2; i <= n; i++) { + if (a[i] < a[id]) id = i; + } + a[id]++; +} +int main() { + int mv = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + mv = max(mv, a[i]); + } + for (int i = 1; i <= m; i++) add(); + int ans = 0; + for (int i = 1; i <= n; i++) ans = max(a[i], ans); + cout << ans << " " << mv + m << endl; + return 0; +} +int main() { + int n, i; + cin >> n; + const int s = sqrt(n); + for (i = s; i > 0; i++) { + int t = n / i; + if (t * i == n) { + cout << min(t, i) << ' ' << max(t, i) << endl; + return 0; + } + } + return 0; +} +char a[110]; +int main() { + int t; + int n; + cin >> t; + while (t--) { + memset(a, 0, sizeof(a)); + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int temp = 0; + for (int i = 0; i < n / 2; i++) { + if (a[i] == a[n - 1 - i]) { + continue; + } else { + int a1 = a[i] - '0'; + int a2 = a[n - 1 - i] - '0'; + if (abs(a1 - a2) == 2 || abs(a1 - a2) == 0) { + continue; + } else { + temp = 1; + break; + } + } + } + if (temp == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +string s1, s2; +int main() { + cin >> s1 >> s2; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] < 92) { s1[i] += 32; } + if (s2[i] < 92) { s2[i] += 32; } + } + if (s1 < s2) + cout << "-1" << endl; + else if (s1 > s2) + cout << "1" << endl; + else if (s1 == s2) + cout << "0" << endl; + return 0; +} +void boost() {} +int main() { + int n; + cin >> n; + long long int arr[n]; + for (int i = 0; i < n; i++) cin >> arr[i]; + long long int ans = 0; + long long int till = 0; + for (int i = 0; i < n; i++) { + if ((i + 1 < n) && (arr[i] == arr[i + 1])) + till++; + else { + till++; + ans += ((till * (till + 1ll)) / 2ll); + till = 0; + } + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + string name, crew; + vector rat, woch, men, cap; + for (int i = 0; i < n; i++) { + cin >> name >> crew; + if (crew == "rat") + rat.push_back(name); + else if (crew == "woman" || crew == "child") + woch.push_back(name); + else if (crew == "man") + men.push_back(name); + else if (crew == "captain") + cap.push_back(name); + } + for (int i = 0; i < rat.size(); i++) { cout << rat[i] << endl; } + for (int i = 0; i < woch.size(); i++) { cout << woch[i] << endl; } + for (int i = 0; i < men.size(); i++) { cout << men[i] << endl; } + for (int i = 0; i < cap.size(); i++) { cout << cap[i] << endl; } + return 0; +} +int main() { + int a, b, c, sum[6], max1 = 0; + cin >> a >> b >> c; + sum[0] = a + b + c; + sum[1] = a * b * c; + sum[2] = a * b + c; + sum[3] = a + (b * c); + sum[4] = (a + b) * c; + sum[5] = a * (b + c); + for (int i = 0; i < 6; i++) { max1 = max(sum[i], max1); } + cout << max1 << endl; +} +inline int read() { + int x = 0, f = 1; + char c = getchar(); + while (c > '9' || c < '0') { + if (c == '-') f = -1; + c = getchar(); + } + while (c >= '0' && c <= '9') { + x = x * 10 + c - '0'; + c = getchar(); + } + return x * f; +} +int main() { + int q; + cin >> q; + for (int i = 1; i <= q; i++) { + int n; + string s; + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) + cout << "NO\n"; + else { + cout << "YES\n" << 2 << "\n" << s[0] << ' ' << s.substr(1) << endl; + } + } + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + if (s1 == s2) { + cout << -1 << endl; + } else { + cout << max(s1.size(), s2.size()) << endl; + } + return 0; +} +int main() { + int a[11][11], n; + cin >> n; + for (int i = 0; i < 11; i++) { + a[i][0] = 1; + a[0][i] = 1; + } + for (int i = 1; i < 11; i++) + for (int j = 1; j < 11; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; + cout << a[n - 1][n - 1] << endl; +} +string toUpp(string s) { + for (int i = 0; i < s.length(); i++) { + int n = s[i]; + if (n >= 97 && n <= 122) { + n -= 32; + s[i] = (char)n; + } + } + return s; +} +string toLow(string s) { + for (int i = 0; i < s.length(); i++) { + int n = s[i]; + if (n >= 65 && n <= 90) { + n += 32; + s[i] = (char)n; + } + } + return s; +} +int main() { + string s; + cin >> s; + int n1 = 0, n2 = 0; + for (int i = 0; i < s.length(); i++) { + int n = (int)s[i]; + if (n >= 65 && n <= 90) + n2++; + else if (n >= 97 && n <= 122) + n1++; + } + if (n1 >= n2) + cout << toLow(s) << endl; + else + cout << toUpp(s) << endl; + return 0; +} +int main() { + int m, x, y, total = 0, k; + cin >> m; + vector ci(m); + for (int i = 0; i < m; i++) { + cin >> ci[i]; + total += ci[i]; + } + cin >> x >> y; + for (int i = 1; i <= m - 1; i++) { + int g2 = 0; + k = i + 1; + for (int j = i; j <= m - 1; j++) { g2 += ci[j]; } + if (g2 >= x && g2 <= y && total - g2 >= x && total - g2 <= y) { + cout << k << '\n'; + return 0; + } + } + cout << 0 << '\n'; + return 0; +} +int res; +int main() { + int n, a, b; + cin >> n >> a >> b; + res = max(a + 1, n - b); + cout << n - res + 1 << endl; + return 0; +} +int arr[5005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) { + if (arr[arr[arr[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n; + char number[30000][21]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> number[i]; } + int size = strlen(number[0]); + for (int i = 0; i < size; i++) { + char c = number[0][i]; + for (int j = 1; j < n; j++) { + if (number[j][i] != c) { + cout << i << endl; + return 0; + } + } + } + cout << size << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (a == b || abs(a - b) == 1) { + if (a != 0 || b != 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +unsigned long long a; +unsigned long long b; +int main() { + cin >> a; + cin >> b; + unsigned long long c = a + b; + ostringstream ss1; + ss1 << a; + string anew = ss1.str(); + ostringstream ss2; + ss2 << b; + string bnew = ss2.str(); + ostringstream ss3; + ss3 << c; + string cnew = ss3.str(); + anew.erase(remove(anew.begin(), anew.end(), '0'), anew.end()); + bnew.erase(remove(bnew.begin(), bnew.end(), '0'), bnew.end()); + cnew.erase(remove(cnew.begin(), cnew.end(), '0'), cnew.end()); + stringstream geek(anew); + unsigned long long x1; + geek >> x1; + stringstream geek1(bnew); + unsigned long long x2; + geek1 >> x2; + stringstream geek2(cnew); + unsigned long long x3; + geek2 >> x3; + if ((x1 + x2) == x3) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + }; + return 0; +} +int main() { + string s; + cin >> s; + for (int i = (s.length() - 1); i >= 0; i--) { + if (s[i] == s[i + 1]) s.erase(i, 2); + } + cout << s << endl; + return 0; +} +int main() { + string s, a; + cin >> s; + int flag = 0; + for (int i = 0; i < 5; i++) { + cin >> a; + if (s[0] == a[0] || s[1] == a[1]) { + flag = 1; + break; + } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int arr[107], brr[107]; +long long int abso(long long int a) { + if (a < 0) return -a; + return a; +} +int main() { + long long int n, k, i, j, b = 0, mm = 0; + cin >> n >> k; + for (i = 1; i <= n; i++) { + cin >> arr[i]; + brr[i] = arr[i]; + } + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) arr[j] = brr[j]; + long long int cnta = 0, cntb = 0; + for (b = i; b <= n; b += k) arr[b] = 0; + for (b = i; b >= 1; b -= k) arr[b] = 0; + for (j = 1; j <= n; j++) { + if (arr[j] == 1) cnta++; + if (arr[j] == -1) cntb++; + } + mm = max(mm, abso(cnta - cntb)); + } + cout << mm << endl; +} +int main() { + long long n, m, s, t; + cin >> n >> m; + s = pow(2, n); + t = m % s; + cout << t << endl; + return 0; +} +const long long mod = 1000000007; +int main() { + long long w, h, u1, d1, u2, d2, i, x = 0; + cin >> w >> h; + cin >> u1 >> d1; + cin >> u2 >> d2; + for (i = h; i >= 0; i--) { + w += i; + if (i == d1) w -= u1; + if (i == d2) w -= u2; + w = max(x, w); + } + cout << w << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n; + string s; + cin >> n >> s; + int sum1, sum2; + sum1 = sum2 = 0; + for (int i = 0; i < n / 2; i++) { + if (s[i] != '7' and s[i] != '4') { + cout << "NO" << endl; + return 0; + } else + sum1 += s[i] - '0'; + } + for (int i = n / 2; i < n; i++) { + if (s[i] != '7' and s[i] != '4') { + cout << "NO" << endl; + return 0; + } else + sum2 += s[i] - '0'; + } + cout << (sum1 == sum2 ? "YES" : "NO") << endl; + return 0; +} +long long int a[204]; +int main() { + long long int n, i, j, k, x, y, t, m; + cin >> n; + for (i = 1; i <= n; i++) cin >> a[i]; + long long int mx = 0, cnt1 = 0; + for (i = 1; i <= n; i++) { + long long int cnt = 0; + if (a[i] == 1) cnt1++; + if (a[i] == 0) { + for (j = 1; j <= i; j++) { + if (a[j] == 0) cnt++; + } + for (j = i + 1; j <= n; j++) { + if (a[j] == 1) cnt++; + } + mx = max(mx, cnt); + } + } + cout << max(mx, cnt1) << endl; +} +int main() { + int n; + cin >> n; + vector x(n), y(n); + int xsum = 0, ysum = 0; + for (int i = 0; i < n; ++i) { + cin >> x[i] >> y[i]; + xsum += x[i]; + ysum += y[i]; + } + if (xsum % 2 == 0 && ysum % 2 == 0) { + cout << 0 << endl; + } else { + for (int i = 0; i < n; ++i) { + xsum -= x[i], ysum -= y[i]; + xsum += y[i], ysum += x[i]; + if (xsum % 2 == 0 && ysum % 2 == 0) { + cout << 1 << endl; + return 0; + } + xsum -= y[i], ysum -= x[i]; + xsum += x[i], ysum += y[i]; + } + cout << -1 << endl; + } +} +int main() { + int n, item, temp = 0; + ; + cin >> n; + string s1, s2; + cin >> s1; + cin >> s2; + for (int i = 0; i < n; i++) { + item = s1[i] - s2[i]; + if (item < 0) { item = (-1) * item; } + if (item == 6) { item = 4; } + if (item == 7) { item = 3; } + if (item == 8) { item = 2; } + if (item == 9) { item = 1; } + temp += item; + } + cout << temp << endl; +} +long long n; +string s; +long long sum[30]; +long long f[30][30]; +int main() { + cin >> n; + for (long long i = 1; i <= n; i++) { + cin >> s; + char t[1005]; + strcpy(t, s.c_str()); + long long len = strlen(t); + sort(t, t + len); + long long al = (unique(t, t + len)) - t; + if (al > 2) continue; + if (al == 2) { + char a = t[0], b = t[1]; + f[a - 'a' + 1][b - 'a' + 1] += len; + f[b - 'a' + 1][a - 'a' + 1] += len; + } + if (al == 1) { + char a = t[0]; + for (long long j = 1; j <= 26; j++) { + f[a - 'a' + 1][j] += len; + f[j][a - 'a' + 1] += len; + } + } + } + long long maxx = 0; + for (long long i = 1; i <= 26; i++) { + for (long long j = 1; j <= 26; j++) { + if (i == j) continue; + maxx = max(f[i][j], maxx); + } + } + cout << maxx << endl; + return 0; +} +int least(int a, int b) { + if (a < b) + return a; + else + return b; +} +int main() { + int n, i, f1 = 0, f2 = 0, f3 = 0, j; + cin >> n; + int a[n]; + for (i = 0; i < n; ++i) { + cin >> a[i]; + if (a[i] == 1) + ++f1; + else if (a[i] == 2) + ++f2; + else + ++f3; + } + int teams = least(f1, least(f2, f3)); + cout << teams << "\n"; + for (j = 0; j < teams; ++j) { + for (i = 0; i < n; ++i) + if (a[i] == 1) { + cout << i + 1 << " "; + a[i] = 0; + break; + } + for (i = 0; i < n; ++i) + if (a[i] == 2) { + cout << i + 1 << " "; + a[i] = 0; + break; + } + for (i = 0; i < n; ++i) + if (a[i] == 3) { + cout << i + 1 << "\n"; + a[i] = 0; + break; + } + } +} +bool test(int num) { + int a = 0; + int b = 0; + int c = 0; + int d = 0; + a = num % 10; + num /= 10; + b = num % 10; + num /= 10; + c = num % 10; + num /= 10; + d = num % 10; + num /= 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) + return 1; + else + return 0; +} +int main() { + int year; + while (cin >> year) { + for (int i = year + 1; i <= 10000; i++) { + if (test(i) == 1) { + cout << i << endl; + break; + } + } + } +} +int main() { + int t; + cin >> t; + while (t--) { + long long s, a, b, c; + cin >> s >> a >> b >> c; + long long choc = s / c; + long long extra = (choc / a) * b; + cout << choc + extra << endl; + } + return 0; +} +bool beat(char x, char b) { + if (x == 'R' && b == 'S') return true; + if (x == 'S' && b == 'P') return true; + if (x == 'P' && b == 'R') return true; + return false; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int sa = 0, sb = 0; + for (int i = 0; i < a.size() * b.size(); i++) { + if (beat(a[i % a.size()], b[i % b.size()])) sb++; + if (beat(b[i % b.size()], a[i % a.size()])) sa++; + } + sa = sa * (n / (a.size() * b.size())); + sb = sb * (n / (a.size() * b.size())); + for (int i = 0; i < n % (a.size() * b.size()); i++) { + if (beat(a[i % a.size()], b[i % b.size()])) sb++; + if (beat(b[i % b.size()], a[i % a.size()])) sa++; + } + cout << sa << ' ' << sb << endl; + return 0; +} +int main() { + int n, a[150005]; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (a[0] == 1) + cout << -1 << endl; + else + cout << 1 << endl; + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int maxx, minn; + maxx = max(a, b); + maxx = max(maxx, c); + minn = min(a, b); + minn = min(minn, c); + cout << maxx - minn << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n / 2; i++) { + for (int j = 0; j < (n - (2 * i + 1)) / 2; j++) cout << '*'; + for (int x = 0; x < 2 * i + 1; x++) cout << 'D'; + for (int o = 0; o < (n - (2 * i + 1)) / 2; o++) cout << '*'; + cout << endl; + } + for (int i = 0; i < n; i++) cout << 'D'; + cout << endl; + for (int i = n / 2 - 1; i >= 0; i--) { + for (int j = 0; j < (n - (2 * i + 1)) / 2; j++) cout << '*'; + for (int x = 0; x < 2 * i + 1; x++) cout << 'D'; + for (int o = 0; o < (n - (2 * i + 1)) / 2; o++) cout << '*'; + cout << endl; + } +} +int main() { + int k, month[12], sum = 0; + bool truth = true; + cin >> k; + for (int i = 0; i < 12; i++) { cin >> month[i]; } + sort(month, month + 12); + if (k != 0) + for (int i = 11; i >= 0; i--) { + if (k - month[i] >= 0) { + k -= month[i]; + sum++; + } else if (k - month[i] < 0 && truth) { + k -= month[i]; + sum++; + truth = false; + } + if (k <= 0) break; + } + if (k <= 0) { + cout << sum << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + int length, times; + cin >> length >> times; + string s; + cin >> s; + int start, end; + char change_in, to_change; + while (times--) { + cin >> start >> end >> to_change >> change_in; + start--; + end--; + for (size_t i = start; i <= end; i++) { + if (s[i] == to_change) { s[i] = change_in; } + } + } + cout << s << endl; + return 0; +} +int i, j; +set all; +string s; +int main() { + cin >> s; + for (i = s.size() - 1; i > 0; i--) { + all.clear(); + for (j = 0; j + i <= s.size(); j++) all.insert(s.substr(j, i)); + if (all.size() != s.size() - i + 1) { + cout << i << endl; + return 0; + } + } + cout << "0" << endl; + return 0; +} +int n; +int arr[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477}; +int main() { + cin >> n; + for (int i = 0; i < sizeof(arr) / 4; i++) + if (!(n % arr[i])) { + cout << "YES\n"; + exit(0); + } + cout << "NO\n"; + return 0; +} +char ab[2] = {'a', 'b'}; +int main() { + int n, k; + cin >> n >> k; + if ((k == 1 && n != 1) || (k > n)) { + cout << -1 << endl; + return 0; + } + int frst = n - k + 2; + bool flag = 0; + int i = 0; + for (; i < frst && i < n; i++) { + cout << ab[flag]; + flag = (!flag & 1); + } + char c = 'c'; + for (; i < n; i++) { + cout << c; + c++; + } + cout << endl; + return 0; +} +int main() { + double l, p, q; + cin >> l >> p >> q; + cout << (l / (p + q)) * p << "\n"; + return 0; +} +inline int f(int n, int x) { + for (int i = 0; i <= 2; i++) { + int ini = i; + for (int j = 1; j <= n; j++) { + if (j % 2 == 1) { + if (ini == 1) + ini = 0; + else if (ini == 0) + ini = 1; + } else { + if (ini == 1) + ini = 2; + else if (ini == 2) + ini = 1; + } + } + if (ini == x) return i; + } +} +int main() { + int n, x; + while (cin >> n >> x) { cout << f(n % 6, x) << endl; } + return 0; +} +int main() { + long long n, l, r, ql, qr, ans; + cin >> n >> l >> r >> ql >> qr; + vector w(n + 1); + w[0] = 0; + for (int i = 1; i <= n; i++) { + cin >> w[i]; + w[i] += w[i - 1]; + } + for (int i = 0; i <= n; i++) { + long long cans = l * w[i] + r * (w[n] - w[i]); + if (i > n - i) + cans += max(0LL, (2 * i - n - 1) * ql); + else + cans += max(0LL, (n - 2 * i - 1) * qr); + if (i) + ans = min(ans, cans); + else + ans = cans; + } + cout << ans << endl; + return 0; +} +int b[10], c[6]; +int main() { + int a[6], i, x, j = 0; + for (i = 0; i < 6; i++) { + cin >> a[i]; + x = a[i]; + b[x]++; + } + for (i = 1; i <= 9; i++) { + if (b[i] != 0) { + c[j] = b[i]; + j++; + } + } + sort(c, c + 3); + if (c[0] == 1 && c[1] == 1 && c[2] == 4) { + cout << "Bear" << endl; + } else if (c[0] == 0 && c[1] == 1 && c[2] == 5) { + cout << "Bear" << endl; + } else if (c[0] == 0 && c[1] == 2 && c[2] == 4) { + cout << "Elephant" << endl; + } else if (c[2] == 6) { + cout << "Elephant" << endl; + } else { + cout << "Alien" << endl; + } + return 0; +} +int main() { + int sx, dx; + char c, d; + cin >> c >> sx >> d >> dx; + int sy = c - 'a' + 1; + int dy = d - 'a' + 1; + vector v; + int cnt = 0; + while (sx != dx || sy != dy) { + ++cnt; + if (sx > dx && sy < dy) { + v.push_back("RD"); + sx--; + sy++; + } else if (sx < dx && sy > dy) { + v.push_back("LU"); + sx++; + sy--; + } else if (sx < dx && sy < dy) { + v.push_back("RU"); + sx++; + sy++; + } else if (sx > dx && sy > dy) { + v.push_back("LD"); + sx--; + sy--; + } else if (sx == dx && sy > dy) { + v.push_back("L"); + sy--; + } else if (sx == dx && sy < dy) { + v.push_back("R"); + sy++; + } else if (sx < dx && sy == dy) { + v.push_back("U"); + sx++; + } else if (sx > dx && sy == dy) { + v.push_back("D"); + sx--; + } + } + cout << cnt << endl; + for (int i = 0; i < v.size(); ++i) cout << v[i] << endl; +} +int main() { + int a[55][55]; + int n, m, flag = 0; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> a[i][j]; + if (a[i][j]) { + if (i == 1 || i == n || j == 1 || j == m) flag = 1; + } + } + } + if (flag) + cout << 2 << endl; + else + cout << 4 << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long d = n / (2 * (k + 1)); + cout << d << ' ' << k * d << ' ' << (n - (k + 1) * d) << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int total = a * c; + int available = b * c; + int needed = total - available; + int wait = needed / b; + if (needed % b) { wait++; } + cout << wait << endl; + return 0; +} +int main() { + int n, mi, ch, m = 0, c = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> mi >> ch; + if (mi > ch) + m++; + else if (mi < ch) + c++; + } + if (m > c) + cout << "Mishka\n"; + else if (m < c) + cout << "Chris\n"; + else + cout << "Friendship is magic!^^\n"; +} +int main() { + int n, k, red, green, blue; + cin >> n >> k; + red = 2 * n; + green = 5 * n; + blue = 8 * n; + if (red % k == 0) + red = red / k; + else + red = red / k + 1; + if (green % k == 0) + green = green / k; + else + green = green / k + 1; + if (blue % k == 0) + blue = blue / k; + else + blue = blue / k + 1; + cout << red + green + blue << endl; + return 0; +} +int main() { + int t; + cin >> t; + long long a, b, c; + vector v; + for (int i = 1; i <= t; i++) { + cin >> a >> b >> c; + if (c % 2 == 0) + v.push_back((c / 2) * (a - b)); + else + v.push_back((c / 2) * (a - b) + a); + } + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + long long int n, ma = 0, d = 0, i, num; + cin >> n; + for (i = 0; i < n; i++) { + cin >> num; + d = gcd(num, d); + ma = max(ma, num); + } + if ((ma / d - n) % 2) + cout << "Alice" << endl; + else + cout << "Bob" << endl; + return 0; +} +int a[51]; +int main() { + int n, m, k, g, t = 0; + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + g = k; + sort(a, a + n); + if (m > g) { + for (int i = n - 1; i >= 0; i--) { + g = g - 1 + a[i]; + k--; + t++; + if (m <= g) { break; } + } + } + if (m <= g) { + cout << t << endl; + } else { + cout << -1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int ctr = 0; + while (n--) { + int x, y, z; + cin >> x >> y >> z; + if (x * y == 1 || x * z == 1 || y * z == 1) ctr++; + } + cout << ctr << endl; + return 0; +} +int a[200001]; +int main() { + int n; + cin >> n; + int i; + for (i = 1; i <= n; i++) { cin >> a[i]; } + int s1 = 0, s2 = 0; + for (i = 1; i <= n; i++) { + if (a[i] == 1) + s1++; + else + s2++; + } + if (s1 > s2) { + cout << s2 + (s1 - s2) / 3 << endl; + } else { + cout << s1 << endl; + } + return 0; +} +int main() { + int n, min1, max1, min2, max2, min3, max3, num3, num2, num1; + while (cin >> n) { + cin >> min1 >> max1; + cin >> min2 >> max2; + cin >> min3 >> max3; + num1 = min1; + num2 = min2; + num3 = min3; + if (num1 + num2 + num3 == n) { + cout << num1 << " " << num2 << " " << num3 << endl; + } else if (num1 + num2 + num3 < n) { + while (1) { + if (num1 < max1 && num1 + num2 + num3 < n) + num1++; + else if (num2 < max2 && num1 + num2 + num3 < n) + num2++; + else if (num3 < max3 && num1 + num2 + num3 < n) + num3++; + if (num1 + num2 + num3 == n) break; + } + cout << num1 << " " << num2 << " " << num3 << endl; + } + } +} +int main() { + int n, s = 0; + cin >> n; + while (n != 0) { + if (n >= 100) { + s += (n / 100); + n = n % 100; + } else if (n >= 20) { + s += (n / 20); + n = n % 20; + } else if (n >= 10) { + s += (n / 10); + n = n % 10; + } else if (n >= 5) { + s += (n / 5); + n = n % 5; + } else if (n >= 1) { + s += (n / 1); + n = n % 1; + } + } + cout << s << endl; +} +int main() { + int n, len_s; + int a, b; + char s[200005]; + while (cin >> n) { + memset(s, 0, 20005); + cin >> s; + a = 0; + b = 0; + len_s = strlen(s); + for (int i = 0; i < len_s; i++) { + if (s[i] - '0' == 0) + a++; + else + b++; + } + cout << abs(a - b) << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + string g[n]; + int ara[n][m]; + int maxn[m]; + for (int w = 0; w < n; w++) { + cin >> g[w]; + for (int q = 0; q < m; q++) { ara[w][q] = (int)g[w][q] - 48; } + } + memset(maxn, 0, sizeof(maxn)); + for (int q = 0; q < m; q++) { + for (int w = 0; w < n; w++) { + if (ara[w][q] >= maxn[q]) { maxn[q] = ara[w][q]; } + } + } + bool mark[n]; + memset(mark, 0, sizeof(mark)); + for (int q = 0; q < m; q++) { + for (int w = 0; w < n; w++) { + if (maxn[q] == ara[w][q]) { mark[w] = 1; } + } + } + int s = 0; + for (int w = 0; w < n; w++) { + if (mark[w]) s++; + } + cout << s << endl; + return 0; +} +int main() { + vector v; + vector v1; + long long i, j, n, ans, min = 1000000002, t, flag; + cin >> n; + for (i = 0; i < n; i++) { + long long x; + cin >> x; + v.push_back(x); + if (x < min) { min = x; } + } + for (i = 0; i < n; i++) { + if (min == v[i]) { v1.push_back(i); } + } + min = 1000000002; + for (i = 1; i < v1.size(); i++) { + if ((v1[i] - v1[i - 1]) < min) { min = (v1[i] - v1[i - 1]); } + } + cout << min << endl; +} +const string name[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; +int main() { + int n; + cin >> n; + int x = 5; + long cur = 0; + while (cur + x < n) { + cur += x; + x *= 2; + } + long id = n - cur; + id = (id - 1) / (x / 5); + cout << name[id] << endl; + return 0; +} +int n; +int arr[35][35]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int y = 0; y < n; y++) cin >> arr[i][y]; + } + int tot = 0; + for (int i = 0; i < n; i++) { + for (int y = 0; y < n; y++) { + int sumc = 0, sumr = 0; + for (int q = 0; q < n; q++) sumr += arr[i][q]; + for (int q = 0; q < n; q++) sumc += arr[q][y]; + if (sumc > sumr) tot++; + } + } + cout << tot << endl; + return 0; +} +int main() { + char a[20]; + cin >> a; + int b = 0; + for (int i = 0; i < strlen(a); i++) { + if (a[i] == '4' || a[i] == '7') b++; + } + if (b == 4 || b == 7) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long l, r; + cin >> l >> r; + if (r - l < 2) + cout << -1 << '\n'; + else if (r - l == 2) { + if (r % 2) + cout << -1 << '\n'; + else + cout << l << " " << l + 1 << " " << r << '\n'; + } else { + if (l % 2) + cout << l + 1 << " " << l + 2 << " " << l + 3 << '\n'; + else + cout << l << " " << l + 1 << " " << l + 2 << '\n'; + } +} +int main() { + int x, y; + cin >> x >> y; + int ai = 0, aj = 0; + int bi = 0, bj = 0; + int a = 0, b = 0; + int ck = 0; + int ck1 = 0; + if (x < 0) { + a = (-1) * x; + ck = 1; + } + if (y < 0) { + b = (-1) * y; + ck1 = 1; + } + if (ck == 0 && ck1 == 0) { + aj = x + y; + bi = x + y; + ai = 0; + bj = 0; + } + if (ck == 1 && ck1 == 0) { + ai = (-1) * (a + y); + aj = 0; + bi = 0; + bj = a + y; + } + if (ck == 1 && ck1 == 1) { + ai = (-1) * (a + b); + aj = 0; + bi = 0; + bj = ai; + } + if (ck == 0 && ck1 == 1) { + ai = 0; + aj = (-1) * (x + b); + bi = x + b; + bj = 0; + } + cout << ai << " " << aj << " " << bi << " " << bj << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + puts((n / k) & 1 ? "YES" : "NO"); +} +long long n, l, r; +int main() { + cin >> n; + while (n--) { + cin >> l >> r; + for (register long long i = 1; (l | i) <= r; i <<= 1) l |= i; + cout << l << endl; + } + return 0; +} +int main() { + string tmp, a, b; + map mp; + cin >> a >> b; + for (int i = 0; i < a.size(); i++) { + tmp.push_back(a[i]); + string tmp1 = tmp; + for (int j = 0; j < b.size(); j++) { + tmp1.push_back(b[j]); + mp[tmp1] = 1; + } + } + map::iterator it = mp.begin(); + cout << it->first << '\n'; +} +int a[605], x, s = 0; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + a[x]++; + } + for (int i = 1; i <= 600; i++) + if (a[i] != 0) s++; + cout << s << endl; + return 0; +} +vector v[1100]; +bool visited[1100]; +long long int ans = 0; +long long int edges = 0; +long long int edge = 0; +long long int dfs(long long int x, long long int parent) { + visited[x] = true; + long long int n = 1; + edges += v[x].size(); + for (long long int i = 0; i < v[x].size(); i++) { + if (!visited[v[x][i]]) n += dfs(v[x][i], x); + } + return n; +} +int main() { + long long int n, m, k, x, y; + cin >> n >> m >> k; + vector home; + for (long long int i = 0; i < k; i++) { + cin >> x; + home.push_back(x); + } + for (long long int i = 0; i < m; i++) { + cin >> x >> y; + v[x].push_back(y); + v[y].push_back(x); + } + long long int sum = 0; + long long int num = 0; + for (long long int i = 0; i < k; i++) { + if (!visited[home[i]]) { + edges = 0; + long long int node = dfs(home[i], 0); + edges /= 2; + edge += edges; + num = max(num, node); + ans += ((node - 1) * (node)) / 2 - edges; + sum += node; + } + } + ans += (n - sum) * num; + ans += ((n - sum - 1) * (n - sum)) / 2 - (m - edge); + cout << ans << endl; +} +int main() { + long long a, b, c, t, k; + cin >> a >> b >> c; + t = a * c; + t = t - b * c; + k = t / b; + if (t % b != 0) k++; + cout << k << endl; +} +int main() { + int n; + cin >> n; + string s; + int answer = 0; + bool mass[6]; + for (int i = 0; i < 6; i++) mass[i] = false; + cin.ignore(); + for (int i = 0; i < n; i++) { + getline(cin, s); + if (s == "purple") { + mass[0] = true; + answer++; + } else if (s == "green") { + mass[1] = true; + answer++; + } else if (s == "blue") { + mass[2] = true; + answer++; + } else if (s == "orange") { + mass[3] = true; + answer++; + } else if (s == "red") { + mass[4] = true; + answer++; + } else if (s == "yellow") { + mass[5] = true; + answer++; + } + } + cout << 6 - answer << endl; + for (int i = 0; i < 6; i++) { + if (mass[i] == false) + if (i == 0) { + cout << "Power\n"; + } else if (i == 1) { + cout << "Time\n"; + } else if (i == 2) { + cout << "Space\n"; + } else if (i == 3) { + cout << "Soul\n"; + } else if (i == 4) { + cout << "Reality\n"; + } else if (i == 5) { + cout << "Mind\n"; + } + } + return 0; +} +int sol(int a, int b, vector &v) { + int ret = 0; + for (int i = 0; i < v.size(); i++) { + int got = 1; + for (int j = 0; j < v[i].length(); j++) { + if (v[i][j] - 97 != a && v[i][j] - 97 != b) { got = 0; } + } + if (got) { ret += v[i].length(); } + } + return ret; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + int ans = 0; + for (int i = 0; i < 26; i++) { + for (int j = 0; j < 26; j++) { ans = max(ans, sol(i, j, v)); } + } + cout << ans << "\n"; + return 0; +} +const int MAXN = 55; +int G[MAXN][MAXN]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> G[i][j]; } + } + bool flag2 = true; + bool flag1 = false; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + flag1 = true; + if (G[i][j] != 1) { + flag1 = false; + for (int k = 1; k <= n; k++) { + if (k == j) continue; + for (int kk = 1; kk <= n; kk++) { + if (kk == i) continue; + if (G[i][k] + G[kk][j] == G[i][j]) { + flag1 = true; + break; + } + } + if (flag1) break; + } + } + if (!flag1) { + flag2 = false; + break; + } + } + if (!flag2) break; + } + if (flag2) + cout << "Yes" << endl; + else + cout << "No" << endl; + } + return 0; +} +bool isVowel(string s) { + if (s == "a" || s == "e" || s == "i" || s == "o" || s == "u") { return true; } + return false; +} +int main() { + string aux; + cin >> aux; + bool resp = true; + for (int i = 0; i < aux.size(); i++) { + if (aux.substr(i, 1) == "n") continue; + if (!isVowel(aux.substr(i, 1))) { + if (!isVowel(aux.substr(i + 1, 1))) { + resp = false; + break; + } + } + } + if (resp) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + string x; + getline(cin, x); + string s; + getline(cin, s); + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i += 1) { + if (s[i] == ' ') continue; + int j = i, tmp = 0; + while (j < n && s[j] != ' ') { + if (s[j] >= 'A' && s[j] <= 'Z') tmp++; + j++; + } + ans = max(ans, tmp); + i = j - 1; + } + cout << ans << '\n'; +} +int main() { + int n; + int flag = 0; + int flag2 = 0; + int a[2] = {1, 2}; + queue q; + cin >> n; + int t = n; + while (n--) { + int a; + cin >> a; + q.push(a); + } + while (!q.empty()) { + int p = q.front(); + q.pop(); + flag = 0; + for (int i = 0; i < 2; i++) { + if (p == a[i]) { + a[1 - i] = 6 - a[0] - a[1]; + flag = 1; + } + } + if (flag == 0) { + cout << "NO" << endl; + flag2 = 1; + break; + } + } + if (q.empty() && !flag2) { cout << "YES" << endl; } + return 0; +} +int n, m, k; +bool debug = false; +int main() { + string ans, s; + int sum = -10000; + cin >> n; + while (n--) { + cin >> s >> m >> k; + int x = m * 100 - 50 * k; + for (int i = 0; i < 5; i++) { + cin >> m; + x += m; + } + if (x > sum) { + sum = x; + ans = s; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + string num; + cin >> n >> num; + int count = 0; + for (int i = 0; i < n; i++) { + if (num[i] == '8') { count++; } + } + cout << (n / 11 > count ? count : n / 11) << endl; +} +int main() { + string n, arr[5]; + bool f = false; + cin >> n; + for (int i = 0; i < 5; i++) cin >> arr[i]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < n.length(); j++) { + if (arr[i][j] == n[j]) f = true; + } + } + if (f) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int removeDuplicates(int arr[], int n) { + if (n == 0 || n == 1) return n; + int temp[n]; + int j = 0; + for (int i = 0; i < n - 1; i++) { + if (arr[i] != arr[i + 1]) { temp[j++] = arr[i]; } + } + temp[j++] = arr[n - 1]; + for (int i = 0; i < j; i++) arr[i] = temp[i]; + return j; +} +int main() { + int n, m, x, y = 0, bul[10000]; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> bul[y]; + y++; + } + } + int sizebul = y; + sort(bul, bul + sizebul); + sizebul = removeDuplicates(bul, sizebul); + if (sizebul == m) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +long long fun(long long n) { + long long ans = (long long)1; + long long x = (long long)2; + while (n > 0) { + if (n % 2 != 0) { ans = ans * x; } + x = x * x; + n = n / 2; + } + return ans; +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= m || n >= 27) { + cout << m << endl; + return 0; + } + long long t = fun(n); + cout << m % t << endl; + return 0; +} +void fast() {} +long long mn = 1e9; +void lucky(long long a, long long c, int b) { + if (a > 1e11) return; + if (a >= b && c == 0) mn = min(mn, a); + lucky(a * 10 + 7, c - 1, b); + lucky(a * 10 + 4, c + 1, b); +} +int n; +void fff(string s, int c) { + if (s.size() == 2 * n) { + if (c == 0) cout << s << endl; + return; + } + fff(s + "(", c + 1); + if (c > 0) fff(s + ")", c - 1); +} +long long toint(string s) { + long long a = 0, c = 1; + ; + for (int i = 0; i < s.size(); i++) { + a += (s[s.size() - i - 1] - '0') * c; + c *= 10; + } + return a; +} +int main() { + fast(); + long long a, b = 0, c = 0, d = 1, sum = 0, x = 0; + string s, ss = ""; + cin >> a >> b >> c; + d = a; + while (a > 1) { + x = a / 2; + a -= x; + while (x--) sum += ((2 * b) + 1); + } + cout << sum << " " << d * c << "\n"; + return 0; +} +int main() { + long int n; + cin >> n; + if (n <= 5) { + if (n == 1) cout << "Sheldon" << endl; + if (n == 2) cout << "Leonard" << endl; + if (n == 3) cout << "Penny" << endl; + if (n == 4) cout << "Rajesh" << endl; + if (n == 5) cout << "Howard" << endl; + } else { + int i = 0, m = 0, s; + for (m = 1;; m++) + if (n - 5 * (pow(2, m + 1) - 1) < 0) { + s = n - 5 * (pow(2, m) - 1); + break; + } + for (i = 1; i <= 5; i++) { + if (s - i * pow(2, m) <= 0) break; + } + if (i == 1) cout << "Sheldon" << endl; + if (i == 2) cout << "Leonard" << endl; + if (i == 3) cout << "Penny" << endl; + if (i == 4) cout << "Rajesh" << endl; + if (i == 5) cout << "Howard" << endl; + } + return 0; +} +const int MAX = 1e5 + 9; +const long long MOD = 1e9 + 7; +int s1[35], s2[35]; +int a[35][35]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) + for (int t = 0; t < n; t++) cin >> a[i][t]; + for (int i = 0; i < n; i++) + for (int t = 0; t < n; t++) { + s1[i] += a[i][t]; + s2[t] += a[i][t]; + } + int res = 0; + for (int i = 0; i < n; i++) + for (int t = 0; t < n; t++) + if (s2[t] > s1[i]) res++; + cout << res << "\n"; +} +int main() { + long long int n; + while (cin >> n) { + if (n % 2 == 1) + cout << "1"; + else + cout << "2"; + cout << endl; + } +} +string name1, name2; +int n; +int main() { + cin >> name1 >> name2 >> n; + string death, rep; + cout << name1 << " " << name2 << endl; + for (int i = 0; i < n; i++) { + cin >> death >> rep; + if (death == name1) { + name1 = rep; + } else { + name2 = rep; + } + cout << name1 << " " << name2 << endl; + } + return 0; +} +int win(char x, char y) { + if (x == y) return 2; + if (x == 'R' && y == 'S') return 0; + if (x == 'S' && y == 'P') return 0; + if (x == 'P' && y == 'R') return 0; + return 1; +} +int main() { + int n; + string A, B; + cin >> n >> A >> B; + int a = A.size(), b = B.size(); + int s[3] = {}, p[3] = {}; + for (int i = 0; i < a * b; i++) s[win(A[i % a], B[i % b])]++; + for (int i = 0; i < n % (a * b); i++) p[win(A[i % a], B[i % b])]++; + for (int i = 0; i < 2; i++) p[i] += s[i] * (n / (a * b)); + cout << p[1] << ' ' << p[0] << endl; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (n / 2) + (n / 1) << endl; + return 0; +} +int main() { + long long k, m, i, v; + cin >> k; + m = (k + 1) / 2; + for (i = 1; i <= m; i++) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } + for (i = (m - 1); i >= 1; i--) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } +} +int sum(long n) { + int d, s = 0; + while (n) { + d = n % 10; + s += d; + n /= 10; + } + return s; +} +int main() { + long n, m, a[100], k = 0; + int d = 0, i, c = 0; + cin >> n; + if (n < 18) { + for (i = 1; i < n; i++) { + if ((i + sum(i)) == n) { + c++; + a[k++] = i; + } + } + } else { + m = n; + while (m) { + d++; + m /= 10; + } + for (i = n - 9 * d; i < n; i++) { + if ((i + sum(i)) == n) { + c++; + a[k++] = i; + } + } + } + cout << c << endl; + for (i = 0; i < k; i++) cout << a[i] << endl; +} +int main() { + int n, x; + set se; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x) se.insert(x); + } + cout << se.size() << endl; +} +int main() { + int n; + int a; + cin >> n; + int min = 100005; + int max = 0; + int count = -1; + for (int i = 0; i < n; i++) { + int flag = 0; + cin >> a; + if (a > max) { + max = a; + flag = 1; + } + if (a < min) { + min = a; + flag = 1; + } + if (flag) count++; + } + cout << count << endl; +} +const int MAXX = 1000005; +const int maxInt = 2147483647; +int a[6], b[6]; +int main() { + int n, x; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + a[x]++; + } + for (int i = 1; i <= n; i++) { + cin >> x; + b[x]++; + } + int ans = 0; + for (int i = 1; i <= 5; i++) { + int tot = abs(a[i] - b[i]); + if (tot & 1) { + cout << -1 << '\n'; + return 0; + } + tot /= 2; + ans += tot; + } + ans /= 2; + cout << ans << '\n'; + return 0; +} +stack s; +int main() { + long long n; + cin >> n; + while (n) s.push(n % 10), n /= 10; + n = 0; + while (!s.empty()) { + if (s.top() == 4 || s.top() == 7) ++n; + s.pop(); + } + if (!n) puts("NO"), exit(0); + while (n) s.push(n % 10), n /= 10; + while (!s.empty()) { + if (s.top() != 4 && s.top() != 7) puts("NO"), exit(0); + s.pop(); + } + puts("YES"); + return 0; +} +long long MOD = 1e9 + 7; +long long mod = 1e9 + 7; +const int N = 100005; +long long inv[100005]; +long long powmod(long long a, long long b) { + long long res = 1; + a %= mod; + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +int main() { + long long n; + cin >> n; + inv[1] = 1; + for (int i = 2; i < N; i++) { inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; } + long long d = powmod(2, n); + long long ans = d * (d + 1) % mod * inv[2] % mod; + cout << ans << endl; +} +int main() { + int x1, y1, x2, y2, x3, y3; + cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; + if ((y2 - y1) * (x3 - x2) == (y3 - y2) * (x2 - x1)) { + cout << "TOWARDS" << endl; + } else if (y1 == y2) { + if (x2 > x1) { + if (y3 > y2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } else { + if (y3 < y2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } + } else if (x1 == x2) { + if (y1 < y2) { + if (x3 > x2) + cout << "RIGHT" << endl; + else + cout << "LEFT" << endl; + } else { + if (x3 < x2) + cout << "RIGHT" << endl; + else + cout << "LEFT" << endl; + } + } else if (x1 < x2 && y1 < y2) { + if (x3 < x2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } else if (x1 > x2 && y1 > y2) { + if (x3 > x2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } else if (x1 < x2 && y1 > y2) { + if (x3 > x2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } else { + if (x3 < x2) + cout << "LEFT" << endl; + else + cout << "RIGHT" << endl; + } + return 0; +} +int sq[1001] = { + 0, +}; +int check(int x) { + if (!binary_search(sq, sq + 1001, x)) + return 1; + else + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i <= 1000; i++) { sq[i] = i * i; } + for (int i = 0; i < n; i++) cin >> a[i]; + int m = INT_MIN; + for (int i = 0; i < n; i++) { + if (a[i] > m && check(a[i])) { m = a[i]; } + } + cout << m << endl; +} +int main() { + char a[10], b[10]; + while (cin >> a >> b) { + int x1 = a[0] - 'a' + 1, y1 = a[1] - '0', x2 = b[0] - 'a' + 1, y2 = b[1] - '0'; + int ans = max(fabs(x1 - x2), fabs(y1 - y2)); + cout << ans << endl; + while (ans--) { + if (x1 != x2) { + if (x1 > x2) { + if (y1 == y2) { + x1--; + cout << "L" << endl; + } else if (y1 > y2) { + y1--; + x1--; + cout << "LD" << endl; + } else { + y2--; + x1--; + cout << "LU" << endl; + } + } else { + if (y1 == y2) { + x2--; + cout << "R" << endl; + } else if (y1 > y2) { + y1--; + x2--; + cout << "RD" << endl; + } else { + y2--; + x2--; + cout << "RU" << endl; + } + } + } else { + if (y1 > y2) { + y1--; + cout << "D" << endl; + } else { + y2--; + cout << "U" << endl; + } + } + } + } + return 0; +} +int i, j, a[6][6]; +bool b[6][6]; +int main() { + for (i = 1; i <= 3; i++) + for (j = 1; j <= 3; j++) cin >> a[i][j], a[i][j] %= 2; + for (i = 1; i <= 3; i++) + for (j = 1; j <= 3; j++) + if (a[i][j] == 1) { + b[i][j] = 1 - b[i][j]; + b[i][j + 1] = 1 - b[i][j + 1]; + b[i][j - 1] = 1 - b[i][j - 1]; + b[i + 1][j] = 1 - b[i + 1][j]; + b[i - 1][j] = 1 - b[i - 1][j]; + } + for (i = 1; i <= 3; i++, cout << endl) + for (j = 1; j <= 3; j++) cout << 1 - b[i][j]; + return 0; +} +int main() { + unsigned long long n; + cin >> n; + n % 2 == 0 ? cout << 2 << endl : cout << 1 << endl; + return 0; +} +int a[1000005]; +int main() { + string s; + cin >> s; + int l = s.length(); + int beg = 1, end = l; + for (int i = 0; i < l; i++) s[i] == 'l' ? a[end--] = i + 1 : a[beg++] = i + 1; + for (int i = 0; i < l; i++) cout << a[i + 1] << "\n"; + return 0; +} +int main() { + int n, x, b, cnt = 0; + priority_queue pq; + cin >> n >> b; + for (int i = 2; i <= n; i++) { + cin >> x; + pq.push(x); + } + x = pq.top(); + while (x >= b) { + x--, cnt++, b++; + pq.pop(); + pq.push(x); + x = pq.top(); + } + cout << cnt << endl; + return 0; +} +const long long E = 1e9; +long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, x, y, z; +string t, u, v, w; +bool A, B, C; +int main() { + cin >> x; + for (int q = 0; q < x; q++) { + cin >> s >> a >> b >> c; + r = 0; + e = s / c; + r += e; + r += e / a * b; + cout << r << '\n'; + } +} +const int N = 1e5 + 100; +string s; +int main() { + for (int i = 0; i < 8; i++) { + cin >> s; + if (s != "BWBWBWBW" && s != "WBWBWBWB") { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + vector jv; + int n, m, t = 0, jvb = 0; + cin >> n; + m = n; + while (m > 0) { + m /= 10; + t++; + } + int x = t * 9; + for (int i = n; i >= n - x && i > 0; i--) { + int sum = 0; + int j = i; + while (j > 0) { + sum += j % 10; + j /= 10; + } + if (sum + i == n) { + jvb++; + jv.push_back(i); + } + } + cout << jvb << endl; + sort(jv.begin(), jv.end()); + for (int i = 0; i < jv.size(); i++) cout << jv[i] << endl; +} +int main() { + int n, cnt1 = 0, cnt2 = 0; + cin >> n; + int x, y; + for (int i = 1; i <= n; i++) { + cin >> x >> y; + if (x < 0) + cnt1++; + else + cnt2++; + } + if (cnt1 <= 1 || cnt2 <= 1) + cout << "Yes\n"; + else + cout << "No\n"; + return 0; +} +int main() { + long long x, y, z; + cin >> x >> y; + z = (y - 1) / x; + z++; + cout << z << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int x = 3 * a; + if (x <= b) + cout << "0" << endl; + else + cout << x - b << endl; +} +int main() { + long long n, z = 2, a, x = 2; + cin >> n; + for (long long i = 1; i <= n; i++) { + a = i * (i + 1) * (i + 1) - z; + cout << a << endl; + x = i * (i + 1); + z = i; + } +} +int main() { + long int n, k, fi, ti, max = 0, x, y, joy; + cin >> n >> k; + cin >> fi >> ti; + if (ti > k) { + max = fi - (ti - k); + } else + max = fi; + while (--n) { + cin >> fi >> ti; + if (ti > k) { + joy = fi - (ti - k); + } else + joy = fi; + if (joy > max) max = joy; + } + cout << max << endl; + return 0; +} +char s[100010]; +bool flag, ok[1010], exist[1010]; +int ans; +int main() { + int n; + cin >> n; + flag = false; + ans = 0; + for (int i = 'a'; i <= 'z'; i++) ok[i] = 1; + int num = 26; + for (int i = 0; i < n; i++) { + char c; + cin >> c >> s; + if (flag) { + if (c != '.' && i != n - 1) ++ans; + } else { + if (c == '!') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; ++j) { + if (ok[j] && !exist[j]) { + --num; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '.') { + int len = strlen(s); + memset(exist, 0, sizeof(exist)); + for (int j = 0; j < len; j++) exist[s[j]] = 1; + for (int j = 'a'; j <= 'z'; ++j) { + if (ok[j] && exist[j]) { + --num; + ok[j] = 0; + } + } + if (num == 1) flag = true; + } else if (c == '?') { + if (ok[s[0]]) { + --num; + ok[s[0]] = 0; + } + if (num == 1) flag = true; + } + } + } + cout << ans << endl; + return 0; +} +int arr[105]; +int n; +int solve(int idx) { + int ret = 0; + for (int i = 0; i <= n - 1 - 1; i += 1) { + if (i == idx) { + ret = max(ret, abs(arr[i - 1] - arr[i + 1])); + } else { + ret = max(ret, abs(arr[i] - arr[i + 1])); + } + } + return ret; +} +int main() { + cin >> n; + for (int i = 0; i <= n - 1; i += 1) cin >> arr[i]; + int mn = 1000000; + for (int i = 1; i <= n - 2; i += 1) { mn = min(mn, solve(i)); } + cout << mn << endl; + return 0; +} +int main() { + map mp; + mp['6'] = 6; + mp['7'] = 7; + mp['8'] = 8; + mp['9'] = 9; + mp['T'] = 10; + mp['J'] = 11; + mp['Q'] = 12; + mp['K'] = 13; + mp['A'] = 14; + string t, f, s; + cin >> t >> f >> s; + if (f[1] != s[1]) { + if (f[1] == t[0]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } else { + if (mp[f[0]] > mp[s[0]]) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +long long max(long long a, long long b) { + return a > b ? a : b; +} +long long min(long long a, long long b) { + return a < b ? a : b; +} +long long modd(long long a) { + if (a < 0LL) return a * -1LL; + return a; +} +int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; +int main() { + int sc = 0, cc = 0; + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') + sc++; + else + cc++; + } + if (cc > sc) { + for (int i = 0; i < s.length(); i++) + if (s[i] >= 'a' && s[i] <= 'z') s[i] = int(s[i]) - 'a' + 'A'; + } else { + for (int i = 0; i < s.length(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') s[i] = int(s[i]) + ('a' - 'A'); + } + } + cout << s << endl; + return 0; +} +int main() { + string s; + cin >> s; + vector v; + for (int i = 0; i < s.size(); i += 2) v.push_back(s[i]); + sort(v.begin(), v.end()); + for (int i = 0; i < v.size(); i++) { + cout << v[i]; + if (i != v.size() - 1) cout << "+"; + } + cout << endl; +} +int main() { + int t; + long long s, a, b, c; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + int bt = s / c; + if (bt >= a) + cout << bt + (bt / a) * b << endl; + else + cout << bt << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int ans = 0; + for (int i = 0; i < n; i++) { ans += min(abs(b[i] - a[i]), 10 - abs(b[i] - a[i])); } + cout << ans << endl; +} +int main() { + string S; + cin >> S; + for (int a = 0; a < S.size(); a++) { + if (S[a] == '.') { + if (S[a - 1] == '9') { + cout << "GOTO Vasilisa." << endl; + return 0; + } + int tmp = S[a + 1] - '0'; + if (tmp >= 5) { + S[a - 1]++; + for (int z = 0; z < a; z++) cout << S[z]; + } else { + for (int z = 0; z < a; z++) cout << S[z]; + break; + } + } + } + cout << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int sum = 0; + while (1) { + sum += s / n; + s = s % n; + n--; + if (n == 0) break; + } + cout << sum << endl; + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return a * b / gcd(a, b); +} +int main() { + long long i, j; + long long n; + cin >> n; + string s; + cin >> s; + vector a(n); + for (long long i = 0; i < (n); i++) cin >> a[i]; + long long ans = 1e9; + for (long long i = 0; i < (n - 1); i++) + if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(ans, (a[i + 1] - a[i]) / 2); } + if (ans == 1e9) { + cout << -1 << endl; + } else { + cout << ans << endl; + } +} +int main() { + set st; + string s, t; + cin >> s; + for (int i = 0; i < s.length(); i++) { + t = s[s.length() - 1]; + s.erase(s.length() - 1); + s = t + s; + if (st.find(s) == st.end()) { st.insert(s); } + } + cout << st.size() << endl; + return 0; +} +int main() { + set st; + string s, p; + cin >> s; + for (int i = 0; i < s.length(); i++) { + p = s[s.length() - 1]; + s.erase(s.length() - 1); + s = p + s; + if (st.find(s) == st.end()) { st.insert(s); } + } + cout << st.size() << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int i = 0; i <= c / a; i++) { + if ((c - i * a) % b == 0) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char cr[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> cr[i][j]; } + } + map mp; + int res = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + mp.clear(); + mp[cr[i][j]]++; + mp[cr[i + 1][j]]++; + mp[cr[i][j + 1]]++; + mp[cr[i + 1][j + 1]]++; + if (mp['f'] == 1 && mp['a'] == 1 && mp['c'] == 1 && mp['e'] == 1) { res++; } + } + } + cout << res << endl; + return 0; +} +int main() { + int n, cun1[500], cun2[500], x, y, ans1 = 0, ans2 = 0; + memset(cun1, 0, sizeof(cun1)); + memset(cun2, 0, sizeof(cun2)); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (!cun1[x]) ans1++; + if (!cun2[y]) ans2++; + cun1[x]++; + cun2[y]++; + } + cout << min(ans1, ans2) << endl; + return 0; +} +int main() { + int n; + int m; + int a; + cin >> n; + m = n / 5; + a = n % 5; + if (a != 0) { m++; } + cout << m << endl; +} +int main() { + int n, m; + while (cin >> n >> m) { + int t = min(n, m); + if (t % 2) { + cout << "Akshat" << endl; + } else { + cout << "Malvika" << endl; + } + } +} +int vis[1000]; +int main() { + int m, n; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + int x, y; + cin >> x; + for (int j = 0; j < x; j++) { + cin >> y; + vis[y] = 1; + } + } + int flag = 0; + for (int i = 1; i <= m; i++) { + if (vis[i] == 0) { + flag = 1; + break; + } + } + if (flag) { + cout << "NO" << endl; + } else + cout << "YES" << endl; + } +} +int gcd(int x, int y) { + if (x == y) return x; + while (x != 0 && y != 0) { + if (x > y) + x %= y; + else + y %= x; + } + return x < y ? y : x; +} +int main() { + int x, y, a, b; + cin >> x >> y >> a >> b; + int z = x * y / gcd(x, y); + cout << b / z - (a - 1) / z << endl; + return 0; +} +int x[101]; +int main() { + int n, sum; + bool flag; + while (cin >> n) { + for (int i = 0; i < n; i++) cin >> x[i]; + while (1) { + sort(x, x + n); + flag = false; + for (int i = n - 1; i >= 1; i--) + if (x[i] > x[i - 1]) { + x[i] -= x[i - 1]; + flag = true; + break; + } + if (!flag) break; + } + sum = 0; + for (int i = 0; i < n; i++) sum += x[i]; + cout << sum << endl; + } + return 0; +} +int main() { + int n, p, maxc = 0, maxbi = 0, maxba = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p; + if ((i + 1) % 3 == 1) { + maxc += p; + } else if ((i + 1) % 3 == 2) { + maxbi += p; + } else { + maxba += p; + } + } + if (maxc > maxbi && maxc > maxba) { + cout << "chest" << endl; + } else if (maxbi > maxba) { + cout << "biceps" << endl; + } else { + cout << "back" << endl; + } + return 0; +} +int main() { + int i, j, k, l, m, n; + cin >> n >> k; + string s; + cin >> s; + int len = s.length(); + int a[27] = {0}; + for (i = 0; i < len; i++) a[s[i] - 'a' + 1] = 1; + int cnt = 0; + int flag = 0, ans = 0; + for (i = 1; i <= 26; i++) { + if (a[i] == 1) { + cnt++; + ans += i; + i++; + } + if (cnt >= k) { + flag = 1; + break; + } + } + if (flag) { + cout << ans << endl; + } else + cout << -1 << endl; +} +map mp1, mp2; +int main() { + mp1.clear(); + mp2.clear(); + int n, ans = 0; + string s[105]; + string str; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s[i]; + mp1[s[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> str; + if (!mp1[str]) + ans++; + else + mp2[str]++; + } + for (int i = 0; i < n; i++) + if (mp2[s[i]] - mp1[s[i]] > 0) ans += mp2[s[i]] - mp1[s[i]], mp2[s[i]] = -1; + cout << ans << endl; + return 0; +} +int main() { + string t1, t2; + cin >> t1; + cin >> t2; + int c1 = 0, c2 = 0; + for (int i = 0; i < t1.length(); i = i + 2) { + if ((t1.at(i) == '[') && (t2.at(i) == '(')) { + c1++; + } else if ((t1.at(i) == '(') && (t2.at(i) == '[')) { + c2++; + } else if ((t1.at(i) == '(') && (t2.at(i) == '8')) { + c1++; + } else if ((t1.at(i) == '8') && (t2.at(i) == '(')) { + c2++; + } else if ((t1.at(i) == '8') && (t2.at(i) == '[')) { + c1++; + } else if ((t1.at(i) == '[') && (t2.at(i) == '8')) { + c2++; + } + } + if (c1 > c2) { + cout << "TEAM 1 WINS" << endl; + } else if (c2 > c1) { + cout << "TEAM 2 WINS" << endl; + } else + cout << "TIE" << endl; +} +int main() { + int n; + cin >> n; + int a[15]; + for (int i = 1; i <= 12; i++) cin >> a[i]; + sort(a + 1, a + 13); + int sum = 0; + int ans = 0; + if (n == 0) { + puts("0"); + return 0; + } + for (int i = 12; i >= 1; i--) { + sum += a[i]; + ans++; + if (sum >= n) break; + } + if (sum >= n) + cout << ans << endl; + else + cout << -1 << endl; +} +int main() { + char arr[100]; + int a1; + gets(arr); + a1 = strlen(arr); + int out = ((a1 * 25) + 26); + cout << out << endl; +} +int main() { + int n; + string s; + cin >> n >> s; + long *a = new long[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + long mi = 999999999; + for (int i = 0; i < s.length() - 1; i++) { + if (s[i] == 'R' && s[i + 1] == 'L') mi = min(mi, (a[i + 1] - a[i]) / 2); + } + if (mi != 999999999) + cout << mi << endl; + else + cout << "-1" << endl; + return 0; +} +int r1[100001], r2[100001]; +int main() { + int a, b, c, d, e, f, g, h; + vector v; + while (cin >> a >> b) { + cin >> c >> d; + for (e = 1; e <= a; e++) { cin >> r1[e]; } + f = 0; + for (e = 1; e <= b; e++) { + cin >> r2[e]; + if (r2[e] > r1[c]) { f++; } + } + if (f >= d) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int a, n; +char p; +int main() { + while (cin >> p) { + if (a == 0) { + if (p == '1') a = 1; + } else { + if (p == '0') n++; + } + } + if (n >= 6) { + cout << "yes" << endl; + } else { + cout << "no" << endl; + } + return 0; +} +int day = 0; +void dfs(int a, int b) { + if (a > day) { + day = a; + } else { + dfs(a + b, b); + } +} +int main() { + int m; + cin >> m; + while (m) { + int a, b; + cin >> a >> b; + dfs(a, b); + m--; + } + cout << day << endl; +} +const int MAX = 1e6; +int main() { + int p, n, x; + cin >> p >> n; + map mp; + for (int i = 0; i < n; i++) { + cin >> x; + if (mp[x % p]) { + cout << i + 1 << endl; + return 0; + } + mp[x % p] = 1; + } + cout << -1 << endl; +} +int main() { + char a[20]; + cin >> a; + int len = strlen(a); + sort(a, a + len); + int t = len - 1; + char c = a[t]; + do { + cout << c; + t--; + c = a[t]; + } while (c == a[len - 1] && t >= 0); + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long int X = 2, R = 1; + while (n--) { + long long int M = R * (R + 1); + cout << M / R * M - X / R << "\n"; + X = M; + ++R; + } +} +const long long mod = 998244353; +const long long inf = 2e18; +const int maxn = 200005; +const int maxa = 300005; +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +long long powmod(long long a, long long b) { + long long res = 1; + a %= mod; + if (b < 0) return -1; + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +int INF = 10000000; +int main() { + int T; + int n, m, l, r; + int ans = 0; + string str; + cin >> n >> l >> r; + cin >> str; + int a[maxn]; + for (int i = 0; i < n; i++) a[i + 1] = str[i] - '0'; + if (a[l] == a[r]) return 0 * puts("0"); + puts("1"); +} +string str; +int vis[1005]; +int main() { + cin >> str; + int len = str.length(); + int sum = 0; + for (int t = 0; t < len - 1; t++) { + if (str[t] == 'V' && str[t + 1] == 'K') { + sum++; + vis[t] = 1; + vis[t + 1] = 1; + } + } + for (int t = 0; t < len - 1; t++) { + if (str[t] == 'V' || str[t + 1] == 'K') { + if (vis[t] == 0 && vis[t + 1] == 0) { + sum++; + break; + } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int r[n], d[n - 1], s(0), m(1000); + cin >> r[0]; + for (int i = 1; i < n; i++) { + cin >> r[i]; + d[i] = r[i] - r[i - 1]; + s = max(s, d[i]); + } + for (int i = 2; i < n; i++) m = max(min(m, d[i] + d[i - 1]), s); + cout << m << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int result = 0; + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) { result += 1; } + } + cout << result << endl; +} +int main() { + int m; + cin >> m; + int sum = 0; + vector c(m); + for (int i = 0; i < m; ++i) { + cin >> c[i]; + sum += c[i]; + } + int x, y; + cin >> x >> y; + int curr = 0; + for (int i = 0; i < m; ++i) { + if (curr >= x && curr <= y && sum - curr >= x && sum - curr <= y) { + cout << i + 1 << endl; + return 0; + } + curr += c[i]; + } + cout << 0 << endl; + return 0; +} +int a[110]; +int main() { + int n; + cin >> n; + int i; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + cout << a[n - 1] << " "; + for (i = 1; i < n - 1; i++) { cout << a[i] << " "; } + cout << a[0] << endl; + return 0; +} +int main() { + int n, x, y; + string str; + cin >> n >> x >> y; + cin >> str; + long long cnt = 0; + for (long long i = 0; i < n; i++) + if (str[i] == '0' && str[i + 1] == '1') cnt++; + if (str[n - 1] == '0') cnt++; + long long minn; + if (x < y) + minn = x * (cnt - 1) + y; + else + minn = y * cnt; + if (cnt == 0) minn = 0; + cout << minn << endl; + return 0; +} +const int maxn = (int)1e5 + 5; +const long long mod = 1e9 + 7; +bool vis[maxn]; +int lie[maxn]; +int hang[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> lie[i]; } + sort(lie + 1, lie + 1 + n, greater()); + int a, b, c; + int ans = 0; + int cnt = 0; + for (int i = 1; i <= m; i++) { + cin >> a >> b >> c; + if (a == 1) { hang[++cnt] = b; } + } + sort(hang + 1, hang + 1 + cnt, greater()); + int len = min(cnt, n); + int t = 0; + for (int i = 1; i <= cnt; i++) { + if (hang[i] == 1000000000) t++; + } + if (len != 0) { + for (int i = 1, j = 1; i <= n && j <= n;) { + if (hang[i] >= lie[j]) { + ans++; + i++; + j++; + } else + j++; + } + } + if (t > ans) ans = t; + cout << ans << endl; + return 0; +} +int main() { + int p = 0; + long long n, x = 1; + cin >> n; + while (x <= n) { + x *= 2; + p++; + if (x - 1 >= n) { + cout << p << endl; + return 0; + } + } + return 0; +} +int main() { + int p = 0, n = 0, x, y, m; + cin >> m; + while (m--) { + cin >> x >> y; + if (x < 0) + n++; + else + p++; + } + if (n <= 1 || p <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int maxn, minn = 0x7ffffff, ans = 0, q; +int main() { + int n; + int a[10000]; + cin >> n; + cin >> q; + maxn = q; + minn = q; + for (int i = 2; i <= n; i++) { + cin >> q; + if (q < minn) { + minn = q; + ans++; + } + if (q > maxn) { + maxn = q; + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m, l, r; + char c1, c2; + string s; + cin >> n >> m >> s; + for (int i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + l--; + r--; + while (l <= r) { + if (s[l] == c1) s[l] = c2; + l++; + } + } + cout << s << endl; + return 0; +} +int main() { + int n, a1 = 0, a2 = 0, a3 = 0, ans, t[5001], j; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t[i]; + if (t[i] == 1) a1++; + if (t[i] == 2) a2++; + if (t[i] == 3) a3++; + j = min(a1, a2); + ans = min(j, a3); + } + cout << ans << endl; + int b1[5001], b2[5001], b3[5001]; + for (int i = 0; i < n; i++) { + if (t[i] == 1) + b1[i] = i + 1; + else + b1[i] = 5002; + if (t[i] == 2) + b2[i] = i + 1; + else + b2[i] = 5002; + if (t[i] == 3) + b3[i] = i + 1; + else + b3[i] = 5002; + } + sort(b1, b1 + n); + sort(b2, b2 + n); + sort(b3, b3 + n); + for (int i = 0; i < ans; i++) { cout << b1[i] << " " << b2[i] << " " << b3[i] << endl; } + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + if (k >= 3 * n) + cout << "0" << endl; + else if (k <= 2 * n) + cout << n << endl; + else + cout << n - k + k / n * n << endl; + } + return 0; +} +int main() { + long long l, r, x, y, k; + cin >> l >> r >> x >> y >> k; + for (int b = x; b <= y; b++) { + long long a = k * b; + if (a >= l && a <= r) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +const int inf = 0x3f3f3f3f; +const int N = 1010; +long long a[N]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long ans = 0; + for (int i = 1; i < n; i++) ans += a[i] - a[i - 1] - 1; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s, s2; + cin >> s; + int i = 0; + int t = s.size(); + for (i = 1; i < n; ++i) { + cin >> s2; + for (int j = 0; j < t; ++j) { + if (s[j] != s2[j]) { + t = j; + break; + } + } + s = s2; + } + cout << t << endl; +} +bool can(int lim, vector v, int m) { + for (int i = 0; i < v.size(); i++) { + while (v[i] < lim && m > 0) { + v[i]++; + m--; + } + } + return m == 0; +} +int main() { + int n, m; + cin >> n >> m; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + int low = *max_element(v.begin(), v.end()), high = 1e8; + while (low <= high) { + int mid = (low + high) / 2; + if (can(mid, v, m)) + high = mid - 1; + else + low = mid + 1; + } + cout << low << " " << m + *max_element(v.begin(), v.end()) << endl; +} +int main() { + int n; + cin >> n; + int a, b, c; + cin >> a >> b >> c; + int m = min(c, min(a, b)); + if (n == 1) { + cout << 0 << endl; + } else { + if (m == min(a, b)) { + cout << (n - 1) * min(a, b) << endl; + } else { + cout << min(a, b) + (n - 2) * c << endl; + } + } + return 0; +} +int lin[101], col[101]; +int main() { + int n; + char p; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> p; + if (p == 'C') { + lin[i]++; + col[j]++; + } + } + } + long long ans = 0; + for (int i = 1; i <= n; i++) { + ans += lin[i] * (lin[i] - 1) / 2; + ans += col[i] * (col[i] - 1) / 2; + } + cout << ans << endl; + return 0; +} +long long mod = 1000000007; +long long int fast_exp(long long int base, long long int ex) { + long long int res = 1; + while (ex > 0) { + if (ex % 2 == 1) res = (res * base) % mod; + base = (base * base) % mod; + ex /= 2; + } + return res % mod; +} +long long int gcd(long long int a, long long int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + long long n; + cin >> n; + long long ar[5] = {0}; + long long a[n]; + long long b[n]; + long long ca[5] = {0}; + for (int i = 0; i < n; i++) { + cin >> a[i]; + a[i]--; + ar[a[i]]++; + ca[a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + b[i]--; + ar[b[i]]++; + } + for (int i = 0; i < 5; i++) + if (ar[i] % 2) { + cout << "-1\n"; + return 0; + } + long long ans = 0; + for (int i = 0; i < 5; i++) + if (ar[i]) ans += abs(ca[i] - (ar[i] / 2LL)); + ans /= 2; + cout << ans << "\n"; + return 0; +} +map cnt; +int main() { + long long disx = 0, disy = 0; + long long n; + cin >> n; + long long x, y; + long long ax[200], ay[200]; + memset(ax, 0, sizeof(ax)); + memset(ay, 0, sizeof(ay)); + for (int i = 0; i < n; i++) { + cin >> x >> y; + if (ax[x] == 0) { + disx++; + ax[x] = 1; + } + if (ay[y] == 0) { + disy++; + ay[y] = 1; + } + } + cout << min(disx, disy) << endl; +} +int main() { + long long a, b; + cin >> a >> b; + long long ans = abs(a) + abs(b); + long long x1 = ans * a / abs(a); + long long x2 = 0; + long long y1 = 0; + long long y2 = ans * b / abs(b); + if (x1 > 0) { + swap(x1, x2); + swap(y1, y2); + } + cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m; + cin >> n; + int s = 0; + while (n != 0) { + if (n >= 100) { + s += n / 100, n -= n / 100 * 100; + if (n == 0) break; + } else if (n >= 20) { + s += n / 20, n -= n / 20 * 20; + if (n == 0) break; + } else if (n >= 10) { + s += n / 10, n -= n / 10 * 10; + if (n == 0) break; + } else if (n >= 5) { + s += n / 5, n -= n / 5 * 5; + if (n == 0) break; + } else if (n >= 1) { + s += n / 1, n -= n / 1 * 1; + if (n == 0) break; + } + } + cout << s << endl; +} +bool check(int a, int b, vector &arr) { + return a >= 0 && a < 8 && b >= 0 && b < 8 && arr[a][b] != 0; +} +int step[4][2] = {{-2, -2}, {-2, 2}, {2, -2}, {2, 2}}; +int check1(vector &arr, long long int y, long long int x) { + arr[y][x] = 0; + for (long long int i = 0; i < (4); ++i) { + long long int y1 = y + step[i][0]; + long long int x1 = x + step[i][1]; + if (check(y1, x1, arr)) { + if (arr[y1][x1] == 'K') return 1; + int r = 0; + if ((r = check1(arr, y1, x1)) != -1) { return r + 1; } + } + } + return -1; +} +int main() { + srand(13); + cout << fixed << setprecision(15); + int n, k; + string s; + cin >> n >> k >> s; + int l = k - 1; + int r = n - k; + if (l < r) { + int pos = l; + while (pos) { + cout << "LEFT\n"; + --pos; + } + for (long long int i = 0; i < (n); ++i) { + cout << "PRINT " << s[i] << "\n"; + if (i != n - 1) { cout << "RIGHT\n"; } + } + } else { + int pos = k; + while (pos < n) { + cout << "RIGHT\n"; + ++pos; + } + for (long long int i = (n)-1; i >= 0; --i) { + cout << "PRINT " << s[i] << "\n"; + if (i != 0) { cout << "LEFT\n"; } + } + } + return 0; +} +const int N = 1e4 + 5; +long long n, k, res = -1e18, joy[N], t[N]; +void Input() { + cin >> n >> k; + for (int i = 1; i <= n; i++) cin >> joy[i] >> t[i]; +} +void Solve() { + for (int i = 1; i <= n; i++) { + if (t[i] <= k) + res = max(res, joy[i]); + else + res = max(res, joy[i] - (t[i] - k)); + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + int n, i, k, t, a; + while (cin >> n >> k) { + t = 0; + for (i = 0; i < n; i++) { + cin >> a; + if (a % k == 0) { + t += a / k; + } else + t += a / k + 1; + } + cout << (t + 1) / 2 << endl; + } + return 0; +} +const int maxn = 0x3f3f3f3f; +int main() { + int n; + cin >> n; + int day[n]; + for (int i = 0; i < n; ++i) cin >> day[i]; + int dp[n][3]; + for (int i = 0; i < n; ++i) { + dp[i][0] = 1; + if (day[i] == 0) { + dp[i][1] = maxn; + dp[i][2] = maxn; + } else if (day[i] == 1) { + dp[i][1] = 0; + dp[i][2] = maxn; + } else if (day[i] == 2) { + dp[i][1] = maxn; + dp[i][2] = 0; + } else if (day[i] == 3) { + dp[i][1] = 0; + dp[i][2] = 0; + } + } + for (int i = 1; i < n; ++i) { + dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1; + if (day[i] == 1) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + } else if (day[i] == 2) { + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } else if (day[i] == 3) { + dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]); + dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]); + } + } + int min = maxn; + for (int i = 0; i < 3; ++i) { + if (min > dp[n - 1][i]) min = dp[n - 1][i]; + } + cout << min << endl; + return 0; +} +int main() { + int n = 0; + cin >> n; + int gg = n; + int pp = n; + if (n < 0) { + gg = n / 10; + pp = (n / 100) * 10 + (n % 10); + } + if (pp > gg) { + n = pp; + } else { + n = gg; + } + cout << n << endl; + return 0; +} +int main() { + long long n, m; + int a, b; + cin >> n >> m >> a >> b; + cout << min(n % m * b, (m - n % m) * a) << endl; + return 0; +} +int main() { + int x, y; + cin >> x >> y; + if (x >= 0 && y >= 0) { + cout << "0 " << x + y << " " << x + y << " 0\n"; + } else if (x <= 0 && y >= 0) { + cout << x - y << " 0 0 " << -x + y << "\n"; + } else if (x >= 0 && y <= 0) { + cout << "0 " << -x + y << " " << x - y << " 0\n"; + } else { + cout << x + y << " 0 0 " << x + y << "\n"; + } + return 0; +} +int main() { + int a, b, c; + while (cin >> a >> b >> c) { + int number; + cin >> number; + int sum = 0; + int an; + for (int i = 1; i <= number; i++) { + cin >> an; + if (an > b && an < c) { sum++; } + } + cout << sum << endl; + } + return 0; +} +int w[100002], sum[100002], sumr[100002], ans = INT_MAX; +int main() { + int n, l, r, ql, qr; + cin >> n >> l >> r >> ql >> qr; + for (int i = 0; i < n; i++) { + cin >> w[i]; + if (i == 0) + sum[i] = w[i]; + else + sum[i] = w[i] + sum[i - 1]; + } + for (int i = n - 1; i >= 0; i--) { + if (i == n - 1) + sumr[i] = w[i]; + else + sumr[i] = w[i] + sumr[i + 1]; + } + ans = sumr[0] * r + qr * (n - 1); + for (int i = 0; i < n; i++) { + int cur = sum[i] * l + sumr[i + 1] * r; + if (i + 1 > n - 1 - i) + cur += (2 * i - n + 1) * ql; + else if (i + 1 < n - 1 - i) + cur += (n - 1 - i - (i + 1) - 1) * qr; + ans = min(ans, cur); + } + cout << ans << endl; +} +int main() { + int n, ans = 0; + cin >> n; + string s; + cin >> s; + for (int i = 0; i < n; i++) (s[i] == '1') ? ans++ : ans--; + cout << abs(ans) << endl; + return 0; +} +int main() { + int n[4][4], m[4][4]; + for (int i = 1; i <= 3; i++) { + cin >> n[i][1] >> n[i][2] >> n[i][3]; + m[i][1] = 1; + m[i][2] = 1; + m[i][3] = 1; + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + if (n[i][j] % 2 != 0) { + m[i][j] = (m[i][j] == 1) ? 0 : 1; + if (i == 2) { + m[i + 1][j] = m[i + 1][j] == 1 ? 0 : 1; + m[i - 1][j] = m[i - 1][j] == 1 ? 0 : 1; + } else if (i == 3) { + m[i - 1][j] = m[i - 1][j] == 1 ? 0 : 1; + } else { + m[i + 1][j] = m[i + 1][j] == 1 ? 0 : 1; + } + if (j == 2) { + m[i][j + 1] = m[i][j + 1] == 1 ? 0 : 1; + m[i][j - 1] = m[i][j - 1] == 1 ? 0 : 1; + } else if (j == 3) { + m[i][j - 1] = m[i][j - 1] == 1 ? 0 : 1; + } else { + m[i][j + 1] = m[i][j + 1] == 1 ? 0 : 1; + } + } + } + } + for (int i = 1; i <= 3; i++) { cout << m[i][1] << m[i][2] << m[i][3] << endl; } + return 0; +} +int arr[10005]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i + 1]; } + int s, t; + cin >> s >> t; + if (s > t) { swap(s, t); } + int aa = 0; + for (int i = s; i < t; i++) { aa += arr[i]; } + int bb = 0; + for (int i = 1; i < s; i++) { bb += arr[i]; } + for (int i = t; i <= n; i++) { bb += arr[i]; } + cout << min(aa, bb) << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int total = ceil((double)(a * c) / b); + int wait = total - c; + if (wait < 0) { + cout << 0 << endl; + } else { + cout << wait << endl; + } + return 0; +} +int main() { + int n, a, ans = 0, b; + priority_queue p; + cin >> n; + cin >> a; + for (int i = 0; i < n - 1; i++) { + cin >> b; + p.push(b); + } + while (1) { + b = p.top(); + p.pop(); + if (a <= b) { + a++; + ans++; + b--; + p.push(b); + } else + break; + } + cout << ans << endl; + return 0; +} +map mymap; +int main() { + int n, sum = 0; + cin >> n; + string s; + char ch; + int base = 0; + while (n--) { + cin >> ch >> s; + sum = 0, base = 0; + for (int i = s.length() - 1; i >= 0; i--) { + int k = s[i] - '0'; + if (k % 2) sum += pow(2, base); + base++; + } + if (ch == '+') + mymap[sum]++; + else if (ch == '-') + mymap[sum]--; + else + cout << mymap[sum] << endl; + } + return 0; +} +int main() { + string s; + int k; + cin >> s >> k; + if (k > s.size()) { + cout << "impossible\n"; + return 0; + } + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + cout << max(k - (int)s.size(), 0) << endl; + return 0; +} +double pi = acos(-1.0); +int main() { + long long n, m; + cin >> n >> m; + long long ans = 1, result = 1; + for (int i = 1; i <= m; i++) ans = (ans * 2) % 1000000009; + for (int i = 1; i <= n; i++) result = (result * (ans - i)) % 1000000009; + cout << result << endl; + return 0; +} +inline int getint() { + int r = 0, k = 1; + char c = getchar(); + for (; c < '0' || c > '9'; c = getchar()) + if (c == '-') k = -1; + for (; c >= '0' && c <= '9'; c = getchar()) r = r * 10 + c - '0'; + return r * k; +} +int main() { + int n = getint(); + int m = getint(); + int maxx = 0; + for (int i = 1; i <= n; i++) { + int x = getint(); + int y = getint(); + if (maxx >= x) maxx = max(maxx, y); + } + if (maxx >= m) + puts("YES"); + else + puts("NO"); + return 0; +} +int main() { + int n, maxval, gcd; + cin >> n; + vector arr(n); + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + maxval = i == 0 ? arr[i] : max(maxval, arr[i]); + gcd = i == 0 ? arr[i] : __gcd(gcd, arr[i]); + } + maxval /= gcd; + for (int i = 0; i < n; ++i) { arr[i] /= gcd; } + cout << ((maxval - n) % 2 ? "Alice\n" : "Bob\n"); +} +int euclides(int x, int y) { + int k; + while (x % y != 0) { + k = x % y; + x = y; + y = k; + } + return y; +} +int main() { + int n, mcd, ans, total, i; + cin >> n; + vector V(n); + for (i = 0; i < n; i++) { cin >> V[i]; } + sort(V.begin(), V.end()); + mcd = V[0]; + for (i = 1; i < n; i++) { mcd = euclides(mcd, V[i]); } + ans = V[n - 1] / mcd; + total = 1; + for (i = 1; i < n; i++) { + if (V[i] != V[i - 1]) total++; + } + ans -= total; + if (ans % 2 == 0) + cout << "Bob" << '\n'; + else + cout << "Alice" << '\n'; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int cur = 0; + for (int i = 1;; ++i) { + if (b >= k - 1) { + b -= (k - 1); + cur += v * k; + } else { + if (b > 0) { + cur += (b + 1) * v; + b = 0; + } else { + cur += v; + } + } + if (cur >= a) { + cout << i << "\n"; + return 0; + } + } + return 0; +} +int main() { + int n, i, j, maxx; + cin >> n; + int a[n]; + int freq[101] = {0}; + for (int i = 0; i < n; i++) { + cin >> a[i]; + freq[a[i]]++; + } + {} + maxx = INT_MIN; + for (int i = 0; i < 101; i++) { + if (freq[i] >= maxx) { maxx = freq[i]; } + } + cout << maxx << endl; + return 0; +} +int n; +int main() { + while (cin >> n) { cout << (n > 10 && n < 22) * 4 + (n == 20) * 11 << endl; } + return 0; +} +const int INF = INT_MAX; +const long long INFL = LLONG_MAX; +const long double pi = acos(-1); +long long K, N, S, P; +int main() { + cout.precision(15); + cout << fixed; + cin >> K >> N >> S >> P; + long long numsheets = K * ((N + S - 1) / S); + long long numpacks = (numsheets + P - 1) / P; + cout << numpacks << '\n'; +} +int main() { + long long l, r, k = 1; + cin >> l >> r; + while (k <= r) { k *= 10; } + long long th = k / 2, ch; + if (l >= th) + ch = l; + else if (r < th) + ch = r; + else + ch = th; + cout << ch * (k - 1 - ch) << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else { + cout << "Ehab" << endl; + } + return 0; +} +int main() { + int arr[] = {1, 5, 10, 20, 100}; + int count = 0, n, m, i, j; + cin >> n; + for (i = 4; i >= 0; i--) { + if (n >= arr[i]) { + m = n / arr[i]; + count = count + m; + if (n % arr[i] == 0) + break; + else { + m = n / arr[i]; + n = n - (m * arr[i]); + } + } + } + cout << count << endl; +} +int main() { + string s; + cin >> s; + int len = s.length(); + int ans = 0, l = 0, kh = 0; + int i, j; + for (i = 0; i < len; i++) { + l = 0, kh = 0; + for (j = i; j < len; j++) { + if (s[j] == '(') + l++; + else if (s[j] == '?') + l--, kh++; + else + l--; + if (l < 0 && kh == 0) + break; + else if (l < 0 && kh > 0) { + l += 2; + kh--; + } + if (l == 0) ans++; + } + } + cout << ans << endl; +} +int main() { + int n, k; + cin >> n >> k; + int left = 240 - k; + int i = 0; + int res = 0; + while (i <= n) { + if (5 * i * (i + 1) / 2 == left) { + res = i; + break; + } + if ((5 * i * (i + 1) / 2) > left) { + res = i - 1; + break; + } + i++; + } + if (i > n) { res = n; } + cout << res << endl; + return 0; +} +long long int n, b, p; +int main() { + cin >> n >> b >> p; + long long int bByGame = b * 2 + 1; + long long int towels = p * n; + long long int bottles = 0; + while (n > 1) { + long long int num = log2(n); + bottles += num * bByGame; + n -= num; + } + cout << bottles << " " << towels << endl; + return 0; +} +int main() { + long long n, i, j, r, mn, mx, x, cnt = 0, a = 1, b = 1; + string s; + cin >> n; + for (i = 0; i < n; i++) { + cin >> s; + if (s == "UR" || s == "DL") + a++; + else if (s == "UL" || s == "DR") + b++; + else { + a++, b++; + } + } + cout << a * b << endl; + return 0; +} +long long n, a, b, c, d; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a >> b >> c >> d; + cout << a / d + (a / d / b) * c << "\n"; + } +} +int main() { + long long i, j, k; + long long n, m; + cin >> n; + m = sqrt(n * 2); + j = m * (m + 1) / 2; + if (j > n) { + m--; + j = m * (m + 1) / 2; + } + k = n % j; + if (!k) + cout << m << endl; + else + cout << k << endl; + return 0; +} +int main() { + int n, res = INT_MAX; + char c; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> c; + if (c == '0') { res = min(res, i); } + } + cout << min(n, res) << endl; +} +int main() { + int n; + cin >> n; + string s1, s2; + cin >> s1 >> s2; + int x = 0; + for (int i = 0; i < n; i++) { + int s = abs(s1[i] - s2[i]); + x += min(s, 10 - s); + } + cout << x << "\n"; + return 0; +} +string ans(int i, int j, string s) { + string p = ""; + for (i; i <= j; i++) { p += s[i]; } + return p; +} +int arr[30]; +int main() { + int k, n, i, j = 1, l = 0, m; + vector vii; + string s, p = ""; + cin >> k >> s; + vector viii; + arr[s[0] - 'a'] = 1; + viii.push_back(s.size() - 1); + for (i = 1; i < s.size(); i++) { + if (!arr[s[i] - 'a']) { + arr[s[i] - 'a'] = 1; + if (j == k) { break; } + viii.push_back(i - 1); + j++; + } + } + sort(viii.begin(), viii.end()); + for (i = 0; i < viii.size(); i++) { + p = ans(l, viii[i], s); + vii.push_back(p); + l = viii[i] + 1; + } + if (vii.size() < k) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + for (i = 0; i < vii.size(); i++) { cout << vii[i] << endl; } + } +} +vector v; +long long LOVE(long long n) { + long long s = 0; + while (n != 0) { + s += n % 10; + n = n / 10; + } + return s; +} +int main() { + long long n; + cin >> n; + for (int i = n; i > n - 100; i--) { + if (LOVE(i) + i == n) v.push_back(i); + } + cout << v.size() << endl; + sort(v.begin(), v.end()); + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (m % n != 0) { + cout << (m / n) + 1 << endl; + } else + cout << (m / n) << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 1; i <= k; i++) { + if (n % 10 != 0) { + n--; + } else { + n = n / 10; + } + } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + int found, fin = 0; + do { + found = a.find("ogo"); + fin = found + 2; + while (a[fin + 1] == 'g' && a[fin + 2] == 'o') fin += 2; + if (found != -1) a.replace(found, fin + 1 - found, "***"); + } while (found != -1); + cout << a << endl; + return 0; +} +int main() { + int n; + cin >> n; + int A[n], B[n], i, j, k = 0, d = 0, l = 0, m = 0, t = 0; + for (i = 0; i < n; i++) { cin >> A[i] >> B[i]; } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i != j) { + if (A[i] < A[j] && B[i] == B[j]) { d = 1; } + if (A[i] > A[j] && B[i] == B[j]) { t = 1; } + if (A[i] == A[j] && B[i] > B[j]) { k = 1; } + if (A[i] == A[j] && B[i] < B[j]) { m = 1; } + } + } + if (m == 1 && k == 1 && t == 1 && d == 1) { l++; } + m = 0; + k = 0; + t = 0; + d = 0; + } + cout << l << endl; + return 0; +} +int main() { + string path, instr; + cin >> path; + cin >> instr; + int i = 0; + int pos = 1; + while (i < instr.length()) { + if (path[pos - 1] == instr[i]) { pos++; } + i++; + } + cout << pos << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int resultado, mltotal, lemoes, sal, resultadofinal; + mltotal = (k * l) / nl; + lemoes = c * d; + sal = p / np; + resultado = min(min(mltotal, lemoes), sal); + resultadofinal = resultado / n; + cout << resultadofinal << endl; +} +int min(int a, int b) { + return a < b ? a : b; +} +int max(int a, int b) { + return a > b ? a : b; +} +int main() { + int n, b, p, matches = 0; + int x = 256; + cin >> n >> b >> p; + int N = n; + while (n != 1) { + if (x > n) { + x /= 2; + continue; + } + n -= x / 2; + matches += x / 2; + } + cout << matches * (1 + 2 * b) << " " << N * p << endl; +} +int n, m, a[128], b, i, ans; +int main() { + cin >> n >> m; + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + ans = max(a[0] * 2, a[n - 1]); + while (m--) { + cin >> b; + if (b <= ans) ans = -1; + } + cout << ans << endl; + return 0; +} +int gcd(int a, int b) { + int mini = min(a, b); + int maxi = max(a, b); + if (mini == 0) { return maxi; } + return gcd(mini, maxi % mini); +} +int a[100005]; +int d[1000005]; +int main() { + for (int i = 1; i < 1000005; i++) { + if (i % 2 == 0 || i % 3 == 0) { d[i] = 1; } + } + for (int i = 4; i * i < 1000005; i++) { + if (!d[i]) { + for (int j = i; j < 1000005; j = j + i) { d[j] = 0; } + } + } + int n, g, p; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + bool b = true; + g = a[0]; + for (int i = 1; i < n; i++) { g = gcd(a[i], g); } + for (int i = 0; i < n; i++) { + int temp = a[i] / g; + while (temp % 2 == 0 && temp > 1000004) { temp = temp / 2; } + while (temp % 3 == 0 && temp > 1000004) { temp = temp / 3; } + if (temp > 1000004 || (temp != 1 && !d[temp])) { b = false; } + } + if (b) + cout << "Yes" << endl; + else { + cout << "No" << endl; + } +} +int main() { + int a, b, c; + cin >> a >> b >> c; + a = (a * b) / __gcd(a, b); + cout << c / a << endl; +} +int main() { + int arr[1000 + 10]; + int n, k; + cin >> n >> k; + int temp = k; + --n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n, greater()); + while (temp <= arr[0]) { + int j = arr[0]; + j--; + arr[0] = j; + temp++; + sort(arr, arr + n, greater()); + } + cout << temp - k << endl; +} +int main() { + string s; + cin >> s; + int l = s.size(); + int one = 0, two = 0, three = 0; + for (int i = 0; i < l; i++) { + if (s[i] == '1') + one++; + else if (s[i] == '2') { + two++; + } else if (s[i] == '3') { + three++; + } else { + continue; + } + } + for (int i = 0; i < one; i++) { + cout << "1"; + if (two == 0 and three == 0 and i == one - 1) { + cout << endl; + continue; + } + cout << "+"; + } + for (int i = 0; i < two; i++) { + cout << "2"; + if (three == 0 and i == two - 1) { + cout << endl; + continue; + } + cout << "+"; + } + for (int i = 0; i < three; i++) { + cout << "3"; + if (i == three - 1) { + cout << endl; + continue; + } + cout << "+"; + } + return 0; +} +int main() { + int n, x, y, m = 0, c = 0, i; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> x >> y; + if (x > y) + m++; + else if (x < y) + c++; + else if (x == y) { + m++; + c++; + } + } + if (m > c) + cout << "Mishka\n"; + else if (c > m) + cout << "Chris\n"; + else if (m == c) + cout << "Friendship is magic!^^\n"; + return 0; +} +int main() { + long long n; + cin >> n; + cout << (n / 2) * 3 << "\n"; + return 0; +} +int main() { + int n, a; + cin >> n; + int u = 0; + for (int i = 0; i < n; i++) { + cin >> a; + u += abs(a); + } + cout << u << endl; + return 0; +} +long long s, x, d, ans, cnt = 0, zero = 0, i = 0; +int main() { + cin >> s >> x; + d = s - x; + if (s < x || (d % 2 == 1)) { + cout << 0 << "\n"; + return 0; + } + d /= 2; + while (d || x) { + ++i; + if (!(d & 1)) { + if (!(x & 1)) { + ++zero; + } else { + ++zero; + ++cnt; + } + } else { + if (x & 1) { + cout << 0 << "\n"; + return 0; + } + } + d >>= 1; + x >>= 1; + } + ans = (1LL << cnt); + if (zero == i) { ans -= 2; } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + string s; + cin >> n; + while (n--) { + cin >> s; + if (s.length() > 10) { + cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; + } else { + cout << s << endl; + } + } + return 0; +} +int main() { + int n, a[101], x, mx = 0; + a[0] = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + a[i] = a[i - 1] + x; + } + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) mx = max(a[n] + j - i + 1 - 2 * (a[j] - a[i - 1]), mx); + cout << mx << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 == 0) + n /= 10; + else + n--; + } + cout << n << endl; + return 0; +} +int main() { + int n, p, q, r = 0; + cin >> n; + while (n--) { + cin >> p >> q; + if (q - p >= 2) { r++; } + } + cout << r << endl; + return 0; +} +int n, a, b, c, d, e, f; +string s; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> s; + if (s == "purple") a++; + if (s == "green") b++; + if (s == "blue") c++; + if (s == "orange") d++; + if (s == "red") e++; + if (s == "yellow") f++; + } + cout << 6 - n << endl; + if (a == 0) { cout << "Power" << endl; } + if (b == 0) { cout << "Time" << endl; } + if (c == 0) { cout << "Space" << endl; } + if (d == 0) { cout << "Soul" << endl; } + if (e == 0) { cout << "Reality" << endl; } + if (f == 0) { cout << "Mind" << endl; } +} +int main() { + string s; + for (long long i = 0; i < 8; i++) { + cin >> s; + for (long long j = 0; j < 7; j++) { + if (s[j] == s[j + 1]) { + cout << "NO" << '\n'; + return 0; + } + } + } + cout << "YES" << '\n'; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + string s; + cin >> s; + if (s.size() <= 10) { + cout << s << "\n"; + continue; + } else { + cout << s[0] << s.size() - 2 << s[s.size() - 1] << "\n"; + } + } + return 0; +} +int main() { + int n, m, i, j, pos = 0; + cin >> n >> m; + int c[n], a[m]; + for (i = 0; i < n; i++) { cin >> c[i]; } + for (j = 0; j < m; j++) { cin >> a[j]; } + for (i = 0; i < n; i++) { + if (pos < m) { + if (a[pos] >= c[i]) { + pos = pos + 1; + } else { + continue; + } + } + } + cout << pos << endl; + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + char a[n + 5][m + 5]; + for (long long i = 1; i <= n; i++) { + for (long long j = 1; j <= m; j++) { cin >> a[i][j]; } + } + for (long long i = 1; i <= n; i++) { + for (long long j = 1; j <= m; j++) { + if (a[i][j] == '.') { + if ((i + j) % 2 == 0) { + a[i][j] = 'B'; + } else { + a[i][j] = 'W'; + } + } + } + } + for (long long i = 1; i <= n; i++) { + for (long long j = 1; j <= m; j++) { cout << a[i][j]; } + cout << endl; + } + return 0; +} +map mp; +int main() { + int q; + cin >> q; + for (int qq = 0; qq < q; qq++) { + int t; + cin >> t; + if (t == 1) { + long long v, u, w; + cin >> v >> u >> w; + while (v != u) { + if (v < u) swap(v, u); + mp[v] += w; + v /= 2; + } + } else { + long long v, u; + cin >> v >> u; + long long ans = 0; + while (v != u) { + if (v < u) swap(v, u); + ans += mp[v]; + v /= 2; + } + cout << ans << '\n'; + } + } + return 0; +} +int main() { + int number_of_lessons; + cin >> number_of_lessons; + int cnt = 0; + bool lessons[100]{}; + for (int i = 0; i < number_of_lessons; i++) { cin >> lessons[i]; } + for (int i = 1; i < number_of_lessons - 1; i++) { + if (!lessons[i] && lessons[i - 1] && lessons[i + 1]) lessons[i] = 1; + } + for (int i = 0; i < number_of_lessons; i++) { + if (lessons[i]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << "+------------------------+" << endl; + cout << "|"; + if (n >= 1) + cout << "O."; + else + cout << "#."; + for (int a = 1; a <= 10; a++) + if (n >= 3 * a + 2) + cout << "O."; + else + cout << "#."; + cout << "|D|)" << endl; + cout << "|"; + if (n >= 2) + cout << "O."; + else + cout << "#."; + for (int a = 1; a <= 10; a++) + if (n >= 3 * a + 3) + cout << "O."; + else + cout << "#."; + cout << "|.|" << endl; + cout << "|"; + if (n >= 3) + cout << "O."; + else + cout << "#."; + cout << "......................|" << endl; + cout << "|"; + if (n >= 4) + cout << "O."; + else + cout << "#."; + for (int a = 1; a <= 10; a++) + if (n >= 3 * a + 4) + cout << "O."; + else + cout << "#."; + cout << "|.|)" << endl; + cout << "+------------------------+" << endl; + return 0; +} +int main() { + int a, b, c = 0; + cin >> a >> b; + while (a <= b) { + a = a * 3; + b = b * 2; + c++; + } + cout << c << endl; +} +int main() { + int n, m, r; + while (cin >> n >> m >> r) { + if (r * 2 <= n && r * 2 <= m) + cout << "First" << endl; + else + cout << "Second" << endl; + } +} +int a[100], b[100]; +int main() { + int m, n, mx = 0, cnt = 0; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; i++) { + cin >> b[i]; + for (int j = 1; j <= n; j++) { + if (b[i] % a[j] == 0) { + if (mx < b[i] / a[j]) { + mx = b[i] / a[j]; + cnt = 1; + } else if (mx == b[i] / a[j]) + cnt++; + } + } + } + cout << cnt << endl; +} +int main() { + string s; + cin >> s; + int num = 0; + int len = s.length(); + for (int i = 0; i < len; i++) { + int r = 0, t = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') { + r++; + } else if (s[j] == ')') { + r--; + } else { + r--; + t++; + } + if (r == 0) num++; + if (r < 0) { + if (t == 0) + break; + else { + r += 2; + t--; + } + } + } + } + cout << num << endl; +} +const int LIM = 1e2 + 10; +bool vis[LIM] = {}; +int main() { + int nb, nbulb; + cin >> nb >> nbulb; + while (nb--) { + int qt; + cin >> qt; + while (qt--) { + int a; + cin >> a; + vis[a] = 1; + } + } + for (int i = 1; i <= nbulb; i++) { + if (vis[i] == 0) { + cout << "NO\n"; + return 0; + } + } + cout << "YES\n"; + return 0; +} +int n, i; +int main() { + cin >> n; + for (i = 1; i <= 40; i++) + if (i * (i + 1) * (i + 2) / 6 > n) break; + cout << i - 1 << endl; +} +int main() { + int n, tmp = 0, hitung = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + hitung += ((i * (i + 1)) / 2); + if (hitung == n) { + tmp = i; + break; + } else if (hitung > n) { + tmp = i - 1; + break; + } + } + cout << tmp << endl; +} +const int N = 1005; +int a[N], b[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; ++i) cin >> a[i]; + for (int i = 1; i <= n; ++i) cin >> b[i]; + long long ans = 0; + for (int i = 1; i <= n; ++i) { + long long ans1 = a[i], ans2 = b[i]; + ans = max(ans, ans1 + ans2); + for (int j = i + 1; j <= n; ++j) { + if (i == 1) ans1 |= a[j]; + ans2 |= b[j]; + ans = max(ans, ans1 + ans2); + } + } + cout << ans << endl; +} +int main() { + int number; + cin >> number; + int numberOfLucky, i; + cin >> numberOfLucky; + int fcounter = 0; + long int arr[100]; + for (i = 0; i < number; i++) { cin >> arr[i]; } + int counter = 0; + for (i = 0; i < number; i++) { + while (arr[i] != 0) { + int rem; + rem = arr[i] % 10; + arr[i] = arr[i] / 10; + if (rem == 4 || rem == 7) { counter++; } + } + if (counter <= numberOfLucky) { fcounter++; } + counter = 0; + } + cout << fcounter << endl; + return 0; +} +int N, A, B, K[25], ans, x, y; +int main() { + cin >> N >> A >> B; + for (int i = 1; i <= N; i++) cin >> K[i]; + for (int i = 1; i <= (N + 1) / 2; i++) { + if (K[i] == K[N - i + 1] && (K[i] != 2 && K[N - i + 1] != 2)) + continue; + else if ((K[i] == 0 && K[N - i + 1] == 2) || (K[i] == 2 && K[N - i + 1] == 0)) + ans += A; + else if ((K[i] == 1 && K[N - i + 1] == 2) || (K[i] == 2 && K[N - i + 1] == 1)) + ans += B; + else if (K[i] == 2 && K[N - i + 1] == 2 && i == N - i + 1) + ans += min(A, B); + else if (K[i] == 2 && K[N - i + 1] == 2) + ans += 2 * min(A, B); + else if (K[i] != K[N - i + 1]) { + cout << -1 << '\n'; + return 0; + } + } + cout << ans << '\n'; +} +int a, b, r; +int main() { + cin >> a >> b >> r; + if (a < r * 2 || b < r * 2) + cout << "Second" << endl; + else + cout << "First" << endl; + return 0; +} +const int maxn = 5000 + 10; +int main() { + string s; + cin >> s; + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int q = 0, cnt = 0; + for (int j = i; j < n; j++) { + if (s[j] == '?') + q++; + else if (s[j] == '(') + cnt++; + else + cnt--; + while (q > 0 && q > cnt) { + q--; + cnt++; + } + if (cnt < 0) break; + if (q >= cnt && (j - i + 1) % 2 == 0) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (p == q) { + if (x == y) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + if (p == 0) { + if (x == 0) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + long long l = 0, r = 1e10; + long long b = y / q * q; + if (y % q) b += q; + for (int id = 0; id < 100; id++) { + long long mid = (l + r) / 2; + long long temp = p * b / q + mid * p; + if (temp >= x && temp <= (x + mid * q + b - y)) + r = mid; + else + l = mid; + } + cout << b + r * q - y << endl; + } + return 0; +} +int a[105]; +int n, x, y, i, l, r; +int sum, j; +int main() { + cin >> n; + cin >> x >> y; + for (i = 1; i < n; i++) { + cin >> l >> r; + for (j = l; j < r; j++) { a[j] = 1; } + } + sum = 0; + for (i = x; i < y; i++) { + if (a[i] == 0) sum++; + } + cout << sum << endl; +} +int main() { + int n, k, cntr = 0; + cin >> n >> k; + string s; + bool f; + for (int i = 0; i < n; i++) { + cin >> s; + for (int j = 0; j <= k; j++) { + if (s.find(j + '0') != string::npos) { + f = 1; + } else { + f = 0; + break; + } + } + if (f) cntr++; + } + cout << cntr << endl; + return 0; +} +const int maxn = 1e5 + 5; +int main() { + long long n; + cin >> n; + if (n % 2) + cout << "1" << endl; + else + cout << "2" << endl; +} +const int mod = 1000000007; +int main() { + string second; + cin >> second; + int i; + vector l, r; + for (i = 0; i < second.length(); i++) { + if (second[i] == 'l') + l.push_back(i + 1); + else + r.push_back(i + 1); + } + for (i = 0; i < r.size(); i++) { cout << r[i] << "\n"; } + for (i = l.size() - 1; i >= 00; i--) { cout << l[i] << "\n"; } + return 0; +} +int a, b, c; +int main() { + cin >> a >> b >> c; + double x = a * c, y = b * c, ans = ceil((x - y) / b); + cout << ans << '\n'; + return 0; +} +int main() { + int ans = 0; + int n; + cin >> n; + string s; + cin >> s; + while (n--) { + string ss, str; + cin >> ss; + int i; + for (i = 0; ss[i] != '-'; i++) str += ss[i]; + if (str == s) + ans++; + else { + str.clear(); + i += 2; + for (; ss[i] != '\0'; i++) str += ss[i]; + if (str == s) ans++; + } + } + if (ans % 2) + cout << "contest" << endl; + else + cout << "home" << endl; + return 0; +} +int main() { + int n, i, cnt = 0; + cin >> n; + cout << n * 2 - n / 2 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << max(a, max(b, c)) - min(a, min(b, c)) << endl; + return 0; +} +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i += 2) { + for (int j = 0; j < (n - i) / 2; j++) { cout << '*'; } + for (int j = 0; j < i; j++) { cout << 'D'; } + for (int j = 0; j < (n - i) / 2; j++) { cout << '*'; } + cout << endl; + } + for (int i = n - 2; i > 0; i -= 2) { + for (int j = 0; j < (n - i) / 2; j++) { cout << '*'; } + for (int j = 0; j < i; j++) { cout << 'D'; } + for (int j = 0; j < (n - i) / 2; j++) { cout << '*'; } + cout << endl; + } +} +int main() { + string s1, s2; + cin >> s1 >> s2; + int f = 0, s = 0; + for (int i = 0; i < (int)s1.length(); i += 2) { + if (s1[i] == '[' && s2[i] == '(') { + f++; + } else if (s1[i] == '(' && s2[i] == '[') { + s++; + } else if (s1[i] == '(' && s2[i] == '8') { + f++; + } else if (s1[i] == '8' && s2[i] == '(') { + s++; + } else if (s1[i] == '8' && s2[i] == '[') { + f++; + } else if (s1[i] == '[' && s2[i] == '8') { + s++; + } + } + if (f > s) { + cout << "TEAM 1 WINS" << endl; + } else if (s > f) { + cout << "TEAM 2 WINS" << endl; + } else { + cout << "TIE" << endl; + } + return 0; +} +int i, j; +int cnt(int n) { + int ans = 1, res; + for (int i = 2; i * i <= n; i++) { + res = 0; + while (n % i == 0) { + n /= i; + res++; + } + ans *= res + 1; + } + return ans; +} +int main() { + int n, x, ans = 0; + cin >> n >> x; + for (i = 1; i * i <= x && i <= n; i++) { + if (x % i) continue; + if (x / i <= n) { ans += 2; } + if (i * i == x) ans--; + } + cout << ans << endl; +} +int main() { + int a[100500], b[100040]; + int na, nb; + int x1, x2, y1, y2; + int i, k, j, m; + char s[20000][20]; + cin >> na >> nb; + cin >> k >> m; + for (i = 0; i < na; i++) cin >> a[i]; + for (j = 0; j < nb; j++) cin >> b[j]; + sort(a, a + na); + sort(b, b + nb); + for (i = 0; i < nb; i++) + if (b[i] > a[k - 1]) break; + if (i + m <= nb) { + cout << "YES" << endl; + return 0; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + sort(v.rbegin(), v.rend()); + int cnt = k; + for (int i = 0; i < n; i++) { + if (cnt >= m) { + cout << i << endl; + return 0; + } + cnt += v[i] - 1; + } + if (cnt >= m) + cout << n << endl; + else + cout << -1 << endl; + return 0; +} +const long long int mod = 998244353; +const long long int N = 100005; +const long long int MAX = 1e6 + 3; +long long int modPow(long long int a, long long int b) { + long long int res = 1; + a %= mod; + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +long long int nCr(long long int n, long long int k) { + long long int res = 1; + if (n < k) return 0; + if (k > n - k) k = n - k; + for (long long int i = 0; i < k; ++i) { + res = (res * (n - i)) % mod; + res = (res * modPow(i + 1, mod - 2)) % mod; + } + return res; +} +set s; +void Sieve() { + bool prime[1000009]; + memset(prime, true, sizeof(prime)); + for (long long int p = 2; p * p <= 1000006; p++) + if (prime[p] == true) + for (long long int i = p * 2; i <= 1000006; i += p) prime[i] = false; + for (long long int i = 2; i < 1000006; i++) + if (prime[i] == true) s.insert(i); +} +long long int factorial(long long int n) { + if (n == 1) return 1; + return (n * factorial(n - 1)) % mod; +} +long long int catalan(long long int n) { + return (nCr(2 * n, n) * modPow(n + 1, mod - 2)) % mod; +} +int main() { + long long int t; + cin >> t; + while (t--) { + int n; + cin >> n; + string s; + cin >> s; + int f = 0; + for (int i = 0; i < n; i++) { + if (s[i] != s[n - 1 - i]) { + f = 1; + break; + } + } + if (f == 0) { + cout << "YES" + << "\n"; + continue; + } + for (int i = 0; i < n / 2; i++) { + if (s[i] != s[n - 1 - i]) { + if (s[i] - 1 == s[n - 1 - i] + 1 || s[i] + 1 == s[n - 1 - i] - 1) { + } else { + f = 0; + break; + } + } + } + if (f) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + } +} +int main() { + char arr[100]; + int a1; + gets(arr); + a1 = strlen(arr); + int out = ((a1 * 25) + 26); + cout << out << endl; +} +int main() { + int n; + cin >> n; + cout << __builtin_popcount(n) << endl; + return 0; +} +int s[1020]; +int main() { + int n, a, b; + cin >> n >> a >> b; + int i, j; + for (i = 0; i < n; i++) { cin >> s[i]; } + int ans = 0; + int flas = 0; + int l = (a < b ? a : b); + for (i = 0, j = n - 1; j > i; j--, i++) { + if ((s[i] == 1 && s[j] == 0) || (s[j] == 1 && s[i] == 0)) { + flas = 1; + break; + } + if (s[i] == 2 && s[j] == 2) + ans += l * 2; + else if (s[i] == 2) { + if (s[j] == 1) + ans += b; + else + ans += a; + } else if (s[j] == 2) { + if (s[i] == 1) { + ans += b; + } else { + ans += a; + } + } + } + if (n % 2 != 0 && s[n / 2] == 2) { ans += (a < b ? a : b); } + if (flas) { + cout << -1 << endl; + } else { + cout << ans << endl; + } + return 0; +} +int n, x, a[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1}; +int main() { + cin >> n >> x; + n %= 6; + cout << a[n][x] << endl; + return 0; +} +const long long N = (1e6 + 5); +const long long inf = (1e9 + 7); +long long q; +long long n; +char ch; +string a; +int main() { + cin >> q; + while (q--) { + cin >> n; + cin >> ch; + cin >> a; + if (n == 2) { + if (ch >= a[0]) + puts("NO"); + else { + puts("YES"); + cout << 2 << endl; + cout << ch << " " << a << endl; + } + } else { + puts("YES"); + cout << 2 << endl; + cout << ch << " " << a << endl; + } + } +} +int main() { + string s; + cin >> s; + int n = s.length(); + int ans = 0; + for (int i = 0; i < n; i++) { + int l = 0, r = 0; + for (int j = i; j < n; j++) { + if (s[j] == '(') + l++; + else if (s[j] == ')') + l--; + else if (s[j] == '?') + l--, r++; + if (!l) + ans++; + else if (l < 0 && r > 0) + l += 2, r--; + else if (l < 0 && !r) + break; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long int pow = 1; + for (int i = 0; i < n; i++) { + if (pow > m) { + cout << m << "\n"; + return 0; + } + pow *= 2; + } + cout << m % pow << "\n"; + return 0; +} +int cnt[30]; +int main() { + int n, k; + string s; + cin >> k >> s; + n = s.length(); + for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } + bool can = true; + string ss = ""; + for (char x = 'a'; x <= 'z'; x++) { + if (cnt[x - 'a'] % k != 0) { + can = false; + } else { + for (int j = 0; j < cnt[x - 'a'] / k; j++) { ss += x; } + } + } + if (can) { + for (int i = 0; i < k; i++) { cout << ss; } + cout << endl; + } else { + cout << -1 << endl; + } +} +int a[1000]; +int t[1000]; +int main() { + int n, count = 0, i, j; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + if (a[0] == 0) t[0] = 1; + if (a[0] == 1) t[0] = 3; + if (a[0] == 2) t[0] = 2; + if (a[0] == 3) { + j = 1; + while (j < n) { + if (a[j] == 0) { + t[0] = 2; + break; + } + if (a[j] == 1) { + if (j % 2 == 0) + t[0] = 3; + else + t[0] = 2; + break; + } else if (a[j] == 2) { + if (j % 2 == 0) + t[0] = 2; + else + t[0] = 3; + break; + } + j++; + } + if (j == n) t[0] = 2; + } + for (i = 1; i < n; i++) { + if (a[i] == 0) + t[i] = 1; + else if (a[i] == 1) { + if (t[i - 1] == 1) + t[i] = 3; + else if (t[i - 1] == 2) + t[i] = 3; + else + t[i] = 1; + } else if (a[i] == 2) { + if (t[i - 1] == 1) + t[i] = 2; + else if (t[i - 1] == 3) + t[i] = 2; + else + t[i] = 1; + } else if (a[i] == 3) { + if (t[i - 1] == 1) { + j = i + 1; + while (j < n) { + if (a[j] == 0) { + t[i] = 2; + break; + } + if (a[j] == 1) { + if ((j - i) % 2 == 0) + t[i] = 3; + else + t[i] = 2; + break; + } else if (a[j] == 2) { + if ((j - i) % 2 == 0) + t[i] = 2; + else + t[i] = 3; + break; + } + j++; + } + if (j == n) t[i] = 2; + } else if (t[i - 1] == 2) + t[i] = 3; + else + t[i] = 2; + } + } + for (i = 0; i < n; i++) { + if (t[i] == 1) count++; + } + cout << count << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int gcd(int a, int b) { + if (a < b) swap(a, b); + if (!b) return a; + return gcd(b, a % b); +} +int main() { + int i, j, k; + int n, m, a, b, c, d; + cin >> a >> b >> c >> d; + k = gcd(a, b); + k = a / k * b; + m = d / k - c / k; + if (c % k == 0) m++; + cout << m << endl; + return 0; +} +int main() { + int n; + string s; + cin >> n >> s; + int x = count(s.begin(), s.end(), '4'); + x += count(s.begin(), s.end(), '7'); + int y = 0; + for (int i = 0; i < n; i++) { + if (i < n / 2) + y += s[i]; + else + y -= s[i]; + } + cout << (x == n && y == 0 ? "YES\n" : "NO\n"); +} +int a[27]; +int main() { + string x; + int c1 = 0, c2 = 0; + cin >> x; + for (int i = 0; i < x.size(); i++) { + if (x[i] >= 97) + c1++; + else + c2++; + } + if (c1 >= c2) + for (int i = 0; i < x.size(); i++) { + x[i] = tolower(x[i]); + cout << x[i]; + } + else + for (int i = 0; i < x.size(); i++) { + x[i] = toupper(x[i]); + cout << x[i]; + } + cout << endl; +} +int main() { + int n, k, t, l, m, g; + cin >> n >> k; + if (n * 2 % k == 0) { + t = n * 2 / k; + } else { + t = n * 2 / k + 1; + } + if (n * 5 % k == 0) { + l = n * 5 / k; + } else { + l = n * 5 / k + 1; + } + if (n * 8 % k == 0) { + m = n * 8 / k; + } else { + m = n * 8 / k + 1; + } + g = m + l + t; + cout << g << endl; + return 0; +} +int main() { + int a, b; + while (cin >> a >> b) { + int t; + t = a; + if (b < a) { t = b; } + int i; + int k = 1; + for (i = 1; i <= t; i++) { k *= i; } + cout << k << endl; + } +} +int main() { + int n; + char ch; + cin >> n; + n--; + string s; + ch = getchar(); + ch = getchar(); + s = ch; + while (ch = getchar()) { + if (ch == '\n') + break; + else if (s.find(ch) == string::npos && n) { + n--; + s += " "; + s += ch; + } else + s += ch; + } + istringstream iss(s); + string word; + if (n) + cout << "NO" << endl; + else { + cout << "YES" << endl; + while (iss >> word) cout << word << endl; + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= (n / 2 - i + 1); j++) cout << "*"; + for (int j = 1; j <= i * 2 - 1; j++) cout << 'D'; + for (int j = 1; j <= (n / 2 - i + 1); j++) cout << "*"; + cout << endl; + } + for (int i = 1; i <= n; i++) cout << "D"; + cout << endl; + for (int i = n / 2; i >= 1; i--) { + for (int j = 1; j <= (n / 2 - i + 1); j++) cout << "*"; + for (int j = 1; j <= i * 2 - 1; j++) cout << 'D'; + for (int j = 1; j <= (n / 2 - i + 1); j++) cout << "*"; + cout << endl; + } +} +int main() { + string str; + cin >> str; + int ans = 1; + int arr[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + for (int i = 0; i < 2; i++) ans *= arr[str[i] - '0']; + cout << ans << endl; + return 0; +} +int N, K, ans = 2e9, A[26], val, x, y; +string T, S; +int main() { + cin >> S >> N; + if (S.length() < N) { + cout << "impossible\n"; + return 0; + } + for (int i = 0; i < S.length(); i++) { + A[S[i] - 'a']++; + if (A[S[i] - 'a'] == 1) val++; + } + cout << max(0, N - val) << '\n'; +} +int main() { + int n; + cin >> n; + cout << n + n / 2 << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + int ans; + int x[2]; + x[0] = min(l, r); + x[1] = max(l, r); + if (x[0] != x[1]) { + while (a > 0) { + x[0]++; + a--; + if (x[0] == x[1]) { break; } + } + } + cout << (x[0] + (a / 2)) * 2 << '\n'; + return 0; +} +const int INF = 1e1; +int main() { + int i, j, k, P, Q, flag; + char s[10][10]; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { cin >> s[i][j]; } + } + P = INF; + Q = INF; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if (s[i][j] == 'W') { + flag = 0; + for (k = i; k >= 0; k--) { + if (s[k][j] == 'B') { + flag = 1; + break; + } + } + if (flag == 0) { Q = min(Q, i + 1); } + } else if (s[i][j] == 'B') { + flag = 0; + for (k = i; k < 8; k++) { + if (s[k][j] == 'W') { + flag = 1; + break; + } + } + if (flag == 0) { P = min(P, 8 - i); } + } + } + } + if (P >= Q) { + cout << "A" << endl; + } else + cout << "B" << endl; + return 0; +} +int main() { + vector v; + int n, g; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (i == 0) + g = x; + else + g = __gcd(g, x); + v.push_back(x); + } + int m = *max_element(v.begin(), v.end()); + cout << (((m / g - v.size()) % 2) ? "Alice\n" : "Bob\n"); +} +bool flag; +int a[71720], n, i, sumend, dp[811][811], m, j, k, x, y, b, c; +long long int sum; +bool cmp(int a, int b) { + return a > b; +} +int gcd(int a, int b) { + if (!b) return a; + return gcd(b, a % b); +} +int maxx(short int a, short int b) { + if (a > b) return a; + return b; +} +int gqt(int n) { + if (!n || n) return 1; + if (n == 2) return 0; + for (i = 3; i <= sqrt(n); i++) + if (n % i == 0) return 1; + return 0; +} +int main() { + cin >> x >> y; + while (y != 0) { + sum = y % 10; + sumend *= 10; + sumend += sum; + y /= 10; + } + sumend += x; + cout << sumend << endl; + return 0; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector sf(n); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> sf[i]; + sum = sum + sf[i]; + } + if (sum < 0) { sum *= -1; } + int h = sum / k; + if (sum % k != 0) { h++; } + cout << h << endl; + return 0; +} +int main() { + int t; + cin >> t; + int arr[t][2]; + for (int i = 0; i < t; i++) cin >> arr[i][0] >> arr[i][1]; + int count = 0, temp = 1; + for (int i = 1; i < t; i++) { + if (temp > count) count = temp; + if (arr[i - 1][0] == arr[i][0] && arr[i - 1][1] == arr[i][1]) + temp++; + else + temp = 1; + } + if (temp > count) count = temp; + cout << count << endl; +} +int main() { + int n, d; + int zero; + string s; + cin >> n >> d; + int ans = 0; + int cnt = 0; + for (int i = 1; i <= d; i++) { + zero = 0; + cin >> s; + for (int j = 0; j < s.size(); j++) { + if (s[j] == '0') { + zero = 1; + break; + } + } + if (zero == 1) { + cnt++; + } else + cnt = 0; + ans = max(cnt, ans); + } + cout << ans << endl; +} +int main() { + int a, b, c, n, x, ans = 0; + cin >> a >> b >> c >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (x > b && x < c) ans++; + } + cout << ans << endl; + return 0; +} +long long f(long long n, long long m) { + if (n == 0) { + return 1 % m; + } else if (n == 1) { + return 3 % m; + } + long long tmp = f(n / 2, m); + if (n % 2 == 0) { + return tmp * tmp % m; + } else { + return (tmp * tmp % m) * 3 % m; + } +} +int main() { + int n, m; + cin >> n >> m; + long long fx = f(n, m); + if (fx == 0) { + cout << m - 1 << endl; + } else { + cout << fx - 1 << endl; + } + return 0; +} +const int maxn = 105; +int n, d[maxn], s, t; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> d[i]; + cin >> s >> t; + int clock = 0, revert = 0, i; + int front = min(s, t), tail = max(s, t); + for (i = front; i < tail; i++) { clock += d[i]; } + for (i = tail; i != front; i++) { + if (i > n) i %= n; + if (i == front) break; + revert += d[i]; + } + cout << min(clock, revert) << endl; +} +int main() { + int n1[20]; + for (int i = 1; i <= 19; i++) n1[i] = 1; + int n; + cin >> n; + int nul, i; + int p = n; + while (--p) { + for (i = 2; i <= n; i++) { + nul = i - 1; + n1[i] = n1[i] + n1[nul]; + } + } + cout << n1[n] << endl; + return 0; +} +int main() { + long long int n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + while (k--) { + long long int t_a, f_a, t_b, f_b; + cin >> t_a >> f_a >> t_b >> f_b; + if (t_a == t_b) + cout << abs(f_b - f_a) << '\n'; + else { + long long int x; + if (a <= f_a && f_a <= b) { + x = 0; + cout << abs(t_b - t_a) + abs(f_b - f_a) << '\n'; + } else { + x = min(abs(f_a - a), abs(f_a - b)); + if (abs(f_a - a) < abs(f_a - b)) { + f_a = a; + cout << abs(t_b - t_a) + x + (abs(f_b - f_a)) << '\n'; + } else { + f_a = b; + cout << abs(t_b - t_a) + x + (abs(f_b - f_a)) << '\n'; + } + } + } + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + cout << a << " " << b << endl; + int n; + cin >> n; + for (int i = 0; i < n; ++i) { + string l, k; + cin >> l >> k; + if (l == a) { + a = k; + cout << a << " " << b << endl; + continue; + } + if (l == b) { + b = k; + cout << a << " " << b << endl; + continue; + } + } + return 0; +} +int main() { + set t; + string s, ss; + cin >> s; + ss = s + s; + for (int i = 0; i < s.length(); i++) { + string tmp; + for (int j = i; j < i + s.length(); j++) tmp += ss[j]; + t.insert(tmp); + } + cout << t.size() << endl; +} +int main() { + int i, t, j; + cin >> t; + int num[101]; + char name[101][11]; + char pos[101][6]; + for (i = 0; i < t; i++) { + cin >> name[i]; + cin >> pos[i]; + if (strcmp(pos[i], "rat") == 0) num[i] = 1; + if (strcmp(pos[i], "woman") == 0) num[i] = 2; + if (strcmp(pos[i], "child") == 0) num[i] = 3; + if (strcmp(pos[i], "man") == 0) num[i] = 4; + if (strcmp(pos[i], "captain") == 0) num[i] = 5; + } + for (i = 0; i < t; i++) { + if (num[i] == 1) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 2 || num[i] == 3) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 4) cout << name[i] << endl; + } + for (i = 0; i < t; i++) { + if (num[i] == 5) cout << name[i] << endl; + } + return 0; +} +int dp[100001]; +char s[100001]; +int book[26]; +int boox[26]; +int main() { + int n, k; + while (cin >> n >> k) { + int ans = 0; + memset(book, 1, sizeof(book)); + cin >> s; + for (int i = 0; i < n; i++) { + if (book[s[i] - 65]) { + book[s[i] - 65] = 0; + ans++; + } + boox[s[i] - 65]++; + } + if (ans != k) + cout << 0 << endl; + else { + int minx = 10000000; + for (int i = 0; i < 26; i++) { + if (boox[i] == 0) + continue; + else { + if (boox[i] < minx) minx = boox[i]; + } + } + cout << minx * k << endl; + } + } +} +int main() { + long long int x, a, b; + cin >> a >> b; + x = a / b; + if (x % 2 == 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + return 0; +} +int main() { + int a, b, c, n, output; + cin >> a >> b >> c >> n; + output = n - (a + b - c); + if ((a + b - c) >= n || c > a || c > b) + cout << -1 << endl; + else + cout << output << endl; + return 0; +} +int length = 1e5; +int main() { + int n, i, sum = 0; + cin >> n; + vector a(n + 1); + a[0] = 0; + for (i = 1; i <= n; i++) { a[i] = a[i - 1] + i; } + for (i = 1; (sum <= n) && (i <= n); i++) { sum += a[i]; } + if (n == 1) i++; + cout << i - 2 << endl; + return 0; +} +int n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + int ans = 0; + while (min(a, b) != 0) { + if (b < a) { swap(a, b); } + ans += b / a; + b = b % a; + } + if (a != 0 && b != 0) { ans += max(a, b) / min(a, b); } + cout << ans << endl; + } +} +int main() { + long long n, k; + cin >> n >> k; + long long c[10000], d = 0, del = 2; + while (n > 1) { + if (n % del == 0) { + d++; + c[d] = del; + n = n / del; + } else { + del++; + } + } + if (k > d) { + cout << -1 << endl; + } else { + for (long long i = 1; i < k; i++) { cout << c[i] << " "; } + long long pp = 1; + for (long long j = k; j <= d; j++) { pp = c[j] * pp; } + cout << pp << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 == 1) { + for (int j = 1; j <= m; j++) { cout << "#"; } + cout << endl; + } else { + if (i % 4 == 0) { + cout << "#"; + for (int j = 1; j < m; j++) { cout << "."; } + cout << endl; + } else { + for (int j = 1; j < m; j++) { cout << "."; } + cout << "#" << endl; + } + } + } +} +const int maxn = 5100; +int n; +int f[maxn]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> f[i]; + for (int i = 1; i <= n; i++) { + if (i == f[f[f[i]]]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, i, b[6]; + string a[6]; + cin >> n; + b[0] = 0; + b[1] = 0; + b[2] = 0; + b[3] = 0; + b[4] = 0; + b[5] = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == "purple") b[0]++; + if (a[i] == "green") b[1]++; + if (a[i] == "blue") b[2]++; + if (a[i] == "orange") b[3]++; + if (a[i] == "red") b[4]++; + if (a[i] == "yellow") b[5]++; + } + cout << 6 - n << endl; + if (b[0] == 0) cout << "Power" << endl; + if (b[1] == 0) cout << "Time" << endl; + if (b[2] == 0) cout << "Space" << endl; + if (b[3] == 0) cout << "Soul" << endl; + if (b[4] == 0) cout << "Reality" << endl; + if (b[5] == 0) cout << "Mind" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int flag1 = 0, flaga = 0, flagA = 0; + if (len >= 5) { + for (int i = 0; i < len; i++) { + if (s[i] >= '0' && s[i] <= '9') { flag1 = 1; } + if (s[i] >= 'a' && s[i] <= 'z') { flaga = 2; } + if (s[i] >= 'A' && s[i] <= 'Z') { flagA = 1; } + } + } + if (flag1 == 1 && flaga == 2 && flagA == 1) { + cout << "Correct" << endl; + } else + cout << "Too weak" << endl; + return 0; +} +int main() { + long long int i, s = 0, j = 0, k = 0, l, n, m; + cin >> m >> n; + for (i = 0; i <= m; i++) { + for (j = 0; j <= n; j++) { + k = i * i + j; + l = i + j * j; + if (k == n && l == m) s++; + } + } + cout << s << endl; + return 0; +} +int main() { + string st; + cin >> st; + int count = 0; + int ll = st.length(); + for (int i = 0; i < ll; i++) { + for (int j = i; j < ll; j++) { + for (int k = j; k < ll; k++) { + if (st[i] == 'Q' && st[j] == 'A' && st[k] == 'Q') count++; + } + } + } + cout << count << endl; + return 0; +} +int main() { + map m; + string s, temp; + cin >> s; + for (long long i = 0; i < 10; i++) { + cin >> temp; + m[temp] = i; + } + char c; + for (long long i = 0; i < 80; i++) { + if (i % 10 == 0) { + if (i != 0) { cout << m[temp]; } + temp = ""; + } + temp += s[i]; + } + cout << m[temp] << endl; + return 0; +} +long long int t, n; +string str; +bool isCheck(char a, char b) { + if ((char)(a + 1) == (char)(b - 1) || (char)(b + 1) == (char)(a - 1)) return true; + return false; +} +int main() { + cin >> t; + while (t--) { + cin >> n; + cin >> str; + long long int i = 0, j = n - 1; + n = n / 2; + bool flag = true; + while (i <= j) { + if (str[i] != str[j] && !isCheck(str[i], str[j])) { + flag = false; + break; + } + i++, j--; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int k, r, res; + cin >> k >> r; + if (k % 10) { + for (int i = 1; i < 10; i++) { + if (((k * i) % 10 == r) || !((k * i) % 10)) { + res = i; + break; + } + } + } else { + res = 1; + } + cout << res << endl; + return 0; +} +int main() { + int n, arr[101], m = 0, c = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + sort(arr, arr + n); + for (int i = 1; i < n; i++) { + if (arr[i - 1] == arr[i]) + c++; + else + c = 0; + m = max(m, c); + } + if (m == 0) + cout << 1 << endl; + else + cout << m + 1 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int ans = abs(a) + abs(b); + if (a > 0 && b > 0) + cout << "0 " << ans << " " << ans << " 0" << endl; + else if (a > 0 && b < 0) + cout << "0 " << -ans << " " << ans << " 0" << endl; + else if (a < 0 && b > 0) + cout << -ans << " 0 0 " << ans << endl; + else + cout << -ans << " 0 0 " << -ans << endl; + return 0; +} +long long cx, cy, cz, x, y, z, k; +long long g(long long a, long long b) { + if (a == b) return 1e18; + return a; +} +int main() { + cin >> x >> y >> z >> k; + cx = cy = cz = 1; + while (true) { + if (k == 0) break; + if (cx == x && cy == y && cz == z) break; + --k; + if (g(cx, x) <= g(cy, y) && g(cx, x) <= g(cz, z)) + ++cx; + else if (g(cy, y) <= g(cx, x) && g(cy, y) <= g(cz, z)) + ++cy; + else + ++cz; + } + cout << (cx) * (cy) * (cz) << endl; + cin.get(); + cin.get(); + return 0; +} +const int N = 1e6; +int n, t, k, d; +int main() { + cin >> n >> t >> k >> d; + int cnt = (n + k - 1) / k; + int cnt2 = d / t; + if (cnt - cnt2 <= 1) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + int n, k, t, ans; + cin >> n >> k; + t = 240 - k; + ans = (-5 + sqrt(5 * 5 - 4 * 5 * (-2 * t))) / 10; + if (ans > n) ans = n; + cout << ans << endl; + return 0; +} +int main() { + int ret = -1; + string ss = "0123456789"; + int n, k, count1 = 0, count2 = 0; + string s; + cin >> n >> k; + while (n--) { + cin >> s; + for (int i = 0; i <= k; i++) { + ret = s.find(ss[i]); + if (ret != -1) { + count1++; + ret = -1; + } + } + if (count1 >= k + 1) count2++; + count1 = 0; + } + cout << count2 << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + long long sum = 0; + int i; + for (i = 1;; i++) { + long long current = 1LL * i * (i + 1) / 2; + if (sum + current <= n) + n -= sum + current; + else + break; + } + cout << i - 1 << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + if (n % 2 == 0) { + cout << "2" << endl; + } else { + cout << "1" << endl; + } + return 0; +} +int main() { + int arr[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + int n; + cin >> n; + cout << arr[n / 10] * arr[n % 10] << endl; + return 0; +} +int main() { + vector v; + int n, a; + cin >> n; + while (n--) { + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + cout << v[v.size() - 1] << " "; + for (int i = 1; i + 1 < v.size(); i++) { cout << v[i] << " "; } + cout << v[0] << endl; + return 0; +} +int main() { + int n; + cin >> n; + set s, d; + while (n--) { + int x; + cin >> x; + if (x == 0) continue; + if (s.count(x)) { + s.erase(x); + d.insert(x); + } else if (d.count(x)) { + cout << "-1\n"; + return 0; + } else { + s.insert(x); + } + } + cout << d.size() << '\n'; +} +const int maxn = 1e3 + 5; +int w, h, k; +int main() { + cin >> w >> h >> k; + int total = 0; + int sum = 0; + sum = (w + h - 2) * 2; + for (int i = 1; i <= k; i++) { + int a = sum - 16 * (i - 1); + total = total + a; + } + cout << total << endl; +} +int main() { + string pass; + string comb[10]; + cin >> pass; + for (int i = 0; i < 10; i++) { cin >> comb[i]; } + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 10; j++) { + if (pass.substr(i * 10, 10) == comb[j]) cout << j; + } + } + cout << endl; + return 0; +} +char board[101][101]; +int main() { + int n, m; + while (cin >> n >> m) { + for (int i = 0; i < n; i++) { + getchar(); + for (int j = 0; j < m; j++) { + if (getchar() == '-') + board[i][j] = '-'; + else { + if (i % 2 == 0) { + if (j % 2 == 0) + board[i][j] = 'B'; + else + board[i][j] = 'W'; + } else { + if (j % 2 == 1) + board[i][j] = 'B'; + else + board[i][j] = 'W'; + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) cout << board[i][j]; + cout << endl; + } + } + return 0; +} +long long int a[200][3]; +long long int b[200]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a[i][1]; + cin >> a[i][2]; + b[i] = 60 * a[i][1] + a[i][2]; + } + for (int i = 0; i <= 5000; i++) { + int flag = 1; + for (int j = 0; j < n; j++) { + if (abs(b[j] - i) <= m) { flag = 0; } + } + if (flag) { + cout << i / 60 << " " << i % 60 << endl; + break; + } + } + return 0; +} +int main() { + int n, x; + cin >> n >> x; + const int MAX = 100000; + int a[MAX] = {}; + for (int i = 1; i <= n; ++i) { cin >> a[i]; } + float p = 0; + for (int j = 1; j <= n; ++j) { p = p + a[j]; } + p = abs(p); + cout << ceil(p / x) << endl; + return 0; +} +int main() { + int TESTS = 1; + while (TESTS--) { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + long long l, r; + cin >> l >> r; + if (l == r) { + cout << l << '\n'; + continue; + } + long long a[60], b[60]; + long long x = r, ans = 0; + for (long long i = 0; i < 60; i++) { + b[i] = l % 2; + l /= 2; + } + for (long long i = 0; i < 60; i++) { + a[i] = r % 2; + r /= 2; + ans += a[i]; + } + reverse(a, a + 60); + reverse(b, b + 60); + for (long long i = 0; i < 60; i++) { + if (a[i]) { + long long c[60]; + for (long long j = 0; j < i; j++) c[j] = a[j]; + c[i] = 0; + long long s = 1; + for (long long j = i + 1; j < 60; j++) c[j] = 1; + for (long long j = 0; j < 60; j++) { + if (s && (c[j] < b[j])) { + s = 2; + break; + } + if (c[j] > b[j]) { + s = 0; + break; + } + } + if (s != 2) { + long long cnt = 0; + for (long long j = 0; j < 60; j++) cnt += c[j]; + if (cnt > ans) { + long long t = 1; + x = 0; + ans = cnt; + for (long long j = 60 - 1; j >= 0; j--) { + x += c[j] * t; + t *= 2; + } + } else if (cnt == ans) { + long long t = 1; + long long z = 0; + ans = cnt; + for (long long j = 60 - 1; j >= 0; j--) { + z += c[j] * t; + t *= 2; + } + if (z < x) { x = z; } + } + } + } + } + cout << x << '\n'; + } + } + return 0; +} +int main() { + int n, a, b, k; + cin >> n; + while (n--) { + cin >> a >> b; + int res = 0; + while (a > 0 && b > 0) { + int mx = max(a, b), mn = min(a, b); + k = mx - mn; + if (a == b) { + res++; + break; + } + if (k % mn == 0) { + res += k / mn; + a = mx - k; + b = mn; + } else { + res += k / mn + 1; + a = mx - (k / mn + 1) * mn; + b = mn; + } + } + cout << res << endl; + } + return 0; +} +const int maxs = 110; +int table[maxs][maxs]; +int main() { + int n; + cin >> n; + int x1, y1, x2, y2; + int maxx = 0, maxy = 0; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + maxx = max(maxx, max(x1, x2)); + maxy = max(maxy, max(y1, y2)); + table[x1][y2] += 1; + table[x1][y1 - 1] -= 1; + table[x2 + 1][y2] -= 1; + table[x2 + 1][y1 - 1] += 1; + } + for (int y = maxy; y > 0; y--) { + for (int x = 2; x <= maxx; x++) { table[x][y] += table[x - 1][y]; } + } + for (int x = 1; x <= maxx; x++) { + for (int y = maxy; y >= 2; y--) { table[x][y - 1] += table[x][y]; } + } + int ans = 0; + for (int x = 1; x <= maxx; x++) { + for (int y = 1; y <= maxy; y++) { ans += table[x][y]; } + } + cout << ans << endl; + return 0; +} +int main() { + int x; + cin >> x; + int a[x + 1]; + for (int i = 1; i <= x; i++) { cin >> a[i]; } + for (int i = 1; i <= x; i++) + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + cout << "NO" << endl; +} +map ok; +string inter(string ss) { + string res; + for (int i = 0; i < ss.length(); i++) { + if ((ss[i] - '0') % 2) + res += '1'; + else + res += '0'; + } + if (res.find_first_not_of('0') == string::npos) return "0"; + int pos = res.find_first_not_of('0'); + res = res.substr(pos, ss.length() - pos); + return res; +} +int main() { + char op; + string s; + int t; + cin >> t; + while (t--) { + cin >> op; + cin >> s; + s = inter(s); + if (op == '+') { + ok[s]++; + } else if (op == '-') { + ok[s]--; + } else { + cout << ok[s] << endl; + } + } + return 0; +} +int main() { + int n, t; + cin >> n; + for (; cin >> t;) + if (t == 1) { + cout << -1 << endl; + return 0; + } + cout << 1 << endl; + return 0; +} +string s; +int flag; +void solve(int i, int v) { + for (int j = i; j < s.length(); j++) { + if (v == 0 && s[j] == 'Q') { solve(j + 1, 1); } + if (v == 1 && s[j] == 'A') { solve(j + 1, 2); } + if (v == 2 && s[j] == 'Q') { + flag++; + continue; + } + } +} +int main() { + cin >> s; + solve(0, 0); + cout << flag << endl; +} +const long long MAXN = 1e5 + 69; +const long long INF = 1e9 + 85; +long long n, res; +string str[MAXN]; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) cin >> str[i]; + for (char i = 'a'; i <= 'z'; i++) + for (char j = i + 1; j <= 'z'; j++) { + long long ans = 0; + for (long long it = 0; it < n; it++) { + long long active = 0; + for (long long jt = 0; jt < str[it].size(); jt++) + if (str[it][jt] != i and str[it][jt] != j) active = 1; + if (active == 0) ans += str[it].size(); + } + res = max(ans, res); + } + cout << res << "\n"; +} +int main() { + int n; + cin >> n; + int a[n], p[n]; + for (int i = 1; i <= n; i++) { cin >> a[i] >> p[i]; } + int m = INT_MAX, ans = 0; + for (int i = 1; i <= n; i++) { + m = min(m, p[i]); + ans += (a[i] * m); + } + cout << ans << endl; + return 0; +} +int main() { + int k, r; + cin >> k >> r; + for (int i = 1;; i++) { + int n = (i * k) % 10; + if (n == r || n == 0) { + cout << i << endl; + break; + } + } + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int a[n + 1] = {0}; + int b[n + 1] = {0}; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + if (a[1] == 0) { + cout << "NO\n"; + return 0; + } + if (a[s] == 1) { + cout << "YES\n"; + return 0; + } + for (int i = s + 1; i <= n; i++) { + if (a[i] == 1 && b[i] == 1 && b[s] == 1) { + cout << "YES\n"; + return 0; + } + } + cout << "NO\n"; + return 0; +} +int n, s = 3, a; +bool cek = 0; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == s) + cek = 1; + else if (!cek) { + for (int j = 1; j <= 3; j++) { + if (j != a && j != s) { + s = j; + break; + } + } + } + } + if (cek) + cout << "NO\n"; + else + cout << "YES\n"; +} +int main() { + int n; + cin >> n; + int k, a, l = 0, m = 0; + k = n; + a = n; + if (n % 2 == 0 && n % 5 == 0) { + cout << n << endl; + } else { + for (int i = 0; i < 8; i++) { + l++; + if (k % 2 == 0 && k % 5 == 0) { break; } + k--; + } + for (int j = 0; j < 8; j++) { + m++; + if (a % 2 == 0 && a % 5 == 0) { break; } + a++; + } + if (l == m) { + cout << k << endl; + } else if (l > m) { + cout << a << endl; + } else { + cout << k << endl; + } + } + return 0; +} +int n; +void work() { + int n; + char k[400]; + cin >> n; + for (int i = 1; i <= n; ++i) { cin >> k[i]; } + if (n > 2) { + cout << "YES\n2\n"; + cout << k[1] << ' '; + for (int j = 2; j <= n; ++j) { cout << k[j]; } + cout << '\n'; + } else { + if (k[1] >= k[2]) { + cout << "NO\n"; + } else { + cout << "YES\n2\n"; + cout << k[1] << ' ' << k[2] << '\n'; + } + } +} +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) { work(); } +} +string shift(string word) { + string result; + result.push_back(*(word.end() - 1)); + for (size_t i = 0; i < word.size() - 1; i++) result.push_back(word[i]); + return result; +} +int main() { + string word; + cin >> word; + vector v; + for (size_t i = 0; i < word.length(); i++) { + if (find(v.begin(), v.end(), word) == v.end()) v.push_back(word); + word = shift(word); + } + cout << v.size() << '\n'; + return 0; +} +long long ar[1000008]; +vector vi; +bool isv(char ch) { + if (ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u' or ch == 'y') return 1; + return 0; +} +int main() { + string s; + long long n; + cin >> n; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (!isv(s[i])) { + vi.push_back(s[i]); + } else { + if (vi.empty()) + vi.push_back(s[i]); + else if (!isv(vi[vi.size() - 1])) + vi.push_back(s[i]); + } + } + for (int i = 0; i < vi.size(); i++) cout << vi[i]; + cout << endl; + return 0; +} +int q, n, i; +string s; +int main() { + cin >> q; + while (q--) { + cin >> n >> s; + if (n == 2 && s[0] >= s[1]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl << 2 << endl << s[0] << " "; + for (i = 1; i < n; i++) cout << s[i]; + cout << endl; + } + } +} +int main() { + int n, x; + long long sum = 0, tot = 0; + cin >> n; + for (int i = 1; i < n; i++) { + cin >> x; + sum += x; + } + for (int j = n; j >= 1; j--) { tot += j; } + cout << tot - sum << endl; + ; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int ans, tmp, cnt; + cnt = pow(2, n); + tmp = m / cnt; + ans = m - tmp * cnt; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n > m) { swap(n, m); } + if (n % 2 == 0) { + cout << "Malvika" << endl; + } else { + cout << "Akshat" << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b; + cin >> a >> b; + long long final = 0; + while (a && b) { + if (a > b) swap(a, b); + final += b / a; + b = b - a * (b / a); + } + cout << final << endl; + } + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << '\n'; + else + cout << "1\n"; + return 0; +} +int arr[100005]; +int main() { + long long int n, k; + cin >> n >> k; + long long int first = n / 2; + long long int m = n % 2; + long long int res = first / (k + 1); + m += first % (k + 1); + cout << res << " " << res * k << " " << m + first << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = n / 2 + n / 2 + n / 2; + cout << ans << endl; + return 0; +} +int main() { + map mp; + string s1; + vector s2; + cin >> s1; + for (int i = 0; i < 10; i++) { + string s; + cin >> s; + mp.insert(pair(s, i)); + } + string temp; + vector ans; + for (int i = 0; i <= s1.length(); i++) { + if (i % 10 == 0 && i != 0) { + ans.push_back(mp.find(temp)->second); + if (i < s1.length()) temp += s1[i]; + temp.clear(); + } + temp += s1[i]; + } + for (int j = 0; j < ans.size(); j++) { cout << ans[j]; } + cout << endl; + return 0; +} +int a[200]; +int mapp[200][200]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + int x, y; + for (int i = 0; i < m; i++) { + cin >> x >> y; + mapp[x][y] = mapp[y][x] = 1; + } + int num = 0, minn = 9999999; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 1; k <= n; k++) { + if (mapp[j][i] && mapp[i][k] && mapp[j][k]) { + num = a[i] + a[j] + a[k]; + if (num < minn) minn = num; + } + } + } + } + if (minn == 9999999) + cout << -1 << endl; + else + cout << minn << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + string s; + cin >> s; + for (int i = 0; i < m; ++i) { + int L, R; + char fro, bac; + cin >> L >> R >> fro >> bac; + for (int j = L - 1; j <= R - 1; ++j) + if (s[j] == fro) s[j] = bac; + } + cout << s << '\n'; + } + return 0; +} +int main() { + int T; + cin >> T; + int n; + while (T--) { + cin >> n; + int t = 180 - n; + if (360 % t != 0) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } + } + return 0; +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c; + if (a > b) swap(a, b); + if (a >= c || b >= c) + cout << 0 << "\n"; + else if (a <= 0 && b <= 0) { + cout << -1 << "\n"; + } else if (a >= 0 && b >= 0) { + long long i; + for (i = 1;; i++) { + d = a + b; + a = max(a, b); + b = d; + if (b >= c || a >= c) break; + } + cout << i << "\n"; + } else { + long long temp_a = abs(a); + long long temp_b = abs(b); + long long co; + co = temp_a / temp_b; + if (co != 0) { a = a + b * co; } + for (int i = 1;; i++) { + d = a + b; + a = max(a, b); + b = d; + if (a >= c || b >= c) { + co = co + i; + break; + } + } + cout << co << "\n"; + } +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int flag = 0; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int cost = 0; + int i = 0; + int j = n - 1; + while (i < j) { + if (arr[i] == 2 && arr[j] == 2) { + cost = cost + min(a, b) * 2; + } else if (arr[i] == 0 && arr[j] == 1) { + flag = 1; + break; + } else if (arr[i] == 1 && arr[j] == 0) { + flag = 1; + break; + } else if (arr[i] == 2) { + if (arr[j] == 0) + cost = cost + a; + else + cost = cost + b; + } else if (arr[j] == 2) { + if (arr[i] == 0) + cost = cost + a; + else + cost = cost + b; + } + i++; + j--; + } + if (i == j && arr[i] == 2) cost = cost + min(a, b); + if (flag) + cout << -1 << endl; + else + cout << cost << endl; + return 0; +} +int selsort(long long arr[], int n) { + for (int i = 0; i < n - 1; i++) { + int min = i; + for (int j = i + 1; j < n; j++) { + if (arr[j] < arr[min]) { min = j; } + } + long long t = arr[i]; + arr[i] = arr[min]; + arr[min] = t; + } +} +int main() { + int n, a, b; + cin >> n >> a >> b; + long long arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + selsort(arr, n); + cout << arr[n - a] - arr[n - a - 1] << "\n"; +} +int main() { + long long int n, m; + cin >> n >> m; + if (n > 32) { + cout << m << endl; + } else { + long long int z = pow(2, n); + cout << m % z << endl; + } +} +int main() { + string s; + cin >> s; + int n; + n = s.length(); + while (n--) { + int m = s[n] - '0'; + char ar[8]; + for (int i = 0; i < 8; i++) { ar[i] = 'O'; } + ar[2] = '|'; + if (m < 5) { + ar[1] = '-'; + ar[3 + m] = '-'; + } + if (m >= 5) { + m = m - 5; + ar[0] = '-'; + ar[3 + m] = '-'; + } + for (int i = 0; i < 8; i++) { cout << ar[i]; } + cout << "\n"; + } +} +int main() { + int test = 1; + cin >> test; + while (test--) { + long long int i, j, k, n, m, a, b, p = 0, q = INT_MAX; + cin >> n >> m; + while (n != 0 && m != 0) { + if (n >= m) { + p = p + n / m; + n = n % m; + } else { + p = p + m / n; + m = m % n; + } + } + cout << p << "\n"; + } + return 0; +} +int main() { + int h, w, h1, h2, w1, w2; + cin >> w >> h; + cin >> w1 >> h1; + cin >> w2 >> h2; + int weight = w; + for (int i = h; i >= 0; i--) { + weight = weight + i; + if (i == h1) { weight = weight - w1; } + if (i == h2) { weight = weight - w2; } + if (weight <= 0) { weight = 0; } + } + cout << weight << endl; + ; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int c, b, i, k, l, j = 0; + cin >> c; + priority_queue pq; + cin >> b; + for (i = 1; i < c; i++) { + int x; + cin >> x; + pq.push(x); + } + while (b <= pq.top()) { + b++; + int x = pq.top(); + x--; + pq.pop(); + pq.push(x); + j++; + } + cout << j << endl; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; +} +int main() { + int n, ans1 = 1, ans2 = 1, ans3 = 1, ans4 = 1, ans5 = 1, ans6 = 1; + string str; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> str; + if (str == "purple") ans1--; + if (str == "green") ans2--; + if (str == "blue") ans3--; + if (str == "orange") ans4--; + if (str == "red") ans5--; + if (str == "yellow") ans6--; + } + cout << 6 - n << endl; + if (ans1 == 1) cout << "Power" << endl; + if (ans2 == 1) cout << "Time" << endl; + if (ans3 == 1) cout << "Space" << endl; + if (ans4 == 1) cout << "Soul" << endl; + if (ans5 == 1) cout << "Reality" << endl; + if (ans6 == 1) cout << "Mind" << endl; + return 0; +} +int main() { + int n, a; + int ans, cnt; + cin >> n >> a; + ans = 0; + cnt = n * 2; + ans += (cnt + a - 1) / a; + cnt = n * 5; + ans += (cnt + a - 1) / a; + cnt = n * 8; + ans += (cnt + a - 1) / a; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int mx = 0; + int a[m]; + for (int i = 0; i < m; i++) { cin >> a[i]; } + int ar[n] = {0}; + for (int i = 0; i < m; i++) { ar[a[i] - 1]++; } + int mn = m; + for (int i = 0; i < n; i++) { mn = min(ar[i], mn); } + cout << mn << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int mid = n / 2; + char s[mid + 1][n]; + for (int i = 0; i <= mid; i++) { + for (int j = 0; j < n; j++) { + if (j >= (mid - i) && j <= (mid + i)) { + s[i][j] = 'D'; + } else { + s[i][j] = '*'; + } + } + } + for (int i = 0; i <= mid; i++) { + for (int j = 0; j < n; j++) { cout << s[i][j]; } + cout << endl; + } + for (int i = mid - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { cout << s[i][j]; } + cout << endl; + } + return 0; +} +int main() { + long long n, a, MAX = -1, ans, d = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + MAX = max(MAX, a); + d = __gcd(d, a); + } + ans = MAX / d - n; + if (n > 1 && ans % 2) + cout << "Alice\n"; + else + cout << "Bob\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int a[n + 10]; + int ma[n + 1][n + 1]; + memset(ma, 0, sizeof(ma)); + vector v[n + 1]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int uu, vv; + for (int i = 1; i <= m; i++) { + cin >> uu >> vv; + ma[uu][vv] = 1; + ma[vv][uu] = 1; + } + int ans = INT_MAX; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int t = 1; t <= n; t++) { + if (i != j && i != t && j != t && ma[i][j] && ma[i][t] && ma[j][t]) { ans = min(ans, a[i] + a[j] + a[t]); } + } + } + } + if (ans != INT_MAX) + cout << ans << endl; + else + cout << -1 << endl; +} +int main() { + int n, k, i; + string str; + cin >> n >> k; + cin >> str; + for (i = 0; i < n; i++) { + if (str[i] == 'T' || str[i] == 'G') { + for (i = i + k; i <= n; i = i + k) { + if (str[i] == 'T' || str[i] == 'G') { + cout << "YES" << endl; + return 0; + } else if (str[i] == '.') { + continue; + } else { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, x, sum = 0; + cin >> n >> x; + for (int i = 0, k = 0; i < n; i++) { + cin >> k; + sum = sum + k; + } + sum = abs(sum); + cout << sum / x + (sum % x ? 1 : 0) << endl; +} +int main() { + set st; + string ss; + cin >> ss; + int len = ss.length(); + for (int i = 0; i < len; i++) { + char temp[1000]; + temp[0] = ss[len - 1]; + int x = 1; + for (int j = 0; j < len - 1; j++) { temp[x++] = ss[j]; } + stringstream k(temp); + string t; + k >> t; + st.insert(t); + ss = t; + } + cout << st.size() << endl; + return 0; +} +int main() { + int a, m; + cin >> a >> m; + set store; + int x = a; + while (1) { + int length = store.size(); + int temp = a % m; + store.insert(temp); + if (length == store.size()) { + cout << "No" << endl; + break; + } else if (a % m == 0) { + cout << "Yes" << endl; + break; + } + a += temp; + x = a; + } + return 0; +} +pair p[3007]; +long long int c[3007]; +int main() { + long long int n, m; + cin >> n >> m; + long long int mx = 0; + for (long long int i = 0; i < n; i++) { + cin >> p[i].second >> p[i].first; + c[p[i].second]++; + } + sort(p, p + n); + for (long long int i = 2; i <= m; i++) mx = max(mx, c[i]); + long long int ans = 21474836470000; + long long int sum = 0; + for (long long int i = mx; i >= 0; i--) { + for (long long int j = 0; j < n; j++) { + if (p[j].second != 1 && c[p[j].second] > i) { + c[p[j].second]--; + p[j].second = 1; + c[1]++; + sum += p[j].first; + } + } + long long int k = i - c[1] + 1; + long long int t = sum; + for (long long int j = 0; j < n; j++) { + if (k > 0) { + if (p[j].second != 1) { + t += p[j].first; + k--; + } + } + } + ans = min(ans, t); + } + cout << ans << '\n'; +} +int main() { + int a, b, c, i, n, mon, ans = 0; + cin >> a >> b >> c; + cin >> n; + for (i = 0; i < n; i++) { + cin >> mon; + if (mon > b && mon < c) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + string a, b, res = ""; + cin >> a >> b; + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[i]) { + res += '1'; + } else + res += '0'; + } + cout << res << endl; + return 0; +} +const int maxn = 5e3 + 10; +int vis[maxn][maxn]; +int main() { + string s; + cin >> s; + int len = s.size(); + int res = 0; + for (int i = 0; i < len; i++) { + int cur = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(' || s[j] == '?') + cur++; + else + cur--; + if (cur >= 0) + vis[i][j]++; + else + break; + } + } + for (int i = len - 1; i >= 0; i--) { + int cur = 0; + for (int j = i; j >= 0; j--) { + if (s[j] == ')' || s[j] == '?') { + cur++; + } else { + cur--; + } + if (cur >= 0) + vis[j][i]++; + else + break; + } + } + for (int i = 0; i < len; i++) { + for (int j = 0; j < len; j++) { + if ((i + j) % 2 && vis[i][j] == 2) { res++; } + } + } + cout << res << endl; + return 0; +} +int main() { + int a[9], i, b[9]; + for (i = 0; i < 9; i++) cin >> a[i]; + b[0] = a[1] + a[3] + a[0]; + b[1] = a[0] + a[2] + a[4] + a[1]; + b[2] = a[1] + a[5] + a[2]; + b[3] = a[0] + a[4] + a[6] + a[3]; + b[4] = a[1] + a[3] + a[5] + a[7] + a[4]; + b[5] = a[2] + a[4] + a[8] + a[5]; + b[6] = a[3] + a[7] + a[6]; + b[7] = a[6] + a[4] + a[8] + a[7]; + b[8] = a[5] + a[7] + a[8]; + for (i = 0; i < 9; i++) { + if (b[i] % 2 == 0) + b[i] = 1; + else + b[i] = 0; + } + cout << b[0] << b[1] << b[2] << endl; + cout << b[3] << b[4] << b[5] << endl; + cout << b[6] << b[7] << b[8] << endl; +} +int main() { + long long n, b, p; + cin >> n >> b >> p; + long long s1 = 0LL, s2 = p * n; + while (n > 1) { + long long k = 1; + while (k < n) k *= 2; + if (k > n) k /= 2; + s1 += (k / 2) * (2 * b + 1); + long long m = n - k; + long long l = k / 2; + n = l + m; + } + cout << s1 << " " << s2 << '\n'; + return 0; +} +int main() { + int n, a[101]; + cin >> n; + for (int i = 0; i < n; ++i) cin >> a[i]; + int maxx, e, minn = 1e9, end, start; + for (int i = 1; i < n - 1; ++i) { + maxx = -1e9; + for (int j = n - 1; j > 0; --j) { + end = a[j - 1]; + start = a[j]; + if (j - 1 == i) end = a[j - 2]; + if (j == i && i != 1) { + start = a[j - 1]; + end = a[j - 2]; + } + if (j == i && i == 1) break; + maxx = max(maxx, start - end); + } + minn = min(minn, maxx); + } + cout << minn << endl; +} +int main() { + string s; + cin >> s; + long long Ma = 0, mi = 0, i; + long long tam = s.size(); + for (i = 0; i < tam; i++) { + if (s[i] >= 97) + mi++; + else + Ma++; + } + if (Ma > mi) { + for (i = 0; i < tam; i++) { s[i] = toupper(s[i]); } + } else { + for (i = 0; i < tam; i++) { s[i] = tolower(s[i]); } + } + cout << s << endl; + return 0; +} +vector Arr; +long long GCD(long long Number1, long long Number2) { + if (Number2 == 0) return Number1; + return GCD(Number2, Number1 % Number2); +} +long long LCM(long long Number1, long long Number2) { + return (Number1 * Number2) / GCD(Number1, Number2); +} +void FirstMulti(long long Number1, long long Number2) { + long long LastCommon = LCM(Number1, Number2); + int counter = 1; + while (Number1 * counter <= LastCommon) { + Arr.push_back(Number1 * counter); + counter++; + } +} +void SecondMulti(long long Number1, long long Number2) { + long long LastCommom = LCM(Number1, Number2); + int counter = 1; + while (Number2 * counter < LastCommom) { + if (Number2 % Number1 != 0) { Arr.push_back(Number2 * counter); } + counter++; + } +} +int main() { + int Number1, Number2; + cin >> Number1 >> Number2; + Arr.push_back(0); + FirstMulti(Number1, Number2); + SecondMulti(Number1, Number2); + sort(Arr.begin(), Arr.end()); + int MashaCount = 0; + int DashaCount = 0; + for (int i = 1; i < Arr.size(); i++) { + if (Arr[i] % Number1 == 0 && Arr[i] % Number2 != 0) { + DashaCount++; + } else if (Arr[i] % Number2 == 0 && Arr[i] % Number1 != 0) { + MashaCount++; + } else { + if (MashaCount >= DashaCount) { + DashaCount++; + } else + MashaCount++; + } + } + if (MashaCount > DashaCount) + cout << "Masha" << endl; + else if (MashaCount < DashaCount) + cout << "Dasha" << endl; + else + cout << "Equal" << endl; +} +int main() { + int n, sumpar = 0, sumimpar = 0; + cin >> n; + int x[n]; + int y[n]; + for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } + for (int i = 0; i < n; i++) { + sumpar += x[i]; + sumimpar += y[i]; + } + if (sumpar % 2 == 0 && sumimpar % 2 == 0) + cout << 0 << endl; + else { + bool sw = false; + if (sumpar % 2 != 0 || sumimpar % 2 != 0) { + for (int i = 0; i < n; i++) { + if ((sumpar - x[i] + y[i]) % 2 == 0 && (sumimpar - y[i] + x[i]) % 2 == 0) { + sw = true; + break; + } + } + } + if (sw) + cout << 1 << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 2]; + a[0] = 0; + for (int i = 1; i <= n; ++i) cin >> a[i]; + sort(a, a + n + 1); + int k = n / 2; + if (n % 2) k++; + cout << a[k] << endl; +} +int main() { + int n, m; + int discounts[100005], items[100005]; + cin >> n; + int min_discount = 1e9; + for (int i = 0; i < n; i++) { + cin >> discounts[i]; + min_discount = min(min_discount, discounts[i]); + } + cin >> m; + for (int i = 0; i < m; i++) cin >> items[i]; + sort(items, items + m); + int countt = 0; + int sum = 0; + for (int i = m - 1; i >= 0; i--) { + if (countt % (min_discount + 2) < min_discount) sum += items[i]; + countt++; + } + cout << sum << endl; + return 0; +} +int a; +bool lucky(int num) { + num = abs(num); + while (num > 0) { + if (num % 10 == 8) { return 1; } + num /= 10; + } + return 0; +} +int main() { + cin >> a; + int b = 1; + while (!lucky(a + b)) { b++; } + cout << b << "\n"; + return 0; +} +map mp; +string s; +int n, m, b[2000], c[2000]; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> c[i]; + for (int i = 0; i < m; i++) cin >> b[i]; + int cur = 0, ans = 0; + for (int i = 0; i < n && cur < m; i++) { + if (c[i] <= b[cur]) { + cur++; + ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, sum; + cin >> n >> sum; + if (sum % n != 0) + cout << sum / n + 1 << endl; + else + cout << sum / n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ang; + for (int i = 0; i < n; i++) { + cin >> ang; + if (360 % (180 - ang) != 0 || ang < 60) + cout << "NO\n"; + else + cout << "YES\n"; + } + return 0; +} +const double PI = 3.1415926535897932384626433832795; +long long mod = 1e9 + 7; +bool isp(char c) { + return (c == '.' || c == ',' || c == '?' || c == '!'); +} +int main() { + cout.precision(12); + cout << fixed; + string s, ans = ""; + while (cin >> s) { + if (s.size() == 1 && isp(s[0]) && ans.size()) + ans[ans.size() - 1] = s[0], ans += " "; + else + ans = ans + s + " "; + } + int sz = ans.size(); + int last = 0, i = 0; + for (i = 0, last = 0; i < sz - 1; ++i) { + if (ans[i] == ' ' && isp(ans[i + 1])) + cout << ans.substr(last, i - last) + ans[i + 1] + " ", last = i + 2, i++; + else if (ans[i] == ' ') + cout << ans.substr(last, i - last + 1), last = i + 1; + else if (isp(ans[i])) + if (ans[i + 1] != ' ') + cout << ans.substr(last, i - last + 1) + " ", last = i + 1; + else + cout << ans.substr(last, i - last + 1), last = i + 1; + } + cout << ans.substr(last, i - last) << '\n'; + return 0; +} +int main() { + int i, n, j, mm; + while (cin >> n >> mm) { + string s[n + 5]; + map m; + for (i = 0; i < n; i++) { cin >> s[i]; } + m['f'] = 0, m['a'] = 0, m['c'] = 0, m['e'] = 0; + int c = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < s[i].size(); j++) { + m['f'] = 0, m['a'] = 0, m['c'] = 0, m['e'] = 0; + int p = i; + if (j + 1 < s[i].size() && p + 1 < n) { m[s[p][j]]++, m[s[p + 1][j]]++, m[s[p][j + 1]]++, m[s[p + 1][j + 1]]++; } + if (m['f'] == 1 && m['a'] == 1 && m['c'] == 1 && m['e'] == 1) { c++; } + } + } + cout << c << endl; + } + return 0; +} +int N, K, ans, A[10], val, x, y; +string T, S, P; +bool cek; +int main() { + cin >> N >> x >> y; + cout << max(0, (N * y - 1) / 100 + 1 - x) << '\n'; +} +int main() { + int n, k, x; + cin >> n >> k; + int a[n]; + vector v; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < k; i++) { + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + x = v.back(); + v.pop_back(); + a[i] = x; + } + } + int c = 1; + for (int i = 0; i < n - 1; i++) + if (a[i + 1] - a[i] > 0) c++; + if (c == n) + cout << "No" << endl; + else + cout << "Yes" << endl; + return 0; +} +int main() { + int n, p; + cin >> n; + cin >> p; + long double apples = 0; + long long answer = 0; + vector data; + for (int i = 0; i < n; i++) { + string temp; + cin >> temp; + data.push_back(temp); + } + for (int i = n - 1; i >= 0; i--) { + if (data[i] == "halfplus") { + apples += 0.5; + apples *= 2; + answer += (apples / 2.0) * p; + } else { + apples *= 2; + answer += (apples / 2.0) * p; + } + } + cout << answer << endl; + cin >> n; +} +int main() { + int n, d[100], s, t, sum = 0, res = 0, mini = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> d[i]; + sum += d[i]; + } + cin >> s >> t; + for (int i = min(s - 1, t - 1); i < max(t - 1, s - 1); i++) { res += d[i]; } + mini = min(res, sum - res); + cout << mini << endl; + return 0; +} +int a[35][35]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + int Counter = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + int rowCount = 0, colCount = 0; + for (int row = 0; row < n; row++) rowCount += a[row][j]; + for (int col = 0; col < n; col++) colCount += a[i][col]; + if (rowCount > colCount) Counter++; + } + cout << Counter << endl; + return 0; +} +int a[35][35]; +int n; +int judge(int i, int j) { + int sum1 = 0, sum2 = 0; + for (int x = 0; x < n; x++) { sum1 += a[x][j]; } + for (int x = 0; x < n; x++) { sum2 += a[i][x]; } + if (sum1 > sum2) { return 1; } + return 0; +} +int main() { + while (cin >> n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + int sum = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int x = judge(i, j); + if (x == 1) { sum++; } + } + } + cout << sum << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int x = 0, y = 0; + if (s[0] == '0') x = 2; + if (s[1] == '0') y = 2; + if (s[0] == '1') x = 7; + if (s[1] == '1') y = 7; + if (s[0] == '2') x = 2; + if (s[1] == '2') y = 2; + if (s[0] == '3') x = 3; + if (s[1] == '3') y = 3; + if (s[0] == '4') x = 3; + if (s[1] == '4') y = 3; + if (s[0] == '5') x = 4; + if (s[1] == '5') y = 4; + if (s[0] == '6') x = 2; + if (s[1] == '6') y = 2; + if (s[0] == '7') x = 5; + if (s[1] == '7') y = 5; + if (s[0] == '8') x = 1; + if (s[1] == '8') y = 1; + if (s[0] == '9') x = 2; + if (s[1] == '9') y = 2; + cout << x * y << endl; +} +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) { + if (a[n - 1] == 15) + cout << "DOWN" << endl; + else if (a[n - 1] == 0) + cout << "UP" << endl; + else + cout << -1 << endl; + } + if (n > 1) { + if (a[n - 1] > a[n - 2] && a[n - 1] != 15) + cout << "UP" << endl; + else if (a[n - 1] < a[n - 2] && a[n - 1] != 0) + cout << "DOWN" << endl; + else if (a[n - 1] == 15) + cout << "DOWN" << endl; + else + cout << "UP" << endl; + } +} +int n; +bool has[8]; +char sir[10]; +char colors[10][10] = {"purple", "green", "blue", "orange", "red", "yellow"}; +char stones[10][10] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; +int main() { + int i, j; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> sir; + if (strcmp(sir, colors[0]) == 0) { + has[0] = true; + continue; + } + if (strcmp(sir, colors[1]) == 0) { + has[1] = true; + continue; + } + if (strcmp(sir, colors[2]) == 0) { + has[2] = true; + continue; + } + if (strcmp(sir, colors[3]) == 0) { + has[3] = true; + continue; + } + if (strcmp(sir, colors[4]) == 0) { + has[4] = true; + continue; + } + if (strcmp(sir, colors[5]) == 0) { + has[5] = true; + continue; + } + } + cout << 6 - n << "\n"; + for (i = 0; i < 6; i++) { + if (!has[i]) { cout << stones[i] << "\n"; } + } + return 0; +} +int main() { + char s[101]; + while (cin >> s) { + int top = 'a'; + int cnt = 0; + int len = strlen(s); + for (int i = 0; i < len; i++) { + int temp = fabs(top - s[i]); + cnt += min(temp, 26 - temp); + top = s[i]; + } + cout << cnt << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int solu = 0; + for (int i = 0; i <= 1000; i++) { + for (int j = 0; j <= 1000; j++) { + if (pow(i, 2) + j == n && i + pow(j, 2) == m) solu++; + } + } + cout << solu << endl; + return 0; +} +int main() { + int a[3], i, j, t, sum; + for (i = 0; i < 3; i++) { cin >> a[i]; } + for (i = 0; i < 3; i++) { + for (j = i; j < 3; j++) { + if (a[i] > a[j]) { + t = a[i]; + a[i] = a[j]; + a[j] = t; + } + } + } + sum = (a[1] - a[0]) + (a[2] - a[1]); + cout << sum << endl; + return 0; +} +int main() { + string a, b; + int x, y, win1 = 0, win2 = 0; + cin >> a >> b; + for (int i = 0; i < a.length(); i += 2) { + if (a[i] == '[' && a[i + 1] == ']') x = 1; + if (a[i] == '(' && a[i + 1] == ')') x = 2; + if (a[i] == '8' && a[i + 1] == '<') x = 3; + if (b[i] == '[' && b[i + 1] == ']') y = 1; + if (b[i] == '(' && b[i + 1] == ')') y = 2; + if (b[i] == '8' && b[i + 1] == '<') y = 3; + if (x == y) + continue; + else if (x == 1 and y == 2 or x == 3 and y == 1 or x == 2 and y == 3) + win1++; + else + win2++; + } + if (win1 == win2) + cout << "TIE" << endl; + else if (win1 < win2) + cout << "TEAM 2 WINS" << endl; + else + cout << "TEAM 1 WINS" << endl; + return 0; +} +inline int gcd(int a, int b) { + if (a % b == 0) + return b; + else + return gcd(b, a % b); +} +int main() { + int n, a[100], i, d, sum; + cin >> n; + cin >> a[0] >> a[1]; + d = gcd(a[0], a[1]); + for (i = 2; i <= n - 1; i++) { + cin >> a[i]; + d = gcd(d, a[i]); + } + sort(a, a + n); + sum = 0; + for (i = d; i <= a[n - 1]; i = i + d) { sum++; } + if ((sum - n) % 2 == 0) { + cout << "Bob" << endl; + } else + cout << "Alice" << endl; + return 0; +} +int main() { + int a, b, c, d, l = 0; + cin >> a >> b >> c; + if (a + b > c && b + c > a && a + c > b) { + d = 0; + cout << d << endl; + } else { + if (a <= b || a <= c) { + while (true) { + a++; + l++; + if (a + b > c && b + c > a && a + c > b) { + cout << l << endl; + break; + } + } + } else { + if (b <= a || b <= c) { + while (true) { + b++; + l++; + if (a + b > c && b + c > a && a + c > b) { + cout << l << endl; + break; + } + } + } + } + } +} +int main() { + string p; + cin >> p; + int y = 0; + while (p[y] == '0') y++; + int rsp = 0; + for (int i = y + 1; i < p.size(); i++) rsp += (p[i] == '0'); + if (rsp >= 6) { + cout << "yes" << endl; + } else { + cout << "no" << endl; + } +} +int main() { + int n, k, count = 0, sum = 0; + long long ele; + cin >> n >> k; + for (int i = 0; i < n; i++) { + count = 0; + cin >> ele; + while (ele) { + if (ele % 10 == 4 || ele % 10 == 7) { count++; } + ele /= 10; + } + if (count <= k) { sum++; } + } + cout << sum << "\n"; +} +long long n, ANS = -1, m, k, x, y, a, b, t, q, ans, sum; +vector v; +long long A[201], fix[201], K[201], B[201][201]; +long long dist[3][3] = {0, 1, 2, 2, 0, 1, 1, 2, 0}; +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> A[i]; + for (int i = 0; i < n; i++) { + cin >> K[i]; + for (int j = 0; j < K[i]; j++) cin >> B[i][j]; + } + for (int T = 1; T <= 3; T++) { + int N = 0, cur = T, ans = 0; + for (int i = 0; i < n; i++) fix[i] = 0; + while (N < n) { + int ind = -1, mndist = 10; + for (int i = 0; i < n; i++) + if (!fix[i]) { + bool ok = true; + for (int j = 0; j < K[i]; j++) + if (!fix[B[i][j] - 1]) { + ok = false; + break; + } + if (ok) { + if (mndist > dist[cur - 1][A[i] - 1]) mndist = dist[cur - 1][A[i] - 1], ind = i; + } + } + ans += mndist; + cur = A[ind]; + fix[ind] = 1; + N++; + } + if (ANS == -1 || ANS > ans) ANS = ans; + } + cout << ANS + n << endl; +} +int arr[1000000]; +int main() { + int n; + cin >> n; + int minimum, answer = (int)1e9; + vector occurrences; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (!i) minimum = arr[0]; + minimum = min(minimum, arr[i]); + } + for (int i = 0; i < n; i++) + if (arr[i] == minimum) occurrences.push_back(i); + for (int i = 1; i < occurrences.size(); i++) answer = min(answer, occurrences[i] - occurrences[i - 1]); + cout << answer << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int A[50][50]; + int row[50], col[50]; + memset(A, 0, sizeof(A)); + memset(row, 0, sizeof(row)); + memset(col, 0, sizeof(col)); + int i, j; + for (i = 1; i <= n; i++) { + for (j = 1; j <= n; j++) { + cin >> A[i][j]; + row[i] += A[i][j]; + col[j] += A[i][j]; + } + } + int ans = 0; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) + if (row[i] < col[j]) ans++; + cout << ans << endl; + } +} +int main() { + string s1, s2; + while (cin >> s1 >> s2) { + cout << s1 << " " << s2 << endl; + int n = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + string kill, rep; + cin >> kill >> rep; + if (kill == s1) + s1 = rep; + else + s2 = rep; + cout << s1 << " " << s2 << endl; + } + } + return 0; +} +const int maxn = 100010; +long long l; +long long ex(long long a, long long b, long long c) { + long long res = 0; + long long Max = a + b + c + l; + for (long long i = a; i <= a + l; i++) { + if (b + c > i) + continue; + else { + long long x = min(Max - i, i) - b - c; + res += (x + 2) * (x + 1) / 2; + } + } + return res; +} +int main() { + long long a, b, c, ans; + ifstream fin("t.txt"); + while (cin >> a >> b >> c >> l) { + ans = (l + 3) * (l + 2) * (l + 1) / 6; + ans -= ex(a, b, c); + ans -= ex(b, a, c); + ans -= ex(c, b, a); + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + long long sum = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += abs(x); + } + cout << sum << '\n'; + return 0; +} +const double pi = acos(-1); +const long long MODPRIMA = (long long)1e9 + 7; +const long long MAXX = (long long)1e18; +const long long MINN = -(long long)1e18; +const double EPS = 1e-9; +int N; +const long long MOD = 1e6 + 3; +long long ans; +int main() { + cin >> N; + ans = 1; + if (N == 0) + cout << 1 << '\n'; + else { + for (int i = 1; i <= N - 1; i++) { + ans *= 3; + ans %= MOD; + } + cout << ans << '\n'; + } + return 0; +} +int a[200010]; +int main() { + long long n, x, ans = 0, sum = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sum += a[i]; + } + for (int i = 1; i <= n; i++) { + ans += a[i]; + if (ans >= sum / 2.0) { + cout << i << endl; + return 0; + } + } + return 0; +} +bool cmp(int a, int b) { + return a > b; +} +int main() { + int i, j; + int n, m, k; + int count; + int array[50]; + cin >> n >> m >> k; + for (i = 0; i < n; i++) { cin >> array[i]; } + sort(array, array + n, cmp); + count = 0; + j = 0; + while (k < m) { + if (j >= n) break; + if (array[j] <= 1) break; + k += array[j++] - 1; + count++; + } + if (k < m) + cout << "-1" << endl; + else + cout << count << endl; + return 0; +} +int main() { + int n; + vector chess; + cin >> n; + int mov1 = 0, mov2 = 0; + for (int x = 0; x < n / 2; x++) { + int acc; + cin >> acc; + chess.push_back(acc); + } + sort(chess.begin(), chess.end()); + for (int x = 0; x < n / 2; x++) { + if (chess[x] != x * 2 + 1) { mov1 += abs(chess[x] - (x * 2 + 1)); } + } + for (int x = 0; x < n / 2; x++) { + if (chess[x] != (x + 1) * 2) { mov2 += abs(chess[x] - ((x + 1) * 2)); } + } + cout << min(mov1, mov2) << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + string answer; + answer += s1[0]; + for (int i = 1; i < s1.length(); i++) { + if (s1[i] >= s2[0]) { + break; + } else { + answer += s1[i]; + } + } + answer += s2[0]; + cout << answer << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + long long sum = 0, prev = 0, x = 0; + for (int i = 1; i <= n; i++) { + prev += sum; + sum += i; + if (sum + prev <= n) + x++; + else + break; + } + cout << x << endl; + } + return 0; +} +int n, cnt; +long long a[200010], mini = 1e18, x; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 1; i < n; i++) { + x = abs(a[i - 1] - a[i]); + if (x < mini) { + cnt = 1; + mini = x; + } else { + if (x == mini) { cnt++; } + } + } + cout << mini << " " << cnt << '\n'; + return 0; +} +int a[100010]; +int per(int x) { + while (x % 2 == 0) x /= 2; + while (x % 3 == 0) x /= 3; + return x; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + a[i] = per(a[i]); + } + int flag = 1; + for (int i = 1; i < n; i++) { + if (a[i] != a[i + 1]) { + flag = 0; + break; + } + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + string s; + int l = 0, u = 0; + cin >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') + u++; + else if (s[i] >= 'a' && s[i] <= 'z') + l++; + } + if (u > l) { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] - 32; } + } + } else if (l >= u) { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = s[i] + 32; } + } + } + cout << s << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2, tot1, tot2; + cin >> s >> v1 >> v2 >> t1 >> t2; + tot1 = s * v1 + t1 * 2; + tot2 = s * v2 + t2 * 2; + if (tot1 < tot2) + cout << "First" << endl; + else if (tot1 > tot2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + long long c = 0; + for (int i = 1; i <= n; i++) { + if (((i > a) && (n - i) <= b)) c++; + } + cout << c << "\n"; +} +int main() { + int n; + cin >> n; + int a[n]; + int buf = 0, ans = 0, max = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < buf) + ans = 1; + else + ans++; + buf = a[i]; + if (ans > max) max = ans; + } + cout << max << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int counter = 0; + for (int a = 0; a <= m; a++) + for (int b = 0; b <= n; b++) + if (a * a + b == n && a + b * b == m) counter++; + cout << counter << endl; + return 0; +} +int main() { + string s; + string n[10]; + cin >> s; + for (int i = 0; i < 10; i++) { cin >> n[i]; } + for (int sp = 0; sp < 80; sp += 10) { + string c = s.substr(sp, 10); + for (int i = 0; i < 10; i++) { + if (c == n[i]) { + cout << i; + break; + } + } + } + cout << endl; +} +int main() { + int n; + string s; + long long c = 1; + cin >> s; + c = 25 + 25 + 1; + int len = s.size() - 1; + c += 25 * len; + cout << c << endl; + return 0; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3, greater()); + if (a[0] + a[1] > a[2] && a[1] + a[2] > a[0] && a[2] + a[1] > a[0]) { + cout << 0 << endl; + } else if (a[0] + a[1] > a[2] && a[0] + a[2] > a[1] && a[2] + a[1] <= a[0]) { + int num1 = a[0] / 2; + num1 = a[0] - num1; + num1 = num1 - a[2]; + int num2 = a[0] / 2; + num2 = a[0] - num2; + num2 = num2 - a[1]; + if (a[0] % 2) { + cout << num1 + num2 << endl; + } else { + cout << num1 + num2 + 1 << endl; + } + } +} +map m; +long long lca(long long u, long long v, int w = -1) { + long long res = 0; + while (u != v) { + if (v < u) swap(v, u); + if (m.find(v) != m.end()) res += m[v]; + if (~w) m[v] += w; + v >>= 1; + } + return res; +} +int main() { + int q; + int t; + long long u, v, w; + cin >> q; + while (q--) { + cin >> t >> u >> v; + if (t == 1) { + cin >> w; + lca(u, v, w); + } else { + cout << lca(u, v) << "\n"; + } + } +} +int main() { + int n, m, i, j, a[105]; + char x; + cin >> n >> m; + for (i = 0; i < n; i++) { + set s; + s.clear(); + for (j = 0; j < m; j++) { + cin >> x; + s.insert(x - '0'); + } + if (s.size() > 1) break; + a[i] = x - '0'; + } + if (i < n) + cout << "NO" << endl; + else { + int flag = 1; + for (i = 1; i < n - 1; i++) { + if (a[i] == a[i - 1] || a[i] == a[i + 1]) { + flag = 0; + break; + } + } + cout << (flag ? "YES" : "NO") << endl; + } + return 0; +} +int main() { + string x[100000]; + int n; + cin >> n; + for (int i = 0; i < n * 2; i++) { cin >> x[i]; } + for (int i = 1; i < n * 2; i += 2) { + if (x[i] == "rat") cout << x[i - 1] << endl; + } + for (int i = 1; i < n * 2; i += 2) { + if (x[i] == "woman" || x[i] == "child") cout << x[i - 1] << endl; + } + for (int i = 1; i < n * 2; i += 2) { + if (x[i] == "man") cout << x[i - 1] << endl; + } + for (int i = 1; i < n * 2; i += 2) { + if (x[i] == "captain") cout << x[i - 1] << endl; + } + return 0; +} +int main() { + int step, s = 0; + cin >> step; + while (step > 0) { + if (step >= 5) { + step -= 5; + s++; + } else if (step >= 4) { + step -= 4; + s++; + } else if (step >= 3) { + step -= 3; + s++; + } else if (step >= 2) { + step -= 2; + s++; + } else if (step >= 1) { + step -= 1; + s++; + } + } + cout << s << endl; + return 0; +} +long long n, m; +int main() { + cin >> n >> m; + if (n / m % 2) { + cout << "YES\n"; + } else + cout << "NO\n"; +} +void speed() {} +long long n, m, k, cnt, ans, sum, x, y, mx, mn = 1e9; +string s, s1, s2, a, b, c; +vector v; +set st; +multimap mp; +int main() { + speed(); + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s1 >> s2; + if (s2 == "rat") a += s1 + '\n'; + if (s2 == "woman" or s2 == "child") b += s1 + '\n'; + if (s2 == "man") c += s1 + '\n'; + if (s2 == "captain") s += s1 + '\n'; + } + cout << a << b << c << s; +} +int main() { + int n, i, a[100], large, ans = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + large = a[0]; + for (i = 0; i < n; i++) { + if (large < a[i]) large = a[i]; + } + for (i = 0; i < n; i++) { ans += large - a[i]; } + cout << ans << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int h = 0, p = 0; + while (h < n) { + h += 5; + p++; + } + cout << p << endl; +} +long long GCD(long long a, long long b) { + return b == 0 ? a : GCD(b, a % b); +} +int main() { + long long T, x, y, p, q, n; + cin >> T; + while (T--) { + cin >> x >> y >> p >> q; + if (p == q) + cout << (x == y ? 0 : -1) << endl; + else if (p == 0) + cout << (x == 0 ? 0 : -1) << endl; + else { + long long gcd = GCD(p, q); + p /= gcd; + q /= gcd; + n = max(ceil(x * 1.0 / p), ceil((y - x) * 1.0 / (q - p))); + cout << n * q - y << endl; + } + } +} +map m1; +map::iterator itr; +long long int cnt = 0; +int main() { + long long int n; + cin >> n; + string str; + cin >> str; + vector ans; + long long int count = 0; + int flag = 0; + for (long long int i = 0; i < str.size(); i++) { + if (str[i] == '1') { + count++; + flag = 1; + } else { + ans.push_back(count); + count = 0; + } + } + if (str[n - 1] = '1') ans.push_back(count); + for (long long int i = 0; i < ans.size(); i++) cout << ans[i]; + cout << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int a[55]; + for (int i = 0; i < m; i++) cin >> a[i]; + sort(a, a + m); + int min2 = 999999999, t; + for (int i = n - 1; i < m; i++) { + t = a[i] - a[i - n + 1]; + if (min2 > t) min2 = t; + } + cout << min2 << endl; + } +} +int main() { + int n, h, st, ed, q; + cin >> n >> h >> st >> ed >> q; + while (q--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + if (x1 == x2) { + cout << abs(y1 - y2) << endl; + } else { + if (y1 >= st && y1 <= ed) + cout << abs(x2 - x1) + abs(y1 - y2) << endl; + else { + int ans1 = abs(y1 - st) + abs(y2 - st) + abs(x1 - x2); + int ans2 = abs(y1 - ed) + abs(y2 - ed) + abs(x1 - x2); + cout << min(ans1, ans2) << endl; + } + } + } +} +int main() { + int n, k; + cin >> n >> k; + int x, y; + int sc = 0; + int ac = 0; + int fs = 0; + int temp = 0; + for (int i = 0; i < n; i++) { + cin >> x >> y; + fs += (y - x + 1); + } + if (fs % k == 0) { + cout << 0 << endl; + return 0; + } else { + fs = fs % k; + if (fs != 0) fs = k - fs; + cout << fs << endl; + } + return 0; +} +string s1, s2, s3, s4; +int n; +int main() { + cin >> s1 >> s2 >> n; + cout << s1 << " " << s2 << endl; + for (int i = 1; i <= n; ++i) { + cin >> s3 >> s4; + if (s3 == s1) + s1 = s4; + else + s2 = s4; + cout << s1 << " " << s2 << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + sort(s.begin(), s.end()); + char last = s[0]; + string ans; + ans += s[0]; + for (int i = 1; i < n and ans.size() < k; i++) { + if (s[i] - last > 1) { + ans += s[i]; + last = s[i]; + } + } + int resp = 0; + for (int i = 0; i < ans.size(); i++) resp += ans[i] - 'a' + 1; + cout << (ans.size() == k ? resp : -1) << endl; + return 0; +} +int main() { + long int n, sum = 0; + cin >> n; + long int a[n]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] < 0) { + sum = sum - a[i]; + } else { + sum = sum + a[i]; + } + } + cout << sum << endl; +} +int n, k; +int c; +int a[405]; +int f[405]; +int ans = 0; +int main() { + memset(f, 0, sizeof(f)); + cin >> n >> k >> c; + for (int i = 1; i <= c; i++) { + cin >> a[i]; + f[a[i]]++; + } + int t = k; + for (int i = 1; i <= n; i++) + if (i == t || f[i]) t = i + k, ans++; + cout << ans << endl; + return 0; +} +int n, m; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + int t; + cin >> t; + m -= 86400 - t; + if (m <= 0) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int k, a, b, v; + cin >> k >> a >> b >> v; + int cnt = 0; + while (a > 0) { + if (b + 1 <= k) { + cnt++; + a -= (b + 1) * v; + b = 0; + if (a > 0) { + cnt += ceil(1.0 * a / v); + a = 0; + } + } else { + cnt++; + a -= k * v; + b -= k - 1; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int pos, post; + for (int i = 0; i < n; i++) { + if (s[i] == 'G') pos = i; + if (s[i] == 'T') post = i; + } + if (abs(pos - post) % k != 0) + cout << "NO\n"; + else { + bool f = 1; + if (pos < post) { + for (int i = pos; i <= post; i += k) + if (s[i] == '#') f = 0; + } else { + for (int i = pos; i >= post; i -= k) + if (s[i] == '#') f = 0; + } + cout << (f ? "YES" : "NO") << '\n'; + } + return 0; +} +int main() { + int n, x; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> x; + if (360 % (180 - x) == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + int n, l, count = 0; + string s; + cin >> s; + l = s.length(); + n = atoi(s.c_str()); + for (int i = 0; i < l; i++) { + if (s[i] == '4' || s[i] == '7') count++; + } + if (count == 4 || count == 7) { + cout << "YES" << endl; + } + else + cout << "NO" << endl; + return 0; +} +int max(int a, int b) { + return a > b ? a : b; +} +int main() { + int n; + string s; + while (cin >> n) { + cin >> s; + if (n == 1) { + cout << "NO" << endl; + continue; + } + for (int i = 1; i < s.size(); i++) { + if (s[i] != s[i - 1]) { + cout << "YES" << endl; + cout << s[i - 1] << s[i] << endl; + exit(0); + } + } + cout << "NO" << endl; + } + return 0; +} +int answer; +int main() { + string s; + int ln; + char sn; + int fn; + int ss[100]; + cin >> s; + ln = s.length(); + sn = s[0]; + ss[0] = 0; + fn = 1; + for (int i = 1; i <= ln; i++) { + if (sn == s[i]) { + fn += 1; + ss[i] = ss[i - 1]; + } else { + ss[i] = ss[i - 1] + (fn + 1) % 2; + sn = s[i]; + fn = 1; + } + } + answer = ss[ln]; + cout << answer << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int t; + cin >> t; + string a; + cin >> a; + if ((a.size() == 2 && a[0] >= a[1]) || a.size() == 1) + cout << "NO\n"; + else { + cout << "YES\n2\n"; + cout << a[0] << " "; + for (int i = 1; i < a.size(); i++) cout << a[i]; + cout << "\n"; + } + } + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int t1 = ((n + k - 1) / k) * t; + int timer = 0, t2 = 0, cake = 0; + while (cake < n) { + timer++; + if (timer > d) t2++; + if (timer % t == 0) { cake += k; } + if (t2 > 0 && t2 % t == 0) { cake += k; } + } + if (t1 <= timer) { + cout << "NO" + << "\n"; + } else { + cout << "YES" + << "\n"; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string str[n]; + for (int i = 0; i < n; i++) { cin >> str[i]; } + bool highest[n] = {false}; + int high[m] = {0}; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (str[i][j] > high[j]) high[j] = str[i][j]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (str[i][j] == high[j]) highest[i] = true; + } + } + int coun = 0; + for (int i = 0; i < n; i++) { + if (highest[i] == true) coun++; + } + cout << coun << endl; + return 0; +} +string st, st1[102]; +long long n; +int main() { + cin >> st >> n; + for (int i = 1; i <= n; i++) cin >> st1[i]; + sort(st1 + 1, st1 + n + 1); + for (int i = 1; i <= n; i++) + if (st1[i].find(st) == 0) { + cout << st1[i] << endl; + return 0; + } + cout << st << endl; + return 0; +} +int n, a[11][11]; +int main() { + cin >> n; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) + if (i == 1 || j == 1) + a[i][j] = 1; + else + a[i][j] = a[i - 1][j] + a[i][j - 1]; + cout << a[n][n] << endl; + return 0; +} +int main() { + long long x; + cin >> x; + if (x % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + priority_queue pq; + int n, m; + cin >> n; + cin >> m; + for (int i = 1; i < n; i++) { + int k; + cin >> k; + if (k >= m) pq.push(k); + } + int cnt = 0; + while (!pq.empty()) { + int k = pq.top(); + pq.pop(); + if (k >= m) { + cnt++; + k--; + m++; + } + if (m <= k) pq.push(k); + } + cout << cnt << endl; +} +int main() { + string cad; + cin >> cad; + int guiones = 0, perlas = 0; + for (int i = 0; i < cad.size(); i++) + if (cad[i] == '-') + guiones++; + else + perlas++; + if (guiones == 0 || perlas == 0) + cout << "YES\n"; + else { + if (guiones < perlas) + cout << "NO\n"; + else { + if (guiones == perlas) + cout << "YES\n"; + else { + if (guiones % perlas == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + } + } + return 0; +} +map m; +int main() { + int n; + cin >> n; + char s; + long long aux; + long long num = 0; + long long pot = 1; + for (int i = 0; i < n; i++) { + cin >> s >> aux; + if (s == '+' || s == '-') { + num = 0; + pot = 1; + while (aux > 0) { + if (aux % 2 != 0) { num += pot; } + pot *= 10; + aux /= 10; + } + if (s == '+') { + m[num]++; + } else { + m[num]--; + } + } else { + cout << m[aux] << endl; + } + } + return 0; +} +bool prime(int n) { + int c = 0; + for (int i = 1; i < n; i++) { + if (n % i == 0) c++; + } + if (c == 1) + return true; + else + return false; +} +int main() { + int n, c = 0; + cin >> n; + int arr[n], ar[n]; + for (int i = 0; i < n; i++) { cin >> arr[i] >> ar[i]; } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (arr[i] == ar[j]) { c++; } + if (ar[i] == arr[j]) c++; + } + } + cout << c / 2 << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[12], x = 0, sum = 0, k = 0; + for (int i = 0; i < 12; i++) cin >> a[i]; + if (n == 0) { + cout << 0 << endl; + continue; + } + sort(a, a + 12); + reverse(a, a + 12); + for (int i = 0; i < 12; i++) { + sum += a[i]; + x++; + if (sum >= n) { + cout << x << endl; + k = 1; + break; + } + } + if (k == 0) cout << -1 << endl; + } + return 0; +} +int main() { + int t, n; + cin >> t; + while (t--) { + string s; + cin >> n >> s; + int flag = 0; + for (int i = 0; i < n / 2; i++) { + if (s[i] == s[n - i - 1]) continue; + if (!(abs(s[i] - s[n - i - 1]) == 2)) { flag = 1; } + } + if (flag == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k; + char a[120]; + cin >> n >> k; + int st = -1; + int ed = -1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 'G') st = i; + if (a[i] == 'T') ed = i; + } + for (int i = st; i < n; i += k) { + if (i == ed) { + cout << "YES" << endl; + return 0; + } + if (a[i] == '#') break; + } + for (int i = st; i >= 0; i -= k) { + if (i == ed) { + cout << "YES" << endl; + return 0; + } + if (a[i] == '#') break; + } + cout << "NO" << endl; + return 0; +} +bool x[105]; +int stat, ans, n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> x[i]; + for (int i = 1; i <= n; i++) { + if (x[i]) stat = 1; + if (!x[i] && !x[i + 1]) stat = 0; + ans += stat; + } + cout << ans << endl; +} +int main() { + int n, w, l, v, i; + cin >> n; + int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + if (arr[0] == 3) { + cout << "NO" << endl; + return 0; + } + w = arr[0]; + if (1 == w) + l = 2; + else + l = 1; + for (i = 1; i < n; i++) { + if (l == arr[i]) { + cout << "NO" << endl; + return 0; + } + if (arr[i] == 1) { + w = 1; + if (l == 2) + l = 3; + else + l = 2; + } else if (arr[i] == 2) { + w = 2; + if (l == 1) + l = 3; + else + l = 1; + } + if (arr[i] == 3) { + w = 3; + if (l == 2) + l = 1; + else + l = 2; + } + } + cout << "YES" << endl; + return 0; +} +int n, k; +int main() { + cin >> n >> k; + for (int i = n; i >= 0; i--) { + if ((((5 + 5 * i) * i) / 2) <= (240 - k)) { + cout << i << endl; + break; + } + } +} +long long n, l, r, Ql, Qr, pre, ans, mn = 1e18; +deque dq; +int main() { + cin >> n >> l >> r >> Ql >> Qr; + for (int i = 0; i < n; i++) { + cin >> pre, dq.push_back(pre); + if (i) dq[i] += dq[i - 1]; + } + for (int i = 0; i < n; i++) { + ans = (dq[i]) * l + (dq[n - 1] - dq[i]) * r; + if (i + 1 > n - i - 1) + ans += (((i + 1) - (n - i - 1)) - 1) * Ql; + else if (i + 1 < n - i - 1) + ans += (((n - i - 1) - (i + 1)) - 1) * Qr; + mn = min(mn, ans); + } + mn = min(mn, dq[n - 1] * r + (n - 1) * Qr); + cout << mn << endl; + return 0; +} +string op[444]; +int main() { + long long n, p; + cin >> n >> p; + p /= 2; + for (int i = 1; i <= n; i++) { cin >> op[i]; } + long long ans = 0, send = 0; + for (int i = n; i >= 1; i--) { + send *= 2; + if (op[i] == "halfplus") { send++; } + ans += send; + } + cout << ans * p << endl; + return 0; +} +int main() { + int n[3][3], dx = 1, dy = 1; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> n[i][j]; + n[i][j] = n[i][j] % 2; + } + } + int out[3][3] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (n[i][j] == 1) { + out[i][j] = out[i][j] ^ 1; + if (j + dy < 3) { out[i][j + dy] ^= 1; } + if (j - dy >= 0) { out[i][j - dy] ^= 1; } + if (i + dx < 3) out[i + dx][j] ^= 1; + if (i - dx >= 0) out[i - dx][j] ^= 1; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) cout << out[i][j]; + cout << endl; + } +} +int n, a[35][35]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) cin >> a[i][j]; + int ans = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int t1, t2; + t1 = t2 = 0; + for (int k = 0; k < n; k++) t1 += a[k][j], t2 += a[i][k]; + if (t1 > t2) ++ans; + } + } + cout << ans << endl; + return 0; +} +const int N = 2e5; +vector v; +int a[N + 1]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + v.push_back(x); + } + int mn = 2e9; + sort(v.begin(), v.end()); + for (int i = 0; i < v.size() - 1; i++) { mn = min(mn, v[i + 1] - v[i]); } + int c = 0; + for (int i = 0; i < v.size() - 1; i++) { + if (v[i] + mn == v[i + 1]) c++; + } + cout << mn << " " << c << endl; +} +int main() { + int n, m; + cin >> n >> m; + bool c = 0; + for (int i = 0; i < n; i++) { + if (i % 2 == 0) { + for (int j = 0; j < m; j++) { cout << "#"; } + cout << endl; + } else { + if (c == 0) { + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << "#"; + cout << endl; + } else if (c == 1) { + cout << "#"; + for (int j = 0; j < m - 1; j++) { cout << "."; } + cout << endl; + } + if (c == 1) { + c = 0; + } else { + c = 1; + } + } + } +} +int main() { + int n; + cin >> n; + int ans = 0; + while (n--) { + int a, b; + cin >> a >> b; + if (b - a >= 2) ans++; + } + cout << ans << endl; +} +int main() { + int n, a, b, d = 0, c = 0; + cin >> n >> a >> b; + d = n - a; + c = b + 1; + if (d <= c) + cout << d << endl; + else + cout << c << endl; + return 0; +} +int a[10000]; +int main() { + long long n; + while (cin >> n) { cout << n * 3 / 2 << endl; } + return 0; +} +static const int mod = 1000000009; +long long power(int a, int m) { + if (m == 1) { + return a; + } else { + long long k = power(a, m / 2) % mod; + k = (m % 2 == 0 ? k * k : k * k * a); + k %= mod; + return k; + } +}; +int main() { + int n, m; + cin >> n >> m; + long long *t = new long long[n]; + long long k = power(2, m); + t[0] = k - 1; + for (int i = 1; i < n; ++i) { t[i] = t[i - 1] - 1; } + long long result = t[0]; + for (int i = 1; i < n; ++i) { result = ((result % mod) * (t[i] % mod)) % mod; } + cout << result << endl; +} +int main() { + int n; + cin >> n; + int *p = new int[2 * n]; + for (int i = 0; i < 2 * n; i++) { cin >> p[i]; } + int sum = 0; + for (int i = 0; i < 2 * n; i = i + 2) { + for (int j = i + 3; j < 2 * n; j = j + 2) { + if (p[i] == p[j]) sum++; + } + } + for (int i = 1; i < 2 * n; i = i + 2) { + for (int j = i + 1; j < 2 * n; j = j + 2) { + if (p[i] == p[j]) sum++; + } + } + cout << sum << endl; + return 0; +} +void rps(string t1, string t2); +int main() { + string t1, t2; + getline(cin, t1, '\n'); + getline(cin, t2, '\n'); + rps(t1, t2); + return 0; +} +void rps(string t1, string t2) { + int tone = 0, ttwo = 0; + for (int i = 0; i < t1.length(); i += 2) + if (t1[i] == '8' && t2[i] == '[') + tone++; + else if (t1[i] == '8' && t2[i] == '(') + ttwo++; + else if (t1[i] == '(' && t2[i] == '8') + tone++; + else if (t1[i] == '(' && t2[i] == '[') + ttwo++; + else if (t1[i] == '[' && t2[i] == '(') + tone++; + else if (t1[i] == '[' && t2[i] == '8') + ttwo++; + if (tone > ttwo) + cout << "TEAM 1 WINS" << endl; + else if (tone < ttwo) + cout << "TEAM 2 WINS" << endl; + else + cout << "TIE" << endl; +} +int n, k, a[1001], ans; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + a[i] = k; + sort(a, a + i + 1); + if (((a[0] == k && a[1] != k) || (a[i] == k && a[i - 1] != k)) && i != 0) ans++; + } + cout << ans << endl; + return 0; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +long long prime[100005]; +void seive() { + memset(prime, 1, sizeof(prime)); + prime[0] = 0; + prime[1] = 0; + for (long long i = 2; i * i <= 100000; i++) { + if (prime[i] == 1) { + for (long long j = i * i; j <= 100000; j += i) prime[j] = 0; + } + } +} +long long power(long long a, long long b) { + long long ans = 1; + while (b > 0) { + if (b % 2 == 1) ans = (ans % 1000000007 * a % 1000000007) % 1000000007; + a = (a * a) % 1000000007; + b = b / 2; + } + return ans; +} +void swap(long long *a, long long *b) { + long long c = *a; + *a = *b; + *b = c; +} +int main() { + bool codechef = 0; + long long t = 1; + if (codechef) cin >> t; + while (t--) { + long long n, k; + cin >> n >> k; + long long i, j; + vector v; + map m; + for (i = 1; i <= k; i++) { + int r = n % 10; + if (r != 0) + n = n - 1; + else + n = n / 10; + } + cout << n << endl; + } + return 0; +} +int main() { + int n = 0, i = 0, t = 0, max = 0; + cin >> n; + vector f(101, 0); + for (i = 0; i < n; i++) { + cin >> t; + f[t]++; + } + for (i = 1; i <= 100; i++) { max = (f[i] > max) ? f[i] : max; } + cout << max << endl; + return 0; +} +int main() { + int n, x, y, p, q; + cin >> n; + vector v; + vector v1; + cin >> p; + for (int i = 0; i < p; i++) { + cin >> x; + v.push_back(x); + } + cin >> q; + for (int i = 0; i < q; i++) { + cin >> y; + v.push_back(y); + } + sort(v.begin(), v.end()); + for (int i = 0; i < (p + q); i++) { + if (v[i] == v[i + 1]) continue; + v1.push_back(v[i]); + } + int l = v1.size(); + if (l == n) { + cout << "I become the guy." << endl; + } else + cout << "Oh, my keyboard!" << endl; +} +long long p, q, k; +long long gcd(long long a, long long b) { + return b == 0 ? a : gcd(b, a % b); +} +inline long long rd() { + long long x = 0, f = 1; + char ch = getchar(); + while (ch > '9' || ch < '0') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = (x << 1) + (x << 3) + ch - '0'; + ch = getchar(); + } + return x * f; +} +inline void solve() { + p = rd(), q = rd(), k = rd(); + long long t = gcd(p, q); + q /= t; + while ((t = gcd(k, q)) != 1) { + while (q % t == 0) q /= t; + } + puts(q == 1 ? "Finite" : "Infinite"); +} +int main() { + for (int T = rd(); T; T--) solve(); + return 0; +} +int main() { + string s[51]; + int m, n; + cin >> n >> m; + getchar(); + for (int i = 0; i < n; i++) { getline(cin, s[i]); } + int count = 0; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + string temp; + temp += s[i][j]; + temp += s[i][j + 1]; + temp += s[i + 1][j]; + temp += s[i + 1][j + 1]; + sort(temp.begin(), temp.end()); + if (temp == "acef") count++; + } + } + cout << count << endl; + return 0; +} +int main() { + int n, a, b; + string str; + cin >> n >> a >> b; + cin >> str; + cout << abs((str[a - 1] - '0') - (str[b - 1] - '0')) << endl; + return 0; +} +int main() { + long long min, max, n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> min >> max; + long long x = 1; + long long result = min; + while (min < max) { + min = min | x; + if (min <= max) result = min; + x *= 2; + } + cout << result << endl; + } + return 0; +} +int main() { + int a, b, c; + int x, y, z; + cin >> a >> b >> c; + x = sqrt((a * c) / b); + y = sqrt((b * a) / c); + z = sqrt((b * c) / a); + cout << x * 4 + y * 4 + z * 4 << endl; + return 0; +} +long long a[101]; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + long long ans = n; + for (long long i = 1; i < n; i++) + if (a[i] == a[i - 1]) ans--; + if (a[0] == 0) ans--; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool flag = 0; + for (int i = 1; i <= n; i++) { + if (i % 2 == 1) { + for (int j = 1; j <= m; j++) { cout << '#'; } + } else if (i % 2 == 0 && flag == 0) { + for (int j = 1; j < m; j++) { cout << '.'; } + cout << '#'; + flag = 1; + } else { + cout << '#'; + for (int j = 1; j < m; j++) { cout << '.'; } + flag = 0; + } + cout << endl; + } + return 0; +} +int main() { + int n, p, q, x = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p >> q; + if (q - p >= 2) x++; + } + cout << x << endl; +} +string IntToPattern(long long i) { + string patt = ""; + while (i != 0) { + long long t = i % 10; + if (t % 2 == 0) { + patt = '0' + patt; + } else { + patt = '1' + patt; + } + i = i / 10; + } + int nl = (18 - patt.length()); + for (int j = 0; j < nl; j++) { patt = '0' + patt; } + return patt; +} +int main() { + int n; + cin >> n; + set second; + map p; + while (n--) { + char c; + cin >> c; + if (c == '+') { + long long el; + cin >> el; + string t; + t = IntToPattern(el); + if (second.count(t)) { + p[t]++; + } else { + second.insert(t); + p[t]++; + } + } else if (c == '-') { + long long el; + cin >> el; + string t; + t = IntToPattern(el); + if (p[t] > 1) { + p[t]--; + } else { + p[t]--; + second.erase(t); + } + } else { + string sl; + cin >> sl; + string temp = ""; + int nl = 18 - sl.length(); + for (int i = 0; i < nl; i++) { temp = temp + '0'; } + temp = temp + sl; + cout << p[temp] << endl; + } + } + return 0; +} +int main() { + int w, h, k; + while (cin >> w >> h >> k) { + int sum = 0; + for (int i = 0; i < k; ++i) { + sum += 2 * (w + h) - 4; + w -= 4; + h -= 4; + } + cout << sum << '\n'; + } + return 0; +} +int main() { + long long int a, b; + cin >> a >> b; + long long int i, f = 1; + for (i = 1;; i++) { + f *= i; + if (i == a || i == b) { + cout << f << endl; + break; + } + } + return 0; +} +int main() { + int l, r, a; + while (cin >> l >> r >> a) { + if (l == 0 && a == 0 || r == 0 && a == 0) { + cout << "0" << endl; + continue; + } else if (l == 0 && r == 0 && a == 1) + cout << "0" << endl; + else if (l == 0 && r == 0) + cout << a << endl; + else if (l == 0) { + if (r < a) { + if (r == 1) + cout << 2 * (r * r) << endl; + else if (r % 2 == 0 && a % 2 == 0) + cout << r + a << endl; + else if (r % 2 == 1 && a % 2 == 0) + cout << r + a - 1 << endl; + else if (r % 2 == 0 && a % 2 == 1) + cout << a + r - 1 << endl; + else if (r % 2 == 1 && a % 2 == 1) + cout << r + a << endl; + } else if (r > a) { + if (a == 1) + cout << 2 * (a * a) << endl; + else + cout << a + a << endl; + } else if (r == a) + cout << a + a << endl; + } else if (r == 0) { + if (l < a) { + if (l == 1) + cout << 2 * (l * l) << endl; + else if (l % 2 == 0 && a % 2 == 0) + cout << l + a << endl; + else if (l % 2 == 1 && a % 2 == 0) + cout << l + a - 1 << endl; + else if (l % 2 == 0 && a % 2 == 1) + cout << a + l - 1 << endl; + else if (l % 2 == 1 && a % 2 == 1) + cout << l + a << endl; + } else if (l > a) { + if (a == 1) + cout << 2 * (a * a) << endl; + else + cout << a + a << endl; + } else if (l == a) + cout << a + a << endl; + } else if (a == 0) { + if (r < l) { + if (r == 1) + cout << 2 * (r * r) << endl; + else + cout << r + r << endl; + } else if (r > l) { + if (l == 1) + cout << 2 * (l * l) << endl; + else + cout << l + l << endl; + } else if (r == l) + cout << l + l << endl; + } else if (l <= a && (l + a) < r) + cout << 2 * (l + a) << endl; + else if (r <= a && (r + a) < l) + cout << 2 * (r + a) << endl; + else if ((l + a) < r) + cout << 2 * (l + a) << endl; + else if ((r + a) < l) + cout << 2 * (r + a) << endl; + else { + int ans, ex1 = 0, ex2 = 0; + int add = l + r; + if (add % 2 == 1) { + add = add - 1; + ex1 = 1; + } + if (a % 2 == 0) + ans = add + a; + else { + ans = add + a - 1; + ex2 = 1; + } + if (ex1 + ex2 == 2) + cout << ans + 2 << endl; + else + cout << ans << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int kir = 0, kan = 0; + for (int i = 0; i < n; i++) { + int x, y; + cin >> x >> y; + if (x < 0) + kir += 1; + else + kan += 1; + } + if (kir <= 1 || kan <= 1) { + cout << "Yes" << endl; + } else + cout << "No" << endl; +} +int main() { + int n, point, result = 0, highest, lowest; + cin >> n; + cin >> point; + highest = lowest = point; + for (int i = 1; i < n; i++) { + cin >> point; + if (point > highest && point > lowest) { + highest = point; + result++; + } + if (point < highest && point < lowest) { + lowest = point; + result++; + } + } + cout << result << endl; +} +int main() { + long long n; + cin >> n; + long long chk = 0; + chk = n / 2; + if (chk * 2 == n) + cout << chk; + else + cout << chk - n; + cout << endl; + return 0; +} +string s; +int main() { + int t; + cin >> t; + int angle; + for (int i = 0; i < t; i++) { + cin >> angle; + if (360 % (180 - angle) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int levels; + cin >> levels; + int x, y; + set myset; + for (int i = 0; i < 2; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> y; + myset.insert(y); + } + } + if (myset.size() == levels) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int main() { + int num[5], sum = 0; + for (int i = 0; i < 5; i++) { + cin >> num[i]; + sum += num[i]; + } + if (sum % 5 == 0 && sum != 0) + cout << sum / 5 << endl; + else + cout << "-1" << endl; +} +int main() { + long long int i, n, count = 0, min = INT_MAX, sum = 0; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 != 0) { + count++; + if (a[i] < min) min = a[i]; + } + sum += a[i]; + } + if (count % 2 != 0) sum = sum - min; + cout << sum << endl; + return 0; +} +void print(int n) { + if (n == 0) + cout << "O-|-OOOO" << endl; + else if (n == 1) + cout << "O-|O-OOO" << endl; + else if (n == 2) + cout << "O-|OO-OO" << endl; + else if (n == 3) + cout << "O-|OOO-O" << endl; + else if (n == 4) + cout << "O-|OOOO-" << endl; + else if (n == 5) + cout << "-O|-OOOO" << endl; + else if (n == 6) + cout << "-O|O-OOO" << endl; + else if (n == 7) + cout << "-O|OO-OO" << endl; + else if (n == 8) + cout << "-O|OOO-O" << endl; + else + cout << "-O|OOOO-" << endl; +} +int main() { + vector v; + int n; + cin >> n; + if (n == 0) print(n); + while (n) { + v.push_back(n % 10); + n /= 10; + } + for (int i = 0; i < v.size(); i++) { print(v[i]); } + return 0; +} +int main() { + int n, m, cnt = 0; + bool check; + cin >> n; + for (int i = 1; i < n; i++) { + check = true; + m = 1; + for (int j = 1; j <= n - 2; j++) { + m = (m * i) % n; + if ((m % n) - 1 == 0) { + check = false; + break; + } + } + if (check && ((m * i) % n) - 1 == 0) cnt++; + } + cout << cnt << endl; + return 0; +} +int a[100001]; +int main() { + int n, ans = 1, maxx = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 1; i++) { + if (a[i] < a[i + 1]) + ans++; + else { + maxx = max(maxx, ans); + ans = 1; + } + } + cout << max(maxx, ans) << endl; + return 0; +} +long long gcd(long long x, long long y) { + if (y == 0) + return x; + else + return gcd(y, x % y); +} +long long expo(long long n, long long m, long long p) { + long long r = 1; + n = n % p; + while (m > 0) { + if (m % 2) r = (r * n) % p; + n = (n * n) % p; + m = m / 2; + } + return r % p; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +int main() { + long long t; + cin >> t; + while (t--) { + long long a, b, c, d; + cin >> a >> b >> c >> d; + cout << (a / b) - ((d / b) - (c - 1) / b) << "\n"; + } + return 0; +} +int main() { + int sum = 0, n, x1, x2, y1, y2; + cin >> n; + while (n--) { + cin >> x1 >> y1 >> x2 >> y2; + for (int i = x1; i <= x2; i++) { + for (int j = y1; j <= y2; j++) sum++; + } + } + cout << sum << endl; + return 0; +} +int main() { + unsigned n; + string s, t, tmp, temp; + cin >> s >> t; + cout << s << ' ' << t << endl; + cin >> n; + for (unsigned i = 0; i < n; i++) { + cin >> tmp >> temp; + if (s == tmp) + s = temp; + else + t = temp; + cout << s << ' ' << t << endl; + } +} +int main() { + unsigned long long n; + cin >> n; + cout << "25" << endl; +} +int main() { + int n; + string *p, *q; + while (cin >> n) { + p = new string[n]; + q = new string[n]; + int a[10], b[10]; + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + int m = 0; + for (int i = 0; i < n; i++) { + cin >> p[i]; + if (p[i] == "S") a[1]++; + if (p[i] == "XS") a[2]++; + if (p[i] == "XXS") a[3]++; + if (p[i] == "XXXS") a[4]++; + if (p[i] == "M") a[5]++; + if (p[i] == "L") a[6]++; + if (p[i] == "XL") a[7]++; + if (p[i] == "XXL") a[8]++; + if (p[i] == "XXXL") a[9]++; + } + for (int i = 0; i < n; i++) { + cin >> q[i]; + if (q[i] == "S") b[1]++; + if (q[i] == "XS") b[2]++; + if (q[i] == "XXS") b[3]++; + if (q[i] == "XXXS") b[4]++; + if (q[i] == "M") b[5]++; + if (q[i] == "L") b[6]++; + if (q[i] == "XL") b[7]++; + if (q[i] == "XXL") b[8]++; + if (q[i] == "XXXL") b[9]++; + } + for (int i = 1; i < 10; i++) { + if (a[i] > b[i]) m += a[i] - b[i]; + } + cout << m << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + for (int i = 0; i <= n; i++) { + if (s[i] == '0') { + cout << i + 1 << endl; + return 0; + } + } + cout << n << endl; +} +int main() { + int n; + cin >> n; + int sum = 0; + for (int i = 1; i <= n; i++) { + int tmp; + cin >> tmp; + sum += abs(tmp); + } + cout << sum << endl; + return 0; +} +int main() { + int n, t, t2; + cin >> n; + t = n / 2 + 1; + t2 = n - 2; + for (int i = 1; i <= n; i++) { + if (i <= t) { + for (int j = 1; j <= t - i; j++) cout << '*'; + for (int j = 1; j <= n - 2 * t + 2 * i; j++) cout << 'D'; + for (int j = 1; j <= t - i; j++) cout << '*'; + cout << '\n'; + } else { + for (int j = 1; j <= (n - t2) / 2; j++) cout << '*'; + for (int j = 1; j <= t2; j++) cout << 'D'; + for (int j = 1; j <= (n - t2) / 2; j++) cout << '*'; + t2 -= 2; + cout << '\n'; + } + } +} +bool isvowel(char ch) { + if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true; + return false; +} +int main() { + string s; + int i; + cin >> s; + int f = 0; + for (i = 0; i < s.size() - 1; i++) { + if (isvowel(s[i]) || s[i] == 'n') + continue; + else { + if (!isvowel(s[i + 1])) { + f = 1; + break; + } + } + } + if (f == 1) + cout << "NO" << endl; + else if (isvowel(s[s.size() - 1]) || s[s.size() - 1] == 'n') + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + a[2]++; + if (a[0] + a[1] >= a[2]) { + cout << "0" << endl; + } else { + cout << a[2] - (a[0] + a[1]) << endl; + return 0; + } +} +int t, x; +void nhap() { + cin >> t; +} +void solve() { + for (int i = (1); i <= (t); ++i) { + cin >> x; + if (360 % (180 - x) == 0) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + } +} +int main() { + nhap(); + solve(); +} +int main() { + string s; + cin >> s; + int cnt = 0; + for (int i = 0; i < s.length(); i++) + if (s[i] == '4' || s[i] == '7') cnt++; + if (cnt == 4 || cnt == 7) + cout << "YES\n"; + else + cout << "NO\n"; +} +int cnt(int x) { + int ret = 0; + while (x) { + x /= 10; + ret++; + } + return ret; +} +int main() { + int i, j, l, r; + cin >> l >> r; + if (l == 9 && r == 9) { return cout << 0 << endl, 0; } + int digit = cnt(r); + int x = 1, t = 1, tt; + for (i = 1; i < digit; i++) { + x *= 10; + t *= 10; + } + tt = t; + for (i = digit; i >= 1; i--) { + if (i == digit) { + int tmp; + for (j = 2; j <= 4; j++) { + tmp = (x / t); + tmp++; + tmp *= t; + if (tmp <= r) { + x = tmp; + } else + break; + } + } else { + int tmp; + for (j = 1; j <= 9; j++) { + tmp = (x / t); + tmp++; + tmp *= t; + if (tmp <= r) { + x = tmp; + } else + break; + } + } + t /= 10; + } + if (x < l) x = l; + t = tt; + long long y = 9 - (x / t), xx; + xx = x % t; + t /= 10; + while (t) { + y *= 10; + y += 9 - (xx / t); + xx %= t; + t /= 10; + } + cout << x * y << endl; +} +long a[100000 + 10], vest[100000 + 10], match[100000 + 10], n, m, x, y; +long max(long a, long b) { + if (a >= b) + return a; + else + return b; +} +long bshead(long key) { + long d = 1; + long c = m; + while (d <= c) { + long mid = (d + c) / 2; + if (vest[mid] >= key) + c = mid - 1; + else + d = mid + 1; + } + return d; +} +long bsend(long key) { + long d = 1; + long c = m; + while (d <= c) { + long mid = (d + c) / 2; + if (vest[mid] <= key) + d = mid + 1; + else + c = mid - 1; + } + return c; +} +int main() { + cin >> n >> m >> x >> y; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= m; i++) cin >> vest[i]; + long res = 0; + long neo = 0; + memset(match, 0, sizeof(match)); + for (int i = 1; i <= n; i++) { + long d = bshead(a[i] - x); + long c = bsend(a[i] + y); + if (d > c) continue; + if (neo + 1 < d) neo = d - 1; + if (neo < c) { + neo++; + match[i] = neo; + res++; + } + } + cout << res << "\n"; + for (int i = 1; i <= n; i++) + if (match[i] != 0) cout << i << " " << match[i] << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int l = s.size(); + stack ch; + for (int i = 0; i < l; i++) { + if (ch.empty()) + ch.push(s[i]); + else { + if (ch.top() != s[i]) + ch.pop(); + else + ch.push(s[i]); + } + } + cout << ch.size() << endl; + return 0; +} +unsigned long long n, l, r; +int main() { + cin >> n; + for (unsigned long long i = 1; i <= n; i++) { + cin >> l >> r; + unsigned long long u, v = l, k = 1; + while (v <= r) { + u = v; + while (v & k) k *= 2; + v += k; + } + cout << u << endl; + } + return 0; +} +long long n, p, k = 0; +int main() { + cin >> n >> p; + vector a(n); + for (int i = 0; i < n; ++i) { + string t; + cin >> t; + a[i] = t.length() > 4; + k += a[i]; + } + double ans = 0; + long long sum = 0; + reverse(a.begin(), a.end()); + for (int i = 0; i < n; ++i) { + if (a[i]) { + ans = ans * 2 + 0.5; + sum += ans * p; + } else { + ans *= 2; + sum += ans * p; + } + } + cout << sum << endl; + return 0; +} +int main() { + int t; + cin >> t; + long long int l, v, x, y; + while (t--) { + cin >> l >> v >> x >> y; + long long int count = 0; + long long int total = l / v; + long long int sub1 = y / v; + long long int sub2 = x / v; + count = total - sub1 + sub2; + if (x % v == 0) count--; + cout << count << endl; + } +} +int main() { + int n, res = 0, cur, x, y; + cin >> n; + vector a(n), b(n); + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { cin >> b[i]; } + for (int i = 0; i < n; i++) { + x = 0; + y = 0; + for (int j = i; j < n; j++) { + x |= a[j]; + y |= b[j]; + cur = x + y; + res = max(res, cur); + } + } + cout << res << endl; + return 0; +} +long long MOD = 1000000007; +string yes = "YES\n"; +string no = "NO\n"; +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + long long a, b, c, d; + cin >> a >> b >> c >> d; + long long f1 = max(3 * a / 10, a - (a / 250) * c); + long long f2 = max(3 * b / 10, b - (b / 250) * d); + if (f1 > f2) + cout << "Misha" + << "\n"; + else if (f1 < f2) + cout << "Vasya" + << "\n"; + else + cout << "Tie" + << "\n"; +} +int k, haSh[30]; +string s; +int main() { + cin >> s >> k; + if (k > s.size()) { + cout << "impossible" << endl; + return 0; + } + for (int i = 0; i < s.size(); i++) { + if (!haSh[(s[i] - 'a')]) { + haSh[s[i] - 'a'] = 1; + k--; + } + } + if (k <= 0) { + cout << 0 << endl; + return 0; + } else { + cout << k << endl; + } + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int ar[105], arr[105]; + for (int i = 0; i < n; i++) { cin >> ar[i] >> arr[i]; } + for (int j = 0; j < n; j++) { + for (int k = 0; k < n; k++) { + if (k != j) { + if (ar[j] == arr[k]) { count++; } + } + } + } + cout << count << endl; + return 0; +} +int main() { + long long int s, n, a, b, k, i, d, e; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b >> k; + if (k % 2 == 0) { + d = (k / 2); + s = (a * d) - (b * d); + } else { + d = (k / 2) + 1; + e = (k - d); + s = (a * d) - (b * e); + } + cout << s << endl; + } + return 0; +} +int main() { + int y, k; + cin >> y; + set st; + while (st.size() != 4) { + ++y; + st.clear(); + k = y; + while (k) { + st.insert(k % 10); + k /= 10; + } + } + cout << y << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int k = n - 1; + if (n == 2) + cout << 2 << endl; + else + cout << n - k << endl; +} +int main() { + int n, s; + cin >> n >> s; + vector forward(n + 1, 0); + vector backward(n + 1, 0); + for (int i = 1; i <= n; i++) { cin >> forward[i]; } + for (int i = 1; i <= n; i++) { cin >> backward[i]; } + if (forward[1] == 0) { + cout << "NO" << endl; + } else { + if (forward[s] == 1) { + cout << "YES" << endl; + } else { + if (backward[s] == 1) { + bool availabe = false; + for (int i = s + 1; i <= n; i++) { + if (forward[i] == 1 && backward[i] == 1) { + availabe = true; + break; + } + } + cout << ((availabe) ? "YES" : "NO") << endl; + } else { + cout << "NO" << endl; + } + } + } + return 0; +} +int num[100]; +int main() { + int count = 0; + cin >> count; + for (int i = 0; i < count; i++) { cin >> num[i]; } + int max_tmp = -1, max_sum = 0; + for (int i = 0; i < count; i++) { + int sum = num[i], tmp = num[i]; + if (tmp > max_tmp) { max_tmp = tmp; } + for (int j = 1; i + j < count; j++) { + tmp ^= num[i + j]; + if (tmp > max_tmp) { max_tmp = tmp; } + } + } + cout << max_tmp << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + long long max = 0; + long long sum = 0; + int a[101]; + for (int i = 0; i < n; ++i) { cin >> a[i]; } + for (int i = 0; i < n; ++i) { + sum = a[i]; + long long total = sum; + for (int j = i + 1; j < n; ++j) { + sum = a[j] ^ sum; + if (sum > total) total = sum; + } + if (total > max) max = total; + } + cout << max << endl; + } + return 0; +} +int main() { + int a, b, c, n, i, j, t = 0; + cin >> a >> b >> c >> n; + int s[n + 1]; + for (i = 0; i < n; i++) { cin >> s[i]; } + for (j = 0; j < n; j++) { + if (s[j] > b && s[j] < c) { t++; } + } + cout << t << endl; +} +int main() { + int n, k, w; + cin >> k >> w >> n; + int amt = n * (n + 1) * 0.5 * k; + if ((amt - w) < 0) { + cout << "0"; + } else { + cout << amt - w; + } + cout << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long turnsDone = n / k; + int remaining = n % k; + if (turnsDone % 2 == 1) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n + 5]; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long int c = 0; + for (int i = 1; i < n; i++) { + c += a[i]; + cout << c << "\n"; + long long int j = 1; + while ((i - 1) + j * 2 < n) j *= 2; + a[i + j] += a[i]; + } +} +int main() { + long long n, m; + cin >> n >> m; + char arena[52][52]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> arena[i][j]; } + } + int tipe = 0; + for (int i = 0; i < n; i++) { + if (arena[i][0] == '1' || arena[i][m - 1] == '1') { + tipe = 1; + break; + } + } + for (int i = 0; i < m; i++) { + if (arena[0][i] == '1' || arena[n - 1][i] == '1') { + tipe = 1; + break; + } + } + if (tipe == 0) { + cout << 4 << endl; + } else + cout << 2 << endl; +} +int main() { + int n; + cin >> n; + int a[n]; + priority_queue p; + int maxi = -1; + cin >> a[0]; + for (int i = 1; i < n; i++) { + cin >> a[i]; + p.push(a[i]); + maxi = max(maxi, a[i]); + } + int ans = 0; + while (1) { + int d = p.top(); + if (a[0] > d) { + cout << ans << endl; + return 0; + } + ans++; + a[0]++; + p.pop(); + p.push(d - 1); + } +} +int main() { + int n, m, i, j; + while (cin >> n >> m) { + if (n < 3 || m < 3 || n > 50 || n > 50 || n % 2 == 0) break; + for (i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (j = 1; j <= m; j++) cout << '#'; + } else { + if (i % 4 == 2) { + for (j = 1; j < m; j++) cout << '.'; + cout << '#'; + } else if (i % 4 == 0) { + cout << '#'; + for (j = 2; j <= m; j++) cout << '.'; + } + } + cout << endl; + } + } +} +int arr[1000000 + 5]; +void sieve() { + arr[1] = 1; + for (int i = 2; i * i <= 1000000; i++) { + if (arr[i] == 0) { + for (int j = i * i; j <= 1000000; j += i) { arr[j] = 1; } + } + } +} +int main() { + sieve(); + int a, b; + cin >> a >> b; + if (arr[b] == 0) { + int flag = 1; + for (int i = a + 1; i < b; i++) { + if (arr[i] == 0) { + flag = 0; + cout << "NO" << endl; + break; + } + } + if (flag) cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n, k; + cin >> n >> k; + char v[n]; + for (int i = int(0); i < int(n); i++) { cin >> v[i]; } + sort(v, v + n); + char ult = 90; + int tam = 0; + int res = 0; + for (int i = int(0); i < int(n); i++) { + if (v[i] >= ult + 2) { + ult = v[i]; + tam++; + res += v[i] - 96; + if (tam >= k) { + cout << res << endl; + return 0; + } + } + } + cout << "-1" << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + while (c > 0) { + if (a < b) { + a++; + } else { + b++; + } + c--; + } + cout << min(a, b) * 2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + set s; + for (int i = 0; i < n; ++i) { + int a; + cin >> a; + s.insert(a); + } + cout << (s.find(1) != s.end() ? -1 : 1) << endl; + return 0; +} +int main() { + int k; + cin >> k; + int arr[12]; + int n = 0; + int total = 0; + for (int i = 0; i < 12; i++) cin >> arr[i]; + for (int x = 0; x < 12; x++) { + for (int y = 0; y < 11; y++) { + if (arr[y] < arr[y + 1]) { + int temp = arr[y]; + arr[y] = arr[y + 1]; + arr[y + 1] = temp; + } + } + } + while (k > total && n < 12) { + total += arr[n]; + n++; + } + if (total >= k) + cout << n << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int *elements = new int[n]; + for (int i = 0; i < n; i++) { cin >> elements[i]; } + int count = 0; + for (int i = 1; i < n - 1; i++) { + int prev = elements[i - 1]; + int cur = elements[i]; + int next = elements[i + 1]; + if ((cur < prev && cur < next) || (cur > prev && cur > next)) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + long long sum = accumulate(a.begin(), a.end(), 0); + long long v = 0; + for (int i = 0; i < n; i++) { + v += a[i]; + if (2 * v >= sum) { + cout << i + 1 << endl; + break; + } + } +} +int main() { + int a, b, d = 1, i = 1, c; + cin >> a >> b; + c = a; + if (a % 10 != 0) { + d = (a % 10) - b; + while (d != 0) { + i++; + a = c * i; + if (a % 10 == 0) break; + d = (a % 10) - b; + } + } + cout << i << endl; +} +int x; +int main() { + string p = "hello"; + char c[10001]; + gets(c); + for (int i = 0; i < strlen(c); i++) + if (c[i] == p[x]) x++; + if (x >= 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +long long int mod = 1000000007; +long long int MOD = 998244353; +int main() { + int n, p; + cin >> n >> p; + string s, s1; + cin >> s; + s1 = s; + char c = 'a' + p - 1; + sort(s1.begin(), s1.end()); + reverse(s1.begin(), s1.end()); + if (s1 == s && s[0] == c) { + cout << "NO" << endl; + return 0; + } + int fl = 0; + for (int i = n - 1; i >= 0; i--) { + for (char x = s[i] + 1; x <= c; x++) { + if ((i - 1 < 0 || s[i - 1] != x) && (i - 2 < 0 || s[i - 2] != x)) { + s[i] = x; + fl = 1; + break; + } + } + if (fl) { + char tmp = 'a'; + for (int j = i + 1; j < n; j++) { + for (char x = 'a'; x <= c; x++) { + if ((j - 1 < 0 || s[j - 1] != x) && (j - 2 < 0 || s[j - 2] != x)) { + s[j] = x; + break; + } + } + } + break; + } + } + if (fl) { + cout << s << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int n; +const int MAXN = 200005; +int p[MAXN]; +bool vis[MAXN]; +void dfs(int idx) { + vis[idx] = true; + if (!vis[p[idx]]) dfs(p[idx]); +} +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> p[i]; + int counter = 0; + for (int i = 1; i <= n; i++) { + int b; + cin >> b; + if (b == 1) counter++; + } + int cycle = 0; + for (int i = 1; i <= n; i++) + if (!vis[i]) { + dfs(i); + cycle++; + } + if (cycle == 1) + cout << 1 - counter % 2 << "\n"; + else + cout << cycle + 1 - counter % 2 << "\n"; + return 0; +} +int main() { + long long int n, x = 0; + cin >> n; + x = n % 10; + if (x > 5) n = n - x + 10; + if (x <= 5) n = n - x; + cout << n << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if ((n / k) % 2 != 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int x[3][3]; + bool y[3][3]; + for (int row = 0; row < 3; ++row) { + for (int col = 0; col < 3; ++col) { y[row][col] = true; } + } + for (int row = 0; row < 3; ++row) { + for (int col = 0; col < 3; ++col) { cin >> x[row][col]; } + } + if (x[0][0] % 2 != 0) { + y[0][1] = !y[0][1]; + y[0][0] = !y[0][0]; + y[1][0] = !y[1][0]; + } + if (x[0][1] % 2 != 0) { + y[0][1] = !y[0][1]; + y[0][0] = !y[0][0]; + y[1][1] = !y[1][1]; + y[0][2] = !y[0][2]; + } + if (x[0][2] % 2 != 0) { + y[0][1] = !y[0][1]; + y[0][2] = !y[0][2]; + y[1][2] = !y[1][2]; + } + if (x[1][0] % 2 != 0) { + y[0][0] = !y[0][0]; + y[1][1] = !y[1][1]; + y[2][0] = !y[2][0]; + y[1][0] = !y[1][0]; + } + if (x[1][1] % 2 != 0) { + y[1][1] = !y[1][1]; + y[0][1] = !y[0][1]; + y[1][0] = !y[1][0]; + y[1][2] = !y[1][2]; + y[2][1] = !y[2][1]; + } + if (x[1][2] % 2 != 0) { + y[0][2] = !y[0][2]; + y[1][1] = !y[1][1]; + y[2][2] = !y[2][2]; + y[1][2] = !y[1][2]; + } + if (x[2][0] % 2 != 0) { + y[1][0] = !y[1][0]; + y[2][1] = !y[2][1]; + y[2][0] = !y[2][0]; + } + if (x[2][1] % 2 != 0) { + y[2][0] = !y[2][0]; + y[1][1] = !y[1][1]; + y[2][2] = !y[2][2]; + y[2][1] = !y[2][1]; + } + if (x[2][2] % 2 != 0) { + y[2][1] = !y[2][1]; + y[1][2] = !y[1][2]; + y[2][2] = !y[2][2]; + } + for (int row = 0; row < 3; ++row) { + for (int col = 0; col < 3; ++col) { + if (y[row][col]) + cout << 1; + else + cout << 0; + } + cout << endl; + } + return 0; +} +int main() { + char ch; + cin >> ch; + string check = "qwertyuiopasdfghjkl;zxcvbnm,./"; + int move = 1; + if (ch == 'R') { move = -1; } + string str; + cin >> str; + for (int i = 0; i < str.length(); i++) { cout << check[(check.find(str[i]) + move + check.length()) % check.length()]; } + cout << endl; + return 0; +} +const long long int MAX = 1000001; +int counting[MAX] = {0}; +int in[MAX] = {0}; +int out[MAX] = {0}; +vector p; +void primeFactors(int n) { + while (n % 2 == 0) { + p.push_back(2); + n = n / 2; + } + for (int i = 3; i <= sqrt(n); i = i + 2) { + while (n % i == 0) { + p.push_back(i); + n = n / i; + } + } + if (n > 2) p.push_back(n); +} +int main() { + int n, k, a = 1; + cin >> n >> k; + primeFactors(n); + int s = p.size(); + if (k > s) { + cout << -1 << endl; + return 0; + } + for (int i = 0; i < k - 1; i++) { cout << p[i] << " "; } + for (int i = k - 1; i < s; i++) a *= p[i]; + cout << a << endl; + return 0; +} +int main() { + int arra[100], sum = 0, key = 0, countt = 0, n, k, sum2, minn, maxx, result; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> k; + sum = sum + k; + arra[i] = k; + } + cin >> minn >> maxx; + for (int i = 0; i < n; i++) { + key = key + arra[i]; + sum2 = sum - key; + if (key >= minn && key <= maxx & sum2 >= minn && sum2 <= maxx) { + result = i + 2; + countt = 1; + break; + } + } + if (countt == 1) { + cout << result << endl; + } else { + cout << 0 << endl; + } + return 0; +} +const long long mxn = 1e5 + 7; +int main() { + long long n, m, cnt = 1; + char s[101][101]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + s[i][j] = '#'; + } else { + if (j >= 1 && j <= m) { s[i][j] = '.'; } + if (cnt % 2 != 0 && j == m) { s[i][j] = '#'; } + if (cnt % 2 == 0 && j == 1) { s[i][j] = '#'; } + if (j == m) { cnt++; } + } + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cout << s[i][j]; } + cout << endl; + } +} +int main() { + long long int n, t; + long long int sum = 0; + vector numbers; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> t; + sum += t; + numbers.push_back(t); + } + sort(numbers.begin(), numbers.end()); + long long int score = sum; + for (int j = 0; j < n - 1; j++) { + score += sum; + sum -= numbers[j]; + } + cout << score << endl; + return 0; +} +int getDis(string a, string b) { + if (a.size() != b.size()) return -1; + int dis = 0; + for (int i = 0; i < a.size(); i++) + if (a[i] != b[i]) dis++; + return dis; +} +int main() { + int n, cost = 0, ans[110]; + string a[110], b[110]; + bool flag_a[110], flag_b[110]; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + sort(a + 1, a + n + 1); + sort(b + 1, b + n + 1); + memset(flag_a, 1, sizeof(flag_a)); + memset(flag_b, 1, sizeof(flag_b)); + int Dis[110][110]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) Dis[i][j] = getDis(a[i], b[j]); + } + for (int t = 1; t <= n; t++) { + int mindis = 100, minid_a = 0, minid_b = 0; + for (int i = 1; i <= n; i++) { + if (flag_a[i]) + for (int j = 1; j <= n; j++) { + if (flag_b[j]) { + int dis = Dis[i][j]; + if (dis >= 0 && dis < mindis) { mindis = dis, minid_a = i, minid_b = j; } + } + } + } + flag_a[minid_a] = 0, flag_b[minid_b] = 0; + cost += mindis; + } + cout << cost << endl; + return 0; +} +int y[10]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> y[i]; + sort(y + 1, y + n + 1); + cout << y[n / 2 + 1] << endl; + return 0; +} +int main() { + long long n, childs = 0, x, packs = 0; + char type; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> type >> packs; + if (type == '+') + x += packs; + else { + if (packs <= x) + x -= packs; + else + childs++; + } + } + packs = x; + cout << packs << " " << childs << endl; +} +int main() { + int n, a, mi = 123456, ma = -1, ans = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a; + if (a < mi) { + mi = a; + ans++; + } + if (a > ma) { + ma = a; + ans++; + } + } + cout << ans - 2 << endl; + return 0; +} +long long n; +long long inside(long long x, long long y) { + if (sqrt(x * x + y * y) <= n) return 1; + return 0; +} +int main() { + long long num; + cin >> n; + num = n / 2; + while ((num + 1) * sqrt(2.0) <= n) num++; + if (n == 1) + cout << 4 << endl; + else if (n == 0) + cout << 1 << endl; + else if (inside(num, num + 1)) + cout << 8 * num + 4 << endl; + else if (!inside(num, num + 1)) + cout << 8 * num << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + while (n--) { + string s; + cin >> s; + if (s == "Tetrahedron") + cnt += 4; + else if (s == "Cube") + cnt += 6; + else if (s == "Octahedron") + cnt += 8; + else if (s == "Dodecahedron") + cnt += 12; + else + cnt += 20; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { cout << n / 2 + 1 << endl; } + return 0; +} +int main() { + int p, n; + cin >> p >> n; + int hash[305]; + memset(hash, 0, sizeof(hash)); + int x; + for (int i = 0; i < n; i++) { + cin >> x; + x = x % p; + if (hash[x]) { + cout << ++i << endl; + return 0; + } + hash[x]++; + } + cout << -1 << endl; + return 0; +} +string s; +int main() { + int t, n; + cin >> t; + while (t--) { + cin >> n; + cin >> s; + if (int(s.length()) == 2) { + string::iterator i = s.begin(); + if (*i >= *(i + 1)) + cout << "NO" << endl; + else { + cout << "YES" << endl << 2 << endl; + cout << *i << " " << *(i + 1) << endl; + } + } else { + cout << "YES" << endl << 2 << endl; + cout << s[0] << " " << s.substr(1, s.length() - 1) << endl; + } + } + return 0; +} +const double pi = 3.14159265359; +const long long MOD = 1000 * 1000 * 1000 + 7; +const int N = 200 * 1000 + 10; +int main() { + int a, b; + cin >> a >> b; + int aa = a * a, bb = b * b; + vector as; + vector bs; + for (int i = 1; i < aa; i++) { + int sq = sqrt(aa - i * i); + if (sq * sq + i * i == aa) as.push_back(i); + } + for (int i = 1; i < bb; i++) { + int sq = sqrt(bb - i * i); + if (sq * sq + i * i == bb) bs.push_back(i); + } + for (int i = 0; i < as.size(); i++) { + for (int j = 0; j < bs.size(); j++) { + int xa = as[i]; + int ya = sqrt(aa - xa * xa); + int xb = bs[j]; + int yb = sqrt(bb - xb * xb); + if ((xb - xa) * (xb - xa) + (ya + yb) * (ya + yb) == aa + bb && xb != xa) { + cout << "YES\n"; + cout << xa << " " << ya << '\n'; + cout << xb << " " << -yb << '\n'; + cout << 0 << " " << 0 << '\n'; + return 0; + } + } + } + cout << "NO\n"; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + if (a < c || b < c) { + cout << -1 << endl; + return 0; + } + int all = a + b - c; + if (all <= n - 1) { + cout << n - all << endl; + } else { + cout << -1 << endl; + } + return 0; +} +long long INF = (1e9); +int n; +long long p[100]; +void init() { + p[0] = 1; + for (int i = 1; i <= 64; i++) { p[i] = p[i - 1] * 2; } +} +long long solve(long long L, long long R) { + long long r = R; + long long Lb[100], Rb[100]; + long long Ln = 0, Rn = 0; + while (L) { + Lb[++Ln] = L % 2; + L /= 2; + } + while (R) { + Rb[++Rn] = R % 2; + R /= 2; + } + if (Rn > Ln) { + if (p[Rn] - 1 == r) { + return r; + } else { + return p[Rn - 1] - 1; + } + } else { + long long ans = 0; + for (int i = Rn; i >= 1; i--) { + if (Lb[i] == 1 && Rb[i] == 1) { ans += p[i - 1]; } + if (Rb[i] == 1 && Lb[i] == 0) { + int flag = 1; + for (int j = i; j >= 1; j--) { + if (Rb[j] == 0) { + flag = 0; + break; + } + } + if (flag) { + ans += p[i] - 1; + } else { + ans += p[i - 1] - 1; + } + break; + } + } + return ans; + } +} +int main() { + cin >> n; + init(); + for (int i = 1; i <= n; i++) { + long long L, R; + cin >> L >> R; + cout << solve(L, R) << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector f; + int on = n; + for (int i = 2; i * i <= n; i++) { + while (n % i == 0) { + f.push_back(i); + n /= i; + } + } + if (n > 1) f.push_back(n); + if (f.size() < k) + cout << -1 << endl; + else { + int acum = 1; + for (int i = 0; i < k - 1; i++) { + cout << f[i] << " "; + acum *= f[i]; + } + cout << on / acum << endl; + } + return 0; +} +int main() { + long long t, s, a, b, c, x, ans; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + x = s / c; + ans = x + (x / a) * b; + cout << ans << "\n"; + } +} +const double PI = acos(-1); +const int INF = 1000 * 1000 * 1000 + 7; +const long long LINF = INF * (long long)INF; +string s; +void no() { + cout << "Too weak" << endl; + exit(0); +} +bool hasLarge(const string &s) { + for (int i = (0); i < ((int)s.size()); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') return true; + } + return false; +} +bool hasSmall(const string &s) { + for (int i = (0); i < ((int)s.size()); i++) { + if (s[i] >= 'a' && s[i] <= 'z') return true; + } + return false; +} +bool hasDigit(const string &s) { + for (int i = (0); i < ((int)s.size()); i++) { + if (s[i] >= '0' && s[i] <= '9') return true; + } + return false; +} +int main() { + cin >> s; + if ((int)s.size() < 5) no(); + if (!hasLarge(s) || !hasSmall(s) || !hasDigit(s)) no(); + cout << "Correct" << endl; + return 0; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int a; + cin >> a; + int ans = 1; + while (a != 1) { + ans++; + a >>= 1; + } + cout << ans << endl; +} +int main() { + int i, j, n; + cin >> n; + for (i = 1; i <= ceil(n / 2.0); i++) { + for (j = 1; j <= n / 2 - i + 1; j++) cout << "*"; + for (j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (j = 1; j <= n / 2 - i + 1; j++) cout << "*"; + cout << endl; + } + for (i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (j = 1; j <= n - i * 2; j++) cout << "D"; + for (j = 1; j <= i; j++) cout << "*"; + cout << endl; + } + return 0; +} +int main() { + int a[1005], n, k; + while (cin >> n) { + k = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n - 1; i++) + if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]) k++; + cout << k << endl; + } + return 0; +} +int main() { + int n, m, l, r; + char c1, c2; + string s; + cin >> n >> m >> s; + for (int i = 0; i < int(m); i++) { + cin >> l >> r >> c1 >> c2; + l--; + for (int j = int(l); j < int(r); j++) { + if (s[j] == c1) s[j] = c2; + } + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + set s; + for (int i = n + 1; i <= 9012; i++) { + if (i % 100 == 0) { continue; } + int a = i / 1000; + s.insert(a); + int b = (i / 100) % 10; + s.insert(b); + int c = (i / 10) % 10; + s.insert(c); + int d = i % 10; + s.insert(d); + if (s.size() == 4) { + cout << i << endl; + break; + } else { + s.clear(); + } + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int i = 0; + while (i != a.length() && (a[i] == b[i] || abs(a[i] - b[i]) == 32)) i++; + if (i == a.length()) + cout << 0 << '\n'; + else if (tolower(a[i]) - tolower(b[i]) < 0) + cout << -1 << '\n'; + else + cout << 1 << '\n'; +} +const long long mod = 1e9 + 7; +int f(int x, int y) { + for (int i = 0; i < 3; ++i) { + if (i + 1 == x or i + 1 == y) continue; + return i + 1; + } + return 1; +} +int main() { + int n; + cin >> n; + int x = 3; + while (n--) { + int temp; + cin >> temp; + if (temp == x) { + cout << "NO" << '\n'; + ; + return 0; + } + x = f(temp, x); + } + cout << "YES" << '\n'; + ; + return 0; +} +int fa[202002]; +int sum[202002]; +int c[202002]; +int max(int a, int b) { + if (a > b) + return a; + else + return b; +} +int findfa(int x) { + if (fa[x] == x) + return x; + else + return findfa(fa[x]); +} +void U(int x, int y) { + int rx = findfa(x); + int ry = findfa(y); + if (rx != ry) { + fa[rx] = ry; + sum[ry] += sum[rx]; + } +} +bool vis[202002]; +vector vec; +int main() { + int n, m, k; + cin >> n >> m >> k; + vec.clear(); + for (int i = 0; i <= n; i++) { + fa[i] = i; + sum[i] = 1; + } + for (int i = 0; i < k; i++) cin >> c[i]; + int x, y; + for (int i = 0; i < m; i++) { + cin >> x >> y; + U(x, y); + } + memset(vis, 0, sizeof(vis)); + for (int i = 0; i < k; i++) vis[findfa(c[i])] = 1; + int MAX = -1; + long long ans = 0; + for (int i = 1; i <= n; i++) { + if (fa[i] == i) { + if (vis[i] == 1) + MAX = max(MAX, sum[i]); + else + vec.push_back(sum[i]); + ans += sum[i] * (sum[i] - 1) / 2; + } + } + int len = vec.size(); + for (int i = 0; i < len; i++) { + for (int j = i + 1; j < len; j++) { ans += vec[i] * vec[j]; } + ans += vec[i] * MAX; + } + ans = ans - m; + if (ans > 0) + cout << ans << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + cout << "Karen" + << "\n"; + return 0; +} +const int maxn = 1e7 + 6; +const int modn = 1e9 + 7; +int main() { + int n, a, x, cnt = 0; + priority_queue pq; + cin >> n >> a; + for (int i = 0; i < n - 1; i++) { + cin >> x; + pq.push(x); + } + while (a <= pq.top()) { + x = pq.top(); + pq.pop(); + a++; + cnt++; + x--; + pq.push(x); + } + cout << cnt << endl; +} +int i; +bool allAreSame(string S) { + bool flag = true; + i = 1; + while (S[i]) { + if (S[i] == '+') { + i++; + } else if (S[0] == S[i]) { + i++; + } else { + flag = false; + return flag; + } + } + return flag; +} +int main() { + string S, S1 = "", S2 = "", S3 = ""; + cin >> S; + if (S.length() == 1) { + cout << S << endl; + return 0; + } + if (allAreSame(S)) { + cout << S[0]; + i = 1; + while (S[i]) { + if (S[i] != '+') { cout << "+" << S[i]; } + i++; + } + cout << endl; + return 0; + } + for (i = 0; i < S.length(); i++) { + if (S[i] == '1') + S1 += S[i]; + else if (S[i] == '2') + S2 += S[i]; + else if (S[i] == '3') + S3 += S[i]; + } + i = 0; + while (S1[i]) { + cout << S1[i]; + i++; + if (S1[i]) cout << "+"; + } + i = 0; + while (S2[i]) { + if (S1[0] == '1') { + cout << "+" << S2[i]; + } else + cout << S2[i]; + i++; + } + i = 0; + while (S3[i]) { + if (S1[0] == '1' || S2[0] == '2') + cout << "+" << S3[i]; + else + cout << S3[i]; + i++; + } + cout << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + int ans = 0; + for (int i = 0; i < n; i++) { + ans++; + if (a[i] == '0') break; + } + cout << ans << endl; + return 0; +} +int main() { + long long a, b, c, n; + cin >> n; + while (n--) { + cin >> a >> b >> c; + if (c % 2 == 0) { + cout << (a * (c / 2) - b * (c / 2)) << endl; + } else { + cout << (a * ((c / 2) + 1)) - (b * (c / 2)) << endl; + } + } + return 0; +} +const int maxn = 5e5 + 5; +const int inf = 0x3f3f3f3f; +const long long INF = 0x3f3f3f3f3f3f3f3f; +int main() { + int n; + cin >> n; + int x, y; + for (int i = 1; i * i <= n; i++) { + if (n % i == 0) { + x = i; + y = n / i; + } + } + cout << x << " " << y << endl; +} +int main() { + string str; + cin >> str; + map m; + for (int i = 0; i < 10; i++) { + string s; + cin >> s; + m[s] = i; + } + string ans = ""; + for (int i = 0; i < str.size(); i += 10) ans += char(m[str.substr(i, 10)] + '0'); + cout << ans << endl; + return 0; +} +int main() { + int n, i, cnt, j, m, l, r; + cin >> n >> m; + cnt = 0; + string s; + char c1, c2; + cin >> s; + for (i = 0; i < m; i++) { + cin >> l >> r >> c1 >> c2; + for (j = l - 1; j < r; j++) { + if (s[j] == c1) s[j] = c2; + } + } + cout << s << endl; +} +int main() { + int n, k, i, ti, tg; + string str; + cin >> n >> k; + cin >> str; + for (i = 0; i < n; i++) { + if (str[i] == 'T') { + ti = i; + } else if (str[i] == 'G') { + tg = i; + } + } + if (tg < ti) { + for (i = tg; i < n; i += k) { + if (i == ti) { + cout << "YES\n"; + return 0; + } else if (str[i] == '#') { + cout << "NO\n"; + return 0; + } + } + cout << "NO\n"; + } else if (tg > ti) { + for (i = tg; i >= 0; i -= k) { + if (i == ti) { + cout << "YES\n"; + return 0; + } else if (str[i] == '#') { + cout << "NO\n"; + return 0; + } + } + cout << "NO\n"; + } else { + cout << "YES\n"; + } + return 0; +} +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, -1, 0, 1}; +int main() { + long long a, b; + cin >> a >> b; + long long Min, s; + if (a > b) { + Min = min(a, b); + s = (a - Min) / 2; + cout << Min << " " << s << endl; + } else { + Min = min(a, b); + s = (b - Min) / 2; + cout << Min << " " << s << endl; + } +} +int main() { + int m, d; + cin >> m >> d; + if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { + if (d < 6) { + cout << "5" << endl; + } else { + cout << "6" << endl; + } + } else if (m == 2) { + if (d == 1) { + cout << "4" << endl; + } else { + cout << "5" << endl; + } + } else { + if (d == 7) { + cout << "6" << endl; + } else { + cout << "5" << endl; + } + } + return 0; +} +bool Lucky(int n) { + if (n == 0) return false; + int digit; + while (n > 0) { + digit = n % 10; + if (digit != 4 && digit != 7) return false; + n = n / 10; + } + return true; +} +int main() { + long long int num; + long long int count = 0; + int d; + cin >> num; + while (num > 0) { + d = num % 10; + if (d == 4 || d == 7) count++; + num = num / 10; + } + if (Lucky(count)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int a[150], dp[5100]; +int main() { + int i, j, n, len, ans, flag, t; + while (cin >> n) { + memset(dp, 0, sizeof(dp)); + for (i = 0, flag = 0; i < n; i++) { + cin >> a[i]; + dp[i] = a[i]; + len = i; + if (flag < dp[i]) flag = dp[i]; + } + for (i = 0; i < n - 1; i++) + for (j = i + 1, ans = a[i], t = len + 1; j < n; j++) { + ans ^= a[j]; + dp[t] = ans; + if (dp[t] > flag) flag = dp[t]; + t++; + } + cout << flag << endl; + } +} +int main() { + int a, b, r; + cin >> a >> b >> r; + if (a >= b) { + if (2 * r <= b) + cout << "First\n"; + else + cout << "Second\n"; + } else { + if (2 * r <= a) + cout << "First\n"; + else + cout << "Second\n"; + } + return 0; +} +int main() { + long long n, m, i, j, k; + cin >> n; + k = 3; + while (1) { + if (n % k != 0) { + m = (n / k) + 1; + break; + } + k *= 3; + } + cout << m << endl; +} +int main() { + int n, l, r, Ql, Qr; + cin >> n >> l >> r >> Ql >> Qr; + vector w(n); + int sum = 0; + for (int i = 0; i < n; i++) { + cin >> w[i]; + sum += w[i]; + } + int m = 2147483647; + int sum1, sum2; + sum1 = 0; + sum2 = sum; + for (int i = 0; i <= n; i++) { + int Q; + if (i > n - i) + Q = Ql; + else + Q = Qr; + int add = abs(2 * i - n) > 1 ? abs(abs(2 * i - n) - 1) * Q : 0; + int newM = sum1 * l + sum2 * r + add; + m = min(m, newM); + if (i != n) { + sum1 += w[i]; + sum2 -= w[i]; + } + } + cout << m << endl; + return 0; +} +int main() { + int n, k, c, ans; + cin >> n >> k; + c = 40 * (240 - k) + 25; + c = sqrt(c) - 5; + ans = c / 10; + if (ans > n) { + cout << n << endl; + } else { + cout << ans << endl; + } +} +int main() { + int n, m, k; + while (cin >> n >> m >> k) { + int nums[n]; + for (int i = 0; i < n; i++) { cin >> nums[i]; } + int flag = 0; + int j = m; + int dis = 0; + if (j < n) { + for (j; j < n; j++) { + if (nums[j] != 0 && nums[j] <= k) { + dis += 10; + flag = 1; + break; + } else + dis += 10; + } + } + int min = 10000; + if (flag) min = dis; + dis = 0; + j = m - 2; + flag = 0; + if (j >= 0) { + for (j; j >= 0; j--) { + if (nums[j] != 0 && nums[j] <= k) { + dis += 10; + flag = 1; + break; + } else { + dis += 10; + } + } + } + if (dis > 0 && flag) min = min < dis ? min : dis; + cout << min << endl; + } +} +const int INF = (int)1e9; +const int mod = (int)1e9 + 7; +const int MAXN = (int)1e3 + 5; +int arr[MAXN]; +long long fact[MAXN], inv[MAXN]; +long long binPow(long long a, int n) { + long long res = 1; + while (n) { + if (n % 2 == 1) res = (res * a) % mod; + a = a * a; + a = a % mod; + n = n / 2; + } + return res; +} +int main() { + int k; + cin >> k; + for (int i = 1; i <= k; i++) cin >> arr[i]; + long long mul = 1; + for (int i = 1; i <= 1000; i++) { + mul = (mul * i) % mod; + fact[i] = mul; + inv[i] = binPow(fact[i], mod - 2); + } + inv[0] = 1; + long long ans = 1; + long long sum = 0; + for (int i = 1; i <= k; i++) { + int a = arr[i]; + a--; + for (int j = 0; j < a; j++) { + ans = (ans * (sum + 1)) % mod; + sum++; + } + ans = ans * inv[a]; + ans = ans % mod; + sum = sum + 1; + } + cout << ans << '\n'; +} +int main() { + long long a, b, ans; + cin >> a >> b; + if (a >= 27) + ans = b; + else + ans = (b & ((1 << (a)) - 1)); + cout << ans << '\n'; + return 0; +} +const int maxn = 100000 + 5; +char s[maxn], ss; +int a[maxn]; +int dp[maxn]; +int ans; +int res; +int main() { + int n, m; + cin >> n >> m; + if ((min(n, m)) & 1) + cout << "Akshat" << endl; + else + cout << "Malvika" << endl; + return 0; +} +int a[1000]; +int main() { + int n; + cin >> n; + for (int x, y, s, i = 1; i <= n; i++) { + s = 0; + cin >> x >> y; + while (x > 0 && y > 0) { + if (x > y) { + s += x / y; + x = (x % y); + } else { + s += y / x; + y = (y % x); + } + if (x == y) { + s++; + break; + } + } + a[i] = s; + } + for (int i = 1; i <= n; i++) cout << a[i] << endl; +} +int main() { + int n = 0, m = 0; + while (cin >> n >> m) { + char a[55][55] = {'0'}; + memset(a, '#', sizeof(a)); + for (int i = 1; i <= n; i += 4) + for (int j = 0; j < m - 1; j++) a[i][j] = '.'; + for (int i = 3; i <= n; i += 4) + for (int j = 1; j < m; j++) a[i][j] = '.'; + for (int j = 0; j < n; j++) { + for (int i = 0; i < m; i++) cout << a[j][i]; + cout << endl; + } + } +} +int main() { + int s, v1, v2, t1, t2, p1, p2; + cin >> s >> v1 >> v2 >> t1 >> t2; + p1 = (s * v1) + (t1 * 2); + p2 = (s * v2) + (t2 * 2); + if (p1 < p2) + cout << "First" << endl; + else if (p1 > p2) + cout << "Second" << endl; + else + cout << "Friendship" << endl; + return 0; +} +int main() { + int w, h, k, value = 0; + cin >> w >> h >> k; + int deck = 0, it = 2; + for (int i = 1; i <= k; i++) { + value = (((h - deck) * 2) + ((w - it) * 2)) + value; + deck = deck + 4; + it = it + 4; + } + cout << value << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int ans; + if (a > b) { + int x = a; + a = b; + b = x; + } + ans = a * 2; + b = b - a; + while ((c > 0) && (b > 0)) { + ans += 2; + b--; + c--; + } + ans = ans + (c / 2) * 2; + cout << ans << endl; +} +int q; +map, long long> m; +long long get(long long u, long long v) { + set p; + while (u != 0) { + p.insert(u); + u /= 2; + } + while (v != 0) { + if (p.find(v) != p.end()) return v; + v /= 2; + } +} +void dfs(long long u, long long v, long long w) { + while (v / 2 >= u) { + if (m[make_pair(v / 2, v)]) + m[make_pair(v / 2, v)] += w; + else + m[make_pair(v / 2, v)] = w; + v /= 2; + } +} +long long dfs2(long long u, long long v) { + long long ans = 0; + while (v / 2 >= u) { + ans += m[make_pair(v / 2, v)]; + v /= 2; + } + return ans; +} +int main() { + cin >> q; + while (q--) { + int o; + cin >> o; + if (o == 1) { + long long u, v, w; + cin >> u >> v >> w; + long long p = get(u, v); + dfs(p, u, w); + dfs(p, v, w); + } else { + long long u, v; + cin >> u >> v; + long long p = get(u, v); + cout << dfs2(p, u) + dfs2(p, v) << endl; + } + } +} +int main() { + long long int n; + cin >> n; + if (n % 2 == 0) { + cout << n / 2 << endl; + } else { + long long int ans = (n - 1) / 2; + cout << -1 - ans << endl; + } + return 0; +} +int main() { + string a = "hello"; + string x; + cin >> x; + int l = x.length(); + int j = 0; + int i, c = 0; + for (i = 0; i < l; i++) { + if (x[i] == a[j]) { + j++; + c++; + } + } + if (c == 5) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int t, a; + cin >> t; + for (; t != 0; t--) { + cin >> a; + if (360 % (180 - a) == 0) + cout << "YES\n"; + else + cout << "NO\n"; + } + return 0; +} +int main() { + int n, r; + cin >> n >> r; + int sum = 0; + for (int i = 0; i < n; ++i) { + int input; + cin >> input; + sum += input; + } + int need = abs(sum), count = 0; + for (int i = r; i >= 1; --i) { + if (need < i) continue; + if (need == 0) break; + while (need >= i) { + need -= i; + count++; + } + } + cout << count << endl; + return 0; +} +int T = 1; +void fun(vector &v) { + for (int i = 0; i < v.size(); i++) cout << v[i] << endl; +} +void solve() { + int N; + cin >> N; + string a, b; + vector r, w, m, c; + for (int i = 0; i < N; i++) { + cin >> a >> b; + if (b[0] == 'r') + r.push_back(a); + else if (b[0] == 'w' || b == "child") + w.push_back(a); + else if (b[0] == 'm') + m.push_back(a); + else + c.push_back(a); + } + fun(r); + fun(w); + fun(m); + fun(c); +} +int main() { + while (T--) { solve(); } + return 0; +} +int main() { + long long l, r; + cin >> l >> r; + if (l % 2 == 0 && l + 2 <= r) + cout << l << " " << l + 1 << " " << l + 2 << endl; + else { + if (l + 3 <= r) + cout << l + 1 << " " << l + 2 << " " << l + 3 << endl; + else + cout << -1 << endl; + } + return 0; +} +int main() { + int n, a1, a2, a3, b1, b2, b3; + cin >> n; + cin >> a1 >> b1; + cin >> a2 >> b2; + cin >> a3 >> b3; + int c1, c2, c3; + c1 = n - a2 - a3; + c2 = a2; + c3 = a3; + if (c1 > b1) { + c2 += c1 - b1; + c1 = b1; + if (c2 > b2) { + c3 += c2 - b2; + c2 = b2; + } + } + cout << c1 << ' ' << c2 << ' ' << c3 << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int l[105]; + memset(l, 0, sizeof(l)); + while (n--) { + int t; + cin >> t; + while (t--) { + int x; + cin >> x; + l[x] = 1; + } + } + int flag = 1; + for (int i = 1; i <= m; i++) { + if (l[i] == 0) { + flag = 0; + break; + } + } + if (flag == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int a, b, i, sum = 0, count = 0; + cin >> a >> b; + b = 240 - b; + for (i = 1; i <= a; i++) { + sum += (5 * i); + if (sum <= b) { + count++; + } else { + break; + } + } + cout << count << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector x; + for (int i = 0; i < n; i++) { + int m; + cin >> m; + x.push_back(m); + } + int s, t; + cin >> s >> t; + int count1 = 0, count2 = 0; + s = s + n; + for (int i = s - 1;; i++) { + if (i % n == t - 1) + break; + else + count1 = count1 + x[i % n]; + } + s--; + for (int i = s - 1;; i--) { + if (i % n == t - 1) { + count2 = count2 + x[i % n]; + break; + } else + count2 = count2 + x[i % n]; + } + if (count1 <= count2) { + cout << count1 << endl; + } else + cout << count2 << endl; + return 0; +} +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +int main() { + long long x, y, a, b; + cin >> x >> y >> a >> b; + long long g = gcd(max(x, y), min(x, y)); + long long lcm = (x * y) / g; + long long r = b / lcm; + long long l = (a - 1) / lcm; + cout << r - l << endl; +} +int main() { + int r, c, s; + cin >> r >> c; + for (int i = 1; i <= r; i++) { + if (i % 2 != 0) { + for (int j = 1; j <= c; j++) { cout << "#"; } + cout << endl; + } else { + s = i / 2; + if (s % 2 != 0) { + for (int i = 1; i <= c; i++) { + if (i != c) { + cout << "."; + } else + cout << "#"; + } + cout << endl; + } else { + for (int i = 1; i <= c; i++) { + if (i != 1) { + cout << "."; + } else + cout << "#"; + } + cout << endl; + } + } + } + return 0; +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + if (a + b + c == d + e + f) + cout << "YES" << endl; + else if (a + b + d == c + e + f) + cout << "YES" << endl; + else if (a + b + e == c + d + f) + cout << "YES" << endl; + else if (a + b + f == c + d + e) + cout << "YES" << endl; + else if (a + c + d == b + e + f) + cout << "YES" << endl; + else if (a + c + e == b + d + f) + cout << "YES" << endl; + else if (a + c + f == b + d + e) + cout << "YES" << endl; + else if (a + d + e == b + c + f) + cout << "YES" << endl; + else if (a + d + f == b + c + e) + cout << "YES" << endl; + else if (a + e + f == b + c + d) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int minn(int a, int b, int c, int d) { + a = min(a, b); + c = min(c, d); + return min(a, c); +} +int main() { + int p1, p2, p3, p4, a, b; + while (cin >> p1 >> p2 >> p3 >> p4 >> a >> b) { + if (p1 <= a || p2 <= a || p3 <= a || p4 <= a) { + cout << 0 << endl; + continue; + } + int p = minn(p1, p2, p3, p4); + if (p > b) { + cout << b - a + 1 << endl; + continue; + } + cout << p - a << endl; + } + return 0; +} +int main() { + long long int t, s, a, b, c, num; + cin >> t; + while (t--) { + num = 0; + cin >> s >> a >> b >> c; + num += s / c; + int x = s / a / c; + num += x * b; + cout << num << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int max = 0; + int count = 0; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (i == 0) { + count++; + if (count > max) max = count; + } else { + if (arr[i] >= arr[i - 1]) { + count++; + if (count > max) max = count; + } else { + count = 1; + } + } + } + cout << max << endl; + return 0; +} +int freq[1005]; +int main() { + int n, m, x; + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> x; + freq[x]++; + } + int minimum = 2e9; + for (int i = 1; i <= n; i++) { minimum = min(minimum, freq[i]); } + cout << minimum << endl; +} +void solve() { + int n, m; + cin >> n >> m; + int cnt = 1; + while (m >= cnt) { + m -= cnt; + cnt++; + if (cnt == n + 1) cnt = 1; + } + cout << m << endl; +} +int main() { + solve(); + return 0; +} +bool hari[1000]; +int main() { + int days, range, input, num; + cin >> days >> range >> num; + for (int a = 0; a < num; a++) { + cin >> input; + hari[input] = 1; + } + int count = -1; + int present = 0; + for (int a = 0; a <= days; a++) { + if (hari[a] == 1) { + count = 0; + present++; + } else + count++; + if (count == range) { + count = 0; + present++; + } + } + cout << present << endl; + return 0; +} +int main() { + long long int n, i, count = 0; + char s[3001]; + gets(s); + cout << (26 - 1) * (strlen(s) + 1) + 1 << endl; + return 0; +} +const double pi = 3.14159265359; +const int INF = 0x3f3f3f3f; +int main() { + string s; + cin >> s; + vector nums; + for (int i = 0; i < s.size(); i += 2) nums.push_back(s[i] - 48); + if (nums.size() == 1) { + cout << nums[0] << "\n"; + return 0; + } + sort((nums).begin(), (nums).end()); + for (int i = 0; i <= nums.size() - 2; i++) cout << nums[i] << '+'; + cout << nums[nums.size() - 1] << "\n"; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + cout << (abs(a - b) <= 1 && a + b ? "YES" : "NO") << endl; +} +long long a, b, k; +void solve() { + if (k % 2) + cout << (k - 1) * (a - b) / 2 + a << endl; + else + cout << k * (a - b) / 2 << endl; +} +void run() { + cin >> a >> b >> k; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + run(); + solve(); + } +} +int n; +int main() { + cin >> n; + int ans = 1; + for (int i = 1; i * i <= n; i++) + if (n % i == 0) ans = i; + cout << ans << " " << n / ans << "\n"; + return 0; +} +string a, b; +int main() { + cin >> a; + cin >> b; + int f = 0, s = 0; + for (int i = 0; i < a.length(); i += 2) { + if (a[i] == '8' && b[i] == '[') + f++; + else if (a[i] == '8' && b[i] == '(') + s++; + else if (a[i] == '(' && b[i] == '[') + s++; + else if (a[i] == '(' && b[i] == '8') + f++; + else if (a[i] == '[' && b[i] == '(') + f++; + else if (a[i] == '[' && b[i] == '8') + s++; + } + if (f > s) + cout << "TEAM 1 WINS" << endl; + else if (f < s) + cout << "TEAM 2 WINS" << endl; + else + cout << "TIE" << endl; + return 0; +} +int main() { + int s, n, cn = 0; + cin >> n >> s; + while (s > n) { + s = s - n; + cn++; + } + cout << cn + 1 << endl; + return 0; +} +char s[101][101]; +int main() { + int i, j, k, m, n, p; + cin >> n >> m; + for (i = 1; i <= n; i++) { + string o; + cin >> o; + for (j = 0; j < m; j++) { + if (o[j] == '.') { + if ((i + j) % 2 == 1) + s[i][j] = 'B'; + else + s[i][j] = 'W'; + } + if (o[j] == '-') s[i][j] = '-'; + } + } + for (i = 1; i <= n; i++) { + for (j = 0; j < m; j++) cout << s[i][j]; + cout << endl; + } + return 0; +} +int main() { + int a[1][13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int m, d, sum = 0, po; + cin >> m >> d; + sum = a[0][m]; + sum = a[0][m] - (8 - d); + po = sum % 7; + sum = sum / 7; + if (po) + cout << sum + 2 << endl; + else + cout << sum + 1 << endl; + return 0; +} +int N; +int main() { + cin >> N; + cout << N / 2 + 1 << endl; + return 0; +} +long long a[202000]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= (n << 1); ++i) { cin >> a[i]; } + sort(a + 1, a + 1 + n + n); + long long s = (s, (a[n] - a[1]) * (a[n << 1] - a[n + 1])); + for (int i = 2; i <= n; i++) { s = min(s, (a[n << 1] - a[1]) * (a[n + i - 1] - a[i])); } + cout << s << endl; + return 0; +} +int main() { + int x, y, r; + cin >> x >> y >> r; + if (x < r * 2 || y < r * 2) + cout << "Second\n"; + else + cout << "First\n"; + return 0; +} +string ans, t; +bool res(string s) { + string::iterator st = s.begin(); + string::iterator ed = --s.end(); + for (; st < ed; ++st, --ed) + if (*st != *ed) return false; + return true; +} +void dfs(int dep, string s) { + if (dep > s.size()) { + if (res(t) && t > ans) ans = t; + return; + } + dfs(dep + 1, s); + t += s[dep]; + dfs(dep + 1, s); + t.erase(--t.end()); + return; +} +int main() { + string s; + cin >> s; + dfs(0, s); + cout << ans << endl; + return 0; +} +int main() { + int n, t, k, d; + cin >> n >> t >> k >> d; + int group = n / k; + if (n % k != 0) group++; + int time = (group - 1) * t; + if (time > d) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + char a[100005]; + int b[100005]; + while (cin >> n) { + memset(a, 0, sizeof(a)); + memset(b, 0, sizeof(b)); + cin >> a; + int j = 1, count = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 'B') + b[j]++; + else if (a[i] == 'W' && a[i + 1] == 'B') + j++; + } + for (int i = 1; i <= j; i++) + if (b[i] != 0) count++; + cout << count << endl; + if (count != 0) { + for (int i = 1; i < j; i++) + if (b[i] != 0) cout << b[i] << " "; + cout << b[j] << endl; + } + } + return 0; +} +int main() { + string *a, s; + int n; + cin >> s >> n; + a = new string[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 0; i < n; i++) { + if (a[i].find(s) == 0) { + cout << a[i] << endl; + return 0; + } + } + cout << s << endl; + return 0; +} +int main() { + long n, i, tmp[40], t1 = 1, ans; + double t = 1; + cin >> n; + for (i = 1; i <= 30; i++) { tmp[i] = 5 * pow(2.0, t++) - 5; } + for (i = 1; i <= 30; i++) { + if (n >= tmp[i] && n <= tmp[i + 1]) { + t1 = n - tmp[i]; + break; + } else if (n >= 1 && n <= 5) { + ans = n; + if (ans == 1) + cout << "Sheldon" << endl; + else if (ans == 2) + cout << "Leonard" << endl; + else if (ans == 3) + cout << "Penny" << endl; + else if (ans == 4) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + return 0; + } + } + if (t1 == 0) + ans = 5; + else if (t1 % (long)pow(2, i) == 0) + ans = t1 / (long)pow(2, i); + else + ans = t1 / (long)pow(2, i) + 1; + if (ans == 1) + cout << "Sheldon" << endl; + else if (ans == 2) + cout << "Leonard" << endl; + else if (ans == 3) + cout << "Penny" << endl; + else if (ans == 4) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n), b(n), c(n); + set s; + for (int i = 0; i < (int)n; i++) { + cin >> a[i]; + s.insert(a[i]); + } + for (int i = 0; i < (int)n; i++) { + cin >> b[i]; + s.insert(b[i]); + } + int cnt = 0; + for (int i = 0; i < (int)n; i++) { + if (s.count(c[i])) cnt++; + } + string ans = (cnt % 2) ? "Koyomi" : "Karen"; + cout << ans << endl; + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int temp = __gcd(n, m); + temp = (n * m) / temp; + cout << z / (temp) << endl; + return 0; +} +int main() { + priority_queue q; + int n, x, y, temp = 0, t = 0; + cin >> n >> x; + for (int i = 2; i <= n; i++) { + cin >> y; + if (y >= x) q.push(y); + } + while (!q.empty()) { + t = q.top(); + q.pop(); + if (t >= x) { + t--; + x++; + q.push(t); + temp++; + } + } + cout << temp << endl; + return 0; +} +int n, p; +string str; +int main() { + cin >> n >> p; + cin >> str; + int flag = 1, i; + for (i = n - 1; i >= 0 && flag; i--) { + for (int j = 1; str[i] + j < 'a' + p; j++) { + if (i >= 1 && str[i] + j == str[i - 1]) continue; + if (i >= 2 && str[i] + j == str[i - 2]) continue; + str[i] += j; + flag = 0; + break; + } + } + if (flag) return cout << "NO" << endl && 0; + int dp = 0; + for (i += 2; i < n; i++) { + for (int j = 0; j < p; j++) { + if ('a' + j == str[i - 1]) continue; + if (i >= 2 && 'a' + j == str[i - 2]) continue; + str[i] = 'a' + j; + break; + } + } + cout << str << endl; + return 0; +} +int main() { + int k, n, w, s = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { s += (i * k); } + if (s - n > 0) + cout << s - n << endl; + else + cout << "0" << endl; + return 0; +} +int main() { + long long n; + cin >> n; + int t = n % 10; + if (t >= 6) + n = n - t + 10; + else + n = n - t; + cout << n << endl; +} +int main() { + int n, k; + cin >> n >> k; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int x = 0; + for (int i = 0; i < n; i++) { + if (a[i] <= k) { + x++; + } else + break; + } + for (int i = n - 1; i >= 0; i--) { + if (a[i] <= k) { + x++; + } else + break; + } + if (x > n) + cout << n << endl; + else + cout << x << endl; +} +int main() { + int a[10000]; + for (int i = 0; i < 1001; i++) { a[i] = i * i; } + int b, c[10000]; + cin >> b; + for (int i = 0; i < b; i++) { cin >> c[i]; } + sort(c, c + b); + for (int i = b - 1; i > -1; i--) { + for (int j = 0; j < 1001; j++) { + if (c[i] == a[j]) { goto momo; } + } + cout << c[i] << endl; + return 0; + momo:; + } +} +int main() { + int n, i, j, sum = 0, alexeyI, alexeyJ; + int dryer[101]; + fill_n(dryer, 101, 1); + cin >> n; + cin >> alexeyI >> alexeyJ; + for (int l = 0; l < n - 1; l++) { + cin >> i >> j; + for (int k = i; k < j; k++) { dryer[k] = 0; } + } + for (int k = alexeyI; k < alexeyJ; k++) { sum += dryer[k]; } + cout << sum << endl; + return 0; +} +ifstream in("txt.in"); +ofstream out("txt.out"); +int main() { + cout << fixed << setprecision(12); + long long t; + cin >> t; + while (t--) { + long long a, b; + cin >> a >> b; + long long cnt = 0; + while (a && b) { + if (a > b) + cnt += a / b, a %= b; + else + cnt += b / a, b %= a; + } + cout << cnt << '\n'; + } + return 0; +} +int a[1000]; +int main() { + int n; + cin >> n; + for (int x, y, s, i = 1; i <= n; i++) { + s = 0; + cin >> x >> y; + while (x > 0 && y > 0) { + if (x > y) { + s += x / y; + x = (x % y); + } else { + s += y / x; + y = (y % x); + } + if (x == y) { + s++; + break; + } + } + a[i] = s; + } + for (int i = 1; i <= n; i++) cout << a[i] << endl; +} +int main() { + int n; + int a[105]; + while (cin >> n) { + int i; + int x, y; + int sum = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + sum = sum + a[i]; + } + int pl = 0, q = 0; + cin >> x >> y; + for (i = 0; i < n; i++) { + q = q + a[i]; + if (q >= x && q <= y && sum - q >= x && sum - q <= y) { + pl = i + 2; + break; + } + } + cout << pl << endl; + } + return 0; +} +long long dat[300005]; +long long sum[300005]; +long long res; +int main() { + int n; + while (cin >> n) { + res = 0; + memset(dat, 0, sizeof(dat)); + for (int i = 0; i < n; i++) cin >> dat[i]; + sort(dat, dat + n); + for (int i = n - 1; i >= 0; i--) dat[i] += dat[i + 1]; + for (int i = 0; i < n - 1; i++) res += dat[i]; + res += dat[0]; + cout << res << endl; + } + return 0; +} +int l[5100] = {}; +int n; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> l[i]; } + for (int i = 1; i <= n; i++) { + if (l[l[l[l[i]]]] == l[i]) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +long long n, num; +int main() { + cin >> n; + long long sum = 1; + int count = 0; + while (sum - 1 < n) { + sum *= 2; + count++; + } + cout << count << endl; +} +int main() { + int n, m; + cin >> n >> m; + int day = 0; + while (1) { + n = n - m; + if (n < 0) break; + day += m; + n += 1; + } + cout << day + n + m << endl; + return 0; +} +int sd(int n) { + int ans = 0; + while (n) { + ans += n % 10; + n /= 10; + } + return ans; +} +int main() { + int n; + cin >> n; + int lower = max(1, n - 81); + vector ans; + for (int i = lower; i < (int)n; i++) { + if (i + sd(i) == n) ans.push_back(i); + } + if ((int)ans.size()) { + cout << ans.size() << endl; + for (int i = 0; i < (int)ans.size(); i++) { cout << ans[i] << endl; } + } else { + cout << 0 << endl; + } + return 0; +} +int a, b; +int main() { + cin >> a >> b; + int ans = 0; + ans = b / a; + if (b % a != 0) ans++; + cout << ans << endl; + return 0; +} +bool ok(char a, char b) { + if (a == b) return true; + a++; + b--; + if (a == b) return true; + a--; + a--; + b++; + b++; + if (a == b) return true; + return false; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + int n; + cin >> n; + string s; + cin >> s; + bool can = true; + for (int j = 0; j < n / 2; j++) { + if (!ok(s[j], s[n - 1 - j])) { + can = false; + break; + } + } + if (can) + cout << "YES\n"; + else + cout << "NO\n"; + } +} +int main() { + char s, c; + int n; + cin >> s >> c; + cin >> n; + string s1 = "v<^>"; + int f, f3, f4; + for (int i = 0; i < 4; i++) { + if (s1[i] == s) f = i; + } + f3 = (f + n) % 4; + f4 = ((f - n) % 4 + 4) % 4; + if (s1[f3] == s1[f4]) + cout << "undefined" << endl; + else if (s1[f3] == c) + cout << "cw" << endl; + else + cout << "ccw" << endl; + return 0; +} +const long long inf = 0x3f3f3f3f; +int a[30010]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n - 1; i++) { cin >> a[i]; } + int k = 1; + while (k <= m) { + if (k == m) { + cout << "YES" << endl; + return 0; + } + k += a[k]; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, hitung = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + if (s[0] == 'T') { + hitung += 4; + } else if (s[0] == 'C') { + hitung += 6; + } else if (s[0] == 'O') { + hitung += 8; + } else if (s[0] == 'D') { + hitung += 12; + } else { + hitung += 20; + } + } + cout << hitung << endl; +} +int main() { + long long n; + cin >> n; + vector v(n, 0); + vector sum(n, 0); + for (long long i = 0; i < n; i++) { + cin >> v[i]; + if (i > 0 && v[i - 1] == v[i]) sum[i] += sum[i - 1]; + sum[i]++; + } + long long ans = 0; + for (long long i = 0; i < n; i++) { + ans++; + if (i > 0 && v[i] == v[i - 1]) { ans += sum[i - 1]; } + } + cout << ans << endl; +} +int main() { + int n, c, counter = 0; + cin >> n; + int C[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { + cin >> c; + C[i][j] = c; + } + } + for (int i = 0; i < n; i++) { + for (int k = 0; k < n; k++) { + if (C[i][0] == C[k][1]) { counter++; } + } + } + cout << counter << endl; + return 0; +} +int main() { + int n, x, indE, indO, ev = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] % 2 == 0) { + indE = i + 1; + ev++; + } else + indO = i + 1; + } + if (ev > 1) + cout << indO << "\n"; + else + cout << indE << "\n"; + return 0; +} +int main() { + int a[1020], n; + int i; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + int cnt = 0; + for (i = 1; i < n - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1]) cnt++; + if (a[i] < a[i - 1] && a[i + 1] > a[i]) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + string s; + cin >> s; + bool check = true; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { + i += 2; + continue; + } else if (s[i] == '1' && s[i + 1] == '4') { + i += 1; + continue; + } else if (s[i] == '1') { + continue; + } else { + check = false; + break; + } + } + if (check) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +long long n, m, a, b, x, ff = 2e7 + 1, l, r, cnt, ans; +vector v, f, res; +string s1, s2; +long long used[1001]; +int main() { + cin >> n; + getline(cin, s1); + getline(cin, s1); + for (int i = 0; i < s1.size(); i++) { + if (s1[i] == ' ') { + a = max(cnt, a); + cnt = 0; + } else if (s1[i] > 64 && s1[i] < 95) { + cnt++; + } + } + a = max(a, cnt); + cout << a << endl; +} +int main() { + int n, i, m, sum = 0; + string s; + cin >> n; + for (i = 0; i < n; i++) { + cin >> s; + if (s == "Tetrahedron") { + m = 4; + } else if (s == "Cube") { + m = 6; + } else if (s == "Octahedron") { + m = 8; + } else if (s == "Dodecahedron") { + m = 12; + } else if (s == "Icosahedron") { + m = 20; + } + sum = sum + m; + } + cout << sum << endl; + return 0; +} +int main() { + long long n, m, a, b; + while (cin >> n >> m >> a >> b) { cout << min((m - n % m) * a, n % m * b) << endl; } + return 0; +} +int main() { + int n, p, k, flag = 0; + char c[305]; + long long x; + cin >> p >> n; + for (int i = 0; i < p; i++) { c[i] = 0; } + for (int i = 0; i < n; i++) { + cin >> x; + k = x % p; + if (c[k] == 0) + c[k] = 1; + else if (!flag) + flag = i + 1; + } + if (flag) + cout << flag << endl; + else + cout << -1 << endl; +} +int main() { + int i, j, a = 0, b, k, w, n; + cin >> k >> n >> w; + for (i = 1; i <= w; i++) { a = a + (i * k); } + b = a - n; + if (b >= 0) { + cout << b << endl; + } else { + cout << "0" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + string s; + int k; + while (n--) { + cin >> k >> s; + if (k == 1 || (k == 2 && s[0] >= s[1])) { + cout << "NO\n"; + } else { + cout << "YES\n"; + cout << 2 << endl; + cout << s[0] << " "; + for (int i = 1; i < k; ++i) { cout << s[i]; } + cout << endl; + } + } +} +int main() { + long long int l, r, ans, n; + cin >> n; + while (n--) { + cin >> l >> r; + ans = l; + while ((ans | (ans + 1)) <= r) ans |= (ans + 1); + cout << ans << "\n"; + } + return 0; +} +long long n, x, y, kq; +void xuli(long long a, long long b) { + kq = 0; + while (a > 0 && b > 0) { + long long n = a; + kq += b / a; + a = b % a; + b = n; + } + cout << kq << endl; +} +int main() { + cin >> n; + while (n > 0) { + cin >> x >> y; + xuli(x, y); + n--; + } + return 0; +} +void insercion(int v[], int n) { + int j; + for (int i = 1; i < n; i++) { + int aux = v[i]; + for (j = i - 1; j >= 0 && v[j] > aux; j--) v[j + 1] = v[j]; + v[j + 1] = aux; + } +} +int main() { + int n, m; + cin >> n >> m; + int v[n], v2[m]; + for (int i = 0; i < n; i++) cin >> v[i]; + for (int i = 0; i < m; i++) cin >> v2[i]; + insercion(v, n); + insercion(v2, m); + int va = v[0], p = v[n - 1], c = v2[0]; + if (max(2 * va, p) < c) + cout << max(2 * va, p) << endl; + else + cout << -1 << endl; + return 0; +} +int getResult(int n) { + if (n > -10) { return n; } + n = (0 - n); + if (n % 10 > ((n / 10) % 10)) { + n = n / 10; + } else { + n = (n / 100) * 10 + n % 10; + } + return (0 - n); +} +int main() { + int n; + cin >> n; + cout << getResult(n) << endl; +} +int main() { + int n; + cin >> n; + int **a = new int *[n + 1]; + for (int i = 1; i <= n; i++) { + a[i] = new int[5]; + for (int j = 1; j <= 4; j++) { cin >> a[i][j]; } + } + int k = 0; + for (int i = 1; i <= n; i++) { k += ((a[i][4] - a[i][2] + 1) * (a[i][3] - a[i][1] + 1)); } + cout << k << endl; + return 0; +} +int main() { + unsigned long long int n; + cin >> n; + if (n == 1) { + cout << n << endl; + return 0; + } + unsigned long long int m = (unsigned long long int)sqrt(2 * n); + m++; + unsigned long long int a = m - 3; + for (unsigned long long int i = a; i <= m; i++) { + unsigned long long int sum = i * (i + 1) / 2; + if (sum <= n) { + unsigned long long int diff = (n - sum); + if (diff <= (i + 1)) { + cout << diff << endl; + return 0; + } + } + } + return 0; +} +int n; +long long x, y; +char seq[3000010]; +int main() { + cin >> n >> x >> y; + cin >> seq; + int cnt = 0; + char last = '1'; + for (int i = 0; i < n; i++) + if (last != seq[i] && last == '1') { + last = seq[i]; + cnt++; + } else if (last != seq[i]) { + last = seq[i]; + } + if (cnt == 0) { + cout << 0 << endl; + } else if (cnt == 1) { + cout << y << endl; + } else { + if (x < y) + cout << y + (x * (cnt - 1)) << endl; + else + cout << y * cnt << endl; + } + return 0; +} +int n; +int main() { + cin >> n; + for (int i = 0; i < n - 1; i++) { + if (i % 2 == 0) + cout << "I hate that "; + else + cout << "I love that "; + } + if (n % 2 == 1) + cout << "I hate it\n"; + else + cout << "I love it\n"; + return 0; +} +int main() { + char a[10050]; + while (cin >> a) { + int len = strlen(a); + int c = 0; + int p = 0; + for (int i = 0; i < len; i++) { + if (a[i] == 'V' && a[i + 1] == 'K') { + c++; + } else if (a[i] == 'K' && a[i - 1] != 'V' && a[i + 1] == 'K') { + p++; + } else if (a[i] == 'V' && a[i - 1] == 'V' && a[i + 1] != 'K') { + p++; + } + } + if (p >= 1) + cout << c + 1 << endl; + else + cout << c << endl; + } + return 0; +} +int main() { + int N; + cin >> N; + vector dic(N + 1); + int result = 0; + int current = 0; + for (int i = 0; i < (int)(2 * N); ++i) { + int a; + cin >> a; + if (dic[a] == 1) { + dic[a] = 0; + current -= 1; + } else { + dic[a] = 1; + current += 1; + } + result = max(result, current); + } + cout << result << "\n"; + return 0; +} +int main() { + int n, a[105], b[105], c[105], t, z; + while (cin >> n) { + t = 0; + z = 0; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 1; i < n; i++) { + b[z] = a[i] - a[i - 1]; + z++; + } + sort(&b[0], &b[z]); + for (int i = 0; i < n - 2; i++) { + c[t] = a[i + 2] - a[i]; + t++; + } + sort(&c[0], &c[t]); + if (c[0] <= b[z - 1]) + cout << b[z - 1] << endl; + else + cout << c[0] << endl; + } +} +int main() { + int t; + cin >> t; + while (t--) { + int n, x, y, d; + cin >> n >> x >> y >> d; + if (abs(x - y) % d == 0) { + cout << abs(x - y) / d << endl; + } else { + int m1 = INT_MAX, m2 = INT_MAX; + bool flag = 0; + if ((y - 1) % d == 0) { + m1 = (x - 1) / d + ((x - 1) % d == 0 ? 0 : 1) + (y - 1) / d; + flag = 1; + } + if ((n - y) % d == 0) { + m2 = (n - x) / d + ((n - x) % d == 0 ? 0 : 1) + (n - y) / d; + flag = 1; + } + if (!flag) { + cout << -1 << endl; + } else { + cout << min(m1, m2) << endl; + } + } + } + return 0; +} +int size_m, size_x, size_y; +int result = -1; +vector sum(0); +int main() { + int ii; + int tmp; + cin >> size_m; + sum.resize(size_m); + cin >> sum[0]; + for (ii = 1; ii < size_m; ii++) { + cin >> tmp; + sum[ii] = sum[ii - 1] + tmp; + } + cin >> size_x >> size_y; + for (ii = 0; (ii < size_m) && (result == -1); ii++) { + if ((sum[ii] > size_y) || ((sum[size_m - 1] - sum[ii]) < size_x)) + result = 0; + else if ((sum[ii] >= size_x) && ((sum[size_m - 1] - sum[ii]) <= size_y)) + result = ii + 2; + } + if (result == -1) result = 0; + cout << result << endl; + return 0; +} +void setIO(string y) { + if (y == "") return; +} +string a, b; +int n; +int main() { + setIO(""); + cin >> a >> b; + cout << a << " " << b << "\n"; + cin >> n; + for (int i = 1; i <= n; i++) { + string c, d; + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + cout << a << " " << b << "\n"; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + bool chars[26]; + for (int i = 0; i < 26; i++) { chars[i] = 0; } + char c; + while (n--) { + cin >> c; + chars[c - 'a'] = 1; + } + int curr = -3, sum = 0, answer = 0; + for (int i = 0; i < 26; i++) { + if (chars[i] && (i > curr + 1)) { + curr = i; + sum++; + answer += (i + 1); + if (sum == k) break; + } + } + if (sum < k) + cout << -1 << endl; + else + cout << answer << endl; +} +int n, ans; +string s, t; +int main() { + cin >> n >> s; + ans = s.size(); + while (n--) { + cin >> t; + for (int i = 0; i < ans; i++) + if (t[i] != s[i]) ans = min(i, ans); + } + cout << ans << endl; +} +long long factorial(long long n) { + if (n > 1) + return n * factorial(n - 1); + else + return 1; +} +int main() { + long long a, b, ans; + cin >> a >> b; + ans = min(a, b); + cout << factorial(ans) << endl; +} +int main() { + int k, m, i, v; + cin >> k; + m = (k + 1) / 2; + for (i = 1; i <= m; i++) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } + for (i = (m - 1); i >= 1; i--) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } +} +int main() { + long long n, m, d, t, k, mx, left[110], right[110]; + string ss, s[1000]; + cin >> ss; + map mp; + int p = 0; + for (int i = 0; i < ss.size(); i++) { + s[p].push_back(ss[i]); + if (s[p].size() == 10) p++; + } + for (int i = 0; i <= 9; i++) { + cin >> ss; + mp[ss] = i; + } + for (int i = 0; i < p; i++) { cout << mp[s[i]]; } + cout << endl; +} +int main() { + long long n, t, cont = 0; + cin >> n >> t; + for (int i = 1; i <= n; i++) { + if (t % i == 0) { + if (t / i >= 1 && t / i <= n) { cont++; } + } + } + cout << cont << endl; + return 0; +} +string s; +void op(int l, int r, char c1, char c2) { + for (int i = l - 1; i < r; i++) + if (s[i] == c1) s[i] = c2; +} +int main() { + int n, m; + cin >> n >> m >> s; + for (int i = 0; i < m; i++) { + int l, r; + char c1, c2; + cin >> l >> r >> c1 >> c2; + op(l, r, c1, c2); + } + cout << s << endl; + return 0; +} +int main() { + int cell, dest; + cin >> cell >> dest; + int line[cell - 1]; + int i; + for (i = 0; i < cell - 1; i++) { cin >> line[i]; } + int g = 0, cnt = 1; + while (g < dest - 1) { + g = g + line[g]; + if (g == dest - 1) { + cout << "YES" << endl; + cnt = 0; + } + } + if (cnt) { cout << "NO" << endl; } +} +int nPr[100][100]; +int main() { + int n, curr = 1, t; + cin >> n >> t; + int arr[n + 1]; + for (int i = 1; i <= n - 1; i++) cin >> arr[i]; + int l = 1; + while (curr <= t) { + if (curr == t) { + cout << "YES" << endl; + return 0; + } + curr += arr[l]; + l = curr; + } + cout << "NO\n"; +} +const int INF = 2147483647, MOD = 1000000007; +const double eps = 1e-8; +int dist[1010], bak[1010]; +int main() { + int T; + T = 1; + for (int tc = 1; tc <= T; tc++) { + int m, k; + cin >> m >> k; + int dist_sum = 0; + for (int i = 0; i < m; i++) { + cin >> dist[i]; + dist_sum += dist[i]; + } + for (int i = 0; i < m; i++) cin >> bak[i]; + long long mn = 0; + int mybak = 0, best = 0; + for (int cur = 0; cur < m; cur++) { + mybak += bak[cur]; + if (bak[cur] > best) best = bak[cur]; + while (mybak < dist[cur]) { + mybak += best; + mn += k; + } + mn += dist[cur]; + mybak -= dist[cur]; + } + cout << mn << endl; + } + return 0; +} +const int INF = 0x3f3f3f3f; +long long a[200000 + 5]; +int main() { + long long i, j, k, l = 0, co = 0, c = 0; + long long n, m; + long long x, y; + cin >> n >> k; + for (i = 0; i < n; i++) { + c = 0; + cin >> j; + while (j) { + m = j % 10; + if (m == 4 || m == 7) c++; + j /= 10; + } + if (c <= k) co++; + } + cout << co << endl; + return 0; +} +int biao[305]; +int main() { + int n, m; + cin >> n >> m; + bool flag = false; + int k; + for (int i = 1; i <= m; i++) { + int a; + cin >> a; + int b = a % n; + if (biao[b] == 1 && !flag) { + flag = true; + k = i; + } else + biao[b] = 1; + } + if (flag) + cout << k << endl; + else + cout << -1 << endl; +} +const int maxn = 1e6; +const int inf = 0x3f3f3f3f; +int Map[maxn]; +int main() { + int n, i, j, k, minn = inf; + cin >> n; + for (i = 1; i <= n; i++) cin >> Map[i]; + sort(Map + 1, Map + 1 + n); + int mid = n / 2; + for (i = 1; i + mid <= n; i++) { minn = min(minn, Map[i + mid] - Map[i]); } + cout << minn << endl; + return 0; +} +int getdigits(int n) { + int c = 0; + while (n != 0) { + n /= 10; + c++; + } + return c; +} +int main() { + int n, d, i, flag = 0; + ; + cin >> n; + d = getdigits(n); + if (n % 4 == 0) { + flag = 1; + } else if (n % 7 == 0) { + flag = 1; + } else if (n % 47 == 0) { + flag = 1; + } else if (n % 477 == 0) { + flag = 1; + } else if (n % 447 == 0) { + flag = 1; + } else if (n % 474 == 0) { + flag = 1; + } else if (n % 744 == 0) { + flag = 1; + } else if (n % 747 == 0) { + flag = 1; + } else if (n % 774 == 0) { + flag = 1; + } + if (flag) + cout << "YES" + << "\n"; + else + cout << "NO" + << "\n"; + return 0; +} +vector woman; +vector child; +vector man; +vector rat; +int main() { + int n; + string captain; + cin >> n; + int f = 0; + for (int i = 0; i < n; i++) { + string name; + string status; + cin >> name; + cin >> status; + if (status == "rat") rat.push_back(name); + if (status == "woman" || status == "child") woman.push_back(name); + if (status == "man") man.push_back(name); + if (status == "captain") captain = name; + } + for (int i = 0; i < rat.size(); i++) cout << rat[i] << endl; + for (int i = 0; i < woman.size(); i++) cout << woman[i] << endl; + for (int i = 0; i < man.size(); i++) cout << man[i] << endl; + cout << captain << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[50][50]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { cin >> a[i][j]; } + int sum = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (a[i][j] != 'x' && i + 1 < n && j + 1 < m) { + bool mark[27] = {false}; + mark[a[i][j] - 'a'] = true; + mark[a[i + 1][j] - 'a'] = true; + mark[a[i][j + 1] - 'a'] = true; + mark[a[i + 1][j + 1] - 'a'] = true; + if (mark['f' - 'a'] && mark['a' - 'a'] && mark['c' - 'a'] && mark['e' - 'a']) { sum++; } + } + } + cout << sum << '\n'; + return 0; +} +int main() { + int a[51], b[51]; + int n, m; + int maxn = 0; + int ans = 0; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int i = 0; i < m; i++) cin >> b[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + int t = b[j] / a[i]; + if (t * a[i] == b[j]) { + if (t == maxn) + ans++, maxn = max(maxn, t); + else if (t > maxn) + ans = 1, maxn = max(maxn, t); + } + } + } + cout << ans << endl; + return 0; +} +string s; +int main() { + int n; + cin >> n >> s; + int cnt = 0, ans = 0; + for (int i = 0; i < n; i++) { + if (s[i] == '0') { + ans = ans * 10 + cnt; + cnt = 0; + continue; + } + cnt++; + } + ans = ans * 10 + cnt; + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + string ans = ""; + ans += a[0]; + char f = b[0]; + int l = a.length(); + for (int i = 1; i < l; i++) { + if (a[i] >= b[0]) + break; + else + ans += a[i]; + } + ans += b[0]; + cout << ans << endl; +} +int main() { + long long x, y, z; + cin >> x >> y >> z; + long long abc = (long long)(sqrt(x * y * z + 0.00001)); + long long ans = 4 * (abc / x + abc / y + abc / z); + cout << ans << endl; + return 0; +} +int main() { + int n; + int max = 0, min = 10000020; + int a[110], b[110], c[110]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + { + for (int i = 0; i < n; i++) { + if (i > 0) { + b[i - 1] = a[i] - a[i - 1]; + if (max < b[i - 1]) max = b[i - 1]; + } + } + for (int i = 0; i < n - 1; i++) { + if (i < n - 2) { + c[i] = b[i] + b[i + 1]; + if (min > c[i]) min = c[i]; + } + } + max > min ? cout << max << endl : cout << min << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i % 2 == 0) { + cout << '#'; + } else { + if (i % 4 == 1) { + if (j == m - 1) + cout << '#'; + else + cout << '.'; + } else if (i % 4 == 3) { + if (j == 0) + cout << '#'; + else + cout << '.'; + } + } + } + cout << endl; + } +} +int main() { + string s; + cin >> s; + int lower = 0, upper = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') + lower++; + else if (s[i] >= 'A' && s[i] <= 'Z') + upper++; + } + if (lower >= upper) { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'A' && s[i] <= 'Z') s[i] = char(s[i] + 32); + } + } else { + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') s[i] = char(s[i] - 32); + } + } + cout << s << '\n'; +} +int main() { + int a[150], b[150], n, cnt = 0, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + x = b[i] - a[i]; + if (a[i] < b[i]) { + if (x > 1) cnt++; + } + } + cout << cnt << endl; + return 0; +} +const int N = 1e5 + 5, mod = 1e9 + 7; +map Cnt; +int main() { + int q; + cin >> q; + while (q--) { + string s, num; + cin >> s >> num; + int x = 0, msk = 0; + for (int i = num.size() - 1; i >= 0; i--) { + if ((num[i] - '0') & 1) msk |= (1 << x); + x++; + } + if (s == "+") + Cnt[msk]++; + else if (s == "-") + Cnt[msk]--; + else + cout << Cnt[msk] << "\n"; + } + return 0; +} +int main() { + long long ans = 1; + int n, m; + cin >> n >> m; + long long pw = 1; + while (m) { + pw *= 2; + m--; + pw %= (long long)(1e9 + 9); + } + for (int i = 1; i <= n; i++) { + ans *= pw - i; + ans %= (long long)(1e9 + 9); + } + cout << ans << endl; + return 0; +} +static const int mod = 1000000009; +long long power(int m) { + long long s = 1; + for (int i = 0; i < m; ++i) { s = (s * 2) % mod; } + return s; +}; +int main() { + int n, m; + cin >> n >> m; + long long *t = new long long[n]; + long long k = power(m); + t[0] = k - 1; + for (int i = 1; i < n; ++i) { t[i] = t[i - 1] - 1; } + long long result = t[0]; + for (int i = 1; i < n; ++i) { result = ((result % mod) * (t[i] % mod)) % mod; } + cout << result << endl; +} +const double PI = acos(-1.0); +long long a[205]; +int gcd(int a, int b) { + if (b % a == 0) return a; + return gcd(b % a, a); +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + int s = a[0]; + for (int i = 1; i < n; i++) { s = gcd(a[i], s); } + int ans = a[n - 1] / s - n; + if (ans & 1) + cout << "Alice\n"; + else + cout << "Bob\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char a[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a[i][j]; + if (a[i][j] == '.') { + if (i % 2 == 1) { + if (j % 2 == 1) + a[i][j] = 'B'; + else + a[i][j] = 'W'; + } else { + if (j % 2 == 1) + a[i][j] = 'W'; + else + a[i][j] = 'B'; + } + } + cout << a[i][j]; + } + cout << '\n'; + } + return 0; +} +int main() { + int n, i, j, k, ans = -1; + string s; + cin >> n >> s; + vector a(n); + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n - 1; i++) { + if ((s[i] == 'R') && (s[i + 1] == 'L')) { + if (ans == -1) + ans = (a[i + 1] - a[i]) / 2; + else + ans = min(ans, (a[i + 1] - a[i]) / 2); + } + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, x, a[1005], sum = 0, cont = 0; + cin >> n >> x; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum += a[i]; + } + int baad = x; + sum = abs(sum); + while (sum != 0) { + while (sum < x) x--; + sum -= x; + cont++; + } + cout << cont << endl; + return 0; +} +int main() { + int n, k; + int *a; + while (cin >> n >> k) { + int ans = 0; + a = new int[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int head = 0, end = n - 1; + while (k >= a[head] && head < n) { + ans++; + head++; + } + while (k >= a[end] && ans != n) { + ans++; + end--; + } + cout << ans << endl; + } + return 0; +} +int main() { + string S, s; + cin >> S >> s; + int len = s.size(), count = 0, couner = 0; + for (int i = 0; i < len; i++) { + if (s[i] == S[couner]) { + count++; + couner++; + } + } + cout << count + 1 << endl; + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + if ((a + b - c) >= n || a < c || b < c) + cout << "-1" << endl; + else + cout << n - a - b + c << endl; +} +string S, T; +long long N, M, A[5][5], B[5][5], sum, x, y, K, ans, val, L, a; +char C; +int main() { + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { cin >> A[i][j]; } + } + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= 3; j++) { + sum = A[i][j] + A[i - 1][j] + A[i + 1][j] + A[i][j - 1] + A[i][j + 1]; + if (sum % 2) + cout << 0; + else + cout << 1; + } + cout << '\n'; + } +} +int main() { + int i, j, x; + int h; + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + cin >> x; + if (x != 0) { h = abs(i - 2) + abs(j - 2); } + } + } + cout << h << endl; + return 0; +} +int a[105], b[105]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= m; i++) cin >> b[i]; + sort(a + 1, a + n + 1); + sort(b + 1, b + m + 1); + int tmp = max(a[n], 2 * a[1]); + if (tmp >= b[1]) + cout << -1 << endl; + else + cout << tmp << endl; + return 0; +} +int main() { + long long n; + while (cin >> n) { + if (n % 2 == 0) { + cout << "2" << endl; + } else { + cout << "1" << endl; + } + } + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long x; + x = n / 2 / (k + 1); + cout << x << " " << x * k << " " << n - x * k - x << endl; + return 0; +} +int main() { + int link = 0, pearl = 0; + string str; + cin >> str; + for (int i = 0; i < str.length(); i++) { + if (str[i] == '-') + link++; + else + pearl++; + } + if (pearl == 0) { + cout << "YES" << endl; + return 0; + } + if (link % pearl == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +map, int> mp; +int main() { + int n; + string ho; + cin >> n >> ho; + for (int i = 1; i <= n; i++) { cin >> ho; } + if (n % 2 == 0) + cout << "home" << endl; + else + cout << "contest" << endl; + return 0; +} +int main() { + string s; + cin >> s; + bool ch1 = 0, ch2 = 0, ch3 = 0; + for (int i = 0; i < s.size(); ++i) { + if (s[i] >= 65 && s[i] <= 90) ch1 = true; + if (s[i] >= 97 && s[i] <= 122) ch2 = true; + if (s[i] >= 48 && s[i] <= 57) ch3 = true; + } + if (s.size() >= 5 && ch1 == true && ch2 == true && ch3 == true) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n / 2 + 1; i++) { + for (int j = 0; j < n; j++) { + if (j >= n / 2 + i + 1 || j <= n / 2 - i - 1) { + cout << '*'; + } else + cout << 'D'; + } + cout << '\n'; + } + for (int i = n / 2 - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (j >= n / 2 + i + 1 || j <= n / 2 - i - 1) { + cout << '*'; + } else + cout << 'D'; + } + cout << '\n'; + } + return 0; +} +string str; +int tam; +int teste() { + tam--; + int i, lim = tam / 2; + for (i = 0; i <= lim; i++) + if (abs(str[i] - str[tam - i]) && abs(str[i] - str[tam - i]) != 2) return 0; + return 1; +} +int main() { + int ncasos; + cin >> ncasos; + while (ncasos--) { + cin >> tam >> str; + if (teste()) + cout << "YES"; + else + cout << "NO"; + cout << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int k = (26 * ((int)s.length() + 1)) - (int)s.length(); + cout << k << endl; +} +int main() { + int f = 0; + string s; + cin >> s; + for (int i = 0; i < s.size();) { + if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { + i = i + 3; + } else if (s[i] == '1' && s[i + 1] == '4') { + i = i + 2; + } else if (s[i] == '1') { + i++; + } else { + f = 1; + break; + } + } + if (f == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector ambos(5, 0), a(5), b(5); + for (int i = 0; i < n; i++) { + int num; + cin >> num; + a[num - 1]++; + ambos[num - 1]++; + } + for (int i = 0; i < n; i++) { + int num; + cin >> num; + b[num - 1]++; + ambos[num - 1]++; + } + bool r = 1; + for (int i = 0; i < 5; i++) + if (ambos[i] % 2 == 1) r = 0; + int ans; + if (r) { + ans = 0; + for (int i = 0; i < 5; i++) ans = ans + abs(a[i] - b[i]); + ans = ans / 4; + } else + ans = -1; + cout << ans << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[105]; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + if (a[0] != 1 && a[0] != 2) { + cout << "NO" << endl; + return 0; + } + long long int p = 6 - a[0] - 3; + long long int f = 1; + for (long long int i = 1; i <= n; i++) { + if (a[i] == p) { + f = 0; + break; + } else { + p = 6 - p - a[i]; + } + } + if (f == 0) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int a, b, c, d, e; + cin >> a; + cin >> b; + cin >> c; + cin >> d; + cin >> e; + if ((a + b + c + d + e) % 5 != 0 || (a + b + c + d + e) / 5 == 0) { + cout << -1 << endl; + } else { + cout << (a + b + c + d + e) / 5 << endl; + } + return 0; +} +int so, os; +string a, b; +int main() { + cin >> a >> b; + for (int i = 0; i < a.size(); ++i) + if (a[i] != b[i]) + if (a[i] == '4') + ++so; + else + ++os; + cout << max(so, os) << endl; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + reverse(s1.begin(), s1.end()); + if (s1 == s2) + cout << "YES\n"; + else + cout << "NO\n"; +} +const int maxn = 1e5 + 10; +long long x, y; +int main() { + cin >> x >> y; + if (x > 0 && y > 0) cout << 0 << ' ' << x + y << ' ' << x + y << ' ' << 0 << endl; + if (x > 0 && y < 0) cout << 0 << ' ' << -x + y << ' ' << x - y << ' ' << 0 << endl; + if (x < 0 && y > 0) cout << -(-x + y) << ' ' << 0 << ' ' << 0 << ' ' << -(x - y) << endl; + if (x < 0 && y < 0) cout << x + y << ' ' << 0 << ' ' << 0 << ' ' << x + y << endl; + return 0; +} +int main() { + long int x, i, bit = 0; + cin >> x; + while (x != 0) { + if (x % 2 != 0) { + bit++; + x = x - 1; + } + x = x / 2; + i++; + } + cout << bit << endl; + return 0; +} +const int mod = 998244353; +long long qpow(long long x, long long y) { + long long s = 1; + while (y) { + if (y & 1) s = s * x % mod; + x = x * x % mod; + y >>= 1; + } + return s; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); + return x * f; +} +long long inve(long long x) { + return x == 1 ? 1 : (mod - mod / x) * inve(mod % x) % mod; +} +int n, w, b, ans; +int a[100050]; +int main() { + cin >> n >> w >> b; + for (int i = 1; i <= n; i++) cin >> a[i]; + int l = 0, r = n + 1; + while (1) { + l++; + r--; + if (r <= l) { + if (r == l && a[l] == 2) ans += min(b, w); + break; + } + if (a[l] == 0 && a[r] == 0) continue; + if (a[l] == 1 && a[r] == 1) continue; + if ((a[l] == 2 && a[r] == 0) || (a[l] == 0 && a[r] == 2)) { + ans += w; + continue; + } + if ((a[l] == 2 && a[r] == 1) || (a[l] == 1 && a[r] == 2)) { + ans += b; + continue; + } + if (a[l] == 2 && a[r] == 2) { + ans += 2 * min(b, w); + continue; + } + if (a[l] != 2 && a[r] != 2 && a[l] != a[r]) return puts("-1"), 0; + } + cout << ans << "\n"; + return 0; +} +int h[2000]; +int main() { + int n, a, b; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { cin >> h[i]; } + sort(h, h + n); + int ans = h[b] - h[b - 1]; + cout << ans << endl; + return 0; +} +char a[52], b[52]; +int main() { + while (cin >> a) { + cin >> b; + int lo = 1, lena, lenb; + lena = strlen(a); + lenb = strlen(b); + for (int i = 0, j = 0; i <= lena && j <= lenb;) { + if (a[i] == b[j]) { + lo++; + j++; + i++; + } else + j++; + } + cout << lo << endl; + lo = 1; + } +} +long long m; +int power(long long a, int n) { + long long res = 1; + while (n > 0) { + if (n % 2 == 1) { + res *= a; + res %= m; + } + a *= a; + a %= m; + n /= 2; + } + return res; +} +int main() { + int n; + cin >> n >> m; + cout << ((power(3, n) - 1) % m + m) % m << endl; + return 0; +} +char s[100050]; +int main() { + map x; + gets(s + 1); + int len = strlen(s + 1); + for (int i = 1; i <= len; i++) { x[s[i]]++; } + x['u'] /= 2; + x['a'] /= 2; + int ans = min(x['B'], x['u']); + ans = min(ans, x['l']); + ans = min(ans, x['b']); + ans = min(ans, x['a']); + ans = min(ans, x['s']); + ans = min(ans, x['r']); + cout << ans << endl; + return 0; +} +int inum(int *a, int k, int i) { + for (int l = 1; l < k; l++) { + if (a[l - 1] != -1) { + a[l] = a[l - 1] + (l + 1); + } else { + a[l] = inum(a, l, i) + l + 1; + } + } + return *(a + (k - 1)); +} +int isum(int i) { + int arr[i], a[i]; + arr[i] = {-1}; + a[i] = {-1}; + a[0] = 1; + arr[0] = 1; + if (i == 1) { + return i; + } else { + int j = 1; + for (j; j < i; j++) { + if (arr[j - 1] != -1) { + arr[j] = arr[j - 1] + inum(a, j + 1, i); + } else { + arr[j] = isum(j) + (j + 1); + } + } + } + return *(arr + (i - 1)); +} +int main() { + int n, i = 1; + cin >> n; + while (isum(i) <= n) { i++; } + cout << (i - 1) << endl; + return 0; +} +int main() { + char s[] = "qwertyuiopasdfghjkl;zxcvbnm,./"; + int n = strlen(s); + char a[111]; + char c; + cin >> c; + cin >> a; + int m = strlen(a); + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (c == 'R') { + if (s[j] == a[i]) { cout << s[j - 1]; } + } else { + if (s[j] == a[i]) cout << s[j + 1]; + } + } + } + cout << endl; + return 0; +} +int a[10005]; +int main() { + int n, m, z, i, cnt = 0; + cin >> n >> m >> z; + int x = n * m; + for (i = 1; i * n <= z; i++) a[i * n] = 1; + for (int i = 1; i * m <= z; i++) { + if (a[i * m] == 1) cnt++; + } + cout << cnt << endl; +} +int main() { + long long n, k = 1; + cin >> n; + while (n - k > 0) { + n = n - k; + k++; + } + cout << n << endl; +} +int a[100009]; +int main() { + int n; + while (cin >> n) { + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int flag = 0; + for (int i = 1; i <= n; i++) { + int x, y; + x = a[i]; + y = a[x]; + if (a[y] == i && x != i && x != y && i != y) { flag = 1; } + if (flag == 1) { break; } + } + if (flag == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int sum = 0; + string s, s1; + cin >> s >> s1; + for (int i = 0; i < n; i++) { sum += min(abs(s[i] - s1[i]), 10 - abs(s[i] - s1[i])); } + cout << sum << endl; + return 0; +} +const long long mod = 1e9 + 7; +int main() { + long long n; + cin >> n; + long long i, j; + long long hi = sqrt(n); + while (hi) { + if (n % hi == 0) { + cout << hi << " " << (n / hi) << endl; + return 0; + } + hi--; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + if (m % n == 0) { + ans = m / n; + } else { + ans += m / n + 1; + } + cout << ans << endl; +} +int a[100005], b[100005], t = 0; +int main() { + int n, x; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x; + if (x >= 0) + a[x]++; + else + b[-x]++; + } + for (int i = 0; i < 100005; i++) { + if (i != 0 && a[i] != 0) t++; + if (i != 0 && b[i] != 0) t++; + } + cout << t << endl; + return 0; +} +int main() { + int x; + cin >> x; + cout << (x % 2) << endl; + return 0; +} +int main() { + long long n; + cin >> n; + bool ar[n + 1]; + memset(ar, 0, sizeof(ar)); + long long a; + cin >> a; + for (long long i = 1; i <= a; i++) { + long long k; + cin >> k; + ar[k] = 1; + } + cin >> a; + for (long long i = 1; i <= a; i++) { + long long k; + cin >> k; + ar[k] = 1; + } + bool yes = 1; + for (long long i = 1; i <= n; i++) { + if (!ar[i]) yes = 0; + } + if (yes) + cout << "I become the guy.\n"; + else + cout << "Oh, my keyboard!\n"; +} +int main() { + int n, i, k, j, t = 0, m; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> j; + j += t; + t = 0; + if (j >= 8) { + t += j - 8; + j = 8; + } + k -= j; + if (k <= 0) { break; } + } + if (k > 0) { + cout << -1 << endl; + } else { + cout << i + 1 << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + set ss; + int l = s.length(); + for (int i = 0; i <= l; i++) { + string t(s.begin() + 1, s.end()); + s = t + s[0]; + ss.insert(s); + } + cout << ss.size() << endl; +} +long long int a, b, c, tt; +int main() { + cin >> a >> b >> c; + cout << (float)a / (b + c) * b << endl; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + long double a, b, c; + cin >> a >> b >> c; + a /= (b + c); + a *= b; + cout << a << endl; + return 0; +} +long long n, last; +int main() { + cin >> n; + cout << 2 << endl; + for (long long i = 3; i <= n + 1; i++) { cout << (i * i * (i - 1)) - (i - 2) << endl; } +} +long long mod = 1000000007; +int main() { + long long n; + cin >> n; + long long num = 2; + cout << 2 << endl; + for (long long i = 2; i < n + 1; i++) { + long long sum = (i * (i + 1) * (i + 1)) - (i - 1); + cout << sum << endl; + } + return 0; +} +int main() { + int i, j, n, p = 0, q, flag = 0, a[10] = {0}; + for (i = 0; i < 6; i++) { + cin >> n; + a[n]++; + } + for (i = 0; i <= 9; i++) { + if (a[i] >= 4) { + a[i] -= 4; + flag = 1; + } + } + if (flag == 0) { + cout << "Alien" << endl; + return 0; + } + for (i = 0; i <= 9; i++) { + if (a[i] == 2) { + cout << "Elephant" << endl; + return 0; + } + } + cout << "Bear" << endl; + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int a[n], i, s = 0; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n - k; i++) s += a[i]; + s += k * x; + cout << s << endl; + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n + 1]; + for (long long int i = 0; i < n; i++) { cin >> a[i]; } + long long int le = 0, maxle = 0; + for (long long int i = 1; i < n; i++) { + if (a[i] > a[i - 1]) { + le++; + } else { + le = 0; + } + if (le > maxle) maxle = le; + } + cout << maxle + 1 << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int r[n], d[n - 1], s(0), m(1000); + cin >> r[0]; + for (int i = 1; i < n; i++) { + cin >> r[i]; + d[i] = r[i] - r[i - 1]; + s = max(s, d[i]); + } + for (int i = 2; i < n; i++) m = max(min(m, d[i] + d[i - 1]), s); + cout << m << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + long long x = (n / 2) / (1 + k); + cout << x << " " << x * k << ' ' << n - (x) * (1 + k) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + int flag = 1; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) flag = -1; + } + cout << flag << endl; +} +int main() { + int n, m; + cin >> n >> m; + int inte_pair = 0; + for (int i = 0; i <= n && i <= m; i++) + for (int j = 0; j <= n && j <= m; j++) + if ((i * i) + j == n && i + (j * j) == m) inte_pair++; + cout << inte_pair << endl; +} +long long modpow(long long x, long long n, long long m) { + if (n == 0) return 1 % m; + long long u = modpow(x, n / 2, m); + u = (u * u) % m; + if (n % 2 == 1) u = (u * x) % m; + return u; +} +int main() { + int n, k, tt = 0; + cin >> n; + k = 1; + for (int e = 0; e < n; e++) { + for (int p = 0; p < (n - k) / 2; p++) cout << "*"; + for (int p = 0; p < k; p++) cout << "D"; + for (int p = 0; p < (n - k) / 2; p++) cout << "*"; + if (k == n && tt == 0) tt = 1; + if (tt == 0) + k += 2; + else + k -= 2; + cout << endl; + } + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int m = (len * 25) + 26; + cout << m << endl; + return 0; +} +int main() { + int n, nn; + cin >> nn; + while (nn--) { + cin >> n; + if (360 % (180 - n) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + if (360 % (180 - n) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + double n, a = 1, i = 1; + cin >> n; + while (a * 2 <= n) { a *= 2; } + while ((n - a) >= 2) { + i++; + n = n - a; + a = 1; + while (a * 2 <= n) { a *= 2; } + } + i += n - a; + cout << i << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << (n + 2) / 2 << endl; +} +int main() { + int n; + cin >> n; + vector a(n * 2); + for (int i = 0; i < n * 2; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + long long ans = LLONG_MAX; + for (int i = 0; i < n; i++) { + if (i == 0) { + ans = min(ans, (a[n - 1] - a[0]) * (a[n * 2 - 1] - a[n])); + } else { + ans = min(ans, (a[i + n - 1] - a[i]) * (a[n * 2 - 1] - a[0])); + } + } + cout << ans << endl; + return 0; +} +const int maxn = 1000000 + 10, mod = 1e9 + 7; +int n, f[maxn] = {0, 1, 3}; +int main() { + cin >> n; + for (int i = 3; i <= n; i++) f[i] = (f[i - 1] + f[i - 2] + 2) % mod; + cout << f[n] << endl; + return 0; +} +const int MOD = 998244353; +const int MAX = 200001; +int An[MAX]; +int book[MAX]; +int main() { + int n, m, x, y; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> y; + book[y] = 1; + } + } + int flag = 0; + for (int i = 1; i <= m; i++) { + if (book[i] == 0) { + flag = 1; + cout << "NO" << endl; + break; + } + } + if (!flag) cout << "YES" << endl; + return 0; +} +long long bigmod(long long a, long long b, long long m) { + if (b == 0) return 1 % m; + long long x = bigmod(a, b / 2, m); + x = (x * x) % m; + if (b % 2) x = (x * a) % m; + return x; +} +long long w[100001], lp, lc, rc, rp, n, l, r, c = INT_MAX; +int main() { + cin >> n >> lc >> rc >> lp >> rp; + for (int i = 0; i < n; i++) cin >> w[i]; + ; + l = 0; + r = 0; + for (int i = 0; i < n; i++) r += (w[i] * rc); + for (int i = 0; i < n + 1; i++) { + long long d = max(0ll, abs((n - i) - i) - 1); + if (n - i > i) + d *= rp; + else if (n - i < i) + d *= lp; + else + d *= min(lp, rp); + c = min(c, l + r + d); + l += (w[i] * lc); + r -= (w[i] * rc); + } + cout << c << endl; +} +const int maxn = 1e6 + 5; +const int mod = 1e9 + 7; +long long fac[maxn], y[maxn]; +long long n, k; +long long qpow(long long a, long long b, long long c) { + long long ans = 1; + a %= c; + b %= c; + while (b > 0) { + if (b % 2 == 1) ans = (ans * a) % c; + b = b / 2; + a = (a * a) % c; + } + return ans; +} +int pow_2(int m) { + int res = 1; + int left = 1; + while (true) { + if (res << left <= m && res << (left + 1) > m) return res << left; + left++; + } +} +int main() { + int n, b, p; + int ans = 0; + cin >> n >> b >> p; + int tow = n * p; + int left = 0; + while (n > 1) { + int k = pow_2(n); + left = n - k; + ans += b * k + k / 2; + n = k / 2 + left; + } + cout << ans << ' ' << tow << '\n'; + return 0; +} +int main() { + int ans[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { ans[i][j] = 1; } + } + int input[3][3]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cin >> input[i][j]; } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + int sum = input[i][j]; + if (i - 1 >= 0) { sum += input[i - 1][j]; } + if (i + 1 < 3) { sum += input[i + 1][j]; } + if (j - 1 >= 0) { sum += input[i][j - 1]; } + if (j + 1 < 3) { sum += input[i][j + 1]; } + if (sum % 2 == 0) { + ans[i][j] = 1; + } else + ans[i][j] = 0; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << ans[i][j]; } + cout << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + long long g = a[0]; + for (int i = 1; i < n; i++) { g = __gcd(a[i], g); } + for (int i = 0; i < n; i++) { a[i] = a[i] / g; } + for (int i = 0; i < n; i++) { + if (a[i] == 1) continue; + long long x = a[i]; + while (x % 2 == 0) x /= 2; + while (x % 3 == 0) x /= 3; + if (x != 1) return cout << "No" << endl, 0; + } + cout << "Yes" << endl; + return 0; +} +int a[105]; +int n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + while (a[0] != a[n - 1]) { + for (int i = 1; i < n; i++) { + if (a[i] > a[0]) a[i] -= a[0]; + } + sort(a, a + n); + } + cout << n * a[0] << endl; + return 0; +} +const int maxn = 1005; +int main() { + int n; + cin >> n; + int a[maxn]; + int b[maxn]; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + int MAX; + if (n == 1) + MAX = a[0] + b[0]; + else { + MAX = 0; + for (int i = 0; i < n; i++) { + int tmp1 = a[i], tmp2 = b[i]; + for (int j = i; j < n; j++) { + for (int k = i; k <= j; k++) { + tmp1 = tmp1 | a[k]; + tmp2 = tmp2 | b[k]; + } + if (tmp1 + tmp2 > MAX) MAX = tmp2 + tmp1; + } + } + } + cout << MAX << endl; + return 0; +} +int main() { + int ar[10] = {1, 6, 1, 2, 2, 3, 1, 4, 0, 1}; + int n; + cin >> n; + int l = (n / 10), r = (n % 10); + cout << (ar[l] + 1) * (ar[r] + 1) << '\n'; + return 0; +} +int main() { + int n; + cin >> n; + int m, c; + int mCount = 0, cCount = 0; + for (int i = 0; i < n; i++) { + cin >> m; + cin >> c; + if (m > c) + mCount++; + else if (c > m) + cCount++; + } + if (mCount > cCount) + cout << "Mishka" << endl; + else if (cCount > mCount) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +string ProduceCode(string, string); +void Solution(void); +int main() { + Solution(); +} +void Solution(void) { + int Size = 0, V = 2; + string *PhoneArray = NULL, CityCode = "X"; + cin >> Size; + PhoneArray = new string[Size]; + cin >> PhoneArray[0] >> PhoneArray[1]; + CityCode = ProduceCode(PhoneArray[0], PhoneArray[1]); + while (V < Size) { + cin >> PhoneArray[V]; + if (PhoneArray[V].substr(0, CityCode.length()) != CityCode) CityCode = PhoneArray[V].substr(0, CityCode.length() - 1); + ++V; + } + cout << CityCode.length() << endl; +} +string ProduceCode(string A, string B) { + int X = 0; + while (A[X] == B[X]) ++X; + return B.substr(0, X); +} +long long int dfs(long long int n) { + long long int k = 0; + while (n > 0) { + k += n % 10; + n = n / 10; + } + return k; +} +int main() { + long long int n, q, i, j; + cin >> n; + vector v; + for (i = 1; i <= 110; i++) { + if (i > n) { break; } + if (dfs(n - i) == i) { v.push_back(n - i); } + } + long long int u = v.size(); + cout << u << endl; + for (i = u - 1; i >= 0; i--) { cout << v[i] << endl; } + return 0; +} +int num[4]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + num[a]++; + } + int max_num = -1; + for (int i = 1; i <= 3; i++) { + if (num[i] > max_num) { max_num = num[i]; } + } + cout << n - max_num << endl; +} +int main() { + int n, s; + cin >> n >> s; + int ans = 0; + while (s) { + if (s == 0) break; + if (s >= n) + s -= n, ans++; + else + n--; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int arr[n]; + int count[3] = {0, 0, 0}; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + count[arr[i] - 1]++; + } + sort(count, count + 3); + int x = count[0]; + cout << x << endl; + while (x > 0) { + for (int i = 0; i < n; i++) { + if (arr[i] == 1) { + cout << i + 1 << " "; + arr[i] = 0; + break; + } + } + for (int i = 0; i < n; i++) { + if (arr[i] == 2) { + cout << i + 1 << " "; + arr[i] = 0; + break; + } + } + for (int i = 0; i < n; i++) { + if (arr[i] == 3) { + cout << i + 1 << endl; + arr[i] = 0; + break; + } + } + x--; + } +} +int main() { + string a; + string b; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a.compare(b) == 0) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int main() { + int n, count = 0; + cin >> n; + int ar[n]; + for (int i = 0; i < n; i++) cin >> ar[i]; + for (int i = 0; i < n; i++) { + if (ar[i] == 1) + count++; + else if (ar[i] == 0 && i > 0 && i < n - 1 && ar[i - 1] == 1 && ar[i + 1] == 1) + count++; + } + cout << count << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +long long a[100000 + 5], b[100000 + 5]; +int main() { + long long i, j, k, l = 0; + long long n, m; + cin >> n; + for (i = 0; i < n; i++) cin >> a[i]; + k = 0; + int cou = 0; + for (i = 1; i < n; i++) { + if (a[i] == a[k]) + cou++; + else { + if (cou) b[l++] = cou + 1; + cou = 0; + k = i; + } + if (i == n - 1) { + if (cou) b[l++] = cou + 1; + } + } + long long s = n; + for (i = 0; i < l; i++) s += b[i] * (b[i] - 1) / 2; + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], sum = 0; + for (int i = 0; i < n; i++) { + int k; + cin >> k; + a[i] = k; + sum = sum + a[i]; + } + int lar = a[0]; + for (int i = 1; i < n; i++) { + if (lar < a[i]) lar = a[i]; + } + for (int j = lar;; j++) { + if (j * n > (2 * sum)) { + cout << j << endl; + break; + } + } +} +int tmp, min1, max1, sum_n, index_max, index_min; +int arr1[1000][1000]; +char arr3[100]; +int arr[10000]; +void display_vector(vector v) { + for (int i = 0; i < v.size(); i++) cout << v[i] << " "; + cout << endl; +} +void speed() {} +void min_max(vector v, int l) { + min1 = INT_MAX; + max1 = INT_MIN; + for (int i = l; i < v.size(); i++) { + if (v[i] <= min1) { + min1 = v[i]; + index_min = i; + } + if (v[i] >= max1) { + max1 = v[i]; + index_max = i; + } + } +} +int sum_v(vector v) { + for (int i = 0; i < v.size(); i++) sum_n += v[i]; + return sum_n; +} +bool is_it_sorted_acs(vector v) { + bool test1 = false; + for (int i = 0; i < v.size() - 1; i++) + if (v[i + 1] <= v[i]) { + test1 = false; + return test1; + } + test1 = true; + return test1; +} +bool is_it_sorted_des(vector v) { + bool test1 = false; + for (int i = 0; i < v.size() - 1; i++) + if (v[i + 1] >= v[i]) { + test1 = false; + return test1; + } + test1 = true; + return test1; +} +int main() { + speed(); + int n, r, ans = 0; + cin >> n; + ans += n / 100; + r = n % 100; + ans += r / 20; + r %= 20; + ans += r / 10; + r %= 10; + ans += r / 5; + r %= 5; + ans += r; + cout << ans << endl; +} +const int N = 1e6 + 6, inf = 1e9 + 7; +int main() { + int n, k; + cin >> n >> k; + int Arr[n + 2]; + for (int i = 1; i <= n; i++) cin >> Arr[i]; + int cnt = 0; + int lft = 1; + while (lft <= n && Arr[lft] <= k) lft++, cnt++; + int rgt = n; + while (rgt >= 1 && lft < rgt && Arr[rgt] <= k) rgt--, cnt++; + cout << cnt << "\n"; + return 0; +} +int p, dp[2005][2005]; +void helper() { + memset(dp, 0, sizeof(dp)); + for (int i = 0; i < p; i++) { dp[i][0] = 1; } + for (int x = 1; x < p; x++) { + for (int i = 1; i < p; i++) { dp[x][i] = ((dp[x][i - 1]) * x) % p; } + } +} +bool isPrimeRoot(int x) { + int curr = 0; + for (int k = 0; k < p - 2; k++) { + curr += dp[x][k]; + if (curr % p == 0 || (x - 1) % p == 0) { return false; } + } + curr = curr + dp[x][p - 2]; + if (curr % p != 0 && (x - 1) % p != 0) { return false; } + return true; +} +int solve() { + helper(); + int ans = 0; + for (int x = 1; x < p; x++) { + if (isPrimeRoot(x)) { ans++; } + } + return ans; +} +int main() { + cin >> p; + int ans = solve(); + cout << ans << endl; + return 0; +} +int main() { + int participants, bottles, towels; + int total_b = 0, total_t = 0, matches; + cin >> participants >> bottles >> towels; + total_t = participants * towels; + while (participants != 1) { + matches = participants / 2; + if (participants % 2 == 1) { + total_b += (participants - 1) * bottles + matches; + participants = participants / 2 + 1; + } else { + total_b += participants * bottles + matches; + participants = participants / 2; + } + } + cout << total_b << " " << total_t << endl; + return 0; +} +const double PI = acos(-1.0); +void fast_in_out() {} +void pause() {} +int dx[] = {0, 0, -1, -1, -1, 1, 1, 1}; +int dy[] = {-1, 1, 0, 1, -1, -1, 0, 1}; +const int N = 2e6 + 10; +bool prime[N]; +int vis[N]; +void sieve() { + prime[1] = prime[0] = 1; + for (long long i = 2; i < N; i++) + for (long long j = i * i; j < N && !prime[i]; j += i) prime[j] = 1; +} +int main() { + fast_in_out(); + int n, m; + cin >> n; + int sum = 0, ans = -1; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += x; + } + cin >> m; + for (int i = 0; i < m; i++) { + int l, r; + cin >> l >> r; + if (sum <= r) { + ans = max(l, sum); + break; + } + } + cout << ans << '\n'; + pause(); + return 0; +} +int main() { + int n, y; + cin >> n; + int x = n / 2; + for (int i = 0; i < x; i++) { + for (int j = 0; j < n; j++) { + if (j >= (x - i) && j <= (x + i)) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + for (int i = 0; i < n; i++) cout << "D"; + cout << endl; + for (int i = x - 1; i >= 0; i--) { + for (int j = 0; j < n; j++) { + if (j >= (x - i) && j <= (x + i)) + cout << "D"; + else + cout << "*"; + } + cout << endl; + } + return 0; +} +int n, c = 0; +vector a(1000); +int main() { + cin >> n; + for (__typeof(n) i = 0; i < (n); i++) cin >> a[i]; + for (__typeof(n - 2) i = 1; i <= (n - 2); i++) { + if (a[i - 1] > a[i] && a[i + 1] > a[i]) c++; + if (a[i - 1] < a[i] && a[i + 1] < a[i]) c++; + } + cout << c << "\n"; +} +int main() { + int a, b; + char ch[100]; + while (cin >> ch) { + a = strlen(ch) + 1; + b = (a * 25) + 1; + cout << b << endl; + } + return 0; +} +int main() { + long long n, y; + double x; + cin >> n; + if (n % 2 == 0 && n != 0) { cout << n / 2 << endl; } + if (n % 2 != 0 && n != 0) { + x = ceil((1. * n) / 2); + y = x; + cout << -y << endl; + } +} +int main() { + int N; + string poly; + long int faces = 0; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> poly; + if (poly == "Tetrahedron") { + faces += 4; + } else if (poly == "Cube") { + faces += 6; + } else if (poly == "Octahedron") { + faces += 8; + } else if (poly == "Dodecahedron") { + faces += 12; + } else if (poly == "Icosahedron") { + faces += 20; + } + } + cout << faces << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a; + cin >> b; + cin >> c; + int s(b), x(0); + while (s < a) { + s *= c; + ++x; + } + cout << x << endl; + return 0; +} +int main() { + int num; + cin >> num; + cout << num / 2 + 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string result = ""; + int top = -3000; + while (n--) { + string name; + int x, y, a, b, c, d, e; + cin >> name >> x >> y >> a >> b >> c >> d >> e; + int score = x * 100 - y * 50 + a + b + c + d + e; + if (score > top) { + top = score; + result = name; + } + } + cout << result << endl; + return 0; +} +const long long INF = (1ll << 62) - 1; +const long long M = 1e9 + 7; +long long modularExponentiation(long long x, long long y) { + int res = 1; + while (y > 0) { + if (y & 1) res = (res * x) % M; + y = y >> 1; + x = (x * x) % M; + } + return res; +} +int main() { + long long n; + cin >> n; + long long ans = modularExponentiation(2, n); + ans = (ans + (ans * ans)) / 2; + cout << ans % M << endl; +} +int main() { + int n, mod, x = 0; + cin >> n; + x += n / 100; + n = n % 100; + x += n / 20; + n = n % 20; + x += n / 10; + n = n % 10; + x += n / 5; + n = n % 5; + x += n; + cout << x << endl; + return 0; +} +int main() { + long long n, l, r, q1, q2; + cin >> n >> l >> r >> q1 >> q2; + long long arr[n]; + long long sum = 0; + for (long long i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + long long tempsum = 0; + long long temp = r * sum + (n - 1) * q2; + for (long long i = 0; i < n; i++) { + tempsum += arr[i]; + long long ans = 0; + long long y = n - i - 1; + long long x = i + 1; + ans += l * (tempsum); + ans += r * (sum - tempsum); + if (y > x + 1) { + ans += (q2 * (y - x - 1)); + } else if (x > y + 1) { + ans += (q1 * (x - y - 1)); + } + if (ans < temp) temp = ans; + } + cout << temp << endl; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int x = (k * l) / nl; + int y = c * d; + int z = p / np; + int w = min(x, min(y, z)); + cout << w / n << '\n'; + return 0; +} +int main() { + string s, t; + cin >> s >> t; + cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])) << "\n"; + while (s != t) { + if (s[0] < t[0]) { + cout << "R"; + s[0] += 1; + } else if (s[0] > t[0]) { + cout << "L"; + s[0] -= 1; + } + if (s[1] < t[1]) { + cout << "U"; + s[1] += 1; + } else if (s[1] > t[1]) { + cout << "D"; + s[1] -= 1; + } + cout << "\n"; + } +} +int main() { + int w, h; + int u1, d1; + int u2, d2; + cin >> w >> h; + cin >> u1 >> d1; + cin >> u2 >> d2; + for (int i = h; i > 0; i--) { + w = w + i; + if (i == d1) w = w - u1; + if (i == d2) w = w - u2; + if (w < 0) w = 0; + } + cout << w << endl; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) { cin >> v[i]; } + sort(v.begin(), v.end()); + int res = 2e9 + 5, cnt = 0; + for (int i = 0; i + 1 < n; i++) { res = min(res, v[i + 1] - v[i]); } + for (int i = 0; i + 1 < n; i++) { + if ((v[i + 1] - v[i]) == res) { cnt++; } + } + cout << res << " " << cnt << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[700] = {0}; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + a[t] = 1; + } + int sum = 0; + for (int i = 1; i <= 600; i++) { + if (a[i]) sum++; + } + cout << sum << endl; +} +const int maxn = 1e5 + 5; +int num[maxn] = {0}; +int n, ans = 1000000000; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> num[i]; + for (int i = 1; i <= n; i++) { + int cnt = 0; + for (int j = 1; j <= n; j++) cnt += 2 * num[j] * (abs(i - j) + abs(j - 1) + abs(1 - i)); + ans = min(cnt, ans); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int k = n - a; + cout << min(k, b + 1) << endl; + return 0; +} +int main() { + int n; + cin >> n; + n = n + n / 2; + cout << n << endl; +} +int main() { + string s1, s2; + int counter1 = 0, counter2 = 0; + cin >> s1; + cin >> s2; + for (int i = 0; i < s1.length(); i += 2) { + if (s1[i] == '8') { + if (s2[i] == '[') + counter1++; + else if (s2[i] == '(') + counter2++; + } else if (s1[i] == '(') { + if (s2[i] == '8') + counter1++; + else if (s2[i] == '[') + counter2++; + } else if (s1[i] == '[') { + if (s2[i] == '(') + counter1++; + else if (s2[i] == '8') + counter2++; + } + } + if (counter1 > counter2) + cout << "TEAM 1 WINS" << endl; + else if (counter1 < counter2) + cout << "TEAM 2 WINS" << endl; + else + cout << "TIE" << endl; +} +int main() { + int a, b; + cin >> a >> b; + vector x, y; + while (a) { + x.push_back(a % 10); + a /= 10; + } + while (b) { + y.push_back(b % 10); + b /= 10; + } + reverse(y.begin(), y.end()); + while (x.size() < y.size()) x.push_back(0); + while (y.size() < x.size()) y.push_back(0); + for (int i = 0; i < y.size(); i++) x[i] += y[i]; + long long ans = 0; + for (int i = x.size() - 1; i >= 0; i--) ans = (long long)10 * ans + (long long)x[i]; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char arr[n][m]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (arr[i][j] == '.') { + if ((i + j) % 2 == 0) { + arr[i][j] = 'B'; + } else { + arr[i][j] = 'W'; + } + } + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { cout << arr[i][j]; } + cout << endl; + } + return 0; +} +string a, b; +long long idx; +int main() { + cin >> a >> b; + for (int i = 0; i < a.size(); i++) + if (a[i] == '0') + idx++; + else + break; + a = a.substr(idx); + idx = 0; + for (int i = 0; i < b.size(); i++) + if (b[i] == '0') + idx++; + else + break; + b = b.substr(idx); + if (a.size() < b.size()) + cout << '<' << '\n'; + else if (a.size() > b.size()) + cout << '>' << '\n'; + else { + if (a < b) + cout << '<' << '\n'; + else if (a > b) + cout << '>' << '\n'; + else + cout << '=' << '\n'; + } + return 0; +} +long long t, s, q; +int main() { + int cnt = 1; + cin >> t >> s >> q; + while (1) { + if (s * q >= t) + break; + else { + s = s * q; + cnt++; + } + } + cout << cnt << endl; + return 0; +} +long long x, y; +int main() { + int T; + cin >> T; + while (T--) { + cin >> x >> y; + long long r = y % x; + cout << x << " " << y - r << "\n"; + } + return 0; +} +int main() { + long long int ans, x, y, x1, y1; + cin >> x >> y >> x1 >> y1; + ans = max(abs(x - x1), abs(y - y1)); + cout << ans << endl; +} +int main() { + int n, k, tmp, sum = 0; + cin >> n >> k; + vector input(k, 0); + for (int i = 0; i < n; i++) { + cin >> tmp; + input[i % k] += tmp; + sum += tmp; + } + int m = INT_MIN; + for (int i = 0; i < k; i++) { m = max(abs(input[i] - sum), m); } + cout << m << endl; + return 0; +} +const int N = 1e3 + 2, MOD = 1e9 + 7; +long long int pascal[N][N], ans, sum; +short int n, arr[N]; +int main() { + ans = 1; + memset(pascal, 0, sizeof pascal); + for (int i = 0; i < N; i++) + for (int j = 0; j <= i; j++) { + if (j == 0) + pascal[i][j] = 1; + else + pascal[i][j] = ((pascal[i - 1][j - 1] % MOD) + (pascal[i - 1][j] % MOD)) % MOD; + } + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + sum += arr[i]; + } + for (int i = n - 1; i > -1; i--) { + sum--; + ans = ((ans % MOD) * (pascal[sum][arr[i] - 1] % MOD)) % MOD; + ans % MOD; + sum -= arr[i]; + sum++; + } + cout << ans << endl; + return 0; +} +const int MX = 5000 + 10; +char s[MX]; +int main() { + cin >> s; + int n = strlen(s); + int ans = 0; + for (int i = 0; i < n; ++i) { + int a = 0, b = 0; + for (int j = i; j < n; ++j) { + if (s[j] == '(') + a++; + else if (s[j] == ')') + a--; + else + b++; + while (b > 0 && b > a) { + b--; + a++; + } + if (a < 0) break; + if ((j - i + 1) % 2 == 0 && b >= a) ans++; + } + } + cout << ans << endl; + return 0; +} +string str; +int B, u, l, b, a, s, r; +int main() { + cin >> str; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'B') B++; + if (str[i] == 'u') u++; + if (str[i] == 'l') l++; + if (str[i] == 'b') b++; + if (str[i] == 'a') a++; + if (str[i] == 's') s++; + if (str[i] == 'r') r++; + } + cout << min(B, min(u / 2, min(l, min(a / 2, min(s, min(b, r)))))) << endl; + return 0; +} +const int MX = 10005; +const int mod = 1000000007; +const long long inf = 1e18; +map mp; +int main() { + int n, m, i, j, k, x, y, z, tc, d; + char ch; + int cnt = 0, sm = 0; + string s, st; + while (getline(cin, s)) { + st = ""; + if (s[0] == '+') { + for (i = 1; i < s.size(); i++) st += s[i]; + if (!mp[st]) { + cnt++; + mp[st]++; + } + } else if (s[0] == '-') { + for (i = 1; i < s.size(); i++) st += s[i]; + if (mp[st]) { + cnt--; + mp[st]--; + } + } else { + int sz = s.size(); + for (i = 0; s[i] != ':'; i++) + ; + sz -= i; + sz--; + sm += (sz * cnt); + } + } + cout << sm << endl; + return 0; +} +int main() { + int t, i1, j1; + for (int i = 1; i <= 5; i++) { + for (int j = 1; j <= 5; j++) { + cin >> t; + if (t == 1) { + i1 = i; + j1 = j; + } + } + } + int ans = abs(3 - i1) + abs(3 - j1); + cout << ans << endl; +} +int n, f[5001]; +int main() { + cin >> n; + for (int i = 1; i <= n; i += 1) cin >> f[i]; + for (int i = 1; i <= n; i += 1) + if (f[f[f[i]]] == i) { + cout << "YES\n"; + return 0; + } + cout << "NO\n"; + return 0; +} +int main() { + int n; + cin >> n; + vector game(n); + int numOf0 = 0; + for (int i = 0; i < n; ++i) { + cin >> game[i]; + if (game[i] == 0) numOf0++; + } + if (numOf0 == 0 || numOf0 == n) { + cout << n << '\n'; + return 0; + } + int last0 = n - 1; + while (last0 >= 0 && game[last0] == 1) { last0--; } + int numOf1 = n - 1 - last0; + int ans = numOf0 + numOf1; + for (int i = last0; i >= 0; --i) { + if (game[i] == 1) { + numOf1++; + continue; + } else { + ans = max(ans, numOf0 + numOf1); + numOf0--; + } + } + cout << max(ans, numOf1) << '\n'; + return 0; +} +int main() { + int n; + int flag = 0; + cin >> n; + int a[105], b[105]; + int asum = 0; + int bsum = 0; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + if ((a[i] % 2 == 0 && b[i] % 2 != 0) || (a[i] % 2 != 0 && b[i] % 2 == 0)) { flag = 1; } + asum += a[i]; + bsum += b[i]; + } + if (asum % 2 == 0 && bsum % 2 == 0) + cout << 0 << endl; + else if (asum % 2 == 0 && bsum % 2 != 0) + cout << -1 << endl; + else if (asum % 2 != 0 && bsum % 2 == 0) + cout << -1 << endl; + else if (asum % 2 != 0 && bsum % 2 != 0 && n != 1) { + if (flag == 1) + cout << 1 << endl; + else + cout << -1 << endl; + } else + cout << -1 << endl; + return 0; +} +int main() { + int A, B, C, D, E; + cin >> A >> B; + C = A - 1; + D = B - 1; + E = C / D; + cout << E + A << endl; + return 0; +} +const int maxn = 15; +const int mod = 1000000007; +const double eps = 1e10 - 7; +char mat[8][8]; +int main() { + for (int i = 0; i < 8; i++) cin >> mat[i]; + int Mina = 999999, Minb = 999999; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (mat[j][i] == 'B') break; + if (mat[j][i] == 'W') { + Mina = min(Mina, j); + break; + } + } + } + for (int i = 0; i < 8; i++) { + for (int j = 7; j >= 0; j--) { + if (mat[j][i] == 'W') break; + if (mat[j][i] == 'B') { + Minb = min(Minb, 8 - j); + break; + } + } + } + if (Mina < Minb) + puts("A"); + else + puts("B"); + return 0; +} +int main() { + int n; + string s; + cin >> n; + while (n--) { + cin >> s; + if (s.length() > 10) { + cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; + } else { + cout << s << endl; + } + } + return 0; +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] > '9' - s[i] + '0') s[i] = '9' - s[i] + '0'; + if (s[0] == '0') s[0] = '9'; + } + cout << s << endl; +} +int main() { + int a1 = 0, a2 = 0, a3 = 0, a4 = 0; + int y; + cin >> y; + int n = y; + while (a1 == a2 || a1 == a3 || a1 == a4 || a2 == a3 || a2 == a4 || a3 == a4) { + n++; + a1 = n % 10; + a2 = n / 10 % 10; + a3 = n / 10 / 10 % 10; + a4 = n / 10 / 10 / 10 % 10; + } + cout << n << endl; + return 0; +} +char color[6] = {'R', 'O', 'Y', 'G', 'B', 'V'}; +vector v; +int tedad[300]; +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) tedad[s[i]]++; + vector v; + for (int i = 0; i < 6; i++) + if (tedad[color[i]]) v.push_back(tedad[color[i]]); + sort(v.begin(), v.end()); + if (v.size() == 1) + cout << 1 << endl; + else if (v.size() == 2) { + if (v[0] == 1) + cout << 1 << endl; + else + cout << 2 << endl; + } else if (v.size() == 3) { + if (v[0] == 1) { + if (v[1] == 1) + cout << 2 << endl; + else + cout << 3 << endl; + } else + cout << 6 << endl; + } else if (v.size() == 4) { + if (v[3] == 3) + cout << 5 << endl; + else if (v[3] == 2) + cout << 8 << endl; + } else if (v.size() == 5) + cout << 15 << endl; + else if (v.size() == 6) + cout << 30 << endl; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (b >= 3 * a) { + cout << 0 << endl; + } else { + cout << 3 * a - b << endl; + } + return 0; +} +int main() { + long long k, n, s, p; + cin >> k >> n >> s >> p; + long long single = ceil(1.0 * n / s); + long long amount = ceil(single * k); + long long end = ceil(1.0 * amount / p); + cout << end << endl; + return 0; +} +int main() { + long long a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + long long ans = (a + b + c) * (a + b + c) - a * a - c * c - e * e; + cout << ans << endl; + return 0; +} +int main() { + int a[10], b[10], i, j, k, n, nn, ans[10]; + while (cin >> n) { + for (i = 0; i < 3; i++) { cin >> a[i] >> b[i]; } + ans[0] = min(b[0], n - a[1] - a[2]); + ans[1] = min(b[1], n - ans[0] - a[2]); + ans[2] = n - ans[0] - ans[1]; + cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl; + } + return 0; +} +int main() { + char a[100]; + cin >> a; + int len = strlen(a); + int maxx = -1; + for (int i = 0; i < len; i++) { + if (a[i] > maxx) { maxx = a[i]; } + } + int cnt = 0; + for (int i = 0; i < len; i++) { + if ((int)a[i] == maxx) { cnt++; } + } + for (int i = 1; i <= cnt; i++) { cout << (char)maxx; } + cout << endl; + return 0; +} +int main() { + int n, arr[1001], c = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == 1) c++; + } + cout << c << endl; + for (int i = 1; i < n; i++) { + if (arr[i] == 1) { cout << arr[i - 1] << " "; } + } + cout << arr[n - 1] << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + string s[n]; + int best[n]; + for (int i = 0; i < n; i++) { + cin >> s[i]; + best[i] = 0; + } + for (int i = 0; i < m; i++) { + int best_score = -1; + for (int k = 0; k < n; k++) { + if (s[k][i] > best_score) { best_score = s[k][i]; } + } + for (int k = 0; k < n; k++) { + if (s[k][i] == best_score) { best[k]++; } + } + } + int count = 0; + for (int i = 0; i < n; i++) { + if (best[i] > 0) count++; + } + cout << count << endl; + return 0; +} +int ar[1000]; +int main() { + int n, k, x; + cin >> n >> k >> x; + for (int i = 0; i < n; i++) cin >> ar[i]; + int ans = 0; + for (int i = 0; i < n - k; i++) { ans += ar[i]; } + for (int i = n - k; i < n; i++) { ans += min(ar[i], x); } + cout << ans << endl; + return 0; +} +bool prim[1000007 + 7]; +queue q; +void seive() { + prim[1] = 1; + for (int i = 4; i <= 1000007; i += 2) prim[i] = 1; + int sq = sqrt(1000007); + for (int i = 3; i <= sq; i += 2) { + if (!prim[i]) + for (int j = i * i; j <= 1000007; j += 2 * i) prim[j] = 1; + } +} +int main() { + int n, m, a, b; + seive(); + cin >> n >> m; + for (int i = 2; i <= n; i++) { + if (!prim[i]) { + while (n % i == 0) { + q.push(i); + n /= i; + } + } + } + if (q.size() >= m) { + for (int i = 1; i <= m - 1; i++) { + cout << q.front() << " "; + q.pop(); + } + int x = 1; + while (!q.empty()) { + x *= q.front(); + q.pop(); + } + cout << x << endl; + } else + cout << "-1" << endl; +} +char p[5]; +int q[12] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; +int main() { + while (cin >> p) { + int t = int(p[0] - '0'); + int tt = int(p[1] - '0'); + int ans = q[t] * q[tt]; + cout << ans << endl; + } + return 0; +} +const long long mod = 1000000007; +long long powmod(long long a, long long b) { + long long res = 1; + a %= mod; + assert(b >= 0); + for (; b; b >>= 1) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + } + return res; +} +long long gcd(long long a, long long b) { + return b ? gcd(b, a % b) : a; +} +int main() { + int n; + cin >> n; + int _x = n / 10; + int _y = n % 10; + int ans1 = 0; + int ans2 = 0; + if (_x == 1) + ans1 = 7; + else if (_x == 2) + ans1 = 2; + else if (_x == 3) + ans1 = 3; + else if (_x == 4) + ans1 = 3; + else if (_x == 5) + ans1 = 4; + else if (_x == 6) + ans1 = 2; + else if (_x == 7) + ans1 = 5; + else if (_x == 8) + ans1 = 1; + else if (_x == 9) + ans1 = 2; + else if (_x == 0) + ans1 = 2; + if (_y == 1) + ans2 = 7; + else if (_y == 2) + ans2 = 2; + else if (_y == 3) + ans2 = 3; + else if (_y == 4) + ans2 = 3; + else if (_y == 5) + ans2 = 4; + else if (_y == 6) + ans2 = 2; + else if (_y == 7) + ans2 = 5; + else if (_y == 8) + ans2 = 1; + else if (_y == 9) + ans2 = 2; + else if (_y == 0) + ans2 = 2; + cout << ans1 * ans2 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string c, s; + map m; + for (int i = 0; i < n; i++) { + cin >> c >> s; + int x = 0, k = 1; + for (int i = s.size() - 1; i >= 0; i--) { + if ((s[i] - 48) % 2 == 1) x += k; + k *= 2; + } + if (c == "+") m[x]++; + if (c == "-") m[x]--; + if (c == "?") cout << m[x] << endl; + x = 0; + k = 1; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (max(3 * a / 10, a - a / 250 * c) == max(3 * b / 10, b - b / 250 * d)) + cout << "Tie" << endl; + else { + if (max(3 * a / 10, a - a / 250 * c) > max(3 * b / 10, b - b / 250 * d)) + cout << "Misha" << endl; + else + cout << "Vasya" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int ara[n]; + for (int i = 0; i < n; i++) cin >> ara[i]; + sort(ara, ara + n); + if (n == 1) + cout << ara[0]; + else if (n == 3) + cout << ara[1]; + else + cout << ara[2]; + cout << endl; + return 0; +} +int main() { + int n, a, b, sum; + int i, j; + int c[105], d[105]; + while (cin >> n) { + sum = 0; + for (i = 0; i < n; i++) { + cin >> a >> b; + c[i] = a; + d[i] = b; + } + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (c[i] == d[j]) sum++; + cout << sum << endl; + } + return 0; +} +int main() { + int n, x, y, x1 = 0, x_1 = 0; + cin >> n; + while (n--) { + cin >> x >> y; + if (x > 0) + x1++; + else if (x < 0) + x_1++; + } + if (x1 >= 2 && x_1 >= 2) + cout << "No" << endl; + else + cout << "Yes" << endl; +} +int n, sum, arr[1000]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int min = arr[0], max = arr[0]; + for (int i = 1; i < n; i++) { + if (arr[i] < min) { + min = arr[i]; + sum++; + } + if (arr[i] > max) { + max = arr[i]; + sum++; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector a(n); + int curr = 0; + int goal = k; + int count = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + curr = curr + a[i]; + int maxGive = min(8, curr); + curr = curr - maxGive; + goal = goal - maxGive; + if (goal <= 0) { + ; + } else { + count++; + } + } + if (goal > 0) { count = -2; } + cout << count + 1 << endl; + return 0; +} +int check(string str) { + int sum = 0; + for (int j = 0; j < str.size(); j++) + if (str[j] == '4' || str[j] == '7') sum++; + return sum; +} +int main() { + int n, k, cnt = 0; + string integer; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> integer; + int res = check(integer); + if (res <= k) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + string name[n + 5], tag[n + 5], l; + for (int i = 0; i < n; ++i) { cin >> name[i] >> tag[i]; } + for (int i = 0; i < 5; ++i) { + for (int j = 0; j < n; ++j) { + if (i == 1 && tag[j] == "rat") { cout << name[j] << endl; } + if (i == 2 && tag[j] == "woman") { cout << name[j] << endl; } + if (i == 2 && tag[j] == "child") { cout << name[j] << endl; } + if (i == 3 && tag[j] == "man") { cout << name[j] << endl; } + if (i == 4 && tag[j] == "captain") { cout << name[j] << endl; } + } + } + return 0; +} +long long int mod = 1000000007; +int main() { + int a, b, r; + cin >> a >> b >> r; + if (2 * r > min(a, b)) { + cout << "Second" << endl; + } else { + cout << "First" << endl; + } + return 0; +} +int main() { + int x; + cin >> x; + int c = 0; + c = x / 5; + if (x % 5) c++; + cout << c << endl; + return 0; +} +int main() { + int t; + cin >> t; + long long a, b, p, q, x, y, k, l, r, m; + while (t--) { + cin >> a >> b >> p >> q; + if (p == q && a < b) { + cout << "-1\n"; + continue; + } else if (p == 0) { + if (a == 0) + cout << "0\n"; + else + cout << "-1\n"; + continue; + } else if (a * q == p * b) { + cout << "0\n"; + continue; + } + l = 0, r = 0x7fffffffffffffff; + r /= q; + r++; + m = (l + r) >> 1; + while (r > l + 1) { + if (a <= m * p && m * (q - p) >= b - a) + r = m; + else + l = m; + m = (l + r) >> 1; + } + cout << r * q - b << endl; + } + return 0; +} +int main() { + int n; + int s = 0, f = 0; + cin >> n; + while ((n - (4 * f)) % 7 != 0 && 4 * f < n) f++; + s = floor((n - (4 * f)) / 7); + int i; + if ((4 * f) + (7 * s) != n) { + cout << -1 << endl; + return 0; + } + for (i = 0; i < f; i++) cout << 4; + for (i = 0; i < s; i++) cout << 7; + cout << endl; +} +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long p = sqrt(a * b * c); + long long res = 0; + res += (p / a + p / b + p / c); + cout << res * 4 << endl; +} +int main() { + long long n; + cin >> n; + cout << 2 - (n % 2) << endl; + return 0; +} +int main() { + int a, b, c, r; + cin >> a >> b >> c; + r = ((a - b) * c + (b - 1)) / b; + cout << r << endl; + return 0; +} +int main() { + int n, a, b; + while (cin >> n >> a >> b) { + int cnt = 0; + n -= a; + if (n <= (b + 1)) { + cout << n << endl; + break; + } else + cout << b + 1 << endl; + } + return 0; +} +long long int f[1000000]; +int main() { + long long int n, i, x; + while (cin >> n) { + memset(f, 0, sizeof(f)); + while (n--) { + char ch; + cin >> ch; + if (ch == '+') { + cin >> x; + long long int s = 0, cn = 0; + while (x != 0) { + long long int p = x % 10; + if (p % 2 == 1) s += (1 << cn); + cn++; + x /= 10; + } + f[s]++; + } else if (ch == '-') { + cin >> x; + long long int s = 0, cn = 0; + while (x != 0) { + long long int p = x % 10; + if (p % 2 == 1) s += (1 << cn); + cn++; + x /= 10; + } + f[s]--; + } else { + string t; + cin >> t; + reverse(t.begin(), t.end()); + long long int s = 0; + for (i = 0; i < t.size(); i++) { + if (t[i] == '1') s += (1 << i); + } + cout << f[s] << endl; + } + } + } + return 0; +} +int main() { + int n, p; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p; + if (!(p - 1)) { + cout << -1 << endl; + return 0; + } + } + cout << 1 << endl; + return 0; +} +int main() { + int X[4], sum = 0; + int max1 = -10; + int min1 = 10000; + int mid; + for (int i = 0; i < 3; i++) { + cin >> X[i]; + if (X[i] > max1) max1 = X[i]; + if (X[i] < min1) min1 = X[i]; + } + for (int i = 0; i < 3; i++) { + if (min1 < X[i] < max1) mid = X[i]; + } + sum = (max1 - mid) + (mid - min1); + cout << sum << endl; + return 0; +} +int main() { + long long int t, n, x, tot = 0; + cin >> n >> t; + for (int i = 1; i <= n; i++) { + cin >> x; + tot += (86400 - x); + if (tot >= t) { + cout << i << endl; + break; + } + } + return 0; +} +long long int MIN(long long int a, long long int b) { + if (a > b) + return b; + else + return a; +} +long long int MAX(long long int a, long long int b) { + if (a > b) + return a; + else + return b; +} +long long int MOD(long long int x) { + if (x >= 0) + return x; + else + return -x; +} +int main() { + long long int k; + cin >> k; + vector v; + vector::iterator it; + ; + for (int i = 1; i <= 12; i++) { + long long int d; + cin >> d; + v.push_back(d); + } + sort(v.begin(), v.end()); + long long int c = 0, sum = 0, f = 0; + for (int i = v.size() - 1; i >= 0; i--) { + if (sum >= k) { + f = 1; + break; + } + c++; + sum += v[i]; + if (sum >= k) { + f = 1; + break; + } + } + if (f == 1) + cout << c << endl; + else + cout << -1 << endl; + return 0; +} +const int maxn = 2e5 + 10; +const double pi = 3.1415926; +int k, a, b, v; +int ans = 0; +int main() { + cin >> k >> a >> b >> v; + while (a > 0) { + int x; + while (b > 0) { + if (a <= 0) break; + if (b >= k) { + x = k - 1; + b -= x; + a -= k * v; + ans++; + } else { + x = b; + b -= x; + a -= (x + 1) * v; + ans++; + } + } + if (a > 0) { + a -= v; + ans++; + } + } + cout << ans << endl; +} +int main() { + long long int n, x, i, cnt = 0; + cin >> n >> x; + for (i = 1; i <= n; i++) { + if (x % i == 0 && x <= (i * n)) cnt++; + } + cout << cnt << endl; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 2) { + if (m == 1) + cout << 4 << endl; + else + cout << 5 << endl; + } else if (n == 4 || n == 6 || n == 9 || n == 11) { + if (m >= 1 && m <= 6) + cout << 5 << endl; + else + cout << 6 << endl; + } else { + if (m >= 1 && m <= 5) + cout << 5 << endl; + else + cout << 6 << endl; + } + return 0; +} +int main() { + int n; + int t; + cin >> n; + cin >> t; + int tab[n]; + for (int i = 0; i < n; i++) { cin >> tab[i]; } + int j = 0; + while (j < n && t > 0) { + t -= (86400 - tab[j]); + j++; + } + cout << j << endl; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int count = 0; + for (int i = n; i > 0; i--) { + int a = s / i; + count = count + a; + s = s % i; + if (s == 0) { break; } + } + cout << count << endl; + return 0; +} +int main() { + int c = 0; + cin >> c; + while (c--) { + int n; + cin >> n; + if (360 % (180 - n) == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + int m, n, ans, a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + cin >> m >> n; + cout << (a[m - 1] + 5 + n) / 7 << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int c74 = 0, c47 = 0; + for (int i = 0; i <= a.size() - 1; i++) { + if (a[i] == '7' && b[i] == '4') c74++; + if (a[i] == '4' && b[i] == '7') c47++; + } + cout << max(c47, c74) << endl; +} +int main() { + string n; + int f = 0; + cin >> n; + for (int i = 0; i < n.length(); i++) { + if (n[i] == '4' || n[i] == '7') f++; + } + if (f == 7 || f == 4) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + ; + long long int i, j, k, l, z, x, c, v, b = 0, n, m = 0; + cin >> n >> k; + x = n % 6; + if (x == 0) + m = k; + else if (x == 1) { + if (k == 0) + m = 1; + else if (k == 1) + m = 0; + else + m = 2; + } else if (x == 2) { + if (k == 0) + m = 1; + else if (k == 1) + m = 2; + else + m = 0; + } else if (x == 3) { + if (k == 0) + m = 2; + else if (k == 1) + m = 1; + else + m = 0; + } else if (x == 4) { + if (k == 0) + m = 2; + else if (k == 1) + m = 0; + else + m = 1; + } else if (x == 5) { + if (k == 0) + m = 0; + else if (k == 1) + m = 2; + else + m = 1; + } + cout << m << endl; + return 0; +} +int main() { + long long a, b, c; + long long n, i, left, right, ans = 0; + cin >> a >> b >> c >> n; + if (b > c) { + long long ttem = b; + b = c; + c = ttem; + } + if (a < b) { + left = 1; + right = b - 1; + } else if (c < a) { + left = c + 1; + right = 1000000001; + } else { + left = b + 1; + right = c - 1; + } + for (i = 1; i <= n; i++) { + long long ttem; + cin >> ttem; + if (ttem >= left && ttem <= right) { ans++; } + } + cout << ans << endl; + return 0; +} +const int MAX = 2009; +int main() { + int n; + cin >> n; + long long tmp = 2; + for (long long i = 1; i <= n; i++) { + long long p = (i + 1) * (i + 1) * i; + cout << p - (tmp / i) << endl; + tmp = (p - tmp) / i; + } + return 0; +} +void solve() { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (x != y && p == q) { + cout << -1 << endl; + return; + } + long long ans = -1; + long long l = 0, r = 1000000000; + while (l <= r) { + long long mid = (l + r) / 2; + if (mid * p - x <= mid * q - y && (mid * p - x >= 0 && mid * q - y >= 0)) { + ans = mid * q - y; + r = mid - 1; + } else + l = mid + 1; + } + cout << ans << endl; +} +int main() { + int t; + cin >> t; + while (t--) { solve(); } + return 0; +} +const int Max = 10055; +long long gcd(long long a, long long b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return (a * (b / gcd(a, b))); +} +int main() { + int n, k; + string s; + cin >> n >> k >> s; + if (k > s.length() / 2) { + for (int i = k; i < s.length(); i++) cout << "RIGHT" << endl; + cout << "PRINT " << s[s.length() - 1] << endl; + for (int i = s.length() - 2; i >= 0; i--) cout << "LEFT" << endl << "PRINT " << s[i] << endl; + } else { + for (int i = k - 1; i > 0; i--) cout << "LEFT" << endl; + cout << "PRINT " << s[0] << endl; + for (int i = 1; i < s.length(); i++) cout << "RIGHT" << endl << "PRINT " << s[i] << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + map m; + vector a(n); + for (int i = 0; i < n; ++i) { + cin >> a[i]; + m[a[i]]++; + } + if (m[a[0]] == n) { + cout << 0 << endl; + return 0; + } + for (int j = 0; j < n; ++j) { + int x = a[j + k - 1]; + m[x]++; + m[a[j]]--; + a.push_back(x); + if (m[x] == n) { + cout << j + 1 << endl; + return 0; + } + } + cout << -1 << endl; +} +int main() { + int i, j, n, max, count = 1; + long long int a[100005]; + cin >> n; + max = 1; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i - 1] < a[i] && i != 0) { + count++; + if (max < count) max = count; + } else + count = 1; + } + cout << max << endl; + return 0; +} +int n; +int main() { + int x, y; + cin >> n; + for (int i = 1; i <= n; i++) cin >> x; + for (int i = 1; i <= n; i++) cin >> y; + cout << "Karen" << endl; + return 0; +} +int main() { + long long n, i, j, k, sum; + while (cin >> n) { + int arr[101][101] = {0}, x1, x2, y1, y2; + for (i = 1; i <= 100; i++) memset(arr[i], 0, sizeof arr[i]); + sum = 0; + for (i = 0; i < n; i++) { + cin >> x1 >> x2 >> y1 >> y2; + for (j = x1; j <= y1; j++) { + for (k = x2; k <= y2; k++) { arr[j][k]++; } + } + } + for (i = 1; i <= 100; i++) { + for (j = 1; j <= 100; j++) { sum += arr[i][j]; } + } + cout << sum << endl; + } +} +int p[5], a, b; +int ans = 0; +int main() { + cin >> p[1] >> p[2] >> p[3] >> p[4] >> a >> b; + int Min = min(min(min(p[1], p[2]), p[3]), p[4]); + if (a < Min) { + ans += (Min - a); + if (b >= Min) { + cout << ans << endl; + return 0; + } + ans = b - a + 1; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + char c[55]; + cin >> n >> k; + cin >> c; + sort(c, c + n); + char pre = c[0]; + int cs = 1, sum = pre - 'a' + 1; + for (int i = 1; i < n; i++) { + if (cs == k) { break; } + if (c[i] - pre > 1) { + sum += c[i] - 'a' + 1; + pre = c[i]; + cs++; + } + } + if (cs == k) + cout << sum << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int i = 0; + while (s[i] == '1') { i++; } + cout << min(i + 1, (int)s.size()) << endl; + return 0; +} +int a, b, c; +int main() { + while (cin >> a >> b >> c) { cout << max(a, max(b, c)) - min(a, min(b, c)) << endl; } + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long ans; + if (n > m) + ans = min(((m - n % m) % m) * a, (n % m) * b); + else { + if (n % m == 0) + ans = 0; + else { + ans = (n + (m - n % m) % m) / m; + ans = min((ans * m - n) * a, (n - (n / m) * m) * b); + } + } + cout << ans << endl; + return 0; +} +const int maxn = 1e5 + 2; +long long a[maxn * 2]; +int main() { + int n; + cin >> n; + long long m = n * 2; + for (int i = 1; i <= m; i++) { cin >> a[i]; } + sort(a + 1, a + m + 1); + long long ans = 1e18; + for (int i = 1; i <= n; i++) { + if (i == 1) { + ans = min(ans, (a[n] - a[1]) * (a[m] - a[n + 1])); + } else { + ans = min(ans, (a[m] - a[1]) * (a[n + i - 1] - a[i])); + } + } + cout << ans << endl; + return 0; +} +int main() { + char s[100001]; + int n, k; + while (cin >> n >> k) { + int a[1001]; + int kk = -1, cnt = 0, flag = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] <= k && flag == 0) { + cnt++; + kk = i; + } else + flag = 1; + } + for (int i = n - 1; i > kk; i--) + if (a[i] <= k) + cnt++; + else + break; + cout << cnt << endl; + } +} +int main() { + string x, y, ans = ""; + cin >> x >> y; + for (int i = 0; i < x.size(); i++) { + if (x[i] == y[i]) + ans += '0'; + else + ans += '1'; + } + cout << ans << endl; + return 0; +} +const int N = 100 + 5; +int m, n, res, a[N][N], best[N]; +string s; +void Input() { + cin >> m >> n; + for (int i = 1; i <= m; i++) { + cin >> s; + for (int j = 0; j < s.size(); j++) a[i][j + 1] = s[j] - 48; + } +} +void Solve() { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) best[i] = max(best[i], a[j][i]); + } + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == best[j]) { + res++; + break; + } + } + } + cout << res << '\n'; +} +int main() { + Input(); + Solve(); + return 0; +} +int main() { + int n, k; + cin >> n >> k; + vector arr; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + arr.push_back(x); + } + bool same = true; + for (int i = --k; i < n && same; i++) { same = arr[i] == arr[k]; } + if (!same) { + cout << "-1" << endl; + return 0; + } + int ans = -1; + for (int i = 0; i < n; i++) { + if (arr[i] != arr[k]) { ans = max(ans, i); } + } + cout << ans + 1 << endl; + return 0; +} +int main() { + int n, m, min_n = 101, max_n = 0, min_m = 101, a; + cin >> n >> m; + for (int i = 0; i < n; i++) { + cin >> a; + if (a > max_n) { max_n = a; } + if (a < min_n) { min_n = a; } + } + if (2 * min_n > max_n) { max_n = 2 * min_n; } + for (int i = 0; i < m; i++) { + cin >> a; + if (a < min_m) { min_m = a; } + } + if (min_m <= max_n) { + cout << -1 << endl; + return 0; + } + cout << max_n << endl; + return 0; +} +int main() { + int n, i, j, ans, x; + ans = 0; + cin >> n; + int a[n], b[n]; + vector mp(30000000, 0); + j = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + mp[a[i]] = 1; + } + for (i = 0; i < n; i++) { + cin >> b[i]; + mp[b[i]] = 1; + } + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + x = a[i] ^ b[j]; + if (mp[x] == 1) ans++; + } + } + if (ans % 2 == 0) + cout << "Karen\n"; + else + cout << "Koyomi\n"; +} +int main() { + int a, b, c, index; + while (cin >> a >> b >> c) { + index = 0; + for (int i = a; i <= c; i += a) + for (int j = b; j <= i; j += b) + if (i == j) { index++; } + cout << index << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + unsigned long long s, a, b, c, x; + cin >> s >> a >> b >> c; + x = s / c; + if (x < a) { + cout << x << endl; + } else { + cout << ((x / a) * b) + x << endl; + } + } +} +int Mininum(long long a, long long b) { + if (b >= a) swap(a, b); + long long c; + for (c = b; c % a != 0; c += b) + ; + return c; +} +int main() { + string a, b; + long long n; + cin >> n >> a >> b; + int l1 = a.length(), l2 = b.length(); + long long both = Mininum(l1, l2); + short prog[both] = {0}; + for (int i = 0; i < both; i++) { + if (a[i % l1] == 'P') { + if (b[i % l2] == 'P') { + prog[i] = 0; + } else if (b[i % l2] == 'R') { + prog[i] = 1; + } else { + prog[i] = 2; + } + } else if (a[i % l1] == 'R') { + if (b[i % l2] == 'P') { + prog[i] = 2; + } else if (b[i % l2] == 'R') { + prog[i] = 0; + } else { + prog[i] = 1; + } + } else { + if (b[i % l2] == 'P') { + prog[i] = 1; + } else if (b[i % l2] == 'R') { + prog[i] = 2; + } else { + prog[i] = 0; + } + } + } + int loss1 = 0, loss2 = 0, rl1, rl2; + for (int i = 0; i < both; i++) { + if (prog[i] != 0) { + if (prog[i] == 1) { + loss2++; + } else { + loss1++; + } + } + } + rl1 = n / both * loss1; + rl2 = n / both * loss2; + for (int i = 0; i < n % both; i++) { + if (prog[i] == 1) rl2++; + if (prog[i] == 2) rl1++; + } + cout << rl1 << ' ' << rl2 << endl; + return 0; +} +int main() { + long long int n, a, b, s = 0, c, d, e, f, i; + string p, q; + cin >> n; + cin >> p; + cin >> q; + for (i = 0; i < n; i++) { + a = p[i] % 10; + b = q[i] % 10; + p[i] = p[i] / 10; + q[i] = q[i] / 10; + c = b - a; + f = a - b; + d = (9 - a) + b + 1; + e = (9 - b) + a + 1; + if (e < 0) e *= -1; + if (f < 0) f *= -1; + if (c < 0) c *= -1; + if (d < 0) d *= -1; + if (e < d) d = e; + if (f < c) c = f; + s += min(c, d); + } + cout << s << endl; + return 0; +} +vector v1; +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + long long a, b, k; + cin >> a >> b >> k; + v1.push_back((a * ((k / 2) + (k % 2))) - (b * (k / 2))); + } + for (int i = 0; i < t; i++) cout << v1[i] << "\n"; + return 0; +} +int main() { + int N, K, C; + cin >> N >> K >> C; + int v[4000]; + for (int i = 1; i <= C; ++i) { + int x; + cin >> x; + v[x] = 1; + } + int last = 0, ans = 0; + for (int day = 0; day <= N; ++day) { + if (v[day]) { + ++ans; + last = day; + } else if (day - last == K) { + ++ans; + last = day; + } + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, s, ansh = -1, ansm = -1; + int hh[105], mm[105]; + cin >> n >> s; + hh[0] = 0; + mm[0] = 0; + for (int i = 1; i <= n; i++) { cin >> hh[i] >> mm[i]; } + if (hh[1] * 60 + mm[1] >= s + 1) { + ansh = 0; + ansm = 0; + } else { + for (int i = 1; i <= n; i++) { + if ((hh[i] - hh[i - 1]) * 60 + mm[i] - mm[i - 1] - 2 >= s * 2) { + ansh = hh[i - 1] + ((s + 1) / 60); + ansm = mm[i - 1] + ((s + 1) % 60); + while (ansm > 59) { + ansm -= 60; + ansh++; + } + break; + } + } + if (ansh == -1) { + ansh = hh[n] + ((s + 1) / 60); + ansm = mm[n] + ((s + 1) % 60); + while (ansm > 59) { + ansm -= 60; + ansh++; + } + } + } + cout << ansh << " " << ansm << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 != 0) + n--; + else + n /= 10; + } + cout << n << endl; + return 0; +} +long long spf[100001]; +long long gcd(long long a, long long b); +long long palindrome(string s); +long long modexp(long long a, long long b, long long m); +void sieve(); +long long ceil(long long a, long long b); +vector getFactorization(long long x); +void getZarr(string str, long long Z[]); +vector prefix_function(string s); +int main() { + long long n; + cin >> n; + long long a[n]; + for (long long i = 0; i < n; i++) { cin >> a[i]; } + long long x = gcd(a[0], a[1]); + for (long long i = 2; i < n; i++) { x = gcd(x, a[i]); } + long long mx = INT_MIN; + for (long long i = 0; i < n; i++) { a[i] = a[i] / x; } + for (long long i = 0; i < n; i++) mx = max(a[i], mx); + long long y = mx - n; + if (y % 2 == 0) { + cout << "Bob" << endl; + } else + cout << "Alice" << endl; +} +long long gcd(long long a, long long b) { + if (a == 0) return b; + if (b == 0) return a; + if (a == b) return a; + if (a > b) return gcd(a % b, b); + return gcd(a, b % a); +} +long long palindrome(string s) { + long long l = 0; + long long h = s.length() - 1; + while (h > l) { + if (s[l++] != s[h--]) { return 0; } + } + return 1; +} +long long modexp(long long a, long long b, long long m) { + if (b == 0) return 1; + long long temp = modexp(a, b / 2, m); + temp = (temp * temp) % m; + if (b & 1) return (temp * (a % m)) % m; + return temp; +} +void sieve() { + spf[1] = 1; + for (long long i = 2; i < 100001; i++) spf[i] = i; + for (long long i = 4; i < 100001; i += 2) spf[i] = 2; + for (long long i = 3; i * i < 100001; i++) { + if (spf[i] == i) { + for (long long j = i * i; j < 100001; j += i) + if (spf[j] == j) spf[j] = i; + } + } +} +vector getFactorization(long long x) { + vector ret; + while (x != 1) { + ret.push_back(spf[x]); + x = x / spf[x]; + } + return ret; +} +long long ceil(long long a, long long b) { + return a / b + (a % b != 0); +} +void getZarr(string str, long long Z[]) { + long long n = str.length(); + long long L, R, k; + L = R = 0; + for (long long i = 1; i < n; ++i) { + if (i > R) { + L = R = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } else { + k = i - L; + if (Z[k] < R - i + 1) + Z[i] = Z[k]; + else { + L = i; + while (R < n && str[R - L] == str[R]) R++; + Z[i] = R - L; + R--; + } + } + } +} +vector prefix_function(string s) { + long long n = (long long)s.length(); + vector pi(n); + for (long long i = 1; i < n; i++) { + long long j = pi[i - 1]; + while (j > 0 && s[i] != s[j]) j = pi[j - 1]; + if (s[i] == s[j]) j++; + pi[i] = j; + } + return pi; +} +int main() { + int n; + cin >> n; + int v[n]; + for (int q = 0; q < n; q++) { cin >> v[q]; } + int ans = 0; + for (int q = 1; q < n - 1; q++) { + if (v[q] > v[q - 1] && v[q] > v[q + 1]) { + ans++; + } else if (v[q] < v[q - 1] && v[q] < v[q + 1]) { + ans++; + } + } + cout << ans << endl; +} +int main() { + long long n, m; + cin >> n; + vector a(n + 2); + map mp; + map tr; + map trunc; + long long qbe = 0; + long long hj = 0; + long long html = 0; + long long jjj = 1e9; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 1) { + mp[qbe] = i + 1; + qbe++; + } else if (a[i] == 2) { + tr[hj] = i + 1; + hj++; + } else if (a[i] == 3) { + trunc[html] = i + 1; + html++; + } + jjj = min((int)(mp.size()), min((int)(tr.size()), (int)(trunc.size()))); + } + cout << jjj << endl; + for (int q = 0; q < jjj; q++) cout << mp[q] << ' ' << tr[q] << ' ' << trunc[q] << endl; + return 0; +} +int main() { + int i, j, l, test = 0, ans, len; + char str[1003], ch; + double maps = 0, k; + cin >> l; + for (i = 0; i < l; i++) { + cin >> str; + if (strcmp(str, "ABSINTH") == 0) { + test++; + } else if (strcmp(str, "BEER") == 0) { + test++; + } else if (strcmp(str, "BRANDY") == 0) { + test++; + } else if (strcmp(str, "CHAMPAGNE") == 0) { + test++; + } else if (strcmp(str, "GIN") == 0) { + test++; + } else if (strcmp(str, "RUM") == 0) { + test++; + } else if (strcmp(str, "SAKE") == 0) { + test++; + } else if (strcmp(str, "TEQUILA") == 0) { + test++; + } else if (strcmp(str, "VODKA") == 0) { + test++; + } else if (strcmp(str, "WHISKEY") == 0) { + test++; + } else if (strcmp(str, "WINE") == 0) { + test++; + } else if (str[0] >= 48 && str[0] <= 57) { + len = strlen(str); + k = 0; + maps = 0; + for (j = len - 1; j >= 0; j--) { + str[j] = str[j] - '0'; + maps = maps + (str[j] * pow(10.0, k)); + k++; + } + ans = (int)maps; + if (ans < 18) { test++; } + } + } + cout << test << endl; +} +const int MAXN = (int)(2 * 1e5 + 5); +int n; +long long a[MAXN]; +int main() { + cin >> n; + for (int i = 0; i < n + n; i++) { cin >> a[i]; } + sort(a, a + n + n); + if (n <= 1) { + cout << "0" << endl; + } else { + long long ans = a[n - 1] - a[0]; + ans *= a[n + n - 1] - a[n]; + long long l = a[n + n - 1] - a[0]; + for (int i = 1; i <= n; i++) { ans = min(ans, l * (a[i + n - 1] - a[i])); } + cout << ans << endl; + } +} +int main() { + int a, b, c, n, collect = 0; + int notes[100000]; + cin >> a >> b >> c; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> notes[i]; + if (notes[i] > b && notes[i] < c) collect++; + } + cout << collect << endl; + return 0; +} +int main() { + int N, M; + cin >> N >> M; + N = min(N, 30); + cout << M % (1 << N) << '\n'; + return 0; +} +int main() { + int n, sum = 0, sum1 = 0, count = 0; + cin >> n; + vector v(n); + for (int i = 0; i < v.size(); i++) { + cin >> v[i]; + sum += v[i]; + } + sort(v.rbegin(), v.rend()); + for (int i = 0; i <= v.size() - 1; i++) { + if (sum1 > sum / 2) break; + count++; + sum1 += v[i]; + } + cout << count << endl; + return 0; +} +long long int arr[1000000]; +bool flag = true; +char ch[4][4]; +int main() { + int k; + int n; + int x, y; + int sum = 0; + cin >> n; + cin >> k; + for (size_t i = 0; i < n; i++) { + cin >> x; + cin >> y; + sum += (y - x) + 1; + } + sum = sum % k; + if (sum == 0) + cout << sum << endl; + else { + cout << k - sum << endl; + ; + } + return 0; +} +int main() { + priority_queue q; + int n, x, y, temp = 0, t; + cin >> n >> x; + for (int i = 2; i <= n; i++) { + cin >> y; + if (y >= x) q.push(y); + } + while (!q.empty()) { + t = q.top(); + q.pop(); + if (t >= x) { + t--; + x++; + q.push(t); + temp++; + } + } + cout << temp << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + vector b(n); + for (size_t i = 0; i < n; i++) cin >> a[i]; + for (size_t i = 0; i < n; i++) cin >> b[i]; + int ai = 0, bi = 0; + for (size_t i = 0; i < n; i++) { + ai |= a[i]; + bi |= b[i]; + } + cout << ai + bi << '\n'; + return 0; +} +int getNextGap(int gap) { + gap = (gap * 10) / 13; + if (gap < 1) return 1; + return gap; +} +void combSort(long long int a[], long long int n) { + int gap = n; + bool swapped = true; + while (gap != 1 || swapped == true) { + gap = getNextGap(gap); + swapped = false; + for (int i = 0; i < n - gap; i++) { + if (a[i] > a[i + gap]) { + swap(a[i], a[i + gap]); + swapped = true; + } + } + } +} +int main() { + long long int numberOfElements; + cin >> numberOfElements; + long long int arr[numberOfElements]; + for (int i = 0; i < numberOfElements; i++) { cin >> arr[i]; } + combSort(arr, numberOfElements); + int counter = 0; + for (int i = 0; i < numberOfElements; i++) { + if (arr[i] == 0) { continue; } + if (arr[i] == arr[i + 1]) { + counter++; + if (arr[i + 1] == arr[i + 2]) { + cout << "-1" << endl; + return 0; + } + } + } + cout << counter << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.size(); + int flag1 = 0, flaga = 0, flagA = 0; + if (len >= 5) { + for (int i = 0; i < len; i++) { + if (s[i] >= '0' && s[i] <= '9') { flag1 = 1; } + if (s[i] >= 'a' && s[i] <= 'z') { flaga = 2; } + if (s[i] >= 'A' && s[i] <= 'Z') { flagA = 1; } + } + } + if (flag1 == 1 && flaga == 2 && flagA == 1) { + cout << "Correct" << endl; + } else + cout << "Too weak" << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + long long a, b, k, ans; + cin >> a >> b >> k; + ans = (k / 2) * (a - b); + if (k & 1) + cout << ans + a << "\n"; + else + cout << ans << "\n"; + } + return 0; +} +int t, n, m, i, j, ans, k, a, b, c, d, e, sz, q, x; +string s, s2, s3, s4, s5, s6; +long long int ar[(int)(1e6 + 10)]; +priority_queue pq; +void brainfuck(); +int main() { + brainfuck(); + return 0; +} +void brainfuck() { + long long int x, y, z, w; + cin >> q; + while (q--) { + cin >> x >> y >> z; + if (z & 1) { + w = x * (z / 2 + 1); + w -= y * (z / 2); + } else { + w = x * (z / 2); + w -= y * (z / 2); + } + cout << w << "\n"; + } +} +int main() { + int n, ans = 0; + while (cin >> n) { cout << n / 2 + 1 << endl; } +} +int main() { + long long a, b; + cin >> a >> b; + if (a == 0) { + cout << -1 * b * b << endl; + for (int(i) = (0); (i) < (b); ++(i)) cout << 'x'; + cout << endl; + } else if (b == 0) { + cout << a * a << endl; + for (int(i) = (0); (i) < (a); ++(i)) cout << 'o'; + cout << endl; + } else if (b == 1) { + cout << a * a - 1 << endl; + for (int(i) = (0); (i) < (a); ++(i)) cout << 'o'; + cout << 'x'; + cout << endl; + } else { + long long ret = LLONG_MIN; + long long foo = 0; + for (long long j = 1; j <= min(b - 1, a); j++) { + long long pos = (a - j + 1) * (a - j + 1) + (j - 1); + long long q = b / (j + 1), r = b % (j + 1); + long long neg = r * (q + 1) * (q + 1) + (j + 1 - r) * q * q; + if (pos - neg > ret) { + ret = pos - neg; + foo = j + 1; + } + } + cout << ret << endl; + long long q = b / foo, r = b % foo; + long long g = (a - (foo - 1) + 1); + for (int(j) = (1); (j) < (foo + 1); ++(j)) { + for (int(i) = (0); (i) < (q); ++(i)) cout << 'x'; + if (j <= r) cout << 'x'; + if (j != foo) { + if (j == 1) + for (int(i) = (0); (i) < (g); ++(i)) cout << 'o'; + else + cout << 'o'; + } + } + cout << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n; + int ar1[n]; + for (int i = 0; i < n; i++) cin >> ar1[i]; + cin >> m; + int ar2[m]; + for (int i = 0; i < m; i++) cin >> ar2[i]; + int res = 0; + int ma = -10000; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (ar2[j] % ar1[i] == 0) { + if (ar2[j] / ar1[i] > ma) { + ma = ar2[j] / ar1[i]; + res = 1; + } else if (ar2[j] / ar1[i] == ma) { + res++; + } + } + } + } + cout << res << endl; +} +int main() { + string s1, s2, s3 = ""; + cin >> s1 >> s2; + for (int i = 0; i < s1.size(); i++) { + if (s1[i] != s2[i]) + s3 += '1'; + else + s3 += '0'; + } + cout << s3 << endl; + return 0; +} +long long n; +int main() { + cin >> n; + long long a = n / 7; + for (int i = a; i >= 0; i--) { + if ((n - i * 7) % 4 == 0) { + if (i != 0) { + for (int j = 1; j <= (n - i * 7) / 4; j++) { cout << "4"; } + for (int j = 1; j <= i; j++) { + if (j == i) { + cout << "7" << endl; + } else { + cout << "7"; + } + } + } else { + for (int k = 1; k <= n / 4; k++) { + if (k != ((n - i * 7) / 4)) { + cout << "4"; + } else { + cout << "4" << endl; + } + } + } + exit(0); + } + } + cout << "-1" << endl; +} +bool pred(int val) { + return val == 1; +} +int main() { + int n = 0; + cin >> n; + map m; + for (int i = 97; i < 123; ++i) ++m[i]; + bool isFound = false; + int lsh = 0; + for (int i = 0; i < n; ++i) { + string str; + cin >> str; + if (str[0] == '.') { + cin >> str; + if (!isFound) { + for (int i = 0; i < str.size(); ++i) { + map::iterator iter = m.find(int(str[i])); + if (iter != m.end()) { --iter->second; } + } + } + } else if (str[0] == '!') { + cin >> str; + if (!isFound) { + for (map::iterator iter = m.begin(); iter != m.end(); ++iter) { + if (find(str.begin(), str.end(), (char)iter->first) == str.end()) --iter->second; + } + } else + ++lsh; + } else if (str[0] == '?') { + cin >> str; + if (!isFound) + --m[(int)str[0]]; + else if (i != n - 1) + ++lsh; + } + int count = 0; + if (!isFound) { + for (map::iterator iter = m.begin(); iter != m.end(); ++iter) { + if (iter->second == 1) ++count; + } + if (count == 1) isFound = true; + } + } + cout << lsh << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + int g = arr[0]; + for (int i = 1; i < n; i++) g = __gcd(g, arr[i]); + cout << g * n << endl; + return 0; +} +int u[1005], gov[1005]; +vector a[1005]; +int cnt; +void dfs(int x) { + cnt++; + u[x] = 1; + for (int i = 0; i < a[x].size(); i++) { + if (!u[a[x][i]]) dfs(a[x][i]); + } +} +int main() { + int n, m, k, i, x, y; + cin >> n >> m >> k; + memset(u, 0, sizeof(u)); + for (i = 0; i < k; i++) cin >> gov[i]; + for (i = 0; i < m; i++) { + cin >> x >> y; + a[x].push_back(y); + a[y].push_back(x); + } + int tot = 0, maxx = 0, ans = 0; + for (i = 0; i < k; i++) { + cnt = 0; + dfs(gov[i]); + tot += cnt; + maxx = max(maxx, cnt); + ans += cnt * (cnt - 1) / 2; + } + tot = n - tot + maxx; + ans += tot * (tot - 1) / 2 - (maxx * (maxx - 1) / 2); + cout << ans - m << endl; +} +string a; +int main() { + int n, s[6]; + while (cin >> n) { + memset(s, 0, sizeof(s)); + for (int i = 0; i < n; i++) { + cin >> a; + if (a[0] == 'p') + s[0] = 1; + else if (a[0] == 'g') + s[1] = 1; + else if (a[0] == 'b') + s[2] = 1; + else if (a[0] == 'o') + s[3] = 1; + else if (a[0] == 'r') + s[4] = 1; + else if (a[0] == 'y') + s[5] = 1; + } + int count = 0; + for (int i = 0; i < 6; i++) { + if (s[i] == 0) count++; + } + cout << count << endl; + for (int i = 0; i < 6; i++) { + if (s[i] == 0) { + if (i == 0) + cout << "Power" << endl; + else if (i == 1) + cout << "Time" << endl; + else if (i == 2) + cout << "Space" << endl; + else if (i == 3) + cout << "Soul" << endl; + else if (i == 4) + cout << "Reality" << endl; + else if (i == 5) + cout << "Mind" << endl; + } + } + } + return 0; +} +long long facto(long long n) { + if (n == 0 or n == 1) return 1; + long long fact[18] = {0}; + fact[0] = 1; + for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; + return fact[n]; +} +int main() { + long long a, b; + cin >> a >> b; + cout << facto(min(a, b)) << "\n"; + return 0; +} +int q[101]; +int main() { + string str; + int num = 0, ans = 0; + cin >> str; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'Q') num++; + q[i] = num; + } + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'A') ans += q[i] * (q[str.length() - 1] - q[i]); + } + cout << ans << endl; + return 0; +} +int main() { + long int n, s, temp, c = 0; + cin >> n >> s; + while (1) { + if (s == 0) { break; } + temp = s; + s %= min(s, n); + c += temp / min(temp, n); + } + cout << c << endl; +} +int n, m; +char a; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + a = getchar(); + for (int j = 1; j <= m; j++) { + a = getchar(); + if (a == '-') { + putchar('-'); + } else { + if ((i + j) & 1) { + putchar('W'); + } else { + putchar('B'); + } + } + } + puts(""); + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int i; + for (i = 0; i < a.length(); i++) { + if (a[i] < 91) a[i] = a[i] + 32; + if (b[i] < 91) b[i] = b[i] + 32; + } + if (a > b) + cout << "1" << endl; + else if (a < b) + cout << "-1" << endl; + else if (a == b) + cout << "0" << endl; + return 0; +} +int main() { + long long n, count = 0, rem, digit; + cin >> n; + while (n != 0) { + rem = n % 10; + if (rem == 4 || rem == 7) { count += 1; } + n /= 10; + } + if (count == 0) { + cout << "NO" << endl; + exit(0); + } + while (count != 0) { + digit = count % 10; + if (digit == 4 || digit == 7) { + count /= 10; + } else + count = -1; + break; + } + if (count == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; +} +int main() { + int a, b, r; + cin >> a >> b >> r; + if (2 * r <= min(a, b)) + cout << "First" << endl; + else + cout << "Second" << endl; + return 0; +} +int main() { + int x; + cin >> x; + if (x % 5 == 0) { + int st = x / 5; + cout << st << endl; + } else { + int st = (x / 5) + 1; + cout << st << endl; + } + return 0; +} +const long long MAXN = 1e5 + 20; +long long n, l, r, a, b, vec[MAXN], p[MAXN]; +int main() { + cin >> n >> l >> r >> a >> b; + for (long long i = 0; i < n; i++) cin >> vec[i], p[i + 1] = p[i] + vec[i]; + long long ans = 1e18; + for (long long i = 0; i <= n; i++) { + long long ret = l * p[i] + r * (p[n] - p[i]); + if (i > (n - i)) + ret += a * max(0LL, (i - (n - i)) - 1); + else + ret += b * max(0LL, ((n - i) - i) - 1); + ans = min(ans, ret); + } + cout << ans << "\n"; + return 0; +} +int main() { + int n, m, x, c, i = 0; + cin >> n >> m; + int a[m]; + fill(a, a + m, 0); + for (i = 0; i < n; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> c; + a[c - 1] = 1; + } + } + for (i = 0; i < m; i++) { + if (a[i] == 0) { + cout << "NO" << endl; + break; + } + } + if (i == m) cout << "YES" << endl; + return 0; +} +int main() { + string s; + int n; + cin >> s >> n; + vector v(n + 1); + for (int i = 0; i < n; i++) { cin >> v[i]; } + v[n] = s; + sort(v.begin(), v.end()); + for (int i = 0; i <= n; i++) { + if (v[i] == s) { + if (i < n && v[i] == v[i + 1].substr(0, (int)v[i].size())) { + cout << v[i + 1] << endl; + break; + } else { + cout << v[i] << endl; + break; + } + } + } + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int sum = 0; + sum = sqrt((a * b) / c) + sqrt((b * c) / a) + sqrt((c * a) / b); + cout << sum * 4 << endl; +} +int main() { + int n, m, a; + cin >> n >> m; + bool isTwo = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> a; + if (a == 1) { + if (i == 0 || i == (n - 1)) isTwo = 1; + if (j == 0 || j == (m - 1)) isTwo = 1; + } + } + } + if (isTwo) + cout << 2 << endl; + else + cout << 4 << endl; +} +int main() { + int a[100][100]; + int g[100], k[100]; + int count; + int n; + while (cin >> n) { + memset(g, 0, sizeof(g)); + memset(k, 0, sizeof(k)); + count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + g[i] += a[i][j]; + k[i] += a[j][i]; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (k[j] > g[i]) { count++; } + } + } + cout << count << endl; + } +} +bool comp(int x, int y) { + return x > y; +} +int main() { + int n, m, ans = 0; + vector v; + cin >> n >> m; + for (int i = 1; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + int fl = 1; + while (fl) { + int k; + sort(v.begin(), v.end(), comp); + if (v[0] >= m) { + m++; + v[0]--; + ans++; + } else + fl = 0; + } + cout << ans << endl; +} +const int N = 1e6 + 5; +int n, a; +vector v1, v2; +long long res = 0; +long long sum(int l, int r) { + l--, r--; + long long s1 = 0, s2 = 0; + for (int j = l; j <= r; j++) s1 |= v1[j]; + for (int j = l; j <= r; j++) s2 |= v2[j]; + return s1 + s2; +} +int main() { + cin >> n; + int aux = n; + while (aux--) cin >> a, v1.push_back(a); + aux = n; + while (aux--) cin >> a, v2.push_back(a); + for (int i = 1; i <= n; i++) + for (int k = 1; k + i - 1 <= n; k++) res = max(res, sum(k, k + i - 1)); + cout << res << endl; +} +long long lcm(long long a, long long b) { + return a / __gcd(a, b) * b; +} +const int N = 1e5 + 9, mod = 1e9 + 7; +int dX[] = {1, -1, 0, 0, 1, 1, -1, -1}; +int dY[] = {0, 0, 1, -1, 1, -1, 1, -1}; +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, 1, 0, -1}; +map mp; +int t; +char c; +string s; +long long ans; +int main() { + cin >> t; + while (t--) { + cin >> c >> s; + if (c == '+') { + string ss; + for (int i = s.size() - 1; i >= 0; i--) { + int a = s[i] - '0'; + if (a & 1) + ss = '1' + ss; + else + ss = '0' + ss; + } + while (ss.size() != 20) { ss = '0' + ss; } + mp[ss]++; + } else if (c == '-') { + string ss; + for (int i = s.size() - 1; i >= 0; i--) { + int a = s[i] - '0'; + if (a & 1) + ss = '1' + ss; + else + ss = '0' + ss; + } + while (ss.size() != 20) { ss = '0' + ss; } + mp[ss]--; + } else { + while (s.size() != 20) { s = '0' + s; } + cout << mp[s] << endl; + } + } +} +int id[1000 + 10]; +int main() { + int n, cnt = 0; + bool b = true; + cin >> n; + for (int i = 0; i < n; i++) cin >> id[i]; + sort(id, id + n); + for (int i = 0; i < n; i++) { + if (id[i] == id[i + 1] && id[i] > 0) { + cnt++; + if (id[i + 1] == id[i + 2]) b = false; + } + } + if (b) + cout << cnt << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int t; + long long a, b, k; + long long ans; + cin >> t; + while (t--) { + cin >> a >> b >> k; + ans = 0; + bool even = true; + if (k % 2 == 0) + ans = k / 2 * (a - b); + else + ans = k / 2 * (a - b) + a; + cout << ans << endl; + } + return 0; +} +int main() { + int l, r, a; + while (cin >> l >> r >> a) { + if (l > r) swap(l, r); + if (l + a <= r) + cout << 2 * (l + a) << endl; + else + cout << (l + a + r) / 2 * 2 << endl; + } + return 0; +} +short who_wins(char a, char b) { + if (a == b) return 0; + if ((a == '8' && b == '[') || (a == '[' && b == '(') || (a == '(' && b == '8')) + return 1; + else + return 2; +} +int main() { + char a[10000], b[10000], c; + int na = 0, nb = 0; + int cnt = 0; + int t; + a[cnt] = getchar(); + while (a[cnt] != '\n') { + cnt++; + c = getchar(); + a[cnt] = getchar(); + } + for (int i = 0; i < cnt; i++) { + cin >> b[i]; + cin >> c; + } + for (int j = 0; j < cnt; j++) { + t = who_wins(a[j], b[j]); + if (t) { + if (t == 1) + na++; + else + nb++; + } + } + if (na == nb) cout << "TIE" << endl; + if (na > nb) cout << "TEAM 1 WINS" << endl; + if (na < nb) cout << "TEAM 2 WINS" << endl; + return 0; +} +int n, m; +char a; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + a = getchar(); + for (int j = 1; j <= m; j++) { + cin >> a; + if (a == '-') + cout << '-'; + else { + if ((i + j) & 1) + cout << 'W'; + else + cout << 'B'; + } + } + cout << endl; + } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + int len = str.length(); + for (int i = 0; i < len; i++) { + if (str[i] == 'G') { + for (int j = i; j < len; j += k) { + if (str[j] == '#') { + cout << "NO" << endl; + return 0; + } else if (str[j] == 'T') { + cout << "YES" << endl; + return 0; + } + } + } else if (str[i] == 'T') { + for (int j = i; j < len; j += k) { + if (str[j] == '#') { + cout << "NO" << endl; + return 0; + } else if (str[j] == 'G') { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; +} +int arr[5000]; +int main() { + int i, j, k, l, ans, n; + for (i = 1, ans = 0; i < 10; i++) + for (j = 0; j < 10; j++) + if (i != j) + for (k = 0; k < 10; k++) + if (k != i && k != j) + for (l = 0; l < 10; l++) + if (l != i && l != j && l != k) arr[ans++] = 1000 * i + 100 * j + 10 * k + l; + cin >> n; + for (i = 0; i < ans; i++) + if (arr[i] > n) { + cout << arr[i] << endl; + return 0; + } + return 0; +} +const int cost[5] = {1, 5, 10, 20, 100}; +int main() { + int A; + int ans = 0; + cin >> A; + for (int i = 4; i >= 0; i--) { + int t = A / cost[i]; + A -= t * cost[i]; + ans += t; + } + cout << ans << endl; + return 0; +} +int main() { + int a[5]; + a[0] = 100; + a[1] = 20; + a[2] = 10; + a[3] = 5; + a[4] = 1; + int n; + cin >> n; + int c = 0, r; + for (int i = 0;; i++) { + c += n / a[i]; + r = n % a[i]; + if (r == 0) + break; + else { + n = r; + } + } + cout << c << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + cout << b * c + (a - 1) * (b + c - 1) << endl; +} +const int maxn = 5000 + 10; +int main() { + string s; + cin >> s; + int n = s.size(); + int ans = 0; + for (int i = 0; i < n; i++) { + int q = 0, cnt = 0; + for (int j = i; j < n; j++) { + if (s[j] == '(') + q++, cnt++; + else if (s[j] == ')') + q--, cnt--; + else + q++, cnt--; + if (q < 0) break; + if (cnt < 0) cnt = 0; + if ((j - i + 1) % 2 == 0 && cnt == 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int n, b, p; + cin >> n >> b >> p; + cout << (n - 1) * (b * 2 + 1) << " " << p * n << '\n'; + return 0; +} +int N, B, P; +int qplays; +int qplayers; +int qoutplayers; +int tplays; +int tplayers; +void calc(int n) { + int k = 1; + while (k < n) k <<= 1; + if (k > n) k >>= 1; + qplays = k - 1; + qoutplayers = n - k; + qplayers = 0; + while (k >= 1) { + qplayers += k; + k >>= 1; + } + --qplayers; +} +int main() { + cin >> N >> B >> P; + tplays = 0; + tplayers = 0; + qoutplayers = 0; + int n = N; + do { + calc(n); + tplayers += qplayers; + tplays += qplays; + n = 1 + qoutplayers; + } while (qoutplayers > 0); + cout << ((tplayers * B) + tplays) << " " << (N * P) << "\n"; + return 0; +} +int main() { + int q; + cin >> q; + while (q--) { + long long a = -1, b = -1, c = -1; + long long n, x, y, d; + cin >> n >> x >> y >> d; + long long ans = -1; + if (abs(x - y) % d == 0) + ans = abs(x - y) / d; + else { + if (abs(n - y) % d == 0) { + b = ceil(abs(n - x) * 1. / d) + abs(n - y) / d; + if (ans != -1) + ans = min(ans, b); + else + ans = b; + } + if ((y - 1) % d == 0) { + c = ceil(abs(x - 1) * 1. / d) + abs(y - 1) / d; + if (ans != -1) + ans = min(ans, c); + else + ans = c; + } + } + cout << ans << endl; + } +} +int main() { + long long n, c; + while (cin >> n >> c) { + long long temp1 = 0; + long long temp2 = 0; + cin >> temp1; + long long ans = 1; + for (int i = 2; i <= n; i++) { + cin >> temp2; + if (temp2 - temp1 > c) + ans = 1; + else { + ans++; + } + temp1 = temp2; + } + cout << ans << endl; + } +} +int main() { + int n; + cin >> n; + int arr1[n]; + int arr2[n]; + for (int i = 0; i < n; i++) { cin >> arr1[i]; } + for (int i = 0; i < n; i++) { cin >> arr2[i]; } + int suma = 0; + int sumb = 0; + for (int i = 0; i < n; i++) { + suma = suma | arr1[i]; + sumb = sumb | arr2[i]; + } + cout << suma + sumb << endl; +} +int arr[1100]; +pair p[1100]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + p[i].first = arr[i]; + bool b = true; + if (p[i].first != 0) { + p[i].second = 1; + bool b = true; + for (int j = 0; j < i; j++) { + if (p[j].first == p[i].first) { + p[i].first = -1; + p[i].second = 0; + p[j].second++; + b = false; + break; + } + } + } + if (!b) p[i].second++; + } + int ans = 0; + for (int i = 0; i < n; i++) { + if (p[i].first != -1) { ans += p[i].second / 2; } + if (p[i].second != 1 && p[i].second % 2 == 1 || p[i].second > 2) { + cout << -1 << endl; + return 0; + } + } + cout << ans << endl; +} +long long i, j, k, n, m, a, b, c, d, x, z; +int main() { + cin >> a >> b >> c >> d; + x = max((3 * a) / 10, a - (a / 250) * c); + z = max((3 * b) / 10, b - (b / 250) * d); + if (x > z) + cout << "Misha" << endl; + else if (x < z) + cout << "Vasya" << endl; + else + cout << "Tie" << endl; + return 0; +} +int main() { + int sum = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + sum += abs(x); + } + cout << sum << endl; + return 0; +} +int main() { + string s; + cin >> s; + int ans = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') + ans++; + else if (s[i] > '0' && s[i] <= '9' && (s[i] - '0') % 2 == 1) + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + ifstream ff("file.txt"); + cin >> n >> k; + int c; + cin >> c; + vector v1(c + 1); + v1[0] = 0; + for (int i = 1; i <= c; i++) { cin >> v1[i]; } + if (k == 1) {} + int sumd = 0; + int needPrezent; + for (int i = 0; i < c; i++) { + int l, r; + l = v1[i]; + r = v1[i + 1]; + if (r - l <= k) { continue; } + needPrezent = r - l; + if (needPrezent % k == 0) { + sumd += (needPrezent / k) - 1; + } else { + sumd += (needPrezent / k); + } + } + if (v1[c] < n) { sumd += (n - v1[c]) / k; } + sumd += v1.size() - 1; + cout << sumd << endl; + return 0; +} +int n, m, a[102], c[102], ans = -1, ansx; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) cin >> a[j]; + for (int j = 1; j <= n; j++) { + if (ans < a[j]) { + ans = a[j]; + ansx = j; + } + } + c[ansx]++; + ans = -1; + } + ans = -1; + ansx = 1; + for (int j = 1; j <= n; j++) { + if (ans < c[j]) { + ans = c[j]; + ansx = j; + } + } + cout << ansx << endl; + return 0; +} +int main() { + int n; + cin >> n; + int t, one[5000], two[5000], three[5000], count[3] = {0, 0, 0}; + for (int i = 0; i < n; i++) { + cin >> t; + if (t == 1) { + one[count[0]] = i + 1; + count[0]++; + } else if (t == 2) { + two[count[1]] = i + 1; + count[1]++; + } else { + three[count[2]] = i + 1; + count[2]++; + } + } + int min = count[0]; + if (count[1] < min) min = count[1]; + if (count[2] < min) min = count[2]; + cout << min << endl; + for (int i = 0; i < min; i++) cout << one[i] << ' ' << two[i] << ' ' << three[i] << endl; + cin >> n; +} +const int N = 1e5 + 100; +int n, m, k, ans, a[55]; +vector v; +int main() { + cin >> n >> m >> k; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (k >= m) { + cout << "0" << endl; + return 0; + } + sort(a, a + n); + reverse(a, a + n); + for (int i = 0; i < n; i++) { + k--; + k += a[i]; + ans++; + if (k >= m) { + cout << ans << endl; + return 0; + } + } + cout << "-1" << endl; + return 0; +} +int x[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int a, b; + cin >> a >> b; + int w = 1; + a = x[a] - 1; + while (a--) { + b++; + if (b == 8) { + b = 1; + w++; + } + } + cout << w << '\n'; +} +int n; +set st; +string f(string s) { + sort(s.begin(), s.end()); + s.resize(unique(s.begin(), s.end()) - s.begin()); + return s; +} +int main() { + cin >> n; + string s; + for (int i = 0; i < n; i++) cin >> s, st.insert(f(s)); + cout << st.size() << endl; +} +int main() { + int n; + while (cin >> n) { + int count = 0; + while (n > 1) { + if (n % 2 == 1) count++; + n = n / 2; + } + cout << count + 1 << endl; + } +} +int main() { + int k, l, m, n, d; + cin >> k >> l >> m >> n >> d; + set s; + for (int i = 1; i <= d / k; i++) { + if (k * i <= d) s.insert(k * i); + } + for (int i = 1; i <= d / l; i++) { + if (l * i <= d) s.insert(l * i); + } + for (int i = 1; i <= d / m; i++) { + if (m * i <= d) s.insert(m * i); + } + for (int i = 1; i <= d / n; i++) { + if (n * i <= d) s.insert(n * i); + } + cout << s.size() << endl; + return 0; +} +int main() { + long long n, m, sum = 0; + cin >> n; + for (int i = 2; i < n; i++) { + m = n; + while (m) { + sum += m % i; + m /= i; + } + } + m = __gcd(sum, n - 2); + cout << sum / m << "/" << (n - 2) / m << endl; +} +int k, c[1010]; +long long dp[1010][1010]; +int main() { + cin >> k; + for (int i = 0, _n = (k); i < _n; i++) cin >> c[i]; + dp[0][0] = 1; + for (int i = (1), _n = (1005); i <= _n; i++) { + dp[i][0] = 1; + for (int j = (1), _n = (1005); j <= _n; j++) { dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % 1000000007; } + } + long long ans = 1; + long long sum = 0; + for (int i = 0, _n = (k); i < _n; i++) { + ans = (ans * dp[sum + c[i] - 1][c[i] - 1]) % 1000000007; + sum += c[i]; + } + cout << ans << endl; +} +int a[100], b[100], maxi, ans; +int main() { + int n, m; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + cin >> m; + for (int i = 1; i <= m; i++) cin >> b[i]; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + if (b[j] % a[i] == 0) maxi = max(maxi, b[j] / a[i]); + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) + if (b[j] % a[i] == 0) ans += (b[j] / a[i] == maxi); + cout << ans << endl; + return 0; +} +long long power(long long a, long long b, long long m) { + long long temp = a, ans = 1; + while (b) { + if (b & 1) ans = (ans % m * temp % m) % m; + temp = (temp % m * temp % m) % m; + b /= 2; + } + return ans; +} +int main() { + long long n, m; + cin >> n >> m; + cout << (power(3, n, m) - 1 + m) % m << endl; +} +int main() { + string s; + cin >> s; + for (int i = s.length() - 1; i >= 0; i--) { + if (s[i] == '0') { cout << "O-|-OOOO" << endl; } + if (s[i] == '1') { cout << "O-|O-OOO" << endl; } + if (s[i] == '2') { cout << "O-|OO-OO" << endl; } + if (s[i] == '3') { cout << "O-|OOO-O" << endl; } + if (s[i] == '4') { cout << "O-|OOOO-" << endl; } + if (s[i] == '5') { cout << "-O|-OOOO" << endl; } + if (s[i] == '6') { cout << "-O|O-OOO" << endl; } + if (s[i] == '7') { cout << "-O|OO-OO" << endl; } + if (s[i] == '8') { cout << "-O|OOO-O" << endl; } + if (s[i] == '9') { cout << "-O|OOOO-" << endl; } + } + return 0; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + int ans(0); + for (int i = 1; i <= z; i++) { + if (i % n == 0 && i % m == 0) ans++; + } + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + vector v(n); + for (int i = 0; i < n; ++i) cin >> v[i]; + if (v[n - 1] == 15 || (v[n - 1] != 0 && v.size() > 1 && v[n - 1] < v[n - 2])) { + cout << "DOWN\n"; + } else if (v[n - 1] == 0 || (v.size() > 1 && v[n - 1] > v[n - 2])) { + cout << "UP\n"; + } else { + cout << "-1\n"; + } + return 0; +} +const int N = 50010; +int main() { + long long n; + cin >> n; + long long low = 1, high = 1000000000, res = 0, mid; + while (high >= low) { + mid = ((high + low) >> 1); + if (mid * (mid + 1) / 2 < n) { + res = mid; + low = mid + 1; + } else + high = mid - 1; + } + n -= res * (res + 1) / 2; + cout << n << endl; + return 0; +} +int main() { + long long int a, b, c; + cin >> a >> b >> c; + long long int k = 0, g = b + 1; + while (g <= a) { + if (a - g <= c) { k++; } + g++; + } + cout << k << '\n'; + return 0; +} +int main() { + int n, i, t, j, sum, x; + string s1, s2; + cin >> n; + cin >> s1 >> s2; + sum = 0; + for (i = 0; i < n; i++) { + x = 10001; + x = min(abs((s1[i] - '0') - 0) + abs(10 - (s2[i] - '0')), x); + x = min(abs((s2[i] - '0') - 0) + abs(10 - (s1[i] - '0')), x); + x = min(abs((s2[i] - '0') - (s1[i] - '0')), x); + sum += x; + } + cout << sum << endl; + return 0; +} +int main() { + int n = 3; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + cout << arr[2] - arr[0] << endl; +} +const int man = 1e5 + 5; +const long long mod = 1e9 + 7; +int v[26][26]; +char a[150][1000]; +int l[150]; +int main() { + int n, i, j; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + sort(a[i], a[i] + strlen(a[i])); + l[i] = unique(a[i], a[i] + strlen(a[i])) - a[i]; + } + for (i = 0; i < n; i++) { + if (l[i] == 1) { + for (j = 0; j < 26; j++) v[a[i][0] - 'a'][j] += strlen(a[i]); + for (j = 0; j < 26; j++) + if (j != a[i][0] - 'a') v[j][a[i][0] - 'a'] += strlen(a[i]); + } else if (l[i] == 2) { + v[a[i][0] - 'a'][a[i][1] - 'a'] += strlen(a[i]); + } + } + int ma = 0; + for (i = 0; i < 26; i++) { + for (j = 0; j < 26; j++) { ma = max(ma, v[i][j]); } + } + cout << ma << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector data; + for (int i = 0; i < n; ++i) { + string line; + cin >> line; + data.push_back(line); + } + bool flag = [&]() -> int { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + int count = 0; + if (i - 1 >= 0 && data[i - 1][j] == 'o') count++; + if (i + 1 < n && data[i + 1][j] == 'o') count++; + if (j - 1 >= 0 && data[i][j - 1] == 'o') count++; + if (j + 1 < n && data[i][j + 1] == 'o') count++; + if (count & 1) return false; + } + } + return true; + }(); + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +char a[100 + 5][100 + 5], b[100 + 5][100 + 5]; +int main() { + int i, j, x, y; + cin >> x >> y; + for (i = 0; i < x; i++) + for (j = 0; j < y; j++) { + cin >> a[i][j]; + if ((i + j) % 2 == 0) + b[i][j] = 'B'; + else + b[i][j] = 'W'; + } + for (i = 0; i < x; i++) { + for (j = 0; j < y; j++) { + if (a[i][j] == '.') + cout << b[i][j]; + else + cout << a[i][j]; + } + cout << endl; + } + return 0; +} +int main() { + int in; + cin >> in; + cout << in % 2 << endl; + return 0; +} +int main() { + int n; + int x; + cin >> n >> x; + int sum = 0; + int t; + for (int i = 0; i < n; i++) { + cin >> t; + sum += t; + } + sum = abs(sum); + if (sum % x == 0) + cout << sum / x << endl; + else + cout << sum / x + 1 << endl; +} +int main() { + int n; + cin >> n; + set yippee; + for (int i = 0; i < 2; i += 1) { + int x; + cin >> x; + for (int j = 0; j < x; j++) { + int t; + cin >> t; + yippee.insert(t); + } + } + if (yippee.size() == n) { + cout << "I become the guy." << endl; + } else { + cout << "Oh, my keyboard!" << endl; + } + return 0; +} +int a[100]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int ans = 0; + for (int i = 0; i < n; i++) + for (int j = i + 1; j <= n; j++) { + int x = 0; + for (int k = i; k < j; k++) x ^= a[k]; + ans = max(ans, x); + } + cout << ans << endl; +} +int main() { + string a; + string b; + cin >> a; + cin >> b; + for (int i = 0; i < a.length(); ++i) { + if (a[i] == b[i]) { + a[i] = '0'; + } else { + a[i] = '1'; + } + } + cout << a << endl; + return 0; +} +double n, k; +int main() { + while (cin >> n >> k) { + int res = floor((-1 + sqrt(1 + 8 * (240 - k) / 5)) / 2); + cerr << (-1 + sqrt(1 + 8 * (240 - k) / 5)) / 2 << endl; + if (res > n) { res = n; } + cout << res << endl; + } + return 0; +} +int arr[1000]; +int main() { + int n; + cin >> n; + int l, r; + cin >> l >> r; + n--; + while (n--) { + int x, y; + cin >> x >> y; + for (int i = y; i > x; i--) arr[i]++; + } + int ans = 0; + for (int i = r; i > l; i--) + if (arr[i] == 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + cout << s1[0]; + int l1 = s1.length(); + int i = 1; + while (s1[i] < s2[0] && i < l1) cout << s1[i++]; + cout << s2[0] << endl; + return 0; +} +const int maxn = 1e5 + 5; +long long n, a, b, ans; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> a >> b; + ans = 0; + if (a > b) { + long long t = a; + a = b; + b = t; + } + while (a != 0) { + ans += b / a; + long long t = a; + a = b % a; + b = t; + } + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + cin >> a[0]; + for (int i = 1; i < n; i++) { + cin >> a[i]; + a[0] = __gcd(a[0], a[i]); + } + cout << a[0] * n << endl; + return 0; +} +int main() { + int n, index = 0, value, exe_A = 0, exe_B = 0, exe_C = 0; + cin >> n; + while (n--) { + cin >> value; + if (index % 3 == 0) + exe_A += value; + else if (index % 3 == 1) + exe_B += value; + else + exe_C += value; + index++; + } + int max = exe_A > exe_B ? exe_A : exe_B; + max = exe_C > max ? exe_C : max; + if (max == exe_A) + cout << "chest" << endl; + else if (max == exe_B) + cout << "biceps" << endl; + else + cout << "back" << endl; +} +long long i, j, k, n, t, m, x, z, ans, a[200007]; +int main() { + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = 1; i < n; i++) { ans += a[i] - a[i - 1] - 1; } + cout << ans << endl; + return 0; +} +int main() { + char n, m; + cin >> n >> m; + if ((m == '1' || m == '8') && (n == 'a' || n == 'h')) + cout << 3 << '\n'; + else if (m == '1' || m == '8' || n == 'a' || n == 'h') + cout << 5 << '\n'; + else + cout << 8 << '\n'; +} +set s; +int main() { + int n, m; + cin >> n >> m; + int ans = 0; + int num = 0; + while (n) { + ans++; + n--; + num++; + if (num == m) { + n++; + num = 0; + } + } + cout << ans << endl; + return 0; +} +int main() { + string s[105]; + int n; + cin >> n; + for (int i = 0; i < n; ++i) cin >> s[i]; + int ans = 0; + for (char i = 'a'; i <= 'z'; i++) { + for (char j = 'a'; j <= 'z'; j++) { + int sum = 0; + for (int k = 0; k < n; k++) { + bool b = 1; + for (int l = 0; l < s[k].length(); l++) + if (s[k][l] != i && s[k][l] != j) b = 0; + if (b) sum += s[k].length(); + } + ans = max(ans, sum); + } + } + cout << ans << endl; + return 0; +} +int main() { + int px; + cin >> px; + for (int i = sqrt(px); i >= 1; --i) { + if (!(px % i)) { + cout << i << ' ' << px / i << endl; + break; + } + } + return 0; +} +bool isVowel(char c) { + return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); +} +int main() { + string s; + bool band = true; + cin >> s; + for (int i = 0; i < s.size() && band; i++) { + if (isVowel(s[i]) || s[i] == 'n') continue; + if (i == s.size() - 1) band = false; + if (!isVowel(s[i + 1])) band = false; + } + if (band) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +bool proverka(char s1, char s2) { + if (abs(s2 - s1) == 2 || abs(s2 - s1) == 0) + return true; + else + return false; +} +int main() { + int N, n, k; + string s; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> n; + cin >> s; + k = 1; + for (int j = 0; j < n / 2; j++) + if (!proverka(s[j], s[n - j - 1])) k = 0; + if (k) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} +int main() { + int y; + cin >> y; + while (true) { + y += 1; + int a = y / 1000; + int b = y / 100 % 10; + int c = y / 10 % 10; + int d = y % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } + } + cout << y << endl; + return 0; +} +const int maxn = 1e5 + 10; +int a[maxn], b[maxn]; +int c[maxn], d[maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + c[a[i]]++; + } + for (int i = 0; i < n; i++) { + cin >> b[i]; + d[b[i]]++; + } + int k = 0; + for (int i = 1; i <= 5; i++) { + if ((d[i] + c[i] & 1)) { + cout << "-1" << endl; + return 0; + } + k += abs(c[i] - d[i]) / 2; + } + cout << k / 2 << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string s; + cin >> s; + int arr[26] = {0}; + for (int i = 0; i < s.length(); i++) arr[s[i] - 'a']++; + int flag = 1; + for (int i = 0; i < 26; i++) { + if (arr[i] > k) flag = 0; + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +long long int maxx(long long int &a, long long int &b) { + return a > b ? a : b; +} +long long int minn(long long int &a, long long int &b) { + return a > b ? b : a; +} +void boostIO() {} +long long int gcd(long long int a, long long int b) { + return b == 0 ? a : gcd(b, a % b); +} +int int_gcd(int a, int b) { + return b == 0 ? a : int_gcd(b, a % b); +} +long long int lcm(long long int a, long long int b) { + return a / gcd(a, b) * b; +} +long long int poww(long long int base, long long int exp, long long int mod) { + base %= mod; + long long int result = 1; + while (exp > 0) { + if (exp & 1) result = (result * base) % mod; + base = (base * base) % mod; + exp >>= 1; + } + return result; +} +int cube_root(long long int x) { + long long int l = 1, r = 1e6 + 10; + while (l < r) { + long long int mid = (l + r) >> 1; + if (mid * mid * mid >= x) { + r = mid; + } else { + l = mid + 1; + } + } + if (l * l * l == x) { return l; } + return -1; +} +int main() { + boostIO(); + int t; + cin >> t; + while (t--) { + long long int a, b; + cin >> a >> b; + int value = cube_root(a * b); + if (value != -1) { + long long int g = gcd(a, b); + if (g % value == 0) { + puts("Yes"); + continue; + } + } + puts("No"); + } +} +long long c[500005], s, bit[100], origin[100]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; ++i) { + long long a, b; + cin >> a >> b; + s ^= a, c[i] = a ^ b; + } + int cnt = 0; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < cnt; ++j) + if (c[i] & bit[j]) c[i] ^= origin[j]; + if (c[i]) origin[cnt] = c[i], bit[cnt] = c[i] & -c[i], ++cnt; + } + for (int j = 0; j < cnt; ++j) + if (s & bit[j]) s ^= origin[j]; + if (s) + cout << "1/1" << endl; + else + cout << (1ll << cnt) - 1 << '/' << (1ll << cnt) << endl; + return 0; +} +int main() { + long long int a, b, c, n, x, i, cnt = 0; + cin >> a >> b >> c; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> x; + if (x > b && x < c) { cnt++; } + } + cout << cnt << endl; +} +int main() { + int n, count = 0; + char s; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> s; + if (s == '1') { + count++; + } else { + count--; + } + } + cout << abs(count) << endl; +} +long long int llin() { + long long int tmp; + cin >> tmp; + return tmp; +} +void solve() { + long long int nsticks = llin(); + long long int lengths[nsticks]; + long long int min = 101; + long long int max = 0; + for (long long int i = 0; i < nsticks; i++) { + long long int tmp = llin(); + lengths[i] = tmp; + if (tmp > max) max = tmp; + if (tmp < min) min = tmp; + } + long long int min_t = min; + long long int min_cost = 1000005; + for (long long int t = min; t < max + 1; t++) { + long long int tmp_cost = 0; + for (long long int i = 0; i < nsticks; i++) { + long long int tmp_length = lengths[i]; + if (tmp_length > t + 1) + tmp_cost += tmp_length - (t + 1); + else if (tmp_length < t - 1) + tmp_cost += t - 1 - (tmp_length); + } + if (min_cost > tmp_cost) { + min_t = t; + min_cost = tmp_cost; + } + } + cout << min_t << " " << min_cost << '\n'; + return; +} +int main() { + int TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +long long n, b, p, x, ans; +bool l = true; +int main() { + cin >> n >> b >> p; + x = n; + while (n > 1) { + ans += (n / 2) * (b * 2 + 1); + n = ceil(n / 2.0); + } + cout << ans << " " << x * p << endl; + return 0; +} +int main() { + long long int n, c, sum = 0; + cin >> n >> c; + long long int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (i == 0) + sum++; + else { + if (arr[i] - arr[i - 1] <= c) + sum++; + else + sum = 1; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + int num[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; + cin >> n; + int x, y; + x = n / 10; + y = n % 10; + cout << num[x] * num[y] << endl; + return 0; +} +int a, b, c, d, i, e, f, g, n, m, k, l; +string s, s2, s3, s4; +int main() { + cin >> s >> s2 >> n; + cout << s << " " << s2 << endl; + for (i = 1; i <= n; i++) { + cin >> s3 >> s4; + if (s3 == s) + s = s4; + else if (s3 == s2) + s2 = s4; + cout << s << " " << s2 << endl; + } +} +const int man = 1e5 + 50; +const long long mod = 1000000007; +long long u[man], v[man]; +int main() { + long long ans = 0, n, m; + long long a, b, c; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> u[i]; + sort(u, u + n); + for (int i = 0; i < m; i++) { + cin >> a >> b >> c; + if (a == 1) { + if (b == 1000000000) { + ans++; + continue; + } + long long k = upper_bound(u, u + n, b) - u - 1; + while (v[k] == 1 && k >= 0) { k--; } + if (k >= 0) { + ans++; + v[k] = 1; + } + } + } + cout << ans << endl; + return 0; +} +int n, k = 0, i, m, j; +int main() { + cin >> n >> m; + for (i = 0; i * i <= n; i++) + for (j = 0; j * j <= m; j++) + if (i * i + j == n && j * j + i == m) k++; + cout << k << endl; + return 0; +} +int main() { + long long int t, a, b, j; + cin >> t; + for (long long int i = 0; i < t; i++) { + cin >> a >> b >> j; + if (j % 2 == 0) + cout << (j / 2) * a - (j / 2) * b << endl; + else + cout << (j / 2 + 1) * a - (j / 2) * b << endl; + } + return 0; +} +int main() { + int arr[12]; + int k; + cin >> k; + int sum = 0; + int counter = 0; + for (int i = 0; i < 12; i++) cin >> arr[i]; + sort(arr, arr + 12); + reverse(arr, arr + 12); + if (k == 0) { + cout << 0 << endl; + return 0; + } + for (int i = 0; i < 12; i++) { + sum += arr[i]; + counter++; + if (sum >= k) { + cout << counter << endl; + break; + } + } + if (sum < k) cout << -1 << endl; +} +int main() { + int m, n, k = 0; + cin >> m >> n; + queue sm; + queue sn; + for (int i = 0; i < m; i++) { + int a; + cin >> a; + sm.push(a); + } + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sn.push(a); + } + while (!sm.empty() && !sn.empty()) { + if (sm.front() <= sn.front()) { + k++; + sm.pop(); + sn.pop(); + } else { + sm.pop(); + } + } + cout << k << endl; + int x; + cin >> x; + return 0; +} +int main() { + string a; + cin >> a; + for (int i = 0; i < a.size(); i++) { + if (a[i] >= '5') a[i] = 9 - (a[i] - '0') + '0'; + } + if (a[0] == '0') { + cout << 9; + } else + cout << a[0]; + for (int j = 1; j < a.size(); j++) { cout << a[j]; } + cout << endl; + return 0; +} +int main() { + int n, i, ara[200001], sum = 0, sum2 = 0; + cin >> n; + for (i = 0; i < n; i++) { + cin >> ara[i]; + sum = sum + ara[i]; + } + sum = (sum + 1) / 2; + for (i = 0; i < n; i++) { + sum2 = sum2 + ara[i]; + if (sum <= sum2) { + cout << i + 1 << endl; + break; + } + } + return 0; +} +int main() { + string s; + cin >> s; + for (int i = 0; i < s.length(); i++) + if (s[i] == '1') { + int sum = 0; + for (int j = i + 1; j < s.length(); j++) + if (s[j] == '0') sum++; + if (sum >= 6) { + cout << "yes" << endl; + return 0; + } + break; + } + cout << "no" << endl; + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + int N, x = 0, i; + cin >> N; + string s; + cin >> s; + for (i = 0; i < (N - 1); i++) { + if (s[i] != s[i + 1]) { + cout << "YES" << endl; + cout << s[i] << s[i + 1] << endl; + x++; + break; + } + } + if (x == 0) cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n, 0); + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + int ans = 0; + for (int i = 0; i < n - n / 2; i++) { + if (i == 0 || abs(a[i] - a[i + n / 2]) < ans) ans = abs(a[i] - a[i + n / 2]); + } + cout << ans << endl; + return 0; +} +const int maxn = 1005; +int main() { + int a[maxn]; + int i; + int j; + int n, k; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + int res = -1; + for (i = 0; i < k; i++) { + int k1 = 0; + int k2 = 0; + for (j = 0; j < n; j++) { + if ((j - i) % k == 0) { + continue; + } else { + if (a[j] == 1) k1++; + if (a[j] == -1) k2++; + } + } + res = max(res, abs(k1 - k2)); + } + cout << res << endl; + return 0; +} +int main() { + locale loc; + int n, s, e; + cin >> n >> s >> e; + string str; + cin >> str; + if (str[s - 1] == str[e - 1]) + cout << 0 << "\n"; + else + cout << 1 << "\n"; +} +int main() { + int n, a, ans[105]; + while (cin >> n) { + memset(ans, 0, sizeof(ans)); + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) { + cin >> a; + if (a == 1 || a == 3) ans[i] = 1; + } + int cnt = 0, b[105]; + for (int i = 1; i <= n; i++) { + if (ans[i] == 0) b[cnt++] = i; + } + if (cnt) { + cout << cnt << endl; + for (int i = 0; i < cnt - 1; i++) cout << b[i] << ' '; + cout << b[cnt - 1] << endl; + } else + cout << 0 << endl; + } + return 0; +} +int main() { + int n; + string s[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; + cin >> n; + while (n > 5) n = n / 2 - 2; + cout << s[n - 1] << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) { + cout << a << endl; + } else { + cout << 1 << endl; + } +} +int gcd(int a, int b) { + while (b != 0) { + int r = b; + b = a % b; + a = r; + } + return a; +} +int main() { + int n, m, z; + cin >> n >> m >> z; + cout << z / (n * m / gcd(n, m)) << endl; +} +int main() { + int n, p, q, c = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> p >> q; + if (q - p >= 2) c++; + } + cout << c << endl; + return 0; +} +int main() { + string s; + cin >> s; + int bul = 0, ris = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '-') { + ris += 1; + } else + bul += 1; + } + if (bul == 0) { + cout << "YES" << endl; + } else if (ris % bul == 0) { + cout << "YES" << endl; + } else + cout << "NO" << endl; +} +int main() { + string a; + cin >> a; + int i, j, l, c = 0, s = 0, d = 0; + l = a.size(); + for (i = 0; i < l; i++) { + if (a[i] >= 'A' && a[i] <= 'Z') { + c = 1; + } else if (a[i] >= 'a' && a[i] <= 'z') { + s = 1; + } else if (a[i] >= '0' && a[i] <= '9') { + d = 1; + } + } + if (d && c && s && l >= 5) { + cout << "Correct" << endl; + return 0; + } else { + cout << "Too weak" << endl; + return 0; + } +} +int main() { + long long n; + cin >> n; + cout << (n / 2) * 3 << endl; + return 0; +} +long long a[101], ans; +int main() { + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> a[i]; + ans += abs(a[i]); + } + cout << ans << endl; + return 0; +} +int main() { + vector vs(8); + for (int i = 0; i < 8; i++) { cin >> vs[i]; } + int minw = 999999; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (vs[i][j] == 'W') { + int dis = 0; + for (int k = i - 1; k >= 0; k--) { + if (vs[k][j] == 'B') { + dis = 999999; + break; + } else + dis++; + } + minw = min(minw, dis); + } + } + } + int minB = 999999; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (vs[i][j] == 'B') { + int dis = 0; + for (int k = i + 1; k < 8; k++) { + if (vs[k][j] == 'W') { + dis = 999999; + break; + } else + dis++; + } + minB = min(minB, dis); + } + } + } + if (minw <= minB) + cout << "A\n"; + else + cout << "B\n"; + return 0; +} +int n, sum, arr[1000]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int min = arr[0], max = arr[0]; + for (int i = 1; i < n; i++) { + if (arr[i] < min) { + min = arr[i]; + sum++; + } + if (arr[i] > max) { + max = arr[i]; + sum++; + } + } + cout << sum << endl; + return 0; +} +int main() { + int n; + cin >> n; + int T[n]; + int max, min, comp = 0; + for (int i = 0; i < n; i++) { + cin >> T[i]; + if (i == 0) { + min = T[0]; + max = T[0]; + } else { + if (T[i] < min) { + min = T[i]; + comp++; + } + if (T[i] > max) { + max = T[i]; + comp++; + } + } + } + cout << comp << endl; + return 0; +} +int main() { + long long n; + cin >> n; + long long k1 = ((2 + (n % 2 == 1 ? n - 1 : n)) / 2) * (n / 2); + long long k2 = ((1 + (n % 2 == 1 ? n : n - 1)) / 2) * ((n + 1) / 2); + cout << k1 - k2 << '\n'; +} +int main() { + int m, w; + cin >> m >> w; + int daysPerMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int days = daysPerMonth[m] - abs(w - 8); + int res = days / 7; + double dres = (double)days / 7; + if ((double)res != dres) res++; + cout << ++res << endl; + return 0; +} +int main() { + int n, m, b; + cin >> n >> m; + int a[200] = {0}, aa; + for (int i = 0; i < m; i++) { + cin >> aa; + a[aa] = 1; + } + cin >> b; + for (int i = 0; i < b; i++) { + cin >> aa; + a[aa] = 1; + } + bool ok = true; + for (int i = 1; i <= n; i++) { + if (a[i] != 1) { + ok = false; + break; + } + } + if (ok) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; + return 0; +} +int main() { + float k, n, p, s; + int ans = 0; + cin >> k >> n >> s >> p; + ans = ceil((ceil(n / s) * k) / p); + cout << ans << endl; + return 0; +} +int r, g, b, cnt = 0; +int main() { + cin >> r >> g >> b; + while (r > 0 || g > 0 || b > 0) { + cnt++; + if (cnt % 3 == 1) + r -= 2; + else if (cnt % 3 == 2) + g -= 2; + else if (cnt % 3 == 0) + b -= 2; + } + cout << cnt + 29 << '\n'; + return 0; +} +int p[] = {100, 20, 10, 5, 1}, n; +int main() { + while (cin >> n) { + int ans = 0; + for (int i = 0; i < 5; i++) ans += n / p[i], n = n % p[i]; + cout << ans << endl; + } + return 0; +} +string s1, s2, ans = ""; +int main() { + cin >> s1 >> s2; + for (int i = 0; i < s1.length(); i++) + if (s1[i] == s2[i]) + ans += "0"; + else + ans += "1"; + cout << ans << endl; + return 0; +} +pair dp[26][26]; +int main() { + long long n; + cin >> n; + string st; + cin >> st; + string ans = ""; + long long cnt = 0; + bool ok = 0; + for (long long i = 0; i < (n); ++i) { + if (st[i] == '0') { + if (cnt >= 1) ans += (cnt + '0'); + if (ok) { ans += '0'; } + ok = 1; + cnt = 0; + } else { + ok = 0; + cnt++; + } + } + if (cnt >= 1) ans += (cnt + '0'); + if (ok) ans += '0'; + cout << ans << "\n"; +} +map m; +int main() { + string a; + cin >> a; + int len = a.size(); + m['B'] = 0; + m['u'] = 0; + m['l'] = 0; + m['b'] = 0; + m['a'] = 0; + m['s'] = 0; + m['r'] = 0; + for (int i = 0; i < len; i++) m[a[i]]++; + int ans = 100000; + ans = min(ans, m['B']); + ans = min(ans, m['u'] / 2); + ans = min(ans, m['l']); + ans = min(ans, m['b']); + ans = min(ans, m['a'] / 2); + ans = min(ans, m['s']); + ans = min(ans, m['r']); + cout << ans << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = 0, y = 0, z = 0, flag = 0; + x = sqrt((b * c) / a); + y = sqrt((c * a) / b); + z = sqrt((a * b) / c); + cout << 4 * (x + y + z) << endl; + return 0; +} +int main() { + char ch; + string s, k = "qwertyuiopasdfghjkl;zxcvbnm,./"; + cin >> ch >> s; + int l = s.size(); + for (int i = 0; i < l; i++) { + int h = k.find(s[i]); + if (ch == 'R') + cout << k[h - 1]; + else + cout << k[h + 1]; + } + cout << endl; + return 0; +} +int main() { + int n, m; + cin >> n; + cin >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 != 0) { + cout << "#"; + } else if (i % 2 == 0 && i % 4 != 0 && j == m) { + cout << "#"; + } else if (i % 2 == 0 && i % 4 == 0 && j == 1) { + cout << "#"; + } else { + cout << "."; + } + } + cout << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int p1 = 0, p2 = 0, p3 = 0; + for (int i = 0; i < n; i++) { + if (i % 3 == 0) { + p1 += arr[i]; + } else if (i % 3 == 1) { + p2 += arr[i]; + } else if (i % 3 == 2) { + p3 += arr[i]; + } + } + if (p1 >= p2 && p1 >= p3) { + cout << "chest" << endl; + } else if (p2 >= p1 && p2 >= p3) { + cout << "biceps" << endl; + } else if (p3 >= p2 && p3 >= p1) { + cout << "back" << endl; + } + return 0; +} +int main() { + long long int i, j = 1, n, k = 1, m = 0; + bool find = false; + cin >> n; + for (i = 1; i <= n; i++) { + if (n - j < k + 1) { + find = true; + if (n - j != 0) { + cout << n - j << endl; + } else { + cout << k << endl; + } + break; + } + k++; + j += k; + } + return 0; +} +int main() { + long long int a, b, c, d; + cin >> a; + cin >> b; + cin >> c; + cin >> d; + long long int misha = max(((3 * a) / 10), a - ((a / 250) * c)); + long long int vasya = max(((3 * b) / 10), b - ((b / 250) * d)); + if (misha > vasya) { + cout << "Misha" << endl; + } else if (vasya > misha) { + cout << "Vasya" << endl; + } else { + cout << "Tie" << endl; + } + return 0; +} +long long int n; +int main() { + cin >> n; + cout << n + n / 2 << "\n"; + return 0; +} +char ara[15][15]; +int main() { + for (int i = 1; i <= 8; i++) { + for (int j = 1; j <= 8; j++) { cin >> ara[i][j]; } + } + bool ok = 0; + for (int i = 1; i <= 8 && !ok; i++) { + if (ara[i][1] == ara[i][8]) { + ok = 1; + break; + } + for (int j = 1; j <= 8 && !ok; j++) { + cin >> ara[i][j]; + if (ara[i][j] == ara[i][j + 1]) { + ok = 1; + break; + } + } + } + if (ok) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int main() { + int i, c = 0, t; + long long sum = 0; + string s; + cin >> s; + for (i = 0; i < s.size(); i++) { + if (s[i] == 'Q') c++; + } + t = c; + for (i = 0; i < s.size(); i++) { + if (s[i] == 'Q') c--; + if (s[i] == 'A') sum += c * (t - c); + } + cout << sum << endl; + return 0; +} +const int maxn = 1e4 + 10; +int a[maxn]; +int n; +int cnt = 0; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 2; i <= n - 1; i++) { + if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]) cnt++; + } + cout << cnt << endl; + return 0; +} +int n, temp; +vector p, t, m; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> temp; + if (temp == 1) { + p.push_back(i + 1); + } else if (temp == 2) { + t.push_back(i + 1); + } else { + m.push_back(i + 1); + } + } + int ans1 = min(p.size(), min(t.size(), m.size())); + cout << ans1 << endl; + for (int i = 0; i < ans1; i++) { cout << p[i] << " " << t[i] << " " << m[i] << endl; } + return 0; +} +int a[10000], b[10000]; +bool ab = 0; +int main() { + int n, s, i, z = 1, x, c; + cin >> n >> s; + x = n + 1; + for (i = 1; i <= n; i++) cin >> a[i]; + for (i = 1; i <= n; i++) cin >> b[i]; + if (a[s] == 1 && a[1] == 1) + ab = 1; + else + for (i = n; i >= 1; i--) { + if (a[i] == 1 && b[i] == 1) { + if (i >= s && b[s] == 1) ab = 1; + } + } + if (a[1] == 0) ab = 0; + if (ab == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2 == 0) { + cout << "Mahmoud" << endl; + } else + cout << "Ehab" << endl; + return 0; +} +int main() { + string s; + cin >> s; + int z = s.size(); + int ans = 0; + int tmp = 1; + for (int i = 1; i < z; i++) { + if (s[i] == s[i - 1]) + tmp++; + else { + if (tmp % 2 == 0) ans++; + tmp = 1; + } + } + if (tmp % 2 == 0) ans++; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + if (i == n) { + cout << "I hate it\n"; + return 0; + } + cout << "I hate that "; + } else { + if (i == n) { + cout << "I love it\n"; + return 0; + } + cout << "I love that "; + } + } +} +int main() { + int n, k; + cin >> n >> k; + k = 240 - k; + int t = 0; + while ((k - 5 * t - 5) >= 0 && n > 0) { + t++; + k -= 5 * t; + n -= 1; + } + cout << t << endl; +} +int main() { + int n; + cin >> n; + int ma = -1e9; + set s; + for (int i = 0; i < 2 * n; i++) { + int a; + cin >> a; + int x = s.size(); + s.insert(a); + if (x == s.size()) { s.erase(a); } + x = s.size(); + ma = max(ma, x); + } + cout << ma << endl; + return 0; +} +int main() { + int a[100 + 10], b[100 + 50]; + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int k = 0; + for (int i = 1; i < n - 1; i++) { + int max = 0; + int s; + for (int j = 1; j < n; j++) { + if (j == i) { + s = a[j + 1] - a[j - 1]; + j += 1; + } else + s = a[j] - a[j - 1]; + if (s > max) max = s; + } + b[k] = max; + k++; + } + int min = 10000; + for (int i = 0; i < k; i++) { + if (min > b[i]) min = b[i]; + } + cout << min << endl; + return 0; +} +int num[100001]; +int main() { + int n, c, sum = 1; + cin >> n >> c; + for (int i = 0; i < n; i++) cin >> num[i]; + for (int i = 1; i < n; i++) { + if (num[i] - num[i - 1] <= c) + sum++; + else + sum = 1; + } + cout << sum << endl; +} +int main() { + string a, b; + cin >> a >> b; + int n; + cin >> n; + cout << a << " " << b << "\n"; + while (n--) { + string c, d; + cin >> c >> d; + if (c == a) { + a = d; + } else { + b = d; + } + cout << a << " " << b << "\n"; + } + return 0; +} +int main() { + int t; + cin >> t; + long long s, a, b, c; + for (int i = 0; i < t; i++) { + cin >> s >> a >> b >> c; + cout << s / c + (s / c) / a * b << endl; + } + return 0; +} +string n; +int main() { + cin >> n; + int total = 0; + int curr = int('a'); + for (int i = 0; i < n.length(); ++i) { + int distance = abs(int(n[i]) - curr); + if (distance <= 13) { + total += distance; + } else { + total += 26 - distance; + } + curr = int(n[i]); + } + cout << total << endl; + return 0; +} +const int maxn = 200000 + 5; +int zw[maxn << 2]; +pair G[maxn]; +int ans[maxn]; +int main() { + int n, m; + while (cin >> n >> m) { + int t = m; + int ans = 0; + while (n--) { + m--; + if (m == 0) { + m = t; + n++; + } + ans++; + } + cout << ans << endl; + } + return 0; +} +int main() { + int a, b[100000], c = 0, d = 0; + cin >> a; + for (int i = 0; i < a; i++) { + cin >> b[i]; + if (b[i] >= 0) { + d += b[i]; + } else { + d += abs(b[i]); + } + } + cout << d << endl; +} +int main() { + long long int ans = 0, x, s, dp0 = 1, dp1 = 0, a, b; + cin >> s >> x; + if (x == 0 && s % 2 == 0) { + cout << 1 << endl; + return 0; + } + if (s == x) ans -= 2; + if (x > s) { + cout << 0 << endl; + return 0; + } + while (s) { + a = s % 2; + b = x % 2; + s /= 2; + x /= 2; + if (a == b) { + if (a == 0) { + dp0 = dp0; + dp1 = dp0; + } else { + dp0 = 2 * dp0; + dp1 = 0; + } + } else { + if (b == 0) { + dp0 = dp1; + dp1 = dp1; + } else { + dp0 = 0; + dp1 = 2 * dp1; + } + } + } + if (!dp0) + cout << 0 << endl; + else + cout << ans + dp0 << endl; +} +int main() { + int n, i, m = 1; + cin >> n; + for (i = 0; i < n - 1; i++) { + m = (m * 3); + m = m % 1000003; + } + cout << m << endl; + return 0; +} +int main() { + string s; + cin >> s; + int len = s.length(); + cout << (len + 1) * 26 - len << endl; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int angel; + cin >> angel; + if (360 % (180 - angel) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, count = 0; + cin >> n; + vector ai(n); + for (int i = 0; i < n; i++) cin >> ai[i]; + for (static int i = 0; i < n; i++) { + if (ai[i] == 1) + count++; + else if (ai[i] == 0 && ai[i + 1] == 1 && i != 0 && ai[i - 1] != 0) + count++; + else if (ai[i] == 0 && ai[i + 1] == 0) + i++; + } + cout << count << '\n'; + return 0; +} +long long n, m, i, maxi, j, A[10000], x, k; +int main() { + string s; + cin >> s; + for (i = s.size() - 1; i >= 0; i--) { + x = s[i] - '0'; + if (x >= 5) { + cout << "-O|"; + x -= 5; + } else + cout << "O-|"; + k = 4; + while (x--) { + cout << "O"; + k--; + } + if (k > 0) { + cout << "-"; + while (k--) cout << "O"; + cout << endl; + } else + cout << "-" << endl; + } + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + if (k >= n) + cout << n * x << endl; + else { + int time = 0; + for (int i = 0; i < n - k; i++) time += a[i]; + for (int i = n - k; i < n; i++) { + if (x < a[i]) + time += x; + else + time += a[i]; + } + cout << time << endl; + } + return 0; +} +int main() { + long long int n, cnt, sum, ans, i; + cin >> n; + cnt = 0, ans = 0, sum = 0; + for (i = 1; i <= 10000; i++) { + ans += i; + sum += ans; + if (sum > n) break; + cnt++; + } + cout << cnt << endl; + return 0; +} +char a[105], b[105]; +int gcd(int a, int b); +int main() { + cin >> a >> b; + if (!strcmp(a, b)) { + cout << a << endl; + } else + cout << 1 << endl; +} +int n, m; +char c[55][55]; +int main() { + int i, j; + cin >> n >> m; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) c[i][j] = '.'; + for (i = 0; i < n; i += 2) { + for (j = 0; j < m; j++) c[i][j] = '#'; + } + for (i = 1; i < n; i += 4) c[i][m - 1] = '#'; + for (i = 3; i < n; i += 4) c[i][0] = '#'; + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) cout << c[i][j]; + cout << endl; + } + return 0; +} +int main() { + int n, i; + cin >> n; + int a[n + 1]; + for (i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + cout << a[n] << " "; + for (i = 2; i < n; i++) cout << a[i] << " "; + cout << a[1] << endl; + return 0; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; i++) { + int s, a, b, c; + cin >> s >> a >> b >> c; + int a1 = a, c1 = c, cont = 0; + while (a1 != 0) { + cont++; + a1 /= 10; + } + while (c1 != 0) { + cont++; + c1 /= 10; + } + unsigned long long int t, rest_money, i_ans = 0, f_ans = 0; + t = (s / a) / c; + if (cont >= 15) + rest_money = s; + else + rest_money = s % (a * c); + i_ans = (a + b) * t; + if (rest_money != 0) + f_ans = i_ans + (rest_money / c); + else + f_ans = i_ans; + cout << f_ans << endl; + } + return 0; +} +int main() { + long long n, m; + cin >> n >> m; + long long r[m + 1]; + r[0] = 1; + for (int i = 1; i <= m; i++) { + r[i] = 2 * r[i - 1]; + r[i] %= 1000000009; + } + long long ans = 1; + for (int i = 0; i < n; i++) { + long long x1 = r[m] - i - 1; + if (x1 < 0) { x1 += 1000000009; } + ans *= x1; + ans %= 1000000009; + } + cout << ans << endl; + return 0; +} +long long dx[] = {1, 0, -1, 0}; +long long dy[] = {0, 1, 0, -1}; +long long gcd(long long x, long long y) { + if (y == 0) + return x; + else + return gcd(y, x % y); +} +long long expo(long long n, long long m, long long p) { + long long r = 1; + n = n % p; + while (m > 0) { + if (m % 2) r = (r * n) % p; + n = (n * n) % p; + m = m / 2; + } + return r % p; +} +bool isPrime(long long n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (long long i = 5; i * i <= n; i = i + 6) + if (n % i == 0 || n % (i + 2) == 0) return false; + return true; +} +vector z_function(string s) { + long long n = (long long)s.length(); + vector z(n); + for (long long i = 1, l = 0, r = 0; i < n; ++i) { + if (i <= r) z[i] = min(r - i + 1, z[i - l]); + while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; + if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; + } + return z; +} +long long s, x; +int main() { + cin >> s >> x; + long long aa = (s - x) / 2; + if ((s - x) % 2 == 1 || x > s) { + cout << 0 << '\n'; + return 0; + } + long long ans = 0; + for (long long i = 0; i < 40; i++) { + if ((x & (1LL << i)) && ((aa & (1LL << i)) == 0)) { + ans++; + } else if ((x & (1LL << i)) && ((aa & (1LL << i)))) { + cout << "0" << '\n'; + return 0; + } + } + ans = (1LL << ans); + if (s == x) ans -= 2; + cout << ans << '\n'; +} +int main() { + int n; + cin >> n; + int x; + cin >> x; + int maxx = x; + int minn = x; + int sum = 0; + for (int i = 1; i < n; i++) { + cin >> x; + if (x > maxx || x < minn) { sum++; } + maxx = max(maxx, x); + minn = min(minn, x); + } + cout << sum << endl; + return 0; +} +int main() { + string s; + cin >> s; + int n = s.length(); + cout << 26 * (n + 1) - n << endl; +} +const int mod = 1e6 + 3; +const int N = 1e6 + 3; +const int inf = 0x3f3f3f3f; +char a[N], b[N]; +int main() { + int numa = 0, numb = 0; + char c; + c = getchar(); + bool start = 0; + while (c != '\n') { + if (c != '0') { + a[numa++] = c; + start = 1; + } else if (start) + a[numa++] = c; + c = getchar(); + } + c = getchar(); + start = 0; + while (c != '\n') { + if (c != '0') { + b[numb++] = c; + start = 1; + } else if (start) + b[numb++] = c; + c = getchar(); + } + if (numa > numb) + cout << ">\n"; + else if (numa < numb) + cout << "<\n"; + else { + for (int i = 0; i < numa; i++) + if (a[i] > b[i]) { + cout << ">\n"; + return 0; + } else if (b[i] > a[i]) { + cout << "<\n"; + return 0; + } + cout << "=\n"; + } + return 0; +} +int main() { + int n; + unsigned long long res = 0; + string s; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> s; + if (s[0] == 'T') + res += 4; + else if (s[0] == 'C') + res += 6; + else if (s[0] == 'O') + res += 8; + else if (s[0] == 'D') + res += 12; + else if (s[0] == 'I') + res += 20; + } + cout << res << endl; + return 0; +} +int sq(int a) { + return a * a; +} +int main() { + int A[6], i, j, k, a, b, c; + for (i = 0; i < 6; i++) { cin >> A[i]; } + a = A[0] + A[1] + A[2]; + b = sq(a); + c = sq(A[0]) + sq(A[2]) + sq(A[4]); + j = b - c; + cout << j << endl; + return 0; +} +int main() { + int n; + cin >> n; + int x0, y0, x1, y1, a = 0; + x0 = y0 = 1e9 + 87; + x1 = y1 = -9e8; + for (int i = 0; i < n; ++i) { + int l, b, r, u; + cin >> l >> b >> r >> u; + a += (r - l) * (u - b); + x0 = min(x0, l); + x1 = max(x1, r); + y0 = min(y0, b); + y1 = max(y1, u); + } + x1 -= x0; + y1 -= y0; + cout << (x1 == y1 && x1 * y1 == a ? "YES\n" : "NO\n"); +} +const int inf = (int)1e9 + 7; +const int N = (int)3e5 + 7; +int n; +int a[N]; +int ans = inf; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + n + 1); + int cnt = n / 2 - 1; + for (int i = 0; i <= cnt; i++) ans = min(ans, a[n - (cnt - i)] - a[i + 1]); + cout << ans << endl; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << '\n'; +} +string A, B, C; +int a, b, c, a1, b1, c1, aa[3000], bb[3000], cc[3000]; +int main() { + cin >> A >> B; + for (int i = 0; i < A.size(); i++) { a = a * 10 + (A[i] - '0'); } + for (int j = 0; j < B.size(); j++) { b = b * 10 + (B[j] - '0'); } + c = a + b; + int num = 1; + while (a > 0) { + int s = a % 10; + if (s == 0) { + a /= 10; + continue; + } + aa[num] = s; + num++; + a /= 10; + } + for (int i = num - 1; i >= 1; i--) a1 = a1 * 10 + aa[i]; + num = 1; + while (b > 0) { + int s = b % 10; + if (s == 0) { + b /= 10; + continue; + } + bb[num] = s; + num++; + b /= 10; + } + for (int i = num - 1; i >= 1; i--) b1 = b1 * 10 + bb[i]; + num = 1; + while (c > 0) { + int s = c % 10; + if (s == 0) { + c /= 10; + continue; + } + cc[num] = s; + num++; + c /= 10; + } + for (int i = num - 1; i >= 1; i--) c1 = c1 * 10 + cc[i]; + if (a1 + b1 == c1) { + cout << "YES" << endl; + } else + cout << "NO" << endl; + return 0; +} +int n; +int main() { + cin >> n; + int a[n + 10]; + for (int i = 0; i < n; ++i) { + cin >> a[i]; + if (a[i] % 2 == 0) { a[i] -= 1; } + } + for (int j = 0; j < n - 1; ++j) { cout << a[j] << " "; } + cout << a[n - 1] << endl; + return 0; +} +int main() { + int a, b, n, i; + cin >> n >> a >> b; + int C[n]; + for (i = 0; i < n; i++) cin >> C[i]; + sort(C, C + n); + cout << C[b] - C[b - 1] << endl; +} +int a[1005]; +map mp; +const double eps = 1e-8; +void init() { + for (int i = 0; i <= 1000; i++) { mp[i * i] = 1; } +} +int main() { + init(); + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = n - 1; i >= 0; i--) { + if (!mp[a[i]]) { + cout << a[i] << endl; + return 0; + } + } +} +int main() { + int a, b[101]; + cin >> a; + for (int i = 0; i < a / 2; i++) { cin >> b[i]; } + sort(b, b + (a / 2)); + int ans1 = 0, ans2 = 0; + for (int i = 0; i < a / 2; i++) { + ans1 += abs(b[i] - (i * 2 + 1)); + ans2 += abs(b[i] - (i * 2 + 2)); + } + cout << min(ans1, ans2) << endl; + return 0; +} +int b[5][5]; +int main() { + int a[5][5]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + cin >> a[i][j]; + b[i][j] = 1; + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (a[i][j] % 2 == 1) { + if (b[i][j] == 1) + b[i][j] = 0; + else + b[i][j] = 1; + if (b[i][j - 1] == 1) + b[i][j - 1] = 0; + else + b[i][j - 1] = 1; + if (b[i][j + 1] == 1) + b[i][j + 1] = 0; + else + b[i][j + 1] = 1; + if (b[i - 1][j] == 1) + b[i - 1][j] = 0; + else + b[i - 1][j] = 1; + if (b[i + 1][j] == 1) + b[i + 1][j] = 0; + else + b[i + 1][j] = 1; + } + } + } + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { cout << b[i][j]; } + cout << "\n"; + } + return 0; +} +int u, v, n, m, k, c, ans, mx, ind, a[1009], visited[1005], sum; +vector s[1005], adj[1005]; +set st; +void DFS(int u, int x) { + visited[u] = 1; + s[x].push_back(u); + st.insert(u); + for (int i = 0; i < adj[u].size(); i++) + if (visited[adj[u][i]] == 0) DFS(adj[u][i], x); +} +int main() { + cin >> n >> m >> k; + for (int i = 0; i < k; i++) cin >> a[i]; + for (int i = 0; i < m; i++) { + cin >> u >> v; + adj[u].push_back(v); + adj[v].push_back(u); + } + for (int i = 0; i < k; i++) { + DFS(a[i], a[i]); + int sz = s[a[i]].size(); + sum = 0; + for (int j = 0; j < sz; j++) sum += adj[s[a[i]][j]].size(); + sum /= 2; + ans += (sz * (sz - 1)) / 2 - sum; + mx = max(mx, sz); + } + sum = 0, c = 0; + for (int i = 1; i <= n; i++) { + if (st.find(i) == st.end()) { + c++; + sum += adj[i].size(); + } + } + sum /= 2; + ans += (c * (c - 1)) / 2 - sum + (mx * c); + cout << ans << endl; + return 0; +} +int main() { + int n, k, a, b; + cin >> n >> k; + int p = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + p += b - a + 1; + } + cout << (k - p % k) % k << '\n'; + return 0; +} +int main() { + int a, b, c, d, e, f; + cin >> a >> b >> c >> d >> e >> f; + if (a + b + c == d + e + f) + cout << "YES" << endl; + else if (a + b + d == c + e + f) + cout << "YES" << endl; + else if (a + b + e == c + d + f) + cout << "YES" << endl; + else if (a + b + f == c + d + e) + cout << "YES" << endl; + else if (a + c + d == b + e + f) + cout << "YES" << endl; + else if (a + c + e == b + d + f) + cout << "YES" << endl; + else if (a + c + f == b + d + e) + cout << "YES" << endl; + else if (a + d + e == b + c + f) + cout << "YES" << endl; + else if (a + d + f == b + c + e) + cout << "YES" << endl; + else if (a + e + f == b + c + d) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, d[5011], lzl = 0; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> d[i]; } + for (int i = 1; i <= n; i++) { + for (int l = 1; l <= n; l++) { + if (d[l] == i) { + for (int c = 1; c <= n; c++) { + if (d[c] == l && d[i] == c) { + cout << "YES" << endl; + lzl++; + i = n + 1; + } + } + } + } + } + if (lzl == 0) { cout << "NO" << endl; } + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int red = 0, green = 0, blue = 0; + int bookred = 0, bookgreen = 0, bookblue = 0; + red = n * 2; + green = n * 5; + blue = n * 8; + if (red % k == 0) { + bookred = red / k; + } else { + bookred = red / k + 1; + } + if (blue % k == 0) { + bookblue = blue / k; + } else { + bookblue = blue / k + 1; + } + if (green % k == 0) { + bookgreen = green / k; + } else { + bookgreen = green / k + 1; + } + int total = 0; + total = bookred + bookblue + bookgreen; + cout << total << endl; + return 0; +} +int main() { + int n, a, b, step = 0, step1 = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) + ++step; + else if (a < b) + ++step1; + } + if (step > step1) + cout << "Mishka" << endl; + else if (step < step1) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; +} +char s[1001][1001]; +int main() { + int n; + int num; + int sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { cin >> s[i]; } + int p; + for (int k = 'a'; k <= 'z'; k++) { + for (int l = k; l <= 'z'; l++) { + num = 0; + for (int i = 0; i < n; i++) { + int j; + p = strlen(s[i]); + for (j = 0; j < p; j++) { + if (s[i][j] == k || s[i][j] == l) { + continue; + } else + break; + } + if (j == p) { num += p; } + } + if (num > sum) { sum = num; } + } + } + cout << sum << endl; + return 0; +} +int main() { + int n, x, ct = 0, mini, maxi; + cin >> n; + n -= 1; + cin >> mini; + maxi = mini; + while (n--) { + cin >> x; + if (x > maxi) { + maxi = x; + ct++; + } else if (x < mini) { + mini = x; + ct++; + } + } + cout << ct << endl; + return 0; +} +int main() { + int y; + cin >> y; + while (true) { + y += 1; + int a = y / 1000; + int b = y / 100 % 10; + int c = y / 10 % 10; + int d = y % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } + } + cout << y << endl; + return 0; +} +int main() { + int n; + char arr[300][300]; + cin >> n; + for (int i = 0; i < n; i++) { + for (int t = 0; t < n; t++) { cin >> arr[i][t]; } + } + char ch1 = arr[0][0], ch2 = arr[0][1]; + if (ch1 == ch2) { + cout << "NO" << endl; + return 0; + } + int p1 = 0, p2 = n - 1; + for (int i = 0; i < n; i++) { + if (arr[i][p1] == ch1 && arr[i][p2] == ch1) { + for (int t = 0; t < n; t++) { + if (t != p1 && t != p2) { + if (arr[i][t] != ch2) { + cout << "NO" << endl; + return 0; + } + } + } + p1++; + p2--; + } else { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, k; + while (cin >> n >> k) { + if (k >= 3 * n) + cout << "0" << endl; + else if (k <= 2 * n) + cout << n << endl; + else + cout << n - k + k / n * n << endl; + } + return 0; +} +const int INF = int(1e9 + 7); +int main() { + string s; + cin >> s; + stack p; + for (int a = 0; a < s.size(); a++) { + if (p.empty()) + p.push(s[a]); + else { + if (p.top() == s[a]) + p.pop(); + else + p.push(s[a]); + } + } + s = ""; + while (!p.empty()) { + s += p.top(); + p.pop(); + } + reverse((s).begin(), (s).end()); + cout << s << endl; + return 0; +} +const int N = 1e5 + 50; +long long a, b, cnt; +long long ans[N]; +int i, j, k, t, m, n; +void dfs(long long st, long long step) { + if (st > b) return; + ans[step] = st; + if (st == b) { + cnt = step; + cout << "YES" << '\n'; + cout << cnt + 1 << '\n'; + cout << ans[0]; + for (i = 1; i < cnt + 1; i++) cout << " " << ans[i]; + cout << '\n'; + return; + } + if (st * 2 <= b) dfs(st * 2, step + 1); + if (st * 10 + 1 <= b) dfs(st * 10 + 1, step + 1); +} +int main() { + cin >> a >> b; + cnt = 0; + dfs(a, 0); + if (!cnt) cout << "NO" << '\n'; + return 0; +} +int main() { + string s; + cin >> s; + sort(s.begin(), s.end()); + char c = s[s.size() - 1]; + string r = ""; + r += c; + for (int i = s.size() - 2; i >= 0; i--) { + if (s[i] == c) + r += s[i]; + else { + break; + } + } + cout << r << endl; +} +int main() { + string s, t[5]; + int a = 0; + cin >> s; + for (int i = 0; i < 5; i++) { + cin >> t[i]; + if (s[0] == t[i][0] || s[1] == t[i][1]) { + a = 1; + break; + } + } + if (a == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + int i, val; + vector v(n + 1); + string s; + cin >> s; + for (i = 0; i < n; i++) { + if (s[i] == '1') + v[i + 1] = 1; + else + v[i + 1] = 0; + } + int aa = min(a, b); + int bb = max(a, b); + int j; + int count = 0; + for (i = aa; i <= bb;) { + if (v[i] == 0) { + int index = i; + for (j = i; j <= bb; j++) { + if (v[j] == 0) index = j; + } + if (index == bb) break; + if (index != bb) { + i = index + 1; + count++; + } + } else { + int index = i; + for (j = i; j <= bb; j++) { + if (v[j] == 1) index = j; + } + if (index == bb) break; + if (index != bb) { + i = index + 1; + count++; + } + } + } + cout << count << endl; +} +int main() { + long long a; + cin >> a; + bool arr[100001] = {false}; + long long present = 0; + long long ans = 0; + for (long long i = 0; i < 2 * a; i++) { + long long b; + cin >> b; + if (arr[b]) { + arr[b] = false; + present--; + } else { + arr[b] = true; + present++; + } + ans = max(ans, present); + } + cout << ans << endl; + return 0; +} +long long a[15][15]; +int main() { + long long n, i, j; + cin >> n; + for (i = 0; i < n; i++) { + a[0][i] = 1; + a[i][0] = 1; + } + for (i = 1; i < n; i++) { + for (j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } + } + cout << a[n - 1][n - 1] << endl; + return 0; +} +const int MAX_N = 1e+5; +void solve() { + long long n; + cin >> n; + long long a[n][n]; + long long row[n], col[n]; + for (int i = 0; i < n; i++) { + row[i] = 0; + col[i] = 0; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> a[i][j]; + row[i] += a[i][j]; + col[j] += a[i][j]; + } + } + long long answer = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (col[j] > row[i]) answer++; + } + } + cout << answer << endl; +} +int main() { + int t; + t = 1; + while (t--) solve(); + return 0; +} +int a[100005]; +int main() { + int x, y, z; + while (cin >> x >> y >> z) { + memset(a, 0, sizeof(a)); + for (int i = x; i <= z; i += x) { a[i]++; } + int flag = 0; + for (int i = y; i <= z; i += y) { + if (a[i] == 1) flag++; + } + cout << flag << endl; + } +} +int main() { + int n; + cin >> n; + int sum1 = 0, sum2 = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum1 |= a; + } + for (int i = 0; i < n; i++) { + int a; + cin >> a; + sum2 |= a; + } + cout << sum1 + sum2 << endl; +} +int a[5005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + string gems[6] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"}; + string color; + map mp; + mp["purple"] = 0; + mp["green"] = 1; + mp["blue"] = 2; + mp["orange"] = 3; + mp["red"] = 4; + mp["yellow"] = 5; + int id[6] = {0, 0, 0, 0, 0, 0}; + int i, n, m; + cin >> n; + cin.ignore(); + m = 6 - n; + i = 0; + while (i < n) { + cin >> color; + id[mp[color]] = 1; + i++; + } + cout << m << endl; + if (m > 0) { + i = 0; + while (i < 6) { + if (id[i] == 0) cout << gems[i] << endl; + i++; + } + } + return 0; +} +long long i, j, n, k, l = 100, m, sum, a, cnt; +vector v; +int main() { + cin >> n; + for (i = 1; i <= min(n, l); i++) { + a = n - i; + sum = 0; + while (a > 0) { + sum = sum + a % 10; + a = a / 10; + } + if (sum == i) cnt++, v.push_back(n - i); + } + cout << cnt << "\n"; + sort(v.begin(), v.end()); + for (i = 0; i < v.size(); i++) cout << v[i] << "\n"; +} +int main() { + long long n; + cin >> n; + long long k; + cin >> k; + long long A[n]; + long long sum = 0; + for (long long i = 0; i < n; i++) cin >> A[i], sum += A[i]; + sort(A, A + n); + cout << max(A[n - 1], (sum + k + n - 1) / n) << " " << A[n - 1] + k << "\n"; + return 0; +} +int main() { + int x, a = 0, b = 0; + cin >> x; + int z[x]; + for (int i = 0; i < x; i++) { cin >> z[i]; } + int min = z[0]; + int max = z[0]; + for (int i = 0; i < x; i++) { + if (z[i] < min) { + min = z[i]; + a++; + } else if (z[i] > max) { + max = z[i]; + b++; + } + } + cout << a + b << endl; +} +vector unos, dos, tres; +int main() { + long long int a, b, c, ans, n; + cin >> n; + for (long long int i = 1; i <= n; i++) { + cin >> a; + if (a == 1) { unos.push_back(i); } + if (a == 2) { dos.push_back(i); } + if (a == 3) { tres.push_back(i); } + } + a = unos.size(); + b = dos.size(); + c = tres.size(); + ans = min(min(a, b), c); + cout << ans << endl; + for (long long int i = 0; i < ans; i++) { cout << unos[i] << " " << dos[i] << " " << tres[i] << endl; } +} +int n, s, q; +int main() { + int t, w, i, j, k, cnt, ans = 0; + cin >> n >> s >> q; + while (s < n) { + ans++; + s *= q; + } + cout << ans << endl; + return 0; +} +void fastIo() {} +int main() { + fastIo(); + int sum = 0; + for (int i = 0; i < 5; i++) { + int temp; + cin >> temp; + sum += temp; + } + if (sum % 5 == 0 && sum >= 5) + cout << sum / 5 << endl; + else + cout << "-1" << endl; + return 0; +} +void fast() {} +void solve() { + int n; + cin >> n; + cout << __builtin_popcount(n) << "\n"; +} +int main() { + solve(); + return 0; +} +const int P = 1000000007; +long long p[400], i, n, ans; +string s; +int main() { + p[0] = 1; + for (i = 1; i < 300; i++) p[i] = 2 * p[i - 1] % P; + cin >> s; + n = s.length(); + for (i = 0; i < n; i++) ans = (ans + (s[i] - '0') * p[2 * n - i - 2]) % P; + cout << ans << endl; +} +const long double eps = 1e-10; +const int inf = 1000000010; +const int mod = 1000 * 1000 * 1000 + 7; +const int MAXN = 1 << 15; +signed long long n, k; +int main() { + cin >> n; + cout << 2 << endl; + for (signed long long k = 2; k <= n; k++) { cout << k * (k + 1) * (k + 1) - k + 1 << endl; } + return 0; +} +void solve() { + string s; + cin >> s; + int t = 0; + int qmarks = 0; + int count = 0; + for (size_t i = 0; i < s.length(); ++i) { + t = 0; + qmarks = 0; + for (size_t j = i; j < s.length(); ++j) { + if (s[j] == '(') { + ++t; + } else if (s[j] == ')') + --t; + else + ++qmarks; + if (qmarks > t) { + if (qmarks > 0) { + --qmarks; + ++t; + } else + break; + } + if ((j - i + 1) % 2 == 0 && qmarks >= t) { ++count; } + } + } + cout << count << '\n'; +} +int main() { + solve(); + return 0; +} +const int N = 400000 + 10; +int main() { + int x, y, z, n; + while (cin >> x >> y >> z >> n) { + x -= z; + y -= z; + int ans = n - x - y - z; + if (x < 0 || y < 0 || ans <= 0) + cout << -1 << endl; + else + cout << ans << endl; + } + return 0; +} +int main() { + int n, x, i, j, k, l, s, m; + int maxx = 0; + long long int diffuclty = 9999999999999; + int rock = 1; + cin >> n; + vector a; + for (j = 0; j < n; j++) { + cin >> x; + a.push_back(x); + } + for (s = 0; s < n - 2; s++) { + vector b(n - 1); + for (l = 0, m = 0; l < n - 1; l++, m++) { + if (l == rock) { m++; } + b[l] = a[m]; + } + for (i = 0, k = 1; i < n - 2; i++, k++) { maxx = b[k] - b[i] > maxx ? b[k] - b[i] : maxx; } + diffuclty = maxx < diffuclty ? maxx : diffuclty; + rock++; + maxx = 0; + } + cout << diffuclty << endl; + return 0; +} +int main() { + long long ans, k, a, b, c, d; + int T; + cin >> T; + while (T--) { + ans = 0; + cin >> a >> b >> c >> d; + k = a / d; + ans += k; + k = a / (d * b) * c; + ans += k; + cout << ans << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + cout << "25" << endl; +} +int main() { + int n; + cin >> n; + cout << (n * 2) - (n / 2) << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + int ans = a[1] - a[0] + a[2] - a[1]; + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int n1 = n / 2; + int j; + for (int i = 0; i < n1; i++) { + for (j = n1; j > i; j--) cout << "*"; + for (int k = n1 - j * 2 - 1; k < n1; k++) cout << "D"; + for (int l = i; l < n1; l++) cout << "*"; + cout << endl; + } + for (int i = 0; i < n; i++) cout << "D"; + cout << endl; + int l; + for (int i = 0; i < n1; i++) { + for (j = 0; j <= i; j++) cout << "*"; + for (int k = 0; k < n - j * 2; k++) cout << "D"; + for (j = 0; j <= i; j++) cout << "*"; + cout << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + char str[1000]; + cin >> str; + while (m--) { + int l, r; + char a, b; + cin >> l >> r >> a >> b; + for (int i = l; i <= r; i++) { + if (str[i - 1] == a) str[i - 1] = b; + } + } + cout << str << endl; +} +int main() { + int w, h, u1, u2, d1, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + while (h > 0) { + w = w + h; + if (h == d1) + w = w - u1; + else if (h == d2) + w = w - u2; + h = h - 1; + if (w <= 0) w = 0; + } + if (w < 0) + cout << 0 << endl; + else + cout << w << endl; + return 0; +} +int main() { + int n, k, value = 0, aux1, aux2; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> aux1 >> aux2; + value += (aux2 - aux1 + 1); + } + if (value % k == 0) + cout << 0 << endl; + else + cout << (k - (value % k)) % k << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) { + cout << a << endl; + } else + cout << 1 << endl; +} +const double pi = 3.14159265358979323846; +int main() { + int p[4]; + int a, b; + cin >> p[0] >> p[1] >> p[2] >> p[3] >> a >> b; + int i, j, k, l, m; + int ctr = 0; + int ans = 0; + for (i = a; i < b + 1; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) { + if (k == j) continue; + for (l = 0; (l < 4); l++) { + if ((l == j) || (l == k)) continue; + for (m = 0; m < 4; m++) { + if ((m == l) || (m == j) || (m == k)) continue; + if (i == (((i % p[j]) % p[k]) % p[l]) % p[m]) ctr++; + } + } + } + } + if (ctr >= 7) ans++; + ctr = 0; + } + cout << ans << "\n"; + return 0; +} +const int M = 10000 + 10; +int gcd(int x, int y) { + return (y == 0 ? x : gcd(y, x % y)); +} +int main() { + int a, b; + cin >> a >> b; + string s[2] = {"Dasha", "Masha"}; + int g = gcd(a, b); + if (a > b) { + int tmp = a; + a = b; + b = tmp; + string t = s[0]; + s[0] = s[1]; + s[1] = t; + } + int start1 = 0; + long long int ans1 = 0; + long long int ans2 = 0; + for (int num = 1; num <= a / gcd(a, b); num++) { + int div = (b - start1) / a; + int res = (b - start1) % a; + ans1 = ans1 + div * a; + ans2 = ans2 + b - start1 - div * a; + start1 = start1 + (div + (res != 0)) * a - b; + start1 = start1 % b; + ans1 += start1; + } + ans1 -= a; + ans2 += a; + if (ans1 > ans2) { cout << s[0] << endl; } + if (ans1 < ans2) { cout << s[1] << endl; } + if (ans1 == ans2) { cout << "Equal" << endl; } + return 0; +} +int main() { + int w, h, k, sum = 0; + cin >> w >> h >> k; + for (int q = 0; q < k; q++) { + sum += ((2 * w) + (2 * h) - 4); + w -= 4; + h -= 4; + if (w <= 1 || h <= 1) break; + } + cout << sum << endl; + return 0; +} +long long n, m, res, c[1010], sum[1010]; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) { + sum[c[i]]++; + bool flag = true; + for (int i = 1; i <= n; i++) + if (sum[i] == 0) { + flag = false; + break; + } + if (flag) { + for (int i = 1; i <= n; i++) sum[i]--; + res++; + } + } + cout << res << endl; + return 0; +} +int main() { + long long a, b; + cin >> a >> b; + long long sum = b, l = 0; + string s; + long long n; + while (a--) { + cin >> s >> n; + if (s[0] == '+') sum += n; + if (s[0] == '-') { + if (sum - n >= 0) + sum -= n; + else + l++; + } + } + cout << sum << " " << l << endl; + return 0; +} +int main() { + int a, b, c, l = 0, n, p, i, sum = 0; + cin >> n >> p; + cin >> c; + for (int i = 0; i < c; i++) { + cin >> a; + sum++; + sum += (a - l - 1) / p; + l = a; + } + sum += (n - l) / p; + cout << sum << endl; + return 0; +} +map tree; +int q; +void add_path(long long u, long long v, long long w) { + while (u != v) { + if (u < v) { + tree[v] += w; + v /= 2; + } else { + tree[u] += w; + u /= 2; + } + } +} +long long dist(long long u, long long v) { + long long res = 0; + while (u != v) { + if (u < v) { + res += tree[v]; + v /= 2; + } else { + res += tree[u]; + u /= 2; + } + } + return res; +} +int main() { + cin >> q; + int t; + long long u, v, w; + for (int i = 0; i < q; ++i) { + cin >> t; + if (t == 1) { + cin >> u >> v >> w; + add_path(u, v, w); + } else { + cin >> u >> v; + cout << dist(u, v) << "\n"; + } + } + return 0; +} +int n, m, count1; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + int count = 0; + for (int i = 0; i < 3; i++) { + cin >> m; + if (m == 1) count++; + } + if (count >= 2) count1++; + } + cout << count1 << endl; + return 0; +} +const int N = (int)1e3 + 5; +int main() { + int l, r, d, q; + cin >> q; + while (q--) { + cin >> l >> r >> d; + cout << ((d >= l && d <= r) ? ((r + d) / d) : 1) * d << "\n"; + } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + sort(s.begin(), s.end()); + cout << s << "\n"; + return 0; +} +int main() { + int n, m, x, y; + cin >> n >> m >> x >> y; + vector a; + vector b; + int inp; + for (int i = 0; i < n; i++) { + cin >> inp; + a.push_back(inp); + } + for (int i = 0; i < m; i++) { + cin >> inp; + b.push_back(inp); + } + int j = 0, cnt = 0; + vector L; + vector R; + for (int i = 0; i < n; i++) { + while (j < m && b[j] < a[i] - x) { j++; } + if (j == m) { break; } + if (a[i] - x <= b[j] && a[i] + y >= b[j]) { + L.push_back(i + 1); + R.push_back(j + 1); + cnt++; + j++; + } + } + cout << cnt << endl; + for (int i = 0; i < cnt; i++) { cout << L[i] << ' ' << R[i] << endl; } + return 0; +} +int main() { + int x, ans; + cin >> x; + ans = x / 5; + if (x % 5) ++ans; + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + bool turned[m + 1]; + memset(turned, 0, m + 1); + for (int i = 0; i < n; i++) { + int k; + cin >> k; + for (int j = 0; j < k; j++) { + int a; + cin >> a; + turned[a] = true; + } + } + for (int i = 1; i < m + 1; i++) { + if (turned[i] == false) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +string str; +int N; +int main() { + cin >> str; + N = str.size(); + int ans = 0; + for (int i = 0; i < N; i++) { + int pre = 0; + int q = 0; + for (int j = i; j < N; j++) { + if (str[j] == '?') + q++; + else if (str[j] == '(') + pre++; + else if (str[j] == ')') + pre--; + if (pre < 0) break; + while (q > pre) { + q--; + pre++; + } + if ((j - i + 1) % 2 == 0 && q == pre) ans++; + } + } + cout << ans << endl; + return (0); +} +int main() { + long long n, m; + cin >> n >> m; + vector a(m, 0); + for (long long i = 0; i < m; i++) { cin >> a[i]; } + sort(a.begin(), a.end()); + long long l, r; + l = r = 0; + r = n - 1; + long long mn = a[m - 1] - a[0]; + while (r != m) { + mn = min(mn, a[r] - a[l]); + l++; + r++; + } + cout << mn << endl; + return 0; +} +int main() { + long int x, y, z, c = 0, s = 10000000, j; + vector a; + vector b; + cin >> x; + while (x--) { + cin >> y; + a.push_back(y); + } + b = a; + x = a.size(); + sort(a.begin(), a.end()); + for (long int i = 0; i < x; i++) { + if (a[0] == b[i]) { + j = i; + c++; + } + } + if (c == 1) + cout << j + 1 << endl; + else + cout << "Still Rozdil" << endl; + return 0; +} +int main() { + int a; + cin >> a; + int l = 0; + int m = a; + for (int i = 0; i < a; i++) { + m = m / 10; + l = l + 1; + if (m == 0) { break; } + } + for (int k = 1; k <= l; k++) { + int b[k] = {}; + for (int i = 1; i <= k; i++) { + int sum1 = 0; + b[k - i] = 4; + for (int j = 0; j < k; j++) { sum1 = 10 * sum1 + b[j]; } + if (a % sum1 == 0) { + cout << "YES" << endl; + return 0; + } + } + for (int i = 1; i <= k; i++) { + int sum1 = 0; + b[k - i] = 7; + for (int j = 0; j < k; j++) { sum1 = 10 * sum1 + b[j]; } + if (a % sum1 == 0) { + cout << "YES" << endl; + return 0; + } + } + for (int j = 0; j < k; j++) { b[j] = 0; } + for (int i = 1; i <= k; i++) { + int sum1 = 0; + b[k - i] = 7; + for (int j = 0; j < k; j++) { sum1 = 10 * sum1 + b[j]; } + if (a % sum1 == 0) { + cout << "YES" << endl; + return 0; + } + } + for (int i = 1; i <= k; i++) { + int sum1 = 0; + b[k - i] = 4; + for (int j = 0; j < k; j++) { sum1 = 10 * sum1 + b[j]; } + if (a % sum1 == 0) { + cout << "YES" << endl; + return 0; + } + } + } + cout << "NO" << endl; +} +int main() { + int n, m; + cin >> n >> m; + char Map[110][110]; + int flag = 1; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> Map[i][j]; + if (Map[i][j] != 'B' && Map[i][j] != 'W' && Map[i][j] != 'G') { flag = 0; } + } + } + if (flag) { + cout << "#Black&White" << endl; + } else { + cout << "#Color" << endl; + } + return 0; +} +int seq[110]; +int n, d; +int main() { + cin >> n >> d; + int i; + for (i = 1; i <= n; i++) cin >> seq[i]; + long long int res = 2; + long long int ax; + for (i = 1; i <= n - 1; i++) { + ax = 0; + if (seq[i] + 2 * d == seq[i + 1]) ax = 1; + if (seq[i] + d < seq[i + 1] - d) ax = 2; + res += ax; + } + cout << res << endl; +} +long long gcd(long long p, long long q) { + return q == 0 ? p : gcd(q, p % q); +} +const int manx = 1e5 + 10; +int main() { + int n, m, flag = 0, ans = 0; + cin >> n >> m; + int a[110]; + for (int i = 0; i < n; ++i) cin >> a[i]; + for (int i = 0; i < n; ++i) { + if (a[i] <= m) + ans++; + else { + flag = 1; + break; + } + } + for (int i = n - 1; i >= 0; --i) { + if (a[i] <= m) + ans++; + else + break; + } + if (flag == 0) + cout << n << endl; + else + cout << ans << endl; + return 0; +} +int a[1000]; +int main() { + int m, n, t, t2; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> t; + for (int j = 1; j <= t; j++) { + cin >> t2; + a[t2]++; + } + } + int flag = 0; + for (int j = 1; j <= m; j++) { + if (a[j] == 0) flag = 1; + } + if (flag) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +int main() { + char a[128] = {0}; + bool vis[128] = {0}; + int len = 0, count = 0; + char ch; + while ((ch = cin.get()) != '\n') { + a[len++] = ch; + if (len > 1 && a[len - 1] == 'K' && a[len - 2] == 'V') { + count++; + vis[len - 1] = vis[len - 2] = 1; + } + } + a[len] = '\0'; + if (len == 1) { + cout << 0 << endl; + } else { + for (int i = 0; i < len; i++) { + if (!vis[i]) { + if (a[i] == 'V') { + if (i != 0 && a[i - 1] == 'V') { + count++; + break; + } + } else { + if (i != len - 1 && a[i + 1] == 'K') { + count++; + break; + } + } + } + } + cout << count << endl; + } + return 0; +} +int main() { + int n, k, arr[100100]; + cin >> n >> k; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + int prev = arr[n - 1]; + bool f = 1; + int idx = 0; + for (int i = n - 2; i >= 0; i--) { + if (arr[i] != prev) { + idx = i + 1; + break; + } + prev = arr[i]; + if (i == 0) { + idx = 0; + break; + } + } + if (idx > k - 1) { + cout << -1 << endl; + } else { + cout << idx << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int a, b, ans = 0, mod; + cin >> a >> b; + if (a == b) { + cout << "1" << endl; + continue; + } + if (a == 1 || b == 1) { + cout << max(a, b) << endl; + continue; + } + while (a != b) { + if (a > b) swap(a, b); + if (b % a == 0) { + ans += (b / a); + b = b % a; + break; + } else { + ans += (b / a); + b = b % a; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c, t1, ans, ans2; + cin >> a >> b >> c; + t1 = (a * c) - (b * c); + ans = t1 / b; + ans2 = ans + 1; + { + if (t1 % b == 0) + cout << ans << endl; + else + cout << ans2 << endl; + } +} +int main() { + string s; + int k; + cin >> s >> k; + set ms; + for (int i = 0; i < s.size(); i++) { ms.insert(s[i]); } + if (s.size() < k) + cout << "impossible" << endl; + else { + if (ms.size() < k) + cout << k - ms.size() << endl; + else + cout << 0 << endl; + } + return 0; +} +int main() { + long long a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + cout << abs(a[0] - a[2]) << endl; + return 0; +} +int main() { + int n, res = 0; + long long x, d; + cin >> n >> x; + string s; + for (int i = 0; i < n; ++i) { + cin >> s >> d; + d = (s[0] == '+' ? d : -d); + if (x + d < 0) { + res++; + } else { + x += d; + } + } + cout << x << ' ' << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int minP = 1e5 + 1; + int p, a; + long long ans = 0; + for (int i = 0; i < n; i++) { + cin >> a >> p; + minP = min(minP, p); + ans += a * minP; + } + cout << ans << '\n'; + return 0; +} +int k, n, s, p; +int main() { + cin >> k >> n >> s >> p; + int sum; + if (n == s || n < s) + sum = k; + else if (n % s == 0) + sum = k * (n / s); + else + sum = k * (n / s + 1); + if (sum % p == 0) + cout << sum / p << endl; + else + cout << sum / p + 1 << endl; + return 0; +} +int main() { + long long l, r, k = 1, t; + cin >> l >> r; + t = r; + while (t > 0) k *= 10, t /= 10; + k /= 10; + l = max(k, l); + if ((k * 5 >= l && k * 5 <= r) || (k * 5 - 1 >= l && k * 5 - 1 <= r)) + cout << (k * (long long)5) * (k * (long long)5 - 1) << endl; + else if (k * 5 > r) + cout << r * (k * (long long)10 - (long long)1 - r) << endl; + else + cout << l * (k * (long long)10 - (long long)1 - l) << endl; +} +int main() { + int n, d, cur = 0, max = 0; + cin >> n >> d; + while (d--) { + string s; + cin >> s; + if (s.find('0') != string::npos) { + cur++; + } else { + if (cur > max) { max = cur; } + cur = 0; + } + } + if (cur > max) { max = cur; } + cout << max << endl; +} +int max(int a, int b) { + if (a > b) return a; + return b; +} +int main() { + int *a, *b, n, m, x, y; + cin >> n >> m >> x >> y; + a = new int[n]; + b = new int[m]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { cin >> b[i]; } + int dem = 0, ans = 0; + int flag; + vector u, v, temp1, temp2; + dem = 0; + int k = 1, r = 1; + while (r <= m && k <= n) { + if (a[k - 1] - x <= b[r - 1] && a[k - 1] + y >= b[r - 1]) { + temp1.push_back(k); + temp2.push_back(r); + dem++; + r++; + k++; + } else if (a[k - 1] - x > b[r - 1]) { + r++; + } else { + k++; + } + if (dem == m) break; + } + ans = max(ans, dem); + if (ans == dem) { + u.clear(); + v.clear(); + for (int i = 0; i < temp1.size(); i++) { + u.push_back(temp1[i]); + v.push_back(temp2[i]); + } + temp1.clear(); + temp2.clear(); + } + if (dem != 0) + ; + cout << ans << endl; + for (int i = 0; i < u.size(); i++) { cout << u[i] << " " << v[i] << endl; } +} +string s; +int a, b, n; +int main() { + cin >> n; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') + a++; + else + b++; + } + cout << abs(b - a) << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + int l = a.size(), ll = b.size(); + if (l != ll) { + cout << max(l, ll) << endl; + } else if (a == b) { + cout << -1 << endl; + } else { + cout << a.size() << endl; + } + return 0; +} +int n, k, a[1003], x; +int main() { + cin >> n >> k >> x; + int sum = 0; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n - k; i++) { sum += a[i]; } + sum += (x * k); + cout << sum << endl; + return 0; +} +int main() { + int s, v1, v2, t1, t2; + cin >> s >> v1 >> v2 >> t1 >> t2; + int a1 = s * v1 + 2 * t1; + int a2 = s * v2 + 2 * t2; + if (a1 < a2) { cout << "First" << endl; } + if (a1 > a2) { cout << "Second" << endl; } + if (a1 == a2) { cout << "Friendship" << endl; } +} +int main() { + string a, b; + cin >> a >> b; + long long n; + cin >> n; + cout << a << " " << b << "\n"; + while (n--) { + string x, y; + cin >> x >> y; + if (x == a) { + a = y; + } else if (x == b) { + b = y; + } + cout << a << " " << b << "\n"; + } + return 0; +} +const int mod = 998244353; +long long qpow(long long x, long long y) { + long long s = 1; + while (y) { + if (y & 1) s = s * x % mod; + x = x * x % mod; + y >>= 1; + } + return s; +} +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); + return x * f; +} +long long inve(long long x) { + return x == 1 ? 1 : (mod - mod / x) * inve(mod % x) % mod; +} +const int maxn = 1e5 + 5; +int a[maxn], b[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + int k = 0, num = 0; + for (int i = 0; i < m; i++) { + int x, y, l; + cin >> x >> l >> y; + if (x == 1) b[k++] = l; + if (l == 1e9) num++; + } + sort(b, b + k); + int tmp = k, ans = num + n; + for (int i = 0, j = 0; i < n; i++) { + while (j < k && b[j] < a[i]) tmp--, j++; + ans = min(ans, tmp + i); + } + cout << (ans) << "\n"; + return 0; +} +inline int who(char a, char b) { + if (a == b) return 0; + if (a == 'R' && b == 'S') return 1; + if (a == 'S' && b == 'P') return 1; + if (a == 'P' && b == 'R') return 1; + return 2; +} +int games; +int cnt[3]; +int main() { + cin >> games; + string a, b; + cin >> a >> b; + int A = games / ((a.size()) * (b.size())); + int B = games % ((a.size()) * (b.size())); + for (int i = 0; i < ((a.size()) * (b.size())); i++) cnt[who(a[i % (a.size())], b[i % (b.size())])]++; + cnt[1] *= A; + cnt[2] *= A; + for (int i = 0; i < B; i++) cnt[who(a[i % (a.size())], b[i % (b.size())])]++; + cout << cnt[2] << " " << cnt[1] << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int b[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> b[i][j]; } + } + int count = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (b[i][0] == b[j][1] && i != j) { count += 1; } + } + } + cout << count << endl; +} +int main() { + long long t; + cin >> t; + for (long long i = 0; i < t; i++) { + long long a, b, k; + cin >> a >> b >> k; + cout << a * (k / 2) - b * (k / 2) + a * (k % 2) << endl; + } +} +int dx[] = {-1, 0, 0, 1}; +int dy[] = {0, -1, 1, 0}; +int gcd(int a, int b) { + if (b == 0) + return a; + else + gcd(b, a % b); +} +int main() { + int m, n; + while (cin >> m >> n) { + int c[100010], a[100010]; + for (int i = 0; i < m; i++) cin >> c[i]; + for (int j = 0; j < n; j++) cin >> a[j]; + int j = 0, cnt = 0; + for (int i = 0; i < m; i++) { + if (c[i] <= a[j]) { + cnt++; + j++; + } + } + cout << cnt << endl; + } +} +int main() { + int a, b; + cin >> a >> b; + if (a < b) { swap(a, b); } + cout << b << " " << (a - b) / 2 << endl; + return 0; +} +int main() { + int t, s, q, cnt = 0; + cin >> t >> s >> q; + while (s < t) { + cnt++; + s *= q; + } + cout << cnt << endl; +} +void selection_insert(int a[], int n) { + for (int i = 0; i < n - 1; i++) { + int imin = i; + for (int j = i + 1; j < n; j++) { + if (a[j] < a[imin]) { imin = j; } + } + int temp; + temp = a[i]; + a[i] = a[imin]; + a[imin] = temp; + } +} +int main() { + int n; + cin >> n; + int arr[n]; + int z = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + z = z + arr[i]; + } + selection_insert(arr, n); + z = z / 2; + int ans = 0, cnt = 0; + while (ans <= z) { + ++cnt; + ans += arr[n - cnt]; + } + cout << cnt << endl; +} +int min(int a, int b, int c) { + if (a <= b) { + if (a <= c) { return a; } + } + if (b <= c) { + if (b <= a) { return b; } + } + return c; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + cout << min(k * l / nl, c * d, p / np) / n << endl; + return 0; +} +const long long int size = 1e5 + 5; +int main() { + long long int n; + cin >> n; + vector a(n, 1); + long long int cnt = 1; + while (cnt < n) { + for (long long int i = 0; i < n; i++) { + if (i == 0) + continue; + else + a[i] = a[i - 1] + a[i]; + } + cnt++; + } + cout << a[n - 1] << endl; + return 0; +} +int gcd(int a, int b) { + if (a % b) + gcd(b, a % b); + else + return b; +} +int main() { + int a, b, c, t; + cin >> a >> b >> c; + int s = a * b / gcd(max(a, b), min(a, b)); + cout << c / s << endl; + return 0; +} +long long gcd(long long a, long long b) { + return a % b ? gcd(b, a % b) : b; +} +int main() { + long long a, b, c, d, e; + cin >> a >> b; + c = (a * b) / gcd(a, b); + d = c / a; + e = c / b; + if (a > b) + e -= 1; + else if (b > a) + d -= 1; + if (d > e) + cout << "Dasha" << endl; + else if (e > d) + cout << "Masha" << endl; + else + cout << "Equal" << endl; + return 0; +} +const double Pi = acos(-1.0); +int getPossibilities(int num) { + if (num == 0) return 2; + if (num == 1) return 7; + if (num == 2) return 2; + if (num == 3) return 3; + if (num == 4) return 3; + if (num == 5) return 4; + if (num == 6) return 2; + if (num == 7) return 5; + if (num == 8) return 1; + return 2; +} +int main() { + int n; + cin >> n; + cout << getPossibilities(n / 10) * getPossibilities(n % 10) << "\n"; + return 0; +} +int main() { + int a, b; + cin >> a >> b; + if (abs(a - b) == 1) { + cout << "YES" << endl; + } else if (a == b && (a != 0 && b != 0)) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +short int a, b; +int main() { + cin >> a >> b; + if (a + b > 0 && abs(a - b) <= 1) + cout << "YES" << '\n'; + else + cout << "NO" << '\n'; + return 0; +} +int main() { + string s; + int c = 0; + cin >> s; + int len = s.size(); + for (int i = 0; i < len; i++) { + if (strchr("aeiou13579", s[i])) { c++; } + } + cout << c << endl; + return 0; +} +int main() { + int c; + while (cin >> c) { + int **a = new int *[c]; + for (int i = 0; i < c; i++) a[i] = new int[2]; + for (int i = 0; i < c; i++) + for (int j = 0; j < 2; j++) cin >> a[i][j]; + int s = 0; + for (int i = 0; i < c; i++) { + for (int j = 0; j < c; j++) + if (a[i][0] == a[j][1]) s += 1; + } + cout << s << endl; + } +} +long long n, m, ans, a[1000]; +long long sum, T; +string s; +bool result; +int read() { + int v = 0, f = 1; + char c = getchar(); + while (c < 48 || 57 < c) { + if (c == '-') f = -1; + c = getchar(); + } + while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); + return v * f; +} +bool ac(string s, int n) { + char *pre = &s[0]; + char *end = &s[n - 1]; + while (pre < end) { + if (abs((*pre) - (*end)) == 0 || abs((*pre) - (*end)) == 2) { + pre++; + end--; + } else { + return false; + } + } + return true; +} +int main() { + while (cin >> T) { + while (T--) { + cin >> n; + cin >> s; + result = ac(s, n); + if (result) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + } + return 0; +} +const int M = 100 + 5; +int a[M]; +int edge[M][M]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < m; i++) { + int x, y; + cin >> x >> y; + x--; + y--; + edge[x][y] = 1; + edge[y][x] = 1; + } + int ans = 1E+9; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + for (int k = j + 1; k < n; k++) { + if (edge[i][j] == 1 && edge[j][k] == 1 && edge[k][i] == 1) { + if (ans > a[i] + a[j] + a[k]) { ans = a[i] + a[j] + a[k]; } + } + } + } + } + if (ans == 1E+9) { + cout << "-1" << endl; + } else { + cout << ans << endl; + } + return 0; +} +char a1[20] = {'v', '<', '^', '>', 'v', '<', '^', '>', 'v'}; +char a2[20] = {'v', '>', '^', '<', 'v', '>', '^', '<', 'v'}; +int main() { + char s1, s2; + int num; + while (cin >> s1) { + cin >> s2; + cin >> num; + int tep1; + int tep2; + tep1 = 0; + tep2 = 0; + int ans1; + ans1 = 0; + int ans2; + ans2 = 0; + num %= 4; + for (int i = 0; i < 9; i++) { + if (a1[i] == s1) { + if (a1[i + num] == s2) { ans1 = 1; } + break; + } + } + for (int i = 0; i < 9; i++) { + if (a2[i] == s1) { + if (a2[i + num] == s2) { ans2 = 1; } + break; + } + } + if (ans1 == 1 && ans2 == 0) { + cout << "cw" << endl; + } else if (ans1 == 0 && ans2 == 1) { + cout << "ccw" << endl; + } else { + cout << "undefined" << endl; + } + } + return 0; +} +int main() { + int n, s; + int t1[100000], t2[100000]; + cin >> n >> s; + for (int i = 0; i < n; ++i) { cin >> t1[i]; } + for (int i = 0; i < n; ++i) { cin >> t2[i]; } + if (t1[0] == 1) { + if (t1[s - 1] == 1) { + cout << "YES" << endl; + return 0; + } + if (t2[s - 1] == 1) { + for (int i = s; i < n; i++) { + if (t1[i] == 1 && t2[i] == 1) { + cout << "YES" << endl; + return 0; + } + } + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int c[n]; + for (int i = 0; i < n; i++) { cin >> c[i]; } + if (k <= n * 8) { + int sum = 0; + int p = 0; + for (int i = 0; i < n; i++) { + if (c[i] <= 8) { + c[i] = c[i]; + } else { + int a = c[i] - 8; + c[i] = 8; + c[i + 1] = (c[i + 1] + a); + } + sum += c[i]; + if (sum >= k) { + cout << i + 1 << endl; + break; + } else { + p++; + } + } + if (p == n) { cout << "-1" << endl; } + } else { + cout << "-1" << endl; + } +} +string s; +int b[200]; +int v[100]; +int main() { + int n; + cin >> n; + memset(b, 0, sizeof(b)); + b['a'] = 1; + b['i'] = 1; + b['e'] = 1; + b['o'] = 1; + b['u'] = 1; + b['y'] = 1; + cin >> s; + memset(v, 0, sizeof(v)); + string s1 = ""; + string tmp = ""; + for (int i = 0; i < n; i++) { + if (b[s[i]]) { + if (i == 0 || v[i - 1] == 0) + v[i] = 1; + else + v[i] = -1; + } else + v[i] = 0; + } + for (int i = 0; i < n; i++) { + if (v[i] == 1 || v[i] == 0) cout << s[i]; + } + cout << s1 << endl; +} +string s; +long long n, p; +const long long MAX = 2000; +const long long ALPH = 31; +bool used[MAX][2][ALPH][ALPH]; +bool termina = false; +string resp = ""; +char getChar(long long x) { + char c = x + 'a'; + return c; +} +bool f(long long pos = 0, long long upper = 0, long long ant1 = 30, long long ant2 = 30) { + if (termina) { return false; } + if (pos == n) { + if (upper == 1) { + termina = true; + return true; + } else { + return false; + } + } + if (used[pos][upper][ant1][ant2]) { return false; } + used[pos][upper][ant1][ant2] = true; + long long d = s[pos] - 'a'; + if (upper == 0) { + for (long long i = d; i < p; i++) { + if (i == ant1 || i == ant2) { continue; } + if (i == d) { + if (f(pos + 1, 0, ant2, i)) { + resp += getChar(i); + return true; + } + } else { + if (f(pos + 1, 1, ant2, i)) { + resp += getChar(i); + return true; + } + } + } + } else { + for (long long i = 0; i < p; i++) { + if (i == ant1 || i == ant2) { continue; } + if (f(pos + 1, 1, ant2, i)) { + resp += getChar(i); + return true; + } + } + } + return false; +} +void doit() { + cin >> n >> p; + cin >> s; + if (f()) { + for (long long i = resp.size() - 1; i >= 0; i--) { cout << resp[i]; } + cout << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long T = 1; + while (T--) { doit(); } + return 0; +} +int main() { + int n, i, no_of_8 = 0, groups; + char c; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> c; + if (c == '8') no_of_8++; + } + groups = n / 11; + if (no_of_8 >= groups) + cout << groups << endl; + else + cout << no_of_8 << endl; + return 0; +} +const long long mod = 1e9 + 7; +long long dp[1001][1001]; +long long C(long long n, long long r) { + if (n < r) return 0; + if (n == r) return dp[n][r] = 1; + if (r == 0) return dp[n][r] = 1; + if (dp[n][r]) + return dp[n][r] % (mod); + else + dp[n][r] = (C(n - 1, r) % (mod) + C(n - 1, r - 1) % (mod)) % (mod); + return dp[n][r] % (mod); +} +int main() { + long long k, i, j; + cin >> k; + vector c(k + 1); + for (i = 1; i < k + 1; i++) cin >> c[i]; + long long curr = c[1]; + long long ans = 1; + long long temp = 0; + long long n1, n2; + n1 = n2 = 0; + for (i = 2; i < k + 1; i++) { + temp = 0; + n1 += curr; + for (j = 1; j < c[i] + 1; j++) { + n2 = c[i] - j; + temp = (C(n1 + n2 - 1, n1 - 1) % mod + temp % mod) % mod; + } + curr = c[i]; + if (ans) ans = (ans % mod * temp % mod) % mod; + } + cout << (ans + mod) % mod << '\n'; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + for (int x = 0; x <= 100; x++) { + int t = c - x * a; + if (t < 0) continue; + if (t % b == 0) { + cout << "Yes\n"; + exit(0); + } + } + cout << "No\n"; + return 0; +} +int main() { + long long n; + cin >> n; + long long curr = 2; + for (long long i = 1; i <= n; i++) { + long long req = (i + 1) * (i + 1) * i; + cout << req - curr / i << '\n'; + curr = i * (i + 1); + } +} +int main() { + int n, one = 0, zero = 0; + string s; + cin >> n >> s; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '1') + one++; + else + zero++; + } + cout << abs(one - zero) << endl; + return 0; +} +int a, b, c, n; +int x, y, z; +int main() { + while (cin >> a >> b >> c >> n) { + x = a - c; + y = b - c; + z = x + y + c; + if (z >= n || a < c || b < c) + cout << "-1" << endl; + else + cout << n - z << endl; + } + return 0; +} +int N; +long long P; +string S[2000010]; +int main() { + cin >> N >> P; + for (int i = 1; i <= N; i++) { cin >> S[i]; } + long double fans = 0; + for (int i = N; i >= 1; i--) { + if (S[i] == "halfplus") { + fans += 0.5; + fans *= 2.00000000; + } else { + fans *= 2.00000000; + } + } + long double cost = 0; + for (int i = 1; i <= N; i++) { + cost += (fans / 2.00000) * (P); + if (S[i] == "half") { + fans /= 2.000; + } else { + fans /= 2.000; + fans -= 0.500; + } + } + cout << fixed << setprecision(0) << cost << endl; + return 0; +} +string n = "qwertyuiopasdfghjkl;zxcvbnm,./"; +string t, s, r = ""; +int main() { + cin >> t >> s; + if (t == "R") { + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < n.length(); j++) { + if (s[i] == n[j]) { r += n[j - 1]; } + } + } + } else if (t == "L") { + for (int i = 0; i < s.length(); i++) { + for (int j = 0; j < n.length(); j++) { + if (s[i] == n[j]) { r += n[j + 1]; } + } + } + } + cout << r << endl; + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int l, r, v, p; + cin >> p >> v >> l >> r; + int ans = p / v; + ans -= r / v - (l - 1) / v; + cout << ans << endl; + } + return 0; +} +int main() { + int n, k, *arr, sum = 0; + cin >> n >> k; + arr = new int[n]; + for (int i = 0; i < n; i++) { cin >> arr[i]; } + for (int i = 0; i < n; i++) { + if (arr[k - 1] == 0) { + if (arr[i] > arr[k - 1]) { sum += 1; } + } else { + if (arr[i] >= arr[k - 1]) sum += 1; + } + } + cout << sum << endl; + return 0; +} +const int M = 2e5 + 5; +const int inf = 1e9 + 5; +int main() { + int n; + vector v; + cin >> n; + for (int i = 0; i < n; i++) { + int t; + cin >> t; + v.push_back(t); + } + sort(v.begin(), v.end()); + cout << v[n / 2] << endl; + return 0; +} +int main() { + int n, i, j; + cin >> n; + for (i = 1; i <= n / 2 + 1; i++) { + for (j = n / 2 - i + 1; j > 0; j--) cout << "*"; + for (j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (j = n / 2 - i + 1; j > 0; j--) cout << "*"; + cout << endl; + } + for (i = 1; i <= n / 2; i++) { + for (j = 1; j <= i; j++) cout << "*"; + for (j = 2 * (n / 2 - i) + 1; j >= 1; j--) cout << "D"; + for (j = 1; j <= i; j++) cout << "*"; + cout << endl; + } +} +int main() { + int c; + cin >> c; + cin.ignore(); + string a[c]; + int i = 0; + int j = 0; + while (i < c) { + getline(cin, a[i]); + i++; + } + while (j < c) { + if (a[j].length() > 10) { + cout << a[j][0] << (a[j].length() - 2) << a[j][a[j].length() - 1] << endl; + } else { + cout << a[j] << endl; + } + j++; + } +} +int main() { + int n; + int num[100]; + int a[100]; + cin >> n; + int count = 0; + for (int i = 0; i < n; ++i) { + cin >> num[i]; + if (num[i] == 1) { + a[i] = -1; + ++count; + } else { + a[i] = 1; + } + } + int max = -2; + int sum = 0; + for (int i = 0; i < n; ++i) { + sum += a[i]; + if (sum > max) { max = sum; } + if (sum < 0) { sum = 0; } + } + cout << max + count << endl; + return 0; +} +int main() { + int n, m, s = 0, i, flag = 0; + cin >> n >> m; + char a; + for (i = 0; i < n; i++) { + cin >> a; + if (a == 'G' || a == 'T') { + while (1) { + cin >> a; + s++; + if (s % m == 0) { + if (a == 'G' || a == 'T') { flag = 1; } + if (a == '#') break; + } + if (a == 'T' || a == 'G') break; + } + break; + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + long long n, m; + cin >> n >> m; + if (n >= m) + cout << 1 << endl; + else { + if (m % n == 0) + cout << m / n << endl; + else + cout << m / n + 1 << endl; + } + return 0; +} +int dp[5000][5]; +int s[5000], c[5000]; +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int n, k, i, c = 0, f = 0; + cin >> n >> k; + string str; + cin >> str; + multiset ms; + for (i = 0; i < str.size(); i++) { ms.insert(str[i]); } + multiset::iterator it; + for (it = ms.begin(); it != ms.end(); it++) { + if (ms.count(*it) > k) { + f = 1; + break; + } + } + if (f == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; + return 0; +} +int ar[3]; +int n; +int number; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 3; j++) { + cin >> number; + ar[j] += number; + } + } + if (ar[0] == 0 && ar[1] == 0 && ar[2] == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + char s[101]; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '8') ans++; + } + if (ans == 0 || n / 11 == 0) + cout << 0 << endl; + else if (ans > n / 11) + cout << n / 11 << endl; + else + cout << ans << endl; + return 0; +} +int main() { + string s; + cin >> s; + string t; + cin >> t; + int ans = 1; + for (int i = 0; i < t.size(); i++) { + if (s[ans - 1] == t[i]) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, n; + while (cin >> a >> b >> c >> n) { + int ans = a + b - c; + ans = n - ans; + if (ans <= 0 || a < c || b < c) + cout << -1 << endl; + else + cout << ans << endl; + } + return 0; +} +int main() { + long long int i, n, k, w, sum = 0, x = 0, y, count = 0; + cin >> n; + long long int a[n]; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (i = n - 1; i >= 0; i--) { sum = sum + a[i]; } + for (i = n - 1; i >= 0; i--) { + x++; + count = count + a[i]; + if (sum / 2 < count) { break; } + } + cout << x; + cout << "\n"; +} +int main() { + int i, a, b, j, k = 1, l, n, m; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a >> b; + k = 0; + while (a > 0 && b > 0) { + if (b > a) swap(a, b); + if (b > 0) { + k += a / b; + a = a % b; + } + if (a > 0) { + k += b / a; + b %= a; + } + } + cout << k << endl; + } +} +int main() { + int n; + cin >> n; + int a[n + 2]; + int res = 9999999; + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n - 2; i++) { res = min(res, a[i + 2] - a[i]); } + for (int i = 0; i < n - 1; i++) { res = max(res, a[i + 1] - a[i]); } + cout << res << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n + 1]; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) { + if (a[a[a[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + map map1; + for (int k = 0; k < n; k++) { + char tmp1[2]; + cin >> tmp1; + if (tmp1[0] == '+') { + long long tmp; + cin >> tmp; + char t[20]; + for (int i = 0; i < 20; i++) { + t[i] = tmp % 2 + 1; + tmp /= 10; + } + t[19] = 0; + map1[t]++; + } + if (tmp1[0] == '-') { + long long tmp; + cin >> tmp; + char t[20]; + for (int i = 0; i < 20; i++) { + t[i] = tmp % 2 + 1; + tmp /= 10; + } + t[19] = 0; + map1[t]--; + } + if (tmp1[0] == '?') { + char tmp[20] = {}; + cin >> tmp; + int lens = strlen(tmp); + lens--; + char t[20] = {}; + for (int i = 0; i <= lens; i++) { t[i] = tmp[lens - i] - '0'; } + for (int i = 0; i < 20; i++) { t[i]++; } + t[19] = 0; + cout << map1[t] << endl; + } + } + return 0; +} +long long a[100010], b[100010], c[100010]; +long long n, m, k, t, r, s, aux, rta; +int main() { + while (cin >> n) { + memset(a, 0, sizeof(a)); + int rta = 0; + while (n) { n /= 2, rta++; } + cout << rta << endl; + } + return 0; +} +string x, y; +int s; +int main() { + int n; + cin >> n >> x >> y; + for (int i = 0; i < n; i++) { + int a = x[i] - 48; + int b = y[i] - 48; + int j = abs(a - b); + int h; + if (a > b) + h = 9 - a + b + 1; + else + h = 9 - b + a + 1; + if (j < h) + s += j; + else + s += h; + } + cout << s << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n][2]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 2; j++) { cin >> a[i][j]; } + } + int cnt = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][0] == a[j][1]) cnt++; + } + } + cout << cnt << endl; + return 0; +} +inline int getint() { + int r = 0, k = 1; + char c = getchar(); + for (; c < '0' || c > '9'; c = getchar()) + if (c == '-') k = -1; + for (; c >= '0' && c <= '9'; c = getchar()) r = r * 10 + c - '0'; + return r * k; +} +int main() { + int n = getint(); + int r = 0, l = 0; + while (n--) { + int x = getint(); + int y = getint(); + if (x > 0) r++; + if (x < 0) l++; + } + if (r > 1 && l > 1) + puts("No"); + else + puts("Yes"); + return 0; +} +int main() { + int n, i, j, min; + long int c = 0; + int a[100000]; + int p[100000]; + vector aux; + cin >> n; + cin >> a[0]; + cin >> p[0]; + min = 0; + c = p[0] * a[0]; + for (i = 1; i < n; i++) { + cin >> a[i]; + cin >> p[i]; + if (p[min] > p[i]) min = i; + c += a[i] * p[min]; + } + cout << c << "\n"; + return 0; +} +bool is_vowel(char ch) { + string vowels = "aeiou"; + return binary_search(vowels.begin(), vowels.end(), ch); +} +bool is_valid(string s) { + for (int i = 0; i < int(s.length()); ++i) { + if (s[i] == 'n') continue; + if (is_vowel(s[i])) + continue; + else { + if (i + 1 >= (int)s.length()) + return false; + else if (!is_vowel(s[i + 1])) + return false; + } + } + return true; +} +int main() { + string s; + cin >> s; + if (is_valid(s)) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int const N = 5e5; +long long a[N]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + long long mn = a[0]; + int x = 0; + bool flage = false; + for (int i = 1; i < n; i++) + if (a[i] < mn) { + mn = a[i]; + x = i; + } + for (int i = 0; i < n; i++) + if (a[i] == mn && i != x) flage = true; + if (flage) + cout << "Still Rozdil" << endl; + else + cout << x + 1 << endl; +} +int main() { + long long n, k; + while (cin >> n >> k) { + long long i; + for (i = 1; i <= k; i++) { + if (n % 10 == 0) + n /= 10; + else { + n = n - 1; + } + } + cout << n << endl; + } +} +int main() { + int n, s1, s2, x[100], y[100], flag = 0; + cin >> n; + cin >> s1; + for (int i = 1; i <= s1; i++) cin >> x[i]; + cin >> s2; + for (int i = 1; i <= s2; i++) cin >> y[i]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= s1; j++) + if (x[j] == i) flag = 1; + if (flag == 0) + for (int j = 1; j <= s2; j++) + if (y[j] == i) flag = 1; + if (flag == 0) { + cout << "Oh, my keyboard!" << endl; + return 0; + } else + flag = 0; + } + cout << "I become the guy." << endl; + return 0; +} +int main() { + int n; + cin >> n; + int cnt = 0; + while (n) { + cnt += n & 1; + n >>= 1; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int mi1, ma1, mi2, ma2, mi3, ma3; + cin >> mi1 >> ma1; + cin >> mi2 >> ma2; + cin >> mi3 >> ma3; + int ans1, ans2, ans3; + if (ma1 + ma2 + mi3 <= n) { + ans1 = ma1; + ans2 = ma2; + ans3 = n - ma1 - ma2; + } else if (ma1 + mi2 + mi3 <= n) { + ans1 = ma1; + ans2 = n - ma1 - mi3; + ans3 = mi3; + } else if (mi1 + mi2 + mi3 <= n) { + ans1 = n - mi2 - mi3; + ans2 = mi2; + ans3 = mi3; + } + cout << ans1 << " " << ans2 << " " << ans3 << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n / 2); + for (int i = 0; i < n / 2; i++) { + cin >> a[i]; + a[i]--; + } + sort(a.begin(), a.end()); + int x = 0, y = 0; + for (int i = 0; i < n / 2; i++) { + x += abs(i * 2 - a[i]); + y += abs(i * 2 + 1 - a[i]); + } + cout << min(x, y) << '\n'; + return 0; +} +string a, b; +int main() { + cin >> a >> b; + string mn = "z"; + mn[0]++; + string A, B; + for (int i = 0; i < a.size(); i++) { + A += a[i]; + B = ""; + for (int j = 0; j < b.size(); j++) { + B += b[j]; + string s = A; + s += B; + mn = min(mn, s); + } + } + cout << mn << endl; +} +int main() { + int n, i; + int a[100005]; + while (cin >> n) { + int Min = 0x7fffffff; + for (i = 1; i <= n; i++) { + cin >> a[i]; + Min = min(a[i], Min); + } + int ans = 0x7fffffff; + int t = -1; + for (i = 1; i <= n; i++) { + if (a[i] == Min) { + t = i; + break; + } + } + for (i = t + 1; i <= n; i++) { + if (a[i] == Min) { + ans = min(i - t, ans); + t = i; + } + } + cout << ans << endl; + } + return 0; +} +const int maxn = 130; +int n; +int a; +set se; +int main() { + cin >> n; + se.clear(); + while (n--) { + cin >> a; + if (a != 0) se.insert(a); + } + int ans = se.size(); + cout << ans << endl; + return 0; +} +int main() { + char a[52][52]; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= m; j++) a[i][j] = '.'; + for (int i = 1; i <= n; i++) { + if (i % 2) { + for (int j = 1; j <= m; j++) a[i][j] = '#'; + } else if ((i / 2) % 2) + a[i][m] = '#'; + else + a[i][1] = '#'; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) cout << a[i][j]; + cout << endl; + } +} +const long long N = 1e5 + 3; +const long long MN = 1e9; +long long n, c; +string s, s1, s2, s3; +vector v; +map mp; +int main() { + cin >> n >> s; + for (long long i = 0; i < n; i++) { cin >> s1; } + if (n % 2 == 1) { + cout << "contest"; + } else { + cout << "home"; + } + cout << "\n"; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int ans = INT_MAX; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (k % a == 0) ans = min(ans, k / a); + } + cout << ans << endl; + return (0); +} +int main() { + int n, temp = 1; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + int od = abs(i - (n + 1) / 2) + abs(j - (n + 1) / 2); + if (od > n / 2) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } + return 0; +} +const long long inf = (long long)1e18; +long long gcd(long long a, long long b) { + long long r; + while (b) { + r = a % b; + a = b; + b = r; + } + return a; +} +long long lcm(long long a, long long b) { + return a / gcd(a, b) * b; +} +long long fpow(long long n, long long k, int p = 1000000007) { + long long r = 1; + for (; k; k >>= 1) { + if (k & 1) r = r * n % p; + n = n * n % p; + } + return r; +} +int inv(int a, int p = 1000000007) { + return fpow(a, p - 2, p); +} +long long spf[1000001 + 1]; +void sieve() { + for (int i = 1; i < 1000001; i++) { spf[i] = i; } + for (long long i = 2; i < 1000001; i += 2) { spf[i] = 2; } + for (long long i = 3; i < 1000001; i += 2) { + if (spf[i] == i) { + for (long long j = i * i; j < 1000001; j += i) { spf[j] = min(i, (long long)spf[j]); } + } + } +} +int main() { + long long n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + long long gg = a[0]; + for (int i = 1; i < n; i++) gg = __gcd(gg, a[i]); + long long m = *max_element(a.begin(), a.end()); + long long val = int(m / gg) - n; + if (val % 2 == 0) + cout << "Bob\n"; + else + cout << "Alice\n"; +} +int main() { + int n, sum = 0; + char s[21]; + cin >> s; + n = strlen(s); + sum = 25 * n + 26; + cout << sum << endl; + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int x[100]; + int i; + for (i = 0; i < n; i++) { cin >> x[i]; } + sort(x, x + n); + int tot = k, ct = 0; + if (tot >= m) { + cout << 0 << endl; + return 0; + } + for (i = n - 1; i >= 0; i--) { + ct++; + tot += (x[i] - 1); + if (tot >= m) { + cout << ct << endl; + return 0; + } + } + cout << -1 << endl; +} +int main() { + long long n; + cin >> n; + long long c[n], max = 1; + for (long long i = 0; i < n; i++) { cin >> c[i]; } + for (long long i = 0; i < n - 1; i++) { + long long cnt = 1; + for (long long j = i + 1; j < n; j++) { + if (c[j] == c[i]) { cnt++; } + } + if (i == 0) max = cnt; + if (cnt >= max) max = cnt; + } + cout << max << endl; + return 0; +} +int main() { + int n, temp; + cin >> n; + int count = 0; + for (int i = 1; i <= n; i++) { + int votes = 0; + for (int j = 1; j <= 3; j++) { + cin >> temp; + votes += temp; + } + if (votes >= 2) count++; + } + cout << count << endl; +} +int main() { + int l, r, a, x, max, min, n; + cin >> l >> r >> a; + if (a == 0) { + x = l > r ? r : l; + x *= 2; + cout << x << endl; + } else { + min = l > r ? r : l; + max = l > r ? l : r; + if (min + a < max) { + x = 2 * (min + a); + cout << x << endl; + } else { + n = min + a - max; + x = max + n / 2; + cout << x * 2 << endl; + } + } + return 0; +} +int main() { + long long int k; + vector v; + cin >> k; + string s; + cin >> s; + long long int j, i, sz = s.size(); + long long int f[26]; + for (i = 0; i < 26; i++) f[i] = 0; + for (i = 0; i < sz; i++) { + long long int temp = (long long int)s[i] - 97; + if (f[temp] == 0) { + f[temp]++; + v.push_back(i); + } + } + long long int vsz = v.size(); + if (k > vsz) + cout << "NO\n"; + else { + cout << "YES\n"; + for (i = 0; i < (k - 1); i++) { + for (j = v[i]; j < v[i + 1]; j++) cout << s[j]; + cout << "\n"; + } + for (j = v[k - 1]; j < sz; j++) cout << s[j]; + cout << "\n"; + } + return 0; +} +int main() { + int n; + long long ans = 0; + cin >> n; + string a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + long long c = 0; + for (int j = 0; j < n; j++) { + if (a[i][j] == 'C') { c++; } + } + if (c == 2) { + ans++; + } else if (c > 2) { + ans += (c * (c - 1) / 2); + } + } + for (int i = 0; i < n; i++) { + long long c = 0; + for (int j = 0; j < n; j++) { + if (a[j][i] == 'C') { c++; } + } + if (c == 2) { + ans++; + } else if (c > 2) { + ans += (c * (c - 1) / 2); + } + } + cout << ans << '\n'; + return 0; +} +int main() { + int a, b, c[200] = {}; + int f = 0; + for (int i = 3; i < 203; i++) { + if ((i - 2) * 180 % i == 0) c[f] = ((i - 2) * 180) / i; + f++; + } + cin >> a; + for (int j = 0; j < a; j++) { + cin >> b; + if (b == 179) { + cout << "YES" << endl; + continue; + } + for (int i = 0; i < 200; i++) { + if (c[i] == b) { + cout << "YES" << endl; + break; + } + if (c[i] > b) { + cout << "NO" << endl; + break; + } + } + } +} +int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005]; +int main() { + int n, k; + cin >> n >> k; + ++n; + for (int i = 1; i < n; ++i) cin >> d[i]; + for (int i = 1; i < n; ++i) cin >> s[i]; + for (int i = n - 1; i >= 1; --i) { + if (s[i] > sufmax[i + 1]) { + mxpos[i] = i; + sufmax[i] = s[i]; + } else { + mxpos[i] = mxpos[i + 1]; + sufmax[i] = sufmax[i + 1]; + } + } + for (int i = 1; i < n; ++i) pred[i] = pred[i - 1] + d[i]; + int tott = 0, oil = s[1]; + for (int i = 1; i < n;) { + int j = i; + do { + oil -= d[j]; + ++j; + while (oil < 0) tott += k, oil += s[i]; + oil += s[j]; + } while (s[j] < s[i] && j < n); + i = j; + } + cout << tott + pred[n - 1] << endl; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + int x, y; + cin >> x >> y; + int x1, y1, x2, y2; + int tmp = abs(x) + abs(y); + if (x > 0 && y > 0) + x1 = 0, x2 = tmp, y1 = tmp, y2 = 0; + else if (x < 0 && y > 0) + x1 = -tmp, x2 = 0, y1 = 0, y2 = tmp; + else if (x < 0 && y < 0) + x1 = -tmp, x2 = 0, y1 = 0, y2 = -tmp; + else + x1 = 0, x2 = tmp, y1 = -tmp, y2 = 0; + cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n'; +} +int main() { + long long n; + while (cin >> n) { + long long ans = n / 5; + if (n % 5 != 0) ans++; + cout << ans << endl; + } +} +int main() { + string s; + string s2; + cin >> s; + cin >> s2; + int sL = s.length(); + int s2L = s2.length(); + if (sL != s2L) { + if (sL > s2L) { + int tmp = sL - s2L; + while (tmp--) { s2 = "0" + s2; } + } else { + int tmp = s2L - sL; + while (tmp--) { s = "0" + s; } + } + } + for (int i = 0; i < s.length(); i++) { + int x = (s[i] - '0') ^ (s2[i] - '0'); + cout << x; + } + cout << endl; +} +int main() { + int n, k, ct = 0, c = 0; + cin >> n >> k; + int ar[n], ar2[k]; + int f = 0; + for (int i = 0; i < n; i++) { + cin >> ar[i]; + if (ar[i] == 0) ct++; + } + if (k > 1) { + for (int i = 0; i < k; i++) { cin >> ar2[i]; } + cout << "Yes" << endl; + return 0; + } + if (k == 1) { + int bitch; + cin >> bitch; + int fl = 0; + for (int i = 0; i < n; i++) { + if (ar[i] == 0) { + ar[i] = bitch; + break; + } + } + for (int i = 1; i < n; i++) { + if (ar[i - 1] >= ar[i]) { + cout << "Yes" << endl; + return 0; + } + } + cout << "No" << endl; + } +} +int main() { + int list[10]; + memset(list, 0, sizeof(list)); + for (int i = 0; i < 6; i++) { + int temp; + cin >> temp; + list[temp]++; + } + for (int i = 0; i < 10; i++) { + if (list[i] == 4) { + for (int j = 0; j < 10; j++) { + if (list[j] == 2) { + cout << "Elephant" << endl; + return 0; + } + } + cout << "Bear" << endl; + return 0; + } else if (list[i] == 5) { + cout << "Bear" << endl; + return 0; + } else if (list[i] == 6) { + cout << "Elephant" << endl; + return 0; + } + } + cout << "Alien" << endl; + return 0; +} +int main() { + int n, m, x; + cin >> n >> m; + vector right, wong; + for (int i = 0; i < n; i++) { + cin >> x; + right.push_back(x); + } + for (int i = 0; i < m; i++) { + cin >> x; + wong.push_back(x); + } + sort(right.begin(), right.end()); + sort(wong.begin(), wong.end()); + if (right[n - 1] < wong[0] && right[0] * 2 < right[n - 1]) { + cout << right[n - 1] << endl; + return 0; + } else if (right[0] * 2 >= right[n - 1] && right[0] * 2 < wong[0]) { + cout << right[0] * 2 << endl; + return 0; + } else + cout << -1 << endl; +} +int main() { + bool flag = true; + int a, b; + cin >> a >> b; + for (int i = 0; i < a; i++) { + if (i % 2 == 0) { + for (int j = 0; j < b; j++) { cout << "#"; } + } else { + if (!flag) { + cout << "#"; + flag = true; + for (int j = 0; j < b - 1; j++) { cout << "."; } + } else { + flag = false; + for (int j = 0; j < b - 1; j++) { cout << "."; } + cout << "#"; + } + } + cout << endl; + } + return 0; +} +inline int Getint() { + register int s = 0; + register char c; + do + c = getchar(); + while (c < 48 || c > 57); + do + s = s * 10 + c - 48, c = getchar(); + while (c > 47 && c < 58); + return s; +} +inline int Hash() { + register int v = 0; + register char c; + do + c = getchar(); + while (c < 'A' || c > 'Z'); + do + v = v * 26 + (c - 'A'), c = getchar(); + while ('A' <= c && c <= 'Z'); + return v; +} +int main() { + register int n = Getint(), Home = Hash(); + register int _v = 1; + for (; n; --n) { + if (Hash() == Home) --_v; + if (Hash() == Home) ++_v; + } + return (puts(_v ? "home" : "contest"), 0); +} +int main() { + int l, last = -100, a, ret = 0, mret = 0; + cin >> l; + while (l--) { + cin >> a; + if (a >= last) + ++ret; + else { + if (mret < ret) mret = ret; + ret = 1; + } + last = a; + } + cout << (mret > ret ? mret : ret) << '\n'; + return 0; +} +int n, k, ans, x, sum, t; +int main() { + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> x; + if (x <= (k * 10)) + ans++; + else { + sum = 0; + while (x > 0) { + t = x % 10; + x /= 10; + if (t == 4 || t == 7) sum++; + } + if (sum <= k) ans++; + } + } + cout << ans << endl; +} +int main() { + long long n, ans = 2; + cin >> n; + if (n == 1) { + cout << 1 << endl; + return 0; + } + if (n == 2 || n == 3) { + cout << 2 << endl; + return 0; + } + cout << n / 2 + 1 << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = 0; + bool r = true; + while (x <= 10000 && r) { + int y = c - a * x; + if (y >= 0 && y % b == 0) + r = false; + else + x++; + } + if (r) + cout << "No\n"; + else + cout << "Yes\n"; + return 0; +} +int main() { + int n; + cin >> n; + while (n--) { + int t; + cin >> t; + string s; + cin >> s; + if (s.size() > 2 || s[0] < s[1]) { + cout << "YES" << endl; + cout << 2 << endl; + cout << s[0] << " " << &s[1] << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + int sum = a + b - c; + if (sum >= n || a > n || b > n || c > n || n == 0 || c > a || c > b) { + cout << -1 << endl; + } else { + cout << n - sum << endl; + } + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a.size() != b.size()) { + cout << max(a.size(), b.size()) << endl; + } else if (a.compare(b) == 0) { + cout << "-1" << endl; + } else { + int s = a.size(); + map mp; + int x = s; + while (x > 0) { + for (int i = 0; i < s && i + x <= s; i++) { + string st(a, i, x); + mp[st] = 1; + } + for (int i = 0; i < s && i + x <= s; i++) { + string st(b, i, x); + if (mp[st] == 0) { + cout << st.size() << endl; + return 0; + } + } + x--; + } + } +} +int main() { + int weight, high, sw1, sh1, sw2, sh2; + cin >> weight >> high >> sw1 >> sh1 >> sw2 >> sh2; + for (int i = high; i >= 0; i--) { + weight += i; + if (i == sh1) { + weight -= sw1; + if (weight < 0) { weight = 0; } + } + if (i == sh2) { + weight -= sw2; + if (weight < 0) { weight = 0; } + } + } + cout << weight << endl; + return 0; +} +const long long maxn = 1e5 + 8; +long long n, c, sum = 0; +long long t[maxn]; +queue que; +int main() { + cin >> n >> c; + for (int i = 1; i <= n; i++) { + cin >> t[i]; + if (t[i] - t[i - 1] <= c && i != 1) { + que.push(t[i]); + sum++; + } else + sum = 0; + } + cout << ++sum << endl; +} +int main() { + long long a_i, b_i, n; + cin >> n; + if (n % 2 == 0) + cout << 2 << endl; + else + cout << 1 << endl; +} +int main() { + int s, v1, v2, t1, t2, m, n; + cin >> s >> v1 >> v2 >> t1 >> t2; + m = (s * v1) + t1 + t1; + n = (s * v2) + t2 + t2; + if (m < n) { + cout << "First" << endl; + ; + } else if (n < m) { + cout << "Second" << endl; + ; + } else { + cout << "Friendship" << endl; + ; + } + return 0; +} +const int maxn = 200500; +int v[maxn]; +int h[maxn]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; ++i) cin >> v[i]; + sort(v, v + n); + int hn = 0; + int ans = 0; + for (int i = 0; i < m; ++i) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 == 1) { h[hn++] = x2; } + if (x2 == 1000000000) ans++; + } + sort(h, h + hn); + ans += n; + int i = 0, j = 0; + int cnt = hn; + while (i < n) { + while (j < hn && h[j] < v[i]) { + --cnt; + ++j; + } + ans = min(ans, cnt + i); + ++i; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + cout << floor(log2(n)) + 1 << '\n'; + return 0; +} +int main() { + int n, a, b, c, x, p, sum, lo, i; + while (cin >> n >> a >> b >> c) { + sum = 0; + lo = 1; + for (i = lo + 1; i <= n; i++) { + if (lo == 1) { + if (a < b) { + x = a, p = 2; + } else { + x = b, p = 3; + } + } + if (lo == 2) { + if (a < c) { + x = a; + p = 1; + } else { + x = c; + p = 3; + } + } + if (lo == 3) { + if (b < c) { + x = b; + p = 1; + } else { + x = c; + p = 2; + } + } + sum += x; + lo = p; + } + cout << sum << endl; + } + return 0; +} +const long long int inf = 1e15; +const int M = 1e9 + 7; +int arr[5000000], c[5000000]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 0; i < n; ++i) { cin >> c[i]; } + for (int i = 0; i < m; ++i) { cin >> arr[i]; } + int j = 0, cnt = 0; + for (int i = 0; i < n; ++i) { + if (c[i] <= arr[j]) cnt++, j++; + } + cout << cnt << endl; + return 0; +} +int main() { + string s11; + string s22; + cin >> s11; + cin >> s22; + long long k = 0; + long long ind = s11.size() - 1; + for (long long i = 0; i < s11.size(); ++i) { + if (s11[i] != '0') { + ind = i; + break; + } + } + long long ind2 = s22.size() - 1; + for (long long i = 0; i < s22.size(); ++i) { + if (s22[i] != '0') { + ind2 = i; + break; + } + } + string s1 = ""; + string s2 = ""; + for (long long i = ind; i < s11.size(); ++i) { s1 += s11[i]; } + for (long long i = ind2; i < s22.size(); ++i) { s2 += s22[i]; } + if (s1.size() < s2.size()) { k = -1; } + if (s1.size() > s2.size()) { k = 1; } + if (k == 0) { + for (long long i = 0; i < s1.size(); ++i) { + if (s1[i] < s2[i]) { + k = -1; + break; + } + if (s1[i] > s2[i]) { + k = 1; + break; + } + } + } + if (k == 0) { cout << "=" << endl; } + if (k == 1) { cout << ">" << endl; } + if (k == -1) { cout << "<" << endl; } + return 0; +} +int main() { + int n, i; + int a, b, c, d; + cin >> n; + while (1) { + n++; + a = n / 1000; + b = (n / 100) % 10; + c = (n / 10) % 10; + d = n % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) break; + } + cout << n << endl; +} +int main() { + int t, s, q; + while (cin >> t >> s >> q) { + int ans = 0; + while (s < t) { + ans++; + s *= q; + } + cout << ans << endl; + } +} +int main() { + long long n, k; + for (; cin >> n >> k;) { + if (k % n == 0) + cout << k / n << endl; + else + cout << k / n + 1 << endl; + } + return 0; +} +int main() { + int k, n, s, p; + cin >> k >> n >> s >> p; + int a; + if (n % s == 0) + a = n / s; + else + a = n / s + 1; + a = a * k; + int ans; + if (a % p == 0) + ans = a / p; + else + ans = a / p + 1; + cout << ans << endl; +} +long long a, b, jum; +vector v; +int main() { + cin >> a >> b; + while (b >= 1) { + jum++; + v.push_back(b); + if (a == b) { break; } + if (b < a) { + cout << "NO" << endl; + return 0; + } else if (b % 2 == 0) { + b = b / 2; + } else if (b % 2 == 1) { + b--; + if (b % 10 == 0) + b = b / 10; + else { + cout << "NO" << endl; + return 0; + } + } + } + sort(v.begin(), v.end()); + cout << "YES" << endl << jum << endl; + for (int i = 0; i < jum; i++) { + cout << v[i]; + if (i < jum - 1) + cout << " "; + else + cout << endl; + } +} +int main() { + int n, a; + cin >> n; + if (n <= 5) { + cout << "1\n"; + } else { + if (n % 5 == 0) { + a = (n / 5); + cout << a << endl; + } else { + a = (n / 5) + 1; + cout << a << endl; + } + } + return 0; +} +int main() { + long long n; + cin >> n; + cout << 2 << endl; + for (long long i = 2; i <= n; i++) { cout << i * (i + 1) * (i + 1) - i + 1 << endl; } + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int ans1 = 0, ans2 = 0, ans3 = 0; + if ((k * l) >= nl) ans1 = (k * l) / nl; + ans2 = c * d; + if (p >= np) ans3 = p / np; + ans2 = min(ans1, ans2); + ans3 = min(ans2, ans3); + ans3 /= n; + cout << ans3 << endl; + return 0; +} +int main() { + string s; + cin >> s; + int cnt = 0; + for (int i = 0; i < s.size() - 1; i++) { + if (s[i] == 'V' && s[i + 1] == 'K') { + s[i] = '.'; + s[i + 1] = '.'; + cnt++; + } + } + for (int i = 0; i < s.size() - 1; i++) { + if (s.substr(i, 2) == "VV" || s.substr(i, 2) == "KK") { + cnt++; + break; + } + } + cout << cnt << endl; + return 0; +} +int main() { + int x, h; + int x1, y1, x2, y2; + cin >> x >> h; + cin >> x1 >> y1 >> x2 >> y2; + int sum = x; + while (h >= 0) { + sum += h; + if (h == y1) { + sum -= x1; + } else if (h == y2) { + sum -= x2; + } + h--; + if (sum <= 0) { sum = 0; } + } + cout << sum << endl; + return 0; +} +int main() { + string s, c; + string s1 = "qwertyuiopasdfghjkl;zxcvbnm,./"; + while (cin >> c) { + cin >> s; + for (int i = 0; i < s.size(); i++) { + for (int j = 0; j < s1.size(); j++) { + if (s[i] == s1[j]) { + if (c == "R") { + cout << s1[j - 1]; + } else if (c == "L") { + cout << s1[j + 1]; + } + } + } + } + cout << endl; + } + return 0; +} +int main() { + int m; + while (cin >> m) { + int c[105]; + int sum = 0; + for (int i = 1; i <= m; i++) { + cin >> c[i]; + sum += c[i]; + } + int x, y; + cin >> x >> y; + int tem = 0; + int flag = 0; + for (int i = 1; i <= m; i++) { + tem += c[i]; + if (tem >= x && tem <= y && (sum - tem) >= x && (sum - tem) <= y) { flag = i + 1; } + if (flag) break; + } + cout << flag << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int x1, y1, x2, y2, s = 0; + for (int i = 0; i < n; ++i) { + cin >> x1 >> y1 >> x2 >> y2; + s += (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1); + } + cout << s << endl; + return 0; +} +const int N = (int)5e5 + 7, MOD = (int)1e9 + 7; +long long n, m, k; +long long a, b; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + long long x; + cin >> x; + a |= x; + } + for (int i = 1; i <= n; i++) { + long long x; + cin >> x; + b |= x; + } + cout << a + b << "\n"; + exit(0); +} +int main() { + int n, b = 0, c = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x < 0) { + c += x; + } else + b += x; + } + cout << b - c << '\n'; + return 0; +} +int main() { + int k; + string s; + cin >> k >> s; + vector v(256); + vector w; + for (int i = 0; i < s.size(); ++i) { + if (!v[s[i]]) { + v[s[i]] = true; + w.push_back(i); + } + } + if (w.size() < k) { + cout << "NO\n"; + } else { + cout << "YES\n"; + for (int i = 0; i < k - 1; ++i) cout << s.substr(w[i], w[i + 1] - w[i]) << endl; + cout << s.substr(w[k - 1]) << endl; + } + return 0; +} +int n; +int arr[52][52]; +bool check(int x, int y, int val) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (arr[x][i] + arr[j][y] == val) return true; + } + } + return false; +} +int main() { + cin >> n; + arr[n + 1][n + 1]; + int cnt1 = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + cin >> arr[i][j]; + if (arr[i][j] == 1) cnt1++; + } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (arr[i][j] != 1) { + int val = arr[i][j]; + if (check(i, j, val)) ans++; + } + } + } + if (cnt1 + ans == n * n) { + cout << "Yes" << endl; + } else + cout << "No" << endl; + return 0; +} +int main() { + long long n, s; + cin >> n >> s; + int ans = (s + n - 1) / n; + cout << ans << endl; +} +int main() { + int n; + cin >> n; + if (n == 2) + cout << "2" << endl; + else + cout << "1" << endl; + return 0; +} +int main() { + int n; + string st; + cin >> n; + getchar(); + getline(cin, st); + int count = 0, compare = 0; + for (int i = 0; i < n; i++) { + if (isupper(st[i])) count++; + compare = max(count, compare); + if (st[i] == ' ') count = 0; + } + cout << compare << endl; + return 0; +} +int main() { + string n; + cin >> n; + int count = 0; + sort(n.begin(), n.end()); + for (int i = 1; i < n.length(); i++) { + if (n[i] != n[i - 1]) + count++; + else + count = count; + } + if ((count + 1) % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +long long n, a, b, c; +int main() { + cin >> n >> a >> b >> c; + int tf = (4 - n % 4) % 4; + if (tf % 4 == 0) + cout << 0 << endl; + else { + if (tf == 1) + cout << min(a, min(b + c, c * 3)) << endl; + else if (tf == 2) + cout << min(a * 2, min(b, c * 2)) << endl; + else + cout << min(3 * a, min(a + b, c)) << endl; + } + return 0; +} +int main() { + int n, a[200010]; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + sort(a + 1, a + n + 1); + int minn = 1000000010; + for (int i = n / 2 + 1; i <= n; i++) { + if (minn > a[i] - a[i - n / 2]) { minn = a[i] - a[i - n / 2]; } + } + cout << minn << endl; + return 0; +} +int main() { + long int n; + cin >> n; + int c = 0; + while (n > 0) { + if (n >= 100) { + n -= 100; + c++; + } else if (n >= 20) { + n -= 20; + c++; + } else if (n >= 10) { + n -= 10; + c++; + } else if (n >= 5) { + n -= 5; + c++; + } else { + n -= 1; + c++; + } + } + cout << c << "\n"; + return 0; +} +map soroban; +int main() { + soroban.clear(); + soroban[0] = "O-|-OOOO"; + soroban[1] = "O-|O-OOO"; + soroban[2] = "O-|OO-OO"; + soroban[3] = "O-|OOO-O"; + soroban[4] = "O-|OOOO-"; + soroban[5] = "-O|-OOOO"; + soroban[6] = "-O|O-OOO"; + soroban[7] = "-O|OO-OO"; + soroban[8] = "-O|OOO-O"; + soroban[9] = "-O|OOOO-"; + string s; + cin >> s; + int len = s.length(); + for (int i = len - 1; i >= 0; i--) cout << soroban[s[i] - '0'] << endl; + return 0; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int nnl = (k * l) / nl; + int nnp = p / np; + int mi = min(nnl, min(nnp, c * d)); + cout << mi / n << '\n'; + return 0; +} +long long int modex(long long int a, long long int b) { + if (b == 0) { return 1; } + if (b % 2 == 0) { + long long int y = modex(a, b / 2); + return ((y % 1000000007) * (y % 1000000007)) % 1000000007; + } + return ((a % 1000000007) * modex(a, b - 1)) % 1000000007; +} +long long int modi(long long int a) { + return modex(a, 1000000007 - 2) % 1000000007; +} +int main() { + long long int n, k; + cin >> n >> k; + string s; + cin >> s; + if (k > (n / 2)) { + long long int r = k; + while (r < n) { + cout << "RIGHT" << endl; + r++; + } + while (r > 0) { + cout << "PRINT " << s[r - 1] << endl; + r--; + if (r > 0) { cout << "LEFT" << endl; } + } + } else { + long long int r = k; + while (r > 1) { + cout << "LEFT" << endl; + r--; + } + while (r <= n) { + cout << "PRINT " << s[r - 1] << endl; + r++; + if (r <= n) { cout << "RIGHT" << endl; } + } + } + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[15][15]; + for (int i = 1; i <= n; i++) { + a[1][i] = 1; + a[i][1] = 1; + } + for (int i = 2; i <= n; i++) { + for (int j = 2; j <= n; j++) { a[i][j] = a[i][j - 1] + a[i - 1][j]; } + } + cout << a[n][n] << endl; + } + return 0; +} +string S, T; +long long N, M, A[10], sum, x, y, K; +bool cek; +int main() { + cin >> N >> S; + for (int i = 0; i < S.length() / 2; i++) { + if (S[i] == '4' || S[i] == '7') A[S[i] - '0']++; + x += S[i] - '0'; + } + for (int i = S.length() / 2; i < S.length(); i++) { + if (S[i] == '4' || S[i] == '7') A[S[i] - '0']++; + y += S[i] - '0'; + } + if (x == y && A[4] + A[7] == N) + cout << "YES\n"; + else + cout << "NO\n"; +} +int a[10005]; +int main() { + int n, m, z, i, cnt = 0; + cin >> n >> m >> z; + int x = n * m; + for (i = 1; i * n <= z; i++) a[i * n] = 1; + for (int i = 1; i * m <= z; i++) { + if (a[i * m] == 1) cnt++; + } + cout << cnt << endl; +} +int main() { + string a, b, c, d; + cin >> a >> b; + int n, i; + cout << a << ' ' << b << endl; + cin >> n; + for (i = 0; i < n; i++) { + cin >> c >> d; + if (a == c) + a = d; + else + b = d; + cout << a << ' ' << b << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a, b; + int z = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (b - a >= 2) { z++; } + } + cout << z << endl; +} +const int N = 1e5 + 10; +int shu[N], k1[N]; +int main() { + int n, m, i, j; + while (cin >> n >> m) { + int ans = 0; + for (i = 0; i < n; i++) cin >> shu[i]; + sort(shu, shu + n); + int t = 0; + for (i = 0; i < m; i++) { + int x1, x2, y; + cin >> x1 >> x2 >> y; + if (x1 == 1) k1[t++] = x2; + if (x2 == 1000000000) ans++; + } + sort(k1, k1 + t); + ans += n; + i = 0, j = 0; + int cnt = t; + while (i < n) { + while (j < t && k1[j] < shu[i]) { + --cnt; + ++j; + } + ans = min(ans, cnt + i); + if (ans == 0) break; + ++i; + } + cout << ans << endl; + } + return 0; +} +int main() { + long long n; + cin >> n; + n = n / 2; + cout << n * 3 << endl; +} +int main() { + char a[8][8]; + int i; + int j; + int k; + int flag1 = 1; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { cin >> a[i][j]; } + } + for (i = 0; i < 8; i++) { + for (k = 0; k < 7; k++) { + if (a[i][k] == a[i][k + 1]) { flag1 = 0; } + } + } + if (flag1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +const long long INF = (1ll << 62) - 1; +const int M = 1e5 + 5; +int q[M], a[M]; +int main() { + int m; + cin >> m; + int mn = INT_MAX; + for (int i = 0; i < m; i++) { + cin >> q[i]; + mn = min(mn, q[i]); + } + int n; + cin >> n; + int la = mn + 2; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n, greater()); + long long s = 0; + for (int i = 0; i < n; i++) { + if (i % la < mn) { s += a[i]; } + } + cout << s << endl; +} +bool check_palindrome(string str) { + int i = 0, j = str.length() - 1; + while (i < j) { + if (str[i] == str[j]) { + i++; + j--; + continue; + } + char a1, a2, b1, b2; + if (str[i] == 'a') { + a1 = a2 = 'b'; + } else if (str[i] == 'z') { + a1 = a2 = 'y'; + } else { + a1 = (char)str[i] + 1; + a2 = (char)str[i] - 1; + } + if (str[j] == 'a') { + b1 = b2 = 'b'; + } else if (str[j] == 'z') { + b1 = b2 = 'y'; + } else { + b1 = (char)str[j] + 1; + b2 = (char)str[j] - 1; + } + if (a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) { + i++; + j--; + continue; + } + return false; + } + return true; +} +int main() { + int lines; + cin >> lines; + for (int i = 0; i < lines; i++) { + int size; + cin >> size; + string s; + cin >> s; + if (check_palindrome(s)) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + } + return 0; +} +int main() { + int K, R, i; + cin >> K >> R; + for (i = 1;; i++) { + if (K * i % 10 == 0) break; + if (((K * i) - R) % 10 == 0) break; + } + cout << i << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + set s1; + set s2; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (i == j || j == n - i - 1) + s1.insert(a[i][j]); + else + s2.insert(a[i][j]); + } + if (s1.size() == 1 && s2.size() == 1 && s1 != s2) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int m, n; + cin >> m >> n; + cout << m * n / 2 << endl; +} +int main() { + int n, count = 0; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +const int MAXN = 101; +int room[MAXN][MAXN]; +int main() { + memset(room, 0, sizeof(int) * MAXN * MAXN); + int n, x, y, rows = 0, cols = 0, maxrow = 0, maxcol = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> y; + room[x][y]++; + } + for (int i = 0; i < MAXN; i++) { + maxrow = 0; + maxcol = 0; + for (int j = 0; j < MAXN; j++) { + maxcol = max(maxcol, room[j][i]); + maxrow = max(maxrow, room[i][j]); + } + rows += min(maxrow, 1); + cols += min(maxcol, 1); + } + cout << min(rows, cols) << endl; + return 0; +} +int main() { + int n, m, c, d; + while (cin >> n >> m) { + if (n == 0 && m == 0) { + cout << 0 << " " << 0 << endl; + } else { + if (n == 0) { + cout << "Impossible" << endl; + } else { + if (n == 1) { + if (m == 0) { + cout << n << " " << n << endl; + } else { + cout << m << " " << m << endl; + } + } else { + if (n >= m) { + if (m == 0) { + cout << n << " " << n << endl; + } else { + c = m + n - 1; + cout << n << " " << c << endl; + } + } else { + d = m + n - 1; + cout << m << " " << d << endl; + } + } + } + } + } +} +int main() { + long long a, b, c, map[100005], i, j, k, n; + while (cin >> a >> b >> c) { + long long sum = 0; + cin >> n; + for (i = 0; i < n; i++) { cin >> map[i]; } + for (i = 0; i < n; i++) { + if (map[i] > b && map[i] < c) sum++; + } + cout << sum << endl; + } + return 0; +} +const int tinf = (int)1e9 + 7; +const long long inf = (long long)1e18 + 7; +const int N = 5e5 + 5; +const long long M = 1e9 + 7; +int main() { + {} + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long x, y, p, q; + cin >> x >> y >> p >> q; + if (p == 0) { + if (x == 0) { + cout << 0 << endl; + continue; + } + cout << -1 << endl; + continue; + } + if (p == q) { + if (x == y) { + cout << 0 << endl; + continue; + } + cout << -1 << endl; + continue; + } else { + long long k = y / q + (y % q != 0), k1 = x / p + (x % p != 0); + k = max(k, k1); + long long r1 = p * k - x, r2 = q * k - y; + k = max(k, (x - y) / (p - q) + ((x - y) % (p - q) != 0)); + cout << q * k - y << endl; + } + } +} +char arr[200000 + 10]; +int main() { + int n, m = 0, a, b; + cin >> n; + for (int i = 0; i < n; ++i) { + cin >> arr[i]; + if (arr[i] == '0') m += 1; + } + a = n - 2 * m; + if (a >= 0) cout << a << endl; + if (a < 0) { + b = 2 * m - n; + cout << b << endl; + } + return 0; +} +int main() { + int n, k, x; + cin >> n >> k >> x; + int arr[n], ans = 0; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (i + k < n) { + ans += arr[i]; + } else { + ans += x; + } + } + cout << ans << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a.length() != b.length()) { + cout << max(a.length(), b.length()) << endl; + } else { + if (a == b) { + cout << -1 << endl; + } else { + cout << a.length() << endl; + } + } + return 0; +} +int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1}; +int dy[8] = {1, -1, -1, 0, 1, -1, 0, 1}; +vector v[1005]; +bool vis[1005]; +int flag = 0, cnt, dd[1005]; +void dfs(int s) { + vis[s] = true; + cnt++; + if (dd[s]) flag = 1; + for (int i = 0; i < v[s].size(); i++) { + if (!vis[v[s][i]]) dfs(v[s][i]); + } + return; +} +int main() { + int n, m, k, a, b; + long long maxx = 0, ans = 0, cnt1 = 0; + vector vec; + cin >> n >> m >> k; + while (k--) { + cin >> a; + dd[a] = 1; + } + int m1 = m; + while (m1--) { + cin >> a >> b; + v[a].push_back(b); + v[b].push_back(a); + } + for (int i = 1; i <= n; i++) { + if (!vis[i]) { + cnt = 0, flag = 0; + dfs(i); + if (flag == 0) + cnt1 += cnt; + else { + maxx = (cnt < maxx ? maxx : cnt); + vec.push_back(cnt); + } + } + } + for (int i = 0; i < vec.size(); i++) { + if (vec[i] == maxx) { + cnt1 += vec[i]; + ans += (cnt1 * (cnt1 - 1)) / 2; + maxx++; + } else { + ans += (vec[i] * (vec[i] - 1)) / 2; + } + } + cout << (ans - m) << endl; + return 0; +} +int main() { + long long n, k, x, y, z; + cin >> n >> k; + x = n / 2; + if ((k + 1) > x) + cout << 0 << " " << 0 << " " << n << endl; + else { + y = x / (k + 1); + z = y * k; + cout << y << " " << z << " " << (n - (z + y)) << endl; + } + return 0; +} +int a, b, c; +int main() { + while (cin >> a >> b >> c) { cout << (((a - b) * c + b - 1) / b) << endl; } + return 0; +} +string get_str(long long num) { + if (num == 0) return "0"; + string s = ""; + while (num) { + int n = num % 10 + 48; + if (n & 1) + s += "1"; + else + s += "0"; + num = num / 10; + } + reverse(s.begin(), s.end()); + return s; +} +int main() { + int t; + cin >> t; + map mp; + while (t--) { + char ch; + long long num; + string sp; + cin >> ch; + if (ch == '?') + cin >> sp; + else + cin >> num; + string str = get_str(num); + if (ch == '+' || ch == '-') { + string str = get_str(num); + if (ch == '+') + mp[str]++; + else + mp[str]--; + } else if (ch == '?') { + int mcnt = 0; + int cnt = 0; + int lead = 0; + for (int i = 0; i < sp.length(); i++) { + if (sp[i] == '1') + break; + else + cnt++; + } + string s = sp.substr(cnt, sp.length() - cnt); + mcnt += mp[s]; + while (cnt--) { + s = "0" + s; + mcnt += mp[s]; + } + s = "0" + s; + while (s.length() < 19) { + mcnt += mp[s]; + s = "0" + s; + } + cout << mcnt << "\n"; + } + } + return 0; +} +int win(char x, char y) { + if (x == y) return 2; + if (x == 'R' && y == 'S') return 0; + if (x == 'S' && y == 'P') return 0; + if (x == 'P' && y == 'R') return 0; + return 1; +} +int main() { + int n; + string A, B; + cin >> n >> A >> B; + int a = A.size(), b = B.size(); + int s[3] = {}, p[3] = {}; + for (int i = 0; i < a * b; i++) s[win(A[i % a], B[i % b])]++; + for (int i = 0; i < n % (a * b); i++) p[win(A[i % a], B[i % b])]++; + for (int i = 0; i < 2; i++) p[i] += s[i] * (n / (a * b)); + cout << p[1] << ' ' << p[0] << endl; + return 0; +} +char a[110], k; +int b[110], tot, n; +int main() { + cin >> n; + k = getchar(); + cin.getline(a, 110); + b[0] = 1; + for (int i = 0; i < strlen(a); i++) { + b[i] += a[i] - '0'; + if (b[i] != a[i] - '0') tot++; + if (b[i] > 1) { + b[i + 1] += b[i] / 2; + b[i] %= 2; + } + } + cout << tot << "\n"; + return 0; +} +inline void boost() {} +int main() { + boost(); + int n; + cin >> n; + int l = n / 2, r = n / 2; + for (int i = 0; i <= n / 2; i++) { + for (int j = 0; j < n; j++) { + if (j >= l && j <= r) { + cout << "D"; + } else { + cout << "*"; + } + } + cout << endl; + l--; + r++; + } + l = 1, r = n - 2; + for (int i = n / 2 + 1; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j >= l && j <= r) { + cout << "D"; + } else { + cout << "*"; + } + } + cout << endl; + l++; + r--; + } +} +int main() { + int t; + cin >> t; + char ans[t]; + for (int i = 0; i < t; ++i) { + int tt; + cin >> tt; + char a[tt]; + for (int l = 0; l < tt; ++l) { cin >> a[l]; } + int count = 0; + for (int j = 0, k = tt - 1; j < tt / 2; ++j, --k) { + if (a[j] == a[k] || (a[j] + 1) == (a[k] - 1) || (a[j] - 1) == (a[k] + 1)) { count++; } + } + if (tt / 2 == count) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + count = 0; + } +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + vector V; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + V.push_back(x); + } + int min = 1 << 30; + bool bit = false; + for (int i = 1; i < n; i++) { + if (s[i - 1] == 'R' && s[i] == 'L') { + bit = true; + min = min < ((V[i] - V[i - 1]) / 2) ? min : ((V[i] - V[i - 1]) / 2); + } + } + if (bit) + cout << min << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + vector arr1, arr2; + int a, b, k, m; + cin >> a >> b >> k >> m; + if (k > a || m > b) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < a; i++) { + int inp; + cin >> inp; + arr1.push_back(inp); + } + for (int i = 0; i < b; i++) { + int inp; + cin >> inp; + arr2.push_back(inp); + } + if (arr1[k - 1] < arr2[b - m]) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +map id; +int n, m, k, x, y, sum, cnt, ans, f[10], g[10]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> x, f[x]++; + for (int i = 1; i <= n; i++) cin >> x, g[x]++; + for (int i = 1; i <= 5; i++) + if ((f[i] + g[i]) % 2 == 1) { + cout << -1 << endl; + return 0; + } + for (int i = 1; i <= 5; i++) ans += abs(f[i] - (f[i] + g[i]) / 2); + cout << ans / 2 << endl; + return 0; +} +string s; +long long n, p; +const long long MAX = 2000; +const long long ALPH = 31; +bool used[MAX][2][ALPH][ALPH]; +bool termina = false; +string resp = ""; +char getChar(long long x) { + char c = x + 'a'; + return c; +} +bool f(long long pos = 0, long long upper = 0, long long ant1 = 30, long long ant2 = 30) { + if (termina) { return false; } + if (pos == n) { + if (upper == 1) { + termina = true; + return true; + } else { + return false; + } + } + if (used[pos][upper][ant1][ant2]) { return false; } + used[pos][upper][ant1][ant2] = true; + long long d = s[pos] - 'a'; + if (upper == 0) { + for (long long i = d; i < p; i++) { + if (i == ant1 || i == ant2) { continue; } + if (i == d) { + if (f(pos + 1, 0, ant2, i)) { + resp += getChar(i); + return true; + } + } else { + if (f(pos + 1, 1, ant2, i)) { + resp += getChar(i); + return true; + } + } + } + } else { + for (long long i = 0; i < p; i++) { + if (i == ant1 || i == ant2) { continue; } + if (f(pos + 1, 1, ant2, i)) { + resp += getChar(i); + return true; + } + } + } + return false; +} +void doit() { + cin >> n >> p; + cin >> s; + if (f()) { + for (long long i = resp.size() - 1; i >= 0; i--) { cout << resp[i]; } + cout << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + long long T = 1; + while (T--) { doit(); } + return 0; +} +int main() { + string s; + cin >> s; + stack st; + for (int i = 0; i < s.size(); i++) { + if (!st.empty() && s[i] == st.top()) + st.pop(); + else + st.push(s[i]); + } + s = ""; + while (!st.empty()) { + s += st.top(); + st.pop(); + } + for (int i = s.size() - 1; i >= 0; i--) cout << s[i]; + cout << endl; +} +int main() { + int n; + cin >> n; + int a[n][2]; + for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } + int count = 0; + for (int i = 0; i < n; i++) { + int x = a[i][0], y = a[i][1]; + bool r = false, l = false, t = false, b = false; + for (int j = 0; j < n; j++) { + if (x > a[j][0] && y == a[j][1]) l = true; + if (x < a[j][0] && y == a[j][1]) r = true; + if (x == a[j][0] && y > a[j][1]) b = true; + if (x == a[j][0] && y < a[j][1]) t = true; + } + if (r && l && t && b) { count++; } + } + cout << count << endl; + return 0; +} +vector vaa; +string s; +void perm(int n, int now, string a) { + string tem = a; + for (int i = now; i < s.length(); i++) { + tem += s[i]; + vaa.push_back(tem); + perm(n + 1, i + 1, tem); + tem = a; + } +} +bool pal(string k) { + for (int i = 0; i < (k.length() + 1) / 2; i++) { + if (k[i] != k[k.length() - i - 1]) { return 0; } + } + return 1; +} +int main() { + cin >> s; + perm(0, 0, ""); + sort(vaa.begin(), vaa.end(), greater()); + for (int i = 0; i < vaa.size(); i++) { + if (pal(vaa[i])) { + cout << vaa[i] << endl; + return 0; + } + } +} +int main() { + int nInputs; + cin >> nInputs; + long rTotal = 0; + long fTotal = 0; + for (int i = 0; i < nInputs - 1; i++) { + int yolo; + cin >> yolo; + fTotal += yolo; + } + for (int i = 0; i < nInputs; i++) { rTotal += i + 1; } + cout << rTotal - fTotal << endl; +} +int main() { + int arr[5][5]; + int x, y; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + cin >> arr[i][j]; + if (arr[i][j]) { + x = i; + y = j; + } + } + } + cout << abs(x - 2) + abs(y - 2) << "\n"; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +int main() { + int n; + cin >> n; + int sum1 = 0, sum2 = 0; + bool ans = true; + for (int i = 0; i < n; i++) { + char v; + cin >> v; + if (v != '4' and v != '7') ans = false; + if (i < n / 2) + sum1 += (v - '0'); + else + sum2 += (v - '0'); + } + if (sum1 != sum2) ans = false; + cout << (ans ? "YES" : "NO") << endl; + return 0; +} +int x, y, ar[100]; +int main() { + int c = 0; + cin >> x >> y; + for (int i = 0; i < x; i++) { + cin >> ar[i]; + if (ar[i] >= ar[y - 1] && ar[i] > 0) c++; + } + cout << c << endl; + return 0; +} +int main() { + string str; + cin >> str; + int x = str[0] - 'a'; + int y = str[1] - '0' - 1; + if ((x == 0 || x == 7) && (y == 0 || y == 7)) + cout << "3\n"; + else if (x == 0 || x == 7 || y == 0 || y == 7) + cout << "5\n"; + else + cout << "8\n"; + return 0; +} +int main() { + long long n; + cin >> n; + map m; + string a; + m.clear(); + for (int i = 1; i <= n; i++) { + cin >> a; + m[a]++; + } + int s = 0; + for (int i = 1; i <= n; i++) { + cin >> a; + if (m[a] > 0) + m[a]--; + else + s++; + } + cout << s << endl; +} +int main() { + int rep; + long long a, b, k; + long long result; + cin >> rep; + while (rep--) { + result = 0; + cin >> a >> b >> k; + if (k % 2 == 0) { + result = (k / 2) * a - (k / 2) * b; + } else { + result = (k / 2 + 1) * a - (k / 2) * b; + } + cout << result << endl; + } + return 0; +} +const int N = 1e5 + 1, inf = 1e9 + 1; +vector anses; +int sum(int n) { + int ans = 0; + while (n) { + ans += n % 10; + n /= 10; + } + return ans; +} +int main() { + int n; + cin >> n; + int n1 = n; + while (n1 > 0 && n - n1 < 82) { + if (n1 + sum(n1) == n) { anses.push_back(n1); } + --n1; + } + sort(anses.begin(), anses.end()); + cout << anses.size() << "\n"; + for (int i = 0; i < anses.size(); ++i) { cout << anses[i] << "\n"; } +} +int main() { + int n; + while (cin >> n) { + int left = 0, right = 0; + for (int i = 0; i < n; ++i) { + int x, y; + cin >> x >> y; + if (x < 0) + left++; + else if (x > 0) + right++; + } + if (left <= 1 || right <= 1) { + cout << "Yes" << '\n'; + } else + cout << "No" << '\n'; + } + return 0; +} +int main() { + int a, b, i, j, x; + cin >> a >> b; + int sum = 0; + while (b != 0) { + sum = sum * 10; + sum += b % 10; + b /= 10; + } + sum += a; + cout << sum << endl; + return 0; +} +int A[3]; +int main() { + for (int i = 0; i < 3; i++) { cin >> A[i]; } + sort(A, A + 3); + cout << max(0, A[2] - A[1] - A[0] + 1) << '\n'; + return 0; +} +int dx[4] = {0, 0, -1, 1}; +int dy[4] = {1, -1, 0, 0}; +int main() { + string s; + cin >> s; + int i0 = -1, i1 = -1, cnt = 0; + for (int i = s.size() - 1; i >= 0; i -= 1) { + if (s[i] == '0') cnt++; + if (cnt == 6) { + i0 = i; + break; + } + } + for (int i = 0; i < s.size(); i += 1) + if (s[i] == '1') { + i1 = i; + break; + } + if (i1 == -1 || i0 == -1) { + cout << "no\n"; + return 0; + } + if (i1 >= i0) { + cout << "no\n"; + return 0; + } + cout << "yes\n"; +} +int main() { + string s; + cin >> s; + int count = 0; + sort(s.begin(), s.end()); + for (int i = 1; i < s.length(); i++) { + if (s[i] != s[i - 1]) count++; + } + if ((count + 1) % 2 == 0) + cout << "CHAT WITH HER!\n"; + else + cout << "IGNORE HIM!\n"; + return 0; +} +int main() { + string s; + cin >> s; + char t = s[0]; + for (int i = 0; i < s.length(); i++) { t = max(t, s[i]); } + int n = 0; + for (int i = 0; i < s.length(); i++) { + if (s[i] == t) n++; + } + for (int i = 0; i < n; i++) { cout << t; } + cout << endl; +} +int main() { + int n, a, b; + cin >> n >> a >> b; + string s; + cin >> s; + if (s[a - 1] == s[b - 1]) { + cout << (0) << endl; + ; + } else + cout << (1) << endl; + ; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + string T; + cin >> T; + bool cond_1 = false, cond_2 = false, cond_3 = false, cond_4 = false; + cond_1 = T.size() >= 5; + for (int i = 0; i < T.size(); ++i) { + cond_2 |= T[i] >= 'A' && T[i] <= 'Z'; + cond_3 |= T[i] >= 'a' && T[i] <= 'z'; + cond_4 |= T[i] >= '0' && T[i] <= '9'; + } + cout << (cond_1 && cond_2 && cond_3 && cond_4 ? "Correct\n" : "Too weak\n"); +} +int main() { + long long n; + cin >> n; + for (int i = 1; i <= 16; i++) { + long long temp = abs(n + i); + while (temp > 0) { + if (temp % 10 == 8) { + cout << i << endl; + return 0; + } else + temp /= 10; + } + } +} +const int MOD = 1e9 + 7; +double gcd(double a, double b) { + return a < 0.01 ? b : gcd(fmod(b, a), a); +} +long long int max(long long int a, long long int b) { + return (a > b) ? a : b; +} +long long int max(long long int a, long long int b, long long int c) { + return max(a, max(b, c)); +} +long long int min(long long int a, long long int b) { + return (a < b) ? a : b; +} +long long int min(long long int a, long long int b, long long int c) { + return min(a, min(b, c)); +} +long long int power(long long int x, long long int y) { + long long int res = 1; + x = x % MOD; + while (y > 0) { + if (y & 1) res = (res * x) % MOD; + y = y >> 1; + x = (x * x) % MOD; + } + return res; +} +void swap(char *x, char *y) { + char temp; + temp = *y; + *y = *x; + *x = temp; +} +long long int mod(long long int a) { + if (a > 0) + return a; + else + return -a; +} +int main() { + bool f = false; + int n, index = 0, m = INT_MAX; + cin >> n; + int a[n + 1]; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (m > a[i]) { + m = a[i]; + index = i; + } + } + int c = 0; + for (int i = 1; i <= n; i++) { + if (a[i] == m) c++; + if (c >= 2) break; + } + if (c >= 2) { + cout << "Still Rozdil\n"; + } else + cout << index << endl; + return 0; +} +long long check(long long n) { + vector vec; + long long t = n; + while (t) { + vec.push_back(t % 10); + t /= 10; + } + long long w = 0; + while (vec.size()) w *= 10, w += 9 - vec.back(), vec.pop_back(); + return n * w; +} +int main() { + int l, r; + cin >> l >> r; + long long x = 1; + while (x * 10ll <= r) x *= 10; + int s = max((int)x, l), e = r; + long long ans = 0; + while (s <= e) { + int mid = (s + e) >> 1; + long long f1 = check(mid); + long long f2 = -100000000; + if (mid + 1 <= r) f2 = check(mid + 1); + if (f1 <= f2) + s = mid + 1, ans = max(ans, f2); + else + e = mid - 1, ans = max(ans, f1); + } + cout << ans << endl; + return 0; +} +int n, a[200009]; +int solve(int p) { + int minx = 1e9; + for (int i = 0; i < n - p; i++) minx = min(minx, a[i + p] - a[i]); + return minx; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (n % 2 == 1) { + if (n == 3) + cout << solve(1) << endl; + else + cout << solve(2) << endl; + } else { + cout << solve(n / 2) << endl; + } + return 0; +} +const int INF_INT = 2147483647; +const long long INF_LL = 9223372036854775807LL; +const unsigned long long INF_ULL = 18446744073709551615Ull; +const long long P = 92540646808111039LL; +const long long maxn = 1e5 + 10, MOD = 1e9 + 7; +const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1}; +const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1}; +inline int read() { + int x = 0, f = 1; + char ch = getchar(); + while (ch < '0' || ch > '9') { + if (ch == '-') f = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + ch - '0'; + ch = getchar(); + } + return x * f; +} +void init() {} +int main() { + init(); + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int cnt = 0; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > b && x < c) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + n = pow(2, n); + int sum = m % n; + cout << sum << endl; + return 0; +} +int main() { + int n; + int a[100]; + while (cin >> n) { + int i = 2, sum = 0; + int cs = 0; + a[1] = 1; + for (i = 2; sum < n; i++) { + a[i] = i + a[i - 1]; + sum += a[i]; + cs = i - 1; + } + cout << cs << endl; + } +} +const int maxn = 100050; +int s[maxn]; +int main() { + int n; + cin >> n; + int count = 0, ans = 0; + for (int i = 1; i <= n * 2; i++) { + int a; + cin >> a; + s[a]++; + if (s[a] == 2) + count--; + else + count++; + ans = max(ans, count); + } + cout << ans << endl; + return 0; +} +long long sz = 100000001; +long long n, m, x, p, b, k; +int main() { + cin >> n >> k; + p = (n / 2) / (k + 1); + cout << p << " " << p * k << " " << n - (p * (k + 1)) << endl; +} +int main() { + string a, b; + cin >> a >> b; + cout << a << ' ' << b << '\n'; + int n; + cin >> n; + while (n--) { + string a1, b1; + cin >> a1 >> b1; + if (a == a1) + a = b1; + else + b = b1; + cout << a << ' ' << b << '\n'; + } +} +int main() { + srand(time(NULL)); + long long t; + cin >> t; + while (t--) { + long long n, a, b, c; + cin >> n >> a >> b >> c; + long long ans2 = (n / c); + long long ans1 = (ans2 / a) * b; + long long ans = ans1 + ans2; + cout << ans << endl; + } + return 0; +} +int main() { + int a, b, c, d, t; + cin >> a >> b >> c >> d; + int m, v; + m = max(3 * a / 10, a - (a / 250) * c); + v = max(3 * b / 10, b - (b / 250) * d); + if (m > v) { cout << "Misha\n"; } + if (m < v) { cout << "Vasya\n"; } + if (m == v) { cout << "Tie\n"; } +} +string initial; +int n, ans; +int main() { + cin >> n >> initial; + if (initial[0] == '0') + cout << 1 << endl; + else { + for (int i = 0; i < initial.size(); i++) { + ans++; + if (initial[i] == '0') break; + } + cout << ans << endl; + } + return 0; +} +const int M = 100 + 5; +int main() { + string s; + getline(cin, s); + char c = s[0]; + for (int i = 0; i < s.length(); i++) { + if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) { c = s[i]; } + } + char le[12] = {'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}; + bool ok = false; + for (int i = 0; i < 12; i++) { + if (c == le[i]) { + ok = true; + break; + } + } + if (ok) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, m, i, temp1 = 0, temp2 = 0, diff; + cin >> n >> m; + if ((m % (n * (n + 1) / 2)) == 0) + cout << "0" << endl; + else { + int r = m % (n * (n + 1) / 2); + for (i = 1; i <= n; i++) { + diff = ((i * (i + 1)) / 2) - r; + if (diff == 0) { + temp2 = i; + break; + } + if (diff > 0) { + temp1 = i; + break; + } + } + if (temp1 != 0) + cout << abs(((temp1 - 1) * temp1 / 2) - r) << endl; + else if (temp2 != 0) + cout << abs((temp2 * (temp2 + 1) / 2) - r) << endl; + } +} +int main() { + int n, ans = 1000000001, flag1 = 0, flag2 = 0, r, l; + cin >> n; + int cordinates[n]; + char movei[n]; + for (int i = 0; i < n; i++) { cin >> movei[i]; } + for (int i = 0; i < n; i++) { cin >> cordinates[i]; } + for (int i = 0; i < n; i++) { + if (movei[i] == 'R') { + flag1 = 1; + r = i; + } + if (movei[i] == 'L' && flag1) { + l = i; + flag2 = 1; + ans = min(ans, (cordinates[l] - cordinates[r]) / 2); + } + } + if (flag1 && flag2) { + cout << ans << endl; + return 0; + } + cout << -1 << endl; +} +int main() { + long long n; + cin >> n; + long long p = 2 * n; + long long arr[p]; + for (long long i = 0; i < 2 * n; i++) { cin >> arr[i]; } + sort(arr, arr + p); + if (arr[n - 1] == arr[n]) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, m, x, b; + char s[55]; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + for (int j = 0; j < m; j++) s[j] = '#'; + } + if (i % 2 == 0) { + x = i / 2; + for (int j = 0; j < m; j++) { + if (x % 2 != 0) { + if (j != m - 1) s[j] = '.'; + if (j == m - 1) s[j] = '#'; + } + if (x % 2 == 0) { + if (j != 0) s[j] = '.'; + if (j == 0) s[j] = '#'; + } + } + } + for (int j = 0; j < m; j++) { + if (j != m - 1) cout << s[j]; + if (j == m - 1) cout << s[j] << endl; + } + } +} +int main() { + long long t; + cin >> t; + while (t--) { + long long n, a, b, c; + cin >> n >> a >> b >> c; + long long total = n / c; + cerr << "total is " << total << endl; + long long times = total / a; + cerr << "times is " << times << endl; + total = total + times * b; + cout << total << endl; + cout.flush(); + continue; + } +} +const int INF = 0x3f3f3f3f; +const int mod = 998244353; +string s; +int k, vis[26], cnt; +int main() { + cin >> s >> k; + if (s.size() < k) + return puts("impossible"), 0; + else { + for (int i = 0; i < s.size(); i++) { + if (vis[s[i] - 'a'] == 0) { + vis[s[i] - 'a'] = 1; + cnt++; + } + } + if (cnt >= k) + cout << 0 << endl; + else + cout << k - cnt << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + long long A = 1; + long long mod = 1000000009; + for (int i = 0; i < m; ++i) A = (A << 1) % mod; + long long res = 1; + for (int i = 0; i < n; ++i) res = (res * (A - i - 1)) % mod; + cout << res << endl; + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + while (a) { + int maxx = max(l, r); + int minn = min(l, r); + minn++; + a--; + l = maxx; + r = minn; + } + cout << min(l, r) * 2 << endl; +} +int main() { + int i, j, c = 0, d = 0, n; + long long int a[100005], b[100005]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + if (a[i] > 0) { + c++; + } else if (a[i] < 0) { + d++; + } + } + if (c == 1 || d == 1 || c == 0 || d == 0) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char c, colors[2] = {'B', 'W'}; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cin >> c; + if (c == '.') + cout << colors[(i + j) % 2]; + else + cout << c; + } + cout << endl; + } + return 0; +} +int main() { + long long n, i, j, k, l, sum = 0, a, count; + string str; + cin >> n; + int x[n], y[n]; + memset(x, 0, n * sizeof(int)); + memset(y, 0, n * sizeof(int)); + for (i = 0; i < n; i++) { + cin >> str; + count = 0; + for (j = 0; j < n; j++) { + if (str[j] == 'C') { + y[j]++; + count++; + } + } + x[i] += count; + } + for (i = 0; i < n; i++) { sum += x[i] * (x[i] - 1) / 2.0; } + for (i = 0; i < n; i++) { sum += y[i] * (y[i] - 1) / 2.0; } + cout << sum << endl; + return 0; +} +int main() { + int n, Petya, Vasya, Tonya, number(0); + cin >> n; + while (n--) { + cin >> Petya >> Vasya >> Tonya; + if (Petya + Vasya + Tonya >= 2) { number += 1; } + } + cout << number << endl; + return 0; +} +int main() { + int n; + while (cin >> n) { + int a[4][2] = {0}; + cin >> a[0][0] >> a[0][1] >> a[1][0] >> a[1][1] >> a[2][0] >> a[2][1]; + int t = n, ad = a[0][0], b = a[1][0], c = a[2][0]; + if (t = t - ad - b - c) { + if (t <= a[0][1] - a[0][0]) { + ad += t; + t = 0; + } else { + t = t + ad - a[0][1]; + ad = a[0][1]; + if (t <= a[1][1] - a[1][0]) { + b += t; + t = 0; + } else { + t = t + b - a[1][1]; + b = a[1][1]; + if (t <= a[2][1] - a[2][0]) { + c += t; + t = 0; + } else { + c = a[2][1]; + } + } + } + } + cout << ad << " " << b << " " << c << endl; + } + return 0; +} +int main() { + int a, b, c, z = 0; + cin >> a >> b >> c; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > b && x < c) z++; + } + cout << z << endl; + return 0; +} +const int maxn = 1000; +int a[maxn], b[maxn], c[maxn]; +bool cmp(int a, int b) { + return a > b; +} +int main() { + int n, k, j = 1; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + if (a[i] != 0) c[j++] = a[i]; + } + for (int i = 2; i < j; i++) + if (c[i] < c[i - 1]) { + puts("Yes"); + return 0; + } + for (int i = 1; i <= k; i++) cin >> b[i]; + sort(b + 1, b + 1 + k, cmp); + for (int i = 1, j = 1; i <= n; i++) + if (a[i] == 0) a[i] = b[j++]; + for (int i = 2; i <= n; i++) + if (a[i] < a[i - 1]) { + puts("Yes"); + return 0; + } + puts("No"); + return 0; +} +int main() { + int n, k, x, i, sum = 0, temp, a[102]; + cin >> n >> k >> x; + for (i = 0; i < n; i++) { + cin >> temp; + a[i] = temp; + } + sort(a, a + n); + for (i = 0; i < n - k; i++) { sum += a[i]; } + sum += k * x; + cout << sum << endl; +} +int main() { + int m, n, p; + cin >> m >> n >> p; + int a = sqrt(p * m / n); + int b = sqrt(m * n / p); + int c = sqrt(n * p / m); + int sum = 4 * (a + b + c); + cout << sum << endl; + return 0; +} +int n, a[200200], ans = 2e9 + 5; +map mp; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + for (int i = 1; i < n; i++) { + mp[a[i] - a[i - 1]]++; + ans = min(ans, a[i] - a[i - 1]); + } + cout << ans << " " << mp[ans] << endl; + return 0; +} +int main() { + int n; + cin >> n; + int ans = 1, cnt = 1, ph = 99, pm = 99; + for (int i = 0; i < n; ++i) { + int h, m; + cin >> h >> m; + if (h == ph && m == pm) { + ++cnt; + if (ans < cnt) ans = cnt; + } else { + cnt = 1; + } + ph = h; + pm = m; + } + cout << ans << endl; + return 0; +} +int k, w, sum, n; +int main() { + cin >> k >> n >> w; + sum = k * (w * (w + 1) / 2); + cout << max(sum - n, 0) << endl; +} +int mp[20]; +int main() { + int n; + vector Q; + memset(mp, 0, sizeof mp); + for (int i = 1; i <= 6; i++) { + int p; + cin >> p; + mp[p]++; + Q.push_back(p); + } + int flag1 = 0, flag2 = 0; + for (int i = 0; i < Q.size(); i++) { + if (mp[Q[i]] >= 4) { flag1 = 1; } + if (mp[Q[i]] == 2) { flag2 = 1; } + if (mp[Q[i]] == 6) { + flag1 = 1; + flag2 = 1; + } + } + if (flag1 == 1 and flag2 == 0) { + cout << "Bear\n"; + } else if (flag1 == 1 and flag2 == 1) { + cout << "Elephant\n"; + } else { + cout << "Alien\n"; + } + return 0; +} +int main() { + int n; + cin >> n; + int r[n], d[n - 1], s = 0, m = 1000; + cin >> r[0]; + for (int i = 1; i < n; i++) { + cin >> r[i]; + d[i] = r[i] - r[i - 1]; + s = max(s, d[i]); + } + for (int i = 2; i < n; i++) m = max(min(m, d[i] + d[i - 1]), s); + cout << m << endl; + return 0; +} +int main() { + int n, m, check = 0; + cin >> n >> m; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + if (i % 2 == 0) + cout << "#"; + else { + if (check == 0 && j == m - 1) + cout << "#"; + else if (check == 1 && j == 0) + cout << "#"; + else + cout << "."; + } + } + cout << endl; + if (i % 2 == 1 && check == 0) + check = 1; + else if (i % 2 == 1 && check == 1) + check = 0; + } +} +char a[60]; +int main() { + int i, j, n, m; + cin >> n >> m; + cin >> a; + sort(a, a + n); + char temp = a[0]; + int k = 1; + int sum = a[0] - 'a' + 1; + for (i = 1; i < n; i++) { + if (k < m) { + if (a[i] > temp + 1) { + sum += (a[i] - 'a' + 1); + k++; + temp = a[i]; + } + } + if (k == m) break; + } + if (k == m) + cout << sum << endl; + else + cout << "-1" << endl; + return 0; +} +int main() { + int n, inp; + cin >> n; + int *A = new int[n]; + for (int i = 0; i < n; i++) cin >> A[i]; + int Min = A[0], Freq = 1, j = 0; + for (int i = 1; i < n; i++) + if (Min >= A[i]) { + if (Min != A[i]) + Min = A[i], Freq = 1, j = i; + else + Freq += 1; + } + if (!(Freq - 1)) + cout << j + 1 << endl; + else + cout << "Still Rozdil" << endl; +} +int main() { + long long int x, y, i, count = 0, j = 0, flag = 0, n1, n2; + string s1, s2; + cin >> s1; + s2 = "hello"; + n1 = s1.length(); + n2 = s2.length(); + for (i = 0; i < n1; i++) { + if (s1[i] == s2[j]) { + j++; + if (j == n2) { + flag = 1; + break; + } + } + } + if (flag == 1) { + cout << "YES"; + } else { + cout << "NO"; + } + cout << "\n"; +} +int n; +string a, b; +int mk; +int res1, res2; +bool Loses(char a, char b) { + return a == 'R' && b == 'P' || a == 'P' && b == 'S' || a == 'S' && b == 'R'; +} +int main() { + cin >> n >> a >> b; + int mk = a.length() * b.length(); + for (int i = 0; i < mk && i < n; i++) { + int tims = 1 + (n - i - 1) / mk; + res1 += Loses(a[i % a.length()], b[i % b.length()]) * tims; + res2 += Loses(b[i % b.length()], a[i % a.length()]) * tims; + } + cout << res1 << " " << res2 << endl; + return 0; +} +const int64_t MOD = 1e9 + 9; +int main() { + int64_t N, M; + cin >> N >> M; + int64_t pow = 1; + for (int64_t i = 0; i < M; i++) { pow = (pow * 2) % MOD; } + int64_t ac = 1; + for (int64_t i = 1; i <= N; i++) { ac = (ac * (pow + MOD - i)) % MOD; } + cout << ac << endl; +} +int main() { + string s; + int n, x; + cin >> s; + x = s.size(); + n = (x + 1) * 26 - x; + cout << n << endl; + return 0; +} +int main() { + long long n, t, k = 1, l = 0; + int i; + cin >> n >> t; + long long *a = new long long[n]; + long long *b = new long long[n]; + for (i = 1; i < n; i++) { + cin >> a[i]; + b[i] = a[i] + i; + } + for (i = 1; i < n; i = k) { + k = b[i]; + if (t == k) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n; + while (cin >> n) { + int a[4]; + a[1] = 1; + a[2] = 1; + a[3] = 0; + bool flag = true; + int temp; + for (int i = 0; i < n; i++) { + cin >> temp; + if (a[temp] != 1) { flag = false; } + if (temp == 1) { + if (a[2] == 1) { + a[3] = 1; + a[2] = 0; + } else { + a[3] = 0; + a[2] = 1; + } + } + if (temp == 2) { + if (a[1] == 1) { + a[3] = 1; + a[1] = 0; + } else { + a[3] = 0; + a[1] = 1; + } + } + if (temp == 3) { + if (a[1] == 1) { + a[2] = 1; + a[1] = 0; + } else { + a[2] = 0; + a[1] = 1; + } + } + } + if (flag) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int a[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1}; +int main() { + long long n; + int x; + cin >> n >> x; + cout << a[n % 6][x] << endl; + return 0; +} +int i, j; +const int M = 1e5 + 6; +void solve() { + long long p, q, x, y; + cin >> x >> y >> p >> q; + if (p == 0) { + cout << p - (x > 0) << "\n"; + return; + } + if (q == 1) { + cout << p - 1 - !(x == y) << "\n"; + return; + } + long long k = max(ceil((long double)x / (long double)p), ceil((long double)(y - x) / (long double)(q - p))); + cout << q * k - y << "\n"; +} +int main() { + int t; + cin >> t; + while (t--) { solve(); } +} +int main() { + string s, t; + cin >> s >> t; + cout << s[0]; + for (int i = 1; i < s.size(); i++) { + if (s[i] < t[0]) + cout << s[i]; + else + break; + } + cout << t[0] << endl; + return 0; +} +int main() { + puts("Karen"); + return 0; +} +int main() { + int w, h, u1, d1, u2, d2; + cin >> w >> h >> u1 >> d1 >> u2 >> d2; + for (; h > 0; h--) { + w = w + h; + if (h == d1) w = max(0, w - u1); + if (h == d2) w = max(0, w - u2); + } + cout << w << endl; +} +int main() { + int n, i = 0, l = 0; + cin >> n; + while (l <= n) { + i++; + l += (i * (i + 1)) / 2; + } + cout << i - 1 << endl; + return 0; +} +int main() { + long long int i, j, n, m, x; + while (cin >> n) { + long long a[n], b[n], sum1, sum2; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { cin >> b[i]; } + sum1 = a[0]; + sum2 = b[0]; + for (i = 1; i < n; i++) { + sum1 |= a[i]; + sum2 |= b[i]; + } + cout << sum1 + sum2 << endl; + } + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + a = max((3 * a) / 10, a - (a * c) / 250); + b = max((3 * b) / 10, b - (b * d) / 250); + if (a > b) + cout << "Misha" << endl; + else if (a == b) + cout << "Tie" << endl; + else + cout << "Vasya" << endl; + return 0; +} +int main() { + int n, k, sumPos = 0, sumNeg = 0; + cin >> n; + for (int i = 0; i < n; i++) { + { + cin >> k; + } + if (k < 0) { + sumNeg += k; + } else { + sumPos += k; + } + } + cout << sumPos - sumNeg << endl; +} +int main() { + int n; + cin >> n; + string s[n]; + for (int i = 0; i < n; i++) { cin >> s[i]; } + for (int i = 0; i < n; i++) { + string ss = s[i]; + if (ss.size() > 10) { + cout << ss[0] << (ss.size() - 2) << ss[ss.size() - 1] << endl; + } else { + cout << ss << endl; + } + } + return 0; +} +int A[4]; +int main() { + int n, inp; + cin >> n; + while (cin >> inp) ++A[inp]; + cout << n - max(A[1], max(A[2], A[3])) << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + string str; + cin >> str; + for (int i = 0; i < n; i++) { + if (str[i] == 'G' or str[i] == 'T') { + for (int j = i; j < n;) { + if (str[j + k] == '.' and j + k < n) { + j += k; + } else if ((str[j + k] == 'G' or str[j + k] == 'T') and j + k < n) { + return cout << "YES" << endl, 0; + } else + return cout << "NO" << endl, 0; + } + } + } + cout << "NO" << endl; + return 0; +} +int a; +int main() { + cin >> a; + cout << a % 2 << '\n'; +} +int a[1010][1010]; +int main() { + int n; + cin >> n; + map str; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + sort(s.begin(), s.end()); + s.erase(unique(s.begin(), s.end()), s.end()); + str[s]++; + } + cout << str.size() << endl; + return 0; +} +int gcd(int a, int b) { + int temp; + while (b != 0) { + temp = a % b; + a = b; + b = temp; + } + return a; +} +int main() { + int a, i, x, res = 0; + cin >> a; + for (i = 2; i < a; i++) { + x = a; + while (x > 0) { + res += (x % i); + x = (x / i); + } + } + cout << res / gcd(res, a - 2) << "/" << (a - 2) / gcd(res, a - 2) << endl; + return 0; +} +const int N = 1e5 + 7; +int arr[N]; +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + memset(arr, (int)(0), sizeof(arr)); + arr[a] = arr[b] = arr[c] = 1; + for (int i = (int)(1); i <= (int)(n); i++) { + if (i >= a and arr[i - a]) arr[i] = max(arr[i], arr[i - a] + 1); + if (i >= b and arr[i - b]) arr[i] = max(arr[i], arr[i - b] + 1); + if (i >= c and arr[i - c]) arr[i] = max(arr[i], arr[i - c] + 1); + } + cout << arr[n] << endl; +} +int main() { + int n; + cin >> n; + if (n % 5 == 0) { + cout << n / 5 << endl; + } else { + cout << (n / 5) + 1 << endl; + } +} +int sqrt2(int x) { + int pkt = 0; + while (x > 1) { + pkt += 1; + x /= 2; + } + return pkt; +} +int pow(int x, int y) { + int now = 1; + for (int i = 1; i <= y; i++) { now *= x; } + return now; +} +int main() { + int n, m; + cin >> n >> m; + int pkt = sqrt2(m); + if (pkt < n) { + cout << m << endl; + } else { + cout << m % (pow(2, n)) << endl; + } +} +int main() { + string s; + set s1; + set::iterator itr; + while (getline(cin, s)) { + int x = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] >= 'a' && s[i] <= 'z') s1.insert(s[i]); + } + cout << s1.size() << endl; + s1.clear(); + } + return 0; +} +int main() { + int n, m, k; + cin >> n >> m >> k; + int house[110]; + int i; + for (i = 0; i < n; i++) cin >> house[i]; + m--; + for (i = 1; i < n; i++) { + if (m + i < n) { + if (house[m + i] != 0 && k >= house[m + i]) { + cout << i * 10 << endl; + return 0; + } + } + if (m - i >= 0) { + if (house[m - i] != 0 && k >= house[m - i]) { + cout << i * 10 << endl; + return 0; + } + } + } + return 0; +} +int main() { + int n, a[200]; + cin >> n; + int sum1 = 0, k = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + sum1 += a[i]; + k = max(k, a[i]); + } + int flag = 0; + while (!flag) { + int sum2 = 0; + for (int i = 0; i < n; i++) { sum2 += k - a[i]; } + if (sum2 > sum1) { + flag = 1; + } else { + k++; + } + } + cout << k << endl; + return 0; +} +const int N = 1e3 + 5; +bool mark[N][N]; +int main() { + int n, m, k; + cin >> n >> m >> k; + for (int i = 0; i < k; i++) { + int x, y; + cin >> x >> y; + mark[--x][--y] = true; + for (int a = x - 1; a <= x; a++) + for (int b = y - 1; b <= y; b++) + if (~min(a, b) && a + 1 < n && b + 1 < m) { + bool bad = true; + for (int c = 0; c < 4; c++) bad &= mark[a + (c & 1)][b + (c >> 1 & 1)]; + if (bad) return cout << i + 1 << endl, 0; + } + } + cout << "0\n"; + return 0; +} +int main() { + int n, a, b; + string s; + cin >> n >> a >> b; + cin >> s; + if (s[a - 1] == s[b - 1]) { + cout << 0 << endl; + return 0; + } else + cout << 1 << endl; +} +int main() { + string s, k; + int a[3][3], b[3][3]; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { b[i][j] = 1; } + } + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + cin >> a[i][j]; + if (a[i][j] % 2) { + b[i][j] = !b[i][j]; + if (i > 0) b[i - 1][j] = !b[i - 1][j]; + if (j > 0) b[i][j - 1] = !b[i][j - 1]; + if (i < 2) b[i + 1][j] = !b[i + 1][j]; + if (j < 2) b[i][j + 1] = !b[i][j + 1]; + } + } + } + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { cout << b[i][j]; } + cout << endl; + } + return 0; +} +int main() { + int n, m, p; + cin >> n >> m >> p; + int ans = 0; + int c = n; + while (n != 1) { + ans += n / 2; + n -= n / 2; + } + cout << ans * (m * 2 + 1) << " " << c * p << endl; +} +int main() { + int n = 0; + cin >> n; + vector cities(n, 0); + for (int i = 0; i < n; i++) { cin >> cities[i]; } + sort(cities.begin(), cities.end()); + map m; + for (int i = 1; i < n; i++) { m[cities[i] - cities[i - 1]]++; } + cout << m.begin()->first << ' ' << m.begin()->second << endl; + return 0; +} +int z[100100]; +int main() { + long long num = 0; + int n; + long long k; + cin >> n >> k; + long long l, r; + for (int i = 0; i < n; i++) { + cin >> l >> r; + num += (r - l + 1); + } + num %= k; + cout << (k - num) % k << endl; + return 0; +} +int main() { + clock_t t1, t2; + t1 = clock(); + long long int n, k; + cin >> n >> k; + long long int a = (n / 2) / (k + 1); + cout << a << " " << a * k << " " << (n - a - a * k) << "\n"; + t2 = clock(); + float diff = (float)t2 - (float)t1; + float execution_time = diff / CLOCKS_PER_SEC; +} +int main() { + char a[1001]; + int n, m; + while (cin >> a) { + n = 0, m = 0; + for (int i = 0; i < strlen(a); i++) { + if (a[i] == '-') { + n++; + } else if (a[i] == 'o') { + m++; + } + } + if (n == 0 || m == 0 || n % m == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +int main() { + int l, r, x, y; + float k; + int flag = 0; + cin >> l >> r >> x >> y >> k; + for (int i = x; i <= y; i++) { + if (l <= k * i && k * i <= r) { flag = 1; } + } + if (flag) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +double EPS = 1e-9; +long long INFF = 1000000000000000005LL; +int main() { + int n, m; + cin >> n >> m; + int c = 0; + for (int a = 0; a <= sqrt(n); ++a) { + for (int b = 0; b <= sqrt(m); ++b) { + if ((a * a + b == n) && (a + b * b == m)) { c++; } + } + } + cout << c << '\n'; + return 0; +} +long long s, x, d, ans, cnt = 0, zero = 0, i = 0; +int main() { + cin >> s >> x; + d = s - x; + if (s < x || (d % 2 == 1)) { + cout << 0 << "\n"; + return 0; + } + d /= 2; + while (d || x) { + ++i; + if (!(d & 1)) { + if (!(x & 1)) { + ++zero; + } else { + ++zero; + ++cnt; + } + } else { + if (x & 1) { + cout << 0 << "\n"; + return 0; + } + } + d >>= 1; + x >>= 1; + } + ans = (1LL << cnt); + if (zero == i) { ans -= 2; } + cout << ans << "\n"; + return 0; +} +int n, a, ans, mn, mx; +int main() { + cin >> n >> a; + mn = mx = a; + n--; + for (int i = 0; i < n; i++) { + cin >> a; + if (a > mx) { + mx = a; + ans++; + } + if (a < mn) { + mn = a; + ans++; + } + } + cout << ans << endl; +} +int main() { + int n, m, mint, maxt; + cin >> n >> m >> mint >> maxt; + int cmin, cmax; + cin >> cmin; + cmax = cmin; + for (int i = 1; i < m; i++) { + int a; + cin >> a; + cmin = min(cmin, a); + cmax = max(cmax, a); + } + try { + if (cmin < mint || maxt < cmax) throw 1; + if (n - m < int(cmin != mint) + (cmax != maxt)) throw 1; + cout << "Correct\n"; + } catch (int a) { cout << "Incorrect\n"; } + return 0; +} +const long long INF = 1e18, MAX_N = 1e6; +const long double EPS = 1e-7; +int main() { + string a, b; + cin >> a >> b; + reverse(a.begin(), a.end()); + reverse(b.begin(), b.end()); + a += string(MAX_N - (signed)a.size(), '0'); + b += string(MAX_N - (signed)b.size(), '0'); + for (long long i = MAX_N - 1; i >= 0; --i) { + if (a[i] > b[i]) { + cout << '>' << endl; + return 0; + } + if (a[i] < b[i]) { + cout << '<' << endl; + return 0; + } + } + cout << '=' << endl; + return 0; +} +int main() { + int n; + cin >> n; + vector coins(101, 0); + for (int i = 0; i < n; i++) { + int value; + cin >> value; + coins[value]++; + } + int minPockets = -1; + for (int i = 0; i < 101; i++) minPockets = max(minPockets, coins[i]); + cout << minPockets << endl; + return 0; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long s = (n + m - 1) / m; + long long t = n / m; + cout << min((s * m - n) * a, (n - t * m) * b) << endl; + return 0; +} +int main() { + map m; + m['f'] = 1; + m['a'] = 2; + m['c'] = 3; + m['e'] = 7; + m['x'] = 0; + int count = 0, sum; + char a[60][60]; + int p, q; + cin >> p >> q; + for (int i = 0; i < p; i++) { + for (int j = 0; j < q; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < p; i++) { + for (int j = 0; j < q; j++) { + if (a[i][j] == 'f') { + if (m[a[i][j]] + m[a[i - 1][j]] + m[a[i][j - 1]] + m[a[i - 1][j - 1]] == 13) count++; + if (m[a[i][j]] + m[a[i + 1][j]] + m[a[i][j - 1]] + m[a[i + 1][j - 1]] == 13) count++; + if (m[a[i][j]] + m[a[i + 1][j]] + m[a[i][j + 1]] + m[a[i + 1][j + 1]] == 13) count++; + if (m[a[i][j]] + m[a[i - 1][j]] + m[a[i][j + 1]] + m[a[i - 1][j + 1]] == 13) count++; + } + } + } + cout << count << endl; + return 0; +} +int main() { + int n, x[200], y[200], supercentral(0); + cin >> n; + for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } + for (int i = 0; i < n; ++i) { + int bit = 15; + for (int j = 0; j < n && bit != 0; ++j) { + if (x[j] == x[i]) { + if (y[j] < y[i]) { bit &= (15 - 1); } + if (y[j] > y[i]) { bit &= (15 - 2); } + } + if (y[j] == y[i]) { + if (x[j] < x[i]) { bit &= (15 - 4); } + if (x[j] > x[i]) { bit &= (15 - 8); } + } + } + if (bit == 0) { supercentral += 1; } + } + cout << supercentral << endl; + return 0; +} +int main() { + string a, b, c; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + if (a[i] == b[i]) { + a[i] = '0'; + } else { + a[i] = '1'; + } + } + cout << a << endl; + return 0; +} +void desperate_optimization(int precision) { + cout.setf(ios::fixed); + cout.setf(ios::showpoint); + cout.precision(precision); +} +vector vec[250]; +queue q[3]; +queue qq[3]; +int type[250]; +int outt[250]; +int toutt[250]; +int main() { + desperate_optimization(20); + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> type[i]; + for (int i = 1; i <= n; i++) { + type[i]--; + int x; + cin >> x; + outt[i] = x; + while (x--) { + int u; + cin >> u; + vec[u].push_back(i); + } + } + for (int i = 1; i <= n; i++) + if (outt[i] == 0) q[type[i]].push(i); + int start = 0; + for (int i = 0; i < 3; i++) qq[i] = q[i]; + for (int i = 1; i <= n; i++) toutt[i] = outt[i]; + int ans = 1e9; + for (int i = 0; i < 3; i++) { + if (qq[i].empty() == true) continue; + for (int j = 0; j < 3; j++) q[j] = qq[j]; + for (int j = 1; j <= n; j++) outt[j] = toutt[j]; + start = i; + int total = 0; + while (!q[0].empty() || !q[1].empty() || !q[2].empty()) { + while (!q[start].empty()) { + int pos = q[start].front(); + q[start].pop(); + for (int i = 0; i < vec[pos].size(); i++) { + int nx = vec[pos][i]; + outt[nx]--; + if (outt[nx] == 0) q[type[nx]].push(nx); + } + total++; + } + start = (start + 1) % 3; + total++; + } + ans = min(ans, total - 1); + } + cout << ans << '\n'; + return 0; +} +int main() { + int n, m, i, j, k, x, y, z = 0, a; + cin >> n >> m >> x; + z += (m * x); + for (i = 0; i < n; i++) { + cin >> a; + if (i < n - m) z += a; + } + cout << z << endl; +} +int main() { + int n, r = 0, t = 0; + cin >> n; + for (int i = 0; i < n; i++) { + int a, b; + cin >> a >> b; + t = t - a + b; + if (t > r) r = t; + } + cout << r << endl; + return 0; +} +int num[1005]; +int r[1005]; +int find(int x) { + if (r[x] == x) return x; + return r[x] = find(r[x]); +} +void setunion(int x, int y) { + int rx = find(x); + int ry = find(y); + if (rx != ry) r[rx] = ry; +} +int main() { + int n, m, k; + int gov[1005]; + int x, y; + while (cin >> n >> m >> k) { + memset(num, 0, sizeof(num)); + for (int i = 0; i <= n; i++) { r[i] = i; } + for (int i = 1; i <= k; i++) { cin >> gov[i]; } + for (int i = 1; i <= m; i++) { + cin >> x >> y; + setunion(x, y); + } + for (int i = 1; i <= n; i++) { num[find(i)]++; } + int maxs = 0; + int left = n; + int re = 0; + for (int i = 1; i <= k; i++) { + num[gov[i]] = num[find(gov[i])]; + maxs = max(maxs, num[gov[i]]); + left -= num[gov[i]]; + re += (num[gov[i]] - 1) * num[gov[i]] / 2; + } + re += (left + maxs) * (left + maxs - 1) / 2; + re -= maxs * (maxs - 1) / 2 + m; + cout << re << endl; + } + return 0; +} +int main() { + int t; + cin >> t; + while (t--) { + int n, x, y, d, tmp, ans1, ans2; + cin >> n >> x >> y >> d; + if (abs(x - y) % d == 0) { + cout << abs(x - y) / d << "\n"; + } else { + tmp = abs(x - n) / d; + if (abs(x - n) % d != 0) { tmp++; } + if (abs(n - y) % d != 0) { + ans1 = -1; + } else { + ans1 = tmp + abs(n - y) / d; + } + tmp = abs(x - 1) / d; + if (abs(x - 1) % d != 0) { tmp++; } + if (abs(1 - y) % d != 0) { + ans2 = -1; + } else { + ans2 = tmp + abs(1 - y) / d; + } + if (ans1 == -1 && ans2 == -1) { + cout << "-1\n"; + } else if (min(ans1, ans2) == -1) { + cout << max(ans1, ans2) << "\n"; + } else { + cout << min(ans2, ans1) << "\n"; + } + } + } + return 0; +} +const int MAXN = 1000; +int a[MAXN], b[MAXN]; +int f(int a[], int l, int r, int n) { + int res = 0; + for (int i = l; i <= r; ++i) { res |= a[i]; } + return res; +} +void solve() { + int n; + cin >> n; + for (int i = int(0); i < int(n); ++i) cin >> a[i]; + for (int i = int(0); i < int(n); ++i) cin >> b[i]; + int mx = INT_MIN; + for (int l = 0; l < n; ++l) { + for (int r = l; r < n; ++r) { mx = max(mx, f(a, l, r, n) + f(b, l, r, n)); } + } + cout << mx << '\n'; +} +int main() { + solve(); + return 0; +} +void theBrickSort(int arr[], int num) { + bool sorted = false; + while (!sorted) { + sorted = true; + for (int i = 1; i <= num - 2; i = i + 2) { + if (arr[i] > arr[i + 1]) { + swap(arr[i], arr[i + 1]); + sorted = false; + } + } + for (int i = 0; i <= num - 2; i = i + 2) { + if (arr[i] > arr[i + 1]) { + swap(arr[i], arr[i + 1]); + sorted = false; + } + } + } + return; +} +int main() { + int secnumbs, flag = 0, counter = 0; + cin >> secnumbs; + int spykeId[secnumbs]; + for (int i = 0; i < secnumbs; i++) { cin >> spykeId[i]; } + theBrickSort(spykeId, secnumbs); + for (int i = 0; i <= secnumbs; i++) { + flag = i + 2; + if (spykeId[i] == spykeId[i + 1] && spykeId[i] != 0) { counter++; } + if (spykeId[i] == spykeId[flag] && spykeId[i] != 0) { + counter = -1; + break; + } + } + cout << counter << endl; +} +int main() { + long long n, m; + long long ans = 1, sum = 1; + cin >> n >> m; + for (int i = 1; i <= m; ++i) { + sum = sum * 2; + sum %= 1000000009; + } + for (int i = 1; i <= n; ++i) { + ans *= (sum - i); + ans %= 1000000009; + } + cout << ans << endl; + return 0; +} +int main() { + string s; + int flag = 0; + for (int i = 0; i < 8; i++) { + cin >> s; + for (int i = 1; i < 8; i++) { + if (s[i] == s[i + 1]) { flag = 1; } + } + } + if (flag == 1) + cout << "NO" << endl; + else + cout << "YES" << endl; +} +const double pi = acos(-1); +int main() { + int num[1005] = { + 1, + 1, + 3, + }; + for (int i = 3; i < 1005; i++) { num[i] = (3 * num[i - 1]) % 1000003; } + int n; + while (cin >> n) { cout << num[n] << endl; } + return 0; +} +int main() { + int n, arr[100], prohibited = 3; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + if (arr[i] == prohibited) { + cout << "NO" << endl; + return 0; + } + if ((arr[i] == 1 && prohibited == 3) || (arr[i] == 3 && prohibited == 1)) + prohibited = 2; + else if ((arr[i] == 2 && prohibited == 3) || (arr[i] == 3 && prohibited == 2)) + prohibited = 1; + else if ((arr[i] == 1 && prohibited == 2) || (arr[i] == 2 && prohibited == 1)) + prohibited = 3; + } + cout << "YES" << endl; + return 0; +} +int main() { + long long int n, m, a, b, x, y; + cin >> n >> m >> a >> b; + x = n % m; + y = m - x; + x = x * b; + y = y * a; + cout << min(x, y) << "\n"; + return 0; +} +void solve() { + int n; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + int i = 0; + int j = n - 1; + int ans = 0; + while (2 * v[i] < v[j]) { + if (2 * v[i + 1] >= v[j]) { + i++; + ans++; + } else if (2 * v[i] >= v[j - 1]) { + j--; + ans++; + } else { + ans += 2; + i++; + j--; + } + } + cout << ans << endl; +} +void solve2() { + int n; + cin >> n; + long long mx = 0; + long long a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + for (int len = 1; len <= 100; len++) { + for (int i = 0; i + len - 1 < n; i++) { + long long k = a[i]; + for (int j = i + 1; j < i + len; j++) { k ^= a[j]; } + if (k > mx) mx = k; + } + } + cout << mx << endl; +} +int main() { + solve2(); + return 0; +} +int main() { + int n; + cin >> n; + int ans = 0; + ans += n / 100; + n = n % 100; + ans += n / 20; + n = n % 20; + ans += n / 10; + n = n % 10; + ans += n / 5; + n = n % 5; + ans += n / 1; + n = n % 100; + cout << ans << endl; +} +long long int ceil(long long int x, long long int y) { + long long int res = x / y; + if (x % y != 0) res++; + return res; +} +int main() { + int T; + cin >> T; + while (T--) { + long long int x, y, p, q; + cin >> x >> y >> p >> q; + if (p == 0) { + if (x == 0) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + if (p == q) { + if (x == y) + cout << 0 << endl; + else + cout << -1 << endl; + continue; + } + long long int t = max(ceil(x, p), ceil(y - x, q - p)); + cout << q * t - y << endl; + } +} +int main() { + int n, ar[10][10] = {0}, a, b; + cin >> n; + for (int i = 0; i < n; i++) ar[i][0] = 1; + for (int i = 0; i < n; i++) ar[0][i] = 1; + for (int i = 1; i < n; i++) + for (int j = 1; j < n; j++) { + int k, w; + k = j - 1; + w = i - 1; + ar[i][j] = ar[i][k] + ar[w][j]; + } + int o, p; + o = n - 1; + cout << ar[o][o] << endl; + return 0; +} +int main() { + long long n, h, a, b, k; + cin >> n >> h >> a >> b >> k; + long long t1, h1, t2, h2; + for (int i = 0; i < k; i++) { + cin >> t1 >> h1 >> t2 >> h2; + if (t1 == t2) { + long long ans1 = fabs(h2 - h1); + cout << ans1 << "\n"; + } else { + long long ans = fabs(t2 - t1); + if (h1 > b) { + ans += (h1 - b) + fabs(h2 - b); + } else if (h1 < a) { + ans += (a - h1) + fabs(h2 - a); + } else { + ans += fabs(h2 - h1); + } + cout << ans << "\n"; + } + } + return 0; +} +int main() { + int n, x, y, m, mm, f = 0; + cin >> n; + cin >> x; + for (int i = 0; i < n - 1; i++) { + m = x; + cin >> y; + x = y; + } + if (n == 1) { + if (x == 0) + f = 1; + else if (x < 15) + f = 2; + } else { + if (m < y) f = 1; + if (y == 0) + f = 1; + else if (y == 15) + f = 0; + } + if (!f) + cout << "DOWN" << endl; + else if (f == 1) + cout << "UP" << endl; + else + cout << -1 << endl; +} +int main() { + long long n; + cin >> n; + string s; + cin >> s; + vector v1; + vector v2; + for (long long i = 0; i < n; i++) { + string s1; + cin >> s1; + string dep = s1.substr(0, 3); + string arr = s1.substr(5, 3); + v1.push_back(dep); + v2.push_back(arr); + } + long long c1 = 0; + long long c2 = 0; + for (long long i = 0; i < v1.size(); i++) { + if (s == v1[i]) c1++; + } + for (long long i = 0; i < v2.size(); i++) { + if (s == v2[i]) c2++; + } + if (c1 == c2) + cout << "home" + << "\n"; + else + cout << "contest" + << "\n"; + return 0; +} +int n; +int arr[100001]; +int maxi = 0; +int solve(int i) { + if (i == n) return 0; + int ret = solve(i + 1); + if (i == n - 1) return 1; + if (arr[i] <= arr[i + 1]) return ret + 1; + maxi = max(maxi, ret); + return 1; +} +int main() { + cin >> n; + for (int i = 0; i < n; i++) cin >> arr[i]; + int ret = solve(0); + cout << max(ret, maxi) << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + int x = 0; + for (int i = 0; i < n; i++) { + if (a[i] == '0') { + x++; + break; + } + if (a[i] == '1') { x++; } + } + cout << x << endl; +} +int main() { + int n, y[10]; + cin >> n; + for (int i = 0; i < n; i++) cin >> y[i]; + sort(y, y + n); + cout << y[n / 2] << endl; +} +int main() { + int n, i, j, k, z = 1; + cin >> n; + for (i = 0; i < (n / 2) + 1; i++) { + for (j = n / 2; j > i; j--) { cout << "*"; } + for (k = 0; k <= z; k += 2) { cout << "D"; } + for (j = n / 2; j > i; j--) { cout << "*"; } + z += 4; + cout << endl; + } + z -= 8; + for (i = n / 2; i > 0; i--) { + for (j = n / 2; j >= i; j--) { cout << "*"; } + for (k = z; k >= 1; k -= 2) { cout << "D"; } + for (j = n / 2; j >= i; j--) { cout << "*"; } + z -= 4; + cout << endl; + } + return 0; +} +int main() { + int n, ans = 1; + cin >> n; + for (int i = 2; i <= n; i++) { + ans *= 3; + ans %= 1000003; + } + cout << ans << endl; + return 0; +} +int main() { + string s; + long long t = 1; + cin >> s; + t = 25 + 25 + 1; + int len = s.size() - 1; + t += 25 * len; + cout << t << endl; + return 0; +} +const long long inf = 0x3f3f3f3f; +int a[30010]; +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n - 1; i++) { cin >> a[i]; } + int k = 1; + while (k <= m) { + if (k == m) { + cout << "YES" << endl; + return 0; + } + k += a[k]; + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 == 0) + n /= 10; + else + n--; + } + cout << n << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a; + int first_p = 1, second_p = 2, third_p = 3; + bool yeah = true; + while (n--) { + cin >> a; + if (a != first_p && a != second_p) yeah = false; + if (a == first_p) { + a = second_p; + second_p = third_p; + third_p = a; + } else { + a = first_p; + first_p = second_p; + second_p = third_p; + third_p = a; + } + } + cout << ((yeah) ? "YES\n" : "NO\n"); + return 0; +} +int a[7]; +int p(int x) { + return x * x; +} +int main() { + for (int i = 1; i <= 6; i++) { cin >> a[i]; } + int ans = p(a[1] + a[2] + a[3]) - p(a[1]) - p(a[3]) - p(a[5]); + cout << ans << "\n"; + return 0; +} +const long long N = 1e5, MN = 1e9; +long long n, x, y, mx1, mx2, cnt1, cnt2; +long long ar[101][101]; +int main() { + cin >> n; + for (long long i = 0; i < n; i++) { + cin >> x >> y; + ar[x][y] = 1; + if (x > mx1) { mx1 = x; } + if (y > mx2) { mx2 = y; } + } + for (long long i = 0; i <= mx1; i++) { + for (long long j = 0; j <= mx2; j++) { + if (ar[i][j] == 1) { + cnt1++; + break; + } + } + } + for (long long j = 0; j <= mx2; j++) { + for (long long i = 0; i <= mx1; i++) { + if (ar[i][j] == 1) { + cnt2++; + break; + } + } + } + cout << min(cnt1, cnt2); + cout << "\n"; + return 0; +} +int main() { + int mn = 50000, mn2 = mn; + int N, mx = -1, mx2 = mx, Ar = 0; + cin >> N; + for (int i = 1; i <= N; ++i) { + int a, b, x, y; + cin >> a >> b >> x >> y; + Ar += (x - a) * (y - b); + mn = min(mn, min(a, x)); + mn2 = min(mn2, min(b, y)); + mx = max(mx, max(a, x)); + mx2 = max(mx2, max(b, y)); + } + if (mx - mn == mx2 - mn2 && Ar == (mx - mn) * (mx2 - mn2)) + cout << "YES\n"; + else + cout << "NO\n"; + return 0; +} +const int maxn = 100001; +long long n; +int main() { + cin >> n; + while (n % 3 == 0) n /= 3; + cout << n / 3 + 1 << endl; +} +int main() { + long long int problems, travel, time, sum = 0, mean; + cin >> problems >> travel; + time = 240 - travel; + if (time == 0) + cout << "0" << endl; + else { + mean = 0; + sum = 0; + for (int i = 1; i <= problems; i++) { + sum = sum + (i * 5); + if (sum > time) { + mean = i - 1; + cout << mean << endl; + break; + } else if (sum < time) + continue; + else if (sum = time) { + mean = i; + cout << mean << endl; + break; + } + } + if (sum < time) cout << problems << endl; + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int *p = new int[m + 10000]; + for (int i = 1; i <= m; i++) { p[i] = 0; } + int r; + for (int i = 0; i < n; i++) { + int q; + cin >> q; + for (int j = 0; j < q; j++) { + cin >> r; + p[r] = 1; + } + } + int f = 0; + for (int i = 1; i <= m; i++) { + if (p[i] == 1) { + } else { + f = 1; + } + } + if (f == 1) { + cout << "NO" << endl; + } else { + cout << "YES" << endl; + } +} +int main() { + int n, m, x[51], i, j, k, a, b; + while (cin >> n >> m) { + j = 0; + for (i = 0; i < n; i++) { + cin >> a >> b; + x[i] = a * 50 - b; + } + sort(x, x + n); + for (i = 0; i < n; i++) { + if (x[i] == x[n - m]) { j++; } + } + cout << j << endl; + } + return 0; +} +int main() { + int n, ans1 = 0, ans2 = 0, d[105], f, t, tot = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> d[i]; + tot += d[i]; + } + cin >> f >> t; + if (f > t) swap(f, t); + for (int i = f; i < t; i++) ans1 += d[i]; + ans2 = tot - ans1; + cout << min(ans1, ans2) << '\n'; +} +const int INF = int(2e9) + 99; +int n, x, y, d; +int dist(int x, int y) { + return (abs(x - y) + (d - 1)) / d; +} +int main() { + int t; + cin >> t; + for (int i = 0; i < t; ++i) { + cin >> n >> x >> y >> d; + int len = abs(x - y); + int res = INF; + if (len % d == 0) res = min(res, dist(x, y)); + len = y - 1; + if (len % d == 0) res = min(res, dist(x, 1) + dist(1, y)); + len = n - y; + if (len % d == 0) res = min(res, dist(x, n) + dist(n, y)); + if (res == INF) res = -1; + cout << res << endl; + } +} +int main() { + int n; + cin >> n; + long long a = 1, b = 1; + while (n--) { + string s; + cin >> s; + if (s == "UR") a++; + if (s == "DL") a++; + if (s == "UL") b++; + if (s == "DR") b++; + if (s == "ULDR") a++; + if (s == "ULDR") b++; + } + cout << a * b << endl; +} +int n; +const int maxn = 100; +int a[maxn]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + if (n == 1) { + if (a[0] == 0) { + cout << "UP" << endl; + } else if (a[0] == 15) { + cout << "DOWN" << endl; + } else { + cout << "-1" << endl; + } + return 0; + } + if (a[n - 1] > a[n - 2]) { + if (a[n - 1] == 15) { + cout << "DOWN" << endl; + } else + cout << "UP" << endl; + } else { + if (a[n - 1] == 0) { + cout << "UP" << endl; + } else { + cout << "DOWN" << endl; + } + } + return 0; +} +int main() { + int n; + cin >> n; + int a, b; + for (int i = 0; i < n - 1; i++) { cin >> a; } + cin >> b; + if (b == 0) { + cout << "UP" << endl; + return 0; + } else if (b == 15) { + cout << "DOWN" << endl; + return 0; + } else if (n == 1) { + cout << "-1" << endl; + return 0; + } else if (a > b) { + cout << "DOWN" << endl; + } else if (b > a) { + cout << "UP" << endl; + } +} +int main() { + long long int n, a, b, sum1, sum2; + cin >> n; + sum1 = sum2 = 0; + for (int i = 0; i < n; i++) { + cin >> a >> b; + if (a > b) + sum1++; + else if (b > a) + sum2++; + } + if (sum1 > sum2) + cout << "Mishka" << endl; + else if (sum2 > sum1) + cout << "Chris" << endl; + else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + int n, m = 0, c = 0, i, j, k; + cin >> n; + for (i = 0; i < n; i++) { + cin >> j; + cin >> k; + if (j > k) + m++; + else if (k > j) + c++; + } + if (m > c) + cout << "Mishka\n"; + else if (c > m) + cout << "Chris\n"; + else + cout << "Friendship is magic!^^\n"; +} +int main() { + vector chess(8); + for (int i = 0; i < 8; i++) cin >> chess[i]; + for (int i = 0; i < 8; i++) + for (int j = 0; j < 7; j++) + if (chess[i][j] == chess[i][j + 1]) { + cout << "NO" << endl; + return 0; + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, i, a, b, c; + cin >> a >> b >> c; + int ma = max(a, max(b, c)); + int mi = min(a, min(b, c)); + cout << ma - mi << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + int i = 1; + while (1) { + if (m < i) break; + m -= i; + if (i == n) + i = 1; + else + i++; + } + cout << m << endl; + return 0; +} +int main() { + int n, m, k, s = 0; + cin >> n >> m >> k; + int j = n - 1; + int a[55]; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + if (k >= m) + cout << 0 << endl; + else { + while (k < m) { + if (j == -1) break; + k += a[j] - 1; + s++; + j--; + } + if (k < m) + cout << -1 << endl; + else + cout << s << endl; + } +} +int main() { + string s, output; + cin >> s; + for (int i = 0; i < s.length(); i++) { + int temp = s[i] - 48; + char tempChar = '\0'; + if ((i == 0 && temp == 9) || temp < 5) + output.push_back(s[i]); + else { + tempChar = (9 - temp) + 48; + output.push_back(tempChar); + } + } + cout << output << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i, j, k, cnt1, cnt = 0; + for (i = 0; i < n; i++) { + cnt1 = 0; + for (j = 0; j < 3; j++) { + cin >> k; + if (k == 1) cnt1++; + } + if (cnt1 > 1) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + vector v; + int n, a, b; + int res = 0; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + v.push_back(x); + } + for (int i = 0; i < (n / 2); i++) { + if (v[i] != v[n - 1 - i] && v[i] != 2 && v[n - 1 - i] != 2) { + cout << -1 << endl; + return 0; + } + if (v[i] == 2) { + if (v[n - 1 - i] == 0) + res += a; + else if (v[n - 1 - i] == 1) + res += b; + else + res += min(a, b); + } + if (v[n - 1 - i] == 2) { + if (v[i] == 0) + res += a; + else if (v[i] == 1) + res += b; + else + res += min(a, b); + } + } + if (n % 2) + if (v[n / 2] == 2) res += min(a, b); + cout << res << endl; + return (6 == 000000); +} +int main() { + int n; + cin >> n; + int *nums = new int[n]; + int sum = 0; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + sum += temp; + nums[i] = temp; + } + sort(nums, nums + n, greater()); + int i = 0; + int minisum = 0; + while (minisum <= sum / 2) { + minisum += nums[i]; + i++; + } + cout << i << endl; + return 0; +} +int main() { + int n, k, ans = 0; + cin >> n >> k; + for (int i = n; i > 0; i--) + if (i * (i + 1) <= 2 * (240 - k) / 5) { + ans = i; + break; + } + cout << ans << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector passed; + vector failed; + long long int min1 = 99999999; + long long int max1 = -1; + long long int min2 = 99999999; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + passed.push_back(x); + if (x < min1) { min1 = x; } + if (x > max1) { max1 = x; } + } + for (int i = 0; i < m; i++) { + int x; + cin >> x; + failed.push_back(x); + if (x < min2) { min2 = x; } + } + vector answers; + for (int i = max1; i < min2; i++) { + if (min1 * 2 <= i) { + cout << i << endl; + return 0; + } + } + cout << "-1" << endl; + return 0; +} +int main() { + long long a; + cin >> a; + long long arr[a]; + for (long long i = 0; i < a; i++) cin >> arr[i]; + long long ans = 1; + for (long long i = 0; i < a; i++) { + long long count = 0; + long long j = i + 1; + while (j < a && arr[j] > arr[j - 1]) j++; + ans = max(ans, j - i); + i = j - 1; + } + cout << ans << endl; + return 0; +} +int n; +int A[3]; +int main() { + cin >> n; + int a; + for (int i = 0; i < n; i++) { + cin >> a; + A[i % 3] += a; + } + int res = max(max(A[0], A[1]), A[2]); + if (res == A[0]) cout << "chest\n"; + if (res == A[1]) cout << "biceps\n"; + if (res == A[2]) cout << "back\n"; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (i % 2 == 1) cout << "#"; + if (i % 4 == 0) { + if (j == 1) + cout << "#"; + else + cout << "."; + } + if (i % 4 == 2) { + if (j == m) + cout << "#"; + else + cout << "."; + } + } + cout << endl; + } +} +int main() { + char n[20]; + while (cin >> n) { cout << 25 << endl; } + return 0; +} +int n; +string s; +int main() { + cin >> n >> s; + for (int i = 0; i < n; i++) { + string s1; + cin >> s1; + } + if (n % 2 == 0) + cout << "home\n"; + else + cout << "contest\n"; + return 0; +} +int main() { + int n; + cin >> n; + cout << ((n / 2) * 3) << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2 + 1; i++) { + for (int j = n / 2 - i + 1; j > 0; j--) cout << "*"; + for (int j = 1; j <= 2 * i - 1; j++) cout << "D"; + for (int j = n / 2 - i + 1; j > 0; j--) cout << "*"; + cout << "\n"; + } + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= i; j++) cout << "*"; + for (int j = 2 * (n / 2 - i) + 1; j >= 1; j--) cout << "D"; + for (int j = 1; j <= i; j++) cout << "*"; + cout << "\n"; + } +} +long long arr[1000000]; +set s; +int main() { + int n, j = 0; + cin >> n; + for (int i = 0; i < 12; i++) cin >> arr[i]; + sort(arr, arr + 12); + for (int i = 11; i >= 0; i--) { + if (n > 0) { + n -= arr[i]; + j++; + } + } + cout << (n > 0 ? -1 : j) << endl; +} +const long long int MOD = 998244353; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N >> M; + string s; + cin >> s; + for (int i = 0; i < M; i++) { + char a, b; + cin >> L >> R >> a >> b; + L--; + R--; + for (int j = L; j <= R; j++) { + if (s[j] == a) s[j] = b; + } + } + cout << s << endl; + return 0; +} +int main() { + int N; + cin >> N; + int A[N], B[N], fA[6] = {0}, fB[6] = {0}, count = 0; + for (int i = 0; i < N; ++i) { + cin >> A[i]; + ++fA[A[i]]; + } + for (int i = 0; i < N; ++i) { + cin >> B[i]; + ++fB[B[i]]; + } + sort(A, A + N); + sort(B, B + N); + for (int i = 1; i <= 5; ++i) { + if ((fA[i] + fB[i]) & 1) { + count = -1; + break; + } + count += abs(fA[i] - fB[i]) / 2; + } + if (count != -1) count /= 2; + cout << count << endl; + return 0; +} +int main() { + long long int i, j, k, n; + cin >> n; + for (i = 0; i < n; i++) { + cin >> k; + if (360 % (180 - k) == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + n %= 4; + if (n == 0 || n == 3) { + cout << 0 << endl; + } else { + cout << 1 << endl; + } + return 0; +} +int main() { + int n, sum = 0; + cin >> n; + sum += n / 100; + n -= (100 * (n / 100)); + sum += n / 20; + n -= (20 * (n / 20)); + sum += n / 10; + n -= (10 * (n / 10)); + sum += n / 5; + n -= (5 * (n / 5)); + sum += n; + cout << sum << endl; + return 0; +} +int n, a, b; +int chores[2000]; +int main() { + cin >> n >> a >> b; + for (int i = 0; i < n; i++) { cin >> chores[i]; } + sort(chores, chores + n); + cout << chores[b] - chores[b - 1] << '\n'; +} +int main() { + int n, num = 0; + char s[91]; + cin >> n; + for (int i = 0; i < n; i++) cin >> s[i]; + for (int i = 0; i < n; i++) { + if (s[i] == '1') + num++; + else { + cout << num; + num = 0; + } + } + cout << num << endl; + return 0; +} +int cur, n; +string s; +int main() { + cin >> n; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '1') + cur++; + else { + cout << cur; + cur = 0; + } + } + cout << cur << endl; +} +int main() { + int x, y, i, c, a, b; + i = 1; + c = 1; + a = 1; + b = 1; + cin >> x; + cin >> y; + while (i <= x) { + if (i % 2 != 0) { + while (c <= y) { + cout << "#"; + c++; + } + c = 1; + cout << endl; + } else if (i % 2 == 0 && i % 4 != 0) { + while (a < y) { + cout << "."; + a++; + } + cout << "#"; + cout << endl; + a = 1; + } else if (i % 4 == 0) { + cout << "#"; + while (b < y) { + cout << "."; + b++; + } + cout << endl; + b = 1; + } + i++; + } +} +int main() { + int m, n; + cin >> m >> n; + int s = 1; + for (int g = 1; g <= m; g++) + for (int f = 1; f <= n; f++) { + if (g % 2) { + cout << "#"; + if (f == n) { cout << endl; } + } else { + if (g % 4 == 0) { + while (s == 1) { + cout << "#"; + s = 0; + } + if (f != n) cout << "."; + if (f == n) { + cout << endl; + s = 1; + } + } else { + if (f != n) + cout << "."; + else { + cout << "#" << endl; + ; + } + } + } + } +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { cin >> a[i]; } + int ans = 2e6; + for (int i = 0; i < n; i++) { + int cur = 0; + for (int j = 0; j < n; j++) { + int d1 = i - j; + if (d1 < 0) { d1 = -d1; } + cur += 2 * (d1 + i + j) * a[j]; + } + if (cur < ans) { ans = cur; } + } + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n], b[n], ans = 0; + for (int i = 0; i < n; i++) { + cin >> a[i] >> b[i]; + if (b[i] - a[i] >= 2) ans++; + } + cout << ans << endl; +} +int main() { + long long int a[10000], b[10000], i, k[10000], t, p[10000]; + cin >> t; + for (i = 1; i <= t; i++) cin >> a[i] >> b[i] >> k[i]; + for (i = 1; i <= t; i++) { + if (k[i] % 2 == 0) { + p[i] = p[i] + k[i] / 2 * a[i] - k[i] / 2 * b[i]; + } else { + p[i] = p[i] + (k[i] - 1) / 2 * a[i] - (k[i] - 1) / 2 * b[i] + a[i]; + } + } + for (i = 1; i <= t; i++) cout << p[i] << endl; + return 0; +} +long long gcd(long long a, long long b) { + return !b ? a : gcd(b, a % b); +} +long long lcm(long long a, long long b) { + return (a / gcd(a, b)) * b; +} +int dix[] = {1, -1, 0, 0, 1, 1, -1, -1}; +int diy[] = {0, 0, 1, -1, 1, -1, 1, -1}; +int main() { + int m, n; + cin >> m; + int mn = 1e6; + for (int i = 0; i < m; i++) { + int x; + cin >> x; + mn = min(x, mn); + } + cin >> n; + vector v(n); + for (int i = 0; i < n; i++) cin >> v[i]; + sort(v.rbegin(), v.rend()); + long long res = 0; + for (int i = 0; i < n; i++) { + int j = 0; + while (j < mn && i < n) res += v[i], i++, j++; + i++; + } + cout << res << '\n'; + return 0; + ; +} +int arr[1000][1000]; +int a[100000]; +int main() { + int n, m, t = 0, tmp = -1, k = 0; + cin >> n >> m; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + cin >> t; + if (t > tmp) { + tmp = t; + k = j; + } + } + a[k]++; + tmp = -1; + } + int max = a[0], res = 1; + for (int i = 1; i < n; i++) { + if (max < a[i]) { + max = a[i]; + res = i + 1; + } + } + cout << res << endl; + return 0; +} +queue q1; +int main() { + int n, m; + while (cin >> n >> m) { + int a, num = 0; + for (int i = 0; i < n; i++) { + cin >> a; + q1.push(a); + } + for (int i = 0; i < m; i++) { + cin >> a; + while (!q1.empty()) { + if (q1.front() <= a) { + num++; + q1.pop(); + n--; + break; + } else + q1.pop(); + } + } + cout << num << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + vector a(n + 1); + for (int i = 0; i < n; i++) { + int x; + cin >> x; + a[i + 1] = a[i] + x; + } + for (int i = 1; i <= n; i++) { + if (a[n] <= 2 * a[i]) { + cout << i << endl; + return 0; + } + } + return 0; +} +int main() { + int n, a, b, x, y, sum = 0, vis[101]; + cin >> n; + cin >> a; + memset(vis, -1, sizeof(vis)); + for (int i = 0; i < a; i++) { + cin >> x; + if (vis[x] < 0) { + sum += x; + vis[x] = 1; + } + } + cin >> b; + for (int i = 0; i < b; i++) { + cin >> y; + if (vis[y] < 0) { + sum += y; + vis[y] = 1; + } + } + if (sum == n * (n + 1) / 2) { + cout << "I become the guy." + << "\n"; + return 0; + } else + cout << "Oh, my keyboard!" + << "\n"; +} +const long long int MOD = 1000000007; +long long int N, M, K, H, W, L, R; +int main() { + cin >> N; + vector v(N + 1); + for (int i = 1; i <= N; i++) cin >> v[i]; + M = accumulate(v.begin(), v.end(), 0); + for (int i = 1; i <= N; i++) v[i] += v[i - 1]; + cin >> L >> R; + if (L > R) swap(L, R); + cout << min(v[R - 1] - v[L - 1], (int)M - v[R - 1] + v[L - 1]) << endl; + return 0; +} +int s[10], a, b, n; +int main() { + for (int i = 0; i < 6; i++) { + cin >> n; + s[n]++; + } + for (int i = 0; i < 10; i++) { + if (s[i] >= 4) { b = 1; } + if (s[i] == 2 || s[i] == 6) { a = 1; } + } + if (b == 0) { + cout << "Alien" << endl; + } else if (a == 1) { + cout << "Elephant" << endl; + } else { + cout << "Bear" << endl; + } +} +int main() { + long long int n, i, sum, minm, x; + minm = 100000000; + cin >> n; + int a[n + 1]; + for (i = 1; i <= n; i++) cin >> a[i]; + for (x = 1; x <= n; x++) { + sum = 0; + for (i = 1; i <= n; i++) { sum = sum + (abs(i - x) + i - 1 + (x - 1)) * a[i] * 2; } + if (sum < minm) minm = sum; + } + cout << minm << endl; +} +int a[10005]; +int b[10005]; +int num, sum; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } + for (int i = 1; i <= n; i++) { + if (a[i] > b[i]) + num++; + else if (a[i] < b[i]) + sum++; + } + if (num > sum) + cout << "Mishka" << endl; + else if (num < sum) + cout << "Chris" << endl; + else if (num == sum) + cout << "Friendship is magic!^^" << endl; +} +int main() { + long long int t, d, i, k, a, b; + cin >> t; + for (i = 0; i < t; i++) { + long long int x = 0; + cin >> a >> b >> k; + if (k % 2 == 0) { + d = a - b; + x = x + d * (k) / 2; + } else { + d = a - b; + x = x + d * (k - 1) / 2; + x += a; + } + cout << x << "\n"; + } + return 0; +} +long long int n, b, d; +long long int a[100007]; +int main() { + cin >> n >> b >> d; + { + for (long long int $i = 0; $i <= n - 1; $i++) cin >> a[$i]; + } + long long int c = 0; + long long int s = 0; + for (long long int i = 0; i <= n - 1; i++) { + if (a[i] <= b) { + s += a[i]; + if (s > d) { + c++; + s = 0; + } + } + } + cout << c << "\n"; + return 0; +} +int n, m, k, arr[51]; +int main() { + cin >> n >> m >> k; + for (int i = 0; i < n; ++i) { cin >> arr[i]; } + if (m <= k) { + cout << 0 << endl; + return 0; + } + sort(arr, arr + n); + int count = 0; + for (int i = n - 1; i >= 0; --i) { + k--; + m -= arr[i]; + count++; + if (m <= 0 || m <= k) { + m = 0; + break; + } + if (k <= 0) { m++; } + } + cout << (m <= 0 ? count : -1) << endl; + return 0; +} +int main() { + int n; + int A[1000]; + int ans; + unsigned int max; + int sum = 0; + cin >> n; + cin >> max; + for (int i = 0; i < n; i++) { + cin >> A[i]; + sum = sum + A[i]; + } + int f; + if (sum == 0) + ans = 0; + else { + f = abs(0 - sum); + if (f <= max) + ans = 1; + else { + ans = f / max; + if (f % max != 0) ans++; + } + } + cout << ans << endl; + return 0; +} +int main() { + int levels; + cin >> levels; + int x, y; + set myset; + for (int i = 0; i < 2; i++) { + cin >> x; + for (int j = 0; j < x; j++) { + cin >> y; + myset.insert(y); + } + } + if (myset.size() == levels) + cout << "I become the guy." << endl; + else + cout << "Oh, my keyboard!" << endl; +} +int main() { + string s, f; + cin >> s >> f; + string ans; + for (int i = 0; i < s.size(); i++) { + if (s[i] == f[i]) + ans += '0'; + else + ans += '1'; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + vector arr; + for (int i = 0; i < n; ++i) { + int temp; + cin >> temp; + arr.push_back(temp); + } + sort(arr.begin(), arr.end()); + for (int i = n - 1; i >= 0; --i) { + int s = sqrt(arr[i]); + if (s * s != arr[i]) { + cout << arr[i] << endl; + break; + } + } +} +int main() { + int k, l, m, n, d; + int cont = 0; + cin >> k >> l >> m >> n >> d; + cont = d; + if (k == 1 || l == 1 || m == 1 || n == 1) { + cout << d << endl; + } else { + for (int i = 1; i <= d; i++) { + if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--; + } + cout << cont << endl; + } + return 0; +} +const int MAXN = 100005; +long long a[MAXN]; +int main() { + int n; + while (cin >> n) { + long long i, sum = 0, num = 0, ans = 0; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] % 2 != 0) num++; + sum += a[i]; + } + sort(a, a + n); + if (num % 2 != 0) { + for (i = 0; i < n; i++) { + if (a[i] % 2 != 0) { + ans = a[i]; + break; + } + } + sum -= ans; + } + cout << sum << endl; + } +} +const int MAX_N = 1000000 + 50; +const int INF = 0x3f3f3f3f; +const double EPS = 1e-10; +long long mod = 1e9 + 7; +string s; +int len, ans; +int main() { + cin >> s; + ans = 0; + len = s.length(); + for (int i = 0; i < len; i++) { + int lt = 0, rt = 0; + for (int j = i; j < len; j++) { + if (s[j] == '(') + lt++; + else if (s[j] == '?') { + if (lt == rt) + lt++; + else + rt++; + } else { + if (lt == rt) + rt--; + else + lt--; + if (lt < 0) break; + if (rt < 0) break; + } + if ((j - i + 1) % 2 == 0 && rt == lt) { ans++; } + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int n, a, b, c[2555], m; + cin >> n >> a >> b; + for (int i = 0; i < n; i++) cin >> c[i]; + sort(c, c + n); + m = c[b] - c[b - 1]; + cout << m << endl; +} +void File() { + freopen("output.txt", "w", stdout); + freopen("input.txt", "r", stdin); +} +void fast() {} +const double pi = 2 * acos(0.0); +const int nn = 2e5 + 5; +const int oo = 0x3f3f3f3f; +int main() { + fast(); + int n, b, e, ans = 0; + int arr[nn] = {}; + cin >> n; + cin >> b >> e; + for (int i = 0; i < n - 1; i++) { + int x, y; + cin >> x >> y; + for (int j = x; j < y; j++) arr[j]++; + } + for (int i = b; i < e; i++) + if (!arr[i]) ans++; + cout << ans << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + if (n == 0) { + cout << "O-|-OOOO" << endl; + return 0; + } + while (n) { + int x = n % 10; + n /= 10; + if (x < 5) + cout << "O-|"; + else + cout << "-O|"; + if (x >= 5) x -= 5; + int all = 4; + while (x) { + cout << 'O'; + x--; + all--; + } + cout << '-'; + while (all--) cout << 'O'; + cout << endl; + } + return 0; +} +const int N = 100005; +int a[N], f[N]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + int ans = 1; + for (int i = 1; i <= n; i++) { + if (a[i - 1] < a[i]) + f[i] = f[i - 1] + 1; + else + f[i] = 1; + ans = max(ans, f[i]); + } + cout << ans << endl; + return 0; +} +int main() { + int i, m, n, cnt = 0, tmp = 0, sum = 0, a[10001]; + cin >> n; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i += 3) { cnt += a[i]; } + for (i = 1; i < n; i += 3) { tmp += a[i]; } + for (i = 2; i < n; i += 3) { sum += a[i]; } + if (cnt > tmp && cnt > sum) + cout << "chest" << endl; + else if (tmp > cnt && tmp > sum) + cout << "biceps" << endl; + else if (sum > tmp && sum > cnt) + cout << "back" << endl; + return 0; +} +string a, b; +int main() { + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +bool prime[55]; +vector v; +void sv() { + memset(prime, 0, sizeof prime); + for (int i = 2; i <= 55; i += 2) prime[i] = true; + prime[2] = 0; + for (long long i = 3; i * i <= 55; i += 2) { + if (prime[i] == false) { + for (int j = i * i; j <= 55; j += i * 2) prime[j] = true; + } + } + for (long long i = 2; i <= 55; i++) { + if (prime[i] == false) v.push_back(i); + } +} +int main() { + sv(); + int n, m; + cin >> n >> m; + for (int i = 0; i < v.size() - 1; i++) { + if (v[i] == n and v[i + 1] == m) + return (cout << "YES" + << "\n", + 0); + } + cout << "NO" + << "\n"; + return 0; +} +int main() { + long long int m, n; + cin >> n; + m = 2 * n - (n / 2); + cout << m << endl; +} +int main() { + long long int t, j, n, m, ck = 0, i, a = 0, b = 0; + cin >> n >> a; + long long int arr[n]; + for (i = 0; i < n; i++) { cin >> arr[i]; } + sort(arr, arr + n); + for (i = 0; i < n; i++) { + if (a % arr[i] == 0) { ck = (a / arr[i]); } + } + cout << ck << endl; +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n / 2; i++) { + for (int j = 1; j <= n / 2 - i + 1; j++) cout << "*"; + for (int j = n / 2 - i + 2; j <= n / 2 + i; j++) cout << "D"; + for (int j = n / 2 + i + 1; j <= n; j++) cout << "*"; + cout << "\n"; + } + for (int i = 1; i <= n; i++) cout << "D"; + cout << "\n"; + for (int i = n / 2; i >= 1; i--) { + for (int j = 1; j <= n / 2 - i + 1; j++) cout << "*"; + for (int j = n / 2 - i + 2; j <= n / 2 + i; j++) cout << "D"; + for (int j = n / 2 + i + 1; j <= n; j++) cout << "*"; + cout << "\n"; + } + return 0; +} +int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); +} +int main() { + int n; + cin >> n; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a.begin(), a.end()); + int g = a[0]; + for (int i = 1; i < n; i++) g = gcd(g, a[i]); + int res = (a[n - 1] / g) - n; + if (res % 2 != 0) + cout << "Alice" << '\n'; + else + cout << "Bob" << '\n'; +} +int main() { + set v; + int n; + while (cin >> n) { + int arr[100005]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + v.insert(arr[i]); + } + v.erase(0); + cout << v.size() << endl; + v.clear(); + } + return 0; +} +const int MAX = 100001; +long long An[MAX], Bn[MAX]; +int main() { + int n, m, a, b; + cin >> n >> m >> a >> b; + for (int i = 1; i <= n; i++) cin >> An[i]; + for (int i = 1; i <= m; i++) cin >> Bn[i]; + sort(An + 1, An + n + 1); + sort(Bn + 1, Bn + m + 1); + if (An[a] < Bn[m - b + 1]) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, x, sum = 0; + cin >> n >> x; + for (int i = 0, k = 0; i < n; i++) { + cin >> k; + sum += k; + } + sum = abs(sum); + cout << sum / x + (sum % x ? 1 : 0) << endl; +} +int main() { + string st; + int sum = 0, a, p = 0, k = 0, g = 1; + cin >> st; + for (int i = 0; i < st.size(); i++) { + if (st[i] == '4' || st[i] == '7') sum = sum + 1; + } + if (sum == 0) { g = 0; } + while (sum > 0) { + a = sum % 10; + sum = sum / 10; + p = p + 1; + if (a == 4 || a == 7) { k = k + 1; } + } + if (p == k && g == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int l, p, q; + double sum, su; + while (cin >> l >> p >> q) { + sum = (double)l / (2 * (p + q)); + su = (double)l - sum * q * 2; + cout << su << endl; + } +} +const long long N = 100011; +int main() { + cout.precision(10); + cout << fixed; + string s; + cin >> s; + long long n = s.size(); + long long ans = 0; + for (long long i = 0; i < n; i++) { + long long cnt1 = 0; + long long cnt2 = 0; + long long tot = 0; + for (long long j = i; j < n; j++) { + if (s[j] == '(') { + cnt1++; + tot++; + } else if (s[j] == '?') { + tot++; + if (cnt1 > 0) { + cnt1--; + } else { + cnt2++; + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } else { + tot--; + if (tot < 0) { break; } + if (cnt1 > 0) { + cnt1--; + } else { + if (cnt2 > 0) { + cnt2--; + } else { + cnt1++; + } + } + if (cnt1 == 0 && tot % 2 == 0) { ans++; } + } + } + } + cout << ans << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long ans = (c + a - 1) * (b + a - 1) - a * (a - 1); + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, n; + cin >> a >> b >> c >> n; + if (a < c || b < c) { + cout << "-1\n"; + return 0; + } + int ans = n - (a + b - c); + if (ans < 1) { + cout << "-1\n"; + } else { + cout << ans << endl; + } +} +int n, f[5518]; +int main() { + cin >> n; + for (int i = 1; i <= n; i++) cin >> f[i]; + for (int i = 1; i <= n; i++) { + if (f[f[f[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +map mp; +int main() { + int t; + cin >> t; + string a; + while (t--) { + string m; + int x = 0; + char c, d; + cin >> c; + if (c == '+') { + cin >> a; + int f = 0, k; + for (int i = 0; i < a.size(); i++) { + k = (a[i] - 48) % 2; + if (k == 1) { f = 1; } + if (k == 1 || f == 1) m.push_back(k + 48); + } + if (f == 0) m.push_back(0 + 48); + mp[m]++; + } else if (c == '-') { + cin >> a; + int f = 0, k; + for (int i = 0; i < a.size(); i++) { + k = (a[i] - 48) % 2; + if (k == 1) { f = 1; } + if (k == 1 || f == 1) m.push_back(k + 48); + } + if (f == 0) m.push_back(0 + 48); + mp[m]--; + } else { + cin >> a; + int f = 0, k; + for (int i = 0; i < a.size(); i++) { + k = (a[i] - 48) % 2; + if (k == 1) { f = 1; } + if (k == 1 || f == 1) m.push_back(k + 48); + } + if (f == 0) m.push_back(0 + 48); + cout << mp[m] << endl; + } + } +} +int main() { + int n, m, j = 1, c = 0; + ; + cin >> n >> m; + int temp = m; + for (int i = 1; n != 0; i++) { + n--; + if (i == m) { + n++; + j++; + m = j * temp; + } + c++; + } + cout << c << endl; + return 0; +} +int main() { + int n, m, x; + cin >> n >> m; + x = (n - 1) / (m - 1); + cout << n + x << endl; + return 0; +} +int main() { + long long n, x; + cin >> n >> x; + char op; + long long num; + long long distress = 0, exist = x; + while (cin >> op >> num) { + if (op == '-') { + if (exist < num) { + distress++; + } else { + exist -= num; + } + } else { + exist += num; + } + } + cout << exist << " " << distress << endl; +} +int main() { + string s; + int i, j, n; + cin >> s; + n = 26 + (s.size() * 25); + cout << n << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + while (k--) { + if (n % 10 == 0) { + n = n / 10; + } else { + n = n - 1; + } + } + cout << n << endl; +} +int main() { + int k, n, s, p, i, j, x = 1, y = 1, a, b; + cin >> k >> n >> s >> p; + while (s * x < n) { x++; } + a = x * k; + while (p * y < a) { y++; } + cout << y << endl; + return 0; +} +int a[100005], dp1[100005], dp2[100005]; +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + a[0] = 0x3f3f3f3f; + a[n + 1] = 0x3f3f3f3f; + int ans = 0; + for (int i = 1; i <= n; i++) { dp1[i] = dp2[i] = 1; } + for (int i = 1; i <= n; i++) { + if (a[i] > a[i - 1]) { dp1[i] = dp1[i - 1] + 1; } + ans = max(ans, dp1[i]); + } + for (int i = n; i > 0; i--) { + if (a[i] < a[i + 1]) { dp2[i] = dp2[i + 1] + 1; } + ans = max(ans, dp2[i]); + } + for (int i = 2; i <= n; i++) { ans = max(ans, dp2[i] + 1); } + for (int i = 1; i < n; i++) { ans = max(ans, dp1[i] + 1); } + for (int i = 2; i < n; i++) { + if (a[i + 1] - a[i - 1] > 1) { ans = max(ans, dp2[i + 1] + dp1[i - 1] + 1); } + } + cout << ans << endl; + return 0; +} +int main() { + double l, a, b; + cin >> l >> a >> b; + cout << l / (a + b) * a << endl; + return 0; +} +const int mod = 1e9 + 7; +int main() { + int n; + cin >> n; + int dp[2] = {1, 1}; + for (int i = 1; i <= n; ++i) { + if (i & 1) + dp[1] += dp[0], dp[1] %= mod; + else + dp[0] += dp[1], dp[0] %= mod; + } + cout << (dp[0] + dp[1] - 2) % mod << endl; + return 0; +} +int main() { + string a, b; + cin >> a >> b; + cout << a[0]; + for (unsigned int i = 1; i < a.size(); i++) { + if (a[i] < b[0]) + cout << a[i]; + else + break; + } + cout << b[0] << endl; + return 0; +} +const int N = 1e5 + 5; +bool isvowel(char c) { + c = tolower(c); + return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); +} +map mp; +int main() { + int n, ans = 0, k, x, arr[105]; + cin >> n >> k >> x; + for (int i = 1; i <= n; ++i) { cin >> arr[i]; } + for (int i = n; i >= 1; --i) { + if (k) + ans += x, k--; + else + ans += arr[i]; + } + return cout << ans << "\n", 0; + return 0; +} +int a[110]; +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + int ret = 1000000000; + for (int i = 1; i < n - 1; i++) { + int d = 0; + for (int j = 0; j < n - 1; j++) + if (j == i) + d = max(d, a[i + 1] - a[j - 1]); + else + d = max(d, a[j + 1] - a[j]); + ret = min(ret, d); + } + cout << ret << endl; +} +int main() { + int n, d; + cin >> n; + long long a[n][4]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 4; j++) { cin >> a[i][j]; } + } + for (int i = 0; i < n; i++) { + d = (a[i][0] / a[i][1]) + ((a[i][2] - 1) / a[i][1]) - (a[i][3] / a[i][1]); + cout << d << "\n"; + } + return 0; +} +int mk[100][100]; +int main() { + int n, m; + cin >> n >> m; + int x = 0, y = 0; + while (1) { + mk[x][y] = 1; + if (x % 4 == 0) + y++; + else + y--; + if (y == m) { + y = m - 1; + x += 2; + mk[x - 1][y] = 1; + } + if (y == -1) { + y = 0; + x += 2; + mk[x - 1][y] = 1; + } + if (x > n) break; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) + if (!mk[i][j]) + cout << "."; + else + cout << "#"; + cout << '\n'; + } +} +const int INF = 0x3f3f3f3f; +long long a[200000 + 5]; +int main() { + long long i, j, k, l, r, co = 0; + long long n, m, t; + cin >> n >> k; + m = (n + 1) / 2; + n -= m; + k++; + if (n < k) + cout << 0 << ' ' << 0 << ' ' << n + m << endl; + else { + m += n % k; + n -= n % k; + cout << n / k << ' ' << n / k * (k - 1) << ' ' << m << endl; + } + return 0; +} +int n = -1, i; +int a[55]; +int main() { + while (cin >> a[++n]) + ; + sort(a, a + n + 1); + for (i = 1; i < n; i++) cout << a[i] << "+"; + cout << a[n] << endl; + return 0; +} +void solve() { + int n; + cin >> n; + vector a[4]; + vector b[4]; + int ans = n; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + a[s.size() - 1].push_back(s[s.size() - 1]); + } + for (int i = 0; i < n; i++) { + string s; + cin >> s; + b[s.size() - 1].push_back(s[s.size() - 1]); + } + for (int it = 0; it < 4; it++) { + sort(a[it].begin(), a[it].end()); + sort(b[it].begin(), b[it].end()); + int i = 0, j = 0; + while (true) { + if (i == a[it].size() or j == b[it].size()) break; + if (a[it][i] == b[it][j]) { + ans--; + i++; + j++; + } else if (a[it][i] < b[it][j]) + i++; + else + j++; + } + } + cout << ans << endl; +} +int main() { + solve(); + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int ans = 0; + for (int a = 0; a <= 1000; a++) { + for (int b = 0; b <= 1000; b++) { + if (a * a + b == n && b * b + a == m) ans++; + } + } + cout << ans << endl; + } + return 0; +} +int main() { + int i, f = 1, n, a; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a; + if (a == 1) f = 0; + } + if (f == 0) + cout << "-1" << endl; + else + cout << "1" << endl; +} +int main() { + int n = 0; + cin >> n; + for (int i = 0, j = 1; i < n; i++, j += 2) { + vector Vector(n, 'D'); + int value = n - j; + for (int k = 0, m = n - 1; k < value / 2; k++, m--) { + Vector[k] = '*'; + Vector[m] = '*'; + } + for (int k = 0; k < n; k++) cout << Vector[k]; + cout << endl; + if (i >= (n - 1) / 2) j -= 4; + } +} +int main() { + int n; + int a, b; + int cnt1 = 0, cnt2 = 0; + cin >> n; + while (n--) { + cin >> a >> b; + if (a > 0) cnt1++; + if (a < 0) cnt2++; + } + if (cnt1 <= 1 || cnt2 <= 1) { + cout << "Yes" << endl; + } else { + cout << "No" << endl; + } + return 0; +} +int main() { + char a[101]; + int n, k, i, flag1, flag2, m = 0; + cin >> n >> k; + for (i = 0; i < n; i++) cin >> a[i]; + for (i = 0; i < n; i++) { + if (a[i] == 'G') { flag1 = i; } + if (a[i] == 'T') { flag2 = i; } + } + if (flag1 < flag2) { + for (i = flag1; i < n; i = i + k) { + if (a[i] == '#') { + cout << "NO" << endl; + break; + } + if (a[i] == 'T') { + cout << "YES" << endl; + break; + } + } + if (i >= n) { cout << "NO" << endl; } + } else { + for (i = flag1; i >= flag2; i = i - k) { + if (a[i] == '#') { + cout << "NO" << endl; + break; + } + if (a[i] == 'T') { + cout << "YES" << endl; + break; + } + } + if (i < flag2) { cout << "NO" << endl; } + } + return 0; +} +int main() { + int k, n; + cin >> n >> k; + cout << max(0, n - (k / 2 - n) * 2 - k % 2) << endl; + return 0; +} +int p[3]; +bool dp[4000 + 10][4000 + 10]; +int main() { + int n; + cin >> n; + for (int i = 0; i < 3; i++) cin >> p[i]; + int minp = min(min(p[0], p[1]), p[2]), maxp = max(max(p[0], p[1]), p[2]); + dp[0][0] = true; + for (int i = minp; i <= n; i++) + for (int k = 1; k <= i / minp; k++) + for (int j = 0; j < 3; j++) + if (i >= p[j]) dp[i][k] |= dp[i - p[j]][k - 1]; + for (int i = n / minp; i >= 1; i--) + if (dp[n][i]) { + cout << i << endl; + break; + } +} +const long long N = 1e4 + 5, M = 2e4 + 5, OO = 0x3f3f3f3f; +const double eps = 1e-6; +int n; +string s1, s2; +int main() { + cin >> n; + vector captain, rat, child, man; + for (int i = 0; i < n; ++i) { + cin >> s1 >> s2; + if (s2 == "rat") + rat.push_back(s1); + else if (s2 == "woman" || s2 == "child") + child.push_back(s1); + else if (s2 == "man") + man.push_back(s1); + else + captain.push_back(s1); + } + for (int i = 0; i < rat.size(); ++i) cout << rat[i] << endl; + for (int j = 0; j < child.size(); ++j) cout << child[j] << endl; + for (int m = 0; m < man.size(); m++) cout << man[m] << endl; + for (int k = 0; k < captain.size(); ++k) cout << captain[k] << endl; + return 0; +} +const int M = 1e2 + 5; +int a[M], b[M], c[10000 + 5]; +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} +int main() { + memset(c, 0, sizeof(c)); + int n, m; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + cin >> m; + for (int i = 0; i < m; i++) cin >> b[i]; + int ans = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) { + if (gcd(a[i], b[j]) == a[i]) c[b[j] / a[i]]++; + } + for (int i = 10004; i >= 0; i--) { + if (c[i] > 0) { + cout << c[i] << endl; + break; + } + if (i == 0) cout << "0" << endl; + } + return 0; +} +int n; +vector vv[210]; +int computer[210], in[210], bk[210], temp[210]; +int bfs(int st) { + queue q; + int ans = n; + for (int i = 1; i <= n; i++) { + if (in[i] == 0) q.push(i); + } + while (!q.empty()) { + memset(bk, 0, sizeof(bk)); + while (!q.empty()) { + int head = q.front(); + q.pop(); + if (bk[head] == 5) { + q.push(head); + break; + } + bk[head]++; + if (computer[head] != st) { + q.push(head); + continue; + } + int up = vv[head].size(); + for (int i = 0; i < up; i++) { + int v = vv[head][i]; + in[v]--; + if (in[v] == 0) q.push(v); + } + } + st = (st == 3 ? 1 : st + 1); + if (!q.empty()) ans++; + } + return ans; +} +int main() { + while (cin >> n) { + memset(in, 0, sizeof(in)); + for (int i = 1; i <= n; i++) vv[i].clear(); + for (int i = 1; i <= n; i++) cin >> computer[i]; + for (int i = 1; i <= n; i++) { + int ki; + cin >> ki; + for (int j = 1; j <= ki; j++) { + int aj; + cin >> aj; + vv[aj].push_back(i); + in[i]++; + } + } + int ans = 0x3f3f3f3f; + for (int i = 1; i <= n; i++) temp[i] = in[i]; + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= n; j++) in[j] = temp[j]; + ans = min(ans, bfs(i)); + } + cout << ans << endl; + } + return 0; +} +int N; +vector pos; +int test_odd() { + int res = 0; + for (int i = 1; i <= N; i += 2) { + int x = pos[(i - 1) / 2]; + res += abs(x - i); + } + return res; +} +int test_even() { + int res = 0; + for (int i = 2; i <= N; i += 2) { + int x = pos[i / 2 - 1]; + res += abs(x - i); + } + return res; +} +int main() { + cin >> N; + pos = vector(N / 2); + for (int i = 0, _n = (N); i < _n; ++i) cin >> pos[i]; + sort(pos.begin(), pos.end()); + int res_odd = test_odd(); + int res_even = test_even(); + int res = min(res_odd, res_even); + cout << res << endl; + return 0; +} +long long cum[100 + 2]; +int main() { + for (int i = 1; i <= 100; i++) cum[i] = i; + for (int i = 2; i <= 100; i++) { cum[i] += cum[i - 1]; } + int n; + cin >> n; + long long sum = 0; + int Count = 0; + int i; + for (i = 1; sum <= n; i++) { + sum += cum[i]; + if (sum > n) + break; + else + Count++; + } + cout << Count << endl; +} +int main() { + long long n, c; + cin >> n >> c; + long long k = 0; + for (int i = 0; i < n; i++) { + long long m, p; + cin >> m; + if (k == 0) { + p = m; + k++; + } else { + if (m - p <= c) { + k++; + p = m; + } else { + k = 0; + p = m; + k++; + } + } + } + cout << k << endl; +} +long long a[100500]; +vector v; +int main() { + long long a, b, c; + cin >> a >> b >> c; + long long t = (c * a + b - 1) / b; + cout << t - c << "\n"; +} +int main() { + int n; + cin >> n; + int ans = (int)10e9; + int arr[n]; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + arr[i] = a; + } + int x = 1; + while (x <= n) { + int cost = 0; + for (int i = 0; i < n; i++) { + int l = i + 1; + cost += (abs(x - l) + abs(l - 1) + abs(x - 1)) * 2 * arr[i]; + } + ans = min(ans, cost); + x++; + } + cout << ans << endl; +} +map, int> loser; +int gcd(int a, int b) { + if (b > a) return gcd(b, a); + if (!b) return a; + return gcd(b, a % b); +} +int lcm(int a, int b) { + return a * b / gcd(a, b); +} +int main() { + loser[pair('R', 'P')] = 1; + loser[pair('P', 'R')] = 2; + loser[pair('P', 'S')] = 1; + loser[pair('S', 'P')] = 2; + loser[pair('S', 'R')] = 1; + loser[pair('R', 'S')] = 2; + loser[pair('S', 'S')] = 0; + loser[pair('P', 'P')] = 0; + loser[pair('R', 'R')] = 0; + int n; + cin >> n; + string s, t; + cin >> s >> t; + int r1 = 0, r2 = 0; + int i; + for (i = 0; i < n && i < lcm(s.size(), t.size()); i++) { + int j = loser[pair(s[i % s.size()], t[i % t.size()])]; + if (j == 1) + r1++; + else if (j == 2) + r2++; + } + if (i == n) + cout << r1 << " " << r2 << endl; + else { + r1 *= n / lcm(s.size(), t.size()), r2 *= n / lcm(s.size(), t.size()); + for (i = 0; i < n % lcm(s.size(), t.size()); i++) { + int j = loser[pair(s[i % s.size()], t[i % t.size()])]; + if (j == 1) + r1++; + else if (j == 2) + r2++; + } + cout << r1 << " " << r2 << endl; + } + return 0; +} +int main() { + long long a, b, c, l; + cin >> a >> b >> c >> l; + long long ans = 0; + for (long long i = 0; i <= l; ++i) ans += (i + 2) * (i + 1) / 2; + for (long long i = 0; i <= l; ++i) { + if (a + i >= b + c) { + long long tmp = min(l - i, a + i - b - c); + ans -= (tmp + 2) * (tmp + 1) / 2; + } + if (b + i >= a + c) { + long long tmp = min(l - i, b + i - a - c); + ans -= (tmp + 2) * (tmp + 1) / 2; + } + if (c + i >= b + a) { + long long tmp = min(l - i, c + i - b - a); + ans -= (tmp + 2) * (tmp + 1) / 2; + } + } + cout << ans << endl; + return 0; +} +int main() { + long long int x1, x2, x3, sum = 0; + cin >> x1 >> x2 >> x3; + if (x1 <= x2 && x1 <= x3 && x2 <= x3) + sum = (x3 - x2) + (x2 - x1); + else if (x1 <= x2 && x1 <= x3 && x3 <= x2) + sum = (x2 - x3) + (x3 - x1); + else if (x2 <= x1 && x2 <= x3 && x1 <= x3) + sum = (x3 - x1) + (x1 - x2); + else if (x2 <= x1 && x2 <= x3 && x3 <= x1) + sum = (x1 - x3) + (x3 - x2); + else if (x3 <= x2 && x3 <= x1 && x1 <= x2) + sum = (x1 - x3) + (x2 - x1); + else if (x3 <= x2 && x3 <= x1 && x2 <= x1) + sum = (x1 - x2) + (x2 - x3); + cout << sum << endl; +} +long long b, c; +const int maxn = 1e2 + 10; +int a[maxn], n; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < 0) + c += a[i]; + else + b += a[i]; + } + cout << b - c << endl; +} +int main() { + int n, t; + cin >> n >> t; + int temp; + for (size_t i = 0; i < n; i++) { + cin >> temp; + t -= (86400 - temp); + if (t <= 0) { + cout << i + 1 << '\n'; + return 0; + } + } + return 0; +} +int main() { + long long int n; + cin >> n; + long long int a[n][n]; + bool flag = true; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) cin >> a[i][j]; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i][j] == 1) + continue; + else { + flag = false; + for (int k = 0; k < n; k++) { + if (k == i) continue; + long long int x, y; + x = a[k][j]; + for (int l = 0; l < n; l++) { + if (l == j) continue; + y = a[i][l]; + if (x + y == a[i][j]) { + flag = true; + break; + } + } + if (flag) break; + } + } + if (flag == false) break; + } + if (flag == false) break; + } + if (flag) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +const double EPS = 1e-9; +long long qx[] = {0, -1, -1}; +long long qy[] = {1, 1, 0}; +long long movx[] = {1, 0, -1, 0}; +long long movy[] = {0, -1, 0, 1}; +long long dist(long long y, long long x) { + return (y * y + x * x); +} +int main() { + long long n; + cin >> n; + if (n == 0) { + cout << 1 << endl; + return 0; + } + long long tot = 0; + long long lasti = 0; + for (long long i = 0; i < n; ++i) { + long long valini = 2 * i * i; + if (valini - n * n > 0) break; + lasti = i; + } + long long posx, posy = lasti; + posx = lasti; + long long contador = 0; + for (long long i = 0; i < 4; ++i) { + if (dist(lasti + movx[i], lasti + movy[i]) - n * n > 0) contador = 1; + } + long long xx, yy; + long long resta = contador; + while (posx != 0 || posy != n) { + bool works = false; + for (long long j = 0; j < 3; j++) { + xx = posx + qx[j]; + yy = posy + qy[j]; + if (n * n - dist(yy, xx) >= 0) { + contador++; + posy = yy; + posx = xx; + works = true; + break; + } + } + } + contador *= 2; + contador -= resta; + contador *= 4; + contador -= 4; + cout << contador << endl; +} +int main() { + map poly; + poly["Tetrahedron"] = 4; + poly["Cube"] = 6; + poly["Octahedron"] = 8; + poly["Dodecahedron"] = 12; + poly["Icosahedron"] = 20; + int n; + int c = 0; + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) { + string s; + cin >> s; + c = c + poly[s]; + } + cout << c << endl; +} +const int INF = 0x3f3f3f3f; +const double PI = acos(-1.0); +pair qta, qtb; +int main() { + string a, b; + cin >> a >> b; + int dif = 0; + for (int i = 0; i < a.size(); i++) { + if (a[i] == '4') qta.first++; + if (a[i] == '7') qta.second++; + if (b[i] == '4') qtb.first++; + if (b[i] == '7') qtb.second++; + if (a[i] != b[i]) dif++; + } + int ans = 0; + if (dif > 0) { + if (qta.first != qtb.first) { + int v; + if (qta.first > qtb.first) { + v = qta.first - qtb.first; + qtb.first += v; + qtb.second -= v; + } + if (qta.first < qtb.first) { + v = qtb.first - qta.first; + qta.first += v; + qta.second -= v; + } + ans += v; + } + if (qta.second != qtb.second) { + int v; + if (qta.second > qtb.second) { + v = qta.second - qtb.second; + qtb.second += v; + qtb.first -= v; + } + if (qta.second < qtb.second) { + v = qtb.second - qta.second; + qta.second += v; + qta.first -= v; + } + ans += v; + } + dif -= ans; + if (dif > 0) { ans += dif / 2; } + } + cout << ans << endl; + return 0; +} +int n; +int main() { + cin >> n; + cout << (n % 2 == 0 ? "Mahmoud\n" : "Ehab\n"); +} +int main() { + int n, m; + int a[52], b[52]; + cin >> n; + for (int i = 0; i < n; i++) { cin >> a[i]; } + cin >> m; + for (int i = 0; i < m; i++) { cin >> b[i]; } + map ppp; + int maxn = -1; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (b[i] % a[j]) { continue; } + int x = b[i] / a[j]; + if (x >= maxn) { + maxn = x; + ppp[maxn]++; + } + } + } + cout << ppp[maxn] << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + int vol = k * l; + int toastFromBottle = vol / nl; + int limes = c * d; + int toastDueToSalt = p / np; + int ans = min(toastFromBottle, toastDueToSalt); + ans = min(ans, limes); + ans = ans / n; + cout << ans << endl; +} +int main() { + long long a, b, c, n, k; + cin >> a >> b >> c >> n; + k = a + b - c; + k = n - k; + if (((k >= 1)) && (c <= a) && (c <= b)) + cout << k << endl; + else + cout << -1 << endl; + return 0; +} +int main() { + int sum = 1; + int levels = 1; + int counter = 0; + int n; + cin >> n; + for (int i = 2; sum <= n; i++) { + counter++; + levels = levels + i; + sum = sum + levels; + } + cout << counter << endl; +} +int main() { + int n; + cin >> n; + vector v; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + int count = 0; + for (int i = 0; i < v.size(); i++) { + for (int j = i; j < n; j++) { + if (v[j] == v[i]) { + i = j; + } else { + break; + } + } + if (v[i] != 0) { count++; } + } + cout << count << endl; + return 0; +} +int main() { + int m, sum = 0; + cin >> m; + vector vec(m); + map cnt; + for (int i = 0; i < m; i++) { + cin >> vec[i]; + sum += vec[i]; + cnt[i + 1] = vec[i]; + } + int x, y; + cin >> x >> y; + for (int i = 1; i <= m; i++) { + int k = i, total = 0; + for (int j = 1; j < k; j++) { total += cnt[j]; } + int be = total, in = sum - total; + if ((be >= x && be <= y) && (in >= x && in <= y)) { + cout << k << '\n'; + return 0; + } + } + cout << 0 << '\n'; + return 0; +} +int n, k, i, val; +char c; +int valori[1000], sel[1000], nrsel, valfin, ultsel; +int main() { + cin >> n >> k; + for (i = 1; i <= n; i += 1) { + cin >> c; + val = (int)c - 'a' + 1; + valori[i] = val; + } + sort(valori + 1, valori + n + 1); + for (i = 1; i <= n; i += 1) { + if (nrsel == k) break; + if (i == 1) { + valfin += valori[i]; + nrsel++; + ultsel = valori[i]; + } else { + if (valori[i] - ultsel <= 1) + continue; + else { + valfin += valori[i]; + ultsel = valori[i]; + nrsel++; + } + } + } + if (nrsel < k) + cout << "-1\n"; + else + cout << valfin << '\n'; + return 0; +} +int main() { + long long n, dead; + cin >> n; + dead = n / 2; + cout << 2 * n - dead << endl; + return 0; +} +int main() { + int t, a, b, c, i = 0, d = 1, k = 1; + cin >> a >> c; + i = min(a, c); + for (t = 1; t <= i; t++) { d *= t; } + cout << d << endl; + return 0; +} +string str[8]; +int main() { + for (int i = 0; i < 8; i++) cin >> str[i]; + int a = 0x3f3f3f3f, b = 0x3f3f3f3f; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (str[i][j] == 'W') { + bool flag = true; + for (int k = i - 1; k >= 0; k--) { + if (str[k][j] != '.') { + flag = false; + break; + } + } + if (flag) a = min(a, i); + } + if (str[i][j] == 'B') { + bool flag = true; + for (int k = i + 1; k < 8; k++) { + if (str[k][j] != '.') { + flag = false; + break; + } + } + if (flag) b = min(b, 8 - i - 1); + } + } + } + if (a <= b) + cout << 'A' << endl; + else + cout << 'B' << endl; +} +int main() { + string encoded; + cin >> encoded; + map code; + for (int i = 0; i < 10; i++) { + string s; + cin >> s; + code[s] = i; + } + for (int i = 0; i < 8; i++) { + string s = encoded.substr(i * 10, 10); + cout << code[s]; + } + cout << endl; + return 0; +} +int main() { + int n, a, p; + cin >> n; + int dp = 101; + int cost = 0; + for (int i = 0; i < n; i++) { + cin >> a; + cin >> p; + if (dp > p) dp = p; + cost += a * dp; + } + cout << cost << endl; + return 0; +} +const int MAXN = 3 * 1e5 + 5; +int N, M, S, x, y, j, z, r; +vector V[MAXN]; +int v[MAXN]; +bool R[MAXN]; +int main() { + cin >> N >> M; + while (M--) { + cin >> x >> y; + if (x == 1) { + V[y].push_back(j); + j++; + S++; + } + if (x == 2) { + z = (int)V[y].size(); + for (int i = v[y]; i < z; i++) { + if (!R[V[y][i]]) S--; + R[V[y][i]] = true; + } + v[y] = z; + } + if (x == 3) { + for (int i = r; i < y; i++) { + if (!R[i]) S--; + R[i] = true; + } + r = max(r, y); + } + cout << S << endl; + } +} +int main() { + int i; + int f = 0; + bool ju = true; + char a[11]; + gets(a); + for (i = 0; a[i] != '\0'; i++) { + if (!(f == 1 || f == 2) && a[i] != '1') { + ju = false; + break; + } + if (a[i] == '1') { + f = 1; + } else if ((f == 1 || f == 2) && a[i] == '4') { + f++; + } else if (a[i] != '1' && a[i] != '4') { + ju = false; + break; + } + } + if (ju) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int n, t; +int cell[30005]; +int DFS(int i) { + if (cell[i] == -1) + return 0; + else if (i + cell[i] == t) { + return 1; + } else { + return DFS(i + cell[i]); + } +} +int main() { + while (cin >> n >> t) { + memset(cell, -1, sizeof(cell)); + for (int i = 1; i < n; i++) { cin >> cell[i]; } + int ans = DFS(1); + if (ans) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } +} +map createMap() { + map shapes; + shapes["Tetrahedron"] = 4; + shapes["Cube"] = 6; + shapes["Octahedron"] = 8; + shapes["Dodecahedron"] = 12; + shapes["Icosahedron"] = 20; + return shapes; +} +int main() { + map shapes = createMap(); + int numShapes, count = 0; + cin >> numShapes; + for (int i = 0; i < numShapes; i++) { + string input; + cin >> input; + count += shapes[input]; + } + cout << count << endl; + return 0; +} +int a, b, c; +int memo[4001]; +int solve(int i) { + if (i == 0) return 0; + if (memo[i] != -1) return memo[i]; + int opt1 = -1e9, opt2 = -1e9, opt3 = -1e9; + if (i >= a) { opt1 = solve(i - a) + 1; } + if (i >= b) { opt2 = solve(i - b) + 1; } + if (i >= c) { opt3 = solve(i - c) + 1; } + return memo[i] = max(opt1, max(opt2, opt3)); +} +int main() { + memset(memo, -1, sizeof memo); + int n; + cin >> n >> a >> b >> c; + cout << solve(n) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + if (n == 0 and m != 0) { + cout << "Impossible" << endl; + } else if (n == 0 and m == 0) { + cout << 0 << " " << 0 << endl; + } else { + int mx = n + max(0, m - 1); + int mn = n + max(0, m - n); + cout << mn << " " << mx << endl; + } +} +int main() { + string n1, n2; + cin >> n1 >> n2; + for (size_t i = 0; i < n1.length(); ++i) { + if (n1[i] == n2[i]) { + n1[i] = '0'; + } else { + n1[i] = '1'; + } + } + cout << n1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n > 0) { + cout << "I hate" + << " "; + for (int i = 2; i <= n; i++) { + if (i % 2 == 0) { + cout << "that I love" + << " "; + } else { + cout << "that I hate" + << " "; + } + } + } + cout << "it" << endl; +} +int main() { + int n, k, x, p, q, ans = 0, cnt = 0; + ; + cin >> n >> k >> x; + int a[n + 5]; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + if (n == 1) { + cout << x << endl; + return 0; + } + for (int i = n; i > 1; i--) { + if (a[i] >= a[i - 1] && cnt < k) { + cnt++; + ans += x; + } else + ans += a[i]; + } + if (cnt < k && a[1] <= a[2]) + ans += x; + else + ans += a[1]; + cout << ans << endl; +} +int main() { + long long n; + while (cin >> n) { + int i; + long long t = 0; + long long k = 0; + int last; + for (i = 1;; i++) { + t += i; + k += t; + if (n >= k) { + last = i; + } else { + break; + } + } + if (n == 0) { last = 0; } + cout << last << endl; + } +} +int main() { + int n, m; + cin >> n >> m; + int a[50][50]; + bool flag = false; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { cin >> a[i][j]; } + } + for (int j = 0; j < m; ++j) { + if (a[0][j] || a[n - 1][j]) { + flag = true; + break; + } + } + for (int i = 0; i < n; ++i) { + if (a[i][0] || a[i][m - 1]) { + flag = true; + break; + } + } + if (flag) + cout << 2 << endl; + else + cout << 4 << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int d = a * c; + int e = (d + b - 1) / b; + int t; + for (t = 0; t < e; t++) { + if (e * b >= (e - t) * a) break; + } + cout << t << endl; + return 0; +} +int main() { + string input, insertion; + int unique, inputLength = 0; + cin >> input >> unique; + inputLength = input.length(); + if (inputLength < unique) { + cout << "impossible" << endl; + } else { + set inputs; + for (int i = 0; i < inputLength; i++) { + insertion = input[i]; + inputs.insert(insertion); + } + if (unique > inputs.size()) + cout << unique - inputs.size() << endl; + else + cout << 0 << endl; + } +} +int main() { + string s; + cin >> s; + char c1 = '.'; + string a = ""; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '.') { + c1 = s[i + 1]; + break; + } + a += s[i]; + } + if (a[a.size() - 1] == '9') + cout << "GOTO Vasilisa." << '\n'; + else if (c1 < '5') + cout << a << '\n'; + else { + a[a.size() - 1]++; + cout << a << '\n'; + } + return 0; +} +int main() { + string word; + int NumOfWords; + cin >> NumOfWords; + for (int i = 0; i < NumOfWords; i++) { + cin >> word; + if (word.length() > 10) { + cout << word[0] << word.length() - 2 << word[word.length() - 1] << endl; + } else + cout << word << endl; + } + return 0; +} +int main() { + int a, b; + cin >> a >> b; + int k, m; + cin >> k >> m; + int ar1[a]; + int ar2[b]; + for (int i = 0; i < a; i++) { cin >> ar1[i]; } + for (int i = 0; i < b; i++) { cin >> ar2[i]; } + if (ar1[k - 1] < ar2[b - m] && k <= a && m <= b) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n, m, ans = 0; + cin >> n >> m; + ans = m - 2 * n; + ans = n - ans; + if (ans < 0) { + cout << "0" << endl; + return 0; + } else + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + string a; + cin >> a; + int x = 0; + for (int i = 0; i < n; i++) { + if (a[i] == '0') { + x++; + break; + } + if (a[i] == '1') { x++; } + } + cout << x << endl; + return 0; +} +bool cmp(long long a, long long b) { + return a < b; +} +int main() { + int a[5]; + for (int i = 0; i < 3; i++) cin >> a[i]; + sort(a, a + 3); + int min = 99999; + int sum1 = (a[1] - a[0]) + (a[2] - a[0]); + int sum2 = (a[1] - a[0]) + (a[2]) - a[1]; + int sum3 = (a[2] - a[0]) + (a[2] - a[1]); + if (sum1 < min) min = sum1; + if (sum2 < min) min = sum2; + if (sum3 < min) min = sum3; + cout << min << endl; +} +int main() { + int n, x, even = 0, lastodd = 0, lasteven = 0; + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> x; + if (x % 2 == 0) { + even += 1; + lasteven = i; + } else { + even -= 1; + lastodd = i; + } + } + cout << (even > 0 ? lastodd : lasteven) << endl; + return 0; +} +int main() { + int x[1002], y[1002]; + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } + if (x[1] * 60 + y[1] > m) { + cout << "0 0\n"; + return 0; + } + for (int i = 1; i <= n; i++) { + int p = x[i] * 60 + y[i]; + int q = x[i + 1] * 60 + y[i + 1]; + if (abs(p - q) > m * 2 + 1) { + int res1 = (p + m) / 60; + int res2 = (p + m) % 60; + cout << res1 + (res2 + 1) / 60 << " " << (res2 + 1) % 60 << endl; + return 0; + } + } + cout << x[n] + (y[n] + m + 1) / 60 << " " << (y[n] + m + 1) % 60 << endl; + return 0; +} +int main() { + int n, a, b, arra[105], arrb[105], has = 0; + memset(arra, 0, sizeof(arra)); + memset(arrb, 0, sizeof(arrb)); + cin >> n; + for (int x = 1; x <= n; x++) { + cin >> a; + arra[a]++; + } + for (int x = 1; x <= n; x++) { + cin >> b; + arrb[b]++; + } + for (int x = 1; x <= 5; x++) { + if (abs(arra[x] - arrb[x]) % 2 == 1) { + cout << "-1" << endl; + return 0; + } + has = has + (abs(arra[x] - arrb[x]) / 2); + } + has /= 2; + cout << has << endl; + return 0; +} +int main() { + int m, d; + int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + cin >> m >> d; + cout << ((d - 1) + day[m - 1] - 1) / 7 + 1 << "\n"; + return 0; +} +int main() { + int n, k, i, a = 0, len, y = 0, j; + char str[10000]; + cin >> n >> k; + for (i = 0; i < n; i++) { + cin >> str; + len = strlen(str); + for (j = 0; j < len; j++) { + if (str[j] == '4' || str[j] == '7') { y++; } + } + if (y <= k) { a++; } + y = 0; + } + cout << a << endl; + return 0; +} +int main() { + long long n, i, min1, min2, min3, max1, max2, max3, s1 = 0, s2 = 0, s3 = 0; + cin >> n; + cin >> min1 >> max1; + cin >> min2 >> max2; + cin >> min3 >> max3; + s1 += min1; + s2 += min2; + s3 += min3; + while (1) { + if (s1 + s2 + s3 == n) break; + if (s1 + s2 + s3 < n) { + if (s1 < max1) + s1++; + else if (s2 < max2) + s2++; + else if (s3 < max3) + s3++; + } + } + cout << s1 << " " << s2 << " " << s3 << endl; + return 0; +} +const int maxn = 1e5 + 10; +int n; +int main() { + cin >> n; + long long x = 2; + cout << 2 << endl; + for (long long i = 3; i < n + 2; i++) { cout << (long long)(i * i * (i - 1)) - (i - 2) << endl; } +} +int main() { + int n, c0, c1; + c0 = c1 = 0; + string s; + cin >> n >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') + c0++; + else + c1++; + } + cout << abs(c0 - c1) << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + if (a + b - c >= d || c > a || c > b) + cout << "-1" << endl; + else + cout << d - (a + b - c) << endl; + return 0; +} +bool check(string s, string t) { + if (s.length() < t.length()) return false; + for (int i = 0; i < t.length(); i++) + if (s[i] != t[i]) return false; + return true; +} +int main() { + string t; + cin >> t; + int n; + cin >> n; + string s[1000]; + for (int i = 1; i <= n; i++) cin >> s[i]; + string min = ""; + for (int i = 1; i <= n; i++) + if (check(s[i], t)) + if (min == "" || s[i] < min) min = s[i]; + if (min == "") + cout << t << endl; + else + cout << min << endl; + return 0; +} +int T; +int main() { + cin >> T; + while (T--) { + int a, b, cnt = 0; + cin >> a >> b; + if (a > b) { swap(a, b); } + while (a != 0) { + cnt += b / a; + swap(a, b); + a = a % b; + } + cout << cnt << endl; + } +} +int main() { + long long n, i, j, r, mn, mx, x, cnt = 0, a = 1, b = 1; + string s; + cin >> n; + for (i = 0; i < n; i++) { + cin >> s; + if (s == "UR" || s == "DL") + a++; + else if (s == "UL" || s == "DR") + b++; + else { + a++, b++; + } + } + cout << a * b << endl; + return 0; +} +int main() { + int n, a, b, c, d, svr = 0; + cin >> n; + while (n--) { + cin >> a >> b >> c >> d; + svr += (c - a + 1) * (d - b + 1); + } + cout << svr << endl; +} +int main() { + int n, x[105]; + cin >> n; + x[0] = -1; + for (int i = 1; i <= n; i++) cin >> x[i]; + int a = x[n]; + int b = x[n - 1]; + if (a == 0) + cout << "UP\n"; + else if (a == 15) + cout << "DOWN\n"; + else if (b == -1) + cout << "-1\n"; + else if (b > a) + cout << "DOWN\n"; + else + cout << "UP\n"; +} +int main() { + int n, a, b, sum = 0, num = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) { sum++; } + if (b > a) { num++; } + } + if (sum > num) { cout << "Mishka" << endl; } + if (sum == num) { cout << "Friendship is magic!^^" << endl; } + if (sum < num) { cout << "Chris" << endl; } + return 0; +} +int main() { + int n; + cin >> n; + cout << n / 2 + 1 << endl; + return 0; +} +pair, int> a[200020]; +long long n, k, c, x, y, m, z, ac, t, b, i; +int main() { + for (cin >> n; n--; i++) + for (cin >> k >> c >> x >> y >> m, t = 0; k--; z = max(z, t)) { + if (ac <= 200000) a[ac++] = make_pair(pair(t, c), i); + b = (c * x + y) % m; + if (b < c && k) t++; + c = b; + } + cout << z << endl; + if (ac < 200001) { + sort(a, a + ac); + for (int i = 0; i < ac; i++) cout << a[i].first.second << " " << a[i].second + 1 << endl; + } +} +int main() { + long long int x, y, m, ans = 0; + cin >> x >> y >> m; + if (max(x, y) >= m) { + cout << "0" << endl; + return 0; + } + if (max(x, y) <= 0) { + cout << "-1" << endl; + return 0; + } + if (x > y) swap(x, y); + if (x < 0) ans += (-x / y + 1 - (x % y == 0)), x += ans * y; + while (max(x, y) < m) { + if (x > y) swap(x, y); + x += y; + ans++; + } + cout << ans << endl; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int n; + cin >> n; + int ans = 0; + for (int i = 0; i < n; i++) { + int cnt; + cin >> cnt; + if (cnt > b && cnt < c) { ++ans; } + } + cout << ans << endl; + return 0; +} +int main() { + long long n, k; + cin >> n >> k; + if (n / k % 2 != 0) { + cout << "YES\n"; + } else { + cout << "NO\n"; + } + return 0; +} +void start_func() {} +int main() { + start_func(); + long long n, m; + cin >> n >> m; + if (n > log2(100000000)) { + cout << m << '\n'; + return 0; + } + long long num = pow(2, n); + cout << m % num << '\n'; + return 0; +} +map nama; +int main() { + nama[1] = "Sheldon"; + nama[2] = "Leonard"; + nama[3] = "Penny"; + nama[4] = "Rajesh"; + nama[5] = "Howard"; + int temp = 5; + int n; + cin >> n; + while (n > temp) { + n -= temp; + temp += temp; + } + temp /= 5; + if (temp == 5) { + cout << nama[n] << endl; + } else { + n--; + cout << nama[(n / temp) + 1] << endl; + } +} +const int maxn = 1e5 + 10; +const int maxm = 1e6 + 10; +const int INF = 0x3f3f3f3f; +long long casn, n, m, k; +long long num[maxn]; +long long cal(long long x) { + long long ans = 1; + for (long long i = 1; i <= x; i++) { ans *= i; } + return ans; +} +int main() { + cin >> n; + cout << 1 + (n % 2 == 0) << endl; + return 0; +} +void compute() { + int n, k; + cin >> n >> k; + int x = 0; + for (int i = 0; i < n; i++) { + int l, r; + cin >> l >> r; + x += r - l + 1; + } + int rem = x % k; + if (rem == 0) { + cout << 0 << "\n"; + return; + } + cout << k - rem << "\n"; +} +int main() { + compute(); + return 0; +} +int main() { + long long t1, t2, v1, v2, s; + cin >> s >> v1 >> v2 >> t1 >> t2; + if ((2 * t1 + v1 * s) < (2 * t2 + v2 * s)) { + cout << "First\n"; + } else if ((2 * t1 + v1 * s) > (2 * t2 + v2 * s)) { + cout << "Second\n"; + } else { + cout << "Friendship\n"; + } + return 0; +} +int main() { + long long t, s[100], a[100], b[100], c[100], r, total[100]; + int i; + cin >> t; + for (i = 0; i < t; i++) { cin >> s[i] >> a[i] >> b[i] >> c[i]; } + for (i = 0; i < t; i++) { + r = s[i] / c[i]; + if (r % a[i] == 0) { + total[i] = r + ((r / a[i]) * b[i]); + } else { + total[i] = (r - (r % a[i])) + (((r - (r % a[i])) / a[i]) * b[i]) + (r % a[i]); + } + } + for (i = 0; i < t; i++) { cout << total[i] << endl; } +} +int main() { + string s; + cin >> s; + vector p(s.length()); + for (int i = 0; i < s.length(); i++) p[i] = s[i]; + int a[4]; + for (int i = 0; i < 4; i++) a[i] = 0; + if (s.length() >= 5) a[0] = 1; + for (int i = 0; i < s.length(); i++) { + if (p[i] - 'A' >= 0 && p[i] - 'A' <= 25) a[1] = 1; + if (p[i] - 'a' >= 0 && p[i] - 'a' <= 25) a[2] = 1; + if (p[i] - '0' >= 0 && p[i] - '0' <= 9) a[3] = 1; + } + int count = 0; + for (int i = 0; i < 4; i++) count += a[i]; + if (count == 4) + cout << "Correct" << endl; + else + cout << "Too weak" << endl; + return 0; +} +int main() { + int n; + long long a, b, k; + cin >> n; + while (n--) { + long long x = 0; + cin >> a >> b >> k; + if (k % 2 == 0) + x = k / 2 * a - k / 2 * b; + else + x = (k / 2 + 1) * a - k / 2 * b; + cout << x << endl; + } + return 0; +} +int main() { + int l, r, a; + cin >> l >> r >> a; + if (abs(l - r) >= a) { + cout << (min(l, r) + a) * 2 << endl; + } else { + cout << (l + r + a) / 2 * 2 << endl; + } +} +int main() { + int n; + cin >> n; + int sum1 = 0; + int sum2 = 0; + for (int i = 0; i < n; i++) { + int x; + int y; + cin >> x >> y; + if (x < 0) + sum2++; + else + sum1++; + } + if (sum1 <= 1 || sum2 <= 1) + cout << "Yes" << endl; + else + cout << "No" << endl; + return 0; +} +int main() { + int n, a; + cin >> n >> a; + int maxa(a), mina(a), ap(0); + for (int i = 1; i < n; i++) { + cin >> a; + if (a > maxa) { + maxa = a; + ap++; + } + if (a < mina) { + mina = a; + ap++; + } + } + cout << ap << endl; + return 0; +} +int main() { + int k, a, b, v, c = 0; + cin >> k >> a >> b >> v; + while (a > 0) { + if (b >= k - 1) { + a = a - (k * v); + c++; + b = b - (k - 1); + } else if (b < k - 1) { + a = a - ((b + 1) * v); + c++; + b = 0; + } else { + a = a - v; + c++; + } + } + cout << c << endl; + return 0; +} +int main() { + int n, m, k, i; + int a[100]; + while (cin >> n >> m >> k) { + for (i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (i = n; k < m && i >= 1; i--) { k += a[i - 1] - 1; } + if (k < m) + cout << -1 << endl; + else + cout << n - i << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10) + cout << 0 << endl; + else if (n > 10 && n <= 19) + cout << 4 << endl; + else if (n == 20) + cout << 15 << endl; + else if (n == 21) + cout << 4 << endl; + else + cout << 0 << endl; +} +int main() { + int T, S, q; + cin >> T >> S >> q; + cout << (int)ceil(log(T * 1.0 / S) / log(q)) << endl; +} +int a[26]; +int main() { + int n, k, mn = 100000; + string s; + cin >> n >> k >> s; + for (int i = 0; i < ((int)(s).size()); i++) a[s[i] - 'A']++; + for (int i = 0; i < k; i++) mn = min(a[i], mn); + cout << mn * k << endl; +} +int main() { + int i, j, a = 0, b = 0, n, m, o, p, q, r, c = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> o; + a = a + o; + cin >> p; + b = b + p; + cin >> q; + c = c + q; + } + if (a == 0 && b == 0 && c == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + char a, d; + char b, c; + int fl = 0; + cin >> b >> c; + for (int i = 1; i <= 5; i++) { + cin >> a >> d; + if (a == b || c == d) { + fl = 1; + break; + } + } + if (fl == 1) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int n, k, sum = 0; + cin >> n >> k; + int a[105], b[105]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + sort(b, b + n); + if (b[n - 1] > k) { + for (int i = 0; i < n; i++) { + if (a[i] <= k) + sum++; + else + break; + } + for (int j = n - 1; j >= 0; j--) { + if (a[j] <= k) + sum++; + else + break; + } + cout << sum << endl; + } else + cout << n << endl; + return 0; +} +bool good[200]; +int main() { + int n; + int a[300][300]; + cin >> n; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { cin >> a[i][j]; } + } + memset(good, true, sizeof(good)); + int sum = 0; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (a[i][j] == 1 || a[i][j] == 3) { + good[i] = false; + break; + } + } + if (!good[i]) continue; + for (int j = 1; j <= n; j++) { + if (a[j][i] == 2 || a[j][i] == 3) { + good[i] = false; + break; + } + } + if (good[i]) sum++; + } + cout << sum << endl; + for (int i = 1; i <= n; i++) { + if (good[i]) { + if (sum == 1) + cout << i << endl; + else + cout << i << ' '; + sum--; + } + } + return 0; +} +int main() { + int n, x, y, i = 0, v[150], o; + cin >> n >> y; + if (n > y) { n = y; } + if (n % 2 == 0) { + cout << "Malvika" << endl; + } else { + cout << "Akshat" << endl; + } + return 0; +} +int main() { + int arr[5][5], indx1 = 0, indx2 = 0, x = 1; + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 4; j++) { cin >> arr[i][j]; } + } + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 4; j++) { + if (arr[i][j] == x) { + indx1 = i; + indx2 = j; + break; + } + } + } + int y = abs(2 - indx1), z = abs(2 - indx2); + cout << y + z << endl; + return 0; +} +int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; +string s; +int main() { + cin >> a >> s; + bool ok = 1; + for (int q = 0; q < a; q++) { + if (s[q] != '4' && s[q] != '7') { + ok = 0; + break; + } + } + if (not ok) { + cout << "NO" << endl; + return 0; + } + for (int q = 0; q < a; q++) { + if (q < (a + 1) / 2) { + d += (int)s[q]; + } else { + c += (int)s[q]; + } + } + if (d == c) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } +} +int main() { + int n, p, q, tot = 0; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> p >> q; + if ((p + 2) <= q) { tot++; } + } + cout << tot << endl; + return 0; +} +long long int n; +long long int a[300001]; +int main() { + cin >> n; + for (long long int i = 1; i <= n; ++i) { cin >> a[i]; } + sort(a + 1, a + n + 1); + long long int ans = 0; + for (long long int i = 1; i < n; ++i) { ans += (i + 1) * a[i]; } + ans += n * a[n]; + cout << ans << endl; + return 0; +} +int main() { + int a, b, c, d; + cin >> a >> b >> c >> d; + int m = max((3 * a) / 10, a - (a / 250) * c); + int v = max((3 * b) / 10, b - (b / 250) * d); + if (m > v) + cout << "Misha" << endl; + else if (m < v) + cout << "Vasya" << endl; + else if (m == v) + cout << "Tie" << endl; + return 0; +} +int main() { + int i, n, moves = 0; + string a, b; + cin >> n >> a >> b; + for (i = 0; i < n; i++) moves += min(abs(b[i] - a[i]), 10 - abs(a[i] - b[i])); + cout << moves << endl; + return 0; +} +int main() { + int x, a, b, hasil = 10000; + cin >> x; + for (int i = 1; i <= sqrt(x); i++) { + if (x % i == 0) { + a = i; + b = x / i; + if (b - a < hasil) { + hasil = b - a; + b = b; + a = a; + } + } + } + cout << a << " " << b << endl; + return 0; +} +const int MAX_N = 60; +int n, grid[MAX_N][MAX_N]; +bool check(int x, int y) { + if (grid[x][y] == 1) return true; + for (int s = 0; s < n; s++) + for (int t = 0; t < n; t++) + if (grid[x][y] == grid[x][s] + grid[t][y]) return true; + return false; +} +int main() { + cin >> n; + for (int r = 0; r < n; r++) + for (int c = 0; c < n; c++) cin >> grid[r][c]; + bool ok = true; + for (int r = 0; r < n; r++) + for (int c = 0; c < n; c++) ok &= check(r, c); + puts(ok ? "Yes" : "No"); + return (0); +} +int main() { + string s, ss; + cin >> s >> ss; + reverse(ss.begin(), ss.end()); + int x, y; + stringstream sss, ssss; + sss << s; + sss >> x; + ssss << ss; + ssss >> y; + cout << x + y << endl; +} +long long int choose(long long int n, long long int m) { + long long int ans = 0; + long long int num = 1; + long long int den = 1; + for (long long int i = 0; i < m; i++) { + num *= (n - i); + num = num / (i + 1); + } + return num; +} +bool isPrime(int n) { + if (n <= 1) return false; + if (n <= 3) return true; + if (n % 2 == 0 || n % 3 == 0) return false; + for (int i = 5; i * i <= n; i = i + 6) { + if (n % i == 0 || n % (i + 2) == 0) return false; + } + return true; +} +long long int gcd(long long int a, long long int b) { + if (a == 0) { + return b; + } else { + return gcd(b % a, a); + } +} +bool sortDes(long long int i, long long int j) { + return i > j; +} +long long int bits(long long int n) { + long long int count = 0; + while (n != 0) { + if (n % 2 != 0) + count++; + else + ; + n /= 2; + } + return count; +} +int main() { + long long int i, j, k, n, s = 0; + cin >> n; + set t; + set h; + string s1, s2; + for (i = 0; i < n; i++) { + cin >> s1; + s2 = ""; + t.clear(); + for (j = 0; j < s1.size(); j++) { t.insert(s1[j]); } + set::iterator itr; + for (itr = t.begin(); itr != t.end(); itr++) { s2 += *itr; } + h.insert(s2); + } + cout << h.size() << endl; + return 0; +} +void Fast_Read_Out() {} +void Random() { + unsigned int seed; + asm("rdtsc" : "=A"(seed)); + srand(seed); +} +unsigned int Time() { + unsigned int time = clock() / 1000.00; + return time; +} +const int inf = int(1e9) + 123; +const int N = int(1e5) + 123; +set s; +map d; +int a[N]; +long long Calc(int x) { + return (x * x - x) / 2; +} +int main() { + Random(); + Fast_Read_Out(); + int n; + cin >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + long long ans = 0, res = 0; + for (int i = 2; i <= n; i++) { + if (a[i] == a[i - 1]) { + res++; + ans += res; + } else + res = 0; + } + cout << ans + n << endl; +} +int main() { + int n; + cin >> n; + vector status(n), name(n); + for (int i = 0; i < n; i++) { cin >> name[i] >> status[i]; } + for (int i = 0; i < n; i++) { + if (status[i] == "rat") cout << name[i] << '\n'; + } + for (int i = 0; i < n; i++) { + if (status[i] == "woman" || status[i] == "child") cout << name[i] << '\n'; + } + for (int i = 0; i < n; i++) { + if (status[i] == "man") cout << name[i] << '\n'; + } + for (int i = 0; i < n; i++) { + if (status[i] == "captain") cout << name[i] << '\n'; + } + return 0; +} +int main() { + long long n, d, a[200], ans = 0; + cin >> n >> d; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n); + for (int i = 1; i < n; i++) { + if (a[i] - a[i - 1] == d * 2) ans++; + if (a[i] - a[i - 1] > d * 2) ans = ans + 2; + } + cout << ans + 2 << endl; + return 0; +} +int main() { + string s; + int len; + cin >> s; + len = s.size(); + string ans; + for (int i = 1; i < (1 << len); i++) { + string b; + for (int j = 0; j < len; j++) + if (i >> j & 1) b += s[j]; + string c = b; + reverse(c.begin(), c.end()); + if (b == c) ans = max(ans, b); + } + cout << ans << endl; + return 0; +} +int main() { + int n, k, l, c, d, p, nl, np; + int drink, lime, salt, toast, quant; + cin >> n >> k >> l >> c >> d >> p >> nl >> np; + drink = k * l / nl; + lime = c * d; + salt = p / np; + toast = min(min(drink, lime), salt); + quant = toast / n; + cout << quant << endl; +} +int main() { + int w, h, w1, h1, w2, h2; + cin >> w >> h >> w1 >> h1 >> w2 >> h2; + for (int i = h; i >= 0; i--) { + w += i; + if (i == h1) { + w -= w1; + if (w < 0) w = 0; + } else if (i == h2) { + w -= w2; + if (w < 0) w = 0; + } + } + cout << w << endl; +} +int main() { + int n, res = 0, one = 0, zero = 0; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i]) { + one = max(one, zero); + one++; + } else { + zero++; + } + } + res = max(one, zero); + cout << res << "\n"; + return 0; +} +int main() { + char a, b; + cin >> a >> b; + if ((a == 'a' || a == 'h') && (b == '1' || b == '8')) { + cout << 3 << endl; + } else if ((a == 'a' || a == 'h') && (b != '1' && b != '8')) + cout << 5 << endl; + else if ((a != 'a' && a != 'h') && (b == '1' || b == '8')) + cout << 5 << endl; + else + cout << 8 << endl; + return 0; +} +int main() { + int n, a; + cin >> a; + n = a + a / 2; + cout << n << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int mp[200][200]; +int main() { + memset(mp, 0, sizeof(mp)); + int ans = 0; + int n; + cin >> n; + while (n--) { + string s; + cin >> s; + int len = s.length(); + int flag1, flag2; + flag1 = flag2 = 0; + for (int i = 0; i < len; i++) { + if (flag1 == s[i] || flag2 == s[i]) continue; + if (!flag1) { + flag1 = s[i]; + continue; + } + if (!flag2) { + flag2 = s[i]; + continue; + } + flag1 = flag2 = 0; + break; + } + if (!flag1) continue; + if (flag1 > 0 && flag2 > 0) { + mp[flag1][flag2] += len; + ans = max(ans, mp[flag1][flag2]); + mp[flag2][flag1] += len; + ans = max(ans, mp[flag2][flag1]); + } else if (flag1 > 0 && flag2 == 0) { + for (int i = 97; i <= 122; i++) { + mp[flag1][i] += len; + ans = max(ans, mp[flag1][i]); + if (i == flag1) continue; + mp[i][flag1] += len; + ans = max(ans, mp[i][flag1]); + } + } + } + cout << ans << endl; +} +int main() { + long long int a, b, c, d, e, f, g; + vector v; + vector v1[200]; + while (cin >> a >> b) { + c = 0; + d = b; + while (1) { + c++; + if (c < a) { + if (b - c == 0) { + cout << "0" << endl; + break; + } else if (b - c > 0) { + b -= c; + } else { + cout << b << endl; + break; + } + } else { + if (b - c == 0) { + cout << "0" << endl; + break; + } else if (b - c > 0) { + b -= c; + } else { + cout << b << endl; + break; + } + c = 0; + } + } + } + return 0; +} +long long int power(long long int a, long long int b) { + if (b == 0) return 1; + return a * power(a, b - 1); +} +long long int gcd(long long int a, long long int b) { + if (a == 0) return b; + return gcd(b % a, a); +} +int main() { + int minval, maxval, res = 0; + int n; + cin >> n; + cin >> minval; + maxval = minval; + while (--n) { + int x; + cin >> x; + if (minval > x) { + res++; + minval = x; + } else if (maxval < x) { + res++; + maxval = x; + } + } + cout << res << "\n"; +} +int main() { + string a; + string b; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a == b) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int main() { + int m, d; + while (cin >> m >> d) { + int week = 1; + int num = month[m] - (7 - d + 1); + if (num % 7 == 0) { + week = week + (num / 7); + } else { + week = week + 1 + (num / 7); + } + cout << week << endl; + } +} +long long gcd(long long a, long long b) { + if (a == 0 || b == 0) return (a + b); + if (a > b) return (gcd(a % b, b)); + return (gcd(b, b % a)); +} +string s; +int main() { + cin >> s; + int p = 1, ans = 0; + for (int i = (int)(1); i < (int)(s.length()); ++i) { + if (s[i] == s[i - 1]) + p++; + else { + if (p % 2 == 0) ans++; + p = 1; + } + } + if (p % 2 == 0) ans++; + p = 1; + cout << ans << endl; + return 0; +} +int n, a, b, sum, h, ans; +bool cek[1000]; +int main() { + cin >> n >> h; + for (int i = 1; i <= n; i++) { + cin >> a; + for (int j = 1; j <= a; j++) { + cin >> b; + cek[b] = 1; + } + } + for (int i = 1; i <= h; i++) { + if (!cek[i]) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + int n, k, i, prev, c; + cin >> n >> k; + for (i = 0; i < n; i++) { + int a; + cin >> a; + if (a == prev) + c++; + else + c = 1; + prev = a; + } + if (c + k > n) + cout << n - c << endl; + else + cout << -1 << endl; +} +int main() { + int n; + cin >> n; + int c[40] = {0}, r[40] = {0}; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) { + int x; + cin >> x; + r[i] += x; + c[j] += x; + } + int ans = 0; + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + if (c[j] > r[i]) ans++; + cout << ans << endl; + return 0; +} +const int maxn = 200005; +const int maxm = maxn * 2; +const int inf = 0x3f3f3f3f; +const long long mod = 998244353; +void init() {} +int n; +long long a[105]; +int main() { + init(); + cin >> n; + long long ans = 1e18; + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= n; i++) { + long long tmp = 0; + for (int j = 1; j <= n; j++) { tmp += a[j] * 4 * ((i - 1) * 2 + (j - 1)); } + ans = min(ans, tmp); + } + cout << ans << endl; + return 0; +} +int main() { + int n, a, b, tot = 0, sum = 0; + cin >> n; + while (n--) { + cin >> a >> b; + if (a > b) { + tot++; + } else if (a < b) { + sum++; + } + } + if (sum > tot) { + cout << "Chris" << endl; + } else if (tot > sum) { + cout << "Mishka" << endl; + } else + cout << "Friendship is magic!^^" << endl; + return 0; +} +int main() { + long long q; + cin >> q; + for (long long z = 0; z < q; z++) { + long long a, b, k, res = 0; + cin >> a >> b >> k; + res += (k - k / 2) * a; + res -= (k / 2) * b; + cout << res << endl; + } +} +int main() { + string st; + int res = 0; + cin >> st; + string srt = st; + sort(srt.begin(), srt.end()); + for (int i = 0; i < srt.length(); i++) { + if (srt[i] != srt[i - 1]) { res++; } + } + if (res % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; +} +int main() { + int n; + cin >> n; + cout << (n + 4) / 5 << '\n'; +} +int main() { + int n, m; + cin >> n; + cin >> m; + n = pow(2, n); + cout << m % n << endl; +} +int main() { + int m, n, p, sum = 0, a, b, c; + cin >> m >> n >> p; + a = sqrt(p * m / n); + b = sqrt(m * n / p); + c = sqrt(n * p / m); + sum = 4 * (a + b + c); + cout << sum << endl; + return 0; +} +const int maxn = 130; +int n; +int a; +set se; +int main() { + cin >> n; + se.clear(); + while (n--) { + cin >> a; + if (a != 0) se.insert(a); + } + int ans = se.size(); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + int arr[n]; + for (int i = 1; i <= n; i++) { cin >> arr[i]; } + for (int i = 1; i <= n; i++) { + if (arr[arr[arr[i]]] == i) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; +} +int main() { + int n, result; + cin >> n; + result = (n / 2) * 3; + cout << result << endl; + return 0; +} +int judge[1005][1005]; +int main() { + long long n, m; + int x, y; + int ans; + int a[110]; + while (cin >> n >> m) { + ans = 0; + memset(judge, 0, sizeof(judge)); + for (int i = 1; i <= n; i++) { cin >> a[i]; } + for (int i = 1; i <= m; i++) { + cin >> x >> y; + judge[y][x] = judge[x][y] = 1; + } + for (int i = 1; i <= n - 2; i++) + for (int j = i + 1; j <= n - 1; j++) + for (int k = j + 1; k <= n; k++) { + int sum = 0; + if (judge[i][j] && judge[i][k] && judge[j][k]) { + sum = a[i] + a[j] + a[k]; + if (ans == 0) + ans = sum; + else if (sum < ans) + ans = sum; + } + } + if (ans == 0) + cout << "-1" << endl; + else + cout << ans << endl; + } +} +int main() { + string s; + cin >> s; + int i = 0, k = 1; + while (i < s.size()) { + if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { + i = i + 3; + } else if (s[i] == '1' && s[i + 1] == '4') { + i = i + 2; + } else if (s[i] == '1') { + i++; + } else { + k = 0; + break; + } + } + if (k == 1) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int n, k, i; + char s[30] = {0}, c; + cin >> n >> k; + getchar(); + for (i = 0; i < n; i++) { + cin >> c; + if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a'; + s[c - 'a']++; + } + for (i = 0; i < 30; i++) { + if (s[i] > k) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; +} +int main() { + long long n, m, a, b; + cin >> n >> m >> a >> b; + long long k = n / m; + long long t1 = (n - k * m) * b; + long long t2 = (m * (k + 1) - n) * a; + if (t1 > t2) { + cout << t2 << endl; + } else { + cout << t1 << endl; + } + return 0; +} +int main() { + string a; + while (cin >> a) { + int cnt = 1; + int res = 0; + int len = a.length(); + for (int i = 1; i < len; i++) { + if (a[i] == a[i - 1]) { cnt++; } + if (i == len - 1 || a[i] != a[i - 1]) { + res = res + (1 - cnt % 2); + cnt = 1; + } + } + cout << res << endl; + } +} +int main() { + int i, x, n, count = 0, a, b, c, sum = 0; + cin >> a >> b >> c; + cin >> n; + for (i = 0; i < n; i++) { + cin >> x; + if (x > b && x < c) count++; + } + cout << count << endl; + return 0; +} +const long long int MOD = 1000000007; +long long int mod(long long int l) { + l %= MOD; + while (l < 0) l += MOD; + return l % MOD; +} +long long int power(long long int x, long long int y, long long int p = MOD) { + long long int res = 1; + x = x % p; + while (y > 0) { + if (y & 1) res = (res * x) % p; + y = y >> 1; + x = (x * x) % p; + } + return res; +} +int main() { + int n, m; + cin >> n >> m; + int arr[m]; + for (int i = 0; i < m; i++) arr[i] = 0; + for (int i = 0; i < n; i++) { + int j; + cin >> j; + for (int k = 0; k < j; k++) { + int g; + cin >> g; + arr[g - 1]++; + } + } + bool done = true; + for (int i = 0; i < m; i++) { + if (arr[i] == 0) { + cout << "NO" << endl; + return 0; + } + } + cout << "YES" << endl; + return 0; +} +int main() { + string s1, s2; + cin >> s1 >> s2; + for (size_t i = 0; i < s1.length(); ++i) { + if (s1[i] == s2[i]) { + s1[i] = '0'; + } else { + s1[i] = '1'; + } + } + cout << s1 << endl; + return 0; +} +int main() { + int n, x, y, d, t, r, a; + cin >> t; + while (t--) { + cin >> n >> x >> y >> d; + n--, x--, y--; + r = abs(x - y); + if (r % d == 0) + a = r / d; + else if (n % d == 0 && y % d == 0) + a = min(y / d + (x + d - 1) / d, (n - x + d - 1) / d + (n - y) / d); + else if (y % d == 0) + a = y / d + (x + d - 1) / d; + else if ((n - y) % d == 0) + a = (n - x + d - 1) / d + (n - y) / d; + else + a = -1; + cout << a << endl; + } +} +int main() { + long long int n; + cin >> n; + if (n % 2) + cout << "contest" << endl; + else + cout << "home" << endl; + return 0; +} +long long dm(long long x, long long y, long long z, long long l) { + long long res = 0, now = 0; + for (long long i = max((long long)0, x + y - z); i <= l; i++) { + now = min(l - i, z + i - x - y); + res += (now + 1) * (now + 2) / 2; + } + return res; +} +int main() { + long long a, b, c, l; + unsigned long long ans; + cin >> a >> b >> c >> l; + ans = (l + 1) * (l + 2) * (l + 3) / 6; + ans -= dm(a, b, c, l); + ans -= dm(a, c, b, l); + ans -= dm(b, c, a, l); + cout << ans << endl; + return 0; +} +int main() { + long long int a, b, k, t, c; + cin >> t; + while (t--) { + cin >> a >> b >> k; + if (k % 2 == 0) { + k = k / 2; + c = (a * k) - (b * k); + } else if (k % 2 != 0) { + k = k - 1; + k = k / 2; + c = (a + a * k) - (b * k); + } + cout << c << endl; + } +} +int main() { + int n, k; + cin >> n; + for (int a = 1; a <= n / 2; ++a) { + k = n / 2 - a + 1; + for (int j = 1; j <= k; ++j) cout << "*"; + for (int j = 1; j <= n - k * 2; ++j) cout << "D"; + for (int j = 1; j <= k; ++j) cout << "*"; + cout << endl; + } + for (int a = 1; a <= n; ++a) cout << "D"; + cout << endl; + for (int a = 1; a <= n / 2; ++a) { + for (int j = 1; j <= a; ++j) cout << "*"; + for (int j = 1; j <= n - a * 2; ++j) cout << "D"; + for (int j = 1; j <= a; ++j) cout << "*"; + cout << endl; + } +} +int main() { + int n, m, sum, i; + cin >> n >> m; + sum = n * (n + 1) / 2; + if (m >= sum) m = m % sum; + for (int i = 1; i < n; i++) { + if (m >= i) { + m -= i; + } else + break; + } + cout << m << endl; +} +int main() { + int a, b, max, min, ans; + cin >> a >> b; + if (a > b) { + max = a; + min = b; + } else { + max = b; + min = a; + } + ans = (max - min) / 2; + cout << min << " " << ans << endl; + return 0; +} +int main() { + long long l, r, temp, ans; + while (cin >> l >> r) { + if (r < 10) { + temp = 9 / 2; + if (temp < l) + ans = l * (9 - l); + else if (temp > r) + ans = r * (9 - r); + else + ans = temp * (9 - temp); + } else if (r < 100) { + temp = 99 / 2; + if (temp < l) + ans = l * (99 - l); + else if (temp > r) + ans = r * (99 - r); + else + ans = temp * (99 - temp); + } else if (r < 1000) { + temp = 999 / 2; + if (temp < l) + ans = l * (999 - l); + else if (temp > r) + ans = r * (999 - r); + else + ans = temp * (999 - temp); + } else if (r < 10000) { + temp = 9999 / 2; + if (temp < l) + ans = l * (9999 - l); + else if (temp > r) + ans = r * (9999 - r); + else + ans = temp * (9999 - temp); + } else if (r < 100000) { + temp = 99999 / 2; + if (temp < l) + ans = l * (99999 - l); + else if (temp > r) + ans = r * (99999 - r); + else + ans = temp * (99999 - temp); + } else if (r < 1000000) { + temp = 999999 / 2; + if (temp < l) + ans = l * (999999 - l); + else if (temp > r) + ans = r * (999999 - r); + else + ans = temp * (999999 - temp); + } else if (r < 10000000) { + temp = 9999999 / 2; + if (temp < l) + ans = l * (9999999 - l); + else if (temp > r) + ans = r * (9999999 - r); + else + ans = temp * (9999999 - temp); + } else if (r < 100000000) { + temp = 99999999 / 2; + if (temp < l) + ans = l * (99999999 - l); + else if (temp > r) + ans = r * (99999999 - r); + else + ans = temp * (99999999 - temp); + } else if (r < 1000000000) { + temp = 999999999 / 2; + if (temp < l) + ans = l * (999999999 - l); + else if (temp > r) + ans = r * (999999999 - r); + else + ans = temp * (999999999 - temp); + } else if (r < 10000000000) { + temp = 9999999999 / 2; + if (temp < l) + ans = l * (9999999999 - l); + else if (temp > r) + ans = r * (9999999999 - r); + else + ans = temp * (9999999999 - temp); + } + cout << ans << endl; + } + return 0; +} +int main() { + double d, a, b; + cin >> d >> a >> b; + double t = d / (a + b); + cout << t * a << endl; +} +int main() { + int a, b, c, n, cnt = 0; + vector X; + cin >> a >> b >> c >> n; + for (int i = 0; i < n; i++) { + int z; + cin >> z; + X.push_back(z); + } + for (int i = 0; i < n; i++) { + if (X[i] > b && X[i] < c) cnt++; + } + cout << cnt << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int sum = 0, solve = 0; + for (int i = 1; sum <= 240 - k; i++, solve += 1) { sum += i * 5; } + cout << (solve - 1 >= n ? n : solve - 1) << endl; +} +int main() { + string s; + int n; + cin >> n; + cin >> s; + int cnt = 0, flag = 0; + for (int i = 0; i < s.size() - 1; i++) { + if (s[i] != s[i + 1]) { + cnt += 2; + s.erase(s.begin() + i); + s.erase(s.begin() + i); + i = max(i - 2, -1); + } + if (s.empty()) break; + } + cout << n - cnt << endl; + return 0; +} +int v[10]; +int main() { + bool can = true; + string s; + int n, k, ans = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + can = true; + memset(v, 0, sizeof(v)); + cin >> s; + for (int j = 0; j < s.size(); j++) { v[s[j] - '0'] = 1; } + for (int j = 0; j <= k; j++) { + if (!v[j]) can = false; + } + if (can) ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int T; + cin >> T; + long int L, v, l, r; + while (T--) { + cin >> L >> v >> l >> r; + long int nbr_lat = L / v; + long int hidden = r / v - l / v; + if (l % v == 0) hidden++; + cout << nbr_lat - hidden << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int a = 1, b = 1; + for (int i = 0; i < n; ++i) { + string s; + cin >> s; + if (s.size() == 4) a++, b++; + if (s == "UR" || s == "DL") a++; + if (s == "UL" || s == "DR") b++; + } + cout << a * 1ll * b << endl; + return 0; +} +int a[105]; +int main() { + int n, t, t1, maxx; + while (cin >> n) { + int sum = 0; + memset(a, 0, sizeof(a)); + for (int i = 0; i < n; i++) cin >> a[i]; + t1 = a[0]; + int ff = 1, t; + while (ff == 1) { + maxx = -1; + for (int i = 1; i < n; i++) { + if (maxx < a[i]) { + maxx = a[i]; + t = i; + } + } + if (a[0] > maxx) + ff = 0; + else { + a[t]--; + a[0]++; + } + } + cout << a[0] - t1 << endl; + } + return 0; +} +int main() { + long long t, s, a, b, c, q, o; + cin >> t; + while (t--) { + cin >> s >> a >> b >> c; + q = s / c; + o = q / a; + cout << q + o * b << endl; + } + return 0; +} +int main() { + long long int n, i, j; + cin >> n; + long long int a[n], dp[n]; + long long int ans = -1; + for (i = 0; i < n; i++) { + cin >> a[i]; + dp[i] = 1; + } + for (i = 1; i < n; i++) { + if (a[i] >= a[i - 1]) dp[i] = max(dp[i], 1 + dp[i - 1]); + } + for (i = 0; i < n; i++) { ans = max(ans, dp[i]); } + cout << ans << "\n"; + return 0; +} +char str[30005][25]; +int i, j, n, m; +int main() { + cin >> n; + for (i = 1; i <= n; i++) { cin >> str[i]; } + m = strlen(str[1]); + for (i = 0; i < m; i++) { + for (j = 1; j <= n; j++) { + if (str[1][i] != str[j][i]) { + cout << i << endl; + return 0; + } + } + } + return 0; +} +int m, n, a, b; +int fit() { + int f1 = a * a + b, f2 = a + b * b; + if (f1 == n && f2 == m) + return 0; + else if (f1 > n) + return 1; + else if (f2 > m) + return 1; + return -1; +} +int main() { + cin >> n >> m; + int cnt = 0; + for (a = 0; a <= 31; a++) + for (b = 0; b <= 31; b++) { + if (fit() == 0) + cnt++; + else if (fit() == 1) + break; + } + cout << cnt << endl; + return 0; +} +int main() { + int n; + cin >> n; + int star_count, d_count, i = 0; + star_count = n - 1, d_count = 1; + vector data; + while (star_count >= 0) { + string row = ""; + for (int i = 0; i < star_count / 2; ++i) row += "*"; + for (int i = 0; i < d_count; ++i) row += "D"; + for (int i = 0; i < star_count / 2; ++i) row += "*"; + data.push_back(row); + star_count -= 2; + d_count += 2; + ++i; + } + for (int i = 0; i < data.size(); ++i) cout << data[i] << endl; + for (int i = data.size() - 2; i >= 0; --i) cout << data[i] << endl; + return 0; +} +int main() { + int n, m, mn, mx; + cin >> n >> m >> mn >> mx; + int cur_min = 105, cur_max = -1, vis_min = 1, vis_max = 1; + for (int i = 0; i < m; i++) { + int temp; + cin >> temp; + cur_min = min(cur_min, temp); + cur_max = max(cur_max, temp); + if (temp == mn) { vis_min = 0; } + if (temp == mx) { vis_max = 0; } + } + if (cur_min < mn) { + cout << "Incorrect" << endl; + } else if (cur_max > mx) { + cout << "Incorrect" << endl; + } else if (vis_min + vis_max > n - m) { + cout << "Incorrect" << endl; + } else { + cout << "Correct" << endl; + } +} +int main() { + int n; + cin >> n; + int *mas = new int[n]; + for (int i = 0; i < n; i++) { cin >> mas[i]; } + int res = 0; + for (int i = 0; i < n; i++) { + int cur_res = mas[i]; + if (cur_res > res) res = cur_res; + for (int j = (i + 1); j < n; j++) { + cur_res = cur_res ^ mas[j]; + if (cur_res > res) res = cur_res; + } + } + cout << res << endl; + return 0; +} +int d[5] = {1, 5, 10, 20, 100}; +int main() { + int n, ans = 0; + cin >> n; + for (int i = 4; i >= 0; i--) { + int t = n / d[i]; + n = n - t * d[i]; + ans += t; + } + cout << ans << endl; + return 0; +} +int main() { + int n, k; + cin >> n >> k; + int a = 240 - k; + int count = 0; + for (int i = 0; i < n; i++) { + a = a - (5 * i); + if (a < (5 * (i + 1))) { + break; + } else { + count++; + } + } + cout << count << endl; + return 0; +} +int p2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256}; +int main() { + int n, b, p, k, m; + int bn = 0; + cin >> n >> b >> p; + m = n; + while (m > 1) { + for (k = 8; k >= 0; k--) { + if (p2[k] <= m) { + bn += p2[k] / 2 + p2[k] * b; + break; + } + } + m = p2[k] / 2 + (m - p2[k]); + } + cout << bn << " " << n * p << endl; + return 0; +} +int main() { + string a; + getline(cin, a); + int temp = 0; + for (int i = 0; i < a.length(); i += 2) { + for (int j = i + 2; j < a.length(); j += 2) { + if (a[j] < a[i]) { + temp = a[j]; + a[j] = a[i]; + a[i] = temp; + } + } + } + cout << a << endl; +} +int main() { + int n; + cin >> n; + vector V(n); + for (int i = 0; i < n; ++i) cin >> V[i]; + for (int i = 0; i < V[0].size(); ++i) { + for (int j = 0; j < n; ++j) { + if (V[j][i] != V[0][i]) { + cout << i << "\n"; + return 0; + } + } + } + cout << V[0].size() << "\n"; + return 0; +} +int main() { + int k, j = 0; + string s; + cin >> k >> s; + map m; + vector v; + for (int i = 1; i <= k && j < s.length(); i++) { + string x = ""; + x += s[j]; + m[s[j]]++; + j++; + while (m[s[j]]) { + x += s[j]; + j++; + } + if (x != " ") v.push_back(x); + } + string x = ""; + for (int u = j; u < s.length(); u++) { x += s[u]; } + if (v.size() < k) + cout << "NO" << endl; + else { + cout << "YES" << endl; + int i = 0; + for (i = 0; i < v.size() - 1; i++) cout << v[i] << endl; + cout << v[i] + x << endl; + } +} +void width(int arr[], int n) { + cout << "hi"; +} +int main() { + int n; + cin >> n; + string s; + cin >> s; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int min = INT_MAX; + for (int i = 0; i < n - 1; i++) { + if (s[i] == 'R' && s[i + 1] == 'L') { + if (a[i + 1] - a[i] < min) { min = a[i + 1] - a[i]; } + } + } + if (min != INT_MAX) + cout << min / 2 << endl; + else + cout << "-1" << endl; +} +int main() { + int n, k; + cin >> n >> k; + for (int i = 0; i < k; i++) { + if (n % 10 == 0) + n = n / 10; + else + n = n - 1; + } + cout << n << endl; +} +int main() { + string a; + string b; + int i; + cin >> a >> b; + for (i = 0; i < a.size(); i++) { + a[i] = tolower(a[i]); + b[i] = tolower(b[i]); + } + if (a == b) + cout << "0" << endl; + else { + for (i = 0; i < a.size(); i++) { + if (a[i] < b[i]) { + cout << "-1" << endl; + break; + } + if (a[i] > b[i]) { + cout << "1" << endl; + break; + } + } + } + return 0; +} +bool vis[26]; +int ans; +int already(char s) { + int cnt = s - 97; + int flag; + if (vis[cnt] == true) { + flag = 0; + } else { + flag = 1; + vis[cnt] = true; + } + return flag; +} +int main() { + string s; + cin >> s; + int len = s.length(); + for (int i = 0; i < len; ++i) { + if (already(s[i])) { ans++; } + } + if (ans % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + if (n % 2) + cout << "Ehab\n"; + else + cout << "Mahmoud\n"; + return 0; +} +int cut_ribbon(int n, int a, int b, int c) { + int arr[n + 1]; + memset(arr, 0, sizeof(arr)); + if (a <= n) { arr[a] = 1; } + if (b <= n) { arr[b] = 1; } + if (c <= n) { arr[c] = 1; } + for (int i = 0; i <= n; i++) { + if (i > a && arr[i - a] != 0) { arr[i] = max(arr[i], arr[i - a] + 1); } + if (i > b && arr[i - b] != 0) { arr[i] = max(arr[i], arr[i - b] + 1); } + if (i > c && arr[i - c] != 0) { arr[i] = max(arr[i], arr[i - c] + 1); } + } + return arr[n]; +} +int main() { + int n, a, b, c; + cin >> n >> a >> b >> c; + cout << cut_ribbon(n, a, b, c) << endl; + return 0; +} +int main() { + string line, move; + int l = 0, sum = 1; + cin >> line >> move; + for (int i = 0; i < move.length(); i++) { + if (move[i] == line[l]) { + sum++; + l++; + } + } + cout << sum << endl; + return 0; +} +int main() { + int c[5] = {100, 20, 10, 5, 1}; + long t = 0, n; + cin >> n; + int i = 0; + while (n > 0) { + t += n / c[i]; + n = n % c[i]; + i++; + } + cout << t << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + n = min(n, m); + if (n % 2 == 0) + cout << "Malvika\n"; + else + cout << "Akshat\n"; + return 0; +} +int main() { + int n, c = 0, c1 = 0; + cin >> n; + char a[n]; + cin >> a; + for (int i = 0; i < n; i++) { + if (a[i] == '0') + c++; + else + c1++; + } + if (c > c1) + cout << c - c1 << endl; + else if (c1 > c) + cout << c1 - c << endl; + else + cout << c - c1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) cin >> a[i]; + int dp[n][3]; + memset(dp, 0, sizeof(dp[0][0]) * n * 3); + dp[0][0] = 0; + if (a[0] == 1 || a[0] == 3) + dp[0][1] = 1; + else + dp[0][1] = 0; + if (a[0] == 2 || a[0] == 3) + dp[0][2] = 1; + else + dp[0][2] = 0; + for (int i = 1; i < n; i++) { + dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])); + if (a[i] == 1 || a[i] == 3) dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][2] + 1); + if (a[i] == 2 || a[i] == 3) dp[i][2] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1); + } + int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); + cout << n - ans << endl; + return 0; +} +const int M = 100 + 5; +string card[9] = {"6", "7", "8", "9", "T", "J", "Q", "K", "A"}; +int main() { + char trump; + cin >> trump; + string s1, s2; + cin >> s1 >> s2; + if (s1[1] == s2[1]) { + int r1 = -1; + int r2 = -1; + string t1 = ""; + string t2 = ""; + t1 = t1 + s1[0]; + t2 = t2 + s2[0]; + for (int i = 0; i < 9; i++) { + if (card[i] == t1) { r1 = i; } + if (card[i] == t2) { r2 = i; } + } + if (r1 > r2) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } else { + if (s1[1] == trump) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + return 0; +} +int main() { + int n, x; + cin >> n; + x = 2 * n - (n / 2); + cout << x << endl; + return 0; +} +const int maxn = 3e5 + 5; +int a[50] = {}; +int main() { + string s; + int k; + cin >> s >> k; + for (int i = 0; i < s.length(); i++) a[s[i] - 'a']++; + int sum = 0, cnt = 0; + for (int i = 0; i < 30; i++) { + if (a[i] > 0) cnt++; + sum += a[i]; + } + if (sum < k) return puts("impossible"), 0; + if (cnt >= k) return puts("0"), 0; + cout << k - cnt << endl; +} +int main() { + int d, a, b, c = 1; + cin >> a; + for (int count = 1; count <= a; ++count) { + int b = a / count; + if (b >= count) { + if (!(a % count)) { d = max(count, c); } + } + } + cout << d << " " << a / d << endl; + return 0; +} +const int INF = 0x3f3f3f3f; +int main() { + int i, j, k; + int n, m, t, z; + cin >> n; + { + k = 1; + for (i = 1; i <= n / 2; i++) { + for (j = 1; j <= (n - k) / 2; j++) cout << '*'; + for (t = j; t < j + k; t++) cout << 'D'; + for (j = t; j <= n; j++) cout << '*'; + cout << endl; + if (k < n) k += 2; + } + for (i = 1; i <= n; i++) cout << 'D'; + cout << endl; + k = n - 2; + for (i = 1; i <= n / 2; i++) { + for (j = 1; j <= (n - k) / 2; j++) cout << '*'; + for (t = j; t < j + k; t++) cout << 'D'; + for (j = t; j <= n; j++) cout << '*'; + cout << endl; + k -= 2; + } + } +} +int main() { + long n, S; + cin >> n >> S; + int coins = 0; + coins += S / n; + int rem = S % n; + if (rem == 0) + cout << coins << endl; + else + cout << ++coins << endl; +} +const int N = 1e5 + 10; +string second; +set myset; +int main() { + cin >> second; + int n = second.size(); + second += second; + for (int i = 0; i < n; i++) { + string t = ""; + for (int l = 0; l < n; l++) { t += (second[i + l]); } + myset.insert(t); + } + cout << myset.size() << '\n'; + return 0; +} +int main() { + string a; + cin >> a; + for (int i = 0; i < a.length() - 1; i++) + while (a.find(a[i], i + 1) != string::npos) a.erase(a.find(a[i], i + 1), 1); + cout << (a.length() % 2 == 0 ? "CHAT WITH HER!" : "IGNORE HIM!") << endl; + ; + return 0; +} +int main() { + string str; + int freq[26]; + for (int i = 0; i < 26; i++) freq[i] = 0; + cin >> str; + for (int i = 0; i < str.size(); i++) ++freq[str[i] - 'a']; + int sum = 0; + for (int i = 0; i < 26; i++) { + if (freq[i] > 0) sum++; + } + if (sum % 2 == 0) + cout << "CHAT WITH HER!" << endl; + else + cout << "IGNORE HIM!" << endl; + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + if (max(x, y) >= m) { + cout << 0 << '\n'; + return 0; + } + long long d = ((x + y) - min(x, y)); + if (d <= 0) { + cout << -1 << '\n'; + return 0; + } + long long X = -min(x, y) / d; + long long times = X; + if (x < y) + x += X * d; + else + y += X * d; + while (x < m && y < m) { + ++times; + long long s = x + y; + if (x < y) + x = s; + else + y = s; + } + cout << times << '\n'; +} +int main() { + int q; + cin >> q; + int n[q]; + for (int i = 0; i < q; i++) { + cin >> n[i]; + char s[n[i]]; + cin >> s; + if (n[i] >= 3) { + cout << "YES" << endl; + cout << 2 << endl; + cout << s[0] << " "; + for (int j = 1; j < n[i]; j++) { cout << s[j]; } + cout << endl; + } + if (n[i] == 2) { + if (s[1] > s[0]) { + cout << "YES" << endl; + cout << 2 << endl; + cout << s[0] << " " << s[1] << endl; + } else { + cout << "NO" << endl; + } + } + } +} +int main() { + string s; + int n; + int n0; + int n1; + n0 = 0; + n1 = 0; + cin >> n; + cin >> s; + for (int i = 0; i < n; i++) { + if (s[i] == '0') + n0++; + else + n1++; + } + cout << abs(n0 - n1) << endl; + return 0; +} +const int N = 100100; +int a[200]; +int b[200]; +string s; +string need = "Bulbasaur"; +int main() { + cin >> s; + for (int i = 0; i < s.size(); i++) { a[s[i]]++; } + for (int i = 0; i < need.size(); i++) { b[need[i]]++; } + int ans = 1e9; + for (int i = 0; i < 200; i++) { + if (b[i]) { ans = min(ans, a[i] / b[i]); } + } + cout << ans << "\n"; +} +const int maxn = 1e7 + 10; +int a[maxn]; +int n; +int mini = 1e9 + 10; +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < mini) mini = a[i]; + } + vector vec; + for (int i = 0; i < n; i++) { + if (mini == a[i]) { vec.push_back(i); } + } + mini = n; + for (int i = 0; i < vec.size() - 1; i++) { mini = min(mini, vec[i + 1] - vec[i]); } + cout << mini << endl; + return 0; +} +int main() { + int t, a, b; + cin >> t; + while (t--) { + cin >> a >> b; + int cnt = 0; + while (a > 0 && b > 0) { + if (a > b) { swap(a, b); } + cnt += b / a; + b = b % a; + } + cout << cnt << endl; + } + return 0; +} +int a[105]; +int main() { + int m; + while (cin >> m) { + for (int i = 0; i < m; i++) cin >> a[i]; + int sum = 1; + int num = 0; + while (sum) { + sum = 0; + int max = -1; + int k = 1; + for (int i = 1; i < m; i++) { + if (a[i] > max) { + max = a[i]; + k = i; + } + } + if (max >= a[0]) { + a[k]--; + a[0]++; + num++; + sum = 1; + } else + sum = 0; + } + cout << num << endl; + } + return 0; +} +int main() { + int n, t; + cin >> n; + if (n == 2) + cout << "NO" << endl; + else { + vector v; + for (int i = 0; i < n; i++) { + cin >> t; + v.push_back(t); + } + for (int i = 0; i < n; i++) { + if (i == v[v[v[i] - 1] - 1] - 1) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + } +} +const int maxn = 3e5 + 10; +long long sum[maxn]; +long long solve(long long a, long long b, long long c, long long l) { + if (a < b + c) return (long long)0; + long long ans = min(a - b - c, l); + return (ans + 1) * (ans + 2) / 2; +} +int main() { + long long a, b, c, l; + while (cin >> a >> b >> c >> l) { + sum[0] = 1; + for (long long i = 1; i <= l; i++) sum[i] = (i + 1) * (i + 2) / 2 + sum[i - 1]; + long long ans = sum[l]; + for (long long i = 0; i <= l; i++) { + ans -= solve(a + i, b, c, l - i); + ans -= solve(b + i, a, c, l - i); + ans -= solve(c + i, a, b, l - i); + } + cout << ans << endl; + } + return 0; +} +int main() { + int n, x, i, j; + long long sum = 0, ans = 0; + char c; + cin >> n >> x; + sum = x; + for (i = 0; i < n; i++) { + cin >> c >> j; + if (c == '-') { + if (sum < j) + ans++; + else + sum -= j; + } else { + sum += j; + } + } + cout << sum << " " << ans << endl; + return 0; +} +string intToString(int n) { + string s; + while (n > 0) { + int digit = n % 10; + n /= 10; + char ch = digit + '0'; + s = ch + s; + } + return s; +} +int main() { + int n; + cin >> n; + int i; + string a[n]; + for (i = 0; i < n; i++) cin >> a[i]; + string t[n]; + for (i = 0; i < n; i++) { + if (a[i].size() > 10) { + int j = i; + t[j] += a[i][0] + intToString(a[i].size() - 2) + a[i][a[i].size() - 1]; + } else { + int j = i; + t[j] = a[i]; + } + } + for (int k = 0; k < n; k++) cout << t[k] << endl; + return 0; +} +int main() { + int n, x, p, temp = INT_MAX; + long sum = 0; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> x >> p; + if (p < temp) temp = p; + sum += temp * x; + } + cout << sum << endl; +} +int main() { + string s1, s2; + string r1, r2; + cin >> s1 >> s2; + r1 = r1.insert(0, s2.length(), '0') + s1; + r2 = r2.insert(0, s1.length(), '0') + s2; + if (r1 == r2) + cout << "=" << endl; + else if (r1 > r2) + cout << ">" << endl; + else + cout << "<" << endl; +} +int number[5]; +int cw, ccw; +int main() { + char q = '>'; + int u = q; + number[u] = 1; + char r = 'v'; + int v = r; + number[v] = 2; + char s = '<'; + int w = s; + number[w] = 3; + char t = '^'; + int x = t; + number[x] = 4; + char a, b; + cin >> a >> b; + int p; + cin >> p; + p %= 4; + int oo = a; + int pp = b; + int y = number[oo] + p; + if (y > 4) { y -= 4; } + int z = number[oo] - p; + if (z <= 0) { z += 4; } + if (z == number[pp]) { ccw = 1; } + if (y == number[pp]) { cw = 1; } + int total = cw + ccw; + if (cw == 1 && total == 1) { + cout << "cw" << endl; + } else if (ccw == 1 && total == 1) { + cout << "ccw" << endl; + } else { + cout << "undefined" << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int arr[n + 3], idx1 = 0, idx2 = n + 1, cnt = 0, f = 0; + for (int i = 2; i <= n + 1; i++) { + cin >> arr[i]; + if (arr[i] == 1 && f == 0) { + idx1 = i; + f = 1; + } + } + for (int i = n + 1; i >= 2; i--) { + if (arr[i] == 1) { + idx2 = i; + break; + } + } + for (int i = idx1; i <= idx2; i++) { + if (arr[i] == 1) { + cnt++; + } else if (arr[i] == 0) { + if (arr[i - 1] != 0 && arr[i + 1] != 0) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +int main() { + int n, a; + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == 1) { + cout << "HARD" << endl; + return 0; + } + } + cout << "EASY" << endl; + return 0; +} +int main() { + string dna; + int identical = 0, ncl = 0; + cin >> dna; + for (int i = 0; i < int(dna.length()); i++) { + if (i > 0 && dna[i] != dna[i - 1]) { + if (!(identical & 1)) ncl++; + identical = 0; + } + identical++; + } + if (!(identical & 1)) ncl++; + cout << ncl << endl; + return 0; +} +int main() { + const int n = 3; + long long x, y, z, k; + cin >> x >> y >> z >> k; + vector dim(n); + dim[0] = x; + dim[1] = y; + dim[2] = z; + sort(dim.begin(), dim.end()); + long long a, b, c; + a = k / 3; + if (a > dim[0] - 1) { a = dim[0] - 1; } + b = (k - a) / 2; + if (b > dim[1] - 1) b = dim[1] - 1; + c = (k - a - b) / 1; + if (c > dim[2] - 1) c = dim[2] - 1; + long long output = (1LL + a) * (1LL + b) * (1LL + c); + cout << output << "\n"; + return 0; +} +int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; +int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; +void fast() {} +int main() { + fast(); + string s, t; + cin >> s >> t; + cout << (s == t ? -1 : (int)max(s.size(), t.size())) << "\n"; +} +int n, k; +int a[100005]; +long fj(long n) { + int c = 1; + for (int i = 2; i <= n; i++) { + while (n % i == 0) { + a[c++] = i; + n /= i; + } + } + return c - 1; +} +int main() { + while (cin >> n >> k) { + memset(a, 0, sizeof(a)); + long len = fj(n); + long num = 1; + if (len < k) { + cout << -1 << endl; + continue; + } + for (int i = k; i <= len; ++i) { num *= a[i]; } + for (int i = 1; i < k; ++i) { cout << a[i] << ' '; } + cout << num << endl; + } +} +int main() { + string number1, number2; + cin >> number1 >> number2; + if (number1 == number2) { + cout << number1 << endl; + } else { + cout << 1 << endl; + } +} +int main() { + string s, t; + cin >> s >> t; + int n; + cin >> n; + cout << s << " " << t << endl; + string x, y; + while (n--) { + cin >> x >> y; + if (x == s) { + s = y; + } else if (x == t) { + t = y; + } + cout << s << " " << t << endl; + } +} +int main() { + int n, i, j, s = 0, max = 0, a[105], b[105]; + cin >> n; + for (i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] == 0) s++; + b[i] = s; + } + for (i = 0; i < n; i++) { + if (a[i] == 0) + if (2 * b[i] + n - 1 - i - s > max) max = 2 * b[i] + n - 1 - i - s; + if (a[i] == 1) + if (2 * b[i] + n - i - s > max) max = 2 * b[i] + n - i - s; + } + cout << max << endl; + return 0; +} +string x; +int s; +int main() { + cin >> x; + if (x[0] - 'a' > 'z' - x[0] + 1) + s += 'z' - x[0] + 1; + else + s += x[0] - 'a'; + for (int i = 0; i < x.length() - 1; i++) { + int a = static_cast(x[i]) - 97; + int b = static_cast(x[i + 1]) - 97; + int l = a > b ? a : b; + int m = a < b ? a : b; + int j = l - m; + int h = 26 - l + m; + if (j < h) + s += j; + else + s += h; + } + cout << s << endl; + return 0; +} +int main() { + long long int h, w, k; + cin >> h >> w >> k; + long long int g = 0; + while (k > 0) { + g += h * 2 + (w - 2) * 2; + k--; + h -= 4; + w -= 4; + if (h <= 0) { break; } + if (w <= 0) { break; } + } + cout << g << '\n'; + return 0; +} +int main() { + char str[100]; + int a, b, i, j; + cin >> a; + getchar(); + for (i = 0; i < a; i++) { + gets(str); + b = strlen(str); + if (b > 10) { + cout << str[0] << b - 2 << str[b - 1] << endl; + } else + cout << str << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int res = 1; + for (int i = 1; i <= n - 1; i++) { + res *= 3; + res %= 1000003; + } + cout << res << endl; +} +int main() { + long long t, s, q; + cin >> t >> s >> q; + long long ans = 0; + while (s < t) { + s *= q; + ans++; + } + cout << ans << endl; + return 0; +} +int main() { + int n, i, a, b, c1 = 0, c2 = 0; + cin >> n; + for (i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) c1++; + if (a < b) c2++; + } + if (c1 > c2) cout << "Mishka" << endl; + if (c2 > c1) cout << "Chris" << endl; + if (c1 == c2) cout << "Friendship is magic!^^" << endl; +} +int main() { + size_t n; + cin >> n; + vector year(n); + for (size_t i = 0; i < n; ++i) { cin >> year[i]; } + sort(year.begin(), year.end()); + cout << year[(n - 1) / 2] << endl; + return 0; +} +int main() { + int t; + cin >> t; + char s[100][100]; + for (int i = 0; i < t; i++) { + for (int j = 0; j < t; j++) { cin >> s[i][j]; } + } + for (int i = 0; i < t; i++) { + int c = 0; + for (int j = 0; j < t; j++) { + if (s[i + 1][j] == 'o') c++; + if (s[i - 1][j] == 'o') c++; + if (s[j - 1][i] == 'o') c++; + if (s[j + 1][i] == 'o') c++; + if (c % 2 == 1) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; +} +const int INF = 0x3f3f3f3f; +int main() { + long long i, j, k = 1; + long long n, m = 1; + cin >> n; + if (!n || n == 1) { + cout << 1 << endl; + return 0; + } + for (i = 2; i <= n; i++) m *= 3, m %= 1000000 + 3; + cout << m << endl; + return 0; +} +map M; +int main() { + long long q, wh, u, v, w; + cin >> q; + while (q--) { + cin >> wh; + if (wh == 1) { + cin >> v >> u >> w; + while (v != u) { + if (v > u) + M[v] += w, v /= 2; + else + M[u] += w, u /= 2; + } + } else { + cin >> u >> v; + long long ans = 0; + while (v != u) { + if (v > u) + ans += M[v], v /= 2; + else + ans += M[u], u /= 2; + } + cout << ans << endl; + } + } +} +int main() { + int n, m, min, max; + cin >> n >> m >> min >> max; + int t; + vector record; + for (int i = 0; i < m; i++) { + cin >> t; + record.push_back(t); + } + sort(record.begin(), record.end()); + if (record[0] < min) { + cout << "Incorrect\n"; + return 0; + } + if (record[m - 1] > max) { + cout << "Incorrect\n"; + return 0; + } + if (record[0] == min && record[m - 1] == max) { + cout << "Correct\n"; + return 0; + } + if (record[0] == min && n - m >= 1) { + cout << "Correct\n"; + return 0; + } + if (record[m - 1] == max && n - m >= 1) { + cout << "Correct\n"; + return 0; + } + if (n - m >= 2) { + cout << "Correct\n"; + return 0; + } + cout << "Incorrect\n"; + return 0; +} +int main() { + int n, i, j, k; + int x[101], y[101]; + while (cin >> n) { + for (i = 0; i <= 100; i++) { x[i] = y[i] = 0; } + for (i = 0; i < n; i++) { + cin >> j >> k; + x[j]++; + y[k]++; + } + j = k = 0; + for (i = 0; i <= 100; i++) { + if (x[i]) j++; + if (y[i]) k++; + } + cout << (j < k ? j : k); + cout << endl; + } + return 0; +} +int main() { + double a; + double l, p, q; + cin >> l >> p >> q; + a = l * p / (p + q); + cout << a << endl; + return 0; +} +int a[101], b[101]; +int main() { + int n, k; + cin >> n >> k; + int i, j; + int t = 0, ans = 0; + for (i = 0; i < n; i++) { cin >> a[i]; } + for (i = 0; i < n; i++) { + t += a[i]; + b[i % k] += a[i]; + } + for (i = 0; i < k; i++) { ans = max(ans, abs(t - b[i])); } + cout << ans << endl; + return 0; +} +int n; +int main() { + while (cin >> n) { + for (int i = 1; i <= n; i++) { + if (i % 2 != 0) { + cout << "I hate "; + } else { + cout << "I love "; + } + if (i == n) { + cout << "it" << endl; + } else { + cout << "that "; + } + } + } + return 0; +} +int main() { + int i, m, n, j, k, a[100001], cnt = 0, tmp = 0, f[100001], t[100001]; + cin >> n >> k; + for (i = 0; i < n; i++) { cin >> f[i] >> t[i]; } + for (i = 0; i < n; i++) { + if (t[i] < k) + a[i] = f[i]; + else { + a[i] = (f[i] - (t[i] - k)); + } + } + int mx = a[0]; + for (i = 0; i < n; i++) { + if (a[i] > mx) mx = a[i]; + } + cout << mx << endl; + return 0; +} +int main() { + string *str, var; + int n; + cin >> var >> n; + str = new string[n]; + for (int i = 0; i < n; i++) cin >> str[i]; + sort(str, str + n); + for (int i = 0; i < n; i++) { + if (str[i].find(var) == 0) { + cout << str[i] << endl; + return 0; + } + } + cout << var << endl; + return 0; +} +char _; +const int INF = 0x3f3f3f3f; +int n, m, ans; +int main() { + cin >> n; + for (int i = 0, x, y; i < n; i++) { + cin >> x >> y; + ans = 0; + while (x != 0 && y != 0) { + if (y > x) swap(x, y); + ans += x / y; + x = x % y; + } + cout << ans << '\n'; + } +} +void swap(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +int main() { + long long int n, h, a, b, q; + cin >> n >> h >> a >> b >> q; + long long int sum = 0; + while (q) { + sum = 0; + long long int t1, f1, t2, f2; + cin >> t1 >> f1 >> t2 >> f2; + if (t1 == t2) { + cout << abs(f1 - f2) << endl; + } else { + if (f1 > b) { + sum = sum + f1 - b; + f1 = b; + } else if (f1 <= b && f1 >= a) { + } else { + sum = sum + a - f1; + f1 = a; + } + sum = sum + abs(t2 - t1); + sum = sum + abs(f1 - f2); + cout << sum << endl; + ; + } + q--; + } +} +string str; +int main() { + cin >> str; + int s = 0, c = str.size(); + for (int i = 0; i < str.size(); i++) { s += str[i] >= 'a'; } + c -= s; + if (c > s) { + for (int i = 0; i < str.size(); i++) { + if (str[i] >= 'a') str[i] = toupper(str[i]); + } + } else + for (int i = 0; i < str.size(); i++) { + if (str[i] < 'a') str[i] = tolower(str[i]); + } + cout << str << endl; + return 0; +} +int main() { + float l, p, q; + cin >> l >> p >> q; + cout << l / (p + q) * p << endl; + return 0; +} +int main() { + set s; + int x, y; + cin >> x >> y; + for (int i = 0; i < x; i++) { + int a; + cin >> a; + for (int j = 0; j < a; j++) { + int m; + cin >> m; + s.insert(m); + } + } + int l; + l = s.size(); + if (l == y) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + return 0; +} +int main() { + int k, i, j; + string s; + int c[26] = {0}; + cin >> k >> s; + if (s.size() % k != 0) { + cout << -1 << endl; + return 0; + } + for (i = 0; i < s.size(); i++) { c[s[i] - 'a']++; } + for (i = 0; i < 26; i++) { + if (c[i] % k != 0) { + cout << -1 << endl; + return 0; + } + } + string result; + for (i = 0; i < 26; i++) { + for (j = 0; j < c[i] / k; j++) { result = result + char('a' + i); } + } + for (i = 0; i < k; i++) { cout << result; } + cout << endl; + return 0; +} +int main() { + int a, b, c; + cin >> a >> b >> c; + int x = sqrt((a * b) / c); + int y = sqrt((a * c) / b); + int z = sqrt((b * c) / a); + cout << 4 * (x + y + z) << endl; + return 0; +} +int main() { + int n, max = -1, min = 1000, index = -1; + cin >> n; + int a[n]; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (i < 2) continue; + if (a[i] - a[i - 2] < min) { + min = a[i] - a[i - 2]; + index = i - 1; + } + } + for (int i = index; i < n - 1; i++) { a[i] = a[i + 1]; } + for (int i = 1; i < n - 1; i++) { + if (max < a[i] - a[i - 1]) { max = a[i] - a[i - 1]; } + } + cout << max << endl; + return 0; +} +const long long arr = 1000000; +vector a; +vector b; +long long func(long long l, long long r) { + long long t = 0; + for (int i = l; i <= r; i++) t |= a[i]; + long long t2 = 0; + for (int i = l; i <= r; i++) t2 |= b[i]; + return t + t2; +} +int main() { + long long n; + cin >> n; + a.resize(n); + b.resize(n); + for (int i = 0; i < n; i++) cin >> a[i]; + for (int i = 0; i < n; i++) cin >> b[i]; + long long ans = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) ans = max(ans, func(i, j)); + cout << ans << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << ((n % 2 != 0) ? "contest" : "home") << endl; +} +int main() { + char c, s = 'a'; + int ans = 0; + while (cin >> c) { + ans += min(abs(c - s), 26 - abs(c - s)); + s = c; + } + cout << ans << endl; +} +int main() { + int n; + cin >> n; + int a; + int flag = 0; + for (int i = 0; i < n; i++) { + cin >> a; + if (a == 1) { flag = 1; } + } + if (flag) + cout << "-1" << endl; + else + cout << 1 << endl; +} +const long long mod = 1e9 + 7; +long long POWER[65]; +long long power(long long a, long long b) { + long long ret = 1; + while (b) { + if (b & 1) ret *= a; + a *= a; + if (ret >= mod) ret %= mod; + if (a >= mod) a %= mod; + b >>= 1; + } + return ret; +} +long long inv(long long x) { + return power(x, mod - 2); +} +void precompute() { + POWER[0] = 1; + for (long long i = 1; i < 63; i++) POWER[i] = POWER[i - 1] << 1LL; +} +vector v; +int main() { +std: + long long m, mi = mod; + cin >> m; + for (long long i = 0; i < m; i++) { + long long x; + cin >> x; + mi = min(mi, x); + } + long long n; + cin >> n; + for (long long i = 0; i < n; i++) { + long long x; + cin >> x; + v.push_back(x); + } + sort(v.begin(), v.end()); + reverse(v.begin(), v.end()); + long long ret = 0, num = 0; + for (long long i = 0; i < ((long long)v.size()); i++) { + if (num == mi) { + i += 1; + num = 0; + continue; + } + ret += v[i]; + num++; + } + cout << ret << '\n'; +} +int y[30]; +int vis[30]; +int main() { + int n; + cin >> n; + string a; + cin >> a; + { + int z = 0; + for (int i = 0; i < a.size(); i++) { + if (vis[a[i] - 'a'] == 0) { + y[z] = i; + z++; + vis[a[i] - 'a'] = 1; + } + } + if (z < n) + cout << "NO" << endl; + else { + cout << "YES" << endl; + sort(y, y + z); + for (int i = 0; i < n; i++) { + if (i + 1 == n) { + for (int j = y[i]; j < a.size(); j++) cout << a[j]; + } else { + for (int j = y[i]; j < y[i + 1]; j++) cout << a[j]; + } + cout << endl; + } + } + } + return 0; +} +string s1, s2, s3; +int main() { + cin >> s1 >> s2 >> s3; + if (s2 == "rock" && s1 == "scissors" && s1 == s3) + cout << "M" << endl; + else if (s1 == "rock" && s2 == "scissors" && s2 == s3) + cout << "F" << endl; + else if (s3 == "rock" && s1 == "scissors" && s2 == s1) + cout << "S" << endl; + else if (s1 == "scissors" && s2 == "paper" && s2 == s3) + cout << "F" << endl; + else if (s2 == "scissors" && s1 == "paper" && s1 == s3) + cout << "M" << endl; + else if (s3 == "scissors" && s2 == "paper" && s2 == s1) + cout << "S" << endl; + else if (s1 == "paper" && s2 == "rock" && s2 == s3) + cout << "F" << endl; + else if (s2 == "paper" && s1 == "rock" && s1 == s3) + cout << "M" << endl; + else if (s3 == "paper" && s2 == "rock" && s2 == s1) + cout << "S" << endl; + else + cout << "?" << endl; + return 0; +} +int main() { + int l, x; + string s; + cin >> s; + l = s.size(); + x = 26 * (l + 1) - l; + cout << x << endl; + return 0; +} +int n; +char arr[300][300]; +int main() { + cin >> n; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) cin >> arr[i][j]; + if (arr[0][0] == arr[1][0]) { + cout << "NO" << endl; + return 0; + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j || j + i == n - 1) { + if (arr[i][j] != arr[0][0]) { + cout << "NO" << endl; + return 0; + } + } else { + if (arr[i][j] != arr[1][0]) { + cout << "NO" << endl; + return 0; + } + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + long long x, y, m; + cin >> x >> y >> m; + long long t, cnt = 0; + t = max(x, y); + if (t >= m) + cout << "0" << endl; + else { + long long z = x + y; + if (z <= min(x, y)) + cout << "-1" << endl; + else { + long long q = min(x, y); + if (q < 0) { + if (x > y) swap(x, y); + cnt += abs(x) / abs(y); + x = x + cnt * y; + t = max(x, y); + z = x + y; + } + while (t < m) { + if (x > y) swap(x, y); + x = z; + z = x + y; + t = max(x, y); + cnt++; + } + cout << cnt << endl; + } + } + return 0; +} +int Get() { + char c; + while (c = getchar(), (c < '0' || c > '9') && (c != '-')) + ; + bool Flag = (c == '-'); + if (Flag) c = getchar(); + int X = 0; + while (c >= '0' && c <= '9') { + X = X * 10 + c - 48; + c = getchar(); + } + return Flag ? -X : X; +} +void Output(int X) { + if (X < 0) { + putchar('-'); + X = -X; + } + int Len = 0, Data[10]; + while (X) { + Data[Len++] = X % 10; + X /= 10; + } + if (!Len) Data[Len++] = 0; + while (Len--) putchar(Data[Len] + 48); + putchar('\n'); +} +int main() { + int N = Get(); + long long K = Get(), Sum = 0; + int Top = 0, Total = N, Number = 0; + for (int i = 0; i < N; i++) { + long long X = Get(); + if (Sum - X * Number * (Total - Number - 1) < K) { + Output(i + 1); + Total--; + } else { + Sum += Number * X; + Number++; + } + } + return 0; +} +int main() { + int n, m; + cin >> n >> m; + char arr[50][50]; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) cin >> arr[i][j]; + int cnt = 0; + set s; + char ar[] = {'f', 'a', 'c', 'e'}; + bool is; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < m - 1; j++) { + is = true; + s.clear(); + s.insert(arr[i][j]); + s.insert(arr[i][j + 1]); + s.insert(arr[i + 1][j]); + s.insert(arr[i + 1][j + 1]); + for (int p = 0; p < 4; p++) + if (!s.count(ar[p])) is = false; + if (is) cnt++; + } + } + cout << cnt << endl; + return 0; +} +int main() { + long int n, r; + cin >> n; + r = n / 5; + if (n == (r * 5)) + cout << r << endl; + else + cout << (r + 1) << endl; + return 0; +} +int main() { + int n; + cin >> n; + int a = n / 7; + while (a != -1) { + if ((n - a * 7) % 4 == 0) { + for (int i = 0; i < (n - a * 7) / 4; i++) cout << "4"; + for (int i = 0; i < a; i++) cout << "7"; + cout << endl; + return 0; + } + a--; + } + cout << "-1" << endl; +} +int main() { + long long arr[3][3], l[3][3]; + memset(l, 0, sizeof(l)); + for (long long i = 0; i < 3; i++) { + for (long long j = 0; j < 3; j++) { cin >> arr[i][j]; } + } + for (long long i = 0; i < 3; i++) { + for (long long j = 0; j < 3; j++) { + if (arr[i][j] % 2 == 1) { + if (i + 1 < 3) l[i + 1][j] = !l[i + 1][j]; + if (i - 1 >= 0) l[i - 1][j] = !l[i - 1][j]; + if (j + 1 < 3) l[i][j + 1] = !l[i][j + 1]; + if (j - 1 >= 0) l[i][j - 1] = !l[i][j - 1]; + l[i][j] = !l[i][j]; + } + } + } + for (long long i = 0; i < 3; i++) { + for (long long j = 0; j < 3; j++) cout << !l[i][j]; + cout << endl; + } +} +int main() { + int x1, x2, x3; + cin >> x1 >> x2 >> x3; + int sum = sqrt((x1 * x3) / x2) + sqrt((x2 * x1) / x3) + sqrt((x3 * x2) / x1); + sum = sum * 4; + cout << sum << endl; + return 0; +} +int main() { + int n, k, x; + long long sum = 0; + cin >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> x; + sum += (x + k - 1) / k; + } + cout << (sum + 1) / 2 << endl; + return 0; +} +int main() { + long int N, K, l, r, numbers_total = 0; + cin >> N >> K; + for (long long int i = 0; i < N; i++) { + cin >> l >> r; + numbers_total += (r - l) + 1; + } + if (numbers_total % K != 0) + cout << K - numbers_total % K << endl; + else + cout << 0 << endl; +} +int main() { + string s; + cin >> s; + int c1 = 0, c2 = 0; + if (s[0] == '0') + c1 += 2; + else if (s[0] == '1') + c1 += 7; + else if (s[0] == '2') + c1 += 2; + else if (s[0] == '3') + c1 += 3; + else if (s[0] == '4') + c1 += 3; + else if (s[0] == '5') + c1 += 4; + else if (s[0] == '6') + c1 += 2; + else if (s[0] == '7') + c1 += 5; + else if (s[0] == '8') + c1 += 1; + else if (s[0] == '9') + c1 += 2; + if (s[1] == '0') + c2 += 2; + else if (s[1] == '1') + c2 += 7; + else if (s[1] == '2') + c2 += 2; + else if (s[1] == '3') + c2 += 3; + else if (s[1] == '4') + c2 += 3; + else if (s[1] == '5') + c2 += 4; + else if (s[1] == '6') + c2 += 2; + else if (s[1] == '7') + c2 += 5; + else if (s[1] == '8') + c2 += 1; + else if (s[1] == '9') + c2 += 2; + cout << c1 * c2 << endl; + return 0; +} +int main() { + int n; + vector color(6); + vector inf(6); + vector q(6); + cin >> n; + for (int i = 0; i < n; i++) cin >> q[i]; + color[0] = "purple"; + inf[0] = "Power"; + color[1] = "green"; + inf[1] = "Time"; + color[2] = "blue"; + inf[2] = "Space"; + color[3] = "orange"; + inf[3] = "Soul"; + color[4] = "red"; + inf[4] = "Reality"; + color[5] = "yellow"; + inf[5] = "Mind"; + cout << 6 - n << endl; + for (int i = 0; i < n; i++) { + for (int j = 0; j < 6; j++) { + if (q[i] == color[j]) { + color[j] = "aa"; + break; + } + } + } + for (int i = 0; i < 6; i++) + if (color[i] != "aa") cout << inf[i] << endl; +} +int main() { + long long int n; + cin >> n; + cout << "25" << endl; +} +int a; +int i = 0; +int main() { + int result[3]; + while (i < 3) { + cin >> a; + result[i] = a; + i += 1; + }; + sort(result, result + 3); + i = 0; + int c = 0; + while (i < 2) { + c += result[i + 1] - result[i]; + i += 1; + }; + cout << c << endl; + return 0; +} +int a[365]; +int main() { + int n, k, h, c = 0, gift = 0, f; + cin >> n >> k >> h; + for (int j = 1; j <= h; j++) { + cin >> f; + a[f] = 1; + } + for (int i = 1; i <= n; i++) { + if (a[i] == 0) + c++; + else + c = 0; + if (c == k) { + a[i] = 1; + c = 0; + } + if (a[i] == 1) gift++; + } + cout << gift << endl; + return 0; +} +int main() { + int n; + cin >> n; + int k = n / 2; + for (int i = 0; i < k; i++) { + for (int j = k; j > i; j--) { cout << "*"; } + for (int j = 1; j <= n - 2 * (k - i); j++) { cout << "D"; } + for (int j = k; j > i; j--) { cout << "*"; } + cout << endl; + } + for (int i = 0; i < n; i++) { cout << "D"; } + cout << endl; + for (int i = k - 1; i >= 0; i--) { + for (int j = k; j > i; j--) { cout << "*"; } + for (int j = 1; j <= n - 2 * (k - i); j++) { cout << "D"; } + for (int j = k; j > i; j--) { cout << "*"; } + cout << endl; + } +} +int main() { + set s; + int n, m; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m; + if (m) { s.insert(m); } + } + cout << s.size() << endl; + ; + return 0; +} +int main() { + int len, n; + cin >> len >> n; + char a[105]; + cin >> a; + for (int i = 0; i < n; i++) { + int l, r; + char s, e; + cin >> l >> r >> s >> e; + for (int i = l - 1; i < r; i++) { + if (a[i] == s) a[i] = e; + } + } + cout << a << endl; +} +int main() { + int i, j; + int flag; + char ss[100]; + string s; + cin.getline(ss, 100); + s = ss; + int length = s.length(); + for (i = 1; i <= length; i++) { + if (length % i == 0) { + flag = 1; + for (j = i; j < length; j++) { + if (s[j] != s[j % i]) { + flag = 0; + break; + } + } + if (flag) { + cout << i << endl; + break; + } + } + } + return 0; +} +void solve() { + long long n; + cin >> n; + string s; + cin >> s; + if (n == 1) + cout << "NO" << '\n'; + else { + for (long long i = 1; i < n; i++) { + if (s[i] != s[i - 1]) { + cout << "YES" << '\n'; + cout << s[i - 1] << s[i] << '\n'; + return; + } + } + cout << "NO" << '\n'; + } +} +int main() { + long long TESTS = 1; + while (TESTS--) { solve(); } + return 0; +} +int dx[] = {-1, 0, 1, 0}; +int dy[] = {0, 1, 0, -1}; +int main() { + long long n, m; + cin >> n >> m; + if (m == 0 && n >= 0) { + cout << n << " " << n << endl; + return 0; + } + if (n == 0 && m > 0) { + cout << "Impossible" << endl; + return 0; + } + long long maxsum = m + n - 1; + long long minsum = n + max(m - n, 0LL); + cout << minsum << " " << maxsum << endl; +} +int main() { + int position = 0, ctr = 0; + string s, t; + cin >> s >> t; + for (int i = 0; i < t.size(); i++) + if (t[i] == s[ctr]) ctr++; + cout << ctr + 1 << endl; + return 0; +} +int n, m; +char s[101][101]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { cin >> s[i][j]; } + } + int ans = 0; + for (int i = 1; i <= n; i++) { + bool p = 0; + for (int j = 1; j <= m; j++) { + p = 0; + for (int k = 1; k <= n; k++) { + if (s[i][j] < s[k][j]) { + p = 1; + break; + } + } + if (!p) { + ans++; + break; + } + } + } + cout << ans << endl; + return 0; +} +map mp; +int main() { + for (int i = 0; i < 6; i++) { + int p; + cin >> p; + mp[p]++; + } + if (mp.size() > 3) { + cout << "Alien" << endl; + return 0; + } + if (mp.size() == 3) { + int f = 0; + map::iterator it; + for (it = mp.begin(); it != mp.end(); it++) { + if (it->second == 4) { + f = 1; + break; + } + } + if (f) { + cout << "Bear" << endl; + return 0; + } else { + cout << "Alien" << endl; + return 0; + } + } + if (mp.size() == 2) { + int f = 0; + map::iterator it; + for (it = mp.begin(); it != mp.end(); it++) { + if (it->second == 2) { + f = 1; + break; + } + if (it->second == 3) { + cout << "Alien" << endl; + return 0; + } + } + if (f) { + cout << "Elephant" << endl; + return 0; + } else { + cout << "Bear" << endl; + return 0; + } + } + if (mp.size() == 1) { + cout << "Elephant" << endl; + return 0; + } + return 0; +} +int find(); +int ar[10][10] = {0}; +int n, i, j, m; +int main() { + while (cin >> n) { + for (i = 0; i < n; i++) { + ar[0][i] = 1; + ar[i][0] = 1; + } + for (i = 1; i < n; i++) { + for (j = 1; j < n; j++) { ar[i][j] = ar[i - 1][j] + ar[i][j - 1]; } + } + m = find(); + cout << m << endl; + } + return 0; +} +int find() { + int s = 0; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (s < ar[i][j]) s = ar[i][j]; + } + } + return s; +} +void to_lower(string &str); +void to_upper(string &str); +int main() { + string input; + cin >> input; + int upper = 0; + int lower = 0; + for (int i = 0; i < input.size(); i++) + if (input[i] < 'a') upper++; + lower = input.size() - upper; + if (upper > lower) + to_upper(input); + else + to_lower(input); + cout << input << endl; + return 0; +} +void to_upper(string &str) { + for (int i = 0; i < str.size(); i++) { + if (str[i] >= 'a' && str[i] <= 'z') str[i] -= 32; + } +} +void to_lower(string &str) { + for (int i = 0; i < str.size(); i++) { + if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 32; + } +} +int main() { + string s; + int a = 0, b = 0; + cin >> s; + for (int i = 0; i < s.length(); i++) { + if (s[i] == '-') + b++; + else + a++; + } + if (a == 0 || b % a == 0) + cout << "YES" << endl; + else + cout << "NO" << endl; +} +int main() { + int n; + cin >> n; + int arr[10]; + for (int i = 1; i <= n; i++) cin >> arr[i]; + sort(arr + 1, arr + n + 1); + if (n == 1) + cout << arr[1] << endl; + else if (n == 3) + cout << arr[2] << endl; + else + cout << arr[3] << endl; + return 0; +} +int main() { + long long k, m, i, v; + cin >> k; + m = (k + 1) / 2; + for (i = 1; i <= m; i++) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } + for (i = (m - 1); i >= 1; i--) { + for (v = 1; v <= k; v++) { + if (abs(m - v) >= i) + cout << "*"; + else + cout << "D"; + } + cout << endl; + } +} +int main() { + string b; + long long a, c, d; + cin >> a >> b; + c = 0; + for (int i = b.length() - 1; i >= 0; i--) { c = c * 10 + b[i] - '0'; } + d = a + c; + cout << d << endl; +} +int main() { + long long n, s, i; + cin >> n >> s; + if (s % n != 0) { + cout << s / n + 1 << endl; + } else { + cout << s / n << endl; + } + return 0; +} +int main() { + string a; + cin >> a; + int i = 0; + while (a[i]) { + if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4') + i += 3; + else if (a[i] == '1' && a[i + 1] == '4') + i += 2; + else if (a[i] == '1') + i++; + else + break; + } + if (i == a.length()) + cout << "YES" << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + char s[100]; + cin >> s; + int l, i, j, c = 0; + l = strlen(s); + sort(s, s + l); + for (i = 0; i < l; i++) { + if (s[i] != s[i + 1]) { c++; } + } + if (c % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } +} +long long Pow(long long b, long long p) { + if (p == 0) return 1; + long long z = Pow(b, p / 2); + if (p % 2 == 0) + return z * z; + else + return z * z * b; +} +int main() { + long long k, l; + cin >> k >> l; + long long ans = 1; + while (Pow(k, ans) < l) ans++; + if (Pow(k, ans) == l) + cout << "YES" << endl << ans - 1 << endl; + else + cout << "NO" << endl; + return 0; +} +int main() { + int k, n, w; + int total = 0; + cin >> k >> n >> w; + for (int i = 1; i <= w; i++) { total = k * i + total; } + if (n >= total) + cout << "0" << endl; + else + cout << total - n << endl; + return 0; +} +const long long mod = 1000000007; +long long k; +long long c[1010]; +long long tol; +long long cal[1010][1010]; +void get() { + cal[1][1] = 1; + for (int i = 2; i <= tol + 1; i++) { + for (int j = 1; j <= i; j++) { + if (j == 1) { + cal[i][j] = 1; + } else if (j == i) { + cal[i][j] = 1; + } else { + cal[i][j] = cal[i - 1][j - 1] + cal[i - 1][j]; + cal[i][j] %= mod; + } + } + } +} +int main() { + cin >> k; + tol = 0; + for (int i = 1; i <= k; i++) { + cin >> c[i]; + tol += c[i]; + } + get(); + long long ans = 1; + for (int i = k; i >= 1; i--) { + ans = (ans * cal[tol][c[i]]) % mod; + tol -= c[i]; + } + cout << ans << endl; + return 0; +} +int main() { + int n, l, k, c, d, p, nl, np, tml, tsd, slt; + cin >> n >> l >> k >> c >> d >> p >> nl >> np; + tml = (k * l) / nl; + tsd = (c * d); + slt = (p / np); + int mi = min(tml, tsd); + cout << min(mi, slt) / n << endl; + return 0; +} +int main() { + int n, m; + while (cin >> n >> m) { + int c = n < m ? n : m; + if (c % 2 == 0) + cout << "Malvika" << endl; + else + cout << "Akshat" << endl; + } +} +unsigned long long gcd(unsigned long long a, unsigned long long b) { + if (b == 0) return a; + return gcd(b, a % b); +} +unsigned long long lcm(unsigned long long a, unsigned long long b) { + return a * b / gcd(a, b); +} +bool check(unsigned long long n) { + while (n % 3 == 0) { n /= 3; } + while (n % 2 == 0) { n /= 2; } + if (n == 1) return true; + return false; +} +int arr[100005]; +int main() { + unsigned long long n, a, b; + cin >> n; + int say = 0; + for (int i = 1; i <= n; i++) { + cin >> a >> b; + if (a > b) swap(a, b); + while (a != 0 && b != 0) { + say += (b / a); + b %= a; + if (a > b) swap(a, b); + } + cout << say << endl; + say = 0; + } + return 0; +} +int main() { + int n; + cin >> n; + int x; + int chest = 0, biceps = 0, back = 0; + for (int i = 1; i <= n; ++i) { + cin >> x; + if (i % 3 == 1) chest += x; + if (i % 3 == 2) biceps += x; + if (i % 3 == 0) back += x; + } + int most = max(chest, max(biceps, back)); + if (most == chest) + puts("chest"); + else if (most == biceps) + puts("biceps"); + else + puts("back"); +} +int LoL(char r) { + if (r == '6') { + return 1; + } else if (r == '7') { + return 2; + } else if (r == '8') { + return 3; + } else if (r == '9') { + return 4; + } else if (r == 'T') { + return 6; + } else if (r == 'J') { + return 7; + } else if (r == 'Q') { + return 8; + } else if (r == 'K') { + return 9; + } else if (r == 'A') { + return 10; + } +} +int main() { + char a; + cin >> a; + string s1, s2; + int p, q; + cin >> s1 >> s2; + bool ans; + p = LoL(s1[0]); + q = LoL(s2[0]); + if (s1[1] == a && s2[1] != a) { + ans = true; + } else if (s1[1] != s2[1]) { + ans = false; + } else { + if (p > q) { + ans = true; + } else { + ans = false; + } + } + if (ans == true) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } +} +int main() { + int s, v1, v2, t1, t2, p1, p2; + cin >> s >> v1 >> v2 >> t1 >> t2; + p1 = t1 + t1 + v1 * s; + p2 = t2 + t2 + v2 * s; + if (p1 < p2) { + cout << "First" << endl; + return 0; + } + if (p2 < p1) { + cout << "Second" << endl; + return 0; + } else + cout << "Friendship" << endl; + return 0; +} +int Ceil(int n, int k) { + return (n + k - 1) / k; +} +int main() { + int n, k; + cin >> n >> k; + int ans = Ceil(2 * n, k) + Ceil(5 * n, k) + Ceil(8 * n, k); + cout << ans << '\n'; + return 0; +} +int main() { + int n, cnt = 0; + cin >> n; + int g[n], h[n]; + for (int i = 0; i < n; ++i) { cin >> h[i] >> g[i]; } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (g[j] == h[i]) { cnt++; } + } + } + cout << cnt << endl; + return 0; +} +int q[100000]; +int a[100000]; +bool mycmp(int i, int j) { + return i > j; +} +int main() { + int m; + int mq; + cin >> m; + for (int i = 0; i < m; i++) cin >> q[i]; + mq = q[0]; + for (int i = 0; i < m; i++) mq = min(mq, q[i]); + int n; + cin >> n; + for (int i = 0; i < n; i++) cin >> a[i]; + sort(a, a + n, mycmp); + int ans = 0; + for (int i = 0; i < n; i++) { + if (i % (mq + 2) < mq) ans += a[i]; + } + cout << ans << endl; + return 0; +} +void solve() { + int n; + cin >> n; + string s, s1, s2; + int res = 0; + for (int i = 0; i < n; i++) { + cin >> s; + s1 += s; + } + s2 = s1; + reverse(s2.begin(), s2.end()); + if (s2 != s1) { + cout << "NO" << endl; + } else + cout << "YES" << endl; +} +int main() { + int t; + t = 1; + while (t--) { solve(); } + return 0; +} +const int MAXN = 1005; +int n, m, ans, a[MAXN], c[MAXN]; +bool flag[MAXN]; +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> c[i]; + for (int i = 1; i <= m; i++) cin >> a[i]; + int t = 1; + for (int i = 1; i <= n; i++) { + if (c[i] <= a[t]) { + ans++; + t++; + } + } + cout << ans << endl; + return 0; +} +int number(int a[], int i, int d, int n) { + int g = a[i] + d, j; + for (j = i; j < n; j++) { + if (a[j] > g) { break; } + } + j--; + if (j == i) { + return (0); + } else { + return (j - i + 1); + } +} +int main() { + int n, d, g, x = 0, y = 2, r, m = -1; + cin >> n >> d; + int i, a[n], j; + for (i = 0; i < n; i++) { cin >> a[i]; } + sort(a, a + n); + if (n == 1) { + cout << "0" << endl; + } else { + for (i = 0; i < n; i++) { + r = number(a, i, d, n); + if (r > m) { m = r; } + } + if (m == 0) { + cout << (n - 1) << endl; + } else + cout << (n - m) << endl; + } + return (0); +} +int main() { + int y; + cin >> y; + while (true) { + y += 1; + int a = y / 1000; + int b = y / 100 % 10; + int c = y / 10 % 10; + int d = y % 10; + if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } + } + cout << y << endl; + return 0; +} +int main() { + string s; + int i, n, Ans = 0, cnt = 0; + cin >> n; + while (cin >> s) { + cnt = 0; + for (i = 0; i < s.size(); i++) { + if (s[i] >= 65 && s[i] <= 65 + 26) cnt++; + } + Ans = max(Ans, cnt); + } + cout << Ans << endl; + return 0; +} +int n, arr[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777}; +int main() { + cin >> n; + for (int i = 0; i < 10; i++) { + if (!(n % arr[i])) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + return 0; +} +int main() { + int n, ans = 0, cur = 0; + int A[200]; + cin >> n; + for (int i = 0; i < n; i++) cin >> A[i]; + for (int i = 0; i < n; i++) { + cur = 0; + for (int j = i; j < n; j++) { + cur = cur ^ A[j]; + ans = max(ans, cur); + } + } + cout << ans << endl; + return 0; +} +const int N = 1e6 + 5, MAX = 3e7, MOD = 1e9 + 7; +int xx1, yy1, xx2, yy2; +int main() { + cin >> xx1 >> yy1 >> xx2 >> yy2; + cout << max(abs(xx1 - xx2), abs(yy1 - yy2)) << "\n"; +} +int main() { + string a; + cin >> a; + int ans = 0; + int x = 1; + for (int i = 1; i < a.size(); i++) { + if (a[i] == a[i - 1]) + x++; + else { + if (x % 2 == 0) ans++; + x = 1; + } + } + if (x % 2 == 0) ans++; + cout << ans << endl; +} +int main() { + long long int n, k; + cin >> n; + for (long long int i = 1; i <= n; i++) { + if (i == 1) + k = 2; + else + k = i * i * (i + 2) + 1; + cout << k << endl; + } + return 0; +} +int n, k, ans; +int main() { + cin >> n >> k; + k = 240 - k; + for (int i = 1; i <= n + 1 && k >= 0; ++i, ++ans) { k -= 5 * i; } + cout << ans - 1 << endl; + return 0; +} +string str; +int B, u, l, b, a, s, r; +int main() { + cin >> str; + for (int i = 0; i < str.length(); i++) { + if (str[i] == 'B') B++; + if (str[i] == 'u') u++; + if (str[i] == 'l') l++; + if (str[i] == 'b') b++; + if (str[i] == 'a') a++; + if (str[i] == 's') s++; + if (str[i] == 'r') r++; + } + cout << min(B, min(u / 2, min(l, min(a / 2, min(s, min(b, r)))))) << endl; + return 0; +} +int main() { + int n, m; + cin >> n >> m; + vector arr; + while (m > 0) { + int i; + cin >> i; + arr.push_back(i); + m--; + } + sort(arr.begin(), arr.end()); + int distance = 1e9; + for (int i = 0; i < arr.size() - n + 1; i++) { + if (arr[i + n - 1] - arr[i] < distance) { distance = arr[i + n - 1] - arr[i]; } + } + cout << distance << endl; + return 0; +} +int main() { + long long int t; + cin >> t; + long long int dest, v, l, r; + while (t--) { + cin >> dest >> v >> l >> r; + long long int fin = dest / v; + long long int fin1 = r / v; + long long int fin2 = (l - 1) / v; + cout << (fin - fin1 + fin2) << endl; + } + return 0; +} +int main() { + int n; + cin >> n; + int x1, x2, y1, y2; + int sum = 0; + int a, b; + for (int i = 0; i < n; i++) { + cin >> x1 >> y1 >> x2 >> y2; + a = x1 - x2; + if (a < 0) a = -a; + b = y1 - y2; + if (b < 0) b = -b; + sum += (a + 1) * (b + 1); + } + cout << sum << endl; + return 0; +} +int arr[105]; +int main() { + int m; + while (cin >> m) { + for (int i = 0; i < m; i++) cin >> arr[i]; + bool flag = 1; + int ans = 0; + while (flag) { + flag = 0; + int Max = -9999999; + int k = 1; + for (int i = 1; i < m; i++) { + if (arr[i] > Max) { + Max = arr[i]; + k = i; + } + } + if (Max >= arr[0]) { + arr[k]--; + arr[0]++; + ans++; + flag = 1; + } else + flag = 0; + } + cout << ans << endl; + } + return 0; +} +int main() { + long long int n, count, i, j; + cin >> n; + long long int a[n][4]; + for (i = 0; i < n; i++) + for (j = 0; j < 4; j++) cin >> a[i][j]; + for (i = 0; i < n; i++) { + count = 0; + count = a[i][0] / a[i][3]; + count += count / a[i][1] * a[i][2]; + cout << count << endl; + } +} +bool beat(char c, char d) { + if (c == 'R' && d == 'S' || c == 'S' && d == 'P' || c == 'P' && d == 'R') return true; + return false; +} +int main() { + int n; + cin >> n; + string a, b; + cin >> a >> b; + int m = a.size(), k = b.size(); + int as = 0, bs = 0; + for (int i = 0; i < m * k; i++) { + if (beat(a[i % a.size()], b[i % b.size()])) bs++; + if (beat(b[i % b.size()], a[i % a.size()])) as++; + } + as *= n / (m * k), bs *= n / (m * k); + n = n % (m * k); + for (int i = 0; i < n; i++) { + if (beat(a[i % a.size()], b[i % b.size()])) bs++; + if (beat(b[i % b.size()], a[i % a.size()])) as++; + } + cout << as << ' ' << bs << endl; + return 0; +} +int main() { + int n; + cin >> n; + for (int i = 0; i < n; i++) { + long long a, b, c; + cin >> a >> b >> c; + long long ans = (a - b) * ((c + 1) / 2); + if (c % 2 == 1) { ans += b; } + cout << ans << endl; + } +} +int main() { + long long a, b; + long long answer = 1; + long long count = 0; + cin >> a >> b; + long long c = a - b; + if (c & 1 || (c >>= 1) & b) + cout << "0" << endl; + else { + while (b != 0) { + if (b & 1) answer *= 2; + b >>= 1; + } + if (!c) answer -= 2; + cout << answer << endl; + } + return 0; +} +int main() { + int n, b, d; + cin >> n >> b >> d; + int tot = 0, ret = 0; + for (int i = 0; i < n; i++) { + int a; + cin >> a; + if (a > b) continue; + tot += a; + if (tot > d) { + ret++; + tot = 0; + } + } + cout << ret << endl; + return 0; +} +int main() { + int n; + cin >> n; + if (n <= 10 || n - 10 >= 12) { + cout << "0" << endl; + return 0; + } + if (n - 10 == 1 || n - 10 == 11) { + cout << 4 << endl; + } else if (n - 10 == 10) { + cout << 15 << endl; + } else { + cout << 4 << endl; + } + return 0; +} +const int maxn = 100050; +string s, t; +int main() { + while (cin >> s >> t) { + int ans; + int n4 = 0, n7 = 0; + for (int i = 0; i < s.size(); i++) { + if (s[i] != t[i]) { + if (s[i] == '4') { + n4++; + } else { + n7++; + } + } + } + ans = max(n4, n7); + cout << ans << endl; + } + return 0; +} +int n, k, p, s; +int main() { + cin >> k >> n >> s >> p; + int num = (n / s) * s == n ? n / s : (n / s + 1); + int sum = num * k; + num = (sum / p) * p == sum ? (sum / p) : (sum / p) + 1; + cout << num << endl; +} +long long n, last; +int main() { + cin >> n; + cout << "2\n"; + last = 2; + for (long long i = 2; i <= n; i++) { + long long x = (i + 1) * (i + 1) * i - last / i; + cout << x << "\n"; + last = i * (i + 1); + } + return 0; +} +int main() { + long long int a; + cin >> a; + for (long long int i = 1; i <= a; i++) { + if (i == 1) + cout << 2 << endl; + else + cout << i * (i + 1) * (i + 1) - (i - 1) << endl; + } + return 0; +} +const int MAX_N = 2e5 + 10; +const int MAX_LOG = 62; +const long long INF = 1e18 + 1; +const long long MOD = 1e9 + 7; +long long n, c1, c2, ans = INF; +string s; +int m; +int main() { + cin >> n >> c1 >> c2; + cin >> s; + for (int i = 0; i < n; i++) + if (s[i] == '1') m++; + for (int i = 1; i <= m; i++) { + long long k = n / i; + long long r = n % i; + long long tmp = r * (c1 + c2 * (k)*k); + tmp += (i - r) * (c1 + c2 * (k - 1) * (k - 1)); + ans = min(ans, tmp); + } + cout << ans << endl; +} +const int maxn = 1e6 + 10; +const int INF = 0x3f3f3f3f; +const int inf = 0x3f; +const double EPS = 1e-7; +const double Pi = acos(-1); +const int MOD = 1e9 + 7; +int main() { + do { + } while (0); + string s1, s2; + cin >> s1 >> s2; + cout << s1[0]; + for (int i = 1; i < s1.size(); i++) { + if (s1[i] < s2[0]) + cout << s1[i]; + else + break; + } + cout << s2[0] << endl; + return 0; +} +int main() { + int n; + cin >> n; + long long t = 0; + for (int i = 0, x; i < n; ++i) cin >> x, t += x; + int m; + cin >> m; + for (int l, r; m--;) { + cin >> l >> r; + if (t <= r) { + cout << max(1LL * l, t) << "\n"; + return 0; + } + } + cout << "-1\n"; + return 0; +} +int main() { + int n; + cin >> n; + int z = 0; + while (n--) { + int a, b, c, d; + cin >> a >> b >> c >> d; + z += (c - a + 1) * (d - b + 1); + } + cout << z << '\n'; +} +int main() { + int a, b, c, l, r, mid, result; + cin >> a >> b >> c; + l = 0; + r = ceil(((float)a * c) / b); + mid = (l + r) / 2; + while (l <= r) { + if ((mid + c) * b >= a * c) { + result = mid; + r = mid - 1; + } else + l = mid + 1; + mid = (l + r) / 2; + } + cout << result << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; + return 0; +} +int main() { + int n; + cin >> n; + cout << 25 << endl; + return 0; +} +string h(string p, string q) { + string a = ""; + for (int i = 0; i < p.length(); i++) { + if (p[i] == q[i]) + a = a + p[i]; + else + return a; + } + return a; +} +int main() { + int n; + cin >> n; + string s[n]; + for (int i = 0; i < n; i++) cin >> s[i]; + string answer = h(s[0], s[1]); + for (int i = 2; i < n; i++) { answer = h(answer, s[i]); } + cout << answer.length() << endl; + return 0; +} +const int N = 1005; +int n, m, c, zlicz[N]; +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> c; + zlicz[c]++; + } + int mn = N; + for (int i = 1; i <= n; i++) mn = min(mn, zlicz[i]); + cout << mn << endl; + return 0; +} +int main() { + int n; + cin >> n; + int nd = 1; + int b = false; + for (int i = 0; i < n; ++i) { + int ns = (n - nd) / 2; + for (int j = 0; j < ns; ++j) { cout << "*"; } + for (int j = 0; j < nd; ++j) { cout << "D"; } + for (int i = 0; i < ns; ++i) { cout << "*"; } + cout << "\n"; + if (b) + nd -= 2; + else { + nd += 2; + if (nd == n) b = true; + } + } +} +int main() { + int n; + cin >> n; + for (int i = 1; i <= n; i += 2) { + for (int j = 0; j < (n - i) / 2; j++) { cout << "*"; } + for (int o = 0; o < i; o++) { cout << "D"; } + for (int p = 0; p < (n - i) / 2; p++) { cout << "*"; } + cout << endl; + } + for (int i = n - 2; i >= 1; i -= 2) { + for (int j = 0; j < (n - i) / 2; j++) { cout << '*'; } + for (int o = 0; o < i; o++) { cout << 'D'; } + for (int p = 0; p < (n - i) / 2; p++) { cout << '*'; } + cout << endl; + } +} +string s; +bool check(char c) { + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; + return false; +} +int main() { + cin >> s; + int l = s.length(); + for (int i = 0; i < l; i++) { + if (!check(s[i]) && s[i] != 'n') { + if (i + 1 == l || !check(s[i + 1])) { + cout << "NO" << endl; + return 0; + } + } + } + cout << "YES" << endl; + return 0; +} +int main() { + int n, a; + string s; + cin >> s; + a = s.length(); + n = (a + 1) * 26 - a; + cout << n << endl; + return 0; +} +int main() { + long long n, d; + cin >> n >> d; + long long array[n]; + for (long long i = 0; i < n; i++) { cin >> array[i]; } + if (n == 1) { + cout << 0 << endl; + return 0; + } + sort(array, array + n); + int flag = 0; + long long min = LONG_MAX; + for (long long i = 0; i < n - 1; i++) { + for (long long j = i + 1; j < n; j++) { + if ((array[j] - array[i]) <= d) { + flag = 1; + if (min > (i + n - j - 1)) min = i + n - j - 1; + } else { + continue; + } + } + } + if (flag == 0) min = n - 1; + cout << min << endl; + return 0; +} +int main() { + int a; + cin >> a; + int b[a][3]; + for (int i = 0; i < a; i++) { + for (int j = 0; j < 3; j++) { cin >> b[i][j]; } + } + int sum1, sum2, sum3; + sum1 = 0; + sum2 = 0; + sum3 = 0; + for (int i = 0; i < a; i++) { sum1 = sum1 + b[i][0]; } + for (int i = 0; i < a; i++) { sum2 = sum2 + b[i][1]; } + for (int i = 0; i < a; i++) { sum3 = sum3 + b[i][2]; } + if (sum1 == 0 && sum2 == 0 && sum3 == 0) { + cout << "YES" << endl; + return 0; + } else { + cout << "NO" << endl; + } +} +int main() { + int n, hitung = 0; + cin >> n; + hitung += (n / 100); + n %= 100; + hitung += (n / 20); + n %= 20; + hitung += (n / 10); + n %= 10; + hitung += (n / 5); + n %= 5; + hitung += (n / 1); + n %= 1; + cout << hitung << endl; +} +int main() { + long long ans, i, tt, n, x, f = 0; + cin >> n; + tt = n - 1; + ans = n; + i = 1; + while (tt--) { + cin >> x; + n ^= x; + n ^= i; + i++; + } + cout << n << endl; + return 0; +} +int main() { + long long amigos, garrafas, militros, limoes, fatias, sal, nl, np; + cin >> amigos >> garrafas >> militros >> limoes >> fatias >> sal >> nl >> np; + militros = militros * garrafas; + fatias = fatias * limoes; + cout << min(fatias, min(sal / np, militros / nl)) / amigos << endl; + return 0; +} +int main() { + int l1 = 0, l2 = 0, k = 0; + long long n = 0, m = 0; + string s1 = "", s2 = ""; + char ziro = '0', one = '1'; + cin >> n; + while (cin >> n >> m) { + if (n == m) { + cout << n << '\n'; + } else { + while (n > 0) { + if (n % 2 > 0) { + s1 = one + s1; + } else { + s1 = ziro + s1; + } + n /= 2; + } + while (m > 0) { + if (m % 2 > 0) { + s2 = one + s2; + } else { + s2 = ziro + s2; + k++; + } + m /= 2; + } + l1 = s1.size(); + l2 = s2.size(); + if (k > 0) { + if (l1 != l2) { + s2[0] = ziro; + for (int i = 1; i < l2; i++) { + if (s2[i] == ziro) { s2[i] = one; } + } + } else { + for (int i = 1; i < l2; i++) { + if (s2[i] == ziro) { k--; } + if (m == 1 && s2[i] == ziro) { s2[i] = one; } + if (m == 0 && k > 0 && i + 1 < l2 && s2[i] == one && s1[i] == ziro) { + s2[i] = ziro; + m = 1; + } + } + } + } + for (int i = l2 - 1, j = 0; i > 0; i--, j++) { + if (s2[j] == one) { + m = 2; + for (int jj = 1; jj < i; jj++) { m *= 2; } + n += m; + } + } + cout << n + 1 << '\n'; + k = 0; + s1 = ""; + s2 = ""; + } + } +} +int main() { + int n; + while (cin >> n) { + int y, z, i, j; + for (i = 1; i < 32; i++) { + if (n <= ((1 << i) - 1) * 5) break; + } + if (i == 0) + z = n; + else { + n -= ((1 << (i - 1)) - 1) * 5; + for (j = 1; j <= 5; j++) + if (n <= (1 << (i - 1)) * j) break; + z = j; + } + if (z == 1) + cout << "Sheldon" << endl; + else if (z == 2) + cout << "Leonard" << endl; + else if (z == 3) + cout << "Penny" << endl; + else if (z == 4) + cout << "Rajesh" << endl; + else + cout << "Howard" << endl; + } + return 0; +} +int gcd(int a, int b) { + return gcd(a % b, a); +} +int main() { + string a, b; + cin >> a >> b; + if (a == b) + cout << a << endl; + else + cout << 1 << endl; + return 0; +} +int main() { + int n; + cin >> n; + set s; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + if (x > 0) { s.insert(x); } + } + cout << s.size() << endl; + return 0; +} +int main() { + int a, b, c, d, m1, m2, v1, v2, m, v; + cin >> a >> b >> c >> d; + m1 = (3 * a) / 10; + m2 = a - (a / 250) * c; + m = max(m1, m2); + v1 = (3 * b) / 10; + v2 = b - (b / 250) * d; + v = max(v1, v2); + if (m == v) { + puts("Tie"); + return 0; + } + puts(m > v ? "Misha" : "Vasya"); + return 0; +} +int main() { + int n; + string a, b; + int c = 0; + cin >> n; + cin >> a >> b; + for (int i = 0; i < n; i++) { c += min(10 - abs(a[i] - b[i]), abs(a[i] - b[i])); } + cout << c << "\n"; + return 0; +} +int main() { + int n; + cin >> n; + int a[35], b[35], num = 0; + for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (a[i] == b[j]) num++; + } + } + cout << num << endl; +} +int main() { + int n; + while (cin >> n) { + int a[150]; + long long sum1 = 0, sum2 = 0; + for (int i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < 0) { + sum1 += a[i]; + } else { + sum2 += a[i]; + } + } + cout << sum2 - sum1 << endl; + } + return 0; +} +int a[1010], c[1010], n, m, j; +int main() { + cin >> n >> m; + for (int i = 0; i < n; i++) { cin >> c[i]; } + for (int i = 0; i < m; i++) { cin >> a[i]; } + for (int i = 0; i < n; i++) { + if (c[i] <= a[j]) { j++; } + } + cout << j << endl; + return 0; +} +int main() { + int n; + cin >> n; + int i, cnt = 0; + vector a(n); + for (i = 0; i < n; i++) cin >> a[i]; + int max = a[0], min = a[0]; + for (i = 1; i < n; i++) { + if (a[i] < min) { + cnt++; + min = a[i]; + } + if (a[i] > max) { + cnt++; + max = a[i]; + } + } + cout << cnt << endl; + return 0; +} +char a[1000010], b[1000010]; +char c[1000010]; +int main() { + cin >> a; + cin >> b; + int lena = strlen(a), lenb = strlen(b); + if (lena > lenb) { + for (int i = 0; i < lenb; i++) c[i] = b[i]; + for (int i = 0; i < lenb; i++) b[i + lena - lenb] = c[i]; + for (int i = 0; i < lena - lenb; i++) b[i] = '0'; + } else if (lena < lenb) { + for (int i = 0; i < lena; i++) c[i] = a[i]; + for (int i = 0; i < lena; i++) a[i + lenb - lena] = c[i]; + for (int i = 0; i < lenb - lena; i++) a[i] = '0'; + } + int len = max(lena, lenb); + int flag = 0; + for (int i = 0; i < len; i++) { + if (a[i] > b[i]) { + flag = 1; + break; + } else if (a[i] < b[i]) { + flag = 2; + break; + } + } + if (flag == 1) + cout << ">\n"; + else if (flag == 2) + cout << "<\n"; + else if (flag == 0) + cout << "=\n"; + return 0; +} +int main() { + int n, s; + cin >> n >> s; + int a[n + 1], b[n + 1]; + for (int i = 1; i <= n; ++i) cin >> a[i]; + for (int i = 1; i <= n; ++i) cin >> b[i]; + if (a[1] == 1) { + if (a[s] == 1) + cout << "YES" << endl; + else if (b[s] == 1) { + for (int i = s + 1; i <= n; ++i) { + if (a[i] == 1 && b[i] == 1) { + cout << "YES" << endl; + return 0; + } + } + cout << "NO" << endl; + } else + cout << "NO" << endl; + } else + cout << "NO" << endl; + return 0; +} +int main() { + int i, j, k, sum1 = 0, sum2 = 0, sum = 0; + char name[100], cnt[26]; + cin >> name; + for (i = 0; i < 26; i++) { cnt[i] = 0; } + for (i = 0; i < strlen(name); i++) { + if (name[i] >= 'a' && name[i] <= 'z') { cnt[name[i] - 'a']++; } + } + for (j = 0; j < 26; j++) { + if (cnt[j] == 1) { + sum1++; + } else if (cnt[j] >= 2) { + sum2++; + } + } + sum = sum1 + sum2; + if (sum % 2 == 0) { + cout << "CHAT WITH HER!" << endl; + } else { + cout << "IGNORE HIM!" << endl; + } + return 0; +}